annotate src/ui_tree_edit.c @ 1536:b1e622788c4a

Just update the internal sort method There is no other use of the internal sort method than speeding up the sorting of a collection. So setting it to SORT_NONE is the better choice.
author mow
date Fri, 10 Apr 2009 13:54:08 +0000
parents 24a12aa0cb54
children 2349fa90226d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
1 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
2 * (SLIK) SimpLIstic sKin functions
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
3 * (C) 2004 John Ellis
1284
8b89e3ff286b Add year 2009 to copyright info everywhere.
zas_
parents: 1147
diff changeset
4 * Copyright (C) 2008 - 2009 The Geeqie Team
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
10 * This software comes with no warranty of any kind, use at your own risk!
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
11 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
12
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
13 #ifdef HAVE_CONFIG_H
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
14 # include "config.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
16 #include "intl.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
17
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
18 #include <stdio.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
19 #include <stdlib.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
20 #include <string.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
21
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
22 #include <gtk/gtk.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
23 #include <gdk/gdkkeysyms.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
24
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
25 #include "ui_tree_edit.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
26
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
27 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
28 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
29 * cell popup editor
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
30 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
31 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
32
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
33 static void tree_edit_close(TreeEditData *ted)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
34 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
35 gtk_grab_remove(ted->window);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
36 gdk_keyboard_ungrab(GDK_CURRENT_TIME);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
37 gdk_pointer_ungrab(GDK_CURRENT_TIME);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
38
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
39 gtk_widget_destroy(ted->window);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
40
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
41 g_free(ted->old_name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42 g_free(ted->new_name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
43 gtk_tree_path_free(ted->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
44
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
45 g_free(ted);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
46 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
47
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48 static void tree_edit_do(TreeEditData *ted)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
50 ted->new_name = g_strdup(gtk_entry_get_text(GTK_ENTRY(ted->entry)));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
51
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52 if (strcmp(ted->new_name, ted->old_name) != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
53 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
54 if (ted->edit_func)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
55 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
56 if (ted->edit_func(ted, ted->old_name, ted->new_name, ted->edit_data))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
57 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
58 /* hmm, should the caller be required to set text instead ? */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
60 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
61 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
62 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
63
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
64 static gboolean tree_edit_click_end_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
65 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
66 TreeEditData *ted = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
67
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
68 tree_edit_do(ted);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
69 tree_edit_close(ted);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
70
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
71 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
72 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
73
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
74 static gboolean tree_edit_click_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
75 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
76 TreeEditData *ted = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
77
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
78 gint x, y;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
79 gint w, h;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
80
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
81 gint xr, yr;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
82
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
83 xr = (gint)event->x_root;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
84 yr = (gint)event->y_root;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
85
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
86 gdk_window_get_origin(ted->window->window, &x, &y);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
87 gdk_drawable_get_size(ted->window->window, &w, &h);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
88
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
89 if (xr < x || yr < y || xr > x + w || yr > y + h)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
90 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
91 /* gobble the release event, so it does not propgate to an underlying widget */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
92 g_signal_connect(G_OBJECT(ted->window), "button_release_event",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
93 G_CALLBACK(tree_edit_click_end_cb), ted);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
94 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
95 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
96 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
97 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
98
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
99 static gboolean tree_edit_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
100 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
101 TreeEditData *ted = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
102
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
103 switch (event->keyval)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
104 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
105 case GDK_Return:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
106 case GDK_KP_Enter:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
107 case GDK_Tab: /* ok, we are going to intercept the focus change
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
108 from keyboard and act like return was hit */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
109 case GDK_ISO_Left_Tab:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
110 case GDK_Up:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
111 case GDK_Down:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
112 case GDK_KP_Up:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
113 case GDK_KP_Down:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
114 case GDK_KP_Left:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
115 case GDK_KP_Right:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116 tree_edit_do(ted);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
117 tree_edit_close(ted);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
118 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
119 case GDK_Escape:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
120 tree_edit_close(ted);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
121 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
122 default:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
123 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
124 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
125
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
126 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
127 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
128
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
129 static gboolean tree_edit_by_path_idle_cb(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
130 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
131 TreeEditData *ted = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
132 GdkRectangle rect;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
133 gint x, y, w, h; /* geometry of cell within tree */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
134 gint wx, wy; /* geometry of tree from root window */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
135 gint sx, sw;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
136
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
137 gtk_tree_view_get_cell_area(ted->tree, ted->path, ted->column, &rect);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
138
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
139 x = rect.x;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
140 y = rect.y;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
141 w = rect.width + 4;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
142 h = rect.height + 4;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
143
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
144 if (gtk_tree_view_column_cell_get_position(ted->column, ted->cell, &sx, &sw))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
145 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
146 x += sx;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
147 w = MAX(w - sx, sw);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
148 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
149
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
150 gdk_window_get_origin(gtk_tree_view_get_bin_window(ted->tree), &wx, &wy);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
151
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
152 x += wx - 2; /* the -val is to 'fix' alignment of entry position */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
153 y += wy - 2;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
154
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
155 /* now show it */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
156 gtk_widget_set_size_request(ted->window, w, h);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
157 gtk_widget_realize(ted->window);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
158 gtk_window_move(GTK_WINDOW(ted->window), x, y);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
159 gtk_window_resize(GTK_WINDOW(ted->window), w, h);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
160 gtk_widget_show(ted->window);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
161
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
162 /* grab it */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
163 gtk_widget_grab_focus(ted->entry);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
164 /* explicitely set the focus flag for the entry, for some reason on popup windows this
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
165 * is not set, and causes no edit cursor to appear ( popups not allowed focus? )
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
166 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
167 GTK_WIDGET_SET_FLAGS(ted->entry, GTK_HAS_FOCUS);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
168 gtk_grab_add(ted->window);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
169 gdk_pointer_grab(ted->window->window, TRUE,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
170 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
171 NULL, NULL, GDK_CURRENT_TIME);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
172 gdk_keyboard_grab(ted->window->window, TRUE, GDK_CURRENT_TIME);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
173
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
174 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
175 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
176
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
177 gboolean tree_edit_by_path(GtkTreeView *tree, GtkTreePath *tpath, gint column, const gchar *text,
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
178 gboolean (*edit_func)(TreeEditData *, const gchar *, const gchar *, gpointer), gpointer data)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
179 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
180 TreeEditData *ted;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
181 GtkTreeViewColumn *tcolumn;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
182 GtkCellRenderer *cell = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
183 GList *list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
184 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
185
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
186 if (!edit_func) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
187 if (!GTK_WIDGET_VISIBLE(tree)) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
188
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
189 tcolumn = gtk_tree_view_get_column(tree, column);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
190 if (!tcolumn) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
192 list = gtk_tree_view_column_get_cell_renderers(tcolumn);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
193 work = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
194 while (work && !cell)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196 cell = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 if (!GTK_IS_CELL_RENDERER_TEXT(cell))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
198 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
199 cell = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
200 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
201 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
202 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
203
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
204 g_list_free(list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
205 if (!cell) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
206
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
207 if (!text) text = "";
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
208
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
209 ted = g_new0(TreeEditData, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
210
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
211 ted->old_name = g_strdup(text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
212
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
213 ted->edit_func = edit_func;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
214 ted->edit_data = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216 ted->tree = tree;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217 ted->path = gtk_tree_path_copy(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218 ted->column = tcolumn;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219 ted->cell = cell;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
220
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 gtk_tree_view_scroll_to_cell(ted->tree, ted->path, ted->column, FALSE, 0.0, 0.0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
223 /* create the window */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
224
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
225 ted->window = gtk_window_new(GTK_WINDOW_POPUP);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
226 gtk_window_set_resizable(GTK_WINDOW(ted->window), FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
227 g_signal_connect(G_OBJECT(ted->window), "button_press_event",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
228 G_CALLBACK(tree_edit_click_cb), ted);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 g_signal_connect(G_OBJECT(ted->window), "key_press_event",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230 G_CALLBACK(tree_edit_key_press_cb), ted);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
232 ted->entry = gtk_entry_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 gtk_entry_set_text(GTK_ENTRY(ted->entry), ted->old_name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234 gtk_editable_select_region(GTK_EDITABLE(ted->entry), 0, strlen(ted->old_name));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235 gtk_container_add(GTK_CONTAINER(ted->window), ted->entry);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
236 gtk_widget_show(ted->entry);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
237
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
238 /* due to the fact that gtktreeview scrolls in an idle loop, we cannot
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
239 * reliably get the cell position until those scroll priority signals are processed
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
240 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
241 g_idle_add_full(G_PRIORITY_DEFAULT_IDLE - 2, tree_edit_by_path_idle_cb, ted, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
242
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
243 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
244 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
245
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
246 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
248 * tree cell position retrieval
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
249 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
250 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
251
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
252 gboolean tree_view_get_cell_origin(GtkTreeView *widget, GtkTreePath *tpath, gint column, gboolean text_cell_only,
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
253 gint *x, gint *y, gint *width, gint *height)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
254 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
255 gint x_origin, y_origin;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
256 gint x_offset, y_offset;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
257 gint header_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
258 GtkTreeViewColumn *tv_column;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
259 GdkRectangle rect;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
260
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
261 tv_column = gtk_tree_view_get_column(widget, column);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
262 if (!tv_column || !tpath) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
263
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
264 /* hmm, appears the rect will not account for X scroll, but does for Y scroll
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
265 * use x_offset instead for X scroll (sigh)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
266 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
267 gtk_tree_view_get_cell_area(widget, tpath, tv_column, &rect);
1147
4220d5536ad9 fixed usage of deprecated functions - patch by Omari Stephens
nadvornik
parents: 1055
diff changeset
268 #if GTK_CHECK_VERSION(2,12,0)
4220d5536ad9 fixed usage of deprecated functions - patch by Omari Stephens
nadvornik
parents: 1055
diff changeset
269 gtk_tree_view_convert_tree_to_widget_coords(widget, 0, 0, &x_offset, &y_offset);
1043
5fc64d6252e7 Replaced gtk depreceated code.
bruclik
parents: 958
diff changeset
270 #else
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
271 gtk_tree_view_tree_to_widget_coords(widget, 0, 0, &x_offset, &y_offset);
1043
5fc64d6252e7 Replaced gtk depreceated code.
bruclik
parents: 958
diff changeset
272 #endif
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
273 gdk_window_get_origin(GTK_WIDGET(widget)->window, &x_origin, &y_origin);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
274
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
275 if (gtk_tree_view_get_headers_visible(widget))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
276 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
277 header_size = tv_column->button->allocation.height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
278 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
279 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
280 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
281 header_size = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
282 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
283
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
284 if (text_cell_only)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
285 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
286 GtkCellRenderer *cell = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
287 GList *renderers;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
288 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
289 gint cell_x;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
290 gint cell_width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
291
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
292 renderers = gtk_tree_view_column_get_cell_renderers(tv_column);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
293 work = renderers;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
294 while (work && !cell)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
295 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
296 cell = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
297 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
298 if (!GTK_IS_CELL_RENDERER_TEXT(cell)) cell = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
300 g_list_free(renderers);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
302 if (!cell) return FALSE;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
303
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
304 if (!gtk_tree_view_column_cell_get_position(tv_column, cell, &cell_x, &cell_width))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
305 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
306 cell_x = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
307 cell_width = rect.width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
308 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309 *x = x_origin + x_offset + rect.x + cell_x;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
310 *width = cell_width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
311 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
312 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
313 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
314 *x = x_origin + x_offset + rect.x;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
315 *width = rect.width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
316 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
317 *y = y_origin + rect.y + header_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
318 *height = rect.height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
319 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
320 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
321
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
322 void tree_view_get_cell_clamped(GtkTreeView *widget, GtkTreePath *tpath, gint column, gboolean text_cell_only,
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
323 gint *x, gint *y, gint *width, gint *height)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
324 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
325 gint wx, wy, ww, wh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
326 GdkWindow *window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
328 window = GTK_WIDGET(widget)->window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
329 gdk_window_get_origin(window, &wx, &wy);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
330 gdk_drawable_get_size(window, &ww, &wh);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
331 if (!tree_view_get_cell_origin(widget, tpath, column, text_cell_only, x, y, width, height))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
332 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
333 *x = wx;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
334 *y = wy;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
335 *width = ww;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
336 *height = wh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
337 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
339
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
340 *width = MIN(*width, ww);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
341 *x = CLAMP(*x, wx, wx + ww - (*width));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
342 *y = CLAMP(*y, wy, wy + wh);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
343 *height = MIN(*height, wy + wh - (*y));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
344 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
345
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
346 gint tree_view_row_get_visibility(GtkTreeView *widget, GtkTreeIter *iter, gboolean fully_visible)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
347 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
348 GtkTreeModel *store;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
349 GtkTreePath *tpath;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
350 gint cx, cy;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
351
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
352 GdkRectangle vrect;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353 GdkRectangle crect;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
354
958
419fe0574a34 fixed setting visible entry in view_dir_tree
nadvornik
parents: 513
diff changeset
355 if (!GTK_WIDGET_REALIZED(GTK_WIDGET(widget))) return -1; /* we will most probably scroll down, needed for tree_view_row_make_visible */
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
356
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
357 store = gtk_tree_view_get_model(widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
358 tpath = gtk_tree_model_get_path(store, iter);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
360 gtk_tree_view_get_visible_rect(widget, &vrect);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
361 gtk_tree_view_get_cell_area(widget, tpath, NULL, &crect);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
362 gtk_tree_path_free(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
363
1043
5fc64d6252e7 Replaced gtk depreceated code.
bruclik
parents: 958
diff changeset
364
1147
4220d5536ad9 fixed usage of deprecated functions - patch by Omari Stephens
nadvornik
parents: 1055
diff changeset
365 #if GTK_CHECK_VERSION(2,12,0)
4220d5536ad9 fixed usage of deprecated functions - patch by Omari Stephens
nadvornik
parents: 1055
diff changeset
366 gtk_tree_view_convert_widget_to_tree_coords(widget, crect.x, crect.y, &cx, &cy);
1043
5fc64d6252e7 Replaced gtk depreceated code.
bruclik
parents: 958
diff changeset
367 #else
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
368 gtk_tree_view_widget_to_tree_coords(widget, crect.x, crect.y, &cx, &cy);
1043
5fc64d6252e7 Replaced gtk depreceated code.
bruclik
parents: 958
diff changeset
369 #endif
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
370
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
371 if (fully_visible)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
372 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
373 if (cy < vrect.y) return -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
374 if (cy + crect.height > vrect.y + vrect.height) return 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375 return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378 if (cy + crect.height < vrect.y) return -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379 if (cy > vrect.y + vrect.height) return 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380 return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
381 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
383 gint tree_view_row_make_visible(GtkTreeView *widget, GtkTreeIter *iter, gboolean center)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
384 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385 GtkTreePath *tpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
386 gint vis;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
387
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
388 vis = tree_view_row_get_visibility(widget, iter, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
389
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
390 tpath = gtk_tree_model_get_path(gtk_tree_view_get_model(widget), iter);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
391 if (center && vis != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
392 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393 gtk_tree_view_scroll_to_cell(widget, tpath, NULL, TRUE, 0.5, 0.0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
394 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
395 else if (vis < 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
396 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 gtk_tree_view_scroll_to_cell(widget, tpath, NULL, TRUE, 0.0, 0.0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
398 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
399 else if (vis > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
400 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
401 gtk_tree_view_scroll_to_cell(widget, tpath, NULL, TRUE, 1.0, 0.0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
402 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
403 gtk_tree_path_free(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
404
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
405 return vis;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
406 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
407
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
408 gboolean tree_view_move_cursor_away(GtkTreeView *widget, GtkTreeIter *iter, gboolean only_selected)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
409 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410 GtkTreeModel *store;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
411 GtkTreePath *tpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
412 GtkTreePath *fpath;
1437
a3d3208b0c50 gint -> gboolean.
zas_
parents: 1367
diff changeset
413 gboolean move = FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
414
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415 if (!iter) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417 store = gtk_tree_view_get_model(widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418 tpath = gtk_tree_model_get_path(store, iter);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419 gtk_tree_view_get_cursor(widget, &fpath, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
421 if (fpath && gtk_tree_path_compare(tpath, fpath) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
422 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
423 GtkTreeSelection *selection;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
424
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425 selection = gtk_tree_view_get_selection(widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
427 if (!only_selected ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428 gtk_tree_selection_path_is_selected(selection, tpath))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
430 GtkTreeIter current;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
432 current = *iter;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
433 if (gtk_tree_model_iter_next(store, &current))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
434 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
435 gtk_tree_path_next(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
436 move = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
438 else if (gtk_tree_path_prev(tpath) &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
439 gtk_tree_model_get_iter(store, &current, tpath))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
440 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
441 move = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
442 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
443
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
444 if (move)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
445 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
446 gtk_tree_view_set_cursor(widget, tpath, NULL, FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
448 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
449 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
450
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
451 gtk_tree_path_free(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
452 if (fpath) gtk_tree_path_free(fpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
454 return move;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
455 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
456
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457 gint tree_path_to_row(GtkTreePath *tpath)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
459 gint *indices;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
460
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
461 indices = gtk_tree_path_get_indices(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
462 if (indices) return indices[0];
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
463
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
464 return -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
465 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
466
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
467
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
468 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
469 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
470 * color utilities
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
471 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
472 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
473
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474 void shift_color(GdkColor *src, gshort val, gint direction)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
475 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
476 gshort cs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
477
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
478 if (val == -1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
479 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
480 val = STYLE_SHIFT_STANDARD;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
481 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
482 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
483 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
484 val = CLAMP(val, 1, 100);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
485 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
486 cs = 0xffff / 100 * val;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
487
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
488 /* up or down ? */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
489 if (direction < 0 ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
490 (direction == 0 &&((gint)src->red + (gint)src->green + (gint)src->blue) / 3 > 0xffff / 2))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
491 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
492 src->red = MAX(0 , src->red - cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493 src->green = MAX(0 , src->green - cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
494 src->blue = MAX(0 , src->blue - cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
495 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
496 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
497 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
498 src->red = MIN(0xffff, src->red + cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
499 src->green = MIN(0xffff, src->green + cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
500 src->blue = MIN(0xffff, src->blue + cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
501 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
502 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
503
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
504 /* darkens or lightens a style's color for given state
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
505 * esp. useful for alternating dark/light in (c)lists
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
506 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
507 void style_shift_color(GtkStyle *style, GtkStateType type, gshort shift_value, gint direction)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
508 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
509 if (!style) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
510
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
511 shift_color(&style->base[type], shift_value, direction);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
512 shift_color(&style->bg[type], shift_value, direction);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
513 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
514
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
515 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
516 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
517 * auto scroll by mouse position
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
518 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
519 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
520
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
521 #define AUTO_SCROLL_DEFAULT_SPEED 100
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
522 #define AUTO_SCROLL_DEFAULT_REGION 20
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
523
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
524 typedef struct _AutoScrollData AutoScrollData;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
525 struct _AutoScrollData
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
526 {
1523
24a12aa0cb54 Fix up event source ids type: gint -> guint.
zas_
parents: 1448
diff changeset
527 guint timer_id; /* event source id */
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
528 gint region_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
529 GtkWidget *widget;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
530 GtkAdjustment *adj;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
531 gint max_step;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
532
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
533 gint (*notify_func)(GtkWidget *, gint, gint, gpointer);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
534 gpointer notify_data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
535 };
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
536
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
537 void widget_auto_scroll_stop(GtkWidget *widget)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
538 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
539 AutoScrollData *sd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
540
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
541 sd = g_object_get_data(G_OBJECT(widget), "autoscroll");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
542 if (!sd) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
543 g_object_set_data(G_OBJECT(widget), "autoscroll", NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
544
1523
24a12aa0cb54 Fix up event source ids type: gint -> guint.
zas_
parents: 1448
diff changeset
545 if (sd->timer_id) g_source_remove(sd->timer_id);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
546 g_free(sd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
547 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
548
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
549 static gboolean widget_auto_scroll_cb(gpointer data)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
550 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
551 AutoScrollData *sd = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
552 GdkWindow *window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
553 gint x, y;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
554 gint w, h;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
555 gint amt = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
556
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
557 if (sd->max_step < sd->region_size)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
558 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
559 sd->max_step = MIN(sd->region_size, sd->max_step + 2);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
560 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
561
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
562 window = sd->widget->window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
563 gdk_window_get_pointer(window, &x, &y, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
564 gdk_drawable_get_size(window, &w, &h);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
565
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
566 if (x < 0 || x >= w || y < 0 || y >= h)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
567 {
1523
24a12aa0cb54 Fix up event source ids type: gint -> guint.
zas_
parents: 1448
diff changeset
568 sd->timer_id = 0;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
569 widget_auto_scroll_stop(sd->widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
570 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
571 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
572
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
573 if (h < sd->region_size * 3)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
574 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
575 /* height is cramped, nicely divide into three equal regions */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
576 if (y < h / 3 || y > h / 3 * 2)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
577 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
578 amt = (y < h / 2) ? 0 - ((h / 2) - y) : y - (h / 2);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
579 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
580 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
581 else if (y < sd->region_size)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
582 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
583 amt = 0 - (sd->region_size - y);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
584 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
585 else if (y >= h - sd->region_size)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
586 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
587 amt = y - (h - sd->region_size);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
588 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
589
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
590 if (amt != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
591 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
592 amt = CLAMP(amt, 0 - sd->max_step, sd->max_step);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
593
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
594 if (sd->adj->value != CLAMP(sd->adj->value + amt, sd->adj->lower, sd->adj->upper - sd->adj->page_size))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
595 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
596 /* only notify when scrolling is needed */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
597 if (sd->notify_func && !sd->notify_func(sd->widget, x, y, sd->notify_data))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
598 {
1523
24a12aa0cb54 Fix up event source ids type: gint -> guint.
zas_
parents: 1448
diff changeset
599 sd->timer_id = 0;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
600 widget_auto_scroll_stop(sd->widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
601 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
602 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
603
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
604 gtk_adjustment_set_value(sd->adj,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
605 CLAMP(sd->adj->value + amt, sd->adj->lower, sd->adj->upper - sd->adj->page_size));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
606 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
607 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
608
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
609 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
610 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
611
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
612 gint widget_auto_scroll_start(GtkWidget *widget, GtkAdjustment *v_adj, gint scroll_speed, gint region_size,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
613 gint (*notify_func)(GtkWidget *widget, gint x, gint y, gpointer data), gpointer notify_data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
614 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
615 AutoScrollData *sd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
616
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
617 if (!widget || !v_adj) return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
618 if (g_object_get_data(G_OBJECT(widget), "autoscroll")) return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
619 if (scroll_speed < 1) scroll_speed = AUTO_SCROLL_DEFAULT_SPEED;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
620 if (region_size < 1) region_size = AUTO_SCROLL_DEFAULT_REGION;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
621
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
622 sd = g_new0(AutoScrollData, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
623 sd->widget = widget;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
624 sd->adj = v_adj;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
625 sd->region_size = region_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
626 sd->max_step = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
627 sd->timer_id = g_timeout_add(scroll_speed, widget_auto_scroll_cb, sd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
628
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
629 sd->notify_func = notify_func;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
630 sd->notify_data = notify_data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
631
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
632 g_object_set_data(G_OBJECT(widget), "autoscroll", sd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
633
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
634 return scroll_speed;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
635 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
636
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
637
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
638 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
639 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
640 * GList utils
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
641 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
642 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
643
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
644 GList *uig_list_insert_link(GList *list, GList *link, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
645 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
646 GList *new_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
647
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
648 if (!list || link == list) return g_list_prepend(list, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
649 if (!link) return g_list_append(list, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
650
513
985fdfebd89e Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents: 475
diff changeset
651 new_list = g_list_alloc();
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
652 new_list->data = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
653
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
654 if (link->prev)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
655 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
656 link->prev->next = new_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
657 new_list->prev = link->prev;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
658 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
659 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
660 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
661 list = new_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
662 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
663 link->prev = new_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
664 new_list->next = link;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
665
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
666 return list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
667 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
668
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
669 GList *uig_list_insert_list(GList *parent, GList *insert_link, GList *list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
670 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
671 GList *end;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
672
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
673 if (!insert_link) return g_list_concat(parent, list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
674 if (insert_link == parent) return g_list_concat(list, parent);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
675 if (!parent) return list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
676 if (!list) return parent;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
677
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
678 end = g_list_last(list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
679
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
680 if (insert_link->prev) insert_link->prev->next = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
681 list->prev = insert_link->prev;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
682 insert_link->prev = end;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
683 end->next = insert_link;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
684
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
685 return parent;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
686 }
1055
1646720364cf Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents: 1046
diff changeset
687 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */