#include "StdAfx.h"
|
#include "Layout.h"
|
|
Layout::Layout(
|
LayoutType type ,
|
CWnd* pWndParent ,
|
|
bool expandToFill,
|
int fillSpaceOrRealSize,
|
|
int wndID,
|
|
int outerPaddingLeft,
|
int outerPaddingRight,
|
|
int outerPaddingUp,
|
int outerPaddingDown,
|
|
int innerPaddingLeft,
|
int innerPaddingRight,
|
|
int innerPaddingUp,
|
int innerPaddingDown)
|
{
|
m_type = type;
|
|
m_pWndParent = pWndParent;
|
|
m_bExpandToFill = expandToFill;
|
m_FillSpaceOrRealSize = fillSpaceOrRealSize;
|
|
m_wndID = wndID;
|
|
m_x = 0;
|
m_y = 0;
|
m_width = 0;
|
m_height = 0;
|
|
m_innerPaddingLeft = innerPaddingLeft;
|
m_innerPaddingRight = innerPaddingRight;
|
m_innerPaddingUp = innerPaddingUp;
|
m_innerPaddingDown = innerPaddingDown;
|
|
m_outerPaddingLeft = outerPaddingLeft;
|
m_outerPaddingRight = outerPaddingRight;
|
m_outerPaddingUp = outerPaddingUp;
|
m_outerPaddingDown = outerPaddingDown;
|
|
}
|
Layout::~Layout(void)
|
{
|
for (vector<Layout*>::iterator iter = m_children.begin() ; iter != m_children.end() ; iter++)
|
{
|
delete *iter;
|
}
|
}
|
Layout* Layout::AddChild(
|
LayoutType type ,
|
|
bool expandToFill,
|
int fillSpaceOrRealSize,
|
|
int wndID,
|
|
int outerPaddingLeft,
|
int outerPaddingRight,
|
|
int outerPaddingUp,
|
int outerPaddingDown,
|
|
int innerPaddingLeft,
|
int innerPaddingRight,
|
|
int innerPaddingUp,
|
int innerPaddingDown)
|
{
|
ASSERT(m_type != LT_Window);
|
Layout* child = new Layout(
|
type , m_pWndParent , expandToFill , fillSpaceOrRealSize , wndID ,
|
outerPaddingLeft , outerPaddingRight , outerPaddingUp , outerPaddingDown,
|
innerPaddingLeft , innerPaddingRight , innerPaddingUp , innerPaddingDown);
|
|
m_children.push_back(child);
|
return child;
|
}
|
|
void Layout::UpdateSize(int w , int h)
|
{
|
m_width = w;
|
m_height = h;
|
UpdateLayout();
|
}
|
void Layout::UpdateLayout()
|
{
|
if (m_type & LT_Window)
|
{
|
UpdateWindow();
|
}
|
if (m_type & LT_LayoutH)
|
{
|
UpdateLayoutH();
|
}
|
if (m_type & LT_LayoutV)
|
{
|
UpdateLayoutV();
|
}
|
}
|
void Layout::UpdateLayoutH()
|
{
|
int totalExpandCount = 0;
|
|
int totalExpandSize = m_width
|
- m_outerPaddingLeft
|
- m_outerPaddingRight
|
- m_innerPaddingLeft
|
- m_innerPaddingRight;
|
|
for (vector<Layout*>::iterator iter = m_children.begin() ; iter != m_children.end() ; iter++)
|
{
|
Layout* child = *iter;
|
|
child->m_height = m_height
|
- m_outerPaddingUp
|
- m_outerPaddingDown
|
- m_innerPaddingUp
|
- m_innerPaddingDown;
|
|
child->m_y = m_y
|
+ m_outerPaddingUp
|
+ m_innerPaddingUp;
|
|
if (child->m_bExpandToFill)
|
{
|
totalExpandCount += child->m_FillSpaceOrRealSize;
|
}else{
|
child->m_width = child->m_FillSpaceOrRealSize;
|
totalExpandSize -= child->m_FillSpaceOrRealSize;
|
}
|
}
|
float unitExpandSize = 0;
|
if (totalExpandCount > 0)
|
{
|
unitExpandSize = float(totalExpandSize) / float(totalExpandCount);
|
}
|
|
int x = m_x
|
+ m_outerPaddingLeft
|
+ m_innerPaddingLeft;
|
|
for (vector<Layout*>::iterator iter = m_children.begin() ; iter != m_children.end() ; iter++)
|
{
|
Layout* child = *iter;
|
|
child->m_x = x;
|
if (child->m_bExpandToFill)
|
{
|
child->m_width = int(unitExpandSize * child->m_FillSpaceOrRealSize);
|
}
|
|
child->UpdateLayout();
|
|
x += child->m_width;
|
}
|
}
|
void Layout::UpdateLayoutV()
|
{
|
int totalExpandCount = 0;
|
|
int totalExpandSize = m_height
|
- m_outerPaddingUp
|
- m_outerPaddingDown
|
- m_innerPaddingUp
|
- m_innerPaddingDown;
|
|
for (vector<Layout*>::iterator iter = m_children.begin() ; iter != m_children.end() ; iter++)
|
{
|
Layout* child = *iter;
|
|
child->m_width = m_width
|
- m_outerPaddingLeft
|
- m_outerPaddingRight
|
- m_innerPaddingLeft
|
- m_innerPaddingRight;
|
|
child->m_x = m_x
|
+ m_outerPaddingLeft
|
+ m_innerPaddingLeft;
|
|
if (child->m_bExpandToFill)
|
{
|
totalExpandCount += child->m_FillSpaceOrRealSize;
|
}else{
|
child->m_height = child->m_FillSpaceOrRealSize;
|
totalExpandSize -= child->m_FillSpaceOrRealSize;
|
}
|
}
|
float unitExpandSize = 0;
|
if (totalExpandCount > 0)
|
{
|
unitExpandSize = float(totalExpandSize) / float(totalExpandCount);
|
}
|
|
int y = m_y
|
+ m_outerPaddingUp
|
+ m_innerPaddingUp;
|
|
for (vector<Layout*>::iterator iter = m_children.begin() ; iter != m_children.end() ; iter++)
|
{
|
Layout* child = *iter;
|
|
child->m_y = y;
|
if (child->m_bExpandToFill)
|
{
|
child->m_height = int(unitExpandSize * child->m_FillSpaceOrRealSize);
|
}
|
|
child->UpdateLayout();
|
|
y += child->m_height;
|
}
|
}
|
|
void Layout::UpdateWindow()
|
{
|
m_pWndParent->GetDlgItem(m_wndID)->MoveWindow(
|
m_x + m_outerPaddingLeft,
|
m_y + m_outerPaddingUp,
|
m_width - m_outerPaddingLeft - m_outerPaddingRight,
|
m_height - m_outerPaddingUp - m_outerPaddingDown);
|
}
|