]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/cursor.cpp
ScanParam has only one parameter now
[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"
c801d85f 17
83624f79
RR
18#include "gdk/gdk.h"
19
238d735d
RR
20//-----------------------------------------------------------------------------
21// idle system
22//-----------------------------------------------------------------------------
23
24extern void wxapp_install_idle_handler();
25extern bool g_isIdle;
26
c801d85f
KB
27//-----------------------------------------------------------------------------
28// wxCursor
29//-----------------------------------------------------------------------------
30
31class wxCursorRefData: public wxObjectRefData
32{
33 public:
8bbe427f
VZ
34
35 wxCursorRefData();
36 ~wxCursorRefData();
37
c801d85f
KB
38 GdkCursor *m_cursor;
39};
40
8bbe427f 41wxCursorRefData::wxCursorRefData()
c801d85f 42{
2d17d68f 43 m_cursor = (GdkCursor *) NULL;
ff7b1510 44}
c801d85f 45
8bbe427f 46wxCursorRefData::~wxCursorRefData()
c801d85f 47{
2d17d68f 48 if (m_cursor) gdk_cursor_destroy( m_cursor );
ff7b1510 49}
c801d85f
KB
50
51//-----------------------------------------------------------------------------
52
53#define M_CURSORDATA ((wxCursorRefData *)m_refData)
54
55IMPLEMENT_DYNAMIC_CLASS(wxCursor,wxObject)
56
8bbe427f 57wxCursor::wxCursor()
c801d85f 58{
ff7b1510 59}
c801d85f 60
debe6624 61wxCursor::wxCursor( int cursorId )
c801d85f 62{
2d17d68f
RR
63 m_refData = new wxCursorRefData();
64
65 GdkCursorType gdk_cur = GDK_LEFT_PTR;
66 switch (cursorId)
67 {
f7bdcdd7 68 case wxCURSOR_DEFAULT: gdk_cur = GDK_LEFT_PTR; break;
2d17d68f
RR
69 case wxCURSOR_HAND: gdk_cur = GDK_HAND1; break;
70 case wxCURSOR_CROSS: gdk_cur = GDK_CROSSHAIR; break;
71 case wxCURSOR_SIZEWE: gdk_cur = GDK_SB_H_DOUBLE_ARROW; break;
72 case wxCURSOR_SIZENS: gdk_cur = GDK_SB_V_DOUBLE_ARROW; break;
7c39369e 73 case wxCURSOR_WAIT:
2d17d68f
RR
74 case wxCURSOR_WATCH: gdk_cur = GDK_WATCH; break;
75 case wxCURSOR_SIZING: gdk_cur = GDK_SIZING; break;
76 case wxCURSOR_SPRAYCAN: gdk_cur = GDK_SPRAYCAN; break;
77 case wxCURSOR_IBEAM: gdk_cur = GDK_XTERM; break;
78 case wxCURSOR_PENCIL: gdk_cur = GDK_PENCIL; break;
79 case wxCURSOR_NO_ENTRY: gdk_cur = GDK_PIRATE; break;
7c39369e 80 case wxCURSOR_SIZENWSE:
2d17d68f
RR
81 case wxCURSOR_SIZENESW: gdk_cur = GDK_FLEUR; break;
82 case wxCURSOR_QUESTION_ARROW: gdk_cur = GDK_QUESTION_ARROW; break;
7c39369e
VZ
83 case wxCURSOR_PAINT_BRUSH: gdk_cur = GDK_SPRAYCAN; break;
84 case wxCURSOR_MAGNIFIER: gdk_cur = GDK_PLUS; break;
85 case wxCURSOR_CHAR: gdk_cur = GDK_XTERM; break;
2d17d68f
RR
86 case wxCURSOR_LEFT_BUTTON: gdk_cur = GDK_LEFTBUTTON; break;
87 case wxCURSOR_MIDDLE_BUTTON: gdk_cur = GDK_MIDDLEBUTTON; break;
88 case wxCURSOR_RIGHT_BUTTON: gdk_cur = GDK_RIGHTBUTTON; break;
c801d85f 89/*
7c39369e
VZ
90 case wxCURSOR_DOUBLE_ARROW: gdk_cur = GDK_DOUBLE_ARROW; break;
91 case wxCURSOR_CROSS_REVERSE: gdk_cur = GDK_CROSS_REVERSE; break;
2d17d68f
RR
92 case wxCURSOR_BASED_ARROW_UP: gdk_cur = GDK_BASED_ARROW_UP; break;
93 case wxCURSOR_BASED_ARROW_DOWN: gdk_cur = GDK_BASED_ARROW_DOWN; break;
c801d85f 94*/
7c39369e 95 default:
93c5dd39 96 wxFAIL_MSG(_T("unsupported cursor type"));
7c39369e
VZ
97 // will use the standard one
98
99 case wxCURSOR_ARROW:
100 break;
2d17d68f 101 }
8bbe427f 102
2d17d68f 103 M_CURSORDATA->m_cursor = gdk_cursor_new( gdk_cur );
ff7b1510 104}
c801d85f
KB
105
106wxCursor::wxCursor( const wxCursor &cursor )
107{
2d17d68f 108 Ref( cursor );
ff7b1510 109}
c801d85f 110
8bbe427f 111wxCursor::~wxCursor()
c801d85f 112{
ff7b1510 113}
c801d85f
KB
114
115wxCursor& wxCursor::operator = ( const wxCursor& cursor )
116{
7c39369e
VZ
117 if (*this == cursor)
118 return (*this);
119
2d17d68f 120 Ref( cursor );
7c39369e 121
2d17d68f 122 return *this;
ff7b1510 123}
c801d85f 124
8bbe427f 125bool wxCursor::operator == ( const wxCursor& cursor ) const
c801d85f 126{
2d17d68f 127 return m_refData == cursor.m_refData;
ff7b1510 128}
c801d85f 129
8bbe427f 130bool wxCursor::operator != ( const wxCursor& cursor ) const
c801d85f 131{
2d17d68f 132 return m_refData != cursor.m_refData;
ff7b1510 133}
c801d85f 134
8bbe427f 135bool wxCursor::Ok() const
c801d85f 136{
2d17d68f 137 return (m_refData != NULL);
ff7b1510 138}
c801d85f 139
8bbe427f 140GdkCursor *wxCursor::GetCursor() const
c801d85f 141{
2d17d68f 142 return M_CURSORDATA->m_cursor;
ff7b1510 143}
c801d85f
KB
144
145//-----------------------------------------------------------------------------
146// busy cursor routines
147//-----------------------------------------------------------------------------
148
238d735d 149extern wxCursor g_globalCursor;
7c39369e 150
238d735d 151static wxCursor gs_savedCursor;
89a43902 152static int gs_busyCount = 0;
c801d85f 153
8bbe427f 154void wxEndBusyCursor()
c801d85f 155{
238d735d 156 if (--gs_busyCount > 0)
89a43902
VZ
157 return;
158
238d735d
RR
159 wxSetCursor( gs_savedCursor );
160 gs_savedCursor = wxNullCursor;
e65cc56a
RR
161
162 wxYield();
ff7b1510 163}
c801d85f
KB
164
165void wxBeginBusyCursor( wxCursor *WXUNUSED(cursor) )
166{
238d735d 167 if (gs_busyCount++ > 0)
89a43902
VZ
168 return;
169
238d735d 170 wxASSERT_MSG( !gs_savedCursor.Ok(),
93c5dd39 171 _T("forgot to call wxEndBusyCursor, will leak memory") );
7c39369e 172
238d735d
RR
173 gs_savedCursor = g_globalCursor;
174
175 wxSetCursor( wxCursor(wxCURSOR_WATCH) );
4dcaf11a
RR
176
177 wxYield();
ff7b1510 178}
c801d85f 179
8bbe427f 180bool wxIsBusy()
c801d85f 181{
89a43902 182 return gs_busyCount > 0;
ff7b1510 183}
c801d85f
KB
184
185void wxSetCursor( const wxCursor& cursor )
186{
238d735d
RR
187 if (g_isIdle)
188 wxapp_install_idle_handler();
189
190 g_globalCursor = cursor;
ff7b1510 191}