]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/cursor.cpp
implemented dummy wxPalette for wxGTK, so that it no longer pops up assertion failure...
[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"
4dcaf11a 16#include "wx/utils.h"
d1dea842 17#include "wx/app.h"
c801d85f 18
071a2d78 19#include <gdk/gdk.h>
a1db952f 20#include <gtk/gtk.h>
83624f79 21
238d735d
RR
22//-----------------------------------------------------------------------------
23// idle system
24//-----------------------------------------------------------------------------
25
26extern void wxapp_install_idle_handler();
27extern bool g_isIdle;
28
c801d85f
KB
29//-----------------------------------------------------------------------------
30// wxCursor
31//-----------------------------------------------------------------------------
32
33class wxCursorRefData: public wxObjectRefData
34{
35 public:
8bbe427f
VZ
36
37 wxCursorRefData();
38 ~wxCursorRefData();
39
c801d85f
KB
40 GdkCursor *m_cursor;
41};
42
8bbe427f 43wxCursorRefData::wxCursorRefData()
c801d85f 44{
2d17d68f 45 m_cursor = (GdkCursor *) NULL;
ff7b1510 46}
c801d85f 47
8bbe427f 48wxCursorRefData::~wxCursorRefData()
c801d85f 49{
2d17d68f 50 if (m_cursor) gdk_cursor_destroy( m_cursor );
ff7b1510 51}
c801d85f
KB
52
53//-----------------------------------------------------------------------------
54
55#define M_CURSORDATA ((wxCursorRefData *)m_refData)
56
57IMPLEMENT_DYNAMIC_CLASS(wxCursor,wxObject)
58
8bbe427f 59wxCursor::wxCursor()
c801d85f 60{
ff7b1510 61}
c801d85f 62
debe6624 63wxCursor::wxCursor( int cursorId )
c801d85f 64{
2d17d68f
RR
65 m_refData = new wxCursorRefData();
66
67 GdkCursorType gdk_cur = GDK_LEFT_PTR;
68 switch (cursorId)
69 {
f7bdcdd7 70 case wxCURSOR_DEFAULT: gdk_cur = GDK_LEFT_PTR; break;
2d17d68f
RR
71 case wxCURSOR_HAND: gdk_cur = GDK_HAND1; break;
72 case wxCURSOR_CROSS: gdk_cur = GDK_CROSSHAIR; break;
73 case wxCURSOR_SIZEWE: gdk_cur = GDK_SB_H_DOUBLE_ARROW; break;
74 case wxCURSOR_SIZENS: gdk_cur = GDK_SB_V_DOUBLE_ARROW; break;
7c39369e 75 case wxCURSOR_WAIT:
2d17d68f
RR
76 case wxCURSOR_WATCH: gdk_cur = GDK_WATCH; break;
77 case wxCURSOR_SIZING: gdk_cur = GDK_SIZING; break;
78 case wxCURSOR_SPRAYCAN: gdk_cur = GDK_SPRAYCAN; break;
79 case wxCURSOR_IBEAM: gdk_cur = GDK_XTERM; break;
80 case wxCURSOR_PENCIL: gdk_cur = GDK_PENCIL; break;
81 case wxCURSOR_NO_ENTRY: gdk_cur = GDK_PIRATE; break;
7c39369e 82 case wxCURSOR_SIZENWSE:
2d17d68f
RR
83 case wxCURSOR_SIZENESW: gdk_cur = GDK_FLEUR; break;
84 case wxCURSOR_QUESTION_ARROW: gdk_cur = GDK_QUESTION_ARROW; break;
7c39369e
VZ
85 case wxCURSOR_PAINT_BRUSH: gdk_cur = GDK_SPRAYCAN; break;
86 case wxCURSOR_MAGNIFIER: gdk_cur = GDK_PLUS; break;
87 case wxCURSOR_CHAR: gdk_cur = GDK_XTERM; break;
2d17d68f
RR
88 case wxCURSOR_LEFT_BUTTON: gdk_cur = GDK_LEFTBUTTON; break;
89 case wxCURSOR_MIDDLE_BUTTON: gdk_cur = GDK_MIDDLEBUTTON; break;
90 case wxCURSOR_RIGHT_BUTTON: gdk_cur = GDK_RIGHTBUTTON; break;
13971833
RD
91 case wxCURSOR_BULLSEYE: gdk_cur = GDK_TARGET; break;
92
957d856c
VZ
93 case wxCURSOR_POINT_LEFT: gdk_cur = GDK_SB_LEFT_ARROW; break;
94 case wxCURSOR_POINT_RIGHT: gdk_cur = GDK_SB_RIGHT_ARROW; break;
c801d85f 95/*
7c39369e
VZ
96 case wxCURSOR_DOUBLE_ARROW: gdk_cur = GDK_DOUBLE_ARROW; break;
97 case wxCURSOR_CROSS_REVERSE: gdk_cur = GDK_CROSS_REVERSE; break;
2d17d68f
RR
98 case wxCURSOR_BASED_ARROW_UP: gdk_cur = GDK_BASED_ARROW_UP; break;
99 case wxCURSOR_BASED_ARROW_DOWN: gdk_cur = GDK_BASED_ARROW_DOWN; break;
c801d85f 100*/
7c39369e 101 default:
223d09f6 102 wxFAIL_MSG(wxT("unsupported cursor type"));
7c39369e
VZ
103 // will use the standard one
104
105 case wxCURSOR_ARROW:
106 break;
2d17d68f 107 }
8bbe427f 108
2d17d68f 109 M_CURSORDATA->m_cursor = gdk_cursor_new( gdk_cur );
ff7b1510 110}
c801d85f 111
a1db952f
VS
112extern GtkWidget *wxRootWindow;
113
114wxCursor::wxCursor(const char bits[], int width, int height,
115 int hotSpotX, int hotSpotY,
116 const char maskBits[], wxColour *fg, wxColour *bg)
117{
118 if (!maskBits)
119 maskBits = bits;
120 if (!fg)
121 fg = wxBLACK;
122 if (!bg)
123 bg = wxWHITE;
124 if (hotSpotX < 0 || hotSpotX >= width)
125 hotSpotX = 0;
126 if (hotSpotY < 0 || hotSpotY >= height)
127 hotSpotY = 0;
128
129 GdkBitmap *data = gdk_bitmap_create_from_data( wxRootWindow->window, (gchar *) bits, width, height );
130 GdkBitmap *mask = gdk_bitmap_create_from_data( wxRootWindow->window, (gchar *) maskBits, width, height);
131
132 m_refData = new wxCursorRefData;
133 M_CURSORDATA->m_cursor = gdk_cursor_new_from_pixmap(
134 data, mask, fg->GetColor(), bg->GetColor(),
135 hotSpotX, hotSpotY );
136
137 gdk_bitmap_unref( data );
138 gdk_bitmap_unref( mask );
139}
140
141
c801d85f
KB
142wxCursor::wxCursor( const wxCursor &cursor )
143{
2d17d68f 144 Ref( cursor );
ff7b1510 145}
c801d85f 146
8bbe427f 147wxCursor::~wxCursor()
c801d85f 148{
ff7b1510 149}
c801d85f
KB
150
151wxCursor& wxCursor::operator = ( const wxCursor& cursor )
152{
7c39369e
VZ
153 if (*this == cursor)
154 return (*this);
155
2d17d68f 156 Ref( cursor );
7c39369e 157
2d17d68f 158 return *this;
ff7b1510 159}
c801d85f 160
8bbe427f 161bool wxCursor::operator == ( const wxCursor& cursor ) const
c801d85f 162{
2d17d68f 163 return m_refData == cursor.m_refData;
ff7b1510 164}
c801d85f 165
8bbe427f 166bool wxCursor::operator != ( const wxCursor& cursor ) const
c801d85f 167{
2d17d68f 168 return m_refData != cursor.m_refData;
ff7b1510 169}
c801d85f 170
8bbe427f 171bool wxCursor::Ok() const
c801d85f 172{
2d17d68f 173 return (m_refData != NULL);
ff7b1510 174}
c801d85f 175
8bbe427f 176GdkCursor *wxCursor::GetCursor() const
c801d85f 177{
2d17d68f 178 return M_CURSORDATA->m_cursor;
ff7b1510 179}
c801d85f
KB
180
181//-----------------------------------------------------------------------------
182// busy cursor routines
183//-----------------------------------------------------------------------------
184
238d735d 185extern wxCursor g_globalCursor;
7c39369e 186
238d735d 187static wxCursor gs_savedCursor;
89a43902 188static int gs_busyCount = 0;
c801d85f 189
f6bcfd97
BP
190const wxCursor &wxBusyCursor::GetStoredCursor()
191{
192 return gs_savedCursor;
193}
194
195const wxCursor wxBusyCursor::GetBusyCursor()
196{
197 return wxCursor(wxCURSOR_WATCH);
198}
199
8bbe427f 200void wxEndBusyCursor()
c801d85f 201{
238d735d 202 if (--gs_busyCount > 0)
89a43902
VZ
203 return;
204
238d735d
RR
205 wxSetCursor( gs_savedCursor );
206 gs_savedCursor = wxNullCursor;
13971833 207
d1dea842
RR
208 if (wxTheApp)
209 wxTheApp->SendIdleEvents();
ff7b1510 210}
c801d85f
KB
211
212void wxBeginBusyCursor( wxCursor *WXUNUSED(cursor) )
213{
238d735d 214 if (gs_busyCount++ > 0)
89a43902
VZ
215 return;
216
238d735d 217 wxASSERT_MSG( !gs_savedCursor.Ok(),
223d09f6 218 wxT("forgot to call wxEndBusyCursor, will leak memory") );
7c39369e 219
238d735d 220 gs_savedCursor = g_globalCursor;
13971833 221
238d735d 222 wxSetCursor( wxCursor(wxCURSOR_WATCH) );
13971833 223
d1dea842
RR
224 if (wxTheApp)
225 wxTheApp->SendIdleEvents();
ff7b1510 226}
c801d85f 227
8bbe427f 228bool wxIsBusy()
c801d85f 229{
89a43902 230 return gs_busyCount > 0;
ff7b1510 231}
c801d85f
KB
232
233void wxSetCursor( const wxCursor& cursor )
234{
13971833 235 if (g_isIdle)
238d735d
RR
236 wxapp_install_idle_handler();
237
238 g_globalCursor = cursor;
ff7b1510 239}