annotate src/ui_tree_edit.c @ 1343:eebb8d0cb677

give the panes more control over expander title
author nadvornik
date Sat, 28 Feb 2009 19:44:58 +0000
parents 8b89e3ff286b
children fe4da037be21
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
64 static gint tree_edit_click_end_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
74 static gint tree_edit_click_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
99 static gint tree_edit_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
177 gint tree_edit_by_path(GtkTreeView *tree, GtkTreePath *tpath, gint column, const gchar *text,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
178 gint (*edit_func)(TreeEditData *, const gchar *, const gchar *, gpointer), gpointer data)
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 ted->new_name = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
213
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
214 ted->edit_func = edit_func;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215 ted->edit_data = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217 ted->tree = tree;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218 ted->path = gtk_tree_path_copy(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219 ted->column = tcolumn;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
220 ted->cell = cell;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222 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
223
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
224 /* create the window */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
225
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
226 ted->window = gtk_window_new(GTK_WINDOW_POPUP);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
227 gtk_window_set_resizable(GTK_WINDOW(ted->window), FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
228 g_signal_connect(G_OBJECT(ted->window), "button_press_event",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 G_CALLBACK(tree_edit_click_cb), ted);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230 g_signal_connect(G_OBJECT(ted->window), "key_press_event",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231 G_CALLBACK(tree_edit_key_press_cb), ted);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
232
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 ted->entry = gtk_entry_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234 gtk_entry_set_text(GTK_ENTRY(ted->entry), ted->old_name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235 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
236 gtk_container_add(GTK_CONTAINER(ted->window), ted->entry);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
237 gtk_widget_show(ted->entry);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
238
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
239 /* 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
240 * reliably get the cell position until those scroll priority signals are processed
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
241 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
242 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
243
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
244 return TRUE;
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 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
249 * tree cell position retrieval
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 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
252
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
253 gint tree_view_get_cell_origin(GtkTreeView *widget, GtkTreePath *tpath, gint column, gint text_cell_only,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
254 gint *x, gint *y, gint *width, gint *height)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
255 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
256 gint x_origin, y_origin;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
257 gint x_offset, y_offset;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
258 gint header_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
259 GtkTreeViewColumn *tv_column;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
260 GdkRectangle rect;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
261
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
262 tv_column = gtk_tree_view_get_column(widget, column);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
263 if (!tv_column || !tpath) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
264
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
265 /* 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
266 * use x_offset instead for X scroll (sigh)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
267 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
268 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
269 #if GTK_CHECK_VERSION(2,12,0)
4220d5536ad9 fixed usage of deprecated functions - patch by Omari Stephens
nadvornik
parents: 1055
diff changeset
270 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
271 #else
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
272 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
273 #endif
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
274 gdk_window_get_origin(GTK_WIDGET(widget)->window, &x_origin, &y_origin);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
275
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
276 if (gtk_tree_view_get_headers_visible(widget))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
277 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
278 header_size = tv_column->button->allocation.height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
279 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
280 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
281 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
282 header_size = 0;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
285 if (text_cell_only)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
286 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
287 GtkCellRenderer *cell = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
288 GList *renderers;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
289 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
290 gint cell_x;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
291 gint cell_width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
292
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
293 renderers = gtk_tree_view_column_get_cell_renderers(tv_column);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
294 work = renderers;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
295 while (work && !cell)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
296 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
297 cell = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
298 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299 if (!GTK_IS_CELL_RENDERER_TEXT(cell)) cell = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
300 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301 g_list_free(renderers);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
302
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
303 if (!cell) return FALSE;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
304
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
305 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
306 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
307 cell_x = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
308 cell_width = rect.width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
310 *x = x_origin + x_offset + rect.x + cell_x;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
311 *width = cell_width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
312 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
313 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
314 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
315 *x = x_origin + x_offset + rect.x;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
316 *width = rect.width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
317 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
318 *y = y_origin + rect.y + header_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
319 *height = rect.height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
320 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
321 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
322
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
323 void tree_view_get_cell_clamped(GtkTreeView *widget, GtkTreePath *tpath, gint column, gint text_cell_only,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
324 gint *x, gint *y, gint *width, gint *height)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
325 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
326 gint wx, wy, ww, wh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327 GdkWindow *window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
328
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
329 window = GTK_WIDGET(widget)->window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
330 gdk_window_get_origin(window, &wx, &wy);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
331 gdk_drawable_get_size(window, &ww, &wh);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
332 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
333 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
334 *x = wx;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
335 *y = wy;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
336 *width = ww;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
337 *height = wh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338 return;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
341 *width = MIN(*width, ww);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
342 *x = CLAMP(*x, wx, wx + ww - (*width));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
343 *y = CLAMP(*y, wy, wy + wh);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
344 *height = MIN(*height, wy + wh - (*y));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
345 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
346
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
347 gint tree_view_row_get_visibility(GtkTreeView *widget, GtkTreeIter *iter, gint fully_visible)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
348 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
349 GtkTreeModel *store;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
350 GtkTreePath *tpath;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
351 gint cx, cy;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
352
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353 GdkRectangle vrect;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
354 GdkRectangle crect;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
355
958
419fe0574a34 fixed setting visible entry in view_dir_tree
nadvornik
parents: 513
diff changeset
356 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
357
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
358 store = gtk_tree_view_get_model(widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359 tpath = gtk_tree_model_get_path(store, iter);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
360
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
361 gtk_tree_view_get_visible_rect(widget, &vrect);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
362 gtk_tree_view_get_cell_area(widget, tpath, NULL, &crect);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
363 gtk_tree_path_free(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
364
1043
5fc64d6252e7 Replaced gtk depreceated code.
bruclik
parents: 958
diff changeset
365
1147
4220d5536ad9 fixed usage of deprecated functions - patch by Omari Stephens
nadvornik
parents: 1055
diff changeset
366 #if GTK_CHECK_VERSION(2,12,0)
4220d5536ad9 fixed usage of deprecated functions - patch by Omari Stephens
nadvornik
parents: 1055
diff changeset
367 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
368 #else
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
369 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
370 #endif
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
371
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
372 if (fully_visible)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
373 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
374 if (cy < vrect.y) return -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375 if (cy + crect.height > vrect.y + vrect.height) return 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376 return 0;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379 if (cy + crect.height < vrect.y) return -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380 if (cy > vrect.y + vrect.height) return 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
381 return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
383
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
384 gint tree_view_row_make_visible(GtkTreeView *widget, GtkTreeIter *iter, gint center)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
386 GtkTreePath *tpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
387 gint vis;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
388
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
389 vis = tree_view_row_get_visibility(widget, iter, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
390
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
391 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
392 if (center && vis != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
394 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
395 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
396 else if (vis < 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
398 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
399 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
400 else if (vis > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
401 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
402 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
403 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
404 gtk_tree_path_free(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
405
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
406 return vis;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
407 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
408
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
409 gint tree_view_move_cursor_away(GtkTreeView *widget, GtkTreeIter *iter, gint only_selected)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
411 GtkTreeModel *store;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
412 GtkTreePath *tpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
413 GtkTreePath *fpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
414 gint move = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416 if (!iter) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418 store = gtk_tree_view_get_model(widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419 tpath = gtk_tree_model_get_path(store, iter);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420 gtk_tree_view_get_cursor(widget, &fpath, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
421
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
422 if (fpath && gtk_tree_path_compare(tpath, fpath) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
423 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
424 GtkTreeSelection *selection;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426 selection = gtk_tree_view_get_selection(widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
427
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428 if (!only_selected ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429 gtk_tree_selection_path_is_selected(selection, tpath))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
430 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431 GtkTreeIter current;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
432
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
433 current = *iter;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
434 if (gtk_tree_model_iter_next(store, &current))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
435 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
436 gtk_tree_path_next(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437 move = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
438 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
439 else if (gtk_tree_path_prev(tpath) &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
440 gtk_tree_model_get_iter(store, &current, tpath))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
441 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
442 move = TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
445 if (move)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
446 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447 gtk_tree_view_set_cursor(widget, tpath, NULL, FALSE);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
452 gtk_tree_path_free(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453 if (fpath) gtk_tree_path_free(fpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
454
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
455 return move;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458 gint tree_path_to_row(GtkTreePath *tpath)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
459 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
460 gint *indices;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
461
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
462 indices = gtk_tree_path_get_indices(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
463 if (indices) return indices[0];
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
464
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
465 return -1;
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 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
471 * color utilities
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
475 void shift_color(GdkColor *src, gshort val, gint direction)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
476 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
477 gshort cs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
478
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
479 if (val == -1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
480 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
481 val = STYLE_SHIFT_STANDARD;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
482 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
483 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
484 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
485 val = CLAMP(val, 1, 100);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
486 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
487 cs = 0xffff / 100 * val;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
488
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
489 /* up or down ? */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
490 if (direction < 0 ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
491 (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
492 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493 src->red = MAX(0 , src->red - cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
494 src->green = MAX(0 , src->green - cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
495 src->blue = MAX(0 , src->blue - cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
496 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
497 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
498 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
499 src->red = MIN(0xffff, src->red + cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
500 src->green = MIN(0xffff, src->green + cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
501 src->blue = MIN(0xffff, src->blue + cs);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
505 /* darkens or lightens a style's color for given state
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
506 * esp. useful for alternating dark/light in (c)lists
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
507 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
508 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
509 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
510 if (!style) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
511
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
512 shift_color(&style->base[type], shift_value, direction);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
513 shift_color(&style->bg[type], shift_value, direction);
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 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
518 * auto scroll by mouse position
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
522 #define AUTO_SCROLL_DEFAULT_SPEED 100
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
523 #define AUTO_SCROLL_DEFAULT_REGION 20
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
524
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
525 typedef struct _AutoScrollData AutoScrollData;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
526 struct _AutoScrollData
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
527 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
528 gint timer_id;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
529 gint region_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
530 GtkWidget *widget;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
531 GtkAdjustment *adj;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
532 gint max_step;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
533
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
534 gint (*notify_func)(GtkWidget *, gint, gint, gpointer);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
535 gpointer notify_data;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
538 void widget_auto_scroll_stop(GtkWidget *widget)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
539 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
540 AutoScrollData *sd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
541
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
542 sd = g_object_get_data(G_OBJECT(widget), "autoscroll");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
543 if (!sd) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
544 g_object_set_data(G_OBJECT(widget), "autoscroll", NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
545
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
546 if (sd->timer_id != -1) g_source_remove(sd->timer_id);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
547 g_free(sd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
548 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
549
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
550 static gint widget_auto_scroll_cb(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
551 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
552 AutoScrollData *sd = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
553 GdkWindow *window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
554 gint x, y;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
555 gint w, h;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
556 gint amt = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
557
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
558 if (sd->max_step < sd->region_size)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
559 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
560 sd->max_step = MIN(sd->region_size, sd->max_step + 2);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
563 window = sd->widget->window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
564 gdk_window_get_pointer(window, &x, &y, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
565 gdk_drawable_get_size(window, &w, &h);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
566
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
567 if (x < 0 || x >= w || y < 0 || y >= h)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
568 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
569 sd->timer_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
570 widget_auto_scroll_stop(sd->widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
571 return FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
574 if (h < sd->region_size * 3)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
575 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
576 /* height is cramped, nicely divide into three equal regions */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
577 if (y < h / 3 || y > h / 3 * 2)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
578 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
579 amt = (y < h / 2) ? 0 - ((h / 2) - y) : y - (h / 2);
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 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
582 else if (y < sd->region_size)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
583 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
584 amt = 0 - (sd->region_size - y);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
585 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
586 else if (y >= h - sd->region_size)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
587 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
588 amt = y - (h - sd->region_size);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
591 if (amt != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
592 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
593 amt = CLAMP(amt, 0 - sd->max_step, sd->max_step);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
594
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
595 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
596 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
597 /* only notify when scrolling is needed */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
598 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
599 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
600 sd->timer_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
601 widget_auto_scroll_stop(sd->widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
602 return FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
605 gtk_adjustment_set_value(sd->adj,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
606 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
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
610 return TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
613 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
614 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
615 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
616 AutoScrollData *sd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
617
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
618 if (!widget || !v_adj) return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
619 if (g_object_get_data(G_OBJECT(widget), "autoscroll")) return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
620 if (scroll_speed < 1) scroll_speed = AUTO_SCROLL_DEFAULT_SPEED;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
621 if (region_size < 1) region_size = AUTO_SCROLL_DEFAULT_REGION;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
622
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
623 sd = g_new0(AutoScrollData, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
624 sd->widget = widget;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
625 sd->adj = v_adj;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
626 sd->region_size = region_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
627 sd->max_step = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
628 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
629
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
630 sd->notify_func = notify_func;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
631 sd->notify_data = notify_data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
632
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
633 g_object_set_data(G_OBJECT(widget), "autoscroll", sd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
634
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
635 return scroll_speed;
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 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
641 * GList utils
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
645 GList *uig_list_insert_link(GList *list, GList *link, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
646 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
647 GList *new_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
648
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
649 if (!list || link == list) return g_list_prepend(list, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
650 if (!link) return g_list_append(list, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
651
513
985fdfebd89e Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents: 475
diff changeset
652 new_list = g_list_alloc();
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
653 new_list->data = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
654
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
655 if (link->prev)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
656 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
657 link->prev->next = new_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
658 new_list->prev = link->prev;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
659 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
660 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
661 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
662 list = new_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
663 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
664 link->prev = new_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
665 new_list->next = link;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
666
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
667 return list;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
670 GList *uig_list_insert_list(GList *parent, GList *insert_link, GList *list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
671 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
672 GList *end;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
673
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
674 if (!insert_link) return g_list_concat(parent, list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
675 if (insert_link == parent) return g_list_concat(list, parent);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
676 if (!parent) return list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
677 if (!list) return parent;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
678
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
679 end = g_list_last(list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
680
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
681 if (insert_link->prev) insert_link->prev->next = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
682 list->prev = insert_link->prev;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
683 insert_link->prev = end;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
684 end->next = insert_link;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
685
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
686 return parent;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
687 }
1055
1646720364cf Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents: 1046
diff changeset
688 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */