Esempio n. 1
0
static int iDetachBoxSetRestoreAttrib(Ihandle* ih, const char* value)
{
  Ihandle *dlg = IupGetDialog(ih);
  Ihandle* new_parent = IupGetHandle(value);
  Ihandle* new_brother = NULL;

  if (!new_parent)
  {
    new_parent = ih->data->old_parent;
    new_brother = ih->data->old_brother;

    if (IupGetChildPos(new_parent, new_brother) == -1)  /* not a child of new_parent */
      new_brother = NULL;
  }

  /* Sets the new parent */
  IupReparent(ih, new_parent, new_brother);

  /* Show handler */
  if (ih->data->barsize)
    IupSetAttribute(ih->firstchild, "VISIBLE", "Yes");

  /* Updates/redraws the layout of the dialog */
  IupRefresh(new_parent);

  /* Reset previous parent and brother */
  ih->data->old_parent = NULL;
  ih->data->old_brother = NULL;

  IupDestroy(dlg);
  return 0;
}
Esempio n. 2
0
static int motSubmenuMapMethod(Ihandle* ih)
{
  int pos;

  if (!ih->parent)
    return IUP_ERROR;

#ifndef HILDON
  if (iupMenuIsMenuBar(ih->parent))
    ih->handle = gtk_menu_item_new_with_label("");
  else
#endif
    ih->handle = gtk_image_menu_item_new_with_label("");

  if (!ih->handle)
    return IUP_ERROR;

  ih->serial = iupMenuGetChildId(ih); 

  pos = IupGetChildPos(ih->parent, ih);
  gtk_menu_shell_insert((GtkMenuShell*)ih->parent->handle, ih->handle, pos);
  gtk_widget_show(ih->handle);

  g_signal_connect(G_OBJECT(ih->handle), "select", G_CALLBACK(gtkItemSelect), ih);

  iupUpdateStandardFontAttrib(ih);

  return IUP_NOERROR;
}
Esempio n. 3
0
static int winMenuAddParentSubmenu(Ihandle* ih)
{
  int pos;
  MENUITEMINFO menuiteminfo;

  pos = IupGetChildPos(ih->parent, ih);
  ih->serial = iupMenuGetChildId(ih);

  menuiteminfo.cbSize = sizeof(MENUITEMINFO); 
  menuiteminfo.fMask = MIIM_ID|MIIM_DATA|MIIM_SUBMENU|MIIM_STRING; 
  menuiteminfo.dwTypeData = ""; /* must set or it will be not possible to update */
  menuiteminfo.cch = 0;
  menuiteminfo.wID = (UINT)ih->serial;
  menuiteminfo.dwItemData = (ULONG_PTR)ih; 
  menuiteminfo.hSubMenu = (HMENU)ih->firstchild->handle;

  if (!InsertMenuItem((HMENU)ih->parent->handle, pos, TRUE, &menuiteminfo))
    return IUP_ERROR;

  ih->handle = ih->parent->handle; /* gets the HMENU of the parent */

  /* must update attributes since submenu is actually created after it is mapped */
  iupAttribUpdate(ih); 
  iupAttribUpdateFromParent(ih);

  winMenuUpdateBar(ih);

  return IUP_NOERROR;
}
Esempio n. 4
0
static int GetChildPos(lua_State *L)
{
  Ihandle* ih = iuplua_checkihandle(L,1);
  Ihandle* child = iuplua_checkihandle(L,2);
  lua_pushinteger(L, IupGetChildPos(ih, child));
  return 1;
}
Esempio n. 5
0
static int winSubmenuAddToParent(Ihandle* ih)
{
  int pos;

  pos = IupGetChildPos(ih->parent, ih);
  ih->serial = iupMenuGetChildId(ih);

  {
    MENUITEMINFO menuiteminfo;

    menuiteminfo.cbSize = sizeof(MENUITEMINFO); 
    menuiteminfo.fMask = MIIM_ID|MIIM_DATA|MIIM_SUBMENU|MIIM_STRING; 
    menuiteminfo.dwTypeData = TEXT(""); /* must set or it will be not possible to update */
    menuiteminfo.cch = 0;
    menuiteminfo.wID = (UINT)ih->serial;
    menuiteminfo.dwItemData = (ULONG_PTR)ih; 
    menuiteminfo.hSubMenu = (HMENU)ih->firstchild->handle;  /* this is why the submenu is created only here with the child menu handle */

    if (!InsertMenuItem((HMENU)ih->parent->handle, pos, TRUE, &menuiteminfo))
      return IUP_ERROR;
  }

  /* Notice that "handle" here is the HMENU of the parent menu,
  and "serial" identifies the submenu */

  ih->handle = ih->parent->handle; /* gets the HMENU of the parent */

  /* must update attributes since submenu is actually created after it is mapped */
  iupAttribUpdate(ih); 
  iupAttribUpdateFromParent(ih);

  winMenuUpdateBar(ih);

  return IUP_NOERROR;
}
Esempio n. 6
0
static int winItemMapMethod(Ihandle* ih)
{
  int pos;
  MENUITEMINFO menuiteminfo;

  if (!ih->parent || !IsMenu((HMENU)ih->parent->handle))
    return IUP_ERROR;

  pos = IupGetChildPos(ih->parent, ih);
  ih->serial = iupMenuGetChildId(ih);

  menuiteminfo.cbSize = sizeof(MENUITEMINFO); 
  menuiteminfo.fMask = MIIM_ID|MIIM_DATA|MIIM_STRING; 
  menuiteminfo.dwTypeData = ""; /* must set or it will be not possible to update */
  menuiteminfo.cch = 0;
  menuiteminfo.wID = (UINT)ih->serial;
  menuiteminfo.dwItemData = (ULONG_PTR)ih; 

  if (!InsertMenuItem((HMENU)ih->parent->handle, pos, TRUE, &menuiteminfo))
    return IUP_ERROR;

  ih->handle = ih->parent->handle; /* gets the HMENU of the parent */
  winMenuUpdateBar(ih);

  return IUP_NOERROR;
}
Esempio n. 7
0
static int winSeparatorMapMethod(Ihandle* ih)
{
  int pos;
  MENUITEMINFO menuiteminfo;

  if (!ih->parent || !IsMenu((HMENU)ih->parent->handle))
    return IUP_ERROR;

  pos = IupGetChildPos(ih->parent, ih);
  ih->serial = iupMenuGetChildId(ih);

  menuiteminfo.cbSize = sizeof(MENUITEMINFO); 
  menuiteminfo.fMask = MIIM_FTYPE|MIIM_ID|MIIM_DATA; 
  menuiteminfo.fType = MFT_SEPARATOR; 
  menuiteminfo.wID = (UINT)ih->serial;
  menuiteminfo.dwItemData = (ULONG_PTR)ih; 

  if (!InsertMenuItem((HMENU)ih->parent->handle, pos, TRUE, &menuiteminfo))
    return IUP_ERROR;

  ih->handle = ih->parent->handle; /* gets the HMENU of the parent */
  winMenuUpdateBar(ih);

  return IUP_NOERROR;
}
Esempio n. 8
0
static int gtkItemMapMethod(Ihandle* ih)
{
  int pos;

  if (!ih->parent)
    return IUP_ERROR;

#ifndef HILDON
  if (iupMenuIsMenuBar(ih->parent))
    ih->handle = gtk_menu_item_new_with_label("");
  else
#endif
  {
    if (iupAttribGet(ih, "IMAGE")||iupAttribGet(ih, "TITLEIMAGE"))
      ih->handle = gtk_image_menu_item_new_with_label("");
    else if (iupAttribGetBoolean(ih->parent, "RADIO"))
    {
      GtkRadioMenuItem* last_tg = (GtkRadioMenuItem*)iupAttribGet(ih->parent, "_IUPGTK_LASTRADIOITEM");
      if (last_tg)
        ih->handle = gtk_radio_menu_item_new_with_label_from_widget(last_tg, "");
      else
        ih->handle = gtk_radio_menu_item_new_with_label(NULL, "");
      iupAttribSetStr(ih->parent, "_IUPGTK_LASTRADIOITEM", (char*)ih->handle);
    }
    else
    {
      char* hidemark = iupAttribGetStr(ih, "HIDEMARK");
      if (!hidemark && gtk_check_version(2, 14, 0) == NULL)
      {
        /* force HIDEMARK if VALUE is defined before Map, after GTK 2.14 */
        if (!iupAttribGet(ih, "VALUE")) 
          hidemark = "YES";
      }

      if (iupStrBoolean(hidemark))
        ih->handle = gtk_menu_item_new_with_label("");
      else
        ih->handle = gtk_check_menu_item_new_with_label("");
    }
  }

  if (!ih->handle)
    return IUP_ERROR;

  ih->serial = iupMenuGetChildId(ih); 

  g_signal_connect(G_OBJECT(ih->handle), "select", G_CALLBACK(gtkItemSelect), ih);
  g_signal_connect(G_OBJECT(ih->handle), "activate", G_CALLBACK(gtkItemActivate), ih);

  pos = IupGetChildPos(ih->parent, ih);
  gtk_menu_shell_insert((GtkMenuShell*)ih->parent->handle, ih->handle, pos);
  gtk_widget_show(ih->handle);

  iupUpdateStandardFontAttrib(ih);

  return IUP_NOERROR;
}
Esempio n. 9
0
static void gtkItemSelect(GtkWidget *widget, Ihandle* ih)
{
  Icallback cb = IupGetCallback(ih, "HIGHLIGHT_CB");
  if (cb)
    cb(ih);

  cb = IupGetCallback(ih, "HELP_CB");
  if (cb)
    gtk_menu_set_active((GtkMenu*)ih->parent->handle, IupGetChildPos(ih->parent, ih));

  (void)widget;
}
Esempio n. 10
0
static int iTabsSetValueHandleAttrib(Ihandle* ih, const char* value)
{
  int pos;
  Ihandle *child;

  child = (Ihandle*)value;

  if (!iupObjectCheck(child))
    return 0;

  pos = IupGetChildPos(ih, child);
  if (pos != -1) /* found child */
    iTabsSetTab(ih, child, pos);
 
  return 0;
}
Esempio n. 11
0
static char* iTabsGetValuePosAttrib(Ihandle* ih)
{
  if (ih->handle)
  {
    int pos = iupdrvTabsGetCurrentTab(ih);
    return iupStrReturnInt(pos);
  }
  else
  {
    Ihandle* child = (Ihandle*)iupAttribGet(ih, "_IUPTABS_VALUE_HANDLE");
    int pos = IupGetChildPos(ih, child);
    if (pos != -1) /* found child */
      return iupStrReturnInt(pos);
  }

  return NULL;
}
Esempio n. 12
0
static int iMatrixMenuItemAction_CB(Ihandle* ih_item)
{
    Ihandle* ih_menu = ih_item->parent;
    Ihandle* ih = (Ihandle*)iupAttribGet(ih_menu, "_IUP_MATRIX");
    char* title = IupGetAttribute(ih_item, "TITLE");
    IFniinsii cb = (IFniinsii)IupGetCallback(ih, "DROPSELECT_CB");
    if(cb)
    {
        int i = IupGetChildPos(ih_menu, ih_item) + 1;
        cb(ih, ih->data->edit_lin, ih->data->edit_col, ih_menu, title, i, 1);
    }

    IupStoreAttribute(ih_menu, "VALUE", title);

    iMatrixEditCallEditionCbUpdateValue(ih, 0, 1);  /* always update, similar to iupMatrixEditConfirm */
    iupMatrixDrawUpdate(ih);

    return IUP_DEFAULT;
}
Esempio n. 13
0
static int gtkSeparatorMapMethod(Ihandle* ih)
{
  int pos;

  if (!ih->parent)
    return IUP_ERROR;

  ih->handle = gtk_separator_menu_item_new();
  if (!ih->handle)
    return IUP_ERROR;

  ih->serial = iupMenuGetChildId(ih); 

  pos = IupGetChildPos(ih->parent, ih);
  gtk_menu_shell_insert((GtkMenuShell*)ih->parent->handle, ih->handle, pos);
  gtk_widget_show(ih->handle);

  return IUP_NOERROR;
}
Esempio n. 14
0
static int iMatrixMenuItemAction(Ihandle* ih)
{
  Ihandle* ih_menu = ih->parent;
  Ihandle* ih_matrix = (Ihandle*)iupAttribGet(ih_menu, "_IUP_MATRIX");
  char* t = IupGetAttribute(ih, "TITLE"); 
  IFniinsii cb = (IFniinsii)IupGetCallback(ih_matrix, "DROPSELECT_CB");
  if(cb)
  {
    int i = IupGetChildPos(ih_menu, ih) + 1;
    cb(ih_matrix, ih_matrix->data->lines.focus_cell, ih_matrix->data->columns.focus_cell, ih_menu, t, i, 1);
  }

  IupStoreAttribute(ih_menu, "VALUE", t);

  iMatrixEditCallEditionCb(ih_matrix, 0, 1);  /* always update */
  iupMatrixDrawUpdate(ih_matrix);

  return IUP_DEFAULT;
}
Esempio n. 15
0
static int iTabsSetValueHandleAttrib(Ihandle* ih, const char* value)
{
  int pos;
  Ihandle *child;

  child = (Ihandle*)value;
  if (!iupObjectCheck(child))
    return 0;

  pos = IupGetChildPos(ih, child);
  if (pos != -1) /* found child */
  {
    if (ih->handle)
      iupdrvTabsSetCurrentTab(ih, pos);
    else
      iupAttribSetStr(ih, "_IUPTABS_VALUE_HANDLE", (char*)child);
  }
 
  return 0;
}
Esempio n. 16
0
static char* iTabsGetValuePosAttrib(Ihandle* ih)
{
  if (ih->handle)
  {
    int pos = iupdrvTabsGetCurrentTab(ih);
    char *str = iupStrGetMemory(50);
    sprintf(str, "%d", pos);
    return str;
  }
  else
  {
    Ihandle* child = (Ihandle*)iupAttribGet(ih, "_IUPTABS_VALUE_HANDLE");
    int pos = IupGetChildPos(ih, child);
    if (pos != -1) /* found child */
    {
      char *str = iupStrGetMemory(50);
      sprintf(str, "%d", pos);
      return str;
    }
  }

  return NULL;
}
Esempio n. 17
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);
    }
  }
}
Esempio n. 18
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);
  }
}
Esempio n. 19
0
static void GetChildPos(void)
{
  lua_pushnumber(IupGetChildPos(iuplua_checkihandle(1), iuplua_checkihandle(2)));
}
Esempio n. 20
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);
  }
}
Esempio n. 21
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);
  }
}
Esempio n. 22
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);
  }
}