Exemple #1
0
static void iDialogAfterShow(Ihandle* ih)
{
  Ihandle* old_focus;
  IFni show_cb;
  int show_state;

  /* process all pending messages */
  IupFlush();

  old_focus = IupGetFocus();
  show_state = ih->data->show_state;

  show_cb = (IFni)IupGetCallback(ih, "SHOW_CB");
  if (show_cb && show_cb(ih, show_state) == IUP_CLOSE)
  {
    IupExitLoop();
    return;
  }

  if (show_state == IUP_SHOW)
  {
    if (show_cb)
      IupFlush();  /* again to update focus */

    /* do it only if show_cb did NOT changed the current focus */
    if (old_focus == IupGetFocus())
    {
      Ihandle *startfocus = IupGetAttributeHandle(ih, "STARTFOCUS");
      if (startfocus)
        IupSetFocus(startfocus);
      else
        IupNextField(ih);
    }
  }
}
Exemple #2
0
static void drawTestGL(Ihandle* ih)
{
  Ihandle* glcanvas = IupGetAttributeHandle(ih, "PREVIEWGLCANVAS");
  if (glcanvas)
  {
    int w = IupGetInt(ih, "PREVIEWWIDTH");
    int h = IupGetInt(ih, "PREVIEWHEIGHT");

    IupGLMakeCurrent(glcanvas);
    glViewport(0,0,w,h);

    glClearColor(1.0, 0.0, 1.0, 1.f);  /* pink */
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3f(1.0,0.0,0.0);  /* red */
    glBegin(GL_QUADS); 
    glVertex2f(0.9f,0.9f); 
    glVertex2f(0.9f,-0.9f); 
    glVertex2f(-0.9f,-0.9f); 
    glVertex2f(-0.9f,0.9f); 
    glEnd();

    IupGLSwapBuffers(glcanvas);
  }
  else
    drawTest(ih);
}
Exemple #3
0
Ihandle* IupGetDialogChild(Ihandle* ih, const char* name)
{
  Ihandle *child, *dialog;
  char attrib[1024] = "_IUP_DIALOG_CHILD_";

  iupASSERT(iupObjectCheck(ih));
  if (!iupObjectCheck(ih))
    return NULL;

  if (!name)
    return NULL;

  dialog = IupGetDialog(ih);
  if (dialog) ih = dialog;
 
  strcat(attrib, name);
  child = (Ihandle*)iupAttribGet(ih, attrib);
  if (child) return child;

  if (ih->firstchild)
  {
    child = iBaseFindNamedChild(ih, name);
    if (child) return child;
  }

  ih = IupGetAttributeHandle(ih, "MENU");
  if (ih)
  {
    child = iBaseFindNamedChild(ih, name);
    if (child) return child;
  }
  return NULL;
}
static Ihandle* winContainerWmCommandGetIhandle(Ihandle *ih, WPARAM wp, LPARAM lp)
{
  /* WPARAM - if HIWORD is 0 if the message is from a menu.
              or HIWORD is 1 if the message is from an accelerator.
              or HIWORD is the notification code if the message is from a control.
              LOWORD is the identifier.
     LPARAM - the control sending the message or 0. */

  Ihandle *child = NULL;

  if (HIWORD(wp)==0 && lp==0 && LOWORD(wp)>10)
  {
    Ihandle* dlg_menu = IupGetAttributeHandle(ih, "MENU");
    if (dlg_menu)
      child = iupwinMenuGetItemHandle((HMENU)dlg_menu->handle, LOWORD(wp));  /* menu */
  }
  else 
  {
    if (lp==0)
      child = ih;                              /* native parent */
    else
    {
      child = iupwinHandleGet((HWND)lp);       /* control */
      if (!child)
        child = iupwinHandleGet(GetParent((HWND)lp));       /* control */
    }
  }

  return child;
}
Exemple #5
0
InativeHandle* iupDialogGetNativeParent(Ihandle* ih)
{
  Ihandle* parent = IupGetAttributeHandle(ih, "PARENTDIALOG");
  if (parent && parent->handle)
    return parent->handle;
  else
    return (InativeHandle*)iupAttribGet(ih, "NATIVEPARENT");
}
Exemple #6
0
static void winFileDlgUpdatePreviewGLCanvas(Ihandle* ih)
{
  Ihandle* glcanvas = IupGetAttributeHandle(ih, "PREVIEWGLCANVAS");
  if (glcanvas)
  {
    iupAttribSetStr(glcanvas, "HWND", iupAttribGet(ih, "HWND"));
    glcanvas->iclass->Map(glcanvas);
  }
}
Exemple #7
0
int item_image_cb(Ihandle* ih)
{
  printf("ACTION(%s)\n", IupGetAttribute(ih, "TITLE"));
  ih = IupGetNextChild(IupGetParent(ih), ih);
  if (IupGetAttributeHandle(ih, "IMAGE"))
    IupSetAttribute(ih, "IMAGE", NULL);
  else
    IupSetAttribute(ih, "IMAGE", "image_test");
  return IUP_DEFAULT;
}
Exemple #8
0
void iupmotCBstructure (Widget w, XtPointer data, XEvent *ev, Boolean *cont)
{
  Ihandle *n = (Ihandle*)data;
  Widget form = XtNameToWidget((Widget)handle(n),"*dialog_area");
  Iwidgetdata *wd;
  int state = -1;
  if (!form) return;
  XtVaGetValues (form, XmNuserData, &wd, NULL);
  if (!wd) return;

  switch(ev->type)
  {
    case MapNotify:
    {
      if ( iconic( wd->data ) ) /* IUP_RESTORE */
      {
        wd->data = (void*)(-((long)wd->data));
        state = IUP_RESTORE;
      }
      else /* IUP_SHOW */
      {
        Ihandle *startfocus = IupGetAttributeHandle(n, "STARTFOCUS");
        if (startfocus)
          IupSetFocus(startfocus);

        state = IUP_SHOW;
        iupmot_nvisiblewin++;
      }
      break;
    }

    case UnmapNotify:
    {
      if ( shown(wd->data) || popuped(wd->data) ) /* IUP_MINIMIZE */
      {
        wd->data = (void*)(-((long)wd->data));
        state = IUP_MINIMIZE;
      }
      break;
    }
  }
  {
    IFni cb = (IFni)IupGetCallback(n, IUP_SHOW_CB);
    if (cb && state>=0)
    {
      iupmot_incallback = TRUE;
      if (cb(n, state) == IUP_CLOSE) 
        iupmot_exitmainloop = 1;
      iupmot_incallback = FALSE;
    }
  }
}
Exemple #9
0
static void gtkFileDlgUpdatePreviewGLCanvas(Ihandle* ih)
{
  Ihandle* glcanvas = IupGetAttributeHandle(ih, "PREVIEWGLCANVAS");
  if (glcanvas)
  {
#ifdef WIN32                                 
    iupAttribSetStr(glcanvas, "HWND", iupAttribGet(ih, "HWND"));
#else
    iupAttribSetStr(glcanvas, "XWINDOW", iupAttribGet(ih, "XWINDOW"));
#endif
    glcanvas->iclass->Map(glcanvas);
  }
}
Exemple #10
0
static void iDialogCallShowCb(Ihandle* ih)
{
  IFni show_cb = (IFni)IupGetCallback(ih, "SHOW_CB");
  if (show_cb && show_cb(ih, ih->data->show_state) == IUP_CLOSE)
    IupExitLoop();

  if (ih->data->show_state == IUP_SHOW)
  {
    Ihandle *startfocus = IupGetAttributeHandle(ih, "STARTFOCUS");
    if (startfocus)
      IupSetFocus(startfocus);
    else
      IupNextField(ih);
  }
}
Exemple #11
0
static int winPopupDialog(Ihandle* n, int x, int y)
{
  HWND last_hwnd;
  HWND popup_hwnd;

  Ihandle* parent = IupGetAttributeHandle(n, IUP_PARENTDIALOG);
  if (parent && handle(parent))
    last_hwnd = handle(parent);
  else
    last_hwnd = GetActiveWindow();

  winShowXY(n, x, y);

  if (iupGetEnv(n, "_IUPWIN_POPUP"))
    return IUP_ERROR;

  popup_hwnd = (HWND)handle(n);

  /* disable all visible dialogs, and mark popup level */
  /* will be enable by IupHide */
  winDisableVisible(n);

  iupSetEnv(n, "_IUPWIN_POPUP", "1");  /* mark window as popup so IupHide can also detect it */

  /* interrupt processing here */
  IupMainLoop();

  /* if window is still valid (IupDestroy not called) */
  if (IsWindow(popup_hwnd))
  {
    iupSetEnv(n, "_IUPWIN_POPUP", "2"); 
    IupHide(n); /* hide the popup to update the disabled windows */
                /* but do not call IupExitLoop again */

    iupSetEnv(n, "_IUPWIN_POPUP", NULL); /* unmark the window */
  }

  /* activate the previous active window */
  if (last_hwnd) 
    SetActiveWindow(last_hwnd);

  return IUP_NOERROR;
}
Exemple #12
0
static void winDestroyWindow(Ihandle *n)
{
  assert(n);
  if(!n)
    return;

  if(type(n) == DIALOG_)
  {
    Ihandle *menu = IupGetAttributeHandle(n, IUP_MENU);
    if (menu) 
    {
      handle(menu) = NULL; /* the dialog will destroy the menu */
      IupDestroy(menu);  
    }

    /* if this is a popup window, this will also end the message loop */
    IupHide(n); 
    
    /* Deletes window and associated window class */
    winDestroyFreeWindowClass(n);
  }
  else if(type(n) == CANVAS_)
  {
    winDestroyFreeWindowClass(n);
  }
  else if(type(n) == MULTILINE_ || type(n) == TEXT_)
  {
    winDestroyRemoveProc(n, handle(n), "_IUPWIN_TEXTOLDPROC__");
    iupwinHandleRemove(n);
    DestroyWindow(handle(n));
  }
  else if(type(n) == LABEL_ || type(n) == LIST_ || type(n) == TOGGLE_)
  {
    if (type(n) == TOGGLE_)
      winDestroyRemoveProc(n, handle(n), "_IUPWIN_TOGGLEOLDPROC__");
    else if (type(n) == LIST_)
    {
      winDestroyRemoveProc(n, (HWND)IupGetAttribute(n, "_IUPWIN_EDITBOX"), "_IUPWIN_TEXTOLDPROC__");
      winDestroyRemoveProc(n, (HWND)IupGetAttribute(n, "_IUPWIN_COMBOBOX"), "_IUPWIN_COMBOLISTOLDPROC__");
    }
    else if (type(n) == LABEL_)
    {
      winDestroyRemoveProc(n, handle(n), "_IUPWIN_BUTTONOLDPROC__");
    }
    iupwinHandleRemove(n);
    DestroyWindow(handle(n));
  }
  else if(type(n) == BUTTON_)
  {
    winDestroyRemoveProc(n, handle(n), "_IUPWIN_BUTTONOLDPROC__");
    iupwinHandleRemove(n);
    DestroyWindow(handle(n));
  }
  else if(type(n) == IMAGE_)
  {
    winDestroyImage(n);
  }
  else if(type(n) == FRAME_)
  {
    winDestroyRemoveProc(n, handle(n), "_IUPWIN_FRAMEOLDPROC__");
    iupwinHandleRemove(n);
    DestroyWindow(handle(n));
  }
  else if(type(n) == MENU_)
  {
    assert(number(n)!=-1); 
    iupwinCleanidIhandle(number(n));
    if (handle(n)) DestroyMenu(handle(n));  /* Destroy Menu is recursive */
  }
  else if(type(n) == SUBMENU_)
  {
    assert(number(n)!=-1); 
    iupwinCleanidIhandle(number(n));
    /* DestroyWindows is automatically called by the system */
  }
  else if(type(n) == ITEM_ || type(n) == SEPARATOR_)
  {
    assert(number(n)!=-1); 
    iupwinCleanidIhandle(number(n));
    /* DestroyWindows is automatically called by the system */
  }
}
Exemple #13
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 (iupAttribGetBoolean(ih, "RESIZE"))
    {
        dwStyle |= WS_THICKFRAME;
        has_border = 1;
    }
    else
        iupAttribSetStr(ih, "MAXBOX", "NO");
    if (iupAttribGetBoolean(ih, "MENUBOX"))
    {
        dwStyle |= WS_SYSMENU;
        has_titlebar = 1;
    }
    if (iupAttribGetBoolean(ih, "MAXBOX"))
    {
        dwStyle |= WS_MAXIMIZEBOX;
        has_titlebar = 1;
    }
    if (iupAttribGetBoolean(ih, "MINBOX"))
    {
        dwStyle |= WS_MINIMIZEBOX;
        has_titlebar = 1;
    }
    if (iupAttribGetBoolean(ih, "BORDER") || has_titlebar)
        has_border = 1;

    if (iupAttribGetBoolean(ih, "MDICHILD"))
    {
        Ihandle *client;

        /* 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);

        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 (iupAttribGetBoolean(ih, "MDIFRAME"))
        {
            COLORREF color = GetSysColor(COLOR_BTNFACE);
            iupAttribSetStrf(ih, "_IUPWIN_BACKGROUND_COLOR", "%d %d %d", (int)GetRValue(color),
                             (int)GetGValue(color),
                             (int)GetBValue(color));
            classname = "IupDialogMDIFrame";
        }
    }

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

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

    iupwinGetNativeParentStyle(ih, &dwExStyle, &dwStyle);

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

    if (iupAttribGetBoolean(ih, "CONTROL") && native_parent)
    {
        /* TODO: this were used by LuaCom to create embeded controls,
           don't know if it is still working */
        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 (iupAttribGetBoolean(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. */
    iupwinHandleAdd(ih, ih->handle);

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

    /* configure for DROP of files */
    if (IupGetCallback(ih, "DROPFILES_CB"))
        iupAttribSetStr(ih, "DROPFILESTARGET", "YES");

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

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

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

    if (iupAttribGetBoolean(ih, "MDICHILD"))
        winDialogMDIRefreshMenu(ih);

    return IUP_NOERROR;
}
Exemple #14
0
static void winListDrawItem(Ihandle* ih, DRAWITEMSTRUCT *drawitem)
{
  char* text;
  int txt_w, txt_h;
  winListItemData* itemdata;
  HFONT hFont = (HFONT)iupwinGetHFontAttrib(ih);
  iupwinBitmapDC bmpDC;
  HDC hDC;
  RECT rect;
  COLORREF fgcolor, bgcolor;

  int x = drawitem->rcItem.left;
  int y = drawitem->rcItem.top;
  int width = drawitem->rcItem.right - drawitem->rcItem.left;
  int height = drawitem->rcItem.bottom - drawitem->rcItem.top;

  /* If there are no list box items, skip this message */
  if (drawitem->itemID == -1)
    return;

  hDC = iupwinDrawCreateBitmapDC(&bmpDC, drawitem->hDC, x, y, width, height);

  if (drawitem->itemState & ODS_SELECTED)
    bgcolor = GetSysColor(COLOR_HIGHLIGHT);
  else if (!iupwinGetColorRef(ih, "BGCOLOR", &bgcolor))
    bgcolor = GetSysColor(COLOR_WINDOW);
  SetDCBrushColor(hDC, bgcolor);
  SetRect(&rect, 0, 0, width, height);
  FillRect(hDC, &rect, (HBRUSH)GetStockObject(DC_BRUSH));

  if (iupdrvIsActive(ih))
  {
    if (drawitem->itemState & ODS_SELECTED)
      fgcolor = GetSysColor(COLOR_HIGHLIGHTTEXT);
    else if (!iupwinGetColorRef(ih, "FGCOLOR", &fgcolor))
      fgcolor = GetSysColor(COLOR_WINDOWTEXT);
  }
  else
    fgcolor = GetSysColor(COLOR_GRAYTEXT);

  /* Get the bitmap associated with the item */
  itemdata = winListGetItemData(ih, drawitem->itemID);

  /* Get and draw the string associated with the item */
  text = winListGetText(ih, drawitem->itemID);
  iupdrvFontGetMultiLineStringSize(ih, text, &txt_w, &txt_h);

  x = ih->data->maximg_w + 3; /* spacing between text and image */
  y = (height - txt_h)/2;  /* vertically centered */
  iupwinDrawText(hDC, text, x, y, txt_w, txt_h, hFont, fgcolor, 0);

  /* Draw the bitmap associated with the item */
  if (itemdata->hBitmap)
  {
    int bpp, img_w, img_h;
    HBITMAP hMask = NULL;

    iupdrvImageGetInfo(itemdata->hBitmap, &img_w, &img_h, &bpp);

    if (bpp == 8)
    {
      char name[50];
      sprintf(name, "IMAGE%d", (int)drawitem->itemID+1);
      hMask = iupdrvImageCreateMask(IupGetAttributeHandle(ih, name));
    }

    x = 0;
    y = (height - img_h)/2;  /* vertically centered */
    iupwinDrawBitmap(hDC, itemdata->hBitmap, hMask, x, y, img_w, img_h, bpp);

    if (hMask)
      DeleteObject(hMask);
  }

  /* If the item has the focus, draw the focus rectangle */
  if (drawitem->itemState & ODS_FOCUS)
    iupdrvDrawFocusRect(ih, hDC, 0, 0, width, height);

  free(text);
  iupwinDrawDestroyBitmapDC(&bmpDC);
}
Exemple #15
0
int iupKeyProcessNavigation(Ihandle* ih, int code, int shift)
{
  /* this is called after K_ANY is processed, 
     so the user may change its behavior */

  if (code == K_cTAB)
  {
    int is_multiline = iupAttribGetInt(ih, "_IUP_MULTILINE_TEXT");
    if (is_multiline)
    {
      if (shift)
        IupPreviousField(ih);
      else
        IupNextField(ih);
      return 1;
    }
  }
  else if (code == K_TAB || code == K_sTAB)
  {
    int is_multiline = iupAttribGetInt(ih, "_IUP_MULTILINE_TEXT");
    if (!is_multiline)
    {
      if (code == K_sTAB || shift)
        IupPreviousField(ih);
      else
        IupNextField(ih);
      return 1;
    }
  }
  else if (code == K_UP || code == K_DOWN)
  {
    int is_button = (IupClassMatch(ih, "button") || 
                     IupClassMatch(ih, "toggle"));
    if (is_button)
    {
      if (code == K_UP)
        iupFocusPrevious(ih);
      else
        iupFocusNext(ih);
      return 1;
    }
  }
  else if (code==K_ESC)
  {
    Ihandle* bt = IupGetAttributeHandle(IupGetDialog(ih), "DEFAULTESC");
    if (iupObjectCheck(bt) && IupClassMatch(bt, "button"))
      iupdrvActivate(bt);
    return 1;
  }
  else if (code==K_CR || code==K_cCR)
  {
    int is_multiline = iupAttribGetInt(ih, "_IUP_MULTILINE_TEXT");
    if ((code==K_CR && !is_multiline) || (code==K_cCR && is_multiline))
    {
      Ihandle* bt = IupGetAttributeHandle(IupGetDialog(ih), "DEFAULTENTER");
      if (iupObjectCheck(bt) && IupClassMatch(bt, "button"))
        iupdrvActivate(bt);
      return 1;
    }
  }

  return 0;
}
Exemple #16
0
static int wGLCanvasMapMethod(Ihandle* ih)
{
  Ihandle* ih_shared;
  int number;
  int isIndex = 0;
  int pixelFormat;
  PIXELFORMATDESCRIPTOR test_pfd;
  PIXELFORMATDESCRIPTOR pfd = { 
    sizeof(PIXELFORMATDESCRIPTOR),  /*  size of this pfd   */
      1,                     /* version number             */
      PFD_DRAW_TO_WINDOW |   /* support window             */
      PFD_SUPPORT_OPENGL,    /* support OpenGL             */
      PFD_TYPE_RGBA,         /* RGBA type                  */
      24,                    /* 24-bit color depth         */
      0, 0, 0, 0, 0, 0,      /* color bits ignored         */
      0,                     /* no alpha buffer            */
      0,                     /* shift bit ignored          */
      0,                     /* no accumulation buffer     */
      0, 0, 0, 0,            /* accum bits ignored         */
      16,                    /* 32-bit z-buffer             */
      0,                     /* no stencil buffer          */
      0,                     /* no auxiliary buffer        */
      PFD_MAIN_PLANE,        /* main layer                 */
      0,                     /* reserved                   */
      0, 0, 0                /* layer masks ignored        */
  };

  /* double or single buffer */
  if (iupStrEqualNoCase(IupGetAttribute(ih,"BUFFER"), "DOUBLE"))
    pfd.dwFlags |= PFD_DOUBLEBUFFER;

  /* stereo */
  if (IupGetInt(ih,"STEREO"))
    pfd.dwFlags |= PFD_STEREO;

  /* rgba or index */ 
  if (iupStrEqualNoCase(IupGetAttribute(ih,"COLOR"), "INDEX"))
  {
    isIndex = 1;
    pfd.iPixelType = PFD_TYPE_COLORINDEX;
    pfd.cColorBits = 8;  /* assume 8 bits when indexed */
    number = IupGetInt(ih,"BUFFER_SIZE");
    if (number > 0) pfd.cColorBits = (BYTE)number;
  }

  /* red, green, blue bits */
  number = IupGetInt(ih,"RED_SIZE");
  if (number > 0) pfd.cRedBits = (BYTE)number;
  pfd.cRedShift = 0;

  number = IupGetInt(ih,"GREEN_SIZE");
  if (number > 0) pfd.cGreenBits = (BYTE)number;
  pfd.cGreenShift = pfd.cRedBits;

  number = IupGetInt(ih,"BLUE_SIZE");
  if (number > 0) pfd.cBlueBits = (BYTE)number;
  pfd.cBlueShift = pfd.cRedBits + pfd.cGreenBits;

  number = IupGetInt(ih,"ALPHA_SIZE");
  if (number > 0) pfd.cAlphaBits = (BYTE)number;
  pfd.cAlphaShift = pfd.cRedBits + pfd.cGreenBits + pfd.cBlueBits;

  /* depth and stencil size */
  number = IupGetInt(ih,"DEPTH_SIZE");
  if (number > 0) pfd.cDepthBits = (BYTE)number;

  /* stencil */
  number = IupGetInt(ih,"STENCIL_SIZE");
  if (number > 0) pfd.cStencilBits = (BYTE)number;

  /* red, green, blue accumulation bits */
  number = IupGetInt(ih,"ACCUM_RED_SIZE");
  if (number > 0) pfd.cAccumRedBits = (BYTE)number;

  number = IupGetInt(ih,"ACCUM_GREEN_SIZE");
  if (number > 0) pfd.cAccumGreenBits = (BYTE)number;

  number = IupGetInt(ih,"ACCUM_BLUE_SIZE");
  if (number > 0) pfd.cAccumBlueBits = (BYTE)number;

  number = IupGetInt(ih,"ACCUM_ALPHA_SIZE");
  if (number > 0) pfd.cAccumAlphaBits = (BYTE)number;

  pfd.cAccumBits = pfd.cAccumRedBits + pfd.cAccumGreenBits + pfd.cAccumBlueBits + pfd.cAccumAlphaBits;

  /* get a device context */
  ih->data->device = GetDC((HWND)IupGetAttribute(ih, "HWND"));

  /* choose pixel format */
  if ((pixelFormat = ChoosePixelFormat(ih->data->device, &pfd)) == 0) 
  {
    iupAttribSetStr(ih, "ERROR", "No appropriate pixel format.");
    return IUP_NOERROR;
  } 
  SetPixelFormat(ih->data->device,pixelFormat,&pfd);

  /* create rendering context */
  if ((ih->data->context = wglCreateContext(ih->data->device)) == NULL)
  {
    iupAttribSetStr(ih, "ERROR", "Could not create a rendering context.");
    return IUP_NOERROR;
  }

  ih_shared = IupGetAttributeHandle(ih, "SHAREDCONTEXT");
  if (ih_shared)
    wglShareLists(ih_shared->data->context, ih->data->context);

  DescribePixelFormat(ih->data->device, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &test_pfd);
  if ((pfd.dwFlags & PFD_STEREO) && !(test_pfd.dwFlags & PFD_STEREO))
  {
    iupAttribSetStr(ih, "ERROR", "Stereo not available.");
    return IUP_NOERROR;
  }

  /* create colormap for index mode */
  if (isIndex)
  {
    LOGPALETTE lp = {0x300,1,{255,255,255,PC_NOCOLLAPSE}};
    ih->data->palette = CreatePalette(&lp);
    ResizePalette(ih->data->palette,1<<pfd.cColorBits);
    SelectPalette(ih->data->device,ih->data->palette,FALSE);
    RealizePalette(ih->data->device);
  }

  iupAttribSetStr(ih, "COLORMAP", (char*)ih->data->palette);
  iupAttribSetStr(ih, "VISUAL", (char*)ih->data->device);
  iupAttribSetStr(ih, "CONTEXT", (char*)ih->data->context);

  return IUP_NOERROR;
}
Exemple #17
0
static int setvisual (Ihandle* self)
{
  HWND hwnd = (HWND)iupGetNativeHandle(self);
  int pixelFormat;
  PIXELFORMATDESCRIPTOR test_pfd;
  PIXELFORMATDESCRIPTOR pfd = { 
    sizeof(PIXELFORMATDESCRIPTOR),  //  size of this pfd 
      1,                     // version number 
      PFD_DRAW_TO_WINDOW |   // support window 
      PFD_SUPPORT_OPENGL,     // support OpenGL
      PFD_TYPE_RGBA,         // RGBA type 
      24,                    // 24-bit color depth 
      0, 0, 0, 0, 0, 0,      // color bits ignored 
      0,                     // no alpha buffer 
      0,                     // shift bit ignored 
      0,                     // no accumulation buffer 
      0, 0, 0, 0,            // accum bits ignored 
      16,                    // 32-bit z-buffer	 
      0,                     // no stencil buffer 
      0,                     // no auxiliary buffer 
      PFD_MAIN_PLANE,        // main layer 
      0,                     // reserved 
      0, 0, 0                // layer masks ignored 
  };
  GLData* d = (GLData*)IupGetAttribute(self,"_IUPGL_DATA");
  Ihandle* shared;
  char* value;
  int number;
  int isIndex = 0;

  /* double or single buffer */
  value = IupGetAttribute(self,IUP_BUFFER);
  if (value && iupStrEqual(value,IUP_DOUBLE))
    pfd.dwFlags |= PFD_DOUBLEBUFFER;

  /* stereo */
  value = IupGetAttribute(self,IUP_STEREO);
  if (value && iupStrEqual(value,IUP_YES))
    pfd.dwFlags |= PFD_STEREO;

  /* rgba or index */ 
  value = IupGetAttribute(self,IUP_COLOR);
  if (value && iupStrEqual(value,IUP_INDEX))
  {
    isIndex = 1;
    pfd.iPixelType = PFD_TYPE_COLORINDEX;
    pfd.cColorBits = 8;	// assume 8 bits as default  
    value = IupGetAttribute(self,IUP_BUFFER_SIZE);
    if (value && (number = atoi(value)) > 0)
      pfd.cColorBits = number;
  }

  /* red, green, blue bits */
  value = IupGetAttribute(self,IUP_RED_SIZE);
  if (value && (number = atoi(value)) > 0)
    pfd.cRedBits = number;
  pfd.cRedShift = 0;
  value = IupGetAttribute(self,IUP_GREEN_SIZE);
  if (value && (number = atoi(value)) > 0)
    pfd.cGreenBits = number;
  pfd.cGreenShift = pfd.cRedBits;
  value = IupGetAttribute(self,IUP_BLUE_SIZE);
  if (value && (number = atoi(value)) > 0)
    pfd.cBlueBits = number;
  pfd.cBlueShift = pfd.cRedBits + pfd.cGreenBits;
  value = IupGetAttribute(self,IUP_ALPHA_SIZE);
  if (value && (number = atoi(value)) > 0)
    pfd.cAlphaBits = number;
  pfd.cAlphaShift = pfd.cRedBits + pfd.cGreenBits + pfd.cBlueBits;

  /* depth and stencil size */
  value = IupGetAttribute(self,IUP_DEPTH_SIZE);
  if (value && (number = atoi(value)) > 0)
    pfd.cDepthBits = number;

  /* stencil */
  value = IupGetAttribute(self,IUP_STENCIL_SIZE);
  if (value && (number = atoi(value)) > 0)
    pfd.cStencilBits = number;

  /* red, green, blue accumulation bits */
  value = IupGetAttribute(self,IUP_ACCUM_RED_SIZE);
  if (value && (number = atoi(value)) > 0)
    pfd.cAccumRedBits = number;
  value = IupGetAttribute(self,IUP_ACCUM_GREEN_SIZE);
  if (value && (number = atoi(value)) > 0)
    pfd.cAccumGreenBits = number;
  value = IupGetAttribute(self,IUP_ACCUM_BLUE_SIZE);
  if (value && (number = atoi(value)) > 0)
    pfd.cAccumBlueBits = number;
  value = IupGetAttribute(self,IUP_ACCUM_ALPHA_SIZE);
  if (value && (number = atoi(value)) > 0)
    pfd.cAccumAlphaBits = number;
  pfd.cAccumBits = pfd.cAccumRedBits + pfd.cAccumGreenBits+
    pfd.cAccumBlueBits + pfd.cAccumAlphaBits;

  /* get a device context */
  d->device = GetDC(hwnd);

  /* choose pixel format */
  if ((pixelFormat = ChoosePixelFormat(d->device, &pfd)) == 0) 
  {
    IupSetAttribute(self, "ERROR", "No appropriate pixel format.");
    fprintf(stderr,"No appropriate pixel format.\n");
    return 0;
  } 
  SetPixelFormat(d->device,pixelFormat,&pfd);

  /* create rendering context */
  if ((d->context = wglCreateContext(d->device)) == NULL)
  {
    IupSetAttribute(self, "ERROR", "Could not create a rendering context.");
    fprintf(stderr,"Could not create a rendering context.\n");
    return 0;
  }

  shared = IupGetAttributeHandle(self, "SHAREDCONTEXT");
  if (shared)
  {
    GLData* d1 = (GLData*)IupGetAttribute(shared,"_IUPGL_DATA");
    wglShareLists(d1->context, d->context);
  }

  DescribePixelFormat(d->device, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &test_pfd);

  value = IupGetAttribute(self,IUP_STEREO);

  if (value && iupStrEqual(value,IUP_YES))
  {
    if (!(test_pfd.dwFlags & PFD_STEREO))
    {
      IupSetAttribute(self, "ERROR", "Stereo not available.");
      fprintf(stderr,"Stereo not available.\n");
      return 0;
    }
  }

  /* create colormap for index mode */
  if (isIndex)
  {
    LOGPALETTE lp = {0x300,1,{255,255,255,PC_NOCOLLAPSE}};
    d->palette = CreatePalette(&lp);
    ResizePalette(d->palette,1<<pfd.cColorBits);
    SelectPalette(d->device,d->palette,FALSE);
    RealizePalette(d->device);
  }

  return 1;
}
Exemple #18
0
static int winCanvasMapMethod(Ihandle* ih)
{
  CLIENTCREATESTRUCT clientstruct;
  void *clientdata = NULL;
  char *classname;
  DWORD dwStyle = WS_CHILD|WS_CLIPSIBLINGS, 
      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 */
    iupwinGetNativeParentStyle(ih, &dwExStyle, &dwStyle);

  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;
                           
  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";
    dwStyle = WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|MDIS_ALLCHILDSTYLES;
    dwExStyle = WS_EX_CLIENTEDGE;

    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_MDI_FIRSTCHILD;
  }
  else 
    classname = "IupCanvas";

  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. */
  iupwinHandleAdd(ih, ih->handle);

  if (iupAttribGetBoolean(ih, "MDICLIENT"))  
    iupwinChangeProc(ih, iupwinBaseWinProc);
  else
    IupSetCallback(ih, "_IUPWIN_OLDPROC_CB", (Icallback)DefWindowProc);

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

  /* configure for DROP of files */
  if (IupGetCallback(ih, "DROPFILES_CB"))
    iupAttribSetStr(ih, "DROPFILESTARGET", "YES");

  return IUP_NOERROR;
}
static int wGLCreateContext(Ihandle* ih, IGlControlData* gldata)
{
  Ihandle* ih_shared;
  HGLRC shared_context = NULL;
  int number;
  int isIndex = 0;
  int pixelFormat;
  PIXELFORMATDESCRIPTOR test_pfd;
  PIXELFORMATDESCRIPTOR pfd = { 
    sizeof(PIXELFORMATDESCRIPTOR),  /*  size of this pfd   */
      1,                     /* version number             */
      PFD_DRAW_TO_WINDOW |   /* support window             */
      PFD_SUPPORT_OPENGL,    /* support OpenGL             */
      PFD_TYPE_RGBA,         /* RGBA type                  */
      24,                    /* 24-bit color depth         */
      0, 0, 0, 0, 0, 0,      /* color bits ignored         */
      0,                     /* no alpha buffer            */
      0,                     /* shift bit ignored          */
      0,                     /* no accumulation buffer     */
      0, 0, 0, 0,            /* accum bits ignored         */
      16,                    /* 32-bit z-buffer             */
      0,                     /* no stencil buffer          */
      0,                     /* no auxiliary buffer        */
      PFD_MAIN_PLANE,        /* main layer                 */
      0,                     /* reserved                   */
      0, 0, 0                /* layer masks ignored        */
  };

  /* the IupCanvas is already mapped, just initialize the OpenGL context */

  /* double or single buffer */
  if (iupStrEqualNoCase(iupAttribGetStr(ih,"BUFFER"), "DOUBLE"))
    pfd.dwFlags |= PFD_DOUBLEBUFFER;

  /* stereo */
  if (iupAttribGetBoolean(ih,"STEREO"))
    pfd.dwFlags |= PFD_STEREO;

  /* rgba or index */ 
  if (iupStrEqualNoCase(iupAttribGetStr(ih,"COLOR"), "INDEX"))
  {
    isIndex = 1;
    pfd.iPixelType = PFD_TYPE_COLORINDEX;
    pfd.cColorBits = 8;  /* assume 8 bits when indexed */
    number = iupAttribGetInt(ih,"BUFFER_SIZE");
    if (number > 0) pfd.cColorBits = (BYTE)number;
  }

  /* red, green, blue bits */
  number = iupAttribGetInt(ih,"RED_SIZE");
  if (number > 0) pfd.cRedBits = (BYTE)number;
  pfd.cRedShift = 0;

  number = iupAttribGetInt(ih,"GREEN_SIZE");
  if (number > 0) pfd.cGreenBits = (BYTE)number;
  pfd.cGreenShift = pfd.cRedBits;

  number = iupAttribGetInt(ih,"BLUE_SIZE");
  if (number > 0) pfd.cBlueBits = (BYTE)number;
  pfd.cBlueShift = pfd.cRedBits + pfd.cGreenBits;

  number = iupAttribGetInt(ih,"ALPHA_SIZE");
  if (number > 0) pfd.cAlphaBits = (BYTE)number;
  pfd.cAlphaShift = pfd.cRedBits + pfd.cGreenBits + pfd.cBlueBits;

  /* depth and stencil size */
  number = iupAttribGetInt(ih,"DEPTH_SIZE");
  if (number > 0) pfd.cDepthBits = (BYTE)number;

  /* stencil */
  number = iupAttribGetInt(ih,"STENCIL_SIZE");
  if (number > 0) pfd.cStencilBits = (BYTE)number;

  /* red, green, blue accumulation bits */
  number = iupAttribGetInt(ih,"ACCUM_RED_SIZE");
  if (number > 0) pfd.cAccumRedBits = (BYTE)number;

  number = iupAttribGetInt(ih,"ACCUM_GREEN_SIZE");
  if (number > 0) pfd.cAccumGreenBits = (BYTE)number;

  number = iupAttribGetInt(ih,"ACCUM_BLUE_SIZE");
  if (number > 0) pfd.cAccumBlueBits = (BYTE)number;

  number = iupAttribGetInt(ih,"ACCUM_ALPHA_SIZE");
  if (number > 0) pfd.cAccumAlphaBits = (BYTE)number;

  pfd.cAccumBits = pfd.cAccumRedBits + pfd.cAccumGreenBits + pfd.cAccumBlueBits + pfd.cAccumAlphaBits;

  /* get a device context */
  {
    LONG style = GetClassLong(gldata->window, GCL_STYLE);
    gldata->is_owned_dc = (int) ((style & CS_OWNDC) || (style & CS_CLASSDC));
  }

  gldata->device = GetDC(gldata->window);
  iupAttribSet(ih, "VISUAL", (char*)gldata->device);

  /* choose pixel format */
  pixelFormat = ChoosePixelFormat(gldata->device, &pfd);
  if (pixelFormat == 0)
  {
    iupAttribSet(ih, "ERROR", "No appropriate pixel format.");
    iupAttribSetStr(ih, "LASTERROR", IupGetGlobal("LASTERROR"));
    return IUP_NOERROR;
  } 
  SetPixelFormat(gldata->device,pixelFormat,&pfd);

  ih_shared = IupGetAttributeHandle(ih, "SHAREDCONTEXT");
  if (ih_shared && IupClassMatch(ih_shared, "glcanvas"))  /* must be an IupGLCanvas */
  {
    IGlControlData* shared_gldata = (IGlControlData*)iupAttribGet(ih_shared, "_IUP_GLCONTROLDATA");
    shared_context = shared_gldata->context;
  }

  /* create rendering context */
  if (iupAttribGetBoolean(ih, "ARBCONTEXT"))
  {
    wglCreateContextAttribsARB_PROC CreateContextAttribsARB;
    HGLRC tempContext = wglCreateContext(gldata->device);
    HGLRC oldContext = wglGetCurrentContext();
    HDC oldDC = wglGetCurrentDC();
    wglMakeCurrent(gldata->device, tempContext);   /* wglGetProcAddress only works with an active context */

    CreateContextAttribsARB = (wglCreateContextAttribsARB_PROC)wglGetProcAddress("wglCreateContextAttribsARB");
    if (CreateContextAttribsARB)
    {
      int attribs[9], a = 0;
      char* value;

      value = iupAttribGetStr(ih, "CONTEXTVERSION");
      if (value)
      {
        int major, minor;
        if (iupStrToIntInt(value, &major, &minor, '.') == 2)
        {
          attribs[a++] = WGL_CONTEXT_MAJOR_VERSION_ARB;
          attribs[a++] = major;
          attribs[a++] = WGL_CONTEXT_MINOR_VERSION_ARB;
          attribs[a++] = minor;
        }
      }

      value = iupAttribGetStr(ih, "CONTEXTFLAGS");
      if (value)
      {
        int flags = 0;
        if (iupStrEqualNoCase(value, "DEBUG"))
          flags = WGL_CONTEXT_DEBUG_BIT_ARB;
        else if (iupStrEqualNoCase(value, "FORWARDCOMPATIBLE"))
          flags = WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
        else if (iupStrEqualNoCase(value, "DEBUGFORWARDCOMPATIBLE"))
          flags = WGL_CONTEXT_DEBUG_BIT_ARB|WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
        if (flags)
        {
          attribs[a++] = WGL_CONTEXT_FLAGS_ARB;
          attribs[a++] = flags;
        }
      }

      value = iupAttribGetStr(ih, "CONTEXTPROFILE");
      if (value)
      {
        int profile = 0;
        if (iupStrEqualNoCase(value, "CORE"))
          profile = WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
        else if (iupStrEqualNoCase(value, "COMPATIBILITY"))
          profile = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
        else if (iupStrEqualNoCase(value, "CORECOMPATIBILITY"))
          profile = WGL_CONTEXT_CORE_PROFILE_BIT_ARB|WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
        if (profile)
        {
          attribs[a++] = WGL_CONTEXT_PROFILE_MASK_ARB;
          attribs[a++] = profile;
        }
      }

      attribs[a] = 0; /* terminator */

      gldata->context = CreateContextAttribsARB(gldata->device, shared_context, attribs);
      if (!gldata->context)
      {
        DWORD error = GetLastError();
        if (error == ERROR_INVALID_VERSION_ARB)
          iupAttribSetStr(ih, "LASTERROR", "Invalid ARB Version");
        else if (error == ERROR_INVALID_PROFILE_ARB)
          iupAttribSetStr(ih, "LASTERROR", "Invalid ARGB Profile");
        else
          iupAttribSetStr(ih, "LASTERROR", IupGetGlobal("LASTERROR"));

        iupAttribSet(ih, "ERROR", "Could not create a rendering context.");

        wglMakeCurrent(oldDC, oldContext);
        wglDeleteContext(tempContext);

        return IUP_NOERROR;
      }
    }

    wglMakeCurrent(oldDC, oldContext);
    wglDeleteContext(tempContext);

    if (!CreateContextAttribsARB)
    {
      gldata->context = wglCreateContext(gldata->device);
      iupAttribSet(ih, "ARBCONTEXT", "NO");
    }
  }
  else
    gldata->context = wglCreateContext(gldata->device);

  if (!gldata->context)
  {
    iupAttribSet(ih, "ERROR", "Could not create a rendering context.");
    iupAttribSetStr(ih, "LASTERROR", IupGetGlobal("LASTERROR"));
    return IUP_NOERROR;
  }

  iupAttribSet(ih, "CONTEXT", (char*)gldata->context);

  if (shared_context)
    wglShareLists(shared_context, gldata->context);

  /* create colormap for index mode */
  if (isIndex)
  {
    if (!gldata->palette)
    {
      LOGPALETTE lp = {0x300,1,{255,255,255,PC_NOCOLLAPSE}};  /* set first color as white */
      gldata->palette = CreatePalette(&lp);
      ResizePalette(gldata->palette,1<<pfd.cColorBits);
      iupAttribSet(ih, "COLORMAP", (char*)gldata->palette);
    }

    SelectPalette(gldata->device,gldata->palette,FALSE);
    RealizePalette(gldata->device);
  }

  DescribePixelFormat(gldata->device, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &test_pfd);
  if ((pfd.dwFlags & PFD_STEREO) && !(test_pfd.dwFlags & PFD_STEREO))
  {
    iupAttribSet(ih, "STEREO", "NO");
    return IUP_NOERROR;
  }

  iupAttribSet(ih, "ERROR", NULL);
  return IUP_NOERROR;
}
static int winCanvasMapMethod(Ihandle* ih)
{
  CLIENTCREATESTRUCT clientstruct;
  void *clientdata = NULL;
  TCHAR *classname;
  DWORD dwStyle = WS_CHILD|WS_CLIPSIBLINGS, 
      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 */
    iupwinGetNativeParentStyle(ih, &dwExStyle, &dwStyle);

  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;
                           
  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 = TEXT("mdiclient");
    dwStyle = WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|MDIS_ALLCHILDSTYLES;
    dwExStyle = WS_EX_CLIENTEDGE;

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

    iupAttribSet(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_MDI_FIRSTCHILD;
  }
  else 
    classname = TEXT("IupCanvas");

  if (!iupwinCreateWindow(ih, classname, dwExStyle, dwStyle, clientdata))
    return IUP_ERROR;

  IupSetCallback(ih, "_IUPWIN_CTRLMSGPROC_CB", (Icallback)winCanvasMsgProc);

  /* configure for DROP of files */
  if (IupGetCallback(ih, "DROPFILES_CB"))
    iupAttribSet(ih, "DROPFILESTARGET", "YES");

  winCanvasSetDXAttrib(ih, NULL);
  winCanvasSetDYAttrib(ih, NULL);

  return IUP_NOERROR;
}
Exemple #21
0
static void iDialogAdjustPos(Ihandle *ih, int *x, int *y)
{
  int cursor_x = 0, cursor_y = 0;
  int screen_width = 0, screen_height = 0;
  int current_x = 0, current_y = 0;
  int parent_x = 0, parent_y = 0;

  /* the dialog is already mapped here */

  if (*x == IUP_CURRENT || *y == IUP_CURRENT)
  {
    /* if first time, there is no current position */
    if (!ih->data->first_show)
    {
      int center = IUP_CENTER;
      InativeHandle* parent = iupDialogGetNativeParent(ih);
      if (parent)
        center = IUP_CENTERPARENT;

      if (*x == IUP_CURRENT) *x = center;
      if (*y == IUP_CURRENT) *y = center;
    }
    else
      iupdrvDialogGetPosition(ih, NULL, &current_x, &current_y);
  }

  if (*x == IUP_CENTER || *y == IUP_CENTER ||
      *x == IUP_RIGHT  || *y == IUP_RIGHT ||
      *x == IUP_CENTERPARENT || *y == IUP_CENTERPARENT)
    iupdrvGetScreenSize(&screen_width, &screen_height);

  if (*x == IUP_CENTERPARENT || *y == IUP_CENTERPARENT)
  {
    InativeHandle* parent = iupDialogGetNativeParent(ih);
    if (parent)
    {
      Ihandle* ih_parent = IupGetAttributeHandle(ih, "PARENTDIALOG");

      iupdrvDialogGetPosition(ih_parent, parent, &parent_x, &parent_y);

      if (*x == IUP_CENTERPARENT && *y == IUP_CENTERPARENT)
        iupdrvDialogGetSize(ih_parent, parent, &screen_width, &screen_height);
      else if (*x == IUP_CENTERPARENT)
        iupdrvDialogGetSize(ih_parent, parent, &screen_width, NULL);
      else if (*y == IUP_CENTERPARENT)
        iupdrvDialogGetSize(ih_parent, parent, NULL, &screen_height);
    }
  }

  if (*x == IUP_MOUSEPOS || *y == IUP_MOUSEPOS)
    iupdrvGetCursorPos(&cursor_x, &cursor_y);

  if (iupAttribGetBoolean(ih, "MDICHILD"))
  {
    Ihandle* client = (Ihandle*)iupAttribGet(ih, "MDICLIENT_HANDLE");
    if (client)
    {
      /* position is relative to mdi client */
      parent_x = 0; 
      parent_y = 0;

      /* screen size is now the size of the mdi client */
      screen_width = client->currentwidth;
      screen_height = client->currentheight;

      iupdrvScreenToClient(client, &current_x, &current_y);
      iupdrvScreenToClient(client, &cursor_x, &cursor_y);
    }
  }

  switch (*x)
  {
  case IUP_CENTERPARENT:
    *x = (screen_width - ih->currentwidth)/2 + parent_x;
    break;
  case IUP_CENTER:
    *x = (screen_width - ih->currentwidth)/2;
    break;
  case IUP_LEFT:
    *x = 0;
    break;
  case IUP_RIGHT:
    *x = screen_width - ih->currentwidth;
    break;
  case IUP_MOUSEPOS:
    *x = cursor_x;
    break;
  case IUP_CURRENT:
    *x = current_x;
    break;
  }

  switch (*y)
  {
  case IUP_CENTERPARENT:
    *y = (screen_height - ih->currentheight)/2 + parent_y;
    break;
  case IUP_CENTER:
    *y = (screen_height - ih->currentheight)/2;
    break;
  case IUP_LEFT:
    *y = 0;
    break;
  case IUP_RIGHT:
    *y = screen_height - ih->currentheight;
    break;
  case IUP_MOUSEPOS:
    *y = cursor_y;
    break;
  case IUP_CURRENT:
    *y = current_y;
    break;
  }

  iupdrvAddScreenOffset(x, y, 1);
}
Exemple #22
0
int iupKeyProcessNavigation(Ihandle* ih, int key, int shift)
{
  /* this is called after K_ANY is processed, 
     so the user may change its behavior */

  if (key == K_cTAB)
  {
    int is_multiline = (iupStrEqual(ih->iclass->name, "multiline") || 
                        (iupStrEqual(ih->iclass->name, "text") && IupGetInt(ih, "MULTILINE")));
    if (is_multiline)
    {
      if (shift)
        IupPreviousField(ih);
      else
        IupNextField(ih);
      return 0;   /* abort default processing */
    }
  }
  else if (key == K_TAB || key == K_sTAB)
  {
    int is_multiline = (iupStrEqual(ih->iclass->name, "multiline") || 
                        (iupStrEqual(ih->iclass->name, "text") && IupGetInt(ih, "MULTILINE")));
    if (!is_multiline)
    {
      if (key == K_sTAB)
        IupPreviousField(ih);
      else
        IupNextField(ih);
      return 0;   /* abort default processing */
    }
  }
  else if (key == K_UP || key == K_DOWN)
  {
    int is_button = (iupStrEqual(ih->iclass->name, "button") || 
                     iupStrEqual(ih->iclass->name, "toggle"));
    if (is_button)
    {
      if (key == K_UP)
        iupFocusPrevious(ih);
      else
        iupFocusNext(ih);
      return 0;   /* abort default processing */
    }
  }
  else if (key==K_ESC)
  {
    Ihandle* bt = IupGetAttributeHandle(IupGetDialog(ih), "DEFAULTESC");
    if (iupObjectCheck(bt) && iupStrEqual(bt->iclass->name, "button"))
      iupdrvActivate(bt);
    return 0;   /* abort default processing */
  }
  else if (key==K_CR || key==K_cCR)
  {
    int is_multiline = (iupStrEqual(ih->iclass->name, "multiline") || 
                        (iupStrEqual(ih->iclass->name, "text") && IupGetInt(ih, "MULTILINE")));

    if ((key==K_CR && !is_multiline) || (key==K_cCR && is_multiline))
    {
      Ihandle* bt = IupGetAttributeHandle(IupGetDialog(ih), "DEFAULTENTER");
      if (iupObjectCheck(bt) && iupStrEqual(bt->iclass->name, "button"))
        iupdrvActivate(bt);
      return 0;   /* abort default processing */
    }
  }

  return 1;
}