annotate src/ui_tree_edit.c @ 784:16b3a5c8aedc

new notification system (used only in vflist for now)
author nadvornik
date Wed, 04 Jun 2008 21:12:47 +0000
parents 985fdfebd89e
children 419fe0574a34
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
475
48c8e49b571c updated copyright in source files
nadvornik
parents: 442
diff changeset
4 * Copyright (C) 2008 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);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
269 gtk_tree_view_tree_to_widget_coords(widget, 0, 0, &x_offset, &y_offset);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
270 gdk_window_get_origin(GTK_WIDGET(widget)->window, &x_origin, &y_origin);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
271
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
272 if (gtk_tree_view_get_headers_visible(widget))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
273 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
274 header_size = tv_column->button->allocation.height;
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 else
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 = 0;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
281 if (text_cell_only)
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 GtkCellRenderer *cell = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
284 GList *renderers;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
285 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
286 gint cell_x;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
287 gint cell_width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
288
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
289 renderers = gtk_tree_view_column_get_cell_renderers(tv_column);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
290 work = renderers;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
291 while (work && !cell)
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 cell = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
294 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
295 if (!GTK_IS_CELL_RENDERER_TEXT(cell)) cell = NULL;
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 g_list_free(renderers);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
298
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299 if (!cell) return FALSE;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
300
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301 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
302 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
303 cell_x = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
304 cell_width = rect.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 *x = x_origin + x_offset + rect.x + cell_x;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
307 *width = cell_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 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
310 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
311 *x = x_origin + x_offset + rect.x;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
312 *width = rect.width;
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 *y = y_origin + rect.y + header_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
315 *height = rect.height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
316 return TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
319 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
320 gint *x, gint *y, gint *width, gint *height)
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 gint wx, wy, ww, wh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
323 GdkWindow *window;
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 window = GTK_WIDGET(widget)->window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
326 gdk_window_get_origin(window, &wx, &wy);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327 gdk_drawable_get_size(window, &ww, &wh);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
328 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
329 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
330 *x = wx;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
331 *y = wy;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
332 *width = ww;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
333 *height = wh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
334 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
335 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
336
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
337 *width = MIN(*width, ww);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338 *x = CLAMP(*x, wx, wx + ww - (*width));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
339 *y = CLAMP(*y, wy, wy + wh);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
340 *height = MIN(*height, wy + wh - (*y));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
341 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
342
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
343 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
344 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
345 GtkTreeModel *store;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
346 GtkTreePath *tpath;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
347 gint cx, cy;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
348
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
349 GdkRectangle vrect;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
350 GdkRectangle crect;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
351
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
352 if (!GTK_WIDGET_REALIZED(GTK_WIDGET(widget))) return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
354 store = gtk_tree_view_get_model(widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
355 tpath = gtk_tree_model_get_path(store, iter);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
356
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
357 gtk_tree_view_get_visible_rect(widget, &vrect);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
358 gtk_tree_view_get_cell_area(widget, tpath, NULL, &crect);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359 gtk_tree_path_free(tpath);
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_widget_to_tree_coords(widget, crect.x, crect.y, &cx, &cy);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
362
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
363 if (fully_visible)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
364 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
365 if (cy < vrect.y) return -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
366 if (cy + crect.height > vrect.y + vrect.height) return 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
367 return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
368 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
369
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
370 if (cy + crect.height < vrect.y) return -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
371 if (cy > vrect.y + vrect.height) return 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
372 return 0;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375 gint tree_view_row_make_visible(GtkTreeView *widget, GtkTreeIter *iter, gint center)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377 GtkTreePath *tpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378 gint vis;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380 vis = tree_view_row_get_visibility(widget, iter, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
381
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382 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
383 if (center && vis != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
384 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385 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
386 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
387 else if (vis < 0)
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 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
390 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
391 else if (vis > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
392 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393 gtk_tree_view_scroll_to_cell(widget, tpath, NULL, TRUE, 1.0, 0.0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
394 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
395 gtk_tree_path_free(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
396
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 return vis;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
398 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
399
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
400 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
401 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
402 GtkTreeModel *store;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
403 GtkTreePath *tpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
404 GtkTreePath *fpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
405 gint move = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
406
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
407 if (!iter) return FALSE;
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 store = gtk_tree_view_get_model(widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410 tpath = gtk_tree_model_get_path(store, iter);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
411 gtk_tree_view_get_cursor(widget, &fpath, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
412
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
413 if (fpath && gtk_tree_path_compare(tpath, fpath) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
414 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415 GtkTreeSelection *selection;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417 selection = gtk_tree_view_get_selection(widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419 if (!only_selected ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420 gtk_tree_selection_path_is_selected(selection, tpath))
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 GtkTreeIter current;
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 current = *iter;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425 if (gtk_tree_model_iter_next(store, &current))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
427 gtk_tree_path_next(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428 move = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
430 else if (gtk_tree_path_prev(tpath) &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431 gtk_tree_model_get_iter(store, &current, tpath))
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 move = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
434 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
435
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
436 if (move)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
438 gtk_tree_view_set_cursor(widget, tpath, NULL, FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
439 }
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 }
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_path_free(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
444 if (fpath) gtk_tree_path_free(fpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
445
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
446 return move;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
448
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
449 gint tree_path_to_row(GtkTreePath *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 gint *indices;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
452
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453 indices = gtk_tree_path_get_indices(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
454 if (indices) return indices[0];
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
455
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
456 return -1;
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
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 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
461 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
462 * color utilities
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
463 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
464 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
465
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
466 void shift_color(GdkColor *src, gshort val, gint direction)
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 gshort cs;
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 if (val == -1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
471 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
472 val = STYLE_SHIFT_STANDARD;
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 else
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 val = CLAMP(val, 1, 100);
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 cs = 0xffff / 100 * val;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
479
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
480 /* up or down ? */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
481 if (direction < 0 ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
482 (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
483 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
484 src->red = MAX(0 , src->red - cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
485 src->green = MAX(0 , src->green - cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
486 src->blue = MAX(0 , src->blue - cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
487 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
488 else
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 src->red = MIN(0xffff, src->red + cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
491 src->green = MIN(0xffff, src->green + cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
492 src->blue = MIN(0xffff, src->blue + cs);
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 /* darkens or lightens a style's color for given state
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
497 * esp. useful for alternating dark/light in (c)lists
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 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
500 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
501 if (!style) return;
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 shift_color(&style->base[type], shift_value, direction);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
504 shift_color(&style->bg[type], shift_value, direction);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
505 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
506
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
507 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
508 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
509 * auto scroll by mouse position
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
510 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
511 */
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 #define AUTO_SCROLL_DEFAULT_SPEED 100
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
514 #define AUTO_SCROLL_DEFAULT_REGION 20
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 typedef struct _AutoScrollData AutoScrollData;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
517 struct _AutoScrollData
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 gint timer_id;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
520 gint region_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
521 GtkWidget *widget;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
522 GtkAdjustment *adj;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
523 gint max_step;
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 gint (*notify_func)(GtkWidget *, gint, gint, gpointer);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
526 gpointer notify_data;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
529 void widget_auto_scroll_stop(GtkWidget *widget)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
530 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
531 AutoScrollData *sd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
532
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
533 sd = g_object_get_data(G_OBJECT(widget), "autoscroll");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
534 if (!sd) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
535 g_object_set_data(G_OBJECT(widget), "autoscroll", NULL);
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 if (sd->timer_id != -1) g_source_remove(sd->timer_id);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
538 g_free(sd);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
541 static gint widget_auto_scroll_cb(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
542 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
543 AutoScrollData *sd = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
544 GdkWindow *window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
545 gint x, y;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
546 gint w, h;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
547 gint amt = 0;
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 if (sd->max_step < sd->region_size)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
550 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
551 sd->max_step = MIN(sd->region_size, sd->max_step + 2);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
554 window = sd->widget->window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
555 gdk_window_get_pointer(window, &x, &y, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
556 gdk_drawable_get_size(window, &w, &h);
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 (x < 0 || x >= w || y < 0 || y >= h)
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->timer_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
561 widget_auto_scroll_stop(sd->widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
562 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
563 }
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 if (h < sd->region_size * 3)
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 /* height is cramped, nicely divide into three equal regions */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
568 if (y < h / 3 || y > h / 3 * 2)
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 amt = (y < h / 2) ? 0 - ((h / 2) - y) : y - (h / 2);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
571 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
572 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
573 else if (y < sd->region_size)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
574 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
575 amt = 0 - (sd->region_size - y);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
576 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
577 else if (y >= h - sd->region_size)
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 - sd->region_size);
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 if (amt != 0)
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 = CLAMP(amt, 0 - sd->max_step, sd->max_step);
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 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
587 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
588 /* only notify when scrolling is needed */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
589 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
590 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
591 sd->timer_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
592 widget_auto_scroll_stop(sd->widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
593 return FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
596 gtk_adjustment_set_value(sd->adj,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
597 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
598 }
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
601 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
602 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
603
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
604 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
605 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
606 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
607 AutoScrollData *sd;
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 if (!widget || !v_adj) return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
610 if (g_object_get_data(G_OBJECT(widget), "autoscroll")) return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
611 if (scroll_speed < 1) scroll_speed = AUTO_SCROLL_DEFAULT_SPEED;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
612 if (region_size < 1) region_size = AUTO_SCROLL_DEFAULT_REGION;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
613
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
614 sd = g_new0(AutoScrollData, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
615 sd->widget = widget;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
616 sd->adj = v_adj;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
617 sd->region_size = region_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
618 sd->max_step = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
619 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
620
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
621 sd->notify_func = notify_func;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
622 sd->notify_data = notify_data;
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 g_object_set_data(G_OBJECT(widget), "autoscroll", sd);
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 return scroll_speed;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
627 }
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
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 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
632 * GList utils
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
633 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
634 */
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 GList *uig_list_insert_link(GList *list, GList *link, gpointer data)
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 GList *new_list;
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 (!list || link == list) return g_list_prepend(list, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
641 if (!link) return g_list_append(list, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
642
513
985fdfebd89e Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents: 475
diff changeset
643 new_list = g_list_alloc();
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
644 new_list->data = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
645
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
646 if (link->prev)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
647 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
648 link->prev->next = new_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
649 new_list->prev = link->prev;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
650 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
651 else
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 list = new_list;
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 link->prev = new_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
656 new_list->next = link;
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 return list;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
661 GList *uig_list_insert_list(GList *parent, GList *insert_link, GList *list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
662 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
663 GList *end;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
664
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
665 if (!insert_link) return g_list_concat(parent, list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
666 if (insert_link == parent) return g_list_concat(list, parent);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
667 if (!parent) return list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
668 if (!list) return parent;
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 end = g_list_last(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 if (insert_link->prev) insert_link->prev->next = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
673 list->prev = insert_link->prev;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
674 insert_link->prev = end;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
675 end->next = insert_link;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
676
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
677 return parent;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
678 }