annotate audacious/widgets/textbox.c @ 1541:06329cbf186a trunk

[svn] this massive commit does the following: - seriously cleans up dependencies on the WA2-like gui code - moves all of the WA2 stuff into a seperate library (libwidgets.a) - makes things less icky in the player tree
author nenolod
date Wed, 09 Aug 2006 02:47:22 -0700
parents
children ec4d858524fa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1541
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
1 /* BMP - Cross-platform multimedia player
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
2 * Copyright (C) 2003-2004 BMP development team.
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
3 *
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
4 * Based on XMMS:
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
5 * Copyright (C) 1998-2003 XMMS development team.
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
6 *
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
10 * (at your option) any later version.
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
11 *
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
15 * GNU General Public License for more details.
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
16 *
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
20 */
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
21
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
22 #include "textbox.h"
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
23
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
24 #include <glib.h>
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
25 #include <gtk/gtk.h>
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
26 #include <gdk/gdk.h>
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
27 #include <gdk/gdkprivate.h>
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
28 #include <string.h>
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
29 #include <ctype.h>
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
30
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
31 #include "main.h"
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
32 #include "util.h"
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
33
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
34 static void textbox_generate_pixmap(TextBox * tb);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
35
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
36 static void
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
37 textbox_draw(Widget * w)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
38 {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
39 TextBox *tb = TEXT_BOX(w);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
40 gint cw;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
41 GdkPixmap *obj;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
42 GdkPixmap *src;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
43
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
44 g_return_if_fail(tb != NULL);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
45
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
46 if (tb->tb_text &&
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
47 (!tb->tb_pixmap_text || strcmp(tb->tb_text, tb->tb_pixmap_text)))
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
48 textbox_generate_pixmap(tb);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
49
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
50 if (tb->tb_pixmap) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
51 if (skin_get_id() != tb->tb_skin_id) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
52 tb->tb_skin_id = skin_get_id();
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
53 textbox_generate_pixmap(tb);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
54 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
55 obj = tb->tb_widget.parent;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
56 src = tb->tb_pixmap;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
57
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
58 cw = tb->tb_pixmap_width - tb->tb_offset;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
59 if (cw > tb->tb_widget.width)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
60 cw = tb->tb_widget.width;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
61 gdk_draw_pixmap(obj, tb->tb_widget.gc, src, tb->tb_offset, 0,
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
62 tb->tb_widget.x, tb->tb_widget.y, cw,
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
63 tb->tb_widget.height);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
64 if (cw < tb->tb_widget.width)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
65 gdk_draw_pixmap(obj, tb->tb_widget.gc, src, 0, 0,
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
66 tb->tb_widget.x + cw, tb->tb_widget.y,
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
67 tb->tb_widget.width - cw, tb->tb_widget.height);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
68 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
69 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
70
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
71 static gboolean
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
72 textbox_scroll(gpointer data)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
73 {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
74 TextBox *tb = TEXT_BOX(data);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
75
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
76 if (!tb->tb_is_dragging) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
77 tb->tb_offset += 1;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
78 if (tb->tb_offset >= tb->tb_pixmap_width)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
79 tb->tb_offset -= tb->tb_pixmap_width;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
80 widget_draw(WIDGET(tb));
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
81 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
82
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
83 return TRUE;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
84 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
85
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
86 static void
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
87 textbox_button_press(GtkWidget * w, GdkEventButton * event, gpointer data)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
88 {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
89 TextBox *tb = TEXT_BOX(data);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
90
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
91 if (event->button != 1)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
92 return;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
93 if (widget_contains(&tb->tb_widget, event->x, event->y) &&
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
94 tb->tb_scroll_allowed &&
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
95 tb->tb_pixmap_width > tb->tb_widget.width && tb->tb_is_scrollable) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
96 tb->tb_is_dragging = TRUE;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
97 tb->tb_drag_off = tb->tb_offset;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
98 tb->tb_drag_x = event->x;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
99 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
100 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
101
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
102 static void
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
103 textbox_motion(GtkWidget * w, GdkEventMotion * event, gpointer data)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
104 {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
105 TextBox *tb = TEXT_BOX(data);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
106
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
107 if (tb->tb_is_dragging) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
108 if (tb->tb_scroll_allowed &&
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
109 tb->tb_pixmap_width > tb->tb_widget.width) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
110 tb->tb_offset = tb->tb_drag_off - (event->x - tb->tb_drag_x);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
111
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
112 while (tb->tb_offset < 0)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
113 tb->tb_offset += tb->tb_pixmap_width;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
114
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
115 while (tb->tb_offset > tb->tb_pixmap_width)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
116 tb->tb_offset -= tb->tb_pixmap_width;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
117
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
118 widget_draw(WIDGET(tb));
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
119 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
120 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
121 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
122
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
123 static void
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
124 textbox_button_release(GtkWidget * w, GdkEventButton * event, gpointer data)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
125 {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
126 TextBox *tb = TEXT_BOX(data);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
127
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
128 if (event->button == 1)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
129 tb->tb_is_dragging = FALSE;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
130 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
131
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
132 static gboolean
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
133 textbox_should_scroll(TextBox * tb)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
134 {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
135 g_return_val_if_fail(tb != NULL, FALSE);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
136
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
137 if (!tb->tb_scroll_allowed)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
138 return FALSE;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
139
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
140 if (tb->tb_font) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
141 gint width;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
142
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
143 text_get_extents(tb->tb_fontname, tb->tb_text, &width, NULL, NULL,
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
144 NULL);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
145
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
146 if (width <= tb->tb_widget.width)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
147 return FALSE;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
148 else
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
149 return TRUE;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
150 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
151
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
152 if (g_utf8_strlen(tb->tb_text, -1) * 5 > tb->tb_widget.width)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
153 return TRUE;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
154
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
155 return FALSE;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
156 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
157
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
158 void
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
159 textbox_set_text(TextBox * tb, const gchar * text)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
160 {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
161 g_return_if_fail(tb != NULL);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
162 g_return_if_fail(text != NULL);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
163
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
164 widget_lock(WIDGET(tb));
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
165
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
166 if (tb->tb_text) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
167 if (!strcmp(text, tb->tb_text)) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
168 widget_unlock(WIDGET(tb));
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
169 return;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
170 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
171 g_free(tb->tb_text);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
172 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
173
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
174 tb->tb_text = str_to_utf8(text);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
175
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
176 widget_unlock(WIDGET(tb));
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
177 widget_draw(WIDGET(tb));
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
178 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
179
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
180 static void
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
181 textbox_generate_xfont_pixmap(TextBox * tb, const gchar * pixmaptext)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
182 {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
183 gint length, i;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
184 GdkGC *gc, *maskgc;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
185 GdkColor *c, pattern;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
186 GdkBitmap *mask;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
187 PangoLayout *layout;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
188 gint width;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
189
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
190 g_return_if_fail(tb != NULL);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
191 g_return_if_fail(pixmaptext != NULL);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
192
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
193 length = g_utf8_strlen(pixmaptext, -1);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
194
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
195 text_get_extents(tb->tb_fontname, pixmaptext, &width, NULL, NULL, NULL);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
196
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
197 tb->tb_pixmap_width = MAX(width, tb->tb_widget.width);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
198 tb->tb_pixmap = gdk_pixmap_new(mainwin->window, tb->tb_pixmap_width,
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
199 tb->tb_widget.height,
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
200 gdk_rgb_get_visual()->depth);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
201 gc = tb->tb_widget.gc;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
202 c = skin_get_color(bmp_active_skin, SKIN_TEXTBG);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
203 for (i = 0; i < tb->tb_widget.height; i++) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
204 gdk_gc_set_foreground(gc, &c[6 * i / tb->tb_widget.height]);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
205 gdk_draw_line(tb->tb_pixmap, gc, 0, i, tb->tb_pixmap_width, i);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
206 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
207
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
208 mask = gdk_pixmap_new(mainwin->window, tb->tb_pixmap_width,
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
209 tb->tb_widget.height, 1);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
210 maskgc = gdk_gc_new(mask);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
211 pattern.pixel = 0;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
212 gdk_gc_set_foreground(maskgc, &pattern);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
213
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
214 gdk_draw_rectangle(mask, maskgc, TRUE, 0, 0,
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
215 tb->tb_pixmap_width, tb->tb_widget.height);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
216 pattern.pixel = 1;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
217 gdk_gc_set_foreground(maskgc, &pattern);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
218
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
219 gdk_gc_set_foreground(gc, skin_get_color(bmp_active_skin, SKIN_TEXTFG));
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
220
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
221 layout = gtk_widget_create_pango_layout(mainwin, pixmaptext);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
222 pango_layout_set_font_description(layout, tb->tb_font);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
223
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
224 gdk_draw_layout(tb->tb_pixmap, gc, 0, (tb->tb_font_descent / 2), layout);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
225 g_object_unref(layout);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
226
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
227 g_object_unref(maskgc);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
228
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
229 gdk_gc_set_clip_mask(gc, mask);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
230 c = skin_get_color(bmp_active_skin, SKIN_TEXTFG);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
231 for (i = 0; i < tb->tb_widget.height; i++) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
232 gdk_gc_set_foreground(gc, &c[6 * i / tb->tb_widget.height]);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
233 gdk_draw_line(tb->tb_pixmap, gc, 0, i, tb->tb_pixmap_width, i);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
234 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
235 g_object_unref(mask);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
236 gdk_gc_set_clip_mask(gc, NULL);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
237 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
238
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
239 static void
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
240 textbox_handle_special_char(gchar c, gint * x, gint * y)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
241 {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
242 switch (c) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
243 case '"':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
244 *x = 130;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
245 *y = 0;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
246 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
247 case '\r':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
248 *x = 50;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
249 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
250 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
251 case ':':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
252 case ';':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
253 *x = 60;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
254 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
255 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
256 case '(':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
257 *x = 65;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
258 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
259 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
260 case ')':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
261 *x = 70;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
262 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
263 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
264 case '-':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
265 *x = 75;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
266 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
267 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
268 case '`':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
269 case '\'':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
270 *x = 80;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
271 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
272 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
273 case '!':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
274 *x = 85;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
275 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
276 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
277 case '_':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
278 *x = 90;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
279 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
280 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
281 case '+':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
282 *x = 95;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
283 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
284 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
285 case '\\':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
286 *x = 100;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
287 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
288 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
289 case '/':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
290 *x = 105;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
291 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
292 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
293 case '[':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
294 *x = 110;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
295 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
296 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
297 case ']':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
298 *x = 115;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
299 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
300 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
301 case '^':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
302 *x = 120;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
303 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
304 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
305 case '&':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
306 *x = 125;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
307 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
308 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
309 case '%':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
310 *x = 130;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
311 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
312 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
313 case '.':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
314 case ',':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
315 *x = 135;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
316 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
317 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
318 case '=':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
319 *x = 140;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
320 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
321 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
322 case '$':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
323 *x = 145;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
324 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
325 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
326 case '#':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
327 *x = 150;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
328 *y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
329 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
330 case 'å':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
331 case 'Å':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
332 *x = 0;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
333 *y = 12;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
334 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
335 case 'ö':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
336 case 'Ö':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
337 *x = 5;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
338 *y = 12;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
339 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
340 case 'ä':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
341 case 'Ä':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
342 *x = 10;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
343 *y = 12;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
344 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
345 case 'ü':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
346 case 'Ü':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
347 *x = 100;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
348 *y = 0;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
349 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
350 case '?':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
351 *x = 15;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
352 *y = 12;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
353 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
354 case '*':
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
355 *x = 20;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
356 *y = 12;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
357 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
358 default:
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
359 *x = 145;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
360 *y = 0;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
361 break;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
362 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
363 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
364
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
365 static void
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
366 textbox_generate_pixmap(TextBox * tb)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
367 {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
368 gint length, i, x, y, wl;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
369 gchar *pixmaptext;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
370 GdkGC *gc;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
371
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
372 g_return_if_fail(tb != NULL);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
373
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
374 if (tb->tb_pixmap) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
375 g_object_unref(tb->tb_pixmap);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
376 tb->tb_pixmap = NULL;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
377 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
378
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
379 /*
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
380 * Don't reset the offset if only text after the last '(' has
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
381 * changed. This is a hack to avoid visual noice on vbr files
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
382 * where we guess the length.
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
383 */
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
384 if (!(tb->tb_pixmap_text && strrchr(tb->tb_text, '(') &&
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
385 !strncmp(tb->tb_pixmap_text, tb->tb_text,
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
386 strrchr(tb->tb_text, '(') - tb->tb_text)))
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
387 tb->tb_offset = 0;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
388
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
389 g_free(tb->tb_pixmap_text);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
390 tb->tb_pixmap_text = g_strdup(tb->tb_text);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
391
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
392 /*
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
393 * wl is the number of (partial) letters visible. Only makes
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
394 * sense when using skinned font.
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
395 */
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
396
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
397 wl = tb->tb_widget.width / 5;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
398 if (wl * 5 != tb->tb_widget.width)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
399 wl++;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
400
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
401 length = g_utf8_strlen(tb->tb_text, -1);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
402
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
403 tb->tb_is_scrollable = FALSE;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
404
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
405 if (textbox_should_scroll(tb)) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
406 tb->tb_is_scrollable = TRUE;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
407 pixmaptext = g_strconcat(tb->tb_pixmap_text, " *** ", NULL);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
408 length += 7;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
409 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
410 else if (!tb->tb_font && length <= wl) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
411 gint pad = wl - length;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
412 gchar *padchars = g_strnfill(pad, ' ');
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
413
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
414 pixmaptext = g_strconcat(tb->tb_pixmap_text, padchars, NULL);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
415 g_free(padchars);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
416 length += pad;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
417 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
418 else
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
419 pixmaptext = g_strdup(tb->tb_pixmap_text);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
420
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
421
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
422 if (tb->tb_is_scrollable) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
423 if (tb->tb_scroll_enabled && !tb->tb_timeout_tag) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
424 gint tag;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
425 tag = TEXTBOX_SCROLL_SMOOTH_TIMEOUT;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
426 tb->tb_timeout_tag = gtk_timeout_add(tag, textbox_scroll, tb);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
427 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
428 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
429 else {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
430 if (tb->tb_timeout_tag) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
431 gtk_timeout_remove(tb->tb_timeout_tag);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
432 tb->tb_timeout_tag = 0;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
433 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
434 tb->tb_offset = 0;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
435 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
436
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
437 if (tb->tb_font) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
438 textbox_generate_xfont_pixmap(tb, pixmaptext);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
439 g_free(pixmaptext);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
440 return;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
441 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
442
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
443 tb->tb_pixmap_width = length * 5;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
444 tb->tb_pixmap = gdk_pixmap_new(mainwin->window,
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
445 tb->tb_pixmap_width, 6,
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
446 gdk_rgb_get_visual()->depth);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
447 gc = tb->tb_widget.gc;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
448
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
449 for (i = 0; i < length; i++) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
450 gchar c;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
451 x = y = -1;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
452 c = toupper(pixmaptext[i]);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
453 if (c >= 'A' && c <= 'Z') {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
454 x = 5 * (c - 'A');
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
455 y = 0;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
456 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
457 else if (c >= '0' && c <= '9') {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
458 x = 5 * (c - '0');
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
459 y = 6;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
460 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
461 else
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
462 textbox_handle_special_char(c, &x, &y);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
463
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
464 skin_draw_pixmap(bmp_active_skin,
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
465 tb->tb_pixmap, gc, tb->tb_skin_index,
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
466 x, y, i * 5, 0, 5, 6);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
467 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
468 g_free(pixmaptext);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
469 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
470
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
471 void
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
472 textbox_set_scroll(TextBox * tb, gboolean s)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
473 {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
474 g_return_if_fail(tb != NULL);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
475
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
476 tb->tb_scroll_enabled = s;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
477 if (tb->tb_scroll_enabled && tb->tb_is_scrollable
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
478 && tb->tb_scroll_allowed) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
479 gint tag;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
480 tag = TEXTBOX_SCROLL_SMOOTH_TIMEOUT;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
481
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
482 if (tb->tb_timeout_tag)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
483 {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
484 gtk_timeout_remove(tb->tb_timeout_tag);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
485 tb->tb_timeout_tag = 0;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
486 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
487
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
488 tb->tb_timeout_tag = gtk_timeout_add(tag, textbox_scroll, tb);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
489 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
490 else
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
491 {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
492 if (tb->tb_timeout_tag)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
493 {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
494 gtk_timeout_remove(tb->tb_timeout_tag);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
495 tb->tb_timeout_tag = 0;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
496 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
497
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
498 tb->tb_offset = 0;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
499 widget_draw(WIDGET(tb));
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
500 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
501
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
502 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
503
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
504 void
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
505 textbox_set_xfont(TextBox * tb, gboolean use_xfont, const gchar * fontname)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
506 {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
507 gint ascent, descent;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
508
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
509 g_return_if_fail(tb != NULL);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
510
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
511 if (tb->tb_font) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
512 pango_font_description_free(tb->tb_font);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
513 tb->tb_font = NULL;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
514 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
515
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
516 tb->tb_widget.y = tb->tb_nominal_y;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
517 tb->tb_widget.height = tb->tb_nominal_height;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
518
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
519 /* Make sure the pixmap is regenerated */
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
520 if (tb->tb_pixmap_text) {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
521 g_free(tb->tb_pixmap_text);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
522 tb->tb_pixmap_text = NULL;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
523 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
524
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
525 if (!use_xfont || strlen(fontname) == 0)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
526 return;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
527
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
528 tb->tb_font = pango_font_description_from_string(fontname);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
529 tb->tb_fontname = g_strdup(fontname);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
530
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
531 text_get_extents(fontname,
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
532 "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz ",
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
533 NULL, NULL, &ascent, &descent);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
534 tb->tb_font_ascent = ascent;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
535 tb->tb_font_descent = descent;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
536
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
537
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
538 if (tb->tb_font == NULL)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
539 return;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
540
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
541 tb->tb_widget.height = tb->tb_font_ascent;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
542 if (tb->tb_widget.height > tb->tb_nominal_height)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
543 tb->tb_widget.y -= (tb->tb_widget.height - tb->tb_nominal_height) / 2;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
544 else
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
545 tb->tb_widget.height = tb->tb_nominal_height;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
546 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
547
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
548 TextBox *
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
549 create_textbox(GList ** wlist, GdkPixmap * parent, GdkGC * gc,
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
550 gint x, gint y, gint w, gboolean allow_scroll, SkinPixmapId si)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
551 {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
552 TextBox *tb;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
553
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
554 tb = g_new0(TextBox, 1);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
555 widget_init(&tb->tb_widget, parent, gc, x, y, w, 6, 1);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
556 tb->tb_widget.button_press_cb = textbox_button_press;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
557 tb->tb_widget.button_release_cb = textbox_button_release;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
558 tb->tb_widget.motion_cb = textbox_motion;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
559 tb->tb_widget.draw = textbox_draw;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
560 tb->tb_scroll_allowed = allow_scroll;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
561 tb->tb_scroll_enabled = TRUE;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
562 tb->tb_skin_index = si;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
563 tb->tb_nominal_y = y;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
564 tb->tb_nominal_height = tb->tb_widget.height;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
565 widget_list_add(wlist, WIDGET(tb));
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
566 tb->tb_timeout_tag = 0;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
567 return tb;
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
568 }
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
569
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
570 void
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
571 textbox_free(TextBox * tb)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
572 {
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
573 g_return_if_fail(tb != NULL);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
574
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
575 if (tb->tb_pixmap)
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
576 g_object_unref(tb->tb_pixmap);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
577 g_free(tb->tb_text);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
578 g_free(tb);
06329cbf186a [svn] this massive commit does the following:
nenolod
parents:
diff changeset
579 }