Mercurial > pidgin
changeset 6337:957c1d28b96a
[gaim-migrate @ 6836]
The multi-field dialog code seems to be working with multi-line text views
in it. It may not work when the text view is in the middle somewhere, but I
don't care. I don't ever want to touch this code again.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 30 Jul 2003 07:39:23 +0000 |
parents | aeb8c2119a58 |
children | 644ebf75f686 |
files | src/gtkrequest.c |
diffstat | 1 files changed, 281 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gtkrequest.c Wed Jul 30 04:50:00 2003 +0000 +++ b/src/gtkrequest.c Wed Jul 30 07:39:23 2003 +0000 @@ -95,10 +95,24 @@ } static gboolean -field_string_focus_out_cb(GtkEntry *entry, GdkEventFocus *event, +field_string_focus_out_cb(GtkWidget *entry, GdkEventFocus *event, GaimRequestField *field) { - const char *value = gtk_entry_get_text(entry); + const char *value; + + if (gaim_request_field_string_is_multiline(field)) { + GtkTextBuffer *buffer; + GtkTextIter start_iter, end_iter; + + buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)); + + gtk_text_buffer_get_start_iter(buffer, &start_iter); + gtk_text_buffer_get_end_iter(buffer, &end_iter); + + value = gtk_text_buffer_get_text(buffer, &start_iter, &end_iter, FALSE); + } + else + value = gtk_entry_get_text(GTK_ENTRY(entry)); gaim_request_field_string_set_value(field, (*value == '\0' ? NULL : value)); @@ -421,7 +435,6 @@ GtkWidget *frame; GtkWidget *label; GtkWidget *table; - /* GtkWidget *sep; */ GtkWidget *button; GtkWidget *img; GtkSizeGroup *sg; @@ -496,7 +509,7 @@ size_t cols = 1; size_t rows; size_t col_num; - size_t row_num; + size_t row_num = 0; group = gl->data; field_list = gaim_request_field_group_get_fields(group); @@ -517,6 +530,20 @@ else rows = field_count; + for (fl = field_list; fl != NULL; fl = fl->next) { + GaimRequestFieldType type; + + field = (GaimRequestField *)fl->data; + + type = gaim_request_field_get_type(field); + + if (type == GAIM_REQUEST_FIELD_STRING && + gaim_request_field_string_is_multiline(field)) { + + rows += 2; + } + } + table = gtk_table_new(rows, 2 * cols, FALSE); gtk_table_set_row_spacings(GTK_TABLE(table), 6); gtk_table_set_col_spacings(GTK_TABLE(table), 6); @@ -524,6 +551,226 @@ gtk_container_add(GTK_CONTAINER(frame), table); gtk_widget_show(table); + for (row_num = 0, fl = field_list; + row_num < rows && fl != NULL; + row_num++) { + + for (col_num = 0; + col_num < cols && fl != NULL; + col_num++, fl = fl->next) { + + size_t col_offset = col_num * 2; + GaimRequestFieldType type; + GtkWidget *widget = NULL; + + field = fl->data; + + type = gaim_request_field_get_type(field); + + gaim_debug(GAIM_DEBUG_INFO, "gtkrequest", + "Adding %s (%d, %d - %d, %d)\n", + gaim_request_field_get_label(field), + row_num, col_num, rows, cols); + + if (type != GAIM_REQUEST_FIELD_BOOLEAN) { + text = g_strdup_printf("%s:", + gaim_request_field_get_label(field)); + + label = gtk_label_new(NULL); + gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), text); + g_free(text); + + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + + gtk_size_group_add_widget(sg, label); + + if (type == GAIM_REQUEST_FIELD_STRING && + gaim_request_field_string_is_multiline(field)) { + + gtk_table_attach_defaults(GTK_TABLE(table), label, + 0, 2 * cols, + row_num, row_num + 1); + + row_num++; + } + else { + gtk_table_attach_defaults(GTK_TABLE(table), label, + col_offset, col_offset + 1, + row_num, row_num + 1); + } + + gtk_widget_show(label); + } + + if (type == GAIM_REQUEST_FIELD_STRING) { + const char *value; + + value = gaim_request_field_string_get_default_value(field); + + if (gaim_request_field_string_is_multiline(field)) { + GtkWidget *textview; + + widget = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_shadow_type( + GTK_SCROLLED_WINDOW(widget), + GTK_SHADOW_IN); + gtk_scrolled_window_set_policy( + GTK_SCROLLED_WINDOW(widget), + GTK_POLICY_NEVER, + GTK_POLICY_AUTOMATIC); + + textview = gtk_text_view_new(); + gtk_text_view_set_editable(GTK_TEXT_VIEW(textview), + TRUE); + gtk_container_add(GTK_CONTAINER(widget), textview); + gtk_widget_show(textview); + + gtk_widget_set_size_request(widget, -1, 75); + + if (value != NULL) { + GtkTextBuffer *buffer; + + buffer = gtk_text_view_get_buffer( + GTK_TEXT_VIEW(textview)); + + gtk_text_buffer_set_text(buffer, value, -1); + } + } + else { + widget = gtk_entry_new(); + + if (value != NULL) + gtk_entry_set_text(GTK_ENTRY(widget), value); + } + + g_signal_connect(G_OBJECT(widget), "focus-out-event", + G_CALLBACK(field_string_focus_out_cb), + field); + } + else if (type == GAIM_REQUEST_FIELD_INTEGER) { + int value; + + widget = gtk_entry_new(); + + value = gaim_request_field_int_get_default_value(field); + + if (value != 0) { + char buf[32]; + + g_snprintf(buf, sizeof(buf), "%d", value); + + gtk_entry_set_text(GTK_ENTRY(widget), buf); + } + + g_signal_connect(G_OBJECT(widget), "focus-out-event", + G_CALLBACK(field_int_focus_out_cb), + field); + } + else if (type == GAIM_REQUEST_FIELD_BOOLEAN) { + widget = gtk_check_button_new_with_label( + gaim_request_field_get_label(field)); + + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), + gaim_request_field_bool_get_default_value(field)); + + g_signal_connect(G_OBJECT(widget), "toggled", + G_CALLBACK(field_bool_cb), field); + } + else if (type == GAIM_REQUEST_FIELD_CHOICE) { + GList *labels; + GList *l; + + labels = gaim_request_field_choice_get_labels(field); + + if (g_list_length(labels) > 5) { + GtkWidget *menu; + GtkWidget *item; + + widget = gtk_option_menu_new(); + + menu = gtk_menu_new(); + + gtk_option_menu_set_menu(GTK_OPTION_MENU(widget), menu); + + for (l = labels; l != NULL; l = l->next) { + const char *text = l->data; + + item = gtk_menu_item_new_with_label(text); + + gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); + } + + g_signal_connect(G_OBJECT(widget), "changed", + G_CALLBACK(field_choice_menu_cb), + field); + } + else { + GtkWidget *box; + GtkWidget *first_radio = NULL; + GtkWidget *radio; + + if (g_list_length(labels) == 2) + box = gtk_hbox_new(FALSE, 6); + else + box = gtk_vbox_new(FALSE, 0); + + widget = box; + + for (l = labels; l != NULL; l = l->next) { + const char *text = l->data; + + radio = + gtk_radio_button_new_with_label_from_widget( + GTK_RADIO_BUTTON(first_radio), text); + + if (first_radio == NULL) + first_radio = radio; + + gtk_box_pack_start(GTK_BOX(box), radio, + TRUE, TRUE, 0); + gtk_widget_show(radio); + + g_signal_connect(G_OBJECT(radio), "toggled", + G_CALLBACK(field_choice_option_cb), + field); + } + } + } + + if (type == GAIM_REQUEST_FIELD_STRING && + gaim_request_field_string_is_multiline(field)) { + + gtk_table_attach(GTK_TABLE(table), widget, + 0, 2 * cols, + row_num, row_num + 1, + GTK_FILL | GTK_EXPAND, + GTK_FILL | GTK_EXPAND, + 5, 0); + } + else if (type != GAIM_REQUEST_FIELD_BOOLEAN) { + gtk_table_attach(GTK_TABLE(table), widget, + col_offset + 1, col_offset + 2, + row_num, row_num + 1, + GTK_FILL | GTK_EXPAND, + GTK_FILL | GTK_EXPAND, + 5, 0); + } + else { + gtk_table_attach(GTK_TABLE(table), widget, + col_offset, col_offset + 1, + row_num, row_num + 1, + GTK_FILL | GTK_EXPAND, + GTK_FILL | GTK_EXPAND, + 5, 0); + } + + gtk_widget_show(widget); + + field->ui_data = widget; + } + } + +#if 0 for (col_num = 0, fl = field_list; col_num < cols && fl != NULL; col_num++) { @@ -540,9 +787,10 @@ type = gaim_request_field_get_type(field); - gaim_debug(GAIM_DEBUG_MISC, "gtkrequest", - "type = %d (%d)\n", - type, field->type); + gaim_debug(GAIM_DEBUG_INFO, "gtkrequest", + "Adding %s (%d, %d - %d, %d)\n", + gaim_request_field_get_label(field), + row_num, col_num, rows, cols); if (type != GAIM_REQUEST_FIELD_BOOLEAN) { text = g_strdup_printf("%s:", @@ -556,9 +804,21 @@ gtk_size_group_add_widget(sg, label); - gtk_table_attach_defaults(GTK_TABLE(table), label, - col_offset, col_offset + 1, - row_num, row_num + 1); + if (type == GAIM_REQUEST_FIELD_STRING && + gaim_request_field_string_is_multiline(field)) { + + gtk_table_attach_defaults(GTK_TABLE(table), label, + 0, 2 * cols, + row_num, row_num + 1); + + row_num++; + } + else { + gtk_table_attach_defaults(GTK_TABLE(table), label, + col_offset, col_offset + 1, + row_num, row_num + 1); + } + gtk_widget_show(label); } @@ -688,6 +948,16 @@ GTK_FILL | GTK_EXPAND, 5, 0); } + else if (type == GAIM_REQUEST_FIELD_STRING && + gaim_request_field_string_is_multiline(field)) { + + gtk_table_attach(GTK_TABLE(table), widget, + 0, 2 * cols, + row_num, row_num + 1, + GTK_FILL | GTK_EXPAND, + GTK_FILL | GTK_EXPAND, + 5, 0); + } else { gtk_table_attach(GTK_TABLE(table), widget, col_offset, col_offset + 1, @@ -702,17 +972,11 @@ field->ui_data = widget; } } +#endif } g_object_unref(sg); -#if 0 - /* Separator */ - sep = gtk_hseparator_new(); - gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); - gtk_widget_show(sep); -#endif - /* Button box. */ bbox = gtk_hbutton_box_new(); gtk_box_set_spacing(GTK_BOX(bbox), 6);