]>
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"
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;
75 case wxCURSOR_ARROWWAIT
:
77 case wxCURSOR_WATCH
: gdk_cur
= GDK_WATCH
; break;
78 case wxCURSOR_SIZING
: gdk_cur
= GDK_SIZING
; break;
79 case wxCURSOR_SPRAYCAN
: gdk_cur
= GDK_SPRAYCAN
; break;
80 case wxCURSOR_IBEAM
: gdk_cur
= GDK_XTERM
; break;
81 case wxCURSOR_PENCIL
: gdk_cur
= GDK_PENCIL
; break;
82 case wxCURSOR_NO_ENTRY
: gdk_cur
= GDK_PIRATE
; break;
83 case wxCURSOR_SIZENWSE
:
84 case wxCURSOR_SIZENESW
: gdk_cur
= GDK_FLEUR
; break;
85 case wxCURSOR_QUESTION_ARROW
: gdk_cur
= GDK_QUESTION_ARROW
; break;
86 case wxCURSOR_PAINT_BRUSH
: gdk_cur
= GDK_SPRAYCAN
; break;
87 case wxCURSOR_MAGNIFIER
: gdk_cur
= GDK_PLUS
; break;
88 case wxCURSOR_CHAR
: gdk_cur
= GDK_XTERM
; break;
89 case wxCURSOR_LEFT_BUTTON
: gdk_cur
= GDK_LEFTBUTTON
; break;
90 case wxCURSOR_MIDDLE_BUTTON
: gdk_cur
= GDK_MIDDLEBUTTON
; break;
91 case wxCURSOR_RIGHT_BUTTON
: gdk_cur
= GDK_RIGHTBUTTON
; break;
92 case wxCURSOR_BULLSEYE
: gdk_cur
= GDK_TARGET
; break;
94 case wxCURSOR_POINT_LEFT
: gdk_cur
= GDK_SB_LEFT_ARROW
; break;
95 case wxCURSOR_POINT_RIGHT
: gdk_cur
= GDK_SB_RIGHT_ARROW
; break;
97 case wxCURSOR_DOUBLE_ARROW: gdk_cur = GDK_DOUBLE_ARROW; break;
98 case wxCURSOR_CROSS_REVERSE: gdk_cur = GDK_CROSS_REVERSE; break;
99 case wxCURSOR_BASED_ARROW_UP: gdk_cur = GDK_BASED_ARROW_UP; break;
100 case wxCURSOR_BASED_ARROW_DOWN: gdk_cur = GDK_BASED_ARROW_DOWN; break;
103 wxFAIL_MSG(wxT("unsupported cursor type"));
104 // will use the standard one
110 M_CURSORDATA
->m_cursor
= gdk_cursor_new( gdk_cur
);
113 extern GtkWidget
*wxRootWindow
;
115 wxCursor::wxCursor(const char bits
[], int width
, int height
,
116 int hotSpotX
, int hotSpotY
,
117 const char maskBits
[], wxColour
*fg
, wxColour
*bg
)
125 if (hotSpotX
< 0 || hotSpotX
>= width
)
127 if (hotSpotY
< 0 || hotSpotY
>= height
)
130 GdkBitmap
*data
= gdk_bitmap_create_from_data( wxRootWindow
->window
, (gchar
*) bits
, width
, height
);
131 GdkBitmap
*mask
= gdk_bitmap_create_from_data( wxRootWindow
->window
, (gchar
*) maskBits
, width
, height
);
133 m_refData
= new wxCursorRefData
;
134 M_CURSORDATA
->m_cursor
= gdk_cursor_new_from_pixmap(
135 data
, mask
, fg
->GetColor(), bg
->GetColor(),
136 hotSpotX
, hotSpotY
);
138 gdk_bitmap_unref( data
);
139 gdk_bitmap_unref( mask
);
143 wxCursor::wxCursor( const wxCursor
&cursor
)
148 wxCursor::~wxCursor()
152 wxCursor
& wxCursor::operator = ( const wxCursor
& cursor
)
162 bool wxCursor::operator == ( const wxCursor
& cursor
) const
164 return m_refData
== cursor
.m_refData
;
167 bool wxCursor::operator != ( const wxCursor
& cursor
) const
169 return m_refData
!= cursor
.m_refData
;
172 bool wxCursor::Ok() const
174 return (m_refData
!= NULL
);
177 GdkCursor
*wxCursor::GetCursor() const
179 return M_CURSORDATA
->m_cursor
;
182 //-----------------------------------------------------------------------------
183 // busy cursor routines
184 //-----------------------------------------------------------------------------
186 extern wxCursor g_globalCursor
;
188 static wxCursor gs_savedCursor
;
189 static int gs_busyCount
= 0;
191 const wxCursor
&wxBusyCursor::GetStoredCursor()
193 return gs_savedCursor
;
196 const wxCursor
wxBusyCursor::GetBusyCursor()
198 return wxCursor(wxCURSOR_WATCH
);
201 void wxEndBusyCursor()
203 if (--gs_busyCount
> 0)
206 wxSetCursor( gs_savedCursor
);
207 gs_savedCursor
= wxNullCursor
;
210 wxTheApp
->SendIdleEvents();
213 void wxBeginBusyCursor( wxCursor
*WXUNUSED(cursor
) )
215 if (gs_busyCount
++ > 0)
218 wxASSERT_MSG( !gs_savedCursor
.Ok(),
219 wxT("forgot to call wxEndBusyCursor, will leak memory") );
221 gs_savedCursor
= g_globalCursor
;
223 wxSetCursor( wxCursor(wxCURSOR_WATCH
) );
226 wxTheApp
->SendIdleEvents();
231 return gs_busyCount
> 0;
234 void wxSetCursor( const wxCursor
& cursor
)
237 wxapp_install_idle_handler();
239 g_globalCursor
= cursor
;