您的位置:首页 > Web前端

[Effective WX] 理解wxWindow与wxSizer的关系

2012-08-15 10:07 155 查看
wxWindow与wxSizer

每个wxWindow都有一个m_contaningSizer(包含这个wxWindow窗口),还有一个m_windowSizer(这个窗口所包含的顶层wxSizer)。

设置包含这个window的sizer

void wxWindowBase::SetContainingSizer(wxSizer* sizer)
{
// adding a window to a sizer twice is going to result in fatal and
// hard to debug problems later because when deleting the second
// associated wxSizerItem we're going to dereference a dangling
// pointer; so try to detect this as early as possible
wxASSERT_MSG( !sizer || m_containingSizer != sizer,
_T("Adding a window to the same sizer twice?") );

m_containingSizer = sizer;
}


设置这个窗口包含的顶层sizer

void wxWindowBase::SetSizer(wxSizer *sizer, bool deleteOld)
{
if ( sizer == m_windowSizer)
return;</em>

if ( m_windowSizer )
{
m_windowSizer->SetContainingWindow(NULL);

if ( deleteOld )
delete m_windowSizer;
}

m_windowSizer = sizer;
if ( m_windowSizer )
{
m_windowSizer->SetContainingWindow((wxWindow *)this);
}

SetAutoLayout(m_windowSizer != NULL);
}


窗口的Layout函数

layout这个窗口时,如果存在顶层sizer,就会调用这个sizer的Layout(in SetDimension函数中)。

bool wxWindowBase::Layout()
{
// If there is a sizer, use it instead of the constraints
if ( GetSizer() )
{
int w = 0, h = 0;
GetVirtualSize(&w, &h);
GetSizer()->SetDimension( 0, 0, w, h );
}
#if wxUSE_CONSTRAINTS
else
{
SatisfyConstraints(); // Find the right constraints values
SetConstraintSizes(); // Recursively set the real window sizes
}
#endif

return true;
}


window的virtual size是client sizer和virtual Size变量的较大值。一般的window都是client size和virtual size变量一样大,除了scroll window类似的窗口。

wxSize wxWindowBase::DoGetVirtualSize() const
{
// we should use the entire client area so if it is greater than our
// virtual size, expand it to fit (otherwise if the window is big enough we
// wouldn't be using parts of it)
wxSize size = GetClientSize();
if ( m_virtualSize.x > size.x )
size.x = m_virtualSize.x;

if ( m_virtualSize.y >= size.y )
size.y = m_virtualSize.y;

return size;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: