]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/cursor.cpp
wxChoice/wxComboBox background colour change (to get back to where we were);
[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
071a2d78 18#include <gdk/gdk.h>
83624f79 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;
13971833
RD
89 case wxCURSOR_BULLSEYE: gdk_cur = GDK_TARGET; break;
90
957d856c
VZ
91 case wxCURSOR_POINT_LEFT: gdk_cur = GDK_SB_LEFT_ARROW; break;
92 case wxCURSOR_POINT_RIGHT: gdk_cur = GDK_SB_RIGHT_ARROW; break;
c801d85f 93/*
7c39369e
VZ
94 case wxCURSOR_DOUBLE_ARROW: gdk_cur = GDK_DOUBLE_ARROW; break;
95 case wxCURSOR_CROSS_REVERSE: gdk_cur = GDK_CROSS_REVERSE; break;
2d17d68f
RR
96 case wxCURSOR_BASED_ARROW_UP: gdk_cur = GDK_BASED_ARROW_UP; break;
97 case wxCURSOR_BASED_ARROW_DOWN: gdk_cur = GDK_BASED_ARROW_DOWN; break;
c801d85f 98*/
7c39369e 99 default:
223d09f6 100 wxFAIL_MSG(wxT("unsupported cursor type"));
7c39369e
VZ
101 // will use the standard one
102
103 case wxCURSOR_ARROW:
104 break;
2d17d68f 105 }
8bbe427f 106
2d17d68f 107 M_CURSORDATA->m_cursor = gdk_cursor_new( gdk_cur );
ff7b1510 108}
c801d85f
KB
109
110wxCursor::wxCursor( const wxCursor &cursor )
111{
2d17d68f 112 Ref( cursor );
ff7b1510 113}
c801d85f 114
8bbe427f 115wxCursor::~wxCursor()
c801d85f 116{
ff7b1510 117}
c801d85f
KB
118
119wxCursor& wxCursor::operator = ( const wxCursor& cursor )
120{
7c39369e
VZ
121 if (*this == cursor)
122 return (*this);
123
2d17d68f 124 Ref( cursor );
7c39369e 125
2d17d68f 126 return *this;
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::operator != ( const wxCursor& cursor ) const
c801d85f 135{
2d17d68f 136 return m_refData != cursor.m_refData;
ff7b1510 137}
c801d85f 138
8bbe427f 139bool wxCursor::Ok() const
c801d85f 140{
2d17d68f 141 return (m_refData != NULL);
ff7b1510 142}
c801d85f 143
8bbe427f 144GdkCursor *wxCursor::GetCursor() const
c801d85f 145{
2d17d68f 146 return M_CURSORDATA->m_cursor;
ff7b1510 147}
c801d85f
KB
148
149//-----------------------------------------------------------------------------
150// busy cursor routines
151//-----------------------------------------------------------------------------
152
238d735d 153extern wxCursor g_globalCursor;
7c39369e 154
238d735d 155static wxCursor gs_savedCursor;
89a43902 156static int gs_busyCount = 0;
c801d85f 157
8bbe427f 158void wxEndBusyCursor()
c801d85f 159{
238d735d 160 if (--gs_busyCount > 0)
89a43902
VZ
161 return;
162
238d735d
RR
163 wxSetCursor( gs_savedCursor );
164 gs_savedCursor = wxNullCursor;
13971833 165
e65cc56a 166 wxYield();
ff7b1510 167}
c801d85f
KB
168
169void wxBeginBusyCursor( wxCursor *WXUNUSED(cursor) )
170{
238d735d 171 if (gs_busyCount++ > 0)
89a43902
VZ
172 return;
173
238d735d 174 wxASSERT_MSG( !gs_savedCursor.Ok(),
223d09f6 175 wxT("forgot to call wxEndBusyCursor, will leak memory") );
7c39369e 176
238d735d 177 gs_savedCursor = g_globalCursor;
13971833 178
238d735d 179 wxSetCursor( wxCursor(wxCURSOR_WATCH) );
13971833 180
4dcaf11a 181 wxYield();
ff7b1510 182}
c801d85f 183
8bbe427f 184bool wxIsBusy()
c801d85f 185{
89a43902 186 return gs_busyCount > 0;
ff7b1510 187}
c801d85f
KB
188
189void wxSetCursor( const wxCursor& cursor )
190{
13971833 191 if (g_isIdle)
238d735d
RR
192 wxapp_install_idle_handler();
193
194 g_globalCursor = cursor;
ff7b1510 195}