CSize CCJSizeDockBar::CalcDynamicLayout(int nLength, DWORD nMode) { int ActualSize = 0; for(int i=0;i<= m_arrBars.GetUpperBound();++i) { CCJControlBar *pBar = (CCJControlBar *)GetDockedControlBar(i); if (pBar != NULL && pBar->IsVisible()) { ActualSize = m_iActualSize; break; } } int cx,cy; if (nMode & LM_VERTDOCK) { cx = ActualSize ; cy = 32767; } if (nMode & LM_HORZDOCK) { cx= 32767; cy = ActualSize; } CalcSizeBarLayout(); return CSize(cx,cy); }
void CExtDockBar::_ContextMenuTrack() { // find any control bar CControlBar * pBar = NULL; for( int nPos = 0; nPos < m_arrBars.GetSize(); nPos++ ) { pBar = GetDockedControlBar(nPos); if( pBar != NULL ) { ASSERT_VALID( pBar ); break; } } if( pBar == NULL ) return; CFrameWnd * pFrame = _GetDockingFrameImpl(); CPoint point; VERIFY( ::GetCursorPos(&point) ); CExtPopupMenuWnd * pPopup = new CExtPopupMenuWnd; VERIFY( pPopup->CreatePopupMenu( pBar->GetOwner()->GetSafeHwnd() ) ); _ContextMenuBuild( pFrame, pPopup ); pPopup->TrackPopupMenu( 0, point.x,point.y, pBar->GetOwner()->GetSafeHwnd() // pFrame->GetSafeHwnd() ); }
void CCJSizeDockBar::Maximize(CCJControlBar* pBar) { int iExt=0; CRect rectAvail; GetClientRect(rectAvail); for (int i=0; i<m_arrBars.GetSize(); ++i) { CCJControlBar *pBarDock = (CCJControlBar *)GetDockedControlBar(i); if (pBarDock && pBarDock->IsVisible() && pBarDock != pBar) { pBarDock->Minimize(); iExt += pBarDock->GetMinExt(); } } if (pBar->IsLeftDocked() || pBar->IsRightDocked()) { iExt = rectAvail.Height()-iExt; } if (pBar->IsTopDocked() || pBar->IsBottomDocked()) { iExt = rectAvail.Width()-iExt; } pBar->Maximize(iExt); CalcSizeBarLayout(); }
void CCJSizeDockBar::Normalize(CCJControlBar *) { for( int i=0; i<m_arrBars.GetSize(); ++i) { CCJControlBar *pBarDock = (CCJControlBar*)GetDockedControlBar(i); if (pBarDock && pBarDock->IsVisible()) pBarDock->Normalize(); } CalcSizeBarLayout(); }
BOOL CCJSizeDockBar::IsLastControlBar(int index) { for( int i=index; i<m_arrBars.GetSize(); ++i) { CCJControlBar *pOther = (CCJControlBar *)GetDockedControlBar(i); if (pOther != NULL && pOther->IsVisible()) { return FALSE; } } return TRUE; }
CSize CGuiDocBarExten::CalcFixedLayout(BOOL bStretch, BOOL bHorz) { ASSERT_VALID(this); CSize sizeFixed = CControlBar::CalcFixedLayout(bStretch, bHorz); // get max size CSize sizeMax; if (!m_rectLayout.IsRectEmpty()) { CRect rect = m_rectLayout; CalcInsideRect(rect, bHorz); sizeMax = rect.Size(); } else { CRect rectFrame; CFrameWnd* pFrame = GetParentFrame(); pFrame->GetClientRect(&rectFrame); sizeMax = rectFrame.Size(); } // prepare for layout AFX_SIZEPARENTPARAMS layout; layout.hDWP = m_bLayoutQuery ? NULL : ::BeginDeferWindowPos(m_arrBars.GetSize()); int cxBorder = 2, cyBorder = 2; CPoint pt(-cxBorder, -cyBorder); int nWidth = 0; BOOL bWrapped = FALSE; // layout all the control bars for (int nPos = 0; nPos < m_arrBars.GetSize(); nPos++) { CControlBar* pBar = GetDockedControlBar(nPos); void* pVoid = m_arrBars[nPos]; if (pBar != NULL) { if(pBar->IsKindOf(RUNTIME_CLASS(CGuiToolBarWnd)) || pBar->IsKindOf(RUNTIME_CLASS(CMenuBar)) ) cxBorder = cyBorder = 0; else cxBorder = cyBorder = 2; if (pBar->IsVisible()) { // get ideal rect for bar DWORD dwMode = 0; if ((pBar->m_dwStyle & CBRS_SIZE_DYNAMIC) && (pBar->m_dwStyle & CBRS_FLOATING)) dwMode |= LM_HORZ | LM_MRUWIDTH; else if (pBar->m_dwStyle & CBRS_ORIENT_HORZ) dwMode |= LM_HORZ | LM_HORZDOCK; else dwMode |= LM_VERTDOCK; CSize sizeBar = pBar->CalcDynamicLayout(-1, dwMode); CRect rect(pt, sizeBar); // get current rect for bar CRect rectBar; pBar->GetWindowRect(&rectBar); ScreenToClient(&rectBar); if (bHorz) { // Offset Calculated Rect out to Actual if (rectBar.left > rect.left && !m_bFloating) rect.OffsetRect(rectBar.left - rect.left, 0); // If ControlBar goes off the right, then right justify if (rect.right > sizeMax.cx && !m_bFloating) { int x = rect.Width() - cxBorder; x = max(sizeMax.cx - x, pt.x); rect.OffsetRect(x - rect.left, 0); } // If ControlBar has been wrapped, then left justify if (bWrapped) { bWrapped = FALSE; rect.OffsetRect(-(rect.left + cxBorder), 0); } // If ControlBar is completely invisible, then wrap it else if ((rect.left >= (sizeMax.cx - cxBorder)) && (nPos > 0) && (m_arrBars[nPos - 1] != NULL)) { m_arrBars.InsertAt(nPos, (CObject*)NULL); pBar = NULL; pVoid = NULL; bWrapped = TRUE; } if (!bWrapped) { if (rect != rectBar) { if (!m_bLayoutQuery && !(pBar->m_dwStyle & CBRS_FLOATING)) { pBar->m_pDockContext->m_rectMRUDockPos = rect; } AfxRepositionWindow(&layout, pBar->m_hWnd, &rect); } pt.x = rect.left + sizeBar.cx - cxBorder; nWidth = max(nWidth, sizeBar.cy); } } else { // Offset Calculated Rect out to Actual if (rectBar.top > rect.top && !m_bFloating) rect.OffsetRect(0, rectBar.top - rect.top); // If ControlBar goes off the bottom, then bottom justify if (rect.bottom > sizeMax.cy && !m_bFloating) { int y = rect.Height() - cyBorder; y = max(sizeMax.cy - y, pt.y); rect.OffsetRect(0, y - rect.top); } // If ControlBar has been wrapped, then top justify if (bWrapped) { bWrapped = FALSE; rect.OffsetRect(0, -(rect.top + cyBorder)); } // If ControlBar is completely invisible, then wrap it else if ((rect.top >= (sizeMax.cy - cyBorder)) && (nPos > 0) && (m_arrBars[nPos - 1] != NULL)) { m_arrBars.InsertAt(nPos, (CObject*)NULL); pBar = NULL; pVoid = NULL; bWrapped = TRUE; } if (!bWrapped) { if (rect != rectBar) { if (!m_bLayoutQuery && !(pBar->m_dwStyle & CBRS_FLOATING)) { pBar->m_pDockContext->m_rectMRUDockPos = rect; } AfxRepositionWindow(&layout, pBar->m_hWnd, &rect); } pt.y = rect.top + sizeBar.cy - cyBorder; nWidth = max(nWidth, sizeBar.cx); } } } if (!bWrapped) { // handle any delay/show hide for the bar pBar->RecalcDelayShow(&layout); } } if (pBar == NULL && pVoid == NULL && nWidth != 0) { // end of row because pBar == NULL if (bHorz) { pt.y += nWidth - cyBorder; sizeFixed.cx = max(sizeFixed.cx, pt.x); sizeFixed.cy = max(sizeFixed.cy, pt.y); pt.x = -cxBorder; } else { pt.x += nWidth - cxBorder; sizeFixed.cx = max(sizeFixed.cx, pt.x); sizeFixed.cy = max(sizeFixed.cy, pt.y); pt.y = -cyBorder; } nWidth = 0; } } if (!m_bLayoutQuery) { // move and resize all the windows at once! if (layout.hDWP == NULL || !::EndDeferWindowPos(layout.hDWP)) TRACE0("Warning: DeferWindowPos failed - low system resources.\n"); } // adjust size for borders on the dock bar itself CRect rect; rect.SetRectEmpty(); CalcInsideRect(rect, bHorz); if ((!bStretch || !bHorz) && sizeFixed.cx != 0) sizeFixed.cx += -rect.right + rect.left; if ((!bStretch || bHorz) && sizeFixed.cy != 0) sizeFixed.cy += -rect.bottom + rect.top; return sizeFixed; }
CSize CExtDockBar::CalcFixedLayout( BOOL bStretch, BOOL bHorz ) { // based on MFC's source of // CDockBar::CalcFixedLayout() ASSERT_VALID(this); CSize sizeFixed = CControlBar::CalcFixedLayout( bStretch, bHorz ); // get max size CSize sizeMax; if( !m_rectLayout.IsRectEmpty() ) sizeMax = m_rectLayout.Size(); else { CFrameWnd * pFrame = GetParentFrame(); CRect rcFrameWindow; pFrame->GetClientRect( &rcFrameWindow ); sizeMax = rcFrameWindow.Size(); } // prepare for layout AFX_SIZEPARENTPARAMS layout; layout.hDWP = m_bLayoutQuery ? NULL : ::BeginDeferWindowPos( m_arrBars.GetSize() ); CPoint pt( 0, 0 ); int nWidth = 0; BOOL bWrapped = FALSE; for( int nPos = 0; nPos < m_arrBars.GetSize(); nPos++ ) { // layout all the control bars CControlBar * pBar = GetDockedControlBar(nPos); void * pVoid = m_arrBars[nPos]; if( pBar != NULL ) { CRect rcBarWin, rcBarClient; pBar->GetWindowRect( &rcBarWin ); pBar->ScreenToClient( & rcBarWin ); pBar->GetClientRect( &rcBarClient ); CSize sizeBarMin = rcBarWin.Size() - rcBarClient.Size(); if( pBar->IsKindOf(RUNTIME_CLASS(CExtControlBar)) ) { if( ! ((CExtControlBar*)pBar)->m_bFixedMode ) { sizeBarMin = CSize( ((CExtControlBar *)pBar)->_CalcDesiredMinHW(), ((CExtControlBar *)pBar)->_CalcDesiredMinVH() ); } // if( ! ((CExtControlBar*)pBar)->m_bFixedMode ) } // if( pBar->IsKindOf(RUNTIME_CLASS(CExtControlBar)) ) if( pBar->IsVisible() ) { // get ideal rect for bar DWORD dwMode = 0; if( (pBar->m_dwStyle & CBRS_SIZE_DYNAMIC) && (pBar->m_dwStyle & CBRS_FLOATING) ) dwMode |= LM_HORZ | LM_MRUWIDTH; else if(pBar->m_dwStyle & CBRS_ORIENT_HORZ) dwMode |= LM_HORZ | LM_HORZDOCK; else dwMode |= LM_VERTDOCK; CSize sizeBar = pBar->CalcDynamicLayout(-1, dwMode); BOOL bIsMenuBar = FALSE; if( pBar->IsKindOf(RUNTIME_CLASS(CExtMenuControlBar)) ) { bIsMenuBar = TRUE; if(dwMode & LM_HORZDOCK) sizeBar.cx = sizeMax.cx; else if(dwMode & LM_VERTDOCK) sizeBar.cy = sizeMax.cy; } CRect rc(pt, sizeBar); // get current rect for bar CRect rcBar; pBar->GetWindowRect( &rcBar ); ScreenToClient( &rcBar ); BOOL bMenuIsCutted = FALSE; if( bHorz ) { // Offset Calculated Rect out to Actual if( rcBar.left > rc.left && !m_bFloating ) rc.OffsetRect( rcBar.left - rc.left, 0 ); // If ControlBar goes off the right, then right justify if( rc.right > sizeMax.cx && !m_bFloating ) { int x = rc.Width(); x = max(sizeMax.cx - x, pt.x); rc.OffsetRect( x - rc.left, 0 ); if( bIsMenuBar ) bMenuIsCutted = TRUE; if( rc.right > sizeMax.cx ) rc.right -= rc.right - sizeMax.cx; } // If ControlBar has been wrapped, then left justify if( bWrapped ) { bWrapped = FALSE; rc.OffsetRect( -rc.left, 0 ); } // If ControlBar is completely invisible, then wrap it else if( rc.Width() < sizeBarMin.cx || (rc.left >= sizeMax.cx || bMenuIsCutted ) && (nPos > 0) && (m_arrBars[nPos - 1] != NULL) ) { if( !pBar->IsKindOf(RUNTIME_CLASS(CExtControlBar)) || ( pBar->IsKindOf(RUNTIME_CLASS(CExtControlBar)) && ((CExtControlBar*)pBar)->m_bFixedMode ) ) { m_arrBars.InsertAt( nPos, (CObject*)NULL ); pBar = NULL; pVoid = NULL; bWrapped = TRUE; } } if( !bWrapped ) { if(rc != rcBar) { if( !m_bLayoutQuery && !(pBar->m_dwStyle & CBRS_FLOATING) ) pBar->m_pDockContext-> m_rectMRUDockPos = rc; AfxRepositionWindow( &layout, pBar->m_hWnd, &rc ); } pt.x = rc.left + sizeBar.cx; nWidth = max(nWidth, sizeBar.cy); } // if( !bWrapped ) } // if( bHorz ) else { // Offset Calculated Rect out to Actual if( rcBar.top > rc.top && !m_bFloating ) rc.OffsetRect( 0, rcBar.top - rc.top ); // If ControlBar goes off the bottom, then bottom justify if( rc.bottom > sizeMax.cy && !m_bFloating ) { int y = rc.Height(); y = max(sizeMax.cy - y, pt.y); rc.OffsetRect( 0, y - rc.top ); if(bIsMenuBar) bMenuIsCutted = TRUE; if( rc.bottom > sizeMax.cy ) rc.bottom -= rc.bottom - sizeMax.cy; } // If ControlBar has been wrapped, then top justify if( bWrapped ) { bWrapped = FALSE; rc.OffsetRect( 0, -rc.top ); } // If ControlBar is completely invisible, then wrap it else if( rc.Height() < sizeBarMin.cy || (rc.top >= sizeMax.cy || bMenuIsCutted ) && (nPos > 0) && (m_arrBars[nPos - 1] != NULL) ) { if( !pBar->IsKindOf(RUNTIME_CLASS(CExtControlBar)) || ( pBar->IsKindOf(RUNTIME_CLASS(CExtControlBar)) && ((CExtControlBar*)pBar)->m_bFixedMode ) ) { m_arrBars.InsertAt( nPos, (CObject*)NULL ); pBar = NULL; pVoid = NULL; bWrapped = TRUE; } } if( !bWrapped ) { if(rc != rcBar) { if( !m_bLayoutQuery && !(pBar->m_dwStyle & CBRS_FLOATING) && pBar->m_pDockContext != NULL ) pBar->m_pDockContext-> m_rectMRUDockPos = rc; AfxRepositionWindow( &layout, pBar->m_hWnd, &rc ); } pt.y = rc.top + sizeBar.cy; nWidth = max(nWidth, sizeBar.cx); } // if( !bWrapped ) } // else from if( bHorz ) } // if( pBar->IsVisible() ) if( !bWrapped ) // handle any delay/show hide for the bar pBar->RecalcDelayShow( &layout ); } // if( pBar != NULL ) else { if( g_bExtendedRepositioning ) { // try to remove wrapping: // are we have free space in the end of previouse row? if( nPos > 0 && nPos != m_arrBars.GetSize()-1 ) { int nPosPrev = nPos-1; CControlBar * pPrevBar = NULL; do { pPrevBar = GetDockedControlBar(nPosPrev--); if( pPrevBar != NULL && pPrevBar->IsVisible() && (!pPrevBar->IsFloating()) ) { if( pPrevBar->IsKindOf(RUNTIME_CLASS(CExtMenuControlBar)) ) { pPrevBar = NULL; break; } // get ideal rect for prev bar DWORD dwMode = 0; if( (pPrevBar->m_dwStyle & CBRS_SIZE_DYNAMIC) && (pPrevBar->m_dwStyle & CBRS_FLOATING) ) dwMode |= LM_HORZ | LM_MRUWIDTH; else if(pPrevBar->m_dwStyle & CBRS_ORIENT_HORZ) dwMode |= LM_HORZ | LM_HORZDOCK; else dwMode |= LM_VERTDOCK; CSize sizePrevBar = pPrevBar->CalcDynamicLayout(-1, dwMode); CRect rcPrev(pt, sizePrevBar); if( bHorz ) { if( rcPrev.right > sizeMax.cx && !m_bFloating ) pPrevBar = NULL; } else { if( rcPrev.bottom > sizeMax.cy && !m_bFloating ) pPrevBar = NULL; } if( pPrevBar != NULL ) break; } pPrevBar = NULL; } while( nPosPrev >= 0 ); if( pPrevBar != NULL ) { m_arrBars.RemoveAt(nPos); nPos--; continue; } } // if( nPos > 0 && nPos != m_arrBars.GetSize()-1 ) } // if( g_bExtendedRepositioning ) } // else from if( pBar != NULL ) if( pBar == NULL && pVoid == NULL && nWidth != 0 ) { // end of row because pBar == NULL if( bHorz ) { pt.y += nWidth; sizeFixed.cx = max(sizeFixed.cx, pt.x); sizeFixed.cy = max(sizeFixed.cy, pt.y); pt.x = 0; sizeFixed.cy--; } else { pt.x += nWidth; sizeFixed.cx = max(sizeFixed.cx, pt.x); sizeFixed.cy = max(sizeFixed.cy, pt.y); pt.y = 0; sizeFixed.cx--; } nWidth = 0; } } // layout all the control bars if( !m_bLayoutQuery ) { VERIFY( layout.hDWP != NULL ); if( layout.hDWP != NULL ) { VERIFY( ::EndDeferWindowPos(layout.hDWP) ); } } // if( !m_bLayoutQuery ) // adjust size for borders on the dock bar itself CRect rc( 0, 0, 0, 0 ); CalcInsideRect(rc, bHorz); if( (!bStretch || !bHorz) && sizeFixed.cx != 0 ) sizeFixed.cx += -rc.right + rc.left + g_bControlBarFixSizePixel ? 1 : 0; if( (!bStretch || bHorz) && sizeFixed.cy != 0 ) sizeFixed.cy += -rc.bottom + rc.top + g_bControlBarFixSizePixel ? 1 : 0; return sizeFixed; }
void CCJSizeDockBar::CalcSizeBarLayout() { HDWP hDWP = ::BeginDeferWindowPos(m_arrBars.GetSize()); CRect rectAvail; GetClientRect(&rectAvail); int nCount = 0; int lastLeft = 0; int lastRight = 0; int lastBottom = 0; int lastTop = 0; for( int i=0; i<m_arrBars.GetSize(); ++i) { CCJControlBar *pBar = (CCJControlBar *)GetDockedControlBar(i); if (pBar != NULL && pBar->IsVisible()) { CRect rectBar; ++nCount; pBar->GetWindowRect(&rectBar); pBar->m_bUnique = FALSE; ScreenToClient(&rectBar); CSize sizeIdeal = pBar->CalcDynamicLayout(-1,0); if( pBar->IsLeftDocked() ) { rectBar.top = lastLeft; rectBar.left = 0; rectBar.right = rectAvail.Width(); rectBar.bottom = rectBar.top + sizeIdeal.cy; if (rectBar.top>lastLeft) rectBar.top = lastLeft; lastLeft = rectBar.bottom; if (IsLastControlBar(i+1)) { rectBar.bottom = rectAvail.bottom; pBar->m_bToFit = TRUE; if( nCount == 1 ) pBar->m_bUnique = TRUE; } else pBar->m_bToFit = FALSE; } else if (pBar->IsTopDocked()) { rectBar.left = lastTop; rectBar.top = 0; rectBar.bottom = rectAvail.Height(); rectBar.right = rectBar.left + sizeIdeal.cx; if( rectBar.left>lastTop ) rectBar.left = lastTop; lastTop = rectBar.right; if (IsLastControlBar(i+1)) { rectBar.right = rectAvail.right; pBar->m_bToFit = TRUE; if (nCount == 1) pBar->m_bUnique = TRUE; } else pBar->m_bToFit = FALSE; } else if (pBar->IsRightDocked()) { rectBar.top = lastRight; rectBar.left = 0; rectBar.right = rectAvail.Width(); rectBar.bottom = rectBar.top + sizeIdeal.cy; if (rectBar.top>lastRight) rectBar.top = lastRight; lastRight = rectBar.bottom; if (IsLastControlBar(i+1)) { rectBar.bottom = rectAvail.bottom; pBar->m_bToFit = TRUE; if (nCount == 1) pBar->m_bUnique = TRUE; } else pBar->m_bToFit = FALSE; } else if (pBar->IsBottomDocked()) { rectBar.left = lastBottom; rectBar.top = 0; rectBar.bottom = rectAvail.Height(); rectBar.right = rectBar.left + sizeIdeal.cx; if( rectBar.left>lastBottom ) rectBar.left = lastBottom; lastBottom = rectBar.right; if (IsLastControlBar(i+1)) { rectBar.right = rectAvail.right; pBar->m_bToFit = TRUE; if( nCount == 1 ) pBar->m_bUnique = TRUE; } else pBar->m_bToFit = FALSE; } pBar->SetWindowPos(NULL,rectBar.left,rectBar.top,rectBar.Width(),rectBar.Height(),SWP_NOZORDER); // pBar->Invalidate(); } } ::EndDeferWindowPos(hDWP); }
CCJControlBar* CCJSizeDockBar::GetDockedSizeBar(int nPos) { return (CCJControlBar*)GetDockedControlBar(nPos); }