]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/cursor.cpp
Don't call busy cursor when creating a message
[wxWidgets.git] / src / gtk / cursor.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: cursor.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10
11#ifdef __GNUG__
12#pragma implementation "cursor.h"
13#endif
14
15#include "wx/cursor.h"
16#include "wx/utils.h"
17#include "wx/app.h"
18
19#include <gdk/gdk.h>
20#include <gtk/gtk.h>
21
22//-----------------------------------------------------------------------------
23// idle system
24//-----------------------------------------------------------------------------
25
26extern void wxapp_install_idle_handler();
27extern bool g_isIdle;
28
29//-----------------------------------------------------------------------------
30// wxCursor
31//-----------------------------------------------------------------------------
32
33class wxCursorRefData: public wxObjectRefData
34{
35 public:
36
37 wxCursorRefData();
38 ~wxCursorRefData();
39
40 GdkCursor *m_cursor;
41};
42
43wxCursorRefData::wxCursorRefData()
44{
45 m_cursor = (GdkCursor *) NULL;
46}
47
48wxCursorRefData::~wxCursorRefData()
49{
50 if (m_cursor) gdk_cursor_destroy( m_cursor );
51}
52
53//-----------------------------------------------------------------------------
54
55#define M_CURSORDATA ((wxCursorRefData *)m_refData)
56
57IMPLEMENT_DYNAMIC_CLASS(wxCursor,wxObject)
58
59wxCursor::wxCursor()
60{
61}
62
63wxCursor::wxCursor( int cursorId )
64{
65 m_refData = new wxCursorRefData();
66
67 GdkCursorType gdk_cur = GDK_LEFT_PTR;
68 switch (cursorId)
69 {
70 case wxCURSOR_DEFAULT: gdk_cur = GDK_LEFT_PTR; break;
71 case wxCURSOR_HAND: gdk_cur = GDK_HAND1; break;
72 case wxCURSOR_CROSS: gdk_cur = GDK_CROSSHAIR; break;
73 case wxCURSOR_SIZEWE: gdk_cur = GDK_SB_H_DOUBLE_ARROW; break;
74 case wxCURSOR_SIZENS: gdk_cur = GDK_SB_V_DOUBLE_ARROW; break;
75 case wxCURSOR_WAIT:
76 case wxCURSOR_WATCH: gdk_cur = GDK_WATCH; break;
77 case wxCURSOR_SIZING: gdk_cur = GDK_SIZING; break;
78 case wxCURSOR_SPRAYCAN: gdk_cur = GDK_SPRAYCAN; break;
79 case wxCURSOR_IBEAM: gdk_cur = GDK_XTERM; break;
80 case wxCURSOR_PENCIL: gdk_cur = GDK_PENCIL; break;
81 case wxCURSOR_NO_ENTRY: gdk_cur = GDK_PIRATE; break;
82 case wxCURSOR_SIZENWSE:
83 case wxCURSOR_SIZENESW: gdk_cur = GDK_FLEUR; break;
84 case wxCURSOR_QUESTION_ARROW: gdk_cur = GDK_QUESTION_ARROW; break;
85 case wxCURSOR_PAINT_BRUSH: gdk_cur = GDK_SPRAYCAN; break;
86 case wxCURSOR_MAGNIFIER: gdk_cur = GDK_PLUS; break;
87 case wxCURSOR_CHAR: gdk_cur = GDK_XTERM; break;
88 case wxCURSOR_LEFT_BUTTON: gdk_cur = GDK_LEFTBUTTON; break;
89 case wxCURSOR_MIDDLE_BUTTON: gdk_cur = GDK_MIDDLEBUTTON; break;
90 case wxCURSOR_RIGHT_BUTTON: gdk_cur = GDK_RIGHTBUTTON; break;
91 case wxCURSOR_BULLSEYE: gdk_cur = GDK_TARGET; break;
92
93 case wxCURSOR_POINT_LEFT: gdk_cur = GDK_SB_LEFT_ARROW; break;
94 case wxCURSOR_POINT_RIGHT: gdk_cur = GDK_SB_RIGHT_ARROW; break;
95/*
96 case wxCURSOR_DOUBLE_ARROW: gdk_cur = GDK_DOUBLE_ARROW; break;
97 case wxCURSOR_CROSS_REVERSE: gdk_cur = GDK_CROSS_REVERSE; break;
98 case wxCURSOR_BASED_ARROW_UP: gdk_cur = GDK_BASED_ARROW_UP; break;
99 case wxCURSOR_BASED_ARROW_DOWN: gdk_cur = GDK_BASED_ARROW_DOWN; break;
100*/
101 default:
102 wxFAIL_MSG(wxT("unsupported cursor type"));
103 // will use the standard one
104
105 case wxCURSOR_ARROW:
106 break;
107 }
108
109 M_CURSORDATA->m_cursor = gdk_cursor_new( gdk_cur );
110}
111
112extern GtkWidget *wxRootWindow;
113
114wxCursor::wxCursor(const char bits[], int width, int height,
115 int hotSpotX, int hotSpotY,
116 const char maskBits[], wxColour *fg, wxColour *bg)
117{
118 if (!maskBits)
119 maskBits = bits;
120 if (!fg)
121 fg = wxBLACK;
122 if (!bg)
123 bg = wxWHITE;
124 if (hotSpotX < 0 || hotSpotX >= width)
125 hotSpotX = 0;
126 if (hotSpotY < 0 || hotSpotY >= height)
127 hotSpotY = 0;
128
129 GdkBitmap *data = gdk_bitmap_create_from_data( wxRootWindow->window, (gchar *) bits, width, height );
130 GdkBitmap *mask = gdk_bitmap_create_from_data( wxRootWindow->window, (gchar *) maskBits, width, height);
131
132 m_refData = new wxCursorRefData;
133 M_CURSORDATA->m_cursor = gdk_cursor_new_from_pixmap(
134 data, mask, fg->GetColor(), bg->GetColor(),
135 hotSpotX, hotSpotY );
136
137 gdk_bitmap_unref( data );
138 gdk_bitmap_unref( mask );
139}
140
141
142wxCursor::wxCursor( const wxCursor &cursor )
143{
144 Ref( cursor );
145}
146
147wxCursor::~wxCursor()
148{
149}
150
151wxCursor& wxCursor::operator = ( const wxCursor& cursor )
152{
153 if (*this == cursor)
154 return (*this);
155
156 Ref( cursor );
157
158 return *this;
159}
160
161bool wxCursor::operator == ( const wxCursor& cursor ) const
162{
163 return m_refData == cursor.m_refData;
164}
165
166bool wxCursor::operator != ( const wxCursor& cursor ) const
167{
168 return m_refData != cursor.m_refData;
169}
170
171bool wxCursor::Ok() const
172{
173 return (m_refData != NULL);
174}
175
176GdkCursor *wxCursor::GetCursor() const
177{
178 return M_CURSORDATA->m_cursor;
179}
180
181//-----------------------------------------------------------------------------
182// busy cursor routines
183//-----------------------------------------------------------------------------
184
185extern wxCursor g_globalCursor;
186
187static wxCursor gs_savedCursor;
188static int gs_busyCount = 0;
189
190const wxCursor &wxBusyCursor::GetStoredCursor()
191{
192 return gs_savedCursor;
193}
194
195const wxCursor wxBusyCursor::GetBusyCursor()
196{
197 return wxCursor(wxCURSOR_WATCH);
198}
199
200void wxEndBusyCursor()
201{
202 if (--gs_busyCount > 0)
203 return;
204
205 wxSetCursor( gs_savedCursor );
206 gs_savedCursor = wxNullCursor;
207
208 if (wxTheApp)
209 wxTheApp->SendIdleEvents();
210}
211
212void wxBeginBusyCursor( wxCursor *WXUNUSED(cursor) )
213{
214 if (gs_busyCount++ > 0)
215 return;
216
217 wxASSERT_MSG( !gs_savedCursor.Ok(),
218 wxT("forgot to call wxEndBusyCursor, will leak memory") );
219
220 gs_savedCursor = g_globalCursor;
221
222 wxSetCursor( wxCursor(wxCURSOR_WATCH) );
223
224 if (wxTheApp)
225 wxTheApp->SendIdleEvents();
226}
227
228bool wxIsBusy()
229{
230 return gs_busyCount > 0;
231}
232
233void wxSetCursor( const wxCursor& cursor )
234{
235 if (g_isIdle)
236 wxapp_install_idle_handler();
237
238 g_globalCursor = cursor;
239}