//********************************************************************************** void CCxLoginBar::AdjustLocations () { ASSERT_VALID(this); if (m_Buttons.IsEmpty () || GetSafeHwnd () == NULL) { return; } CRect rectClient; GetClientRect (rectClient); if ( rectClient.IsRectEmpty() || rectClient.IsRectNull() ) { return; } CRect rc; for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;) { CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) m_Buttons.GetNext (pos); if (pButton == NULL || pButton == (CBCGPToolbarButton*)m_pCustomizeBtn) { break; } ASSERT_VALID (pButton); if (pButton->IsVisible ()) { if ( pButton->IsKindOf( RUNTIME_CLASS(CCxLoginBarUserButton) ) ) { rc = rectClient; //rc.right = rectClient.right - g_nLoginWidth - 1; pButton->SetRect (rc); } /*else if ( pButton->IsKindOf( RUNTIME_CLASS(CCxLoginBarLoginButton) ) ) { rc = rectClient; rc.left = rectClient.right - g_nLoginWidth; pButton->SetRect (rc); }*/ } } }
CSize CToolPalette::CalcButtonLocations(int nColumns, bool bCalcOnly) { if (nColumns < 1) { nColumns = 1; } bool bHorizontal = (GetCurrentAlignment () & CBRS_ORIENT_HORZ) != 0; // Toolbar layout mode CRect rectClient; GetClientRect (rectClient); EDisplayOptions edo = GetToolbarDisplayOptions (); if ((edo & eDisplayTitle) != 0) { if (!bHorizontal) { rectClient.top += m_nCaptionHeight + 4; } } int xBorders = 0; int yBorders = 0; if ((edo & eDisplayBorder) != 0) { const CRect& rectCorners = m_imgCaption.GetParams ().m_rectCorners; rectClient.left += rectCorners.left + 3; rectClient.top += rectCorners.top; xBorders = rectCorners.left + rectCorners.right; yBorders = rectCorners.top + rectCorners.bottom; } else { rectClient.left += 1; } if ((edo & eDisplaySizeControl) != 0 && bHorizontal) { const int sizeControlHeight = m_imgCaption.GetParams ().m_rectImage.Height (); yBorders += sizeControlHeight; rectClient.top += sizeControlHeight; } // Consider border area CPoint xyPos = rectClient.TopLeft (); // Current position bool bPrevSeparator = true; // Indicates that previous button was a separator. // Initial 'true' value prevents separator to appear first. CClientDC dc (this); CSize szButtonDefault (GetColumnWidth (), GetRowHeight ()); // Default button size to pass to button's OnCalculateSize method int nMaxSize = nColumns * (bHorizontal ? szButtonDefault.cy : szButtonDefault.cx) * 11 / 10; // (11/10) adds +10% space here // The toolbar height (for horizontal layout) or width (for vertical) of toolbar. CList<ButtonStripe, const ButtonStripe&> listStripes; ButtonStripe stripe; // Current stripe CBCGPToolbarButton* pButton = NULL; // Current button for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;) { pButton = (CBCGPToolbarButton*)m_Buttons.GetNext (pos); if (pButton == NULL) { break; } if (!pButton->IsVisible ()) { continue; } bool bSep = (pButton->m_nStyle & TBBS_SEPARATOR) != 0; if (bSep && bPrevSeparator) { continue; } // Layout algorithm: // ------------------- // if (separator) AddPreviousStripe, AddSeparatorStripe, BeginNewStripe // else { // AddButton // if (stripe.breadth > default_stripe_breadth) // AddPreviousStripe, BeginNewStripe, AddButton // } CSize szButton = pButton->OnCalculateSize (&dc, szButtonDefault, bHorizontal); if (bHorizontal) { } else // vertical layout { if (bSep) { if (stripe.buttonCount > 0) { listStripes.AddTail (stripe); } stripe.buttonCount = 1; stripe.breadth = 0; // separator length is set automatically stripe.size = szButton.cy; // cx for horz. listStripes.AddTail (stripe); stripe = ButtonStripe (); } else if (szButton.cx > nMaxSize) // this button is larger than current toolbar width { if (stripe.buttonCount > 0) { listStripes.AddTail (stripe); } stripe.buttonCount = 1; stripe.breadth = szButton.cx; // cy for horz. stripe.size = szButton.cy; // cx for horz. listStripes.AddTail (stripe); // stripe with a single large button stripe = ButtonStripe (); } else // usual button { if (stripe.breadth + szButton.cx <= nMaxSize) { stripe.breadth += szButton.cx; stripe.buttonCount ++; if (szButton.cy > stripe.size) stripe.size = szButton.cy; } else { if (stripe.buttonCount > 0) { listStripes.AddTail (stripe); } stripe.buttonCount = 1; stripe.breadth = szButton.cx; // cy for horz. stripe.size = szButton.cy; // cx for horz. } } } bPrevSeparator = bSep; } if (stripe.buttonCount > 0) { listStripes.AddTail (stripe); } if (listStripes.IsEmpty ()) { return CSize (0, 0); } if (listStripes.GetTail ().breadth == 0) // last item is separator { listStripes.RemoveTail (); } // Now calculate total size int totalLength = m_nCaptionHeight + 4; int maxBreadth = nMaxSize; POSITION posStripes = listStripes.GetHeadPosition (); while (posStripes != NULL) { stripe = listStripes.GetNext (posStripes); ASSERT (stripe.buttonCount > 0); totalLength += stripe.size; if (stripe.breadth > maxBreadth) { maxBreadth = stripe.breadth; } } if (!bCalcOnly) { CPoint ptButtonPos = rectClient.TopLeft (); posStripes = listStripes.GetHeadPosition (); stripe = ButtonStripe(); for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;) { pButton = (CBCGPToolbarButton*)m_Buttons.GetNext (pos); if (pButton == NULL) { break; } if (!pButton->IsVisible ()) { continue; } bool bSep = (pButton->m_nStyle & TBBS_SEPARATOR) != 0; if (bSep && bPrevSeparator) { continue; } CSize szButton = pButton->OnCalculateSize (&dc, szButtonDefault, bHorizontal); CRect rcButton (0, 0, 0, 0); if (stripe.buttonCount == 0) // this member is decremented below { ptButtonPos.y += stripe.size; if (posStripes == NULL) { break; } stripe = listStripes.GetNext (posStripes); ptButtonPos.x = rectClient.left + (maxBreadth - stripe.breadth) / 2; // center-alignment } if (bSep) { ASSERT (stripe.breadth == 0); ASSERT (stripe.buttonCount == 1); rcButton.left = rectClient.left; rcButton.top = ptButtonPos.y; rcButton.right = rcButton.left + maxBreadth; rcButton.bottom = rcButton.top + szButton.cy; } else { rcButton.left = ptButtonPos.x; rcButton.top = ptButtonPos.y + (stripe.size - szButton.cy) / 2; // center-alignment rcButton.right = rcButton.left + szButton.cx; rcButton.bottom = rcButton.top + szButton.cy; ptButtonPos.x += szButton.cx; } pButton->SetRect (rcButton); stripe.buttonCount --; } } if (m_bAdditionalPixel) { ++maxBreadth; } return bHorizontal ? CSize (totalLength + xBorders, maxBreadth + yBorders) : CSize (maxBreadth + xBorders, totalLength + yBorders); }