From d139c3a84be966e6989b35ed6fc31e2580352c2b Mon Sep 17 00:00:00 2001 From: David Elliott Date: Wed, 13 Aug 2003 19:37:45 +0000 Subject: [PATCH] Added helper functions for setting initial window size: * inline MakeDefaultNSRect makes an NSRect with position (10.0,10.0) and size based on the size passed to Create run through (Width|Height)Default This NSRect is to be used with the initWithFrame: initializer. * SetInitialFrameRect is called after the window has been added to its parent and (if applicable) sized to fit. If -1 is specified for a dimension then the fit/default size is kept. If not, the window is sized to the specified size. It will be positioned in wxWindows coordinates (0,0==TL). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22809 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/window.h | 12 ++++++++++++ src/cocoa/window.mm | 20 ++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/wx/cocoa/window.h b/include/wx/cocoa/window.h index ef3dcb4740..44865f4d20 100644 --- a/include/wx/cocoa/window.h +++ b/include/wx/cocoa/window.h @@ -14,6 +14,10 @@ #include "wx/cocoa/NSView.h" +#ifdef __OBJC__ + #import +#endif //def __OBJC__ + class wxWindowCocoaHider; // ======================================================================== @@ -83,6 +87,14 @@ protected: bool m_isInPaint; static wxWindow *sm_capturedWindow; virtual void CocoaReplaceView(WX_NSView oldView, WX_NSView newView); + void SetInitialFrameRect(const wxPoint& pos, const wxSize& size); +#ifdef __OBJC__ + inline NSRect MakeDefaultNSRect(const wxSize& size) + { + // NOTE: position is 10,10 to make it "obvious" that it's out of place + return NSMakeRect(10.0,10.0,WidthDefault(size.x),HeightDefault(size.y)); + } +#endif //def __OBJC__ // ------------------------------------------------------------------------ // Implementation // ------------------------------------------------------------------------ diff --git a/src/cocoa/window.mm b/src/cocoa/window.mm index b255cb1212..bd68943c13 100644 --- a/src/cocoa/window.mm +++ b/src/cocoa/window.mm @@ -98,9 +98,8 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID winid, return false; // TODO: create the window - NSRect cocoaRect = NSMakeRect(10,10,20,20); m_cocoaNSView = NULL; - SetNSView([[NSView alloc] initWithFrame: cocoaRect]); + SetNSView([[NSView alloc] initWithFrame: MakeDefaultNSRect(size)]); [m_cocoaNSView release]; if (m_parent) @@ -108,6 +107,7 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID winid, m_parent->AddChild(this); m_parent->CocoaAddChild(this); } + SetInitialFrameRect(pos,size); return TRUE; } @@ -386,6 +386,22 @@ void wxWindowCocoa::DoMoveWindow(int x, int y, int width, int height) [nsview setFrame: cocoaRect]; } +void wxWindowCocoa::SetInitialFrameRect(const wxPoint& pos, const wxSize& size) +{ + NSView *nsview = GetNSViewForSuperview(); + NSView *superview = [nsview superview]; + wxCHECK_RET(superview,"NSView does not have a superview"); + NSRect parentRect = [superview frame]; + NSRect frameRect = [nsview frame]; + if(size.x!=-1) + frameRect.size.width = size.x; + if(size.y!=-1) + frameRect.size.height = size.y; + frameRect.origin.x = pos.x; + frameRect.origin.y = parentRect.size.height-(pos.y+size.y); + [nsview setFrame: frameRect]; +} + // Get total size void wxWindow::DoGetSize(int *w, int *h) const { -- 2.45.2