//----------------------------------------------------------------------------------// void CBCGPAutoHideDockBar::DockControlBar (CBCGPControlBar* pControlBar, BCGP_DOCK_METHOD /*dockMethod*/, LPCRECT lpRect) { ASSERT_VALID (this); ASSERT_VALID (pControlBar); BOOL bVertDock = !IsHorizontal (); CSize szBarSize = pControlBar->CalcFixedLayout (FALSE, !bVertDock); // the control bar doesn't take up all space of the row int nRowHeight = bVertDock ? szBarSize.cx + m_nExtraSpace : szBarSize.cy + m_nExtraSpace; if (!m_lstControlBars.Find (pControlBar)) { CBCGPDockBarRow* pRowToDock = NULL; if (m_lstDockBarRows.IsEmpty ()) { pRowToDock = AddRow (NULL, nRowHeight); if (GetCurrentAlignment () & CBRS_ALIGN_LEFT || GetCurrentAlignment () & CBRS_ALIGN_TOP) { pRowToDock->SetExtra (m_nExtraSpace, BCGP_ROW_ALIGN_TOP); } else { pRowToDock->SetExtra (m_nExtraSpace, BCGP_ROW_ALIGN_BOTTOM); } } else { pRowToDock = (CBCGPDockBarRow*) m_lstDockBarRows.GetHead (); } ASSERT_VALID (pRowToDock); // the bar should be placed on the existing row or new row pRowToDock->AddControlBar (pControlBar, BCGP_DM_RECT, lpRect, TRUE); ShowWindow (SW_SHOW); m_lstControlBars.AddTail (pControlBar); AdjustDockingLayout (); CRect rectClient; GetClientRect (rectClient); RepositionBars (rectClient); } }
//********************************************************************************** void CToolPalette::DoPaint(CDC* pDC) { CRect rcClient; GetClientRect(rcClient); CBCGPMemDC bufferDC(*pDC, rcClient); CBCGPToolBar::DoPaint (&bufferDC.GetDC()); CBCGPDrawManager dm (bufferDC.GetDC()); bool bHorizontal = (GetCurrentAlignment() & CBRS_ORIENT_HORZ) != 0; // Toolbar layout mode EDisplayOptions edo = GetToolbarDisplayOptions(); if ((edo & eDisplaySizeControl) != 0 && !bHorizontal) { const int sizeControlHeight = m_imgCaption.GetParams().m_rectImage.Height(); CRect rcSizeControl = rcClient; rcSizeControl.bottom = rcSizeControl.top + sizeControlHeight; m_imgCaption.Draw(pDC, rcSizeControl, 1); // 1 is the index of border image rcClient.top += sizeControlHeight; } if ((edo & eDisplayTitle) != 0) { CString title; GetWindowText (title); CRect rcTitle = rcClient; if ((edo & eDisplayBorder) != 0) { const CRect& rectCorners = m_imgCaption.GetParams().m_rectCorners; rcTitle.top += rectCorners.top; } rcTitle.top += 1; rcTitle.bottom = rcTitle.top + m_nCaptionHeight; dm.FillGradient2 (rcTitle, RGB(48, 112, 202), RGB(21, 57, 111), 305); rcTitle.DeflateRect (1, 2, 1, 2); CFont* pOldFont = bufferDC.GetDC().SelectObject(&m_fntTitle); bufferDC.GetDC().SetBkMode(TRANSPARENT); bufferDC.GetDC().SetTextColor(0xFFFFFF); bufferDC.GetDC().DrawText (title, rcTitle, DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_SINGLELINE | DT_END_ELLIPSIS); bufferDC.GetDC().SelectObject (pOldFont); } if ((edo & eDisplayBorder) != 0) { m_imgCaption.DrawFrame (&bufferDC.GetDC(), rcClient, 0); // 0 is the index of border image } }
//------------------------------------------------------------------------------ void QLabel::init() { // This needs to be called after the LUA variables have been submitted to // the object. TODO we want to support TTF rendering, but not through the // CQabelTTF class as the implimentation they chose is teh suck! QAssert(font != NULL, "label font is null"); // Create and retain the node CCLabelNode *node = new CCLabelNode(this); m_CCNode = node; m_CCNode->retain(); // Set the width to the box width if one is specified float width = GetCalculatedWidth(); float text_width = width - textBorderLeft - textBorderRight; float height = GetCalculatedHeight(); // Get the alignment information cocos2d::CCTextAlignment halign_val; cocos2d::CCVerticalTextAlignment valign_val; GetCurrentAlignment( &halign_val, &valign_val); // Create the label and add it to the node (node holds the reference) m_CCFontNode = CCLabelBMFont::create( text.c_str(), font->get_fileName().c_str(), text_width, halign_val); m_CCNode->addChild(m_CCFontNode); // Calculate the size of the text if we aren't rendering into a box CalculateSize(); // Now set the anchor and position of the CQabel SetAlignmentAnchors( halign_val, valign_val); m_CCNode->setPosition( x, y); m_CCNode->setAnchorPoint(ccp(xAnchor, yAnchor)); m_CachedWidth = width; m_CachedHeight = height; m_CachedHAlignment = hAlignment; m_CachedVAlignment = vAlignment; m_CachedTextBorderTop = textBorderTop; m_CachedTextBorderBottom = textBorderBottom; m_CachedTextBorderLeft = textBorderLeft; m_CachedTextBorderRight = textBorderRight; m_CachedTextXScale = textXScale; m_CachedTextYScale = textYScale; }
//********************************************************************************** CToolPalette::EDisplayOptions CToolPalette::GetToolbarDisplayOptions() const { int x = 0; bool bHorizontal = (GetCurrentAlignment() & CBRS_ORIENT_HORZ) != 0; if (!bHorizontal) { CString title; GetWindowText (title); if (!title.IsEmpty ()) { x |= eDisplayTitle; } if (IsDocked ()) { x |= eDisplayBorder; } } return (EDisplayOptions)x; }
//------------------------------------------------------------------------------ void QLabel::sync() { // Only sync if sync is enabled if (!isSynced) { return; } float old_w = w; float old_h = h; // Make sure w and h are correct values for the purposes of update if (m_CCNode) { w = GetCalculatedWidth(); h = GetCalculatedHeight(); } // Superclass QNode::sync(); // Other if (m_CCNode) { if ( strcmp( m_CCFontNode->getString(), text.c_str()) != 0) { m_CCFontNode->setString( text.c_str()); CalculateSize(); } bool force_realignment = false; if ( m_CachedTextBorderTop != textBorderTop || m_CachedTextBorderBottom != textBorderBottom || m_CachedTextBorderLeft != textBorderLeft || m_CachedTextBorderRight != textBorderRight || m_CachedTextXScale != textXScale || m_CachedTextYScale != textYScale) { force_realignment = true; m_CachedTextBorderTop = textBorderTop; m_CachedTextBorderBottom = textBorderBottom; m_CachedTextBorderLeft = textBorderLeft; m_CachedTextBorderRight = textBorderRight; m_CachedTextXScale = textXScale; m_CachedTextYScale = textYScale; } if ( m_CachedWidth != w || m_CachedHeight != h || force_realignment) { m_CachedWidth = w; m_CachedHeight = h; float text_width = w - textBorderLeft - textBorderRight; m_CCFontNode->setWidth( text_width); force_realignment = true; } if ( m_CachedHAlignment.compare( hAlignment) != 0 || m_CachedVAlignment.compare( vAlignment) || force_realignment) { m_CachedHAlignment = hAlignment; m_CachedVAlignment = vAlignment; // Get the alignment information cocos2d::CCTextAlignment halign_val; cocos2d::CCVerticalTextAlignment valign_val; GetCurrentAlignment( &halign_val, &valign_val); // Now set the anchor and position of the CCLabel SetAlignmentAnchors( halign_val, valign_val); CalculateSize(); } // Color uint8 alpha8 = (uint8)(_alphaInternal * color.a); // multiply "alpha" by color.a component if ( m_CCFontNode->getOpacity() != alpha8) { m_CCFontNode->setOpacity( alpha8); } m_CCFontNode->setColor(*(ccColor3B*)&color); // cast ccColor4B* to ccColor3B* should be OK } // Reset the w and h values correctly w = old_w; h = old_h; }
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); }
void CuResizableDlgBar::OnSize(UINT nType, int cx, int cy) { int i, y, x; int nDividerWidth = 6; CRect rb1, rDlg; CuBitmapButton* tab [] = { &m_Button01, &m_Button02, &m_Button03, &m_Button04, &m_ButtonSC, &m_Button05, &m_Button06, &m_Button07, &m_Button08, &m_Button09, &m_Button10, &m_Button11 }; CMainFrame* MainFramePtr = (CMainFrame*)AfxGetMainWnd(); if (!IsWindow (m_Tree.m_hWnd)) return; CRect rMDIClient; CWnd* WndMDIClient = NULL; TCHAR tchszClass [12]; CWnd* ChildWPtr = MainFramePtr->GetWindow (GW_CHILD); while (ChildWPtr) { GetClassName (ChildWPtr->m_hWnd, tchszClass, sizeof (tchszClass)); if (lstrcmpi (tchszClass, _T("MDIClient")) == 0) { WndMDIClient = ChildWPtr; break; } ChildWPtr = MainFramePtr->GetWindow (GW_HWNDNEXT); } ASSERT (ChildWPtr != NULL); WndMDIClient->GetWindowRect (rMDIClient); MainFramePtr->ScreenToClient (rMDIClient); CRect rClient, r2, r3, r4; GetClientRect (r2); if (m_WindowVersion != VER_PLATFORM_WIN32_NT) nDividerWidth = 7; m_SplitterRight.MoveWindow (CRect (r2.Width()-nDividerWidth, 0, r2.Width(), r2.Height())); m_SplitterRight.GetClientRect (r4); m_SplitterLeft.MoveWindow (CRect (0, 0, nDividerWidth, r2.Height())); m_SplitterTop.MoveWindow (CRect (0, 0, r2.Width(), nDividerWidth)); m_SplitterBottom.MoveWindow(CRect (0, r2.Height()-nDividerWidth, r2.Width(), r2.Height())); // // Size the NUMBEROFBUTTONS buttons and replace then at the appropriate place. m_Tree.ShowWindow (SW_HIDE); m_Button01.GetClientRect (rb1); x = m_Button01Position.x; y = m_Button01Position.y; GetClientRect (rDlg); m_Tree.GetWindowRect (r2); ScreenToClient (r2); for (i=1; i<NUMBEROFBUTTONS; i++) { if ((x + 2*rb1.Width()) > (rDlg.Width()-m_Button01Position.x)) { x = m_Button01Position.x; y += rb1.Height(); } else { x += rb1.Width(); } tab [i]->SetWindowPos (NULL, x, y, 0, 0, SWP_NOSIZE); } tab [NUMBEROFBUTTONS-1]->Invalidate(); CRect r (m_Button01Position.x-2, y + rb1.Height() +6, cx-12, cy-10); m_Tree.MoveWindow (r); m_Tree.ShowWindow (SW_SHOW); CRect rx; GetWindowRect (rx); MainFramePtr->ScreenToClient (rx); CString str; str.Format ( _T("CuResizableDlgBar::OneSize, r: (%d,%d, %d %d), rMDIClient: (%d,%d, %d %d): Floating= %d\n"), rx.left, rx.top, rx.right, rx.bottom, rMDIClient.left, rMDIClient.top, rMDIClient.right, rMDIClient.bottom, IsFloating()); // TRACE0 (str); m_Alignment = GetCurrentAlignment (rx, rMDIClient); if (IsFloating()) m_Alignment = 0; switch (m_Alignment) { case CBRS_ALIGN_LEFT: m_SplitterLeft.ShowWindow (SW_HIDE); m_SplitterTop.ShowWindow (SW_HIDE); m_SplitterBottom.ShowWindow(SW_HIDE); m_SplitterRight.ShowWindow (SW_SHOW); break; case CBRS_ALIGN_RIGHT: m_SplitterTop.ShowWindow (SW_HIDE); m_SplitterBottom.ShowWindow(SW_HIDE); m_SplitterRight.ShowWindow (SW_HIDE); m_SplitterLeft.ShowWindow (SW_SHOW); break; case CBRS_ALIGN_TOP: m_SplitterTop.ShowWindow (SW_HIDE); m_SplitterRight.ShowWindow (SW_HIDE); m_SplitterLeft.ShowWindow (SW_HIDE); m_SplitterBottom.ShowWindow(SW_SHOW); break; case CBRS_ALIGN_BOTTOM: m_SplitterBottom.ShowWindow(SW_HIDE); m_SplitterRight.ShowWindow (SW_HIDE); m_SplitterLeft.ShowWindow (SW_HIDE); m_SplitterTop.ShowWindow (SW_SHOW); break; default: m_SplitterTop.ShowWindow (SW_HIDE); m_SplitterBottom.ShowWindow(SW_HIDE); m_SplitterRight.ShowWindow (SW_HIDE); m_SplitterLeft.ShowWindow (SW_HIDE); break; } MainFramePtr->SetMessageText (""); }
CSize CuResizableDlgBar::CalcDynamicLayout (int nLength, DWORD dwMode) { CWnd* WndMDIClient = NULL; //GetMDIClientWnd(); TCHAR tchszClass [12]; CRect rFrame; CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd(); CWnd* ChildWPtr = pFrame->GetWindow (GW_CHILD); m_SplitterRight.ShowWindow (SW_SHOW); while (ChildWPtr) { GetClassName (ChildWPtr->m_hWnd, tchszClass, sizeof (tchszClass)); if (lstrcmpi (tchszClass, _T("MDIClient")) == 0) { WndMDIClient = ChildWPtr; break; } ChildWPtr = pFrame->GetWindow (GW_HWNDNEXT); } ASSERT (ChildWPtr != NULL); if (IsFloating()) { m_SplitterTop.ShowWindow (SW_HIDE); m_SplitterBottom.ShowWindow(SW_HIDE); m_SplitterRight.ShowWindow (SW_HIDE); m_SplitterLeft.ShowWindow (SW_HIDE); } else { /* CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd(); CWnd* ChildWPtr = pFrame->GetWindow (GW_CHILD); m_SplitterRight.ShowWindow (SW_SHOW); while (ChildWPtr) { GetClassName (ChildWPtr->m_hWnd, tchszClass, sizeof (tchszClass)); if (lstrcmpi (tchszClass, "MDIClient") == 0) { WndMDIClient = ChildWPtr; break; } ChildWPtr = pFrame->GetWindow (GW_HWNDNEXT); } ASSERT (ChildWPtr != NULL); */ CRect r, rMDIClient; WndMDIClient->GetWindowRect (rMDIClient); GetWindowRect (r); pFrame->ScreenToClient (rMDIClient); pFrame->ScreenToClient (r); m_Alignment = GetCurrentAlignment(); switch (m_Alignment) { case CBRS_ALIGN_LEFT: m_SplitterLeft.ShowWindow (SW_HIDE); m_SplitterTop.ShowWindow (SW_HIDE); m_SplitterBottom.ShowWindow(SW_HIDE); m_SplitterRight.ShowWindow (SW_SHOW); break; case CBRS_ALIGN_RIGHT: m_SplitterTop.ShowWindow (SW_HIDE); m_SplitterBottom.ShowWindow(SW_HIDE); m_SplitterRight.ShowWindow (SW_HIDE); m_SplitterLeft.ShowWindow (SW_SHOW); break; case CBRS_ALIGN_TOP: m_SplitterTop.ShowWindow (SW_HIDE); m_SplitterRight.ShowWindow (SW_HIDE); m_SplitterLeft.ShowWindow (SW_HIDE); m_SplitterBottom.ShowWindow(SW_SHOW); break; case CBRS_ALIGN_BOTTOM: m_SplitterBottom.ShowWindow(SW_HIDE); m_SplitterRight.ShowWindow (SW_HIDE); m_SplitterLeft.ShowWindow (SW_HIDE); m_SplitterTop.ShowWindow (SW_SHOW); break; default: m_SplitterTop.ShowWindow (SW_HIDE); m_SplitterBottom.ShowWindow(SW_HIDE); m_SplitterRight.ShowWindow (SW_HIDE); m_SplitterLeft.ShowWindow (SW_HIDE); break; } WndMDIClient->GetClientRect (rFrame); } if ((dwMode & LM_VERTDOCK) || (dwMode & LM_HORZDOCK)) { CRect r; /* if (WndMDIClient && (m_Alignment== CBRS_ALIGN_LEFT || m_Alignment == CBRS_ALIGN_RIGHT || m_Alignment== CBRS_ALIGN_TOP || m_Alignment== CBRS_ALIGN_BOTTOM)) WndMDIClient->GetClientRect (r); else pMain->GetClientRect (r); */ WndMDIClient->GetClientRect (r); if (dwMode & LM_STRETCH) { return CSize ((dwMode & LM_HORZ)? r.Width(): m_sizeDocked.cx, (dwMode & LM_HORZ)? m_sizeDocked.cy: r.Height()+8); } else { // CRect r; // CFrameWnd* pMain = (CFrameWnd*)AfxGetMainWnd(); // if (WndMDIClient && (m_Alignment== CBRS_ALIGN_LEFT || m_Alignment == CBRS_ALIGN_RIGHT || m_Alignment== CBRS_ALIGN_TOP || m_Alignment== CBRS_ALIGN_BOTTOM)) // WndMDIClient->GetClientRect (r); // else // pMain->GetClientRect (r); if (dwMode & LM_VERTDOCK) return CSize (m_sizeDocked.cx, r.Height()+8); else return CSize (r.Width()+8, m_sizeDocked.cy); return CSize (m_sizeDocked.cx, r.Height()); } } if (dwMode & LM_MRUWIDTH) { return m_sizeFloating; } if (dwMode & LM_LENGTHY) { return CSize (m_sizeFloating.cx, (m_bChangeDockedSize)? m_sizeFloating.cy = m_sizeDocked.cy = nLength: m_sizeFloating.cy = nLength); } else { return CSize (m_sizeFloating.cx = nLength, m_sizeFloating.cy); } }