// repositions client area of specified window // assumes everything has WS_BORDER or is inset like it does // (includes scroll bars) static void AFXAPI DeferClientPos(AFX_SIZEPARENTPARAMS* lpLayout, CWnd* pWnd, int x, int y, int cx, int cy, BOOL bScrollBar) { ASSERT(pWnd != NULL); ASSERT(pWnd->m_hWnd != NULL); if (bScrollBar) { // if there is enough room, draw scroll bar without border // if there is not enough room, set the WS_BORDER bit so that // we will at least get a proper border drawn BOOL bNeedBorder = (cx <= CX_BORDER || cy <= CY_BORDER); pWnd->ModifyStyle(bNeedBorder ? 0 : WS_BORDER, bNeedBorder ? WS_BORDER : 0); } CRect rect(x, y, x+cx, y+cy); // adjust for border size (even if zero client size) // adjust for 3d border (splitter windows have implied border) if ((pWnd->GetExStyle() & WS_EX_CLIENTEDGE) || pWnd->IsKindOf(RUNTIME_CLASS(CSplitterWnd))) rect.InflateRect(CX_BORDER*2, CY_BORDER*2); // first check if the new rectangle is the same as the current CRect rectOld; pWnd->GetWindowRect(rectOld); pWnd->GetParent()->ScreenToClient(&rectOld); if (rect != rectOld) AfxRepositionWindow(lpLayout, pWnd->m_hWnd, rect); }
LRESULT CControlBar::OnSizeParent( WPARAM wParam, LPARAM lParam ) /***************************************************************/ { UNUSED_ALWAYS( wParam ); if( GetStyle() & WS_VISIBLE ) { AFX_SIZEPARENTPARAMS *pSPP = (AFX_SIZEPARENTPARAMS *)lParam; ASSERT( pSPP != NULL ); DWORD nMode = 0L; if( m_dwStyle & CBRS_ORIENT_HORZ ) { nMode |= LM_HORZ; } if( pSPP->bStretch ) { nMode |= LM_STRETCH; } CSize size = CalcDynamicLayout( -1, nMode ); CRect rect; if( m_dwStyle & CBRS_ALIGN_LEFT ) { rect.left = pSPP->rect.left; rect.top = pSPP->rect.top; rect.right = pSPP->rect.left + size.cx; rect.bottom = min( pSPP->rect.top + size.cy, pSPP->rect.bottom ); pSPP->rect.left += size.cx; pSPP->sizeTotal.cx += size.cx; pSPP->sizeTotal.cy = max( pSPP->sizeTotal.cy, size.cy ); } else if( m_dwStyle & CBRS_ALIGN_RIGHT ) { rect.left = pSPP->rect.right - size.cx; rect.top = pSPP->rect.top; rect.right = pSPP->rect.right; rect.bottom = min( pSPP->rect.top + size.cy, pSPP->rect.bottom ); pSPP->rect.right -= size.cx; pSPP->sizeTotal.cx += size.cx; pSPP->sizeTotal.cy = max( pSPP->sizeTotal.cy, size.cy ); } else if( m_dwStyle & CBRS_ALIGN_BOTTOM ) { rect.left = pSPP->rect.left; rect.top = pSPP->rect.bottom - size.cy; rect.right = min( pSPP->rect.left + size.cx, pSPP->rect.right ); rect.bottom = pSPP->rect.bottom; pSPP->rect.bottom -= size.cy; pSPP->sizeTotal.cx = max( pSPP->sizeTotal.cx, size.cx ); pSPP->sizeTotal.cy += size.cy; } else { rect.left = pSPP->rect.left; rect.top = pSPP->rect.top; rect.right = min( pSPP->rect.left + size.cx, pSPP->rect.right ); rect.bottom = pSPP->rect.top + size.cy; pSPP->rect.top += size.cy; pSPP->sizeTotal.cx = max( pSPP->sizeTotal.cx, size.cx ); pSPP->sizeTotal.cy += size.cy; } AfxRepositionWindow( pSPP, m_hWnd, &rect ); } return( 0L ); }
void CXTPPropertyPageControlNavigator::SizeToPage(AFX_SIZEPARENTPARAMS* pLayout, CSize szClient, CRect& rcPage) { CSize szList(m_szControl.cx, szClient.cy - m_rcNavigatorMargin.top - m_rcNavigatorMargin.bottom); CSize szPage(szClient.cx - szList.cx - 2 * m_rcNavigatorMargin.left - m_rcNavigatorMargin.right, szClient.cy - m_rcNavigatorMargin.top - m_rcNavigatorMargin.bottom); rcPage = CRect(CPoint(szList.cx + 2 * m_rcNavigatorMargin.left, m_rcNavigatorMargin.top), szPage); AfxRepositionWindow(pLayout, GetSafeHwnd(), CRect(m_rcNavigatorMargin.TopLeft(), szList)); }
void CXTPPropertyPageControlNavigator::PageToSize(AFX_SIZEPARENTPARAMS* pLayout, CSize szPage, CRect& rcPage, CSize& szClient) { CSize szList(m_szControl); szList.cy = max(szList.cy, szPage.cy); szClient = CSize(szList.cx + 2 * m_rcNavigatorMargin.left + m_rcNavigatorMargin.right + szPage.cx, szList.cy + m_rcNavigatorMargin.top + m_rcNavigatorMargin.bottom); rcPage = CRect(CPoint(szList.cx + 2 * m_rcNavigatorMargin.left, m_rcNavigatorMargin.top), szPage); AfxRepositionWindow(pLayout, GetSafeHwnd(), CRect(m_rcNavigatorMargin.TopLeft(), szList)); }
void CXTPPropertyPageTabNavigator::SizeToPage(AFX_SIZEPARENTPARAMS* pLayout, CSize szClient, CRect& rcPage) { CRect rcTabControl(0, 0, szClient.cx, szClient.cy); rcTabControl.DeflateRect(m_rcNavigatorMargin); rcPage = rcTabControl; AdjustRect(FALSE, &rcPage); rcPage.DeflateRect(m_rcPageMargin); AfxRepositionWindow(pLayout, m_hWnd, CRect(m_rcNavigatorMargin.TopLeft(), rcTabControl.Size())); m_brushPage.DeleteObject(); }
void COleIPFrameWnd::RecalcLayout(BOOL /*bNotify*/) { ASSERT_VALID(this); // better have a parent window (only used for inplace) CWnd* pParentWnd = GetParent(); ASSERT_VALID(pParentWnd); // first call reposition bars with arbitarily large rect just to // see how much space the bars will take up CRect rectBig(0, 0, INT_MAX/2, INT_MAX/2); CRect rectLeft; RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &rectLeft, &rectBig); // grow the rect by the size of the control bars CRect rect = m_rectPos; rect.left -= rectLeft.left; rect.top -= rectLeft.top; rect.right += INT_MAX/2 - rectLeft.right; rect.bottom += INT_MAX/2 - rectLeft.bottom; // see how much extra space for non-client areas (such as scrollbars) // that the view needs. CWnd* pLeftOver = GetDlgItem(AFX_IDW_PANE_FIRST); if (pLeftOver != NULL) { rectBig = m_rectPos; pLeftOver->CalcWindowRect(&rectBig, CWnd::adjustOutside); rect.left -= m_rectPos.left - rectBig.left; rect.top -= m_rectPos.top - rectBig.top; rect.right += rectBig.right - m_rectPos.right; rect.bottom += rectBig.bottom - m_rectPos.bottom; } // adjust for non-client area on the frame window CalcWindowRect(&rect, CWnd::adjustOutside); // the frame window must be clipped to the visible part in the container CRect rectVis; rectVis.IntersectRect(&rect, &m_rectClip); // move the window AfxRepositionWindow(NULL, m_hWnd, &rectVis); // now resize the control bars relative to the (now moved) frame pParentWnd->ClientToScreen(&rect); ScreenToClient(&rect); RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, CWnd::reposDefault, NULL, &rect); }
LRESULT COleResizeBar::OnSizeParent(WPARAM, LPARAM lParam) { AFX_SIZEPARENTPARAMS* lpLayout = (AFX_SIZEPARENTPARAMS*)lParam; // only resize the window if doing layout and not just rect query if (lpLayout->hDWP != NULL) AfxRepositionWindow(lpLayout, m_hWnd, &lpLayout->rect); // always adjust the rectangle after the resize int nHandleSize = m_tracker.m_nHandleSize; ::InflateRect(&lpLayout->rect, -nHandleSize, -nHandleSize); return 0; }
//----- OnSizeParent() ------------------------------------------------------ LRESULT BCTabBarCtrl::OnSizeParent(WPARAM wParam, LPARAM lParam) { AFX_SIZEPARENTPARAMS* lpLayout = (AFX_SIZEPARENTPARAMS*)lParam; CRect rectItem, rectClient(lpLayout->rect); GetItemRect(0, rectItem); rectClient.bottom = rectClient.top + rectItem.Height() + CLIENT_FUDGE; lpLayout->rect.top = rectClient.bottom; lpLayout->sizeTotal = rectClient.Size(); if (lpLayout->hDWP != NULL) AfxRepositionWindow(lpLayout, m_hWnd, &rectClient); return 0; }
void CXTPPropertyPageTabNavigator::PageToSize(AFX_SIZEPARENTPARAMS* pLayout, CSize szPage, CRect& rcPage, CSize& szClient) { CRect rcTabControl(0, 0, szPage.cx, szPage.cy); CClientDC dc(this); GetPaintManager()->RepositionTabControl(this, &dc, rcTabControl); AdjustRect(TRUE, &rcTabControl); rcTabControl.InflateRect(m_rcPageMargin); szClient = CSize(rcTabControl.Width() + m_rcNavigatorMargin.left + m_rcNavigatorMargin.right, rcTabControl.Height() + m_rcNavigatorMargin.top + m_rcNavigatorMargin.bottom); rcPage = CRect(CPoint(m_rcNavigatorMargin.left - rcTabControl.left, m_rcNavigatorMargin.top - rcTabControl.top), szPage); AfxRepositionWindow(pLayout, m_hWnd, CRect(m_rcNavigatorMargin.TopLeft(), rcTabControl.Size())); GetPaintManager()->RepositionTabControl(this, &dc, CRect(0, 0, rcTabControl.Width(), rcTabControl.Height())); }
LRESULT Dialog_OnSizeParent(HWND hwnd, AFX_SIZEPARENTPARAMS* lpLayout) { // align the control bar CRect rect, r; CSize size; BOOL Ribbon = hwnd == AstralDlgGet(Tool.idRibbon); BOOL Status = hwnd == AstralDlgGet(IDD_STATUS); rect.CopyRect(&lpLayout->rect); CSize sizeAvail = rect.Size(); // maximum size available // get maximum requested size, size of ribbon GetClientRect(GetParent(hwnd), &r); size.cx = r.Width(); if (Ribbon) size.cy = 42; else if (Status) size.cy = 22; size.cx = min(size.cx, sizeAvail.cx); size.cy = min(size.cy, sizeAvail.cy); lpLayout->sizeTotal.cy += size.cy; lpLayout->sizeTotal.cx = max(lpLayout->sizeTotal.cx, size.cx); if (Ribbon) lpLayout->rect.top += size.cy; else if (Status) { rect.top = rect.bottom - size.cy; lpLayout->rect.bottom -= size.cy; } rect.right = rect.left + size.cx; rect.bottom = rect.top + size.cy; // only resize the window if doing layout and not just rect query if (lpLayout->hDWP != NULL) AfxRepositionWindow(lpLayout, hwnd, &rect); return 0; }
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; }
CSize CDockBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz) { ASSERT_VALID(this); CSize sizeFixed = CControlBar::CalcFixedLayout(bStretch, bHorz); // prepare for layout AFX_SIZEPARENTPARAMS layout; layout.hDWP = m_bLayoutQuery ? NULL : ::BeginDeferWindowPos(m_arrBars.GetSize()); CPoint pt(-afxData.cxBorder2, -afxData.cyBorder2); int nWidth = 0; // layout all the control bars for (int nPos = 0; nPos < m_arrBars.GetSize(); nPos++) { CControlBar* pBar = (CControlBar*)m_arrBars[nPos]; if (pBar != NULL) { if (pBar->IsVisible()) { // get ideal rect for bar CSize sizeBar = pBar->CalcFixedLayout(FALSE, (pBar->m_dwStyle & CBRS_ORIENT_HORZ) ? TRUE : FALSE); CRect rect(pt, sizeBar); // get current rect for bar CRect rectBar; pBar->GetWindowRect(&rectBar); ScreenToClient(&rectBar); if (bHorz) { // change position if size changed or top not the same or // rectbar.left < rect.left // if floating compress pt.x = rectBar.left; if (rect.Size() != rectBar.Size() || rect.top != rectBar.top || (rectBar.left < rect.left && !m_bFloating) || (rectBar.left != rect.left && m_bFloating)) { if (rectBar.left > rect.left && !m_bFloating) rect.OffsetRect(rectBar.left - rect.left, 0); AfxRepositionWindow(&layout, pBar->m_hWnd, &rect); pt.x = rect.left; } pt.x += sizeBar.cx - afxData.cxBorder2; nWidth = max(nWidth, sizeBar.cy); } else { // change position if size changed or top not the same or // rectbar.left < rect.left // if floating compress pt.y = rectBar.top; if (rect.Size() != rectBar.Size() || rect.left != rectBar.left || (rectBar.top < rect.top && !m_bFloating) || (rectBar.top != rect.top && m_bFloating)) { if (rectBar.top > rect.top && !m_bFloating) rect.OffsetRect(0, rectBar.top - rect.top); AfxRepositionWindow(&layout, pBar->m_hWnd, &rect); pt.y = rect.top; } pt.y += sizeBar.cy - afxData.cyBorder2; nWidth = max(nWidth, sizeBar.cx); } } // handle any delay/show hide for the bar pBar->RecalcDelayShow(&layout); } else if (nWidth != 0) { // end of row because pBar == NULL if (bHorz) { pt.y += nWidth - afxData.cyBorder2; sizeFixed.cx = max(sizeFixed.cx, pt.x); sizeFixed.cy = max(sizeFixed.cy, pt.y); pt.x = -afxData.cxBorder2; } else { pt.x += nWidth - afxData.cxBorder2; sizeFixed.cx = max(sizeFixed.cx, pt.x); sizeFixed.cy = max(sizeFixed.cy, pt.y); pt.y = -afxData.cyBorder2; } 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; }
LRESULT CProgressBar::OnSizeParent(WPARAM, LPARAM lParam) // This overrides the normal OnSizeParent method (CControlBar) // Normal control bars can never overlap - each is opened using the parent's // client rectangle, and then their area is subtracted from the available client // area, so that they never overlap. // However, the progress bar wants to sit over the top of the status bar if // possible, so before allowing the normal action to proceed... // If the status window's client rectangle butts onto the layout rect passed in, // then we extend the layout rectangle to include the status bar, and hence we // will be placed over the top of the SB. // NOTE - currently only does this if attached to the BOTTOM of the window. // If this fails (sttaus bar not open, or at top of window, etc), the progress // bar will appear normally (above/below all other control bars) { AFX_SIZEPARENTPARAMS FAR* lpLayout = (AFX_SIZEPARENTPARAMS FAR*)lParam; CRect StatusRect; ((CMainFrame *) AfxGetApp()->m_pMainWnd)->GetStatusBarWindowRect(&StatusRect); if (!StatusRect.IsRectEmpty()) // Cover status bar (if open) { // JustinF says: this is a quick bodge so that the progress-bar respects any // overriding prefix displayed in the status line by StatusLine::SetPrefix. StatusRect.left = StatusLine::GetPrefixWidth(); // We just move our window so it is covering the status bar, using the // HWDP supplied in the AFX_SIZEPARENTPARAMS structure. lpLayout->hDWP = ::DeferWindowPos(lpLayout->hDWP, m_hWnd, HWND_TOP, StatusRect.left, StatusRect.top, StatusRect.right - StatusRect.left, StatusRect.bottom - StatusRect.top, SWP_NOACTIVATE); } else { #if _MFC_VER < 0x300 // No status bar - just plonk the progress bar where we can... return (CControlBar::OnSizeParent((WPARAM)0, lParam)); #else // resize and reposition this control bar based on styles DWORD dwStyle = (m_dwStyle & (CBRS_ALIGN_ANY|CBRS_BORDER_ANY)) | (GetStyle() & WS_VISIBLE); if ((dwStyle & WS_VISIBLE) && (dwStyle & CBRS_ALIGN_ANY) != 0) { // align the control bar CRect rect; if (StatusRect.IsRectEmpty()) { // Status bar is not open - just fit in where we can. // (This code copied from barcore.cpp in MFC 3) rect.CopyRect(&lpLayout->rect); CSize sizeAvail = rect.Size(); // maximum size available // get maximum requested size CSize size = CalcFixedLayout(lpLayout->bStretch, (dwStyle & CBRS_ORIENT_HORZ) ? TRUE : FALSE); size.cx = min(size.cx, sizeAvail.cx); size.cy = BarHeight; lpLayout->sizeTotal.cy += size.cy; lpLayout->sizeTotal.cx = max(lpLayout->sizeTotal.cx, size.cx); rect.top = rect.bottom - size.cy; lpLayout->rect.bottom -= size.cy; rect.right = rect.left + size.cx; rect.bottom = rect.top + size.cy; // only resize the window if doing layout and not just rect query if (lpLayout->hDWP != NULL) { AfxRepositionWindow(lpLayout, m_hWnd, &rect); } } } #endif } return 0; }
LRESULT CXTPDockBar::OnSizeParent(WPARAM, LPARAM lParam) { AFX_SIZEPARENTPARAMS* lpLayout = (AFX_SIZEPARENTPARAMS*)lParam; DWORD dwStyle = GetStyle(); if (dwStyle & WS_VISIBLE) { // align the control bar CRect rect; rect.CopyRect(&lpLayout->rect); CSize sizeAvail = rect.Size(); // maximum size available // get maximum requested size DWORD dwMode = lpLayout->bStretch ? LM_STRETCH : 0; if ((m_dwStyle & CBRS_SIZE_DYNAMIC) && m_dwStyle & CBRS_FLOATING) dwMode |= LM_HORZ | LM_MRUWIDTH; else if (dwStyle & CBRS_ORIENT_HORZ) dwMode |= LM_HORZ | LM_HORZDOCK; else dwMode |= LM_VERTDOCK; int nLength = (dwStyle & CBRS_ORIENT_HORZ ? sizeAvail.cx : sizeAvail.cy) /*- 2 * GetSystemMetrics(SM_CXBORDER)*/; CSize size = CalcDynamicLayout(nLength, dwMode, lpLayout); size.cx = min(size.cx, sizeAvail.cx); size.cy = min(size.cy, sizeAvail.cy); if (dwStyle & CBRS_ORIENT_HORZ) { lpLayout->sizeTotal.cy += size.cy; lpLayout->sizeTotal.cx = max(lpLayout->sizeTotal.cx, size.cx); if (dwStyle & CBRS_ALIGN_TOP) lpLayout->rect.top += size.cy; else if (dwStyle & CBRS_ALIGN_BOTTOM) { rect.top = rect.bottom - size.cy; lpLayout->rect.bottom -= size.cy; } } else { lpLayout->sizeTotal.cx += size.cx; lpLayout->sizeTotal.cy = max(lpLayout->sizeTotal.cy, size.cy); if (dwStyle & CBRS_ALIGN_LEFT) lpLayout->rect.left += size.cx; else if (dwStyle & CBRS_ALIGN_RIGHT) { rect.left = rect.right - size.cx; lpLayout->rect.right -= size.cx; } } rect.right = rect.left + size.cx; rect.bottom = rect.top + size.cy; // only resize the window if doing layout and not just rect query if (lpLayout->hDWP != NULL) AfxRepositionWindow(lpLayout, m_hWnd, &rect); Invalidate(FALSE); } return 0; }
int CXTPDockBar::_AdjustRow(CToolBarArray& arrRow, CPoint pt, int nLength, BOOL bHorz, AFX_SIZEPARENTPARAMS* lpLayout, int& nRemove) { CDockInfoArray arrInfo; int nPos; // Step 1. Getting maximum available size; for (nPos = 0; nPos < arrRow.GetSize(); nPos++) { CXTPToolBar* pBar = arrRow[nPos]; CSize sizeBar = pBar->CalcDockingLayout(nLength, _GetMode(bHorz, pBar)); CPoint p = bHorz ? CPoint(pBar->m_pDockContext->m_rectMRUDockPos.left, pt.y) : CPoint(pt.x, pBar->m_pDockContext->m_rectMRUDockPos.top); DOCK_INFO dockInfo(pBar, CRect(p, sizeBar), nPos); arrInfo.Add(dockInfo); } ASSERT(arrInfo.GetSize() == arrRow.GetSize()); if (!bHorz) arrInfo.InvertRects(); arrInfo.Sort(); // Step 2. if Total length is more than available, fill empty area. int nIndex = -1; int nLen = 0; BOOL bMove = TRUE; for (nPos = 0; nPos < arrInfo.GetSize(); nPos++) { CRect& rect = arrInfo[nPos].rcBar; bMove = (rect.left < nLen && (nIndex < arrInfo[nPos].nIndex || bMove)); if (bMove) rect.OffsetRect(nLen - rect.left, 0); nLen = rect.right; nIndex = arrInfo[nPos].nIndex; } nLen = nLength; nIndex = -1; bMove = TRUE; for (nPos = (int)arrInfo.GetSize() - 1; nPos >= 0; nPos--) { CRect& rect = arrInfo[nPos].rcBar; bMove = (rect.right - nLen > 0 && (nIndex < arrInfo[nPos].nIndex || bMove)); if (bMove) rect.OffsetRect(nLen - rect.right, 0); nLen = rect.left; nIndex = arrInfo[nPos].nIndex; } nLen = 0; for (nPos = 0; nPos < arrInfo.GetSize(); nPos++) { CRect& rect = arrInfo[nPos].rcBar; if (rect.left < nLen) rect.OffsetRect(nLen - rect.left, 0); nLen = rect.left + rect.Width(); } // Step 3. if Total length is more than available, make it expandable. if (nLen > nLength) { int nSum = 0; for (nPos = 0; nPos < arrInfo.GetSize(); nPos++) { CXTPToolBar* pBar = arrInfo[nPos].pBar; if (!(_GetMode(bHorz, pBar) & LM_HIDEWRAP)) arrInfo[nPos].nMinWidth = nLength; else { CSize sz = pBar->CalcDockingLayout(1, _GetMode(bHorz, pBar)); arrInfo[nPos].nMinWidth = bHorz ? sz.cx : sz.cy; } arrInfo[nPos].nTotlaMinWidth = nSum; nSum += arrInfo[nPos].nMinWidth; } nLen = nLength; for (nPos = (int)arrInfo.GetSize() - 1; nPos >= 0; nPos--) { CRect& rect = arrInfo[nPos].rcBar; int nLeft = bHorz ? arrInfo[nPos].rcMRUPos.left : arrInfo[nPos].rcMRUPos.top; if (nLeft > rect.left) nLeft = rect.left; if (nLeft < nLen - rect.Width()) nLeft = nLen - rect.Width(); if (nLeft < arrInfo[nPos].nTotlaMinWidth) nLeft = arrInfo[nPos].nTotlaMinWidth; if (nLen - nLeft < arrInfo[nPos].nMinWidth) nLeft = nLen - arrInfo[nPos].nMinWidth; if ((nLen - nLeft < arrInfo[nPos].nMinWidth || nLeft < arrInfo[nPos].nTotlaMinWidth) && arrInfo.GetSize() != 1) { nRemove = arrInfo[arrInfo.GetSize() - 1].nIndex; return -1; } rect.right = nLen; nLen = rect.left = max(0, nLeft); } } if (!bHorz) arrInfo.InvertRects(); int nWidth = 0; // Calculate total width for (nPos = 0; nPos < arrInfo.GetSize(); nPos++) { CXTPToolBar* pBar = arrInfo[nPos].pBar; CRect& rect = arrInfo[nPos].rcBar; CSize sizeBar = pBar->CalcDockingLayout(bHorz ? rect.Width() : rect.Height(), _GetMode(bHorz, pBar)); nWidth = max(nWidth, bHorz ? sizeBar.cy : sizeBar.cx); } if (lpLayout->hDWP == 0) return nWidth; // Step 4. Move it. for (nPos = 0; nPos < arrInfo.GetSize(); nPos++) { CXTPToolBar* pBar = arrInfo[nPos].pBar; CRect& rect = arrInfo[nPos].rcBar; int nMode = _GetMode(bHorz, pBar) | LM_COMMIT; if (pBar->GetFlags() & xtpFlagStretchedShared) { if (bHorz) { rect.right = nPos == arrInfo.GetSize() - 1 ? nLength : arrInfo[nPos + 1].rcBar.left; rect.left = nPos == 0 ? 0 : min(arrInfo[nPos - 1].rcBar.right, rect.left); } else { rect.bottom = nPos == arrInfo.GetSize() - 1 ? nLength : arrInfo[nPos + 1].rcBar.top; rect.top = nPos == 0 ? 0 : min(arrInfo[nPos - 1].rcBar.bottom, rect.top); } nMode |= LM_STRETCH; } CSize sz = pBar->CalcDockingLayout(bHorz ? rect.Width() : rect.Height(), nMode, nWidth); rect = CRect(rect.TopLeft(), sz); pBar->m_pDockContext->m_uMRUDockPosition = GetPosition(); CXTPWindowRect rectOld(pBar); ScreenToClient(&rectOld); if (!::EqualRect(rectOld, rect)) { AfxRepositionWindow(lpLayout, pBar->m_hWnd, &rect); pBar->Redraw(); } } return nWidth; }
LRESULT CControlBar::OnSizeParent(WPARAM, LPARAM lParam) { AFX_SIZEPARENTPARAMS* lpLayout = (AFX_SIZEPARENTPARAMS*)lParam; DWORD dwStyle = RecalcDelayShow(lpLayout); if ((dwStyle & WS_VISIBLE) && (dwStyle & CBRS_ALIGN_ANY) != 0) { // align the control bar CRect rect; rect.CopyRect(&lpLayout->rect); CSize sizeAvail = rect.Size(); // maximum size available // get maximum requested size DWORD dwMode = lpLayout->bStretch ? LM_STRETCH : 0; if ((m_dwStyle & CBRS_SIZE_DYNAMIC) && m_dwStyle & CBRS_FLOATING) dwMode |= LM_HORZ | LM_MRUWIDTH; else if (dwStyle & CBRS_ORIENT_HORZ) dwMode |= LM_HORZ | LM_HORZDOCK; else dwMode |= LM_VERTDOCK; CSize size = CalcDynamicLayout(-1, dwMode); size.cx = min(size.cx, sizeAvail.cx); size.cy = min(size.cy, sizeAvail.cy); if (dwStyle & CBRS_ORIENT_HORZ) { lpLayout->sizeTotal.cy += size.cy; lpLayout->sizeTotal.cx = max(lpLayout->sizeTotal.cx, size.cx); if (dwStyle & CBRS_ALIGN_TOP) lpLayout->rect.top += size.cy; else if (dwStyle & CBRS_ALIGN_BOTTOM) { rect.top = rect.bottom - size.cy; lpLayout->rect.bottom -= size.cy; } } else if (dwStyle & CBRS_ORIENT_VERT) { lpLayout->sizeTotal.cx += size.cx; lpLayout->sizeTotal.cy = max(lpLayout->sizeTotal.cy, size.cy); if (dwStyle & CBRS_ALIGN_LEFT) lpLayout->rect.left += size.cx; else if (dwStyle & CBRS_ALIGN_RIGHT) { rect.left = rect.right - size.cx; lpLayout->rect.right -= size.cx; } } else { ASSERT(FALSE); // can never happen } rect.right = rect.left + size.cx; rect.bottom = rect.top + size.cy; // only resize the window if doing layout and not just rect query if (lpLayout->hDWP != NULL) AfxRepositionWindow(lpLayout, m_hWnd, &rect); } return 0; }
LRESULT CControlBar::OnSizeParent(WPARAM, LPARAM lParam) { AFX_SIZEPARENTPARAMS* lpLayout = (AFX_SIZEPARENTPARAMS*)lParam; DWORD dwStyle = RecalcDelayShow(lpLayout); if ((dwStyle & WS_VISIBLE) && (dwStyle & CBRS_ALIGN_ANY) != 0) { // align the control bar CRect rect; rect.CopyRect(&lpLayout->rect); CSize sizeAvail = rect.Size(); // maximum size available // get maximum requested size CSize size = CalcFixedLayout(lpLayout->bStretch, dwStyle & CBRS_ORIENT_HORZ); size.cx = min(size.cx, sizeAvail.cx); size.cy = min(size.cy, sizeAvail.cy); if (dwStyle & CBRS_ORIENT_HORZ) { lpLayout->sizeTotal.cy += size.cy; lpLayout->sizeTotal.cx = max(lpLayout->sizeTotal.cx, size.cx); if (dwStyle & CBRS_ALIGN_TOP) lpLayout->rect.top += size.cy; else if (dwStyle & CBRS_ALIGN_BOTTOM) { rect.top = rect.bottom - size.cy; lpLayout->rect.bottom -= size.cy; } } else if (dwStyle & CBRS_ORIENT_VERT) { lpLayout->sizeTotal.cx += size.cx; lpLayout->sizeTotal.cy = max(lpLayout->sizeTotal.cy, size.cy); if (dwStyle & CBRS_ALIGN_LEFT) lpLayout->rect.left += size.cx; else if (dwStyle & CBRS_ALIGN_RIGHT) { rect.left = rect.right - size.cx; lpLayout->rect.right -= size.cx; } } else { ASSERT(FALSE); // can never happen } rect.right = rect.left + size.cx; rect.bottom = rect.top + size.cy; #ifdef _MAC // account for the Macintosh grow box, if there is one CWnd* pWnd = GetParentFrame(); if (pWnd != NULL) { DWORD dwWndStyle = pWnd->GetStyle(); DWORD dwExStyle = pWnd->GetExStyle(); if (!(dwExStyle & WS_EX_MDIFRAME) && (dwExStyle & WS_EX_FORCESIZEBOX) && !(dwWndStyle & (WS_VSCROLL|WS_HSCROLL))) { CRect rectParent; pWnd->GetClientRect(rectParent); if (dwStyle & CBRS_ALIGN_BOTTOM) { if (rect.bottom > rectParent.bottom - afxData.cxVScroll + 1) rect.right -= (afxData.cxVScroll - 1); } else if (dwStyle & CBRS_ALIGN_RIGHT) { if (rect.bottom > rectParent.bottom - afxData.cyHScroll + 1) rect.bottom -= (afxData.cxVScroll - 1); } } } #endif // only resize the window if doing layout and not just rect query if (lpLayout->hDWP != NULL) AfxRepositionWindow(lpLayout, m_hWnd, &rect); } return 0; }