aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/ename/test-ename-western-gtk.c
blob: 15db38ce10e0eb4797c0ecba50d733dd5fe52c44 (plain) (blame)
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
#include <gnome.h>
#include <ename/e-name.h>

ENameWestern *name;
GtkWidget    *full;
GtkWidget    *prefix;
GtkWidget    *first;
GtkWidget    *middle;
GtkWidget    *nick;
GtkWidget    *last;
GtkWidget    *suffix;

static void
fill_entries (void)
{

#define SET(a,b) (gtk_entry_set_text (GTK_ENTRY (a), (b) == NULL ? "" : (b)))
    SET(prefix, name->prefix);
    SET(first,  name->first);
    SET(middle, name->middle);
    SET(nick,   name->nick);
    SET(last,   name->last);
    SET(suffix, name->suffix);
}

static void
full_changed_cb (GtkEntry *fulle)
{
    e_name_western_free (name);
    name = e_name_western_parse (gtk_entry_get_text (fulle));
    fill_entries ();
}

static void
create_window (void)
{
    GtkWidget *app;
    GtkTable  *table;

    GtkWidget *prefix_label;
    GtkWidget *first_label;
    GtkWidget *middle_label;
    GtkWidget *nick_label;
    GtkWidget *last_label;
    GtkWidget *suffix_label;

    app = gnome_app_new ("test", "Evolution Western Name Parser");

    table = GTK_TABLE (gtk_table_new (3, 6, FALSE));

    full   = gtk_entry_new ();
    prefix = gtk_entry_new ();
    first  = gtk_entry_new ();
    middle = gtk_entry_new ();
    nick   = gtk_entry_new ();
    last   = gtk_entry_new ();
    suffix = gtk_entry_new ();

    gtk_widget_set_usize (prefix, 100, 0);
    gtk_widget_set_usize (first,  100, 0);
    gtk_widget_set_usize (middle, 100, 0);
    gtk_widget_set_usize (nick,   100, 0);
    gtk_widget_set_usize (last,   100, 0);
    gtk_widget_set_usize (suffix, 100, 0);

    gtk_table_attach (table, full, 0, 6, 0, 1,
              GTK_EXPAND | GTK_FILL, 0,
              0, 0);

    gtk_table_attach (table, prefix, 0, 1, 1, 2,
              GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0,
              0, 0);

    gtk_table_attach (table, first, 1, 2, 1, 2,
              GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0,
              0, 0);

    gtk_table_attach (table, middle, 2, 3, 1, 2,
              GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0,
              0, 0);

    gtk_table_attach (table, nick, 3, 4, 1, 2,
              GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0,
              0, 0);

    gtk_table_attach (table, last, 4, 5, 1, 2,
              GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0,
              0, 0);

    gtk_table_attach (table, suffix, 5, 6, 1, 2,
              GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0,
              0, 0);

    prefix_label = gtk_label_new ("Prefix"); 
    first_label  = gtk_label_new ("First"); 
    middle_label = gtk_label_new ("Middle"); 
    nick_label   = gtk_label_new ("Nick"); 
    last_label   = gtk_label_new ("Last"); 
    suffix_label = gtk_label_new ("Suffix"); 

    gtk_table_attach (table, prefix_label, 0, 1, 2, 3,
              GTK_SHRINK, 0,
              0, 0);

    gtk_table_attach (table, first_label, 1, 2, 2, 3,
              GTK_SHRINK, 0,
              0, 0);

    gtk_table_attach (table, middle_label, 2, 3, 2, 3,
              GTK_SHRINK, 0,
              0, 0);

    gtk_table_attach (table, nick_label, 3, 4, 2, 3,
              GTK_SHRINK, 0,
              0, 0);

    gtk_table_attach (table, last_label, 4, 5, 2, 3,
              GTK_SHRINK, 0,
              0, 0);

    gtk_table_attach (table, suffix_label, 5, 6, 2, 3,
              GTK_SHRINK, 0,
              0, 0);

    gnome_app_set_contents (GNOME_APP (app), GTK_WIDGET (table));

    gtk_widget_show_all (app);

    gtk_entry_set_text (GTK_ENTRY (full),
                "The Honorable Doctor van Jacobsen, Albert Roderick \"The Clenched Fist\" Jr, MD, PhD, Esquire");

    name = e_name_western_parse ("The Honorable Doctor van Jacobsen, Albert Roderick \"The Clenched Fist\" Jr, MD, PhD, Esquire");
    fill_entries ();

    gtk_signal_connect (GTK_OBJECT (full), "changed", full_changed_cb, NULL);
}

int
main (int argc, char **argv)
{
    gnome_init ("Test EName", "Test EName", argc, argv);

    create_window ();

    gtk_main ();

    return 0;
}