📄 etslayout.cpp
字号:
bool ETSLayoutMgr::Pane::resizeTo(CRect& rcNewArea)
{
// There must be some items or subpanes
ASSERT(m_paneItems.GetSize());
// This Array holds the size in primary direction for each item/subpane
CArray<int,int> sizePrimary;
sizePrimary.SetSize(m_paneItems.GetSize());
// This Array holds information about the minimum size in primary direction
CArray<int,int> sizeMin;
sizeMin.SetSize(m_paneItems.GetSize());
// This Array holds information about the maximum size in primary direction
CArray<int,int> sizeMax;
sizeMax.SetSize(m_paneItems.GetSize());
// How much space is actually available, subtract all borders between items
int availSpace = (m_Orientation == HORIZONTAL ? rcNewArea.Width() : rcNewArea.Height() ) - (m_paneItems.GetUpperBound()*m_sizeBorder);
// If there is some Extra border (on top/bottem resp. left/right) subtract it too
availSpace -= 2*m_sizeExtraBorder;
// Add the extra Border to top/bottem resp. left/right
if(m_Orientation == HORIZONTAL) {
rcNewArea.top += m_sizeExtraBorder;
rcNewArea.bottom -= m_sizeExtraBorder;
}
else {
rcNewArea.left += m_sizeExtraBorder;
rcNewArea.right -= m_sizeExtraBorder;
}
// Counts the number of greedy items/subpanes
int nGreedy = resizeToAbsolute(availSpace, sizePrimary, sizeMin, sizeMax );
if(nGreedy == -1)
return false;
if(! resizeToRelative(availSpace, sizePrimary, sizeMin, sizeMax ) )
return false;
if(! resizeToGreedy(availSpace, nGreedy, sizePrimary, sizeMin, sizeMax ) )
return false;
// If there is any left space and there are ALIGN_FILL_* Items to assign it
// equally among them
if( availSpace > 0 ) {
// Count possible Items
int nFillItems = 0;
for(int i=0; i<m_paneItems.GetSize(); ++i) {
CPaneBase pItem = m_paneItems[i];
if( m_Orientation == HORIZONTAL
&& (pItem->modeResize() & ABSOLUTE_HORZ )
&& (pItem->modeResize() & ALIGN_FILL_HORZ)
||
(pItem->modeResize() & ABSOLUTE_VERT )
&& (pItem->modeResize() & ALIGN_FILL_VERT)
)
{
++nFillItems;
}
}
if( nFillItems > 0 ) {
// okay, there are nFillItems, make them all availSpace/nFillItems bigger
for(int i=0; i<m_paneItems.GetSize(); ++i) {
CPaneBase pItem = m_paneItems[i];
if( m_Orientation == HORIZONTAL
&& (pItem->modeResize() & ABSOLUTE_HORZ )
&& (pItem->modeResize() & ALIGN_FILL_HORZ)
||
(pItem->modeResize() & ABSOLUTE_VERT )
&& (pItem->modeResize() & ALIGN_FILL_VERT)
)
{
if( nFillItems == 1 ) {
// the last one gets all the rest
sizePrimary[i] += availSpace;
availSpace = 0;
--nFillItems;
}
else {
sizePrimary[i] += availSpace/nFillItems;
availSpace -= availSpace/nFillItems;
--nFillItems;
}
}
}
}
}
// Now reposition all items:
// starting offset
int nOffset = (m_Orientation==HORIZONTAL ? rcNewArea.left : rcNewArea.top ) + m_sizeExtraBorder;
for(int i=0; i<m_paneItems.GetSize(); ++i) {
CPaneBase pItem = m_paneItems[i];
// Calculate rect of item/subpane
CRect rcPane;
if( m_Orientation==HORIZONTAL ) {
rcPane.SetRect(nOffset, rcNewArea.top, nOffset+sizePrimary[i], rcNewArea.bottom);
}
else {
rcPane.SetRect(rcNewArea.left, nOffset, rcNewArea.right, nOffset+sizePrimary[i]);
}
// do the resizing!
pItem->resizeTo( rcPane );
// go to the next position (old pos + size + border)
nOffset += m_sizeBorder + sizePrimary[i];
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// ETSLayoutDialog dialog
#pragma warning(disable: 4355)
ETSLayoutDialog::ETSLayoutDialog(UINT nID, CWnd* pParent /*=NULL*/, LPCTSTR strName /*=NULL*/, bool bGripper /*=true*/)
: CBaseDialog(nID, pParent), ETSLayoutMgr( this )
{
//{{AFX_DATA_INIT(ETSLayoutDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_bGripper = bGripper;
if(strName)
m_strRegStore = strName;
}
#pragma warning(default: 4355)
BEGIN_MESSAGE_MAP(ETSLayoutDialog, CBaseDialog)
//{{AFX_MSG_MAP(ETSLayoutDialog)
ON_WM_SIZE()
ON_WM_GETMINMAXINFO()
ON_WM_ERASEBKGND()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// ETSLayoutDialog message handlers
BOOL ETSLayoutDialog::OnEraseBkgnd(CDC* pDC)
{
EraseBkgnd(pDC);
return true;
}
void ETSLayoutDialog::OnSize(UINT nType, int cx, int cy)
{
CBaseDialog::OnSize(nType, cx, cy);
if( abs(cx) + abs(cy) > 0)
{
// Reposition Size Marker
// Re-Layout all controls
UpdateLayout();
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
}
}
void ETSLayoutDialog::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
if(m_RootPane.IsValid()) {
CRect rcClient = GetRect();
CRect rcWnd;
GetWindowRect(rcWnd);
// How much do Window and Client differ
int nDiffHorz = rcWnd.Width() - rcClient.Width();
int nDiffVert = rcWnd.Height() - rcClient.Height();
// Take into account that there is a border around the rootPane
lpMMI->ptMinTrackSize = CPoint(m_RootPane->getMinConstrainHorz() + nDiffHorz + 2*m_sizeRootBorders.cx,
m_RootPane->getMinConstrainVert() + nDiffVert + 2*m_sizeRootBorders.cy);
int maxWidth = m_RootPane->getMaxConstrainHorz();
int maxHeight = m_RootPane->getMaxConstrainVert();
if( maxWidth != -1 ) {
lpMMI->ptMaxTrackSize.x = maxWidth + nDiffHorz + 2*m_sizeRootBorders.cx;
lpMMI->ptMaxSize.x = maxWidth + nDiffHorz + 2*m_sizeRootBorders.cx;
}
if( maxHeight != -1 ) {
lpMMI->ptMaxTrackSize.y = maxHeight + nDiffVert + 2*m_sizeRootBorders.cy;
lpMMI->ptMaxSize.y = maxHeight + nDiffVert + 2*m_sizeRootBorders.cy;
}
}
}
CRect ETSLayoutDialog::GetRect()
{
CRect r;
GetClientRect(r);
if( m_bGripper )
{
if( ::IsWindow(m_StatusBar.GetSafeHwnd()) )
{
CRect rcSizeIcon;
m_StatusBar.GetWindowRect( rcSizeIcon);
r.bottom -= (rcSizeIcon.Height() - m_sizeRootBorders.cy - 5);
}
}
return r;
}
BOOL ETSLayoutDialog::OnInitDialog()
{
CBaseDialog::OnInitDialog();
if(!m_strRegStore.IsEmpty()) {
Load(m_strRegStore);
}
#ifdef _AUTO_SET_ICON
POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition();
if(pos) {
class ETSPseudoDocTemplate : public CDocTemplate
{
friend class ETSLayoutDialog;
};
ETSPseudoDocTemplate* pDocT = (ETSPseudoDocTemplate*) AfxGetApp()->GetNextDocTemplate(pos);
SetIcon( AfxGetApp()->LoadIcon(pDocT->m_nIDResource) ,FALSE);
}
#endif
// Sizing icon
if(m_bGripper)
{
if(m_StatusBar.Create(m_pWnd))
{
m_StatusBar.SetIndicators(auIDStatusBar, sizeof(auIDStatusBar) / sizeof(UINT));
m_StatusBar.SetWindowText("");
m_StatusBar.SetPaneStyle( 0, SBPS_STRETCH | SBPS_NOBORDERS );
m_pWnd -> RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
}
else
AfxMessageBox("Error - Statusbar");
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void ETSLayoutDialog::OnDestroy()
{
// Store size/position
if(!m_strRegStore.IsEmpty()) {
Save(m_strRegStore);
}
// manually delete layout definition if object is reused
m_RootPane = 0;
CBaseDialog::OnDestroy();
}
/////////////////////////////////////////////////////////////////////////////
// ETSLayoutDialog dialog
#pragma warning(disable: 4355)
#ifdef CS_HELP
ETSLayoutDialogBar::ETSLayoutDialogBar(UINT nID )
: CBaseDialogBar( nID ), ETSLayoutMgr( this )
#else
ETSLayoutDialogBar::ETSLayoutDialogBar()
: ETSLayoutMgr( this )
#endif
{
//{{AFX_DATA_INIT(ETSLayoutDialogBar)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_bInitialized = false;
setRootBorders(0,0);
}
#pragma warning(default: 4355)
BEGIN_MESSAGE_MAP(ETSLayoutDialogBar, CBaseDialogBar)
//{{AFX_MSG_MAP(ETSLayoutDialogBar)
ON_WM_SIZE()
ON_WM_GETMINMAXINFO()
ON_WM_DESTROY()
ON_WM_ERASEBKGND()
ON_MESSAGE(WM_INITDIALOG, OnInitDialog)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// ETSLayoutDialogBar message handlers
LRESULT ETSLayoutDialogBar::OnInitDialog(WPARAM, LPARAM)
{
Default();
Initialize();
return TRUE;
}
CSize ETSLayoutDialogBar::CalcDynamicLayout(int nLength, DWORD dwMode)
{
CSize sizeRet = CBaseDialogBar::CalcDynamicLayout(nLength, dwMode);
CSize sizeMin = sizeRet;
CSize sizeMax = sizeRet;
if(m_RootPane.IsValid()) {
CRect rcClient = GetRect();
CRect rcWnd;
GetWindowRect(rcWnd);
// How much do Window and Client differ
CSize sizeDiff( rcWnd.Width() - rcClient.Width(), rcWnd.Height() - rcClient.Height());
// Take into account that there is a border around the rootPane
sizeMin = CSize(m_RootPane->getMinConstrainHorz() + sizeDiff.cx + 2*m_sizeRootBorders.cx,
m_RootPane->getMinConstrainVert() + sizeDiff.cy + 2*m_sizeRootBorders.cy);
int maxWidth = m_RootPane->getMaxConstrainHorz();
int maxHeight = m_RootPane->getMaxConstrainVert();
if( maxWidth != -1 ) {
sizeMax.cx = maxWidth + sizeDiff.cy + 2*m_sizeRootBorders.cx;
}
if( maxHeight != -1 ) {
sizeMax.cy = maxHeight + sizeDiff.cy + 2*m_sizeRootBorders.cy;
}
}
if( IsFloating() || !(dwMode&LM_HORZ))
{
sizeRet.cx = min( sizeRet.cx, sizeMax.cx );
}
if( IsFloating() || (dwMode&LM_HORZ))
{
sizeRet.cy = min( sizeRet.cy, sizeMax.cy );
}
sizeRet.cx = max( sizeRet.cx, sizeMin.cx );
sizeRet.cy = max( sizeRet.cy, sizeMin.cy );
return sizeRet;
}
BOOL ETSLayoutDialogBar::OnEraseBkgnd(CDC* pDC)
{
EraseBkgnd(pDC);
return true;
}
void ETSLayoutDialogBar::OnSize(UINT nType, int cx, int cy)
{
CBaseDialogBar::OnSize(nType, cx, cy);
if( abs(cx) + abs(cy) > 0)
{
// Re-Layout all controls
UpdateLayout();
}
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
}
CRect ETSLayoutDialogBar::GetRect()
{
CRect r;
GetClientRect(r);
if( IsFloating() )
r.DeflateRect(4,4);
return r;
}
void ETSLayoutDialogBar::OnDestroy()
{
// Store size/position on your own!
CBaseDialogBar::OnDestroy();
}
/////////////////////////////////////////////////////////////////////////////
// ETSLayoutFormView dialog
IMPLEMENT_DYNAMIC(ETSLayoutFormView, CFormView)
#pragma warning(disable: 4355)
ETSLayoutFormView::ETSLayoutFormView(UINT nID, LPCTSTR strName /*=NULL*/)
: CBaseFormView(nID), ETSLayoutMgr( this )
{
if(strName)
m_strRegStore = strName;
}
#pragma warning(default: 4355)
BEGIN_MESSAGE_MAP(ETSLayoutFormView, CBaseFormView)
//{{AFX_MSG_MAP(ETSLayoutFormView)
ON_WM_SIZE()
ON_WM_GETMINMAXINFO()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// ETSLayoutFormView message handlers
BOOL ETSLayoutFormView::OnEraseBkgnd(CDC* pDC)
{
EraseBkgnd(pDC);
return true;
}
void ETSLayoutFormView::OnSize(UINT nType, int cx, int cy)
{
// CBaseFormView::OnSize(nType, cx, cy);
SetScrollSizes(MM_TEXT, CSize(cx,cy));
if( abs(cx) + abs(cy) > 0) {
// Re-Layout all controls
UpdateLayout();
}
// MoveWindow(0,0,cx,cy);
}
/*
void ETSLayoutFormView::UpdateLayout()
{
ETSLayoutMgr::UpdateLayout();
if(m_RootPane.IsValid()) {
// Force MainFrame to re-layout
CFrameWnd* pFrame = static_cast<CFrameWnd*>(GetParent());
if(pFrame) {
CRect rcWnd;
pFrame->GetWindowRect(rcWnd);
pFrame->MoveWindow(rcWnd);
pFrame->RecalcLayout();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -