From: Ryan Norton Date: Wed, 6 Oct 2004 22:11:46 +0000 (+0000) Subject: cursors for cocoa X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/5558135c4894ec39d39d46a3586df2bb0e89da09?ds=sidebyside cursors for cocoa git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29690 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/cocoa/NSView.h b/include/wx/cocoa/NSView.h index 7c9fabbbfd..ffff7fdf92 100644 --- a/include/wx/cocoa/NSView.h +++ b/include/wx/cocoa/NSView.h @@ -55,6 +55,8 @@ public: { return false; } virtual bool Cocoa_otherMouseUp(WX_NSEvent theEvent) { return false; } + virtual bool Cocoa_resetCursorRects() + { return false; } }; #endif // _WX_COCOA_NSVIEW_H_ diff --git a/include/wx/cocoa/cursor.h b/include/wx/cocoa/cursor.h index 52e8a32786..ecb60d7329 100644 --- a/include/wx/cocoa/cursor.h +++ b/include/wx/cocoa/cursor.h @@ -30,6 +30,7 @@ public: protected: int m_width, m_height; + WX_NSCursor m_hCursor; }; #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 WX_NSCursor GetNSCursor() const + { + return (M_CURSORDATA ? M_CURSORDATA->m_hCursor : 0); + } }; diff --git a/include/wx/cocoa/window.h b/include/wx/cocoa/window.h index 30e1a12dda..3f0138d6ce 100644 --- a/include/wx/cocoa/window.h +++ b/include/wx/cocoa/window.h @@ -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_resetCursorRects(); 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); + // 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 diff --git a/src/cocoa/NSView.mm b/src/cocoa/NSView.mm index 7a4d133ff4..364fa03059 100644 --- a/src/cocoa/NSView.mm +++ b/src/cocoa/NSView.mm @@ -73,6 +73,7 @@ void wxCocoaNSView::DisassociateNSView(WX_NSView cocoaNSView) - (void)otherMouseDown:(NSEvent *)theEvent; - (void)otherMouseDragged:(NSEvent *)theEvent; - (void)otherMouseUp:(NSEvent *)theEvent; +- (void)resetCursorRects; @end // wxPoserNSView WX_IMPLEMENT_POSER(wxPoserNSView); @@ -169,6 +170,13 @@ WX_IMPLEMENT_POSER(wxPoserNSView); [super otherMouseUp:theEvent]; } +- (void)resetCursorRects +{ + wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); + if( !win || !win->Cocoa_resetCursorRects() ) + [super resetCursorRects]; +} + @end // implementation wxPoserNSView @interface wxNSViewNotificationObserver : NSObject diff --git a/src/cocoa/cursor.mm b/src/cocoa/cursor.mm index 76a007999e..6b5011c61d 100644 --- a/src/cocoa/cursor.mm +++ b/src/cocoa/cursor.mm @@ -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: -// Created: ??/??/98 +// Created: 2004-10-05 // RCS-ID: $Id$ -// Copyright: (c) AUTHOR +// Copyright: (c) Ryan Norton // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// @@ -19,22 +19,23 @@ #include "wx/cursor.h" #endif //WX_PRECOMP +#import +#import +#include + #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() { - // TODO: destroy cursor + if (m_hCursor) + [m_hCursor release]; } // 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 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 @@ -59,15 +82,18 @@ wxCursor::wxCursor(int cursor_type) { m_refData = new wxCursorRefData; -/* TODO 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_IBEAM: - M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_IBEAM); - 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; } +*/ 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) { - // TODO (optional on platforms with no global cursor) + if (cursor.GetNSCursor()) + [cursor.GetNSCursor() push]; } static int wxBusyCursorCount = 0; diff --git a/src/cocoa/window.mm b/src/cocoa/window.mm index f2b9e65341..666f6ba6a4 100644 --- a/src/cocoa/window.mm +++ b/src/cocoa/window.mm @@ -121,6 +121,7 @@ void wxWindowCocoaHider::Cocoa_FrameChanged(void) [m_owner->GetNSViewForHiding() setFrame:[m_dummyNSView frame]]; } + #ifdef WXCOCOA_FILL_DUMMY_VIEW bool wxWindowCocoaHider::Cocoa_drawRect(const NSRect& rect) { @@ -481,6 +482,16 @@ void wxWindowCocoa::Cocoa_FrameChanged(void) 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 @@ -873,7 +884,7 @@ bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) } // Get the window with the focus -wxWindow *wxWindowBase::DoFindFocus() +wxWindow *wxWindowBase::FindFocus() { // TODO return NULL;