|
1 /* |
|
2 * CDDL HEADER START |
|
3 * |
|
4 * The contents of this file are subject to the terms of the |
|
5 * Common Development and Distribution License (the "License"). |
|
6 * You may not use this file except in compliance with the License. |
|
7 * |
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 * or http://www.opensolaris.org/os/licensing. |
|
10 * See the License for the specific language governing permissions |
|
11 * and limitations under the License. |
|
12 * |
|
13 * When distributing Covered Code, include this CDDL HEADER in each |
|
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 * If applicable, add the following below this CDDL HEADER, with the |
|
16 * fields enclosed by brackets "[]" replaced with your own identifying |
|
17 * information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 * |
|
19 * CDDL HEADER END |
|
20 */ |
|
21 |
|
22 /* |
|
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
|
24 * Use is subject to license terms. |
|
25 */ |
|
26 #include <glib.h> |
|
27 #include <glib/gi18n.h> |
|
28 #include <gtk/gtk.h> |
|
29 #include <glade/glade.h> |
|
30 #include <gconf/gconf-client.h> |
|
31 |
|
32 #include "fsexam-header.h" |
|
33 #include "fsexam-dialog.h" |
|
34 #include "fsexam-ui.h" |
|
35 |
|
36 extern gint indexg; |
|
37 |
|
38 /* |
|
39 * Callback for 'toggled' signal of GtkRadioButton |
|
40 */ |
|
41 void |
|
42 fsexam_convert_candidate_set (GtkWidget *widget, |
|
43 gpointer user_data) |
|
44 { |
|
45 indexg = (gint)user_data; /* the user_data is the real index in GList */ |
|
46 } |
|
47 |
|
48 /* |
|
49 * Iterate function for Encoding List |
|
50 * |
|
51 * Add one element of Encoding list into candidate dialog as one candidate. |
|
52 */ |
|
53 static gboolean |
|
54 fsexam_construct_index_ui (Encoding *encode, |
|
55 gint index, /* the index in encode_list */ |
|
56 va_list args) |
|
57 { |
|
58 GtkWidget *table = NULL; |
|
59 GtkWidget *entry = NULL; |
|
60 GtkWidget *radio = NULL; |
|
61 GtkWidget **radio_group = NULL; |
|
62 gboolean name_conversion; |
|
63 |
|
64 table = va_arg (args, GtkWidget *); |
|
65 radio_group = va_arg (args, GtkWidget **); |
|
66 name_conversion = va_arg (args, gboolean); |
|
67 |
|
68 /* Radio button */ |
|
69 if (*radio_group == NULL) { /* is NULL for the first element */ |
|
70 radio = gtk_radio_button_new_with_label (NULL, |
|
71 id2encoding (encode->encodingID)); |
|
72 *radio_group = radio; |
|
73 } else { |
|
74 radio = gtk_radio_button_new_with_label_from_widget ( |
|
75 GTK_RADIO_BUTTON (*radio_group), |
|
76 id2encoding (encode->encodingID)); |
|
77 } |
|
78 |
|
79 gtk_table_attach (GTK_TABLE (table), |
|
80 radio, |
|
81 0, 1, |
|
82 index, index+1, |
|
83 GTK_FILL | GTK_SHRINK, /* GtkAttachOptions xoption */ |
|
84 GTK_SHRINK, /* GtkAttachOptions yoption */ |
|
85 0, /* xpadding */ |
|
86 0); /* ypadding */ |
|
87 |
|
88 /* Text Entry */ |
|
89 entry = gtk_entry_new (); |
|
90 |
|
91 if (name_conversion) { |
|
92 gtk_entry_set_text (GTK_ENTRY (entry), encode->u.converted_text); |
|
93 }else{ |
|
94 gtk_entry_set_text (GTK_ENTRY (entry), encode->u.contents); |
|
95 } |
|
96 |
|
97 gtk_table_attach (GTK_TABLE (table), |
|
98 entry, |
|
99 1, 2, |
|
100 index, index+1, |
|
101 GTK_EXPAND | GTK_FILL, |
|
102 GTK_SHRINK | GTK_FILL, |
|
103 0, |
|
104 0); |
|
105 |
|
106 |
|
107 g_signal_connect (G_OBJECT (radio), |
|
108 "toggled", |
|
109 G_CALLBACK (fsexam_convert_candidate_set), |
|
110 (gpointer)index); /* this is the index in encode list */ |
|
111 |
|
112 return TRUE; |
|
113 } |
|
114 |
|
115 #define BOX_SPACE 8 |
|
116 |
|
117 /* |
|
118 * Create candidates list dialog for user to select |
|
119 */ |
|
120 GtkWidget * |
|
121 fsexam_dialog_candidate (GList *encoding, gboolean forname) |
|
122 { |
|
123 GtkWidget *dialog = NULL; |
|
124 GtkWidget *hbox = NULL; |
|
125 GtkWidget *vbox = NULL; |
|
126 GtkWidget *stock = NULL; |
|
127 GtkWidget *table = NULL; |
|
128 GtkWidget *button_ask = NULL; |
|
129 GtkWidget *radio_group = NULL; |
|
130 gint num_encoding; |
|
131 |
|
132 num_encoding = fsexam_encoding_get_length (encoding); |
|
133 |
|
134 dialog = gtk_dialog_new_with_buttons ( |
|
135 _("Please select candidate"), |
|
136 GTK_WINDOW (view->mainwin), |
|
137 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, |
|
138 GTK_STOCK_CANCEL, |
|
139 GTK_RESPONSE_CANCEL, |
|
140 GTK_STOCK_OK, |
|
141 GTK_RESPONSE_OK, |
|
142 NULL); |
|
143 |
|
144 /* The main container for Dialog content */ |
|
145 hbox = gtk_hbox_new (FALSE, BOX_SPACE); |
|
146 gtk_container_set_border_width (GTK_CONTAINER (hbox), BOX_SPACE); |
|
147 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), |
|
148 hbox, |
|
149 TRUE, /* expand */ |
|
150 TRUE, /* fill */ |
|
151 0); /* padding */ |
|
152 |
|
153 /* Left part */ |
|
154 vbox = gtk_vbox_new (FALSE, BOX_SPACE); |
|
155 gtk_box_pack_start (GTK_BOX (hbox), |
|
156 vbox, |
|
157 FALSE, |
|
158 FALSE, |
|
159 0); |
|
160 |
|
161 |
|
162 /* Add Quesiton stock ICON into HBox */ |
|
163 stock = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, |
|
164 GTK_ICON_SIZE_DIALOG); |
|
165 gtk_box_pack_start (GTK_BOX (vbox), |
|
166 stock, |
|
167 TRUE, |
|
168 TRUE, |
|
169 0); |
|
170 /* Ask me button */ |
|
171 button_ask = gtk_check_button_new_with_label (_("Don't ask me again")); |
|
172 g_object_set_data (G_OBJECT (dialog), "chkbtn_ask", button_ask); |
|
173 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_ask), FALSE); |
|
174 gtk_box_pack_start (GTK_BOX (vbox), |
|
175 button_ask, |
|
176 FALSE, |
|
177 FALSE, |
|
178 0); |
|
179 |
|
180 /* Create table */ |
|
181 table = gtk_table_new (num_encoding, |
|
182 2, |
|
183 FALSE); /* homogouse */ |
|
184 gtk_table_set_row_spacings (GTK_TABLE (table), 4); |
|
185 gtk_table_set_col_spacings (GTK_TABLE (table), 4); |
|
186 |
|
187 if (num_encoding > 10) { |
|
188 /* add scrollwindow */ |
|
189 GtkWidget *scroll_window = NULL; |
|
190 GtkWidget *view_port = NULL; |
|
191 |
|
192 view_port = gtk_viewport_new (NULL, NULL); |
|
193 gtk_viewport_set_shadow_type (GTK_VIEWPORT (view_port), |
|
194 GTK_SHADOW_NONE); |
|
195 gtk_container_add (GTK_CONTAINER (view_port), table); |
|
196 |
|
197 scroll_window = gtk_scrolled_window_new (NULL, NULL); |
|
198 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll_window), |
|
199 GTK_POLICY_AUTOMATIC, |
|
200 GTK_POLICY_AUTOMATIC); |
|
201 gtk_scrolled_window_set_shadow_type ( |
|
202 GTK_SCROLLED_WINDOW (scroll_window), |
|
203 GTK_SHADOW_NONE); |
|
204 gtk_container_add (GTK_CONTAINER (scroll_window), view_port); |
|
205 |
|
206 gtk_box_pack_start (GTK_BOX (hbox), |
|
207 scroll_window, |
|
208 TRUE, |
|
209 TRUE, |
|
210 5); |
|
211 |
|
212 gtk_window_resize (GTK_WINDOW (dialog), 550, 400); |
|
213 }else{ |
|
214 gint height; |
|
215 |
|
216 gtk_box_pack_start (GTK_BOX (hbox), |
|
217 table, |
|
218 TRUE, |
|
219 TRUE, |
|
220 0); |
|
221 |
|
222 gtk_window_get_size (GTK_WINDOW (dialog), NULL, &height); |
|
223 gtk_window_resize (GTK_WINDOW (dialog), 450, height); |
|
224 } |
|
225 |
|
226 fsexam_encoding_iterate_with_func (encoding, |
|
227 fsexam_construct_index_ui, |
|
228 table, |
|
229 &radio_group, |
|
230 forname); |
|
231 |
|
232 gtk_widget_show_all (dialog); |
|
233 |
|
234 return dialog; |
|
235 } |