annotate console/libgnt/gnttextview.c @ 13882:5c750626eaa5

[gaim-migrate @ 16362] New widget GntTextView. It's really simple as it is. But it 'works'. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 28 Jun 2006 00:17:35 +0000
parents
children 9d66969a2e32
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13882
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1 #include "gnttextview.h"
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
2
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
3 enum
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
4 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
5 SIGS = 1,
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
6 };
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
7
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
8 static GntWidgetClass *parent_class = NULL;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
9 static guint signals[SIGS] = { 0 };
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
10
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
11 static void
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
12 gnt_text_view_draw(GntWidget *widget)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
13 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
14 GntTextView *view = GNT_TEXT_VIEW(widget);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
15
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
16 copywin(view->scroll, widget->window, view->pos, 0, 0, 0,
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
17 widget->priv.height - 1, widget->priv.width - 1, FALSE);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
18
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
19 DEBUG;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
20 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
21
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
22 static void
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
23 gnt_text_view_size_request(GntWidget *widget)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
24 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
25 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED))
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
26 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
27 gnt_widget_set_size(widget, 64, 24);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
28 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
29 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
30
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
31 static void
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
32 gnt_text_view_map(GntWidget *widget)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
33 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
34 if (widget->priv.width == 0 || widget->priv.height == 0)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
35 gnt_widget_size_request(widget);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
36 DEBUG;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
37 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
38
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
39 static gboolean
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
40 gnt_text_view_key_pressed(GntWidget *widget, const char *text)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
41 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
42 return FALSE;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
43 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
44
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
45 static void
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
46 gnt_text_view_destroy(GntWidget *widget)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
47 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
48 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
49
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
50 static void
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
51 gnt_text_view_class_init(GntTextViewClass *klass)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
52 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
53 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
54
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
55 parent_class = GNT_WIDGET_CLASS(klass);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
56 parent_class->destroy = gnt_text_view_destroy;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
57 parent_class->draw = gnt_text_view_draw;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
58 parent_class->map = gnt_text_view_map;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
59 parent_class->size_request = gnt_text_view_size_request;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
60 parent_class->key_pressed = gnt_text_view_key_pressed;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
61
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
62 DEBUG;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
63 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
64
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
65 static void
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
66 gnt_text_view_init(GTypeInstance *instance, gpointer class)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
67 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
68 DEBUG;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
69 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
70
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
71 /******************************************************************************
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
72 * GntTextView API
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
73 *****************************************************************************/
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
74 GType
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
75 gnt_text_view_get_gtype(void)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
76 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
77 static GType type = 0;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
78
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
79 if(type == 0)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
80 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
81 static const GTypeInfo info = {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
82 sizeof(GntTextViewClass),
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
83 NULL, /* base_init */
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
84 NULL, /* base_finalize */
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
85 (GClassInitFunc)gnt_text_view_class_init,
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
86 NULL, /* class_finalize */
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
87 NULL, /* class_data */
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
88 sizeof(GntTextView),
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
89 0, /* n_preallocs */
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
90 gnt_text_view_init, /* instance_init */
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
91 };
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
92
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
93 type = g_type_register_static(GNT_TYPE_WIDGET,
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
94 "GntTextView",
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
95 &info, 0);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
96 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
97
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
98 return type;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
99 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
100
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
101 GntWidget *gnt_text_view_new()
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
102 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
103 GntWidget *widget = g_object_new(GNT_TYPE_TEXTVIEW, NULL);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
104 GntTextView *view = GNT_TEXT_VIEW(widget);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
105
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
106 view->scroll = newwin(255, widget->priv.width, widget->priv.y, widget->priv.x);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
107 scrollok(view->scroll, TRUE);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
108 wsetscrreg(view->scroll, 0, 254);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
109 wbkgd(view->scroll, COLOR_PAIR(GNT_COLOR_NORMAL));
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
110 werase(view->scroll);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
111 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
112
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
113 return widget;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
114 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
115
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
116 void gnt_text_view_append_text_with_flags(GntTextView *view, const char *text, GntTextViewFlags flags)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
117 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
118 GntWidget *widget = GNT_WIDGET(view);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
119 int fl = 0;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
120 char **split;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
121 int i;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
122
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
123 if (text == NULL || *text == '\0')
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
124 return;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
125
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
126 if (flags & GNT_TEXT_FLAG_BOLD)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
127 fl |= A_BOLD;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
128 if (flags & GNT_TEXT_FLAG_UNDERLINE)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
129 fl |= A_UNDERLINE;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
130 if (flags & GNT_TEXT_FLAG_BLINK)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
131 fl |= A_BLINK;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
132
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
133 wattrset(view->scroll, fl | COLOR_PAIR(GNT_COLOR_NORMAL));
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
134
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
135 split = g_strsplit(text, "\n", 0);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
136 for (i = 0; split[i + 1]; i++)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
137 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
138 /* XXX: Do something if the strlen of split[i] is big
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
139 * enough to cause the text to wrap. */
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
140 wprintw(view->scroll, "%s\n", split[i]);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
141 view->lines++;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
142 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
143 wprintw(view->scroll, "%s", split[i]);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
144 g_strfreev(split);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
145
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
146 gnt_widget_draw(widget);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
147 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
148
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
149 void gnt_text_view_scroll(GntTextView *view, int scroll)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
150 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
151 GntWidget *widget = GNT_WIDGET(view);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
152 int height;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
153
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
154 if (scroll == 0)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
155 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
156 view->pos = view->lines - widget->priv.height + 1;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
157 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
158 else
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
159 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
160 view->pos += scroll;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
161 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
162
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
163 if (view->pos + (height = widget->priv.height) > view->lines)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
164 view->pos = view->lines - height + 1;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
165
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
166 if (view->pos < 0)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
167 view->pos = 0;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
168
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
169 gnt_widget_draw(GNT_WIDGET(view));
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
170 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
171
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
172 void gnt_text_view_next_line(GntTextView *view)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
173 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
174 wclrtoeol(view->scroll);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
175 gnt_text_view_append_text_with_flags(view, "\n", 0);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
176 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
177