]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/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"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
23 extern void wxapp_install_idle_handler();
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 class wxCursorRefData
: public wxObjectRefData
40 wxCursorRefData::wxCursorRefData()
42 m_cursor
= (GdkCursor
*) NULL
;
45 wxCursorRefData::~wxCursorRefData()
47 if (m_cursor
) gdk_cursor_destroy( m_cursor
);
50 //-----------------------------------------------------------------------------
52 #define M_CURSORDATA ((wxCursorRefData *)m_refData)
54 IMPLEMENT_DYNAMIC_CLASS(wxCursor
,wxObject
)
60 wxCursor::wxCursor( int cursorId
)
62 m_refData
= new wxCursorRefData();
64 GdkCursorType gdk_cur
= GDK_LEFT_PTR
;
67 case wxCURSOR_DEFAULT
: gdk_cur
= GDK_LEFT_PTR
; break;
68 case wxCURSOR_HAND
: gdk_cur
= GDK_HAND1
; break;
69 case wxCURSOR_CROSS
: gdk_cur
= GDK_CROSSHAIR
; break;
70 case wxCURSOR_SIZEWE
: gdk_cur
= GDK_SB_H_DOUBLE_ARROW
; break;
71 case wxCURSOR_SIZENS
: gdk_cur
= GDK_SB_V_DOUBLE_ARROW
; break;
73 case wxCURSOR_WATCH
: gdk_cur
= GDK_WATCH
; break;
74 case wxCURSOR_SIZING
: gdk_cur
= GDK_SIZING
; break;
75 case wxCURSOR_SPRAYCAN
: gdk_cur
= GDK_SPRAYCAN
; break;
76 case wxCURSOR_IBEAM
: gdk_cur
= GDK_XTERM
; break;
77 case wxCURSOR_PENCIL
: gdk_cur
= GDK_PENCIL
; break;
78 case wxCURSOR_NO_ENTRY
: gdk_cur
= GDK_PIRATE
; break;
79 case wxCURSOR_SIZENWSE
:
80 case wxCURSOR_SIZENESW
: gdk_cur
= GDK_FLEUR
; break;
81 case wxCURSOR_QUESTION_ARROW
: gdk_cur
= GDK_QUESTION_ARROW
; break;
82 case wxCURSOR_PAINT_BRUSH
: gdk_cur
= GDK_SPRAYCAN
; break;
83 case wxCURSOR_MAGNIFIER
: gdk_cur
= GDK_PLUS
; break;
84 case wxCURSOR_CHAR
: gdk_cur
= GDK_XTERM
; break;
85 case wxCURSOR_LEFT_BUTTON
: gdk_cur
= GDK_LEFTBUTTON
; break;
86 case wxCURSOR_MIDDLE_BUTTON
: gdk_cur
= GDK_MIDDLEBUTTON
; break;
87 case wxCURSOR_RIGHT_BUTTON
: gdk_cur
= GDK_RIGHTBUTTON
; break;
89 case wxCURSOR_DOUBLE_ARROW: gdk_cur = GDK_DOUBLE_ARROW; break;
90 case wxCURSOR_CROSS_REVERSE: gdk_cur = GDK_CROSS_REVERSE; break;
91 case wxCURSOR_BASED_ARROW_UP: gdk_cur = GDK_BASED_ARROW_UP; break;
92 case wxCURSOR_BASED_ARROW_DOWN: gdk_cur = GDK_BASED_ARROW_DOWN; break;
95 wxFAIL_MSG(_T("unsupported cursor type"));
96 // will use the standard one
102 M_CURSORDATA
->m_cursor
= gdk_cursor_new( gdk_cur
);
105 wxCursor::wxCursor( const wxCursor
&cursor
)
110 wxCursor::~wxCursor()
114 wxCursor
& wxCursor::operator = ( const wxCursor
& cursor
)
124 bool wxCursor::operator == ( const wxCursor
& cursor
) const
126 return m_refData
== cursor
.m_refData
;
129 bool wxCursor::operator != ( const wxCursor
& cursor
) const
131 return m_refData
!= cursor
.m_refData
;
134 bool wxCursor::Ok() const
136 return (m_refData
!= NULL
);
139 GdkCursor
*wxCursor::GetCursor() const
141 return M_CURSORDATA
->m_cursor
;
144 //-----------------------------------------------------------------------------
145 // busy cursor routines
146 //-----------------------------------------------------------------------------
148 extern wxCursor g_globalCursor
;
150 static wxCursor gs_savedCursor
;
151 static int gs_busyCount
= 0;
153 void wxEndBusyCursor()
155 if (--gs_busyCount
> 0)
158 wxSetCursor( gs_savedCursor
);
159 gs_savedCursor
= wxNullCursor
;
162 void wxBeginBusyCursor( wxCursor
*WXUNUSED(cursor
) )
164 if (gs_busyCount
++ > 0)
167 wxASSERT_MSG( !gs_savedCursor
.Ok(),
168 _T("forgot to call wxEndBusyCursor, will leak memory") );
170 gs_savedCursor
= g_globalCursor
;
172 wxSetCursor( wxCursor(wxCURSOR_WATCH
) );
177 return gs_busyCount
> 0;
180 void wxSetCursor( const wxCursor
& cursor
)
183 wxapp_install_idle_handler();
185 g_globalCursor
= cursor
;