Mercurial > pidgin
comparison finch/libgnt/gntentry.c @ 21280:cfbff4a9b2b6
Hitting Return in the entry will trigger the 'activate' signal.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Mon, 05 Nov 2007 19:20:30 +0000 |
parents | 1f59065c606a |
children | 65f2a29617a2 |
comparison
equal
deleted
inserted
replaced
21279:47118f6062e9 | 21280:cfbff4a9b2b6 |
---|---|
715 return TRUE; | 715 return TRUE; |
716 } | 716 } |
717 | 717 |
718 return FALSE; | 718 return FALSE; |
719 } | 719 } |
720 else | 720 |
721 { | 721 if ((text[0] == '\r' || text[0] == ' ') && entry->ddown) |
722 if ((text[0] == '\r' || text[0] == ' ') && entry->ddown) | 722 { |
723 char *text = g_strdup(gnt_tree_get_selection_data(GNT_TREE(entry->ddown))); | |
724 destroy_suggest(entry); | |
725 complete_suggest(entry, text); | |
726 g_free(text); | |
727 update_kill_ring(entry, ENTRY_JAIL, NULL, 0); | |
728 entry_text_changed(entry); | |
729 return TRUE; | |
730 } | |
731 | |
732 if (!iscntrl(text[0])) | |
733 { | |
734 const char *str, *next; | |
735 | |
736 for (str = text; *str; str = next) | |
723 { | 737 { |
724 char *text = g_strdup(gnt_tree_get_selection_data(GNT_TREE(entry->ddown))); | 738 int len; |
725 destroy_suggest(entry); | 739 next = g_utf8_find_next_char(str, NULL); |
726 complete_suggest(entry, text); | 740 len = next - str; |
727 g_free(text); | 741 |
728 update_kill_ring(entry, ENTRY_JAIL, NULL, 0); | 742 /* Valid input? */ |
729 entry_text_changed(entry); | 743 /* XXX: Is it necessary to use _unichar_ variants here? */ |
730 return TRUE; | 744 if (ispunct(*str) && (entry->flag & GNT_ENTRY_FLAG_NO_PUNCT)) |
745 continue; | |
746 if (isspace(*str) && (entry->flag & GNT_ENTRY_FLAG_NO_SPACE)) | |
747 continue; | |
748 if (isalpha(*str) && !(entry->flag & GNT_ENTRY_FLAG_ALPHA)) | |
749 continue; | |
750 if (isdigit(*str) && !(entry->flag & GNT_ENTRY_FLAG_INT)) | |
751 continue; | |
752 | |
753 /* Reached the max? */ | |
754 if (entry->max && g_utf8_pointer_to_offset(entry->start, entry->end) >= entry->max) | |
755 continue; | |
756 | |
757 if (entry->end + len - entry->start >= entry->buffer) | |
758 { | |
759 /* This will cause the buffer to grow */ | |
760 char *tmp = g_strdup(entry->start); | |
761 gnt_entry_set_text_internal(entry, tmp); | |
762 g_free(tmp); | |
763 } | |
764 | |
765 memmove(entry->cursor + len, entry->cursor, entry->end - entry->cursor + 1); | |
766 entry->end += len; | |
767 | |
768 while (str < next) | |
769 { | |
770 if (*str == '\r' || *str == '\n') | |
771 *entry->cursor = ' '; | |
772 else | |
773 *entry->cursor = *str; | |
774 entry->cursor++; | |
775 str++; | |
776 } | |
777 | |
778 while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= widget->priv.width) | |
779 entry->scroll = g_utf8_find_next_char(entry->scroll, NULL); | |
780 | |
781 if (entry->ddown) | |
782 show_suggest_dropdown(entry); | |
731 } | 783 } |
732 | 784 update_kill_ring(entry, ENTRY_JAIL, NULL, 0); |
733 if (!iscntrl(text[0])) | 785 entry_redraw(widget); |
734 { | 786 entry_text_changed(entry); |
735 const char *str, *next; | 787 return TRUE; |
736 | 788 } |
737 for (str = text; *str; str = next) | 789 |
738 { | 790 if (text[0] == '\r') { |
739 int len; | 791 gnt_widget_activate(widget); |
740 next = g_utf8_find_next_char(str, NULL); | 792 return TRUE; |
741 len = next - str; | |
742 | |
743 /* Valid input? */ | |
744 /* XXX: Is it necessary to use _unichar_ variants here? */ | |
745 if (ispunct(*str) && (entry->flag & GNT_ENTRY_FLAG_NO_PUNCT)) | |
746 continue; | |
747 if (isspace(*str) && (entry->flag & GNT_ENTRY_FLAG_NO_SPACE)) | |
748 continue; | |
749 if (isalpha(*str) && !(entry->flag & GNT_ENTRY_FLAG_ALPHA)) | |
750 continue; | |
751 if (isdigit(*str) && !(entry->flag & GNT_ENTRY_FLAG_INT)) | |
752 continue; | |
753 | |
754 /* Reached the max? */ | |
755 if (entry->max && g_utf8_pointer_to_offset(entry->start, entry->end) >= entry->max) | |
756 continue; | |
757 | |
758 if (entry->end + len - entry->start >= entry->buffer) | |
759 { | |
760 /* This will cause the buffer to grow */ | |
761 char *tmp = g_strdup(entry->start); | |
762 gnt_entry_set_text_internal(entry, tmp); | |
763 g_free(tmp); | |
764 } | |
765 | |
766 memmove(entry->cursor + len, entry->cursor, entry->end - entry->cursor + 1); | |
767 entry->end += len; | |
768 | |
769 while (str < next) | |
770 { | |
771 if (*str == '\r' || *str == '\n') | |
772 *entry->cursor = ' '; | |
773 else | |
774 *entry->cursor = *str; | |
775 entry->cursor++; | |
776 str++; | |
777 } | |
778 | |
779 while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= widget->priv.width) | |
780 entry->scroll = g_utf8_find_next_char(entry->scroll, NULL); | |
781 | |
782 if (entry->ddown) | |
783 show_suggest_dropdown(entry); | |
784 } | |
785 update_kill_ring(entry, ENTRY_JAIL, NULL, 0); | |
786 entry_redraw(widget); | |
787 entry_text_changed(entry); | |
788 return TRUE; | |
789 } | |
790 } | 793 } |
791 | 794 |
792 return FALSE; | 795 return FALSE; |
793 } | 796 } |
794 | 797 |