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