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
This commit is contained in:
parent
6056c7c6f3
commit
d139c3a84b
@ -14,6 +14,10 @@
|
||||
|
||||
#include "wx/cocoa/NSView.h"
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Foundation/NSGeometry.h>
|
||||
#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
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user