Mercurial > audlegacy-plugins
annotate src/skins/ui_skinned_textbox.c @ 3203:f5456241bff9 default tip
changed include path from audacious to audlegacy.
| author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
|---|---|
| date | Tue, 10 Nov 2009 05:19:25 +0900 |
| parents | 1ffcad5f406c |
| children |
| 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 | |
|
3159
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
366 #if 1 |
|
2860
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
367 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
|
368 widget->allocation.x, |
|
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
369 widget->allocation.y, |
|
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2836
diff
changeset
|
370 priv->scaled); |
|
3159
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
371 #else |
|
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
372 ui_skinned_widget_draw(widget, obj, textbox->width, textbox->height, priv->scaled); |
|
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
373 #endif |
| 2586 | 374 |
| 375 g_object_unref(obj); | |
| 376 } | |
| 377 | |
| 378 return FALSE; | |
| 379 } | |
| 380 | |
| 381 static gboolean ui_skinned_textbox_button_press(GtkWidget *widget, GdkEventButton *event) { | |
| 382 g_return_val_if_fail (widget != NULL, FALSE); | |
| 383 g_return_val_if_fail (UI_SKINNED_IS_TEXTBOX (widget), FALSE); | |
| 384 g_return_val_if_fail (event != NULL, FALSE); | |
| 385 | |
| 386 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); | |
| 387 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
| 388 | |
| 389 if (event->type == GDK_BUTTON_PRESS) { | |
| 390 textbox = UI_SKINNED_TEXTBOX(widget); | |
| 391 if (event->button == 3 && !g_signal_has_handler_pending(widget, textbox_signals[RIGHT_CLICKED], 0, TRUE)) | |
| 392 return FALSE; | |
| 393 else if (event->button == 1) { | |
| 394 if (priv->scroll_allowed) { | |
| 395 if ((priv->pixbuf_width > textbox->width) && priv->is_scrollable) { | |
| 396 priv->is_dragging = TRUE; | |
| 397 priv->drag_off = priv->offset; | |
| 398 priv->drag_x = event->x; | |
| 399 } | |
| 400 } else | |
| 401 g_signal_emit(widget, textbox_signals[CLICKED], 0); | |
| 402 | |
| 403 } else if (event->button == 3) { | |
| 404 g_signal_emit(widget, textbox_signals[RIGHT_CLICKED], 0, event); | |
| 405 } else | |
| 406 priv->is_dragging = FALSE; | |
| 407 } else if (event->type == GDK_2BUTTON_PRESS) { | |
| 408 if (event->button == 1) { | |
| 409 if (g_signal_has_handler_pending(widget, textbox_signals[DOUBLE_CLICKED], 0, TRUE)) | |
| 410 g_signal_emit(widget, textbox_signals[DOUBLE_CLICKED], 0); | |
| 411 else | |
| 412 return FALSE; | |
| 413 } | |
| 414 } | |
| 415 | |
| 416 return TRUE; | |
| 417 } | |
| 418 | |
| 419 static gboolean ui_skinned_textbox_button_release(GtkWidget *widget, GdkEventButton *event) { | |
| 420 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(widget); | |
| 421 | |
| 422 if (event->button == 1) { | |
| 423 priv->is_dragging = FALSE; | |
| 424 } | |
| 425 | |
| 426 return TRUE; | |
| 427 } | |
| 428 | |
| 429 static gboolean ui_skinned_textbox_motion_notify(GtkWidget *widget, GdkEventMotion *event) { | |
| 430 g_return_val_if_fail (widget != NULL, FALSE); | |
| 431 g_return_val_if_fail (UI_SKINNED_IS_TEXTBOX (widget), FALSE); | |
| 432 g_return_val_if_fail (event != NULL, FALSE); | |
| 433 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); | |
| 434 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(widget); | |
| 435 | |
| 436 if (priv->is_dragging) { | |
| 437 if (priv->scroll_allowed && | |
| 438 priv->pixbuf_width > textbox->width) { | |
| 439 priv->offset = priv->drag_off - (event->x - priv->drag_x); | |
| 440 | |
| 441 while (priv->offset < 0) | |
| 442 priv->offset = 0; | |
| 443 | |
| 444 while (priv->offset > (priv->pixbuf_width - textbox->width)) | |
| 445 priv->offset = (priv->pixbuf_width - textbox->width); | |
| 446 | |
| 447 gtk_widget_queue_draw(widget); | |
| 448 } | |
| 449 } | |
| 450 | |
| 451 return TRUE; | |
| 452 } | |
| 453 | |
| 454 static void ui_skinned_textbox_toggle_scaled(UiSkinnedTextbox *textbox) { | |
| 455 GtkWidget *widget = GTK_WIDGET (textbox); | |
| 456 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
| 457 | |
| 458 priv->scaled = !priv->scaled; | |
| 459 | |
|
3036
b0f8da03187b
Fix multiple issues with vector fonts in the skinned interface.
John Lindgren <john.lindgren@tds.net>
parents:
3032
diff
changeset
|
460 gtk_widget_set_size_request(widget, textbox->width*(priv->scaled ? config.scale_factor : 1 ), |
| 2586 | 461 textbox->height*(priv->scaled ? config.scale_factor : 1 )); |
| 462 | |
| 463 gtk_widget_queue_draw(GTK_WIDGET(textbox)); | |
| 464 } | |
| 465 | |
| 466 static gboolean ui_skinned_textbox_should_scroll(UiSkinnedTextbox *textbox) { | |
| 467 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
| 468 | |
| 469 if (!priv->scroll_allowed) | |
| 470 return FALSE; | |
| 471 | |
| 472 if (priv->font) { | |
| 473 gint width; | |
| 474 text_get_extents(priv->fontname, textbox->text, &width, NULL, NULL, NULL); | |
| 475 | |
| 476 if (width <= textbox->width) | |
| 477 return FALSE; | |
| 478 else | |
| 479 return TRUE; | |
| 480 } | |
| 481 | |
| 482 if (g_utf8_strlen(textbox->text, -1) * aud_active_skin->properties.textbox_bitmap_font_width > textbox->width) | |
| 483 return TRUE; | |
| 484 | |
| 485 return FALSE; | |
| 486 } | |
| 487 | |
| 488 void ui_skinned_textbox_set_xfont(GtkWidget *widget, gboolean use_xfont, const gchar * fontname) { | |
| 489 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); | |
| 490 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
| 491 | |
| 492 gint ascent, descent; | |
| 493 | |
| 494 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
|
495 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
|
496 gtk_widget_queue_draw (widget); |
| 2586 | 497 |
| 498 if (priv->font) { | |
| 499 pango_font_description_free(priv->font); | |
| 500 priv->font = NULL; | |
| 501 } | |
| 502 | |
| 503 textbox->y = priv->nominal_y; | |
| 504 textbox->height = priv->nominal_height; | |
| 505 | |
| 506 /* Make sure the pixmap is regenerated */ | |
| 507 if (priv->pixbuf_text) { | |
| 508 g_free(priv->pixbuf_text); | |
| 509 priv->pixbuf_text = NULL; | |
| 510 } | |
| 511 | |
| 512 if (!use_xfont || strlen(fontname) == 0) | |
| 513 return; | |
| 514 | |
| 515 priv->font = pango_font_description_from_string(fontname); | |
| 516 priv->fontname = g_strdup(fontname); | |
| 517 | |
| 518 text_get_extents(fontname, | |
| 519 "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz ", | |
| 520 NULL, NULL, &ascent, &descent); | |
| 521 priv->font_ascent = ascent; | |
| 522 priv->font_descent = descent; | |
| 523 | |
| 524 | |
| 525 if (priv->font == NULL) | |
| 526 return; | |
| 527 | |
|
3159
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
528 #if 0 |
|
3036
b0f8da03187b
Fix multiple issues with vector fonts in the skinned interface.
John Lindgren <john.lindgren@tds.net>
parents:
3032
diff
changeset
|
529 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
|
530 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
|
531 the top to make it fit better. See textbox_generate_xfont_pixmap. */ |
|
3159
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
532 //#else |
|
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
533 textbox->height = priv->font_ascent; |
|
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
534 if (textbox->height > priv->nominal_height) |
|
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
535 textbox->y -= (textbox->height - priv->nominal_height) / 2; |
|
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
536 else |
|
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
537 textbox->height = priv->nominal_height; |
|
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
538 #endif |
|
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
539 #if 0 |
|
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
540 textbox->height = priv->font_ascent = priv->font_descent; |
|
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
541 printf("font_ascent = %d font_descent = %d textbox->height = %d \n", priv->font_ascent, priv->font_descent, textbox->height); |
|
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
542 #endif |
|
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
543 textbox->height = 40; |
|
1ffcad5f406c
import new skins plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
3036
diff
changeset
|
544 |
| 2586 | 545 } |
| 546 | |
| 547 void ui_skinned_textbox_set_text(GtkWidget *widget, const gchar *text) { | |
| 548 g_return_if_fail(text != NULL); | |
| 549 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget); | |
| 550 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
| 551 | |
| 552 if (!strcmp(textbox->text, text)) | |
| 553 return; | |
| 554 if (textbox->text) | |
| 555 g_free(textbox->text); | |
| 556 | |
| 557 textbox->text = aud_str_to_utf8(text); | |
| 558 priv->scroll_back = FALSE; | |
| 559 gtk_widget_queue_draw(GTK_WIDGET(textbox)); | |
| 560 } | |
| 561 | |
| 562 static void textbox_generate_xfont_pixmap(UiSkinnedTextbox *textbox, const gchar *pixmaptext) { | |
| 563 /* FIXME: should operate directly on priv->pixbuf, it shouldn't use pixmap */ | |
| 564 gint length, i; | |
| 565 GdkGC *gc, *maskgc; | |
| 566 GdkColor *c, pattern; | |
| 567 GdkBitmap *mask; | |
| 568 PangoLayout *layout; | |
| 569 gint width; | |
| 570 GdkPixmap *pixmap; | |
| 571 | |
| 572 g_return_if_fail(textbox != NULL); | |
| 573 g_return_if_fail(pixmaptext != NULL); | |
| 574 g_return_if_fail(textbox->height > 0); | |
| 575 | |
| 576 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
| 577 | |
| 578 length = g_utf8_strlen(pixmaptext, -1); | |
| 579 | |
| 580 text_get_extents(priv->fontname, pixmaptext, &width, NULL, NULL, NULL); | |
| 581 | |
| 582 priv->pixbuf_width = MAX(width, textbox->width); | |
| 583 pixmap = gdk_pixmap_new(mainwin->window, priv->pixbuf_width, | |
| 584 textbox->height, | |
| 585 gdk_rgb_get_visual()->depth); | |
| 586 gc = gdk_gc_new(pixmap); | |
| 587 c = skin_get_color(aud_active_skin, SKIN_TEXTBG); | |
| 588 for (i = 0; i < textbox->height; i++) { | |
| 589 gdk_gc_set_foreground(gc, &c[6 * i / textbox->height]); | |
| 590 gdk_draw_line(pixmap, gc, 0, i, priv->pixbuf_width, i); | |
| 591 } | |
| 592 | |
| 593 mask = gdk_pixmap_new(mainwin->window, priv->pixbuf_width, textbox->height, 1); | |
| 594 maskgc = gdk_gc_new(mask); | |
| 595 pattern.pixel = 0; | |
| 596 gdk_gc_set_foreground(maskgc, &pattern); | |
| 597 | |
| 598 gdk_draw_rectangle(mask, maskgc, TRUE, 0, 0, priv->pixbuf_width, textbox->height); | |
| 599 pattern.pixel = 1; | |
| 600 gdk_gc_set_foreground(maskgc, &pattern); | |
| 601 | |
| 602 gdk_gc_set_foreground(gc, skin_get_color(aud_active_skin, SKIN_TEXTFG)); | |
| 603 | |
| 604 layout = gtk_widget_create_pango_layout(mainwin, pixmaptext); | |
| 605 pango_layout_set_font_description(layout, priv->font); | |
| 606 | |
|
3036
b0f8da03187b
Fix multiple issues with vector fonts in the skinned interface.
John Lindgren <john.lindgren@tds.net>
parents:
3032
diff
changeset
|
607 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
|
608 explanation in ui_skinned_textbox_set_xfont. */ |
| 2586 | 609 g_object_unref(layout); |
| 610 | |
| 611 g_object_unref(maskgc); | |
| 612 | |
| 613 gdk_gc_set_clip_mask(gc, mask); | |
| 614 c = skin_get_color(aud_active_skin, SKIN_TEXTFG); | |
| 615 for (i = 0; i < textbox->height; i++) { | |
| 616 gdk_gc_set_foreground(gc, &c[6 * i / textbox->height]); | |
| 617 gdk_draw_line(pixmap, gc, 0, i, priv->pixbuf_width, i); | |
| 618 } | |
| 619 priv->pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, gdk_colormap_get_system(), 0, 0, 0, 0, priv->pixbuf_width, textbox->height); | |
| 620 g_object_unref(mask); | |
| 621 g_object_unref(gc); | |
| 622 } | |
| 623 | |
| 624 static gboolean textbox_scroll(gpointer data) { | |
| 625 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(data); | |
| 626 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
| 627 | |
| 628 if (!priv->is_dragging) { | |
| 629 if (priv->scroll_dummy < TEXTBOX_SCROLL_WAIT) | |
| 630 priv->scroll_dummy++; | |
| 631 else { | |
| 632 if(config.twoway_scroll) { | |
| 633 if (priv->scroll_back) | |
| 634 priv->offset -= 1; | |
| 635 else | |
| 636 priv->offset += 1; | |
| 637 | |
| 638 if (priv->offset >= (priv->pixbuf_width - textbox->width)) { | |
| 639 priv->scroll_back = TRUE; | |
| 640 priv->scroll_dummy = 0; | |
| 641 priv->offset = priv->pixbuf_width - textbox->width; | |
| 642 } | |
| 643 if (priv->offset <= 0) { | |
| 644 priv->scroll_back = FALSE; | |
| 645 priv->scroll_dummy = 0; | |
| 646 priv->offset = 0; | |
| 647 } | |
| 648 } | |
| 649 else { // oneway scroll | |
| 650 priv->scroll_back = FALSE; | |
| 651 priv->offset += 1; | |
| 652 } | |
| 653 gtk_widget_queue_draw(GTK_WIDGET(textbox)); | |
| 654 } | |
| 655 } | |
| 656 return TRUE; | |
| 657 } | |
| 658 | |
| 659 static void textbox_generate_pixmap(UiSkinnedTextbox *textbox) { | |
| 660 gint length, i, x, y, wl; | |
| 661 gchar *pixmaptext; | |
| 662 gchar *tmp, *stxt; | |
| 663 | |
| 664 g_return_if_fail(textbox != NULL); | |
| 665 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
| 666 | |
| 667 if (priv->pixbuf) { | |
| 668 g_object_unref(priv->pixbuf); | |
| 669 priv->pixbuf = NULL; | |
| 670 } | |
| 671 | |
| 672 /* | |
| 673 * Don't reset the offset if only text after the last '(' has | |
| 674 * changed. This is a hack to avoid visual noice on vbr files | |
| 675 * where we guess the length. | |
| 676 */ | |
| 677 if (!(priv->pixbuf_text && strrchr(textbox->text, '(') && | |
| 678 !strncmp(priv->pixbuf_text, textbox->text, | |
| 679 strrchr(textbox->text, '(') - textbox->text))) | |
| 680 priv->offset = 0; | |
| 681 | |
| 682 g_free(priv->pixbuf_text); | |
| 683 priv->pixbuf_text = g_strdup(textbox->text); | |
| 684 | |
| 685 /* | |
| 686 * wl is the number of (partial) letters visible. Only makes | |
| 687 * sense when using skinned font. | |
| 688 */ | |
| 689 wl = textbox->width / 5; | |
| 690 if (wl * 5 != textbox->width) | |
| 691 wl++; | |
| 692 | |
| 693 length = g_utf8_strlen(textbox->text, -1); | |
| 694 | |
| 695 priv->is_scrollable = FALSE; | |
| 696 | |
| 697 priv->is_scrollable = ui_skinned_textbox_should_scroll(textbox); | |
| 698 | |
| 699 if (priv->is_scrollable) { | |
| 700 if(!config.twoway_scroll) { | |
| 701 pixmaptext = g_strdup_printf("%s *** ", priv->pixbuf_text); | |
| 702 length += 5; | |
| 703 } else | |
| 704 pixmaptext = g_strdup(priv->pixbuf_text); | |
| 705 } else | |
| 706 if (!priv->font && length <= wl) { | |
| 707 gint pad = wl - length; | |
| 708 gchar *padchars = g_strnfill(pad, ' '); | |
| 709 | |
| 710 pixmaptext = g_strconcat(priv->pixbuf_text, padchars, NULL); | |
| 711 g_free(padchars); | |
| 712 length += pad; | |
| 713 } else | |
| 714 pixmaptext = g_strdup(priv->pixbuf_text); | |
| 715 | |
| 716 if (priv->is_scrollable) { | |
| 717 if (priv->scroll_enabled && !priv->scroll_timeout) { | |
| 718 gint tag; | |
| 719 tag = TEXTBOX_SCROLL_SMOOTH_TIMEOUT; | |
| 720 priv->scroll_timeout = g_timeout_add(tag, textbox_scroll, textbox); | |
| 721 } | |
| 722 } else { | |
| 723 if (priv->scroll_timeout) { | |
| 724 g_source_remove(priv->scroll_timeout); | |
| 725 priv->scroll_timeout = 0; | |
| 726 } | |
| 727 priv->offset = 0; | |
| 728 } | |
| 729 | |
| 730 if (priv->font) { | |
| 731 textbox_generate_xfont_pixmap(textbox, pixmaptext); | |
| 732 g_free(pixmaptext); | |
| 733 return; | |
| 734 } | |
| 735 | |
| 736 priv->pixbuf_width = length * aud_active_skin->properties.textbox_bitmap_font_width; | |
| 737 priv->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, | |
| 738 priv->pixbuf_width, aud_active_skin->properties.textbox_bitmap_font_height); | |
| 739 | |
| 740 for (tmp = stxt = g_utf8_strup(pixmaptext, -1), i = 0; | |
| 741 tmp != NULL && i < length; i++, tmp = g_utf8_next_char(tmp)) { | |
| 742 gchar c = *tmp; | |
| 743 x = y = -1; | |
| 744 if (c >= 'A' && c <= 'Z') { | |
| 745 x = aud_active_skin->properties.textbox_bitmap_font_width * (c - 'A'); | |
| 746 y = 0; | |
| 747 } | |
| 748 else if (c >= '0' && c <= '9') { | |
| 749 x = aud_active_skin->properties.textbox_bitmap_font_width * (c - '0'); | |
| 750 y = aud_active_skin->properties.textbox_bitmap_font_height; | |
| 751 } | |
| 752 else | |
| 753 textbox_handle_special_char(tmp, &x, &y); | |
| 754 | |
| 755 skin_draw_pixbuf(GTK_WIDGET(textbox), aud_active_skin, | |
| 756 priv->pixbuf, priv->skin_index, | |
| 757 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
|
758 aud_active_skin->properties.textbox_bitmap_font_width, |
| 2586 | 759 aud_active_skin->properties.textbox_bitmap_font_height); |
| 760 } | |
| 761 g_free(stxt); | |
| 762 g_free(pixmaptext); | |
| 763 } | |
| 764 | |
| 765 void ui_skinned_textbox_set_scroll(GtkWidget *widget, gboolean scroll) { | |
| 766 g_return_if_fail(widget != NULL); | |
|
2635
b990e7eb0c25
save config on plugin cleanup
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
767 g_return_if_fail(UI_SKINNED_IS_TEXTBOX(widget)); |
|
b990e7eb0c25
save config on plugin cleanup
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
768 |
| 2586 | 769 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); |
| 770 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox); | |
| 771 | |
| 772 priv->scroll_enabled = scroll; | |
| 773 if (priv->scroll_enabled && priv->is_scrollable && priv->scroll_allowed) { | |
| 774 gint tag; | |
| 775 tag = TEXTBOX_SCROLL_SMOOTH_TIMEOUT; | |
| 776 if (priv->scroll_timeout) { | |
| 777 g_source_remove(priv->scroll_timeout); | |
| 778 priv->scroll_timeout = 0; | |
| 779 } | |
| 780 priv->scroll_timeout = g_timeout_add(tag, textbox_scroll, textbox); | |
| 781 | |
| 782 } else { | |
| 783 | |
| 784 if (priv->scroll_timeout) { | |
| 785 g_source_remove(priv->scroll_timeout); | |
| 786 priv->scroll_timeout = 0; | |
| 787 } | |
| 788 | |
| 789 priv->offset = 0; | |
| 790 gtk_widget_queue_draw(GTK_WIDGET(textbox)); | |
| 791 } | |
| 792 } | |
| 793 | |
| 794 static void textbox_handle_special_char(gchar *c, gint * x, gint * y) { | |
| 795 gint tx, ty; | |
| 796 | |
| 797 switch (*c) { | |
| 798 case '"': | |
| 799 tx = 26; | |
| 800 ty = 0; | |
| 801 break; | |
| 802 case '\r': | |
| 803 tx = 10; | |
| 804 ty = 1; | |
| 805 break; | |
| 806 case ':': | |
| 807 case ';': | |
| 808 tx = 12; | |
| 809 ty = 1; | |
| 810 break; | |
| 811 case '(': | |
| 812 tx = 13; | |
| 813 ty = 1; | |
| 814 break; | |
| 815 case ')': | |
| 816 tx = 14; | |
| 817 ty = 1; | |
| 818 break; | |
| 819 case '-': | |
| 820 tx = 15; | |
| 821 ty = 1; | |
| 822 break; | |
| 823 case '`': | |
| 824 case '\'': | |
| 825 tx = 16; | |
| 826 ty = 1; | |
| 827 break; | |
| 828 case '!': | |
| 829 tx = 17; | |
| 830 ty = 1; | |
| 831 break; | |
| 832 case '_': | |
| 833 tx = 18; | |
| 834 ty = 1; | |
| 835 break; | |
| 836 case '+': | |
| 837 tx = 19; | |
| 838 ty = 1; | |
| 839 break; | |
| 840 case '\\': | |
| 841 tx = 20; | |
| 842 ty = 1; | |
| 843 break; | |
| 844 case '/': | |
| 845 tx = 21; | |
| 846 ty = 1; | |
| 847 break; | |
| 848 case '[': | |
| 849 tx = 22; | |
| 850 ty = 1; | |
| 851 break; | |
| 852 case ']': | |
| 853 tx = 23; | |
| 854 ty = 1; | |
| 855 break; | |
| 856 case '^': | |
| 857 tx = 24; | |
| 858 ty = 1; | |
| 859 break; | |
| 860 case '&': | |
| 861 tx = 25; | |
| 862 ty = 1; | |
| 863 break; | |
| 864 case '%': | |
| 865 tx = 26; | |
| 866 ty = 1; | |
| 867 break; | |
| 868 case '.': | |
| 869 case ',': | |
| 870 tx = 27; | |
| 871 ty = 1; | |
| 872 break; | |
| 873 case '=': | |
| 874 tx = 28; | |
| 875 ty = 1; | |
| 876 break; | |
| 877 case '$': | |
| 878 tx = 29; | |
| 879 ty = 1; | |
| 880 break; | |
| 881 case '#': | |
| 882 tx = 30; | |
| 883 ty = 1; | |
| 884 break; | |
| 885 case '?': | |
| 886 tx = 3; | |
| 887 ty = 2; | |
| 888 break; | |
| 889 case '*': | |
| 890 tx = 4; | |
| 891 ty = 2; | |
| 892 break; | |
| 893 default: | |
| 894 tx = 29; | |
| 895 ty = 0; | |
| 896 break; | |
| 897 } | |
| 898 | |
| 899 const gchar *change[] = {"Ą", "A", "Ę", "E", "Ć", "C", "Ł", "L", "Ó", "O", "Ś", "S", "Ż", "Z", "Ź", "Z", | |
| 900 "Ń", "N", "Ü", "U", NULL}; | |
| 901 int i; | |
| 902 for (i = 0; change[i]; i+=2) { | |
| 903 if (!strncmp(c, change[i], strlen(change[i]))) { | |
| 904 tx = (*change[i+1] - 'A'); | |
| 905 break; | |
| 906 } | |
| 907 } | |
| 908 | |
| 909 /* those are commonly included into skins */ | |
| 910 if (!strncmp(c, "Å", strlen("Å"))) { | |
| 911 tx = 0; | |
| 912 ty = 2; | |
| 913 } else if (!strncmp(c, "Ö", strlen("Ö"))) { | |
| 914 tx = 1; | |
| 915 ty = 2; | |
| 916 } else if (!strncmp(c, "Ä", strlen("Ä"))) { | |
| 917 tx = 2; | |
| 918 ty = 2; | |
| 919 } | |
| 920 | |
| 921 *x = tx * aud_active_skin->properties.textbox_bitmap_font_width; | |
| 922 *y = ty * aud_active_skin->properties.textbox_bitmap_font_height; | |
| 923 } | |
| 924 | |
| 925 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
|
926 UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget); |
| 2586 | 927 UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(widget); |
| 928 priv->move_x += x; | |
| 929 priv->move_y += y; | |
|
2698
32e99af83a3e
I don't think redraw signal is needed anymore
Tomasz Mon <desowin@gmail.com>
parents:
2635
diff
changeset
|
930 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
|
931 textbox->x+priv->move_x, textbox->y+priv->move_y); |
| 2586 | 932 } |
