1 /********************************************************************\
2 * cursor.c -- functions for changing cursors *
3 * *
4 * Copyright (C) 1997 Robin D. Clark <rclark@cs.hmc.edu> *
5 * Copyright (C) 1998-2000 Linas Vepstas <linas@linas.org> *
6 * *
7 * This program is free software; you can redistribute it and/or *
8 * modify it under the terms of the GNU General Public License as *
9 * published by the Free Software Foundation; either version 2 of *
10 * the License, or (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License*
18 * along with this program; if not, contact: *
19 * *
20 * Free Software Foundation Voice: +1-617-542-5942 *
21 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
22 * Boston, MA 02110-1301, USA gnu@gnu.org *
23 \********************************************************************/
24 #include <config.h>
25 #include <gtk/gtk.h>
26 #include "gnc-ui.h"
27
28
29 typedef enum
30 {
31 GNC_CURSOR_NORMAL = -1,
32 GNC_CURSOR_BUSY = GDK_WATCH
33 } GNCCursorType;
34
35
36 /********************************************************************\
37 * gnc_ui_set_cursor *
38 * sets the cursor to the specified type *
39 * *
40 * Args: w - the widget over which to change the cursor *
41 * type - the type of cursor to make *
42 * Return: none *
43 \********************************************************************/
44 static void
gnc_ui_set_cursor(GdkWindow * win,GNCCursorType type,gboolean update_now)45 gnc_ui_set_cursor (GdkWindow *win, GNCCursorType type, gboolean update_now)
46 {
47 GdkCursor *cursor = NULL;
48
49 if (win == NULL)
50 return;
51
52 if (type != GNC_CURSOR_NORMAL)
53 cursor = gdk_cursor_new_for_display (gdk_window_get_display (win),
54 (GdkCursorType)type);
55
56 gdk_window_set_cursor (win, cursor);
57
58 if (update_now && type != GNC_CURSOR_NORMAL)
59 {
60 while (gtk_events_pending ())
61 gtk_main_iteration ();
62 }
63
64 if (type != GNC_CURSOR_NORMAL)
65 g_object_unref (cursor);
66 }
67
68
69 /********************************************************************\
70 * gnc_set_busy_cursor *
71 * sets the cursor to the busy watch for the given window. *
72 * if the window is null, sets the cursor for all toplevel windows*
73 * *
74 * Args: w - the widget over which to make cursor busy *
75 * update_now - if true the cursor will be changed when the *
76 * call returns. *
77 * Return: none *
78 \********************************************************************/
79 void
gnc_set_busy_cursor(GtkWidget * w,gboolean update_now)80 gnc_set_busy_cursor (GtkWidget *w, gboolean update_now)
81 {
82 if (w != NULL)
83 gnc_ui_set_cursor (gtk_widget_get_window(w), GNC_CURSOR_BUSY, update_now);
84 else
85 {
86 GList *containerstop, *node;
87
88 for (containerstop = node = gtk_window_list_toplevels (); node; node = node->next)
89 {
90 w = node->data;
91
92 if (!w || !GTK_IS_WIDGET (w) || (!gtk_widget_get_has_window(w)))
93 continue;
94
95 gnc_ui_set_cursor (gtk_widget_get_window(w), GNC_CURSOR_BUSY, update_now);
96 }
97 g_list_free (containerstop);
98 }
99 }
100
101
102 /********************************************************************\
103 * gnc_unset_busy_cursor *
104 * sets the cursor to the default cursor for the given window. *
105 * if the window is null, sets the cursor for all toplevel windows*
106 * *
107 * Args: w - the widget over which to make cursor normal *
108 * Return: none *
109 \********************************************************************/
110 void
gnc_unset_busy_cursor(GtkWidget * w)111 gnc_unset_busy_cursor (GtkWidget *w)
112 {
113 if (w != NULL)
114 gnc_ui_set_cursor (gtk_widget_get_window(w), GNC_CURSOR_NORMAL, FALSE);
115 else
116 {
117 GList *containerstop, *node;
118
119 for (containerstop = node = gtk_window_list_toplevels (); node; node = node->next)
120 {
121 w = GTK_WIDGET (node->data);
122
123 if (!w || !GTK_IS_WIDGET (w) || (!gtk_widget_get_has_window(w)))
124 continue;
125
126 gnc_ui_set_cursor (gtk_widget_get_window(w), GNC_CURSOR_NORMAL, FALSE);
127 }
128 g_list_free (containerstop);
129 }
130 }
131
132