[libgda] Added gdaui_bar_add_button_from_stock()
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Added gdaui_bar_add_button_from_stock()
- Date: Wed, 22 Aug 2012 19:52:58 +0000 (UTC)
commit 5a311d7ed09613643afd5ee92fe63d483d482421
Author: Vivien Malerba <malerba gnome-db org>
Date: Wed Aug 22 15:40:46 2012 +0200
Added gdaui_bar_add_button_from_stock()
control-center/gdaui-bar.c | 57 ++++++++++++++++++++-
control-center/gdaui-bar.h | 19 ++++----
tools/browser/data-manager/data-console.c | 6 +--
tools/browser/schema-browser/objects-index.c | 6 +--
tools/browser/schema-browser/relations-diagram.c | 6 +--
5 files changed, 67 insertions(+), 27 deletions(-)
---
diff --git a/control-center/gdaui-bar.c b/control-center/gdaui-bar.c
index 88f1710..6008c29 100644
--- a/control-center/gdaui-bar.c
+++ b/control-center/gdaui-bar.c
@@ -125,9 +125,8 @@ gdaui_bar_init (GdauiBar *bar)
gtk_widget_show (content_area);
gtk_box_pack_start (GTK_BOX (bar), content_area, TRUE, TRUE, 0);
- action_area = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
+ action_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_show (action_area);
- gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
gtk_box_pack_start (GTK_BOX (bar), action_area, FALSE, TRUE, 0);
gtk_widget_set_app_paintable (widget, TRUE);
@@ -160,7 +159,7 @@ gdaui_bar_init (GdauiBar *bar)
GtkStyleContext *context;
GtkStyleProvider *provider;
#define CSS ".gdauibar {\n" \
- "background-color: #b3b3b3;\n" \
+ "background-color: #b3b3b3;\n" \
"padding: 5px;\n" \
"}"
context = gtk_widget_get_style_context (GTK_WIDGET (bar));
@@ -437,3 +436,55 @@ gdaui_bar_get_show_icon (GdauiBar *bar)
return bar->priv->show_icon;
}
+
+/**
+ * gdaui_bar_add_button_from_stock:
+ * @bar: a #GdauiBar
+ * @stock_id: the stock name of the button to add
+ *
+ * Returns: (transfer none): the created #GtkButton
+ */
+GtkWidget *
+gdaui_bar_add_button_from_stock (GdauiBar *bar, const gchar *stock_id)
+{
+ g_return_val_if_fail (GDAUI_IS_BAR (bar), NULL);
+ g_return_val_if_fail (stock_id && *stock_id, NULL);
+
+ GtkWidget *vb, *button, *img;
+
+ vb = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
+ gtk_button_box_set_layout (GTK_BUTTON_BOX (vb), GTK_BUTTONBOX_CENTER);
+ gtk_box_pack_start (GTK_BOX (bar->priv->action_area), vb, FALSE, FALSE, 0);
+
+ button = gtk_button_new ();
+ img = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
+ gtk_container_add (GTK_CONTAINER (button), img);
+ gtk_box_pack_start (GTK_BOX (vb), button, FALSE, FALSE, 0);
+ g_object_set (G_OBJECT (button), "label", NULL, NULL);
+
+ /* CSS theming */
+ GtkStyleContext *context;
+ GtkStyleProvider *provider;
+#define BUTTON_CSS "* {\n" \
+ "-GtkButton-default-border : 0px;\n" \
+ "-GtkButton-default-outside-border : 0px;\n" \
+ "-GtkWidget-focus-line-width : 0px;\n" \
+ "-GtkWidget-focus-padding : 0px;\n" \
+ "padding: 0px;\n" \
+ "-GtkButtonBox-child-internal-pad-x : 1px;\n" \
+ "-GtkButtonBox-child-min-width : 0px;\n" \
+ "border-style: none;\n" \
+ "}"
+ provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
+ gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (provider), BUTTON_CSS, -1, NULL);
+ context = gtk_widget_get_style_context (vb);
+ gtk_style_context_add_provider (context, provider, G_MAXUINT);
+ context = gtk_widget_get_style_context (button);
+ gtk_style_context_add_provider (context, provider, G_MAXUINT);
+ context = gtk_widget_get_style_context (img);
+ gtk_style_context_add_provider (context, provider, G_MAXUINT);
+ g_object_unref (provider);
+
+ gtk_widget_show_all (vb);
+ return button;
+}
diff --git a/control-center/gdaui-bar.h b/control-center/gdaui-bar.h
index c77f342..becb4cb 100644
--- a/control-center/gdaui-bar.h
+++ b/control-center/gdaui-bar.h
@@ -52,15 +52,16 @@ struct _GdauiBarClass
GtkBoxClass parent_class;
};
-GType gdaui_bar_get_type (void) G_GNUC_CONST;
-GtkWidget *gdaui_bar_new (const gchar *text);
-const gchar *gdaui_bar_get_text (GdauiBar *bar);
-void gdaui_bar_set_text (GdauiBar *bar, const gchar *text);
-void gdaui_bar_set_icon_from_pixbuf (GdauiBar *bar, GdkPixbuf *pixbuf);
-void gdaui_bar_set_icon_from_file (GdauiBar *bar, const gchar *file);
-void gdaui_bar_set_icon_from_stock (GdauiBar *bar, const gchar *stock_id, GtkIconSize size);
-void gdaui_bar_set_show_icon (GdauiBar *bar, gboolean show);
-gboolean gdaui_bar_get_show_icon (GdauiBar *bar);
+GType gdaui_bar_get_type (void) G_GNUC_CONST;
+GtkWidget *gdaui_bar_new (const gchar *text);
+const gchar *gdaui_bar_get_text (GdauiBar *bar);
+void gdaui_bar_set_text (GdauiBar *bar, const gchar *text);
+void gdaui_bar_set_icon_from_pixbuf (GdauiBar *bar, GdkPixbuf *pixbuf);
+void gdaui_bar_set_icon_from_file (GdauiBar *bar, const gchar *file);
+void gdaui_bar_set_icon_from_stock (GdauiBar *bar, const gchar *stock_id, GtkIconSize size);
+void gdaui_bar_set_show_icon (GdauiBar *bar, gboolean show);
+gboolean gdaui_bar_get_show_icon (GdauiBar *bar);
+GtkWidget *gdaui_bar_add_button_from_stock (GdauiBar *bar, const gchar *stock_id);
G_END_DECLS
diff --git a/tools/browser/data-manager/data-console.c b/tools/browser/data-manager/data-console.c
index 8a10d6b..dbb327d 100644
--- a/tools/browser/data-manager/data-console.c
+++ b/tools/browser/data-manager/data-console.c
@@ -305,11 +305,7 @@ data_console_new (BrowserConnection *bcnc)
gtk_widget_show (label);
dconsole->priv->header = GDAUI_BAR (label);
- wid = gtk_button_new ();
- label = gtk_image_new_from_stock (GTK_STOCK_SAVE, GTK_ICON_SIZE_BUTTON);
- gtk_container_add (GTK_CONTAINER (wid), label);
- gtk_box_pack_start (GTK_BOX (hbox), wid, FALSE, FALSE, 0);
- g_object_set (G_OBJECT (wid), "label", NULL, NULL);
+ wid = gdaui_bar_add_button_from_stock (GDAUI_BAR (label), GTK_STOCK_SAVE);
dconsole->priv->save_button = wid;
g_signal_connect (wid, "clicked",
diff --git a/tools/browser/schema-browser/objects-index.c b/tools/browser/schema-browser/objects-index.c
index becb9f5..921fcca 100644
--- a/tools/browser/schema-browser/objects-index.c
+++ b/tools/browser/schema-browser/objects-index.c
@@ -186,11 +186,7 @@ objects_index_new (BrowserConnection *bcnc)
G_CALLBACK (cloud_object_selected_cb), index);
/* find button */
- wid = gtk_button_new ();
- label = gtk_image_new_from_stock (GTK_STOCK_FIND, GTK_ICON_SIZE_BUTTON);
- gtk_container_add (GTK_CONTAINER (wid), label);
- gtk_box_pack_start (GTK_BOX (hbox), wid, FALSE, FALSE, 0);
- g_object_set (G_OBJECT (wid), "label", NULL, NULL);
+ wid = gdaui_bar_add_button_from_stock (GDAUI_BAR (label), GTK_STOCK_FIND);
GtkWidget *popup;
popup = popup_container_new (wid);
diff --git a/tools/browser/schema-browser/relations-diagram.c b/tools/browser/schema-browser/relations-diagram.c
index 597ec4e..24059aa 100644
--- a/tools/browser/schema-browser/relations-diagram.c
+++ b/tools/browser/schema-browser/relations-diagram.c
@@ -332,11 +332,7 @@ relations_diagram_new (BrowserConnection *bcnc)
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
diagram->priv->header = GDAUI_BAR (label);
- wid = gtk_button_new ();
- label = gtk_image_new_from_stock (GTK_STOCK_SAVE, GTK_ICON_SIZE_BUTTON);
- gtk_container_add (GTK_CONTAINER (wid), label);
- gtk_box_pack_start (GTK_BOX (hbox), wid, FALSE, FALSE, 0);
- g_object_set (G_OBJECT (wid), "label", NULL, NULL);
+ wid = gdaui_bar_add_button_from_stock (GDAUI_BAR (label), GTK_STOCK_SAVE);
diagram->priv->save_button = wid;
g_signal_connect (wid, "clicked",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]