Пример #1
0
void IupSetAttributeHandle(Ihandle *ih, const char* name, Ihandle *ih_named)
{
  int inherit;
  char* handle_name;

  iupASSERT(name!=NULL);
  if (!name)
    return;

  handle_name = IupGetName(ih_named);
  if (!handle_name)
  {
    iupAttribSetHandleName(ih_named);
    handle_name = IupGetName(ih_named);
  }

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

    iupClassObjectSetAttribute(ih, name, handle_name, &inherit);
    iupAttribStoreStr(ih, name, handle_name);
  }
  else
    IupStoreGlobal(name, handle_name);
}
Пример #2
0
static int iFlatButtonMapMethod(Ihandle* ih)
{
  if (iupAttribGetBoolean(ih, "TOGGLE"))
  {
    Ihandle* radio = iupRadioFindToggleParent(ih);
    if (radio)
    {
      if (!iupAttribGet(radio, "_IUP_FLATBUTTON_LASTRADIO"))
      {
        /* this is the first toggle in the radio, and then set it with VALUE=ON */
        iupAttribSet(ih, "VALUE", "ON");
      }

      /* make sure it has at least one name */
      if (!iupAttribGetHandleName(ih))
        iupAttribSetHandleName(ih);
    }
  }
  return IUP_NOERROR;
}
Пример #3
0
static void iColorDrawTransparentRectangle(Ihandle* color_cnv, int xmin, int ymin, int xmax, int ymax, long color)
{
  if (iupDrawAlpha(color) == 255)
  {
    iupDrawSetColor(color_cnv, "DRAWCOLOR", color);
    IupDrawRectangle(color_cnv, xmin, ymin, xmax, ymax);
  }
  else
  {
    int w = xmax - xmin + 1;
    int h = ymax - ymin + 1;
    Ihandle* image = IupImageRGBA(w,h,NULL);
    unsigned char *colors = (unsigned char*)iupAttribGet(image, "WID");
    int x, y;
    unsigned char red = iupDrawRed(color);
    unsigned char green = iupDrawGreen(color);
    unsigned char blue = iupDrawBlue(color);
    unsigned char alpha = iupDrawAlpha(color);

    for (y = 0; y < h; y++)
    {
      for (x = 0; x < w; x++)
      {
        colors[0] = red;
        colors[1] = green;
        colors[2] = blue;
        colors[3] = alpha;

        colors += 4;
      }
    }

    iupAttribSetHandleName(image);
    IupDrawImage(color_cnv, iupAttribGetHandleName(image), xmin, ymin, -1, -1);

    IupDestroy(image);
  }
}
Пример #4
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;
}
Пример #5
0
static int gtkToggleMapMethod(Ihandle* ih)
{
  Ihandle* radio = iupRadioFindToggleParent(ih);
  char *value;
  int is3state = 0;

  if (!ih->parent)
    return IUP_ERROR;

  value = iupAttribGet(ih, "IMAGE");
  if (value)
    ih->data->type = IUP_TOGGLE_IMAGE;
  else
    ih->data->type = IUP_TOGGLE_TEXT;

  if (radio)
  {
    GtkRadioButton* last_tg = (GtkRadioButton*)iupAttribGet(radio, "_IUPGTK_LASTRADIOBUTTON");
    if (last_tg)
      ih->handle = gtk_radio_button_new_from_widget(last_tg);
    else
      ih->handle = gtk_radio_button_new(NULL);
    iupAttribSet(radio, "_IUPGTK_LASTRADIOBUTTON", (char*)ih->handle);

    /* make sure it has at least one name */
    if (!iupAttribGetHandleName(ih))
      iupAttribSetHandleName(ih);

    ih->data->is_radio = 1;
  }
  else
  {
    if (ih->data->type == IUP_TOGGLE_TEXT)
    {
      ih->handle = gtk_check_button_new();

      if (iupAttribGetBoolean(ih, "3STATE"))
        is3state = 1;
    }
    else
      ih->handle = gtk_toggle_button_new();
  }

  if (!ih->handle)
    return IUP_ERROR;

  if (ih->data->type == IUP_TOGGLE_TEXT)
  {
    gtk_button_set_image((GtkButton*)ih->handle, gtk_label_new(NULL));
    gtk_toggle_button_set_mode((GtkToggleButton*)ih->handle, TRUE);
  }
  else
  {
    gtk_button_set_image((GtkButton*)ih->handle, gtk_image_new());
    gtk_toggle_button_set_mode((GtkToggleButton*)ih->handle, FALSE);
  }

  iupgtkClearSizeStyleCSS(ih->handle);

  /* add to the parent, all GTK controls must call this. */
  iupgtkAddToParent(ih);

  if (!iupAttribGetBoolean(ih, "CANFOCUS"))
    iupgtkSetCanFocus(ih->handle, 0);

  if (ih->data->type == IUP_TOGGLE_IMAGE && ih->data->flat)
  {
    gtk_button_set_relief((GtkButton*)ih->handle, GTK_RELIEF_NONE);

    g_signal_connect(G_OBJECT(ih->handle), "enter-notify-event", G_CALLBACK(gtkToggleEnterLeaveEvent), ih);
    g_signal_connect(G_OBJECT(ih->handle), "leave-notify-event", G_CALLBACK(gtkToggleEnterLeaveEvent), ih);
  }
  else
  {
    g_signal_connect(G_OBJECT(ih->handle), "enter-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih);
    g_signal_connect(G_OBJECT(ih->handle), "leave-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih);
  }

  g_signal_connect(G_OBJECT(ih->handle), "focus-in-event",     G_CALLBACK(iupgtkFocusInOutEvent), ih);
  g_signal_connect(G_OBJECT(ih->handle), "focus-out-event",    G_CALLBACK(iupgtkFocusInOutEvent), ih);
  g_signal_connect(G_OBJECT(ih->handle), "key-press-event",    G_CALLBACK(iupgtkKeyPressEvent), ih);
  g_signal_connect(G_OBJECT(ih->handle), "show-help",          G_CALLBACK(iupgtkShowHelp), ih);

  g_signal_connect(G_OBJECT(ih->handle), "toggled",            G_CALLBACK(gtkToggleToggled), ih);

  if (ih->data->type == IUP_TOGGLE_IMAGE || is3state)
  {
    g_signal_connect(G_OBJECT(ih->handle), "button-press-event",  G_CALLBACK(gtkToggleButtonEvent), ih);
    g_signal_connect(G_OBJECT(ih->handle), "button-release-event",G_CALLBACK(gtkToggleButtonEvent), ih);
  }

  if (is3state)
  {
    g_signal_connect(G_OBJECT(ih->handle), "key-press-event",  G_CALLBACK(gtkToggleKeyEvent), ih);
    g_signal_connect(G_OBJECT(ih->handle), "key-release-event",  G_CALLBACK(gtkToggleKeyEvent), ih);
  }

  gtk_widget_realize(ih->handle);

  /* update a mnemonic in a label if necessary */
  iupgtkUpdateMnemonic(ih);

  return IUP_NOERROR;
}
Пример #6
0
static void motTabsChildAddedMethod(Ihandle* ih, Ihandle* child)
{
  if (IupGetName(child) == NULL)
    iupAttribSetHandleName(child);

  if (ih->handle)
  {
    Widget child_manager;
    Widget tab_button;
    int num_args = 0, pos;
    Arg args[30];
    char *tabtitle, *tabimage, *background;
    Pixel color;

    /* open space for new tab number */
    motTabsUpdatePageNumber(ih);

    pos = IupGetChildPos(ih, child);

    /* Create pages */
    child_manager = XtVaCreateManagedWidget(
                    "child_manager",
                    xmBulletinBoardWidgetClass,
                    ih->handle,
                    /* Core */
                    XmNborderWidth, 0,
                    /* Manager */
                    XmNshadowThickness, 0,
                    XmNnavigationType, XmTAB_GROUP,
                    XmNuserData, child, /* used only in motTabsConfigureNotify  */
                    /* BulletinBoard */
                    XmNmarginWidth, 0,
                    XmNmarginHeight, 0,
                    XmNresizePolicy, XmRESIZE_NONE, /* no automatic resize of children */
                    /* Notebook Constraint */
                    XmNnotebookChildType, XmPAGE,
                    XmNpageNumber, pos,
                    XmNresizable, True,
                    NULL);   

    XtOverrideTranslations(child_manager, XtParseTranslationTable("<Configure>: iupTabsConfigure()"));

    tabtitle = iupAttribGet(child, "TABTITLE");
    if (!tabtitle) tabtitle = iupTabsAttribGetStrId(ih, "TABTITLE", pos);
    tabimage = iupAttribGet(child, "TABIMAGE");
    if (!tabimage) tabimage = iupTabsAttribGetStrId(ih, "TABIMAGE", pos);
    if (!tabtitle && !tabimage)
      tabtitle = "     ";

    /* Create tabs */
    /* Label */
    iupmotSetArg(args[num_args++], XmNlabelType, tabtitle? XmSTRING: XmPIXMAP);
    iupmotSetArg(args[num_args++], XmNmarginHeight, 0);
    iupmotSetArg(args[num_args++], XmNmarginWidth, 0);
    /* Notebook Constraint */
    iupmotSetArg(args[num_args++], XmNnotebookChildType, XmMAJOR_TAB);
    iupmotSetArg(args[num_args++], XmNpageNumber, pos);
    tab_button = XtCreateManagedWidget("tab_button", xmPushButtonWidgetClass, ih->handle, args, num_args);

    /* Disable Drag Source */
    iupmotDisableDragSource(tab_button);

    XtAddEventHandler(tab_button, EnterWindowMask, False, (XtEventHandler)iupmotEnterLeaveWindowEvent, (XtPointer)ih);
    XtAddEventHandler(tab_button, LeaveWindowMask, False, (XtEventHandler)iupmotEnterLeaveWindowEvent, (XtPointer)ih);
    XtAddEventHandler(tab_button, FocusChangeMask, False, (XtEventHandler)iupmotFocusChangeEvent, (XtPointer)ih);
    XtAddEventHandler(tab_button, KeyPressMask,    False, (XtEventHandler)iupmotKeyPressEvent, (XtPointer)ih);

    if (tabtitle)
      iupmotSetString(tab_button, XmNlabelString, tabtitle);
    else
    {
      Pixmap pixmap = (Pixmap)iupImageGetImage(tabimage, ih, 0, "TABIMAGE");
      if (pixmap)
        XtVaSetValues(tab_button, XmNlabelPixmap, pixmap, NULL);
    }

    background = iupBaseNativeParentGetBgColorAttrib(ih);
    color = iupmotColorGetPixelStr(background);
    if (color != -1)
      iupmotSetBgColor(child_manager, color);
    else
    {
      Pixmap pixmap = (Pixmap)iupImageGetImage(background, ih, 0, "BACKGROUND");
      if (pixmap)
      {
        XtVaSetValues(child_manager, XmNbackgroundPixmap, pixmap, NULL);
      }
    }

    background = iupAttribGetStr(ih, "BGCOLOR");
    color = iupmotColorGetPixelStr(background);
    if (color != -1)
      iupmotSetBgColor(tab_button, color);

    color = iupmotColorGetPixelStr(IupGetAttribute(ih, "FGCOLOR"));
    XtVaSetValues(tab_button, XmNforeground, color, NULL);

    XtRealizeWidget(child_manager);
    XtRealizeWidget(tab_button);

    iupAttribSetStr(child, "_IUPTAB_CONTAINER", (char*)child_manager);
    iupAttribSetStr(child, "_IUPMOT_TABBUTTON", (char*)tab_button);
    iupAttribSetInt(child, "_IUPMOT_TABNUMBER", pos);
  }
}
Пример #7
0
static void gtkTabsChildAddedMethod(Ihandle* ih, Ihandle* child)
{
  if (IupGetName(child) == NULL)
    iupAttribSetHandleName(child);

  if (ih->handle)
  {
    GtkWidget* tab_page;
    GtkWidget *tab_label = NULL, *tab_image = NULL;
    char *tabtitle, *tabimage;
    int pos;
    unsigned char r, g, b;

    pos = IupGetChildPos(ih, child);

    tab_page = gtk_fixed_new();
    gtk_widget_show(tab_page);

    tabtitle = iupAttribGet(child, "TABTITLE");
    if (!tabtitle) tabtitle = iupTabsAttribGetStrId(ih, "TABTITLE", pos);
    tabimage = iupAttribGet(child, "TABIMAGE");
    if (!tabimage) tabimage = iupTabsAttribGetStrId(ih, "TABIMAGE", pos);
    if (!tabtitle && !tabimage)
      tabtitle = "     ";

    if (tabtitle)
    {
      tab_label = gtk_label_new(iupgtkStrConvertToUTF8(tabtitle));

#if GTK_CHECK_VERSION(2, 6, 0)
      if (ih->data->orientation == ITABS_VERTICAL)
        gtk_label_set_angle((GtkLabel*)tab_label, 90);
#endif
    }

    if (tabimage)
    {
      GdkPixbuf* pixbuf = iupImageGetImage(tabimage, ih, 0, "TABIMAGE");

      tab_image = gtk_image_new();

      if (pixbuf)
        gtk_image_set_from_pixbuf((GtkImage*)tab_image, pixbuf);
    }

    iupAttribSetStr(ih, "_IUPGTK_IGNORE_CHANGE", "1");

    if (tabimage && tabtitle)
    {
      GtkWidget* box;
      if (ih->data->orientation == ITABS_VERTICAL)
        box = gtk_vbox_new(FALSE, 2);
      else
        box = gtk_hbox_new(FALSE, 2);
      gtk_widget_show(box);

      gtk_container_add((GtkContainer*)box, tab_image);
      gtk_container_add((GtkContainer*)box, tab_label);

      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, box, pos);
      gtk_notebook_set_menu_label_text((GtkNotebook*)ih->handle, tab_page, gtk_label_get_text((GtkLabel*)tab_label));
    }
    else if (tabimage)
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, tab_image, pos);
    else
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, tab_label, pos);

    gtk_widget_realize(tab_page);

    iupAttribSetStr(child, "_IUPGTK_TABIMAGE", (char*)tab_image);  /* store it even if its NULL */
    iupAttribSetStr(child, "_IUPGTK_TABLABEL", (char*)tab_label);
    iupAttribSetStr(child, "_IUPTAB_CONTAINER", (char*)tab_page);
    iupStrToRGB(IupGetAttribute(ih, "BGCOLOR"), &r, &g, &b);
    iupgtkBaseSetBgColor(tab_page, r, g, b);

    if (tabtitle)
    {
      PangoFontDescription* fontdesc = (PangoFontDescription*)iupgtkGetPangoFontDescAttrib(ih);
      gtk_widget_modify_font(tab_label, fontdesc);
      iupgtkFontUpdatePangoLayout(ih, gtk_label_get_layout((GtkLabel*)tab_label));

      iupgtkBaseSetBgColor(tab_label, r, g, b);

      iupStrToRGB(IupGetAttribute(ih, "FGCOLOR"), &r, &g, &b);
      iupgtkBaseSetFgColor(tab_label, r, g, b);

      gtk_widget_show(tab_label);
      gtk_widget_realize(tab_label);
    }

    if (tabimage)
    {
      gtk_widget_show(tab_image);
      gtk_widget_realize(tab_image);
    }

    iupAttribSetStr(ih, "_IUPGTK_IGNORE_CHANGE", NULL);
  }
}
Пример #8
0
/* ------------------------------------------------------------------------- */
static void gtkTabsChildAddedMethod(Ihandle* ih, Ihandle* child)
{
  /* make sure it has at least one name */
  if (!iupAttribGetHandleName(child))
    iupAttribSetHandleName(child);

  if (ih->handle)
  {
    GtkWidget *evtBox, *tab_page, *tab_container, *box = NULL;
    GtkWidget *tab_label = NULL, *tab_image = NULL, *tab_close = NULL;
    char *tabtitle, *tabimage;
    int pos;
    unsigned char r, g, b;

    pos = IupGetChildPos(ih, child);

    /* Can not hide the tab_page, 
       or the tab will be automatically hidden.
       So create a secondary container to hide its child instead. */
#if GTK_CHECK_VERSION(3, 0, 0)
    tab_page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
#else
    tab_page = gtk_vbox_new(FALSE, 0);
#endif
    gtk_widget_show(tab_page);

    tab_container = gtk_fixed_new(); /* can not use iupgtkNativeContainerNew in GTK3 */
    gtk_widget_show(tab_container);
    gtk_container_add((GtkContainer*)tab_page, tab_container);

    tabtitle = iupAttribGet(child, "TABTITLE");
    if (!tabtitle)
    {
      tabtitle = iupAttribGetId(ih, "TABTITLE", pos);
      if (tabtitle)
        iupAttribSetStr(child, "TABTITLE", tabtitle);
    }
    tabimage = iupAttribGet(child, "TABIMAGE");
    if (!tabimage)
    {
      tabimage = iupAttribGetId(ih, "TABIMAGE", pos);
      if (tabimage)
        iupAttribSetStr(child, "TABIMAGE", tabimage);
    }
    if (!tabtitle && !tabimage)
      tabtitle = "     ";

    if (tabtitle)
    {
      tab_label = gtk_label_new(NULL);
      iupgtkSetMnemonicTitle(ih, (GtkLabel*)tab_label, tabtitle);

#if GTK_CHECK_VERSION(2, 6, 0)
      if (ih->data->orientation == ITABS_VERTICAL)
        gtk_label_set_angle((GtkLabel*)tab_label, 90);
#endif
    }

    if (tabimage)
    {
      GdkPixbuf* pixbuf = iupImageGetImage(tabimage, ih, 0);

      tab_image = gtk_image_new();

      if (pixbuf)
        gtk_image_set_from_pixbuf((GtkImage*)tab_image, pixbuf);
    }

    if(ih->data->show_close)
    {
#if GTK_CHECK_VERSION(3, 10, 0)
      GtkWidget* image = gtk_image_new_from_icon_name("window-close", GTK_ICON_SIZE_MENU);
#else
      GtkWidget* image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
#endif

      tab_close = gtk_button_new();
      gtk_button_set_image((GtkButton*)tab_close, image);
      gtk_button_set_relief((GtkButton*)tab_close, GTK_RELIEF_NONE);
      gtk_button_set_focus_on_click((GtkButton*)tab_close, FALSE);
      iupgtkSetCanFocus(tab_close, FALSE);

      g_signal_connect(G_OBJECT(tab_close), "clicked", G_CALLBACK(gtkTabsCloseButtonClicked), child);
    }

    iupAttribSet(ih, "_IUPGTK_IGNORE_CHANGE", "1");

    if ((tabimage && tabtitle) || ih->data->show_close)
    { 
#if GTK_CHECK_VERSION(3, 0, 0)
      if (ih->data->orientation == ITABS_VERTICAL)
        box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
      else
        box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
#else
      if (ih->data->orientation == ITABS_VERTICAL)
        box = gtk_vbox_new(FALSE, 2);
      else
        box = gtk_hbox_new(FALSE, 2);
#endif
      gtk_widget_show(box);
    }

    /* RIGHTCLICK_CB will not work without the eventbox */
    evtBox = gtk_event_box_new();
    gtk_widget_add_events(evtBox, GDK_BUTTON_PRESS_MASK);
    g_signal_connect(G_OBJECT(evtBox), "button-press-event", G_CALLBACK(gtkTabsButtonPressEvent), child);

    if (tabimage && tabtitle)
    {
      gtk_container_add((GtkContainer*)box, tab_image);
      gtk_container_add((GtkContainer*)box, tab_label);
      
      if(ih->data->show_close)
        gtk_container_add((GtkContainer*)box, tab_close);

      gtk_container_add((GtkContainer*)evtBox, box);
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos);
      gtk_notebook_set_menu_label_text((GtkNotebook*)ih->handle, tab_page, gtk_label_get_text((GtkLabel*)tab_label));
    }
    else if(tabimage && ih->data->show_close)
    {
      gtk_container_add((GtkContainer*)box, tab_image);
      gtk_container_add((GtkContainer*)box, tab_close);
      gtk_container_add((GtkContainer*)evtBox, box);
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos);
    }
    else if(tabtitle && ih->data->show_close)
    {
      gtk_container_add((GtkContainer*)box, tab_label);
      gtk_container_add((GtkContainer*)box, tab_close);
      gtk_container_add((GtkContainer*)evtBox, box);
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos);
      gtk_notebook_set_menu_label_text((GtkNotebook*)ih->handle, tab_page, gtk_label_get_text((GtkLabel*)tab_label));
    }
    else if (tabimage)
    {
      gtk_container_add((GtkContainer*)evtBox, tab_image);
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos);
    }
    else
    {
      gtk_container_add((GtkContainer*)evtBox, tab_label);
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos);
    }

    gtk_widget_realize(tab_page);

    iupAttribSet(child, "_IUPGTK_TABCLOSE", (char*)tab_close);
    iupAttribSet(child, "_IUPGTK_TABIMAGE", (char*)tab_image);  /* store it even if its NULL */
    iupAttribSet(child, "_IUPGTK_TABLABEL", (char*)tab_label);
    iupAttribSet(child, "_IUPTAB_CONTAINER", (char*)tab_container);
    iupAttribSet(child, "_IUPTAB_PAGE", (char*)tab_page);
    iupStrToRGB(IupGetAttribute(ih, "BGCOLOR"), &r, &g, &b);
    iupgtkSetBgColor(tab_container, r, g, b);

    if (tabtitle)
    {
      iupgtkUpdateWidgetFont(ih, tab_label);

      iupgtkSetBgColor(tab_label, r, g, b);

      iupStrToRGB(IupGetAttribute(ih, "FGCOLOR"), &r, &g, &b);
      iupgtkSetFgColor(tab_label, r, g, b);

      gtk_widget_show(tab_label);
      gtk_widget_realize(tab_label);
    }

    if (tabimage)
    {
      gtk_widget_show(tab_image);
      gtk_widget_realize(tab_image);
    }

    if (ih->data->show_close)
    {
      gtk_widget_show(tab_close);
      gtk_widget_realize(tab_close);
    }

    iupAttribSet(ih, "_IUPGTK_IGNORE_CHANGE", NULL);

    if (pos != iupdrvTabsGetCurrentTab(ih))
      gtk_widget_hide(tab_container);
  }
}
Пример #9
0
static int winToggleMapMethod(Ihandle* ih)
{
  Ihandle* radio = iupRadioFindToggleParent(ih);
  char* value;
  int ownerdraw = 0;
  DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS |
                  BS_NOTIFY; /* necessary because of the base messages */

  if (!ih->parent)
    return IUP_ERROR;

  if (radio)
    ih->data->is_radio = 1;

  value = iupAttribGet(ih, "IMAGE");
  if (value)
  {
    ih->data->type = IUP_TOGGLE_IMAGE;
    if (!iupwin_comctl32ver6 && ih->data->flat)
    {
      dwStyle |= BS_OWNERDRAW;
      ownerdraw = 1;
    }
    else
      dwStyle |= BS_BITMAP|BS_PUSHLIKE;
  }
  else
  {
    ih->data->type = IUP_TOGGLE_TEXT;
    dwStyle |= BS_TEXT|BS_MULTILINE;

    if (iupAttribGetBoolean(ih, "RIGHTBUTTON"))
      dwStyle |= BS_RIGHTBUTTON;
  }

  if (iupAttribGetBoolean(ih, "CANFOCUS"))
    dwStyle |= WS_TABSTOP;

  if (ih->data->is_radio)
  {
    if (!ownerdraw)
      dwStyle |= BS_RADIOBUTTON;

    if (!iupAttribGet(radio, "_IUPWIN_LASTTOGGLE"))
    {
      /* this is the first toggle in the radio, and then set it with VALUE=ON */
      iupAttribSet(ih, "VALUE","ON");
    }

    /* make sure it has at least one name */
    if (!iupAttribGetHandleName(ih))
      iupAttribSetHandleName(ih);
  }
  else if (!ownerdraw)
  {
    if (ih->data->type == IUP_TOGGLE_TEXT && iupAttribGetBoolean(ih, "3STATE"))
      dwStyle |= BS_AUTO3STATE;
    else
      dwStyle |= BS_AUTOCHECKBOX;
  }

  if (!iupwinCreateWindow(ih, WC_BUTTON, 0, dwStyle, NULL))
    return IUP_ERROR;

  /* Process WM_COMMAND */
  IupSetCallback(ih, "_IUPWIN_COMMAND_CB", (Icallback)winToggleWmCommand);

  /* Process background color */
  IupSetCallback(ih, "_IUPWIN_CTLCOLOR_CB", (Icallback)winToggleCtlColor);

  if (ih->data->type == IUP_TOGGLE_IMAGE)
  {
    if (iupwin_comctl32ver6)
    {
      IupSetCallback(ih, "_IUPWIN_NOTIFY_CB", (Icallback)winToggleImageWmNotify);  /* Process WM_NOTIFY */
      if (ih->data->flat)
        IupSetCallback(ih, "_IUPWIN_CTRLMSGPROC_CB", (Icallback)winToggleImageFlatMsgProc);
    }
    else
    {
      if (ih->data->flat)
      {
        iupAttribSet(ih, "FLAT_ALPHA", "NO");
        IupSetCallback(ih, "_IUPWIN_DRAWITEM_CB", (Icallback)winToggleDrawItem);  /* Process WM_DRAWITEM */
        IupSetCallback(ih, "_IUPWIN_CTRLMSGPROC_CB", (Icallback)winToggleImageFlatMsgProc);
      }
      else
      {
        IupSetCallback(ih, "_IUPWIN_CTRLMSGPROC_CB", (Icallback)winToggleImageClassicMsgProc);
        iupAttribSet(ih, "_IUPWIN_ACTIVE", "YES");
      }
    }
  }

  return IUP_NOERROR;
}
Пример #10
0
static void gtkTabsChildAddedMethod(Ihandle* ih, Ihandle* child)
{
  if (IupGetName(child) == NULL)
    iupAttribSetHandleName(child);

  if (ih->handle)
  {
    GtkWidget *tab_page, *tab_container;
    GtkWidget *tab_label = NULL, *tab_image = NULL;
    char *tabtitle, *tabimage;
    int pos;
    unsigned char r, g, b;

    pos = IupGetChildPos(ih, child);

    /* Can not hide the tab_page, 
       or the tab will be automatically hidden.
       So create a secondary container to hide its child instead. */
#if GTK_CHECK_VERSION(3, 0, 0)
    tab_page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
#else
    tab_page = gtk_vbox_new(FALSE, 0);
#endif
    gtk_widget_show(tab_page);

    tab_container = gtk_fixed_new(); /* can not use iupgtkNativeContainerNew in GTK3 */
    gtk_widget_show(tab_container);
    gtk_container_add((GtkContainer*)tab_page, tab_container);

    tabtitle = iupTabsAttribGetStrId(ih, "TABTITLE", pos);
    if (!tabtitle) 
    {
      tabtitle = iupAttribGet(child, "TABTITLE");
      if (tabtitle)
        iupTabsAttribSetStrId(ih, "TABTITLE", pos, tabtitle);
    }
    tabimage = iupTabsAttribGetStrId(ih, "TABIMAGE", pos);
    if (!tabimage) 
    {
      tabimage = iupAttribGet(child, "TABIMAGE");
      if (tabimage)
        iupTabsAttribSetStrId(ih, "TABIMAGE", pos, tabimage);
    }
    if (!tabtitle && !tabimage)
      tabtitle = "     ";

    if (tabtitle)
    {
      tab_label = gtk_label_new(NULL);
      iupgtkSetMnemonicTitle(ih, (GtkLabel*)tab_label, tabtitle);

#if GTK_CHECK_VERSION(2, 6, 0)
      if (ih->data->orientation == ITABS_VERTICAL)
        gtk_label_set_angle((GtkLabel*)tab_label, 90);
#endif
    }

    if (tabimage)
    {
      GdkPixbuf* pixbuf = iupImageGetImage(tabimage, ih, 0);

      tab_image = gtk_image_new();

      if (pixbuf)
        gtk_image_set_from_pixbuf((GtkImage*)tab_image, pixbuf);
    }

    iupAttribSetStr(ih, "_IUPGTK_IGNORE_CHANGE", "1");

    if (tabimage && tabtitle)
    {
      GtkWidget* box;
#if GTK_CHECK_VERSION(3, 0, 0)
      if (ih->data->orientation == ITABS_VERTICAL)
        box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
      else
        box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
#else
      if (ih->data->orientation == ITABS_VERTICAL)
        box = gtk_vbox_new(FALSE, 2);
      else
        box = gtk_hbox_new(FALSE, 2);
#endif
      gtk_widget_show(box);

      gtk_container_add((GtkContainer*)box, tab_image);
      gtk_container_add((GtkContainer*)box, tab_label);

      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, box, pos);
      gtk_notebook_set_menu_label_text((GtkNotebook*)ih->handle, tab_page, gtk_label_get_text((GtkLabel*)tab_label));
    }
    else if (tabimage)
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, tab_image, pos);
    else
      gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, tab_label, pos);

    gtk_widget_realize(tab_page);

    iupAttribSetStr(child, "_IUPGTK_TABIMAGE", (char*)tab_image);  /* store it even if its NULL */
    iupAttribSetStr(child, "_IUPGTK_TABLABEL", (char*)tab_label);
    iupAttribSetStr(child, "_IUPTAB_CONTAINER", (char*)tab_container);
    iupAttribSetStr(child, "_IUPTAB_PAGE", (char*)tab_page);
    iupStrToRGB(IupGetAttribute(ih, "BGCOLOR"), &r, &g, &b);
    iupgtkSetBgColor(tab_container, r, g, b);

    if (tabtitle)
    {
      PangoFontDescription* fontdesc = (PangoFontDescription*)iupgtkGetPangoFontDescAttrib(ih);
#if GTK_CHECK_VERSION(3, 0, 0)
      gtk_widget_override_font(tab_label, fontdesc);
#else
      gtk_widget_modify_font(tab_label, fontdesc);
#endif
      iupgtkFontUpdatePangoLayout(ih, gtk_label_get_layout((GtkLabel*)tab_label));

      iupgtkSetBgColor(tab_label, r, g, b);

      iupStrToRGB(IupGetAttribute(ih, "FGCOLOR"), &r, &g, &b);
      iupgtkSetFgColor(tab_label, r, g, b);

      gtk_widget_show(tab_label);
      gtk_widget_realize(tab_label);
    }

    if (tabimage)
    {
      gtk_widget_show(tab_image);
      gtk_widget_realize(tab_image);
    }

    iupAttribSetStr(ih, "_IUPGTK_IGNORE_CHANGE", NULL);

    if (pos != iupdrvTabsGetCurrentTab(ih))
      gtk_widget_hide(tab_container);
  }
}
Пример #11
0
static void winTabsChildAddedMethod(Ihandle* ih, Ihandle* child)
{
  if (IupGetName(child) == NULL)
    iupAttribSetHandleName(child);

  if (ih->handle)
  {
    TCITEM tie;
    HWND tab_page;
    char *tabtitle, *tabimage;
    int pos, old_rowcount;
    RECT rect; 

    pos = IupGetChildPos(ih, child);

    tab_page = winTabCreatePageWindow(ih);

    if (pos == 0)
      ShowWindow(tab_page, SW_SHOW);

    tabtitle = iupAttribGet(child, "TABTITLE");
    if (!tabtitle) tabtitle = iupTabsAttribGetStrId(ih, "TABTITLE", pos);
    tabimage = iupAttribGet(child, "TABIMAGE");
    if (!tabimage) tabimage = iupTabsAttribGetStrId(ih, "TABIMAGE", pos);
    if (!tabtitle && !tabimage)
      tabtitle = "     ";

    old_rowcount = (int)SendMessage(ih->handle, TCM_GETROWCOUNT, 0, 0);

    tie.mask = TCIF_PARAM;

    if (tabtitle)
    {
      tie.mask |= TCIF_TEXT;
      tie.pszText = tabtitle;
      tie.cchTextMax = strlen(tabtitle);
    }

    if (tabimage)
    {
      tie.mask |= TCIF_IMAGE;
      tie.iImage = winTabsGetImageIndex(ih, tabimage);
    }

    /* create tabs and label them */
    tie.lParam = (LPARAM)tab_page;
    SendMessage(ih->handle, TCM_INSERTITEM, pos, (LPARAM)&tie);

    /* Calculate the display rectangle, assuming the 
       tab control is the size of the client area. */
    GetClientRect(ih->handle, &rect);
    SendMessage(ih->handle, TCM_ADJUSTRECT, FALSE, (LPARAM)&rect);

    SetWindowPos(tab_page, NULL, 
                 rect.left, rect.top,  
                 rect.right - rect.left, rect.bottom - rect.top, 
                 SWP_NOACTIVATE|SWP_NOZORDER);

    iupAttribSetStr(child, "_IUPTAB_CONTAINER", (char*)tab_page);

    if (ih->data->is_multiline)
    {
      if (ih->data->type == ITABS_LEFT || ih->data->type == ITABS_RIGHT)
      {
        int rowcount = (int)SendMessage(ih->handle, TCM_GETROWCOUNT, 0, 0);
        if (rowcount != old_rowcount)
        {
          GetClientRect(ih->handle, &rect);
          winTabsPlacePageWindows(ih, rect.right - rect.left, rect.bottom - rect.top);
        }
      }

      iupdrvDisplayRedraw(ih);
    }
  }
}
Пример #12
0
static int motToggleMapMethod(Ihandle* ih)
{
    Ihandle* radio = iupRadioFindToggleParent(ih);
    char* value;
    int num_args = 0;
    Arg args[40];

    if (radio)
        ih->data->is_radio = 1;

    value = iupAttribGet(ih, "IMAGE");
    if (value)
    {
        ih->data->type = IUP_TOGGLE_IMAGE;
        iupMOT_SETARG(args, num_args, XmNlabelType, XmPIXMAP);
    }
    else
    {
        ih->data->type = IUP_TOGGLE_TEXT;
        iupMOT_SETARG(args, num_args, XmNlabelType, XmSTRING);
    }

    /* Core */
    iupMOT_SETARG(args, num_args, XmNmappedWhenManaged, False);  /* not visible when managed */
    iupMOT_SETARG(args, num_args, XmNx, 0);  /* x-position */
    iupMOT_SETARG(args, num_args, XmNy, 0);  /* y-position */
    iupMOT_SETARG(args, num_args, XmNwidth, 10);  /* default width to avoid 0 */
    iupMOT_SETARG(args, num_args, XmNheight, 10); /* default height to avoid 0 */
    /* Primitive */
    if (iupAttribGetBoolean(ih, "CANFOCUS"))
        iupMOT_SETARG(args, num_args, XmNtraversalOn, True);
    else
        iupMOT_SETARG(args, num_args, XmNtraversalOn, False);
    iupMOT_SETARG(args, num_args, XmNhighlightThickness, 2);
    iupMOT_SETARG(args, num_args, XmNnavigationType, XmTAB_GROUP);
    /* Label */
    iupMOT_SETARG(args, num_args, XmNrecomputeSize, False);  /* no automatic resize from text */
    iupMOT_SETARG(args, num_args, XmNmarginHeight, 0);  /* default padding */
    iupMOT_SETARG(args, num_args, XmNmarginWidth, 0);
    iupMOT_SETARG(args, num_args, XmNmarginTop, 0);     /* no extra margins */
    iupMOT_SETARG(args, num_args, XmNmarginLeft, 0);
    iupMOT_SETARG(args, num_args, XmNmarginBottom, 0);
    iupMOT_SETARG(args, num_args, XmNmarginRight, 0);

    if (ih->data->is_radio)
    {
        iupMOT_SETARG(args, num_args, XmNtoggleMode, XmTOGGLE_BOOLEAN);
        iupMOT_SETARG(args, num_args, XmNindicatorType, XmONE_OF_MANY_ROUND);

        if (!iupAttribGet(radio, "_IUPMOT_LASTTOGGLE"))
        {
            /* this is the first toggle in the radio, and the last toggle with VALUE=ON */
            iupAttribSet(ih, "VALUE","ON");
        }

        /* make sure it has at least one name */
        if (!iupAttribGetHandleName(ih))
            iupAttribSetHandleName(ih);
    }
    else
    {
        if (ih->data->type == IUP_TOGGLE_TEXT && iupAttribGetBoolean(ih, "3STATE"))
            iupMOT_SETARG(args, num_args, XmNtoggleMode, XmTOGGLE_INDETERMINATE);
        else
            iupMOT_SETARG(args, num_args, XmNtoggleMode, XmTOGGLE_BOOLEAN);
        iupMOT_SETARG(args, num_args, XmNindicatorType, XmN_OF_MANY);
    }

    if (ih->data->type == IUP_TOGGLE_IMAGE)
    {
        iupMOT_SETARG(args, num_args, XmNindicatorOn, XmINDICATOR_NONE);
        iupMOT_SETARG(args, num_args, XmNalignment, XmALIGNMENT_CENTER);
        iupMOT_SETARG(args, num_args, XmNshadowThickness, 2);
    }
    else
    {
        iupMOT_SETARG(args, num_args, XmNspacing, 3);
        iupMOT_SETARG(args, num_args, XmNindicatorOn, XmINDICATOR_CHECK_BOX);
        iupMOT_SETARG(args, num_args, XmNalignment, XmALIGNMENT_BEGINNING);

        if (ih->data->is_radio)
        {
            iupMOT_SETARG(args, num_args, XmNindicatorSize, 13);
            iupMOT_SETARG(args, num_args, XmNselectColor, iupmotColorGetPixel(0, 0, 0));
        }
        else
            iupMOT_SETARG(args, num_args, XmNindicatorSize, 15);

        iupMOT_SETARG(args, num_args, XmNshadowThickness, 0);
        iupMOT_SETARG(args, num_args, XmNdetailShadowThickness, 2);
    }

    ih->handle = XtCreateManagedWidget(
                     iupDialogGetChildIdStr(ih),  /* child identifier */
                     xmToggleButtonWidgetClass,     /* widget class */
                     iupChildTreeGetNativeParentHandle(ih), /* widget parent */
                     args, num_args);

    if (!ih->handle)
        return IUP_ERROR;

    ih->serial = iupDialogGetChildId(ih); /* must be after using the string */

    XtAddCallback(ih->handle, XmNhelpCallback, (XtCallbackProc)iupmotHelpCallback, (XtPointer)ih);

    if (ih->data->type == IUP_TOGGLE_IMAGE && ih->data->flat)
    {
        XtVaSetValues(ih->handle, XmNshadowThickness, 0, NULL);
        XtAddEventHandler(ih->handle, EnterWindowMask, False, (XtEventHandler)motToggleEnterLeaveWindowEvent, (XtPointer)ih);
        XtAddEventHandler(ih->handle, LeaveWindowMask, False, (XtEventHandler)motToggleEnterLeaveWindowEvent, (XtPointer)ih);
    }
    else
    {
        XtAddEventHandler(ih->handle, EnterWindowMask, False, (XtEventHandler)iupmotEnterLeaveWindowEvent, (XtPointer)ih);
        XtAddEventHandler(ih->handle, LeaveWindowMask, False, (XtEventHandler)iupmotEnterLeaveWindowEvent, (XtPointer)ih);
    }

    XtAddEventHandler(ih->handle, FocusChangeMask, False, (XtEventHandler)iupmotFocusChangeEvent, (XtPointer)ih);
    XtAddEventHandler(ih->handle, KeyPressMask,    False, (XtEventHandler)iupmotKeyPressEvent,    (XtPointer)ih);

    XtAddCallback(ih->handle, XmNvalueChangedCallback, (XtCallbackProc)motToggleValueChangedCallback, (XtPointer)ih);

    if (iupStrBoolean(IupGetGlobal("INPUTCALLBACKS")))
        XtAddEventHandler(ih->handle, PointerMotionMask, False, (XtEventHandler)iupmotDummyPointerMotionEvent, NULL);

    /* Disable Drag Source */
    iupmotDisableDragSource(ih->handle);

    /* initialize the widget */
    XtRealizeWidget(ih->handle);

    if (ih->data->type == IUP_TOGGLE_TEXT)
        iupmotSetXmString(ih->handle, XmNlabelString, "");

    return IUP_NOERROR;
}