]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/cursor.cpp
Small changed to wxExtDialog
[wxWidgets.git] / src / gtk1 / 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 {
f7bdcdd7 67 case wxCURSOR_DEFAULT: gdk_cur = GDK_LEFT_PTR; break;
2d17d68f
RR
68 case wxCURSOR_HAND: gdk_cur = GDK_HAND1; break;
69 case wxCURSOR_CROSS: gdk_cur = GDK_CROSSHAIR; break;
70 case wxCURSOR_SIZEWE: gdk_cur = GDK_SB_H_DOUBLE_ARROW; break;
71 case wxCURSOR_SIZENS: gdk_cur = GDK_SB_V_DOUBLE_ARROW; break;
7c39369e 72 case wxCURSOR_WAIT:
2d17d68f
RR
73 case wxCURSOR_WATCH: gdk_cur = GDK_WATCH; break;
74 case wxCURSOR_SIZING: gdk_cur = GDK_SIZING; break;
75 case wxCURSOR_SPRAYCAN: gdk_cur = GDK_SPRAYCAN; break;
76 case wxCURSOR_IBEAM: gdk_cur = GDK_XTERM; break;
77 case wxCURSOR_PENCIL: gdk_cur = GDK_PENCIL; break;
78 case wxCURSOR_NO_ENTRY: gdk_cur = GDK_PIRATE; break;
7c39369e 79 case wxCURSOR_SIZENWSE:
2d17d68f
RR
80 case wxCURSOR_SIZENESW: gdk_cur = GDK_FLEUR; break;
81 case wxCURSOR_QUESTION_ARROW: gdk_cur = GDK_QUESTION_ARROW; break;
7c39369e
VZ
82 case wxCURSOR_PAINT_BRUSH: gdk_cur = GDK_SPRAYCAN; break;
83 case wxCURSOR_MAGNIFIER: gdk_cur = GDK_PLUS; break;
84 case wxCURSOR_CHAR: gdk_cur = GDK_XTERM; break;
2d17d68f
RR
85 case wxCURSOR_LEFT_BUTTON: gdk_cur = GDK_LEFTBUTTON; break;
86 case wxCURSOR_MIDDLE_BUTTON: gdk_cur = GDK_MIDDLEBUTTON; break;
87 case wxCURSOR_RIGHT_BUTTON: gdk_cur = GDK_RIGHTBUTTON; break;
c801d85f 88/*
7c39369e
VZ
89 case wxCURSOR_DOUBLE_ARROW: gdk_cur = GDK_DOUBLE_ARROW; break;
90 case wxCURSOR_CROSS_REVERSE: gdk_cur = GDK_CROSS_REVERSE; break;
2d17d68f
RR
91 case wxCURSOR_BASED_ARROW_UP: gdk_cur = GDK_BASED_ARROW_UP; break;
92 case wxCURSOR_BASED_ARROW_DOWN: gdk_cur = GDK_BASED_ARROW_DOWN; break;
c801d85f 93*/
7c39369e 94 default:
93c5dd39 95 wxFAIL_MSG(_T("unsupported cursor type"));
7c39369e
VZ
96 // will use the standard one
97
98 case wxCURSOR_ARROW:
99 break;
2d17d68f 100 }
8bbe427f 101
2d17d68f 102 M_CURSORDATA->m_cursor = gdk_cursor_new( gdk_cur );
ff7b1510 103}
c801d85f
KB
104
105wxCursor::wxCursor( const wxCursor &cursor )
106{
2d17d68f 107 Ref( cursor );
ff7b1510 108}
c801d85f 109
8bbe427f 110wxCursor::~wxCursor()
c801d85f 111{
ff7b1510 112}
c801d85f
KB
113
114wxCursor& wxCursor::operator = ( const wxCursor& cursor )
115{
7c39369e
VZ
116 if (*this == cursor)
117 return (*this);
118
2d17d68f 119 Ref( cursor );
7c39369e 120
2d17d68f 121 return *this;
ff7b1510 122}
c801d85f 123
8bbe427f 124bool wxCursor::operator == ( const wxCursor& cursor ) const
c801d85f 125{
2d17d68f 126 return m_refData == cursor.m_refData;
ff7b1510 127}
c801d85f 128
8bbe427f 129bool wxCursor::operator != ( const wxCursor& cursor ) const
c801d85f 130{
2d17d68f 131 return m_refData != cursor.m_refData;
ff7b1510 132}
c801d85f 133
8bbe427f 134bool wxCursor::Ok() const
c801d85f 135{
2d17d68f 136 return (m_refData != NULL);
ff7b1510 137}
c801d85f 138
8bbe427f 139GdkCursor *wxCursor::GetCursor() const
c801d85f 140{
2d17d68f 141 return M_CURSORDATA->m_cursor;
ff7b1510 142}
c801d85f
KB
143
144//-----------------------------------------------------------------------------
145// busy cursor routines
146//-----------------------------------------------------------------------------
147
238d735d 148extern wxCursor g_globalCursor;
7c39369e 149
238d735d 150static wxCursor gs_savedCursor;
89a43902 151static int gs_busyCount = 0;
c801d85f 152
8bbe427f 153void wxEndBusyCursor()
c801d85f 154{
238d735d 155 if (--gs_busyCount > 0)
89a43902
VZ
156 return;
157
238d735d
RR
158 wxSetCursor( gs_savedCursor );
159 gs_savedCursor = wxNullCursor;
ff7b1510 160}
c801d85f
KB
161
162void wxBeginBusyCursor( wxCursor *WXUNUSED(cursor) )
163{
238d735d 164 if (gs_busyCount++ > 0)
89a43902
VZ
165 return;
166
238d735d 167 wxASSERT_MSG( !gs_savedCursor.Ok(),
93c5dd39 168 _T("forgot to call wxEndBusyCursor, will leak memory") );
7c39369e 169
238d735d
RR
170 gs_savedCursor = g_globalCursor;
171
172 wxSetCursor( wxCursor(wxCURSOR_WATCH) );
ff7b1510 173}
c801d85f 174
8bbe427f 175bool wxIsBusy()
c801d85f 176{
89a43902 177 return gs_busyCount > 0;
ff7b1510 178}
c801d85f
KB
179
180void wxSetCursor( const wxCursor& cursor )
181{
238d735d
RR
182 if (g_isIdle)
183 wxapp_install_idle_handler();
184
185 g_globalCursor = cursor;
ff7b1510 186}