annotate src/ui_tree_edit.c @ 1650:c16f499ea1ce

made file_util_start_editor_from_file consider also sidecars
author nadvornik
date Wed, 17 Jun 2009 18:41:10 +0000
parents 2349fa90226d
children 9a351e8f3b97
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
1631
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
346 #if GTK_CHECK_VERSION(2,8,0)
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
347 /* an implementation that uses gtk_tree_view_get_visible_range */
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
348 gint tree_view_row_get_visibility(GtkTreeView *widget, GtkTreeIter *iter, gboolean fully_visible)
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
349 {
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
350 GtkTreeModel *store;
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
351 GtkTreePath *tpath, *start_path, *end_path;
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
352 gint ret = 0;
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
353
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
354 if (!gtk_tree_view_get_visible_range(widget, &start_path, &end_path)) return -1; /* we will most probably scroll down, needed for tree_view_row_make_visible */
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
355
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
356 store = gtk_tree_view_get_model(widget);
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
357 tpath = gtk_tree_model_get_path(store, iter);
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
358
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
359 if (fully_visible)
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
360 {
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
361 if (gtk_tree_path_compare(tpath, start_path) <= 0)
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
362 {
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
363 ret = -1;
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
364 }
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
365 else if (gtk_tree_path_compare(tpath, end_path) >= 0)
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
366 {
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
367 ret = 1;
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
368 }
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
369 }
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
370 else
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
371 {
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
372 if (gtk_tree_path_compare(tpath, start_path) < 0)
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
373 {
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
374 ret = -1;
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
375 }
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
376 else if (gtk_tree_path_compare(tpath, end_path) > 0)
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
377 {
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
378 ret = 1;
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
379 }
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
380 }
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
381
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
382 gtk_tree_path_free(tpath);
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
383 gtk_tree_path_free(start_path);
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
384 gtk_tree_path_free(end_path);
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
385 return ret;
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
386 }
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
387
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
388 #else
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
389 /* an implementation that uses gtk_tree_view_get_visible_rect, it seems to be more error prone than the variant above */
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
390
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
391 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
392 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393 GtkTreeModel *store;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
394 GtkTreePath *tpath;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
395 gint cx, cy;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
396
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 GdkRectangle vrect;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
398 GdkRectangle crect;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
399
958
419fe0574a34 fixed setting visible entry in view_dir_tree
nadvornik
parents: 513
diff changeset
400 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
401
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
402 store = gtk_tree_view_get_model(widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
403 tpath = gtk_tree_model_get_path(store, iter);
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 gtk_tree_view_get_visible_rect(widget, &vrect);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
406 gtk_tree_view_get_cell_area(widget, tpath, NULL, &crect);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
407 gtk_tree_path_free(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
408
1043
5fc64d6252e7 Replaced gtk depreceated code.
bruclik
parents: 958
diff changeset
409
1147
4220d5536ad9 fixed usage of deprecated functions - patch by Omari Stephens
nadvornik
parents: 1055
diff changeset
410 #if GTK_CHECK_VERSION(2,12,0)
4220d5536ad9 fixed usage of deprecated functions - patch by Omari Stephens
nadvornik
parents: 1055
diff changeset
411 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
412 #else
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
413 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
414 #endif
9
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 (fully_visible)
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 if (cy < vrect.y) return -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419 if (cy + crect.height > vrect.y + vrect.height) return 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420 return 0;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
423 if (cy + crect.height < vrect.y) return -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
424 if (cy > vrect.y + vrect.height) return 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425 return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426 }
1631
2349fa90226d better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
427 #endif
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
429 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
430 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431 GtkTreePath *tpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
432 gint vis;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
433
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
434 vis = tree_view_row_get_visibility(widget, iter, TRUE);
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 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
437 if (center && vis != 0)
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 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
440 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
441 else if (vis < 0)
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 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
444 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
445 else if (vis > 0)
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_scroll_to_cell(widget, tpath, NULL, TRUE, 1.0, 0.0);
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 gtk_tree_path_free(tpath);
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 return vis;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
452 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
454 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
455 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
456 GtkTreeModel *store;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457 GtkTreePath *tpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458 GtkTreePath *fpath;
1437
a3d3208b0c50 gint -> gboolean.
zas_
parents: 1367
diff changeset
459 gboolean move = FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
460
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
461 if (!iter) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
462
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
463 store = gtk_tree_view_get_model(widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
464 tpath = gtk_tree_model_get_path(store, iter);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
465 gtk_tree_view_get_cursor(widget, &fpath, NULL);
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 if (fpath && gtk_tree_path_compare(tpath, fpath) == 0)
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 GtkTreeSelection *selection;
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 selection = gtk_tree_view_get_selection(widget);
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 if (!only_selected ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474 gtk_tree_selection_path_is_selected(selection, tpath))
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 GtkTreeIter current;
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 current = *iter;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
479 if (gtk_tree_model_iter_next(store, &current))
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 gtk_tree_path_next(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
482 move = TRUE;
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 else if (gtk_tree_path_prev(tpath) &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
485 gtk_tree_model_get_iter(store, &current, tpath))
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 move = TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
490 if (move)
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 gtk_tree_view_set_cursor(widget, tpath, NULL, FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
494 }
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
497 gtk_tree_path_free(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
498 if (fpath) gtk_tree_path_free(fpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
499
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
500 return move;
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 gint tree_path_to_row(GtkTreePath *tpath)
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 gint *indices;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
506
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
507 indices = gtk_tree_path_get_indices(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
508 if (indices) return indices[0];
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
509
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
510 return -1;
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
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 * color utilities
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 */
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 void shift_color(GdkColor *src, gshort val, gint direction)
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 gshort cs;
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 if (val == -1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
525 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
526 val = STYLE_SHIFT_STANDARD;
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 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
529 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
530 val = CLAMP(val, 1, 100);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
531 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
532 cs = 0xffff / 100 * val;
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 /* up or down ? */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
535 if (direction < 0 ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
536 (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
537 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
538 src->red = MAX(0 , src->red - cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
539 src->green = MAX(0 , src->green - cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
540 src->blue = MAX(0 , src->blue - cs);
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 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
543 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
544 src->red = MIN(0xffff, src->red + cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
545 src->green = MIN(0xffff, src->green + cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
546 src->blue = MIN(0xffff, src->blue + cs);
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 }
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 /* darkens or lightens a style's color for given state
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
551 * esp. useful for alternating dark/light in (c)lists
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
552 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
553 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
554 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
555 if (!style) return;
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 shift_color(&style->base[type], shift_value, direction);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
558 shift_color(&style->bg[type], shift_value, direction);
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
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 * auto scroll by mouse position
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
564 *-------------------------------------------------------------------
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
567 #define AUTO_SCROLL_DEFAULT_SPEED 100
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
568 #define AUTO_SCROLL_DEFAULT_REGION 20
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
569
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
570 typedef struct _AutoScrollData AutoScrollData;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
571 struct _AutoScrollData
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
572 {
1523
24a12aa0cb54 Fix up event source ids type: gint -> guint.
zas_
parents: 1448
diff changeset
573 guint timer_id; /* event source id */
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
574 gint region_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
575 GtkWidget *widget;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
576 GtkAdjustment *adj;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
577 gint max_step;
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 gint (*notify_func)(GtkWidget *, gint, gint, gpointer);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
580 gpointer notify_data;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
583 void widget_auto_scroll_stop(GtkWidget *widget)
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 AutoScrollData *sd;
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 sd = g_object_get_data(G_OBJECT(widget), "autoscroll");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
588 if (!sd) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
589 g_object_set_data(G_OBJECT(widget), "autoscroll", NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
590
1523
24a12aa0cb54 Fix up event source ids type: gint -> guint.
zas_
parents: 1448
diff changeset
591 if (sd->timer_id) g_source_remove(sd->timer_id);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
592 g_free(sd);
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
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
595 static gboolean widget_auto_scroll_cb(gpointer data)
9
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 AutoScrollData *sd = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
598 GdkWindow *window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
599 gint x, y;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
600 gint w, h;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
601 gint amt = 0;
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 if (sd->max_step < sd->region_size)
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 sd->max_step = MIN(sd->region_size, sd->max_step + 2);
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 window = sd->widget->window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
609 gdk_window_get_pointer(window, &x, &y, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
610 gdk_drawable_get_size(window, &w, &h);
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 if (x < 0 || x >= w || y < 0 || y >= h)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
613 {
1523
24a12aa0cb54 Fix up event source ids type: gint -> guint.
zas_
parents: 1448
diff changeset
614 sd->timer_id = 0;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
615 widget_auto_scroll_stop(sd->widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
616 return FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
619 if (h < sd->region_size * 3)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
620 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
621 /* height is cramped, nicely divide into three equal regions */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
622 if (y < h / 3 || y > h / 3 * 2)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
623 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
624 amt = (y < h / 2) ? 0 - ((h / 2) - y) : y - (h / 2);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
625 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
626 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
627 else if (y < sd->region_size)
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 amt = 0 - (sd->region_size - y);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
630 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
631 else if (y >= h - sd->region_size)
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 amt = y - (h - sd->region_size);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
636 if (amt != 0)
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 amt = CLAMP(amt, 0 - sd->max_step, sd->max_step);
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 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
641 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
642 /* only notify when scrolling is needed */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
643 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
644 {
1523
24a12aa0cb54 Fix up event source ids type: gint -> guint.
zas_
parents: 1448
diff changeset
645 sd->timer_id = 0;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
646 widget_auto_scroll_stop(sd->widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
647 return FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
650 gtk_adjustment_set_value(sd->adj,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
651 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
652 }
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
655 return TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
658 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
659 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
660 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
661 AutoScrollData *sd;
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 if (!widget || !v_adj) return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
664 if (g_object_get_data(G_OBJECT(widget), "autoscroll")) return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
665 if (scroll_speed < 1) scroll_speed = AUTO_SCROLL_DEFAULT_SPEED;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
666 if (region_size < 1) region_size = AUTO_SCROLL_DEFAULT_REGION;
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 sd = g_new0(AutoScrollData, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
669 sd->widget = widget;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
670 sd->adj = v_adj;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
671 sd->region_size = region_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
672 sd->max_step = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
673 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
674
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
675 sd->notify_func = notify_func;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
676 sd->notify_data = notify_data;
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 g_object_set_data(G_OBJECT(widget), "autoscroll", sd);
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 return scroll_speed;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
681 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
682
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
683
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 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
686 * GList utils
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
687 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
688 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
689
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
690 GList *uig_list_insert_link(GList *list, GList *link, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
691 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
692 GList *new_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
693
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
694 if (!list || link == list) return g_list_prepend(list, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
695 if (!link) return g_list_append(list, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
696
513
985fdfebd89e Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents: 475
diff changeset
697 new_list = g_list_alloc();
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
698 new_list->data = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
699
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
700 if (link->prev)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
701 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
702 link->prev->next = new_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
703 new_list->prev = link->prev;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
704 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
705 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
706 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
707 list = new_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
708 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
709 link->prev = new_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
710 new_list->next = link;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
711
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
712 return list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
713 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
714
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
715 GList *uig_list_insert_list(GList *parent, GList *insert_link, GList *list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
716 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
717 GList *end;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
718
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
719 if (!insert_link) return g_list_concat(parent, list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
720 if (insert_link == parent) return g_list_concat(list, parent);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
721 if (!parent) return list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
722 if (!list) return parent;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
723
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
724 end = g_list_last(list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
725
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
726 if (insert_link->prev) insert_link->prev->next = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
727 list->prev = insert_link->prev;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
728 insert_link->prev = end;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
729 end->next = insert_link;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
730
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
731 return parent;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
732 }
1055
1646720364cf Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents: 1046
diff changeset
733 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */