File: scim_panel_gtk_setup.cpp

package info (click to toggle)
scim 1.4.7-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 20,368 kB
  • ctags: 12,834
  • sloc: cpp: 51,239; sh: 22,370; ansic: 18,716; makefile: 1,258; xml: 641; yacc: 288
file content (829 lines) | stat: -rw-r--r-- 35,056 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
/** @file scim_panel_gtk_setup.cpp
 * implementation of Setup Module of scim-panel-gtk.
 */

/*
 * Smart Common Input Method
 * 
 * Copyright (c) 2002-2005 James Su <suzhe@tsinghua.org.cn>
 *
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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
 *
 * $Id: scim_panel_gtk_setup.cpp,v 1.15 2005/12/10 14:04:54 suzhe Exp $
 *
 */

#define Uses_SCIM_CONFIG_BASE
#define Uses_SCIM_PANEL

#include <gtk/gtk.h>
#include "scim_private.h"
#include "scim.h"

using namespace scim;

#define scim_module_init panel_gtk_setup_LTX_scim_module_init
#define scim_module_exit panel_gtk_setup_LTX_scim_module_exit

#define scim_setup_module_create_ui       panel_gtk_setup_LTX_scim_setup_module_create_ui
#define scim_setup_module_get_category    panel_gtk_setup_LTX_scim_setup_module_get_category
#define scim_setup_module_get_name        panel_gtk_setup_LTX_scim_setup_module_get_name
#define scim_setup_module_get_description panel_gtk_setup_LTX_scim_setup_module_get_description
#define scim_setup_module_load_config     panel_gtk_setup_LTX_scim_setup_module_load_config
#define scim_setup_module_save_config     panel_gtk_setup_LTX_scim_setup_module_save_config
#define scim_setup_module_query_changed   panel_gtk_setup_LTX_scim_setup_module_query_changed

#define SCIM_CONFIG_PANEL_GTK_FONT                      "/Panel/Gtk/Font"
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_ALWAYS_SHOW       "/Panel/Gtk/ToolBar/AlwaysShow"
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_ALWAYS_HIDDEN     "/Panel/Gtk/ToolBar/AlwaysHidden"
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_AUTO_SNAP         "/Panel/Gtk/ToolBar/AutoSnap"
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_HIDE_TIMEOUT      "/Panel/Gtk/ToolBar/HideTimeout"
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_POS_X             "/Panel/Gtk/ToolBar/POS_X"
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_POS_Y             "/Panel/Gtk/ToolBar/POS_Y"
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_FACTORY_ICON "/Panel/Gtk/ToolBar/ShowFactoryIcon"
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_FACTORY_NAME "/Panel/Gtk/ToolBar/ShowFactoryName"
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_STICK_ICON   "/Panel/Gtk/ToolBar/ShowStickIcon"
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_MENU_ICON    "/Panel/Gtk/ToolBar/ShowMenuIcon"
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_HELP_ICON    "/Panel/Gtk/ToolBar/ShowHelpIcon"
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_PROPERTY_LABEL "/Panel/Gtk/ToolBar/ShowPropertyLabel"
#define SCIM_CONFIG_PANEL_GTK_LOOKUP_TABLE_EMBEDDED     "/Panel/Gtk/LookupTableEmbedded"
#define SCIM_CONFIG_PANEL_GTK_LOOKUP_TABLE_VERTICAL     "/Panel/Gtk/LookupTableVertical"
#define SCIM_CONFIG_PANEL_GTK_DEFAULT_STICKED           "/Panel/Gtk/DefaultSticked"
#define SCIM_CONFIG_PANEL_GTK_SHOW_TRAY_ICON            "/Panel/Gtk/ShowTrayIcon"

static GtkWidget * create_setup_window ();
static void        load_config (const ConfigPointer &config);
static void        save_config (const ConfigPointer &config);
static bool        query_changed ();

// Module Interface.
extern "C" {
    void scim_module_init (void)
    {
    }

    void scim_module_exit (void)
    {
    }

    GtkWidget * scim_setup_module_create_ui (void)
    {
        return create_setup_window ();
    }

    String scim_setup_module_get_category (void)
    {
        return String ("Panel");
    }

    String scim_setup_module_get_name (void)
    {
        return String (_("GTK"));
    }

    String scim_setup_module_get_description (void)
    {
        return String (_("A panel daemon based on GTK+-2.x library."));
    }

    void scim_setup_module_load_config (const ConfigPointer &config)
    {
        load_config (config);
    }

    void scim_setup_module_save_config (const ConfigPointer &config)
    {
        save_config (config);
    }

    bool scim_setup_module_query_changed ()
    {
        return query_changed ();
    }
} // extern "C"

// Internal data declaration.
static bool   __config_toolbar_always_show       = false;
static bool   __config_toolbar_always_hidden     = false;
static bool   __config_toolbar_auto_snap         = false;
static int    __config_toolbar_hide_timeout      = 2;
static bool   __config_toolbar_show_factory_icon = true;
static bool   __config_toolbar_show_factory_name = true;
static bool   __config_toolbar_show_stick_icon   = false;
static bool   __config_toolbar_show_menu_icon    = true;
static bool   __config_toolbar_show_help_icon    = false;
static bool   __config_toolbar_show_property_label = true;
static bool   __config_lookup_table_embedded     = true;
static bool   __config_lookup_table_vertical     = false;
static bool   __config_default_sticked           = false;
static bool   __config_show_tray_icon            = true;

static String __config_font                      = "default";

static bool   __have_changed                     = false;

static GtkWidget * __widget_toolbar_show_behaviour    = 0;
static GtkWidget * __widget_toolbar_auto_snap         = 0;
static GtkWidget * __widget_toolbar_hide_timeout      = 0;
static GtkWidget * __widget_toolbar_show_factory_icon  = 0;
static GtkWidget * __widget_toolbar_show_factory_name  = 0;
static GtkWidget * __widget_toolbar_show_stick_icon   = 0;
static GtkWidget * __widget_toolbar_show_menu_icon   = 0;
static GtkWidget * __widget_toolbar_show_help_icon    = 0;
static GtkWidget * __widget_toolbar_show_property_label = 0;
static GtkWidget * __widget_lookup_table_embedded     = 0;
static GtkWidget * __widget_lookup_table_vertical     = 0;
static GtkWidget * __widget_default_sticked           = 0;
static GtkWidget * __widget_show_tray_icon            = 0;
static GtkWidget * __widget_font                      = 0;

static GtkTooltips * __widget_tooltips                = 0;

enum ToolbarShowFlavourType {
    SCIM_TOOLBAR_SHOW_ALWAYS,
    SCIM_TOOLBAR_SHOW_ON_DEMAND,
    SCIM_TOOLBAR_SHOW_NEVER
};

static char * __toolbar_show_behaviour_text[] = {
    N_("Always"),
    N_("On demand"),
    N_("Never")
};

// Declaration of internal functions.
static void
on_default_toggle_button_toggled     (GtkToggleButton *togglebutton,
                                      gpointer         user_data);

static void
on_default_spin_button_changed       (GtkSpinButton   *spinbutton,
                                      gpointer         user_data);

static void
on_toolbar_show_behaviour_changed      (GtkComboBox     *combobox,
                                      gpointer         user_data);

static void
on_font_selection_clicked            (GtkButton       *button,
                                      gpointer         user_data);

static void
setup_widget_value ();

// Function implementations.
GtkWidget *
create_setup_window ()
{
    static GtkWidget *window = 0;

    if (!window) {
        GtkWidget *page;
        GtkWidget *table;
        GtkWidget *frame;
        GtkWidget *vbox;
        GtkWidget *label;
        GtkWidget *hbox;

        __widget_tooltips = gtk_tooltips_new ();

        // Create the vbox for the first page.
        page = gtk_vbox_new (FALSE, 0);
        gtk_widget_show (page);

        vbox = page;

        // Create the ToolBar setup block.
        frame = gtk_frame_new (_("ToolBar"));
        gtk_widget_show (frame);
        gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
        gtk_container_set_border_width (GTK_CONTAINER (frame), 4);

        table = gtk_table_new (4, 2, FALSE);
        gtk_widget_show (table);
        gtk_container_add (GTK_CONTAINER (frame), table);
        gtk_table_set_row_spacings (GTK_TABLE (table), 4);
        gtk_table_set_col_spacings (GTK_TABLE (table), 8);

        hbox = gtk_hbox_new (FALSE, 0);
        gtk_widget_show (hbox);

        gtk_table_attach (GTK_TABLE (table), hbox, 0, 1, 0, 1,
                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                          (GtkAttachOptions) (GTK_EXPAND), 4, 0);

        label = gtk_label_new_with_mnemonic (_("_Show:"));
        gtk_widget_show (label);
        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
        gtk_misc_set_padding (GTK_MISC (label), 4, 0);
 
        __widget_toolbar_show_behaviour = gtk_combo_box_new_text ();
        gtk_combo_box_append_text (GTK_COMBO_BOX (__widget_toolbar_show_behaviour), 
                                   _(__toolbar_show_behaviour_text[SCIM_TOOLBAR_SHOW_ALWAYS]));
        gtk_combo_box_append_text (GTK_COMBO_BOX (__widget_toolbar_show_behaviour),
                                   _(__toolbar_show_behaviour_text[SCIM_TOOLBAR_SHOW_ON_DEMAND]));
        gtk_combo_box_append_text (GTK_COMBO_BOX (__widget_toolbar_show_behaviour),
                                   _(__toolbar_show_behaviour_text[SCIM_TOOLBAR_SHOW_NEVER]));
        gtk_widget_show (__widget_toolbar_show_behaviour);
        gtk_box_pack_start (GTK_BOX (hbox), __widget_toolbar_show_behaviour, FALSE, FALSE, 0);
        gtk_label_set_mnemonic_widget (GTK_LABEL (label), __widget_toolbar_show_behaviour);

        __widget_toolbar_auto_snap = gtk_check_button_new_with_mnemonic (_("Auto s_nap"));
        gtk_widget_show (__widget_toolbar_auto_snap);
        gtk_table_attach (GTK_TABLE (table), __widget_toolbar_auto_snap, 0, 1, 1, 2,
                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                          (GtkAttachOptions) (GTK_EXPAND), 4, 0);

        __widget_toolbar_show_factory_icon = gtk_check_button_new_with_mnemonic (_("Show _input method icon"));
        gtk_widget_show (__widget_toolbar_show_factory_icon);
        gtk_table_attach (GTK_TABLE (table), __widget_toolbar_show_factory_icon, 0, 1, 2, 3,
                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                          (GtkAttachOptions) (GTK_EXPAND), 4, 0);

        __widget_toolbar_show_factory_name = gtk_check_button_new_with_mnemonic (_("Show inp_ut method name"));
        gtk_widget_show (__widget_toolbar_show_factory_name);
        gtk_table_attach (GTK_TABLE (table), __widget_toolbar_show_factory_name, 0, 1, 3, 4,
                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                          (GtkAttachOptions) (GTK_EXPAND), 4, 0);

        hbox = gtk_hbox_new (FALSE, 0);
        gtk_widget_show (hbox);
        gtk_table_attach (GTK_TABLE (table), hbox, 1, 2, 0, 1,
                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                          (GtkAttachOptions) (GTK_EXPAND), 4, 0);

        label = gtk_label_new_with_mnemonic (_("Hide time_out:"));
        gtk_widget_show (label);
        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
        gtk_misc_set_padding (GTK_MISC (label), 4, 0);

        __widget_toolbar_hide_timeout = gtk_spin_button_new_with_range (0, 60, 1);
        gtk_widget_show (__widget_toolbar_hide_timeout);
        gtk_box_pack_start (GTK_BOX (hbox), __widget_toolbar_hide_timeout, FALSE, FALSE, 0);
        gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (__widget_toolbar_hide_timeout), TRUE);
        gtk_spin_button_set_snap_to_ticks (GTK_SPIN_BUTTON (__widget_toolbar_hide_timeout), TRUE);
        gtk_spin_button_set_digits (GTK_SPIN_BUTTON (__widget_toolbar_hide_timeout), 0);
        gtk_label_set_mnemonic_widget (GTK_LABEL (label), __widget_toolbar_hide_timeout);

        __widget_toolbar_show_stick_icon = gtk_check_button_new_with_mnemonic (_("Show s_tick icon"));
        gtk_widget_show (__widget_toolbar_show_stick_icon);
        gtk_table_attach (GTK_TABLE (table), __widget_toolbar_show_stick_icon, 1, 2, 1, 2,
                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                          (GtkAttachOptions) (GTK_EXPAND), 4, 0);

        __widget_toolbar_show_menu_icon = gtk_check_button_new_with_mnemonic (_("Show m_enu icon"));
        gtk_widget_show (__widget_toolbar_show_menu_icon);
        gtk_table_attach (GTK_TABLE (table), __widget_toolbar_show_menu_icon, 1, 2, 2, 3,
                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                          (GtkAttachOptions) (GTK_EXPAND), 4, 0);

        __widget_toolbar_show_help_icon = gtk_check_button_new_with_mnemonic (_("Show _help icon"));
        gtk_widget_show (__widget_toolbar_show_help_icon);
        gtk_table_attach (GTK_TABLE (table), __widget_toolbar_show_help_icon, 1, 2, 3, 4,
                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                          (GtkAttachOptions) (GTK_EXPAND), 4, 0);

        __widget_toolbar_show_property_label = gtk_check_button_new_with_mnemonic (_("Show _property label"));
        gtk_widget_show (__widget_toolbar_show_property_label);
        gtk_table_attach (GTK_TABLE (table), __widget_toolbar_show_property_label, 0, 1, 4, 5,
                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                          (GtkAttachOptions) (GTK_EXPAND), 4, 0);

        hbox = gtk_hbox_new (FALSE, 8);
        gtk_widget_show (hbox);
        gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);

        // Create the Input Window setup block
        frame = gtk_frame_new (_("Input window"));
        gtk_widget_show (frame);
        gtk_container_set_border_width (GTK_CONTAINER (frame), 4);
        gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);

        vbox = gtk_vbox_new (FALSE, 4);
        gtk_widget_show (vbox);
        gtk_container_add (GTK_CONTAINER (frame), vbox);

        __widget_lookup_table_embedded = gtk_check_button_new_with_mnemonic (_("E_mbedded lookup table"));
        gtk_widget_show (__widget_lookup_table_embedded);
        gtk_box_pack_start (GTK_BOX (vbox), __widget_lookup_table_embedded, FALSE, FALSE, 0);

        __widget_lookup_table_vertical = gtk_check_button_new_with_mnemonic (_("_Vertical lookup table"));
        gtk_widget_show (__widget_lookup_table_vertical);
        gtk_box_pack_start (GTK_BOX (vbox), __widget_lookup_table_vertical, FALSE, FALSE, 0);

        frame = gtk_frame_new (_("Misc"));
        gtk_widget_show (frame);
        gtk_container_set_border_width (GTK_CONTAINER (frame), 4);
        gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);

        vbox = gtk_vbox_new (FALSE, 4);
        gtk_widget_show (vbox);
        gtk_container_add (GTK_CONTAINER (frame), vbox);

        __widget_show_tray_icon = gtk_check_button_new_with_mnemonic (_("Show tra_y icon"));
        gtk_widget_show (__widget_show_tray_icon);
        gtk_box_pack_start (GTK_BOX (vbox), __widget_show_tray_icon, FALSE, FALSE, 0);

        __widget_default_sticked = gtk_check_button_new_with_mnemonic (_("Stick _windows"));
        gtk_widget_show (__widget_default_sticked);
        gtk_box_pack_start (GTK_BOX (vbox), __widget_default_sticked, FALSE, FALSE, 0);

        hbox = gtk_hbox_new (FALSE, 0);
        gtk_widget_show (hbox);
        gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);

        label = gtk_label_new_with_mnemonic (_("_Font:"));
        gtk_widget_show (label);
        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
        gtk_misc_set_padding (GTK_MISC (label), 4, 0);

        __widget_font = gtk_button_new_with_label ("default");
        gtk_widget_show (__widget_font);
        gtk_container_set_border_width (GTK_CONTAINER (__widget_font), 4);
        gtk_box_pack_start (GTK_BOX (hbox), __widget_font, FALSE, FALSE, 0);
        gtk_label_set_mnemonic_widget (GTK_LABEL (label), __widget_font);

        // Connect all signals.
        g_signal_connect ((gpointer) __widget_toolbar_show_behaviour, "changed",
                          G_CALLBACK (on_toolbar_show_behaviour_changed),
                          NULL);

        g_signal_connect ((gpointer) __widget_toolbar_auto_snap, "toggled",
                          G_CALLBACK (on_default_toggle_button_toggled),
                          &__config_toolbar_auto_snap);

        g_signal_connect ((gpointer) __widget_toolbar_hide_timeout, "value_changed",
                          G_CALLBACK (on_default_spin_button_changed),
                          &__config_toolbar_hide_timeout);

        g_signal_connect ((gpointer) __widget_toolbar_show_factory_icon, "toggled",
                          G_CALLBACK (on_default_toggle_button_toggled),
                          &__config_toolbar_show_factory_icon);

        g_signal_connect ((gpointer) __widget_toolbar_show_factory_name, "toggled",
                          G_CALLBACK (on_default_toggle_button_toggled),
                          &__config_toolbar_show_factory_name);

        g_signal_connect ((gpointer) __widget_toolbar_show_stick_icon, "toggled",
                          G_CALLBACK (on_default_toggle_button_toggled),
                          &__config_toolbar_show_stick_icon);

        g_signal_connect ((gpointer) __widget_toolbar_show_menu_icon, "toggled",
                          G_CALLBACK (on_default_toggle_button_toggled),
                          &__config_toolbar_show_menu_icon);

        g_signal_connect ((gpointer) __widget_toolbar_show_help_icon, "toggled",
                          G_CALLBACK (on_default_toggle_button_toggled),
                          &__config_toolbar_show_help_icon);

        g_signal_connect ((gpointer) __widget_toolbar_show_property_label, "toggled",
                          G_CALLBACK (on_default_toggle_button_toggled),
                          &__config_toolbar_show_property_label);

        g_signal_connect ((gpointer) __widget_lookup_table_embedded, "toggled",
                          G_CALLBACK (on_default_toggle_button_toggled),
                          &__config_lookup_table_embedded);

        g_signal_connect ((gpointer) __widget_lookup_table_vertical, "toggled",
                          G_CALLBACK (on_default_toggle_button_toggled),
                          &__config_lookup_table_vertical);

        g_signal_connect ((gpointer) __widget_default_sticked, "toggled",
                          G_CALLBACK (on_default_toggle_button_toggled),
                          &__config_default_sticked);

        g_signal_connect ((gpointer) __widget_show_tray_icon, "toggled",
                          G_CALLBACK (on_default_toggle_button_toggled),
                          &__config_show_tray_icon);

        g_signal_connect ((gpointer) __widget_font, "clicked",
                          G_CALLBACK (on_font_selection_clicked),
                          NULL);

        // Set all tooltips.
        gtk_tooltips_set_tip (__widget_tooltips, __widget_toolbar_show_behaviour,
                              _("If option \"Always\" is selected, "
                                "the toolbar will always be shown on the screen. "
                                "If option \"On demand\" is selected, it will only be shown when SCIM "
                                "is activated. "
                                "If option \"Never\" is selected, it will never be shown."), NULL);

        gtk_tooltips_set_tip (__widget_tooltips, __widget_toolbar_auto_snap,
                              _("If this option is checked, "
                                "the toolbar will be snapped to "
                                "the screen border."), NULL);

        gtk_tooltips_set_tip (__widget_tooltips, __widget_toolbar_hide_timeout,
                              _("The toolbar will be hidden out after "
                                "this timeout is elapsed. "
                                "This option is only valid when "
                                "\"Always show\" is selected. "
                                "Set to zero to disable this behavior."), NULL);

        gtk_tooltips_set_tip (__widget_tooltips, __widget_toolbar_show_factory_icon,
                              _("If this option is checked, "
                                "the input method icon will be showed on the toolbar."), NULL);

        gtk_tooltips_set_tip (__widget_tooltips, __widget_toolbar_show_factory_name,
                              _("If this option is checked, "
                                "the input method name will be showed on the toolbar."), NULL);

        gtk_tooltips_set_tip (__widget_tooltips, __widget_toolbar_show_stick_icon,
                              _("If this option is checked, "
                                "the stick icon will be showed on the toolbar."), NULL);

        gtk_tooltips_set_tip (__widget_tooltips, __widget_toolbar_show_menu_icon,
                              _("If this option is checked, "
                                "the menu icon will be showed on the toolbar."), NULL);

        gtk_tooltips_set_tip (__widget_tooltips, __widget_toolbar_show_help_icon,
                              _("If this option is checked, "
                                "the help icon will be showed on the toolbar."), NULL);

        gtk_tooltips_set_tip (__widget_tooltips, __widget_toolbar_show_property_label,
                              _("If this option is checked, "
                                "the text label of input method properties will be showed on the toolbar."), NULL);

        gtk_tooltips_set_tip (__widget_tooltips, __widget_lookup_table_embedded,
                              _("If this option is checked, "
                                "the lookup table will be embedded into "
                                "the input window."), NULL);

        gtk_tooltips_set_tip (__widget_tooltips, __widget_lookup_table_vertical,
                              _("If this option is checked, "
                                "the lookup table will be displayed "
                                "vertically."), NULL);

        gtk_tooltips_set_tip (__widget_tooltips, __widget_show_tray_icon,
                              _("If this option is checked, "
                                "the tray icon will be showed on the desktop's taskbar."), NULL);

        gtk_tooltips_set_tip (__widget_tooltips, __widget_default_sticked,
                              _("If this option is checked, "
                                "the toolbar, input and lookup table "
                                "windows will be sticked to "
                                "its original position."),NULL);

        gtk_tooltips_set_tip (__widget_tooltips, __widget_font,
                              _("The font setting will be used in "
                                "the input and lookup table windows."), NULL);

        window = page;

        setup_widget_value ();
    }
    return window;
}

void
setup_widget_value ()
{
    if (__widget_toolbar_show_behaviour) {
        if (__config_toolbar_always_hidden) {
            gtk_combo_box_set_active (
                GTK_COMBO_BOX (__widget_toolbar_show_behaviour),
                SCIM_TOOLBAR_SHOW_NEVER);
        } else if (__config_toolbar_always_show) {
            gtk_combo_box_set_active (
                GTK_COMBO_BOX (__widget_toolbar_show_behaviour),
                SCIM_TOOLBAR_SHOW_ALWAYS);
        } else {
            gtk_combo_box_set_active (
                GTK_COMBO_BOX (__widget_toolbar_show_behaviour),
                SCIM_TOOLBAR_SHOW_ON_DEMAND);
        }
    }

    if (__widget_toolbar_auto_snap) {
        gtk_toggle_button_set_active (
            GTK_TOGGLE_BUTTON (__widget_toolbar_auto_snap),
            __config_toolbar_auto_snap);
    }

    if (__widget_toolbar_hide_timeout) {
        gtk_spin_button_set_value (
            GTK_SPIN_BUTTON (__widget_toolbar_hide_timeout),
            __config_toolbar_hide_timeout);

        gtk_widget_set_sensitive (
            __widget_toolbar_hide_timeout,
            __config_toolbar_always_show);
    }

    if (__widget_toolbar_show_factory_icon) {
        gtk_toggle_button_set_active (
            GTK_TOGGLE_BUTTON (__widget_toolbar_show_factory_icon),
            __config_toolbar_show_factory_icon);
    }

    if (__widget_toolbar_show_factory_name) {
        gtk_toggle_button_set_active (
            GTK_TOGGLE_BUTTON (__widget_toolbar_show_factory_name),
            __config_toolbar_show_factory_name);
    }

    if (__widget_toolbar_show_stick_icon) {
        gtk_toggle_button_set_active (
            GTK_TOGGLE_BUTTON (__widget_toolbar_show_stick_icon),
            __config_toolbar_show_stick_icon);
    }

    if (__widget_toolbar_show_menu_icon) {
        gtk_toggle_button_set_active (
            GTK_TOGGLE_BUTTON (__widget_toolbar_show_menu_icon),
            __config_toolbar_show_menu_icon);
    }

    if (__widget_toolbar_show_help_icon) {
        gtk_toggle_button_set_active (
            GTK_TOGGLE_BUTTON (__widget_toolbar_show_help_icon),
            __config_toolbar_show_help_icon);
    }

    if (__widget_toolbar_show_property_label) {
        gtk_toggle_button_set_active (
            GTK_TOGGLE_BUTTON (__widget_toolbar_show_property_label),
            __config_toolbar_show_property_label);
    }

    if (__widget_lookup_table_embedded) {
        gtk_toggle_button_set_active (
            GTK_TOGGLE_BUTTON (__widget_lookup_table_embedded),
            __config_lookup_table_embedded);
    }

    if (__widget_lookup_table_vertical) {
        gtk_toggle_button_set_active (
            GTK_TOGGLE_BUTTON (__widget_lookup_table_vertical),
            __config_lookup_table_vertical);
    }

    if (__widget_default_sticked) {
        gtk_toggle_button_set_active (
            GTK_TOGGLE_BUTTON (__widget_default_sticked),
            __config_default_sticked);
    }

    if (__widget_show_tray_icon) {
        gtk_toggle_button_set_active (
            GTK_TOGGLE_BUTTON (__widget_show_tray_icon),
            __config_show_tray_icon);
    }

    if (__widget_font) {
        gtk_button_set_label (
            GTK_BUTTON (__widget_font),
            __config_font.c_str ());
    }
}

void
load_config (const ConfigPointer &config)
{
    if (!config.null ()) {
        __config_toolbar_always_hidden =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_ALWAYS_HIDDEN),
                          __config_toolbar_always_hidden);
        __config_toolbar_always_show =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_ALWAYS_SHOW),
                          __config_toolbar_always_show);
        __config_toolbar_auto_snap =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_AUTO_SNAP),
                          __config_toolbar_auto_snap);
        __config_toolbar_hide_timeout =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_HIDE_TIMEOUT),
                          __config_toolbar_hide_timeout);
        __config_toolbar_show_factory_icon =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_FACTORY_ICON),
                          __config_toolbar_show_factory_icon);
        __config_toolbar_show_factory_name =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_FACTORY_NAME),
                          __config_toolbar_show_factory_name);
        __config_toolbar_show_stick_icon =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_STICK_ICON),
                          __config_toolbar_show_stick_icon);
        __config_toolbar_show_menu_icon =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_MENU_ICON),
                          __config_toolbar_show_menu_icon);
        __config_toolbar_show_help_icon =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_HELP_ICON),
                          __config_toolbar_show_help_icon);
        __config_toolbar_show_property_label =
            config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_PROPERTY_LABEL),
                          __config_toolbar_show_property_label);
        __config_lookup_table_embedded =
            config->read (String (SCIM_CONFIG_PANEL_GTK_LOOKUP_TABLE_EMBEDDED),
                          __config_lookup_table_embedded);
        __config_lookup_table_vertical =
            config->read (String (SCIM_CONFIG_PANEL_GTK_LOOKUP_TABLE_VERTICAL),
                          __config_lookup_table_vertical);
        __config_default_sticked =
            config->read (String (SCIM_CONFIG_PANEL_GTK_DEFAULT_STICKED),
                          __config_default_sticked);
        __config_show_tray_icon =
            config->read (String (SCIM_CONFIG_PANEL_GTK_SHOW_TRAY_ICON),
                          __config_show_tray_icon);
        __config_font =
            config->read (String (SCIM_CONFIG_PANEL_GTK_FONT),
                          __config_font);

        setup_widget_value ();

        __have_changed = false;
    }
}

void
save_config (const ConfigPointer &config)
{
    if (!config.null ()) {
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_ALWAYS_HIDDEN),
                       __config_toolbar_always_hidden);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_ALWAYS_SHOW),
                       __config_toolbar_always_show);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_AUTO_SNAP),
                       __config_toolbar_auto_snap);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_HIDE_TIMEOUT),
                       __config_toolbar_hide_timeout);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_FACTORY_ICON),
                       __config_toolbar_show_factory_icon);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_FACTORY_NAME),
                       __config_toolbar_show_factory_name);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_STICK_ICON),
                       __config_toolbar_show_stick_icon);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_MENU_ICON),
                       __config_toolbar_show_menu_icon);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_HELP_ICON),
                       __config_toolbar_show_help_icon);
        config->write (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_PROPERTY_LABEL),
                       __config_toolbar_show_property_label);
        config->write (String (SCIM_CONFIG_PANEL_GTK_LOOKUP_TABLE_EMBEDDED),
                        __config_lookup_table_embedded);
        config->write (String (SCIM_CONFIG_PANEL_GTK_LOOKUP_TABLE_VERTICAL),
                       __config_lookup_table_vertical);
        config->write (String (SCIM_CONFIG_PANEL_GTK_SHOW_TRAY_ICON),
                       __config_show_tray_icon);
        config->write (String (SCIM_CONFIG_PANEL_GTK_DEFAULT_STICKED),
                       __config_default_sticked);
        config->write (String (SCIM_CONFIG_PANEL_GTK_FONT),
                       __config_font);

        __have_changed = false;
    }
}

bool
query_changed ()
{
    return __have_changed;
}

static void
on_default_spin_button_changed (GtkSpinButton *spinbutton,
                                gpointer       user_data)
{
	int *value = static_cast <int *> (user_data);

	if (value) {
		*value = gtk_spin_button_get_value_as_int (spinbutton);
		__have_changed = true;
	}
}

static void
on_default_toggle_button_toggled (GtkToggleButton *togglebutton,
                                  gpointer         user_data)
{
    bool *toggle = static_cast<bool*> (user_data);

    if (toggle) {
        *toggle = gtk_toggle_button_get_active (togglebutton);
        __have_changed = true;
    }
}

static void
on_toolbar_show_behaviour_changed (GtkComboBox *combobox,
                                 gpointer     user_data)
{
    gint active;
    active  = gtk_combo_box_get_active (combobox);

    switch (active) {
        case SCIM_TOOLBAR_SHOW_ALWAYS:
            __config_toolbar_always_show   = true;
            __config_toolbar_always_hidden = false;
            break;
        case SCIM_TOOLBAR_SHOW_ON_DEMAND:
            __config_toolbar_always_show   = false;
            __config_toolbar_always_hidden = false;
            break;
        case SCIM_TOOLBAR_SHOW_NEVER:
            __config_toolbar_always_show   = false;
            __config_toolbar_always_hidden = true;
            break;
        default:
            __config_toolbar_always_show   = true;
            __config_toolbar_always_hidden = false;
            break;
    }

    if (__widget_toolbar_hide_timeout) {
        gtk_widget_set_sensitive (
            __widget_toolbar_hide_timeout,
            !__config_toolbar_always_hidden &&
            __config_toolbar_always_show);
    }

    if (__widget_toolbar_auto_snap) {
        gtk_widget_set_sensitive (
            __widget_toolbar_auto_snap,
            !__config_toolbar_always_hidden);
    }

    if (__widget_toolbar_show_factory_icon) {
        gtk_widget_set_sensitive (
            __widget_toolbar_show_factory_icon,
            !__config_toolbar_always_hidden);
    }

    if (__widget_toolbar_show_factory_name) {
        gtk_widget_set_sensitive (
            __widget_toolbar_show_factory_name,
            !__config_toolbar_always_hidden);
    }

    if (__widget_toolbar_show_stick_icon) {
        gtk_widget_set_sensitive (
            __widget_toolbar_show_stick_icon,
            !__config_toolbar_always_hidden);
    }

    if (__widget_toolbar_show_menu_icon) {
        gtk_widget_set_sensitive (
            __widget_toolbar_show_menu_icon,
            !__config_toolbar_always_hidden);
    }

    if (__widget_toolbar_show_help_icon) {
        gtk_widget_set_sensitive (
            __widget_toolbar_show_help_icon,
            !__config_toolbar_always_hidden);
    }

    if (__widget_toolbar_show_property_label) {
        gtk_widget_set_sensitive (
            __widget_toolbar_show_property_label,
            !__config_toolbar_always_hidden);
    }

    __have_changed = true;
}

static void
on_font_selection_clicked (GtkButton *button,
                           gpointer   user_data)
{
    GtkWidget *font_selection = gtk_font_selection_dialog_new (_("Select Interface Font"));
    gint result;

    if (__config_font != "default") {
        gtk_font_selection_dialog_set_font_name (
            GTK_FONT_SELECTION_DIALOG (font_selection),
            __config_font.c_str ());
    }

    result = gtk_dialog_run (GTK_DIALOG (font_selection));

    if (result == GTK_RESPONSE_OK) {
        __config_font = String (
                            gtk_font_selection_dialog_get_font_name (
                                GTK_FONT_SELECTION_DIALOG (font_selection)));

        gtk_button_set_label (
            GTK_BUTTON (__widget_font),
            __config_font.c_str ());

        __have_changed = true;
    }

    gtk_widget_destroy (font_selection);
}

/*
vi:ts=4:nowrap:expandtab
*/