Back to index

plt-scheme  4.2.1
BusyCursor.cc
Go to the documentation of this file.
00001 /*                                                      -*- C++ -*-
00002  *
00003  * Purpose: busy cursor
00004  *
00005  * Authors: Markus Holzem and Julian Smart
00006  *
00007  * Copyright: (C) 2004-2009 PLT Scheme Inc.
00008  * Copyright: (C) 1995, AIAI, University of Edinburgh (Julian)
00009  * Copyright: (C) 1995, GNU (Markus)
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00024  * 02110-1301 USA.
00025  */
00026 
00027 #define  Uses_XLib
00028 #define  Uses_XtIntrinsic
00029 #define  Uses_wxCursor
00030 #define  Uses_wxWindow
00031 #define  Uses_wxTypeTree
00032 #include "wx.h"
00033 #define  Uses_SimpleWidget
00034 #include "widgets.h"
00035 
00036 extern int wxGetBusyState();
00037 extern void wxSetBusyState(int);
00038 
00039 void wxXSetNoCursor(wxWindow *win, wxCursor *cursor)
00040 {
00041   Cursor c;
00042   Cursor cc;
00043   wxChildList *cl;
00044   wxChildNode *node;
00045 
00046   if (cursor || !win->cursor)
00047     c = None;
00048   else
00049     c = GETCURSOR(win->cursor);
00050 
00051   win->user_edit_mode = !!cursor;
00052 
00053   XtVaGetValues(win->X->handle, XtNcursor, &cc, NULL);
00054   if (cc != c) {
00055     XtVaSetValues(win->X->handle, XtNcursor, c, NULL);
00056     if (win->__type == wxTYPE_LIST_BOX) {
00057       XtVaSetValues(XtParent(win->X->handle), XtNcursor, c, NULL);
00058     }
00059   }
00060   
00061 #ifdef MZ_PRECISE_GC
00062   if (win->__type == wxTYPE_MENU_BAR)
00063     return;
00064 #endif
00065 
00066   cl = win->GetChildren();
00067   for (node = cl->First(); node; node = node->Next()) {
00068     wxWindow *child;
00069     child = (wxWindow *) node->Data ();
00070     wxXSetNoCursor(child, cursor);
00071   }
00072 }
00073 
00074 void wxXSetBusyCursor(wxWindow *win, wxCursor *cursor)
00075 {
00076   Cursor c;
00077   wxChildNode *node;
00078   wxChildList *cl;
00079 
00080   if (cursor)
00081     c = GETCURSOR(cursor);
00082   else if (win->cursor)
00083     c = GETCURSOR(win->cursor);
00084   else
00085     c = GETCURSOR(wxSTANDARD_CURSOR);
00086   
00087   win->user_edit_mode = !!cursor;
00088 
00089   XtVaSetValues(win->X->handle, XtNcursor, c, NULL);
00090   if (win->__type == wxTYPE_LIST_BOX) {
00091     XtVaSetValues(XtParent(win->X->handle), XtNcursor, c, NULL);
00092   }
00093 
00094   cl = win->GetChildren();
00095   for (node = cl->First(); node; node = node->Next()) {
00096     wxWindow *child;
00097     child = (wxWindow *) node->Data ();
00098     if (wxSubType(child->__type, wxTYPE_FRAME))
00099       wxXSetBusyCursor(child, cursor);
00100     else
00101       wxXSetNoCursor(child, cursor);
00102   }
00103 }
00104 
00105 static void set_all_cursors(wxObject *o, wxCursor *cursor)
00106 {
00107   wxChildList *cl;
00108   wxWindow *win;
00109   wxChildNode *node;
00110 
00111   cl = wxTopLevelFrames(o);
00112   for (node = cl->First(); node; node = node->Next()) {
00113     win = (wxWindow *)node->Data();
00114     if (win)
00115       wxXSetBusyCursor(win, cursor);
00116   }
00117 
00118   XFlush(wxAPP_DISPLAY);
00119 }
00120 
00121 /* Busy state valeus:
00122     0    => not busy, not blanked
00123     -1   => not busy, blanked
00124     < -1 => busy, blanked
00125     > 0  => busy, not blanked
00126 */
00127 
00128 void wxBeginBusyCursor(wxCursor * cursor)
00129 {
00130   int busy;
00131 
00132   busy = wxGetBusyState();
00133   if (busy >= 0) {
00134     busy++;
00135     wxSetBusyState(busy);
00136   } else {
00137     /* Blanked, so "increment", but don't change cursor */
00138     --busy;
00139     wxSetBusyState(busy);
00140     return;
00141   }
00142 
00143   if (busy == 1) {
00144     set_all_cursors(NULL, cursor);
00145   }
00146 }
00147 
00148 // Restore cursor to normal
00149 void 
00150 wxEndBusyCursor (void)
00151 {
00152   int busy;
00153 
00154   busy = wxGetBusyState();
00155   if ((busy == 0) || (busy == -1))
00156     return;
00157   if (busy > 0) {
00158     busy--;
00159     wxSetBusyState(busy);
00160   } else {
00161     /* Blanked, so "decrement", but don't change cursor */
00162     busy++;
00163     wxSetBusyState(busy);
00164     return;
00165   }
00166 
00167   if (busy == 0) {
00168     set_all_cursors(NULL, NULL);
00169   }
00170 }
00171 
00172 Bool wxIsBusy (void)
00173 {
00174   int busy;
00175   busy = wxGetBusyState();
00176   return ((busy > 0) || (busy < -1));
00177 }
00178 
00179 static int some_hidden = 0;
00180 
00181 void 
00182 wxHideCursor (void)
00183 {
00184   int busy;
00185   busy = wxGetBusyState();
00186 
00187   if (busy >= 0) {
00188     some_hidden++;
00189     busy = -(busy + 1);
00190     wxSetBusyState(busy);
00191     set_all_cursors(NULL, wxBLANK_CURSOR);
00192   }
00193 }
00194 
00195 void
00196 wxUnhideCursor(void)
00197      /* Not currently used. MrEd calls wxUnhideCursorInFrame, instead */
00198 {
00199   int busy;
00200   busy = wxGetBusyState();
00201 
00202   if (busy < 0) {
00203     if (some_hidden)
00204       --some_hidden;
00205     busy = -(busy + 1);
00206     wxSetBusyState(busy);
00207     set_all_cursors(NULL, (busy > 0) ? wxHOURGLASS_CURSOR : NULL);
00208   }  
00209 }
00210 
00211 int wxCheckHiddenCursors()
00212      /* Called by MrEd to check whether cursors need to be unhidden in
00213        some context. */
00214 {
00215   if (some_hidden) {
00216     some_hidden = 0;
00217     return 1;
00218   }
00219   return 0;
00220 }
00221 
00222 int wxUnhideCursorInFrame(wxObject *o, int busy)
00223      /* Called by MrEd to try to unhide cursors in each context. */
00224 {
00225   if (busy < 0) {
00226     busy = -(busy + 1);
00227     set_all_cursors(o, (busy > 0) ? wxHOURGLASS_CURSOR : NULL);
00228   }
00229   return busy;
00230 }