[gimp/gtk3-port: 162/224] libgimpwidgets: move all GimpBrowser members to a private struct
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gtk3-port: 162/224] libgimpwidgets: move all GimpBrowser members to a private struct
- Date: Sat, 10 Dec 2011 21:31:41 +0000 (UTC)
commit 12b14ec3a7e7c60e9a24ff6b42709f6c1d2d7b36
Author: Michael Natterer <mitch gimp org>
Date: Fri Dec 31 18:19:37 2010 +0100
libgimpwidgets: move all GimpBrowser members to a private struct
The newly added API is ugly and will change.
libgimp/gimpprocbrowserdialog.c | 12 +-
libgimpwidgets/gimpbrowser.c | 218 ++++++++++++++++++++++++++++----------
libgimpwidgets/gimpbrowser.h | 40 +++----
plug-ins/common/plugin-browser.c | 6 +-
4 files changed, 187 insertions(+), 89 deletions(-)
---
diff --git a/libgimp/gimpprocbrowserdialog.c b/libgimp/gimpprocbrowserdialog.c
index a7b5ca0..e9f96c0 100644
--- a/libgimp/gimpprocbrowserdialog.c
+++ b/libgimp/gimpprocbrowserdialog.c
@@ -171,7 +171,7 @@ gimp_proc_browser_dialog_init (GimpProcBrowserDialog *dialog)
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_ALWAYS);
- gtk_box_pack_start (GTK_BOX (GIMP_BROWSER (dialog->browser)->left_vbox),
+ gtk_box_pack_start (GTK_BOX (gimp_browser_get_left_vbox (GIMP_BROWSER (dialog->browser))),
scrolled_window, TRUE, TRUE, 0);
gtk_widget_show (scrolled_window);
@@ -202,10 +202,10 @@ gimp_proc_browser_dialog_init (GimpProcBrowserDialog *dialog)
G_CALLBACK (browser_selection_changed),
dialog);
- parent = gtk_widget_get_parent (GIMP_BROWSER (dialog->browser)->right_vbox);
+ parent = gtk_widget_get_parent (gimp_browser_get_right_vbox (GIMP_BROWSER (dialog->browser)));
parent = gtk_widget_get_parent (parent);
- gtk_widget_set_size_request (parent, DBL_WIDTH - DBL_LIST_WIDTH, -1);
+ gtk_widget_set_size_request (parent, DBL_WIDTH - DBL_LIST_WIDTH, -1);
}
@@ -393,8 +393,8 @@ browser_search (GimpBrowser *browser,
gimp_browser_show_message (browser, _("No matches"));
- gtk_label_set_text (GTK_LABEL (browser->count_label),
- _("Search term invalid or incomplete"));
+ gimp_browser_set_search_summary (browser,
+ _("Search term invalid or incomplete"));
return;
}
@@ -500,7 +500,7 @@ browser_search (GimpBrowser *browser,
}
}
- gtk_label_set_text (GTK_LABEL (browser->count_label), str);
+ gimp_browser_set_search_summary (browser, str);
g_free (str);
if (num_procs > 0)
diff --git a/libgimpwidgets/gimpbrowser.c b/libgimpwidgets/gimpbrowser.c
index b3653b7..89e6a0e 100644
--- a/libgimpwidgets/gimpbrowser.c
+++ b/libgimpwidgets/gimpbrowser.c
@@ -49,6 +49,29 @@ enum
};
+typedef struct _GimpBrowserPrivate GimpBrowserPrivate;
+
+struct _GimpBrowserPrivate
+{
+ GtkWidget *left_vbox;
+
+ GtkWidget *search_entry;
+ guint search_timeout_id;
+
+ GtkWidget *search_type_combo;
+ gint search_type;
+
+ GtkWidget *count_label;
+
+ GtkWidget *right_vbox;
+ GtkWidget *right_widget;
+};
+
+#define GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE (obj, \
+ GIMP_TYPE_BROWSER, \
+ GimpBrowserPrivate)
+
+
static void gimp_browser_dispose (GObject *object);
static void gimp_browser_combo_changed (GtkComboBox *combo,
@@ -62,7 +85,7 @@ static void gimp_browser_entry_icon_press (GtkEntry *entry,
static gboolean gimp_browser_search_timeout (gpointer data);
-G_DEFINE_TYPE (GimpBrowser, gimp_browser, GTK_TYPE_HPANED)
+G_DEFINE_TYPE (GimpBrowser, gimp_browser, GTK_TYPE_PANED)
#define parent_class gimp_browser_parent_class
@@ -88,62 +111,68 @@ gimp_browser_class_init (GimpBrowserClass *klass)
object_class->dispose = gimp_browser_dispose;
klass->search = NULL;
+
+ g_type_class_add_private (object_class, sizeof (GimpBrowserPrivate));
}
static void
gimp_browser_init (GimpBrowser *browser)
{
- GtkWidget *hbox;
- GtkWidget *label;
- GtkWidget *scrolled_window;
+ GimpBrowserPrivate *private = GET_PRIVATE (browser);
+ GtkWidget *hbox;
+ GtkWidget *label;
+ GtkWidget *scrolled_window;
- browser->search_type = -1;
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (browser),
+ GTK_ORIENTATION_HORIZONTAL);
- browser->left_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
- gtk_paned_pack1 (GTK_PANED (browser), browser->left_vbox, FALSE, TRUE);
- gtk_widget_show (browser->left_vbox);
+ private->search_type = -1;
+
+ private->left_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+ gtk_paned_pack1 (GTK_PANED (browser), private->left_vbox, FALSE, TRUE);
+ gtk_widget_show (private->left_vbox);
/* search entry */
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
- gtk_box_pack_start (GTK_BOX (browser->left_vbox), hbox, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (private->left_vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
label = gtk_label_new_with_mnemonic (_("_Search:"));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
- browser->search_entry = gtk_entry_new ();
- gtk_box_pack_start (GTK_BOX (hbox), browser->search_entry, TRUE, TRUE, 0);
- gtk_widget_show (browser->search_entry);
+ private->search_entry = gtk_entry_new ();
+ gtk_box_pack_start (GTK_BOX (hbox), private->search_entry, TRUE, TRUE, 0);
+ gtk_widget_show (private->search_entry);
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), browser->search_entry);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), private->search_entry);
- g_signal_connect (browser->search_entry, "changed",
+ g_signal_connect (private->search_entry, "changed",
G_CALLBACK (gimp_browser_entry_changed),
browser);
- gtk_entry_set_icon_from_stock (GTK_ENTRY (browser->search_entry),
+ gtk_entry_set_icon_from_stock (GTK_ENTRY (private->search_entry),
GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
- gtk_entry_set_icon_activatable (GTK_ENTRY (browser->search_entry),
+ gtk_entry_set_icon_activatable (GTK_ENTRY (private->search_entry),
GTK_ENTRY_ICON_SECONDARY, TRUE);
- gtk_entry_set_icon_sensitive (GTK_ENTRY (browser->search_entry),
+ gtk_entry_set_icon_sensitive (GTK_ENTRY (private->search_entry),
GTK_ENTRY_ICON_SECONDARY, FALSE);
- g_signal_connect (browser->search_entry, "icon-press",
+ g_signal_connect (private->search_entry, "icon-press",
G_CALLBACK (gimp_browser_entry_icon_press),
browser);
/* count label */
- browser->count_label = gtk_label_new (_("No matches"));
- gtk_misc_set_alignment (GTK_MISC (browser->count_label), 0.0, 0.5);
- gimp_label_set_attributes (GTK_LABEL (browser->count_label),
+ private->count_label = gtk_label_new (_("No matches"));
+ gtk_misc_set_alignment (GTK_MISC (private->count_label), 0.0, 0.5);
+ gimp_label_set_attributes (GTK_LABEL (private->count_label),
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
-1);
- gtk_box_pack_end (GTK_BOX (browser->left_vbox), browser->count_label,
+ gtk_box_pack_end (GTK_BOX (private->left_vbox), private->count_label,
FALSE, FALSE, 0);
- gtk_widget_show (browser->count_label);
+ gtk_widget_show (private->count_label);
/* scrolled window */
@@ -154,24 +183,24 @@ gimp_browser_init (GimpBrowser *browser)
gtk_paned_pack2 (GTK_PANED (browser), scrolled_window, TRUE, TRUE);
gtk_widget_show (scrolled_window);
- browser->right_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_container_set_border_width (GTK_CONTAINER (browser->right_vbox), 12);
+ private->right_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (private->right_vbox), 12);
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window),
- browser->right_vbox);
- gtk_widget_show (browser->right_vbox);
+ private->right_vbox);
+ gtk_widget_show (private->right_vbox);
- gtk_widget_grab_focus (browser->search_entry);
+ gtk_widget_grab_focus (private->search_entry);
}
static void
gimp_browser_dispose (GObject *object)
{
- GimpBrowser *browser = GIMP_BROWSER (object);
+ GimpBrowserPrivate *private = GET_PRIVATE (object);
- if (browser->search_timeout_id)
+ if (private->search_timeout_id)
{
- g_source_remove (browser->search_timeout_id);
- browser->search_timeout_id = 0;
+ g_source_remove (private->search_timeout_id);
+ private->search_timeout_id = 0;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
@@ -213,10 +242,14 @@ gimp_browser_add_search_types (GimpBrowser *browser,
gint first_type_id,
...)
{
+ GimpBrowserPrivate *private;
+
g_return_if_fail (GIMP_IS_BROWSER (browser));
g_return_if_fail (first_type_label != NULL);
- if (! browser->search_type_combo)
+ private = GET_PRIVATE (browser);
+
+ if (! private->search_type_combo)
{
GtkWidget *combo;
va_list args;
@@ -229,17 +262,17 @@ gimp_browser_add_search_types (GimpBrowser *browser,
gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (combo), FALSE);
- browser->search_type_combo = combo;
- browser->search_type = first_type_id;
+ private->search_type_combo = combo;
+ private->search_type = first_type_id;
- gtk_box_pack_end (GTK_BOX (gtk_widget_get_parent (browser->search_entry)),
+ gtk_box_pack_end (GTK_BOX (gtk_widget_get_parent (private->search_entry)),
combo, FALSE, FALSE, 0);
gtk_widget_show (combo);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
- browser->search_type,
+ private->search_type,
G_CALLBACK (gimp_int_combo_box_get_active),
- &browser->search_type);
+ &private->search_type);
g_signal_connect (combo, "changed",
G_CALLBACK (gimp_browser_combo_changed),
@@ -247,13 +280,76 @@ gimp_browser_add_search_types (GimpBrowser *browser,
}
else
{
- gimp_int_combo_box_append (GIMP_INT_COMBO_BOX (browser->search_type_combo),
+ gimp_int_combo_box_append (GIMP_INT_COMBO_BOX (private->search_type_combo),
first_type_label, first_type_id,
NULL);
}
}
/**
+ * gimp_browser_get_left_vbox:
+ * @browser: a #GimpBrowser widget
+ *
+ * Returns: The left vbox.
+ *
+ * Since: GIMP 3.0
+ **/
+GtkWidget *
+gimp_browser_get_left_vbox (GimpBrowser *browser)
+{
+ GimpBrowserPrivate *private;
+
+ g_return_val_if_fail (GIMP_IS_BROWSER (browser), NULL);
+
+ private = GET_PRIVATE (browser);
+
+ return private->left_vbox;
+}
+
+/**
+ * gimp_browser_get_right_vbox:
+ * @browser: a #GimpBrowser widget
+ *
+ * Returns: The right vbox.
+ *
+ * Since: GIMP 3.0
+ **/
+GtkWidget *
+gimp_browser_get_right_vbox (GimpBrowser *browser)
+{
+ GimpBrowserPrivate *private;
+
+ g_return_val_if_fail (GIMP_IS_BROWSER (browser), NULL);
+
+ private = GET_PRIVATE (browser);
+
+ return private->right_vbox;
+}
+
+/**
+ * gimp_browser_set_search_summary:
+ * @browser: a #GimpBrowser widget
+ * @summary: a string describing the search result
+ *
+ * Sets the search summary text.
+ *
+ * Since: GIMP 3.0
+ **/
+void
+gimp_browser_set_search_summary (GimpBrowser *browser,
+ const gchar *summary)
+{
+ GimpBrowserPrivate *private;
+
+ g_return_if_fail (GIMP_IS_BROWSER (browser));
+ g_return_if_fail (summary != NULL);
+
+ private = GET_PRIVATE (browser);
+
+ gtk_label_set_text (GTK_LABEL (private->count_label), summary);
+}
+
+/**
* gimp_browser_set_widget:
* @browser: a #GimpBrowser widget
* @widget: a #GtkWidget
@@ -266,21 +362,25 @@ void
gimp_browser_set_widget (GimpBrowser *browser,
GtkWidget *widget)
{
+ GimpBrowserPrivate *private;
+
g_return_if_fail (GIMP_IS_BROWSER (browser));
g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
- if (widget == browser->right_widget)
+ private = GET_PRIVATE (browser);
+
+ if (widget == private->right_widget)
return;
- if (browser->right_widget)
- gtk_container_remove (GTK_CONTAINER (browser->right_vbox),
- browser->right_widget);
+ if (private->right_widget)
+ gtk_container_remove (GTK_CONTAINER (private->right_vbox),
+ private->right_widget);
- browser->right_widget = widget;
+ private->right_widget = widget;
if (widget)
{
- gtk_box_pack_start (GTK_BOX (browser->right_vbox), widget,
+ gtk_box_pack_start (GTK_BOX (private->right_vbox), widget,
FALSE, FALSE, 0);
gtk_widget_show (widget);
}
@@ -301,12 +401,16 @@ void
gimp_browser_show_message (GimpBrowser *browser,
const gchar *message)
{
+ GimpBrowserPrivate *private;
+
g_return_if_fail (GIMP_IS_BROWSER (browser));
g_return_if_fail (message != NULL);
- if (GTK_IS_LABEL (browser->right_widget))
+ private = GET_PRIVATE (browser);
+
+ if (GTK_IS_LABEL (private->right_widget))
{
- gtk_label_set_text (GTK_LABEL (browser->right_widget), message);
+ gtk_label_set_text (GTK_LABEL (private->right_widget), message);
}
else
{
@@ -328,10 +432,12 @@ gimp_browser_show_message (GimpBrowser *browser,
static void
gimp_browser_queue_search (GimpBrowser *browser)
{
- if (browser->search_timeout_id)
- g_source_remove (browser->search_timeout_id);
+ GimpBrowserPrivate *private = GET_PRIVATE (browser);
+
+ if (private->search_timeout_id)
+ g_source_remove (private->search_timeout_id);
- browser->search_timeout_id =
+ private->search_timeout_id =
g_timeout_add (100, gimp_browser_search_timeout, browser);
}
@@ -370,20 +476,20 @@ gimp_browser_entry_icon_press (GtkEntry *entry,
static gboolean
gimp_browser_search_timeout (gpointer data)
{
- GimpBrowser *browser = GIMP_BROWSER (data);
- const gchar *search_string;
+ GimpBrowserPrivate *private = GET_PRIVATE (data);
+ const gchar *search_string;
GDK_THREADS_ENTER();
- search_string = gtk_entry_get_text (GTK_ENTRY (browser->search_entry));
+ search_string = gtk_entry_get_text (GTK_ENTRY (private->search_entry));
if (! search_string)
search_string = "";
- g_signal_emit (browser, browser_signals[SEARCH], 0,
- search_string, browser->search_type);
+ g_signal_emit (data, browser_signals[SEARCH], 0,
+ search_string, private->search_type);
- browser->search_timeout_id = 0;
+ private->search_timeout_id = 0;
GDK_THREADS_LEAVE();
diff --git a/libgimpwidgets/gimpbrowser.h b/libgimpwidgets/gimpbrowser.h
index 0837aa6..af8b60c 100644
--- a/libgimpwidgets/gimpbrowser.h
+++ b/libgimpwidgets/gimpbrowser.h
@@ -43,25 +43,12 @@ typedef struct _GimpBrowserClass GimpBrowserClass;
struct _GimpBrowser
{
- GtkHPaned parent_instance;
-
- GtkWidget *left_vbox;
-
- GtkWidget *search_entry;
- guint search_timeout_id;
-
- GtkWidget *search_type_combo;
- gint search_type;
-
- GtkWidget *count_label;
-
- GtkWidget *right_vbox;
- GtkWidget *right_widget;
+ GtkPaned parent_instance;
};
struct _GimpBrowserClass
{
- GtkHPanedClass parent_class;
+ GtkPanedClass parent_class;
void (* search) (GimpBrowser *browser,
const gchar *search_string,
@@ -77,17 +64,22 @@ struct _GimpBrowserClass
GType gimp_browser_get_type (void) G_GNUC_CONST;
-GtkWidget * gimp_browser_new (void);
+GtkWidget * gimp_browser_new (void);
+
+void gimp_browser_add_search_types (GimpBrowser *browser,
+ const gchar *first_type_label,
+ gint first_type_id,
+ ...) G_GNUC_NULL_TERMINATED;
-void gimp_browser_add_search_types (GimpBrowser *browser,
- const gchar *first_type_label,
- gint first_type_id,
- ...) G_GNUC_NULL_TERMINATED;
+GtkWidget * gimp_browser_get_left_vbox (GimpBrowser *browser);
+GtkWidget * gimp_browser_get_right_vbox (GimpBrowser *browser);
-void gimp_browser_set_widget (GimpBrowser *browser,
- GtkWidget *widget);
-void gimp_browser_show_message (GimpBrowser *browser,
- const gchar *message);
+void gimp_browser_set_search_summary (GimpBrowser *browser,
+ const gchar *summary);
+void gimp_browser_set_widget (GimpBrowser *browser,
+ GtkWidget *widget);
+void gimp_browser_show_message (GimpBrowser *browser,
+ const gchar *message);
G_END_DECLS
diff --git a/plug-ins/common/plugin-browser.c b/plug-ins/common/plugin-browser.c
index 7184f83..91810d4 100644
--- a/plug-ins/common/plugin-browser.c
+++ b/plug-ins/common/plugin-browser.c
@@ -393,7 +393,7 @@ browser_search (GimpBrowser *gimp_browser,
}
}
- gtk_label_set_text (GTK_LABEL (gimp_browser->count_label), str);
+ gimp_browser_set_search_summary (gimp_browser, str);
g_free (str);
list_store = GTK_LIST_STORE (gtk_tree_view_get_model (browser->list_view));
@@ -568,7 +568,7 @@ browser_dialog_new (void)
/* left = notebook */
notebook = gtk_notebook_new ();
- gtk_box_pack_start (GTK_BOX (GIMP_BROWSER (browser->browser)->left_vbox),
+ gtk_box_pack_start (GTK_BOX (gimp_browser_get_left_vbox (GIMP_BROWSER (browser->browser))),
notebook, TRUE, TRUE, 0);
/* list : list in a scrolled_win */
@@ -706,7 +706,7 @@ browser_dialog_new (void)
gtk_widget_show (scrolled_window);
gtk_widget_show (notebook);
- parent = gtk_widget_get_parent (GIMP_BROWSER (browser->browser)->right_vbox);
+ parent = gtk_widget_get_parent (gimp_browser_get_right_vbox (GIMP_BROWSER (browser->browser)));
parent = gtk_widget_get_parent (parent);
gtk_widget_set_size_request (parent, DBL_WIDTH - DBL_LIST_WIDTH, -1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]