annotate src/ui_tree_edit.c @ 1752:7cd0f91329e2

import 1768 and 1789 together
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Fri, 29 Jan 2010 19:16:00 +0900
parents 760e8d68290c
children
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
1729
760e8d68290c Add compatibility for GTK 2.18
mow
parents: 1629
diff changeset
192 #if GTK_CHECK_VERSION(2,18,0)
760e8d68290c Add compatibility for GTK 2.18
mow
parents: 1629
diff changeset
193 list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(tcolumn));
760e8d68290c Add compatibility for GTK 2.18
mow
parents: 1629
diff changeset
194 #else
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195 list = gtk_tree_view_column_get_cell_renderers(tcolumn);
1729
760e8d68290c Add compatibility for GTK 2.18
mow
parents: 1629
diff changeset
196 #endif
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 work = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
198 while (work && !cell)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
199 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
200 cell = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
201 if (!GTK_IS_CELL_RENDERER_TEXT(cell))
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 cell = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
204 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
205 work = work->next;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
208 g_list_free(list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
209 if (!cell) return FALSE;
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 if (!text) 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 = g_new0(TreeEditData, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
214
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215 ted->old_name = g_strdup(text);
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->edit_func = edit_func;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218 ted->edit_data = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
220 ted->tree = tree;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 ted->path = gtk_tree_path_copy(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222 ted->column = tcolumn;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
223 ted->cell = cell;
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 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
226
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
227 /* create the window */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
228
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 ted->window = gtk_window_new(GTK_WINDOW_POPUP);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230 gtk_window_set_resizable(GTK_WINDOW(ted->window), FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231 g_signal_connect(G_OBJECT(ted->window), "button_press_event",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
232 G_CALLBACK(tree_edit_click_cb), ted);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 g_signal_connect(G_OBJECT(ted->window), "key_press_event",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234 G_CALLBACK(tree_edit_key_press_cb), ted);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
236 ted->entry = gtk_entry_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
237 gtk_entry_set_text(GTK_ENTRY(ted->entry), ted->old_name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
238 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
239 gtk_container_add(GTK_CONTAINER(ted->window), ted->entry);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
240 gtk_widget_show(ted->entry);
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 /* 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
243 * reliably get the cell position until those scroll priority signals are processed
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 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
246
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247 return TRUE;
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
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 * tree cell position retrieval
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
253 *-------------------------------------------------------------------
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
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
256 gboolean tree_view_get_cell_origin(GtkTreeView *widget, GtkTreePath *tpath, gint column, gboolean text_cell_only,
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
257 gint *x, gint *y, gint *width, gint *height)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
258 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
259 gint x_origin, y_origin;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
260 gint x_offset, y_offset;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
261 gint header_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
262 GtkTreeViewColumn *tv_column;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
263 GdkRectangle rect;
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 tv_column = gtk_tree_view_get_column(widget, column);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
266 if (!tv_column || !tpath) return FALSE;
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 /* 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
269 * use x_offset instead for X scroll (sigh)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
270 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
271 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
272 #if GTK_CHECK_VERSION(2,12,0)
4220d5536ad9 fixed usage of deprecated functions - patch by Omari Stephens
nadvornik
parents: 1055
diff changeset
273 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
274 #else
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
275 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
276 #endif
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
277 gdk_window_get_origin(GTK_WIDGET(widget)->window, &x_origin, &y_origin);
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 if (gtk_tree_view_get_headers_visible(widget))
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 = tv_column->button->allocation.height;
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 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
284 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
285 header_size = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
286 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
287
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
288 if (text_cell_only)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
289 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
290 GtkCellRenderer *cell = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
291 GList *renderers;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
292 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
293 gint cell_x;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
294 gint cell_width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
295
1729
760e8d68290c Add compatibility for GTK 2.18
mow
parents: 1629
diff changeset
296 #if GTK_CHECK_VERSION(2,18,0)
760e8d68290c Add compatibility for GTK 2.18
mow
parents: 1629
diff changeset
297 renderers = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(tv_column));
760e8d68290c Add compatibility for GTK 2.18
mow
parents: 1629
diff changeset
298 #else
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299 renderers = gtk_tree_view_column_get_cell_renderers(tv_column);
1729
760e8d68290c Add compatibility for GTK 2.18
mow
parents: 1629
diff changeset
300 #endif
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301 work = renderers;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
302 while (work && !cell)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
303 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
304 cell = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
305 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
306 if (!GTK_IS_CELL_RENDERER_TEXT(cell)) cell = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
307 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
308 g_list_free(renderers);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
310 if (!cell) return FALSE;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
311
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
312 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
313 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
314 cell_x = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
315 cell_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 *x = x_origin + x_offset + rect.x + cell_x;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
318 *width = cell_width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
319 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
320 else
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 *x = x_origin + x_offset + rect.x;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
323 *width = rect.width;
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 *y = y_origin + rect.y + header_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
326 *height = rect.height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
328 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
329
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
330 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
331 gint *x, gint *y, gint *width, gint *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 gint wx, wy, ww, wh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
334 GdkWindow *window;
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 window = GTK_WIDGET(widget)->window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
337 gdk_window_get_origin(window, &wx, &wy);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338 gdk_drawable_get_size(window, &ww, &wh);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
339 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
340 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
341 *x = wx;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
342 *y = wy;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
343 *width = ww;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
344 *height = wh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
345 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
346 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
347
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
348 *width = MIN(*width, ww);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
349 *x = CLAMP(*x, wx, wx + ww - (*width));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
350 *y = CLAMP(*y, wy, wy + wh);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
351 *height = MIN(*height, wy + wh - (*y));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
352 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353
1629
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
354 #if GTK_CHECK_VERSION(2,8,0)
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
355 /* an implementation that uses gtk_tree_view_get_visible_range */
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
356 gint tree_view_row_get_visibility(GtkTreeView *widget, GtkTreeIter *iter, gboolean fully_visible)
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
357 {
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
358 GtkTreeModel *store;
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
359 GtkTreePath *tpath, *start_path, *end_path;
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
360 gint ret = 0;
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
361
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
362 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 */
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
363
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
364 store = gtk_tree_view_get_model(widget);
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
365 tpath = gtk_tree_model_get_path(store, iter);
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
366
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
367 if (fully_visible)
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
368 {
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
369 if (gtk_tree_path_compare(tpath, start_path) <= 0)
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
370 {
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
371 ret = -1;
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
372 }
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
373 else if (gtk_tree_path_compare(tpath, end_path) >= 0)
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
374 {
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
375 ret = 1;
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
376 }
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
377 }
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
378 else
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
379 {
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
380 if (gtk_tree_path_compare(tpath, start_path) < 0)
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
381 {
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
382 ret = -1;
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
383 }
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
384 else if (gtk_tree_path_compare(tpath, end_path) > 0)
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
385 {
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
386 ret = 1;
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
387 }
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
388 }
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
389
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
390 gtk_tree_path_free(tpath);
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
391 gtk_tree_path_free(start_path);
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
392 gtk_tree_path_free(end_path);
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
393 return ret;
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
394 }
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
395
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
396 #else
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
397 /* an implementation that uses gtk_tree_view_get_visible_rect, it seems to be more error prone than the variant above */
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
398
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
399 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
400 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
401 GtkTreeModel *store;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
402 GtkTreePath *tpath;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
403 gint cx, cy;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
404
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
405 GdkRectangle vrect;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
406 GdkRectangle crect;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
407
958
419fe0574a34 fixed setting visible entry in view_dir_tree
nadvornik
parents: 513
diff changeset
408 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
409
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410 store = gtk_tree_view_get_model(widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
411 tpath = gtk_tree_model_get_path(store, iter);
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 gtk_tree_view_get_visible_rect(widget, &vrect);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
414 gtk_tree_view_get_cell_area(widget, tpath, NULL, &crect);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415 gtk_tree_path_free(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416
1043
5fc64d6252e7 Replaced gtk depreceated code.
bruclik
parents: 958
diff changeset
417
1147
4220d5536ad9 fixed usage of deprecated functions - patch by Omari Stephens
nadvornik
parents: 1055
diff changeset
418 #if GTK_CHECK_VERSION(2,12,0)
4220d5536ad9 fixed usage of deprecated functions - patch by Omari Stephens
nadvornik
parents: 1055
diff changeset
419 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
420 #else
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
421 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
422 #endif
9
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 if (fully_visible)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426 if (cy < vrect.y) return -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
427 if (cy + crect.height > vrect.y + vrect.height) return 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428 return 0;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431 if (cy + crect.height < vrect.y) return -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
432 if (cy > vrect.y + vrect.height) return 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
433 return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
434 }
1629
f8503019ac38 better implementation of tree_view_row_get_visibility,
nadvornik
parents: 1523
diff changeset
435 #endif
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
436
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
437 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
438 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
439 GtkTreePath *tpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
440 gint vis;
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 vis = tree_view_row_get_visibility(widget, iter, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
443
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
444 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
445 if (center && 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, 0.5, 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 else if (vis < 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
450 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
451 gtk_tree_view_scroll_to_cell(widget, tpath, NULL, TRUE, 0.0, 0.0);
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 else if (vis > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
454 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
455 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
456 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457 gtk_tree_path_free(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
459 return vis;
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
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
462 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
463 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
464 GtkTreeModel *store;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
465 GtkTreePath *tpath;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
466 GtkTreePath *fpath;
1437
a3d3208b0c50 gint -> gboolean.
zas_
parents: 1367
diff changeset
467 gboolean move = FALSE;
9
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 if (!iter) return FALSE;
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 store = gtk_tree_view_get_model(widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
472 tpath = gtk_tree_model_get_path(store, iter);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
473 gtk_tree_view_get_cursor(widget, &fpath, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
475 if (fpath && gtk_tree_path_compare(tpath, fpath) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
476 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
477 GtkTreeSelection *selection;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
478
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
479 selection = gtk_tree_view_get_selection(widget);
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 if (!only_selected ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
482 gtk_tree_selection_path_is_selected(selection, tpath))
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 GtkTreeIter current;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
485
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
486 current = *iter;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
487 if (gtk_tree_model_iter_next(store, &current))
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 gtk_tree_path_next(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
490 move = TRUE;
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 else if (gtk_tree_path_prev(tpath) &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493 gtk_tree_model_get_iter(store, &current, tpath))
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 move = TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
498 if (move)
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 gtk_tree_view_set_cursor(widget, tpath, NULL, FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
501 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
502 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
503 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
504
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
505 gtk_tree_path_free(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
506 if (fpath) gtk_tree_path_free(fpath);
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 return move;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
509 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
510
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
511 gint tree_path_to_row(GtkTreePath *tpath)
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 gint *indices;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
514
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
515 indices = gtk_tree_path_get_indices(tpath);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
516 if (indices) return indices[0];
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 9
diff changeset
517
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
518 return -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
519 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
520
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
521
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
522 /*
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 * color utilities
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 */
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 void shift_color(GdkColor *src, gshort val, gint direction)
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 gshort cs;
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 if (val == -1)
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 val = STYLE_SHIFT_STANDARD;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
535 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
536 else
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 val = CLAMP(val, 1, 100);
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 cs = 0xffff / 100 * val;
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 /* up or down ? */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
543 if (direction < 0 ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
544 (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
545 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
546 src->red = MAX(0 , src->red - cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
547 src->green = MAX(0 , src->green - cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
548 src->blue = MAX(0 , src->blue - cs);
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 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
551 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
552 src->red = MIN(0xffff, src->red + cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
553 src->green = MIN(0xffff, src->green + cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
554 src->blue = MIN(0xffff, src->blue + cs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
555 }
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
558 /* darkens or lightens a style's color for given state
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
559 * esp. useful for alternating dark/light in (c)lists
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 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
562 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
563 if (!style) return;
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 shift_color(&style->base[type], shift_value, direction);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
566 shift_color(&style->bg[type], shift_value, direction);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
567 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
568
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
569 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
570 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
571 * auto scroll by mouse position
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
572 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
573 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
574
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
575 #define AUTO_SCROLL_DEFAULT_SPEED 100
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
576 #define AUTO_SCROLL_DEFAULT_REGION 20
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
577
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
578 typedef struct _AutoScrollData AutoScrollData;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
579 struct _AutoScrollData
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
580 {
1523
24a12aa0cb54 Fix up event source ids type: gint -> guint.
zas_
parents: 1448
diff changeset
581 guint timer_id; /* event source id */
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
582 gint region_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
583 GtkWidget *widget;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
584 GtkAdjustment *adj;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
585 gint max_step;
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 gint (*notify_func)(GtkWidget *, gint, gint, gpointer);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
588 gpointer notify_data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
589 };
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
590
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
591 void widget_auto_scroll_stop(GtkWidget *widget)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
592 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
593 AutoScrollData *sd;
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 sd = g_object_get_data(G_OBJECT(widget), "autoscroll");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
596 if (!sd) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
597 g_object_set_data(G_OBJECT(widget), "autoscroll", NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
598
1523
24a12aa0cb54 Fix up event source ids type: gint -> guint.
zas_
parents: 1448
diff changeset
599 if (sd->timer_id) g_source_remove(sd->timer_id);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
600 g_free(sd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
601 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
602
1448
89dedc61b1bd gint -> gboolean.
zas_
parents: 1437
diff changeset
603 static gboolean widget_auto_scroll_cb(gpointer data)
9
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 AutoScrollData *sd = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
606 GdkWindow *window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
607 gint x, y;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
608 gint w, h;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
609 gint amt = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
610
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
611 if (sd->max_step < sd->region_size)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
612 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
613 sd->max_step = MIN(sd->region_size, sd->max_step + 2);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
614 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
615
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
616 window = sd->widget->window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
617 gdk_window_get_pointer(window, &x, &y, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
618 gdk_drawable_get_size(window, &w, &h);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
619
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
620 if (x < 0 || x >= w || y < 0 || y >= h)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
621 {
1523
24a12aa0cb54 Fix up event source ids type: gint -> guint.
zas_
parents: 1448
diff changeset
622 sd->timer_id = 0;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
623 widget_auto_scroll_stop(sd->widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
624 return FALSE;
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 if (h < sd->region_size * 3)
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 /* height is cramped, nicely divide into three equal regions */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
630 if (y < h / 3 || y > h / 3 * 2)
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 amt = (y < h / 2) ? 0 - ((h / 2) - y) : y - (h / 2);
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 else if (y < sd->region_size)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
636 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
637 amt = 0 - (sd->region_size - y);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
638 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
639 else if (y >= h - sd->region_size)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
640 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
641 amt = y - (h - sd->region_size);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
642 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
643
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
644 if (amt != 0)
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 amt = CLAMP(amt, 0 - sd->max_step, sd->max_step);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
647
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
648 if (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
649 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
650 /* only notify when scrolling is needed */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
651 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
652 {
1523
24a12aa0cb54 Fix up event source ids type: gint -> guint.
zas_
parents: 1448
diff changeset
653 sd->timer_id = 0;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
654 widget_auto_scroll_stop(sd->widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
655 return FALSE;
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 gtk_adjustment_set_value(sd->adj,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
659 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
660 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
661 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
662
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
663 return TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
666 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
667 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
668 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
669 AutoScrollData *sd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
670
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
671 if (!widget || !v_adj) return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
672 if (g_object_get_data(G_OBJECT(widget), "autoscroll")) return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
673 if (scroll_speed < 1) scroll_speed = AUTO_SCROLL_DEFAULT_SPEED;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
674 if (region_size < 1) region_size = AUTO_SCROLL_DEFAULT_REGION;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
675
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
676 sd = g_new0(AutoScrollData, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
677 sd->widget = widget;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
678 sd->adj = v_adj;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
679 sd->region_size = region_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
680 sd->max_step = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
681 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
682
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
683 sd->notify_func = notify_func;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
684 sd->notify_data = notify_data;
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 g_object_set_data(G_OBJECT(widget), "autoscroll", sd);
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 return scroll_speed;
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
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 /*
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 * GList utils
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
695 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
696 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
697
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
698 GList *uig_list_insert_link(GList *list, GList *link, gpointer 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 GList *new_list;
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 if (!list || link == list) return g_list_prepend(list, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
703 if (!link) return g_list_append(list, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
704
513
985fdfebd89e Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents: 475
diff changeset
705 new_list = g_list_alloc();
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
706 new_list->data = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
707
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
708 if (link->prev)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
709 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
710 link->prev->next = new_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
711 new_list->prev = link->prev;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
712 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
713 else
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 list = new_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 link->prev = new_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
718 new_list->next = link;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
719
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
720 return list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
721 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
722
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
723 GList *uig_list_insert_list(GList *parent, GList *insert_link, GList *list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
724 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
725 GList *end;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
726
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
727 if (!insert_link) return g_list_concat(parent, list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
728 if (insert_link == parent) return g_list_concat(list, parent);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
729 if (!parent) return list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
730 if (!list) return parent;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
731
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
732 end = g_list_last(list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
733
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
734 if (insert_link->prev) insert_link->prev->next = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
735 list->prev = insert_link->prev;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
736 insert_link->prev = end;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
737 end->next = insert_link;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
738
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
739 return parent;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
740 }
1055
1646720364cf Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents: 1046
diff changeset
741 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */