diff --git a/docs/changes.txt b/docs/changes.txt index df68cb53d5..9d9a37fc88 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -60,6 +60,7 @@ All (GUI): - Allow customizing window shown by wxBusyInfo. - Make results of wxDC::DrawEllipticArc() consistent across all platforms. - XRC handler for wxAuiToolBar added (Kinaou Hervé, David Hart). +- Add wxCursor::GetHotSpot(). - Add wxFD_NO_FOLLOW style for wxFileDialog (Luca Bacci). - Add support for embedding bitmaps in generated SVG in wxSVGFileDC (iwbnwif). - Add support for sorting wxDataViewCtrl by multiple columns (Trigve). diff --git a/include/wx/cursor.h b/include/wx/cursor.h index f5cbdab5fc..f44cbaacf4 100644 --- a/include/wx/cursor.h +++ b/include/wx/cursor.h @@ -39,6 +39,8 @@ public: wxCursor(int id) { InitFromStock((wxStockCursor)id); } #endif */ + + virtual wxPoint GetHotSpot() const { return wxDefaultPosition; } }; #if defined(__WXMSW__) diff --git a/include/wx/gtk/cursor.h b/include/wx/gtk/cursor.h index bf3f22ba88..c7795feb30 100644 --- a/include/wx/gtk/cursor.h +++ b/include/wx/gtk/cursor.h @@ -36,6 +36,9 @@ public: int hotSpotX = -1, int hotSpotY = -1, const char maskBits[] = NULL, const wxColour* fg = NULL, const wxColour* bg = NULL); + + virtual wxPoint GetHotSpot() const wxOVERRIDE; + virtual ~wxCursor(); // implementation diff --git a/include/wx/msw/cursor.h b/include/wx/msw/cursor.h index c3ec916fc9..8e5dcceb5b 100644 --- a/include/wx/msw/cursor.h +++ b/include/wx/msw/cursor.h @@ -27,6 +27,9 @@ public: #if WXWIN_COMPATIBILITY_2_8 wxCursor(int id) { InitFromStock((wxStockCursor)id); } #endif + + virtual wxPoint GetHotSpot() const wxOVERRIDE; + virtual ~wxCursor(); // implementation only diff --git a/interface/wx/cursor.h b/interface/wx/cursor.h index 29177dfbac..56b5b7ad1a 100644 --- a/interface/wx/cursor.h +++ b/interface/wx/cursor.h @@ -214,6 +214,19 @@ public: */ virtual bool IsOk() const; + /** + Returns the coordinates of the cursor hot spot. + + The hot spot is the point at which the mouse is actually considered to + be when this cursor is used. + + This method is currently only implemented in wxMSW and wxGTK2+ and + simply returns ::wxDefaultPosition in the other ports. + + @since 3.1.0 + */ + wxPoint GetHotSpot() const; + /** Assignment operator, using @ref overview_refcount "reference counting". */ diff --git a/src/gtk/cursor.cpp b/src/gtk/cursor.cpp index 48af86985d..2a8d175abe 100644 --- a/src/gtk/cursor.cpp +++ b/src/gtk/cursor.cpp @@ -170,6 +170,35 @@ wxCursor::~wxCursor() { } +wxPoint wxCursor::GetHotSpot() const +{ +#if GTK_CHECK_VERSION(2,8,0) + if (GetCursor()) + { + if (gtk_check_version(2,8,0) == NULL) + { + GdkPixbuf *pixbuf = gdk_cursor_get_image(GetCursor()); + if (pixbuf) + { + wxPoint hotSpot = wxDefaultPosition; + const gchar* opt_xhot = gdk_pixbuf_get_option(pixbuf, "x_hot"); + const gchar* opt_yhot = gdk_pixbuf_get_option(pixbuf, "y_hot"); + if (opt_xhot && opt_yhot) + { + const int xhot = atoi(opt_xhot); + const int yhot = atoi(opt_yhot); + hotSpot = wxPoint(xhot, yhot); + } + g_object_unref(pixbuf); + return hotSpot; + } + } + } +#endif + + return wxDefaultPosition; +} + void wxCursor::InitFromStock( wxStockCursor cursorId ) { m_refData = new wxCursorRefData(); diff --git a/src/msw/cursor.cpp b/src/msw/cursor.cpp index 5e399713c4..9e1e69eb85 100644 --- a/src/msw/cursor.cpp +++ b/src/msw/cursor.cpp @@ -275,6 +275,18 @@ wxCursor::wxCursor(const wxString& filename, } } +wxPoint wxCursor::GetHotSpot() const +{ + if ( !GetGDIImageData() ) + return wxDefaultPosition; + + AutoIconInfo ii; + if ( !ii.GetFrom((HICON)GetGDIImageData()->m_hCursor) ) + return wxDefaultPosition; + + return wxPoint(ii.xHotspot, ii.yHotspot); +} + namespace {