annotate src/skins/ui_skinned_textbox.c @ 2635:b990e7eb0c25

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