Mercurial > pidgin.yaz
comparison src/gtkrequest.c @ 5490:421020171808
[gaim-migrate @ 5886]
Added multiline input requests.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Thu, 22 May 2003 19:44:59 +0000 |
parents | c103ba09c62a |
children | b7c0be69c749 |
comparison
equal
deleted
inserted
replaced
5489:5b5aa701d46b | 5490:421020171808 |
---|---|
32 { | 32 { |
33 GaimRequestType type; | 33 GaimRequestType type; |
34 | 34 |
35 void *user_data; | 35 void *user_data; |
36 GtkWidget *dialog; | 36 GtkWidget *dialog; |
37 GtkWidget *entry; | |
38 | 37 |
39 size_t cb_count; | 38 size_t cb_count; |
40 GCallback *cbs; | 39 GCallback *cbs; |
41 | 40 |
41 union | |
42 { | |
43 struct | |
44 { | |
45 GtkWidget *entry; | |
46 | |
47 gboolean multiline; | |
48 | |
49 } input; | |
50 | |
51 } u; | |
52 | |
42 } GaimRequestData; | 53 } GaimRequestData; |
43 | 54 |
44 static void | 55 static void |
45 __input_response_cb(GtkDialog *dialog, gint id, GaimRequestData *data) | 56 __input_response_cb(GtkDialog *dialog, gint id, GaimRequestData *data) |
46 { | 57 { |
47 if (id < data->cb_count && data->cbs[id] != NULL) { | 58 const char *value; |
48 ((GaimRequestInputCb)data->cbs[id])( | 59 |
49 gtk_entry_get_text(GTK_ENTRY(data->entry)), data->user_data); | 60 if (data->u.input.multiline) { |
61 GtkTextIter start_iter, end_iter; | |
62 GtkTextBuffer *buffer = | |
63 gtk_text_view_get_buffer(GTK_TEXT_VIEW(data->u.input.entry)); | |
64 | |
65 gtk_text_buffer_get_start_iter(buffer, &start_iter); | |
66 gtk_text_buffer_get_end_iter(buffer, &end_iter); | |
67 | |
68 value = gtk_text_buffer_get_text(buffer, &start_iter, &end_iter, | |
69 FALSE); | |
50 } | 70 } |
71 else | |
72 value = gtk_entry_get_text(GTK_ENTRY(data->u.input.entry)); | |
73 | |
74 if (id < data->cb_count && data->cbs[id] != NULL) | |
75 ((GaimRequestInputCb)data->cbs[id])(value, data->user_data); | |
51 | 76 |
52 gaim_request_close(GAIM_REQUEST_INPUT, data); | 77 gaim_request_close(GAIM_REQUEST_INPUT, data); |
53 } | 78 } |
54 | 79 |
55 #define STOCK_ITEMIZE(r, l) \ | 80 #define STOCK_ITEMIZE(r, l) \ |
67 STOCK_ITEMIZE(_("Close"), GTK_STOCK_CLOSE); | 92 STOCK_ITEMIZE(_("Close"), GTK_STOCK_CLOSE); |
68 STOCK_ITEMIZE(_("Delete"), GTK_STOCK_DELETE); | 93 STOCK_ITEMIZE(_("Delete"), GTK_STOCK_DELETE); |
69 STOCK_ITEMIZE(_("Add"), GTK_STOCK_ADD); | 94 STOCK_ITEMIZE(_("Add"), GTK_STOCK_ADD); |
70 STOCK_ITEMIZE(_("Remove"), GTK_STOCK_REMOVE); | 95 STOCK_ITEMIZE(_("Remove"), GTK_STOCK_REMOVE); |
71 | 96 |
72 return NULL; | 97 return text; |
73 } | 98 } |
74 | 99 |
75 void * | 100 void * |
76 gaim_gtk_request_input(const char *title, const char *primary, | 101 gaim_gtk_request_input(const char *title, const char *primary, |
77 const char *secondary, const char *default_value, | 102 const char *secondary, const char *default_value, |
151 gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); | 176 gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); |
152 | 177 |
153 g_free(label_text); | 178 g_free(label_text); |
154 | 179 |
155 /* Entry field. */ | 180 /* Entry field. */ |
156 data->entry = entry = gtk_entry_new(); | 181 data->u.input.multiline = multiline; |
157 gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0); | 182 |
158 | 183 if (multiline) { |
159 if (default_value != NULL) | 184 GtkWidget *sw; |
160 gtk_entry_set_text(GTK_ENTRY(entry), default_value); | 185 |
186 sw = gtk_scrolled_window_new(NULL, NULL); | |
187 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
188 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); | |
189 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), | |
190 GTK_SHADOW_IN); | |
191 | |
192 gtk_widget_set_size_request(sw, 300, 75); | |
193 | |
194 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); | |
195 | |
196 entry = gtk_text_view_new(); | |
197 gtk_text_view_set_editable(GTK_TEXT_VIEW(entry), TRUE); | |
198 | |
199 gtk_container_add(GTK_CONTAINER(sw), entry); | |
200 | |
201 if (default_value != NULL) { | |
202 GtkTextBuffer *buffer; | |
203 | |
204 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)); | |
205 gtk_text_buffer_set_text(buffer, default_value, -1); | |
206 } | |
207 } | |
208 else { | |
209 entry = gtk_entry_new(); | |
210 | |
211 gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0); | |
212 | |
213 if (default_value != NULL) | |
214 gtk_entry_set_text(GTK_ENTRY(entry), default_value); | |
215 } | |
216 | |
217 data->u.input.entry = entry; | |
161 | 218 |
162 /* Show everything. */ | 219 /* Show everything. */ |
163 gtk_widget_show_all(dialog); | 220 gtk_widget_show_all(dialog); |
164 | 221 |
165 return data; | 222 return data; |