📄 etslayout.cpp
字号:
#define OEMRESOURCE
#include <windows.h>
#include "stdafx.h"
#include "ETSLayout.h"
#ifndef OBM_SIZE
#define OBM_SIZE 32766
// taken from WinresRc.h
// if not used for any reason
#endif
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static UINT auIDStatusBar[] =
{
ID_SEPARATOR
};
const int ERASE_GROUP_BORDER = 10;
const int FIXUP_CUTOFF = 5;
const int TAB_SPACE = 5;
// the _NULL-Pane
CWnd* ETSLayoutMgr::paneNull = 0;
void ETSLayoutMgr::Layout(CRect& rcClient)
{
// Does nothing, use WITH_LAYOUT in derived class
// see DialogMgr.h
}
ETSLayoutMgr::CPane ETSLayoutMgr::pane( layOrientation orientation, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/,
int sizeBorder /*=nDefaultBorder*/, int sizeExtraBorder /*=0*/,
int sizeSecondary /*=0*/)
{
Pane* pPane = new Pane ( this, orientation, sizeBorder, sizeExtraBorder );
pPane->m_sizeSecondary = sizeSecondary;
pPane->m_modeResize = modeResize;
return CPane(pPane);
}
ETSLayoutMgr::CPane ETSLayoutMgr::paneTab( CTabCtrl* pTab, layOrientation orientation,
ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, int sizeBorder /*=nDefaultBorder*/,
int sizeExtraBorder /*=0*/, int sizeSecondary /*=0*/)
{
Pane* pPane = new PaneTab ( pTab, this, orientation, sizeBorder, sizeExtraBorder );
pPane->m_sizeSecondary = sizeSecondary;
pPane->m_modeResize = modeResize;
return CPane(pPane);
}
ETSLayoutMgr::CPane ETSLayoutMgr::paneCtrl( CWnd* pCtrl, layOrientation orientation,
ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, int sizeBorder /*=nDefaultBorder*/,
int sizeExtraBorder /*=0*/, int sizeTopExtra /*=0*/,
int sizeSecondary /*=0*/)
{
Pane* pPane = new PaneCtrl ( pCtrl, this, orientation, sizeBorder, sizeExtraBorder, sizeTopExtra );
pPane->m_sizeSecondary = sizeSecondary;
pPane->m_modeResize = modeResize;
return CPane(pPane);
}
ETSLayoutMgr::CPane ETSLayoutMgr::paneCtrl( UINT nID, layOrientation orientation, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/,
int sizeBorder /*=nDefaultBorder*/, int sizeExtraBorder /*=0*/,
int sizeTopExtra /*=0*/, int sizeSecondary /*=0*/)
{
Pane* pPane = new PaneCtrl ( nID, this, orientation, sizeBorder, sizeExtraBorder, sizeTopExtra );
pPane->m_sizeSecondary = sizeSecondary;
pPane->m_modeResize = modeResize;
return CPane(pPane);
}
ETSLayoutMgr::CPaneBase ETSLayoutMgr::item(UINT nID, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, int sizeX /*=0*/, int sizeY /*=0*/,
int sizeXMin /*=-1*/, int sizeYMin /*=-1*/)
{
return new PaneItem( nID, this, modeResize, sizeX, sizeY, sizeXMin, sizeYMin);
}
ETSLayoutMgr::CPaneBase ETSLayoutMgr::item(CWnd* pWnd, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/,
int sizeX /*=0*/, int sizeY /*=0*/, int sizeXMin /*=-1*/,
int sizeYMin /*=-1*/)
{
return new PaneItem( pWnd, this, modeResize, sizeX, sizeY, sizeXMin, sizeYMin);
}
ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemFixed(layOrientation orientation, int sizePrimary)
{
CPaneBase p = new PaneItem(paneNull, this, NORESIZE, (orientation==HORIZONTAL)?sizePrimary:0, (orientation==VERTICAL)?sizePrimary:0);
return p;
}
ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemGrowing(layOrientation orientation)
{
return new PaneItem(paneNull, this, (orientation==HORIZONTAL)?ABSOLUTE_VERT:ABSOLUTE_HORZ, 0, 0, 0, 0);
}
ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemSpaceBetween( layOrientation orientation, CWnd* pWndFirst, CWnd* pWndSecond )
{
if( orientation == HORIZONTAL ) {
// I'm interested in horizontal spacing
CRect rLeft, rRight;
pWndFirst->GetWindowRect(&rLeft);
pWndSecond->GetWindowRect(&rRight);
int sizeX = rRight.left - rLeft.right;
if( sizeX < 0 ) {
// compare top to top
sizeX = rRight.left - rLeft.left;
}
else {
sizeX -= 2*nDefaultBorder;
}
return new PaneItem(paneNull, this, ABSOLUTE_HORZ, sizeX, 0);
}
else {
// I'm interested in vertical spacing
CRect rTop, rBot;
pWndFirst->GetWindowRect(&rTop);
pWndSecond->GetWindowRect(&rBot);
int sizeY = rBot.top - rTop.bottom;
if( sizeY < 0 ) {
// compare top to top
sizeY = sizeY = rBot.top - rTop.top;
}
else {
sizeY -= 2*nDefaultBorder;
}
return new PaneItem(paneNull, this, ABSOLUTE_VERT, 0, sizeY);
}
}
ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemSpaceBetween( layOrientation orientation, UINT nIDFirst, UINT nIDSecond )
{
CWnd *pFirst = GetWnd()->GetDlgItem(nIDFirst);
CWnd *pSecond = GetWnd()->GetDlgItem(nIDSecond);
ASSERT( pFirst && pSecond );
return itemSpaceBetween( orientation, pFirst, pSecond );
}
ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemSpaceLike( layOrientation orientation, CWnd* pWnd )
{
CRect rRect;
pWnd->GetWindowRect(&rRect);
if( orientation == HORIZONTAL ) {
// I'm interested in horizontal spacing
return new PaneItem(paneNull, this, ABSOLUTE_HORZ, rRect.Width(), 0);
}
else {
// I'm interested in vertical spacing
return new PaneItem(paneNull, this, ABSOLUTE_VERT, 0, rRect.Height() );
}
}
ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemSpaceLike( layOrientation orientation, UINT nID )
{
CWnd *pWnd = GetWnd()->GetDlgItem(nID);
ASSERT( pWnd );
return itemSpaceLike( orientation, pWnd );
}
ETSLayoutMgr::~ETSLayoutMgr()
{
}
void ETSLayoutMgr::UpdateLayout()
{
if(!m_RootPane)
return;
// Check constraints
CRect rcClient = GetRect();
if( m_pWnd->IsKindOf( RUNTIME_CLASS( CDialog ) ) && !m_pWnd->IsKindOf( RUNTIME_CLASS( CPropertyPage ) ) ) {
CRect rcWindow;
m_pWnd->GetWindowRect(rcWindow);
CRect rcBorder = rcWindow;
rcBorder -= rcClient;
// Min and Max info
int minWidth = m_RootPane->getMinConstrainHorz() + rcBorder.Width() + 2*m_sizeRootBorders.cx;
int minHeight = m_RootPane->getMinConstrainVert() + rcBorder.Height() + 2*m_sizeRootBorders.cy;
int maxWidth = m_RootPane->getMaxConstrainHorz();
if(maxWidth != -1) {
maxWidth += rcBorder.Width() + 2*m_sizeRootBorders.cx;
maxWidth = max(maxWidth, minWidth);
}
int maxHeight = m_RootPane->getMaxConstrainVert();
if(maxHeight != -1) {
maxHeight += rcBorder.Height() + 2*m_sizeRootBorders.cy;
maxHeight = max(maxHeight, minHeight);
}
if(rcWindow.Width() < minWidth)
rcWindow.right = rcWindow.left + minWidth;
if(rcWindow.Height() < minHeight)
rcWindow.bottom = rcWindow.top + minHeight;
if(maxWidth != -1 && rcWindow.Width() > maxWidth)
rcWindow.right = rcWindow.left + maxWidth;
if(maxHeight != -1 && rcWindow.Height() > maxHeight)
rcWindow.bottom = rcWindow.top + maxHeight;
m_pWnd->MoveWindow(rcWindow);
}
// Do the Layout
rcClient = GetRect();
// Add a Border around the rootPane
rcClient.top += m_sizeRootBorders.cy;
rcClient.bottom -= m_sizeRootBorders.cy;
rcClient.left += m_sizeRootBorders.cx;
rcClient.right -= m_sizeRootBorders.cx;
if(GetWnd()->IsWindowVisible()) {
// Avoid ugly artifacts
//GetWnd()->SetRedraw(FALSE);
Layout(rcClient);
//GetWnd()->SetRedraw(TRUE);
}
else
Layout(rcClient);
GetWnd()->Invalidate();
}
bool ETSLayoutMgr::Save(LPCTSTR lpstrRegKey)
{
CRect rcWnd;
if(IsWindow(GetWnd()->m_hWnd))
{
WINDOWPLACEMENT wp;
if(GetWnd()->GetWindowPlacement(&wp))
{
// Make sure we don't pop up
// minimized the next time
if(wp.showCmd != SW_SHOWMAXIMIZED)
wp.showCmd = SW_SHOWNORMAL;
AfxGetApp()->WriteProfileBinary(lpstrRegKey,
"WindowPlacement",
reinterpret_cast<LPBYTE>(&wp), sizeof(wp));
}
}
return true;
}
bool ETSLayoutMgr::Load(LPCTSTR lpstrRegKey)
{
LPBYTE pbtData = 0;
UINT nSize = 0;
if(AfxGetApp()->GetProfileBinary(lpstrRegKey,
"WindowPlacement", &pbtData, &nSize))
{
WINDOWPLACEMENT* pwp =
reinterpret_cast<WINDOWPLACEMENT*>(pbtData);
ASSERT(nSize == sizeof(WINDOWPLACEMENT));
if(nSize == sizeof(WINDOWPLACEMENT))
GetWnd()->SetWindowPlacement(reinterpret_cast<WINDOWPLACEMENT*>(pbtData));
delete [] pbtData;
}
return true;
}
void ETSLayoutMgr::EraseBkgnd(CDC* pDC)
{
CRect rcClient;
GetWnd()->GetClientRect( rcClient );
CRgn rgn;
rgn.CreateRectRgnIndirect(rcClient);
CRgn rgnRect;
rgnRect.CreateRectRgn(0,0,0,0);
CRect rcChild;
CWnd* pWndChild = GetWnd()->GetWindow( GW_CHILD );
TCHAR szClassName[ MAX_PATH ];
while( pWndChild ) {
pWndChild->GetWindowRect(rcChild);
GetWnd()->ScreenToClient( rcChild );
rgnRect.SetRectRgn( rcChild );
::GetClassName( pWndChild->GetSafeHwnd(), szClassName, MAX_PATH );
DWORD dwStyle = pWndChild->GetStyle();
// doesn't make sense for hidden children
if( dwStyle & WS_VISIBLE ) {
if( strcmp(szClassName,"Button")==0 && (dwStyle & BS_GROUPBOX) ) {
// it is a group-box, ignore completly
}
else if( strcmp(szClassName,"SysTabControl32")==0 ) {
// ignore Tab-Control's inside rect
static_cast<CTabCtrl*>(pWndChild)->AdjustRect(FALSE,rcChild);
CRgn rgnContent;
rgnContent.CreateRectRgnIndirect(rcChild);
rgnRect.CombineRgn( &rgnRect, &rgnContent, RGN_DIFF );
rgn.CombineRgn( &rgn, &rgnRect, RGN_DIFF );
}
else {
rgn.CombineRgn( &rgn, &rgnRect, RGN_DIFF );
}
}
pWndChild = pWndChild->GetNextWindow();
}
CBrush backBrush(GetSysColor(COLOR_BTNFACE));
pDC->FillRgn( &rgn, &backBrush );
}
/////////////////////////////////////////////////////////////////////////////
// ETSLayoutMgr::PaneItem implementation
ETSLayoutMgr::PaneItem::PaneItem(CWnd* pWnd, ETSLayoutMgr* pMgr, ETSLayoutMgr::layResizeMode modeResize/*=GREEDY*/
, int sizeX/*=0*/, int sizeY/*=0*/
, int sizeXMin/*=-1*/, int sizeYMin/*=-1*/ ) : PaneBase( pMgr )
{
m_modeResize = modeResize;
m_hwndCtrl = pWnd->GetSafeHwnd();
m_sizeX = 0;
m_sizeY = 0;
m_sizeXMin = sizeXMin;
m_sizeYMin = sizeYMin;
if(!m_hwndCtrl) { // only Dummy!
m_sizeX = sizeX;
m_sizeY = sizeY;
}
else {
CRect rcControl;
::GetWindowRect(m_hwndCtrl, &rcControl);
if(sizeX == 0) {
m_sizeX = rcControl.Width();
}
else {
m_sizeX = sizeX;
}
if( m_sizeXMin == -1 ) {
// do not make smaller than current size
m_sizeXMin = rcControl.Width();
}
if(sizeY == 0) {
m_sizeY = rcControl.Height();
}
else {
m_sizeY = sizeY;
}
if( m_sizeYMin == -1 ) {
// do not make smaller than current size
m_sizeYMin = rcControl.Height();
}
}
}
ETSLayoutMgr::PaneItem::PaneItem( UINT nID, ETSLayoutMgr* pMgr, ETSLayoutMgr::layResizeMode modeResize/*=GREEDY*/
, int sizeX/*=0*/, int sizeY/*=0*/
, int sizeXMin/*=-1*/, int sizeYMin/*=-1*/ ) : PaneBase( pMgr )
{
CWnd* pWnd = pMgr->GetWnd()->GetDlgItem(nID);
m_hwndCtrl = pWnd->GetSafeHwnd();
m_sizeX = 0;
m_sizeY = 0;
m_modeResize = modeResize;
m_sizeXMin = sizeXMin;
m_sizeYMin = sizeYMin;
if(!m_hwndCtrl) { // only Dummy!
m_sizeX = sizeX;
m_sizeY = sizeY;
}
else {
CRect rcControl;
::GetWindowRect(m_hwndCtrl, &rcControl);
if(sizeX == 0) {
m_sizeX = rcControl.Width();
}
else {
m_sizeX = sizeX;
}
if( m_sizeXMin == -1 ) {
// do not make smaller than current size
m_sizeXMin = rcControl.Width();
}
if(sizeY == 0) {
m_sizeY = rcControl.Height();
}
else {
m_sizeY = sizeY;
}
if( m_sizeYMin == -1 ) {
// do not make smaller than current size
m_sizeYMin = rcControl.Height();
}
}
}
int ETSLayoutMgr::PaneItem::getConstrainHorz(int sizeParent)
{
if( m_modeResize & ABSOLUTE_HORZ) {
return m_sizeX;
}
if(m_modeResize & RELATIVE_HORZ) {
return (sizeParent * m_sizeX) / 100;
}
return -1;
}
int ETSLayoutMgr::PaneItem::getConstrainVert(int sizeParent)
{
if(m_modeResize & ABSOLUTE_VERT) {
return m_sizeY;
}
if(m_modeResize & RELATIVE_VERT) {
return (sizeParent * m_sizeY) / 100;
}
return -1;
}
int ETSLayoutMgr::PaneItem::getMinConstrainHorz()
{
if(m_modeResize & ABSOLUTE_HORZ) {
return m_sizeX;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -