static void photos_zoom_controls_update_buttons (PhotosZoomControls *self) { GtkWidget *image; gboolean zoom_best_fit_enabled; gboolean zoom_out_enabled; const gchar *icon_name; zoom_best_fit_enabled = g_action_get_enabled (self->zoom_best_fit_action); zoom_out_enabled = g_action_get_enabled (self->zoom_out_action); g_return_if_fail (zoom_best_fit_enabled == zoom_out_enabled); gtk_revealer_set_reveal_child (GTK_REVEALER (self->revealer), zoom_out_enabled); gtk_actionable_set_action_name (GTK_ACTIONABLE (self->zoom_toggle_button), NULL); gtk_actionable_set_action_target_value (GTK_ACTIONABLE (self->zoom_toggle_button), NULL); if (zoom_out_enabled) { gtk_actionable_set_action_name (GTK_ACTIONABLE (self->zoom_toggle_button), "app.zoom-best-fit"); } else { GVariant *target_value = NULL; target_value = photos_utils_create_zoom_target_value (1.0, PHOTOS_ZOOM_EVENT_MOUSE_CLICK); gtk_actionable_set_action_target_value (GTK_ACTIONABLE (self->zoom_toggle_button), target_value); gtk_actionable_set_action_name (GTK_ACTIONABLE (self->zoom_toggle_button), "app.zoom-in"); } icon_name = zoom_out_enabled ? "zoom-fit-best-symbolic" : "zoom-in-symbolic"; image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_INVALID); gtk_image_set_pixel_size (GTK_IMAGE (image), 16); gtk_button_set_image (GTK_BUTTON (self->zoom_toggle_button), image); }
static GtkWidget * create_toolbar (void) { GtkWidget *toolbar; GtkToolItem *item; toolbar = gtk_toolbar_new (); item = gtk_tool_button_new (gtk_image_new_from_icon_name ("document-new", GTK_ICON_SIZE_SMALL_TOOLBAR), NULL); gtk_tool_item_set_tooltip_markup (item, "Open another one of these windows"); gtk_actionable_set_action_name (GTK_ACTIONABLE (item), "demo.new"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); item = gtk_tool_button_new (gtk_image_new_from_icon_name ("document-open", GTK_ICON_SIZE_SMALL_TOOLBAR), NULL); gtk_tool_item_set_tooltip_markup (item, "This is a demo button that locks up the demo"); gtk_actionable_set_action_name (GTK_ACTIONABLE (item), "demo.lock"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); item = gtk_tool_button_new (gtk_image_new_from_icon_name ("document-open", GTK_ICON_SIZE_SMALL_TOOLBAR), NULL); gtk_tool_item_set_tooltip_markup (item, "This is a demo button that toggles window decorations"); gtk_actionable_set_action_name (GTK_ACTIONABLE (item), "demo.decorations"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); item = gtk_tool_button_new (gtk_image_new_from_icon_name ("document-open", GTK_ICON_SIZE_SMALL_TOOLBAR), NULL); gtk_tool_item_set_tooltip_markup (item, "This is a demo button that locks the aspect ratio using a hint"); gtk_actionable_set_action_name (GTK_ACTIONABLE (item), "demo.ratio"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); item = gtk_tool_button_new (gtk_image_new_from_icon_name ("gtk-quit", GTK_ICON_SIZE_SMALL_TOOLBAR), NULL); gtk_tool_item_set_tooltip_markup (item, "This is a demo button with a 'quit' icon"); gtk_actionable_set_action_name (GTK_ACTIONABLE (item), "demo.quit"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); return toolbar; }
static void gb_preferences_switch_update_settings (GbPreferencesSwitch *self) { g_assert (GB_IS_PREFERENCES_SWITCH (self)); if ((self->settings != NULL) && (self->settings_schema_key != NULL)) { GSimpleActionGroup *group; GAction *action; gchar *name; action = g_settings_create_action (self->settings, self->settings_schema_key); group = g_simple_action_group_new (); g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (action)); gtk_widget_insert_action_group (GTK_WIDGET (self), "settings", G_ACTION_GROUP (group)); g_object_unref (action); name = g_strdup_printf ("settings.%s", self->settings_schema_key); if (self->is_radio) { gtk_actionable_set_action_name (GTK_ACTIONABLE (self->settings_radio), name); gtk_actionable_set_action_name (GTK_ACTIONABLE (self->settings_switch), NULL); } else { gtk_actionable_set_action_name (GTK_ACTIONABLE (self->settings_radio), NULL); gtk_actionable_set_action_name (GTK_ACTIONABLE (self->settings_switch), name); } g_free (name); } }
static void schema_browser_perspective_customize (BrowserPerspective *perspective, GtkToolbar *toolbar, GtkHeaderBar *header) { g_print ("%s ()\n", __FUNCTION__); customization_data_init (G_OBJECT (perspective), toolbar, header); /* add perspective's actions */ customization_data_add_actions (G_OBJECT (perspective), win_entries, G_N_ELEMENTS (win_entries)); /* add to toolbar */ GtkToolItem *titem; titem = gtk_toggle_tool_button_new (); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (titem), "user-bookmarks-symbolic"); gtk_widget_set_tooltip_text (GTK_WIDGET (titem), _("Show favorites")); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), titem, -1); gtk_actionable_set_action_name (GTK_ACTIONABLE (titem), "win.show-favorites"); gtk_widget_show (GTK_WIDGET (titem)); customization_data_add_part (G_OBJECT (perspective), G_OBJECT (titem)); #ifdef HAVE_GOOCANVAS titem = gtk_tool_button_new (NULL, NULL); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (titem), "tab-new-symbolic"); gtk_widget_set_tooltip_text (GTK_WIDGET (titem), _("Create a new diagram")); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), titem, -1); gtk_actionable_set_action_name (GTK_ACTIONABLE (titem), "win.action-diagram-new"); gtk_widget_show (GTK_WIDGET (titem)); customization_data_add_part (G_OBJECT (perspective), G_OBJECT (titem)); #endif }
static void tm_populate(GtkWidget * toolbar, BalsaToolbarModel * model) { gboolean style_is_both; gboolean make_two_line; GArray *current; guint j; GActionMap *action_map = g_object_get_data(G_OBJECT(toolbar), BALSA_TOOLBAR_ACTION_MAP); style_is_both = (model->style == GTK_TOOLBAR_BOTH || (model->style == (GtkToolbarStyle) - 1 && tm_default_style() == GTK_TOOLBAR_BOTH)); make_two_line = style_is_both && tm_has_second_line(model); current = balsa_toolbar_model_get_current(model); for (j = 0; j < current->len; j++) { BalsaToolbarEntry *entry; GtkToolItem *item; entry = &g_array_index(current, BalsaToolbarEntry, j); if (!*entry->action) { item = gtk_separator_tool_item_new(); } else { GtkWidget *icon; GAction *action; const GVariantType *type; gchar *prefixed_action; icon = gtk_image_new_from_icon_name (balsa_icon_id(entry->icon), GTK_ICON_SIZE_SMALL_TOOLBAR); action = g_action_map_lookup_action(action_map, entry->action); if (action && (type = g_action_get_state_type(action)) && g_variant_type_equal(type, G_VARIANT_TYPE_BOOLEAN)) { item = gtk_toggle_tool_button_new(); g_object_set(G_OBJECT(item), "icon-widget", icon, "label", entry->action, NULL); } else { item = gtk_tool_button_new(icon, entry->action); } tm_set_tool_item_label(GTK_TOOL_ITEM(item), entry->icon, make_two_line); prefixed_action = g_strconcat(action ? "win." : "app.", entry->action, NULL); gtk_actionable_set_action_name(GTK_ACTIONABLE(item), prefixed_action); g_free(prefixed_action); } gtk_toolbar_insert((GtkToolbar *) toolbar, item, -1); } gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), model->style != (GtkToolbarStyle) (-1) ? model->style : tm_default_style()); gtk_widget_show_all(toolbar); }
static void gtk_tool_button_set_action_name (GtkActionable *actionable, const gchar *action_name) { GtkToolButton *button = GTK_TOOL_BUTTON (actionable); gtk_actionable_set_action_name (GTK_ACTIONABLE (button->priv->button), action_name); }
static void setup_header_bar (GtkWidget *window, VteTerminal *vtterm, gboolean show_maximized_title) { /* * Using the default GtkHeaderBar title/subtitle widget makes the bar * too thick to look nice for a terminal, so set a custom widget. */ GtkWidget *hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5); const gchar *title = gtk_window_get_title (GTK_WINDOW (window)); GtkWidget *label = gtk_label_new (title ? title : "dwt"); g_object_bind_property (G_OBJECT (vtterm), "window-title", G_OBJECT (label), "label", G_BINDING_DEFAULT); GtkWidget *header = gtk_header_bar_new (); gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (header), TRUE); gtk_header_bar_set_has_subtitle (GTK_HEADER_BAR (header), FALSE); gtk_header_bar_set_custom_title (GTK_HEADER_BAR (header), label); GtkWidget *button = gtk_button_new_from_icon_name ("tab-new-symbolic", GTK_ICON_SIZE_BUTTON); gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "app.new-terminal"); gtk_header_bar_pack_start (GTK_HEADER_BAR (header), button); GtkWidget *revealer = gtk_revealer_new (); gtk_container_add (GTK_CONTAINER (revealer), gtk_image_new_from_icon_name ("software-update-urgent-symbolic", GTK_ICON_SIZE_BUTTON)); gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 500); gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_CROSSFADE); gtk_header_bar_pack_end (GTK_HEADER_BAR (header), revealer); g_signal_connect (G_OBJECT (vtterm), "bell", G_CALLBACK (header_bar_term_beeped), revealer); g_object_bind_property (G_OBJECT (window), "urgency-hint", G_OBJECT (revealer), "reveal-child", G_BINDING_DEFAULT); gtk_window_set_titlebar (GTK_WINDOW (window), header); /* Hide the header bar when the window is maximized. */ if (!show_maximized_title) { g_object_bind_property (G_OBJECT (window), "is-maximized", G_OBJECT (header), "visible", G_BINDING_INVERT_BOOLEAN); } }
NiepceWindow::NiepceWindow() : fwk::AppFrame("mainWindow-frame") , m_vbox(Gtk::ORIENTATION_VERTICAL) , m_hbox(Gtk::ORIENTATION_HORIZONTAL) { // headerbar. Gtk::HeaderBar *header = Gtk::manage(new Gtk::HeaderBar); header->set_show_close_button(true); header->set_has_subtitle(true); Gtk::MenuButton* menu_btn = Gtk::manage(new Gtk::MenuButton); menu_btn->set_direction(Gtk::ARROW_NONE); m_main_menu = Gio::Menu::create(); menu_btn->set_menu_model(m_main_menu); header->pack_end(*menu_btn); // Undo redo buttons Gtk::Box *button_box = Gtk::manage(new Gtk::Box); button_box->get_style_context()->add_class("linked"); Gtk::Button *undo_button = Gtk::manage(new Gtk::Button); undo_button->set_image_from_icon_name("edit-undo-symbolic"); undo_button->set_label(_("Undo")); undo_button->set_always_show_image(true); gtk_actionable_set_action_name(GTK_ACTIONABLE(undo_button->gobj()), "win.Undo"); Gtk::Button *redo_button = Gtk::manage(new Gtk::Button); redo_button->set_image_from_icon_name("edit-redo-symbolic"); gtk_actionable_set_action_name(GTK_ACTIONABLE(redo_button->gobj()), "win.Redo"); button_box->pack_start(*undo_button, false, false, 0); button_box->pack_start(*redo_button, false, false, 0); header->pack_start(*button_box); Gtk::Button *import_button = Gtk::manage(new Gtk::Button); import_button->set_label(_("Import...")); gtk_actionable_set_action_name(GTK_ACTIONABLE(import_button->gobj()), "workspace.Import"); header->pack_start(*import_button); setHeaderBar(header); }
/** * gtk_actionable_set_detailed_action_name: * @actionable: a #GtkActionable widget * @detailed_action_name: the detailed action name * * Sets the action-name and associated string target value of an * actionable widget. * * This allows for the effect of both gtk_actionable_set_action_name() * and gtk_actionable_set_action_target_value() in the common case that * the target is string-valued. * * @detailed_action_name is a string of the form * `"action::target"` where `action` * is the action name and `target` is the string to use * as the target. * * Since: 3.4 **/ void gtk_actionable_set_detailed_action_name (GtkActionable *actionable, const gchar *detailed_action_name) { gchar **parts; g_return_if_fail (GTK_IS_ACTIONABLE (actionable)); if (detailed_action_name == NULL) { gtk_actionable_set_action_name (actionable, NULL); gtk_actionable_set_action_target_value (actionable, NULL); return; } parts = g_strsplit (detailed_action_name, "::", 2); gtk_actionable_set_action_name (actionable, parts[0]); if (parts[0] && parts[1]) gtk_actionable_set_action_target (actionable, "s", parts[1]); else gtk_actionable_set_action_target_value (actionable, NULL); g_strfreev (parts); }
GtkWidget * _gtk_header_bar_create_image_button (const char *icon_name, const char *tooltip, const char *action_name) { GtkWidget *button; g_return_val_if_fail (icon_name != NULL, NULL); g_return_val_if_fail (action_name != NULL, NULL); button = _gtk_image_button_new_for_header_bar (icon_name); gtk_actionable_set_action_name (GTK_ACTIONABLE (button), action_name); if (tooltip != NULL) gtk_widget_set_tooltip_text (button, tooltip); gtk_widget_show (button); return button; }
static void relations_diagram_customize (BrowserPage *page, GtkToolbar *toolbar, GtkHeaderBar *header) { g_print ("%s ()\n", __FUNCTION__); customization_data_init (G_OBJECT (page), toolbar, header); /* add perspective's actions */ customization_data_add_actions (G_OBJECT (page), win_entries, G_N_ELEMENTS (win_entries)); /* add to toolbar */ GtkToolItem *titem; titem = gtk_tool_button_new (NULL, NULL); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (titem), "go-jump-symbolic"); gtk_widget_set_tooltip_text (GTK_WIDGET (titem), _("Manage data in selected tables")); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), titem, -1); gtk_actionable_set_action_name (GTK_ACTIONABLE (titem), "win.ViewContents"); gtk_widget_show (GTK_WIDGET (titem)); customization_data_add_part (G_OBJECT (page), G_OBJECT (titem)); }
static void query_console_customize (BrowserPage *page, GtkToolbar *toolbar, GtkHeaderBar *header) { g_print ("%s ()\n", __FUNCTION__); customization_data_init (G_OBJECT (page), toolbar, header); /* add perspective's actions */ customization_data_add_actions (G_OBJECT (page), win_entries, G_N_ELEMENTS (win_entries)); /* add to toolbar */ GtkToolItem *titem; titem = gtk_tool_button_new (NULL, NULL); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (titem), "system-run-symbolic"); gtk_widget_set_tooltip_text (GTK_WIDGET (titem), _("Execute query")); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), titem, -1); gtk_actionable_set_action_name (GTK_ACTIONABLE (titem), "win.ExecuteQuery"); gtk_widget_show (GTK_WIDGET (titem)); customization_data_add_part (G_OBJECT (page), G_OBJECT (titem)); }
GtkWidget * _gtk_header_bar_create_image_toggle_button (const char *icon_name, const char *tooltip, const char *action_name) { GtkWidget *button; g_return_val_if_fail (icon_name != NULL, NULL); g_return_val_if_fail (action_name != NULL, NULL); button = gtk_toggle_button_new (); gtk_container_add (GTK_CONTAINER (button), gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU)); _gtk_menu_button_set_style_for_header_bar (button); gtk_actionable_set_action_name (GTK_ACTIONABLE (button), action_name); if (tooltip != NULL) gtk_widget_set_tooltip_text (button, tooltip); gtk_widget_show_all (button); return button; }
GtkWidget * _gtk_header_bar_create_text_button (const char *label, const char *tooltip, const char *action_name) { GtkWidget *button; g_return_val_if_fail (label != NULL, NULL); g_return_val_if_fail (action_name != NULL, NULL); button = gtk_button_new_with_label (label); gtk_widget_set_valign (button, GTK_ALIGN_CENTER); gtk_style_context_add_class (gtk_widget_get_style_context (button), "text-button"); gtk_style_context_remove_class (gtk_widget_get_style_context (button), "image-button"); gtk_actionable_set_action_name (GTK_ACTIONABLE (button), action_name); if (tooltip != NULL) gtk_widget_set_tooltip_text (button, tooltip); gtk_widget_show (button); return button; }
static GtkWidget * photos_import_dialog_create_collection_button (PhotosBaseItem *collection) { GtkWidget *collection_button; GtkWidget *collection_label; const gchar *id; const gchar *name; id = photos_filterable_get_id (PHOTOS_FILTERABLE (collection)); name = photos_base_item_get_name (collection); collection_button = photos_model_button_new (); gtk_actionable_set_action_name (GTK_ACTIONABLE (collection_button), "dialog.add-existing"); gtk_actionable_set_action_target (GTK_ACTIONABLE (collection_button), "s", id); collection_label = gtk_label_new (name); gtk_widget_set_halign (collection_label, GTK_ALIGN_START); gtk_widget_set_hexpand (collection_label, TRUE); gtk_container_add (GTK_CONTAINER (collection_button), collection_label); return collection_button; }
/*********************************************************************** Menu */ void bmd_construct_menu (GtkApplication *app, gpointer data) { GtkWidget *headerbar; // the application menu displayed in the GNOME panel GMenu *appmenu; GMenu *editmenu; GtkWidget *openbutton; GtkWidget *savebutton; // the menu displayed as a popover below the gears button GMenu *gearmenu; GtkWidget *gearmenubutton; GtkWidget *gearicon; bmd_widgets *a = (bmd_widgets *) data; // define keyboard accelerators const gchar *open_accels[2] = { "<Ctrl>O", NULL }; const gchar *save_accels[2] = { "<Ctrl>S", NULL }; const gchar *quit_accels[2] = { "<Ctrl>Q", NULL }; const gchar *add_accels[2] = { "<Ctrl>A", NULL }; const gchar *del_accels[2] = { "<Ctrl>D", NULL }; const gchar *find_accels[2] = { "<Ctrl>F", NULL }; const gchar *help_accels[2] = { "F1", NULL }; // create and fill in the application menu in the GNOME panel appmenu = g_menu_new(); g_menu_append (appmenu, "About", "app.about"); g_menu_append (appmenu, "Help", "app.help"); g_menu_append (appmenu, "_Quit", "app.quit"); gtk_application_set_app_menu (GTK_APPLICATION (app), G_MENU_MODEL (appmenu)); g_object_unref (appmenu); // create a headerbar headerbar = gtk_header_bar_new (); gtk_widget_show (headerbar); gtk_header_bar_set_title (GTK_HEADER_BAR (headerbar), "Book Management"); gtk_header_bar_set_subtitle (GTK_HEADER_BAR (headerbar), "Simple Demo Application"); gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (headerbar), TRUE); gtk_window_set_titlebar (GTK_WINDOW (a->window), headerbar); // create an OPEN button, add it to the headerbar and connect the callbacks openbutton = gtk_button_new_with_label ("Open"); gtk_header_bar_pack_start (GTK_HEADER_BAR (headerbar), openbutton); gtk_actionable_set_action_name (GTK_ACTIONABLE (openbutton), "app.open"); // create the gear menu button gearmenubutton = gtk_menu_button_new(); gearicon = gtk_image_new_from_icon_name ("emblem-system-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_button_set_image (GTK_BUTTON (gearmenubutton), gearicon); gtk_header_bar_pack_end (GTK_HEADER_BAR (headerbar), gearmenubutton); // create a menu for the gear button gearmenu = g_menu_new(); g_menu_append (gearmenu, "Save As ...", "app.saveAs"); editmenu = g_menu_new(); g_menu_append (editmenu, "_Find", "app.find"); g_menu_append (editmenu, "_Add", "app.add"); g_menu_append (editmenu, "_Delete", "app.delete"); g_menu_append_section (gearmenu, NULL, G_MENU_MODEL (editmenu)); gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (gearmenubutton), G_MENU_MODEL (gearmenu)); g_object_unref (editmenu); g_object_unref (gearmenu); // create an SAVE button, add it to the headerbar and connect the callbacks savebutton = gtk_button_new_with_label ("Save"); gtk_header_bar_pack_end (GTK_HEADER_BAR (headerbar), savebutton); gtk_actionable_set_action_name (GTK_ACTIONABLE (savebutton), "app.save"); // connect keyboard accelerators gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.open", open_accels); gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.save", save_accels); gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.quit", quit_accels); gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.add", add_accels); gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.delete", del_accels); gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.find", find_accels); gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.help", help_accels); }
GtkWidget * dsn_config_new (void) { DsnConfigPrivate *priv; GtkWidget *dsn; GtkWidget *label; GtkWidget *sw; gchar *title; GdaDataModel *model; priv = g_new0 (DsnConfigPrivate, 1); dsn = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_widget_show (dsn); gtk_container_set_border_width (GTK_CONTAINER (dsn), 6); g_object_set_data_full (G_OBJECT (dsn), DSN_CONFIG_DATA, priv, (GDestroyNotify) free_private_data); /* title */ title = g_strdup_printf ("<b>%s</b>\n%s", _("Data Sources"), _("Data sources are the means by which database " "connections are identified: all " "the information needed to open a connection to " "a specific database using a 'provider' is referenced using " "a unique name.")); priv->title = gdaui_bar_new (title); g_free (title); gdaui_bar_set_icon_from_resource (GDAUI_BAR (priv->title), "/images/gdaui-generic.png"); gtk_box_pack_start (GTK_BOX (dsn), priv->title, FALSE, FALSE, 0); gtk_widget_show (priv->title); /* horizontal box for the provider list and its properties */ GtkWidget *hbox; hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_pack_start (GTK_BOX (dsn), hbox, TRUE, TRUE, 0); /* left part */ GtkWidget *vbox; vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_widget_set_size_request (vbox, 150, -1); gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0); /* create the data source list */ sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0); model = gda_config_list_dsn (); priv->dsn_list = gdaui_raw_grid_new (model); gtk_tree_view_move_column_after (GTK_TREE_VIEW (priv->dsn_list), gtk_tree_view_get_column (GTK_TREE_VIEW (priv->dsn_list), 1), gtk_tree_view_get_column (GTK_TREE_VIEW (priv->dsn_list), 2)); g_object_unref (model); g_object_set_data (G_OBJECT (dsn), "grid", priv->dsn_list); gdaui_data_proxy_column_set_editable (GDAUI_DATA_PROXY (priv->dsn_list), 0, FALSE); gdaui_data_selector_set_column_visible (GDAUI_DATA_SELECTOR (priv->dsn_list), -1, FALSE); gdaui_data_selector_set_column_visible (GDAUI_DATA_SELECTOR (priv->dsn_list), 0, TRUE); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->dsn_list), FALSE); g_object_set (priv->dsn_list, "info-cell-visible", FALSE, NULL); gtk_container_add (GTK_CONTAINER (sw), priv->dsn_list); g_signal_connect (priv->dsn_list, "selection-changed", G_CALLBACK (list_selection_changed_cb), dsn); g_signal_connect (priv->dsn_list, "populate-popup", G_CALLBACK (list_popup_cb), dsn); /* add/delete buttons */ GtkWidget *toolbar; toolbar = gtk_toolbar_new (); gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_style_context_add_class (gtk_widget_get_style_context (toolbar), "inline-toolbar"); gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0); GtkToolItem *titem; titem = gtk_tool_button_new (NULL, NULL); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (titem), "list-add-symbolic"); gtk_actionable_set_action_name (GTK_ACTIONABLE (titem), "win.DatasourceNew"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), titem, -1); titem = gtk_tool_button_new (NULL, NULL); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (titem), "list-remove-symbolic"); gtk_actionable_set_action_name (GTK_ACTIONABLE (titem), "win.DatasourceDelete"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), titem, -1); /* create the data source's properties */ GtkWidget *stack; stack = gtk_stack_new (); priv->stack = stack; gtk_box_pack_start (GTK_BOX (hbox), stack, TRUE, TRUE, 10); label = gtk_label_new (_("No data source selected.")); gtk_stack_add_named (GTK_STACK (stack), label, ST_NOPROP); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_stack_add_named (GTK_STACK (stack), vbox, ST_PROP); GtkWidget *form; form = gdaui_dsn_editor_new (); priv->dsn_editor = GDAUI_DSN_EDITOR (form); gtk_box_pack_start (GTK_BOX (vbox), form, TRUE, TRUE, 0); g_signal_connect (priv->dsn_editor, "changed", G_CALLBACK (dsn_editor_changed_cb), dsn); /* action buttons */ GtkWidget *hbox2; hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 6); GtkWidget *bbox; bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL); gtk_widget_set_hexpand (bbox, TRUE); gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_CENTER); gtk_box_pack_start (GTK_BOX (hbox2), bbox, FALSE, FALSE, 6); GtkWidget *button; button = gtk_toggle_button_new_with_label (_("Definition")); gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0); priv->view_buttons [GDAUI_DSN_EDITOR_PANE_DEFINITION] = GTK_TOGGLE_BUTTON (button); g_signal_connect (button, "toggled", G_CALLBACK (view_toggled_cb), dsn); button = gtk_toggle_button_new_with_label (_("Parameters")); gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0); priv->view_buttons [GDAUI_DSN_EDITOR_PANE_PARAMS] = GTK_TOGGLE_BUTTON (button); g_signal_connect (button, "toggled", G_CALLBACK (view_toggled_cb), dsn); button = gtk_toggle_button_new_with_label (_("Authentication")); gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0); priv->view_buttons [GDAUI_DSN_EDITOR_PANE_AUTH] = GTK_TOGGLE_BUTTON (button); g_signal_connect (button, "toggled", G_CALLBACK (view_toggled_cb), dsn); button = gtk_button_new_from_icon_name ("document-save-symbolic", GTK_ICON_SIZE_BUTTON); gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); priv->commit_button = button; gtk_widget_set_sensitive (button, FALSE); gtk_widget_set_tooltip_text (button, _("Write changes made to the DSN")); g_signal_connect (button, "clicked", G_CALLBACK (save_cb), dsn); gtk_widget_show_all (hbox); return dsn; }
static void photos_preview_nav_buttons_constructed (GObject *object) { PhotosPreviewNavButtons *self = PHOTOS_PREVIEW_NAV_BUTTONS (object); GtkStyleContext *context; GtkWidget *button; GtkWidget *image; G_OBJECT_CLASS (photos_preview_nav_buttons_parent_class)->constructed (object); self->prev_widget = g_object_ref_sink (gtk_revealer_new ()); gtk_widget_set_halign (self->prev_widget, GTK_ALIGN_START); gtk_widget_set_margin_start (self->prev_widget, 30); gtk_widget_set_margin_end (self->prev_widget, 30); gtk_widget_set_valign (self->prev_widget, GTK_ALIGN_CENTER); gtk_revealer_set_transition_type (GTK_REVEALER (self->prev_widget), GTK_REVEALER_TRANSITION_TYPE_CROSSFADE); gtk_overlay_add_overlay (GTK_OVERLAY (self->overlay), self->prev_widget); image = gtk_image_new_from_icon_name (PHOTOS_ICON_GO_PREVIOUS_SYMBOLIC, GTK_ICON_SIZE_INVALID); gtk_image_set_pixel_size (GTK_IMAGE (image), 16); button = gtk_button_new (); gtk_button_set_image (GTK_BUTTON (button), image); gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "app.load-previous"); context = gtk_widget_get_style_context (button); gtk_style_context_add_class (context, "osd"); gtk_container_add (GTK_CONTAINER (self->prev_widget), button); g_signal_connect_swapped (button, "enter-notify-event", G_CALLBACK (photos_preview_nav_buttons_enter_notify), self); g_signal_connect_swapped (button, "leave-notify-event", G_CALLBACK (photos_preview_nav_buttons_leave_notify), self); self->next_widget = g_object_ref_sink (gtk_revealer_new ()); gtk_widget_set_halign (self->next_widget, GTK_ALIGN_END); gtk_widget_set_margin_start (self->next_widget, 30); gtk_widget_set_margin_end (self->next_widget, 30); gtk_widget_set_valign (self->next_widget, GTK_ALIGN_CENTER); gtk_revealer_set_transition_type (GTK_REVEALER (self->next_widget), GTK_REVEALER_TRANSITION_TYPE_CROSSFADE); gtk_overlay_add_overlay (GTK_OVERLAY (self->overlay), self->next_widget); image = gtk_image_new_from_icon_name (PHOTOS_ICON_GO_NEXT_SYMBOLIC, GTK_ICON_SIZE_INVALID); gtk_image_set_pixel_size (GTK_IMAGE (image), 16); button = gtk_button_new (); gtk_button_set_image (GTK_BUTTON (button), image); gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "app.load-next"); context = gtk_widget_get_style_context (button); gtk_style_context_add_class (context, "osd"); gtk_container_add (GTK_CONTAINER (self->next_widget), button); g_signal_connect_swapped (button, "enter-notify-event", G_CALLBACK (photos_preview_nav_buttons_enter_notify), self); g_signal_connect_swapped (button, "leave-notify-event", G_CALLBACK (photos_preview_nav_buttons_leave_notify), self); g_signal_connect_swapped (self->overlay, "motion-notify-event", G_CALLBACK (photos_preview_nav_buttons_motion_notify), self); self->tap_gesture = gtk_gesture_multi_press_new (self->preview_view); gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (self->tap_gesture), TRUE); g_signal_connect_swapped (self->tap_gesture, "released", G_CALLBACK (photos_preview_nav_buttons_multi_press_released), self); g_signal_connect_swapped (self->tap_gesture, "stopped", G_CALLBACK (photos_preview_nav_buttons_multi_press_stopped), self); /* We will not need them any more */ self->overlay = NULL; self->preview_view = NULL; }
static void photos_tool_filter_button_set_action_name (GtkActionable *actionable, const gchar *action_name) { PhotosToolFilterButton *self = PHOTOS_TOOL_FILTER_BUTTON (actionable); gtk_actionable_set_action_name (GTK_ACTIONABLE (self->button), action_name); }
static void GyahtzeeCreateMainWindow (GApplication *app, gpointer user_data) { GtkWidget *hbox, *vbox; GtkWidget *toolbar; GtkWidget *tmp; GtkWidget *dicebox; GtkWidget *undo_button; GtkWidget *menu_button; GtkWidget *icon; GtkBuilder *builder; GMenuModel *appmenu; int i, j; window = gtk_application_window_new (application); gtk_window_set_application (GTK_WINDOW (window), application); gtk_window_set_title (GTK_WINDOW (window), _(appName)); gtk_window_set_hide_titlebar_when_maximized (GTK_WINDOW (window), FALSE); gtk_window_set_icon_name (GTK_WINDOW (window), "org.gnome.Tali"); //games_conf_add_window (GTK_WINDOW (window), NULL); g_signal_connect (GTK_WIDGET (window), "key_press_event", G_CALLBACK (key_press), NULL); g_action_map_add_action_entries (G_ACTION_MAP (application), app_entries, G_N_ELEMENTS (app_entries), application); const gchar *vaccels_help[] = {"F1", NULL}; const gchar *vaccels_new[] = {"<Primary>n", NULL}; const gchar *vaccels_roll[] = {"<Primary>r", NULL}; const gchar *vaccels_undo[] = {"<Primary>z", NULL}; gtk_application_set_accels_for_action (application, "app.help", vaccels_help); gtk_application_set_accels_for_action (application, "app.new-game", vaccels_new); gtk_application_set_accels_for_action (application, "app.roll", vaccels_roll); gtk_application_set_accels_for_action (application, "app.undo", vaccels_undo); scores_action = g_action_map_lookup_action (G_ACTION_MAP (application), "scores"); undo_action = g_action_map_lookup_action (G_ACTION_MAP (application), "undo"); update_undo_sensitivity (); /*--- Headerbar ---*/ hbar = gtk_header_bar_new (); gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (hbar), TRUE); gtk_header_bar_set_title (GTK_HEADER_BAR (hbar), _(appName)); gtk_widget_show (hbar); gtk_window_set_titlebar (GTK_WINDOW (window), hbar); if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL) undo_button = gtk_button_new_from_icon_name ("edit-undo-rtl-symbolic", GTK_ICON_SIZE_BUTTON); else undo_button = gtk_button_new_from_icon_name ("edit-undo-symbolic", GTK_ICON_SIZE_BUTTON); gtk_widget_set_valign (undo_button, GTK_ALIGN_CENTER); gtk_actionable_set_action_name (GTK_ACTIONABLE (undo_button), "app.undo"); gtk_widget_set_tooltip_text (undo_button, _("Undo your most recent move")); gtk_widget_show (undo_button); gtk_header_bar_pack_start (GTK_HEADER_BAR (hbar), undo_button); builder = gtk_builder_new_from_resource ("/org/gnome/Tali/ui/menus.ui"); appmenu = (GMenuModel *) gtk_builder_get_object (builder, "app-menu"); menu_button = gtk_menu_button_new(); icon = gtk_image_new_from_icon_name ("open-menu-symbolic", GTK_ICON_SIZE_BUTTON); gtk_button_set_image (GTK_BUTTON (menu_button), icon); gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (menu_button), appmenu); gtk_widget_show (menu_button); gtk_header_bar_pack_end (GTK_HEADER_BAR (hbar), menu_button); /*---- Content ----*/ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_add (GTK_CONTAINER (window), vbox); gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0); /* Retreive dice pixmaps from memory or files */ LoadDicePixmaps (); /* Put all the dice in a vertical column */ dicebox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_box_pack_start (GTK_BOX (hbox), dicebox, FALSE, TRUE, 0); gtk_widget_show (dicebox); rollLabel = gtk_label_new (NULL); gtk_label_set_use_markup (GTK_LABEL (rollLabel), TRUE); gtk_widget_show (rollLabel); gtk_box_pack_start (GTK_BOX (dicebox), rollLabel, FALSE, TRUE, 5); mbutton = gtk_button_new_with_label (_("Roll!")); gtk_box_pack_end (GTK_BOX (dicebox), mbutton, FALSE, FALSE, 5); g_signal_connect (GTK_BUTTON (mbutton), "clicked", G_CALLBACK (roll_button_pressed_cb), NULL); gtk_widget_show (GTK_WIDGET (mbutton)); toolbar = gtk_toolbar_new (); gtk_orientable_set_orientation (GTK_ORIENTABLE (toolbar), GTK_ORIENTATION_VERTICAL); gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS); gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), FALSE); gtk_box_pack_end (GTK_BOX (dicebox), toolbar, TRUE, TRUE, 0); for (i = 0; i < NUMBER_OF_DICE; i++) { tmp = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); for (j = 0; j < NUMBER_OF_PIXMAPS; j++) { gtk_box_pack_start (GTK_BOX (tmp), dicePixmaps[i][j][GAME_YAHTZEE], FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (tmp), dicePixmaps[i][j][GAME_KISMET], FALSE, FALSE, 0); } diceBox[i] = gtk_toggle_tool_button_new (); gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (diceBox[i]), tmp); g_signal_connect (GTK_TOOL_BUTTON (diceBox[i]), "clicked", G_CALLBACK (modify_dice), &DiceValues[i]); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (diceBox[i]), -1); gtk_widget_show (GTK_WIDGET (diceBox[i])); gtk_widget_show (tmp); /*gtk_widget_show (dicePixmaps[i][0][game_type]);*/ } gtk_widget_show (toolbar); /* Scores displayed in score list */ ScoreList = create_score_list (); gtk_box_pack_end (GTK_BOX (hbox), ScoreList, TRUE, TRUE, 0); setup_score_list (ScoreList); gtk_widget_show (ScoreList); gtk_widget_show (hbox); gtk_widget_show (vbox); }
GtkWidget * reader_window_new(GtkApplication *application, CainteoirSettings *settings, CainteoirSpeechSynthesizers *synthesizers, const gchar *filename) { ReaderWindow *reader = READER_WINDOW(g_object_new(READER_TYPE_WINDOW, "application", application, nullptr)); ReaderWindowPrivate *priv = READER_WINDOW_PRIVATE(reader); priv->self = GTK_WIDGET(reader); priv->settings = CAINTEOIR_SETTINGS(g_object_ref(G_OBJECT(settings))); priv->tts = CAINTEOIR_SPEECH_SYNTHESIZERS(g_object_ref(G_OBJECT(synthesizers))); priv->application = READER_APPLICATION(application); gtk_window_set_default_size(GTK_WINDOW(reader), INDEX_PANE_WIDTH + DOCUMENT_PANE_WIDTH + 5, 300); gtk_window_set_title(GTK_WINDOW(reader), i18n("Cainteoir Text-to-Speech")); GtkWidget *layout = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_container_add(GTK_CONTAINER(reader), layout); priv->header = gtk_header_bar_new(); gtk_header_bar_set_title(GTK_HEADER_BAR(priv->header), i18n("Cainteoir Text-to-Speech")); if (cainteoir_settings_get_boolean(priv->settings, "window", "have-csd", TRUE)) { // Use client-side decorations (e.g. on Gnome Shell and Unity) ... gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(priv->header), TRUE); gtk_window_set_titlebar(GTK_WINDOW(reader), priv->header); } else { // Don't use client-side decorations (e.g. on KDE) ... gtk_box_pack_start(GTK_BOX(layout), priv->header, FALSE, FALSE, 0); } priv->actions = create_action_group(priv); gtk_widget_insert_action_group(GTK_WIDGET(reader), "cainteoir", G_ACTION_GROUP(priv->actions)); priv->view = reader_document_view_new(priv->settings); gtk_box_pack_start(GTK_BOX(layout), priv->view, TRUE, TRUE, 0); reader_document_view_set_index_pane_close_action_name(READER_DOCUMENT_VIEW(priv->view), "cainteoir.side-pane"); GtkWidget *bottombar = gtk_toolbar_new(); gtk_widget_set_size_request(bottombar, -1, 45); gtk_style_context_add_class(gtk_widget_get_style_context(bottombar), "bottombar"); gtk_box_pack_start(GTK_BOX(layout), bottombar, FALSE, FALSE, 0); GtkToolItem *record = gtk_tool_button_new(gtk_image_new_from_icon_name("media-record-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR), nullptr); gtk_toolbar_insert(GTK_TOOLBAR(bottombar), record, -1); gtk_actionable_set_action_name(GTK_ACTIONABLE(record), "cainteoir.record"); priv->play_stop = gtk_tool_button_new(nullptr, nullptr); gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(priv->play_stop), "media-playback-start-symbolic"); gtk_toolbar_insert(GTK_TOOLBAR(bottombar), priv->play_stop, -1); gtk_actionable_set_action_name(GTK_ACTIONABLE(priv->play_stop), "cainteoir.play-stop"); GtkToolItem *open = gtk_tool_button_new(gtk_image_new_from_icon_name("document-open-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR), nullptr); gtk_toolbar_insert(GTK_TOOLBAR(bottombar), open, -1); gtk_actionable_set_action_name(GTK_ACTIONABLE(open), "cainteoir.open"); GtkToolItem *timebar = gtk_tool_item_new(); gtk_tool_item_set_expand(GTK_TOOL_ITEM(timebar), TRUE); gtk_toolbar_insert(GTK_TOOLBAR(bottombar), timebar, -1); priv->timebar = cainteoir_timebar_new(); gtk_style_context_add_class(gtk_widget_get_style_context(priv->timebar), "timebar"); gtk_container_add(GTK_CONTAINER(timebar), priv->timebar); priv->previous = gtk_button_new(); gtk_button_set_image(GTK_BUTTON(priv->previous), gtk_image_new_from_icon_name("go-previous-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR)); gtk_header_bar_pack_start(GTK_HEADER_BAR(priv->header), priv->previous); gtk_actionable_set_action_name(GTK_ACTIONABLE(priv->previous), "cainteoir.view-previous"); GtkWidget *menu_button = gtk_menu_button_new(); gtk_button_set_image(GTK_BUTTON(menu_button), gtk_image_new_from_icon_name(HAMBURGER_MENU_ICON, GTK_ICON_SIZE_SMALL_TOOLBAR)); gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(menu_button), create_main_menu()); gtk_header_bar_pack_end(GTK_HEADER_BAR(priv->header), menu_button); g_signal_connect(reader, "window-state-event", G_CALLBACK(on_window_state_changed), priv->settings); g_signal_connect(reader, "delete_event", G_CALLBACK(on_window_delete), priv); g_signal_connect(reader, "show", G_CALLBACK(on_window_show), priv); g_signal_connect(priv->tts, "speaking", G_CALLBACK(on_speaking), priv); g_signal_connect(priv->tts, "text-range-changed", G_CALLBACK(on_text_range_changed), priv); gtk_window_resize(GTK_WINDOW(reader), cainteoir_settings_get_integer(priv->settings, "window", "width", 700), cainteoir_settings_get_integer(priv->settings, "window", "height", 445)); gtk_window_move(GTK_WINDOW(reader), cainteoir_settings_get_integer(priv->settings, "window", "left", 0), cainteoir_settings_get_integer(priv->settings, "window", "top", 0)); if (cainteoir_settings_get_boolean(priv->settings, "window", "maximized", FALSE)) gtk_window_maximize(GTK_WINDOW(reader)); if (filename) reader_window_load_document(reader, filename); else { gchar *prev_filename = cainteoir_settings_get_string(priv->settings, "document", "filename", nullptr); if (prev_filename) { reader_window_load_document(reader, prev_filename); g_free(prev_filename); } } gchar *anchor = cainteoir_settings_get_string(priv->settings, "highlight", "anchor", "none"); if (anchor) { if (!strcmp(anchor, "top")) reader_window_set_highlight_anchor(reader, GTK_ALIGN_START); else if (!strcmp(anchor, "middle")) reader_window_set_highlight_anchor(reader, GTK_ALIGN_CENTER); else if (!strcmp(anchor, "bottom")) reader_window_set_highlight_anchor(reader, GTK_ALIGN_END); g_free(anchor); } return GTK_WIDGET(reader); }
static gboolean append_menu (RBButtonBar *bar, GMenuModel *menu, gboolean need_separator) { int i; gulong id; id = g_signal_connect (menu, "items-changed", G_CALLBACK (items_changed_cb), bar); g_hash_table_insert (bar->priv->handlers, (gpointer)id, g_object_ref (menu)); for (i = 0; i < g_menu_model_get_n_items (menu); i++) { char *label_text; char *accel; GtkWidget *button; GtkWidget *label; GMenuModel *submenu; /* recurse into sections */ submenu = g_menu_model_get_item_link (menu, i, G_MENU_LINK_SECTION); if (submenu != NULL) { need_separator = append_menu (bar, submenu, TRUE); continue; } /* if this item and the previous item are in different sections, add * a separator between them. this may not be a good idea. */ if (need_separator) { GtkWidget *sep; if (bar->priv->position > 0) { sep = gtk_separator_new (GTK_ORIENTATION_VERTICAL); gtk_widget_show (sep); g_object_set (sep, "margin-start", 6, "margin-end", 6, NULL); gtk_grid_attach (GTK_GRID (bar), sep, bar->priv->position++, 0, 1, 1); } need_separator = FALSE; } button = NULL; /* submenus become menu buttons, normal items become buttons */ submenu = g_menu_model_get_item_link (menu, i, G_MENU_LINK_SUBMENU); if (submenu != NULL) { button = gtk_menu_button_new (); gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), submenu); g_object_set_data_full (G_OBJECT (button), "rb-menu-model", g_object_ref (submenu), (GDestroyNotify)g_object_unref); } else { GMenuAttributeIter *iter; const char *name; GVariant *value; char *str; guint signal_id; /* we can't do more than one of action and rb-property-bind * and rb-signal-bind, so just do whichever turns up first * in the iterator */ iter = g_menu_model_iterate_item_attributes (menu, i); while (g_menu_attribute_iter_get_next (iter, &name, &value)) { if (g_str_equal (name, "action")) { button = gtk_button_new (); g_variant_get (value, "s", &str, NULL); gtk_actionable_set_action_name (GTK_ACTIONABLE (button), str); /* action target too somehow? */ g_free (str); break; } else if (g_str_equal (name, "rb-property-bind")) { /* property has to be a boolean, can't do inverts, etc. etc. */ button = gtk_toggle_button_new (); g_variant_get (value, "s", &str, NULL); g_object_bind_property (bar->priv->target, str, button, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); g_free (str); break; } else if (g_str_equal (name, "rb-signal-bind")) { button = gtk_button_new (); g_variant_get (value, "s", &str, NULL); signal_id = g_signal_lookup (str, G_OBJECT_TYPE (bar->priv->target)); if (signal_id != 0) { g_object_set_data (G_OBJECT (button), "rb-signal-bind-id", GUINT_TO_POINTER (signal_id)); g_signal_connect (button, "clicked", G_CALLBACK (signal_button_clicked_cb), bar); } g_free (str); break; } } g_object_unref (iter); } if (button == NULL) { g_warning ("no idea what's going on here"); continue; } gtk_widget_set_hexpand (button, FALSE); gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); label_text = NULL; g_menu_model_get_item_attribute (menu, i, "label", "s", &label_text); label = gtk_label_new (g_dgettext (NULL, label_text)); g_object_set (label, "margin-left", 6, "margin-right", 6, NULL); gtk_container_add (GTK_CONTAINER (button), label); if (g_menu_model_get_item_attribute (menu, i, "accel", "s", &accel)) { g_object_set_data_full (G_OBJECT (button), "rb-accel", accel, (GDestroyNotify) g_free); } gtk_widget_show_all (button); gtk_size_group_add_widget (bar->priv->size_group, button); gtk_grid_attach (GTK_GRID (bar), button, bar->priv->position++, 0, 1, 1); g_free (label_text); } return need_separator; }
void main_window_enable_csd(MainWindow *wnd) { GIcon *open_icon; GIcon *fullscreen_icon; GIcon *menu_icon; open_icon = g_themed_icon_new_with_default_fallbacks ("list-add-symbolic"); fullscreen_icon = g_themed_icon_new_with_default_fallbacks ("view-fullscreen-symbolic"); menu_icon = g_themed_icon_new_with_default_fallbacks ("view-list-symbolic"); wnd->playlist_width = PLAYLIST_DEFAULT_WIDTH+PLAYLIST_CSD_OFFSET; wnd->open_hdr_btn = gtk_menu_button_new(); wnd->fullscreen_hdr_btn = gtk_button_new(); wnd->menu_hdr_btn = gtk_menu_button_new(); gtk_widget_set_can_focus(wnd->open_hdr_btn, FALSE); gtk_widget_set_can_focus(wnd->fullscreen_hdr_btn, FALSE); gtk_widget_set_can_focus(wnd->menu_hdr_btn, FALSE); gtk_button_set_image ( GTK_BUTTON(wnd->fullscreen_hdr_btn), gtk_image_new_from_gicon (fullscreen_icon, GTK_ICON_SIZE_MENU )); gtk_button_set_image ( GTK_BUTTON(wnd->open_hdr_btn), gtk_image_new_from_gicon (open_icon, GTK_ICON_SIZE_MENU )); gtk_button_set_image ( GTK_BUTTON(wnd->menu_hdr_btn), gtk_image_new_from_gicon (menu_icon, GTK_ICON_SIZE_MENU )); gtk_menu_button_set_menu_model ( GTK_MENU_BUTTON(wnd->open_hdr_btn), G_MENU_MODEL(open_btn_build_menu()) ); gtk_menu_button_set_menu_model ( GTK_MENU_BUTTON(wnd->menu_hdr_btn), G_MENU_MODEL(menu_btn_build_menu()) ); gtk_header_bar_pack_start (GTK_HEADER_BAR(wnd->header_bar), wnd->open_hdr_btn); gtk_header_bar_pack_end (GTK_HEADER_BAR(wnd->header_bar), wnd->menu_hdr_btn); gtk_header_bar_pack_end (GTK_HEADER_BAR(wnd->header_bar), wnd->fullscreen_hdr_btn); gtk_actionable_set_action_name (GTK_ACTIONABLE(wnd->fullscreen_hdr_btn), "app.fullscreen"); gtk_paned_set_position( GTK_PANED(wnd->vid_area_paned), MAIN_WINDOW_DEFAULT_WIDTH -PLAYLIST_DEFAULT_WIDTH -PLAYLIST_CSD_OFFSET ); gtk_window_set_titlebar(GTK_WINDOW(wnd), wnd->header_bar); gtk_window_set_title(GTK_WINDOW(wnd), g_get_application_name()); }
static void nautilus_toolbar_constructed (GObject *obj) { NautilusToolbar *self = NAUTILUS_TOOLBAR (obj); GtkWidget *toolbar; GtkWidget *button; GtkWidget *menu; GtkWidget *box; GtkWidget *separator; GtkUIManager *ui_manager; gboolean rtl; G_OBJECT_CLASS (nautilus_toolbar_parent_class)->constructed (obj); gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)), "header-bar"); self->priv->toolbar = toolbar = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); g_object_set (toolbar, "margin", 8, NULL); gtk_container_add (GTK_CONTAINER (self), toolbar); rtl = gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL; ui_manager = nautilus_window_get_ui_manager (self->priv->window); gtk_style_context_set_junction_sides (gtk_widget_get_style_context (GTK_WIDGET (self)), GTK_JUNCTION_BOTTOM); /* Back and Forward */ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); /* Back */ button = toolbar_create_toolbutton (self, FALSE, FALSE, NAUTILUS_ACTION_BACK, NULL); gtk_widget_set_valign (button, GTK_ALIGN_CENTER); gtk_action_set_icon_name (gtk_activatable_get_related_action (GTK_ACTIVATABLE (button)), rtl ? "go-previous-rtl-symbolic" : "go-previous-symbolic"); navigation_button_setup_menu (self, button, NAUTILUS_NAVIGATION_DIRECTION_BACK); gtk_container_add (GTK_CONTAINER (box), button); /* Forward */ button = toolbar_create_toolbutton (self, FALSE, FALSE, NAUTILUS_ACTION_FORWARD, NULL); gtk_widget_set_valign (button, GTK_ALIGN_CENTER); gtk_action_set_icon_name (gtk_activatable_get_related_action (GTK_ACTIVATABLE (button)), rtl ? "go-next-rtl-symbolic" : "go-next-symbolic"); navigation_button_setup_menu (self, button, NAUTILUS_NAVIGATION_DIRECTION_FORWARD); gtk_container_add (GTK_CONTAINER (box), button); gtk_style_context_add_class (gtk_widget_get_style_context (box), GTK_STYLE_CLASS_RAISED); gtk_style_context_add_class (gtk_widget_get_style_context (box), GTK_STYLE_CLASS_LINKED); gtk_box_pack_start (GTK_BOX (toolbar), box, FALSE, FALSE, 0); if (rtl) { gtk_widget_set_margin_left (box, 12); } else { gtk_widget_set_margin_right (box, 12); } /* regular path bar */ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); self->priv->path_bar = g_object_new (NAUTILUS_TYPE_PATH_BAR, NULL); gtk_box_pack_start (GTK_BOX (box), self->priv->path_bar, TRUE, TRUE, 0); /* entry-like location bar */ self->priv->location_entry = nautilus_location_entry_new (); gtk_box_pack_start (GTK_BOX (box), self->priv->location_entry, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (toolbar), box, TRUE, TRUE, 0); /* search */ button = toolbar_create_toolbutton (self, FALSE, TRUE, NAUTILUS_ACTION_SEARCH, NULL); gtk_widget_set_valign (button, GTK_ALIGN_CENTER); gtk_container_add (GTK_CONTAINER (toolbar), button); if (rtl) { gtk_widget_set_margin_right (button, 76); } else { gtk_widget_set_margin_left (button, 76); } /* View buttons */ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); button = toolbar_create_toolbutton (self, FALSE, TRUE, NAUTILUS_ACTION_VIEW_LIST, NULL); gtk_widget_set_valign (button, GTK_ALIGN_CENTER); gtk_container_add (GTK_CONTAINER (box), button); button = toolbar_create_toolbutton (self, FALSE, TRUE, NAUTILUS_ACTION_VIEW_GRID, NULL); gtk_widget_set_valign (button, GTK_ALIGN_CENTER); gtk_container_add (GTK_CONTAINER (box), button); button = toolbar_create_toolbutton (self, TRUE, FALSE, "go-down-symbolic", _("View options")); gtk_widget_set_valign (button, GTK_ALIGN_CENTER); gtk_container_add (GTK_CONTAINER (box), button); menu = gtk_ui_manager_get_widget (ui_manager, "/ViewMenu"); gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), menu); gtk_style_context_add_class (gtk_widget_get_style_context (box), GTK_STYLE_CLASS_RAISED); gtk_style_context_add_class (gtk_widget_get_style_context (box), GTK_STYLE_CLASS_LINKED); gtk_container_add (GTK_CONTAINER (toolbar), box); if (rtl) { gtk_widget_set_margin_right (box, 12); } else { gtk_widget_set_margin_left (box, 12); } /* Action Menu */ button = toolbar_create_toolbutton (self, TRUE, FALSE, "emblem-system-symbolic", _("Location options")); gtk_widget_set_valign (button, GTK_ALIGN_CENTER); menu = gtk_ui_manager_get_widget (ui_manager, "/ActionMenu"); gtk_widget_set_halign (menu, GTK_ALIGN_END); gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), menu); gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "win.gear-menu"); g_signal_connect (menu, "key-press-event", G_CALLBACK (gear_menu_key_press), self); gtk_container_add (GTK_CONTAINER (toolbar), button); if (rtl) { gtk_widget_set_margin_right (button, 12); } else { gtk_widget_set_margin_left (button, 12); } /* Separator and Close */ separator = gtk_separator_new (GTK_ORIENTATION_VERTICAL); gtk_container_add (GTK_CONTAINER (toolbar), separator); if (rtl) { gtk_widget_set_margin_right (separator, 8); } else { gtk_widget_set_margin_left (separator, 8); } button = gtk_button_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_MENU); gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); g_signal_connect (button, "clicked", G_CALLBACK (close_button_clicked), self); gtk_container_add (GTK_CONTAINER (toolbar), button); if (rtl) { gtk_widget_set_margin_right (button, 6); } else { gtk_widget_set_margin_left (button, 6); } g_signal_connect_swapped (nautilus_preferences, "changed::" NAUTILUS_PREFERENCES_ALWAYS_USE_LOCATION_ENTRY, G_CALLBACK (toolbar_update_appearance), self); gtk_widget_show_all (toolbar); toolbar_update_appearance (self); }
static void activate (GtkApplication *app, gpointer user_data) { GtkWidget *grid; GtkWidget *window; GtkWidget *toolbar; GtkToolItem *new_button; GtkToolItem *open_button; GtkToolItem *undo_button; GtkStyleContext *style_context; GSimpleAction *undo_action; window = gtk_application_window_new (app); gtk_window_set_title (GTK_WINDOW (window), "Toolbar with Tooltips Example"); gtk_window_set_default_size (GTK_WINDOW (window), 400, 200); /* Here we begin to create the toolbar */ toolbar = gtk_toolbar_new (); /* Set the toolbar to be the primary toolbar of the application */ style_context = gtk_widget_get_style_context (toolbar); gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_PRIMARY_TOOLBAR); /* Create a button for the "new" action, with a stock image */ new_button = gtk_tool_button_new_from_stock (GTK_STOCK_NEW); gtk_tool_item_set_is_important (new_button, TRUE); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), new_button, 0); gtk_widget_show (GTK_WIDGET (new_button)); /* Set the action name for the "new" action. We use "app.new" to * indicate that the action controls the application. */ gtk_actionable_set_action_name (GTK_ACTIONABLE (new_button), "app.new"); /******************************* * Tooltip for the New ToolItem: * a tooltip with text *******************************/ gtk_tool_item_set_tooltip_text (new_button, "Create a new file"); /* "Open" */ open_button = gtk_tool_button_new_from_stock (GTK_STOCK_OPEN); gtk_tool_item_set_is_important (open_button, TRUE); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), open_button, 1); gtk_widget_show (GTK_WIDGET (open_button)); gtk_actionable_set_action_name (GTK_ACTIONABLE (open_button), "app.open"); /******************************* * Tooltip for the Open ToolItem: * a tooltip using Pango markup * language *******************************/ gtk_tool_item_set_tooltip_text (open_button, "Open an <i>existing</i> file"); /* "Undo" */ undo_button = gtk_tool_button_new_from_stock (GTK_STOCK_UNDO); gtk_tool_item_set_is_important (undo_button, TRUE); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), undo_button, 2); gtk_widget_show (GTK_WIDGET (undo_button)); /* In this case, we use "win.undo" to indicate that * the action controls only the window */ gtk_actionable_set_action_name (GTK_ACTIONABLE (undo_button), "win.undo"); /******************************* * Tooltip for the Undo ToolItem: * a tooltip with an image *******************************/ gtk_widget_set_has_tooltip (GTK_WIDGET (undo_button), TRUE); // Next, we connect the query_tooltip signal g_signal_connect (undo_button, "query-tooltip", G_CALLBACK (undo_tooltip_callback), NULL); gtk_widget_set_hexpand (toolbar, TRUE); gtk_widget_show (toolbar); grid = gtk_grid_new (); gtk_grid_attach (GTK_GRID (grid), toolbar, 0, 0, 1, 1); gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (grid)); gtk_widget_show (GTK_WIDGET (grid)); /* Use the action names to create the actions that control the window, and * connect them to the appropriate callbackfunctions. */ undo_action = g_simple_action_new ("undo", NULL); g_signal_connect (undo_action, "activate", G_CALLBACK (undo_callback), GTK_WINDOW (window)); g_action_map_add_action (G_ACTION_MAP (window), G_ACTION (undo_action)); gtk_widget_show (window); }