moved all instance members to a private struct.

2005-07-08  Michael Natterer  <mitch@gimp.org>

	* libgimpwidgets/gimppageselector.[ch]: moved all instance members
	to a private struct.
This commit is contained in:
Michael Natterer 2005-07-08 13:25:57 +00:00 committed by Michael Natterer
parent 2a5be9758e
commit 0cf2783cc4
3 changed files with 250 additions and 172 deletions

View File

@ -1,3 +1,8 @@
2005-07-08 Michael Natterer <mitch@gimp.org>
* libgimpwidgets/gimppageselector.[ch]: moved all instance members
to a private struct.
2005-07-08 Michael Natterer <mitch@gimp.org> 2005-07-08 Michael Natterer <mitch@gimp.org>
* libgimpwidgets/gimppageselector.[ch]: fixed horizontal layout to * libgimpwidgets/gimppageselector.[ch]: fixed horizontal layout to

View File

@ -58,6 +58,28 @@ enum
}; };
typedef struct _GimpPageSelectorPrivate GimpPageSelectorPrivate;
struct _GimpPageSelectorPrivate
{
gint n_pages;
GimpPageSelectorTarget target;
GtkListStore *store;
GtkWidget *view;
GtkWidget *range_entry;
GdkPixbuf *thumbnail;
gint default_item_width;
gint max_item_width;
guint item_width_idle_id;
};
#define GIMP_PAGE_SELECTOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIMP_TYPE_PAGE_SELECTOR, GimpPageSelectorPrivate))
static void gimp_page_selector_class_init (GimpPageSelectorClass *klass); static void gimp_page_selector_class_init (GimpPageSelectorClass *klass);
static void gimp_page_selector_init (GimpPageSelector *selector); static void gimp_page_selector_init (GimpPageSelector *selector);
@ -153,7 +175,7 @@ gimp_page_selector_class_init (GimpPageSelectorClass *klass)
G_TYPE_NONE, 0); G_TYPE_NONE, 0);
/** /**
* GimpPageSelector:n_pages: * GimpPageSelector::n_pages:
* *
* The number of pages of the document to open. * The number of pages of the document to open.
* *
@ -165,7 +187,7 @@ gimp_page_selector_class_init (GimpPageSelectorClass *klass)
G_PARAM_READWRITE)); G_PARAM_READWRITE));
/** /**
* GimpPageSelector:target: * GimpPageSelector::target:
* *
* The target to open the document to. * The target to open the document to.
* *
@ -176,11 +198,14 @@ gimp_page_selector_class_init (GimpPageSelectorClass *klass)
GIMP_TYPE_PAGE_SELECTOR_TARGET, GIMP_TYPE_PAGE_SELECTOR_TARGET,
GIMP_PAGE_SELECTOR_TARGET_LAYERS, GIMP_PAGE_SELECTOR_TARGET_LAYERS,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_type_class_add_private (object_class, sizeof (GimpPageSelectorPrivate));
} }
static void static void
gimp_page_selector_init (GimpPageSelector *selector) gimp_page_selector_init (GimpPageSelector *selector)
{ {
GimpPageSelectorPrivate *priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
GtkWidget *sw; GtkWidget *sw;
GtkWidget *hbox; GtkWidget *hbox;
GtkWidget *hbbox; GtkWidget *hbbox;
@ -188,8 +213,8 @@ gimp_page_selector_init (GimpPageSelector *selector)
GtkWidget *label; GtkWidget *label;
GtkWidget *combo; GtkWidget *combo;
selector->n_pages = 0; priv->n_pages = 0;
selector->target = GIMP_PAGE_SELECTOR_TARGET_LAYERS; priv->target = GIMP_PAGE_SELECTOR_TARGET_LAYERS;
gtk_box_set_spacing (GTK_BOX (selector), 6); gtk_box_set_spacing (GTK_BOX (selector), 6);
@ -202,24 +227,23 @@ gimp_page_selector_init (GimpPageSelector *selector)
gtk_box_pack_start (GTK_BOX (selector), sw, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (selector), sw, TRUE, TRUE, 0);
gtk_widget_show (sw); gtk_widget_show (sw);
selector->store = gtk_list_store_new (4, priv->store = gtk_list_store_new (4,
G_TYPE_INT, G_TYPE_INT,
GDK_TYPE_PIXBUF, GDK_TYPE_PIXBUF,
G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_BOOLEAN); G_TYPE_BOOLEAN);
selector->view = priv->view = gtk_icon_view_new_with_model (GTK_TREE_MODEL (priv->store));
gtk_icon_view_new_with_model (GTK_TREE_MODEL (selector->store)); gtk_icon_view_set_text_column (GTK_ICON_VIEW (priv->view),
gtk_icon_view_set_text_column (GTK_ICON_VIEW (selector->view),
COLUMN_LABEL); COLUMN_LABEL);
gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (selector->view), gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (priv->view),
COLUMN_THUMBNAIL); COLUMN_THUMBNAIL);
gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (selector->view), gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (priv->view),
GTK_SELECTION_MULTIPLE); GTK_SELECTION_MULTIPLE);
gtk_container_add (GTK_CONTAINER (sw), selector->view); gtk_container_add (GTK_CONTAINER (sw), priv->view);
gtk_widget_show (selector->view); gtk_widget_show (priv->view);
g_signal_connect (selector->view, "selection-changed", g_signal_connect (priv->view, "selection-changed",
G_CALLBACK (gimp_page_selector_selection_changed), G_CALLBACK (gimp_page_selector_selection_changed),
selector); selector);
@ -249,15 +273,15 @@ gimp_page_selector_init (GimpPageSelector *selector)
G_CALLBACK (gimp_page_selector_unselect_all), G_CALLBACK (gimp_page_selector_unselect_all),
selector); selector);
selector->range_entry = gtk_entry_new (); priv->range_entry = gtk_entry_new ();
gtk_widget_set_size_request (selector->range_entry, 80, -1); gtk_widget_set_size_request (priv->range_entry, 80, -1);
gtk_box_pack_end (GTK_BOX (hbox), selector->range_entry, TRUE, TRUE, 0); gtk_box_pack_end (GTK_BOX (hbox), priv->range_entry, TRUE, TRUE, 0);
gtk_widget_show (selector->range_entry); gtk_widget_show (priv->range_entry);
g_signal_connect (selector->range_entry, "focus-out-event", g_signal_connect (priv->range_entry, "focus-out-event",
G_CALLBACK (gimp_page_selector_range_focus_out), G_CALLBACK (gimp_page_selector_range_focus_out),
selector); selector);
g_signal_connect (selector->range_entry, "activate", g_signal_connect (priv->range_entry, "activate",
G_CALLBACK (gimp_page_selector_range_activate), G_CALLBACK (gimp_page_selector_range_activate),
selector); selector);
@ -265,7 +289,7 @@ gimp_page_selector_init (GimpPageSelector *selector)
gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label); gtk_widget_show (label);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), selector->range_entry); gtk_label_set_mnemonic_widget (GTK_LABEL (label), priv->range_entry);
/* Target combo */ /* Target combo */
@ -283,7 +307,7 @@ gimp_page_selector_init (GimpPageSelector *selector)
gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo); gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
selector->thumbnail = gtk_widget_render_icon (GTK_WIDGET (selector), priv->thumbnail = gtk_widget_render_icon (GTK_WIDGET (selector),
GTK_STOCK_FILE, GTK_STOCK_FILE,
GTK_ICON_SIZE_DND, GTK_ICON_SIZE_DND,
NULL); NULL);
@ -292,12 +316,12 @@ gimp_page_selector_init (GimpPageSelector *selector)
static void static void
gimp_page_selector_dispose (GObject *object) gimp_page_selector_dispose (GObject *object)
{ {
GimpPageSelector *selector = GIMP_PAGE_SELECTOR (object); GimpPageSelectorPrivate *priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (object);
if (selector->item_width_idle_id) if (priv->item_width_idle_id)
{ {
g_source_remove (selector->item_width_idle_id); g_source_remove (priv->item_width_idle_id);
selector->item_width_idle_id = 0; priv->item_width_idle_id = 0;
} }
G_OBJECT_CLASS (parent_class)->dispose (object); G_OBJECT_CLASS (parent_class)->dispose (object);
@ -306,10 +330,10 @@ gimp_page_selector_dispose (GObject *object)
static void static void
gimp_page_selector_finalize (GObject *object) gimp_page_selector_finalize (GObject *object)
{ {
GimpPageSelector *selector = GIMP_PAGE_SELECTOR (object); GimpPageSelectorPrivate *priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (object);
if (selector->thumbnail) if (priv->thumbnail)
g_object_unref (selector->thumbnail); g_object_unref (priv->thumbnail);
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
@ -320,15 +344,15 @@ gimp_page_selector_get_property (GObject *object,
GValue *value, GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GimpPageSelector *selector = GIMP_PAGE_SELECTOR (object); GimpPageSelectorPrivate *priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (object);
switch (property_id) switch (property_id)
{ {
case PROP_N_PAGES: case PROP_N_PAGES:
g_value_set_int (value, selector->n_pages); g_value_set_int (value, priv->n_pages);
break; break;
case PROP_TARGET: case PROP_TARGET:
g_value_set_enum (value, selector->target); g_value_set_enum (value, priv->target);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -343,6 +367,7 @@ gimp_page_selector_set_property (GObject *object,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GimpPageSelector *selector = GIMP_PAGE_SELECTOR (object); GimpPageSelector *selector = GIMP_PAGE_SELECTOR (object);
GimpPageSelectorPrivate *priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (object);
switch (property_id) switch (property_id)
{ {
@ -350,7 +375,7 @@ gimp_page_selector_set_property (GObject *object,
gimp_page_selector_set_n_pages (selector, g_value_get_int (value)); gimp_page_selector_set_n_pages (selector, g_value_get_int (value));
break; break;
case PROP_TARGET: case PROP_TARGET:
selector->target = g_value_get_enum (value); priv->target = g_value_get_enum (value);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -362,7 +387,7 @@ static void
gimp_page_selector_style_set (GtkWidget *widget, gimp_page_selector_style_set (GtkWidget *widget,
GtkStyle *prev_style) GtkStyle *prev_style)
{ {
GimpPageSelector *selector = GIMP_PAGE_SELECTOR (widget); GimpPageSelectorPrivate *priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (widget);
PangoLayout *layout; PangoLayout *layout;
PangoRectangle ink_rect; PangoRectangle ink_rect;
PangoRectangle logical_rect; PangoRectangle logical_rect;
@ -384,20 +409,20 @@ gimp_page_selector_style_set (GtkWidget *widget,
#define ICON_TEXT_PADDING 3 /* EEK */ #define ICON_TEXT_PADDING 3 /* EEK */
item_width = MAX (selector->thumbnail ? item_width = MAX (priv->thumbnail ?
gdk_pixbuf_get_width (selector->thumbnail) : 0, gdk_pixbuf_get_width (priv->thumbnail) : 0,
PANGO_PIXELS (MAX (ink_rect.width, PANGO_PIXELS (MAX (ink_rect.width,
logical_rect.width)) + logical_rect.width)) +
2 * (focus_line_width + focus_padding + 2 * (focus_line_width + focus_padding +
ICON_TEXT_PADDING)); ICON_TEXT_PADDING));
if (item_width != selector->default_item_width) if (item_width != priv->default_item_width)
{ {
selector->default_item_width = item_width; priv->default_item_width = item_width;
gtk_icon_view_set_item_width (GTK_ICON_VIEW (selector->view), gtk_icon_view_set_item_width (GTK_ICON_VIEW (priv->view),
MAX (selector->default_item_width, MAX (priv->default_item_width,
selector->max_item_width)); priv->max_item_width));
} }
} }
@ -435,37 +460,41 @@ void
gimp_page_selector_set_n_pages (GimpPageSelector *selector, gimp_page_selector_set_n_pages (GimpPageSelector *selector,
gint n_pages) gint n_pages)
{ {
GimpPageSelectorPrivate *priv;
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector)); g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
g_return_if_fail (n_pages >= 0); g_return_if_fail (n_pages >= 0);
if (n_pages != selector->n_pages) priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
if (n_pages != priv->n_pages)
{ {
GtkTreeIter iter; GtkTreeIter iter;
gint i; gint i;
if (n_pages < selector->n_pages) if (n_pages < priv->n_pages)
{ {
for (i = n_pages; i < selector->n_pages; i++) for (i = n_pages; i < priv->n_pages; i++)
{ {
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (selector->store), gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (priv->store),
&iter, NULL, n_pages); &iter, NULL, n_pages);
gtk_list_store_remove (selector->store, &iter); gtk_list_store_remove (priv->store, &iter);
} }
gimp_page_selector_update_item_width (selector); gimp_page_selector_update_item_width (selector);
} }
else else
{ {
for (i = selector->n_pages; i < n_pages; i++) for (i = priv->n_pages; i < n_pages; i++)
{ {
gchar *text; gchar *text;
text = g_strdup_printf (_("Page %d"), i + 1); text = g_strdup_printf (_("Page %d"), i + 1);
gtk_list_store_append (selector->store, &iter); gtk_list_store_append (priv->store, &iter);
gtk_list_store_set (selector->store, &iter, gtk_list_store_set (priv->store, &iter,
COLUMN_PAGE_NO, i, COLUMN_PAGE_NO, i,
COLUMN_THUMBNAIL, selector->thumbnail, COLUMN_THUMBNAIL, priv->thumbnail,
COLUMN_LABEL, text, COLUMN_LABEL, text,
COLUMN_LABEL_SET, FALSE, COLUMN_LABEL_SET, FALSE,
-1); -1);
@ -474,7 +503,7 @@ gimp_page_selector_set_n_pages (GimpPageSelector *selector,
} }
} }
selector->n_pages = n_pages; priv->n_pages = n_pages;
g_object_notify (G_OBJECT (selector), "n-pages"); g_object_notify (G_OBJECT (selector), "n-pages");
} }
@ -491,9 +520,13 @@ gimp_page_selector_set_n_pages (GimpPageSelector *selector,
gint gint
gimp_page_selector_get_n_pages (GimpPageSelector *selector) gimp_page_selector_get_n_pages (GimpPageSelector *selector)
{ {
GimpPageSelectorPrivate *priv;
g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), 0); g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), 0);
return selector->n_pages; priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
return priv->n_pages;
} }
/** /**
@ -507,13 +540,17 @@ void
gimp_page_selector_set_target (GimpPageSelector *selector, gimp_page_selector_set_target (GimpPageSelector *selector,
GimpPageSelectorTarget target) GimpPageSelectorTarget target)
{ {
GimpPageSelectorPrivate *priv;
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector)); g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
g_return_if_fail (target >= GIMP_PAGE_SELECTOR_TARGET_LAYERS && g_return_if_fail (target >= GIMP_PAGE_SELECTOR_TARGET_LAYERS &&
target <= GIMP_PAGE_SELECTOR_TARGET_IMAGES); target <= GIMP_PAGE_SELECTOR_TARGET_IMAGES);
if (target != selector->target) priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
if (target != priv->target)
{ {
selector->target = target; priv->target = target;
g_object_notify (G_OBJECT (selector), "target"); g_object_notify (G_OBJECT (selector), "target");
} }
@ -530,10 +567,14 @@ gimp_page_selector_set_target (GimpPageSelector *selector,
GimpPageSelectorTarget GimpPageSelectorTarget
gimp_page_selector_get_target (GimpPageSelector *selector) gimp_page_selector_get_target (GimpPageSelector *selector)
{ {
GimpPageSelectorPrivate *priv;
g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector),
GIMP_PAGE_SELECTOR_TARGET_LAYERS); GIMP_PAGE_SELECTOR_TARGET_LAYERS);
return selector->target; priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
return priv->target;
} }
/** /**
@ -552,18 +593,22 @@ gimp_page_selector_set_page_thumbnail (GimpPageSelector *selector,
gint page_no, gint page_no,
GdkPixbuf *thumbnail) GdkPixbuf *thumbnail)
{ {
GimpPageSelectorPrivate *priv;
GtkTreeIter iter; GtkTreeIter iter;
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector)); g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
g_return_if_fail (page_no >= 0 && page_no < selector->n_pages);
g_return_if_fail (thumbnail == NULL || GDK_IS_PIXBUF (thumbnail)); g_return_if_fail (thumbnail == NULL || GDK_IS_PIXBUF (thumbnail));
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (selector->store), priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
g_return_if_fail (page_no >= 0 && page_no < priv->n_pages);
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (priv->store),
&iter, NULL, page_no); &iter, NULL, page_no);
if (! thumbnail) if (! thumbnail)
{ {
thumbnail = g_object_ref (selector->thumbnail); thumbnail = g_object_ref (priv->thumbnail);
gimp_page_selector_update_item_width (selector); gimp_page_selector_update_item_width (selector);
} }
@ -584,25 +629,25 @@ gimp_page_selector_set_page_thumbnail (GimpPageSelector *selector,
width = gdk_pixbuf_get_width (thumbnail) + 2 * (focus_line_width + width = gdk_pixbuf_get_width (thumbnail) + 2 * (focus_line_width +
focus_padding); focus_padding);
if (width > selector->max_item_width) if (width > priv->max_item_width)
{ {
selector->max_item_width = width; priv->max_item_width = width;
gtk_icon_view_set_item_width (GTK_ICON_VIEW (selector->view), gtk_icon_view_set_item_width (GTK_ICON_VIEW (priv->view),
MAX (selector->default_item_width, MAX (priv->default_item_width,
selector->max_item_width)); priv->max_item_width));
} }
else if (width < selector->max_item_width) else if (width < priv->max_item_width)
{ {
GdkPixbuf *old; GdkPixbuf *old;
gtk_tree_model_get (GTK_TREE_MODEL (selector->store), &iter, gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
COLUMN_THUMBNAIL, &old, COLUMN_THUMBNAIL, &old,
-1); -1);
if (old) if (old)
{ {
if (gdk_pixbuf_get_width (old) == selector->max_item_width) if (gdk_pixbuf_get_width (old) == priv->max_item_width)
gimp_page_selector_update_item_width (selector); gimp_page_selector_update_item_width (selector);
g_object_unref (old); g_object_unref (old);
@ -610,7 +655,7 @@ gimp_page_selector_set_page_thumbnail (GimpPageSelector *selector,
} }
} }
gtk_list_store_set (selector->store, &iter, gtk_list_store_set (priv->store, &iter,
COLUMN_THUMBNAIL, thumbnail, COLUMN_THUMBNAIL, thumbnail,
-1); -1);
g_object_unref (thumbnail); g_object_unref (thumbnail);
@ -631,22 +676,26 @@ GdkPixbuf *
gimp_page_selector_get_page_thumbnail (GimpPageSelector *selector, gimp_page_selector_get_page_thumbnail (GimpPageSelector *selector,
gint page_no) gint page_no)
{ {
GimpPageSelectorPrivate *priv;
GdkPixbuf *thumbnail; GdkPixbuf *thumbnail;
GtkTreeIter iter; GtkTreeIter iter;
g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), NULL); g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), NULL);
g_return_val_if_fail (page_no >= 0 && page_no < selector->n_pages, NULL);
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (selector->store), priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
g_return_val_if_fail (page_no >= 0 && page_no < priv->n_pages, NULL);
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (priv->store),
&iter, NULL, page_no); &iter, NULL, page_no);
gtk_tree_model_get (GTK_TREE_MODEL (selector->store), &iter, gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
COLUMN_THUMBNAIL, &thumbnail, COLUMN_THUMBNAIL, &thumbnail,
-1); -1);
if (thumbnail) if (thumbnail)
g_object_unref (thumbnail); g_object_unref (thumbnail);
if (thumbnail == selector->thumbnail) if (thumbnail == priv->thumbnail)
return NULL; return NULL;
return thumbnail; return thumbnail;
@ -666,20 +715,24 @@ gimp_page_selector_set_page_label (GimpPageSelector *selector,
gint page_no, gint page_no,
const gchar *label) const gchar *label)
{ {
GimpPageSelectorPrivate *priv;
GtkTreeIter iter; GtkTreeIter iter;
gchar *tmp; gchar *tmp;
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector)); g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
g_return_if_fail (page_no >= 0 && page_no < selector->n_pages);
priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
g_return_if_fail (page_no >= 0 && page_no < priv->n_pages);
if (! label) if (! label)
tmp = g_strdup_printf (_("Page %d"), page_no + 1); tmp = g_strdup_printf (_("Page %d"), page_no + 1);
else else
tmp = (gchar *) label; tmp = (gchar *) label;
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (selector->store), gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (priv->store),
&iter, NULL, page_no); &iter, NULL, page_no);
gtk_list_store_set (selector->store, &iter, gtk_list_store_set (priv->store, &iter,
COLUMN_LABEL, tmp, COLUMN_LABEL, tmp,
COLUMN_LABEL_SET, label != NULL, COLUMN_LABEL_SET, label != NULL,
-1); -1);
@ -703,16 +756,20 @@ gchar *
gimp_page_selector_get_page_label (GimpPageSelector *selector, gimp_page_selector_get_page_label (GimpPageSelector *selector,
gint page_no) gint page_no)
{ {
GimpPageSelectorPrivate *priv;
GtkTreeIter iter; GtkTreeIter iter;
gchar *label; gchar *label;
gboolean label_set; gboolean label_set;
g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), NULL); g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), NULL);
g_return_val_if_fail (page_no >= 0 && page_no < selector->n_pages, NULL);
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (selector->store), priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
g_return_val_if_fail (page_no >= 0 && page_no < priv->n_pages, NULL);
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (priv->store),
&iter, NULL, page_no); &iter, NULL, page_no);
gtk_tree_model_get (GTK_TREE_MODEL (selector->store), &iter, gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
COLUMN_LABEL, &label, COLUMN_LABEL, &label,
COLUMN_LABEL_SET, &label_set, COLUMN_LABEL_SET, &label_set,
-1); -1);
@ -737,9 +794,13 @@ gimp_page_selector_get_page_label (GimpPageSelector *selector,
void void
gimp_page_selector_select_all (GimpPageSelector *selector) gimp_page_selector_select_all (GimpPageSelector *selector)
{ {
GimpPageSelectorPrivate *priv;
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector)); g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
gtk_icon_view_select_all (GTK_ICON_VIEW (selector->view)); priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
gtk_icon_view_select_all (GTK_ICON_VIEW (priv->view));
} }
/** /**
@ -753,9 +814,13 @@ gimp_page_selector_select_all (GimpPageSelector *selector)
void void
gimp_page_selector_unselect_all (GimpPageSelector *selector) gimp_page_selector_unselect_all (GimpPageSelector *selector)
{ {
GimpPageSelectorPrivate *priv;
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector)); g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
gtk_icon_view_unselect_all (GTK_ICON_VIEW (selector->view)); priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
gtk_icon_view_unselect_all (GTK_ICON_VIEW (priv->view));
} }
/** /**
@ -771,17 +836,21 @@ void
gimp_page_selector_select_page (GimpPageSelector *selector, gimp_page_selector_select_page (GimpPageSelector *selector,
gint page_no) gint page_no)
{ {
GimpPageSelectorPrivate *priv;
GtkTreeIter iter; GtkTreeIter iter;
GtkTreePath *path; GtkTreePath *path;
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector)); g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
g_return_if_fail (page_no >= 0 && page_no < selector->n_pages);
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (selector->store), priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
g_return_if_fail (page_no >= 0 && page_no < priv->n_pages);
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (priv->store),
&iter, NULL, page_no); &iter, NULL, page_no);
path = gtk_tree_model_get_path (GTK_TREE_MODEL (selector->store), &iter); path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->store), &iter);
gtk_icon_view_select_path (GTK_ICON_VIEW (selector->view), path); gtk_icon_view_select_path (GTK_ICON_VIEW (priv->view), path);
gtk_tree_path_free (path); gtk_tree_path_free (path);
} }
@ -799,17 +868,21 @@ void
gimp_page_selector_unselect_page (GimpPageSelector *selector, gimp_page_selector_unselect_page (GimpPageSelector *selector,
gint page_no) gint page_no)
{ {
GimpPageSelectorPrivate *priv;
GtkTreeIter iter; GtkTreeIter iter;
GtkTreePath *path; GtkTreePath *path;
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector)); g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
g_return_if_fail (page_no >= 0 && page_no < selector->n_pages);
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (selector->store), priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
g_return_if_fail (page_no >= 0 && page_no < priv->n_pages);
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (priv->store),
&iter, NULL, page_no); &iter, NULL, page_no);
path = gtk_tree_model_get_path (GTK_TREE_MODEL (selector->store), &iter); path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->store), &iter);
gtk_icon_view_unselect_path (GTK_ICON_VIEW (selector->view), path); gtk_icon_view_unselect_path (GTK_ICON_VIEW (priv->view), path);
gtk_tree_path_free (path); gtk_tree_path_free (path);
} }
@ -827,18 +900,22 @@ gboolean
gimp_page_selector_page_is_selected (GimpPageSelector *selector, gimp_page_selector_page_is_selected (GimpPageSelector *selector,
gint page_no) gint page_no)
{ {
GimpPageSelectorPrivate *priv;
GtkTreeIter iter; GtkTreeIter iter;
GtkTreePath *path; GtkTreePath *path;
gboolean selected; gboolean selected;
g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), FALSE); g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), FALSE);
g_return_val_if_fail (page_no >= 0 && page_no < selector->n_pages, FALSE);
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (selector->store), priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
g_return_val_if_fail (page_no >= 0 && page_no < priv->n_pages, FALSE);
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (priv->store),
&iter, NULL, page_no); &iter, NULL, page_no);
path = gtk_tree_model_get_path (GTK_TREE_MODEL (selector->store), &iter); path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->store), &iter);
selected = gtk_icon_view_path_is_selected (GTK_ICON_VIEW (selector->view), selected = gtk_icon_view_path_is_selected (GTK_ICON_VIEW (priv->view),
path); path);
gtk_tree_path_free (path); gtk_tree_path_free (path);
@ -860,6 +937,7 @@ gint *
gimp_page_selector_get_selected_pages (GimpPageSelector *selector, gimp_page_selector_get_selected_pages (GimpPageSelector *selector,
gint *n_selected_pages) gint *n_selected_pages)
{ {
GimpPageSelectorPrivate *priv;
GList *selected; GList *selected;
GList *list; GList *list;
gint *array; gint *array;
@ -868,7 +946,9 @@ gimp_page_selector_get_selected_pages (GimpPageSelector *selector,
g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), NULL); g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), NULL);
g_return_val_if_fail (n_selected_pages != NULL, NULL); g_return_val_if_fail (n_selected_pages != NULL, NULL);
selected = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (selector->view)); priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
selected = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (priv->view));
*n_selected_pages = g_list_length (selected); *n_selected_pages = g_list_length (selected);
array = g_new0 (gint, *n_selected_pages); array = g_new0 (gint, *n_selected_pages);
@ -908,14 +988,17 @@ void
gimp_page_selector_select_range (GimpPageSelector *selector, gimp_page_selector_select_range (GimpPageSelector *selector,
const gchar *range) const gchar *range)
{ {
GimpPageSelectorPrivate *priv;
gchar **ranges; gchar **ranges;
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector)); g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
if (! range) if (! range)
range = ""; range = "";
g_signal_handlers_block_by_func (selector->view, g_signal_handlers_block_by_func (priv->view,
gimp_page_selector_selection_changed, gimp_page_selector_selection_changed,
selector); selector);
@ -942,12 +1025,12 @@ gimp_page_selector_select_range (GimpPageSelector *selector,
if (sscanf (range, "%i", &page_from) == 1 && if (sscanf (range, "%i", &page_from) == 1 &&
sscanf (dash + 1, "%i", &page_to) == 1 && sscanf (dash + 1, "%i", &page_to) == 1 &&
page_from <= page_to && page_from <= page_to &&
page_from <= selector->n_pages) page_from <= priv->n_pages)
{ {
gint page_no; gint page_no;
page_from = MAX (page_from, 1) - 1; page_from = MAX (page_from, 1) - 1;
page_to = MIN (page_to, selector->n_pages) - 1; page_to = MIN (page_to, priv->n_pages) - 1;
for (page_no = page_from; page_no <= page_to; page_no++) for (page_no = page_from; page_no <= page_to; page_no++)
gimp_page_selector_select_page (selector, page_no); gimp_page_selector_select_page (selector, page_no);
@ -959,7 +1042,7 @@ gimp_page_selector_select_range (GimpPageSelector *selector,
if (sscanf (range, "%i", &page_no) == 1 && if (sscanf (range, "%i", &page_no) == 1 &&
page_no >= 1 && page_no >= 1 &&
page_no <= selector->n_pages) page_no <= priv->n_pages)
{ {
gimp_page_selector_select_page (selector, page_no - 1); gimp_page_selector_select_page (selector, page_no - 1);
} }
@ -969,11 +1052,11 @@ gimp_page_selector_select_range (GimpPageSelector *selector,
g_strfreev (ranges); g_strfreev (ranges);
} }
g_signal_handlers_unblock_by_func (selector->view, g_signal_handlers_unblock_by_func (priv->view,
gimp_page_selector_selection_changed, gimp_page_selector_selection_changed,
selector); selector);
gimp_page_selector_selection_changed (GTK_ICON_VIEW (selector->view), gimp_page_selector_selection_changed (GTK_ICON_VIEW (priv->view),
selector); selector);
} }
@ -1040,13 +1123,14 @@ static void
gimp_page_selector_selection_changed (GtkIconView *icon_view, gimp_page_selector_selection_changed (GtkIconView *icon_view,
GimpPageSelector *selector) GimpPageSelector *selector)
{ {
GimpPageSelectorPrivate *priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
gchar *range; gchar *range;
range = gimp_page_selector_get_selected_range (selector); range = gimp_page_selector_get_selected_range (selector);
gtk_entry_set_text (GTK_ENTRY (selector->range_entry), range); gtk_entry_set_text (GTK_ENTRY (priv->range_entry), range);
g_free (range); g_free (range);
gtk_editable_set_position (GTK_EDITABLE (selector->range_entry), -1); gtk_editable_set_position (GTK_EDITABLE (priv->range_entry), -1);
g_signal_emit (selector, selector_signals[SELECTION_CHANGED], 0); g_signal_emit (selector, selector_signals[SELECTION_CHANGED], 0);
} }
@ -1092,17 +1176,20 @@ gimp_page_selector_print_range (GString *string,
static void static void
gimp_page_selector_update_item_width (GimpPageSelector *selector) gimp_page_selector_update_item_width (GimpPageSelector *selector)
{ {
if (selector->item_width_idle_id) GimpPageSelectorPrivate *priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
g_source_remove (selector->item_width_idle_id);
selector->item_width_idle_id = if (priv->item_width_idle_id)
g_source_remove (priv->item_width_idle_id);
priv->item_width_idle_id =
g_idle_add ((GSourceFunc) gimp_page_selector_item_width_idle, selector); g_idle_add ((GSourceFunc) gimp_page_selector_item_width_idle, selector);
} }
static gboolean static gboolean
gimp_page_selector_item_width_idle (GimpPageSelector *selector) gimp_page_selector_item_width_idle (GimpPageSelector *selector)
{ {
GtkTreeModel *model = GTK_TREE_MODEL (selector->store); GimpPageSelectorPrivate *priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
GtkTreeModel *model = GTK_TREE_MODEL (priv->store);
GtkTreeIter iter; GtkTreeIter iter;
gboolean iter_valid; gboolean iter_valid;
gint focus_line_width; gint focus_line_width;
@ -1111,7 +1198,7 @@ gimp_page_selector_item_width_idle (GimpPageSelector *selector)
GDK_THREADS_ENTER (); GDK_THREADS_ENTER ();
selector->item_width_idle_id = 0; priv->item_width_idle_id = 0;
gtk_widget_style_get (GTK_WIDGET (selector), gtk_widget_style_get (GTK_WIDGET (selector),
"focus-line-width", &focus_line_width, "focus-line-width", &focus_line_width,
@ -1124,13 +1211,13 @@ gimp_page_selector_item_width_idle (GimpPageSelector *selector)
{ {
GdkPixbuf *thumbnail; GdkPixbuf *thumbnail;
gtk_tree_model_get (GTK_TREE_MODEL (selector->store), &iter, gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
COLUMN_THUMBNAIL, &thumbnail, COLUMN_THUMBNAIL, &thumbnail,
-1); -1);
if (thumbnail) if (thumbnail)
{ {
if (thumbnail != selector->thumbnail) if (thumbnail != priv->thumbnail)
{ {
gint width; gint width;
@ -1145,13 +1232,13 @@ gimp_page_selector_item_width_idle (GimpPageSelector *selector)
} }
} }
if (max_width != selector->max_item_width) if (max_width != priv->max_item_width)
{ {
selector->max_item_width = max_width; priv->max_item_width = max_width;
gtk_icon_view_set_item_width (GTK_ICON_VIEW (selector->view), gtk_icon_view_set_item_width (GTK_ICON_VIEW (priv->view),
MAX (selector->default_item_width, MAX (priv->default_item_width,
selector->max_item_width)); priv->max_item_width));
} }
GDK_THREADS_LEAVE (); GDK_THREADS_LEAVE ();

View File

@ -40,20 +40,6 @@ typedef struct _GimpPageSelectorClass GimpPageSelectorClass;
struct _GimpPageSelector struct _GimpPageSelector
{ {
GtkVBox parent_instance; GtkVBox parent_instance;
gint n_pages;
GimpPageSelectorTarget target;
GtkListStore *store;
GtkWidget *view;
GtkWidget *range_entry;
GdkPixbuf *thumbnail;
gint default_item_width;
gint max_item_width;
guint item_width_idle_id;
}; };
struct _GimpPageSelectorClass struct _GimpPageSelectorClass