]> git.saurik.com Git - wxWidgets.git/commitdiff
cursors for cocoa
authorRyan Norton <wxprojects@comcast.net>
Wed, 6 Oct 2004 22:11:46 +0000 (22:11 +0000)
committerRyan Norton <wxprojects@comcast.net>
Wed, 6 Oct 2004 22:11:46 +0000 (22:11 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29690 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/cocoa/NSView.h
include/wx/cocoa/cursor.h
include/wx/cocoa/window.h
src/cocoa/NSView.mm
src/cocoa/cursor.mm
src/cocoa/window.mm

index 7c9fabbbfd29aa2d872e5088858538d7b23643ce..ffff7fdf92242e42e12832d21c862a8c35bbc0e7 100644 (file)
@@ -55,6 +55,8 @@ public:
     {   return false; }
     virtual bool Cocoa_otherMouseUp(WX_NSEvent theEvent)
     {   return false; }
     {   return false; }
     virtual bool Cocoa_otherMouseUp(WX_NSEvent theEvent)
     {   return false; }
+    virtual bool Cocoa_resetCursorRects()
+    {  return false; }
 };
 
 #endif // _WX_COCOA_NSVIEW_H_
 };
 
 #endif // _WX_COCOA_NSVIEW_H_
index 52e8a32786d2937533f94882d07be0fffa97f590..ecb60d73297e2442e2e2c3925a110a80c68d75cd 100644 (file)
@@ -30,6 +30,7 @@ public:
 
 protected:
     int m_width, m_height;
 
 protected:
     int m_width, m_height;
+    WX_NSCursor m_hCursor;
 };
 
 #define M_CURSORDATA ((wxCursorRefData *)m_refData)
 };
 
 #define M_CURSORDATA ((wxCursorRefData *)m_refData)
@@ -62,6 +63,11 @@ public:
   inline wxCursor& operator = (const wxCursor& cursor) { if (*this == cursor) return (*this); Ref(cursor); return *this; }
   inline bool operator == (const wxCursor& cursor) { return m_refData == cursor.m_refData; }
   inline bool operator != (const wxCursor& cursor) { return m_refData != cursor.m_refData; }
   inline wxCursor& operator = (const wxCursor& cursor) { if (*this == cursor) return (*this); Ref(cursor); return *this; }
   inline bool operator == (const wxCursor& cursor) { return m_refData == cursor.m_refData; }
   inline bool operator != (const wxCursor& cursor) { return m_refData != cursor.m_refData; }
+  
+  inline WX_NSCursor GetNSCursor() const
+  {    
+    return (M_CURSORDATA ? M_CURSORDATA->m_hCursor : 0);
+  }
 
 };
 
 
 };
 
index 30e1a12dda57ac860cc060774a30861f1a387d72..3f0138d6ce0c42b60b041cdc8d3e6027f1cb467d 100644 (file)
@@ -95,6 +95,7 @@ protected:
     virtual bool Cocoa_otherMouseDown(WX_NSEvent theEvent);
     virtual bool Cocoa_otherMouseDragged(WX_NSEvent theEvent);
     virtual bool Cocoa_otherMouseUp(WX_NSEvent theEvent);
     virtual bool Cocoa_otherMouseDown(WX_NSEvent theEvent);
     virtual bool Cocoa_otherMouseDragged(WX_NSEvent theEvent);
     virtual bool Cocoa_otherMouseUp(WX_NSEvent theEvent);
+    virtual bool Cocoa_resetCursorRects();
     void SetNSView(WX_NSView cocoaNSView);
     WX_NSView m_cocoaNSView;
     wxWindowCocoaHider *m_cocoaHider;
     void SetNSView(WX_NSView cocoaNSView);
     WX_NSView m_cocoaNSView;
     wxWindowCocoaHider *m_cocoaHider;
@@ -160,6 +161,8 @@ public:
     // Get/set client (application-useable) size
     virtual void DoGetClientSize(int *width, int *height) const;
     virtual void DoSetClientSize(int width, int size);
     // Get/set client (application-useable) size
     virtual void DoGetClientSize(int *width, int *height) const;
     virtual void DoSetClientSize(int width, int size);
+    // Set this window's tooltip
+    virtual void DoSetToolTip( wxToolTip *tip );
     // Set the size of the wxWindow (the contentView of an NSWindow)
     // wxTopLevelWindow will override this and set the NSWindow size
     // such that the contentView will be this size
     // Set the size of the wxWindow (the contentView of an NSWindow)
     // wxTopLevelWindow will override this and set the NSWindow size
     // such that the contentView will be this size
index 7a4d133ff4d7dea8826ce6ee9eb6157179bd4c26..364fa030594906b1508ac51100ad67b02f055c17 100644 (file)
@@ -73,6 +73,7 @@ void wxCocoaNSView::DisassociateNSView(WX_NSView cocoaNSView)
 - (void)otherMouseDown:(NSEvent *)theEvent;
 - (void)otherMouseDragged:(NSEvent *)theEvent;
 - (void)otherMouseUp:(NSEvent *)theEvent;
 - (void)otherMouseDown:(NSEvent *)theEvent;
 - (void)otherMouseDragged:(NSEvent *)theEvent;
 - (void)otherMouseUp:(NSEvent *)theEvent;
+- (void)resetCursorRects;
 @end // wxPoserNSView
 
 WX_IMPLEMENT_POSER(wxPoserNSView);
 @end // wxPoserNSView
 
 WX_IMPLEMENT_POSER(wxPoserNSView);
@@ -169,6 +170,13 @@ WX_IMPLEMENT_POSER(wxPoserNSView);
         [super otherMouseUp:theEvent];
 }
 
         [super otherMouseUp:theEvent];
 }
 
+- (void)resetCursorRects
+{
+    wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
+    if( !win || !win->Cocoa_resetCursorRects() )
+        [super resetCursorRects];
+}
+
 @end // implementation wxPoserNSView
 
 @interface wxNSViewNotificationObserver : NSObject
 @end // implementation wxPoserNSView
 
 @interface wxNSViewNotificationObserver : NSObject
index 76a007999e69156f67f937da7de1f4daef3a18ec..6b5011c61d6cf664a359590ceedb3d978bea72b9 100644 (file)
@@ -1,11 +1,11 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        cursor.cpp
-// Purpose:     wxCursor class
-// Author:      AUTHOR
+// Name:        cursor.mm
+// Purpose:     wxCursor class for wxCocoa
+// Author:      Ryan Norton
 // Modified by:
 // Modified by:
-// Created:     ??/??/98
+// Created:     2004-10-05
 // RCS-ID:      $Id$
 // RCS-ID:      $Id$
-// Copyright:   (c) AUTHOR
+// Copyright:   (c) Ryan Norton
 // Licence:    wxWidgets licence
 /////////////////////////////////////////////////////////////////////////////
 
 // Licence:    wxWidgets licence
 /////////////////////////////////////////////////////////////////////////////
 
     #include "wx/cursor.h"
 #endif //WX_PRECOMP
 
     #include "wx/cursor.h"
 #endif //WX_PRECOMP
 
+#import <AppKit/NSCursor.h>
+#import <AppKit/NSImage.h>
+#include <wx/cocoa/string.h>
+
 #if !USE_SHARED_LIBRARIES
 IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap)
 #endif
 
 #if !USE_SHARED_LIBRARIES
 IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap)
 #endif
 
-wxCursorRefData::wxCursorRefData()
+wxCursorRefData::wxCursorRefData() :
+    m_width(32), m_height(32), m_hCursor(nil)
 {
 {
-    m_width = 32; m_height = 32;
-
-/* TODO
-    m_hCursor = 0 ;
-*/
 }
 
 wxCursorRefData::~wxCursorRefData()
 {
 }
 
 wxCursorRefData::~wxCursorRefData()
 {
-    // TODO: destroy cursor
+    if (m_hCursor)
+        [m_hCursor release];
 }
 
 // Cursors
 }
 
 // Cursors
@@ -45,13 +46,35 @@ wxCursor::wxCursor()
 wxCursor::wxCursor(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height),
     int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), const char WXUNUSED(maskBits)[])
 {
 wxCursor::wxCursor(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height),
     int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), const char WXUNUSED(maskBits)[])
 {
+    
 }
 
 wxCursor::wxCursor(const wxString& cursor_file, long flags, int hotSpotX, int hotSpotY)
 {
     m_refData = new wxCursorRefData;
 }
 
 wxCursor::wxCursor(const wxString& cursor_file, long flags, int hotSpotX, int hotSpotY)
 {
     m_refData = new wxCursorRefData;
-
-    // TODO: create cursor from a file
+    
+    //TODO:  Not sure if this works or not
+    NSImage* theImage;
+    
+    if (flags & wxBITMAP_TYPE_MACCURSOR_RESOURCE)
+    {
+        //[NSBundle bundleForClass:[self class]]?
+        theImage = [[NSImage alloc] 
+                        initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:wxNSStringWithWxString(cursor_file) ofType:nil]
+                    ];
+        
+    }
+    else 
+        theImage = [[NSImage alloc] initByReferencingFile:wxNSStringWithWxString(cursor_file)
+                ];
+    
+    wxASSERT(theImage);
+    
+    M_CURSORDATA->m_hCursor = [[NSCursor alloc] initWithImage:theImage
+                                        hotSpot:NSMakePoint(hotSpotX, hotSpotY)
+                                ];
+    
+    [theImage release];
 }
 
 // Cursors by stock number
 }
 
 // Cursors by stock number
@@ -59,15 +82,18 @@ wxCursor::wxCursor(int cursor_type)
 {
   m_refData = new wxCursorRefData;
 
 {
   m_refData = new wxCursorRefData;
 
-/* TODO
   switch (cursor_type)
   {
   switch (cursor_type)
   {
+    case wxCURSOR_IBEAM:
+      M_CURSORDATA->m_hCursor = [[NSCursor IBeamCursor] retain];
+      break;
+    case wxCURSOR_ARROW:
+      M_CURSORDATA->m_hCursor = [[NSCursor arrowCursor] retain];
+      break;
+/* TODO
     case wxCURSOR_WAIT:
       M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_WAIT);
       break;
     case wxCURSOR_WAIT:
       M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_WAIT);
       break;
-    case wxCURSOR_IBEAM:
-      M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_IBEAM);
-      break;
     case wxCURSOR_CROSS:
       M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_CROSS);
       break;
     case wxCURSOR_CROSS:
       M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_CROSS);
       break;
@@ -168,12 +194,10 @@ wxCursor::wxCursor(int cursor_type)
       M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_BLANK");
       break;
     }
       M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_BLANK");
       break;
     }
+*/
     default:
     default:
-    case wxCURSOR_ARROW:
-      M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_ARROW);
-      break;
+    break;
   }
   }
-*/
 
 }
 
 
 }
 
@@ -184,7 +208,8 @@ wxCursor::~wxCursor()
 // Global cursor setting
 void wxSetCursor(const wxCursor& cursor)
 {
 // Global cursor setting
 void wxSetCursor(const wxCursor& cursor)
 {
-  // TODO (optional on platforms with no global cursor)
+    if (cursor.GetNSCursor())
+        [cursor.GetNSCursor() push];
 }
 
 static int wxBusyCursorCount = 0;
 }
 
 static int wxBusyCursorCount = 0;
index f2b9e653415121df2373c305019f17d831f91d85..666f6ba6a4493c375b054f5cef3e2057416b9533 100644 (file)
@@ -121,6 +121,7 @@ void wxWindowCocoaHider::Cocoa_FrameChanged(void)
     [m_owner->GetNSViewForHiding() setFrame:[m_dummyNSView frame]];
 }
 
     [m_owner->GetNSViewForHiding() setFrame:[m_dummyNSView frame]];
 }
 
+
 #ifdef WXCOCOA_FILL_DUMMY_VIEW
 bool wxWindowCocoaHider::Cocoa_drawRect(const NSRect& rect)
 {
 #ifdef WXCOCOA_FILL_DUMMY_VIEW
 bool wxWindowCocoaHider::Cocoa_drawRect(const NSRect& rect)
 {
@@ -481,6 +482,16 @@ void wxWindowCocoa::Cocoa_FrameChanged(void)
     GetEventHandler()->ProcessEvent(event);
 }
 
     GetEventHandler()->ProcessEvent(event);
 }
 
+bool wxWindowCocoa::Cocoa_resetCursorRects()
+{
+    if(!m_cursor.GetNSCursor())
+        return false;
+    
+    [GetNSView() addCursorRect: [GetNSView() visibleRect]  cursor: m_cursor.GetNSCursor()];    
+        
+    return true;
+}
+
 bool wxWindow::Close(bool force)
 {
     // The only reason this function exists is that it is virtual and
 bool wxWindow::Close(bool force)
 {
     // The only reason this function exists is that it is virtual and
@@ -873,7 +884,7 @@ bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
 }
 
 // Get the window with the focus
 }
 
 // Get the window with the focus
-wxWindow *wxWindowBase::DoFindFocus()
+wxWindow *wxWindowBase::FindFocus()
 {
     // TODO
     return NULL;
 {
     // TODO
     return NULL;