]>
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"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 extern void wxapp_install_idle_handler();
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 class wxCursorRefData
: public wxObjectRefData
42 wxCursorRefData::wxCursorRefData()
44 m_cursor
= (GdkCursor
*) NULL
;
47 wxCursorRefData::~wxCursorRefData()
49 if (m_cursor
) gdk_cursor_destroy( m_cursor
);
52 //-----------------------------------------------------------------------------
54 #define M_CURSORDATA ((wxCursorRefData *)m_refData)
56 IMPLEMENT_DYNAMIC_CLASS(wxCursor
,wxObject
)
62 wxCursor::wxCursor( int cursorId
)
64 m_refData
= new wxCursorRefData();
66 GdkCursorType gdk_cur
= GDK_LEFT_PTR
;
69 case wxCURSOR_DEFAULT
: gdk_cur
= GDK_LEFT_PTR
; break;
70 case wxCURSOR_HAND
: gdk_cur
= GDK_HAND1
; break;
71 case wxCURSOR_CROSS
: gdk_cur
= GDK_CROSSHAIR
; break;
72 case wxCURSOR_SIZEWE
: gdk_cur
= GDK_SB_H_DOUBLE_ARROW
; break;
73 case wxCURSOR_SIZENS
: gdk_cur
= GDK_SB_V_DOUBLE_ARROW
; break;
75 case wxCURSOR_WATCH
: gdk_cur
= GDK_WATCH
; break;
76 case wxCURSOR_SIZING
: gdk_cur
= GDK_SIZING
; break;
77 case wxCURSOR_SPRAYCAN
: gdk_cur
= GDK_SPRAYCAN
; break;
78 case wxCURSOR_IBEAM
: gdk_cur
= GDK_XTERM
; break;
79 case wxCURSOR_PENCIL
: gdk_cur
= GDK_PENCIL
; break;
80 case wxCURSOR_NO_ENTRY
: gdk_cur
= GDK_PIRATE
; break;
81 case wxCURSOR_SIZENWSE
:
82 case wxCURSOR_SIZENESW
: gdk_cur
= GDK_FLEUR
; break;
83 case wxCURSOR_QUESTION_ARROW
: gdk_cur
= GDK_QUESTION_ARROW
; break;
84 case wxCURSOR_PAINT_BRUSH
: gdk_cur
= GDK_SPRAYCAN
; break;
85 case wxCURSOR_MAGNIFIER
: gdk_cur
= GDK_PLUS
; break;
86 case wxCURSOR_CHAR
: gdk_cur
= GDK_XTERM
; break;
87 case wxCURSOR_LEFT_BUTTON
: gdk_cur
= GDK_LEFTBUTTON
; break;
88 case wxCURSOR_MIDDLE_BUTTON
: gdk_cur
= GDK_MIDDLEBUTTON
; break;
89 case wxCURSOR_RIGHT_BUTTON
: gdk_cur
= GDK_RIGHTBUTTON
; break;
90 case wxCURSOR_BULLSEYE
: gdk_cur
= GDK_TARGET
; break;
92 case wxCURSOR_POINT_LEFT
: gdk_cur
= GDK_SB_LEFT_ARROW
; break;
93 case wxCURSOR_POINT_RIGHT
: gdk_cur
= GDK_SB_RIGHT_ARROW
; break;
95 case wxCURSOR_DOUBLE_ARROW: gdk_cur = GDK_DOUBLE_ARROW; break;
96 case wxCURSOR_CROSS_REVERSE: gdk_cur = GDK_CROSS_REVERSE; break;
97 case wxCURSOR_BASED_ARROW_UP: gdk_cur = GDK_BASED_ARROW_UP; break;
98 case wxCURSOR_BASED_ARROW_DOWN: gdk_cur = GDK_BASED_ARROW_DOWN; break;
101 wxFAIL_MSG(wxT("unsupported cursor type"));
102 // will use the standard one
108 M_CURSORDATA
->m_cursor
= gdk_cursor_new( gdk_cur
);
111 extern GtkWidget
*wxRootWindow
;
113 wxCursor::wxCursor(const char bits
[], int width
, int height
,
114 int hotSpotX
, int hotSpotY
,
115 const char maskBits
[], wxColour
*fg
, wxColour
*bg
)
123 if (hotSpotX
< 0 || hotSpotX
>= width
)
125 if (hotSpotY
< 0 || hotSpotY
>= height
)
128 GdkBitmap
*data
= gdk_bitmap_create_from_data( wxRootWindow
->window
, (gchar
*) bits
, width
, height
);
129 GdkBitmap
*mask
= gdk_bitmap_create_from_data( wxRootWindow
->window
, (gchar
*) maskBits
, width
, height
);
131 m_refData
= new wxCursorRefData
;
132 M_CURSORDATA
->m_cursor
= gdk_cursor_new_from_pixmap(
133 data
, mask
, fg
->GetColor(), bg
->GetColor(),
134 hotSpotX
, hotSpotY
);
136 gdk_bitmap_unref( data
);
137 gdk_bitmap_unref( mask
);
141 wxCursor::wxCursor( const wxCursor
&cursor
)
146 wxCursor::~wxCursor()
150 wxCursor
& wxCursor::operator = ( const wxCursor
& cursor
)
160 bool wxCursor::operator == ( const wxCursor
& cursor
) const
162 return m_refData
== cursor
.m_refData
;
165 bool wxCursor::operator != ( const wxCursor
& cursor
) const
167 return m_refData
!= cursor
.m_refData
;
170 bool wxCursor::Ok() const
172 return (m_refData
!= NULL
);
175 GdkCursor
*wxCursor::GetCursor() const
177 return M_CURSORDATA
->m_cursor
;
180 //-----------------------------------------------------------------------------
181 // busy cursor routines
182 //-----------------------------------------------------------------------------
184 extern wxCursor g_globalCursor
;
186 static wxCursor gs_savedCursor
;
187 static int gs_busyCount
= 0;
189 const wxCursor
&wxBusyCursor::GetStoredCursor()
191 return gs_savedCursor
;
194 const wxCursor
wxBusyCursor::GetBusyCursor()
196 return wxCursor(wxCURSOR_WATCH
);
199 void wxEndBusyCursor()
201 if (--gs_busyCount
> 0)
204 wxSetCursor( gs_savedCursor
);
205 gs_savedCursor
= wxNullCursor
;
210 void wxBeginBusyCursor( wxCursor
*WXUNUSED(cursor
) )
212 if (gs_busyCount
++ > 0)
215 wxASSERT_MSG( !gs_savedCursor
.Ok(),
216 wxT("forgot to call wxEndBusyCursor, will leak memory") );
218 gs_savedCursor
= g_globalCursor
;
220 wxSetCursor( wxCursor(wxCURSOR_WATCH
) );
227 return gs_busyCount
> 0;
230 void wxSetCursor( const wxCursor
& cursor
)
233 wxapp_install_idle_handler();
235 g_globalCursor
= cursor
;