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
This commit is contained in:
David Elliott
2007-04-20 22:27:56 +00:00
parent ad3628fa86
commit 829a2e9521
13 changed files with 196 additions and 36 deletions

View File

@@ -73,7 +73,7 @@ private:
// ======================================================================== // ========================================================================
// wxMenuBar // wxMenuBar
// ======================================================================== // ========================================================================
class WXDLLEXPORT wxMenuBar : public wxMenuBarBase, public wxCocoaNSMenu class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
{ {
public: public:
// ctors and dtor // ctors and dtor

View File

@@ -1,6 +1,6 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Name: wx/cocoa/objc/NSMenu.h // Name: wx/cocoa/objc/NSMenu.h
// Purpose: wxPoserNSMenu class // Purpose: WXNSMenu class
// Author: David Elliott // Author: David Elliott
// Modified by: // Modified by:
// Created: 2007/04/20 (move from NSMenu.mm) // Created: 2007/04/20 (move from NSMenu.mm)
@@ -15,14 +15,14 @@
#import <AppKit/NSMenu.h> #import <AppKit/NSMenu.h>
// ============================================================================ // ============================================================================
// @class wxPoserNSMenu // @class WXNSMenu
// ============================================================================ // ============================================================================
@interface wxPoserNSMenu : NSMenu @interface WXNSMenu : NSMenu
{ {
} }
- (void)dealloc; - (void)dealloc;
@end // wxPoserNSMenu @end // WXNSMenu
#endif //ndef __WX_COCOA_OBJC_NSMENU_H__ #endif //ndef __WX_COCOA_OBJC_NSMENU_H__

View File

@@ -1,6 +1,6 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Name: wx/cocoa/objc/NSView.h // Name: wx/cocoa/objc/NSView.h
// Purpose: wxPoserNSView class // Purpose: WXNSView class
// Author: David Elliott // Author: David Elliott
// Modified by: // Modified by:
// Created: 2007/04/20 (move from NSView.mm) // Created: 2007/04/20 (move from NSView.mm)
@@ -15,9 +15,9 @@
#import <AppKit/NSView.h> #import <AppKit/NSView.h>
// ============================================================================ // ============================================================================
// @class wxPoserNSView // @class WXNSView
// ============================================================================ // ============================================================================
@interface wxPoserNSView : NSView @interface WXNSView : NSView
{ {
} }
@@ -35,6 +35,6 @@
- (void)otherMouseDragged:(NSEvent *)theEvent; - (void)otherMouseDragged:(NSEvent *)theEvent;
- (void)otherMouseUp:(NSEvent *)theEvent; - (void)otherMouseUp:(NSEvent *)theEvent;
- (void)resetCursorRects; - (void)resetCursorRects;
@end // wxPoserNSView @end // WXNSView
#endif //ndef __WX_COCOA_OBJC_NSVIEW_H__ #endif //ndef __WX_COCOA_OBJC_NSVIEW_H__

View File

@@ -1,6 +1,6 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Name: wx/cocoa/objc/NSWindow.h // Name: wx/cocoa/objc/NSWindow.h
// Purpose: wxPoserNSWindow class // Purpose: WXNSWindow class
// Author: David Elliott // Author: David Elliott
// Modified by: // Modified by:
// Created: 2007/04/20 (move from NSWindow.mm) // Created: 2007/04/20 (move from NSWindow.mm)
@@ -10,15 +10,27 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#import <AppKit/NSWindow.h> #import <AppKit/NSWindow.h>
#import <AppKit/NSPanel.h>
// ============================================================================ // ============================================================================
// @class wxPoserNSWindow // @class WXNSWindow
// ============================================================================ // ============================================================================
@interface wxPoserNSWindow : NSWindow @interface WXNSWindow : NSWindow
{ {
} }
- (BOOL)canBecomeKeyWindow; - (BOOL)canBecomeKeyWindow;
- (BOOL)canBecomeMainWindow; - (BOOL)canBecomeMainWindow;
@end // wxPoserNSwindow @end // WXNSWindow
// ============================================================================
// @class WXNSPanel
// ============================================================================
@interface WXNSPanel : NSPanel
{
}
- (BOOL)canBecomeKeyWindow;
- (BOOL)canBecomeMainWindow;
@end // WXNSPanel

View File

@@ -22,11 +22,10 @@
#include "wx/cocoa/objc/NSMenu.h" #include "wx/cocoa/objc/NSMenu.h"
// ============================================================================ // ============================================================================
// @class wxPoserNSMenu // @class WXNSMenu
// ============================================================================ // ============================================================================
WX_IMPLEMENT_POSER(wxPoserNSMenu); @implementation WXNSMenu : NSMenu
@implementation wxPoserNSMenu : NSMenu
- (void)dealloc - (void)dealloc
{ {
@@ -36,7 +35,7 @@ WX_IMPLEMENT_POSER(wxPoserNSMenu);
[super dealloc]; [super dealloc];
} }
@end // wxPoserNSMenu @end // WXNSMenu
// ============================================================================ // ============================================================================
// @class wxNSMenuNotificationObserver // @class wxNSMenuNotificationObserver

View File

@@ -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 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
{ {
@@ -166,7 +166,7 @@ WX_IMPLEMENT_POSER(wxPoserNSView);
[super resetCursorRects]; [super resetCursorRects];
} }
@end // implementation wxPoserNSView @end // implementation WXNSView
@interface wxNSViewNotificationObserver : NSObject @interface wxNSViewNotificationObserver : NSObject
{ {

View File

@@ -187,10 +187,9 @@ wxMenuBar* wxCocoaNSWindow::GetAppMenuBar(wxCocoaNSWindow *win)
} }
// ============================================================================ // ============================================================================
// @class wxPoserNSWindow // @class WXNSWindow
// ============================================================================ // ============================================================================
WX_IMPLEMENT_POSER(wxPoserNSWindow); @implementation WXNSWindow : NSWindow
@implementation wxPoserNSWindow : NSWindow
- (BOOL)canBecomeKeyWindow - (BOOL)canBecomeKeyWindow
{ {
@@ -210,4 +209,29 @@ WX_IMPLEMENT_POSER(wxPoserNSWindow);
return canBecome; 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

View File

@@ -30,15 +30,130 @@
} }
- (void)drawRect: (NSRect)rect; - (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 @end // wxNonControlNSControl
@implementation wxNonControlNSControl : NSControl @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 - (void)drawRect: (NSRect)rect
{ {
wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self); wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
if( !win || !win->Cocoa_drawRect(rect) ) if( !win || !win->Cocoa_drawRect(rect) )
[super 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 @end // wxNonControlNSControl
IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)

View File

@@ -170,7 +170,7 @@ void wxFrame::CocoaReplaceView(WX_NSView oldView, WX_NSView newView)
void wxFrame::UpdateFrameNSView() void wxFrame::UpdateFrameNSView()
{ {
if(!m_frameNSView) 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_frameNSView = [[NSView alloc] initWithFrame:[[m_cocoaNSWindow contentView] frame]];
[m_cocoaNSWindow setContentView: m_frameNSView]; [m_cocoaNSWindow setContentView: m_frameNSView];
[m_frameNSView addSubview:m_cocoaNSView]; [m_frameNSView addSubview:m_cocoaNSView];

View File

@@ -29,7 +29,7 @@
#include "wx/cocoa/string.h" #include "wx/cocoa/string.h"
#import <Foundation/NSString.h> #import <Foundation/NSString.h>
#import <AppKit/NSMenu.h> #include "wx/cocoa/objc/NSMenu.h"
#if wxUSE_MENUS #if wxUSE_MENUS
@@ -46,7 +46,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler)
bool wxMenu::Create(const wxString& title, long style) bool wxMenu::Create(const wxString& title, long style)
{ {
wxAutoNSAutoreleasePool pool; wxAutoNSAutoreleasePool pool;
m_cocoaNSMenu = [[NSMenu alloc] initWithTitle: wxNSStringWithWxString(title)]; m_cocoaNSMenu = [[WXNSMenu alloc] initWithTitle: wxNSStringWithWxString(title)];
AssociateNSMenu(m_cocoaNSMenu); AssociateNSMenu(m_cocoaNSMenu);
return true; return true;
} }

View File

@@ -20,7 +20,7 @@
#include "wx/arrstr.h" #include "wx/arrstr.h"
#endif //WX_PRECOMP #endif //WX_PRECOMP
#import <AppKit/NSView.h> #include "wx/cocoa/objc/NSView.h"
IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
BEGIN_EVENT_TABLE(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)) if(!CreateControl(parent,winid,pos,size,style,validator,name))
return false; return false;
SetNSView([[NSView alloc] initWithFrame: MakeDefaultNSRect(size)]); SetNSView([[WXNSView alloc] initWithFrame: MakeDefaultNSRect(size)]);
[m_cocoaNSView release]; [m_cocoaNSView release];
if(m_parent) if(m_parent)
m_parent->CocoaAddChild(this); m_parent->CocoaAddChild(this);

View File

@@ -33,8 +33,8 @@
#include "wx/cocoa/autorelease.h" #include "wx/cocoa/autorelease.h"
#include "wx/cocoa/string.h" #include "wx/cocoa/string.h"
#import <AppKit/NSView.h> #include "wx/cocoa/objc/NSView.h"
#import <AppKit/NSWindow.h> #include "wx/cocoa/objc/NSWindow.h"
#import <AppKit/NSPanel.h> #import <AppKit/NSPanel.h>
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// globals // globals
@@ -131,10 +131,18 @@ bool wxTopLevelWindowCocoa::Create(wxWindow *parent,
m_cocoaNSWindow = NULL; m_cocoaNSWindow = NULL;
m_cocoaNSView = 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) 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 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. // NOTE: SetNSWindow has retained the Cocoa object for this object.
// Because we do not release on close, the following release matches the // Because we do not release on close, the following release matches the
// above alloc and thus the retain count will be 1. // above alloc and thus the retain count will be 1.
@@ -188,6 +196,8 @@ void wxTopLevelWindowCocoa::SetNSWindow(WX_NSWindow cocoaNSWindow)
[cocoaNSWindow retain]; [cocoaNSWindow retain];
[m_cocoaNSWindow release]; [m_cocoaNSWindow release];
m_cocoaNSWindow = cocoaNSWindow; 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) if(m_cocoaNSWindow)
SetNSView([m_cocoaNSWindow contentView]); SetNSView([m_cocoaNSWindow contentView]);
else else

View File

@@ -23,7 +23,7 @@
#include "wx/cocoa/autorelease.h" #include "wx/cocoa/autorelease.h"
#include "wx/cocoa/string.h" #include "wx/cocoa/string.h"
#import <AppKit/NSView.h> #include "wx/cocoa/objc/NSView.h"
#import <AppKit/NSEvent.h> #import <AppKit/NSEvent.h>
#import <AppKit/NSScrollView.h> #import <AppKit/NSScrollView.h>
#import <AppKit/NSColor.h> #import <AppKit/NSColor.h>
@@ -327,7 +327,7 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID winid,
// TODO: create the window // TODO: create the window
m_cocoaNSView = NULL; m_cocoaNSView = NULL;
SetNSView([[NSView alloc] initWithFrame: MakeDefaultNSRect(size)]); SetNSView([[WXNSView alloc] initWithFrame: MakeDefaultNSRect(size)]);
[m_cocoaNSView release]; [m_cocoaNSView release];
if (m_parent) if (m_parent)