reworking event handling to redirect to c++ virtual functions

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58704 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2009-02-07 13:25:58 +00:00
parent 58fbf2616f
commit 4dd9fdf827
29 changed files with 878 additions and 779 deletions

View File

@@ -455,7 +455,7 @@ public :
virtual OSStatus SetTabEnabled( SInt16 tabNo , bool enable ); virtual OSStatus SetTabEnabled( SInt16 tabNo , bool enable );
void InstallEventHandler( WXWidget control = NULL ); virtual void InstallEventHandler( WXWidget control = NULL );
protected : protected :
WXEVENTHANDLERREF m_macControlEventHandler ; WXEVENTHANDLERREF m_macControlEventHandler ;
ControlRef m_controlRef; ControlRef m_controlRef;

View File

@@ -127,8 +127,28 @@ public :
virtual bool DoHandleKeyEvent(NSEvent *event); virtual bool DoHandleKeyEvent(NSEvent *event);
virtual void DoNotifyFocusEvent(bool receivedFocus); virtual void DoNotifyFocusEvent(bool receivedFocus);
void SetFlipped(bool flipped);
virtual unsigned int draggingEntered(void* sender, WXWidget slf, void* _cmd);
virtual void draggingExited(void* sender, WXWidget slf, void* _cmd);
virtual unsigned int draggingUpdated(void* sender, WXWidget slf, void* _cmd);
virtual bool performDragOperation(void* sender, WXWidget slf, void* _cmd);
virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
virtual void keyEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
virtual bool performKeyEquivalent(WX_NSEvent event, WXWidget slf, void* _cmd);
virtual bool becomeFirstResponder(WXWidget slf, void* _cmd);
virtual bool resignFirstResponder(WXWidget slf, void* _cmd);
virtual void resetCursorRects(WXWidget slf, void* _cmd);
virtual bool isFlipped(WXWidget slf, void* _cmd);
virtual void drawRect(void* rect, WXWidget slf, void* _cmd);
virtual void clickedAction(WXWidget slf, void* _cmd, void* sender);
virtual void doubleClickedAction(WXWidget slf, void* _cmd, void *sender);
protected: protected:
WXWidget m_osxView; WXWidget m_osxView;
bool m_isFlipped;
DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl) DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl)
}; };
@@ -203,217 +223,24 @@ protected :
NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size ,
bool adjustForOrigin = true ); bool adjustForOrigin = true );
// common code snippets for cocoa implementations
// later to be done using injection in method table
#define WXCOCOAIMPL_COMMON_EVENTS_INTERFACE -(void)mouseDown:(NSEvent *)event ;\
- (void)rightMouseDown:(NSEvent *)event ;\
- (void)otherMouseDown:(NSEvent *)event ;\
- (void)mouseUp:(NSEvent *)event ;\
- (void)rightMouseUp:(NSEvent *)event ;\
- (void)otherMouseUp:(NSEvent *)event ;\
- (void)mouseMoved:(NSEvent *)event;\
- (void)mouseDragged:(NSEvent *)event;\
- (void)rightMouseDragged:(NSEvent *)event;\
- (void)otherMouseDragged:(NSEvent *)event;\
- (void)scrollWheel:(NSEvent *)theEvent;\
- (void)mouseEntered:(NSEvent *)event;\
- (void)mouseExited:(NSEvent *)event;\
- (void)keyDown:(NSEvent *)event;\
- (void)keyUp:(NSEvent *)event;\
- (BOOL)performKeyEquivalent:(NSEvent *)event;\
- (void)flagsChanged:(NSEvent *)event;\
- (BOOL)becomeFirstResponder;\
- (BOOL)resignFirstResponder;\
- (void)resetCursorRects;
#define WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN -(void)rightMouseDown:(NSEvent *)event\
{\
if ( !impl->DoHandleMouseEvent(event) )\
[super rightMouseDown:event];\
}\
-(void)otherMouseDown:(NSEvent *)event\
{\
if ( !impl->DoHandleMouseEvent(event) )\
[super otherMouseDown:event];\
}\
-(void)mouseUp:(NSEvent *)event\
{\
if ( !impl->DoHandleMouseEvent(event) )\
[super mouseUp:event];\
}\
-(void)rightMouseUp:(NSEvent *)event\
{\
if ( !impl->DoHandleMouseEvent(event) )\
[super rightMouseUp:event];\
}\
-(void)otherMouseUp:(NSEvent *)event\
{\
if ( !impl->DoHandleMouseEvent(event) )\
[super otherMouseUp:event];\
}\
-(void)mouseMoved:(NSEvent *)event\
{\
if ( !impl->DoHandleMouseEvent(event) )\
[super mouseMoved:event];\
}\
-(void)mouseDragged:(NSEvent *)event\
{\
if ( !impl->DoHandleMouseEvent(event) )\
[super mouseDragged:event];\
}\
-(void)rightMouseDragged:(NSEvent *)event\
{\
if ( !impl->DoHandleMouseEvent(event) )\
[super rightMouseDragged:event];\
}\
-(void)otherMouseDragged:(NSEvent *)event\
{\
if ( !impl->DoHandleMouseEvent(event) )\
[super otherMouseDragged:event];\
}\
-(void)scrollWheel:(NSEvent *)event\
{\
if ( !impl->DoHandleMouseEvent(event) )\
[super scrollWheel:event];\
}\
-(void)mouseEntered:(NSEvent *)event\
{\
if ( !impl->DoHandleMouseEvent(event) )\
[super mouseEntered:event];\
}\
-(void)mouseExited:(NSEvent *)event\
{\
if ( !impl->DoHandleMouseEvent(event) )\
[super mouseExited:event];\
}\
-(BOOL)performKeyEquivalent:(NSEvent *)event\
{\
if ( !impl->DoHandleKeyEvent(event) )\
return [super performKeyEquivalent:event];\
return YES;\
}\
-(void)keyDown:(NSEvent *)event\
{\
if ( !impl->DoHandleKeyEvent(event) )\
[super keyDown:event];\
}\
-(void)keyUp:(NSEvent *)event\
{\
if ( !impl->DoHandleKeyEvent(event) )\
[super keyUp:event];\
}\
-(void)flagsChanged:(NSEvent *)event\
{\
if ( !impl->DoHandleKeyEvent(event) )\
[super flagsChanged:event];\
}\
- (BOOL) becomeFirstResponder\
{\
BOOL r = [super becomeFirstResponder];\
if ( r )\
impl->DoNotifyFocusEvent( true );\
return r;\
}\
- (BOOL) resignFirstResponder\
{\
BOOL r = [super resignFirstResponder];\
if ( r )\
impl->DoNotifyFocusEvent( false );\
return r;\
}\
- (void) resetCursorRects\
{\
if ( impl )\
{\
wxWindow* wxpeer = impl->GetWXPeer();\
if ( wxpeer )\
{\
NSCursor *cursor = (NSCursor*)wxpeer->GetCursor().GetHCURSOR();\
if (cursor == NULL)\
[super resetCursorRects];\
else\
[self addCursorRect: [self bounds]\
cursor: cursor];\
}\
}\
}
#define WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION -(void)mouseDown:(NSEvent *)event \
{\
if ( !impl->DoHandleMouseEvent(event) )\
[super mouseDown:event];\
}\
WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN
#define WXCOCOAIMPL_COMMON_MEMBERS wxWidgetCocoaImpl* impl;
#define WXCOCOAIMPL_COMMON_INTERFACE \
- (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation;\
- (wxWidgetCocoaImpl*) implementation;\
- (BOOL) isFlipped;\
WXCOCOAIMPL_COMMON_EVENTS_INTERFACE
#define WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE - (void)setImplementation: (wxWidgetCocoaImpl *) theImplementation\
{\
impl = theImplementation;\
}\
- (wxWidgetCocoaImpl*) implementation\
{\
return impl;\
}\
#define WXCOCOAIMPL_COMMON_IMPLEMENTATION WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \
WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \
- (BOOL) isFlipped\
{\
return YES;\
}
#define WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION_NO_MOUSEDOWN \
WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \
- (BOOL) isFlipped\
{\
return YES;\
}
#define WXCOCOAIMPL_COMMON_IMPLEMENTATION_NOT_FLIPPED WXCOCOAIMPL_COMMON_EVENTS_IMPLEMENTATION \
WXCOCOAIMPL_COMMON_IMPLEMENTATION_BASE \
- (BOOL) isFlipped\
{\
return NO;\
}
// used for many wxControls // used for many wxControls
@interface wxNSButton : NSButton @interface wxNSButton : NSButton
{ {
WXCOCOAIMPL_COMMON_MEMBERS
} }
WXCOCOAIMPL_COMMON_INTERFACE
- (void) clickedAction: (id) sender;
@end @end
@interface wxNSBox : NSBox @interface wxNSBox : NSBox
{ {
WXCOCOAIMPL_COMMON_MEMBERS
} }
WXCOCOAIMPL_COMMON_INTERFACE
@end @end
@interface wxNSTextField : NSTextField @interface wxNSTextField : NSTextField
{ {
WXCOCOAIMPL_COMMON_MEMBERS
} }
WXCOCOAIMPL_COMMON_INTERFACE
@end @end
@interface wxNSMenu : NSMenu @interface wxNSMenu : NSMenu
@@ -438,6 +265,8 @@ protected :
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem; - (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
@end @end
void wxOSXCocoaClassAddWXMethods(Class c);
#endif // __OBJC__ #endif // __OBJC__

View File

@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: wx/mac/carbon/cursor.h // Name: wx/osx/cursor.h
// Purpose: wxCursor class // Purpose: wxCursor class
// Author: Stefan Csomor // Author: Stefan Csomor
// Modified by: // Modified by:

View File

@@ -57,10 +57,9 @@ class WXDLLIMPEXP_CORE wxDropTarget: public wxDropTargetBase
virtual bool GetData(); virtual bool GetData();
bool CurrentDragHasSupportedFormat() ; bool CurrentDragHasSupportedFormat() ;
void SetCurrentDrag( void* drag ) { m_currentDrag = drag ; } void SetCurrentDragPasteboard( void* dragpasteboard ) { m_currentDragPasteboard = dragpasteboard ; }
void* GetCurrentDrag() { return m_currentDrag ; }
protected : protected :
void* m_currentDrag ; void* m_currentDragPasteboard ;
}; };
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@@ -93,13 +92,12 @@ public:
virtual wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly); virtual wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);
wxWindow* GetWindow() { return m_window ; } wxWindow* GetWindow() { return m_window ; }
void SetCurrentDrag( void* drag ) { m_currentDrag = drag ; } void SetCurrentDragPasteboard( void* dragpasteboard ) { m_currentDragPasteboard = dragpasteboard ; }
void* GetCurrentDrag() { return m_currentDrag ; }
bool MacInstallDefaultCursor(wxDragResult effect) ; bool MacInstallDefaultCursor(wxDragResult effect) ;
protected : protected :
wxWindow *m_window; wxWindow *m_window;
void* m_currentDrag ; void* m_currentDragPasteboard ;
}; };
#endif // wxUSE_DRAG_AND_DROP #endif // wxUSE_DRAG_AND_DROP

View File

@@ -138,7 +138,7 @@ public:
// event handlers // event handlers
// -------------- // --------------
void OnPaint( wxPaintEvent& event );
void OnNcPaint( wxNcPaintEvent& event ); void OnNcPaint( wxNcPaintEvent& event );
void OnEraseBackground(wxEraseEvent& event ); void OnEraseBackground(wxEraseEvent& event );
void OnMouseEvent( wxMouseEvent &event ); void OnMouseEvent( wxMouseEvent &event );

View File

@@ -107,17 +107,10 @@ bool wxDropTarget::CurrentDragHasSupportedFormat()
} }
} }
#if wxOSX_USE_CARBON
if ( !supported ) if ( !supported )
{ {
PasteboardRef pasteboard; supported = m_dataObject->HasDataInPasteboard( m_currentDragPasteboard );
if ( GetDragPasteboard( (DragReference)m_currentDrag, &pasteboard ) == noErr )
{
supported = m_dataObject->HasDataInPasteboard( pasteboard );
}
} }
#endif
return supported; return supported;
} }
@@ -166,17 +159,10 @@ bool wxDropTarget::GetData()
} }
} }
#if wxOSX_USE_CARBON
if ( !transferred ) if ( !transferred )
{ {
PasteboardRef pasteboard; transferred = m_dataObject->GetFromPasteboard( m_currentDragPasteboard );
if ( GetDragPasteboard( (DragReference)m_currentDrag, &pasteboard ) == noErr )
{
transferred = m_dataObject->GetFromPasteboard( pasteboard );
}
} }
#endif
return transferred; return transferred;
} }
@@ -369,7 +355,8 @@ pascal OSErr wxMacWindowDragTrackingHandler(
DragAttributes attributes; DragAttributes attributes;
GetDragAttributes( theDrag, &attributes ); GetDragAttributes( theDrag, &attributes );
PasteboardRef pasteboard = 0;
GetDragPasteboard( theDrag, &pasteboard );
wxNonOwnedWindow* toplevel = wxNonOwnedWindow::GetFromWXWindow( (WXWindow) theWindow ); wxNonOwnedWindow* toplevel = wxNonOwnedWindow::GetFromWXWindow( (WXWindow) theWindow );
bool optionDown = GetCurrentKeyModifiers() & optionKey; bool optionDown = GetCurrentKeyModifiers() & optionKey;
@@ -427,7 +414,7 @@ pascal OSErr wxMacWindowDragTrackingHandler(
#ifndef __LP64__ #ifndef __LP64__
HideDragHilite( theDrag ); HideDragHilite( theDrag );
#endif #endif
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ); trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
trackingGlobals->m_currentTarget->OnLeave(); trackingGlobals->m_currentTarget->OnLeave();
trackingGlobals->m_currentTarget = NULL; trackingGlobals->m_currentTarget = NULL;
trackingGlobals->m_currentTargetWindow = NULL; trackingGlobals->m_currentTargetWindow = NULL;
@@ -442,7 +429,7 @@ pascal OSErr wxMacWindowDragTrackingHandler(
{ {
if ( trackingGlobals->m_currentTarget ) if ( trackingGlobals->m_currentTarget )
{ {
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ); trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
result = trackingGlobals->m_currentTarget->OnEnter( localx, localy, result ); result = trackingGlobals->m_currentTarget->OnEnter( localx, localy, result );
} }
@@ -467,7 +454,7 @@ pascal OSErr wxMacWindowDragTrackingHandler(
{ {
if ( trackingGlobals->m_currentTarget ) if ( trackingGlobals->m_currentTarget )
{ {
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ); trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
result = trackingGlobals->m_currentTarget->OnDragOver( localx, localy, result ); result = trackingGlobals->m_currentTarget->OnDragOver( localx, localy, result );
} }
} }
@@ -517,7 +504,7 @@ pascal OSErr wxMacWindowDragTrackingHandler(
if (trackingGlobals->m_currentTarget) if (trackingGlobals->m_currentTarget)
{ {
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ); trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
trackingGlobals->m_currentTarget->OnLeave(); trackingGlobals->m_currentTarget->OnLeave();
#ifndef __LP64__ #ifndef __LP64__
HideDragHilite( theDrag ); HideDragHilite( theDrag );
@@ -545,7 +532,9 @@ pascal OSErr wxMacWindowDragReceiveHandler(
Point mouse, localMouse; Point mouse, localMouse;
int localx, localy; int localx, localy;
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ); PasteboardRef pasteboard = 0;
GetDragPasteboard( theDrag, &pasteboard );
trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
GetDragMouse( theDrag, &mouse, 0L ); GetDragMouse( theDrag, &mouse, 0L );
localMouse = mouse; localMouse = mouse;
localx = localMouse.h; localx = localMouse.h;

View File

@@ -424,7 +424,7 @@ void wxFontRefData::MacFindFont()
// QD selection algorithm is the fastest by orders of magnitude on 10.5 // QD selection algorithm is the fastest by orders of magnitude on 10.5
if ( m_faceName.IsAscii() ) if ( m_faceName.IsAscii() )
{ {
uint8 qdstyle = 0; uint8_t qdstyle = 0;
if (m_weight == wxFONTWEIGHT_BOLD) if (m_weight == wxFONTWEIGHT_BOLD)
qdstyle |= bold; qdstyle |= bold;
if (m_style == wxFONTSTYLE_ITALIC || m_style == wxFONTSTYLE_SLANT) if (m_style == wxFONTSTYLE_ITALIC || m_style == wxFONTSTYLE_SLANT)

View File

@@ -210,8 +210,6 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
CGContextClearRect( cgContext, bounds ); CGContextClearRect( cgContext, bounds );
} }
if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) ) if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
result = noErr ; result = noErr ;

View File

@@ -50,7 +50,6 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer,
[v setImage:bitmap.GetNSImage() ]; [v setImage:bitmap.GetNSImage() ];
[v setButtonType:NSMomentaryPushInButton]; [v setButtonType:NSMomentaryPushInButton];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c; return c;
} }

View File

@@ -123,24 +123,13 @@ wxSize wxButton::GetDefaultSize()
@implementation wxNSButton @implementation wxNSButton
- (id)initWithFrame:(NSRect)frame + (void)initialize
{ {
[super initWithFrame:frame]; static BOOL initialized = NO;
impl = NULL; if (!initialized)
[self setTarget: self];
[self setAction: @selector(clickedAction:)];
return self;
}
WXCOCOAIMPL_COMMON_IMPLEMENTATION
- (void) clickedAction: (id) sender
{
if ( impl )
{ {
wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); initialized = YES;
if ( wxpeer ) wxOSXCocoaClassAddWXMethods( self );
wxpeer->OSXHandleClicked(0);
} }
} }
@@ -199,7 +188,6 @@ wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer,
[v setButtonType:NSMomentaryPushInButton]; [v setButtonType:NSMomentaryPushInButton];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c; return c;
/* /*
OSStatus err; OSStatus err;
@@ -278,6 +266,5 @@ wxWidgetImplType* wxWidgetImpl::CreateDisclosureTriangle( wxWindowMac* wxpeer,
[v setTitle:wxCFStringRef( label).AsNSString()]; [v setTitle:wxCFStringRef( label).AsNSString()];
[v setImagePosition:NSImageRight]; [v setImagePosition:NSImageRight];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c; return c;
} }

View File

@@ -33,7 +33,6 @@ wxWidgetImplType* wxWidgetImpl::CreateCheckBox( wxWindowMac* wxpeer,
[v setAllowsMixedState:YES]; [v setAllowsMixedState:YES];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c; return c;
} }

View File

@@ -24,38 +24,22 @@
@interface wxNSPopUpButton : NSPopUpButton @interface wxNSPopUpButton : NSPopUpButton
{ {
WXCOCOAIMPL_COMMON_MEMBERS
} }
WXCOCOAIMPL_COMMON_INTERFACE
- (void) clickedAction: (id) sender;
@end @end
@implementation wxNSPopUpButton @implementation wxNSPopUpButton
- (id)initWithFrame:(NSRect)frame pullsDown:(BOOL) pd + (void)initialize
{ {
[super initWithFrame:frame pullsDown:pd]; static BOOL initialized = NO;
impl = NULL; if (!initialized)
[self setTarget: self];
[self setAction: @selector(clickedAction:)];
return self;
}
- (void) clickedAction: (id) sender
{
if ( impl )
{ {
wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); initialized = YES;
if ( wxpeer ) wxOSXCocoaClassAddWXMethods( self );
wxpeer->OSXHandleClicked(0);
} }
} }
WXCOCOAIMPL_COMMON_IMPLEMENTATION
- (int) intValue - (int) intValue
{ {
return [self indexOfSelectedItem]; return [self indexOfSelectedItem];
@@ -81,7 +65,6 @@ wxWidgetImplType* wxWidgetImpl::CreateChoice( wxWindowMac* wxpeer,
wxNSPopUpButton* v = [[wxNSPopUpButton alloc] initWithFrame:r pullsDown:NO]; wxNSPopUpButton* v = [[wxNSPopUpButton alloc] initWithFrame:r pullsDown:NO];
[v setMenu: menu->GetHMenu()]; [v setMenu: menu->GetHMenu()];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c; return c;
} }

View File

@@ -37,6 +37,10 @@
// implementation // implementation
// ============================================================================ // ============================================================================
// Open Items:
// - support for old style MacOS creator / type combos
// - parameter support for descending into packages as directories (setTreatsFilePackagesAsDirectories)
IMPLEMENT_CLASS(wxFileDialog, wxFileDialogBase) IMPLEMENT_CLASS(wxFileDialog, wxFileDialogBase)
wxFileDialog::wxFileDialog( wxFileDialog::wxFileDialog(
@@ -123,8 +127,8 @@ NSArray* GetTypesFromFilter( const wxString filter )
wxCFStringRef cfext(extension); wxCFStringRef cfext(extension);
[types addObject: (NSString*)cfext.AsNSString() ]; [types addObject: (NSString*)cfext.AsNSString() ];
#if 0 #if 0
// add support for classic fileType / creator here
wxUint32 fileType, creator; wxUint32 fileType, creator;
// extension -> mactypes // extension -> mactypes
#endif #endif
} }
@@ -152,7 +156,10 @@ int wxFileDialog::ShowModal()
// makes things more convenient: // makes things more convenient:
[sPanel setCanCreateDirectories:YES]; [sPanel setCanCreateDirectories:YES];
[sPanel setMessage:cf.AsNSString()]; [sPanel setMessage:cf.AsNSString()];
// if we should be able to descend into pacakges we must somehow
// be able to pass this in
[sPanel setTreatsFilePackagesAsDirectories:NO]; [sPanel setTreatsFilePackagesAsDirectories:NO];
[sPanel setCanSelectHiddenExtension:YES];
if ( HasFlag(wxFD_OVERWRITE_PROMPT) ) if ( HasFlag(wxFD_OVERWRITE_PROMPT) )
{ {
@@ -206,181 +213,4 @@ int wxFileDialog::ShowModal()
return result; return result;
} }
#if 0
wxASSERT(CreateBase(parent,wxID_ANY,pos,wxDefaultSize,style,wxDefaultValidator,wxDialogNameStr));
if ( parent )
parent->AddChild(this);
m_cocoaNSWindow = nil;
m_cocoaNSView = nil;
//Init the wildcard array
m_wildcards = [[NSMutableArray alloc] initWithCapacity:0];
//If the user requests to save - use a NSSavePanel
//else use a NSOpenPanel
if (HasFlag(wxFD_SAVE))
{
SetNSPanel([NSSavePanel savePanel]);
[GetNSSavePanel() setTitle:wxNSStringWithWxString(message)];
[GetNSSavePanel() setPrompt:@"Save"];
[GetNSSavePanel() setTreatsFilePackagesAsDirectories:YES];
[GetNSSavePanel() setCanSelectHiddenExtension:YES];
// Cached as per-app in obj-c
// [GetNSSavePanel() setExtensionHidden:YES];
//
// NB: Note that only Panther supports wildcards
// with save dialogs - not that wildcards in save
// dialogs are all that useful, anyway :)
//
}
else //m_dialogStyle & wxFD_OPEN
{
SetNSPanel([NSOpenPanel openPanel]);
[m_cocoaNSWindow setTitle:wxNSStringWithWxString(message)];
[(NSOpenPanel*)m_cocoaNSWindow setAllowsMultipleSelection:(HasFlag(wxFD_MULTIPLE))];
[(NSOpenPanel*)m_cocoaNSWindow setResolvesAliases:YES];
[(NSOpenPanel*)m_cocoaNSWindow setCanChooseFiles:YES];
[(NSOpenPanel*)m_cocoaNSWindow setCanChooseDirectories:NO];
[GetNSSavePanel() setPrompt:@"Open"];
//convert wildcards - open panel only takes file extensions -
//no actual wildcards here :)
size_t lastwcpos = 0;
bool bDescription = true;
size_t i;
for(i = wildCard.find('|');
i != wxString::npos;
i = wildCard.find('|', lastwcpos+1))
{
size_t oldi = i;
if(!bDescription)
{
bDescription = !bDescription;
//work backwards looking for a period
while(i != lastwcpos && wildCard[--i] != '.') {}
if(i == lastwcpos)
{
//no extension - can't use this wildcard
lastwcpos = oldi;
continue;
}
[m_wildcards addObject:wxNSStringWithWxString(wildCard.substr(i+1, oldi-i-1))];
}
else
bDescription = !bDescription;
lastwcpos = oldi;
}
if (!bDescription)
{
//get last wildcard
size_t oldi = wildCard.length();
i = oldi;
//work backwards looking for a period
while(i != lastwcpos && wildCard[--i] != '.') {}
if(i != lastwcpos)
[m_wildcards addObject:wxNSStringWithWxString(wildCard.substr(i+1, oldi-i-1))];
}
if ([m_wildcards count] == 0)
{
[m_wildcards release];
m_wildcards = nil;
}
}
}
wxFileDialog::~wxFileDialog()
{
[m_wildcards release];
}
void wxFileDialog::GetPaths(wxArrayString& paths) const
{
paths.Empty();
wxString dir(m_dir);
if ( m_dir.Last() != _T('\\') )
dir += _T('\\');
size_t count = m_fileNames.GetCount();
for ( size_t n = 0; n < count; n++ )
{
if (wxFileName(m_fileNames[n]).IsAbsolute())
paths.Add(m_fileNames[n]);
else
paths.Add(dir + m_fileNames[n]);
}
}
void wxFileDialog::GetFilenames(wxArrayString& files) const
{
files = m_fileNames;
}
void wxFileDialog::SetPath(const wxString& path)
{
wxString ext;
wxFileName::SplitPath(path, &m_dir, &m_fileName, &ext);
if ( !ext.empty() )
m_fileName << _T('.') << ext;
}
int wxFileDialog::ShowModal()
{
wxAutoNSAutoreleasePool thePool;
m_fileNames.Empty();
int nResult;
if (HasFlag(wxFD_SAVE))
{
nResult = [GetNSSavePanel()
runModalForDirectory:wxNSStringWithWxString(m_dir)
file:wxNSStringWithWxString(m_fileName)];
if (nResult == NSOKButton)
{
m_fileNames.Add(wxStringWithNSString([GetNSSavePanel() filename]));
m_path = m_fileNames[0];
}
}
else //m_dialogStyle & wxFD_OPEN
{
nResult = [(NSOpenPanel*)m_cocoaNSWindow
runModalForDirectory:wxNSStringWithWxString(m_dir)
file:wxNSStringWithWxString(m_fileName)
types:m_wildcards];
if (nResult == NSOKButton)
{
for(unsigned i = 0; i < [[(NSOpenPanel*)m_cocoaNSWindow filenames] count]; ++i)
{
m_fileNames.Add(wxStringWithNSString([[(NSOpenPanel*)m_cocoaNSWindow filenames] objectAtIndex:(i)]));
}
m_path = m_fileNames[0];
}
}
return nResult == NSOKButton ? wxID_OK : wxID_CANCEL;
}
#endif
#endif // wxUSE_FILEDLG #endif // wxUSE_FILEDLG

View File

@@ -19,24 +19,22 @@
@interface wxNSProgressIndicator : NSProgressIndicator @interface wxNSProgressIndicator : NSProgressIndicator
{ {
WXCOCOAIMPL_COMMON_MEMBERS
} }
WXCOCOAIMPL_COMMON_INTERFACE
@end @end
@implementation wxNSProgressIndicator @implementation wxNSProgressIndicator
- (id)initWithFrame:(NSRect)frame + (void)initialize
{ {
[super initWithFrame:frame]; static BOOL initialized = NO;
impl = NULL; if (!initialized)
return self; {
initialized = YES;
wxOSXCocoaClassAddWXMethods( self );
}
} }
WXCOCOAIMPL_COMMON_IMPLEMENTATION
@end @end
class wxOSXGaugeCocoaImpl : public wxWidgetCocoaImpl class wxOSXGaugeCocoaImpl : public wxWidgetCocoaImpl
@@ -98,7 +96,6 @@ wxWidgetImplType* wxWidgetImpl::CreateGauge( wxWindowMac* wxpeer,
[v setIndeterminate:FALSE]; [v setIndeterminate:FALSE];
[v setDoubleValue: (double) value]; [v setDoubleValue: (double) value];
wxWidgetCocoaImpl* c = new wxOSXGaugeCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxOSXGaugeCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c; return c;
} }

View File

@@ -229,27 +229,23 @@ bool wxGLContext::SetCurrent(const wxGLCanvas& win) const
@interface wxNSCustomOpenGLView : NSView @interface wxNSCustomOpenGLView : NSView
{ {
WXCOCOAIMPL_COMMON_MEMBERS
NSOpenGLContext* context; NSOpenGLContext* context;
} }
- (id)initWithFrame:(NSRect)frame;
WXCOCOAIMPL_COMMON_INTERFACE
@end @end
@implementation wxNSCustomOpenGLView @implementation wxNSCustomOpenGLView
- (id)initWithFrame:(NSRect)frame + (void)initialize
{ {
[super initWithFrame:frame]; static BOOL initialized = NO;
impl = NULL; if (!initialized)
return self; {
initialized = YES;
wxOSXCocoaClassAddWXMethods( self );
}
} }
WXCOCOAIMPL_COMMON_IMPLEMENTATION
- (BOOL)isOpaque - (BOOL)isOpaque
{ {
return YES; return YES;
@@ -279,7 +275,6 @@ bool wxGLCanvas::Create(wxWindow *parent,
NSRect r = wxOSXGetFrameForControl( this, pos , size ) ; NSRect r = wxOSXGetFrameForControl( this, pos , size ) ;
wxNSCustomOpenGLView* v = [[wxNSCustomOpenGLView alloc] initWithFrame:r]; wxNSCustomOpenGLView* v = [[wxNSCustomOpenGLView alloc] initWithFrame:r];
m_peer = new wxWidgetCocoaImpl( this, v ); m_peer = new wxWidgetCocoaImpl( this, v );
[v setImplementation:m_peer];
MacPostControlCreate(pos, size) ; MacPostControlCreate(pos, size) ;
*/ */

View File

@@ -14,6 +14,7 @@
#if wxUSE_LISTBOX #if wxUSE_LISTBOX
#include "wx/listbox.h" #include "wx/listbox.h"
#include "wx/dnd.h"
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/log.h" #include "wx/log.h"
@@ -54,14 +55,8 @@ class wxListWidgetCocoaImpl;
@interface wxNSTableView : NSTableView @interface wxNSTableView : NSTableView
{ {
wxListWidgetCocoaImpl* impl;
} }
- (void)setImplementation: (wxListWidgetCocoaImpl *) theImplementation;
- (wxListWidgetCocoaImpl*) implementation;
- (void)clickedAction: (id) sender;
- (void)doubleClickedAction: (id) sender;
@end @end
// //
@@ -147,6 +142,9 @@ public :
} }
virtual void UpdateLine( unsigned int n, wxListWidgetColumn* col = NULL ) ; virtual void UpdateLine( unsigned int n, wxListWidgetColumn* col = NULL ) ;
virtual void UpdateLineToEnd( unsigned int n); virtual void UpdateLineToEnd( unsigned int n);
virtual void clickedAction(WXWidget slf, void* _cmd, void *sender);
virtual void doubleClickedAction(void* _cmd);
protected : protected :
wxNSTableView* m_tableView ; wxNSTableView* m_tableView ;
@@ -274,55 +272,13 @@ protected:
@implementation wxNSTableView @implementation wxNSTableView
- (void)setImplementation: (wxListWidgetCocoaImpl *) theImplementation + (void)initialize
{ {
impl = theImplementation; static BOOL initialized = NO;
} if (!initialized)
- (wxListWidgetCocoaImpl*) implementation
{
return impl;
}
- (id) init
{
[super init];
impl = NULL;
[self setTarget: self];
[self setAction: @selector(clickedAction:)];
[self setDoubleAction: @selector(doubleClickedAction:)];
return self;
}
- (void) clickedAction: (id) sender
{
if ( impl )
{ {
wxListBox *list = static_cast<wxListBox*> ( impl->GetWXPeer()); initialized = YES;
wxCHECK_RET( list != NULL , wxT("Listbox expected")); wxOSXCocoaClassAddWXMethods( self );
wxCommandEvent event( wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() );
int sel = [self clickedRow];
if ((sel < 0) || (sel > (int) list->GetCount())) // OS X can select an item below the last item (why?)
return;
list->HandleLineEvent( sel, false );
}
}
- (void) doubleClickedAction: (id) sender
{
if ( impl )
{
wxListBox *list = static_cast<wxListBox*> ( impl->GetWXPeer());
wxCHECK_RET( list != NULL , wxT("Listbox expected"));
int sel = [self clickedRow];
if ((sel < 0) || (sel > (int) list->GetCount())) // OS X can select an item below the last item (why?)
return;
list->HandleLineEvent( sel, true );
} }
} }
@@ -335,6 +291,7 @@ protected:
wxListWidgetCocoaImpl::wxListWidgetCocoaImpl( wxWindowMac* peer, NSScrollView* view, wxNSTableView* tableview, wxNSTableDataSource* data ) : wxListWidgetCocoaImpl::wxListWidgetCocoaImpl( wxWindowMac* peer, NSScrollView* view, wxNSTableView* tableview, wxNSTableDataSource* data ) :
wxWidgetCocoaImpl( peer, view ), m_tableView(tableview), m_dataSource(data) wxWidgetCocoaImpl( peer, view ), m_tableView(tableview), m_dataSource(data)
{ {
InstallEventHandler( tableview );
} }
wxListWidgetCocoaImpl::~wxListWidgetCocoaImpl() wxListWidgetCocoaImpl::~wxListWidgetCocoaImpl()
@@ -514,6 +471,31 @@ void wxListWidgetCocoaImpl::UpdateLineToEnd( unsigned int n)
[m_tableView reloadData]; [m_tableView reloadData];
} }
void wxListWidgetCocoaImpl::clickedAction(WXWidget slf,void* _cmd, void *sender)
{
wxListBox *list = static_cast<wxListBox*> ( GetWXPeer());
wxCHECK_RET( list != NULL , wxT("Listbox expected"));
wxCommandEvent event( wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() );
int sel = [m_tableView clickedRow];
if ((sel < 0) || (sel > (int) list->GetCount())) // OS X can select an item below the last item (why?)
return;
list->HandleLineEvent( sel, false );
}
void wxListWidgetCocoaImpl::doubleClickedAction(void* _cmd)
{
wxListBox *list = static_cast<wxListBox*> ( GetWXPeer());
wxCHECK_RET( list != NULL , wxT("Listbox expected"));
int sel = [m_tableView clickedRow];
if ((sel < 0) || (sel > (int) list->GetCount())) // OS X can select an item below the last item (why?)
return;
list->HandleLineEvent( sel, true );
}
// accessing content // accessing content
@@ -555,7 +537,11 @@ wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer,
wxNSTableDataSource* ds = [[ wxNSTableDataSource alloc] init]; wxNSTableDataSource* ds = [[ wxNSTableDataSource alloc] init];
[tableview setDataSource:ds]; [tableview setDataSource:ds];
wxListWidgetCocoaImpl* c = new wxListWidgetCocoaImpl( wxpeer, scrollview, tableview, ds ); wxListWidgetCocoaImpl* c = new wxListWidgetCocoaImpl( wxpeer, scrollview, tableview, ds );
[tableview setImplementation:c];
// temporary hook for dnd
[tableview registerForDraggedTypes:[NSArray arrayWithObjects:
NSStringPboardType, NSFilenamesPboardType, NSTIFFPboardType, NSPICTPboardType, NSPDFPboardType, nil]];
[ds setImplementation:c]; [ds setImplementation:c];
return c; return c;
} }

View File

@@ -41,11 +41,8 @@
@interface wxNSTabView : NSTabView @interface wxNSTabView : NSTabView
{ {
WXCOCOAIMPL_COMMON_MEMBERS
} }
WXCOCOAIMPL_COMMON_INTERFACE
@end @end
@implementation wxTabViewController @implementation wxTabViewController
@@ -59,7 +56,8 @@ WXCOCOAIMPL_COMMON_INTERFACE
- (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem - (BOOL)tabView:(NSTabView *)tabView shouldSelectTabViewItem:(NSTabViewItem *)tabViewItem
{ {
wxNSTabView* view = (wxNSTabView*) tabView; wxNSTabView* view = (wxNSTabView*) tabView;
wxWidgetCocoaImpl* viewimpl = [view implementation]; wxWidgetCocoaImpl* viewimpl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( view );
if ( viewimpl ) if ( viewimpl )
{ {
// wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer(); // wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer();
@@ -71,7 +69,7 @@ WXCOCOAIMPL_COMMON_INTERFACE
{ {
wxNSTabView* view = (wxNSTabView*) tabView; wxNSTabView* view = (wxNSTabView*) tabView;
wxWidgetCocoaImpl* viewimpl = [view implementation]; wxWidgetCocoaImpl* viewimpl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( view );
if ( viewimpl ) if ( viewimpl )
{ {
wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer(); wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer();
@@ -83,7 +81,15 @@ WXCOCOAIMPL_COMMON_INTERFACE
@implementation wxNSTabView @implementation wxNSTabView
WXCOCOAIMPL_COMMON_IMPLEMENTATION + (void)initialize
{
static BOOL initialized = NO;
if (!initialized)
{
initialized = YES;
wxOSXCocoaClassAddWXMethods( self );
}
}
@end @end
@@ -244,7 +250,6 @@ wxWidgetImplType* wxWidgetImpl::CreateTabView( wxWindowMac* wxpeer,
wxNSTabView* v = [[wxNSTabView alloc] initWithFrame:r]; wxNSTabView* v = [[wxNSTabView alloc] initWithFrame:r];
[v setTabViewType:tabstyle]; [v setTabViewType:tabstyle];
wxWidgetCocoaImpl* c = new wxCocoaTabView( wxpeer, v ); wxWidgetCocoaImpl* c = new wxCocoaTabView( wxpeer, v );
[v setImplementation:c];
[v setDelegate: controller]; [v setDelegate: controller];
return c; return c;
} }

View File

@@ -31,7 +31,6 @@ wxWidgetImplType* wxWidgetImpl::CreateRadioButton( wxWindowMac* wxpeer,
[v setButtonType:NSRadioButton]; [v setButtonType:NSRadioButton];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c; return c;
} }

View File

@@ -23,80 +23,18 @@
@interface wxNSScroller : NSScroller @interface wxNSScroller : NSScroller
{ {
WXCOCOAIMPL_COMMON_MEMBERS
} }
WXCOCOAIMPL_COMMON_INTERFACE
- (void) clickedAction: (id) sender;
@end @end
@implementation wxNSScroller @implementation wxNSScroller
- (id)initWithFrame:(NSRect)frame + (void)initialize
{ {
[super initWithFrame:frame]; static BOOL initialized = NO;
impl = NULL; if (!initialized)
[self setTarget: self];
[self setAction: @selector(clickedAction:)];
return self;
}
WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN
// we will have a mouseDown, then in the native
// implementation of mouseDown the tracking code
// is calling clickedAction, therefore we wire this
// to thumbtrack and only after super mouseDown
// returns we will call the thumbrelease
- (void) clickedAction: (id) sender
{
if ( impl )
{ {
wxEventType scrollEvent = wxEVT_NULL; initialized = YES;
switch ([self hitPart]) wxOSXCocoaClassAddWXMethods(self);
{
case NSScrollerIncrementLine:
scrollEvent = wxEVT_SCROLL_LINEDOWN;
break;
case NSScrollerIncrementPage:
scrollEvent = wxEVT_SCROLL_PAGEDOWN;
break;
case NSScrollerDecrementLine:
scrollEvent = wxEVT_SCROLL_LINEUP;
break;
case NSScrollerDecrementPage:
scrollEvent = wxEVT_SCROLL_PAGEUP;
break;
case NSScrollerKnob:
case NSScrollerKnobSlot:
scrollEvent = wxEVT_SCROLL_THUMBTRACK;
break;
case NSScrollerNoPart:
default:
return;
}
wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
if ( wxpeer )
wxpeer->TriggerScrollEvent(scrollEvent);
}
}
-(void)mouseDown:(NSEvent *)event
{
if ( !impl->DoHandleMouseEvent(event) )
[super mouseDown:event];
// send a release event in case we've been tracking the thumb
NSScrollerPart hit = [self hitPart];
if ( impl && (hit == NSScrollerKnob || hit == NSScrollerKnobSlot) )
{
wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
if ( wxpeer )
wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBRELEASE);
} }
} }
@@ -118,7 +56,7 @@ public :
void SetScrollThumb( wxInt32 value, wxInt32 thumbSize ) void SetScrollThumb( wxInt32 value, wxInt32 thumbSize )
{ {
double v = ((double) value)/m_maximum; double v = ((double) value)/m_maximum;
double t = ((double) thumbSize)/m_maximum; double t = ((double) thumbSize)/(m_maximum+thumbSize);
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
[(wxNSScroller*) m_osxView setFloatValue:v knobProportion:t]; [(wxNSScroller*) m_osxView setFloatValue:v knobProportion:t];
#else #else
@@ -127,19 +65,76 @@ public :
#endif #endif
} }
wxInt32 GetValue() const virtual wxInt32 GetValue() const
{ {
return [(wxNSScroller*) m_osxView floatValue] * m_maximum; return [(wxNSScroller*) m_osxView floatValue] * m_maximum;
} }
wxInt32 GetMaximum() const virtual wxInt32 GetMaximum() const
{ {
return m_maximum; return m_maximum;
} }
virtual void clickedAction(WXWidget slf, void* _cmd, void *sender);
virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
protected: protected:
wxInt32 m_maximum; wxInt32 m_maximum;
}; };
// we will have a mouseDown, then in the native
// implementation of mouseDown the tracking code
// is calling clickedAction, therefore we wire this
// to thumbtrack and only after super mouseDown
// returns we will call the thumbrelease
void wxOSXScrollBarCocoaImpl::clickedAction( WXWidget slf, void *_cmd, void *sender)
{
wxEventType scrollEvent = wxEVT_NULL;
switch ([(NSScroller*)m_osxView hitPart])
{
case NSScrollerIncrementLine:
scrollEvent = wxEVT_SCROLL_LINEDOWN;
break;
case NSScrollerIncrementPage:
scrollEvent = wxEVT_SCROLL_PAGEDOWN;
break;
case NSScrollerDecrementLine:
scrollEvent = wxEVT_SCROLL_LINEUP;
break;
case NSScrollerDecrementPage:
scrollEvent = wxEVT_SCROLL_PAGEUP;
break;
case NSScrollerKnob:
case NSScrollerKnobSlot:
scrollEvent = wxEVT_SCROLL_THUMBTRACK;
break;
case NSScrollerNoPart:
default:
return;
}
wxWindow* wxpeer = (wxWindow*) GetWXPeer();
if ( wxpeer )
wxpeer->TriggerScrollEvent(scrollEvent);
}
void wxOSXScrollBarCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
{
wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
// send a release event in case we've been tracking the thumb
if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 )
{
NSScrollerPart hit = [(NSScroller*)m_osxView hitPart];
if ( (hit == NSScrollerKnob || hit == NSScrollerKnobSlot) )
{
wxWindow* wxpeer = (wxWindow*) GetWXPeer();
if ( wxpeer )
wxpeer->OSXHandleClicked(0);
}
}
}
wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer, wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer,
wxWindowMac* parent, wxWindowMac* parent,
wxWindowID id, wxWindowID id,
@@ -152,7 +147,6 @@ wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer,
wxNSScroller* v = [[wxNSScroller alloc] initWithFrame:r]; wxNSScroller* v = [[wxNSScroller alloc] initWithFrame:r];
wxWidgetCocoaImpl* c = new wxOSXScrollBarCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxOSXScrollBarCocoaImpl( wxpeer, v );
[v setImplementation:c];
[v setEnabled:YES]; [v setEnabled:YES];
return c; return c;
} }

View File

@@ -18,27 +18,38 @@
@interface wxNSSlider : NSSlider @interface wxNSSlider : NSSlider
{ {
WXCOCOAIMPL_COMMON_MEMBERS
} }
WXCOCOAIMPL_COMMON_INTERFACE
- (void) clickedAction: (id) sender;
@end @end
@implementation wxNSSlider @implementation wxNSSlider
- (id)initWithFrame:(NSRect)frame + (void)initialize
{ {
[super initWithFrame:frame]; static BOOL initialized = NO;
impl = NULL; if (!initialized)
[self setTarget: self]; {
[self setAction: @selector(clickedAction:)]; initialized = YES;
return self; wxOSXCocoaClassAddWXMethods(self);
}
} }
WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN @end
class wxSliderCocoaImpl : public wxWidgetCocoaImpl
{
public :
wxSliderCocoaImpl(wxWindowMac* peer , WXWidget w) :
wxWidgetCocoaImpl(peer, w)
{
}
~wxSliderCocoaImpl()
{
}
virtual void clickedAction(WXWidget slf, void* _cmd, void *sender);
virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
};
// we will have a mouseDown, then in the native // we will have a mouseDown, then in the native
// implementation of mouseDown the tracking code // implementation of mouseDown the tracking code
@@ -46,30 +57,26 @@ WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN
// to thumbtrack and only after super mouseDown // to thumbtrack and only after super mouseDown
// returns we will call the thumbrelease // returns we will call the thumbrelease
- (void) clickedAction: (id) sender void wxSliderCocoaImpl::clickedAction( WXWidget slf, void *_cmd, void *sender)
{ {
if ( impl ) wxWindow* wxpeer = (wxWindow*) GetWXPeer();
{ if ( wxpeer )
wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBTRACK);
if ( wxpeer )
wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBTRACK);
}
} }
-(void)mouseDown:(NSEvent *)event void wxSliderCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
{ {
if ( !impl->DoHandleMouseEvent(event) ) wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
[super mouseDown:event];
if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 )
if ( impl )
{ {
wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); wxWindow* wxpeer = (wxWindow*) GetWXPeer();
if ( wxpeer ) if ( wxpeer )
wxpeer->OSXHandleClicked(0); wxpeer->OSXHandleClicked(0);
} }
} }
@end
wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer, wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer,
wxWindowMac* parent, wxWindowMac* parent,
@@ -102,8 +109,7 @@ wxWidgetImplType* wxWidgetImpl::CreateSlider( wxWindowMac* wxpeer,
[v setMinValue: minimum]; [v setMinValue: minimum];
[v setMaxValue: maximum]; [v setMaxValue: maximum];
[v setFloatValue: (double) value]; [v setFloatValue: (double) value];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxSliderCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c; return c;
} }

View File

@@ -18,68 +18,80 @@
@interface wxNSStepper : NSStepper @interface wxNSStepper : NSStepper
{ {
WXCOCOAIMPL_COMMON_MEMBERS
int formerValue;
} }
WXCOCOAIMPL_COMMON_INTERFACE
- (void) clickedAction: (id) sender;
@end @end
@implementation wxNSStepper @implementation wxNSStepper
- (id)initWithFrame:(NSRect)frame + (void)initialize
{ {
[super initWithFrame:frame]; static BOOL initialized = NO;
impl = NULL; if (!initialized)
formerValue = 0;
[self setTarget: self];
[self setAction: @selector(clickedAction:)];
return self;
}
- (void) clickedAction: (id) sender
{
if ( impl )
{ {
wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); initialized = YES;
if ( wxpeer ) wxOSXCocoaClassAddWXMethods(self);
{
// because wx expects to be able to veto
// a change we must revert the value change
// and expose it
int currentValue = [self intValue];
[self setIntValue:formerValue];
int inc = currentValue-formerValue;
// adjust for wrap arounds
if ( inc > 1 )
inc = -1;
else if (inc < -1 )
inc = 1;
if ( inc == 1 )
wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEUP);
else if ( inc == -1 )
wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEDOWN);
formerValue = [self intValue];
}
} }
} }
-(void)mouseDown:(NSEvent *)event @end
class wxSpinButtonCocoaImpl : public wxWidgetCocoaImpl
{ {
formerValue = [self intValue]; public :
if ( !impl->DoHandleMouseEvent(event) ) wxSpinButtonCocoaImpl(wxWindowMac* peer , WXWidget w) :
[super mouseDown:event]; wxWidgetCocoaImpl(peer, w)
{
m_formerValue = 0;
}
~wxSpinButtonCocoaImpl()
{
}
virtual void clickedAction(WXWidget slf, void* _cmd, void *sender);
virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
private:
int m_formerValue;
};
void wxSpinButtonCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
{
// send a release event in case we've been tracking the thumb
if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 )
{
m_formerValue = [(NSStepper*)m_osxView intValue];
}
wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
} }
WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN void wxSpinButtonCocoaImpl::clickedAction( WXWidget slf, void *_cmd, void *sender)
{
wxWindow* wxpeer = (wxWindow*) GetWXPeer();
if ( wxpeer )
{
// because wx expects to be able to veto
// a change we must revert the value change
// and expose it
int currentValue = [(NSStepper*)m_osxView intValue];
[(NSStepper*)m_osxView setIntValue:m_formerValue];
int inc = currentValue-m_formerValue;
// adjust for wrap arounds
if ( inc > 1 )
inc = -1;
else if (inc < -1 )
inc = 1;
if ( inc == 1 )
wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEUP);
else if ( inc == -1 )
wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEDOWN);
@end m_formerValue = [(NSStepper*)m_osxView intValue];
}
}
wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer, wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer,
wxWindowMac* parent, wxWindowMac* parent,
@@ -102,8 +114,7 @@ wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer,
if ( style & wxSP_WRAP ) if ( style & wxSP_WRAP )
[v setValueWraps:YES]; [v setValueWraps:YES];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxSpinButtonCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c; return c;
} }

View File

@@ -31,26 +31,30 @@
@interface wxNSSearchField : NSSearchField @interface wxNSSearchField : NSSearchField
{ {
WXCOCOAIMPL_COMMON_MEMBERS
} }
WXCOCOAIMPL_COMMON_INTERFACE
@end @end
@implementation wxNSSearchField @implementation wxNSSearchField
+ (void)initialize
{
static BOOL initialized = NO;
if (!initialized)
{
initialized = YES;
wxOSXCocoaClassAddWXMethods( self );
}
}
- (id)initWithFrame:(NSRect)frame - (id)initWithFrame:(NSRect)frame
{ {
[super initWithFrame:frame]; [super initWithFrame:frame];
impl = NULL;
[self setTarget: self]; [self setTarget: self];
[self setAction: @selector(searchAction:)]; [self setAction: @selector(searchAction:)];
return self; return self;
} }
WXCOCOAIMPL_COMMON_IMPLEMENTATION
// use our common calls // use our common calls
- (void) setTitle:(NSString *) title - (void) setTitle:(NSString *) title
{ {
@@ -59,6 +63,7 @@ WXCOCOAIMPL_COMMON_IMPLEMENTATION
- (void) searchAction: (id) sender - (void) searchAction: (id) sender
{ {
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if ( impl ) if ( impl )
{ {
wxSearchCtrl* wxpeer = dynamic_cast<wxSearchCtrl*>( impl->GetWXPeer() ); wxSearchCtrl* wxpeer = dynamic_cast<wxSearchCtrl*>( impl->GetWXPeer() );
@@ -168,7 +173,6 @@ wxWidgetImplType* wxWidgetImpl::CreateSearchControl( wxTextCtrl* wxpeer,
wxNSSearchFieldControl* c = new wxNSSearchFieldControl( wxpeer, v ); wxNSSearchFieldControl* c = new wxNSSearchFieldControl( wxpeer, v );
c->SetStringValue( str ); c->SetStringValue( str );
[v setImplementation:c];
return c; return c;
} }

View File

@@ -18,7 +18,15 @@
@implementation wxNSBox @implementation wxNSBox
WXCOCOAIMPL_COMMON_IMPLEMENTATION_NOT_FLIPPED + (void)initialize
{
static BOOL initialized = NO;
if (!initialized)
{
initialized = YES;
wxOSXCocoaClassAddWXMethods( self );
}
}
@end @end
@@ -34,7 +42,7 @@ wxWidgetImplType* wxWidgetImpl::CreateGroupBox( wxWindowMac* wxpeer,
NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
wxNSBox* v = [[wxNSBox alloc] initWithFrame:r]; wxNSBox* v = [[wxNSBox alloc] initWithFrame:r];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c]; c->SetFlipped(false);
return c; return c;
} }

View File

@@ -44,7 +44,6 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticLine( wxWindowMac* wxpeer,
NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
wxNSBox* v = [[wxNSBox alloc] initWithFrame:r]; wxNSBox* v = [[wxNSBox alloc] initWithFrame:r];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c; return c;
} }

View File

@@ -88,7 +88,6 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
[v setDrawsBackground:NO]; [v setDrawsBackground:NO];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c; return c;
/* /*
Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size ); Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );

View File

@@ -51,12 +51,19 @@
@implementation wxNSTextField @implementation wxNSTextField
WXCOCOAIMPL_COMMON_IMPLEMENTATION + (void)initialize
{
static BOOL initialized = NO;
if (!initialized)
{
initialized = YES;
wxOSXCocoaClassAddWXMethods( self );
}
}
- (id)initWithFrame:(NSRect)frame - (id)initWithFrame:(NSRect)frame
{ {
[super initWithFrame:frame]; [super initWithFrame:frame];
impl = NULL;
[self setDelegate: self]; [self setDelegate: self];
[self setTarget: self]; [self setTarget: self];
// [self setAction: @selector(enterAction:)]; // [self setAction: @selector(enterAction:)];
@@ -190,7 +197,6 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
//[v setDrawsBackground:NO]; //[v setDrawsBackground:NO];
wxWidgetCocoaImpl* c = new wxNSTextFieldControl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxNSTextFieldControl( wxpeer, v );
[v setImplementation:c];
return c; return c;
} }

View File

@@ -40,7 +40,6 @@ wxWidgetImplType* wxWidgetImpl::CreateToggleButton( wxWindowMac* wxpeer,
[v setBezelStyle:NSRoundedBezelStyle]; [v setBezelStyle:NSRoundedBezelStyle];
[v setButtonType:NSOnOffButton]; [v setButtonType:NSOnOffButton];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c; return c;
} }
@@ -59,7 +58,6 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapToggleButton( wxWindowMac* wxpeer,
[v setBezelStyle:NSRegularSquareBezelStyle]; [v setBezelStyle:NSRegularSquareBezelStyle];
[v setButtonType:NSOnOffButton]; [v setButtonType:NSOnOffButton];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c; return c;
} }

View File

@@ -17,13 +17,19 @@
#endif #endif
#ifdef __WXMAC__ #ifdef __WXMAC__
#include "wx/osx/private.h" #include "wx/osx/private.h"
#endif #endif
#if wxUSE_CARET #if wxUSE_CARET
#include "wx/caret.h" #include "wx/caret.h"
#endif #endif
#if wxUSE_DRAG_AND_DROP
#include "wx/dnd.h"
#endif
#include <objc/objc-runtime.h>
NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin ) NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
{ {
int x, y, w, h ; int x, y, w, h ;
@@ -37,19 +43,13 @@ NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const
@interface wxNSView : NSView @interface wxNSView : NSView
{ {
WXCOCOAIMPL_COMMON_MEMBERS
} }
- (void)drawRect: (NSRect) rect;
WXCOCOAIMPL_COMMON_INTERFACE
- (BOOL) canBecomeKeyView; - (BOOL) canBecomeKeyView;
@end // wxNSView @end // wxNSView
@interface NSView(PossibleMethods) @interface NSView(PossibleMethods)
- (void)setImplementation:(wxWidgetCocoaImpl *)theImplementation;
- (void)setTitle:(NSString *)aString; - (void)setTitle:(NSString *)aString;
- (void)setStringValue:(NSString *)aString; - (void)setStringValue:(NSString *)aString;
- (void)setIntValue:(int)anInt; - (void)setIntValue:(int)anInt;
@@ -70,6 +70,10 @@ WXCOCOAIMPL_COMMON_INTERFACE
- (void)setControlSize:(NSControlSize)size; - (void)setControlSize:(NSControlSize)size;
- (id)contentView; - (id)contentView;
- (void)setTarget:(id)anObject;
- (void)setAction:(SEL)aSelector;
- (void)setDoubleAction:(SEL)aSelector;
@end @end
long wxOSXTranslateCocoaKey( int unichar ) long wxOSXTranslateCocoaKey( int unichar )
@@ -336,60 +340,16 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
@implementation wxNSView @implementation wxNSView
#define OSX_DEBUG_DRAWING 0 + (void)initialize
- (void)drawRect: (NSRect) rect
{ {
if ( impl ) static BOOL initialized = NO;
if (!initialized)
{ {
CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]; initialized = YES;
CGContextSaveGState( context ); wxOSXCocoaClassAddWXMethods( self );
#if OSX_DEBUG_DRAWING
CGContextBeginPath( context );
CGContextMoveToPoint(context, 0, 0);
NSRect bounds = [self bounds];
CGContextAddLineToPoint(context, 10, 0);
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, 0, 10);
CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
CGContextAddLineToPoint(context, bounds.size.width, bounds.size.height-10);
CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
CGContextAddLineToPoint(context, bounds.size.width-10, bounds.size.height);
CGContextClosePath( context );
CGContextStrokePath(context);
#endif
if ( [ self isFlipped ] == NO )
{
CGContextTranslateCTM( context, 0, [self bounds].size.height );
CGContextScaleCTM( context, 1, -1 );
}
wxRegion updateRgn;
const NSRect *rects;
NSInteger count;
[self getRectsBeingDrawn:&rects count:&count];
for ( int i = 0 ; i < count ; ++i )
{
updateRgn.Union(wxFromNSRect(self, rects[i]) );
}
wxWindow* wxpeer = impl->GetWXPeer();
wxpeer->GetUpdateRegion() = updateRgn;
wxpeer->MacSetCGContextRef( context );
wxPaintEvent event;
event.SetTimestamp(0); // todo
event.SetEventObject(wxpeer);
wxpeer->HandleWindowEvent(event);
CGContextRestoreGState( context );
} }
} }
WXCOCOAIMPL_COMMON_IMPLEMENTATION
- (BOOL) canBecomeKeyView - (BOOL) canBecomeKeyView
{ {
return YES; return YES;
@@ -397,26 +357,533 @@ WXCOCOAIMPL_COMMON_IMPLEMENTATION
@end // wxNSView @end // wxNSView
//
// event handlers
//
#if wxUSE_DRAG_AND_DROP
// see http://lists.apple.com/archives/Cocoa-dev/2005/Jul/msg01244.html
// for details on the NSPasteboard -> PasteboardRef conversion
NSDragOperation wxOSX_draggingEntered( id self, SEL _cmd, id <NSDraggingInfo>sender )
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl == NULL)
return NSDragOperationNone;
return impl->draggingEntered(sender, self, _cmd);
}
void wxOSX_draggingExited( id self, SEL _cmd, id <NSDraggingInfo> sender )
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl == NULL)
return ;
return impl->draggingExited(sender, self, _cmd);
}
NSDragOperation wxOSX_draggingUpdated( id self, SEL _cmd, id <NSDraggingInfo>sender )
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl == NULL)
return NSDragOperationNone;
return impl->draggingUpdated(sender, self, _cmd);
}
BOOL wxOSX_performDragOperation( id self, SEL _cmd, id <NSDraggingInfo> sender )
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl == NULL)
return NSDragOperationNone;
return impl->performDragOperation(sender, self, _cmd) ? YES:NO ;
}
void wxOSX_mouseEvent(NSView* self, SEL _cmd, NSEvent *event)
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl == NULL)
return;
impl->mouseEvent(event, self, _cmd);
}
void wxOSX_keyEvent(NSView* self, SEL _cmd, NSEvent *event)
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl == NULL)
return;
impl->keyEvent(event, self, _cmd);
}
BOOL wxOSX_performKeyEquivalent(NSView* self, SEL _cmd, NSEvent *event)
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl == NULL)
return NO;
return impl->performKeyEquivalent(event, self, _cmd);
}
BOOL wxOSX_becomeFirstResponder(NSView* self, SEL _cmd)
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl == NULL)
return NO;
return impl->becomeFirstResponder(self, _cmd);
}
BOOL wxOSX_resignFirstResponder(NSView* self, SEL _cmd)
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl == NULL)
return NO;
return impl->resignFirstResponder(self, _cmd);
}
void wxOSX_resetCursorRects(NSView* self, SEL _cmd)
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl == NULL)
return;
impl->resetCursorRects(self, _cmd);
}
BOOL wxOSX_isFlipped(NSView* self, SEL _cmd)
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl == NULL)
return NO;
return impl->isFlipped(self, _cmd) ? YES:NO;
}
void wxOSX_drawRect(NSView* self, SEL _cmd, NSRect rect)
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl == NULL)
return;
return impl->drawRect(&rect, self, _cmd);
}
void wxOSX_clickedAction(NSView* self, SEL _cmd, id sender)
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl == NULL)
return;
impl->clickedAction(self, _cmd, sender);
}
void wxOSX_doubleClickedAction(NSView* self, SEL _cmd, id sender)
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if (impl == NULL)
return;
impl->doubleClickedAction(self, _cmd, sender);
}
unsigned int wxWidgetCocoaImpl::draggingEntered(void* s, WXWidget slf, void *_cmd)
{
id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
NSPasteboard *pboard = [sender draggingPasteboard];
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
wxWindow* wxpeer = GetWXPeer();
if ( wxpeer == NULL )
return NSDragOperationNone;
wxDropTarget* target = wxpeer->GetDropTarget();
if ( target == NULL )
return NSDragOperationNone;
wxDragResult result = wxDragNone;
wxPoint pt = wxFromNSPoint( m_osxView, [sender draggingLocation] );
if ( sourceDragMask & NSDragOperationLink )
result = wxDragLink;
else if ( sourceDragMask & NSDragOperationCopy )
result = wxDragCopy;
else if ( sourceDragMask & NSDragOperationMove )
result = wxDragMove;
PasteboardRef pboardRef;
PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
target->SetCurrentDragPasteboard(pboardRef);
result = target->OnEnter(pt.x, pt.y, result);
CFRelease(pboardRef);
NSDragOperation nsresult = NSDragOperationNone;
switch (result )
{
case wxDragLink:
nsresult = NSDragOperationLink;
case wxDragMove:
nsresult = NSDragOperationMove;
case wxDragCopy:
nsresult = NSDragOperationCopy;
default :
break;
}
return nsresult;
}
void wxWidgetCocoaImpl::draggingExited(void* s, WXWidget slf, void *_cmd)
{
id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
NSPasteboard *pboard = [sender draggingPasteboard];
wxWindow* wxpeer = GetWXPeer();
if ( wxpeer == NULL )
return;
wxDropTarget* target = wxpeer->GetDropTarget();
if ( target == NULL )
return;
PasteboardRef pboardRef;
PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
target->SetCurrentDragPasteboard(pboardRef);
target->OnLeave();
CFRelease(pboardRef);
}
unsigned int wxWidgetCocoaImpl::draggingUpdated(void* s, WXWidget slf, void *_cmd)
{
id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
NSPasteboard *pboard = [sender draggingPasteboard];
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
wxWindow* wxpeer = GetWXPeer();
if ( wxpeer == NULL )
return NSDragOperationNone;
wxDropTarget* target = wxpeer->GetDropTarget();
if ( target == NULL )
return NSDragOperationNone;
wxDragResult result = wxDragNone;
wxPoint pt = wxFromNSPoint( m_osxView, [sender draggingLocation] );
if ( sourceDragMask & NSDragOperationLink )
result = wxDragLink;
else if ( sourceDragMask & NSDragOperationCopy )
result = wxDragCopy;
else if ( sourceDragMask & NSDragOperationMove )
result = wxDragMove;
PasteboardRef pboardRef;
PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
target->SetCurrentDragPasteboard(pboardRef);
result = target->OnDragOver(pt.x, pt.y, result);
CFRelease(pboardRef);
NSDragOperation nsresult = NSDragOperationNone;
switch (result )
{
case wxDragLink:
nsresult = NSDragOperationLink;
case wxDragMove:
nsresult = NSDragOperationMove;
case wxDragCopy:
nsresult = NSDragOperationCopy;
default :
break;
}
return nsresult;
}
bool wxWidgetCocoaImpl::performDragOperation(void* s, WXWidget slf, void *_cmd)
{
id <NSDraggingInfo>sender = (id <NSDraggingInfo>) s;
NSPasteboard *pboard = [sender draggingPasteboard];
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
wxWindow* wxpeer = GetWXPeer();
wxDropTarget* target = wxpeer->GetDropTarget();
wxDragResult result = wxDragNone;
wxPoint pt = wxFromNSPoint( m_osxView, [sender draggingLocation] );
if ( sourceDragMask & NSDragOperationLink )
result = wxDragLink;
else if ( sourceDragMask & NSDragOperationCopy )
result = wxDragCopy;
else if ( sourceDragMask & NSDragOperationMove )
result = wxDragMove;
PasteboardRef pboardRef;
PasteboardCreate((CFStringRef)[pboard name], &pboardRef);
target->SetCurrentDragPasteboard(pboardRef);
result = target->OnData(pt.x, pt.y, result);
CFRelease(pboardRef);
return result != wxDragNone;
}
#endif
typedef void (*wxOSX_EventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
typedef BOOL (*wxOSX_PerformKeyEventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event);
typedef BOOL (*wxOSX_FocusHandlerPtr)(NSView* self, SEL _cmd);
typedef BOOL (*wxOSX_ResetCursorRectsHandlerPtr)(NSView* self, SEL _cmd);
typedef BOOL (*wxOSX_DrawRectHandlerPtr)(NSView* self, SEL _cmd, NSRect rect);
void wxWidgetCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
{
if ( !DoHandleMouseEvent(event) )
{
wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
superimpl(slf, (SEL)_cmd, event);
}
}
void wxWidgetCocoaImpl::keyEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
{
if ( !DoHandleKeyEvent(event) )
{
wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
superimpl(slf, (SEL)_cmd, event);
}
}
bool wxWidgetCocoaImpl::performKeyEquivalent(WX_NSEvent event, WXWidget slf, void *_cmd)
{
if ( !DoHandleKeyEvent(event) )
{
wxOSX_PerformKeyEventHandlerPtr superimpl = (wxOSX_PerformKeyEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
return superimpl(slf, (SEL)_cmd, event);
}
return YES;
}
bool wxWidgetCocoaImpl::becomeFirstResponder(WXWidget slf, void *_cmd)
{
wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
BOOL r = superimpl(slf, (SEL)_cmd);
if ( r )
DoNotifyFocusEvent( true );
return r;
}
bool wxWidgetCocoaImpl::resignFirstResponder(WXWidget slf, void *_cmd)
{
wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
BOOL r = superimpl(slf, (SEL)_cmd);
if ( r )
DoNotifyFocusEvent( false );
return r;
}
void wxWidgetCocoaImpl::resetCursorRects(WXWidget slf, void *_cmd)
{
wxWindow* wxpeer = GetWXPeer();
if ( wxpeer )
{
NSCursor *cursor = (NSCursor*)wxpeer->GetCursor().GetHCURSOR();
if (cursor == NULL)
{
wxOSX_ResetCursorRectsHandlerPtr superimpl = (wxOSX_ResetCursorRectsHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
superimpl(slf, (SEL)_cmd);
}
else
[slf addCursorRect: [slf bounds]
cursor: cursor];
}
}
bool wxWidgetCocoaImpl::isFlipped(WXWidget slf, void *_cmd)
{
return m_isFlipped;
}
#define OSX_DEBUG_DRAWING 0
void wxWidgetCocoaImpl::drawRect(void* rect, WXWidget slf, void *_cmd)
{
CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
CGContextSaveGState( context );
#if OSX_DEBUG_DRAWING
CGContextBeginPath( context );
CGContextMoveToPoint(context, 0, 0);
NSRect bounds = [self bounds];
CGContextAddLineToPoint(context, 10, 0);
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, 0, 10);
CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
CGContextAddLineToPoint(context, bounds.size.width, bounds.size.height-10);
CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
CGContextAddLineToPoint(context, bounds.size.width-10, bounds.size.height);
CGContextClosePath( context );
CGContextStrokePath(context);
#endif
if ( !m_isFlipped )
{
CGContextTranslateCTM( context, 0, [m_osxView bounds].size.height );
CGContextScaleCTM( context, 1, -1 );
}
wxRegion updateRgn;
const NSRect *rects;
NSInteger count;
[slf getRectsBeingDrawn:&rects count:&count];
for ( int i = 0 ; i < count ; ++i )
{
updateRgn.Union(wxFromNSRect(slf, rects[i]) );
}
wxWindow* wxpeer = GetWXPeer();
wxpeer->GetUpdateRegion() = updateRgn;
wxpeer->MacSetCGContextRef( context );
wxPaintEvent event;
event.SetTimestamp(0); // todo
event.SetEventObject(wxpeer);
bool handled = wxpeer->HandleWindowEvent(event);
CGContextRestoreGState( context );
if ( !handled )
{
// call super
SEL _cmd = @selector(drawRect:);
wxOSX_DrawRectHandlerPtr superimpl = (wxOSX_DrawRectHandlerPtr) [[slf superclass] instanceMethodForSelector:_cmd];
superimpl(slf, _cmd, *(NSRect*)rect);
}
}
void wxWidgetCocoaImpl::clickedAction( WXWidget slf, void *_cmd, void *sender)
{
wxWindow* wxpeer = (wxWindow*) GetWXPeer();
if ( wxpeer )
wxpeer->OSXHandleClicked(0);
}
void wxWidgetCocoaImpl::doubleClickedAction( WXWidget slf, void *_cmd, void *sender)
{
}
//
#if OBJC_API_VERSION >= 2
#define wxOSX_CLASS_ADD_METHOD( c, s, i, t ) \
class_addMethod(c, s, i, t );
#else
#define wxOSX_CLASS_ADD_METHOD( c, s, i, t ) \
{ s, t, i },
#endif
void wxOSXCocoaClassAddWXMethods(Class c)
{
#if OBJC_API_VERSION < 2
static objc_method wxmethods[] =
{
#endif
wxOSX_CLASS_ADD_METHOD(c, @selector(mouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseDown:), (IMP) wxOSX_mouseEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(mouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseUp:), (IMP) wxOSX_mouseEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(mouseMoved:), (IMP) wxOSX_mouseEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(mouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(rightMouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(otherMouseDragged:), (IMP) wxOSX_mouseEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(scrollWheel:), (IMP) wxOSX_mouseEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(mouseEntered:), (IMP) wxOSX_mouseEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(mouseExited:), (IMP) wxOSX_mouseEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(keyDown:), (IMP) wxOSX_keyEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(keyUp:), (IMP) wxOSX_keyEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(flagsChanged:), (IMP) wxOSX_keyEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(performKeyEquivalent:), (IMP) wxOSX_performKeyEquivalent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(becomeFirstResponder), (IMP) wxOSX_becomeFirstResponder, "c@:" )
wxOSX_CLASS_ADD_METHOD(c, @selector(resignFirstResponder), (IMP) wxOSX_resignFirstResponder, "c@:" )
wxOSX_CLASS_ADD_METHOD(c, @selector(resetCursorRects), (IMP) wxOSX_resetCursorRects, "v@:" )
wxOSX_CLASS_ADD_METHOD(c, @selector(isFlipped), (IMP) wxOSX_isFlipped, "c@:" )
wxOSX_CLASS_ADD_METHOD(c, @selector(drawRect:), (IMP) wxOSX_drawRect, "v@:{_NSRect={_NSPoint=ff}{_NSSize=ff}}" )
wxOSX_CLASS_ADD_METHOD(c, @selector(clickedAction:), (IMP) wxOSX_clickedAction, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(doubleClickedAction:), (IMP) wxOSX_doubleClickedAction, "v@:@" )
#if wxUSE_DRAG_AND_DROP
wxOSX_CLASS_ADD_METHOD(c, @selector(draggingEntered:), (IMP) wxOSX_draggingEntered, "I@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(draggingUpdated:), (IMP) wxOSX_draggingUpdated, "I@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(draggingExited:), (IMP) wxOSX_draggingExited, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(performDragOperation:), (IMP) wxOSX_performDragOperation, "c@:@" )
#endif
#if OBJC_API_VERSION < 2
} ;
static int method_count = WXSIZEOF( wxmethods );
static objc_method_list *wxmethodlist = NULL;
if ( wxmethodlist == NULL )
{
wxmethodlist = (objc_method_list*) malloc(sizeof(objc_method_list) + sizeof(wxmethods) );
memcpy( &wxmethodlist->method_list[0], &wxmethods[0], sizeof(wxmethods) );
wxmethodlist->method_count = method_count;
wxmethodlist->obsolete = 0;
}
class_addMethods( c, wxmethodlist );
#endif
}
//
// C++ implementation class
//
IMPLEMENT_DYNAMIC_CLASS( wxWidgetCocoaImpl , wxWidgetImpl ) IMPLEMENT_DYNAMIC_CLASS( wxWidgetCocoaImpl , wxWidgetImpl )
wxWidgetCocoaImpl::wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl ) : wxWidgetCocoaImpl::wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl ) :
wxWidgetImpl( peer, isRootControl ), m_osxView(w) wxWidgetImpl( peer, isRootControl )
{ {
Init();
m_osxView = w;
} }
wxWidgetCocoaImpl::wxWidgetCocoaImpl() wxWidgetCocoaImpl::wxWidgetCocoaImpl()
{ {
Init();
} }
void wxWidgetCocoaImpl::Init() void wxWidgetCocoaImpl::Init()
{ {
m_osxView = NULL; m_osxView = NULL;
m_isFlipped = true;
} }
wxWidgetCocoaImpl::~wxWidgetCocoaImpl() wxWidgetCocoaImpl::~wxWidgetCocoaImpl()
{ {
if ( [m_osxView respondsToSelector:@selector(setImplementation:) ] ) RemoveAssociations( this );
[m_osxView setImplementation:NULL];
if ( !IsRootControl() ) if ( !IsRootControl() )
{ {
NSView *sv = [m_osxView superview]; NSView *sv = [m_osxView superview];
@@ -722,6 +1189,18 @@ void wxWidgetCocoaImpl::SetFont(wxFont const&, wxColour const&, long, bool)
void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control ) void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
{ {
WXWidget c = control ? control : (WXWidget) m_osxView;
wxWidgetImpl::Associate( c, this ) ;
if ([c respondsToSelector:@selector(setAction:)])
{
[c setTarget: c];
[c setAction: @selector(clickedAction:)];
if ([c respondsToSelector:@selector(setDoubleAction:)])
{
[c setDoubleAction: @selector(doubleClickedAction:)];
}
}
} }
bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event) bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event)
@@ -810,6 +1289,11 @@ void wxWidgetCocoaImpl::ReleaseMouse()
[[m_osxView window] enableCursorRects]; [[m_osxView window] enableCursorRects];
} }
void wxWidgetCocoaImpl::SetFlipped(bool flipped)
{
m_isFlipped = flipped;
}
// //
// Factory methods // Factory methods
// //
@@ -817,13 +1301,14 @@ void wxWidgetCocoaImpl::ReleaseMouse()
wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
long style, long extraStyle) long style, long extraStyle)
{ {
NSView* sv = (wxpeer->GetParent()->GetHandle() );
NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
wxNSView* v = [[wxNSView alloc] initWithFrame:r]; wxNSView* v = [[wxNSView alloc] initWithFrame:r];
[sv addSubview:v];
// temporary hook for dnd
[v registerForDraggedTypes:[NSArray arrayWithObjects:
NSStringPboardType, NSFilenamesPboardType, NSTIFFPboardType, NSPICTPboardType, NSPDFPboardType, nil]];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
return c; return c;
} }
@@ -832,7 +1317,6 @@ wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
NSWindow* tlw = now->GetWXWindow(); NSWindow* tlw = now->GetWXWindow();
wxNSView* v = [[wxNSView alloc] initWithFrame:[[tlw contentView] frame]]; wxNSView* v = [[wxNSView alloc] initWithFrame:[[tlw contentView] frame]];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( now, v, true ); wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( now, v, true );
[v setImplementation:c];
[tlw setContentView:v]; [tlw setContentView:v];
return c; return c;
} }

View File

@@ -85,7 +85,6 @@
BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase) BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
EVT_NC_PAINT(wxWindowMac::OnNcPaint) EVT_NC_PAINT(wxWindowMac::OnNcPaint)
EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground) EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground)
EVT_PAINT(wxWindowMac::OnPaint)
EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent)
END_EVENT_TABLE() END_EVENT_TABLE()
@@ -1869,7 +1868,19 @@ bool wxWindowMac::MacDoRedraw( void* updatergnr , long time )
wxPaintEvent event; wxPaintEvent event;
event.SetTimestamp(time); event.SetTimestamp(time);
event.SetEventObject(this); event.SetEventObject(this);
HandleWindowEvent(event); if ( !HandleWindowEvent(event) )
{
// for native controls: call their native paint method
if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM ) )
{
if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL
&& GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT )
CallNextEventHandler(
(EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() ,
(EventRef) wxTheApp->MacGetCurrentEvent() ) ;
}
}
handled = true ; handled = true ;
} }
@@ -2200,21 +2211,6 @@ void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
} }
} }
void wxWindowMac::OnPaint( wxPaintEvent & WXUNUSED(event) )
{
#if wxOSX_USE_COCOA_OR_CARBON
// for native controls: call their native paint method
if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM ) )
{
if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL
&& GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT )
CallNextEventHandler(
(EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() ,
(EventRef) wxTheApp->MacGetCurrentEvent() ) ;
}
#endif
}
void wxWindowMac::TriggerScrollEvent( wxEventType WXUNUSED(scrollEvent) ) void wxWindowMac::TriggerScrollEvent( wxEventType WXUNUSED(scrollEvent) )
{ {
} }