static void gtkTabsUpdatePageFgColor(Ihandle* ih, unsigned char r, unsigned char g, unsigned char b) { Ihandle* child; for (child = ih->firstchild; child; child = child->brother) { GtkWidget* tab_label = (GtkWidget*)iupAttribGet(child, "_IUPGTK_TABLABEL"); if (tab_label) iupgtkSetFgColor(tab_label, r, g, b); } }
static int gtkTabsSetFgColorAttrib(Ihandle* ih, const char* value) { unsigned char r, g, b; if (!iupStrToRGB(value, &r, &g, &b)) return 0; iupgtkSetFgColor(ih->handle, r, g, b); gtkTabsUpdatePageFgColor(ih, r, g, b); return 1; }
static int gtkButtonSetFgColorAttrib(Ihandle* ih, const char* value) { unsigned char r, g, b; GtkLabel* label = gtkButtonGetLabel(ih); if (!label) return 0; if (!iupStrToRGB(value, &r, &g, &b)) return 0; iupgtkSetFgColor((GtkWidget*)label, r, g, b); return 1; }
static int gtkToggleSetFgColorAttrib(Ihandle* ih, const char* value) { unsigned char r, g, b; GtkWidget* label = (GtkWidget*)gtk_button_get_image((GtkButton*)ih->handle); if (!label) return 0; if (!iupStrToRGB(value, &r, &g, &b)) return 0; iupgtkSetFgColor(label, r, g, b); return 1; }
static int gtkFrameSetFgColorAttrib(Ihandle* ih, const char* value) { unsigned char r, g, b; GtkWidget* label = gtk_frame_get_label_widget((GtkFrame*)ih->handle); if (!label) return 0; if (!iupStrToRGB(value, &r, &g, &b)) return 0; iupgtkSetFgColor(label, r, g, b); return 1; }
/* ------------------------------------------------------------------------- */ 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); } }
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); } }