X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/833fb475ceac59451d18a9d30e29d40486875193..8a31648287be0ef976f133de2786b137f1e98340:/src/gtk/cursor.cpp?ds=sidebyside diff --git a/src/gtk/cursor.cpp b/src/gtk/cursor.cpp index 76d5822955..615677e506 100644 --- a/src/gtk/cursor.cpp +++ b/src/gtk/cursor.cpp @@ -22,6 +22,7 @@ #include #include "wx/gtk/private/object.h" +#include "wx/gtk/private/gtk2-compat.h" //----------------------------------------------------------------------------- // wxCursorRefData @@ -36,6 +37,11 @@ public: virtual bool IsOk() const { return m_cursor != NULL; } GdkCursor *m_cursor; + +private: + // There is no way to copy m_cursor so we can't implement a copy ctor + // properly. + wxDECLARE_NO_COPY_CLASS(wxCursorRefData); }; wxCursorRefData::wxCursorRefData() @@ -104,8 +110,10 @@ wxCursor::wxCursor(const char bits[], int width, int height, if (hotSpotY < 0 || hotSpotY >= height) hotSpotY = 0; - GdkBitmap *data = gdk_bitmap_create_from_data( wxGetRootWindow()->window, (gchar *) bits, width, height ); - GdkBitmap *mask = gdk_bitmap_create_from_data( wxGetRootWindow()->window, (gchar *) maskBits, width, height); + GdkBitmap* data = gdk_bitmap_create_from_data( + gtk_widget_get_window(wxGetRootWindow()), const_cast(bits), width, height); + GdkBitmap* mask = gdk_bitmap_create_from_data( + gtk_widget_get_window(wxGetRootWindow()), const_cast(maskBits), width, height); m_refData = new wxCursorRefData; M_CURSORDATA->m_cursor = gdk_cursor_new_from_pixmap( @@ -216,7 +224,7 @@ void wxCursor::InitFromImage( const wxImage & image ) m_refData = new wxCursorRefData; wxImage image_copy(image); - GdkDisplay* display = gdk_drawable_get_display(wxGetRootWindow()->window); + GdkDisplay* display = gdk_drawable_get_display(gtk_widget_get_window(wxGetRootWindow())); if (gdk_display_supports_cursor_color(display)) { if (!image.HasAlpha()) @@ -252,7 +260,7 @@ void wxCursor::InitFromImage( const wxImage & image ) char* bits = new char[size]; memset(bits, 0xff, size); maskRaw = gdk_bitmap_create_from_data( - wxGetRootWindow()->window, bits, w, h); + gtk_widget_get_window(wxGetRootWindow()), bits, w, h); delete[] bits; } @@ -348,9 +356,17 @@ wxGDIRefData *wxCursor::CreateGDIRefData() const return new wxCursorRefData; } -wxGDIRefData *wxCursor::CloneGDIRefData(const wxGDIRefData *data) const +wxGDIRefData * +wxCursor::CloneGDIRefData(const wxGDIRefData * WXUNUSED(data)) const { - return new wxCursorRefData(*static_cast(data)); + // TODO: We can't clone GDK cursors at the moment. To do this we'd need + // to remember the original data from which the cursor was created + // (i.e. standard cursor type or the bitmap) or use + // gdk_cursor_get_cursor_type() (which is in 2.22+ only) and + // gdk_cursor_get_image(). + wxFAIL_MSG( wxS("Cloning cursors is not implemented in wxGTK.") ); + + return new wxCursorRefData; } //----------------------------------------------------------------------------- @@ -374,16 +390,15 @@ const wxCursor wxBusyCursor::GetBusyCursor() return wxCursor(wxCURSOR_WATCH); } -static void UpdateCursors(const wxWindowList& list, GdkDisplay*& display) +static void UpdateCursors(GdkDisplay** display) { - wxWindowList::const_iterator i = list.begin(); - for (size_t n = list.size(); n--; ++i) + wxWindowList::const_iterator i = wxTopLevelWindows.begin(); + for (size_t n = wxTopLevelWindows.size(); n--; ++i) { wxWindow* win = *i; - if (display == NULL && win->m_widget && win->m_widget->window) - display = gdk_drawable_get_display(win->m_widget->window); - win->GTKUpdateCursor(true, false); - UpdateCursors(win->GetChildren(), display); + win->GTKUpdateCursor(); + if (display && *display == NULL && win->m_widget) + *display = gtk_widget_get_display(win->m_widget); } } @@ -394,8 +409,7 @@ void wxEndBusyCursor() g_globalCursor = gs_savedCursor; gs_savedCursor = wxNullCursor; - GdkDisplay* unused = NULL; - UpdateCursors(wxTopLevelWindows, unused); + UpdateCursors(NULL); } void wxBeginBusyCursor(const wxCursor* cursor) @@ -403,13 +417,13 @@ void wxBeginBusyCursor(const wxCursor* cursor) if (gs_busyCount++ > 0) return; - wxASSERT_MSG( !gs_savedCursor.Ok(), + wxASSERT_MSG( !gs_savedCursor.IsOk(), wxT("forgot to call wxEndBusyCursor, will leak memory") ); gs_savedCursor = g_globalCursor; g_globalCursor = *cursor; GdkDisplay* display = NULL; - UpdateCursors(wxTopLevelWindows, display); + UpdateCursors(&display); if (display) gdk_display_flush(display); } @@ -422,6 +436,5 @@ bool wxIsBusy() void wxSetCursor( const wxCursor& cursor ) { g_globalCursor = cursor; - GdkDisplay* unused = NULL; - UpdateCursors(wxTopLevelWindows, unused); + UpdateCursors(NULL); }