]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/cursor.cpp
fixed tests for dashed/dotted pens under OS != NT (bug 1182319)
[wxWidgets.git] / src / msw / cursor.cpp
index c18fe15a4e3c969bb6a9d19c8c53c0c31110025f..4dee125894752eae54b4ed9b8dcfcecbaaf7bac1 100644 (file)
@@ -6,7 +6,7 @@
 // Created:     01/02/97
 // RCS-ID:      $Id$
 // Copyright:   (c) 1997-2003 Julian Smart and Vadim Zeitlin
-// Licence:     wxWidgets licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
@@ -102,7 +102,7 @@ public:
     {
         gs_globalCursor = new wxCursor;
 
-        return TRUE;
+        return true;
     }
 
     virtual void OnExit()
@@ -180,19 +180,37 @@ wxCursor::wxCursor(const wxImage& image)
     const int w = wxCursorRefData::GetStandardWidth();
     const int h = wxCursorRefData::GetStandardHeight();
 
-    const int hotSpotX = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
-    const int hotSpotY = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
+    int hotSpotX = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
+    int hotSpotY = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
+    int image_w = image.GetWidth();
+    int image_h = image.GetHeight();
 
-    wxASSERT_MSG( hotSpotX >= 0 && hotSpotX < w &&
-                    hotSpotY >= 0 && hotSpotY < h,
+    wxASSERT_MSG( hotSpotX >= 0 && hotSpotX < image_w &&
+                  hotSpotY >= 0 && hotSpotY < image_h,
                   _T("invalid cursor hot spot coordinates") );
 
-    HCURSOR hcursor = wxBitmapToHCURSOR
-                      (
-                        wxBitmap(image.Scale(w, h)),
-                        hotSpotX,
-                        hotSpotY
-                      );
+    wxImage imageSized(image); // final image of correct size
+
+    // if image is too small then place it in the center, resize it if too big
+    if ((w > image_w) && (h > image_h))
+    {
+        wxPoint offset((w - image_w)/2, (h - image_h)/2);
+        hotSpotX = hotSpotX + offset.x;
+        hotSpotY = hotSpotY + offset.y;
+
+        imageSized = image.Size(wxSize(w, h), offset);
+    }
+    else if ((w != image_w) || (h != image_h))
+    {
+        hotSpotX = int(hotSpotX * double(w) / double(image_w)); 
+        hotSpotY = int(hotSpotY * double(h) / double(image_h)); 
+
+        imageSized = image.Scale(w, h);
+    }
+
+    HCURSOR hcursor = wxBitmapToHCURSOR( wxBitmap(imageSized), 
+                                         hotSpotX, hotSpotY );
+
     if ( !hcursor )
     {
         wxLogWarning(_("Failed to create cursor."));
@@ -293,7 +311,9 @@ wxCursor::wxCursor(int idCursor)
         { false, _T("WXCURSOR_RIGHT_ARROW")  }, // wxCURSOR_RIGHT_ARROW
         { false, _T("WXCURSOR_BULLSEYE")     }, // wxCURSOR_BULLSEYE
         {  true, IDC_ARROW                   }, // WXCURSOR_CHAR
-        {  true, IDC_CROSS                   }, // WXCURSOR_CROSS
+        // Displays as an I-beam on XP, so use a cursor file
+//        {  true, IDC_CROSS                   }, // WXCURSOR_CROSS
+        {  false, _T("WXCURSOR_CROSS")       }, // WXCURSOR_CROSS
         { false, _T("WXCURSOR_HAND")         }, // wxCURSOR_HAND
         {  true, IDC_IBEAM                   }, // WXCURSOR_IBEAM
         {  true, IDC_ARROW                   }, // WXCURSOR_LEFT_BUTTON