void glade_gtk_action_bar_set_property (GladeWidgetAdaptor * adaptor, GObject * object, const gchar * id, const GValue * value) { if (!strcmp (id, "use-center-child")) { GtkWidget *child; if (g_value_get_boolean (value)) { child = gtk_action_bar_get_center_widget (GTK_ACTION_BAR (object)); if (!child) child = glade_placeholder_new (); g_object_set_data (G_OBJECT (child), "special-child-type", "center"); } else child = NULL; gtk_action_bar_set_center_widget (GTK_ACTION_BAR (object), child); } else if (!strcmp (id, "size")) glade_gtk_action_bar_set_size (object, value); else GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, id, value); }
static gint sort_children (GtkWidget * widget_a, GtkWidget * widget_b, GtkWidget *box) { GladeWidget *gwidget_a, *gwidget_b; gint position_a, position_b; gwidget_a = glade_widget_get_from_gobject (widget_a); gwidget_b = glade_widget_get_from_gobject (widget_b); /* Sort internal children before any other children */ if (box != gtk_widget_get_parent (widget_a)) return -1; if (box != gtk_widget_get_parent (widget_b)) return 1; if (gtk_action_bar_get_center_widget (GTK_ACTION_BAR (box)) == widget_a) return -1; if (gtk_action_bar_get_center_widget (GTK_ACTION_BAR (box)) == widget_b) return -1; if (gwidget_a) glade_widget_pack_property_get (gwidget_a, "position", &position_a); else gtk_container_child_get (GTK_CONTAINER (box), widget_a, "position", &position_a, NULL); if (gwidget_b) glade_widget_pack_property_get (gwidget_b, "position", &position_b); else gtk_container_child_get (GTK_CONTAINER (box), widget_b, "position", &position_b, NULL); return position_a - position_b; }
int main (int argc, char *argv[]) { GtkWidget *window; GtkWidget *box; GtkWidget *footer; GtkWidget *button; GtkWidget *content; GtkCssProvider *provider; gtk_init (NULL, NULL); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_style_context_add_class (gtk_widget_get_style_context (window), "main"); provider = gtk_css_provider_new (); gtk_css_provider_load_from_data (provider, css, -1); gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (window), GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_USER); change_header (NULL, window); box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_add (GTK_CONTAINER (window), box); footer = gtk_action_bar_new (); gtk_action_bar_set_center_widget (GTK_ACTION_BAR (footer), gtk_check_button_new_with_label ("Middle")); button = gtk_toggle_button_new_with_label ("Custom"); g_signal_connect (button, "clicked", G_CALLBACK (change_header), window); gtk_action_bar_pack_start (GTK_ACTION_BAR (footer), button); button = gtk_button_new_with_label ("Subtitle"); g_signal_connect (button, "clicked", G_CALLBACK (change_subtitle), NULL); gtk_action_bar_pack_end (GTK_ACTION_BAR (footer), button); button = gtk_button_new_with_label ("Fullscreen"); gtk_action_bar_pack_end (GTK_ACTION_BAR (footer), button); g_signal_connect (button, "clicked", G_CALLBACK (toggle_fullscreen), window); gtk_box_pack_end (GTK_BOX (box), footer, FALSE, FALSE); content = gtk_image_new_from_icon_name ("start-here-symbolic", GTK_ICON_SIZE_DIALOG); gtk_image_set_pixel_size (GTK_IMAGE (content), 512); gtk_box_pack_start (GTK_BOX (box), content, FALSE, TRUE); gtk_widget_show_all (window); gtk_main (); gtk_widget_destroy (window); return 0; }
static gboolean glade_gtk_action_bar_verify_size (GObject *object, const GValue *value) { GList *child, *children; gint old_size, count = 0; gint new_size = g_value_get_int (value); children = gtk_container_get_children (GTK_CONTAINER (object)); children = g_list_remove (children, gtk_action_bar_get_center_widget (GTK_ACTION_BAR (object))); old_size = g_list_length (children); for (child = g_list_last (children); child && old_size > new_size; child = g_list_previous (child)) { GtkWidget *widget = child->data; if (glade_widget_get_from_gobject (widget) != NULL) count++; else old_size--; } g_list_free (children); return count > new_size ? FALSE : new_size >= 0; }
void glade_gtk_action_bar_remove_child (GladeWidgetAdaptor * adaptor, GObject * object, GObject * child) { GladeWidget *gbox; gint size; gchar *special_child_type; gbox = glade_widget_get_from_gobject (object); special_child_type = g_object_get_data (child, "special-child-type"); if (special_child_type && !strcmp (special_child_type, "center")) { GtkWidget *w; w = glade_placeholder_new (); g_object_set_data (G_OBJECT (w), "special-child-type", "center"); gtk_action_bar_set_center_widget (GTK_ACTION_BAR (object), w); return; } gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child)); if (!glade_widget_superuser ()) { glade_widget_property_get (gbox, "size", &size); glade_widget_property_set (gbox, "size", size); } }
static void glade_gtk_action_bar_set_size (GObject * object, const GValue * value) { GtkActionBar *box; GList *child, *children; guint new_size, old_size, i; box = GTK_ACTION_BAR (object); if (glade_util_object_is_loading (object)) return; children = gtk_container_get_children (GTK_CONTAINER (box)); children = g_list_remove (children, gtk_action_bar_get_center_widget (box)); old_size = g_list_length (children); new_size = g_value_get_int (value); if (old_size == new_size) { g_list_free (children); return; } /* Ensure placeholders first... */ for (i = 0; i < new_size; i++) { if (g_list_length (children) < (i + 1)) { GtkWidget *placeholder = glade_placeholder_new (); gint blank = glade_gtk_action_bar_get_first_blank (box); gtk_container_add (GTK_CONTAINER (box), placeholder); gtk_container_child_set (GTK_CONTAINER (box), placeholder, "position", blank, NULL); } } /* The box has shrunk. Remove the widgets that are on those slots */ for (child = g_list_last (children); child && old_size > new_size; child = g_list_previous (child)) { GtkWidget *child_widget = child->data; /* Refuse to remove any widgets that are either GladeWidget objects * or internal to the hierarchic entity (may be a composite widget, * not all internal widgets have GladeWidgets). */ if (glade_widget_get_from_gobject (child_widget) || GLADE_IS_PLACEHOLDER (child_widget) == FALSE) continue; gtk_container_remove (GTK_CONTAINER (box), child_widget); old_size--; } g_list_free (children); }
static gint glade_gtk_action_bar_get_num_children (GObject *box) { GList *children = gtk_container_get_children (GTK_CONTAINER (box)); gint retval = g_list_length (children); if (gtk_action_bar_get_center_widget (GTK_ACTION_BAR (box)) != NULL) retval -= 1; g_list_free (children); return retval; }
static void use_center_child_toggled (GtkWidget * widget, GladeActionBarEditor * box_editor) { GladeActionBarEditorPrivate *priv = box_editor->priv; GladeWidget *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (box_editor)); GladeWidget *gcenter = NULL; GtkWidget *box; GtkWidget *center; GladeProperty *property; gboolean use_center_child; if (glade_editable_loading (GLADE_EDITABLE (box_editor)) || !gwidget) return; /* Get new desired property state */ use_center_child = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->use_center_child)); /* Get any existing center child */ box = (GtkWidget *)glade_widget_get_object (gwidget); center = gtk_action_bar_get_center_widget (GTK_ACTION_BAR (box)); if (center && !GLADE_IS_PLACEHOLDER (center)) gcenter = glade_widget_get_from_gobject (center); glade_editable_block (GLADE_EDITABLE (box_editor)); if (use_center_child) glade_command_push_group (_("Setting %s to use a center child"), glade_widget_get_name (gwidget)); else glade_command_push_group (_("Setting %s to not use a center child"), glade_widget_get_name (gwidget)); /* If a project widget exists when were disabling center child, it needs * to be removed first as a part of the issuing GladeCommand group */ if (gcenter) { GList list; list.prev = list.next = NULL; list.data = gcenter; glade_command_delete (&list); } property = glade_widget_get_property (gwidget, "use-center-child"); glade_command_set_property (property, use_center_child); glade_command_pop_group (); glade_editable_unblock (GLADE_EDITABLE (box_editor)); /* reload buttons and sensitivity and stuff... */ glade_editable_load (GLADE_EDITABLE (box_editor), gwidget); }
void glade_gtk_action_bar_add_child (GladeWidgetAdaptor * adaptor, GObject * object, GObject * child) { GladeWidget *gbox, *gchild; gint num_children; gchar *special_child_type; gbox = glade_widget_get_from_gobject (object); special_child_type = g_object_get_data (child, "special-child-type"); if (special_child_type && !strcmp (special_child_type, "center")) { gtk_action_bar_set_center_widget (GTK_ACTION_BAR (object), GTK_WIDGET (child)); return; } /* Try to remove the last placeholder if any, this way GtkBox`s size will not be changed. */ if (!glade_widget_superuser () && !GLADE_IS_PLACEHOLDER (child)) { GList *l, *children; children = gtk_container_get_children (GTK_CONTAINER (object)); for (l = g_list_last (children); l; l = g_list_previous (l)) { GtkWidget *child_widget = l->data; if (GLADE_IS_PLACEHOLDER (child_widget)) { gtk_container_remove (GTK_CONTAINER (object), child_widget); break; } } g_list_free (children); } gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child)); num_children = glade_gtk_action_bar_get_num_children (object); glade_widget_property_set (gbox, "size", num_children); if (glade_widget_superuser ()) return; gchild = glade_widget_get_from_gobject (child); /* Packing props arent around when parenting during a glade_widget_dup() */ if (gchild && glade_widget_get_packing_properties (gchild)) glade_widget_pack_property_set (gchild, "position", num_children - 1); }
void glade_gtk_action_bar_get_property (GladeWidgetAdaptor * adaptor, GObject * object, const gchar * id, GValue * value) { if (!strcmp (id, "use-center-child")) { g_value_reset (value); g_value_set_boolean (value, gtk_action_bar_get_center_widget (GTK_ACTION_BAR (object)) != NULL); } else if (!strcmp (id, "size")) { g_value_reset (value); g_value_set_int (value, glade_gtk_action_bar_get_num_children (object)); } else GWA_GET_CLASS (GTK_TYPE_CONTAINER)->get_property (adaptor, object, id, value); }
static gint glade_gtk_action_bar_get_first_blank (GtkActionBar * box) { GList *child, *children; GladeWidget *gwidget; gint position; children = gtk_container_get_children (GTK_CONTAINER (box)); for (child = children, position = 0; child && child->data; child = child->next, position++) { GtkWidget *widget = child->data; if (widget == gtk_action_bar_get_center_widget (GTK_ACTION_BAR (box))) continue; if ((gwidget = glade_widget_get_from_gobject (widget)) != NULL) { gint gwidget_position = 0; GladeProperty *property = glade_widget_get_pack_property (gwidget, "position"); /* property can be NULL here when project is closing */ if (property) gwidget_position = g_value_get_int (glade_property_inline_value (property)); if (gwidget_position > position) break; } } g_list_free (children); return position; }
void glade_gtk_action_bar_replace_child (GladeWidgetAdaptor * adaptor, GObject * container, GObject * current, GObject * new_widget) { gint position; GtkPackType pack_type; gchar *special_child_type; special_child_type = g_object_get_data (G_OBJECT (current), "special-child-type"); if (special_child_type && !strcmp (special_child_type, "center")) { g_object_set_data (G_OBJECT (new_widget), "special-child-type", "center"); gtk_action_bar_set_center_widget (GTK_ACTION_BAR (container), GTK_WIDGET (new_widget)); return; } gtk_container_child_get (GTK_CONTAINER (container), GTK_WIDGET (current), "position", &position, "pack-type", &pack_type, NULL); gtk_container_remove (GTK_CONTAINER (container), GTK_WIDGET (current)); gtk_container_add (GTK_CONTAINER (container), GTK_WIDGET (new_widget)); gtk_container_child_set (GTK_CONTAINER (container), GTK_WIDGET (new_widget), "position", position, "pack-type", pack_type, NULL); }
GtkActionBar* cast_GtkActionBar(GtkWidget* widget) { return GTK_ACTION_BAR(widget); }
static void glade_gtk_action_bar_parse_finished (GladeProject * project, GObject * object) { GladeWidget *gbox; gbox = glade_widget_get_from_gobject (object); glade_widget_property_set (gbox, "use-center-child", gtk_action_bar_get_center_widget (GTK_ACTION_BAR (object)) != NULL); }
static void photos_selection_toolbar_init (PhotosSelectionToolbar *self) { PhotosSelectionToolbarPrivate *priv; GtkWidget *toolbar; self->priv = photos_selection_toolbar_get_instance_private (self); priv = self->priv; priv->item_listeners = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref); toolbar = gtk_action_bar_new (); gtk_container_add (GTK_CONTAINER (self), toolbar); priv->toolbar_favorite = gd_header_toggle_button_new (); gd_header_button_set_symbolic_icon_name (GD_HEADER_BUTTON (priv->toolbar_favorite), PHOTOS_ICON_FAVORITE_SYMBOLIC); gtk_action_bar_pack_start (GTK_ACTION_BAR (toolbar), priv->toolbar_favorite); g_signal_connect (priv->toolbar_favorite, "clicked", G_CALLBACK (photos_selection_toolbar_favorite_clicked), self); priv->toolbar_open = gd_header_simple_button_new (); gd_header_button_set_label (GD_HEADER_BUTTON (priv->toolbar_open), _("Open")); gtk_action_bar_pack_start (GTK_ACTION_BAR (toolbar), priv->toolbar_open); g_signal_connect (priv->toolbar_open, "clicked", G_CALLBACK (photos_selection_toolbar_open_clicked), self); priv->toolbar_print = gd_header_simple_button_new (); gd_header_button_set_label (GD_HEADER_BUTTON (priv->toolbar_print), _("Print")); gtk_action_bar_pack_start (GTK_ACTION_BAR (toolbar), priv->toolbar_print); g_signal_connect (priv->toolbar_print, "clicked", G_CALLBACK (photos_selection_toolbar_print_clicked), self); priv->toolbar_trash = gd_header_simple_button_new (); gd_header_button_set_label (GD_HEADER_BUTTON (priv->toolbar_trash), _("Delete")); gtk_action_bar_pack_start (GTK_ACTION_BAR (toolbar), priv->toolbar_trash); g_signal_connect (priv->toolbar_trash, "clicked", G_CALLBACK (photos_selection_toolbar_trash_clicked), self); priv->toolbar_properties = gd_header_simple_button_new (); gd_header_button_set_label (GD_HEADER_BUTTON (priv->toolbar_properties), _("Properties")); gtk_action_bar_pack_end (GTK_ACTION_BAR (toolbar), priv->toolbar_properties); g_signal_connect (priv->toolbar_properties, "clicked", G_CALLBACK (photos_selection_toolbar_properties_clicked), self); priv->toolbar_collection = gd_header_simple_button_new (); gd_header_button_set_label (GD_HEADER_BUTTON (priv->toolbar_collection), _("Add to Album")); gtk_action_bar_pack_end (GTK_ACTION_BAR (toolbar), priv->toolbar_collection); g_signal_connect (priv->toolbar_collection, "clicked", G_CALLBACK (photos_selection_toolbar_collection_clicked), self); gtk_widget_show_all (GTK_WIDGET (self)); priv->item_mngr = photos_item_manager_dup_singleton (); priv->sel_cntrlr = photos_selection_controller_dup_singleton (); g_signal_connect (priv->sel_cntrlr, "selection-changed", G_CALLBACK (photos_selection_toolbar_selection_changed), self); g_signal_connect (priv->sel_cntrlr, "selection-mode-changed", G_CALLBACK (photos_selection_toolbar_selection_mode_changed), self); }
static void photos_preview_nav_buttons_constructed (GObject *object) { PhotosPreviewNavButtons *self = PHOTOS_PREVIEW_NAV_BUTTONS (object); PhotosPreviewNavButtonsPrivate *priv = self->priv; GtkStyleContext *context; GtkWidget *button; GtkWidget *image; GtkWidget *toolbar; gboolean is_rtl; const gchar *next_icon_name; const gchar *prev_icon_name; G_OBJECT_CLASS (photos_preview_nav_buttons_parent_class)->constructed (object); is_rtl = (gtk_widget_get_direction (priv->preview_view) == GTK_TEXT_DIR_RTL); prev_icon_name = is_rtl ? PHOTOS_ICON_GO_NEXT_SYMBOLIC : PHOTOS_ICON_GO_PREVIOUS_SYMBOLIC; next_icon_name = is_rtl ? PHOTOS_ICON_GO_PREVIOUS_SYMBOLIC : PHOTOS_ICON_GO_NEXT_SYMBOLIC; priv->prev_widget = gtk_revealer_new (); gtk_widget_set_halign (priv->prev_widget, GTK_ALIGN_START); gtk_widget_set_margin_start (priv->prev_widget, 30); gtk_widget_set_margin_end (priv->prev_widget, 30); gtk_widget_set_valign (priv->prev_widget, GTK_ALIGN_CENTER); gtk_revealer_set_transition_type (GTK_REVEALER (priv->prev_widget), GTK_REVEALER_TRANSITION_TYPE_CROSSFADE); gtk_overlay_add_overlay (GTK_OVERLAY (priv->overlay), priv->prev_widget); image = gtk_image_new_from_icon_name (prev_icon_name, GTK_ICON_SIZE_INVALID); gtk_image_set_pixel_size (GTK_IMAGE (image), 16); button = gtk_button_new (); gtk_container_add (GTK_CONTAINER (button), image); context = gtk_widget_get_style_context (button); gtk_style_context_add_class (context, "osd"); gtk_container_add (GTK_CONTAINER (priv->prev_widget), button); g_signal_connect_swapped (button, "clicked", G_CALLBACK (photos_preview_nav_buttons_prev_clicked), self); 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); priv->next_widget = gtk_revealer_new (); gtk_widget_set_halign (priv->next_widget, GTK_ALIGN_END); gtk_widget_set_margin_start (priv->next_widget, 30); gtk_widget_set_margin_end (priv->next_widget, 30); gtk_widget_set_valign (priv->next_widget, GTK_ALIGN_CENTER); gtk_revealer_set_transition_type (GTK_REVEALER (priv->next_widget), GTK_REVEALER_TRANSITION_TYPE_CROSSFADE); gtk_overlay_add_overlay (GTK_OVERLAY (priv->overlay), priv->next_widget); image = gtk_image_new_from_icon_name (next_icon_name, GTK_ICON_SIZE_INVALID); gtk_image_set_pixel_size (GTK_IMAGE (image), 16); button = gtk_button_new (); gtk_container_add (GTK_CONTAINER (button), image); context = gtk_widget_get_style_context (button); gtk_style_context_add_class (context, "osd"); gtk_container_add (GTK_CONTAINER (priv->next_widget), button); g_signal_connect_swapped (button, "clicked", G_CALLBACK (photos_preview_nav_buttons_next_clicked), self); 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); priv->toolbar_widget = gtk_revealer_new (); gtk_widget_set_halign (priv->toolbar_widget, GTK_ALIGN_FILL); gtk_widget_set_valign (priv->toolbar_widget, GTK_ALIGN_END); gtk_revealer_set_transition_type (GTK_REVEALER (priv->toolbar_widget), GTK_REVEALER_TRANSITION_TYPE_CROSSFADE); gtk_overlay_add_overlay (GTK_OVERLAY (priv->overlay), priv->toolbar_widget); toolbar = gtk_action_bar_new (); context = gtk_widget_get_style_context (toolbar); gtk_style_context_add_class (context, "osd"); gtk_container_add (GTK_CONTAINER (priv->toolbar_widget), toolbar); g_signal_connect_swapped (toolbar, "enter-notify-event", G_CALLBACK (photos_preview_nav_buttons_enter_notify), self); g_signal_connect_swapped (toolbar, "leave-notify-event", G_CALLBACK (photos_preview_nav_buttons_leave_notify), self); priv->favorite_button = gd_header_toggle_button_new (); gd_header_button_set_symbolic_icon_name (GD_HEADER_BUTTON (priv->favorite_button), PHOTOS_ICON_FAVORITE_SYMBOLIC); gtk_action_bar_pack_end (GTK_ACTION_BAR (toolbar), priv->favorite_button); g_signal_connect_swapped (priv->favorite_button, "clicked", G_CALLBACK (photos_preview_nav_buttons_favorite_clicked), self); g_signal_connect_swapped (priv->overlay, "motion-notify-event", G_CALLBACK (photos_preview_nav_buttons_motion_notify), self); }
static void photos_selection_toolbar_init (PhotosSelectionToolbar *self) { PhotosSelectionToolbarPrivate *priv; GApplication *app; GtkWidget *toolbar; PhotosSearchContextState *state; self->priv = photos_selection_toolbar_get_instance_private (self); priv = self->priv; app = g_application_get_default (); state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app)); priv->item_listeners = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref); toolbar = gtk_action_bar_new (); gtk_container_add (GTK_CONTAINER (self), toolbar); priv->toolbar_favorite = gtk_button_new (); gtk_action_bar_pack_start (GTK_ACTION_BAR (toolbar), priv->toolbar_favorite); g_signal_connect (priv->toolbar_favorite, "clicked", G_CALLBACK (photos_selection_toolbar_favorite_clicked), self); priv->toolbar_open = gtk_button_new_with_label (_("Open")); gtk_action_bar_pack_start (GTK_ACTION_BAR (toolbar), priv->toolbar_open); g_signal_connect (priv->toolbar_open, "clicked", G_CALLBACK (photos_selection_toolbar_open_clicked), self); priv->toolbar_print = gtk_button_new_with_label (_("Print")); gtk_action_bar_pack_start (GTK_ACTION_BAR (toolbar), priv->toolbar_print); g_signal_connect (priv->toolbar_print, "clicked", G_CALLBACK (photos_selection_toolbar_print_clicked), self); priv->toolbar_trash = gtk_button_new_with_label (_("Delete")); gtk_action_bar_pack_start (GTK_ACTION_BAR (toolbar), priv->toolbar_trash); g_signal_connect (priv->toolbar_trash, "clicked", G_CALLBACK (photos_selection_toolbar_trash_clicked), self); priv->toolbar_properties = gtk_button_new_with_label (_("Properties")); gtk_action_bar_pack_end (GTK_ACTION_BAR (toolbar), priv->toolbar_properties); g_signal_connect (priv->toolbar_properties, "clicked", G_CALLBACK (photos_selection_toolbar_properties_clicked), self); priv->toolbar_collection = gtk_button_new_with_label (_("Add to Album")); gtk_action_bar_pack_end (GTK_ACTION_BAR (toolbar), priv->toolbar_collection); g_signal_connect (priv->toolbar_collection, "clicked", G_CALLBACK (photos_selection_toolbar_collection_clicked), self); gtk_widget_show_all (GTK_WIDGET (self)); priv->item_mngr = g_object_ref (state->item_mngr); priv->sel_cntrlr = photos_selection_controller_dup_singleton (); g_signal_connect (priv->sel_cntrlr, "selection-changed", G_CALLBACK (photos_selection_toolbar_selection_changed), self); g_signal_connect (priv->sel_cntrlr, "selection-mode-changed", G_CALLBACK (photos_selection_toolbar_selection_mode_changed), self); }