]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/cursor.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "cursor.h"
15 #include "wx/cursor.h"
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 extern void wxapp_install_idle_handler();
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 class wxCursorRefData
: public wxObjectRefData
43 wxCursorRefData::wxCursorRefData()
45 m_cursor
= (GdkCursor
*) NULL
;
48 wxCursorRefData::~wxCursorRefData()
50 if (m_cursor
) gdk_cursor_destroy( m_cursor
);
53 //-----------------------------------------------------------------------------
55 #define M_CURSORDATA ((wxCursorRefData *)m_refData)
57 IMPLEMENT_DYNAMIC_CLASS(wxCursor
,wxObject
)
63 wxCursor::wxCursor( int cursorId
)
65 m_refData
= new wxCursorRefData();
67 GdkCursorType gdk_cur
= GDK_LEFT_PTR
;
70 case wxCURSOR_DEFAULT
: gdk_cur
= GDK_LEFT_PTR
; break;
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;
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;
82 case wxCURSOR_SIZENWSE
:
83 case wxCURSOR_SIZENESW
: gdk_cur
= GDK_FLEUR
; break;
84 case wxCURSOR_QUESTION_ARROW
: gdk_cur
= GDK_QUESTION_ARROW
; break;
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;
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;
91 case wxCURSOR_BULLSEYE
: gdk_cur
= GDK_TARGET
; break;
93 case wxCURSOR_POINT_LEFT
: gdk_cur
= GDK_SB_LEFT_ARROW
; break;
94 case wxCURSOR_POINT_RIGHT
: gdk_cur
= GDK_SB_RIGHT_ARROW
; break;
96 case wxCURSOR_DOUBLE_ARROW: gdk_cur = GDK_DOUBLE_ARROW; break;
97 case wxCURSOR_CROSS_REVERSE: gdk_cur = GDK_CROSS_REVERSE; break;
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;
102 wxFAIL_MSG(wxT("unsupported cursor type"));
103 // will use the standard one
109 M_CURSORDATA
->m_cursor
= gdk_cursor_new( gdk_cur
);
112 extern GtkWidget
*wxRootWindow
;
114 wxCursor::wxCursor(const char bits
[], int width
, int height
,
115 int hotSpotX
, int hotSpotY
,
116 const char maskBits
[], wxColour
*fg
, wxColour
*bg
)
124 if (hotSpotX
< 0 || hotSpotX
>= width
)
126 if (hotSpotY
< 0 || hotSpotY
>= height
)
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
);
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
);
137 gdk_bitmap_unref( data
);
138 gdk_bitmap_unref( mask
);
142 wxCursor::wxCursor( const wxCursor
&cursor
)
147 wxCursor::~wxCursor()
151 wxCursor
& wxCursor::operator = ( const wxCursor
& cursor
)
161 bool wxCursor::operator == ( const wxCursor
& cursor
) const
163 return m_refData
== cursor
.m_refData
;
166 bool wxCursor::operator != ( const wxCursor
& cursor
) const
168 return m_refData
!= cursor
.m_refData
;
171 bool wxCursor::Ok() const
173 return (m_refData
!= NULL
);
176 GdkCursor
*wxCursor::GetCursor() const
178 return M_CURSORDATA
->m_cursor
;
181 //-----------------------------------------------------------------------------
182 // busy cursor routines
183 //-----------------------------------------------------------------------------
185 extern wxCursor g_globalCursor
;
187 static wxCursor gs_savedCursor
;
188 static int gs_busyCount
= 0;
190 const wxCursor
&wxBusyCursor::GetStoredCursor()
192 return gs_savedCursor
;
195 const wxCursor
wxBusyCursor::GetBusyCursor()
197 return wxCursor(wxCURSOR_WATCH
);
200 void wxEndBusyCursor()
202 if (--gs_busyCount
> 0)
205 wxSetCursor( gs_savedCursor
);
206 gs_savedCursor
= wxNullCursor
;
209 wxTheApp
->SendIdleEvents();
212 void wxBeginBusyCursor( wxCursor
*WXUNUSED(cursor
) )
214 if (gs_busyCount
++ > 0)
217 wxASSERT_MSG( !gs_savedCursor
.Ok(),
218 wxT("forgot to call wxEndBusyCursor, will leak memory") );
220 gs_savedCursor
= g_globalCursor
;
222 wxSetCursor( wxCursor(wxCURSOR_WATCH
) );
225 wxTheApp
->SendIdleEvents();
230 return gs_busyCount
> 0;
233 void wxSetCursor( const wxCursor
& cursor
)
236 wxapp_install_idle_handler();
238 g_globalCursor
= cursor
;