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