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 );
void InstallEventHandler( WXWidget control = NULL );
virtual void InstallEventHandler( WXWidget control = NULL );
protected :
WXEVENTHANDLERREF m_macControlEventHandler ;
ControlRef m_controlRef;

View File

@ -127,8 +127,28 @@ public :
virtual bool DoHandleKeyEvent(NSEvent *event);
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:
WXWidget m_osxView;
bool m_isFlipped;
DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl)
};
@ -203,217 +223,24 @@ protected :
NSRect WXDLLIMPEXP_CORE wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size ,
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
@interface wxNSButton : NSButton
{
WXCOCOAIMPL_COMMON_MEMBERS
}
WXCOCOAIMPL_COMMON_INTERFACE
- (void) clickedAction: (id) sender;
@end
@interface wxNSBox : NSBox
{
WXCOCOAIMPL_COMMON_MEMBERS
}
WXCOCOAIMPL_COMMON_INTERFACE
@end
@interface wxNSTextField : NSTextField
{
WXCOCOAIMPL_COMMON_MEMBERS
}
WXCOCOAIMPL_COMMON_INTERFACE
@end
@interface wxNSMenu : NSMenu
@ -439,6 +266,8 @@ protected :
@end
void wxOSXCocoaClassAddWXMethods(Class c);
#endif // __OBJC__
// NSCursor

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -37,6 +37,10 @@
// implementation
// ============================================================================
// Open Items:
// - support for old style MacOS creator / type combos
// - parameter support for descending into packages as directories (setTreatsFilePackagesAsDirectories)
IMPLEMENT_CLASS(wxFileDialog, wxFileDialogBase)
wxFileDialog::wxFileDialog(
@ -123,8 +127,8 @@ NSArray* GetTypesFromFilter( const wxString filter )
wxCFStringRef cfext(extension);
[types addObject: (NSString*)cfext.AsNSString() ];
#if 0
// add support for classic fileType / creator here
wxUint32 fileType, creator;
// extension -> mactypes
#endif
}
@ -152,7 +156,10 @@ int wxFileDialog::ShowModal()
// makes things more convenient:
[sPanel setCanCreateDirectories:YES];
[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 setCanSelectHiddenExtension:YES];
if ( HasFlag(wxFD_OVERWRITE_PROMPT) )
{
@ -206,181 +213,4 @@ int wxFileDialog::ShowModal()
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

View File

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

View File

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

View File

@ -14,6 +14,7 @@
#if wxUSE_LISTBOX
#include "wx/listbox.h"
#include "wx/dnd.h"
#ifndef WX_PRECOMP
#include "wx/log.h"
@ -54,14 +55,8 @@ class wxListWidgetCocoaImpl;
@interface wxNSTableView : NSTableView
{
wxListWidgetCocoaImpl* impl;
}
- (void)setImplementation: (wxListWidgetCocoaImpl *) theImplementation;
- (wxListWidgetCocoaImpl*) implementation;
- (void)clickedAction: (id) sender;
- (void)doubleClickedAction: (id) sender;
@end
//
@ -147,6 +142,9 @@ public :
}
virtual void UpdateLine( unsigned int n, wxListWidgetColumn* col = NULL ) ;
virtual void UpdateLineToEnd( unsigned int n);
virtual void clickedAction(WXWidget slf, void* _cmd, void *sender);
virtual void doubleClickedAction(void* _cmd);
protected :
wxNSTableView* m_tableView ;
@ -274,55 +272,13 @@ protected:
@implementation wxNSTableView
- (void)setImplementation: (wxListWidgetCocoaImpl *) theImplementation
+ (void)initialize
{
impl = theImplementation;
}
- (wxListWidgetCocoaImpl*) implementation
static BOOL initialized = NO;
if (!initialized)
{
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());
wxCHECK_RET( list != NULL , wxT("Listbox expected"));
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 );
initialized = YES;
wxOSXCocoaClassAddWXMethods( self );
}
}
@ -335,6 +291,7 @@ protected:
wxListWidgetCocoaImpl::wxListWidgetCocoaImpl( wxWindowMac* peer, NSScrollView* view, wxNSTableView* tableview, wxNSTableDataSource* data ) :
wxWidgetCocoaImpl( peer, view ), m_tableView(tableview), m_dataSource(data)
{
InstallEventHandler( tableview );
}
wxListWidgetCocoaImpl::~wxListWidgetCocoaImpl()
@ -514,6 +471,31 @@ void wxListWidgetCocoaImpl::UpdateLineToEnd( unsigned int n)
[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
@ -555,7 +537,11 @@ wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer,
wxNSTableDataSource* ds = [[ wxNSTableDataSource alloc] init];
[tableview setDataSource: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];
return c;
}

View File

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

View File

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

View File

@ -23,27 +23,63 @@
@interface wxNSScroller : NSScroller
{
WXCOCOAIMPL_COMMON_MEMBERS
}
WXCOCOAIMPL_COMMON_INTERFACE
- (void) clickedAction: (id) sender;
@end
@implementation wxNSScroller
- (id)initWithFrame:(NSRect)frame
+ (void)initialize
{
[super initWithFrame:frame];
impl = NULL;
[self setTarget: self];
[self setAction: @selector(clickedAction:)];
return self;
static BOOL initialized = NO;
if (!initialized)
{
initialized = YES;
wxOSXCocoaClassAddWXMethods(self);
}
}
WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN
@end
class wxOSXScrollBarCocoaImpl : public wxWidgetCocoaImpl
{
public :
wxOSXScrollBarCocoaImpl( wxWindowMac* peer, WXWidget w) : wxWidgetCocoaImpl( peer, w )
{
m_maximum = 1;
}
void SetMaximum(wxInt32 v)
{
m_maximum = (v == 0) ? 1 : v;
}
void SetScrollThumb( wxInt32 value, wxInt32 thumbSize )
{
double v = ((double) value)/m_maximum;
double t = ((double) thumbSize)/(m_maximum+thumbSize);
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
[(wxNSScroller*) m_osxView setFloatValue:v knobProportion:t];
#else
[(wxNSScroller*) m_osxView setDoubleValue:v];
[(wxNSScroller*) m_osxView setKnobProportion:t];
#endif
}
virtual wxInt32 GetValue() const
{
return [(wxNSScroller*) m_osxView floatValue] * m_maximum;
}
virtual wxInt32 GetMaximum() const
{
return m_maximum;
}
virtual void clickedAction(WXWidget slf, void* _cmd, void *sender);
virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
protected:
wxInt32 m_maximum;
};
// we will have a mouseDown, then in the native
// implementation of mouseDown the tracking code
@ -51,12 +87,10 @@ WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN
// to thumbtrack and only after super mouseDown
// returns we will call the thumbrelease
- (void) clickedAction: (id) sender
{
if ( impl )
void wxOSXScrollBarCocoaImpl::clickedAction( WXWidget slf, void *_cmd, void *sender)
{
wxEventType scrollEvent = wxEVT_NULL;
switch ([self hitPart])
switch ([(NSScroller*)m_osxView hitPart])
{
case NSScrollerIncrementLine:
scrollEvent = wxEVT_SCROLL_LINEDOWN;
@ -79,67 +113,28 @@ WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN
return;
}
wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
wxWindow* wxpeer = (wxWindow*) GetWXPeer();
if ( wxpeer )
wxpeer->TriggerScrollEvent(scrollEvent);
}
}
-(void)mouseDown:(NSEvent *)event
void wxOSXScrollBarCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
{
if ( !impl->DoHandleMouseEvent(event) )
[super mouseDown:event];
wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
// send a release event in case we've been tracking the thumb
NSScrollerPart hit = [self hitPart];
if ( impl && (hit == NSScrollerKnob || hit == NSScrollerKnobSlot) )
if ( strcmp( sel_getName((SEL) _cmd) , "mouseDown:") == 0 )
{
wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
NSScrollerPart hit = [(NSScroller*)m_osxView hitPart];
if ( (hit == NSScrollerKnob || hit == NSScrollerKnobSlot) )
{
wxWindow* wxpeer = (wxWindow*) GetWXPeer();
if ( wxpeer )
wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBRELEASE);
wxpeer->OSXHandleClicked(0);
}
}
@end
class wxOSXScrollBarCocoaImpl : public wxWidgetCocoaImpl
{
public :
wxOSXScrollBarCocoaImpl( wxWindowMac* peer, WXWidget w) : wxWidgetCocoaImpl( peer, w )
{
m_maximum = 1;
}
void SetMaximum(wxInt32 v)
{
m_maximum = (v == 0) ? 1 : v;
}
void SetScrollThumb( wxInt32 value, wxInt32 thumbSize )
{
double v = ((double) value)/m_maximum;
double t = ((double) thumbSize)/m_maximum;
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
[(wxNSScroller*) m_osxView setFloatValue:v knobProportion:t];
#else
[(wxNSScroller*) m_osxView setDoubleValue:v];
[(wxNSScroller*) m_osxView setKnobProportion:t];
#endif
}
wxInt32 GetValue() const
{
return [(wxNSScroller*) m_osxView floatValue] * m_maximum;
}
wxInt32 GetMaximum() const
{
return m_maximum;
}
protected:
wxInt32 m_maximum;
};
wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer,
wxWindowMac* parent,
wxWindowID id,
@ -152,7 +147,6 @@ wxWidgetImplType* wxWidgetImpl::CreateScrollBar( wxWindowMac* wxpeer,
wxNSScroller* v = [[wxNSScroller alloc] initWithFrame:r];
wxWidgetCocoaImpl* c = new wxOSXScrollBarCocoaImpl( wxpeer, v );
[v setImplementation:c];
[v setEnabled:YES];
return c;
}

View File

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

View File

@ -18,41 +18,65 @@
@interface wxNSStepper : NSStepper
{
WXCOCOAIMPL_COMMON_MEMBERS
int formerValue;
}
WXCOCOAIMPL_COMMON_INTERFACE
- (void) clickedAction: (id) sender;
@end
@implementation wxNSStepper
- (id)initWithFrame:(NSRect)frame
+ (void)initialize
{
[super initWithFrame:frame];
impl = NULL;
formerValue = 0;
[self setTarget: self];
[self setAction: @selector(clickedAction:)];
return self;
static BOOL initialized = NO;
if (!initialized)
{
initialized = YES;
wxOSXCocoaClassAddWXMethods(self);
}
}
- (void) clickedAction: (id) sender
@end
class wxSpinButtonCocoaImpl : public wxWidgetCocoaImpl
{
if ( impl )
public :
wxSpinButtonCocoaImpl(wxWindowMac* peer , WXWidget w) :
wxWidgetCocoaImpl(peer, w)
{
wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
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);
}
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 = [self intValue];
[self setIntValue:formerValue];
int inc = currentValue-formerValue;
int currentValue = [(NSStepper*)m_osxView intValue];
[(NSStepper*)m_osxView setIntValue:m_formerValue];
int inc = currentValue-m_formerValue;
// adjust for wrap arounds
if ( inc > 1 )
@ -65,21 +89,9 @@ WXCOCOAIMPL_COMMON_INTERFACE
else if ( inc == -1 )
wxpeer->TriggerScrollEvent(wxEVT_SCROLL_LINEDOWN);
formerValue = [self intValue];
m_formerValue = [(NSStepper*)m_osxView intValue];
}
}
}
-(void)mouseDown:(NSEvent *)event
{
formerValue = [self intValue];
if ( !impl->DoHandleMouseEvent(event) )
[super mouseDown:event];
}
WXCOCOAIMPL_COMMON_IMPLEMENTATION_NO_MOUSEDOWN
@end
wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer,
wxWindowMac* parent,
@ -102,8 +114,7 @@ wxWidgetImplType* wxWidgetImpl::CreateSpinButton( wxWindowMac* wxpeer,
if ( style & wxSP_WRAP )
[v setValueWraps:YES];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
[v setImplementation:c];
wxWidgetCocoaImpl* c = new wxSpinButtonCocoaImpl( wxpeer, v );
return c;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,6 +24,12 @@
#include "wx/caret.h"
#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 )
{
int x, y, w, h ;
@ -37,19 +43,13 @@ NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const
@interface wxNSView : NSView
{
WXCOCOAIMPL_COMMON_MEMBERS
}
- (void)drawRect: (NSRect) rect;
WXCOCOAIMPL_COMMON_INTERFACE
- (BOOL) canBecomeKeyView;
@end // wxNSView
@interface NSView(PossibleMethods)
- (void)setImplementation:(wxWidgetCocoaImpl *)theImplementation;
- (void)setTitle:(NSString *)aString;
- (void)setStringValue:(NSString *)aString;
- (void)setIntValue:(int)anInt;
@ -70,6 +70,10 @@ WXCOCOAIMPL_COMMON_INTERFACE
- (void)setControlSize:(NSControlSize)size;
- (id)contentView;
- (void)setTarget:(id)anObject;
- (void)setAction:(SEL)aSelector;
- (void)setDoubleAction:(SEL)aSelector;
@end
long wxOSXTranslateCocoaKey( int unichar )
@ -336,14 +340,381 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
@implementation wxNSView
+ (void)initialize
{
static BOOL initialized = NO;
if (!initialized)
{
initialized = YES;
wxOSXCocoaClassAddWXMethods( self );
}
}
- (BOOL) canBecomeKeyView
{
return YES;
}
@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)drawRect: (NSRect) rect
{
if ( impl )
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);
@ -359,9 +730,9 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
CGContextStrokePath(context);
#endif
if ( [ self isFlipped ] == NO )
if ( !m_isFlipped )
{
CGContextTranslateCTM( context, 0, [self bounds].size.height );
CGContextTranslateCTM( context, 0, [m_osxView bounds].size.height );
CGContextScaleCTM( context, 1, -1 );
}
@ -369,54 +740,150 @@ void SetupMouseEvent( wxMouseEvent &wxevent , NSEvent * nsEvent )
const NSRect *rects;
NSInteger count;
[self getRectsBeingDrawn:&rects count:&count];
[slf getRectsBeingDrawn:&rects count:&count];
for ( int i = 0 ; i < count ; ++i )
{
updateRgn.Union(wxFromNSRect(self, rects[i]) );
updateRgn.Union(wxFromNSRect(slf, rects[i]) );
}
wxWindow* wxpeer = impl->GetWXPeer();
wxWindow* wxpeer = GetWXPeer();
wxpeer->GetUpdateRegion() = updateRgn;
wxpeer->MacSetCGContextRef( context );
wxPaintEvent event;
event.SetTimestamp(0); // todo
event.SetEventObject(wxpeer);
wxpeer->HandleWindowEvent(event);
bool handled = wxpeer->HandleWindowEvent(event);
CGContextRestoreGState( context );
}
}
WXCOCOAIMPL_COMMON_IMPLEMENTATION
- (BOOL) canBecomeKeyView
if ( !handled )
{
return YES;
// call super
SEL _cmd = @selector(drawRect:);
wxOSX_DrawRectHandlerPtr superimpl = (wxOSX_DrawRectHandlerPtr) [[slf superclass] instanceMethodForSelector:_cmd];
superimpl(slf, _cmd, *(NSRect*)rect);
}
}
@end // wxNSView
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 )
wxWidgetCocoaImpl::wxWidgetCocoaImpl( wxWindowMac* peer , WXWidget w, bool isRootControl ) :
wxWidgetImpl( peer, isRootControl ), m_osxView(w)
wxWidgetImpl( peer, isRootControl )
{
Init();
m_osxView = w;
}
wxWidgetCocoaImpl::wxWidgetCocoaImpl()
{
Init();
}
void wxWidgetCocoaImpl::Init()
{
m_osxView = NULL;
m_isFlipped = true;
}
wxWidgetCocoaImpl::~wxWidgetCocoaImpl()
{
if ( [m_osxView respondsToSelector:@selector(setImplementation:) ] )
[m_osxView setImplementation:NULL];
RemoveAssociations( this );
if ( !IsRootControl() )
{
NSView *sv = [m_osxView superview];
@ -722,6 +1189,18 @@ void wxWidgetCocoaImpl::SetFont(wxFont const&, wxColour const&, long, bool)
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)
@ -810,6 +1289,11 @@ void wxWidgetCocoaImpl::ReleaseMouse()
[[m_osxView window] enableCursorRects];
}
void wxWidgetCocoaImpl::SetFlipped(bool flipped)
{
m_isFlipped = flipped;
}
//
// Factory methods
//
@ -817,13 +1301,14 @@ void wxWidgetCocoaImpl::ReleaseMouse()
wxWidgetImpl* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
long style, long extraStyle)
{
NSView* sv = (wxpeer->GetParent()->GetHandle() );
NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
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 );
[v setImplementation:c];
return c;
}
@ -832,7 +1317,6 @@ wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
NSWindow* tlw = now->GetWXWindow();
wxNSView* v = [[wxNSView alloc] initWithFrame:[[tlw contentView] frame]];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( now, v, true );
[v setImplementation:c];
[tlw setContentView:v];
return c;
}

View File

@ -85,7 +85,6 @@
BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
EVT_NC_PAINT(wxWindowMac::OnNcPaint)
EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground)
EVT_PAINT(wxWindowMac::OnPaint)
EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent)
END_EVENT_TABLE()
@ -1869,7 +1868,19 @@ bool wxWindowMac::MacDoRedraw( void* updatergnr , long time )
wxPaintEvent event;
event.SetTimestamp(time);
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 ;
}
@ -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) )
{
}