]> git.sur5r.net Git - glabels/blob - src/object-editor-text-page.c
Imported Upstream version 3.2.0
[glabels] / src / object-editor-text-page.c
1 /*
2  *  object-editor-text-page.c
3  *  Copyright (C) 2003-2009  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
7  *  gLabels is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  gLabels is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <config.h>
22
23 #include "object-editor.h"
24
25 #include <glib/gi18n.h>
26 #include <gtk/gtk.h>
27 #include <math.h>
28
29 #include "prefs.h"
30 #include "color-combo.h"
31 #include "color.h"
32 #include "font-combo.h"
33 #include "font-util.h"
34 #include "field-button.h"
35 #include "builder-util.h"
36
37 #include "object-editor-private.h"
38
39 #include "debug.h"
40
41
42 /*===========================================*/
43 /* Private macros                            */
44 /*===========================================*/
45
46
47 /*===========================================*/
48 /* Private data types                        */
49 /*===========================================*/
50
51
52 /*===========================================*/
53 /* Private globals                           */
54 /*===========================================*/
55
56
57 /*===========================================*/
58 /* Local function prototypes                 */
59 /*===========================================*/
60
61 static void align_toggle_cb (GtkToggleButton *toggle,
62                              glObjectEditor  *editor);
63 static void valign_toggle_cb (GtkToggleButton *toggle,
64                               glObjectEditor  *editor);
65 static void text_radio_toggled_cb              (glObjectEditor        *editor);
66
67
68 /*--------------------------------------------------------------------------*/
69 /* PRIVATE.  Prepare size page.                                             */
70 /*--------------------------------------------------------------------------*/
71 void
72 gl_object_editor_prepare_text_page (glObjectEditor       *editor)
73 {
74         gl_debug (DEBUG_EDITOR, "START");
75
76         /* Extract widgets from XML tree. */
77         gl_builder_util_get_widgets (editor->priv->builder,
78                                      "text_page_vbox",         &editor->priv->text_page_vbox,
79                                      "text_family_hbox",       &editor->priv->text_family_hbox,
80                                      "text_size_spin",         &editor->priv->text_size_spin,
81                                      "text_bold_toggle",       &editor->priv->text_bold_toggle,
82                                      "text_italic_toggle",     &editor->priv->text_italic_toggle,
83                                      "text_color_hbox",        &editor->priv->text_color_hbox,
84                                      "text_color_radio",       &editor->priv->text_color_radio,
85                                      "text_color_key_radio",   &editor->priv->text_color_key_radio,
86                                      "text_color_key_hbox",    &editor->priv->text_color_key_hbox,
87                                      "text_left_toggle",       &editor->priv->text_left_toggle,
88                                      "text_center_toggle",     &editor->priv->text_center_toggle,
89                                      "text_right_toggle",      &editor->priv->text_right_toggle,
90                                      "text_top_toggle",        &editor->priv->text_top_toggle,
91                                      "text_vcenter_toggle",    &editor->priv->text_vcenter_toggle,
92                                      "text_bottom_toggle",     &editor->priv->text_bottom_toggle,
93                                      "text_line_spacing_spin", &editor->priv->text_line_spacing_spin,
94                                      "text_auto_shrink_check", &editor->priv->text_auto_shrink_check,
95                                      NULL);
96
97         editor->priv->text_family_combo = gl_font_combo_new ("Sans");
98         gtk_box_pack_start (GTK_BOX (editor->priv->text_family_hbox),
99                             editor->priv->text_family_combo,
100                             TRUE, TRUE, 0);
101
102         editor->priv->text_color_combo = gl_color_combo_new (_("Default"),
103                                                              GL_COLOR_TEXT_DEFAULT,
104                                                              gl_prefs_model_get_default_text_color (gl_prefs));
105         gtk_box_pack_start (GTK_BOX (editor->priv->text_color_hbox),
106                             editor->priv->text_color_combo,
107                             FALSE, FALSE, 0);
108
109         editor->priv->text_color_key_combo = gl_field_button_new (NULL);
110         gtk_box_pack_start (GTK_BOX (editor->priv->text_color_key_hbox),
111                             editor->priv->text_color_key_combo,
112                             TRUE, TRUE, 0);
113
114
115         /* Modify widgets */
116         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio), TRUE);
117         gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
118         gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
119
120         /* Un-hide */
121         gtk_widget_show_all (editor->priv->text_page_vbox);
122
123         /* Connect signals */
124         g_signal_connect_swapped (G_OBJECT (editor->priv->text_family_combo),
125                                   "changed",
126                                   G_CALLBACK (gl_object_editor_changed_cb),
127                                   G_OBJECT (editor));
128         g_signal_connect_swapped (G_OBJECT (editor->priv->text_size_spin),
129                                   "value-changed",
130                                   G_CALLBACK (gl_object_editor_changed_cb),
131                                   G_OBJECT (editor));
132         g_signal_connect_swapped (G_OBJECT (editor->priv->text_bold_toggle),
133                                   "toggled",
134                                   G_CALLBACK (gl_object_editor_changed_cb),
135                                   G_OBJECT (editor));
136         g_signal_connect_swapped (G_OBJECT (editor->priv->text_italic_toggle),
137                                   "toggled",
138                                   G_CALLBACK (gl_object_editor_changed_cb),
139                                   G_OBJECT (editor));
140         g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_combo),
141                                   "color_changed",
142                                   G_CALLBACK (gl_object_editor_changed_cb),
143                                   G_OBJECT (editor));
144         g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_key_combo),
145                                   "changed",
146                                   G_CALLBACK (gl_object_editor_changed_cb),
147                                   G_OBJECT (editor));
148         g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_radio),
149                                   "toggled",
150                                   G_CALLBACK (text_radio_toggled_cb),
151                                   G_OBJECT (editor));                             
152         g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_key_radio),
153                                   "toggled",
154                                   G_CALLBACK (text_radio_toggled_cb),
155                                   G_OBJECT (editor));
156
157         g_signal_connect (G_OBJECT (editor->priv->text_left_toggle),
158                           "toggled",
159                           G_CALLBACK (align_toggle_cb),
160                           G_OBJECT (editor));
161         g_signal_connect (G_OBJECT (editor->priv->text_center_toggle),
162                           "toggled",
163                           G_CALLBACK (align_toggle_cb),
164                           G_OBJECT (editor));
165         g_signal_connect (G_OBJECT (editor->priv->text_right_toggle),
166                           "toggled",
167                           G_CALLBACK (align_toggle_cb),
168                           G_OBJECT (editor));
169
170         g_signal_connect (G_OBJECT (editor->priv->text_top_toggle),
171                           "toggled",
172                           G_CALLBACK (valign_toggle_cb),
173                           G_OBJECT (editor));
174         g_signal_connect (G_OBJECT (editor->priv->text_vcenter_toggle),
175                           "toggled",
176                           G_CALLBACK (valign_toggle_cb),
177                           G_OBJECT (editor));
178         g_signal_connect (G_OBJECT (editor->priv->text_bottom_toggle),
179                           "toggled",
180                           G_CALLBACK (valign_toggle_cb),
181                           G_OBJECT (editor));
182
183         g_signal_connect_swapped (G_OBJECT (editor->priv->text_line_spacing_spin),
184                                   "value-changed",
185                                   G_CALLBACK (gl_object_editor_changed_cb),
186                                   G_OBJECT (editor));
187
188         g_signal_connect_swapped (G_OBJECT (editor->priv->text_auto_shrink_check),
189                                   "toggled",
190                                   G_CALLBACK (gl_object_editor_changed_cb),
191                                   G_OBJECT (editor));
192
193         gl_debug (DEBUG_EDITOR, "END");
194 }
195
196
197 /*--------------------------------------------------------------------------*/
198 /* PRIVATE.  Alignment togglebutton callback.                               */
199 /*--------------------------------------------------------------------------*/
200 static void
201 align_toggle_cb (GtkToggleButton *toggle,
202                  glObjectEditor  *editor)
203 {
204         if (gtk_toggle_button_get_active (toggle)) {
205  
206                 if (GTK_WIDGET (toggle) == GTK_WIDGET (editor->priv->text_left_toggle)) {
207                         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
208                                                       (editor->priv->text_center_toggle),
209                                                       FALSE);
210                         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
211                                                       (editor->priv->text_right_toggle),
212                                                       FALSE);
213                 } else if (GTK_WIDGET (toggle) ==
214                            GTK_WIDGET (editor->priv->text_center_toggle)) {
215                         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
216                                                       (editor->priv->text_left_toggle),
217                                                       FALSE);
218                         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
219                                                       (editor->priv->text_right_toggle),
220                                                       FALSE);
221                 } else if (GTK_WIDGET (toggle) ==
222                            GTK_WIDGET (editor->priv->text_right_toggle)) {
223                         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
224                                                       (editor->priv->text_left_toggle),
225                                                       FALSE);
226                         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
227                                                       (editor->priv->text_center_toggle),
228                                                       FALSE);
229                 }
230
231                 gl_object_editor_changed_cb (editor);
232         }
233
234 }
235
236
237 /*--------------------------------------------------------------------------*/
238 /* PRIVATE.  Vertical alignment togglebutton callback.                      */
239 /*--------------------------------------------------------------------------*/
240 static void
241 valign_toggle_cb (GtkToggleButton *toggle,
242                  glObjectEditor  *editor)
243 {
244         if (gtk_toggle_button_get_active (toggle)) {
245
246                 if (GTK_WIDGET (toggle) == GTK_WIDGET (editor->priv->text_top_toggle)) {
247                         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
248                                                       (editor->priv->text_vcenter_toggle),
249                                                       FALSE);
250                         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
251                                                       (editor->priv->text_bottom_toggle),
252                                                       FALSE);
253                 } else if (GTK_WIDGET (toggle) ==
254                            GTK_WIDGET (editor->priv->text_vcenter_toggle)) {
255                         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
256                                                       (editor->priv->text_top_toggle),
257                                                       FALSE);
258                         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
259                                                       (editor->priv->text_bottom_toggle),
260                                                       FALSE);
261                 } else if (GTK_WIDGET (toggle) ==
262                            GTK_WIDGET (editor->priv->text_bottom_toggle)) {
263                         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
264                                                       (editor->priv->text_top_toggle),
265                                                       FALSE);
266                         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
267                                                       (editor->priv->text_vcenter_toggle),
268                                                       FALSE);
269                 }
270
271                 gl_object_editor_changed_cb (editor);
272         }
273
274 }
275
276
277 /*****************************************************************************/
278 /* Set font family.                                                          */
279 /*****************************************************************************/
280 void
281 gl_object_editor_set_font_family (glObjectEditor      *editor,
282                                   const gchar         *font_family)
283 {
284         gchar    *old_font_family;
285
286         if (font_family == NULL)
287         {
288                 return;
289         }
290
291         gl_debug (DEBUG_EDITOR, "START");
292
293
294         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_family_combo),
295                                          gl_object_editor_changed_cb, editor);
296
297
298         old_font_family = gl_font_combo_get_family (GL_FONT_COMBO (editor->priv->text_family_combo));
299
300         if ( !old_font_family || g_utf8_collate( old_font_family, font_family ) )
301         {
302                 gl_font_combo_set_family (GL_FONT_COMBO (editor->priv->text_family_combo),
303                                           font_family);
304         }
305
306         g_free (old_font_family);
307
308
309         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_family_combo),
310                                            gl_object_editor_changed_cb, editor);
311
312
313         gl_debug (DEBUG_EDITOR, "END");
314 }
315
316
317 /*****************************************************************************/
318 /* Query font family.                                                        */
319 /*****************************************************************************/
320 gchar *
321 gl_object_editor_get_font_family (glObjectEditor      *editor)
322 {
323         gchar *font_family;
324
325         gl_debug (DEBUG_EDITOR, "START");
326
327         font_family = gl_font_combo_get_family (GL_FONT_COMBO (editor->priv->text_family_combo));
328
329         gl_debug (DEBUG_EDITOR, "END");
330
331         return font_family;
332 }
333
334
335 /*****************************************************************************/
336 /* Set font size.                                                            */
337 /*****************************************************************************/
338 void
339 gl_object_editor_set_font_size (glObjectEditor      *editor,
340                                 gdouble              font_size)
341 {
342         gl_debug (DEBUG_EDITOR, "START");
343
344
345         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_size_spin),
346                                          gl_object_editor_changed_cb, editor);
347
348
349         gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->text_size_spin),
350                                    font_size);
351
352
353         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_size_spin),
354                                            gl_object_editor_changed_cb, editor);
355
356
357         gl_debug (DEBUG_EDITOR, "END");
358 }
359
360
361 /*****************************************************************************/
362 /* Query font size.                                                          */
363 /*****************************************************************************/
364 gdouble
365 gl_object_editor_get_font_size (glObjectEditor      *editor)
366 {
367         gdouble font_size;
368
369         gl_debug (DEBUG_EDITOR, "START");
370
371         font_size =
372                 gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->text_size_spin));
373
374         gl_debug (DEBUG_EDITOR, "END");
375
376         return font_size;
377 }
378
379
380 /*****************************************************************************/
381 /* Set font weight.                                                          */
382 /*****************************************************************************/
383 void
384 gl_object_editor_set_font_weight (glObjectEditor      *editor,
385                                   PangoWeight          font_weight)
386 {
387         gl_debug (DEBUG_EDITOR, "START");
388
389
390         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_bold_toggle),
391                                          gl_object_editor_changed_cb, editor);
392
393
394         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_bold_toggle),
395                                       (font_weight == PANGO_WEIGHT_BOLD));
396
397
398         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_bold_toggle),
399                                            gl_object_editor_changed_cb, editor);
400
401
402         gl_debug (DEBUG_EDITOR, "END");
403 }
404
405
406 /*****************************************************************************/
407 /* Query font weight.                                                        */
408 /*****************************************************************************/
409 PangoWeight
410 gl_object_editor_get_font_weight (glObjectEditor      *editor)
411 {
412         PangoWeight font_weight;
413
414         gl_debug (DEBUG_EDITOR, "START");
415
416         if (gtk_toggle_button_get_active
417             (GTK_TOGGLE_BUTTON (editor->priv->text_bold_toggle))) {
418                 font_weight = PANGO_WEIGHT_BOLD;
419         } else {
420                 font_weight = PANGO_WEIGHT_NORMAL;
421         }
422
423         gl_debug (DEBUG_EDITOR, "END");
424
425         return font_weight;
426 }
427
428
429 /*****************************************************************************/
430 /* Set font italic flag.                                                     */
431 /*****************************************************************************/
432 void
433 gl_object_editor_set_font_italic_flag (glObjectEditor      *editor,
434                                        gboolean             font_italic_flag)
435 {
436         gl_debug (DEBUG_EDITOR, "START");
437
438
439         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_italic_toggle),
440                                          gl_object_editor_changed_cb, editor);
441
442
443         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_italic_toggle),
444                                       font_italic_flag);
445
446
447         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_italic_toggle),
448                                            gl_object_editor_changed_cb, editor);
449
450
451         gl_debug (DEBUG_EDITOR, "END");
452 }
453
454
455 /*****************************************************************************/
456 /* Query font italic flag.                                                   */
457 /*****************************************************************************/
458 gboolean
459 gl_object_editor_get_font_italic_flag (glObjectEditor      *editor)
460 {
461         gboolean italic_flag;
462
463         gl_debug (DEBUG_EDITOR, "START");
464
465         italic_flag =
466                 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
467                                               (editor->priv->text_italic_toggle));
468
469         gl_debug (DEBUG_EDITOR, "END");
470
471         return italic_flag;
472 }
473
474
475 /*****************************************************************************/
476 /* Set text alignment.                                                       */
477 /*****************************************************************************/
478 void
479 gl_object_editor_set_text_alignment (glObjectEditor      *editor,
480                                      PangoAlignment       align)
481 {
482         gl_debug (DEBUG_EDITOR, "START");
483
484
485         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_left_toggle), align_toggle_cb, editor);
486         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_center_toggle), align_toggle_cb, editor);
487         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_right_toggle), align_toggle_cb, editor);
488
489
490         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_left_toggle),
491                                       (align == PANGO_ALIGN_LEFT));
492         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_center_toggle),
493                                       (align == PANGO_ALIGN_CENTER));
494         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_right_toggle),
495                                       (align == PANGO_ALIGN_RIGHT));
496
497
498         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_left_toggle), align_toggle_cb, editor);
499         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_center_toggle), align_toggle_cb, editor);
500         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_right_toggle), align_toggle_cb, editor);
501
502
503         gl_debug (DEBUG_EDITOR, "END");
504 }
505
506
507 /*****************************************************************************/
508 /* Query text alignment.                                                     */
509 /*****************************************************************************/
510 PangoAlignment
511 gl_object_editor_get_text_alignment (glObjectEditor      *editor)
512 {
513         PangoAlignment align;
514
515         gl_debug (DEBUG_EDITOR, "START");
516
517         if (gtk_toggle_button_get_active
518             (GTK_TOGGLE_BUTTON (editor->priv->text_left_toggle))) {
519                 align = PANGO_ALIGN_LEFT;
520         } else
521             if (gtk_toggle_button_get_active
522                 (GTK_TOGGLE_BUTTON (editor->priv->text_right_toggle))) {
523                 align = PANGO_ALIGN_RIGHT;
524         } else
525             if (gtk_toggle_button_get_active
526                 (GTK_TOGGLE_BUTTON (editor->priv->text_center_toggle))) {
527                 align = PANGO_ALIGN_CENTER;
528         } else {
529                 align = PANGO_ALIGN_LEFT;       /* Should not happen. */
530         }
531
532         gl_debug (DEBUG_EDITOR, "END");
533
534         return align;
535 }
536
537
538 /*****************************************************************************/
539 /* Set vertical text alignment.                                              */
540 /*****************************************************************************/
541 void
542 gl_object_editor_set_text_valignment (glObjectEditor      *editor,
543                                       glValignment         valign)
544 {
545         gl_debug (DEBUG_EDITOR, "START");
546
547
548         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_top_toggle), valign_toggle_cb, editor);
549         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_vcenter_toggle), valign_toggle_cb, editor);
550         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_bottom_toggle), valign_toggle_cb, editor);
551
552
553         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_top_toggle),
554                                       (valign == GL_VALIGN_TOP));
555         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_vcenter_toggle),
556                                       (valign == GL_VALIGN_VCENTER));
557         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_bottom_toggle),
558                                       (valign == GL_VALIGN_BOTTOM));
559
560
561         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_top_toggle), valign_toggle_cb, editor);
562         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_vcenter_toggle), valign_toggle_cb, editor);
563         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_bottom_toggle), valign_toggle_cb, editor);
564
565
566         gl_debug (DEBUG_EDITOR, "END");
567 }
568
569
570 /*****************************************************************************/
571 /* Query vertical text alignment.                                            */
572 /*****************************************************************************/
573 glValignment
574 gl_object_editor_get_text_valignment (glObjectEditor      *editor)
575 {
576         glValignment valign;
577
578         gl_debug (DEBUG_EDITOR, "START");
579
580         if (gtk_toggle_button_get_active
581             (GTK_TOGGLE_BUTTON (editor->priv->text_top_toggle))) {
582                 valign = GL_VALIGN_TOP;
583         } else
584             if (gtk_toggle_button_get_active
585                 (GTK_TOGGLE_BUTTON (editor->priv->text_bottom_toggle))) {
586                 valign = GL_VALIGN_BOTTOM;
587         } else
588             if (gtk_toggle_button_get_active
589                 (GTK_TOGGLE_BUTTON (editor->priv->text_vcenter_toggle))) {
590                 valign = GL_VALIGN_VCENTER;
591         } else {
592                 valign = GL_VALIGN_TOP;       /* Should not happen. */
593         }
594
595         gl_debug (DEBUG_EDITOR, "END");
596
597         return valign;
598 }
599
600
601 /*****************************************************************************/
602 /* Set text color.                                                           */
603 /*****************************************************************************/
604 void
605 gl_object_editor_set_text_color (glObjectEditor      *editor,
606                                  gboolean             merge_flag,
607                                  glColorNode         *text_color_node)
608 {
609         gl_debug (DEBUG_EDITOR, "START");
610
611         if (text_color_node == NULL)
612         {
613                 return;
614         }
615
616
617         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_color_combo),
618                                          gl_object_editor_changed_cb, editor);
619         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_color_radio),
620                                          text_radio_toggled_cb, editor);
621         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_color_key_radio),
622                                          text_radio_toggled_cb, editor);
623         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_color_key_combo),
624                                          gl_object_editor_changed_cb, editor);
625
626
627         gl_debug (DEBUG_EDITOR, "color field %s(%d) / %X",
628                   text_color_node->key, text_color_node->field_flag, text_color_node->color);
629         
630         gtk_widget_set_sensitive (editor->priv->text_color_key_radio, merge_flag);
631
632         if ( text_color_node->color == GL_COLOR_NONE ) {
633
634                 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->text_color_combo));
635
636         } else {
637                 
638                 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->text_color_combo),
639                                           text_color_node->color);
640         }
641         
642         if (!text_color_node->field_flag || !merge_flag)
643         {
644                 gl_debug (DEBUG_EDITOR, "color field false");
645                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio), TRUE); 
646                 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
647                 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
648                 
649         }
650         else
651         {
652                 gl_debug (DEBUG_EDITOR, "color field true");
653                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_key_radio), TRUE); 
654                 gtk_widget_set_sensitive (editor->priv->text_color_combo, FALSE);
655                 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, TRUE);
656                 
657                 gl_field_button_set_key (GL_FIELD_BUTTON (editor->priv->text_color_key_combo), "");
658         }
659
660
661         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_color_combo),
662                                            gl_object_editor_changed_cb, editor);
663         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_color_radio),
664                                            text_radio_toggled_cb, editor);
665         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_color_key_radio),
666                                            text_radio_toggled_cb, editor);
667         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_color_key_combo),
668                                            gl_object_editor_changed_cb, editor);
669
670
671         gl_debug (DEBUG_EDITOR, "END");
672 }
673
674
675 /*****************************************************************************/
676 /* Query text color.                                                         */
677 /*****************************************************************************/
678 glColorNode*
679 gl_object_editor_get_text_color (glObjectEditor      *editor)
680 {
681         guint        color;
682         glColorNode *color_node;
683         gboolean     is_default;
684
685         gl_debug (DEBUG_EDITOR, "START");
686
687         color_node = gl_color_node_new_default ();
688         
689         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_key_radio))) {
690                 color_node->field_flag = TRUE;
691                 color_node->color = gl_prefs_model_get_default_text_color (gl_prefs);
692                 color_node->key = 
693                         gl_field_button_get_key (GL_FIELD_BUTTON (editor->priv->text_color_key_combo));
694         } else {
695                 color_node->field_flag = FALSE;
696                 color_node->key = NULL;
697                 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->text_color_combo),
698                                                   &is_default);
699
700                 if (is_default) {
701                         color_node->color = gl_prefs_model_get_default_text_color (gl_prefs);
702                 } else {
703                         color_node->color = color;
704                 }
705         }      
706
707         gl_debug (DEBUG_EDITOR, "END");
708
709         return color_node;
710 }
711
712
713 /*****************************************************************************/
714 /* Set text line spacing.                                                    */
715 /*****************************************************************************/
716 void
717 gl_object_editor_set_text_line_spacing (glObjectEditor      *editor,
718                                         gdouble              text_line_spacing)
719 {
720         gl_debug (DEBUG_EDITOR, "START");
721
722
723         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_line_spacing_spin),
724                                          gl_object_editor_changed_cb, editor);
725
726
727         gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->text_line_spacing_spin),
728                                    text_line_spacing);
729
730
731         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_line_spacing_spin),
732                                            gl_object_editor_changed_cb, editor);
733
734
735         gl_debug (DEBUG_EDITOR, "END");
736 }
737
738
739 /*****************************************************************************/
740 /* Query text line spacing.                                                  */
741 /*****************************************************************************/
742 gdouble
743 gl_object_editor_get_text_line_spacing (glObjectEditor      *editor)
744 {
745         gdouble text_line_spacing;
746
747         gl_debug (DEBUG_EDITOR, "START");
748
749         text_line_spacing = 
750                 gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->text_line_spacing_spin));
751
752         gl_debug (DEBUG_EDITOR, "END");
753
754         return text_line_spacing;
755 }
756
757
758 /*****************************************************************************/
759 /* Set auto shrink checkbox.                                                 */
760 /*****************************************************************************/
761 void
762 gl_object_editor_set_text_auto_shrink (glObjectEditor      *editor,
763                                        gboolean             auto_shrink)
764 {
765         gl_debug (DEBUG_EDITOR, "START");
766
767
768         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_auto_shrink_check),
769                                          gl_object_editor_changed_cb, editor);
770
771
772         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check),
773                                       auto_shrink);
774
775
776         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_auto_shrink_check),
777                                            gl_object_editor_changed_cb, editor);
778
779
780         gl_debug (DEBUG_EDITOR, "END");
781 }
782
783
784 /*****************************************************************************/
785 /* Query auto shrink checkbox.                                               */
786 /*****************************************************************************/
787 gboolean    gl_object_editor_get_text_auto_shrink (glObjectEditor      *editor)
788 {
789         gboolean auto_shrink;
790
791         gl_debug (DEBUG_EDITOR, "START");
792
793         auto_shrink = 
794                 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check));
795
796         gl_debug (DEBUG_EDITOR, "END");
797
798         return auto_shrink;
799 }
800
801
802 /*--------------------------------------------------------------------------*/
803 /* PRIVATE.  color radio callback.                                           */
804 /*--------------------------------------------------------------------------*/
805 static void
806 text_radio_toggled_cb (glObjectEditor *editor)
807 {
808         gl_debug (DEBUG_EDITOR, "START");
809         
810         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio))) {
811                 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
812                 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
813         } else {
814                 gtk_widget_set_sensitive (editor->priv->text_color_combo, FALSE);
815                 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, TRUE);
816                 
817         }
818  
819         gl_object_editor_changed_cb (editor);
820  
821         gl_debug (DEBUG_EDITOR, "END");
822 }
823
824
825
826 /*
827  * Local Variables:       -- emacs
828  * mode: C                -- emacs
829  * c-basic-offset: 8      -- emacs
830  * tab-width: 8           -- emacs
831  * indent-tabs-mode: nil  -- emacs
832  * End:                   -- emacs
833  */