2005-06-27 22:14:25 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimppageselector.c
|
|
|
|
* Copyright (C) 2005 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2005-06-27 22:14:25 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2005-06-27 22:14:25 +08:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
2005-06-27 22:14:25 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2005-06-28 01:12:43 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2005-06-27 22:14:25 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "gimpwidgetstypes.h"
|
|
|
|
|
|
|
|
#include "gimppageselector.h"
|
2005-06-28 16:07:50 +08:00
|
|
|
#include "gimppropwidgets.h"
|
2005-07-06 06:46:34 +08:00
|
|
|
#include "gimpstock.h"
|
2005-07-24 00:37:33 +08:00
|
|
|
#include "gimpwidgets.h"
|
2011-09-30 21:43:02 +08:00
|
|
|
#include "gimp3migration.h"
|
2005-06-27 22:14:25 +08:00
|
|
|
|
|
|
|
#include "libgimp/libgimp-intl.h"
|
|
|
|
|
|
|
|
|
2010-07-06 00:01:28 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimppageselector
|
|
|
|
* @title: GimpPageSelector
|
|
|
|
* @short_description: A widget to select pages from multi-page things.
|
|
|
|
*
|
|
|
|
* Use this for example for specifying what pages to import from
|
|
|
|
* a PDF or PS document.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2005-06-27 22:14:25 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SELECTION_CHANGED,
|
2005-10-28 22:57:32 +08:00
|
|
|
ACTIVATE,
|
2005-06-27 22:14:25 +08:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2005-06-28 16:07:50 +08:00
|
|
|
PROP_N_PAGES,
|
|
|
|
PROP_TARGET
|
2005-06-27 22:14:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
COLUMN_PAGE_NO,
|
|
|
|
COLUMN_THUMBNAIL,
|
2005-07-01 04:16:23 +08:00
|
|
|
COLUMN_LABEL,
|
|
|
|
COLUMN_LABEL_SET
|
2005-06-27 22:14:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-01-25 22:35:56 +08:00
|
|
|
typedef struct
|
2005-07-08 21:25:57 +08:00
|
|
|
{
|
|
|
|
gint n_pages;
|
|
|
|
GimpPageSelectorTarget target;
|
|
|
|
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkWidget *view;
|
|
|
|
|
2005-07-24 00:37:33 +08:00
|
|
|
GtkWidget *count_label;
|
2005-07-08 21:25:57 +08:00
|
|
|
GtkWidget *range_entry;
|
|
|
|
|
2005-07-24 00:37:33 +08:00
|
|
|
GdkPixbuf *default_thumbnail;
|
2006-01-25 22:35:56 +08:00
|
|
|
} GimpPageSelectorPrivate;
|
2005-07-08 21:25:57 +08:00
|
|
|
|
2006-01-25 22:35:56 +08:00
|
|
|
#define GIMP_PAGE_SELECTOR_GET_PRIVATE(obj) \
|
|
|
|
((GimpPageSelectorPrivate *) ((GimpPageSelector *) (obj))->priv)
|
2005-07-08 21:25:57 +08:00
|
|
|
|
|
|
|
|
2005-06-28 01:12:43 +08:00
|
|
|
static void gimp_page_selector_finalize (GObject *object);
|
|
|
|
static void gimp_page_selector_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_page_selector_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2005-06-27 22:14:25 +08:00
|
|
|
|
2005-06-28 01:12:43 +08:00
|
|
|
static void gimp_page_selector_selection_changed (GtkIconView *icon_view,
|
|
|
|
GimpPageSelector *selector);
|
2005-10-28 22:57:32 +08:00
|
|
|
static void gimp_page_selector_item_activated (GtkIconView *icon_view,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GimpPageSelector *selector);
|
2005-06-28 01:12:43 +08:00
|
|
|
static gboolean gimp_page_selector_range_focus_out (GtkEntry *entry,
|
|
|
|
GdkEventFocus *fevent,
|
|
|
|
GimpPageSelector *selector);
|
|
|
|
static void gimp_page_selector_range_activate (GtkEntry *entry,
|
|
|
|
GimpPageSelector *selector);
|
2005-07-02 22:38:22 +08:00
|
|
|
static gint gimp_page_selector_int_compare (gconstpointer a,
|
|
|
|
gconstpointer b);
|
2005-06-28 01:47:44 +08:00
|
|
|
static void gimp_page_selector_print_range (GString *string,
|
|
|
|
gint start,
|
|
|
|
gint end);
|
2005-06-27 22:14:25 +08:00
|
|
|
|
2005-07-06 06:46:34 +08:00
|
|
|
static GdkPixbuf * gimp_page_selector_add_frame (GtkWidget *widget,
|
|
|
|
GdkPixbuf *pixbuf);
|
|
|
|
|
2005-06-27 22:14:25 +08:00
|
|
|
|
2011-07-28 01:53:34 +08:00
|
|
|
G_DEFINE_TYPE (GimpPageSelector, gimp_page_selector, GTK_TYPE_BOX)
|
2005-06-27 22:14:25 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
#define parent_class gimp_page_selector_parent_class
|
|
|
|
|
|
|
|
static guint selector_signals[LAST_SIGNAL] = { 0 };
|
2005-06-27 22:14:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_page_selector_class_init (GimpPageSelectorClass *klass)
|
|
|
|
{
|
2005-06-28 16:07:50 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2005-06-27 22:14:25 +08:00
|
|
|
|
2005-06-28 16:07:50 +08:00
|
|
|
object_class->finalize = gimp_page_selector_finalize;
|
|
|
|
object_class->get_property = gimp_page_selector_get_property;
|
|
|
|
object_class->set_property = gimp_page_selector_set_property;
|
|
|
|
|
|
|
|
klass->selection_changed = NULL;
|
2005-10-28 22:57:32 +08:00
|
|
|
klass->activate = NULL;
|
2005-06-28 16:07:50 +08:00
|
|
|
|
2005-07-09 02:16:20 +08:00
|
|
|
/**
|
|
|
|
* GimpPageSelector::selection-changed:
|
2005-10-28 22:57:32 +08:00
|
|
|
* @widget: the object which received the signal.
|
2005-07-09 02:16:20 +08:00
|
|
|
*
|
|
|
|
* This signal is emitted whenever the set of selected pages changes.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2005-06-27 22:14:25 +08:00
|
|
|
selector_signals[SELECTION_CHANGED] =
|
|
|
|
g_signal_new ("selection-changed",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpPageSelectorClass, selection_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2005-10-28 22:57:32 +08:00
|
|
|
/**
|
|
|
|
* GimpPageSelector::activate:
|
|
|
|
* @widget: the object which received the signal.
|
|
|
|
*
|
|
|
|
* The "activate" signal on GimpPageSelector is an action signal. It
|
|
|
|
* is emitted when a user double-clicks an item in the page selection.
|
2005-10-29 00:11:40 +08:00
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
2005-10-28 22:57:32 +08:00
|
|
|
*/
|
|
|
|
selector_signals[ACTIVATE] =
|
|
|
|
g_signal_new ("activate",
|
2006-04-12 18:53:28 +08:00
|
|
|
G_OBJECT_CLASS_TYPE (object_class),
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
G_STRUCT_OFFSET (GimpPageSelectorClass, activate),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2005-10-28 22:57:32 +08:00
|
|
|
widget_class->activate_signal = selector_signals[ACTIVATE];
|
|
|
|
|
2005-06-27 22:14:25 +08:00
|
|
|
/**
|
2005-07-09 02:16:20 +08:00
|
|
|
* GimpPageSelector:n-pages:
|
2005-06-27 22:14:25 +08:00
|
|
|
*
|
|
|
|
* The number of pages of the document to open.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
2005-07-02 22:38:22 +08:00
|
|
|
**/
|
2005-06-27 22:14:25 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_N_PAGES,
|
|
|
|
g_param_spec_int ("n-pages", NULL, NULL,
|
|
|
|
0, G_MAXINT, 0,
|
2006-01-31 00:10:56 +08:00
|
|
|
GIMP_PARAM_READWRITE));
|
2005-06-28 16:07:50 +08:00
|
|
|
|
|
|
|
/**
|
2005-07-09 02:16:20 +08:00
|
|
|
* GimpPageSelector:target:
|
2005-06-28 16:07:50 +08:00
|
|
|
*
|
|
|
|
* The target to open the document to.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
2005-07-02 22:38:22 +08:00
|
|
|
**/
|
2005-06-28 16:07:50 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_TARGET,
|
|
|
|
g_param_spec_enum ("target", NULL, NULL,
|
|
|
|
GIMP_TYPE_PAGE_SELECTOR_TARGET,
|
|
|
|
GIMP_PAGE_SELECTOR_TARGET_LAYERS,
|
2006-01-31 00:10:56 +08:00
|
|
|
GIMP_PARAM_READWRITE));
|
2005-07-08 21:25:57 +08:00
|
|
|
|
|
|
|
g_type_class_add_private (object_class, sizeof (GimpPageSelectorPrivate));
|
2005-06-27 22:14:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_page_selector_init (GimpPageSelector *selector)
|
|
|
|
{
|
2006-01-25 22:35:56 +08:00
|
|
|
GimpPageSelectorPrivate *priv;
|
2005-07-24 00:37:33 +08:00
|
|
|
GtkWidget *vbox;
|
2005-07-08 21:25:57 +08:00
|
|
|
GtkWidget *sw;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *hbbox;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *combo;
|
2005-06-28 01:12:43 +08:00
|
|
|
|
2006-01-25 22:35:56 +08:00
|
|
|
selector->priv = G_TYPE_INSTANCE_GET_PRIVATE (selector,
|
|
|
|
GIMP_TYPE_PAGE_SELECTOR,
|
|
|
|
GimpPageSelectorPrivate);
|
|
|
|
|
|
|
|
priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
priv->n_pages = 0;
|
|
|
|
priv->target = GIMP_PAGE_SELECTOR_TARGET_LAYERS;
|
2005-06-28 01:12:43 +08:00
|
|
|
|
2011-07-28 01:53:34 +08:00
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (selector),
|
|
|
|
GTK_ORIENTATION_VERTICAL);
|
|
|
|
|
2005-07-30 05:02:19 +08:00
|
|
|
gtk_box_set_spacing (GTK_BOX (selector), 12);
|
2005-06-28 01:12:43 +08:00
|
|
|
|
2005-06-28 16:07:50 +08:00
|
|
|
/* Pages */
|
2005-06-27 22:14:25 +08:00
|
|
|
|
2011-09-30 16:50:50 +08:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
|
2005-07-24 00:37:33 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (selector), vbox, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
2005-06-27 22:14:25 +08:00
|
|
|
sw = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);
|
2005-07-08 07:54:32 +08:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
|
|
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
2005-07-24 00:37:33 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
|
2005-06-27 22:14:25 +08:00
|
|
|
gtk_widget_show (sw);
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
priv->store = gtk_list_store_new (4,
|
|
|
|
G_TYPE_INT,
|
|
|
|
GDK_TYPE_PIXBUF,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_BOOLEAN);
|
2005-06-27 22:14:25 +08:00
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
priv->view = gtk_icon_view_new_with_model (GTK_TREE_MODEL (priv->store));
|
|
|
|
gtk_icon_view_set_text_column (GTK_ICON_VIEW (priv->view),
|
2005-07-01 04:16:23 +08:00
|
|
|
COLUMN_LABEL);
|
2005-07-08 21:25:57 +08:00
|
|
|
gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (priv->view),
|
2005-06-27 22:14:25 +08:00
|
|
|
COLUMN_THUMBNAIL);
|
2005-07-08 21:25:57 +08:00
|
|
|
gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (priv->view),
|
2005-06-27 22:14:25 +08:00
|
|
|
GTK_SELECTION_MULTIPLE);
|
2005-07-08 21:25:57 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (sw), priv->view);
|
|
|
|
gtk_widget_show (priv->view);
|
2005-06-27 22:14:25 +08:00
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
g_signal_connect (priv->view, "selection-changed",
|
2005-06-28 01:12:43 +08:00
|
|
|
G_CALLBACK (gimp_page_selector_selection_changed),
|
|
|
|
selector);
|
2005-10-28 22:57:32 +08:00
|
|
|
g_signal_connect (priv->view, "item-activated",
|
|
|
|
G_CALLBACK (gimp_page_selector_item_activated),
|
|
|
|
selector);
|
2005-06-28 01:12:43 +08:00
|
|
|
|
2005-07-24 00:37:33 +08:00
|
|
|
/* Count label */
|
|
|
|
|
|
|
|
priv->count_label = gtk_label_new (_("Nothing selected"));
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (priv->count_label), 0.0, 0.5);
|
|
|
|
gimp_label_set_attributes (GTK_LABEL (priv->count_label),
|
|
|
|
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
|
|
|
|
-1);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), priv->count_label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (priv->count_label);
|
|
|
|
|
|
|
|
/* Select all button & range entry */
|
|
|
|
|
2011-09-30 16:50:50 +08:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
2005-06-28 16:07:50 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (selector), hbox, FALSE, FALSE, 0);
|
2005-06-28 01:12:43 +08:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2011-09-30 21:43:02 +08:00
|
|
|
hbbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
|
2005-06-28 01:12:43 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), hbbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbbox);
|
|
|
|
|
|
|
|
button = gtk_button_new_with_mnemonic (_("Select _All"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbbox), button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (button, "clicked",
|
|
|
|
G_CALLBACK (gimp_page_selector_select_all),
|
|
|
|
selector);
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
priv->range_entry = gtk_entry_new ();
|
|
|
|
gtk_widget_set_size_request (priv->range_entry, 80, -1);
|
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), priv->range_entry, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (priv->range_entry);
|
2005-06-28 01:12:43 +08:00
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
g_signal_connect (priv->range_entry, "focus-out-event",
|
2005-06-28 01:12:43 +08:00
|
|
|
G_CALLBACK (gimp_page_selector_range_focus_out),
|
|
|
|
selector);
|
2005-07-08 21:25:57 +08:00
|
|
|
g_signal_connect (priv->range_entry, "activate",
|
2005-06-28 01:12:43 +08:00
|
|
|
G_CALLBACK (gimp_page_selector_range_activate),
|
|
|
|
selector);
|
|
|
|
|
2005-06-28 16:07:50 +08:00
|
|
|
label = gtk_label_new_with_mnemonic (_("Select _range:"));
|
2005-06-28 01:12:43 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), priv->range_entry);
|
2005-06-28 01:12:43 +08:00
|
|
|
|
2005-06-28 16:07:50 +08:00
|
|
|
/* Target combo */
|
|
|
|
|
2011-09-30 16:50:50 +08:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
2005-06-28 16:07:50 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (selector), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
label = gtk_label_new_with_mnemonic (_("Open _pages as"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
combo = gimp_prop_enum_combo_box_new (G_OBJECT (selector), "target", -1, -1);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (combo);
|
|
|
|
|
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
|
|
|
|
|
2005-07-24 00:37:33 +08:00
|
|
|
priv->default_thumbnail = gtk_widget_render_icon (GTK_WIDGET (selector),
|
|
|
|
GTK_STOCK_FILE,
|
|
|
|
GTK_ICON_SIZE_DND,
|
|
|
|
NULL);
|
2005-06-27 22:14:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_page_selector_finalize (GObject *object)
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (object);
|
2005-06-27 22:14:25 +08:00
|
|
|
|
2005-07-24 00:37:33 +08:00
|
|
|
if (priv->default_thumbnail)
|
|
|
|
g_object_unref (priv->default_thumbnail);
|
2005-06-27 22:14:25 +08:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_page_selector_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (object);
|
2005-06-27 22:14:25 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_N_PAGES:
|
2005-07-08 21:25:57 +08:00
|
|
|
g_value_set_int (value, priv->n_pages);
|
2005-06-27 22:14:25 +08:00
|
|
|
break;
|
2005-06-28 16:07:50 +08:00
|
|
|
case PROP_TARGET:
|
2005-07-08 21:25:57 +08:00
|
|
|
g_value_set_enum (value, priv->target);
|
2005-06-28 16:07:50 +08:00
|
|
|
break;
|
2005-06-27 22:14:25 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_page_selector_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelector *selector = GIMP_PAGE_SELECTOR (object);
|
|
|
|
GimpPageSelectorPrivate *priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (object);
|
2005-06-27 22:14:25 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_N_PAGES:
|
|
|
|
gimp_page_selector_set_n_pages (selector, g_value_get_int (value));
|
|
|
|
break;
|
2005-06-28 16:07:50 +08:00
|
|
|
case PROP_TARGET:
|
2005-07-08 21:25:57 +08:00
|
|
|
priv->target = g_value_get_enum (value);
|
2005-06-28 16:07:50 +08:00
|
|
|
break;
|
2005-06-27 22:14:25 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-28 01:12:43 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2005-06-27 22:14:25 +08:00
|
|
|
/**
|
|
|
|
* gimp_page_selector_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GimpPageSelector widget.
|
|
|
|
*
|
|
|
|
* Returns: Pointer to the new #GimpPageSelector widget.
|
2005-07-01 22:06:03 +08:00
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
2005-06-27 22:14:25 +08:00
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_page_selector_new (void)
|
|
|
|
{
|
2007-11-11 00:02:30 +08:00
|
|
|
return g_object_new (GIMP_TYPE_PAGE_SELECTOR, NULL);
|
2005-06-27 22:14:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_page_selector_set_n_pages:
|
|
|
|
* @selector: Pointer to a #GimpPageSelector.
|
2005-07-24 00:37:33 +08:00
|
|
|
* @n_pages: The number of pages.
|
2005-06-27 22:14:25 +08:00
|
|
|
*
|
2005-07-24 00:37:33 +08:00
|
|
|
* Sets the number of pages in the document to open.
|
2005-06-27 22:14:25 +08:00
|
|
|
*
|
2005-07-01 22:06:03 +08:00
|
|
|
* Since: GIMP 2.4
|
2005-06-27 22:14:25 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_page_selector_set_n_pages (GimpPageSelector *selector,
|
|
|
|
gint n_pages)
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv;
|
|
|
|
|
2005-06-27 22:14:25 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
|
|
|
|
g_return_if_fail (n_pages >= 0);
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
|
|
|
|
|
|
|
|
if (n_pages != priv->n_pages)
|
2005-06-27 22:14:25 +08:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gint i;
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
if (n_pages < priv->n_pages)
|
2005-06-27 22:14:25 +08:00
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
for (i = n_pages; i < priv->n_pages; i++)
|
2005-06-27 22:14:25 +08:00
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (priv->store),
|
2005-06-27 22:14:25 +08:00
|
|
|
&iter, NULL, n_pages);
|
2005-07-08 21:25:57 +08:00
|
|
|
gtk_list_store_remove (priv->store, &iter);
|
2005-06-27 22:14:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
for (i = priv->n_pages; i < n_pages; i++)
|
2005-06-27 22:14:25 +08:00
|
|
|
{
|
|
|
|
gchar *text;
|
|
|
|
|
|
|
|
text = g_strdup_printf (_("Page %d"), i + 1);
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
gtk_list_store_append (priv->store, &iter);
|
|
|
|
gtk_list_store_set (priv->store, &iter,
|
2005-06-27 22:14:25 +08:00
|
|
|
COLUMN_PAGE_NO, i,
|
2005-07-24 00:37:33 +08:00
|
|
|
COLUMN_THUMBNAIL, priv->default_thumbnail,
|
2005-07-01 04:16:23 +08:00
|
|
|
COLUMN_LABEL, text,
|
|
|
|
COLUMN_LABEL_SET, FALSE,
|
2005-06-27 22:14:25 +08:00
|
|
|
-1);
|
|
|
|
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
priv->n_pages = n_pages;
|
2005-06-27 22:14:25 +08:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (selector), "n-pages");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_page_selector_get_n_pages:
|
|
|
|
* @selector: Pointer to a #GimpPageSelector.
|
|
|
|
*
|
2005-07-01 22:06:03 +08:00
|
|
|
* Returns: the number of pages in the document to open.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
2005-06-27 22:14:25 +08:00
|
|
|
**/
|
|
|
|
gint
|
|
|
|
gimp_page_selector_get_n_pages (GimpPageSelector *selector)
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv;
|
|
|
|
|
2005-06-27 22:14:25 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), 0);
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
|
|
|
|
|
|
|
|
return priv->n_pages;
|
2005-06-27 22:14:25 +08:00
|
|
|
}
|
|
|
|
|
2005-07-02 22:38:22 +08:00
|
|
|
/**
|
|
|
|
* gimp_page_selector_set_target:
|
|
|
|
* @selector: Pointer to a #GimpPageSelector.
|
|
|
|
* @target: How to open the selected pages.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2005-06-28 16:07:50 +08:00
|
|
|
void
|
|
|
|
gimp_page_selector_set_target (GimpPageSelector *selector,
|
|
|
|
GimpPageSelectorTarget target)
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv;
|
|
|
|
|
2005-06-28 16:07:50 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
|
2008-01-06 10:14:44 +08:00
|
|
|
g_return_if_fail (target <= GIMP_PAGE_SELECTOR_TARGET_IMAGES);
|
2005-06-28 16:07:50 +08:00
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
|
|
|
|
|
|
|
|
if (target != priv->target)
|
2005-06-28 16:07:50 +08:00
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
priv->target = target;
|
2005-06-28 16:07:50 +08:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (selector), "target");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-02 22:38:22 +08:00
|
|
|
/**
|
|
|
|
* gimp_page_selector_get_target:
|
|
|
|
* @selector: Pointer to a #GimpPageSelector.
|
|
|
|
*
|
|
|
|
* Returns: How the selected pages should be opened.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2005-06-28 16:07:50 +08:00
|
|
|
GimpPageSelectorTarget
|
|
|
|
gimp_page_selector_get_target (GimpPageSelector *selector)
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv;
|
|
|
|
|
2005-06-28 16:07:50 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector),
|
|
|
|
GIMP_PAGE_SELECTOR_TARGET_LAYERS);
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
|
|
|
|
|
|
|
|
return priv->target;
|
2005-06-28 16:07:50 +08:00
|
|
|
}
|
|
|
|
|
2005-06-27 22:14:25 +08:00
|
|
|
/**
|
|
|
|
* gimp_page_selector_set_page_thumbnail:
|
|
|
|
* @selector: Pointer to a #GimpPageSelector.
|
|
|
|
* @page_no: The number of the page to set the thumbnail for.
|
|
|
|
* @thumbnail: The thumbnail pixbuf.
|
|
|
|
*
|
2010-07-06 01:04:15 +08:00
|
|
|
* Sets the thumbnail for given @page_no. A default "page" icon will
|
2005-07-02 22:38:22 +08:00
|
|
|
* be used if no page thumbnail is set.
|
2005-07-01 22:06:03 +08:00
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
2005-06-27 22:14:25 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_page_selector_set_page_thumbnail (GimpPageSelector *selector,
|
|
|
|
gint page_no,
|
|
|
|
GdkPixbuf *thumbnail)
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv;
|
|
|
|
GtkTreeIter iter;
|
2005-06-27 22:14:25 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
|
|
|
|
g_return_if_fail (thumbnail == NULL || GDK_IS_PIXBUF (thumbnail));
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
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),
|
2005-07-08 07:54:32 +08:00
|
|
|
&iter, NULL, page_no);
|
|
|
|
|
2005-06-27 22:14:25 +08:00
|
|
|
if (! thumbnail)
|
2005-07-08 07:54:32 +08:00
|
|
|
{
|
2005-07-24 00:37:33 +08:00
|
|
|
thumbnail = g_object_ref (priv->default_thumbnail);
|
2005-07-08 07:54:32 +08:00
|
|
|
}
|
2005-07-06 06:46:34 +08:00
|
|
|
else
|
2005-07-08 07:54:32 +08:00
|
|
|
{
|
|
|
|
thumbnail = gimp_page_selector_add_frame (GTK_WIDGET (selector),
|
|
|
|
thumbnail);
|
|
|
|
}
|
2005-06-27 22:14:25 +08:00
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
gtk_list_store_set (priv->store, &iter,
|
2005-06-27 22:14:25 +08:00
|
|
|
COLUMN_THUMBNAIL, thumbnail,
|
|
|
|
-1);
|
2005-07-06 06:46:34 +08:00
|
|
|
g_object_unref (thumbnail);
|
2005-06-27 22:14:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_page_selector_get_page_thumbnail:
|
2005-07-01 22:06:03 +08:00
|
|
|
* @selector: Pointer to a #GimpPageSelector.
|
2005-06-27 22:14:25 +08:00
|
|
|
* @page_no: The number of the page to get the thumbnail for.
|
|
|
|
*
|
2005-07-02 22:38:22 +08:00
|
|
|
* Returns: The page's thumbnail, or %NULL if none is set. The returned
|
|
|
|
* pixbuf is owned by #GimpPageSelector and must not be
|
|
|
|
* unref'ed when no longer needed.
|
2005-07-01 22:06:03 +08:00
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
2005-06-27 22:14:25 +08:00
|
|
|
**/
|
|
|
|
GdkPixbuf *
|
2005-07-02 22:38:22 +08:00
|
|
|
gimp_page_selector_get_page_thumbnail (GimpPageSelector *selector,
|
|
|
|
gint page_no)
|
2005-06-27 22:14:25 +08:00
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv;
|
|
|
|
GdkPixbuf *thumbnail;
|
|
|
|
GtkTreeIter iter;
|
2005-06-27 22:14:25 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), NULL);
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
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),
|
2005-06-27 22:14:25 +08:00
|
|
|
&iter, NULL, page_no);
|
2005-07-08 21:25:57 +08:00
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
|
2005-06-27 22:14:25 +08:00
|
|
|
COLUMN_THUMBNAIL, &thumbnail,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (thumbnail)
|
|
|
|
g_object_unref (thumbnail);
|
|
|
|
|
2005-07-24 00:37:33 +08:00
|
|
|
if (thumbnail == priv->default_thumbnail)
|
2005-06-27 22:14:25 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return thumbnail;
|
|
|
|
}
|
|
|
|
|
2005-07-01 22:06:03 +08:00
|
|
|
/**
|
|
|
|
* gimp_page_selector_set_page_label:
|
|
|
|
* @selector: Pointer to a #GimpPageSelector.
|
2010-07-06 01:04:15 +08:00
|
|
|
* @page_no: The number of the page to set the label for.
|
|
|
|
* @label: The label.
|
2005-07-01 22:06:03 +08:00
|
|
|
*
|
2010-07-06 01:04:15 +08:00
|
|
|
* Sets the label of the specified page.
|
2005-07-01 22:06:03 +08:00
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2005-07-01 04:16:23 +08:00
|
|
|
void
|
|
|
|
gimp_page_selector_set_page_label (GimpPageSelector *selector,
|
|
|
|
gint page_no,
|
|
|
|
const gchar *label)
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gchar *tmp;
|
2005-07-01 04:16:23 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
|
2005-07-08 21:25:57 +08:00
|
|
|
|
|
|
|
priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
|
|
|
|
|
|
|
|
g_return_if_fail (page_no >= 0 && page_no < priv->n_pages);
|
2005-07-01 04:16:23 +08:00
|
|
|
|
|
|
|
if (! label)
|
|
|
|
tmp = g_strdup_printf (_("Page %d"), page_no + 1);
|
|
|
|
else
|
|
|
|
tmp = (gchar *) label;
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (priv->store),
|
2005-07-01 04:16:23 +08:00
|
|
|
&iter, NULL, page_no);
|
2005-07-08 21:25:57 +08:00
|
|
|
gtk_list_store_set (priv->store, &iter,
|
2005-07-01 04:16:23 +08:00
|
|
|
COLUMN_LABEL, tmp,
|
|
|
|
COLUMN_LABEL_SET, label != NULL,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (! label)
|
|
|
|
g_free (tmp);
|
|
|
|
}
|
|
|
|
|
2005-07-01 22:06:03 +08:00
|
|
|
/**
|
|
|
|
* gimp_page_selector_get_page_label:
|
|
|
|
* @selector: Pointer to a #GimpPageSelector.
|
|
|
|
* @page_no: The number of the page to get the thumbnail for.
|
|
|
|
*
|
2005-07-02 22:38:22 +08:00
|
|
|
* Returns: The page's label, or %NULL if none is set. This is a newly
|
|
|
|
* allocated string that should be g_free()'d when no longer
|
|
|
|
* needed.
|
2005-07-01 22:06:03 +08:00
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2005-07-01 04:16:23 +08:00
|
|
|
gchar *
|
|
|
|
gimp_page_selector_get_page_label (GimpPageSelector *selector,
|
|
|
|
gint page_no)
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gchar *label;
|
|
|
|
gboolean label_set;
|
2005-07-01 04:16:23 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), NULL);
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
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),
|
2005-07-01 04:16:23 +08:00
|
|
|
&iter, NULL, page_no);
|
2005-07-08 21:25:57 +08:00
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
|
2005-07-01 04:16:23 +08:00
|
|
|
COLUMN_LABEL, &label,
|
|
|
|
COLUMN_LABEL_SET, &label_set,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (! label_set)
|
|
|
|
{
|
|
|
|
g_free (label);
|
2005-07-02 22:38:22 +08:00
|
|
|
label = NULL;
|
2005-07-01 04:16:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2005-07-01 22:06:03 +08:00
|
|
|
/**
|
|
|
|
* gimp_page_selector_select_all:
|
|
|
|
* @selector: Pointer to a #GimpPageSelector.
|
|
|
|
*
|
|
|
|
* Selects all pages.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2005-06-27 22:14:25 +08:00
|
|
|
void
|
|
|
|
gimp_page_selector_select_all (GimpPageSelector *selector)
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv;
|
|
|
|
|
2005-06-27 22:14:25 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
|
|
|
|
|
|
|
|
gtk_icon_view_select_all (GTK_ICON_VIEW (priv->view));
|
2005-06-27 22:14:25 +08:00
|
|
|
}
|
|
|
|
|
2005-07-01 22:06:03 +08:00
|
|
|
/**
|
|
|
|
* gimp_page_selector_unselect_all:
|
|
|
|
* @selector: Pointer to a #GimpPageSelector.
|
|
|
|
*
|
|
|
|
* Unselects all pages.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2005-06-27 22:14:25 +08:00
|
|
|
void
|
|
|
|
gimp_page_selector_unselect_all (GimpPageSelector *selector)
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv;
|
|
|
|
|
2005-06-27 22:14:25 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
|
|
|
|
|
|
|
|
gtk_icon_view_unselect_all (GTK_ICON_VIEW (priv->view));
|
2005-06-27 22:14:25 +08:00
|
|
|
}
|
|
|
|
|
2005-07-01 22:06:03 +08:00
|
|
|
/**
|
|
|
|
* gimp_page_selector_select_page:
|
|
|
|
* @selector: Pointer to a #GimpPageSelector.
|
|
|
|
* @page_no: The number of the page to select.
|
|
|
|
*
|
|
|
|
* Adds a page to the selection.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2005-06-27 22:14:25 +08:00
|
|
|
void
|
|
|
|
gimp_page_selector_select_page (GimpPageSelector *selector,
|
|
|
|
gint page_no)
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path;
|
2005-06-27 22:14:25 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
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),
|
2005-06-27 22:14:25 +08:00
|
|
|
&iter, NULL, page_no);
|
2005-07-08 21:25:57 +08:00
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->store), &iter);
|
2005-06-27 22:14:25 +08:00
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
gtk_icon_view_select_path (GTK_ICON_VIEW (priv->view), path);
|
2005-06-27 22:14:25 +08:00
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
2005-07-01 22:06:03 +08:00
|
|
|
/**
|
|
|
|
* gimp_page_selector_unselect_page:
|
|
|
|
* @selector: Pointer to a #GimpPageSelector.
|
|
|
|
* @page_no: The number of the page to unselect.
|
|
|
|
*
|
|
|
|
* Removes a page from the selection.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2005-06-27 22:14:25 +08:00
|
|
|
void
|
|
|
|
gimp_page_selector_unselect_page (GimpPageSelector *selector,
|
|
|
|
gint page_no)
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path;
|
2005-06-27 22:14:25 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
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),
|
2005-06-27 22:14:25 +08:00
|
|
|
&iter, NULL, page_no);
|
2005-07-08 21:25:57 +08:00
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->store), &iter);
|
2005-06-27 22:14:25 +08:00
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
gtk_icon_view_unselect_path (GTK_ICON_VIEW (priv->view), path);
|
2005-06-27 22:14:25 +08:00
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
2005-07-01 22:06:03 +08:00
|
|
|
/**
|
|
|
|
* gimp_page_selector_page_is_selected:
|
|
|
|
* @selector: Pointer to a #GimpPageSelector.
|
|
|
|
* @page_no: The number of the page to check.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the page is selected, %FALSE otherwise.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2005-06-27 22:14:25 +08:00
|
|
|
gboolean
|
|
|
|
gimp_page_selector_page_is_selected (GimpPageSelector *selector,
|
|
|
|
gint page_no)
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path;
|
|
|
|
gboolean selected;
|
2005-06-27 22:14:25 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), FALSE);
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
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),
|
2005-06-27 22:14:25 +08:00
|
|
|
&iter, NULL, page_no);
|
2005-07-08 21:25:57 +08:00
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->store), &iter);
|
2005-06-27 22:14:25 +08:00
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
selected = gtk_icon_view_path_is_selected (GTK_ICON_VIEW (priv->view),
|
2005-06-27 22:14:25 +08:00
|
|
|
path);
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
return selected;
|
|
|
|
}
|
|
|
|
|
2005-07-01 22:06:03 +08:00
|
|
|
/**
|
|
|
|
* gimp_page_selector_get_selected_pages:
|
|
|
|
* @selector: Pointer to a #GimpPageSelector.
|
|
|
|
* @n_selected_pages: Returns the number of selected pages.
|
|
|
|
*
|
2007-04-25 02:31:46 +08:00
|
|
|
* Returns: A sorted array of page numbers of selected pages. Use g_free() if
|
2005-07-01 22:06:03 +08:00
|
|
|
* you don't need the array any longer.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2005-06-27 22:14:25 +08:00
|
|
|
gint *
|
|
|
|
gimp_page_selector_get_selected_pages (GimpPageSelector *selector,
|
|
|
|
gint *n_selected_pages)
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv;
|
|
|
|
GList *selected;
|
|
|
|
GList *list;
|
|
|
|
gint *array;
|
|
|
|
gint i;
|
2005-06-27 22:14:25 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), NULL);
|
|
|
|
g_return_val_if_fail (n_selected_pages != NULL, NULL);
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
|
|
|
|
|
|
|
|
selected = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (priv->view));
|
2005-06-27 22:14:25 +08:00
|
|
|
|
|
|
|
*n_selected_pages = g_list_length (selected);
|
|
|
|
array = g_new0 (gint, *n_selected_pages);
|
|
|
|
|
|
|
|
for (list = selected, i = 0; list; list = g_list_next (list), i++)
|
|
|
|
{
|
|
|
|
gint *indices = gtk_tree_path_get_indices (list->data);
|
|
|
|
|
|
|
|
array[i] = indices[0];
|
|
|
|
}
|
|
|
|
|
2005-06-28 01:12:43 +08:00
|
|
|
qsort (array, *n_selected_pages, sizeof (gint),
|
|
|
|
gimp_page_selector_int_compare);
|
|
|
|
|
2011-03-08 00:10:18 +08:00
|
|
|
g_list_free_full (selected, (GDestroyNotify) gtk_tree_path_free);
|
2005-06-27 22:14:25 +08:00
|
|
|
|
|
|
|
return array;
|
|
|
|
}
|
2005-06-28 01:12:43 +08:00
|
|
|
|
2005-07-01 22:06:03 +08:00
|
|
|
/**
|
|
|
|
* gimp_page_selector_select_range:
|
|
|
|
* @selector: Pointer to a #GimpPageSelector.
|
2005-07-02 22:38:22 +08:00
|
|
|
* @range: A string representing the set of selected pages.
|
|
|
|
*
|
2010-07-06 01:04:15 +08:00
|
|
|
* Selectes the pages described by @range. The range string is a
|
2005-07-02 22:38:22 +08:00
|
|
|
* user-editable list of pages and ranges, e.g. "1,3,5-7,9-12,14".
|
|
|
|
* Note that the page numbering in the range string starts with 1,
|
|
|
|
* not 0.
|
|
|
|
*
|
|
|
|
* Invalid pages and ranges will be silently ignored, duplicate and
|
|
|
|
* overlapping pages and ranges will be merged.
|
2005-07-01 22:06:03 +08:00
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2005-06-28 01:47:44 +08:00
|
|
|
void
|
|
|
|
gimp_page_selector_select_range (GimpPageSelector *selector,
|
2005-07-01 22:06:03 +08:00
|
|
|
const gchar *range)
|
2005-06-28 01:47:44 +08:00
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv;
|
|
|
|
gchar **ranges;
|
2005-06-28 01:12:43 +08:00
|
|
|
|
2005-06-28 01:47:44 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PAGE_SELECTOR (selector));
|
2005-06-28 01:12:43 +08:00
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
|
|
|
|
|
2005-07-01 22:06:03 +08:00
|
|
|
if (! range)
|
|
|
|
range = "";
|
2005-06-28 01:12:43 +08:00
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
g_signal_handlers_block_by_func (priv->view,
|
2005-06-28 01:47:44 +08:00
|
|
|
gimp_page_selector_selection_changed,
|
|
|
|
selector);
|
|
|
|
|
|
|
|
gimp_page_selector_unselect_all (selector);
|
|
|
|
|
2005-07-01 22:06:03 +08:00
|
|
|
ranges = g_strsplit (range, ",", -1);
|
2005-06-28 01:47:44 +08:00
|
|
|
|
|
|
|
if (ranges)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; ranges[i] != NULL; i++)
|
|
|
|
{
|
|
|
|
gchar *range = g_strstrip (ranges[i]);
|
|
|
|
gchar *dash;
|
|
|
|
|
|
|
|
dash = strchr (range, '-');
|
|
|
|
|
|
|
|
if (dash)
|
|
|
|
{
|
2005-07-24 00:37:33 +08:00
|
|
|
gchar *from;
|
|
|
|
gchar *to;
|
|
|
|
gint page_from = -1;
|
|
|
|
gint page_to = -1;
|
|
|
|
|
|
|
|
*dash = '\0';
|
2005-06-28 01:47:44 +08:00
|
|
|
|
2005-07-24 00:37:33 +08:00
|
|
|
from = g_strstrip (range);
|
|
|
|
to = g_strstrip (dash + 1);
|
|
|
|
|
|
|
|
if (sscanf (from, "%i", &page_from) != 1 && strlen (from) == 0)
|
|
|
|
page_from = 1;
|
|
|
|
|
|
|
|
if (sscanf (to, "%i", &page_to) != 1 && strlen (to) == 0)
|
|
|
|
page_to = priv->n_pages;
|
|
|
|
|
|
|
|
if (page_from > 0 &&
|
|
|
|
page_to > 0 &&
|
|
|
|
page_from <= page_to &&
|
2005-07-08 21:25:57 +08:00
|
|
|
page_from <= priv->n_pages)
|
2005-06-28 01:47:44 +08:00
|
|
|
{
|
|
|
|
gint page_no;
|
|
|
|
|
|
|
|
page_from = MAX (page_from, 1) - 1;
|
2005-07-08 21:25:57 +08:00
|
|
|
page_to = MIN (page_to, priv->n_pages) - 1;
|
2005-06-28 01:47:44 +08:00
|
|
|
|
|
|
|
for (page_no = page_from; page_no <= page_to; page_no++)
|
|
|
|
gimp_page_selector_select_page (selector, page_no);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gint page_no;
|
|
|
|
|
|
|
|
if (sscanf (range, "%i", &page_no) == 1 &&
|
|
|
|
page_no >= 1 &&
|
2005-07-08 21:25:57 +08:00
|
|
|
page_no <= priv->n_pages)
|
2005-06-28 01:47:44 +08:00
|
|
|
{
|
|
|
|
gimp_page_selector_select_page (selector, page_no - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (ranges);
|
|
|
|
}
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
g_signal_handlers_unblock_by_func (priv->view,
|
2005-06-28 01:47:44 +08:00
|
|
|
gimp_page_selector_selection_changed,
|
|
|
|
selector);
|
|
|
|
|
2005-10-28 22:57:32 +08:00
|
|
|
gimp_page_selector_selection_changed (GTK_ICON_VIEW (priv->view), selector);
|
2005-06-28 01:12:43 +08:00
|
|
|
}
|
|
|
|
|
2005-07-01 22:06:03 +08:00
|
|
|
/**
|
|
|
|
* gimp_page_selector_get_selected_range:
|
|
|
|
* @selector: Pointer to a #GimpPageSelector.
|
|
|
|
*
|
2005-07-02 22:38:22 +08:00
|
|
|
* Returns: A newly allocated string representing the set of selected
|
2010-07-06 01:04:15 +08:00
|
|
|
* pages. See gimp_page_selector_select_range() for the
|
2005-07-02 22:38:22 +08:00
|
|
|
* format of the string.
|
2005-07-01 22:06:03 +08:00
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2005-06-28 01:47:44 +08:00
|
|
|
gchar *
|
|
|
|
gimp_page_selector_get_selected_range (GimpPageSelector *selector)
|
2005-06-28 01:12:43 +08:00
|
|
|
{
|
|
|
|
gint *pages;
|
|
|
|
gint n_pages;
|
|
|
|
GString *string;
|
|
|
|
|
2005-06-28 01:47:44 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PAGE_SELECTOR (selector), NULL);
|
|
|
|
|
2005-06-28 01:12:43 +08:00
|
|
|
string = g_string_new ("");
|
|
|
|
|
|
|
|
pages = gimp_page_selector_get_selected_pages (selector, &n_pages);
|
|
|
|
|
|
|
|
if (pages)
|
|
|
|
{
|
|
|
|
gint range_start, range_end;
|
|
|
|
gint last_printed;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
range_start = pages[0];
|
|
|
|
range_end = pages[0];
|
|
|
|
last_printed = -1;
|
|
|
|
|
|
|
|
for (i = 1; i < n_pages; i++)
|
|
|
|
{
|
|
|
|
if (pages[i] > range_end + 1)
|
|
|
|
{
|
|
|
|
gimp_page_selector_print_range (string,
|
|
|
|
range_start, range_end);
|
|
|
|
|
|
|
|
last_printed = range_end;
|
|
|
|
range_start = pages[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
range_end = pages[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (range_end != last_printed)
|
|
|
|
gimp_page_selector_print_range (string, range_start, range_end);
|
|
|
|
|
|
|
|
g_free (pages);
|
|
|
|
}
|
|
|
|
|
2005-06-28 01:47:44 +08:00
|
|
|
return g_string_free (string, FALSE);
|
|
|
|
}
|
|
|
|
|
2005-07-02 22:38:22 +08:00
|
|
|
|
2005-06-28 01:47:44 +08:00
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_page_selector_selection_changed (GtkIconView *icon_view,
|
|
|
|
GimpPageSelector *selector)
|
|
|
|
{
|
2005-07-08 21:25:57 +08:00
|
|
|
GimpPageSelectorPrivate *priv = GIMP_PAGE_SELECTOR_GET_PRIVATE (selector);
|
2005-07-24 00:37:33 +08:00
|
|
|
GList *selected;
|
|
|
|
gint n_selected;
|
2005-07-08 21:25:57 +08:00
|
|
|
gchar *range;
|
2005-06-28 01:47:44 +08:00
|
|
|
|
2005-07-24 00:37:33 +08:00
|
|
|
selected = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (priv->view));
|
|
|
|
n_selected = g_list_length (selected);
|
2011-03-08 00:10:18 +08:00
|
|
|
g_list_free_full (selected, (GDestroyNotify) gtk_tree_path_free);
|
2005-07-24 00:37:33 +08:00
|
|
|
|
|
|
|
if (n_selected == 0)
|
|
|
|
{
|
|
|
|
gtk_label_set_text (GTK_LABEL (priv->count_label),
|
|
|
|
_("Nothing selected"));
|
|
|
|
}
|
|
|
|
else if (n_selected == 1)
|
|
|
|
{
|
|
|
|
gtk_label_set_text (GTK_LABEL (priv->count_label),
|
|
|
|
_("One page selected"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gchar *text;
|
|
|
|
|
|
|
|
if (n_selected == priv->n_pages)
|
2006-08-23 22:55:39 +08:00
|
|
|
text = g_strdup_printf (ngettext ("%d page selected",
|
2006-06-27 15:49:14 +08:00
|
|
|
"All %d pages selected", n_selected),
|
|
|
|
n_selected);
|
2005-07-24 00:37:33 +08:00
|
|
|
else
|
2006-06-27 15:49:14 +08:00
|
|
|
text = g_strdup_printf (ngettext ("%d page selected",
|
|
|
|
"%d pages selected",
|
|
|
|
n_selected),
|
|
|
|
n_selected);
|
2005-07-24 00:37:33 +08:00
|
|
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (priv->count_label), text);
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
|
2005-06-28 01:47:44 +08:00
|
|
|
range = gimp_page_selector_get_selected_range (selector);
|
2005-07-08 21:25:57 +08:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (priv->range_entry), range);
|
2005-06-28 01:47:44 +08:00
|
|
|
g_free (range);
|
|
|
|
|
2005-07-08 21:25:57 +08:00
|
|
|
gtk_editable_set_position (GTK_EDITABLE (priv->range_entry), -1);
|
2005-06-28 01:12:43 +08:00
|
|
|
|
|
|
|
g_signal_emit (selector, selector_signals[SELECTION_CHANGED], 0);
|
|
|
|
}
|
|
|
|
|
2005-10-28 22:57:32 +08:00
|
|
|
static void
|
|
|
|
gimp_page_selector_item_activated (GtkIconView *icon_view,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GimpPageSelector *selector)
|
|
|
|
{
|
|
|
|
g_signal_emit (selector, selector_signals[ACTIVATE], 0);
|
|
|
|
}
|
|
|
|
|
2005-06-28 01:12:43 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_page_selector_range_focus_out (GtkEntry *entry,
|
|
|
|
GdkEventFocus *fevent,
|
|
|
|
GimpPageSelector *selector)
|
|
|
|
{
|
|
|
|
gimp_page_selector_range_activate (entry, selector);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_page_selector_range_activate (GtkEntry *entry,
|
|
|
|
GimpPageSelector *selector)
|
|
|
|
{
|
2005-06-28 01:47:44 +08:00
|
|
|
gimp_page_selector_select_range (selector, gtk_entry_get_text (entry));
|
|
|
|
}
|
2005-06-28 01:12:43 +08:00
|
|
|
|
2005-07-02 22:38:22 +08:00
|
|
|
static gint
|
|
|
|
gimp_page_selector_int_compare (gconstpointer a,
|
|
|
|
gconstpointer b)
|
|
|
|
{
|
|
|
|
return *(gint*)a - *(gint*)b;
|
|
|
|
}
|
|
|
|
|
2005-06-28 01:47:44 +08:00
|
|
|
static void
|
|
|
|
gimp_page_selector_print_range (GString *string,
|
|
|
|
gint start,
|
|
|
|
gint end)
|
|
|
|
{
|
|
|
|
if (string->len != 0)
|
|
|
|
g_string_append_c (string, ',');
|
2005-06-28 01:12:43 +08:00
|
|
|
|
2005-06-28 01:47:44 +08:00
|
|
|
if (start == end)
|
|
|
|
g_string_append_printf (string, "%d", start + 1);
|
|
|
|
else
|
|
|
|
g_string_append_printf (string, "%d-%d", start + 1, end + 1);
|
2005-06-28 01:12:43 +08:00
|
|
|
}
|
2005-07-06 06:46:34 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
draw_frame_row (GdkPixbuf *frame_image,
|
|
|
|
gint target_width,
|
|
|
|
gint source_width,
|
|
|
|
gint source_v_position,
|
|
|
|
gint dest_v_position,
|
|
|
|
GdkPixbuf *result_pixbuf,
|
|
|
|
gint left_offset,
|
|
|
|
gint height)
|
|
|
|
{
|
|
|
|
gint remaining_width = target_width;
|
|
|
|
gint h_offset = 0;
|
|
|
|
|
|
|
|
while (remaining_width > 0)
|
|
|
|
{
|
|
|
|
gint slab_width = (remaining_width > source_width ?
|
|
|
|
source_width : remaining_width);
|
2005-07-24 00:37:33 +08:00
|
|
|
|
2005-07-06 06:46:34 +08:00
|
|
|
gdk_pixbuf_copy_area (frame_image,
|
|
|
|
left_offset, source_v_position,
|
|
|
|
slab_width, height,
|
|
|
|
result_pixbuf,
|
|
|
|
left_offset + h_offset, dest_v_position);
|
|
|
|
|
|
|
|
remaining_width -= slab_width;
|
|
|
|
h_offset += slab_width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* utility to draw the middle section of the frame in a loop */
|
|
|
|
static void
|
|
|
|
draw_frame_column (GdkPixbuf *frame_image,
|
|
|
|
gint target_height,
|
|
|
|
gint source_height,
|
|
|
|
gint source_h_position,
|
|
|
|
gint dest_h_position,
|
|
|
|
GdkPixbuf *result_pixbuf,
|
|
|
|
gint top_offset, int width)
|
|
|
|
{
|
|
|
|
gint remaining_height = target_height;
|
|
|
|
gint v_offset = 0;
|
|
|
|
|
|
|
|
while (remaining_height > 0)
|
|
|
|
{
|
|
|
|
gint slab_height = (remaining_height > source_height ?
|
|
|
|
source_height : remaining_height);
|
|
|
|
|
|
|
|
gdk_pixbuf_copy_area (frame_image,
|
|
|
|
source_h_position, top_offset,
|
|
|
|
width, slab_height,
|
|
|
|
result_pixbuf,
|
|
|
|
dest_h_position, top_offset + v_offset);
|
|
|
|
|
|
|
|
remaining_height -= slab_height;
|
|
|
|
v_offset += slab_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-26 00:55:20 +08:00
|
|
|
static GdkPixbuf *
|
2005-07-06 06:46:34 +08:00
|
|
|
stretch_frame_image (GdkPixbuf *frame_image,
|
|
|
|
gint left_offset,
|
|
|
|
gint top_offset,
|
|
|
|
gint right_offset,
|
|
|
|
gint bottom_offset,
|
|
|
|
gint dest_width,
|
|
|
|
gint dest_height)
|
|
|
|
{
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
gint frame_width, frame_height;
|
|
|
|
gint target_width, target_frame_width;
|
|
|
|
gint target_height, target_frame_height;
|
|
|
|
|
|
|
|
frame_width = gdk_pixbuf_get_width (frame_image);
|
|
|
|
frame_height = gdk_pixbuf_get_height (frame_image );
|
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
|
|
|
|
dest_width, dest_height);
|
|
|
|
gdk_pixbuf_fill (pixbuf, 0);
|
|
|
|
|
|
|
|
target_width = dest_width - left_offset - right_offset;
|
|
|
|
target_height = dest_height - top_offset - bottom_offset;
|
|
|
|
target_frame_width = frame_width - left_offset - right_offset;
|
|
|
|
target_frame_height = frame_height - top_offset - bottom_offset;
|
|
|
|
|
|
|
|
left_offset += MIN (target_width / 4, target_frame_width / 4);
|
|
|
|
right_offset += MIN (target_width / 4, target_frame_width / 4);
|
|
|
|
top_offset += MIN (target_height / 4, target_frame_height / 4);
|
|
|
|
bottom_offset += MIN (target_height / 4, target_frame_height / 4);
|
|
|
|
|
|
|
|
target_width = dest_width - left_offset - right_offset;
|
|
|
|
target_height = dest_height - top_offset - bottom_offset;
|
|
|
|
target_frame_width = frame_width - left_offset - right_offset;
|
|
|
|
target_frame_height = frame_height - top_offset - bottom_offset;
|
|
|
|
|
|
|
|
/* draw the left top corner and top row */
|
|
|
|
gdk_pixbuf_copy_area (frame_image,
|
|
|
|
0, 0, left_offset, top_offset,
|
|
|
|
pixbuf, 0, 0);
|
|
|
|
draw_frame_row (frame_image, target_width, target_frame_width,
|
|
|
|
0, 0,
|
|
|
|
pixbuf,
|
|
|
|
left_offset, top_offset);
|
|
|
|
|
|
|
|
/* draw the right top corner and left column */
|
|
|
|
gdk_pixbuf_copy_area (frame_image,
|
|
|
|
frame_width - right_offset, 0,
|
|
|
|
right_offset, top_offset,
|
|
|
|
|
|
|
|
pixbuf,
|
|
|
|
dest_width - right_offset, 0);
|
|
|
|
draw_frame_column (frame_image, target_height, target_frame_height, 0, 0,
|
|
|
|
pixbuf, top_offset, left_offset);
|
|
|
|
|
|
|
|
/* draw the bottom right corner and bottom row */
|
|
|
|
gdk_pixbuf_copy_area (frame_image,
|
|
|
|
frame_width - right_offset, frame_height - bottom_offset,
|
|
|
|
right_offset, bottom_offset,
|
|
|
|
pixbuf,
|
|
|
|
dest_width - right_offset, dest_height - bottom_offset);
|
|
|
|
draw_frame_row (frame_image, target_width, target_frame_width,
|
|
|
|
frame_height - bottom_offset, dest_height - bottom_offset,
|
|
|
|
pixbuf, left_offset, bottom_offset);
|
|
|
|
|
|
|
|
/* draw the bottom left corner and the right column */
|
|
|
|
gdk_pixbuf_copy_area (frame_image,
|
|
|
|
0, frame_height - bottom_offset,
|
|
|
|
left_offset, bottom_offset,
|
|
|
|
pixbuf,
|
|
|
|
0, dest_height - bottom_offset);
|
|
|
|
draw_frame_column (frame_image, target_height, target_frame_height,
|
|
|
|
frame_width - right_offset, dest_width - right_offset,
|
|
|
|
pixbuf, top_offset, right_offset);
|
|
|
|
|
|
|
|
return pixbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FRAME_LEFT 2
|
|
|
|
#define FRAME_TOP 2
|
|
|
|
#define FRAME_RIGHT 4
|
|
|
|
#define FRAME_BOTTOM 4
|
|
|
|
|
|
|
|
static GdkPixbuf *
|
|
|
|
gimp_page_selector_add_frame (GtkWidget *widget,
|
|
|
|
GdkPixbuf *pixbuf)
|
|
|
|
{
|
|
|
|
GdkPixbuf *frame;
|
|
|
|
gint width, height;
|
|
|
|
|
|
|
|
width = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
height = gdk_pixbuf_get_height (pixbuf);
|
|
|
|
|
|
|
|
frame = g_object_get_data (G_OBJECT (widget), "frame");
|
|
|
|
|
|
|
|
if (! frame)
|
|
|
|
{
|
|
|
|
frame = gtk_widget_render_icon (widget,
|
|
|
|
GIMP_STOCK_FRAME,
|
|
|
|
GTK_ICON_SIZE_DIALOG, NULL);
|
|
|
|
g_object_set_data_full (G_OBJECT (widget), "frame", frame,
|
|
|
|
(GDestroyNotify) g_object_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
frame = stretch_frame_image (frame,
|
|
|
|
FRAME_LEFT,
|
|
|
|
FRAME_TOP,
|
|
|
|
FRAME_RIGHT,
|
|
|
|
FRAME_BOTTOM,
|
|
|
|
width + FRAME_LEFT + FRAME_RIGHT,
|
|
|
|
height + FRAME_TOP + FRAME_BOTTOM);
|
|
|
|
|
|
|
|
gdk_pixbuf_copy_area (pixbuf, 0, 0, width, height,
|
|
|
|
frame, FRAME_LEFT, FRAME_TOP);
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|