annotate src/audacious/intl/ui_skinned_textbox.c @ 4023:0f3cd542f23a

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