From 829a2e9521175cd943d671f16535242a467c4f91 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Fri, 20 Apr 2007 22:27:56 +0000 Subject: [PATCH] Remove Objective-C class posing for everything except for NSApplication. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45554 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/menu.h | 2 +- include/wx/cocoa/objc/NSMenu.h | 8 +-- include/wx/cocoa/objc/NSView.h | 8 +-- include/wx/cocoa/objc/NSWindow.h | 20 ++++-- src/cocoa/NSMenu.mm | 7 +- src/cocoa/NSView.mm | 8 +-- src/cocoa/NSWindow.mm | 32 +++++++-- src/cocoa/control.mm | 115 +++++++++++++++++++++++++++++++ src/cocoa/frame.mm | 2 +- src/cocoa/menu.mm | 4 +- src/cocoa/radiobox.mm | 4 +- src/cocoa/toplevel.mm | 18 +++-- src/cocoa/window.mm | 4 +- 13 files changed, 196 insertions(+), 36 deletions(-) diff --git a/include/wx/cocoa/menu.h b/include/wx/cocoa/menu.h index 21ceed2f32..479afe083b 100644 --- a/include/wx/cocoa/menu.h +++ b/include/wx/cocoa/menu.h @@ -73,7 +73,7 @@ private: // ======================================================================== // wxMenuBar // ======================================================================== -class WXDLLEXPORT wxMenuBar : public wxMenuBarBase, public wxCocoaNSMenu +class WXDLLEXPORT wxMenuBar : public wxMenuBarBase { public: // ctors and dtor diff --git a/include/wx/cocoa/objc/NSMenu.h b/include/wx/cocoa/objc/NSMenu.h index 88df42043f..f9211ddfb0 100644 --- a/include/wx/cocoa/objc/NSMenu.h +++ b/include/wx/cocoa/objc/NSMenu.h @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////// // Name: wx/cocoa/objc/NSMenu.h -// Purpose: wxPoserNSMenu class +// Purpose: WXNSMenu class // Author: David Elliott // Modified by: // Created: 2007/04/20 (move from NSMenu.mm) @@ -15,14 +15,14 @@ #import // ============================================================================ -// @class wxPoserNSMenu +// @class WXNSMenu // ============================================================================ -@interface wxPoserNSMenu : NSMenu +@interface WXNSMenu : NSMenu { } - (void)dealloc; -@end // wxPoserNSMenu +@end // WXNSMenu #endif //ndef __WX_COCOA_OBJC_NSMENU_H__ diff --git a/include/wx/cocoa/objc/NSView.h b/include/wx/cocoa/objc/NSView.h index 58c4f5101d..4bedd94b4f 100644 --- a/include/wx/cocoa/objc/NSView.h +++ b/include/wx/cocoa/objc/NSView.h @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////// // Name: wx/cocoa/objc/NSView.h -// Purpose: wxPoserNSView class +// Purpose: WXNSView class // Author: David Elliott // Modified by: // Created: 2007/04/20 (move from NSView.mm) @@ -15,9 +15,9 @@ #import // ============================================================================ -// @class wxPoserNSView +// @class WXNSView // ============================================================================ -@interface wxPoserNSView : NSView +@interface WXNSView : NSView { } @@ -35,6 +35,6 @@ - (void)otherMouseDragged:(NSEvent *)theEvent; - (void)otherMouseUp:(NSEvent *)theEvent; - (void)resetCursorRects; -@end // wxPoserNSView +@end // WXNSView #endif //ndef __WX_COCOA_OBJC_NSVIEW_H__ diff --git a/include/wx/cocoa/objc/NSWindow.h b/include/wx/cocoa/objc/NSWindow.h index 91109254d2..56ba3e151b 100644 --- a/include/wx/cocoa/objc/NSWindow.h +++ b/include/wx/cocoa/objc/NSWindow.h @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////// // Name: wx/cocoa/objc/NSWindow.h -// Purpose: wxPoserNSWindow class +// Purpose: WXNSWindow class // Author: David Elliott // Modified by: // Created: 2007/04/20 (move from NSWindow.mm) @@ -10,15 +10,27 @@ /////////////////////////////////////////////////////////////////////////////// #import +#import // ============================================================================ -// @class wxPoserNSWindow +// @class WXNSWindow // ============================================================================ -@interface wxPoserNSWindow : NSWindow +@interface WXNSWindow : NSWindow { } - (BOOL)canBecomeKeyWindow; - (BOOL)canBecomeMainWindow; -@end // wxPoserNSwindow +@end // WXNSWindow + +// ============================================================================ +// @class WXNSPanel +// ============================================================================ +@interface WXNSPanel : NSPanel +{ +} + +- (BOOL)canBecomeKeyWindow; +- (BOOL)canBecomeMainWindow; +@end // WXNSPanel diff --git a/src/cocoa/NSMenu.mm b/src/cocoa/NSMenu.mm index 40226cd5a2..18451658af 100644 --- a/src/cocoa/NSMenu.mm +++ b/src/cocoa/NSMenu.mm @@ -22,11 +22,10 @@ #include "wx/cocoa/objc/NSMenu.h" // ============================================================================ -// @class wxPoserNSMenu +// @class WXNSMenu // ============================================================================ -WX_IMPLEMENT_POSER(wxPoserNSMenu); -@implementation wxPoserNSMenu : NSMenu +@implementation WXNSMenu : NSMenu - (void)dealloc { @@ -36,7 +35,7 @@ WX_IMPLEMENT_POSER(wxPoserNSMenu); [super dealloc]; } -@end // wxPoserNSMenu +@end // WXNSMenu // ============================================================================ // @class wxNSMenuNotificationObserver diff --git a/src/cocoa/NSView.mm b/src/cocoa/NSView.mm index db8d47e618..7d864f2e30 100644 --- a/src/cocoa/NSView.mm +++ b/src/cocoa/NSView.mm @@ -54,10 +54,10 @@ void wxCocoaNSView::DisassociateNSView(WX_NSView cocoaNSView) } // ============================================================================ -// @class wxPoserNSView +// @class WXNSView // ============================================================================ -WX_IMPLEMENT_POSER(wxPoserNSView); -@implementation wxPoserNSView : NSView + +@implementation WXNSView : NSView - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent { @@ -166,7 +166,7 @@ WX_IMPLEMENT_POSER(wxPoserNSView); [super resetCursorRects]; } -@end // implementation wxPoserNSView +@end // implementation WXNSView @interface wxNSViewNotificationObserver : NSObject { diff --git a/src/cocoa/NSWindow.mm b/src/cocoa/NSWindow.mm index 2a75aac9c0..a18760ee59 100644 --- a/src/cocoa/NSWindow.mm +++ b/src/cocoa/NSWindow.mm @@ -187,10 +187,9 @@ wxMenuBar* wxCocoaNSWindow::GetAppMenuBar(wxCocoaNSWindow *win) } // ============================================================================ -// @class wxPoserNSWindow +// @class WXNSWindow // ============================================================================ -WX_IMPLEMENT_POSER(wxPoserNSWindow); -@implementation wxPoserNSWindow : NSWindow +@implementation WXNSWindow : NSWindow - (BOOL)canBecomeKeyWindow { @@ -210,4 +209,29 @@ WX_IMPLEMENT_POSER(wxPoserNSWindow); return canBecome; } -@end // implementation wxPoserNSWindow +@end // implementation WXNSWindow + +// ============================================================================ +// @class WXNSPanel +// ============================================================================ +@implementation WXNSPanel : NSPanel + +- (BOOL)canBecomeKeyWindow +{ + bool canBecome = false; + wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self); + if(!tlw || !tlw->Cocoa_canBecomeKeyWindow(canBecome)) + canBecome = [super canBecomeKeyWindow]; + return canBecome; +} + +- (BOOL)canBecomeMainWindow +{ + bool canBecome = false; + wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self); + if(!tlw || !tlw->Cocoa_canBecomeMainWindow(canBecome)) + canBecome = [super canBecomeMainWindow]; + return canBecome; +} + +@end // implementation WXNSPanel diff --git a/src/cocoa/control.mm b/src/cocoa/control.mm index 3bb9b1b29f..1d14483d6d 100644 --- a/src/cocoa/control.mm +++ b/src/cocoa/control.mm @@ -30,15 +30,130 @@ } - (void)drawRect: (NSRect)rect; +- (void)mouseDown:(NSEvent *)theEvent; +- (void)mouseDragged:(NSEvent *)theEvent; +- (void)mouseUp:(NSEvent *)theEvent; +- (void)mouseMoved:(NSEvent *)theEvent; +- (void)mouseEntered:(NSEvent *)theEvent; +- (void)mouseExited:(NSEvent *)theEvent; +- (void)rightMouseDown:(NSEvent *)theEvent; +- (void)rightMouseDragged:(NSEvent *)theEvent; +- (void)rightMouseUp:(NSEvent *)theEvent; +- (void)otherMouseDown:(NSEvent *)theEvent; +- (void)otherMouseDragged:(NSEvent *)theEvent; +- (void)otherMouseUp:(NSEvent *)theEvent; +- (void)resetCursorRects; @end // wxNonControlNSControl @implementation wxNonControlNSControl : NSControl + +- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent +{ + bool acceptsFirstMouse = false; + wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); + if(!win || !win->Cocoa_acceptsFirstMouse(acceptsFirstMouse, theEvent)) + acceptsFirstMouse = [super acceptsFirstMouse:theEvent]; + return acceptsFirstMouse; +} + - (void)drawRect: (NSRect)rect { wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); if( !win || !win->Cocoa_drawRect(rect) ) [super drawRect:rect]; } + +- (void)mouseDown:(NSEvent *)theEvent +{ + wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); + if( !win || !win->Cocoa_mouseDown(theEvent) ) + [super mouseDown:theEvent]; +} + +- (void)mouseDragged:(NSEvent *)theEvent +{ + wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); + if( !win || !win->Cocoa_mouseDragged(theEvent) ) + [super mouseDragged:theEvent]; +} + +- (void)mouseUp:(NSEvent *)theEvent +{ + wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); + if( !win || !win->Cocoa_mouseUp(theEvent) ) + [super mouseUp:theEvent]; +} + +- (void)mouseMoved:(NSEvent *)theEvent +{ + wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); + if( !win || !win->Cocoa_mouseMoved(theEvent) ) + [super mouseMoved:theEvent]; +} + +- (void)mouseEntered:(NSEvent *)theEvent +{ + wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); + if( !win || !win->Cocoa_mouseEntered(theEvent) ) + [super mouseEntered:theEvent]; +} + +- (void)mouseExited:(NSEvent *)theEvent +{ + wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); + if( !win || !win->Cocoa_mouseExited(theEvent) ) + [super mouseExited:theEvent]; +} + +- (void)rightMouseDown:(NSEvent *)theEvent +{ + wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); + if( !win || !win->Cocoa_rightMouseDown(theEvent) ) + [super rightMouseDown:theEvent]; +} + +- (void)rightMouseDragged:(NSEvent *)theEvent +{ + wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); + if( !win || !win->Cocoa_rightMouseDragged(theEvent) ) + [super rightMouseDragged:theEvent]; +} + +- (void)rightMouseUp:(NSEvent *)theEvent +{ + wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); + if( !win || !win->Cocoa_rightMouseUp(theEvent) ) + [super rightMouseUp:theEvent]; +} + +- (void)otherMouseDown:(NSEvent *)theEvent +{ + wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); + if( !win || !win->Cocoa_otherMouseDown(theEvent) ) + [super otherMouseDown:theEvent]; +} + +- (void)otherMouseDragged:(NSEvent *)theEvent +{ + wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); + if( !win || !win->Cocoa_otherMouseDragged(theEvent) ) + [super otherMouseDragged:theEvent]; +} + +- (void)otherMouseUp:(NSEvent *)theEvent +{ + wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); + if( !win || !win->Cocoa_otherMouseUp(theEvent) ) + [super otherMouseUp:theEvent]; +} + +- (void)resetCursorRects +{ + wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); + if( !win || !win->Cocoa_resetCursorRects() ) + [super resetCursorRects]; +} + @end // wxNonControlNSControl IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) diff --git a/src/cocoa/frame.mm b/src/cocoa/frame.mm index 4a3569d81e..dd494c88df 100644 --- a/src/cocoa/frame.mm +++ b/src/cocoa/frame.mm @@ -170,7 +170,7 @@ void wxFrame::CocoaReplaceView(WX_NSView oldView, WX_NSView newView) void wxFrame::UpdateFrameNSView() { if(!m_frameNSView) - { + { // NOTE: We only need a plain NSView here since we don't associate it with ourselves. m_frameNSView = [[NSView alloc] initWithFrame:[[m_cocoaNSWindow contentView] frame]]; [m_cocoaNSWindow setContentView: m_frameNSView]; [m_frameNSView addSubview:m_cocoaNSView]; diff --git a/src/cocoa/menu.mm b/src/cocoa/menu.mm index 27cc125141..55e0f3035b 100644 --- a/src/cocoa/menu.mm +++ b/src/cocoa/menu.mm @@ -29,7 +29,7 @@ #include "wx/cocoa/string.h" #import -#import +#include "wx/cocoa/objc/NSMenu.h" #if wxUSE_MENUS @@ -46,7 +46,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler) bool wxMenu::Create(const wxString& title, long style) { wxAutoNSAutoreleasePool pool; - m_cocoaNSMenu = [[NSMenu alloc] initWithTitle: wxNSStringWithWxString(title)]; + m_cocoaNSMenu = [[WXNSMenu alloc] initWithTitle: wxNSStringWithWxString(title)]; AssociateNSMenu(m_cocoaNSMenu); return true; } diff --git a/src/cocoa/radiobox.mm b/src/cocoa/radiobox.mm index a6e87e742f..4b4f7522e2 100644 --- a/src/cocoa/radiobox.mm +++ b/src/cocoa/radiobox.mm @@ -20,7 +20,7 @@ #include "wx/arrstr.h" #endif //WX_PRECOMP -#import +#include "wx/cocoa/objc/NSView.h" IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl) BEGIN_EVENT_TABLE(wxRadioBox, wxControl) @@ -53,7 +53,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID winid, { if(!CreateControl(parent,winid,pos,size,style,validator,name)) return false; - SetNSView([[NSView alloc] initWithFrame: MakeDefaultNSRect(size)]); + SetNSView([[WXNSView alloc] initWithFrame: MakeDefaultNSRect(size)]); [m_cocoaNSView release]; if(m_parent) m_parent->CocoaAddChild(this); diff --git a/src/cocoa/toplevel.mm b/src/cocoa/toplevel.mm index 1a5379ff52..fbcf064b1b 100644 --- a/src/cocoa/toplevel.mm +++ b/src/cocoa/toplevel.mm @@ -33,8 +33,8 @@ #include "wx/cocoa/autorelease.h" #include "wx/cocoa/string.h" -#import -#import +#include "wx/cocoa/objc/NSView.h" +#include "wx/cocoa/objc/NSWindow.h" #import // ---------------------------------------------------------------------------- // globals @@ -131,10 +131,18 @@ bool wxTopLevelWindowCocoa::Create(wxWindow *parent, m_cocoaNSWindow = NULL; m_cocoaNSView = NULL; + // NOTE: We may need to deal with the contentView becoming a wx NSView as well. + NSWindow *newWindow; + // Create a WXNSPanel or a WXNSWindow depending on what type of window is desired. if(style & wxFRAME_TOOL_WINDOW) - SetNSWindow([[NSPanel alloc] initWithContentRect:cocoaRect styleMask:cocoaStyle backing:NSBackingStoreBuffered defer:NO]); + newWindow = [[WXNSPanel alloc] initWithContentRect:cocoaRect styleMask:cocoaStyle backing:NSBackingStoreBuffered defer:NO]; else - SetNSWindow([[NSWindow alloc] initWithContentRect:cocoaRect styleMask:cocoaStyle backing:NSBackingStoreBuffered defer:NO]); + newWindow = [[WXNSWindow alloc] initWithContentRect:cocoaRect styleMask:cocoaStyle backing:NSBackingStoreBuffered defer:NO]; + // Make sure the default content view is a WXNSView + [newWindow setContentView: [[WXNSView alloc] initWithFrame: [[newWindow contentView] frame]]]; + // Associate the window and view + SetNSWindow(newWindow); + // NOTE: SetNSWindow has retained the Cocoa object for this object. // Because we do not release on close, the following release matches the // above alloc and thus the retain count will be 1. @@ -188,6 +196,8 @@ void wxTopLevelWindowCocoa::SetNSWindow(WX_NSWindow cocoaNSWindow) [cocoaNSWindow retain]; [m_cocoaNSWindow release]; m_cocoaNSWindow = cocoaNSWindow; + // NOTE: We are no longer using posing so we won't get events on the + // window's view unless it was explicitly created as the wx view class. if(m_cocoaNSWindow) SetNSView([m_cocoaNSWindow contentView]); else diff --git a/src/cocoa/window.mm b/src/cocoa/window.mm index 91bb13ef99..13024b9f67 100644 --- a/src/cocoa/window.mm +++ b/src/cocoa/window.mm @@ -23,7 +23,7 @@ #include "wx/cocoa/autorelease.h" #include "wx/cocoa/string.h" -#import +#include "wx/cocoa/objc/NSView.h" #import #import #import @@ -327,7 +327,7 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID winid, // TODO: create the window m_cocoaNSView = NULL; - SetNSView([[NSView alloc] initWithFrame: MakeDefaultNSRect(size)]); + SetNSView([[WXNSView alloc] initWithFrame: MakeDefaultNSRect(size)]); [m_cocoaNSView release]; if (m_parent) -- 2.45.2