annotate audacious/textbox.c @ 351:c6e9eb0ee70b trunk

[svn] filterchain stuff
author nenolod
date Mon, 26 Dec 2005 13:56:03 -0800
parents f490def08b5c
children 8fee6432cd63
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* BMP - Cross-platform multimedia player
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 * Copyright (C) 2003-2004 BMP development team.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 * Based on XMMS:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 * Copyright (C) 1998-2003 XMMS development team.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 * (at your option) any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 * GNU General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 #include "textbox.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 #include <glib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 #include <gtk/gtk.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 #include <gdk/gdk.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27 #include <gdk/gdkprivate.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 #include <ctype.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 #include "main.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 #include "util.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 static void textbox_generate_pixmap(TextBox * tb);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 textbox_draw(Widget * w)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 TextBox *tb = TEXT_BOX(w);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 gint cw;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 GdkPixmap *obj;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 GdkPixmap *src;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 g_return_if_fail(tb != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 if (tb->tb_text &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 (!tb->tb_pixmap_text || strcmp(tb->tb_text, tb->tb_pixmap_text)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 textbox_generate_pixmap(tb);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 if (tb->tb_pixmap) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 if (skin_get_id() != tb->tb_skin_id) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 tb->tb_skin_id = skin_get_id();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 textbox_generate_pixmap(tb);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 obj = tb->tb_widget.parent;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 src = tb->tb_pixmap;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 cw = tb->tb_pixmap_width - tb->tb_offset;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 if (cw > tb->tb_widget.width)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 cw = tb->tb_widget.width;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 gdk_draw_pixmap(obj, tb->tb_widget.gc, src, tb->tb_offset, 0,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 tb->tb_widget.x, tb->tb_widget.y, cw,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 tb->tb_widget.height);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 if (cw < tb->tb_widget.width)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 gdk_draw_pixmap(obj, tb->tb_widget.gc, src, 0, 0,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 tb->tb_widget.x + cw, tb->tb_widget.y,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 tb->tb_widget.width - cw, tb->tb_widget.height);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 textbox_scroll(gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 TextBox *tb = TEXT_BOX(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 if (!tb->tb_is_dragging) {
221
f490def08b5c [svn] Revert logic part of scrolling.
nenolod
parents: 124
diff changeset
77 tb->tb_offset += 1;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 if (tb->tb_offset >= tb->tb_pixmap_width)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 tb->tb_offset -= tb->tb_pixmap_width;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 widget_draw(WIDGET(tb));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 textbox_button_press(GtkWidget * w, GdkEventButton * event, gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 TextBox *tb = TEXT_BOX(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 if (event->button != 1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 if (widget_contains(&tb->tb_widget, event->x, event->y) &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 tb->tb_scroll_allowed &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 tb->tb_pixmap_width > tb->tb_widget.width && tb->tb_is_scrollable) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 tb->tb_is_dragging = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 tb->tb_drag_off = tb->tb_offset;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 tb->tb_drag_x = event->x;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 textbox_motion(GtkWidget * w, GdkEventMotion * event, gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 TextBox *tb = TEXT_BOX(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 if (tb->tb_is_dragging) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 if (tb->tb_scroll_allowed &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 tb->tb_pixmap_width > tb->tb_widget.width) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 tb->tb_offset = tb->tb_drag_off - (event->x - tb->tb_drag_x);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 while (tb->tb_offset < 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 tb->tb_offset += tb->tb_pixmap_width;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 while (tb->tb_offset > tb->tb_pixmap_width)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 tb->tb_offset -= tb->tb_pixmap_width;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 widget_draw(WIDGET(tb));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 textbox_button_release(GtkWidget * w, GdkEventButton * event, gpointer data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 TextBox *tb = TEXT_BOX(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 if (event->button == 1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 tb->tb_is_dragging = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 textbox_should_scroll(TextBox * tb)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 g_return_val_if_fail(tb != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 if (!tb->tb_scroll_allowed)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 if (tb->tb_font) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 gint width;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 text_get_extents(tb->tb_fontname, tb->tb_text, &width, NULL, NULL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 if (width <= tb->tb_widget.width)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 if (g_utf8_strlen(tb->tb_text, -1) * 5 > tb->tb_widget.width)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 textbox_set_text(TextBox * tb, const gchar * text)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 g_return_if_fail(tb != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 g_return_if_fail(text != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 widget_lock(WIDGET(tb));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 if (tb->tb_text) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 if (!strcmp(text, tb->tb_text)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 widget_unlock(WIDGET(tb));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 g_free(tb->tb_text);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 tb->tb_text = str_to_utf8(text);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 widget_unlock(WIDGET(tb));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 widget_draw(WIDGET(tb));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 textbox_generate_xfont_pixmap(TextBox * tb, const gchar * pixmaptext)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 gint length, i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 GdkGC *gc, *maskgc;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 GdkColor *c, pattern;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 GdkBitmap *mask;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 PangoLayout *layout;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 gint width;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 g_return_if_fail(tb != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 g_return_if_fail(pixmaptext != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 length = g_utf8_strlen(pixmaptext, -1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 text_get_extents(tb->tb_fontname, pixmaptext, &width, NULL, NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 tb->tb_pixmap_width = MAX(width, tb->tb_widget.width);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198 tb->tb_pixmap = gdk_pixmap_new(mainwin->window, tb->tb_pixmap_width,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 tb->tb_widget.height,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200 gdk_rgb_get_visual()->depth);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 gc = tb->tb_widget.gc;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 c = skin_get_color(bmp_active_skin, SKIN_TEXTBG);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203 for (i = 0; i < tb->tb_widget.height; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204 gdk_gc_set_foreground(gc, &c[6 * i / tb->tb_widget.height]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 gdk_draw_line(tb->tb_pixmap, gc, 0, i, tb->tb_pixmap_width, i);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208 mask = gdk_pixmap_new(mainwin->window, tb->tb_pixmap_width,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209 tb->tb_widget.height, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 maskgc = gdk_gc_new(mask);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211 pattern.pixel = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212 gdk_gc_set_foreground(maskgc, &pattern);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214 gdk_draw_rectangle(mask, maskgc, TRUE, 0, 0,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215 tb->tb_pixmap_width, tb->tb_widget.height);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216 pattern.pixel = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217 gdk_gc_set_foreground(maskgc, &pattern);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219 gdk_gc_set_foreground(gc, skin_get_color(bmp_active_skin, SKIN_TEXTFG));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221 layout = gtk_widget_create_pango_layout(mainwin, pixmaptext);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222 pango_layout_set_font_description(layout, tb->tb_font);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224 gdk_draw_layout(tb->tb_pixmap, gc, 0, (tb->tb_font_descent / 2), layout);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225 g_object_unref(layout);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227 g_object_unref(maskgc);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 gdk_gc_set_clip_mask(gc, mask);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230 c = skin_get_color(bmp_active_skin, SKIN_TEXTFG);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 for (i = 0; i < tb->tb_widget.height; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 gdk_gc_set_foreground(gc, &c[6 * i / tb->tb_widget.height]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233 gdk_draw_line(tb->tb_pixmap, gc, 0, i, tb->tb_pixmap_width, i);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235 g_object_unref(mask);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 gdk_gc_set_clip_mask(gc, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240 textbox_handle_special_char(gchar c, gint * x, gint * y)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 switch (c) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 case '"':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 *x = 130;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 *y = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247 case ':':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248 *x = 60;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251 case '(':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252 *x = 65;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255 case ')':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256 *x = 70;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 case '-':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 *x = 75;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263 case '`':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264 case '\'':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 *x = 80;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268 case '!':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 *x = 85;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272 case '_':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273 *x = 90;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276 case '+':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277 *x = 95;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280 case '\\':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281 *x = 100;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284 case '/':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285 *x = 105;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 case '[':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 *x = 110;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292 case ']':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293 *x = 115;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296 case '^':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 *x = 120;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300 case '&':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301 *x = 125;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 case '%':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305 *x = 130;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308 case '.':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309 case ',':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310 *x = 135;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313 case '=':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 *x = 140;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317 case '$':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
318 *x = 145;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321 case '#':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322 *x = 150;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 *y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325 case 'å':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326 case 'Å':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327 *x = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328 *y = 12;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 case 'ö':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331 case 'Ö':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 *x = 5;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333 *y = 12;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
334 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335 case 'ä':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336 case 'Ä':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337 *x = 10;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
338 *y = 12;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
339 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
340 case 'ü':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
341 case 'Ü':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342 *x = 100;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343 *y = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345 case '?':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
346 *x = 15;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
347 *y = 12;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
348 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
349 case '*':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
350 *x = 20;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
351 *y = 12;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
352 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
353 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
354 *x = 145;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
355 *y = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
356 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
357 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
358 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
359
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
360 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
361 textbox_generate_pixmap(TextBox * tb)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
362 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
363 gint length, i, x, y, wl;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
364 gchar *pixmaptext;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
365 GdkGC *gc;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
366
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
367 g_return_if_fail(tb != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
368
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
369 if (tb->tb_pixmap) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
370 g_object_unref(tb->tb_pixmap);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
371 tb->tb_pixmap = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
372 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
373
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
374 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
375 * Don't reset the offset if only text after the last '(' has
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
376 * changed. This is a hack to avoid visual noice on vbr files
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
377 * where we guess the length.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
378 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
379 if (!(tb->tb_pixmap_text && strrchr(tb->tb_text, '(') &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
380 !strncmp(tb->tb_pixmap_text, tb->tb_text,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
381 strrchr(tb->tb_text, '(') - tb->tb_text)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
382 tb->tb_offset = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
383
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
384 g_free(tb->tb_pixmap_text);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
385 tb->tb_pixmap_text = g_strdup(tb->tb_text);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
386
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
387 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
388 * wl is the number of (partial) letters visible. Only makes
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
389 * sense when using skinned font.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
390 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
391
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
392 wl = tb->tb_widget.width / 5;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
393 if (wl * 5 != tb->tb_widget.width)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
394 wl++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
395
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
396 length = g_utf8_strlen(tb->tb_text, -1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
397
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
398 tb->tb_is_scrollable = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
399
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
400 if (textbox_should_scroll(tb)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
401 tb->tb_is_scrollable = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
402 pixmaptext = g_strconcat(tb->tb_pixmap_text, " *** ", NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
403 length += 7;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
404 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
405 else if (!tb->tb_font && length <= wl) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
406 gint pad = wl - length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
407 gchar *padchars = g_strnfill(pad, ' ');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
408
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
409 pixmaptext = g_strconcat(tb->tb_pixmap_text, padchars, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
410 g_free(padchars);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
411 length += pad;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
412 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
413 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
414 pixmaptext = g_strdup(tb->tb_pixmap_text);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
415
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
416
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
417 if (tb->tb_is_scrollable) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
418 if (tb->tb_scroll_enabled && !tb->tb_timeout_tag) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
419 gint tag;
221
f490def08b5c [svn] Revert logic part of scrolling.
nenolod
parents: 124
diff changeset
420 tag = TEXTBOX_SCROLL_SMOOTH_TIMEOUT;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
421 tb->tb_timeout_tag = gtk_timeout_add(tag, textbox_scroll, tb);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
422 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
423 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
424 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
425 if (tb->tb_timeout_tag) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
426 gtk_timeout_remove(tb->tb_timeout_tag);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
427 tb->tb_timeout_tag = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
428 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
429 tb->tb_offset = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
430 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
431
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
432 if (tb->tb_font) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
433 textbox_generate_xfont_pixmap(tb, pixmaptext);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
434 g_free(pixmaptext);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
435 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
436 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
437
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
438 tb->tb_pixmap_width = length * 5;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
439 tb->tb_pixmap = gdk_pixmap_new(mainwin->window,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
440 tb->tb_pixmap_width, 6,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
441 gdk_rgb_get_visual()->depth);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
442 gc = tb->tb_widget.gc;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
443
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
444 for (i = 0; i < length; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
445 gchar c;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
446 x = y = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
447 c = toupper(pixmaptext[i]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
448 if (c >= 'A' && c <= 'Z') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
449 x = 5 * (c - 'A');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
450 y = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
451 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
452 else if (c >= '0' && c <= '9') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
453 x = 5 * (c - '0');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
454 y = 6;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
455 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
456 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
457 textbox_handle_special_char(c, &x, &y);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
458
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
459 skin_draw_pixmap(bmp_active_skin,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
460 tb->tb_pixmap, gc, tb->tb_skin_index,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
461 x, y, i * 5, 0, 5, 6);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
462 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
463 g_free(pixmaptext);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
464 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
465
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
466 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
467 textbox_set_scroll(TextBox * tb, gboolean s)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
468 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
469 g_return_if_fail(tb != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
470
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
471 tb->tb_scroll_enabled = s;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
472 if (tb->tb_scroll_enabled && tb->tb_is_scrollable
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
473 && tb->tb_scroll_allowed) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
474 gint tag;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
475 tag = TEXTBOX_SCROLL_SMOOTH_TIMEOUT;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
476 tb->tb_timeout_tag = gtk_timeout_add(tag, textbox_scroll, tb);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
477 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
478 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
479 if (tb->tb_timeout_tag) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
480 gtk_timeout_remove(tb->tb_timeout_tag);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
481 tb->tb_timeout_tag = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
482 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
483 tb->tb_offset = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
484 widget_draw(WIDGET(tb));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
485 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
486
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
487 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
488
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
489 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
490 textbox_set_xfont(TextBox * tb, gboolean use_xfont, const gchar * fontname)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
491 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
492 gint ascent, descent;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
493
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
494 g_return_if_fail(tb != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
495
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
496 if (tb->tb_font) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
497 pango_font_description_free(tb->tb_font);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
498 tb->tb_font = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
499 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
500
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
501 tb->tb_widget.y = tb->tb_nominal_y;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
502 tb->tb_widget.height = tb->tb_nominal_height;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
503
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
504 /* Make sure the pixmap is regenerated */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
505 if (tb->tb_pixmap_text) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
506 g_free(tb->tb_pixmap_text);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
507 tb->tb_pixmap_text = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
508 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
509
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
510 if (!use_xfont || strlen(fontname) == 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
511 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
512
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
513 tb->tb_font = pango_font_description_from_string(fontname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
514 tb->tb_fontname = g_strdup(fontname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
515
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
516 text_get_extents(fontname,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
517 "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz ",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
518 NULL, NULL, &ascent, &descent);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
519 tb->tb_font_ascent = ascent;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
520 tb->tb_font_descent = descent;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
521
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
522
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
523 if (tb->tb_font == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
524 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
525
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
526 tb->tb_widget.height = tb->tb_font_ascent;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
527 if (tb->tb_widget.height > tb->tb_nominal_height)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
528 tb->tb_widget.y -= (tb->tb_widget.height - tb->tb_nominal_height) / 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
529 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
530 tb->tb_widget.height = tb->tb_nominal_height;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
531 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
532
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
533 TextBox *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
534 create_textbox(GList ** wlist, GdkPixmap * parent, GdkGC * gc,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
535 gint x, gint y, gint w, gboolean allow_scroll, SkinPixmapId si)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
536 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
537 TextBox *tb;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
538
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
539 tb = g_new0(TextBox, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
540 widget_init(&tb->tb_widget, parent, gc, x, y, w, 6, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
541 tb->tb_widget.button_press_cb = textbox_button_press;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
542 tb->tb_widget.button_release_cb = textbox_button_release;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
543 tb->tb_widget.motion_cb = textbox_motion;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
544 tb->tb_widget.draw = textbox_draw;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
545 tb->tb_scroll_allowed = allow_scroll;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
546 tb->tb_scroll_enabled = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
547 tb->tb_skin_index = si;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
548 tb->tb_nominal_y = y;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
549 tb->tb_nominal_height = tb->tb_widget.height;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
550 widget_list_add(wlist, WIDGET(tb));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
551 return tb;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
552 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
553
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
554 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
555 textbox_free(TextBox * tb)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
556 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
557 g_return_if_fail(tb != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
558
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
559 if (tb->tb_pixmap)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
560 g_object_unref(tb->tb_pixmap);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
561 g_free(tb->tb_text);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
562 g_free(tb);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
563 }