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:
David Elliott
2003-08-13 19:37:45 +00:00
parent 6056c7c6f3
commit d139c3a84b
2 changed files with 30 additions and 2 deletions

View File

@@ -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
{