From: Jim Evins Date: Mon, 4 Apr 2005 01:41:35 +0000 (+0000) Subject: 2005-04-03 Jim Evins X-Git-Tag: glabels-2_3_0~433 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d99e9af35cbdba98f6919c63e1d6e6755e2ab66f;p=glabels 2005-04-03 Jim Evins * src/Makefile.am: * src/wdgt-image-select.h: * src/wdgt-image-select.c: Removed obsolete wdgt-image-select.[ch] files. * libglabels/paper.c: (gl_paper_dup): Fixed rename of parameter introduced during documentation updates. * data/glade/object-editor.glade: * src/object-editor-image-page.c: (gl_object_editor_prepare_image_page), (img_radio_toggled_cb), (gl_object_editor_set_image), (gl_object_editor_get_image), (update_preview_cb), (add_image_filters_to_chooser): * src/object-editor-private.h: Replaced deprecated GnomePixmapEntry with GtkFileChooserButton. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@514 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 40074041..2da805c4 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,21 @@ +2005-04-03 Jim Evins + + * src/Makefile.am: + * src/wdgt-image-select.h: + * src/wdgt-image-select.c: + Removed obsolete wdgt-image-select.[ch] files. + * libglabels/paper.c: (gl_paper_dup): + Fixed rename of parameter introduced during documentation + updates. + * data/glade/object-editor.glade: + * src/object-editor-image-page.c: + (gl_object_editor_prepare_image_page), (img_radio_toggled_cb), + (gl_object_editor_set_image), (gl_object_editor_get_image), + (update_preview_cb), (add_image_filters_to_chooser): + * src/object-editor-private.h: + Replaced deprecated GnomePixmapEntry with + GtkFileChooserButton. + 2005-04-02 Jim Evins * src/mygal/mygal-combo-box.c: (deactivate_arrow), diff --git a/glabels2/data/glade/object-editor.glade b/glabels2/data/glade/object-editor.glade index cffea583..f9bb0579 100644 --- a/glabels2/data/glade/object-editor.glade +++ b/glabels2/data/glade/object-editor.glade @@ -18,6 +18,7 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True True @@ -93,6 +94,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -194,6 +199,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -221,7 +230,7 @@ 0 True - * + * False @@ -282,6 +291,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 tab @@ -317,6 +330,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -341,6 +358,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -365,6 +386,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -389,6 +414,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -413,6 +442,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -448,7 +481,7 @@ 0 True - * + * False @@ -486,7 +519,7 @@ True True - 0.01 + 0.00999999977648 0 True GTK_UPDATE_ALWAYS @@ -693,7 +726,7 @@ True True - 0.01 + 0.00999999977648 2 False GTK_UPDATE_ALWAYS @@ -857,7 +890,7 @@ 0 True - * + * False @@ -910,9 +943,13 @@ False False 0 - 0.14 + 0.140000000596 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -950,6 +987,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 tab @@ -985,6 +1026,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1006,7 +1051,7 @@ True True - 0.01 + 0.00999999977648 2 True GTK_UPDATE_ALWAYS @@ -1034,6 +1079,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1168,7 +1217,7 @@ 0 True - * + * False @@ -1221,9 +1270,13 @@ False False 0 - 0.14 + 0.140000000596 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1261,6 +1314,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 tab @@ -1400,7 +1457,7 @@ 0 True - * + * False @@ -1452,9 +1509,13 @@ False False 0 - 0.14 + 0.140000000596 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1492,6 +1553,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 tab @@ -1506,10 +1571,13 @@ 12 - + True + 2 + 2 False - 12 + 12 + 6 @@ -1524,66 +1592,14 @@ True - 0 - False - False + 0 + 1 + 0 + 1 + fill + - - - 0 - False - False - - - - - - True - image - 10 - Load image - False - True - False - - - - True - True - True - True - 0 - - True - * - False - - - - - 0 - False - False - - - - - - True - - - 0 - True - True - - - - - - True - False - 12 @@ -1600,9 +1616,12 @@ img_file_radio - 0 - False - False + 0 + 1 + 1 + 2 + fill + @@ -1624,7 +1643,7 @@ 0 True - * + * False @@ -1637,16 +1656,37 @@ - 0 - False - False + 1 + 2 + 1 + 2 + + + + + + + True + Select A File + GTK_FILE_CHOOSER_ACTION_OPEN + True + False + -1 + + + 1 + 2 + 0 + 1 + fill + fill 0 - False - False + True + True @@ -1669,6 +1709,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 tab @@ -1751,7 +1795,7 @@ 0 True - * + * False @@ -1794,7 +1838,7 @@ 0 True - * + * False @@ -1845,6 +1889,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1869,6 +1917,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 1 @@ -1893,6 +1945,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -1975,6 +2031,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 tab @@ -2010,6 +2070,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2045,7 +2109,7 @@ 0 True - * + * False @@ -2235,7 +2299,7 @@ 0 True - * + * False @@ -2288,9 +2352,13 @@ False False 0 - 0.14 + 0.140000000596 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2328,6 +2396,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 tab @@ -2363,6 +2435,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2387,6 +2463,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2408,7 +2488,7 @@ True True - 0.01 + 0.00999999977648 2 True GTK_UPDATE_ALWAYS @@ -2436,6 +2516,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2496,7 +2580,7 @@ True True - 0.01 + 0.00999999977648 2 True GTK_UPDATE_ALWAYS @@ -2524,6 +2608,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2586,6 +2674,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 tab @@ -2621,6 +2713,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2645,6 +2741,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2666,7 +2766,7 @@ True True - 0.01 + 0.00999999977648 2 True GTK_UPDATE_ALWAYS @@ -2694,6 +2794,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2721,7 +2825,7 @@ True True - 0.01 + 0.00999999977648 1 True GTK_UPDATE_ALWAYS @@ -2749,6 +2853,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2793,6 +2901,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 tab @@ -2829,6 +2941,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2853,6 +2969,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -2877,6 +2997,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 2 @@ -2901,6 +3025,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 2 @@ -2916,7 +3044,7 @@ True True - 0.01 + 0.00999999977648 2 True GTK_UPDATE_ALWAYS @@ -2938,7 +3066,7 @@ True True - 0.01 + 0.00999999977648 2 True GTK_UPDATE_ALWAYS @@ -2982,6 +3110,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 tab diff --git a/glabels2/libglabels/paper.c b/glabels2/libglabels/paper.c index fd005d54..5145e77d 100644 --- a/glabels2/libglabels/paper.c +++ b/glabels2/libglabels/paper.c @@ -117,14 +117,14 @@ glPaper *gl_paper_dup (const glPaper *orig) { glPaper *paper; - g_return_val_if_fail (orig_paper, NULL); + g_return_val_if_fail (orig, NULL); paper = g_new0 (glPaper,1); - paper->id = g_strdup (orig_paper->id); - paper->name = g_strdup (orig_paper->name); - paper->width = orig_paper->width; - paper->height = orig_paper->height; + paper->id = g_strdup (orig->id); + paper->name = g_strdup (orig->name); + paper->width = orig->width; + paper->height = orig->height; return paper; } diff --git a/glabels2/src/Makefile.am b/glabels2/src/Makefile.am index d23bc4e8..106d39b2 100644 --- a/glabels2/src/Makefile.am +++ b/glabels2/src/Makefile.am @@ -153,8 +153,6 @@ glabels_SOURCES = \ merge-text.h \ text-node.c \ text-node.h \ - wdgt-image-select.c \ - wdgt-image-select.h \ wdgt-print-copies.c \ wdgt-print-copies.h \ wdgt-print-merge.c \ diff --git a/glabels2/src/object-editor-image-page.c b/glabels2/src/object-editor-image-page.c index 4464fab7..e9704839 100644 --- a/glabels2/src/object-editor-image-page.c +++ b/glabels2/src/object-editor-image-page.c @@ -23,6 +23,7 @@ #include #include +#include #include "object-editor.h" #include "prefs.h" @@ -49,6 +50,10 @@ static void img_radio_toggled_cb (glObjectEditor *editor); +static void update_preview_cb (GtkFileChooser *file_chooser, + gpointer data); +static void add_image_filters_to_chooser (GtkFileChooser *file_chooser); + /*--------------------------------------------------------------------------*/ @@ -57,8 +62,10 @@ static void img_radio_toggled_cb (glObjectEditor *editor); void gl_object_editor_prepare_image_page (glObjectEditor *editor) { - GdkColor *gdk_color; - GtkWidget *ge; + GdkColor *gdk_color; + GtkFileFilter *filter; + GtkWidget *preview; + gl_debug (DEBUG_EDITOR, "START"); @@ -69,20 +76,27 @@ gl_object_editor_prepare_image_page (glObjectEditor *editor) "img_file_radio"); editor->priv->img_key_radio = glade_xml_get_widget (editor->priv->gui, "img_key_radio"); - editor->priv->img_pixmap_entry = glade_xml_get_widget (editor->priv->gui, - "img_pixmap_entry"); + editor->priv->img_file_button = glade_xml_get_widget (editor->priv->gui, + "img_file_button"); editor->priv->img_key_combo = glade_xml_get_widget (editor->priv->gui, "img_key_combo"); editor->priv->img_key_entry = glade_xml_get_widget (editor->priv->gui, "img_key_entry"); + /* Modify file button properties. */ + add_image_filters_to_chooser (GTK_FILE_CHOOSER (editor->priv->img_file_button)); + preview = gtk_image_new (); + gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (editor->priv->img_file_button), preview); + g_signal_connect (G_OBJECT (editor->priv->img_file_button), + "update-preview", + G_CALLBACK (update_preview_cb), preview); + /* Un-hide */ gtk_widget_show_all (editor->priv->img_page_vbox); /* Connect signals */ - ge = gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(editor->priv->img_pixmap_entry)); - g_signal_connect_swapped (G_OBJECT (ge), - "changed", + g_signal_connect_swapped (G_OBJECT (editor->priv->img_file_button), + "selection-changed", G_CALLBACK (gl_object_editor_changed_cb), G_OBJECT (editor)); g_signal_connect_swapped (G_OBJECT (editor->priv->img_key_entry), @@ -110,10 +124,10 @@ img_radio_toggled_cb (glObjectEditor *editor) gl_debug (DEBUG_WDGT, "START"); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->img_file_radio))) { - gtk_widget_set_sensitive (editor->priv->img_pixmap_entry, TRUE); + gtk_widget_set_sensitive (editor->priv->img_file_button, TRUE); gtk_widget_set_sensitive (editor->priv->img_key_combo, FALSE); } else { - gtk_widget_set_sensitive (editor->priv->img_pixmap_entry, FALSE); + gtk_widget_set_sensitive (editor->priv->img_file_button, FALSE); gtk_widget_set_sensitive (editor->priv->img_key_combo, TRUE); } @@ -135,7 +149,7 @@ gl_object_editor_set_image (glObjectEditor *editor, gl_debug (DEBUG_EDITOR, "START"); - g_signal_handlers_block_by_func (G_OBJECT (editor->priv->img_pixmap_entry), + g_signal_handlers_block_by_func (G_OBJECT (editor->priv->img_file_button), G_CALLBACK (gl_object_editor_changed_cb), editor); g_signal_handlers_block_by_func (G_OBJECT (editor->priv->img_key_entry), @@ -148,22 +162,21 @@ gl_object_editor_set_image (glObjectEditor *editor, gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->img_file_radio), TRUE); - gtk_widget_set_sensitive (editor->priv->img_pixmap_entry, TRUE); + gtk_widget_set_sensitive (editor->priv->img_file_button, TRUE); gtk_widget_set_sensitive (editor->priv->img_key_combo, FALSE); if (text_node->data != NULL ) { - gnome_file_entry_set_filename (GNOME_FILE_ENTRY(editor->priv->img_pixmap_entry), + gtk_file_chooser_set_filename (GTK_FILE_CHOOSER(editor->priv->img_file_button), text_node->data); } else { - gnome_file_entry_set_filename (GNOME_FILE_ENTRY(editor->priv->img_pixmap_entry), - ""); + gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER(editor->priv->img_file_button)); } } else { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->img_key_radio), TRUE); - gtk_widget_set_sensitive (editor->priv->img_pixmap_entry, FALSE); + gtk_widget_set_sensitive (editor->priv->img_file_button, FALSE); gtk_widget_set_sensitive (editor->priv->img_key_combo, TRUE); gtk_editable_delete_text (GTK_EDITABLE (editor->priv->img_key_entry), 0, -1); @@ -174,7 +187,7 @@ gl_object_editor_set_image (glObjectEditor *editor, &pos); } - g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->img_pixmap_entry), + g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->img_file_button), G_CALLBACK (gl_object_editor_changed_cb), editor); g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->img_key_entry), @@ -199,7 +212,7 @@ gl_object_editor_get_image (glObjectEditor *editor) if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->img_file_radio))) { text_node->field_flag = FALSE; text_node->data = - gnome_pixmap_entry_get_filename (GNOME_PIXMAP_ENTRY(editor->priv->img_pixmap_entry)); + gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(editor->priv->img_file_button)); } else { text_node->field_flag = TRUE; text_node->data = @@ -215,3 +228,105 @@ gl_object_editor_get_image (glObjectEditor *editor) return text_node; } +/*--------------------------------------------------------------------------*/ +/* PRIVATE. Update preview image. */ +/*--------------------------------------------------------------------------*/ +static void +update_preview_cb (GtkFileChooser *file_chooser, gpointer data) +{ + GtkWidget *preview; + char *filename; + GdkPixbuf *pixbuf; + gboolean have_preview; + + preview = GTK_WIDGET (data); + filename = gtk_file_chooser_get_preview_filename (file_chooser); + + if (filename) { + pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL); + have_preview = (pixbuf != NULL); + g_free (filename); + + gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf); + if (pixbuf) + gdk_pixbuf_unref (pixbuf); + + gtk_file_chooser_set_preview_widget_active (file_chooser, + have_preview); + } else { + gtk_file_chooser_set_preview_widget_active (file_chooser, FALSE); + } +} + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. Add filters to file chooser. */ +/* Based on eog's eog_file_selection_add_filter(). */ +/*--------------------------------------------------------------------------*/ +static void +add_image_filters_to_chooser (GtkFileChooser *chooser) +{ + GtkFileFilter *all_file_filter; + GtkFileFilter *all_img_filter; + GSList *formats; + GSList *it; + GtkFileFilter *filter; + GSList *filters = NULL; + gchar **mime_types, **pattern, *tmp; + int i; + + /* All Files Filter */ + all_file_filter = gtk_file_filter_new (); + gtk_file_filter_set_name (all_file_filter, _("All Files")); + gtk_file_filter_add_pattern (all_file_filter, "*"); + + /* All Image Filter */ + all_img_filter = gtk_file_filter_new (); + gtk_file_filter_set_name (all_img_filter, _("All Images")); + + /* Individual image filters */ + formats = gdk_pixbuf_get_formats (); + for (it = formats; it != NULL; it = it->next) { + char *filter_name; + GdkPixbufFormat *format; + filter = gtk_file_filter_new (); + + format = (GdkPixbufFormat*) it->data; + + /* Filter name: First description then file extension, eg. "The PNG-Format (*.png)".*/ + filter_name = g_strdup_printf (_("%s (*.%s)"), + gdk_pixbuf_format_get_description (format), + gdk_pixbuf_format_get_name (format)); + gtk_file_filter_set_name (filter, filter_name); + g_free (filter_name); + + mime_types = gdk_pixbuf_format_get_mime_types ((GdkPixbufFormat *) it->data); + for (i = 0; mime_types[i] != NULL; i++) { + gtk_file_filter_add_mime_type (filter, mime_types[i]); + gtk_file_filter_add_mime_type (all_img_filter, mime_types[i]); + } + g_strfreev (mime_types); + + pattern = gdk_pixbuf_format_get_extensions ((GdkPixbufFormat *) it->data); + for (i = 0; pattern[i] != NULL; i++) { + tmp = g_strconcat ("*.", pattern[i], NULL); + gtk_file_filter_add_pattern (filter, tmp); + gtk_file_filter_add_pattern (all_img_filter, tmp); + g_free (tmp); + } + g_strfreev (pattern); + + filters = g_slist_prepend (filters, filter); + } + g_slist_free (formats); + + /* Add filter to filechooser */ + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), all_file_filter); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), all_img_filter); + gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), all_img_filter); + + for (it = filters; it != NULL; it = it->next) { + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), + GTK_FILE_FILTER (it->data)); + } + g_slist_free (filters); +} diff --git a/glabels2/src/object-editor-private.h b/glabels2/src/object-editor-private.h index 23381695..4c140318 100644 --- a/glabels2/src/object-editor-private.h +++ b/glabels2/src/object-editor-private.h @@ -90,7 +90,7 @@ struct _glObjectEditorPrivate { GtkWidget *img_page_vbox; GtkWidget *img_file_radio; GtkWidget *img_key_radio; - GtkWidget *img_pixmap_entry; + GtkWidget *img_file_button; GtkWidget *img_key_combo; GtkWidget *img_key_entry; diff --git a/glabels2/src/wdgt-image-select.c b/glabels2/src/wdgt-image-select.c deleted file mode 100644 index ff50938b..00000000 --- a/glabels2/src/wdgt-image-select.c +++ /dev/null @@ -1,443 +0,0 @@ -/* - * (GLABELS) Label and Business Card Creation program for GNOME - * - * wdgt_image_select.c: image selection widget module - * - * Copyright (C) 2001-2002 Jim Evins . - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include - -#include - -#include "wdgt-image-select.h" -#include "merge.h" -#include "marshal.h" - -#include "debug.h" - -/*===========================================*/ -/* Private types */ -/*===========================================*/ - -enum { - CHANGED, - LAST_SIGNAL -}; - -typedef void (*glWdgtImageSelectSignal) (GObject * object, gpointer data); - -/*===========================================*/ -/* Private globals */ -/*===========================================*/ - -static glHigVBoxClass *parent_class; - -static gint wdgt_image_select_signals[LAST_SIGNAL] = { 0 }; - -/* Save state of image file entry */ -static gchar *image_path = NULL; - -/*===========================================*/ -/* Local function prototypes */ -/*===========================================*/ - -static void gl_wdgt_image_select_class_init (glWdgtImageSelectClass *class); -static void gl_wdgt_image_select_instance_init (glWdgtImageSelect *image_select); -static void gl_wdgt_image_select_finalize (GObject *object); -static void gl_wdgt_image_select_construct (glWdgtImageSelect *image_select, - glMerge *merge, - glTextNode *text_node); - - -static void changed_cb (glWdgtImageSelect *image_select); - -static void radio_toggled_cb (GtkToggleButton *togglebutton, - glWdgtImageSelect *image_select); - - -/****************************************************************************/ -/* Boilerplate Object stuff. */ -/****************************************************************************/ -GType -gl_wdgt_image_select_get_type (void) -{ - static GType type = 0; - - if (!type) { - static const GTypeInfo info = { - sizeof (glWdgtImageSelectClass), - NULL, - NULL, - (GClassInitFunc) gl_wdgt_image_select_class_init, - NULL, - NULL, - sizeof (glWdgtImageSelect), - 0, - (GInstanceInitFunc) gl_wdgt_image_select_instance_init, - NULL - }; - - type = g_type_register_static (GL_TYPE_HIG_VBOX, - "glWdgtImageSelect", &info, 0); - } - - return type; -} - -static void -gl_wdgt_image_select_class_init (glWdgtImageSelectClass *class) -{ - GObjectClass *object_class; - - gl_debug (DEBUG_WDGT, "START"); - - object_class = (GObjectClass *) class; - - parent_class = g_type_class_peek_parent (class); - - object_class->finalize = gl_wdgt_image_select_finalize; - - wdgt_image_select_signals[CHANGED] = - g_signal_new ("changed", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (glWdgtImageSelectClass, changed), - NULL, NULL, - gl_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - gl_debug (DEBUG_WDGT, "END"); -} - -static void -gl_wdgt_image_select_instance_init (glWdgtImageSelect *image_select) -{ - gl_debug (DEBUG_WDGT, "START"); - - image_select->file_radio = NULL; - image_select->file_entry = NULL; - - image_select->key_radio = NULL; - image_select->key_combo = NULL; - image_select->key_entry = NULL; - - gl_debug (DEBUG_WDGT, "END"); -} - -static void -gl_wdgt_image_select_finalize (GObject *object) -{ - glWdgtImageSelect *image_select; - glWdgtImageSelectClass *class; - - gl_debug (DEBUG_WDGT, "START"); - - g_return_if_fail (object != NULL); - g_return_if_fail (GL_IS_WDGT_IMAGE_SELECT (object)); - - image_select = GL_WDGT_IMAGE_SELECT (object); - - G_OBJECT_CLASS (parent_class)->finalize (object); - - gl_debug (DEBUG_WDGT, "END"); -} - -/****************************************************************************/ -/* New widget. */ -/****************************************************************************/ -GtkWidget * -gl_wdgt_image_select_new (glMerge *merge, glTextNode *text_node) -{ - glWdgtImageSelect *image_select; - - gl_debug (DEBUG_WDGT, "START"); - - image_select = g_object_new (gl_wdgt_image_select_get_type (), NULL); - - gl_wdgt_image_select_construct (image_select, merge, text_node); - - gl_debug (DEBUG_WDGT, "END"); - - return GTK_WIDGET (image_select); -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Construct composite widget. */ -/*--------------------------------------------------------------------------*/ -static void -gl_wdgt_image_select_construct (glWdgtImageSelect *image_select, - glMerge *merge, - glTextNode *text_node) -{ - GtkWidget *wvbox, *whbox; - GSList *radio_group = NULL; - GList *keys; - gchar *filename; - - gl_debug (DEBUG_WDGT, "START"); - - wvbox = GTK_WIDGET (image_select); - - /* ---- File line ---- */ - whbox = gl_hig_hbox_new (); - gl_hig_vbox_add_widget (GL_HIG_VBOX(wvbox), whbox); - - /* File radio */ - image_select->file_radio = gtk_radio_button_new_with_label (radio_group, - _ - ("File:")); - radio_group = - gtk_radio_button_get_group (GTK_RADIO_BUTTON (image_select->file_radio)); - g_signal_connect (G_OBJECT (image_select->file_radio), "toggled", - G_CALLBACK (radio_toggled_cb), - G_OBJECT (image_select)); - gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), image_select->file_radio); - - /* File entry widget */ - image_select->file_entry = - gnome_pixmap_entry_new ("image", "Load image", TRUE); - gnome_pixmap_entry_set_preview_size (GNOME_PIXMAP_ENTRY - (image_select->file_entry), - 128, 128); - - /* Set default path for image entry */ - filename = text_node->field_flag? NULL : text_node->data; - if (filename != NULL) { - /* Set default path to the directory containing image. */ - if (image_path != NULL) - g_free (image_path); - image_path = g_path_get_dirname (filename); - if (image_path != NULL) { - image_path = g_strconcat (image_path, "/", NULL); - } - } else if (image_path == NULL) { - /* First time, set it to our CWD. */ - image_path = g_get_current_dir (); - } - /* Otherwise, leave it in the last directory that we got an image. */ - gnome_pixmap_entry_set_pixmap_subdir (GNOME_PIXMAP_ENTRY(image_select->file_entry), - image_path); - g_signal_connect_swapped ( G_OBJECT(gnome_file_entry_gtk_entry - (GNOME_FILE_ENTRY (image_select->file_entry))), - "changed", G_CALLBACK (changed_cb), image_select); - gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), image_select->file_entry); - - - /* ---- Key line ---- */ - whbox = gl_hig_hbox_new (); - gl_hig_vbox_add_widget (GL_HIG_VBOX(wvbox), whbox); - - /* Key radio */ - image_select->key_radio = gtk_radio_button_new_with_label (radio_group, - _("Key:")); - g_signal_connect (G_OBJECT (image_select->key_radio), "toggled", - G_CALLBACK (radio_toggled_cb), - G_OBJECT (image_select)); - gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), image_select->key_radio); - - /* Key entry widget */ - image_select->key_combo = gtk_combo_new (); - keys = gl_merge_get_key_list (merge); - if (keys != NULL) - gtk_combo_set_popdown_strings (GTK_COMBO (image_select->key_combo), - keys); - gl_merge_free_key_list (&keys); - image_select->key_entry = GTK_COMBO (image_select->key_combo)->entry; - gtk_entry_set_editable (GTK_ENTRY (image_select->key_entry), FALSE); - gtk_widget_set_size_request (image_select->key_combo, 200, -1); - g_signal_connect_swapped (G_OBJECT (image_select->key_entry), "changed", - G_CALLBACK (changed_cb), - G_OBJECT (image_select)); - gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), image_select->key_combo); - - - gl_wdgt_image_select_set_data (image_select, - (merge != NULL), - text_node); - - gl_debug (DEBUG_WDGT, "END"); -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Callback for when any control in the widget has changed. */ -/*--------------------------------------------------------------------------*/ -static void -changed_cb (glWdgtImageSelect *image_select) -{ - gl_debug (DEBUG_WDGT, "START"); - - /* Emit our "changed" signal */ - g_signal_emit (G_OBJECT (image_select), wdgt_image_select_signals[CHANGED], 0); - - gl_debug (DEBUG_WDGT, "END"); -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Callback to handle toggling of radio buttons */ -/*--------------------------------------------------------------------------*/ -static void -radio_toggled_cb (GtkToggleButton *togglebutton, - glWdgtImageSelect *image_select) -{ - gl_debug (DEBUG_WDGT, "START"); - - if (gtk_toggle_button_get_active - (GTK_TOGGLE_BUTTON (image_select->file_radio))) { - gtk_widget_set_sensitive (image_select->file_entry, TRUE); - gtk_widget_set_sensitive (image_select->key_combo, FALSE); - } else { - gtk_widget_set_sensitive (image_select->file_entry, FALSE); - gtk_widget_set_sensitive (image_select->key_combo, TRUE); - } - - /* Emit our "changed" signal */ - g_signal_emit (G_OBJECT (image_select), wdgt_image_select_signals[CHANGED], 0); - - gl_debug (DEBUG_WDGT, "END"); -} - -/****************************************************************************/ -/* Set new field definitions. */ -/****************************************************************************/ -void -gl_wdgt_image_select_set_field_defs (glWdgtImageSelect *image_select, - glMerge *merge) -{ - GList *keys; - - gl_debug (DEBUG_WDGT, "START"); - - keys = gl_merge_get_key_list (merge); - if ( keys != NULL ) { - gtk_combo_set_popdown_strings (GTK_COMBO (image_select->key_combo), - keys); - gl_merge_free_key_list (&keys); - } else { - keys = g_list_append (keys, ""); - gtk_combo_set_popdown_strings (GTK_COMBO (image_select->key_combo), - keys); - g_list_free (keys); - } - - gl_debug (DEBUG_WDGT, "END"); -} - - -/****************************************************************************/ -/* Get widget data. */ -/****************************************************************************/ -glTextNode * -gl_wdgt_image_select_get_data (glWdgtImageSelect *image_select) -{ - glTextNode *text_node; - - gl_debug (DEBUG_WDGT, "START"); - - text_node = g_new0(glTextNode,1); - - if (gtk_toggle_button_get_active - (GTK_TOGGLE_BUTTON (image_select->file_radio))) { - text_node->field_flag = FALSE; - text_node->data = - gnome_pixmap_entry_get_filename (GNOME_PIXMAP_ENTRY(image_select->file_entry)); - } else { - text_node->field_flag = TRUE; - text_node->data = - gtk_editable_get_chars (GTK_EDITABLE (image_select->key_entry), - 0, -1); - gl_debug (DEBUG_WDGT, "text_node: field_flag=%d, data=%s", - text_node->field_flag, text_node->data); - } - - gl_debug (DEBUG_WDGT, "END"); - - return text_node; -} - -/****************************************************************************/ -/* Set widget data. */ -/****************************************************************************/ -void -gl_wdgt_image_select_set_data (glWdgtImageSelect *image_select, - gboolean merge_flag, - glTextNode *text_node) -{ - gint pos; - - gl_debug (DEBUG_WDGT, "START"); - - gtk_widget_set_sensitive (image_select->key_radio, merge_flag); - - if (!text_node->field_flag) { - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON - (image_select->file_radio), TRUE); - - gtk_widget_set_sensitive (image_select->file_entry, TRUE); - gtk_widget_set_sensitive (image_select->key_combo, FALSE); - - if (text_node->data != NULL ) { - gnome_file_entry_set_filename (GNOME_FILE_ENTRY(image_select->file_entry), - text_node->data); - } else { - gnome_file_entry_set_filename (GNOME_FILE_ENTRY(image_select->file_entry), - ""); - } - } else { - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON - (image_select->key_radio), TRUE); - - gtk_widget_set_sensitive (image_select->file_entry, FALSE); - gtk_widget_set_sensitive (image_select->key_combo, TRUE); - - g_signal_handlers_block_by_func (G_OBJECT - (image_select->key_entry), - G_CALLBACK (changed_cb), - image_select); - gtk_editable_delete_text (GTK_EDITABLE (image_select->key_entry), 0, - -1); - g_signal_handlers_unblock_by_func (G_OBJECT - (image_select->key_entry), - G_CALLBACK - (changed_cb), image_select); - - pos = 0; - gtk_editable_insert_text (GTK_EDITABLE (image_select->key_entry), - text_node->data, - strlen (text_node->data), - &pos); - } - - gl_debug (DEBUG_WDGT, "END"); -} - -/****************************************************************************/ -/* Set size group for internal labels */ -/****************************************************************************/ -void -gl_wdgt_image_select_set_label_size_group (glWdgtImageSelect *image_select, - GtkSizeGroup *label_size_group) -{ - gl_debug (DEBUG_WDGT, "START"); - - gtk_size_group_add_widget (label_size_group, image_select->file_radio); - gtk_size_group_add_widget (label_size_group, image_select->key_radio); - - gl_debug (DEBUG_WDGT, "END"); -} diff --git a/glabels2/src/wdgt-image-select.h b/glabels2/src/wdgt-image-select.h deleted file mode 100644 index 69e4eb40..00000000 --- a/glabels2/src/wdgt-image-select.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * (GLABELS) Label and Business Card Creation program for GNOME - * - * wdgt_image_select.h: image selection widget module header file - * - * Copyright (C) 2001-2002 Jim Evins . - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef __WDGT_IMAGE_SELECT_H__ -#define __WDGT_IMAGE_SELECT_H__ - -#include -#include "text-node.h" -#include "hig.h" - -G_BEGIN_DECLS - -#define GL_TYPE_WDGT_IMAGE_SELECT (gl_wdgt_image_select_get_type ()) -#define GL_WDGT_IMAGE_SELECT(obj) \ - (GTK_CHECK_CAST((obj), GL_TYPE_WDGT_IMAGE_SELECT, glWdgtImageSelect )) -#define GL_WDGT_IMAGE_SELECT_CLASS(klass) \ - (GTK_CHECK_CLASS_CAST ((klass), GL_TYPE_WDGT_IMAGE_SELECT, glWdgtImageSelectClass)) -#define GL_IS_WDGT_IMAGE_SELECT(obj) \ - (GTK_CHECK_TYPE ((obj), GL_TYPE_WDGT_IMAGE_SELECT)) -#define GL_IS_WDGT_IMAGE_SELECT_CLASS(klass) \ - (GTK_CHECK_CLASS_TYPE ((klass), GL_TYPE_WDGT_IMAGE_SELECT)) - -typedef struct _glWdgtImageSelect glWdgtImageSelect; -typedef struct _glWdgtImageSelectClass glWdgtImageSelectClass; - -struct _glWdgtImageSelect { - glHigVBox parent_widget; - - GtkWidget *file_radio; - GtkWidget *file_entry; - - GtkWidget *key_radio; - GtkWidget *key_combo; - GtkWidget *key_entry; -}; - -struct _glWdgtImageSelectClass { - glHigVBoxClass parent_class; - - void (*changed) (glWdgtImageSelect *image_select, - gpointer user_data); -}; - -GType gl_wdgt_image_select_get_type (void) G_GNUC_CONST; - -GtkWidget *gl_wdgt_image_select_new (glMerge *merge, - glTextNode *text_node); - -void gl_wdgt_image_select_set_field_defs (glWdgtImageSelect *image_select, - glMerge *merge); - -glTextNode *gl_wdgt_image_select_get_data (glWdgtImageSelect *image_select); - -void gl_wdgt_image_select_set_data (glWdgtImageSelect *image_select, - gboolean merge_flag, - glTextNode *text_node); - -void gl_wdgt_image_select_set_label_size_group (glWdgtImageSelect *image_select, - GtkSizeGroup *label_size_group); - -G_END_DECLS - -#endif