]> git.sur5r.net Git - glabels/blob - glabels2/src/object-editor-image-page.c
2004-07-12 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / src / object-editor-image-page.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  object-editor.c:  object properties editor module
5  *
6  *  Copyright (C) 2003  Jim Evins <evins@snaught.com>.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  */
22 #include <config.h>
23
24 #include <gnome.h>
25 #include <math.h>
26
27 #include "object-editor.h"
28 #include "prefs.h"
29
30 #include "object-editor-private.h"
31
32 #include "debug.h"
33
34 /*===========================================*/
35 /* Private macros                            */
36 /*===========================================*/
37
38 /*===========================================*/
39 /* Private data types                        */
40 /*===========================================*/
41
42 /*===========================================*/
43 /* Private globals                           */
44 /*===========================================*/
45
46 /*===========================================*/
47 /* Local function prototypes                 */
48 /*===========================================*/
49
50 static void img_radio_toggled_cb                (glObjectEditor        *editor);
51
52
53 \f
54 /*--------------------------------------------------------------------------*/
55 /* PRIVATE.  Prepare image page.                                             */
56 /*--------------------------------------------------------------------------*/
57 void
58 gl_object_editor_prepare_image_page (glObjectEditor *editor)
59 {
60         GdkColor     *gdk_color;
61         GtkWidget    *ge;
62
63         gl_debug (DEBUG_EDITOR, "START");
64
65         /* Extract widgets from XML tree. */
66         editor->priv->img_page_vbox    = glade_xml_get_widget (editor->priv->gui,
67                                                                "img_page_vbox");
68         editor->priv->img_file_radio   = glade_xml_get_widget (editor->priv->gui,
69                                                                "img_file_radio");
70         editor->priv->img_key_radio    = glade_xml_get_widget (editor->priv->gui,
71                                                                "img_key_radio");
72         editor->priv->img_pixmap_entry = glade_xml_get_widget (editor->priv->gui,
73                                                               "img_pixmap_entry");
74         editor->priv->img_key_combo    = glade_xml_get_widget (editor->priv->gui,
75                                                                "img_key_combo");
76         editor->priv->img_key_entry    = glade_xml_get_widget (editor->priv->gui,
77                                                                "img_key_entry");
78
79         /* Un-hide */
80         gtk_widget_show_all (editor->priv->img_page_vbox);
81
82         /* Connect signals */
83         ge = gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(editor->priv->img_pixmap_entry));
84         g_signal_connect_swapped (G_OBJECT (ge),
85                                   "changed",
86                                   G_CALLBACK (gl_object_editor_changed_cb),
87                                   G_OBJECT (editor));
88         g_signal_connect_swapped (G_OBJECT (editor->priv->img_key_entry),
89                                   "changed",
90                                   G_CALLBACK (gl_object_editor_changed_cb),
91                                   G_OBJECT (editor));
92         g_signal_connect_swapped (G_OBJECT (editor->priv->img_file_radio),
93                                   "toggled",
94                                   G_CALLBACK (img_radio_toggled_cb),
95                                   G_OBJECT (editor));
96         g_signal_connect_swapped (G_OBJECT (editor->priv->img_key_radio),
97                                   "toggled",
98                                   G_CALLBACK (img_radio_toggled_cb),
99                                   G_OBJECT (editor));
100
101         gl_debug (DEBUG_EDITOR, "END");
102 }
103
104 /*--------------------------------------------------------------------------*/
105 /* PRIVATE.  image radio callback.                                          */
106 /*--------------------------------------------------------------------------*/
107 static void
108 img_radio_toggled_cb (glObjectEditor *editor)
109 {
110         gl_debug (DEBUG_WDGT, "START");
111  
112         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->img_file_radio))) {
113                 gtk_widget_set_sensitive (editor->priv->img_pixmap_entry, TRUE);
114                 gtk_widget_set_sensitive (editor->priv->img_key_combo, FALSE);
115         } else {
116                 gtk_widget_set_sensitive (editor->priv->img_pixmap_entry, FALSE);
117                 gtk_widget_set_sensitive (editor->priv->img_key_combo, TRUE);
118         }
119  
120         /* Emit our "changed" signal */
121         g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
122  
123         gl_debug (DEBUG_WDGT, "END");
124 }
125
126 /*****************************************************************************/
127 /* Set image.                                                                */
128 /*****************************************************************************/
129 void
130 gl_object_editor_set_image (glObjectEditor      *editor,
131                             gboolean             merge_flag,
132                             glTextNode          *text_node)
133 {
134         gint pos;
135  
136         gl_debug (DEBUG_EDITOR, "START");
137  
138         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->img_pixmap_entry),
139                                          G_CALLBACK (gl_object_editor_changed_cb),
140                                          editor);
141         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->img_key_entry),
142                                          G_CALLBACK (gl_object_editor_changed_cb),
143                                          editor);
144
145         gtk_widget_set_sensitive (editor->priv->img_key_radio, merge_flag);
146  
147         if (!text_node->field_flag) {
148  
149                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
150                                               (editor->priv->img_file_radio), TRUE); 
151                 gtk_widget_set_sensitive (editor->priv->img_pixmap_entry, TRUE);
152                 gtk_widget_set_sensitive (editor->priv->img_key_combo, FALSE);
153  
154                 if (text_node->data != NULL ) {
155                         gnome_file_entry_set_filename (GNOME_FILE_ENTRY(editor->priv->img_pixmap_entry),
156                                                        text_node->data);
157                 } else {
158                         gnome_file_entry_set_filename (GNOME_FILE_ENTRY(editor->priv->img_pixmap_entry),
159                                                        "");
160                 }
161         } else {
162                                                                                 
163                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
164                                               (editor->priv->img_key_radio), TRUE);
165                                                                                 
166                 gtk_widget_set_sensitive (editor->priv->img_pixmap_entry, FALSE);
167                 gtk_widget_set_sensitive (editor->priv->img_key_combo, TRUE);
168                                                                                 
169                 gtk_editable_delete_text (GTK_EDITABLE (editor->priv->img_key_entry), 0, -1);
170                 pos = 0;
171                 gtk_editable_insert_text (GTK_EDITABLE (editor->priv->img_key_entry),
172                                           text_node->data,
173                                           strlen (text_node->data),
174                                           &pos);
175         }
176                                                                                 
177         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->img_pixmap_entry),
178                                            G_CALLBACK (gl_object_editor_changed_cb),
179                                            editor);
180         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->img_key_entry),
181                                            G_CALLBACK (gl_object_editor_changed_cb),
182                                            editor);
183                                                                                 
184         gl_debug (DEBUG_EDITOR, "END");
185 }
186
187 /*****************************************************************************/
188 /* Query image.                                                              */
189 /*****************************************************************************/
190 glTextNode *
191 gl_object_editor_get_image (glObjectEditor      *editor)
192 {
193         glTextNode *text_node;
194  
195         gl_debug (DEBUG_EDITOR, "START");
196  
197         text_node = g_new0(glTextNode,1);
198  
199         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->img_file_radio))) {
200                 text_node->field_flag = FALSE;
201                 text_node->data =
202                         gnome_pixmap_entry_get_filename (GNOME_PIXMAP_ENTRY(editor->priv->img_pixmap_entry));
203         } else {
204                 text_node->field_flag = TRUE;
205                 text_node->data =
206                     gtk_editable_get_chars (GTK_EDITABLE (editor->priv->img_key_entry),
207                                             0, -1);
208         }
209  
210         gl_debug (DEBUG_EDITOR, "text_node: field_flag=%d, data=%s",
211                   text_node->field_flag, text_node->data);
212
213         gl_debug (DEBUG_EDITOR, "END");
214  
215         return text_node;
216 }
217