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