static int gtkFrameSetBgColorAttrib(Ihandle* ih, const char* value) { unsigned char r, g, b; GtkWidget* widget = gtk_frame_get_label_widget((GtkFrame*)ih->handle); if (!iupAttribGet(ih, "_IUPFRAME_HAS_BGCOLOR")) { /* ignore given value, must use only from parent */ value = iupBaseNativeParentGetBgColor(ih); } if (!iupStrToRGB(value, &r, &g, &b)) return 0; if (widget) iupgtkSetBgColor(widget, r, g, b); widget = gtk_bin_get_child((GtkBin*)ih->handle); iupgtkSetBgColor(widget, r, g, b); if (iupAttribGet(ih, "_IUPFRAME_HAS_BGCOLOR")) return 1; /* save on the hash table */ else return 0; }
static void gtkTabsUpdatePageBgColor(Ihandle* ih, unsigned char r, unsigned char g, unsigned char b) { Ihandle* child; for (child = ih->firstchild; child; child = child->brother) { GtkWidget* tab_container = (GtkWidget*)iupAttribGet(child, "_IUPTAB_CONTAINER"); if (tab_container) { GtkWidget* tab_label = (GtkWidget*)iupAttribGet(child, "_IUPGTK_TABLABEL"); if (tab_label) iupgtkSetBgColor(tab_label, r, g, b); iupgtkSetBgColor(tab_container, r, g, b); } } }
static int gtkTabsSetBgColorAttrib(Ihandle* ih, const char* value) { unsigned char r, g, b; if (!iupStrToRGB(value, &r, &g, &b)) return 0; iupgtkSetBgColor(ih->handle, r, g, b); gtkTabsUpdatePageBgColor(ih, r, g, b); return 1; }
static int gtkCanvasSetBgColorAttrib(Ihandle* ih, const char* value) { GtkWidget* sb_win = (GtkWidget*)iupAttribGet(ih, "_IUP_EXTRAPARENT"); unsigned char r, g, b; /* ignore given value, must use only from parent for the scrollbars */ char* parent_value = iupBaseNativeParentGetBgColor(ih); if (iupStrToRGB(parent_value, &r, &g, &b)) { GtkWidget* sb; iupgtkSetBgColor(sb_win, r, g, b); sb = (GtkWidget*)iupAttribGet(ih, "_IUPGTK_SBHORIZ"); if (sb) iupgtkSetBgColor(sb, r, g, b); sb = (GtkWidget*)iupAttribGet(ih, "_IUPGTK_SBVERT"); if (sb) iupgtkSetBgColor(sb, r, g, b); } if (!IupGetCallback(ih, "ACTION")) { /* enable automatic double buffering */ gtk_widget_set_double_buffered(ih->handle, TRUE); gtk_widget_set_double_buffered(sb_win, TRUE); return iupdrvBaseSetBgColorAttrib(ih, value); } else { /* disable automatic double buffering */ gtk_widget_set_double_buffered(ih->handle, FALSE); gtk_widget_set_double_buffered(sb_win, FALSE); #if !GTK_CHECK_VERSION(3, 0, 0) gdk_window_set_back_pixmap(iupgtkGetWindow(ih->handle), NULL, FALSE); #endif iupAttribSetStr(ih, "_IUPGTK_NO_BGCOLOR", "1"); return 1; } }
static int gtkButtonSetBgColorAttrib(Ihandle* ih, const char* value) { if (ih->data->type == IUP_BUTTON_TEXT) { GtkWidget* frame = gtk_button_get_image(GTK_BUTTON(ih->handle)); if (frame && GTK_IS_FRAME(frame)) { unsigned char r, g, b; if (!iupStrToRGB(value, &r, &g, &b)) return 0; iupgtkSetBgColor(gtk_bin_get_child(GTK_BIN(frame)), r, g, b); return 1; } } return iupdrvBaseSetBgColorAttrib(ih, value); }
/* ------------------------------------------------------------------------- */ 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); } }