Mercurial > pidgin.yaz
comparison src/gtkrequest.c @ 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 | ea47bddc7376 |
children | 644ebf75f686 |
comparison
equal
deleted
inserted
replaced
6336:aeb8c2119a58 | 6337:957c1d28b96a |
---|---|
93 | 93 |
94 gaim_request_close(GAIM_REQUEST_INPUT, data); | 94 gaim_request_close(GAIM_REQUEST_INPUT, data); |
95 } | 95 } |
96 | 96 |
97 static gboolean | 97 static gboolean |
98 field_string_focus_out_cb(GtkEntry *entry, GdkEventFocus *event, | 98 field_string_focus_out_cb(GtkWidget *entry, GdkEventFocus *event, |
99 GaimRequestField *field) | 99 GaimRequestField *field) |
100 { | 100 { |
101 const char *value = gtk_entry_get_text(entry); | 101 const char *value; |
102 | |
103 if (gaim_request_field_string_is_multiline(field)) { | |
104 GtkTextBuffer *buffer; | |
105 GtkTextIter start_iter, end_iter; | |
106 | |
107 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)); | |
108 | |
109 gtk_text_buffer_get_start_iter(buffer, &start_iter); | |
110 gtk_text_buffer_get_end_iter(buffer, &end_iter); | |
111 | |
112 value = gtk_text_buffer_get_text(buffer, &start_iter, &end_iter, FALSE); | |
113 } | |
114 else | |
115 value = gtk_entry_get_text(GTK_ENTRY(entry)); | |
102 | 116 |
103 gaim_request_field_string_set_value(field, | 117 gaim_request_field_string_set_value(field, |
104 (*value == '\0' ? NULL : value)); | 118 (*value == '\0' ? NULL : value)); |
105 | 119 |
106 return FALSE; | 120 return FALSE; |
419 GtkWidget *hbox; | 433 GtkWidget *hbox; |
420 GtkWidget *bbox; | 434 GtkWidget *bbox; |
421 GtkWidget *frame; | 435 GtkWidget *frame; |
422 GtkWidget *label; | 436 GtkWidget *label; |
423 GtkWidget *table; | 437 GtkWidget *table; |
424 /* GtkWidget *sep; */ | |
425 GtkWidget *button; | 438 GtkWidget *button; |
426 GtkWidget *img; | 439 GtkWidget *img; |
427 GtkSizeGroup *sg; | 440 GtkSizeGroup *sg; |
428 GList *gl, *fl; | 441 GList *gl, *fl; |
429 GaimRequestFieldGroup *group; | 442 GaimRequestFieldGroup *group; |
494 GList *field_list; | 507 GList *field_list; |
495 size_t field_count = 0; | 508 size_t field_count = 0; |
496 size_t cols = 1; | 509 size_t cols = 1; |
497 size_t rows; | 510 size_t rows; |
498 size_t col_num; | 511 size_t col_num; |
499 size_t row_num; | 512 size_t row_num = 0; |
500 | 513 |
501 group = gl->data; | 514 group = gl->data; |
502 field_list = gaim_request_field_group_get_fields(group); | 515 field_list = gaim_request_field_group_get_fields(group); |
503 | 516 |
504 if (gaim_request_field_group_get_title(group) != NULL) { | 517 if (gaim_request_field_group_get_title(group) != NULL) { |
515 cols++; | 528 cols++; |
516 } | 529 } |
517 else | 530 else |
518 rows = field_count; | 531 rows = field_count; |
519 | 532 |
533 for (fl = field_list; fl != NULL; fl = fl->next) { | |
534 GaimRequestFieldType type; | |
535 | |
536 field = (GaimRequestField *)fl->data; | |
537 | |
538 type = gaim_request_field_get_type(field); | |
539 | |
540 if (type == GAIM_REQUEST_FIELD_STRING && | |
541 gaim_request_field_string_is_multiline(field)) { | |
542 | |
543 rows += 2; | |
544 } | |
545 } | |
546 | |
520 table = gtk_table_new(rows, 2 * cols, FALSE); | 547 table = gtk_table_new(rows, 2 * cols, FALSE); |
521 gtk_table_set_row_spacings(GTK_TABLE(table), 6); | 548 gtk_table_set_row_spacings(GTK_TABLE(table), 6); |
522 gtk_table_set_col_spacings(GTK_TABLE(table), 6); | 549 gtk_table_set_col_spacings(GTK_TABLE(table), 6); |
523 | 550 |
524 gtk_container_add(GTK_CONTAINER(frame), table); | 551 gtk_container_add(GTK_CONTAINER(frame), table); |
525 gtk_widget_show(table); | 552 gtk_widget_show(table); |
526 | 553 |
554 for (row_num = 0, fl = field_list; | |
555 row_num < rows && fl != NULL; | |
556 row_num++) { | |
557 | |
558 for (col_num = 0; | |
559 col_num < cols && fl != NULL; | |
560 col_num++, fl = fl->next) { | |
561 | |
562 size_t col_offset = col_num * 2; | |
563 GaimRequestFieldType type; | |
564 GtkWidget *widget = NULL; | |
565 | |
566 field = fl->data; | |
567 | |
568 type = gaim_request_field_get_type(field); | |
569 | |
570 gaim_debug(GAIM_DEBUG_INFO, "gtkrequest", | |
571 "Adding %s (%d, %d - %d, %d)\n", | |
572 gaim_request_field_get_label(field), | |
573 row_num, col_num, rows, cols); | |
574 | |
575 if (type != GAIM_REQUEST_FIELD_BOOLEAN) { | |
576 text = g_strdup_printf("%s:", | |
577 gaim_request_field_get_label(field)); | |
578 | |
579 label = gtk_label_new(NULL); | |
580 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), text); | |
581 g_free(text); | |
582 | |
583 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
584 | |
585 gtk_size_group_add_widget(sg, label); | |
586 | |
587 if (type == GAIM_REQUEST_FIELD_STRING && | |
588 gaim_request_field_string_is_multiline(field)) { | |
589 | |
590 gtk_table_attach_defaults(GTK_TABLE(table), label, | |
591 0, 2 * cols, | |
592 row_num, row_num + 1); | |
593 | |
594 row_num++; | |
595 } | |
596 else { | |
597 gtk_table_attach_defaults(GTK_TABLE(table), label, | |
598 col_offset, col_offset + 1, | |
599 row_num, row_num + 1); | |
600 } | |
601 | |
602 gtk_widget_show(label); | |
603 } | |
604 | |
605 if (type == GAIM_REQUEST_FIELD_STRING) { | |
606 const char *value; | |
607 | |
608 value = gaim_request_field_string_get_default_value(field); | |
609 | |
610 if (gaim_request_field_string_is_multiline(field)) { | |
611 GtkWidget *textview; | |
612 | |
613 widget = gtk_scrolled_window_new(NULL, NULL); | |
614 gtk_scrolled_window_set_shadow_type( | |
615 GTK_SCROLLED_WINDOW(widget), | |
616 GTK_SHADOW_IN); | |
617 gtk_scrolled_window_set_policy( | |
618 GTK_SCROLLED_WINDOW(widget), | |
619 GTK_POLICY_NEVER, | |
620 GTK_POLICY_AUTOMATIC); | |
621 | |
622 textview = gtk_text_view_new(); | |
623 gtk_text_view_set_editable(GTK_TEXT_VIEW(textview), | |
624 TRUE); | |
625 gtk_container_add(GTK_CONTAINER(widget), textview); | |
626 gtk_widget_show(textview); | |
627 | |
628 gtk_widget_set_size_request(widget, -1, 75); | |
629 | |
630 if (value != NULL) { | |
631 GtkTextBuffer *buffer; | |
632 | |
633 buffer = gtk_text_view_get_buffer( | |
634 GTK_TEXT_VIEW(textview)); | |
635 | |
636 gtk_text_buffer_set_text(buffer, value, -1); | |
637 } | |
638 } | |
639 else { | |
640 widget = gtk_entry_new(); | |
641 | |
642 if (value != NULL) | |
643 gtk_entry_set_text(GTK_ENTRY(widget), value); | |
644 } | |
645 | |
646 g_signal_connect(G_OBJECT(widget), "focus-out-event", | |
647 G_CALLBACK(field_string_focus_out_cb), | |
648 field); | |
649 } | |
650 else if (type == GAIM_REQUEST_FIELD_INTEGER) { | |
651 int value; | |
652 | |
653 widget = gtk_entry_new(); | |
654 | |
655 value = gaim_request_field_int_get_default_value(field); | |
656 | |
657 if (value != 0) { | |
658 char buf[32]; | |
659 | |
660 g_snprintf(buf, sizeof(buf), "%d", value); | |
661 | |
662 gtk_entry_set_text(GTK_ENTRY(widget), buf); | |
663 } | |
664 | |
665 g_signal_connect(G_OBJECT(widget), "focus-out-event", | |
666 G_CALLBACK(field_int_focus_out_cb), | |
667 field); | |
668 } | |
669 else if (type == GAIM_REQUEST_FIELD_BOOLEAN) { | |
670 widget = gtk_check_button_new_with_label( | |
671 gaim_request_field_get_label(field)); | |
672 | |
673 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), | |
674 gaim_request_field_bool_get_default_value(field)); | |
675 | |
676 g_signal_connect(G_OBJECT(widget), "toggled", | |
677 G_CALLBACK(field_bool_cb), field); | |
678 } | |
679 else if (type == GAIM_REQUEST_FIELD_CHOICE) { | |
680 GList *labels; | |
681 GList *l; | |
682 | |
683 labels = gaim_request_field_choice_get_labels(field); | |
684 | |
685 if (g_list_length(labels) > 5) { | |
686 GtkWidget *menu; | |
687 GtkWidget *item; | |
688 | |
689 widget = gtk_option_menu_new(); | |
690 | |
691 menu = gtk_menu_new(); | |
692 | |
693 gtk_option_menu_set_menu(GTK_OPTION_MENU(widget), menu); | |
694 | |
695 for (l = labels; l != NULL; l = l->next) { | |
696 const char *text = l->data; | |
697 | |
698 item = gtk_menu_item_new_with_label(text); | |
699 | |
700 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
701 } | |
702 | |
703 g_signal_connect(G_OBJECT(widget), "changed", | |
704 G_CALLBACK(field_choice_menu_cb), | |
705 field); | |
706 } | |
707 else { | |
708 GtkWidget *box; | |
709 GtkWidget *first_radio = NULL; | |
710 GtkWidget *radio; | |
711 | |
712 if (g_list_length(labels) == 2) | |
713 box = gtk_hbox_new(FALSE, 6); | |
714 else | |
715 box = gtk_vbox_new(FALSE, 0); | |
716 | |
717 widget = box; | |
718 | |
719 for (l = labels; l != NULL; l = l->next) { | |
720 const char *text = l->data; | |
721 | |
722 radio = | |
723 gtk_radio_button_new_with_label_from_widget( | |
724 GTK_RADIO_BUTTON(first_radio), text); | |
725 | |
726 if (first_radio == NULL) | |
727 first_radio = radio; | |
728 | |
729 gtk_box_pack_start(GTK_BOX(box), radio, | |
730 TRUE, TRUE, 0); | |
731 gtk_widget_show(radio); | |
732 | |
733 g_signal_connect(G_OBJECT(radio), "toggled", | |
734 G_CALLBACK(field_choice_option_cb), | |
735 field); | |
736 } | |
737 } | |
738 } | |
739 | |
740 if (type == GAIM_REQUEST_FIELD_STRING && | |
741 gaim_request_field_string_is_multiline(field)) { | |
742 | |
743 gtk_table_attach(GTK_TABLE(table), widget, | |
744 0, 2 * cols, | |
745 row_num, row_num + 1, | |
746 GTK_FILL | GTK_EXPAND, | |
747 GTK_FILL | GTK_EXPAND, | |
748 5, 0); | |
749 } | |
750 else if (type != GAIM_REQUEST_FIELD_BOOLEAN) { | |
751 gtk_table_attach(GTK_TABLE(table), widget, | |
752 col_offset + 1, col_offset + 2, | |
753 row_num, row_num + 1, | |
754 GTK_FILL | GTK_EXPAND, | |
755 GTK_FILL | GTK_EXPAND, | |
756 5, 0); | |
757 } | |
758 else { | |
759 gtk_table_attach(GTK_TABLE(table), widget, | |
760 col_offset, col_offset + 1, | |
761 row_num, row_num + 1, | |
762 GTK_FILL | GTK_EXPAND, | |
763 GTK_FILL | GTK_EXPAND, | |
764 5, 0); | |
765 } | |
766 | |
767 gtk_widget_show(widget); | |
768 | |
769 field->ui_data = widget; | |
770 } | |
771 } | |
772 | |
773 #if 0 | |
527 for (col_num = 0, fl = field_list; | 774 for (col_num = 0, fl = field_list; |
528 col_num < cols && fl != NULL; | 775 col_num < cols && fl != NULL; |
529 col_num++) { | 776 col_num++) { |
530 | 777 |
531 for (row_num = 0; | 778 for (row_num = 0; |
538 | 785 |
539 field = fl->data; | 786 field = fl->data; |
540 | 787 |
541 type = gaim_request_field_get_type(field); | 788 type = gaim_request_field_get_type(field); |
542 | 789 |
543 gaim_debug(GAIM_DEBUG_MISC, "gtkrequest", | 790 gaim_debug(GAIM_DEBUG_INFO, "gtkrequest", |
544 "type = %d (%d)\n", | 791 "Adding %s (%d, %d - %d, %d)\n", |
545 type, field->type); | 792 gaim_request_field_get_label(field), |
793 row_num, col_num, rows, cols); | |
546 | 794 |
547 if (type != GAIM_REQUEST_FIELD_BOOLEAN) { | 795 if (type != GAIM_REQUEST_FIELD_BOOLEAN) { |
548 text = g_strdup_printf("%s:", | 796 text = g_strdup_printf("%s:", |
549 gaim_request_field_get_label(field)); | 797 gaim_request_field_get_label(field)); |
550 | 798 |
554 | 802 |
555 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | 803 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
556 | 804 |
557 gtk_size_group_add_widget(sg, label); | 805 gtk_size_group_add_widget(sg, label); |
558 | 806 |
559 gtk_table_attach_defaults(GTK_TABLE(table), label, | 807 if (type == GAIM_REQUEST_FIELD_STRING && |
560 col_offset, col_offset + 1, | 808 gaim_request_field_string_is_multiline(field)) { |
561 row_num, row_num + 1); | 809 |
810 gtk_table_attach_defaults(GTK_TABLE(table), label, | |
811 0, 2 * cols, | |
812 row_num, row_num + 1); | |
813 | |
814 row_num++; | |
815 } | |
816 else { | |
817 gtk_table_attach_defaults(GTK_TABLE(table), label, | |
818 col_offset, col_offset + 1, | |
819 row_num, row_num + 1); | |
820 } | |
821 | |
562 gtk_widget_show(label); | 822 gtk_widget_show(label); |
563 } | 823 } |
564 | 824 |
565 if (type == GAIM_REQUEST_FIELD_STRING) { | 825 if (type == GAIM_REQUEST_FIELD_STRING) { |
566 const char *value; | 826 const char *value; |
686 row_num, row_num + 1, | 946 row_num, row_num + 1, |
687 GTK_FILL | GTK_EXPAND, | 947 GTK_FILL | GTK_EXPAND, |
688 GTK_FILL | GTK_EXPAND, | 948 GTK_FILL | GTK_EXPAND, |
689 5, 0); | 949 5, 0); |
690 } | 950 } |
951 else if (type == GAIM_REQUEST_FIELD_STRING && | |
952 gaim_request_field_string_is_multiline(field)) { | |
953 | |
954 gtk_table_attach(GTK_TABLE(table), widget, | |
955 0, 2 * cols, | |
956 row_num, row_num + 1, | |
957 GTK_FILL | GTK_EXPAND, | |
958 GTK_FILL | GTK_EXPAND, | |
959 5, 0); | |
960 } | |
691 else { | 961 else { |
692 gtk_table_attach(GTK_TABLE(table), widget, | 962 gtk_table_attach(GTK_TABLE(table), widget, |
693 col_offset, col_offset + 1, | 963 col_offset, col_offset + 1, |
694 row_num, row_num + 1, | 964 row_num, row_num + 1, |
695 GTK_FILL | GTK_EXPAND, | 965 GTK_FILL | GTK_EXPAND, |
700 gtk_widget_show(widget); | 970 gtk_widget_show(widget); |
701 | 971 |
702 field->ui_data = widget; | 972 field->ui_data = widget; |
703 } | 973 } |
704 } | 974 } |
975 #endif | |
705 } | 976 } |
706 | 977 |
707 g_object_unref(sg); | 978 g_object_unref(sg); |
708 | |
709 #if 0 | |
710 /* Separator */ | |
711 sep = gtk_hseparator_new(); | |
712 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
713 gtk_widget_show(sep); | |
714 #endif | |
715 | 979 |
716 /* Button box. */ | 980 /* Button box. */ |
717 bbox = gtk_hbutton_box_new(); | 981 bbox = gtk_hbutton_box_new(); |
718 gtk_box_set_spacing(GTK_BOX(bbox), 6); | 982 gtk_box_set_spacing(GTK_BOX(bbox), 6); |
719 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | 983 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); |