static GtkWidget * accellabel_new (GladeXML *xml, GladeWidgetInfo *info) { GList *tmp; GtkWidget *label; gchar *string = NULL; GtkJustification just = GTK_JUSTIFY_CENTER; gboolean wrap = FALSE; for (tmp = info->attributes; tmp; tmp = tmp->next) { GladeAttribute *attr = tmp->data; if (!strcmp(attr->name, "label")) { string = attr->value; } else if (!strcmp(attr->name, "justify")) just = glade_enum_from_string(GTK_TYPE_JUSTIFICATION, attr->value); else if (!strcmp(attr->name, "wrap")) wrap = attr->value[0] == 'T'; } label = gtk_accel_label_new(_(string)); if (just != GTK_JUSTIFY_CENTER) gtk_label_set_justify(GTK_LABEL(label), just); if (wrap) gtk_label_set_line_wrap(GTK_LABEL(label), wrap); if (GTK_IS_MISC(label)) misc_set(GTK_MISC(label), info); return label; }
/**** ACCEL LABEL constructor ****/ int clip_GTK_ACCELLABELNEW(ClipMachine * ClipMachineMemory) { ClipVar *cv = _clip_spar(ClipMachineMemory, 1); char *text = _clip_parc(ClipMachineMemory, 2); GtkWidget *wid = NULL; C_widget *cwid; CHECKOPT(1, MAP_type_of_ClipVarType); CHECKOPT(2, CHARACTER_type_of_ClipVarType); LOCALE_TO_UTF(text); wid = gtk_accel_label_new(text); FREE_TEXT(text); if (!wid) goto err; cwid = _register_widget(ClipMachineMemory, wid, cv); _clip_mclone(ClipMachineMemory, RETPTR(ClipMachineMemory), &cwid->obj); return 0; err: return 1; }
static void CreateAndConnect( intf_thread_t *p_intf, GtkMenu *menu, const char *psz_var, const char *text, const char *help, int i_item_type, vlc_object_t *p_obj, vlc_value_t val, int i_val_type, bool checked ) { GtkMenuItem *menu_item = (GtkMenuItem *)vlc_menu_item_new (p_obj, i_item_type, val, psz_var ); (void)help; (void)i_val_type; #if GTK_CHECK_VERSION(2,16,0) gtk_menu_item_set_label (menu_item, text ? text : psz_var); #else GtkWidget *accel_label = gtk_accel_label_new(text ? text : psz_var); gtk_misc_set_alignment(GTK_MISC (accel_label), 0.0, 0.5); gtk_container_add (GTK_CONTAINER (menu_item), accel_label); gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (accel_label), GTK_WIDGET(menu_item)); gtk_widget_show (accel_label); #endif /* GTK_CHECK_VERSION(2,16,0) */ gtk_menu_append( GTK_WIDGET(menu), GTK_WIDGET(menu_item) ); if( i_item_type == ITEM_CHECK || i_item_type == ITEM_RADIO ) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_item), checked); g_signal_connect( GTK_OBJECT(menu_item), "activate", G_CALLBACK( menu_callback ), p_intf ); }
/* * Creates a new GtkWidget of class GtkAccelLabel, performing any specialized * initialization needed for the widget to work correctly in this environment. * If a dialog box is used to initialize the widget, return NULL from this * function, and call data->callback with your new widget when it is done. * If the widget needs a special destroy handler, add a signal here. */ GtkWidget* gb_accel_label_new (GbWidgetNewData *data) { GtkWidget *new_widget; new_widget = gtk_accel_label_new (data->name); return new_widget; }
GtkWidget* gtk_radio_menu_item_new_with_label (GSList *group, const gchar *label) { GtkWidget *radio_menu_item; GtkWidget *accel_label; radio_menu_item = gtk_radio_menu_item_new (group); accel_label = gtk_accel_label_new (label); gtk_misc_set_alignment (GTK_MISC (accel_label), 0.0, 0.5); gtk_container_add (GTK_CONTAINER (radio_menu_item), accel_label); gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (accel_label), radio_menu_item); gtk_widget_show (accel_label); return radio_menu_item; }
nsSystemFontsGTK2::nsSystemFontsGTK2() : mDefaultFontName(NS_LITERAL_STRING("sans-serif")) , mButtonFontName(NS_LITERAL_STRING("sans-serif")) , mFieldFontName(NS_LITERAL_STRING("sans-serif")) , mMenuFontName(NS_LITERAL_STRING("sans-serif")) { InitPangoLib(); /* * Much of the widget creation code here is similar to the code in * nsLookAndFeel::InitColors(). */ // mDefaultFont GtkWidget *label = gtk_label_new("M"); GtkWidget *parent = gtk_fixed_new(); GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP); gtk_container_add(GTK_CONTAINER(parent), label); gtk_container_add(GTK_CONTAINER(window), parent); gtk_widget_ensure_style(label); GetSystemFontInfo(label, &mDefaultFontName, &mDefaultFontStyle); gtk_widget_destroy(window); // no unref, windows are different // mFieldFont GtkWidget *entry = gtk_entry_new(); parent = gtk_fixed_new(); window = gtk_window_new(GTK_WINDOW_POPUP); gtk_container_add(GTK_CONTAINER(parent), entry); gtk_container_add(GTK_CONTAINER(window), parent); gtk_widget_ensure_style(entry); GetSystemFontInfo(entry, &mFieldFontName, &mFieldFontStyle); gtk_widget_destroy(window); // no unref, windows are different // mMenuFont GtkWidget *accel_label = gtk_accel_label_new("M"); GtkWidget *menuitem = gtk_menu_item_new(); GtkWidget *menu = gtk_menu_new(); g_object_ref_sink(GTK_OBJECT(menu)); gtk_container_add(GTK_CONTAINER(menuitem), accel_label); gtk_menu_shell_append((GtkMenuShell *)GTK_MENU(menu), menuitem); gtk_widget_ensure_style(accel_label); GetSystemFontInfo(accel_label, &mMenuFontName, &mMenuFontStyle); g_object_unref(menu); // mButtonFont parent = gtk_fixed_new(); GtkWidget *button = gtk_button_new(); label = gtk_label_new("M"); window = gtk_window_new(GTK_WINDOW_POPUP); gtk_container_add(GTK_CONTAINER(button), label); gtk_container_add(GTK_CONTAINER(parent), button); gtk_container_add(GTK_CONTAINER(window), parent); gtk_widget_ensure_style(label); GetSystemFontInfo(label, &mButtonFontName, &mButtonFontStyle); gtk_widget_destroy(window); // no unref, windows are different }
/* * Sets the properties of the widget. This is used for both applying the * properties changed in the property editor, and also for loading. */ static void gb_menu_item_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) { gboolean input_label = TRUE, input_rest = TRUE; GtkAccelGroup *accel_group; guint key; GdkModifierType modifiers; /* We only support loading the properties here. */ if (data->action != GB_LOADING) return; #ifdef USE_GNOME /* Check for a stock menu item. */ if (glade_project_get_gnome_support (data->project)) { GnomeUIInfo *uiinfo; gchar *stock_item; GtkWidget *label; gint stock_item_index; stock_item = gb_widget_input_string (data, "stock_item"); if (stock_item && stock_item[0]) { /* Special case for the NEW_SUBTREE. */ if (!strcmp (stock_item, "GNOMEUIINFO_MENU_NEW_SUBTREE")) { stock_item_index = GladeStockMenuItemNew; } else { stock_item_index = glade_util_string_array_index (GladeStockMenuItemSymbols, GladeStockMenuItemSize, stock_item); } if (stock_item_index != -1) { uiinfo = &GladeStockMenuItemValues[stock_item_index]; if (uiinfo->type == GNOME_APP_UI_ITEM_CONFIGURABLE) gnome_app_ui_configure_configurable (uiinfo); /* Note that we don't have to worry about the pixmap, since if it had a pixmap it would be a GtkImageMenuItem. */ label = gtk_accel_label_new (""); gtk_label_set_text_with_mnemonic (GTK_LABEL (label), uiinfo->label); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_widget_show (label); gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label), widget); gtk_container_add (GTK_CONTAINER (widget), label); /* Add the configured accelerator key. */ if (uiinfo->accelerator_key != 0 && widget->parent && GTK_IS_MENU (widget->parent)) { accel_group = GTK_MENU (widget->parent)->accel_group; gtk_widget_add_accelerator (widget, "activate", accel_group, uiinfo->accelerator_key, uiinfo->ac_mods, GTK_ACCEL_VISIBLE); } /* Remember the index of the stock item. */ gtk_object_set_data (GTK_OBJECT (widget), GladeMenuItemStockIndexKey, GINT_TO_POINTER (stock_item_index)); /* The 'New' item can have a label. The rest can't. */ if (stock_item_index != GladeStockMenuItemNew) input_label = FALSE; input_rest = FALSE; } else { #ifdef FIXME load_add_error_message_with_tag (data, GLADE_LINE_PROPERTY, _("Invalid stock menu item"), "stock_item", stock_item); #endif } } } #endif if (input_label) gb_widget_input_child_label (widget, data, Label); if (input_rest) { /* FIXME: should this be somewhere else? */ /* If we are loading, install the 'activate' accelerator, if it has one, so that is is visible. */ if (data->action == GB_LOADING && widget->parent && GTK_IS_MENU (widget->parent)) { int i; for (i = 0; i < data->widget_info->n_accels; i++) { if (!strcmp (data->widget_info->accels[i].signal, "activate")) { key = data->widget_info->accels[i].key; modifiers = data->widget_info->accels[i].modifiers; accel_group = GTK_MENU (widget->parent)->accel_group; gtk_widget_add_accelerator (widget, "activate", accel_group, key, modifiers, GTK_ACCEL_VISIBLE); break; } } } } }
GtkWidget* create_dialog1 (void) { GtkWidget *dialog1; GtkWidget *dialog_vbox1; GtkWidget *vbox1; GtkWidget *accellabel1; GtkWidget *hscale1; GtkWidget *label1; GtkWidget *hscale2; GtkWidget *dialog_action_area1; GtkWidget *hbox1; GtkWidget *button_ok; GtkWidget *button_ko; GtkWidget *button_preview; dialog1 = gtk_dialog_new (); gtk_object_set_data (GTK_OBJECT (dialog1), "dialog1", dialog1); gtk_window_set_title (GTK_WINDOW (dialog1), "Clean smoother"); gtk_window_set_policy (GTK_WINDOW (dialog1), TRUE, TRUE, FALSE); gtk_window_set_modal(GTK_WINDOW(dialog1), TRUE); dialog_vbox1 = GTK_DIALOG (dialog1)->vbox; gtk_object_set_data (GTK_OBJECT (dialog1), "dialog_vbox1", dialog_vbox1); gtk_widget_show (dialog_vbox1); vbox1 = gtk_vbox_new (FALSE, 0); gtk_widget_ref (vbox1); gtk_object_set_data_full (GTK_OBJECT (dialog1), "vbox1", vbox1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (vbox1); gtk_box_pack_start (GTK_BOX (dialog_vbox1), vbox1, TRUE, TRUE, 0); accellabel1 = gtk_accel_label_new ("Diameter"); gtk_widget_ref (accellabel1); gtk_object_set_data_full (GTK_OBJECT (dialog1), "accellabel1", accellabel1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (accellabel1); gtk_box_pack_start (GTK_BOX (vbox1), accellabel1, FALSE, FALSE, 0); radius_adj=gtk_adjustment_new (2, 2, 10, 1, 1, 1); hscale1 = gtk_hscale_new (GTK_ADJUSTMENT (radius_adj)); gtk_widget_ref (hscale1); gtk_object_set_data_full (GTK_OBJECT (dialog1), "hscale1", hscale1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (hscale1); gtk_box_pack_start (GTK_BOX (vbox1), hscale1, TRUE, TRUE, 0); gtk_scale_set_digits(GTK_SCALE(hscale1),0); label1 = gtk_label_new ("Blend amount"); gtk_widget_ref (label1); gtk_object_set_data_full (GTK_OBJECT (dialog1), "label1", label1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (label1); gtk_box_pack_start (GTK_BOX (vbox1), label1, FALSE, FALSE, 0); blend_adj= gtk_adjustment_new (1, 1, 10, 1, 1, 1); hscale2 = gtk_hscale_new (GTK_ADJUSTMENT (blend_adj)); gtk_widget_ref (hscale2); gtk_object_set_data_full (GTK_OBJECT (dialog1), "hscale2", hscale2, (GtkDestroyNotify) gtk_widget_unref); gtk_scale_set_digits(GTK_SCALE(hscale2),0); gtk_widget_show (hscale2); gtk_box_pack_start (GTK_BOX (vbox1), hscale2, TRUE, TRUE, 0); dialog_action_area1 = GTK_DIALOG (dialog1)->action_area; gtk_object_set_data (GTK_OBJECT (dialog1), "dialog_action_area1", dialog_action_area1); gtk_widget_show (dialog_action_area1); gtk_container_set_border_width (GTK_CONTAINER (dialog_action_area1), 10); hbox1 = gtk_hbox_new (FALSE, 0); gtk_widget_ref (hbox1); gtk_object_set_data_full (GTK_OBJECT (dialog1), "hbox1", hbox1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (hbox1); gtk_box_pack_start (GTK_BOX (dialog_action_area1), hbox1, TRUE, TRUE, 0); button_ok = gtk_button_new_with_label ("OK"); gtk_widget_ref (button_ok); gtk_object_set_data_full (GTK_OBJECT (dialog1), "button_ok", button_ok, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (button_ok); gtk_box_pack_start (GTK_BOX (hbox1), button_ok, FALSE, FALSE, 0); button_ko = gtk_button_new_with_label ("Cancel"); gtk_widget_ref (button_ko); gtk_object_set_data_full (GTK_OBJECT (dialog1), "button_ko", button_ko, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (button_ko); gtk_box_pack_start (GTK_BOX (hbox1), button_ko, FALSE, FALSE, 0); button_preview = gtk_button_new_with_label ("Preview"); gtk_widget_ref (button_preview); gtk_object_set_data_full (GTK_OBJECT (dialog1), "button_preview", button_preview, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (button_preview); gtk_box_pack_start (GTK_BOX (hbox1), button_preview, TRUE, FALSE, 0); gtk_signal_connect (GTK_OBJECT (button_ok), "clicked", GTK_SIGNAL_FUNC (gui_ok), (void *)1); gtk_signal_connect (GTK_OBJECT (button_ko), "clicked", GTK_SIGNAL_FUNC (gui_ok), (void *)0); return dialog1; }
void nsLookAndFeel::InitLookAndFeel() { GtkStyle *style; // tooltip foreground and background style = gtk_rc_get_style_by_paths(gtk_settings_get_default(), "gtk-tooltips", "GtkWindow", GTK_TYPE_WINDOW); if (style) { sInfoBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]); sInfoText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]); } // menu foreground & menu background GtkWidget *accel_label = gtk_accel_label_new("M"); GtkWidget *menuitem = gtk_menu_item_new(); GtkWidget *menu = gtk_menu_new(); g_object_ref_sink(menu); gtk_container_add(GTK_CONTAINER(menuitem), accel_label); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); gtk_widget_set_style(accel_label, NULL); gtk_widget_set_style(menu, NULL); gtk_widget_realize(menu); gtk_widget_realize(accel_label); style = gtk_widget_get_style(accel_label); if (style) { sMenuText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]); } style = gtk_widget_get_style(menu); if (style) { sMenuBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]); } style = gtk_widget_get_style(menuitem); if (style) { sMenuHover = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_PRELIGHT]); sMenuHoverText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_PRELIGHT]); } g_object_unref(menu); // button styles GtkWidget *parent = gtk_fixed_new(); GtkWidget *button = gtk_button_new(); GtkWidget *label = gtk_label_new("M"); GtkWidget *combobox = gtk_combo_box_new(); GtkWidget *comboboxLabel = gtk_label_new("M"); GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP); GtkWidget *treeView = gtk_tree_view_new(); GtkWidget *linkButton = gtk_link_button_new("http://example.com/"); GtkWidget *menuBar = gtk_menu_bar_new(); GtkWidget *entry = gtk_entry_new(); gtk_container_add(GTK_CONTAINER(button), label); gtk_container_add(GTK_CONTAINER(combobox), comboboxLabel); gtk_container_add(GTK_CONTAINER(parent), button); gtk_container_add(GTK_CONTAINER(parent), treeView); gtk_container_add(GTK_CONTAINER(parent), linkButton); gtk_container_add(GTK_CONTAINER(parent), combobox); gtk_container_add(GTK_CONTAINER(parent), menuBar); gtk_container_add(GTK_CONTAINER(window), parent); gtk_container_add(GTK_CONTAINER(parent), entry); gtk_widget_set_style(button, NULL); gtk_widget_set_style(label, NULL); gtk_widget_set_style(treeView, NULL); gtk_widget_set_style(linkButton, NULL); gtk_widget_set_style(combobox, NULL); gtk_widget_set_style(comboboxLabel, NULL); gtk_widget_set_style(menuBar, NULL); gtk_widget_set_style(entry, NULL); gtk_widget_realize(button); gtk_widget_realize(label); gtk_widget_realize(treeView); gtk_widget_realize(linkButton); gtk_widget_realize(combobox); gtk_widget_realize(comboboxLabel); gtk_widget_realize(menuBar); gtk_widget_realize(entry); style = gtk_widget_get_style(label); if (style) { sButtonText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]); } style = gtk_widget_get_style(comboboxLabel); if (style) { sComboBoxText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]); } style = gtk_widget_get_style(combobox); if (style) { sComboBoxBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]); } style = gtk_widget_get_style(menuBar); if (style) { sMenuBarText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]); sMenuBarHoverText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_SELECTED]); } // Some themes have a unified menu bar, and support window dragging on it gboolean supports_menubar_drag = FALSE; GParamSpec *param_spec = gtk_widget_class_find_style_property(GTK_WIDGET_GET_CLASS(menuBar), "window-dragging"); if (param_spec) { if (g_type_is_a(G_PARAM_SPEC_VALUE_TYPE(param_spec), G_TYPE_BOOLEAN)) { gtk_widget_style_get(menuBar, "window-dragging", &supports_menubar_drag, NULL); } } sMenuSupportsDrag = supports_menubar_drag; // GTK's guide to fancy odd row background colors: // 1) Check if a theme explicitly defines an odd row color // 2) If not, check if it defines an even row color, and darken it // slightly by a hardcoded value (gtkstyle.c) // 3) If neither are defined, take the base background color and // darken that by a hardcoded value GdkColor colorValue; GdkColor *colorValuePtr = NULL; gtk_widget_style_get(treeView, "odd-row-color", &colorValuePtr, NULL); if (colorValuePtr) { colorValue = *colorValuePtr; } else { gtk_widget_style_get(treeView, "even-row-color", &colorValuePtr, NULL); if (colorValuePtr) darken_gdk_color(colorValuePtr, &colorValue); else darken_gdk_color(&treeView->style->base[GTK_STATE_NORMAL], &colorValue); } sOddCellBackground = GDK_COLOR_TO_NS_RGB(colorValue); if (colorValuePtr) gdk_color_free(colorValuePtr); style = gtk_widget_get_style(button); if (style) { sButtonBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]); sButtonOuterLightBorder = GDK_COLOR_TO_NS_RGB(style->light[GTK_STATE_NORMAL]); sButtonInnerDarkBorder = GDK_COLOR_TO_NS_RGB(style->dark[GTK_STATE_NORMAL]); } colorValuePtr = NULL; gtk_widget_style_get(linkButton, "link-color", &colorValuePtr, NULL); if (colorValuePtr) { colorValue = *colorValuePtr; // we can't pass deref pointers to GDK_COLOR_TO_NS_RGB sNativeHyperLinkText = GDK_COLOR_TO_NS_RGB(colorValue); gdk_color_free(colorValuePtr); } else { sNativeHyperLinkText = NS_RGB(0x00,0x00,0xEE); } // invisible character styles guint value; g_object_get (entry, "invisible-char", &value, NULL); sInvisibleCharacter = PRUnichar(value); // caret styles gtk_widget_style_get(entry, "cursor-aspect-ratio", &sCaretRatio, NULL); gtk_widget_destroy(window); }