Mercurial > audlegacy-plugins
annotate src/skins/ui_skinned_textbox.c @ 3123:a2093254960a
Sanity check to work around a WMA decoding error.
author | John Lindgren <john.lindgren@tds.net> |
---|---|
date | Wed, 06 May 2009 12:11:06 -0400 |
parents | b0f8da03187b |
children | 1ffcad5f406c |
rev | line source |
---|---|
2586 | 1 /* |
2 * Audacious - a cross-platform multimedia player | |
3 * Copyright (c) 2007 Tomasz Moń | |
4 * | |
5 * Based on: | |
6 * BMP - Cross-platform multimedia player | |
7 * Copyright (C) 2003-2004 BMP development team. | |
8 * XMMS: | |
9 * Copyright (C) 1998-2003 XMMS development team. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; under version 3 of the License. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program. If not, see <http://www.gnu.org/licenses>. | |
22 * | |
23 * The Audacious team does not consider modular code linking to | |
24 * Audacious or using our public API to be a derived work. | |
25 */ | |
26 | |
27 #include "ui_skinned_textbox.h" | |
28 #include "skins_cfg.h" | |
29 #include "plugin.h" | |
30 #include <string.h> | |
31 | |
32 #include "util.h" | |
33 | |
34 #define UI_SKINNED_TEXTBOX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ui_skinned_textbox_get_type(), UiSkinnedTextboxPrivate)) | |
35 typedef struct _UiSkinnedTextboxPrivate UiSkinnedTextboxPrivate; | |
36 | |
37 #define TEXTBOX_SCROLL_SMOOTH_TIMEOUT 30 | |
38 #define TEXTBOX_SCROLL_WAIT 80 | |
39 | |
40 enum { | |
41 CLICKED, | |
42 DOUBLE_CLICKED, | |
43 RIGHT_CLICKED, | |
44 DOUBLED, | |
45 LAST_SIGNAL | |
46 }; | |
47 | |
48 struct _UiSkinnedTextboxPrivate { | |
49 SkinPixmapId skin_index; | |
50 gboolean scaled; | |
51 gboolean scroll_back; | |
52 gint nominal_y, nominal_height; | |
53 gint scroll_timeout; | |
54 gint font_ascent, font_descent; | |
55 PangoFontDescription *font; | |
56 gchar *fontname; | |
57 gchar *pixbuf_text; | |
58 gint skin_id; | |
59 gint drag_x, drag_off, offset; | |
60 gboolean is_scrollable, is_dragging; | |
61 gint pixbuf_width; | |
62 GdkPixbuf *pixbuf; | |
63 gboolean scroll_allowed, scroll_enabled; | |
64 gint scroll_dummy; | |
65 gint move_x, move_y; | |
66 }; | |
67 | |
68 static void ui_skinned_textbox_class_init (UiSkinnedTextboxClass *klass); | |
69 static void ui_skinned_textbox_init (UiSkinnedTextbox *textbox); | |
70 static void ui_skinned_textbox_destroy (GtkObject *object); | |
71 static void ui_skinned_textbox_realize (GtkWidget *widget); | |
2860
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
72 static void ui_skinned_textbox_unrealize (GtkWidget *widget); |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
73 static void ui_skinned_textbox_map (GtkWidget *widget); |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
74 static void ui_skinned_textbox_unmap (GtkWidget *widget); |
2586 | 75 static void ui_skinned_textbox_size_request (GtkWidget *widget, GtkRequisition *requisition); |
76 static void ui_skinned_textbox_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
77 static gboolean ui_skinned_textbox_expose (GtkWidget *widget, GdkEventExpose *event); | |
78 static gboolean ui_skinned_textbox_button_press (GtkWidget *widget, GdkEventButton *event); | |
79 static gboolean ui_skinned_textbox_button_release (GtkWidget *widget, GdkEventButton *event); | |
80 static gboolean ui_skinned_textbox_motion_notify (GtkWidget *widget, GdkEventMotion *event); | |
81 static void ui_skinned_textbox_toggle_scaled (UiSkinnedTextbox *textbox); | |
82 static gboolean ui_skinned_textbox_should_scroll (UiSkinnedTextbox *textbox); | |
83 static void textbox_generate_xfont_pixmap (UiSkinnedTextbox *textbox, const gchar *pixmaptext); | |
84 static gboolean textbox_scroll (gpointer data); | |
85 static void textbox_generate_pixmap (UiSkinnedTextbox *textbox); | |
86 static void textbox_handle_special_char (gchar *c, gint * x, gint * y); | |
87 | |
88 static GtkWidgetClass *parent_class = NULL; | |
89 static guint textbox_signals[LAST_SIGNAL] = { 0 }; | |
90 | |
91 GType ui_skinned_textbox_get_type() { | |
92 static GType textbox_type = 0; | |
93 if (!textbox_type) { | |
94 static const GTypeInfo textbox_info = { | |
95 sizeof (UiSkinnedTextboxClass), | |
96 NULL, | |
97 NULL, | |
98 (GClassInitFunc) ui_skinned_textbox_class_init, | |
99 NULL, | |
100 NULL, | |
101 sizeof (UiSkinnedTextbox), | |
102 0, | |
103 (GInstanceInitFunc) ui_skinned_textbox_init, | |
104 }; | |
2590 | 105 textbox_type = g_type_register_static (GTK_TYPE_WIDGET, "UiSkinnedTextbox", &textbox_info, 0); |
2586 | 106 } |
107 | |
108 return textbox_type; | |
109 } | |
110 | |
111 static void ui_skinned_textbox_class_init(UiSkinnedTextboxClass *klass) { | |
112 GObjectClass *gobject_class; | |
113 GtkObjectClass *object_class; | |
114 GtkWidgetClass *widget_class; | |
115 | |
116 gobject_class = G_OBJECT_CLASS(klass); | |
117 object_class = (GtkObjectClass*) klass; | |
118 widget_class = (GtkWidgetClass*) klass; | |
3032
6baa6eaf8290
Don't use deprecated gtk_type_class()
Tomasz Mon <desowin@gmail.com>
parents:
3017
diff
changeset
|
119 parent_class = g_type_class_peek_parent(klass); |
2586 | 120 |
121 object_class->destroy = ui_skinned_textbox_destroy; | |
122 | |
123 widget_class->realize = ui_skinned_textbox_realize; | |
2860
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
124 widget_class->unrealize = ui_skinned_textbox_unrealize; |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
125 widget_class->map = ui_skinned_textbox_map; |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
126 widget_class->unmap = ui_skinned_textbox_unmap; |
2586 | 127 widget_class->expose_event = ui_skinned_textbox_expose; |
128 widget_class->size_request = ui_skinned_textbox_size_request; | |
129 widget_class->size_allocate = ui_skinned_textbox_size_allocate; | |
130 widget_class->button_press_event = ui_skinned_textbox_button_press; | |
131 widget_class->button_release_event = ui_skinned_textbox_button_release; | |
132 widget_class->motion_notify_event = ui_skinned_textbox_motion_notify; | |
133 | |
134 klass->clicked = NULL; | |
135 klass->double_clicked = NULL; | |
136 klass->right_clicked = NULL; | |
137 klass->scaled = ui_skinned_textbox_toggle_scaled; | |
138 | |
3036
b0f8da03187b
Fix multiple issues with vector fonts in the skinned interface.
John Lindgren <john.lindgren@tds.net>
parents:
3032
diff
changeset
|
139 textbox_signals[CLICKED] = |
2586 | 140 g_signal_new ("clicked", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, |
141 G_STRUCT_OFFSET (UiSkinnedTextboxClass, clicked), NULL, NULL, | |
3017
963796db51ea
Don't use deprecated gtk macros and types
Tomasz Mon <desowin@gmail.com>
parents:
2860
diff
changeset
|
142 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); |
2586 | 143 |
3036
b0f8da03187b
Fix multiple issues with vector fonts in the skinned interface.
John Lindgren <john.lindgren@tds.net>
parents:
3032
diff
changeset
|
144 textbox_signals[DOUBLE_CLICKED] = |
2586 | 145 g_signal_new ("double-clicked", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, |
146 G_STRUCT_OFFSET (UiSkinnedTextboxClass, double_clicked), NULL, NULL, | |
3017
963796db51ea
Don't use deprecated gtk macros and types
Tomasz Mon <desowin@gmail.com>
parents:
2860
diff
changeset
|
147 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); |
2586 | 148 |
3036
b0f8da03187b
Fix multiple issues with vector fonts in the skinned interface.
John Lindgren <john.lindgren@tds.net>
parents:
3032
diff
changeset
|
149 textbox_signals[RIGHT_CLICKED] = |
2586 | 150 g_signal_new ("right-clicked", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, |
151 G_STRUCT_OFFSET (UiSkinnedTextboxClass, right_clicked), NULL, NULL, | |
3017
963796db51ea
Don't use deprecated gtk macros and types
Tomasz Mon <desowin@gmail.com>
parents:
2860
diff
changeset
|
152 g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); |
2586 | 153 |
3036
b0f8da03187b
Fix multiple issues with vector fonts in the skinned interface.
John Lindgren <john.lindgren@tds.net>
parents:
3032
diff
changeset
|
154 textbox_signals[DOUBLED] = |
2586 | 155 g_signal_new ("toggle-scaled", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, |
156 G_STRUCT_OFFSET (UiSkinnedTextboxClass, scaled), NULL, NULL, | |
3017
963796db51ea
Don't use deprecated gtk macros and types
Tomasz Mon <desowin@gmail.com>
parents:
2860
diff
changeset
|
157 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); |
2586 | 158 |
159 g_type_class_add_private (gobject_class, sizeof (UiSkinnedTextboxPrivate)); | |
160 } | |
161 | |
162 static void ui_skinned_textbox_init(UiSkinnedTextbox *textbox) { | |
163 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
164 priv->move_x = 0; | |
165 priv->move_y = 0; | |
2860
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
166 |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
167 textbox->event_window = NULL; |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
168 GTK_WIDGET_SET_FLAGS (textbox, GTK_NO_WINDOW); |
2586 | 169 } |
170 | |
171 GtkWidget* ui_skinned_textbox_new(GtkWidget *fixed, gint x, gint y, gint w, gboolean allow_scroll, SkinPixmapId si) { | |
172 UiSkinnedTextbox *textbox = g_object_new (ui_skinned_textbox_get_type (), NULL); | |
173 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
174 | |
175 textbox->height = aud_active_skin->properties.textbox_bitmap_font_height; | |
176 textbox->x = x; | |
177 textbox->y = y; | |
178 textbox->text = g_strdup(""); | |
179 textbox->width = w; | |
180 priv->scroll_allowed = allow_scroll; | |
181 priv->scroll_enabled = TRUE; | |
182 priv->skin_index = si; | |
183 priv->nominal_y = y; | |
184 priv->nominal_height = textbox->height; | |
185 priv->scroll_timeout = 0; | |
186 priv->scroll_dummy = 0; | |
187 | |
188 priv->scaled = FALSE; | |
189 | |
190 gtk_fixed_put(GTK_FIXED(fixed), GTK_WIDGET(textbox), textbox->x, textbox->y); | |
191 | |
192 return GTK_WIDGET(textbox); | |
193 } | |
194 | |
195 static void ui_skinned_textbox_destroy(GtkObject *object) { | |
196 UiSkinnedTextbox *textbox; | |
2836
fbb17b57229a
fix possible segfault on cleanup
Tomasz Mon <desowin@gmail.com>
parents:
2698
diff
changeset
|
197 UiSkinnedTextboxPrivate *priv; |
2586 | 198 |
199 g_return_if_fail (object != NULL); | |
200 g_return_if_fail (UI_SKINNED_IS_TEXTBOX (object)); | |
201 | |
202 textbox = UI_SKINNED_TEXTBOX (object); | |
2836
fbb17b57229a
fix possible segfault on cleanup
Tomasz Mon <desowin@gmail.com>
parents:
2698
diff
changeset
|
203 priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(object); |
fbb17b57229a
fix possible segfault on cleanup
Tomasz Mon <desowin@gmail.com>
parents:
2698
diff
changeset
|
204 |
fbb17b57229a
fix possible segfault on cleanup
Tomasz Mon <desowin@gmail.com>
parents:
2698
diff
changeset
|
205 if (priv->scroll_timeout) { |
fbb17b57229a
fix possible segfault on cleanup
Tomasz Mon <desowin@gmail.com>
parents:
2698
diff
changeset
|
206 g_source_remove(priv->scroll_timeout); |
fbb17b57229a
fix possible segfault on cleanup
Tomasz Mon <desowin@gmail.com>
parents:
2698
diff
changeset
|
207 priv->scroll_timeout = 0; |
fbb17b57229a
fix possible segfault on cleanup
Tomasz Mon <desowin@gmail.com>
parents:
2698
diff
changeset
|
208 } |
2586 | 209 |
210 if (GTK_OBJECT_CLASS (parent_class)->destroy) | |
211 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); | |
212 } | |
213 | |
214 static void ui_skinned_textbox_realize(GtkWidget *widget) { | |
215 UiSkinnedTextbox *textbox; | |
216 GdkWindowAttr attributes; | |
217 gint attributes_mask; | |
218 | |
219 g_return_if_fail (widget != NULL); | |
220 g_return_if_fail (UI_SKINNED_IS_TEXTBOX(widget)); | |
221 | |
2860
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
222 if (GTK_WIDGET_CLASS (parent_class)->realize) |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
223 (* GTK_WIDGET_CLASS (parent_class)->realize) (widget); |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
224 |
2586 | 225 textbox = UI_SKINNED_TEXTBOX(widget); |
226 | |
227 attributes.x = widget->allocation.x; | |
228 attributes.y = widget->allocation.y; | |
229 attributes.width = widget->allocation.width; | |
230 attributes.height = widget->allocation.height; | |
2860
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
231 attributes.wclass = GDK_INPUT_ONLY; |
2586 | 232 attributes.window_type = GDK_WINDOW_CHILD; |
233 attributes.event_mask = gtk_widget_get_events(widget); | |
2860
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
234 attributes.event_mask |= GDK_BUTTON_PRESS_MASK | |
2586 | 235 GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | |
236 GDK_POINTER_MOTION_HINT_MASK; | |
237 | |
2860
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
238 attributes_mask = GDK_WA_X | GDK_WA_Y; |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
239 textbox->event_window = gdk_window_new (widget->window, &attributes, attributes_mask); |
2586 | 240 |
241 widget->style = gtk_style_attach(widget->style, widget->window); | |
242 | |
2860
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
243 gdk_window_set_user_data(textbox->event_window, widget); |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
244 } |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
245 |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
246 static void ui_skinned_textbox_unrealize(GtkWidget *widget) { |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
247 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
248 |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
249 if ( textbox->event_window != NULL ) |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
250 { |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
251 gdk_window_set_user_data( textbox->event_window , NULL ); |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
252 gdk_window_destroy( textbox->event_window ); |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
253 textbox->event_window = NULL; |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
254 } |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
255 |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
256 if (GTK_WIDGET_CLASS (parent_class)->unrealize) |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
257 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
258 } |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
259 |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
260 static void ui_skinned_textbox_map (GtkWidget *widget) |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
261 { |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
262 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
263 |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
264 if (textbox->event_window != NULL) |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
265 gdk_window_show (textbox->event_window); |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
266 |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
267 if (GTK_WIDGET_CLASS (parent_class)->map) |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
268 (* GTK_WIDGET_CLASS (parent_class)->map) (widget); |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
269 } |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
270 |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
271 static void ui_skinned_textbox_unmap (GtkWidget *widget) |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
272 { |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
273 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
274 |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
275 if (textbox->event_window != NULL) |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
276 gdk_window_hide (textbox->event_window); |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
277 |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
278 if (GTK_WIDGET_CLASS (parent_class)->unmap) |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
279 (* GTK_WIDGET_CLASS (parent_class)->unmap) (widget); |
2586 | 280 } |
281 | |
282 static void ui_skinned_textbox_size_request(GtkWidget *widget, GtkRequisition *requisition) { | |
283 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); | |
284 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
285 | |
286 requisition->width = textbox->width*(priv->scaled ? config.scale_factor : 1); | |
287 requisition->height = textbox->height*(priv->scaled ? config.scale_factor : 1 ); | |
288 } | |
289 | |
290 static void ui_skinned_textbox_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { | |
291 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); | |
292 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
293 | |
294 widget->allocation = *allocation; | |
295 widget->allocation.x *= (priv->scaled ? config.scale_factor : 1); | |
296 widget->allocation.y *= (priv->scaled ? config.scale_factor : 1); | |
297 if (GTK_WIDGET_REALIZED (widget)) | |
2860
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
298 if (textbox->event_window) |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
299 gdk_window_move_resize(textbox->event_window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height); |
2586 | 300 |
301 if (textbox->x + priv->move_x - widget->allocation.x/(priv->scaled ? config.scale_factor : 1) <3); | |
302 priv->move_x = 0; | |
303 if (textbox->y + priv->move_y - widget->allocation.y/(priv->scaled ? config.scale_factor : 1) <3); | |
304 priv->move_y = 0; | |
305 textbox->x = widget->allocation.x/(priv->scaled ? config.scale_factor : 1); | |
306 textbox->y = widget->allocation.y/(priv->scaled ? config.scale_factor : 1); | |
307 | |
308 if (textbox->width - (guint) (widget->allocation.width / (priv->scaled ? config.scale_factor : 1)) > 2) { | |
309 textbox->width = (guint) (widget->allocation.width / (priv->scaled ? config.scale_factor : 1)); | |
310 if (priv->pixbuf_text) g_free(priv->pixbuf_text); | |
311 priv->pixbuf_text = NULL; | |
312 priv->offset = 0; | |
313 gtk_widget_set_size_request(widget, textbox->width, textbox->height); | |
314 gtk_widget_queue_draw(GTK_WIDGET(textbox)); | |
315 } | |
316 } | |
317 | |
318 static gboolean ui_skinned_textbox_expose(GtkWidget *widget, GdkEventExpose *event) { | |
319 g_return_val_if_fail (widget != NULL, FALSE); | |
320 g_return_val_if_fail (UI_SKINNED_IS_TEXTBOX (widget), FALSE); | |
321 g_return_val_if_fail (event != NULL, FALSE); | |
322 | |
323 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); | |
324 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
325 g_return_val_if_fail (textbox->width > 0 && textbox->height > 0, FALSE); | |
326 | |
327 GdkPixbuf *obj = NULL; | |
328 gint cw; | |
329 | |
330 if (textbox->text && (!priv->pixbuf_text || strcmp(textbox->text, priv->pixbuf_text))) | |
331 textbox_generate_pixmap(textbox); | |
332 | |
333 if (priv->pixbuf) { | |
334 if (skin_get_id() != priv->skin_id) { | |
335 priv->skin_id = skin_get_id(); | |
336 textbox_generate_pixmap(textbox); | |
337 } | |
338 obj = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, textbox->width, textbox->height); | |
339 | |
340 if (config.twoway_scroll) { // twoway scroll | |
341 cw = priv->pixbuf_width - priv->offset; | |
342 if (cw > textbox->width) | |
343 cw = textbox->width; | |
344 gdk_pixbuf_copy_area(priv->pixbuf, priv->offset, 0, cw, textbox->height, obj, 0, 0); | |
345 if (cw < textbox->width) | |
346 gdk_pixbuf_copy_area(priv->pixbuf, 0, 0, textbox->width - cw, textbox->height, | |
347 obj, textbox->width - cw, textbox->height); | |
348 } else { // oneway scroll | |
349 int cw1, cw2; | |
350 | |
351 if (priv->offset >= priv->pixbuf_width) | |
352 priv->offset = 0; | |
353 | |
354 if (priv->pixbuf_width - priv->offset > textbox->width) { // case1 | |
355 cw1 = textbox->width; | |
356 gdk_pixbuf_copy_area(priv->pixbuf, priv->offset, 0, cw1, textbox->height, | |
357 obj, 0, 0); | |
358 } else { // case 2 | |
359 cw1 = priv->pixbuf_width - priv->offset; | |
360 gdk_pixbuf_copy_area(priv->pixbuf, priv->offset, 0, cw1, textbox->height, obj, 0, 0); | |
361 cw2 = textbox->width - cw1; | |
362 gdk_pixbuf_copy_area(priv->pixbuf, 0, 0, cw2, textbox->height, obj, cw1, 0); | |
363 } | |
364 } | |
365 | |
2860
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
366 ui_skinned_widget_draw_with_coordinates(widget, obj, textbox->width, textbox->height, |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
367 widget->allocation.x, |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
368 widget->allocation.y, |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
369 priv->scaled); |
2586 | 370 |
371 g_object_unref(obj); | |
372 } | |
373 | |
374 return FALSE; | |
375 } | |
376 | |
377 static gboolean ui_skinned_textbox_button_press(GtkWidget *widget, GdkEventButton *event) { | |
378 g_return_val_if_fail (widget != NULL, FALSE); | |
379 g_return_val_if_fail (UI_SKINNED_IS_TEXTBOX (widget), FALSE); | |
380 g_return_val_if_fail (event != NULL, FALSE); | |
381 | |
382 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); | |
383 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
384 | |
385 if (event->type == GDK_BUTTON_PRESS) { | |
386 textbox = UI_SKINNED_TEXTBOX(widget); | |
387 if (event->button == 3 && !g_signal_has_handler_pending(widget, textbox_signals[RIGHT_CLICKED], 0, TRUE)) | |
388 return FALSE; | |
389 else if (event->button == 1) { | |
390 if (priv->scroll_allowed) { | |
391 if ((priv->pixbuf_width > textbox->width) && priv->is_scrollable) { | |
392 priv->is_dragging = TRUE; | |
393 priv->drag_off = priv->offset; | |
394 priv->drag_x = event->x; | |
395 } | |
396 } else | |
397 g_signal_emit(widget, textbox_signals[CLICKED], 0); | |
398 | |
399 } else if (event->button == 3) { | |
400 g_signal_emit(widget, textbox_signals[RIGHT_CLICKED], 0, event); | |
401 } else | |
402 priv->is_dragging = FALSE; | |
403 } else if (event->type == GDK_2BUTTON_PRESS) { | |
404 if (event->button == 1) { | |
405 if (g_signal_has_handler_pending(widget, textbox_signals[DOUBLE_CLICKED], 0, TRUE)) | |
406 g_signal_emit(widget, textbox_signals[DOUBLE_CLICKED], 0); | |
407 else | |
408 return FALSE; | |
409 } | |
410 } | |
411 | |
412 return TRUE; | |
413 } | |
414 | |
415 static gboolean ui_skinned_textbox_button_release(GtkWidget *widget, GdkEventButton *event) { | |
416 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(widget); | |
417 | |
418 if (event->button == 1) { | |
419 priv->is_dragging = FALSE; | |
420 } | |
421 | |
422 return TRUE; | |
423 } | |
424 | |
425 static gboolean ui_skinned_textbox_motion_notify(GtkWidget *widget, GdkEventMotion *event) { | |
426 g_return_val_if_fail (widget != NULL, FALSE); | |
427 g_return_val_if_fail (UI_SKINNED_IS_TEXTBOX (widget), FALSE); | |
428 g_return_val_if_fail (event != NULL, FALSE); | |
429 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); | |
430 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(widget); | |
431 | |
432 if (priv->is_dragging) { | |
433 if (priv->scroll_allowed && | |
434 priv->pixbuf_width > textbox->width) { | |
435 priv->offset = priv->drag_off - (event->x - priv->drag_x); | |
436 | |
437 while (priv->offset < 0) | |
438 priv->offset = 0; | |
439 | |
440 while (priv->offset > (priv->pixbuf_width - textbox->width)) | |
441 priv->offset = (priv->pixbuf_width - textbox->width); | |
442 | |
443 gtk_widget_queue_draw(widget); | |
444 } | |
445 } | |
446 | |
447 return TRUE; | |
448 } | |
449 | |
450 static void ui_skinned_textbox_toggle_scaled(UiSkinnedTextbox *textbox) { | |
451 GtkWidget *widget = GTK_WIDGET (textbox); | |
452 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
453 | |
454 priv->scaled = !priv->scaled; | |
455 | |
3036
b0f8da03187b
Fix multiple issues with vector fonts in the skinned interface.
John Lindgren <john.lindgren@tds.net>
parents:
3032
diff
changeset
|
456 gtk_widget_set_size_request(widget, textbox->width*(priv->scaled ? config.scale_factor : 1 ), |
2586 | 457 textbox->height*(priv->scaled ? config.scale_factor : 1 )); |
458 | |
459 gtk_widget_queue_draw(GTK_WIDGET(textbox)); | |
460 } | |
461 | |
462 static gboolean ui_skinned_textbox_should_scroll(UiSkinnedTextbox *textbox) { | |
463 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
464 | |
465 if (!priv->scroll_allowed) | |
466 return FALSE; | |
467 | |
468 if (priv->font) { | |
469 gint width; | |
470 text_get_extents(priv->fontname, textbox->text, &width, NULL, NULL, NULL); | |
471 | |
472 if (width <= textbox->width) | |
473 return FALSE; | |
474 else | |
475 return TRUE; | |
476 } | |
477 | |
478 if (g_utf8_strlen(textbox->text, -1) * aud_active_skin->properties.textbox_bitmap_font_width > textbox->width) | |
479 return TRUE; | |
480 | |
481 return FALSE; | |
482 } | |
483 | |
484 void ui_skinned_textbox_set_xfont(GtkWidget *widget, gboolean use_xfont, const gchar * fontname) { | |
485 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); | |
486 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
487 | |
488 gint ascent, descent; | |
489 | |
490 g_return_if_fail(textbox != NULL); | |
3036
b0f8da03187b
Fix multiple issues with vector fonts in the skinned interface.
John Lindgren <john.lindgren@tds.net>
parents:
3032
diff
changeset
|
491 gtk_widget_queue_resize (widget); |
b0f8da03187b
Fix multiple issues with vector fonts in the skinned interface.
John Lindgren <john.lindgren@tds.net>
parents:
3032
diff
changeset
|
492 gtk_widget_queue_draw (widget); |
2586 | 493 |
494 if (priv->font) { | |
495 pango_font_description_free(priv->font); | |
496 priv->font = NULL; | |
497 } | |
498 | |
499 textbox->y = priv->nominal_y; | |
500 textbox->height = priv->nominal_height; | |
501 | |
502 /* Make sure the pixmap is regenerated */ | |
503 if (priv->pixbuf_text) { | |
504 g_free(priv->pixbuf_text); | |
505 priv->pixbuf_text = NULL; | |
506 } | |
507 | |
508 if (!use_xfont || strlen(fontname) == 0) | |
509 return; | |
510 | |
511 priv->font = pango_font_description_from_string(fontname); | |
512 priv->fontname = g_strdup(fontname); | |
513 | |
514 text_get_extents(fontname, | |
515 "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz ", | |
516 NULL, NULL, &ascent, &descent); | |
517 priv->font_ascent = ascent; | |
518 priv->font_descent = descent; | |
519 | |
520 | |
521 if (priv->font == NULL) | |
522 return; | |
523 | |
3036
b0f8da03187b
Fix multiple issues with vector fonts in the skinned interface.
John Lindgren <john.lindgren@tds.net>
parents:
3032
diff
changeset
|
524 textbox->height = priv->font_ascent; /* The real height of the text is |
b0f8da03187b
Fix multiple issues with vector fonts in the skinned interface.
John Lindgren <john.lindgren@tds.net>
parents:
3032
diff
changeset
|
525 ascent - descent (descent is negative), but we cut off descent pixels from |
b0f8da03187b
Fix multiple issues with vector fonts in the skinned interface.
John Lindgren <john.lindgren@tds.net>
parents:
3032
diff
changeset
|
526 the top to make it fit better. See textbox_generate_xfont_pixmap. */ |
2586 | 527 } |
528 | |
529 void ui_skinned_textbox_set_text(GtkWidget *widget, const gchar *text) { | |
530 g_return_if_fail(text != NULL); | |
531 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); | |
532 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
533 | |
534 if (!strcmp(textbox->text, text)) | |
535 return; | |
536 if (textbox->text) | |
537 g_free(textbox->text); | |
538 | |
539 textbox->text = aud_str_to_utf8(text); | |
540 priv->scroll_back = FALSE; | |
541 gtk_widget_queue_draw(GTK_WIDGET(textbox)); | |
542 } | |
543 | |
544 static void textbox_generate_xfont_pixmap(UiSkinnedTextbox *textbox, const gchar *pixmaptext) { | |
545 /* FIXME: should operate directly on priv->pixbuf, it shouldn't use pixmap */ | |
546 gint length, i; | |
547 GdkGC *gc, *maskgc; | |
548 GdkColor *c, pattern; | |
549 GdkBitmap *mask; | |
550 PangoLayout *layout; | |
551 gint width; | |
552 GdkPixmap *pixmap; | |
553 | |
554 g_return_if_fail(textbox != NULL); | |
555 g_return_if_fail(pixmaptext != NULL); | |
556 g_return_if_fail(textbox->height > 0); | |
557 | |
558 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
559 | |
560 length = g_utf8_strlen(pixmaptext, -1); | |
561 | |
562 text_get_extents(priv->fontname, pixmaptext, &width, NULL, NULL, NULL); | |
563 | |
564 priv->pixbuf_width = MAX(width, textbox->width); | |
565 pixmap = gdk_pixmap_new(mainwin->window, priv->pixbuf_width, | |
566 textbox->height, | |
567 gdk_rgb_get_visual()->depth); | |
568 gc = gdk_gc_new(pixmap); | |
569 c = skin_get_color(aud_active_skin, SKIN_TEXTBG); | |
570 for (i = 0; i < textbox->height; i++) { | |
571 gdk_gc_set_foreground(gc, &c[6 * i / textbox->height]); | |
572 gdk_draw_line(pixmap, gc, 0, i, priv->pixbuf_width, i); | |
573 } | |
574 | |
575 mask = gdk_pixmap_new(mainwin->window, priv->pixbuf_width, textbox->height, 1); | |
576 maskgc = gdk_gc_new(mask); | |
577 pattern.pixel = 0; | |
578 gdk_gc_set_foreground(maskgc, &pattern); | |
579 | |
580 gdk_draw_rectangle(mask, maskgc, TRUE, 0, 0, priv->pixbuf_width, textbox->height); | |
581 pattern.pixel = 1; | |
582 gdk_gc_set_foreground(maskgc, &pattern); | |
583 | |
584 gdk_gc_set_foreground(gc, skin_get_color(aud_active_skin, SKIN_TEXTFG)); | |
585 | |
586 layout = gtk_widget_create_pango_layout(mainwin, pixmaptext); | |
587 pango_layout_set_font_description(layout, priv->font); | |
588 | |
3036
b0f8da03187b
Fix multiple issues with vector fonts in the skinned interface.
John Lindgren <john.lindgren@tds.net>
parents:
3032
diff
changeset
|
589 gdk_draw_layout (pixmap, gc, 0, priv->font_descent, layout); /* See |
b0f8da03187b
Fix multiple issues with vector fonts in the skinned interface.
John Lindgren <john.lindgren@tds.net>
parents:
3032
diff
changeset
|
590 explanation in ui_skinned_textbox_set_xfont. */ |
2586 | 591 g_object_unref(layout); |
592 | |
593 g_object_unref(maskgc); | |
594 | |
595 gdk_gc_set_clip_mask(gc, mask); | |
596 c = skin_get_color(aud_active_skin, SKIN_TEXTFG); | |
597 for (i = 0; i < textbox->height; i++) { | |
598 gdk_gc_set_foreground(gc, &c[6 * i / textbox->height]); | |
599 gdk_draw_line(pixmap, gc, 0, i, priv->pixbuf_width, i); | |
600 } | |
601 priv->pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, gdk_colormap_get_system(), 0, 0, 0, 0, priv->pixbuf_width, textbox->height); | |
602 g_object_unref(mask); | |
603 g_object_unref(gc); | |
604 } | |
605 | |
606 static gboolean textbox_scroll(gpointer data) { | |
607 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(data); | |
608 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
609 | |
610 if (!priv->is_dragging) { | |
611 if (priv->scroll_dummy < TEXTBOX_SCROLL_WAIT) | |
612 priv->scroll_dummy++; | |
613 else { | |
614 if(config.twoway_scroll) { | |
615 if (priv->scroll_back) | |
616 priv->offset -= 1; | |
617 else | |
618 priv->offset += 1; | |
619 | |
620 if (priv->offset >= (priv->pixbuf_width - textbox->width)) { | |
621 priv->scroll_back = TRUE; | |
622 priv->scroll_dummy = 0; | |
623 priv->offset = priv->pixbuf_width - textbox->width; | |
624 } | |
625 if (priv->offset <= 0) { | |
626 priv->scroll_back = FALSE; | |
627 priv->scroll_dummy = 0; | |
628 priv->offset = 0; | |
629 } | |
630 } | |
631 else { // oneway scroll | |
632 priv->scroll_back = FALSE; | |
633 priv->offset += 1; | |
634 } | |
635 gtk_widget_queue_draw(GTK_WIDGET(textbox)); | |
636 } | |
637 } | |
638 return TRUE; | |
639 } | |
640 | |
641 static void textbox_generate_pixmap(UiSkinnedTextbox *textbox) { | |
642 gint length, i, x, y, wl; | |
643 gchar *pixmaptext; | |
644 gchar *tmp, *stxt; | |
645 | |
646 g_return_if_fail(textbox != NULL); | |
647 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
648 | |
649 if (priv->pixbuf) { | |
650 g_object_unref(priv->pixbuf); | |
651 priv->pixbuf = NULL; | |
652 } | |
653 | |
654 /* | |
655 * Don't reset the offset if only text after the last '(' has | |
656 * changed. This is a hack to avoid visual noice on vbr files | |
657 * where we guess the length. | |
658 */ | |
659 if (!(priv->pixbuf_text && strrchr(textbox->text, '(') && | |
660 !strncmp(priv->pixbuf_text, textbox->text, | |
661 strrchr(textbox->text, '(') - textbox->text))) | |
662 priv->offset = 0; | |
663 | |
664 g_free(priv->pixbuf_text); | |
665 priv->pixbuf_text = g_strdup(textbox->text); | |
666 | |
667 /* | |
668 * wl is the number of (partial) letters visible. Only makes | |
669 * sense when using skinned font. | |
670 */ | |
671 wl = textbox->width / 5; | |
672 if (wl * 5 != textbox->width) | |
673 wl++; | |
674 | |
675 length = g_utf8_strlen(textbox->text, -1); | |
676 | |
677 priv->is_scrollable = FALSE; | |
678 | |
679 priv->is_scrollable = ui_skinned_textbox_should_scroll(textbox); | |
680 | |
681 if (priv->is_scrollable) { | |
682 if(!config.twoway_scroll) { | |
683 pixmaptext = g_strdup_printf("%s *** ", priv->pixbuf_text); | |
684 length += 5; | |
685 } else | |
686 pixmaptext = g_strdup(priv->pixbuf_text); | |
687 } else | |
688 if (!priv->font && length <= wl) { | |
689 gint pad = wl - length; | |
690 gchar *padchars = g_strnfill(pad, ' '); | |
691 | |
692 pixmaptext = g_strconcat(priv->pixbuf_text, padchars, NULL); | |
693 g_free(padchars); | |
694 length += pad; | |
695 } else | |
696 pixmaptext = g_strdup(priv->pixbuf_text); | |
697 | |
698 if (priv->is_scrollable) { | |
699 if (priv->scroll_enabled && !priv->scroll_timeout) { | |
700 gint tag; | |
701 tag = TEXTBOX_SCROLL_SMOOTH_TIMEOUT; | |
702 priv->scroll_timeout = g_timeout_add(tag, textbox_scroll, textbox); | |
703 } | |
704 } else { | |
705 if (priv->scroll_timeout) { | |
706 g_source_remove(priv->scroll_timeout); | |
707 priv->scroll_timeout = 0; | |
708 } | |
709 priv->offset = 0; | |
710 } | |
711 | |
712 if (priv->font) { | |
713 textbox_generate_xfont_pixmap(textbox, pixmaptext); | |
714 g_free(pixmaptext); | |
715 return; | |
716 } | |
717 | |
718 priv->pixbuf_width = length * aud_active_skin->properties.textbox_bitmap_font_width; | |
719 priv->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, | |
720 priv->pixbuf_width, aud_active_skin->properties.textbox_bitmap_font_height); | |
721 | |
722 for (tmp = stxt = g_utf8_strup(pixmaptext, -1), i = 0; | |
723 tmp != NULL && i < length; i++, tmp = g_utf8_next_char(tmp)) { | |
724 gchar c = *tmp; | |
725 x = y = -1; | |
726 if (c >= 'A' && c <= 'Z') { | |
727 x = aud_active_skin->properties.textbox_bitmap_font_width * (c - 'A'); | |
728 y = 0; | |
729 } | |
730 else if (c >= '0' && c <= '9') { | |
731 x = aud_active_skin->properties.textbox_bitmap_font_width * (c - '0'); | |
732 y = aud_active_skin->properties.textbox_bitmap_font_height; | |
733 } | |
734 else | |
735 textbox_handle_special_char(tmp, &x, &y); | |
736 | |
737 skin_draw_pixbuf(GTK_WIDGET(textbox), aud_active_skin, | |
738 priv->pixbuf, priv->skin_index, | |
739 x, y, i * aud_active_skin->properties.textbox_bitmap_font_width, 0, | |
3036
b0f8da03187b
Fix multiple issues with vector fonts in the skinned interface.
John Lindgren <john.lindgren@tds.net>
parents:
3032
diff
changeset
|
740 aud_active_skin->properties.textbox_bitmap_font_width, |
2586 | 741 aud_active_skin->properties.textbox_bitmap_font_height); |
742 } | |
743 g_free(stxt); | |
744 g_free(pixmaptext); | |
745 } | |
746 | |
747 void ui_skinned_textbox_set_scroll(GtkWidget *widget, gboolean scroll) { | |
748 g_return_if_fail(widget != NULL); | |
2635
b990e7eb0c25
save config on plugin cleanup
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
749 g_return_if_fail(UI_SKINNED_IS_TEXTBOX(widget)); |
b990e7eb0c25
save config on plugin cleanup
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
750 |
2586 | 751 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); |
752 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
753 | |
754 priv->scroll_enabled = scroll; | |
755 if (priv->scroll_enabled && priv->is_scrollable && priv->scroll_allowed) { | |
756 gint tag; | |
757 tag = TEXTBOX_SCROLL_SMOOTH_TIMEOUT; | |
758 if (priv->scroll_timeout) { | |
759 g_source_remove(priv->scroll_timeout); | |
760 priv->scroll_timeout = 0; | |
761 } | |
762 priv->scroll_timeout = g_timeout_add(tag, textbox_scroll, textbox); | |
763 | |
764 } else { | |
765 | |
766 if (priv->scroll_timeout) { | |
767 g_source_remove(priv->scroll_timeout); | |
768 priv->scroll_timeout = 0; | |
769 } | |
770 | |
771 priv->offset = 0; | |
772 gtk_widget_queue_draw(GTK_WIDGET(textbox)); | |
773 } | |
774 } | |
775 | |
776 static void textbox_handle_special_char(gchar *c, gint * x, gint * y) { | |
777 gint tx, ty; | |
778 | |
779 switch (*c) { | |
780 case '"': | |
781 tx = 26; | |
782 ty = 0; | |
783 break; | |
784 case '\r': | |
785 tx = 10; | |
786 ty = 1; | |
787 break; | |
788 case ':': | |
789 case ';': | |
790 tx = 12; | |
791 ty = 1; | |
792 break; | |
793 case '(': | |
794 tx = 13; | |
795 ty = 1; | |
796 break; | |
797 case ')': | |
798 tx = 14; | |
799 ty = 1; | |
800 break; | |
801 case '-': | |
802 tx = 15; | |
803 ty = 1; | |
804 break; | |
805 case '`': | |
806 case '\'': | |
807 tx = 16; | |
808 ty = 1; | |
809 break; | |
810 case '!': | |
811 tx = 17; | |
812 ty = 1; | |
813 break; | |
814 case '_': | |
815 tx = 18; | |
816 ty = 1; | |
817 break; | |
818 case '+': | |
819 tx = 19; | |
820 ty = 1; | |
821 break; | |
822 case '\\': | |
823 tx = 20; | |
824 ty = 1; | |
825 break; | |
826 case '/': | |
827 tx = 21; | |
828 ty = 1; | |
829 break; | |
830 case '[': | |
831 tx = 22; | |
832 ty = 1; | |
833 break; | |
834 case ']': | |
835 tx = 23; | |
836 ty = 1; | |
837 break; | |
838 case '^': | |
839 tx = 24; | |
840 ty = 1; | |
841 break; | |
842 case '&': | |
843 tx = 25; | |
844 ty = 1; | |
845 break; | |
846 case '%': | |
847 tx = 26; | |
848 ty = 1; | |
849 break; | |
850 case '.': | |
851 case ',': | |
852 tx = 27; | |
853 ty = 1; | |
854 break; | |
855 case '=': | |
856 tx = 28; | |
857 ty = 1; | |
858 break; | |
859 case '$': | |
860 tx = 29; | |
861 ty = 1; | |
862 break; | |
863 case '#': | |
864 tx = 30; | |
865 ty = 1; | |
866 break; | |
867 case '?': | |
868 tx = 3; | |
869 ty = 2; | |
870 break; | |
871 case '*': | |
872 tx = 4; | |
873 ty = 2; | |
874 break; | |
875 default: | |
876 tx = 29; | |
877 ty = 0; | |
878 break; | |
879 } | |
880 | |
881 const gchar *change[] = {"Ą", "A", "Ę", "E", "Ć", "C", "Ł", "L", "Ó", "O", "Ś", "S", "Ż", "Z", "Ź", "Z", | |
882 "Ń", "N", "Ü", "U", NULL}; | |
883 int i; | |
884 for (i = 0; change[i]; i+=2) { | |
885 if (!strncmp(c, change[i], strlen(change[i]))) { | |
886 tx = (*change[i+1] - 'A'); | |
887 break; | |
888 } | |
889 } | |
890 | |
891 /* those are commonly included into skins */ | |
892 if (!strncmp(c, "Å", strlen("Å"))) { | |
893 tx = 0; | |
894 ty = 2; | |
895 } else if (!strncmp(c, "Ö", strlen("Ö"))) { | |
896 tx = 1; | |
897 ty = 2; | |
898 } else if (!strncmp(c, "Ä", strlen("Ä"))) { | |
899 tx = 2; | |
900 ty = 2; | |
901 } | |
902 | |
903 *x = tx * aud_active_skin->properties.textbox_bitmap_font_width; | |
904 *y = ty * aud_active_skin->properties.textbox_bitmap_font_height; | |
905 } | |
906 | |
907 void ui_skinned_textbox_move_relative(GtkWidget *widget, gint x, gint y) { | |
2698
32e99af83a3e
I don't think redraw signal is needed anymore
Tomasz Mon <desowin@gmail.com>
parents:
2635
diff
changeset
|
908 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); |
2586 | 909 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(widget); |
910 priv->move_x += x; | |
911 priv->move_y += y; | |
2698
32e99af83a3e
I don't think redraw signal is needed anymore
Tomasz Mon <desowin@gmail.com>
parents:
2635
diff
changeset
|
912 gtk_fixed_move(GTK_FIXED(gtk_widget_get_parent(widget)), widget, |
32e99af83a3e
I don't think redraw signal is needed anymore
Tomasz Mon <desowin@gmail.com>
parents:
2635
diff
changeset
|
913 textbox->x+priv->move_x, textbox->y+priv->move_y); |
2586 | 914 } |