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; }
bool CSizableReBar::DoAddBar( CWnd* pBar, REBARBANDINFO* prbbi, LPCTSTR lpszTitle, bool bAlwaysVisible, bool bHasGripper, int nStartingWidth ) { UINT nID = ( UINT )pBar->GetDlgCtrlID(); ASSERT( nID != 0 ); ASSERT( m_rbCtrl.IDToIndex( nID ) == -1 ); // ID must be unique! // Save bar info for context menu BARINFO barinfo; barinfo.nID = nID; barinfo.bAlwaysVisible = bAlwaysVisible; barinfo.bHasGripper = bHasGripper; _tcsncpy( barinfo.szTitle, lpszTitle ? lpszTitle : _T(""), MAX_PATH ); m_aBars.Add( barinfo ); prbbi->cbSize = sizeof( *prbbi ); prbbi->fMask |= RBBIM_ID | RBBIM_BACKGROUND | RBBIM_CHILD | RBBIM_CHILDSIZE; prbbi->wID = nID; prbbi->hbmBack = m_hbmBack; prbbi->hwndChild = pBar->m_hWnd; BOOL bHorz = ( m_dwStyle & CBRS_ORIENT_HORZ ) != 0; CControlBar* pTemp = DYNAMIC_DOWNCAST( CControlBar, pBar ); if ( pTemp != 0 ) { CSize szBar = pTemp->CalcFixedLayout( FALSE, bHorz ); prbbi->cxMinChild = bHorz ? szBar.cx : szBar.cy; prbbi->cyMinChild = bHorz ? szBar.cy : szBar.cx; } else { CRect rcWindow; pBar->GetWindowRect( rcWindow ); prbbi->cxMinChild = bHorz ? rcWindow.Width() : rcWindow.Height(); prbbi->cyMinChild = bHorz ? rcWindow.Height() : rcWindow.Width(); } if ( m_bLocked || !bHasGripper ) { prbbi->fStyle &= ~RBBS_GRIPPERALWAYS; prbbi->fStyle |= RBBS_NOGRIPPER; } else { prbbi->fStyle |= RBBS_GRIPPERALWAYS; prbbi->fStyle &= ~RBBS_NOGRIPPER; } if ( pBar->IsKindOf( RUNTIME_CLASS( CMenuBar ) ) || pBar->IsKindOf( RUNTIME_CLASS( CToolBarEx ) ) ) { prbbi->fStyle |= RBBS_USECHEVRON; } if ( nStartingWidth > 0 ) { prbbi->fMask |= RBBIM_SIZE | RBBIM_CHILD | RBBIM_CHILDSIZE; prbbi->cx = nStartingWidth; prbbi->cxMinChild = nStartingWidth; } if ( !m_rbCtrl.InsertBand( ( UINT )-1, prbbi ) ) { return false; } pBar->SetOwner( this ); GetParentFrame()->RecalcLayout(); return true; }