GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cursors.c
1 /********************************************************************\
2  * cursor.c -- functions for changing cursors *
3  * *
4  * Copyright (C) 1997 Robin D. Clark <[email protected]> *
5  * Copyright (C) 1998-2000 Linas Vepstas <[email protected]> *
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 [email protected] *
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
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 ((GdkCursorType)type);
54 
55  gdk_window_set_cursor (win, cursor);
56 
57  if (update_now && type != GNC_CURSOR_NORMAL)
58  {
59  while (gtk_events_pending ())
60  gtk_main_iteration ();
61  }
62 
63  if (type != GNC_CURSOR_NORMAL)
64  gdk_cursor_unref (cursor);
65 }
66 
67 
68 /********************************************************************\
69  * gnc_set_busy_cursor *
70  * sets the cursor to the busy watch for the given window. *
71  * if the window is null, sets the cursor for all toplevel windows*
72  * *
73  * Args: w - the widget over which to make cursor busy *
74  * update_now - if true the cursor will be changed when the *
75  * call returns. *
76  * Return: none *
77 \********************************************************************/
78 void
79 gnc_set_busy_cursor (GtkWidget *w, gboolean update_now)
80 {
81  if (w != NULL)
82  gnc_ui_set_cursor (gtk_widget_get_window(w), GNC_CURSOR_BUSY, update_now);
83  else
84  {
85  GList *containerstop, *node;
86 
87  for (containerstop = node = gtk_window_list_toplevels (); node; node = node->next)
88  {
89  w = node->data;
90 
91  if (!w || !GTK_IS_WIDGET (w) || !w->window)
92  continue;
93 
94  gnc_ui_set_cursor (gtk_widget_get_window(w), GNC_CURSOR_BUSY, update_now);
95  }
96  g_list_free (containerstop);
97  }
98 }
99 
100 
101 /********************************************************************\
102  * gnc_unset_busy_cursor *
103  * sets the cursor to the default cursor for the given window. *
104  * if the window is null, sets the cursor for all toplevel windows*
105  * *
106  * Args: w - the widget over which to make cursor normal *
107  * Return: none *
108 \********************************************************************/
109 void
110 gnc_unset_busy_cursor (GtkWidget *w)
111 {
112  if (w != NULL)
113  gnc_ui_set_cursor (gtk_widget_get_window(w), GNC_CURSOR_NORMAL, FALSE);
114  else
115  {
116  GList *containerstop, *node;
117 
118  for (containerstop = node = gtk_window_list_toplevels (); node; node = node->next)
119  {
120  w = GTK_WIDGET (node->data);
121 
122  if (!w || !GTK_IS_WIDGET (w) || (!gtk_widget_get_has_window(w)))
123  continue;
124 
125  gnc_ui_set_cursor (gtk_widget_get_window(w), GNC_CURSOR_NORMAL, FALSE);
126  }
127  g_list_free (containerstop);
128  }
129 }
130