cursors for cocoa

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29690 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Ryan Norton
2004-10-06 22:11:46 +00:00
parent f744f3456c
commit 5558135c48
6 changed files with 80 additions and 25 deletions

View File

@@ -55,6 +55,8 @@ public:
{ return false; } { return false; }
virtual bool Cocoa_otherMouseUp(WX_NSEvent theEvent) virtual bool Cocoa_otherMouseUp(WX_NSEvent theEvent)
{ return false; } { return false; }
virtual bool Cocoa_resetCursorRects()
{ return false; }
}; };
#endif // _WX_COCOA_NSVIEW_H_ #endif // _WX_COCOA_NSVIEW_H_

View File

@@ -30,6 +30,7 @@ public:
protected: protected:
int m_width, m_height; int m_width, m_height;
WX_NSCursor m_hCursor;
}; };
#define M_CURSORDATA ((wxCursorRefData *)m_refData) #define M_CURSORDATA ((wxCursorRefData *)m_refData)
@@ -63,6 +64,11 @@ public:
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 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);
}
}; };
extern WXDLLEXPORT void wxSetCursor(const wxCursor& cursor); extern WXDLLEXPORT void wxSetCursor(const wxCursor& cursor);

View File

@@ -95,6 +95,7 @@ protected:
virtual bool Cocoa_otherMouseDown(WX_NSEvent theEvent); virtual bool Cocoa_otherMouseDown(WX_NSEvent theEvent);
virtual bool Cocoa_otherMouseDragged(WX_NSEvent theEvent); virtual bool Cocoa_otherMouseDragged(WX_NSEvent theEvent);
virtual bool Cocoa_otherMouseUp(WX_NSEvent theEvent); virtual bool Cocoa_otherMouseUp(WX_NSEvent theEvent);
virtual bool Cocoa_resetCursorRects();
void SetNSView(WX_NSView cocoaNSView); void SetNSView(WX_NSView cocoaNSView);
WX_NSView m_cocoaNSView; WX_NSView m_cocoaNSView;
wxWindowCocoaHider *m_cocoaHider; wxWindowCocoaHider *m_cocoaHider;
@@ -160,6 +161,8 @@ public:
// Get/set client (application-useable) size // Get/set client (application-useable) size
virtual void DoGetClientSize(int *width, int *height) const; virtual void DoGetClientSize(int *width, int *height) const;
virtual void DoSetClientSize(int width, int size); 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) // Set the size of the wxWindow (the contentView of an NSWindow)
// wxTopLevelWindow will override this and set the NSWindow size // wxTopLevelWindow will override this and set the NSWindow size
// such that the contentView will be this size // such that the contentView will be this size

View File

@@ -73,6 +73,7 @@ void wxCocoaNSView::DisassociateNSView(WX_NSView cocoaNSView)
- (void)otherMouseDown:(NSEvent *)theEvent; - (void)otherMouseDown:(NSEvent *)theEvent;
- (void)otherMouseDragged:(NSEvent *)theEvent; - (void)otherMouseDragged:(NSEvent *)theEvent;
- (void)otherMouseUp:(NSEvent *)theEvent; - (void)otherMouseUp:(NSEvent *)theEvent;
- (void)resetCursorRects;
@end // wxPoserNSView @end // wxPoserNSView
WX_IMPLEMENT_POSER(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 @end // implementation wxPoserNSView
@interface wxNSViewNotificationObserver : NSObject @interface wxNSViewNotificationObserver : NSObject

View File

@@ -1,11 +1,11 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: cursor.cpp // Name: cursor.mm
// Purpose: wxCursor class // Purpose: wxCursor class for wxCocoa
// Author: AUTHOR // 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
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@@ -19,22 +19,23 @@
#include "wx/cursor.h" #include "wx/cursor.h"
#endif //WX_PRECOMP #endif //WX_PRECOMP
#import <AppKit/NSCursor.h>
#import <AppKit/NSImage.h>
#include <wx/cocoa/string.h>
#if !USE_SHARED_LIBRARIES #if !USE_SHARED_LIBRARIES
IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap) IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap)
#endif #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), wxCursor::wxCursor(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height),
int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), const char WXUNUSED(maskBits)[]) int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), const char WXUNUSED(maskBits)[])
{ {
} }
wxCursor::wxCursor(const wxString& cursor_file, long flags, int hotSpotX, int hotSpotY) wxCursor::wxCursor(const wxString& cursor_file, long flags, int hotSpotX, int hotSpotY)
{ {
m_refData = new wxCursorRefData; 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: case wxCURSOR_WAIT:
M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_WAIT); M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_WAIT);
break; break;
case wxCURSOR_IBEAM:
M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_IBEAM);
break;
case wxCURSOR_CROSS: case wxCURSOR_CROSS:
M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_CROSS); M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(NULL, IDC_CROSS);
break; break;
@@ -168,12 +194,10 @@ wxCursor::wxCursor(int cursor_type)
M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_BLANK"); M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), "wxCURSOR_BLANK");
break; 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 // Global cursor setting
void wxSetCursor(const wxCursor& cursor) 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;

View 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 #ifdef WXCOCOA_FILL_DUMMY_VIEW
bool wxWindowCocoaHider::Cocoa_drawRect(const NSRect& rect) 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) bool wxWindow::Close(bool force)
{ {
// The only reason this function exists is that it is virtual and // 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 // TODO
return NULL; return NULL;