cursors.c

00001 /********************************************************************\
00002  * cursor.c -- functions for changing cursors                       *
00003  *                                                                  *
00004  * Copyright (C) 1997 Robin D. Clark <rclark@cs.hmc.edu>            *
00005  * Copyright (C) 1998-2000 Linas Vepstas <linas@linas.org>          *
00006  *                                                                  *
00007  * This program is free software; you can redistribute it and/or    *
00008  * modify it under the terms of the GNU General Public License as   *
00009  * published by the Free Software Foundation; either version 2 of   *
00010  * the License, or (at your option) any later version.              *
00011  *                                                                  *
00012  * This program is distributed in the hope that it will be useful,  *
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00015  * GNU General Public License for more details.                     *
00016  *                                                                  *
00017  * You should have received a copy of the GNU General Public License*
00018  * along with this program; if not, contact:                        *
00019  *                                                                  *
00020  * Free Software Foundation           Voice:  +1-617-542-5942       *
00021  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00022  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00023 \********************************************************************/
00024 
00025 /********************************************************************\
00026  * 2003-03-16 TomF changes for gnucash-gnome2-dev, 8th batch        *
00027  * * src/gnome-utils/cursors.c                                      *
00028  *   Replace calls of deprecated gtk_container_get_toplevels by     *
00029  *   gtk_window_list_toplevels                                      *
00030 \********************************************************************/
00031 
00032 #include "config.h"
00033 
00034 #include <gtk/gtk.h>
00035 
00036 #include "gnc-ui.h"
00037 
00038 
00039 typedef enum
00040 {
00041   GNC_CURSOR_NORMAL = -1,
00042   GNC_CURSOR_BUSY   = GDK_WATCH
00043 } GNCCursorType;
00044 
00045 
00046 /********************************************************************\
00047  * gnc_ui_set_cursor                                                * 
00048  *   sets the cursor to the specified type                          * 
00049  *                                                                  * 
00050  * Args: w    - the widget over which to change the cursor          *
00051  *       type - the type of cursor to make                          *
00052  * Return: none                                                     * 
00053 \********************************************************************/
00054 static void
00055 gnc_ui_set_cursor (GdkWindow *win, GNCCursorType type, gboolean update_now)
00056 {
00057   GdkCursor *cursor = NULL;
00058 
00059   if (win == NULL)
00060     return;
00061 
00062   if (type != GNC_CURSOR_NORMAL)
00063     cursor = gdk_cursor_new (type);
00064 
00065   gdk_window_set_cursor (win, cursor);
00066 
00067   if (update_now && type != GNC_CURSOR_NORMAL)
00068   {
00069     while (gtk_events_pending ())
00070       gtk_main_iteration ();
00071   }
00072 
00073   if (type != GNC_CURSOR_NORMAL)
00074     gdk_cursor_unref (cursor);
00075 }
00076 
00077 
00078 /********************************************************************\
00079  * gnc_set_busy_cursor                                              *
00080  *   sets the cursor to the busy watch for the given window.        *
00081  *   if the window is null, sets the cursor for all toplevel windows*
00082  *                                                                  *
00083  * Args: w          - the widget over which to make cursor busy     *
00084  *       update_now - if true the cursor will be changed when the   *
00085  *                    call returns.                                 *
00086  * Return: none                                                     *
00087 \********************************************************************/
00088 void 
00089 gnc_set_busy_cursor (GtkWidget *w, gboolean update_now)
00090 {
00091   if (w != NULL)
00092     gnc_ui_set_cursor (w->window, GNC_CURSOR_BUSY, update_now);
00093   else
00094   {
00095     GList *containerstop, *node;
00096 
00097     for (containerstop = node = gtk_window_list_toplevels (); node; node = node->next)
00098     {
00099       w = node->data;
00100 
00101       if (!w || !GTK_IS_WIDGET (w) || !w->window)
00102         continue;
00103 
00104       gnc_ui_set_cursor (w->window, GNC_CURSOR_BUSY, update_now);
00105     }
00106     g_list_free (containerstop);
00107   }
00108 }
00109 
00110 
00111 /********************************************************************\
00112  * gnc_unset_busy_cursor                                            * 
00113  *   sets the cursor to the default cursor for the given window.    * 
00114  *   if the window is null, sets the cursor for all toplevel windows*
00115  *                                                                  * 
00116  * Args:   w - the widget over which to make cursor normal          * 
00117  * Return: none                                                     * 
00118 \********************************************************************/
00119 void 
00120 gnc_unset_busy_cursor (GtkWidget *w)
00121 {
00122   if (w != NULL)
00123     gnc_ui_set_cursor (w->window, GNC_CURSOR_NORMAL, FALSE);
00124   else
00125   {
00126     GList *containerstop, *node;
00127 
00128     for (containerstop = node = gtk_window_list_toplevels (); node; node = node->next)
00129     {
00130       w = GTK_WIDGET (node->data);
00131 
00132       if (!w || !GTK_IS_WIDGET (w) || GTK_WIDGET_NO_WINDOW(w))
00133         continue;
00134 
00135       gnc_ui_set_cursor (w->window, GNC_CURSOR_NORMAL, FALSE);
00136     }
00137     g_list_free (containerstop);
00138   }
00139 }
00140 

Generated on Thu Jul 3 05:06:28 2008 for GnuCash by  doxygen 1.5.2