Exemplo n.º 1
0
static int winCanvasMapMethod(Ihandle* ih)
{
  CLIENTCREATESTRUCT clientstruct;
  void *clientdata = NULL;
  char *classname;
  DWORD dwStyle = WS_CHILD, dwExStyle = 0;

  if (!ih->parent)
    return IUP_ERROR;

  if (ih->iclass->is_interactive)
  {
    if (iupAttribGetBoolean(ih, "CANFOCUS"))
      dwStyle |= WS_TABSTOP;
  }
                           
  if (ih->firstchild) /* can be a container */
  {
    dwStyle |= WS_CLIPSIBLINGS;

    if (iupAttribGetBoolean(IupGetDialog(ih), "COMPOSITED"))
      dwExStyle |= WS_EX_COMPOSITED;
    else
      dwStyle |= WS_CLIPCHILDREN;
  }
                           
  if (iupAttribGetBoolean(ih, "MDICLIENT"))  
  {
    /* creating a MDI Client that will be inside the MDI Frame, 
       it will work as parent of all MDI children */
    Ihandle *winmenu = IupGetAttributeHandle(ih, "MDIMENU");

    classname = "mdiclient";

    iupAttribSetStr(ih, "BORDER", "NO");

    iupAttribSetStr(IupGetDialog(ih), "MDICLIENT_HANDLE", (char*)ih);

    clientdata = &clientstruct;
    clientstruct.hWindowMenu = winmenu? winmenu->handle: NULL;

    /* The system increments the identifier 
       for each additional MDI child window the application creates, 
       and reassigns identifiers when the application 
       destroys a window to keep the range of identifiers contiguous. */
    clientstruct.idFirstChild = IUP_MDICHILD_START;
  }
  else 
    classname = "IupCanvas";

  if (iupAttribGetBoolean(ih, "BORDER"))
    dwStyle |= WS_BORDER;

  ih->data->sb = iupBaseGetScrollbar(ih);
  if (ih->data->sb & IUP_SB_HORIZ)
    dwStyle |= WS_HSCROLL;
  if (ih->data->sb & IUP_SB_VERT)
    dwStyle |= WS_VSCROLL;

  ih->serial = iupDialogGetChildId(ih);

  ih->handle = CreateWindowEx(dwExStyle,/* extended style */
          classname,                    /* window class */
          NULL,                         /* title */
          dwStyle,                      /* window style */
          0,                            /* x-position */
          0,                            /* y-position */
          10,                           /* default width to avoid 0 */
          10,                           /* default height to avoid 0 */
          iupChildTreeGetNativeParentHandle(ih),     /* window parent */
          (HMENU)ih->serial,            /* child identifier */
          iupwin_hinstance,             /* instance of app. */
          clientdata);

  if (!ih->handle)
    return IUP_ERROR;

  /* associate HWND with Ihandle*, all Win32 controls must call this. */
  iupwinHandleSet(ih);

  IupSetCallback(ih, "_IUPWIN_OLDPROC_CB", (Icallback)DefWindowProc);
  IupSetCallback(ih, "_IUPWIN_CTRLPROC_CB", (Icallback)winCanvasProc);

  /* configure for DRAG&DROP */
  if (IupGetCallback(ih, "DROPFILES_CB"))
    iupAttribSetStr(ih, "DRAGDROP", "YES");

  return IUP_NOERROR;
}
Exemplo n.º 2
0
static int winDialogMapMethod(Ihandle* ih)
{
  InativeHandle* native_parent;
  DWORD dwStyle = WS_CLIPSIBLINGS, 
        dwExStyle = 0;
  int has_titlebar = 0,
      has_border = 0;
  char* classname = "IupDialog";

  char* title = iupAttribGet(ih, "TITLE"); 
  if (title)
    has_titlebar = 1;

  if (iupAttribGetInt(ih, "DIALOGFRAME")) 
  {
    iupAttribSetStr(ih, "RESIZE", "NO");
    iupAttribSetStr(ih, "MINBOX", "NO");
  }

  if (iupAttribGetInt(ih, "RESIZE"))
    dwStyle |= WS_THICKFRAME;
  else
    iupAttribSetStr(ih, "MAXBOX", "NO");  /* Must also remove this to RESIZE=NO work */

  if (iupAttribGetInt(ih, "MAXBOX"))
  {
    dwStyle |= WS_MAXIMIZEBOX;
    has_titlebar = 1;
  }

  if (iupAttribGetInt(ih, "MINBOX"))
  {
    dwStyle |= WS_MINIMIZEBOX;
    has_titlebar = 1;
  }

  if (iupAttribGetInt(ih, "MENUBOX"))
  {
    dwStyle |= WS_SYSMENU;
    has_titlebar = 1;
  }

  if (iupAttribGetInt(ih, "BORDER") || has_titlebar)
    has_border = 1;

  if (iupAttribGetInt(ih, "MDICHILD"))
  {
    static int mdi_child_id = 0;
    Ihandle *client;
    char name[50];

    /* must have a parent dialog (the mdi frame) */
    Ihandle* parent = IupGetAttributeHandle(ih, "PARENTDIALOG");
    if (!parent || !parent->handle)
      return IUP_ERROR;

    /* set when the mdi client is mapped */
    client = (Ihandle*)iupAttribGet(parent, "MDICLIENT_HANDLE");
    if (!client)
      return IUP_ERROR;

    /* store the mdi client handle in each mdi child also */
    iupAttribSetStr(ih, "MDICLIENT_HANDLE", (char*)client);

    sprintf(name, "_IUPWIN_MDI_ID_[%d]", mdi_child_id);
    iupAttribSetStr(parent, name, (char*)ih);
    mdi_child_id++;
    iupAttribSetInt(parent, "_IUPWIN_MAX_MDI_ID", mdi_child_id);

    classname = "IupDialogMDIChild";

    /* The actual parent is the mdi client */
    native_parent = client->handle;

    dwStyle |= WS_CHILD;
    if (has_titlebar)
      dwStyle |= WS_CAPTION;
    else if (has_border)
      dwStyle |= WS_BORDER;

    if (!IupGetName(ih))
      iupAttribSetHandleName(ih);
  }
  else
  {
    native_parent = iupDialogGetNativeParent(ih);

    if (native_parent)
    {
      dwStyle |= WS_POPUP;

      if (has_titlebar)
        dwStyle |= WS_CAPTION;
      else if (has_border)
        dwStyle |= WS_BORDER;
    }
    else
    {
      if (has_titlebar)
      {
        dwStyle |= WS_OVERLAPPED;
      }
      else 
      {
        if (has_border)
          dwStyle |= WS_POPUP | WS_BORDER;
        else
          dwStyle |= WS_POPUP;

        dwExStyle |= WS_EX_NOACTIVATE; /* this will hide it from the taskbar */ 
      }
    }

    if (iupAttribGet(ih, "MDIFRAME"))
      classname = "IupDialogMDIFrame";
  }

  if (iupAttribGetInt(ih, "TOOLBOX") && native_parent)
    dwExStyle |= WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE;

  if (iupAttribGetInt(ih, "DIALOGFRAME") && native_parent)
    dwExStyle |= WS_EX_DLGMODALFRAME;  /* this will hide the MENUBOX but not the close button */

  if (iupAttribGetInt(ih, "COMPOSITED"))
    dwExStyle |= WS_EX_COMPOSITED;
  else
    dwStyle |= WS_CLIPCHILDREN;

  if (iupAttribGetInt(ih, "HELPBUTTON"))
    dwExStyle |= WS_EX_CONTEXTHELP;

  if (iupAttribGetInt(ih, "CONTROL") && native_parent) 
  {
    /* TODO: this were used by LuaCom to create embeded controls, 
       don't know if it is still working */
    dwExStyle |= WS_EX_CONTROLPARENT;
    dwStyle = WS_CHILD | WS_TABSTOP | WS_CLIPCHILDREN;
    classname = "IupDialogControl";
  }

  /* CreateWindowEx will send WM_GETMINMAXINFO before Ihandle is associated with HWND */
  if (iupAttribGet(ih, "MINSIZE") || iupAttribGet(ih, "MAXSIZE"))
    winMinMaxHandle = ih;

  /* size will be updated in IupRefresh -> winDialogLayoutUpdate */
  /* position will be updated in iupDialogShowXY              */

  if (iupAttribGetInt(ih, "MDICHILD"))
    ih->handle = CreateMDIWindow(classname, 
                                title,              /* title */
                                dwStyle,            /* style */
                                0,                  /* x-position */
                                0,                  /* y-position */
                                100,                /* horizontal size - set this to avoid size calculation problems */
                                100,                /* vertical size */
                                native_parent,      /* owner window */
                                iupwin_hinstance,   /* instance of app. */
                                0);                 /* no creation parameters */
  else
    ih->handle = CreateWindowEx(dwExStyle,          /* extended styles */
                              classname,          /* class */
                              title,              /* title */
                              dwStyle,            /* style */
                              0,                  /* x-position */
                              0,                  /* y-position */
                              100,                /* horizontal size - set this to avoid size calculation problems */
                              100,                /* vertical size */
                              native_parent,      /* owner window */
                              (HMENU)0,           /* Menu or child-window identifier */
                              iupwin_hinstance,   /* instance of app. */
                              NULL);              /* no creation parameters */
  if (!ih->handle)
    return IUP_ERROR;

  /* associate HWND with Ihandle*, all Win32 controls must call this. */
  iupwinHandleSet(ih);

  if (iupStrEqual(classname, "IupDialogMDIChild")) /* hides the mdi child */
    ShowWindow(ih->handle, SW_HIDE);

  /* configure for DRAG&DROP */
  if (IupGetCallback(ih, "DROPFILES_CB"))
    iupAttribSetStr(ih, "DRAGDROP", "YES");

  /* Reset attributes handled during creation that */
  /* also can be changed later, and can be consulted from the native system. */
  iupAttribSetStr(ih, "TITLE", NULL); 
  iupAttribSetStr(ih, "BORDER", NULL);

  /* Ignore VISIBLE before mapping */
  iupAttribSetStr(ih, "VISIBLE", NULL);

  /* Set the default CmdShow for ShowWindow */
  ih->data->cmd_show = SW_SHOWNORMAL;

  return IUP_NOERROR;
}