Mercurial > audlegacy
annotate src/audacious/ui_skinned_textbox.c @ 2965:f84d09bada0f trunk
correct _move_relative() and _resize_relative()
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Mon, 02 Jul 2007 11:18:25 +0200 |
parents | ba45ef731cf1 |
children | dd4a213bab66 |
rev | line source |
---|---|
2911 | 1 /* |
2 * Audacious - a cross-platform multimedia player | |
3 * Copyright (c) 2007 Audacious development team. | |
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 | |
2918
4e71092ab29b
remove evil GPL3 upgrade phrase
Tomasz Mon <desowin@gmail.com>
parents:
2917
diff
changeset
|
13 * the Free Software Foundation; under version 2 of the License. |
2911 | 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, write to the Free Software | |
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
23 */ | |
24 | |
25 #include "widgets/widgetcore.h" | |
26 #include "ui_skinned_textbox.h" | |
27 #include "main.h" | |
28 #include "util.h" | |
29 #include "strings.h" | |
30 #include <string.h> | |
31 #include <ctype.h> | |
32 #include <gtk/gtkmain.h> | |
33 #include <gtk/gtkmarshal.h> | |
34 #include <gtk/gtkimage.h> | |
35 | |
36 #define UI_SKINNED_TEXTBOX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UI_TYPE_SKINNED_TEXTBOX, UiSkinnedTextboxPrivate)) | |
37 typedef struct _UiSkinnedTextboxPrivate UiSkinnedTextboxPrivate; | |
38 | |
2965
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
39 static GMutex *mutex = NULL; |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
40 |
2911 | 41 enum { |
2942
1a59a0ced6a8
make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
Tomasz Mon <desowin@gmail.com>
parents:
2920
diff
changeset
|
42 CLICKED, |
2911 | 43 DOUBLE_CLICKED, |
44 RIGHT_CLICKED, | |
45 DOUBLED, | |
46 REDRAW, | |
47 LAST_SIGNAL | |
48 }; | |
49 | |
50 struct _UiSkinnedTextboxPrivate { | |
51 GtkWidget *image; | |
52 GdkGC *gc; | |
53 SkinPixmapId skin_index; | |
54 GtkWidget *fixed; | |
55 gboolean double_size; | |
56 gboolean scroll_back; | |
57 gint nominal_y, nominal_height; | |
58 gint scroll_timeout; | |
59 gint font_ascent, font_descent; | |
60 PangoFontDescription *font; | |
61 gchar *fontname; | |
62 gchar *pixmap_text; | |
63 gint skin_id; | |
64 gint drag_x, drag_off, offset; | |
65 gboolean is_scrollable, is_dragging; | |
66 gint pixmap_width; | |
67 GdkPixmap *pixmap; | |
68 gboolean scroll_allowed, scroll_enabled; | |
2948
830fdbec31be
introduce scroll_dummy to stop scrolling when it reaches end
Tomasz Mon <desowin@gmail.com>
parents:
2947
diff
changeset
|
69 gint scroll_dummy; |
2965
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
70 gint resize_width, resize_height; |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
71 gint move_x, move_y; |
2911 | 72 }; |
73 | |
74 | |
75 static GtkBinClass *parent_class = NULL; | |
76 static void ui_skinned_textbox_class_init(UiSkinnedTextboxClass *klass); | |
77 static void ui_skinned_textbox_init(UiSkinnedTextbox *textbox); | |
78 static GObject* ui_skinned_textbox_constructor(GType type, guint n_construct_properties, GObjectConstructParam *construct_params); | |
79 static void ui_skinned_textbox_destroy(GtkObject *object); | |
80 static void ui_skinned_textbox_realize(GtkWidget *widget); | |
81 static void ui_skinned_textbox_unrealize(GtkWidget *widget); | |
82 static void ui_skinned_textbox_map(GtkWidget *widget); | |
83 static void ui_skinned_textbox_unmap(GtkWidget *widget); | |
84 static gint ui_skinned_textbox_expose(GtkWidget *widget,GdkEventExpose *event); | |
85 | |
86 static void ui_skinned_textbox_size_allocate(GtkWidget *widget, GtkAllocation *allocation); | |
87 | |
88 static guint textbox_signals[LAST_SIGNAL] = { 0 }; | |
89 static gint ui_skinned_textbox_textbox_press(GtkWidget *widget, GdkEventButton *event); | |
90 static gint ui_skinned_textbox_textbox_release(GtkWidget *widget, GdkEventButton *event); | |
91 | |
92 static void ui_skinned_textbox_add(GtkContainer *container, GtkWidget *widget); | |
93 static void ui_skinned_textbox_toggle_doublesize(UiSkinnedTextbox *textbox); | |
94 | |
95 static gint ui_skinned_textbox_motion_notify(GtkWidget *widget, GdkEventMotion *event); | |
96 static void ui_skinned_textbox_paint(UiSkinnedTextbox *textbox); | |
97 static void ui_skinned_textbox_redraw(UiSkinnedTextbox *textbox); | |
98 static gboolean ui_skinned_textbox_should_scroll(UiSkinnedTextbox *textbox); | |
99 static void textbox_generate_xfont_pixmap(UiSkinnedTextbox *textbox, const gchar *pixmaptext); | |
100 static void textbox_generate_pixmap(UiSkinnedTextbox *textbox); | |
101 static void textbox_handle_special_char(gchar c, gint * x, gint * y); | |
102 | |
103 GType ui_skinned_textbox_get_type (void) { | |
104 static GType textbox_type = 0; | |
105 | |
106 if (!textbox_type) { | |
107 static const GTypeInfo textbox_info = { | |
108 sizeof (UiSkinnedTextboxClass), | |
109 NULL, /* base_init */ | |
110 NULL, /* base_finalize */ | |
111 (GClassInitFunc) ui_skinned_textbox_class_init, | |
112 NULL, /* class_finalize */ | |
113 NULL, /* class_data */ | |
114 sizeof (UiSkinnedTextbox), | |
115 16, /* n_preallocs */ | |
116 (GInstanceInitFunc) ui_skinned_textbox_init, | |
117 }; | |
118 | |
119 textbox_type = g_type_register_static (GTK_TYPE_BIN, "UiSkinnedTextbox", &textbox_info, 0); | |
120 } | |
121 return textbox_type; | |
122 } | |
123 | |
124 static void ui_skinned_textbox_class_init (UiSkinnedTextboxClass *klass) { | |
125 GObjectClass *gobject_class; | |
126 GtkObjectClass *object_class; | |
127 GtkWidgetClass *widget_class; | |
128 GtkContainerClass *container_class; | |
129 | |
130 gobject_class = G_OBJECT_CLASS(klass); | |
131 object_class = (GtkObjectClass*)klass; | |
132 widget_class = (GtkWidgetClass*)klass; | |
133 container_class = (GtkContainerClass*)klass; | |
134 | |
135 parent_class = g_type_class_peek_parent(klass); | |
136 gobject_class->constructor = ui_skinned_textbox_constructor; | |
137 object_class->destroy = ui_skinned_textbox_destroy; | |
138 | |
139 widget_class->realize = ui_skinned_textbox_realize; | |
140 widget_class->unrealize = ui_skinned_textbox_unrealize; | |
141 widget_class->map = ui_skinned_textbox_map; | |
142 widget_class->unmap = ui_skinned_textbox_unmap; | |
143 widget_class->size_allocate = ui_skinned_textbox_size_allocate; | |
144 widget_class->expose_event = ui_skinned_textbox_expose; | |
145 widget_class->button_press_event = ui_skinned_textbox_textbox_press; | |
146 widget_class->button_release_event = ui_skinned_textbox_textbox_release; | |
147 widget_class->motion_notify_event = ui_skinned_textbox_motion_notify; | |
148 | |
149 container_class->add = ui_skinned_textbox_add; | |
150 | |
2942
1a59a0ced6a8
make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
Tomasz Mon <desowin@gmail.com>
parents:
2920
diff
changeset
|
151 klass->clicked = NULL; |
2911 | 152 klass->double_clicked = NULL; |
153 klass->right_clicked = NULL; | |
154 klass->doubled = ui_skinned_textbox_toggle_doublesize; | |
155 klass->redraw = ui_skinned_textbox_redraw; | |
156 | |
2942
1a59a0ced6a8
make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
Tomasz Mon <desowin@gmail.com>
parents:
2920
diff
changeset
|
157 textbox_signals[CLICKED] = |
1a59a0ced6a8
make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
Tomasz Mon <desowin@gmail.com>
parents:
2920
diff
changeset
|
158 g_signal_new ("clicked", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, |
1a59a0ced6a8
make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
Tomasz Mon <desowin@gmail.com>
parents:
2920
diff
changeset
|
159 G_STRUCT_OFFSET (UiSkinnedTextboxClass, clicked), NULL, NULL, |
1a59a0ced6a8
make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
Tomasz Mon <desowin@gmail.com>
parents:
2920
diff
changeset
|
160 gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); |
1a59a0ced6a8
make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
Tomasz Mon <desowin@gmail.com>
parents:
2920
diff
changeset
|
161 |
2911 | 162 textbox_signals[DOUBLE_CLICKED] = |
163 g_signal_new ("double-clicked", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
164 G_STRUCT_OFFSET (UiSkinnedTextboxClass, double_clicked), NULL, NULL, | |
165 gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); | |
166 | |
167 textbox_signals[RIGHT_CLICKED] = | |
168 g_signal_new ("right-clicked", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
169 G_STRUCT_OFFSET (UiSkinnedTextboxClass, right_clicked), NULL, NULL, | |
170 gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); | |
171 | |
172 textbox_signals[DOUBLED] = | |
173 g_signal_new ("toggle-double-size", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
174 G_STRUCT_OFFSET (UiSkinnedTextboxClass, doubled), NULL, NULL, | |
175 gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); | |
176 | |
177 textbox_signals[REDRAW] = | |
178 g_signal_new ("redraw", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
179 G_STRUCT_OFFSET (UiSkinnedTextboxClass, redraw), NULL, NULL, | |
180 gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); | |
181 | |
182 g_type_class_add_private (gobject_class, sizeof (UiSkinnedTextboxPrivate)); | |
183 } | |
184 | |
185 static void ui_skinned_textbox_init (UiSkinnedTextbox *textbox) { | |
186 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); | |
2965
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
187 mutex = g_mutex_new(); |
2911 | 188 priv->image = gtk_image_new(); |
2965
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
189 priv->resize_width = 0; |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
190 priv->resize_height = 0; |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
191 priv->move_x = 0; |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
192 priv->move_y = 0; |
2911 | 193 textbox->redraw = TRUE; |
194 | |
195 g_object_set (priv->image, "visible", TRUE, NULL); | |
196 gtk_container_add(GTK_CONTAINER(GTK_WIDGET(textbox)), priv->image); | |
197 | |
198 GTK_WIDGET_SET_FLAGS (textbox, GTK_NO_WINDOW); | |
199 } | |
200 | |
201 static void ui_skinned_textbox_destroy (GtkObject *object) { | |
202 (*GTK_OBJECT_CLASS (parent_class)->destroy) (object); | |
203 } | |
204 | |
205 static GObject* ui_skinned_textbox_constructor(GType type, guint n_construct_properties, GObjectConstructParam *construct_params) { | |
206 GObject *object = (*G_OBJECT_CLASS (parent_class)->constructor)(type, n_construct_properties, construct_params); | |
207 | |
208 return object; | |
209 } | |
210 | |
211 static void ui_skinned_textbox_realize (GtkWidget *widget) { | |
212 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); | |
213 GdkWindowAttr attrib; | |
214 | |
215 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); | |
216 | |
217 attrib.window_type = GDK_WINDOW_CHILD; | |
218 attrib.x = widget->allocation.x; | |
219 attrib.y = widget->allocation.y; | |
220 attrib.width = widget->allocation.width; | |
221 attrib.height = widget->allocation.height; | |
222 attrib.wclass = GDK_INPUT_ONLY; | |
223 attrib.event_mask = gtk_widget_get_events (widget); | |
224 attrib.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_RELEASE_MASK); | |
225 | |
226 widget->window = gtk_widget_get_parent_window(widget); | |
227 g_object_ref(widget->window); | |
228 | |
229 textbox->event_window = gdk_window_new(gtk_widget_get_parent_window(widget), &attrib, GDK_WA_X | GDK_WA_Y); | |
230 gdk_window_set_user_data (textbox->event_window, textbox); | |
231 } | |
232 | |
233 static void ui_skinned_textbox_unrealize(GtkWidget *widget) { | |
234 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); | |
235 | |
236 if (textbox->event_window) { | |
237 gdk_window_set_user_data (textbox->event_window, NULL); | |
238 gdk_window_destroy (textbox->event_window); | |
239 textbox->event_window = NULL; | |
240 } | |
241 | |
242 GTK_WIDGET_CLASS (parent_class)->unrealize (widget); | |
243 } | |
244 | |
245 static void ui_skinned_textbox_map(GtkWidget *widget) { | |
246 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); | |
247 g_return_if_fail (UI_IS_SKINNED_TEXTBOX (widget)); | |
248 GTK_WIDGET_CLASS (parent_class)->map(widget); | |
249 gdk_window_show (textbox->event_window); | |
250 } | |
251 | |
252 static void ui_skinned_textbox_unmap (GtkWidget *widget) { | |
253 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); | |
254 g_return_if_fail (UI_IS_SKINNED_TEXTBOX(widget)); | |
255 | |
256 if (textbox->event_window) | |
257 gdk_window_hide (textbox->event_window); | |
258 | |
259 GTK_WIDGET_CLASS (parent_class)->unmap (widget); | |
260 } | |
261 | |
262 static gboolean ui_skinned_textbox_expose(GtkWidget *widget, GdkEventExpose *event) { | |
2962
ba45ef731cf1
don't call ui_skinned_textbox_paint() directly, use gtk_widget_queue_draw() instead; fix ui_skinned_textbox_expose()
Tomasz Mon <desowin@gmail.com>
parents:
2961
diff
changeset
|
263 if (GTK_WIDGET_DRAWABLE (widget)) { |
ba45ef731cf1
don't call ui_skinned_textbox_paint() directly, use gtk_widget_queue_draw() instead; fix ui_skinned_textbox_expose()
Tomasz Mon <desowin@gmail.com>
parents:
2961
diff
changeset
|
264 ui_skinned_textbox_paint(UI_SKINNED_TEXTBOX(widget)); |
2911 | 265 (*GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event); |
2962
ba45ef731cf1
don't call ui_skinned_textbox_paint() directly, use gtk_widget_queue_draw() instead; fix ui_skinned_textbox_expose()
Tomasz Mon <desowin@gmail.com>
parents:
2961
diff
changeset
|
266 } |
2911 | 267 |
268 return FALSE; | |
269 } | |
270 | |
271 GtkWidget* ui_skinned_textbox_new () { | |
272 return g_object_new (UI_TYPE_SKINNED_TEXTBOX, NULL); | |
273 } | |
274 | |
275 void ui_skinned_textbox_setup(GtkWidget *widget, GtkWidget *fixed,GdkPixmap * parent, GdkGC * gc, gint x, gint y, gint w, gboolean allow_scroll, SkinPixmapId si) { | |
276 | |
277 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); | |
278 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
279 textbox->height = bmp_active_skin->properties.textbox_bitmap_font_height; | |
280 textbox->x = x; | |
281 textbox->y = y; | |
2957
c859aa1a1a4e
don't update text if it haven't changed
Tomasz Mon <desowin@gmail.com>
parents:
2956
diff
changeset
|
282 textbox->text = g_strdup(""); |
2911 | 283 priv->gc = gc; |
2947 | 284 textbox->width = w; |
2911 | 285 priv->scroll_allowed = allow_scroll; |
286 priv->scroll_enabled = TRUE; | |
287 priv->skin_index = si; | |
288 priv->nominal_y = y; | |
289 priv->nominal_height = textbox->height; | |
290 priv->scroll_timeout = 0; | |
2948
830fdbec31be
introduce scroll_dummy to stop scrolling when it reaches end
Tomasz Mon <desowin@gmail.com>
parents:
2947
diff
changeset
|
291 priv->scroll_dummy = 0; |
2911 | 292 |
293 priv->fixed = fixed; | |
294 priv->double_size = FALSE; | |
295 | |
2947 | 296 gtk_widget_set_size_request(widget, textbox->width, textbox->height); |
2911 | 297 gtk_fixed_put(GTK_FIXED(priv->fixed), widget, textbox->x, textbox->y); |
298 } | |
299 | |
300 static void ui_skinned_textbox_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { | |
2965
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
301 g_mutex_lock(mutex); |
2911 | 302 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); |
303 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); | |
304 GtkAllocation child_alloc; | |
305 | |
306 widget->allocation = *allocation; | |
307 if (GTK_BIN (textbox)->child) { //image should fill whole widget | |
308 child_alloc.x = widget->allocation.x; | |
309 child_alloc.y = widget->allocation.y; | |
310 child_alloc.width = MAX (1, widget->allocation.width); | |
311 child_alloc.height = MAX (1, widget->allocation.height); | |
312 | |
313 gtk_widget_size_allocate (GTK_BIN (textbox)->child, &child_alloc); | |
314 } | |
315 | |
316 if (GDK_IS_WINDOW(textbox->event_window)) | |
317 gdk_window_move_resize (textbox->event_window, widget->allocation.x, widget->allocation.y, | |
318 widget->allocation.width, widget->allocation.height); | |
319 | |
320 textbox->x = widget->allocation.x/(priv->double_size ? 2 : 1); | |
321 textbox->y = widget->allocation.y/(priv->double_size ? 2 : 1); | |
2965
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
322 priv->move_x = 0; |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
323 priv->move_y = 0; |
2919 | 324 |
2965
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
325 if (textbox->width != widget->allocation.width) { |
2947 | 326 textbox->width = widget->allocation.width; |
2965
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
327 priv->resize_width = 0; |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
328 priv->resize_height = 0; |
2919 | 329 if (priv->pixmap_text) g_free(priv->pixmap_text); |
330 priv->pixmap_text = NULL; | |
331 priv->offset = 0; | |
2965
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
332 textbox->redraw = TRUE; |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
333 gtk_widget_queue_draw(GTK_WIDGET(textbox)); |
2919 | 334 } |
2965
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
335 g_mutex_unlock(mutex); |
2911 | 336 } |
337 | |
338 static gboolean ui_skinned_textbox_textbox_press(GtkWidget *widget, GdkEventButton *event) { | |
339 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); | |
340 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); | |
341 | |
342 if (event->type == GDK_BUTTON_PRESS) { | |
343 textbox = UI_SKINNED_TEXTBOX(widget); | |
344 | |
345 if (event->button == 1) { | |
2942
1a59a0ced6a8
make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
Tomasz Mon <desowin@gmail.com>
parents:
2920
diff
changeset
|
346 if (priv->scroll_allowed) { |
2947 | 347 if ((priv->pixmap_width > textbox->width) && priv->is_scrollable) { |
2942
1a59a0ced6a8
make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
Tomasz Mon <desowin@gmail.com>
parents:
2920
diff
changeset
|
348 priv->is_dragging = TRUE; |
1a59a0ced6a8
make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
Tomasz Mon <desowin@gmail.com>
parents:
2920
diff
changeset
|
349 textbox->redraw = TRUE; |
1a59a0ced6a8
make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
Tomasz Mon <desowin@gmail.com>
parents:
2920
diff
changeset
|
350 priv->drag_off = priv->offset; |
1a59a0ced6a8
make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
Tomasz Mon <desowin@gmail.com>
parents:
2920
diff
changeset
|
351 priv->drag_x = event->x; |
1a59a0ced6a8
make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
Tomasz Mon <desowin@gmail.com>
parents:
2920
diff
changeset
|
352 } |
1a59a0ced6a8
make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
Tomasz Mon <desowin@gmail.com>
parents:
2920
diff
changeset
|
353 } else |
1a59a0ced6a8
make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
Tomasz Mon <desowin@gmail.com>
parents:
2920
diff
changeset
|
354 g_signal_emit(widget, textbox_signals[CLICKED], 0); |
1a59a0ced6a8
make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
Tomasz Mon <desowin@gmail.com>
parents:
2920
diff
changeset
|
355 |
2911 | 356 } else if (event->button == 3) { |
357 g_signal_emit(widget, textbox_signals[RIGHT_CLICKED], 0); | |
358 } | |
359 } else if (event->type == GDK_2BUTTON_PRESS) { | |
360 if (event->button == 1) { | |
361 g_signal_emit(widget, textbox_signals[DOUBLE_CLICKED], 0); | |
362 } | |
363 } | |
364 return TRUE; | |
365 } | |
366 | |
367 static gboolean ui_skinned_textbox_textbox_release(GtkWidget *widget, GdkEventButton *event) { | |
368 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); | |
369 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); | |
370 if (event->button == 1) { | |
371 priv->is_dragging = FALSE; | |
372 textbox->redraw = TRUE; | |
373 } | |
374 | |
375 return TRUE; | |
376 } | |
377 | |
378 static gboolean ui_skinned_textbox_motion_notify(GtkWidget *widget, GdkEventMotion *event) { | |
379 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); | |
380 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); | |
381 | |
382 if (priv->is_dragging) { | |
383 if (priv->scroll_allowed && | |
2947 | 384 priv->pixmap_width > textbox->width) { |
2911 | 385 priv->offset = priv->drag_off - (event->x - priv->drag_x); |
386 | |
387 while (priv->offset < 0) | |
2917 | 388 priv->offset = 0; |
2911 | 389 |
2947 | 390 while (priv->offset > (priv->pixmap_width - textbox->width)) |
391 priv->offset = (priv->pixmap_width - textbox->width); | |
2911 | 392 |
2965
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
393 textbox->redraw = TRUE; |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
394 gtk_widget_queue_draw(widget); |
2911 | 395 } |
396 } | |
397 | |
398 return FALSE; | |
399 } | |
400 | |
401 static void ui_skinned_textbox_add(GtkContainer *container, GtkWidget *widget) { | |
402 GTK_CONTAINER_CLASS (parent_class)->add(container, widget); | |
403 } | |
404 | |
405 static void ui_skinned_textbox_toggle_doublesize(UiSkinnedTextbox *textbox) { | |
406 GtkWidget *widget = GTK_WIDGET (textbox); | |
407 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); | |
408 priv->double_size = !priv->double_size; | |
409 | |
2947 | 410 gtk_widget_set_size_request(widget, textbox->width*(1+priv->double_size), textbox->height*(1+priv->double_size)); |
2911 | 411 gtk_widget_set_uposition(widget, textbox->x*(1+priv->double_size), textbox->y*(1+priv->double_size)); |
412 | |
413 textbox->redraw = TRUE; | |
2962
ba45ef731cf1
don't call ui_skinned_textbox_paint() directly, use gtk_widget_queue_draw() instead; fix ui_skinned_textbox_expose()
Tomasz Mon <desowin@gmail.com>
parents:
2961
diff
changeset
|
414 gtk_widget_queue_draw(GTK_WIDGET(textbox)); |
2911 | 415 } |
416 | |
417 static void ui_skinned_textbox_paint(UiSkinnedTextbox *textbox) { | |
418 GtkWidget *widget = GTK_WIDGET (textbox); | |
419 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); | |
420 | |
421 if (textbox->redraw == TRUE) { | |
422 textbox->redraw = FALSE; | |
423 gint cw; | |
424 GdkPixmap *obj; | |
425 | |
426 if (textbox->text && (!priv->pixmap_text || strcmp(textbox->text, priv->pixmap_text))) | |
427 textbox_generate_pixmap(textbox); | |
428 | |
429 if (priv->pixmap) { | |
430 if (skin_get_id() != priv->skin_id) { | |
431 priv->skin_id = skin_get_id(); | |
432 textbox_generate_pixmap(textbox); | |
433 } | |
2947 | 434 obj = gdk_pixmap_new(NULL, textbox->width, textbox->height, gdk_rgb_get_visual()->depth); |
2911 | 435 |
436 cw = priv->pixmap_width - priv->offset; | |
2947 | 437 if (cw > textbox->width) |
438 cw = textbox->width; | |
2958
afc8f8c21e75
use priv->pixmap instead of src
Tomasz Mon <desowin@gmail.com>
parents:
2957
diff
changeset
|
439 gdk_draw_drawable(obj, priv->gc, priv->pixmap, priv->offset, 0, 0, 0, cw, textbox->height); |
2947 | 440 if (cw < textbox->width) |
2958
afc8f8c21e75
use priv->pixmap instead of src
Tomasz Mon <desowin@gmail.com>
parents:
2957
diff
changeset
|
441 gdk_draw_drawable(obj, priv->gc, priv->pixmap, 0, 0, |
2911 | 442 textbox->x + cw, textbox->y, |
2947 | 443 textbox->width - cw, textbox->height); |
2911 | 444 |
445 if (priv->double_size) { | |
446 GdkImage *img, *img2x; | |
2947 | 447 img = gdk_drawable_get_image(obj, 0, 0, textbox->width, textbox->height); |
2911 | 448 img2x = create_dblsize_image(img); |
449 gtk_image_set(GTK_IMAGE(priv->image), img2x, NULL); | |
450 g_object_unref(img2x); | |
451 g_object_unref(img); | |
452 } else | |
453 gtk_image_set_from_pixmap(GTK_IMAGE(priv->image), obj, NULL); | |
454 | |
455 g_object_unref(obj); | |
456 gtk_widget_queue_resize(widget); | |
457 } | |
458 } | |
459 } | |
460 | |
461 static void ui_skinned_textbox_redraw(UiSkinnedTextbox *textbox) { | |
2965
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
462 g_mutex_lock(mutex); |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
463 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
464 if (priv->resize_width || priv->resize_height) |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
465 gtk_widget_set_size_request(GTK_WIDGET(textbox), |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
466 (textbox->width+priv->resize_width)*(1+priv->double_size), |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
467 (textbox->height+priv->resize_height)*(1+priv->double_size)); |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
468 if (priv->move_x || priv->move_y) |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
469 gtk_fixed_move(GTK_FIXED(priv->fixed), GTK_WIDGET(textbox), textbox->x+priv->move_x, textbox->y+priv->move_y); |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
470 |
2911 | 471 textbox->redraw = TRUE; |
2962
ba45ef731cf1
don't call ui_skinned_textbox_paint() directly, use gtk_widget_queue_draw() instead; fix ui_skinned_textbox_expose()
Tomasz Mon <desowin@gmail.com>
parents:
2961
diff
changeset
|
472 gtk_widget_queue_draw(GTK_WIDGET(textbox)); |
2965
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
473 g_mutex_unlock(mutex); |
2911 | 474 } |
475 | |
476 static gboolean ui_skinned_textbox_should_scroll(UiSkinnedTextbox *textbox) { | |
477 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); | |
478 if (!priv->scroll_allowed) | |
479 return FALSE; | |
480 | |
481 if (priv->font) { | |
482 gint width; | |
483 text_get_extents(priv->fontname, textbox->text, &width, NULL, NULL, NULL); | |
484 | |
2947 | 485 if (width <= textbox->width) |
2911 | 486 return FALSE; |
487 else | |
488 return TRUE; | |
489 } | |
490 | |
2947 | 491 if (g_utf8_strlen(textbox->text, -1) * bmp_active_skin->properties.textbox_bitmap_font_width > textbox->width) |
2911 | 492 return TRUE; |
493 | |
494 return FALSE; | |
495 } | |
496 | |
497 void ui_skinned_textbox_set_xfont(GtkWidget *widget, gboolean use_xfont, const gchar * fontname) { | |
498 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); | |
499 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); | |
500 gint ascent, descent; | |
501 | |
502 g_return_if_fail(textbox != NULL); | |
503 | |
504 if (priv->font) { | |
505 pango_font_description_free(priv->font); | |
506 priv->font = NULL; | |
507 } | |
508 | |
509 textbox->y = priv->nominal_y; | |
510 textbox->height = priv->nominal_height; | |
511 | |
512 /* Make sure the pixmap is regenerated */ | |
513 if (priv->pixmap_text) { | |
514 g_free(priv->pixmap_text); | |
515 priv->pixmap_text = NULL; | |
516 } | |
517 | |
518 if (!use_xfont || strlen(fontname) == 0) | |
519 return; | |
520 | |
521 priv->font = pango_font_description_from_string(fontname); | |
522 priv->fontname = g_strdup(fontname); | |
523 | |
524 text_get_extents(fontname, | |
525 "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz ", | |
526 NULL, NULL, &ascent, &descent); | |
527 priv->font_ascent = ascent; | |
528 priv->font_descent = descent; | |
529 | |
530 | |
531 if (priv->font == NULL) | |
532 return; | |
533 | |
534 textbox->height = priv->font_ascent; | |
535 if (textbox->height > priv->nominal_height) | |
536 textbox->y -= (textbox->height - priv->nominal_height) / 2; | |
537 else | |
538 textbox->height = priv->nominal_height; | |
539 } | |
540 | |
541 void ui_skinned_textbox_set_text(GtkWidget *widget, const gchar *text) { | |
542 g_return_if_fail(text != NULL); | |
543 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); | |
544 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); | |
545 | |
2957
c859aa1a1a4e
don't update text if it haven't changed
Tomasz Mon <desowin@gmail.com>
parents:
2956
diff
changeset
|
546 if (!strcmp(textbox->text, text)) |
c859aa1a1a4e
don't update text if it haven't changed
Tomasz Mon <desowin@gmail.com>
parents:
2956
diff
changeset
|
547 return; |
2951
4586c0951eab
Handle multibyte sequences properly when encountered.
William Pitcock <nenolod@atheme-project.org>
parents:
2949
diff
changeset
|
548 if (textbox->text) |
2911 | 549 g_free(textbox->text); |
550 | |
2952
cb15e12b6352
Preserve capitalization for xfont users.
William Pitcock <nenolod@atheme-project.org>
parents:
2951
diff
changeset
|
551 textbox->text = str_to_utf8(text); |
2911 | 552 priv->scroll_back = FALSE; |
2960
aeb8b690c92b
don't update UiSkinnedTextbox just after ui_skinned_textbox_set_text; results in not automatically updated textboxes, but it gets rid of gui hangs
Tomasz Mon <desowin@gmail.com>
parents:
2958
diff
changeset
|
553 textbox->redraw = TRUE; |
2961
dd53d2d49b79
Use gtk_widget_queue_draw() instead of forcing a draw operation which can be an X protocol violation.
William Pitcock <nenolod@atheme-project.org>
parents:
2960
diff
changeset
|
554 gtk_widget_queue_draw(GTK_WIDGET(textbox)); |
2911 | 555 } |
556 | |
557 static void textbox_generate_xfont_pixmap(UiSkinnedTextbox *textbox, const gchar *pixmaptext) { | |
558 gint length, i; | |
559 GdkGC *gc, *maskgc; | |
560 GdkColor *c, pattern; | |
561 GdkBitmap *mask; | |
562 PangoLayout *layout; | |
563 gint width; | |
564 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); | |
565 | |
566 g_return_if_fail(textbox != NULL); | |
567 g_return_if_fail(pixmaptext != NULL); | |
568 | |
569 length = g_utf8_strlen(pixmaptext, -1); | |
570 | |
571 text_get_extents(priv->fontname, pixmaptext, &width, NULL, NULL, NULL); | |
572 | |
2947 | 573 priv->pixmap_width = MAX(width, textbox->width); |
2911 | 574 priv->pixmap = gdk_pixmap_new(mainwin->window, priv->pixmap_width, |
575 textbox->height, | |
576 gdk_rgb_get_visual()->depth); | |
577 gc = priv->gc; | |
578 c = skin_get_color(bmp_active_skin, SKIN_TEXTBG); | |
579 for (i = 0; i < textbox->height; i++) { | |
580 gdk_gc_set_foreground(gc, &c[6 * i / textbox->height]); | |
2920
5a94507f507e
fix textbox_generate_xfont_pixmap
Tomasz Mon <desowin@gmail.com>
parents:
2919
diff
changeset
|
581 gdk_draw_line(priv->pixmap, gc, 0, i, priv->pixmap_width, i); |
2911 | 582 } |
583 | |
584 mask = gdk_pixmap_new(mainwin->window, priv->pixmap_width, textbox->height, 1); | |
585 maskgc = gdk_gc_new(mask); | |
586 pattern.pixel = 0; | |
587 gdk_gc_set_foreground(maskgc, &pattern); | |
588 | |
589 gdk_draw_rectangle(mask, maskgc, TRUE, 0, 0, priv->pixmap_width, textbox->height); | |
590 pattern.pixel = 1; | |
591 gdk_gc_set_foreground(maskgc, &pattern); | |
592 | |
593 gdk_gc_set_foreground(gc, skin_get_color(bmp_active_skin, SKIN_TEXTFG)); | |
594 | |
595 layout = gtk_widget_create_pango_layout(mainwin, pixmaptext); | |
596 pango_layout_set_font_description(layout, priv->font); | |
597 | |
598 gdk_draw_layout(priv->pixmap, gc, 0, (priv->font_descent / 2), layout); | |
599 g_object_unref(layout); | |
600 | |
601 g_object_unref(maskgc); | |
602 | |
603 gdk_gc_set_clip_mask(gc, mask); | |
604 c = skin_get_color(bmp_active_skin, SKIN_TEXTFG); | |
605 for (i = 0; i < textbox->height; i++) { | |
606 gdk_gc_set_foreground(gc, &c[6 * i / textbox->height]); | |
607 gdk_draw_line(priv->pixmap, gc, 0, i, priv->pixmap_width, i); | |
608 } | |
609 g_object_unref(mask); | |
610 gdk_gc_set_clip_mask(gc, NULL); | |
611 } | |
612 | |
613 static gboolean textbox_scroll(gpointer data) { | |
614 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(data); | |
615 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (data); | |
616 | |
617 if (!priv->is_dragging) { | |
2948
830fdbec31be
introduce scroll_dummy to stop scrolling when it reaches end
Tomasz Mon <desowin@gmail.com>
parents:
2947
diff
changeset
|
618 if (priv->scroll_dummy < TEXTBOX_SCROLL_WAIT) priv->scroll_dummy++; |
830fdbec31be
introduce scroll_dummy to stop scrolling when it reaches end
Tomasz Mon <desowin@gmail.com>
parents:
2947
diff
changeset
|
619 else { |
830fdbec31be
introduce scroll_dummy to stop scrolling when it reaches end
Tomasz Mon <desowin@gmail.com>
parents:
2947
diff
changeset
|
620 if (priv->scroll_back) priv->offset -= 1; |
830fdbec31be
introduce scroll_dummy to stop scrolling when it reaches end
Tomasz Mon <desowin@gmail.com>
parents:
2947
diff
changeset
|
621 else priv->offset += 1; |
2911 | 622 |
2948
830fdbec31be
introduce scroll_dummy to stop scrolling when it reaches end
Tomasz Mon <desowin@gmail.com>
parents:
2947
diff
changeset
|
623 if (priv->offset >= (priv->pixmap_width - textbox->width)) { |
830fdbec31be
introduce scroll_dummy to stop scrolling when it reaches end
Tomasz Mon <desowin@gmail.com>
parents:
2947
diff
changeset
|
624 priv->scroll_back = TRUE; |
830fdbec31be
introduce scroll_dummy to stop scrolling when it reaches end
Tomasz Mon <desowin@gmail.com>
parents:
2947
diff
changeset
|
625 priv->scroll_dummy = 0; |
830fdbec31be
introduce scroll_dummy to stop scrolling when it reaches end
Tomasz Mon <desowin@gmail.com>
parents:
2947
diff
changeset
|
626 } |
830fdbec31be
introduce scroll_dummy to stop scrolling when it reaches end
Tomasz Mon <desowin@gmail.com>
parents:
2947
diff
changeset
|
627 if (priv->offset <= 0) { |
830fdbec31be
introduce scroll_dummy to stop scrolling when it reaches end
Tomasz Mon <desowin@gmail.com>
parents:
2947
diff
changeset
|
628 priv->scroll_back = FALSE; |
830fdbec31be
introduce scroll_dummy to stop scrolling when it reaches end
Tomasz Mon <desowin@gmail.com>
parents:
2947
diff
changeset
|
629 priv->scroll_dummy = 0; |
830fdbec31be
introduce scroll_dummy to stop scrolling when it reaches end
Tomasz Mon <desowin@gmail.com>
parents:
2947
diff
changeset
|
630 } |
2965
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
631 textbox->redraw = TRUE; |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
632 gtk_widget_queue_draw(GTK_WIDGET(textbox)); |
2942
1a59a0ced6a8
make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
Tomasz Mon <desowin@gmail.com>
parents:
2920
diff
changeset
|
633 } |
2911 | 634 } |
635 return TRUE; | |
636 } | |
637 | |
638 static void textbox_generate_pixmap(UiSkinnedTextbox *textbox) { | |
639 gint length, i, x, y, wl; | |
640 gchar *pixmaptext; | |
2953
80b6fc3f4d29
Fix invalid free.
William Pitcock <nenolod@atheme-project.org>
parents:
2952
diff
changeset
|
641 gchar *tmp, *stxt; |
2911 | 642 GdkGC *gc; |
643 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); | |
644 g_return_if_fail(textbox != NULL); | |
645 | |
646 if (priv->pixmap) { | |
647 g_object_unref(priv->pixmap); | |
648 priv->pixmap = NULL; | |
649 } | |
650 | |
651 /* | |
652 * Don't reset the offset if only text after the last '(' has | |
653 * changed. This is a hack to avoid visual noice on vbr files | |
654 * where we guess the length. | |
655 */ | |
656 if (!(priv->pixmap_text && strrchr(textbox->text, '(') && | |
657 !strncmp(priv->pixmap_text, textbox->text, | |
658 strrchr(textbox->text, '(') - textbox->text))) | |
659 priv->offset = 0; | |
660 | |
661 g_free(priv->pixmap_text); | |
662 priv->pixmap_text = g_strdup(textbox->text); | |
663 | |
664 /* | |
665 * wl is the number of (partial) letters visible. Only makes | |
666 * sense when using skinned font. | |
667 */ | |
2947 | 668 wl = textbox->width / 5; |
669 if (wl * 5 != textbox->width) | |
2911 | 670 wl++; |
671 | |
672 length = g_utf8_strlen(textbox->text, -1); | |
673 | |
674 priv->is_scrollable = FALSE; | |
675 | |
676 priv->is_scrollable = ui_skinned_textbox_should_scroll(textbox); | |
2916
3ef909ed3056
fix clearing textbox when short text is displayed
Tomasz Mon <desowin@gmail.com>
parents:
2913
diff
changeset
|
677 |
3ef909ed3056
fix clearing textbox when short text is displayed
Tomasz Mon <desowin@gmail.com>
parents:
2913
diff
changeset
|
678 if (!priv->is_scrollable && !priv->font && length <= wl) { |
3ef909ed3056
fix clearing textbox when short text is displayed
Tomasz Mon <desowin@gmail.com>
parents:
2913
diff
changeset
|
679 gint pad = wl - length; |
3ef909ed3056
fix clearing textbox when short text is displayed
Tomasz Mon <desowin@gmail.com>
parents:
2913
diff
changeset
|
680 gchar *padchars = g_strnfill(pad, ' '); |
3ef909ed3056
fix clearing textbox when short text is displayed
Tomasz Mon <desowin@gmail.com>
parents:
2913
diff
changeset
|
681 |
3ef909ed3056
fix clearing textbox when short text is displayed
Tomasz Mon <desowin@gmail.com>
parents:
2913
diff
changeset
|
682 pixmaptext = g_strconcat(priv->pixmap_text, padchars, NULL); |
3ef909ed3056
fix clearing textbox when short text is displayed
Tomasz Mon <desowin@gmail.com>
parents:
2913
diff
changeset
|
683 g_free(padchars); |
3ef909ed3056
fix clearing textbox when short text is displayed
Tomasz Mon <desowin@gmail.com>
parents:
2913
diff
changeset
|
684 length += pad; |
3ef909ed3056
fix clearing textbox when short text is displayed
Tomasz Mon <desowin@gmail.com>
parents:
2913
diff
changeset
|
685 } else |
3ef909ed3056
fix clearing textbox when short text is displayed
Tomasz Mon <desowin@gmail.com>
parents:
2913
diff
changeset
|
686 pixmaptext = g_strdup(priv->pixmap_text); |
2911 | 687 |
688 if (priv->is_scrollable) { | |
689 if (priv->scroll_enabled && !priv->scroll_timeout) { | |
690 gint tag; | |
691 tag = TEXTBOX_SCROLL_SMOOTH_TIMEOUT; | |
692 priv->scroll_timeout = g_timeout_add(tag, textbox_scroll, textbox); | |
693 } | |
694 } else { | |
695 if (priv->scroll_timeout) { | |
696 g_source_remove(priv->scroll_timeout); | |
697 priv->scroll_timeout = 0; | |
698 } | |
699 priv->offset = 0; | |
700 } | |
701 | |
702 if (priv->font) { | |
703 textbox_generate_xfont_pixmap(textbox, pixmaptext); | |
704 g_free(pixmaptext); | |
705 return; | |
706 } | |
707 | |
708 priv->pixmap_width = length * bmp_active_skin->properties.textbox_bitmap_font_width; | |
2949
7a88f6d9cd92
use g_strdup_printf instead of fixed-size gchar*
Tomasz Mon <desowin@gmail.com>
parents:
2948
diff
changeset
|
709 priv->pixmap = gdk_pixmap_new(NULL, |
2911 | 710 priv->pixmap_width, bmp_active_skin->properties.textbox_bitmap_font_height, |
711 gdk_rgb_get_visual()->depth); | |
712 gc = priv->gc; | |
713 | |
2953
80b6fc3f4d29
Fix invalid free.
William Pitcock <nenolod@atheme-project.org>
parents:
2952
diff
changeset
|
714 for (tmp = stxt = g_utf8_strup(pixmaptext, -1), i = 0; |
2952
cb15e12b6352
Preserve capitalization for xfont users.
William Pitcock <nenolod@atheme-project.org>
parents:
2951
diff
changeset
|
715 tmp != NULL && i < length; i++, tmp = g_utf8_next_char(tmp)) { |
2951
4586c0951eab
Handle multibyte sequences properly when encountered.
William Pitcock <nenolod@atheme-project.org>
parents:
2949
diff
changeset
|
716 gchar c = *tmp; |
2911 | 717 x = y = -1; |
718 if (c >= 'A' && c <= 'Z') { | |
719 x = bmp_active_skin->properties.textbox_bitmap_font_width * (c - 'A'); | |
720 y = 0; | |
721 } | |
722 else if (c >= '0' && c <= '9') { | |
723 x = bmp_active_skin->properties.textbox_bitmap_font_width * (c - '0'); | |
724 y = bmp_active_skin->properties.textbox_bitmap_font_height; | |
725 } | |
726 else | |
727 textbox_handle_special_char(c, &x, &y); | |
728 | |
729 skin_draw_pixmap(bmp_active_skin, | |
730 priv->pixmap, gc, priv->skin_index, | |
731 x, y, i * bmp_active_skin->properties.textbox_bitmap_font_width, 0, | |
732 bmp_active_skin->properties.textbox_bitmap_font_width, | |
733 bmp_active_skin->properties.textbox_bitmap_font_height); | |
734 } | |
2953
80b6fc3f4d29
Fix invalid free.
William Pitcock <nenolod@atheme-project.org>
parents:
2952
diff
changeset
|
735 g_free(stxt); |
2911 | 736 g_free(pixmaptext); |
737 } | |
738 | |
739 void ui_skinned_textbox_set_scroll(GtkWidget *widget, gboolean scroll) { | |
740 g_return_if_fail(widget != NULL); | |
741 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); | |
742 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (textbox); | |
743 | |
744 priv->scroll_enabled = scroll; | |
745 if (priv->scroll_enabled && priv->is_scrollable && priv->scroll_allowed) { | |
746 gint tag; | |
747 tag = TEXTBOX_SCROLL_SMOOTH_TIMEOUT; | |
748 if (priv->scroll_timeout) { | |
749 g_source_remove(priv->scroll_timeout); | |
750 priv->scroll_timeout = 0; | |
751 } | |
752 priv->scroll_timeout = g_timeout_add(tag, textbox_scroll, textbox); | |
753 | |
754 } else { | |
755 | |
756 if (priv->scroll_timeout) { | |
757 g_source_remove(priv->scroll_timeout); | |
758 priv->scroll_timeout = 0; | |
759 } | |
760 | |
761 priv->offset = 0; | |
2965
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
762 textbox->redraw = TRUE; |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
763 gtk_widget_queue_draw(GTK_WIDGET(textbox)); |
2911 | 764 } |
765 } | |
766 | |
767 static void | |
768 textbox_handle_special_char(gchar c, gint * x, gint * y) | |
769 { | |
770 gint tx, ty; | |
771 | |
772 switch (c) { | |
773 case '"': | |
774 tx = 26; | |
775 ty = 0; | |
776 break; | |
777 case '\r': | |
778 tx = 10; | |
779 ty = 1; | |
780 break; | |
781 case ':': | |
782 case ';': | |
783 tx = 12; | |
784 ty = 1; | |
785 break; | |
786 case '(': | |
787 tx = 13; | |
788 ty = 1; | |
789 break; | |
790 case ')': | |
791 tx = 14; | |
792 ty = 1; | |
793 break; | |
794 case '-': | |
795 tx = 15; | |
796 ty = 1; | |
797 break; | |
798 case '`': | |
799 case '\'': | |
800 tx = 16; | |
801 ty = 1; | |
802 break; | |
803 case '!': | |
804 tx = 17; | |
805 ty = 1; | |
806 break; | |
807 case '_': | |
808 tx = 18; | |
809 ty = 1; | |
810 break; | |
811 case '+': | |
812 tx = 19; | |
813 ty = 1; | |
814 break; | |
815 case '\\': | |
816 tx = 20; | |
817 ty = 1; | |
818 break; | |
819 case '/': | |
820 tx = 21; | |
821 ty = 1; | |
822 break; | |
823 case '[': | |
824 tx = 22; | |
825 ty = 1; | |
826 break; | |
827 case ']': | |
828 tx = 23; | |
829 ty = 1; | |
830 break; | |
831 case '^': | |
832 tx = 24; | |
833 ty = 1; | |
834 break; | |
835 case '&': | |
836 tx = 25; | |
837 ty = 1; | |
838 break; | |
839 case '%': | |
840 tx = 26; | |
841 ty = 1; | |
842 break; | |
843 case '.': | |
844 case ',': | |
845 tx = 27; | |
846 ty = 1; | |
847 break; | |
848 case '=': | |
849 tx = 28; | |
850 ty = 1; | |
851 break; | |
852 case '$': | |
853 tx = 29; | |
854 ty = 1; | |
855 break; | |
856 case '#': | |
857 tx = 30; | |
858 ty = 1; | |
859 break; | |
860 case '?': | |
861 tx = 3; | |
862 ty = 2; | |
863 break; | |
864 case '*': | |
865 tx = 4; | |
866 ty = 2; | |
867 break; | |
868 default: | |
869 tx = 29; | |
870 ty = 0; | |
871 break; | |
872 } | |
873 | |
874 *x = tx * bmp_active_skin->properties.textbox_bitmap_font_width; | |
875 *y = ty * bmp_active_skin->properties.textbox_bitmap_font_height; | |
876 } | |
2943
a8f2c99727eb
replace Textbox in playlistwin with UiSkinnedTextbox, textbox.c no longer needed, temporary comment out g_usleep in textbox_scroll as it needs to be run as new thread
Tomasz Mon <desowin@gmail.com>
parents:
2942
diff
changeset
|
877 |
a8f2c99727eb
replace Textbox in playlistwin with UiSkinnedTextbox, textbox.c no longer needed, temporary comment out g_usleep in textbox_scroll as it needs to be run as new thread
Tomasz Mon <desowin@gmail.com>
parents:
2942
diff
changeset
|
878 void ui_skinned_textbox_move_relative(GtkWidget *widget, gint x, gint y) { |
2965
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
879 g_mutex_lock(mutex); |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
880 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (widget); |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
881 priv->move_x += x; |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
882 priv->move_y += y; |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
883 g_mutex_unlock(mutex); |
2943
a8f2c99727eb
replace Textbox in playlistwin with UiSkinnedTextbox, textbox.c no longer needed, temporary comment out g_usleep in textbox_scroll as it needs to be run as new thread
Tomasz Mon <desowin@gmail.com>
parents:
2942
diff
changeset
|
884 } |
2945
09c216d437b2
Backed out changeset 3c66c8d03c534692d1606ed3ed79634e227f7bd2
William Pitcock <nenolod@atheme.org>
parents:
2944
diff
changeset
|
885 |
09c216d437b2
Backed out changeset 3c66c8d03c534692d1606ed3ed79634e227f7bd2
William Pitcock <nenolod@atheme.org>
parents:
2944
diff
changeset
|
886 void ui_skinned_textbox_resize_relative(GtkWidget *widget, gint w, gint h) { |
2965
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
887 g_mutex_lock(mutex); |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
888 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE (widget); |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
889 priv->resize_width += w; |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
890 priv->resize_height += h; |
f84d09bada0f
correct _move_relative() and _resize_relative()
Tomasz Mon <desowin@gmail.com>
parents:
2962
diff
changeset
|
891 g_mutex_unlock(mutex); |
2945
09c216d437b2
Backed out changeset 3c66c8d03c534692d1606ed3ed79634e227f7bd2
William Pitcock <nenolod@atheme.org>
parents:
2944
diff
changeset
|
892 } |