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