⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 etslayout.cpp

📁 PC抄表软件, 用于降数据上载到PC机上, 通过USB传COM口实现.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	return max(nMinConstrain, m_sizeXMin);
}

int ETSLayoutMgr::PaneItem::getMinConstrainVert() 
{
	if(m_modeResize & ABSOLUTE_VERT) {
		return m_sizeY;	
	}
	return max(nMinConstrain, m_sizeYMin);
}

int ETSLayoutMgr::PaneItem::getMaxConstrainHorz() 
{
	if(m_modeResize & ABSOLUTE_HORZ) {
		return m_sizeX;	
	}
	return -1;
}

int ETSLayoutMgr::PaneItem::getMaxConstrainVert() 
{
	if(m_modeResize & ABSOLUTE_VERT) {
		return m_sizeY;	
	}
	return -1;	
}

bool ETSLayoutMgr::PaneItem::resizeTo(CRect& rcNewArea) 
{
	if(m_hwndCtrl) {

		CRect rcWnd;
		::GetWindowRect( m_hwndCtrl, rcWnd );

		if( !(m_modeResize & ALIGN_FILL_HORZ) && m_modeResize & ABSOLUTE_HORZ ) {


			if( (m_modeResize & ALIGN_HCENTER) == ALIGN_HCENTER ) {
				rcNewArea.OffsetRect( (rcNewArea.Width() - rcWnd.Width())/2, 0 ); 
			}
			else if( m_modeResize & ALIGN_RIGHT ) {
				rcNewArea.OffsetRect( rcNewArea.Width() - rcWnd.Width(), 0 ); 
			}

			rcNewArea.right = rcNewArea.left + rcWnd.Width();
		}
		if( !(m_modeResize & ALIGN_FILL_VERT) && m_modeResize & ABSOLUTE_VERT ) {


			if( (m_modeResize & ALIGN_VCENTER) == ALIGN_VCENTER ) {
				rcNewArea.OffsetRect( 0, (rcNewArea.Height()-rcWnd.Height())/2 ); 
			}
			else if( m_modeResize & ALIGN_BOTTOM ) {
				rcNewArea.OffsetRect( 0, rcNewArea.Height() - rcWnd.Height()); 
			}

			rcNewArea.bottom = rcNewArea.top + rcWnd.Height();

		}
		
		::MoveWindow( m_hwndCtrl, rcNewArea.left, rcNewArea.top, rcNewArea.Width(), rcNewArea.Height(), true );
		::RedrawWindow(m_hwndCtrl,0,0, RDW_INVALIDATE | RDW_UPDATENOW ); 

	}
	return true;
}


/////////////////////////////////////////////////////////////////////////////
// ETSLayoutMgr::PaneTab implementation


ETSLayoutMgr::PaneTab::PaneTab( CTabCtrl* pTab, ETSLayoutMgr* pMgr, layOrientation orientation, int sizeBorder /*= nDefaultBorder*/, int sizeExtraBorder /*= 0*/ )
: ETSLayoutMgr::Pane(pMgr, orientation, sizeBorder, sizeExtraBorder) 
{
	ASSERT(pTab);
	m_pTab = pTab;
}

int ETSLayoutMgr::PaneTab::getConstrainHorz(int sizeParent)
{
	CRect rcTab;
	m_pTab->AdjustRect(TRUE, &rcTab);

	if(rcTab.Width() > sizeParent)
		return rcTab.Width();

	return Pane::getConstrainHorz(sizeParent /*- rcTab.Width()*/);
}

int ETSLayoutMgr::PaneTab::getConstrainVert(int sizeParent)
{
	CRect rcTab;
	m_pTab->AdjustRect(TRUE, &rcTab);

	if( m_modeResize & ABSOLUTE_VERT ) {
		return m_sizeSecondary + rcTab.Height();
	}

	if(rcTab.Height() > sizeParent)
		return rcTab.Height();

	return Pane::getConstrainVert(sizeParent /*- rcTab.Height()*/);
}

int ETSLayoutMgr::PaneTab::getMinConstrainHorz()
{
	CRect rcTab(0,0,0,0);
	m_pTab->AdjustRect(TRUE, &rcTab);

	return Pane::getMinConstrainHorz() + rcTab.Width() ;
}

int ETSLayoutMgr::PaneTab::getMinConstrainVert()
{
	CRect rcTab(0,0,0,0);
	m_pTab->AdjustRect(TRUE, &rcTab);

	return Pane::getMinConstrainVert() + rcTab.Height();
}

int ETSLayoutMgr::PaneTab::getMaxConstrainHorz()
{
	CRect rcTab(0,0,0,0);
	m_pTab->AdjustRect(TRUE, &rcTab);

	int paneMax = Pane::getMaxConstrainHorz();
	return (paneMax != -1) ? paneMax + rcTab.Width() : -1;
}

int ETSLayoutMgr::PaneTab::getMaxConstrainVert()
{
	CRect rcTab(0,0,0,0);
	m_pTab->AdjustRect(TRUE, &rcTab);

	int paneMax = Pane::getMaxConstrainVert();
	return (paneMax != -1) ? paneMax + rcTab.Height() : -1;
}

bool ETSLayoutMgr::PaneTab::resizeTo(CRect& rcNewArea)
{
	m_pTab->MoveWindow(rcNewArea);
	m_pTab->AdjustRect(FALSE,rcNewArea);

	return Pane::resizeTo(rcNewArea);
}

/////////////////////////////////////////////////////////////////////////////
// ETSLayoutMgr::PaneCtrl implementation


ETSLayoutMgr::PaneCtrl::PaneCtrl( CWnd* pCtrl, ETSLayoutMgr* pMgr, layOrientation orientation, int sizeBorder /*= nDefaultBorder*/, int sizeExtraBorder /*= 0*/, int sizeTopExtra /*= 0*/ )
: ETSLayoutMgr::Pane(pMgr, orientation, sizeBorder, sizeExtraBorder)
{
	m_sizeTopExtra = sizeTopExtra;

	ASSERT(pCtrl);
	m_hwndCtrl = pCtrl->GetSafeHwnd();
}

ETSLayoutMgr::PaneCtrl::PaneCtrl( UINT nID, ETSLayoutMgr* pMgr, layOrientation orientation, int sizeBorder /*= nDefaultBorder*/, int sizeExtraBorder /*= 0*/, int sizeTopExtra /*= 0*/ )
: ETSLayoutMgr::Pane(pMgr, orientation, sizeBorder, sizeExtraBorder)
{
	m_sizeTopExtra = sizeTopExtra;

	m_hwndCtrl = ::GetDlgItem(pMgr->GetWnd()->GetSafeHwnd(), nID);
	ASSERT(m_hwndCtrl);
}

int ETSLayoutMgr::PaneCtrl::getConstrainHorz(int sizeParent)
{
	return Pane::getConstrainHorz(sizeParent) ;
}

int ETSLayoutMgr::PaneCtrl::getConstrainVert(int sizeParent)
{
	return Pane::getConstrainVert(sizeParent);
}

int ETSLayoutMgr::PaneCtrl::getMinConstrainHorz()
{
	return Pane::getMinConstrainHorz();
}

int ETSLayoutMgr::PaneCtrl::getMinConstrainVert()
{
	return Pane::getMinConstrainVert() + m_sizeTopExtra;
}

int ETSLayoutMgr::PaneCtrl::getMaxConstrainHorz()
{
	int paneMax = Pane::getMaxConstrainHorz();
	return ( paneMax == -1) ? -1 : paneMax ;
}

int ETSLayoutMgr::PaneCtrl::getMaxConstrainVert()
{
	int paneMax = Pane::getMaxConstrainVert();
	return ( paneMax == -1) ? -1 : paneMax + m_sizeTopExtra;
}

bool ETSLayoutMgr::PaneCtrl::resizeTo(CRect& rcNewArea)
{
	::MoveWindow(m_hwndCtrl, rcNewArea.left, rcNewArea.top, rcNewArea.Width(), rcNewArea.Height(), true);
	::RedrawWindow(m_hwndCtrl,0,0, RDW_INVALIDATE | RDW_UPDATENOW |RDW_ERASE); 
	rcNewArea.top	+= m_sizeTopExtra;
	return Pane::resizeTo(rcNewArea);
}

/////////////////////////////////////////////////////////////////////////////
// ETSLayoutMgr::Pane implementation

ETSLayoutMgr::Pane::Pane( ETSLayoutMgr* pMgr, layOrientation orientation, int sizeBorder /* = nDefaultBorder */, int sizeExtraBorder /*= 0*/) 
: PaneBase(pMgr)
{
	m_Orientation	= orientation;
	m_sizeBorder	= sizeBorder;
	m_sizeSecondary	= 0;
	m_modeResize	= 0;
	m_sizeExtraBorder= sizeExtraBorder;
}


ETSLayoutMgr::Pane::~Pane() 
{
}


bool ETSLayoutMgr::Pane::addItem( CWnd* pWnd, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, int sizeX /*=0*/, int sizeY /*=0*/, int sizeXMin /*=0*/, int sizeYMin /*=0*/)
{
	CPaneBase pItem = new PaneItem( pWnd, m_pMgr, modeResize, sizeX, sizeY, sizeXMin, sizeYMin);
	return addPane( pItem );
}

bool ETSLayoutMgr::Pane::addItem( UINT nID, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, int sizeX /*=0*/, int sizeY /*=0*/, int sizeXMin /*=0*/, int sizeYMin /*=0*/)
{
	CPaneBase pItem = new PaneItem( nID, m_pMgr, modeResize, sizeX, sizeY, sizeXMin, sizeYMin);
	return addPane( pItem );
}

bool ETSLayoutMgr::Pane::addItemFixed(int size)
{
	CPaneBase pNewItem = m_pMgr->itemFixed(m_Orientation, size);
	return addPane( pNewItem );
}

bool ETSLayoutMgr::Pane::addItemGrowing()
{
	CPaneBase pNewItem = m_pMgr->itemGrowing(m_Orientation);
	return addPane( pNewItem );
}

bool ETSLayoutMgr::Pane::addItemSpaceBetween( CWnd* pWndFirst, CWnd* pWndSecond )
{
	CPaneBase pNewItem = m_pMgr->itemSpaceBetween(m_Orientation, pWndFirst, pWndSecond);
	return addPane( pNewItem );
}

bool ETSLayoutMgr::Pane::addItemSpaceBetween( UINT nIDFirst, UINT nIDSecond )
{
	CPaneBase pNewItem = m_pMgr->itemSpaceBetween(m_Orientation, nIDFirst, nIDSecond);
	return addPane( pNewItem );
}

bool ETSLayoutMgr::Pane::addItemSpaceLike( CWnd* pWnd )
{
	CPaneBase pNewItem = m_pMgr->itemSpaceLike(m_Orientation, pWnd);
	return addPane( pNewItem );
}

bool ETSLayoutMgr::Pane::addItemSpaceLike( UINT nID )
{
	CPaneBase pNewItem = m_pMgr->itemSpaceLike(m_Orientation, nID);
	return addPane( pNewItem );
}

bool ETSLayoutMgr::Pane::addPane( CPane pSubpane, ETSLayoutMgr::layResizeMode modeResize, int sizeSecondary /* = 0 */) 
{
	if( pSubpane->getOrientation() == m_Orientation)
	{
		// wrap in subpane of opposite orientation
		CPane pPaneWrap = new Pane(m_pMgr, m_Orientation==HORIZONTAL?VERTICAL:HORIZONTAL,0,0);
		pPaneWrap->addPane( pSubpane  );

		addPane( pPaneWrap, modeResize, sizeSecondary );
	}
	else
	{
		pSubpane->m_modeResize = modeResize;

		if(m_Orientation==HORIZONTAL && (modeResize & ABSOLUTE_HORZ) ) {
			if(sizeSecondary == 0) {
				pSubpane->m_sizeSecondary = pSubpane->getMinConstrainHorz();
			}
		}
		else if(m_Orientation==HORIZONTAL && (modeResize & RELATIVE_HORZ) ) {
			pSubpane->m_sizeSecondary = max( nMinConstrain, sizeSecondary);
		}
		else if(m_Orientation==VERTICAL && (modeResize & ABSOLUTE_VERT) ) {
			if(sizeSecondary == 0) {
				pSubpane->m_sizeSecondary = pSubpane->getMinConstrainVert();
			}
		}
		else if(m_Orientation==VERTICAL && (modeResize & RELATIVE_VERT) ) {
			pSubpane->m_sizeSecondary = max( nMinConstrain, sizeSecondary);
		}

		m_paneItems.Add(pSubpane);
	}

	return true;
}

bool ETSLayoutMgr::Pane::addPane( CPaneBase pItem ) 
{
	m_paneItems.Add(pItem);
	return true;
}

int ETSLayoutMgr::Pane::getConstrainHorz(int sizeParent) 
{
	ASSERT( m_Orientation == VERTICAL);

	if( m_modeResize & RELATIVE_HORZ ) {
		return (sizeParent * m_sizeSecondary) / 100;
	}
	else if( m_modeResize & ABSOLUTE_HORZ ){
		return m_sizeSecondary;
	}
	else
		return 0;
}


int ETSLayoutMgr::Pane::getConstrainVert(int sizeParent) 
{
	ASSERT( m_Orientation == HORIZONTAL);

	if( m_modeResize & RELATIVE_VERT ) {
		return (sizeParent * m_sizeSecondary) / 100;
	}
	else if( m_modeResize & ABSOLUTE_VERT ) {
		return m_sizeSecondary;
	}
	else {
		return 0;
	}
}

int ETSLayoutMgr::Pane::getMaxConstrainHorz() 
{
	if(m_Orientation == HORIZONTAL) {
		int nMaxConstr = -1;
		for(int i=0; i<m_paneItems.GetSize(); ++i) {
			CPaneBase pItem = m_paneItems[i];

			int nConstrain = pItem->getMaxConstrainHorz();
			if(nConstrain == -1)
				return -1;

			nMaxConstr += nConstrain;
		}
		return (nMaxConstr == -1) ? -1 : nMaxConstr + (m_paneItems.GetUpperBound()*m_sizeBorder) + 2*m_sizeExtraBorder;
	}
	else if( m_modeResize & ABSOLUTE_HORZ && m_sizeSecondary!=0) {
		return m_sizeSecondary; // + 2*m_sizeExtraBorder;
	}
	else {
		int nMaxConstr = -1;
		for(int i=0; i<m_paneItems.GetSize(); ++i) {
			CPaneBase pItem = m_paneItems[i];

			int nConstrain = pItem->getMaxConstrainHorz();

			if( nConstrain == -1)
				return -1;
			else
				nMaxConstr = max(nMaxConstr, nConstrain);

		}
		return (nMaxConstr == -1) ? -1 : nMaxConstr + 2*m_sizeExtraBorder;
	}
}

int ETSLayoutMgr::Pane::getMaxConstrainVert() 
{
	if(m_Orientation == VERTICAL) {
		int nMaxConstr = -1;
		for(int i=0; i<m_paneItems.GetSize(); ++i) {
			CPaneBase pItem = m_paneItems[i];

			int nConstrain = pItem->getMaxConstrainVert();
			if(nConstrain == -1)
				return -1;

			nMaxConstr += nConstrain;
		}
		return (nMaxConstr == -1) ? -1 : nMaxConstr + (m_paneItems.GetUpperBound()*m_sizeBorder) + 2*m_sizeExtraBorder;
	}
	else if( m_modeResize & ABSOLUTE_VERT && m_sizeSecondary!=0) {
		return m_sizeSecondary; // + 2*m_sizeExtraBorder;
	}
	else {
		int nMaxConstr = -1;
		for(int i=0; i<m_paneItems.GetSize(); ++i) {
			CPaneBase pItem = m_paneItems[i];

			int nConstrain = pItem->getMaxConstrainVert();

			if( nConstrain == -1)
				return -1;
			else
				nMaxConstr = max(nMaxConstr, nConstrain);

		}
		return (nMaxConstr == -1) ? -1 : nMaxConstr + 2*m_sizeExtraBorder;
	}
}

int ETSLayoutMgr::Pane::getMinConstrainHorz() 
{
	if(m_Orientation == HORIZONTAL) {
		int nMaxConstr = 0;
		for(int i=0; i<m_paneItems.GetSize(); ++i) {
			CPaneBase pItem = m_paneItems[i];
			nMaxConstr += pItem->getMinConstrainHorz();
		}
		return nMaxConstr + (m_paneItems.GetUpperBound()*m_sizeBorder) + 2*m_sizeExtraBorder;
	}
	else if( m_modeResize & ABSOLUTE_HORZ && m_sizeSecondary!=0) {
		return m_sizeSecondary; // + 2*m_sizeExtraBorder;
	}
	else {
		int nMaxConstr = 0;
		for(int i=0; i<m_paneItems.GetSize(); ++i) {
			CPaneBase pItem = m_paneItems[i];
			int nConstrain = pItem->getMinConstrainHorz();
			nMaxConstr = max(nMaxConstr, nConstrain);
		}
		return nMaxConstr + 2*m_sizeExtraBorder;
	}
}

int ETSLayoutMgr::Pane::getMinConstrainVert() 
{
	if(m_Orientation == VERTICAL) {
		int nMaxConstr = 0;
		for(int i=0; i<m_paneItems.GetSize(); ++i) {
			CPaneBase pItem = m_paneItems[i];
			nMaxConstr += pItem->getMinConstrainVert();
		}
		return nMaxConstr + (m_paneItems.GetUpperBound()*m_sizeBorder) + 2*m_sizeExtraBorder;
	}
	else if( m_modeResize & ABSOLUTE_VERT && m_sizeSecondary!=0) {
		return m_sizeSecondary; // + 2*m_sizeExtraBorder;
	}
	else {
		int nMaxConstr = 0;
		for(int i=0; i<m_paneItems.GetSize(); ++i) {
			CPaneBase pItem = m_paneItems[i];
			int nConstrain = pItem->getMinConstrainVert();
			nMaxConstr = max(nMaxConstr, nConstrain);
		}
		return nMaxConstr + 2*m_sizeExtraBorder;
	}
}


int ETSLayoutMgr::Pane::resizeToAbsolute(int& availSpace, CArray<int,int>& sizePrimary, 
										 CArray<int,int>& sizeMin, CArray<int,int>& sizeMax)
{
	// count all greedy items as returnvalue
	int nGreedy = 0;

	// first, subtract all absoulute items from available space
	for(int i=0; i<m_paneItems.GetSize(); ++i) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -