annotate libaudacious/xentry.c @ 866:419fea14270c trunk

[svn] fixed multiple spawns of vorbis aboutbox
author giacomo
date Fri, 24 Mar 2006 07:54:14 -0800
parents 0a73d1faeb4e
children f12d7e208b43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* GTK - The GIMP Toolkit
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 * This library is free software; you can redistribute it and/or
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 * modify it under the terms of the GNU Library General Public
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 * License as published by the Free Software Foundation; either
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 * version 2 of the License, or (at your option) any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 * This library is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 * Library General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 * You should have received a copy of the GNU Library General Public
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 * License along with this library; if not, write to the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 * Boston, MA 02111-1307, USA.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 * file for a list of people on the GTK+ Team. See the ChangeLog
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 * files for a list of changes. These files are distributed with
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 * Small modification of the entry widget where keyboard navigation
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 * works even when the entry is not editable.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 * Copyright 2003 Haavard Kvaalen <havardk@xmms.org>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 #include <glib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 #include <gtk/gtk.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 #include <gdk/gdkkeysyms.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 #include <ctype.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 #include "xentry.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 static gint gtk_entry_key_press(GtkWidget * widget, GdkEventKey * event);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 static void gtk_entry_move_cursor(GtkOldEditable * editable, int x);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 static void gtk_move_forward_character(GtkEntry * entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 static void gtk_move_backward_character(GtkEntry * entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 static void gtk_move_forward_word(GtkEntry * entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 static void gtk_move_backward_word(GtkEntry * entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 static void gtk_move_beginning_of_line(GtkEntry * entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 static void gtk_move_end_of_line(GtkEntry * entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 static const GtkTextFunction control_keys[26] = {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 (GtkTextFunction) gtk_move_beginning_of_line, /* a */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 (GtkTextFunction) gtk_move_backward_character, /* b */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 (GtkTextFunction) gtk_editable_copy_clipboard, /* c */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 NULL, /* d */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 (GtkTextFunction) gtk_move_end_of_line, /* e */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 (GtkTextFunction) gtk_move_forward_character, /* f */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 static const GtkTextFunction alt_keys[26] = {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 NULL, /* a */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 (GtkTextFunction) gtk_move_backward_word, /* b */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 NULL, /* c */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 NULL, /* d */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 NULL, /* e */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 (GtkTextFunction) gtk_move_forward_word, /* f */
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 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 xmms_entry_class_init(GtkEntryClass * class)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 GtkWidgetClass *widget_class = (GtkWidgetClass *) class;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 widget_class->key_press_event = gtk_entry_key_press;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 GtkType
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 xmms_entry_get_type(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 static GtkType entry_type = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 if (!entry_type) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 static const GtkTypeInfo entry_info = {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 "XmmsEntry",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 sizeof(XmmsEntry),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 sizeof(XmmsEntryClass),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 (GtkClassInitFunc) xmms_entry_class_init,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 NULL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 /* reserved_1 */ NULL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 /* reserved_2 */ NULL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 (GtkClassInitFunc) NULL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 entry_type = gtk_type_unique(GTK_TYPE_ENTRY, &entry_info);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 return entry_type;
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 GtkWidget *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 xmms_entry_new(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 return GTK_WIDGET(gtk_type_new(XMMS_TYPE_ENTRY));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 gtk_entry_key_press(GtkWidget * widget, GdkEventKey * event)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 GtkEntry *entry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 GtkOldEditable *editable;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 int return_val;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 guint initial_pos, sel_start_pos, sel_end_pos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 int extend_selection;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 gboolean extend_start = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 g_return_val_if_fail(widget != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 g_return_val_if_fail(XMMS_IS_ENTRY(widget), FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 g_return_val_if_fail(event != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 entry = GTK_ENTRY(widget);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 editable = GTK_OLD_EDITABLE(widget);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 return_val = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 if (editable->editable)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 /* Let the regular entry handler do it */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 initial_pos = gtk_editable_get_position(GTK_EDITABLE(editable));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 extend_selection = event->state & GDK_SHIFT_MASK;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 sel_start_pos = editable->selection_start_pos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 sel_end_pos = editable->selection_end_pos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 if (extend_selection) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 if (sel_start_pos == sel_end_pos) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 sel_start_pos = editable->current_pos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 sel_end_pos = editable->current_pos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 extend_start = (editable->current_pos == sel_start_pos);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 switch (event->keyval) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 case GDK_Insert:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 return_val = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 if (event->state & GDK_CONTROL_MASK)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 gtk_editable_copy_clipboard(GTK_EDITABLE(editable));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 case GDK_Home:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 return_val = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 gtk_move_beginning_of_line(entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 case GDK_End:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 return_val = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 gtk_move_end_of_line(entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 case GDK_Left:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 return_val = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 if (!extend_selection && sel_start_pos != sel_end_pos) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 gtk_editable_set_position(GTK_EDITABLE(editable),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 MIN(sel_start_pos, sel_end_pos));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 /* Force redraw below */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 initial_pos = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 gtk_move_backward_character(entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 case GDK_Right:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 return_val = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 if (!extend_selection && sel_start_pos != sel_end_pos) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 gtk_editable_set_position(GTK_EDITABLE(editable),
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 MAX(sel_start_pos, sel_end_pos));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 /* Force redraw below */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 initial_pos = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 gtk_move_forward_character(entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 case GDK_Return:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 return_val = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 gtk_widget_activate(widget);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 if ((event->keyval >= 0x20) && (event->keyval <= 0xFF)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 int key = event->keyval;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 if (key >= 'A' && key <= 'Z')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 key -= 'A' - 'a';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 if (key >= 'a' && key <= 'z')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 key -= 'a';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 if (event->state & GDK_CONTROL_MASK) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200 if (control_keys[key]) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 (*control_keys[key]) (editable, event->time);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 return_val = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206 else if (event->state & GDK_MOD1_MASK) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207 if (alt_keys[key]) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208 (*alt_keys[key]) (editable, event->time);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209 return_val = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216 if (return_val && (editable->current_pos != initial_pos)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217 if (extend_selection) {
625
0a73d1faeb4e [svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents: 0
diff changeset
218 size_t cpos = gtk_editable_get_position(GTK_EDITABLE(editable));
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219 if (cpos < sel_start_pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220 sel_start_pos = cpos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221 else if (cpos > sel_end_pos)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222 sel_end_pos = cpos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224 if (extend_start)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225 sel_start_pos = cpos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227 sel_end_pos = cpos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 sel_start_pos = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 sel_end_pos = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235 gtk_editable_select_region(GTK_EDITABLE(editable), sel_start_pos,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 sel_end_pos);
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 return return_val;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 gtk_entry_move_cursor(GtkOldEditable * editable, int x)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 int set, pos = gtk_editable_get_position(GTK_EDITABLE(editable));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246 if (pos + x < 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247 set = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249 set = pos + x;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 gtk_editable_set_position(GTK_EDITABLE(editable), set);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254 gtk_move_forward_character(GtkEntry * entry)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256 gtk_entry_move_cursor(GTK_OLD_EDITABLE(entry), 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 gtk_move_backward_character(GtkEntry * entry)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262 gtk_entry_move_cursor(GTK_OLD_EDITABLE(entry), -1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266 gtk_move_forward_word(GtkEntry * entry)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268 GtkOldEditable *editable;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 GdkWChar *text;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272 editable = GTK_OLD_EDITABLE(entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274 /* Prevent any leak of information */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275 if (!editable->visible) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276 gtk_editable_set_position(GTK_EDITABLE(entry), -1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280 if (entry->text && (editable->current_pos < entry->text_length)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281 text = (GdkWChar *) entry->text;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282 i = editable->current_pos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284 /* if ((entry->use_wchar && !gdk_iswalnum(text[i])) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285 !isalnum(text[i]))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286 for (; i < entry->text_length; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 if (entry->use_wchar)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290 if (gdk_iswalnum(text[i]))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292 else if (isalnum(text[i]))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 for (; i < entry->text_length; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 if (entry->use_wchar)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301 if (gdk_iswalnum(text[i]))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303 else if (isalnum(text[i]))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310 gtk_editable_set_position(GTK_EDITABLE(entry), i);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315 gtk_move_backward_word(GtkEntry * entry)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317 GtkOldEditable *editable;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
318 GdkWChar *text;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321 editable = GTK_OLD_EDITABLE(entry);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 /* Prevent any leak of information */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324 if (!editable->visible) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325 gtk_editable_set_position(GTK_EDITABLE(entry), 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 if (entry->text && editable->current_pos > 0) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 text = (GdkWChar *) entry->text;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331 i = editable->current_pos;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333 /* if ((entry->use_wchar && !gdk_iswalnum(text[i])) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
334 !isalnum(text[i]))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335 for (; i >= 0; i--)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337 if (entry->use_wchar)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
338 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
339 if (gdk_iswalnum(text[i]))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
340 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
341 else if (isalnum(text[i]))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345 for (; i >= 0; i--)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
346 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
347 if ((entry->use_wchar && !gdk_iswalnum(text[i])) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
348 !isalnum(text[i]))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
349 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
350 i++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
351 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
352 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
353 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
354 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
355 if (i < 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
356 i = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
357
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
358 gtk_editable_set_position(GTK_EDITABLE(entry), i);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
359 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
360 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
361
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
362 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
363 gtk_move_beginning_of_line(GtkEntry * entry)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
364 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
365 gtk_editable_set_position(GTK_EDITABLE(entry), 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
366 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
367
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
368 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
369 gtk_move_end_of_line(GtkEntry * entry)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
370 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
371 gtk_editable_set_position(GTK_EDITABLE(entry), -1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
372 }