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;
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)
};
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
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
@end
+
+ void wxOSXCocoaClassAddWXMethods(Class c);
#endif // __OBJC__
/////////////////////////////////////////////////////////////////////////////
-// Name: wx/mac/carbon/cursor.h
+// Name: wx/osx/cursor.h
// Purpose: wxCursor class
// Author: Stefan Csomor
// Modified by:
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 ;
};
//-------------------------------------------------------------------------
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
// event handlers
// --------------
- void OnPaint( wxPaintEvent& event );
+
void OnNcPaint( wxNcPaintEvent& event );
void OnEraseBackground(wxEraseEvent& event );
void OnMouseEvent( wxMouseEvent &event );
}
}
-#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;
}
}
}
-#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;
}
DragAttributes attributes;
GetDragAttributes( theDrag, &attributes );
-
+ PasteboardRef pasteboard = 0;
+ GetDragPasteboard( theDrag, &pasteboard );
wxNonOwnedWindow* toplevel = wxNonOwnedWindow::GetFromWXWindow( (WXWindow) theWindow );
bool optionDown = GetCurrentKeyModifiers() & optionKey;
#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;
{
if ( trackingGlobals->m_currentTarget )
{
- trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
+ trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
result = trackingGlobals->m_currentTarget->OnEnter( localx, localy, result );
}
{
if ( trackingGlobals->m_currentTarget )
{
- trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
+ trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
result = trackingGlobals->m_currentTarget->OnDragOver( localx, localy, result );
}
}
if (trackingGlobals->m_currentTarget)
{
- trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
+ trackingGlobals->m_currentTarget->SetCurrentDragPasteboard( pasteboard );
trackingGlobals->m_currentTarget->OnLeave();
#ifndef __LP64__
HideDragHilite( theDrag );
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;
// 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)
CGContextClearRect( cgContext, bounds );
}
-
-
if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
result = noErr ;
[v setImage:bitmap.GetNSImage() ];
[v setButtonType:NSMomentaryPushInButton];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
- [v setImplementation:c];
return c;
}
@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
-{
- if ( impl )
+ static BOOL initialized = NO;
+ if (!initialized)
{
- wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
- if ( wxpeer )
- wxpeer->OSXHandleClicked(0);
+ initialized = YES;
+ wxOSXCocoaClassAddWXMethods( self );
}
}
[v setButtonType:NSMomentaryPushInButton];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
- [v setImplementation:c];
return c;
/*
OSStatus err;
[v setTitle:wxCFStringRef( label).AsNSString()];
[v setImagePosition:NSImageRight];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
- [v setImplementation:c];
return c;
}
[v setAllowsMixedState:YES];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
- [v setImplementation:c];
return c;
}
@interface wxNSPopUpButton : NSPopUpButton
{
- WXCOCOAIMPL_COMMON_MEMBERS
}
-WXCOCOAIMPL_COMMON_INTERFACE
-
-- (void) clickedAction: (id) sender;
-
@end
@implementation wxNSPopUpButton
-- (id)initWithFrame:(NSRect)frame pullsDown:(BOOL) pd
-{
- [super initWithFrame:frame pullsDown:pd];
- impl = NULL;
- [self setTarget: self];
- [self setAction: @selector(clickedAction:)];
- return self;
-}
-
-- (void) clickedAction: (id) sender
++ (void)initialize
{
- if ( impl )
+ static BOOL initialized = NO;
+ if (!initialized)
{
- wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
- if ( wxpeer )
- wxpeer->OSXHandleClicked(0);
+ initialized = YES;
+ wxOSXCocoaClassAddWXMethods( self );
}
}
-WXCOCOAIMPL_COMMON_IMPLEMENTATION
-
- (int) intValue
{
return [self indexOfSelectedItem];
wxNSPopUpButton* v = [[wxNSPopUpButton alloc] initWithFrame:r pullsDown:NO];
[v setMenu: menu->GetHMenu()];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
- [v setImplementation:c];
return c;
}
// 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(
wxCFStringRef cfext(extension);
[types addObject: (NSString*)cfext.AsNSString() ];
#if 0
+ // add support for classic fileType / creator here
wxUint32 fileType, creator;
-
// extension -> mactypes
#endif
}
// 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) )
{
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
@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
class wxOSXGaugeCocoaImpl : public wxWidgetCocoaImpl
[v setIndeterminate:FALSE];
[v setDoubleValue: (double) value];
wxWidgetCocoaImpl* c = new wxOSXGaugeCocoaImpl( wxpeer, v );
- [v setImplementation:c];
return c;
}
@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
{
return YES;
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) ;
*/
#if wxUSE_LISTBOX
#include "wx/listbox.h"
+#include "wx/dnd.h"
#ifndef WX_PRECOMP
#include "wx/log.h"
@interface wxNSTableView : NSTableView
{
- wxListWidgetCocoaImpl* impl;
}
-- (void)setImplementation: (wxListWidgetCocoaImpl *) theImplementation;
-- (wxListWidgetCocoaImpl*) implementation;
-- (void)clickedAction: (id) sender;
-- (void)doubleClickedAction: (id) sender;
-
@end
//
}
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 ;
@implementation wxNSTableView
-- (void)setImplementation: (wxListWidgetCocoaImpl *) theImplementation
-{
- impl = theImplementation;
-}
-
-- (wxListWidgetCocoaImpl*) implementation
-{
- return impl;
-}
-
-- (id) init
++ (void)initialize
{
- [super init];
- impl = NULL;
- [self setTarget: self];
- [self setAction: @selector(clickedAction:)];
- [self setDoubleAction: @selector(doubleClickedAction:)];
- return self;
-}
-
-- (void) clickedAction: (id) sender
-{
- if ( impl )
+ static BOOL initialized = NO;
+ if (!initialized)
{
- 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 );
}
}
wxListWidgetCocoaImpl::wxListWidgetCocoaImpl( wxWindowMac* peer, NSScrollView* view, wxNSTableView* tableview, wxNSTableDataSource* data ) :
wxWidgetCocoaImpl( peer, view ), m_tableView(tableview), m_dataSource(data)
{
+ InstallEventHandler( tableview );
}
wxListWidgetCocoaImpl::~wxListWidgetCocoaImpl()
[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
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;
}
@interface wxNSTabView : NSTabView
{
- WXCOCOAIMPL_COMMON_MEMBERS
}
-WXCOCOAIMPL_COMMON_INTERFACE
-
@end
@implementation wxTabViewController
- (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();
{
wxNSTabView* view = (wxNSTabView*) tabView;
- wxWidgetCocoaImpl* viewimpl = [view implementation];
+ wxWidgetCocoaImpl* viewimpl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( view );
if ( viewimpl )
{
wxNotebook* wxpeer = (wxNotebook*) viewimpl->GetWXPeer();
@implementation wxNSTabView
-WXCOCOAIMPL_COMMON_IMPLEMENTATION
++ (void)initialize
+{
+ static BOOL initialized = NO;
+ if (!initialized)
+ {
+ initialized = YES;
+ wxOSXCocoaClassAddWXMethods( self );
+ }
+}
@end
wxNSTabView* v = [[wxNSTabView alloc] initWithFrame:r];
[v setTabViewType:tabstyle];
wxWidgetCocoaImpl* c = new wxCocoaTabView( wxpeer, v );
- [v setImplementation:c];
[v setDelegate: controller];
return c;
}
[v setButtonType:NSRadioButton];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
- [v setImplementation:c];
return c;
}
@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;
-}
-
-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;
- switch ([self 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*) 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) )
+ static BOOL initialized = NO;
+ if (!initialized)
{
- wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
- if ( wxpeer )
- wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBRELEASE);
+ initialized = YES;
+ wxOSXCocoaClassAddWXMethods(self);
}
}
void SetScrollThumb( wxInt32 value, wxInt32 thumbSize )
{
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
[(wxNSScroller*) m_osxView setFloatValue:v knobProportion:t];
#else
#endif
}
- wxInt32 GetValue() const
+ virtual wxInt32 GetValue() const
{
return [(wxNSScroller*) m_osxView floatValue] * m_maximum;
}
- wxInt32 GetMaximum() const
+ 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
+// 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,
wxWindowMac* parent,
wxWindowID id,
wxNSScroller* v = [[wxNSScroller alloc] initWithFrame:r];
wxWidgetCocoaImpl* c = new wxOSXScrollBarCocoaImpl( wxpeer, v );
- [v setImplementation:c];
[v setEnabled:YES];
return c;
}
@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
// 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();
- if ( wxpeer )
- wxpeer->TriggerScrollEvent(wxEVT_SCROLL_THUMBTRACK);
- }
+ 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];
-
- if ( impl )
+ wxWidgetCocoaImpl::mouseEvent(event, slf, _cmd);
+
+ 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,
[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;
}
@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)
+ {
+ m_formerValue = 0;
+ }
+
+ ~wxSpinButtonCocoaImpl()
{
- wxWindow* wxpeer = (wxWindow*) impl->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;
-
- // 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
+ 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)
{
- formerValue = [self intValue];
- if ( !impl->DoHandleMouseEvent(event) )
- [super mouseDown:event];
+
+ // 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,
wxWindowMac* parent,
if ( style & wxSP_WRAP )
[v setValueWraps:YES];
- wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
- [v setImplementation:c];
+ wxWidgetCocoaImpl* c = new wxSpinButtonCocoaImpl( wxpeer, v );
return c;
}
@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
{
- (void) searchAction: (id) sender
{
+ wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
if ( impl )
{
wxSearchCtrl* wxpeer = dynamic_cast<wxSearchCtrl*>( impl->GetWXPeer() );
wxNSSearchFieldControl* c = new wxNSSearchFieldControl( wxpeer, v );
c->SetStringValue( str );
- [v setImplementation:c];
return c;
}
@implementation wxNSBox
-WXCOCOAIMPL_COMMON_IMPLEMENTATION_NOT_FLIPPED
++ (void)initialize
+{
+ static BOOL initialized = NO;
+ if (!initialized)
+ {
+ initialized = YES;
+ wxOSXCocoaClassAddWXMethods( self );
+ }
+}
@end
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;
}
NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
wxNSBox* v = [[wxNSBox alloc] initWithFrame:r];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
- [v setImplementation:c];
return c;
}
[v setDrawsBackground:NO];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
- [v setImplementation:c];
return c;
/*
Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size );
@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:)];
//[v setDrawsBackground:NO];
wxWidgetCocoaImpl* c = new wxNSTextFieldControl( wxpeer, v );
- [v setImplementation:c];
return c;
}
[v setBezelStyle:NSRoundedBezelStyle];
[v setButtonType:NSOnOffButton];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
- [v setImplementation:c];
return c;
}
[v setBezelStyle:NSRegularSquareBezelStyle];
[v setButtonType:NSOnOffButton];
wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
- [v setImplementation:c];
return c;
}
#endif
#ifdef __WXMAC__
-#include "wx/osx/private.h"
+ #include "wx/osx/private.h"
#endif
#if wxUSE_CARET
#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 ;
@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;
- (void)setControlSize:(NSControlSize)size;
- (id)contentView;
+
+- (void)setTarget:(id)anObject;
+- (void)setAction:(SEL)aSelector;
+- (void)setDoubleAction:(SEL)aSelector;
@end
long wxOSXTranslateCocoaKey( int unichar )
@implementation wxNSView
-#define OSX_DEBUG_DRAWING 0
++ (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);
+}
-- (void)drawRect: (NSRect) rect
+unsigned int wxWidgetCocoaImpl::draggingEntered(void* s, WXWidget slf, void *_cmd)
{
- if ( impl )
+ 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 )
{
- 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
+ case wxDragLink:
+ nsresult = NSDragOperationLink;
+ case wxDragMove:
+ nsresult = NSDragOperationMove;
+ case wxDragCopy:
+ nsresult = NSDragOperationCopy;
+ default :
+ break;
+ }
+ return nsresult;
+}
- if ( [ self isFlipped ] == NO )
- {
- CGContextTranslateCTM( context, 0, [self bounds].size.height );
- CGContextScaleCTM( context, 1, -1 );
- }
+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];
- wxRegion updateRgn;
- const NSRect *rects;
- NSInteger count;
+ 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;
- [self getRectsBeingDrawn:&rects count:&count];
- for ( int i = 0 ; i < count ; ++i )
+ 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)
{
- updateRgn.Union(wxFromNSRect(self, rects[i]) );
+ 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;
+}
- wxWindow* wxpeer = impl->GetWXPeer();
- wxpeer->GetUpdateRegion() = updateRgn;
- wxpeer->MacSetCGContextRef( context );
-
- wxPaintEvent event;
- event.SetTimestamp(0); // todo
- event.SetEventObject(wxpeer);
- wxpeer->HandleWindowEvent(event);
-
- CGContextRestoreGState( context );
+
+#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);
}
}
-WXCOCOAIMPL_COMMON_IMPLEMENTATION
+void wxWidgetCocoaImpl::clickedAction( WXWidget slf, void *_cmd, void *sender)
+{
+ wxWindow* wxpeer = (wxWindow*) GetWXPeer();
+ if ( wxpeer )
+ wxpeer->OSXHandleClicked(0);
+}
-- (BOOL) canBecomeKeyView
+void wxWidgetCocoaImpl::doubleClickedAction( WXWidget slf, void *_cmd, void *sender)
{
- return YES;
}
-@end // wxNSView
+//
+
+#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];
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)
[[m_osxView window] enableCursorRects];
}
+void wxWidgetCocoaImpl::SetFlipped(bool flipped)
+{
+ m_isFlipped = flipped;
+}
+
//
// Factory methods
//
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;
}
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;
}
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()
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 ;
}
}
}
-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) )
{
}