BOOL CGridBtnCellBase::GetTextRect( LPRECT pRect) // i/o: i=dims of cell rect; o=dims of text rect { CGridCtrl* pGrid = GetGrid(); ASSERT( pGrid); CRect RectCell( *pRect); // any button images ASSERT( MAX_NBR_CTLS_INCELL > GetDrawCtlNbrMax() ); // whoa! CRect RectAry[ MAX_NBR_CTLS_INCELL]; const int iCtlNbr = GetDrawCtlNbr(); if( iCtlNbr > 0) { if( CalcDrawCtlRects( RectAry, // returns: CRects with coordinates // last entry has optional leftover rect // available for text, etc. MAX_NBR_CTLS_INCELL,// nbr of Rects in above array *pRect) ) // cell rectangle to work with { // allowable text area has shrunk up *pRect = RectAry[ iCtlNbr]; pRect->left += GetMargin(); pRect->right -= GetMargin(); } } // I've modified the starting point before passing to base return CGridCellBase::GetTextRect( pRect); }
// Returns the dimensions and placement of the checkbox in client coords. CRect CGridCellButton::GetButtonPlacement() { int nWidth = GetSystemMetrics(SM_CXHSCROLL); CRect place = m_Rect + CSize(GetMargin(), GetMargin()); place.right = place.left + nWidth; place.bottom = place.top + nWidth; /* for centering int nDiff = (place.Width() - nWidth)/2; if (nDiff > 0) { place.left += nDiff; place.right = place.left + nWidth; } nDiff = (place.Height() - nWidth)/2; if (nDiff > 0) { place.top += nDiff; place.bottom = place.top + nWidth; } */ if (m_Rect.Height() < nWidth + 2 * static_cast<int> (GetMargin())) { place.top = m_Rect.top + (m_Rect.Height() - nWidth) / 2; place.bottom = place.top + nWidth; } return place; }
void on_ok_button_clicked (GtkButton *button, gpointer user_data) { BJFLTDEVICE bjdev; BJFLTCOLORSYSTEM bjcolor; BJFLT_UISETUP uisetup; CNCLPAPERSIZE psize; IPCU ipc; gboolean change_item; short thick_value; // Get paper margin. GetMargin(&psize); SetBJFltDevice(&bjdev); // Save the thickness value. thick_value = GetCurrentnValue(CNCL_MESS_THICK); // Check Media type and Media size combination. if( CheckMediaSizeCombination(&bjdev, &change_item) != TRUE ) return; if( change_item ) { // If change the thickness, show alert. if( thick_value != GetCurrentnValue(CNCL_MESS_THICK) ) ShowLeverPositionAlert(); // Get paper margin. GetMargin(&psize); SetBJFltDevice(&bjdev); } SetBJFltColorSystem(&bjcolor); // Make uisetup data. SetUISetup(&uisetup); // Then prepare for IPC memcpy(&ipc.parm.bjfltdev, &bjdev, sizeof(BJFLTDEVICE)); memcpy(&ipc.parm.papersize, &psize, sizeof(CNCLPAPERSIZE)); memcpy(&ipc.parm.bjfltcolor, &bjcolor, sizeof(BJFLTCOLORSYSTEM)); memcpy(&ipc.parm.bjflt_uisetup, &uisetup, sizeof(BJFLT_UISETUP)); if( g_socketname != NULL ) { // client mode PutIPCData(&ipc); } gtk_main_quit(); }
void WebListBox::ResizeScrollBars(void) { if (mpHScroll) { WebRect r; r.Set(GetMargin() + GetBorder(), Height() - GetMargin() - GetBorder() - miSliderWidth - 1, Width() - (mpVScroll ? miSliderWidth : 0) - GetMargin() - GetBorder() - 1, Height() - GetMargin() - GetBorder() - 1); mpHScroll->Move(&r); WebRect vr; GetOptionsRect(&vr); mpHScroll->SetWindow(vr.Width()); mpHScroll->Invalidate(); } if (mpVScroll) { WebRect r; r.Set(Width() - 1 - GetMargin() - GetBorder() - miSliderWidth, GetMargin() + GetBorder(), Width() - 1 - GetMargin() - GetBorder(), Height() - 1 - (mpHScroll ? miSliderWidth : 0) - GetMargin() - GetBorder()); mpVScroll->Move(&r); WebRect vr; GetOptionsRect(&vr); mpVScroll->SetWindow(vr.Height()); mpVScroll->Invalidate(); } }
SimdVector3 ConvexTriangleMeshShape::LocalGetSupportingVertex(const SimdVector3& vec)const { SimdVector3 supVertex = LocalGetSupportingVertexWithoutMargin(vec); if ( GetMargin()!=0.f ) { SimdVector3 vecnorm = vec; if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON)) { vecnorm.setValue(-1.f,-1.f,-1.f); } vecnorm.normalize(); supVertex+= GetMargin() * vecnorm; } return supVertex; }
void ButtonFrameRenderer::DrawButton(Canvas &canvas, PixelRect rc, bool focused, bool pressed) const { const ButtonLook::StateLook &_look = focused ? look.focused : look.standard; canvas.DrawFilledRectangle(rc, _look.background_color); const unsigned margin = GetMargin(); if (margin < 4) { /* draw 1-pixel lines */ canvas.Select(pressed ? _look.dark_border_pen : _look.light_border_pen); for (unsigned i = 0; i < margin; ++i) canvas.DrawTwoLinesExact(rc.left + i, rc.bottom - 2 - i, rc.left + i, rc.top + i, rc.right - 2 - i, rc.top + i); canvas.Select(pressed ? _look.light_border_pen : _look.dark_border_pen); for (unsigned i = 0; i < margin; ++i) canvas.DrawTwoLinesExact(rc.left + 1 + i, rc.bottom - 1 - i, rc.right - 1 - i, rc.bottom - 1 - i, rc.right - 1 - i, rc.top + 1 + i); } else { /* at 4 pixels or more, it's more efficient to draw a filled polygon */ const RasterPoint p1[] = { RasterPoint(rc.left, rc.top), RasterPoint(rc.right, rc.top), RasterPoint(rc.right - margin, rc.top + margin), RasterPoint(rc.left + margin, rc.top + margin), RasterPoint(rc.left + margin, rc.bottom - margin), RasterPoint(rc.left, rc.bottom), }; canvas.SelectNullPen(); canvas.Select(pressed ? _look.dark_border_brush : _look.light_border_brush); canvas.DrawTriangleFan(p1, ARRAY_SIZE(p1)); const RasterPoint p2[] = { RasterPoint(rc.right, rc.bottom), RasterPoint(rc.right, rc.top), RasterPoint(rc.right - margin, rc.top + margin), RasterPoint(rc.right - margin, rc.bottom - margin), RasterPoint(rc.left + margin, rc.bottom - margin), RasterPoint(rc.left, rc.bottom), }; canvas.Select(pressed ? _look.light_border_brush : _look.dark_border_brush); canvas.DrawTriangleFan(p2, ARRAY_SIZE(p2)); } }
CSize CGridCellButton::GetCellExtent(CDC* pDC) { // Using SM_CXHSCROLL as a guide to the size of the checkbox int nWidth = GetSystemMetrics(SM_CXHSCROLL) + 2*GetMargin(); CSize cellSize = CGridCell::GetCellExtent(pDC); cellSize.cx += nWidth; cellSize.cy = max (cellSize.cy, nWidth); return cellSize; }
// i/o: i=dims of cell rect; o=dims of text rect BOOL CGridCellButton::GetTextRect( LPRECT pRect) { BOOL bResult = CGridCell::GetTextRect(pRect); if (bResult) { int nWidth = GetSystemMetrics(SM_CXHSCROLL) + 2*GetMargin(); pRect->left += nWidth; if (pRect->left > pRect->right) pRect->left = pRect->right; } return bResult; }
// Returns the dimensions and placement of the checkbox in client coords. CRect CGridCellCheck::GetCheckPlacement() { int nWidth = GetSystemMetrics(SM_CXHSCROLL); CRect place = m_Rect + CSize(GetMargin(), GetMargin()); place.right = place.left + nWidth; place.bottom = place.top + nWidth; /* for centering int nDiff = (place.Width() - nWidth)/2; if (nDiff > 0) { place.left += nDiff; place.right = place.left + nWidth; } nDiff = (place.Height() - nWidth)/2; if (nDiff > 0) { place.top += nDiff; place.bottom = place.top + nWidth; } */ return place; }
/***************************************************************************** For mouse hit test want to know if user clicked on the "+" / "-" box. Also for drawing the box *****************************************************************************/ void CGridTreeCellBase::TreeGetBoxRelCoords(CRect* apRect) // returns: relative coordinates { ASSERT( apRect != NULL); ASSERT( m_pTreeColumn != NULL); int iMargin = GetMargin(); int iDefTreeIndent = m_pTreeColumn->GetDefTreeIndent(); unsigned char ucLevel = GetLevel(); if( ucLevel < 1) return; apRect->left = iMargin + (iDefTreeIndent * ( ucLevel - 1) ) + TREE_BOX_MARGIN; apRect->right = apRect->left + iDefTreeIndent - TREE_BOX_MARGIN; apRect->top = iMargin; apRect->bottom = apRect->top + iDefTreeIndent - (2*TREE_BOX_MARGIN); }
CSize CGridBtnCellBase::GetCellExtent(CDC* pDC) { CSize sizeBase = CGridCellBase::GetCellExtent(pDC); // any button images? int iCtlNbr = GetDrawCtlNbr(); if( iCtlNbr > 0) { int iDefaultWidth = sizeBase.cy; int iWidthTotal = 0; int iWidth; CSize SizeText; CFont* pOldFont = pDC->SelectObject(GetFontObject()); CRect rectText; for( int i1=0; i1 < iCtlNbr; i1++) { iWidth = GetDrawCtlWidth( i1); if( iWidth <= 0) { const char* pszBtnText = GetDrawCtlBtnText( i1); if( pszBtnText == NULL) { iWidth = iDefaultWidth; } else { // use width of text in button as a gauge rectText.SetRectEmpty(); pDC->DrawText( pszBtnText, strlen( pszBtnText), &rectText, GetFormat() | DT_CALCRECT); iWidth = rectText.Width(); } } iWidthTotal += iWidth; } pDC->SelectObject(pOldFont); sizeBase += CSize( iWidthTotal + 4*GetMargin(), 0); } return sizeBase; }
void PolyhedralConvexShape::CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia) { //not yet, return box inertia float margin = GetMargin(); SimdTransform ident; ident.setIdentity(); SimdVector3 aabbMin,aabbMax; GetAabb(ident,aabbMin,aabbMax); SimdVector3 halfExtents = (aabbMax-aabbMin)*0.5f; SimdScalar lx=2.f*(halfExtents.x()+margin); SimdScalar ly=2.f*(halfExtents.y()+margin); SimdScalar lz=2.f*(halfExtents.z()+margin); const SimdScalar x2 = lx*lx; const SimdScalar y2 = ly*ly; const SimdScalar z2 = lz*lz; const SimdScalar scaledmass = mass * 0.08333333f; inertia = scaledmass * (SimdVector3(y2+z2,x2+z2,x2+y2)); }
void ItemsControl::OnInitialized() { __super::OnInitialized(); // 加入可视树 AddVisualChild(_scrollHost.get()); AddLogicalChild(_scrollHost.get()); _itemsHost->WriteFlag(CoreFlags::IsComposition, true); _scrollHost->WriteFlag(CoreFlags::IsComposition, true); _scrollHost->BeginInit(); _scrollHost->EndInit(); _scrollHost->SetHorizontalAlignment(HoriAlignment::Stretch); _scrollHost->SetVerticalAlignment(VertAlignment::Stretch); _scrollHost->SetMargin(GetMargin()); _scrollHost->SetFocusable(false); _itemsHost->SetFocusable(false); _itemsHost->SetPadding(GetPadding()); SetPadding(suic::Rect()); }
void MultiButton::Lay(Rect& r) { int border, lx, rx; bool frm = Metrics(border, lx, rx); bool left = false; bool right = false; for(int i = 0; i < button.GetCount(); i++) { SubButton& b = button[i]; int cx = 0; int x = 0; GetPos(b, lx, rx, x, cx); (b.left ? left : right) = true; } if(ComplexFrame()) { r.right = r.left + rx; r.left += lx; } else if(frm) { Rect m = GetMargin(); r = Rect(r.left + max(lx, m.left), r.top + m.top, min(rx, r.right - m.right), r.bottom - m.bottom); } else { Rect m = style->margin; r = Rect(r.left + max(lx, m.left), r.top + m.top, min(rx, r.right - m.right), r.bottom - m.bottom); if(!IsTrivial() || style->trivialsep) { if(left) r.left++; if(right) r.right--; } } if(!IsNull(valuecy)) { r.top += (r.GetHeight() - valuecy) / 2; r.bottom = r.top + valuecy; } }
void CBCGPToolTipCtrl::OnPaint() { if (m_Params.m_bBallonTooltip) { CToolTipCtrl::OnPaint (); return; } CPaintDC dcPaint(this); // device context for painting CBCGPMemDC memDC (dcPaint, this); CDC* pDC = &memDC.GetDC (); CRect rect; GetClientRect (rect); CRect rectMargin; GetMargin (rectMargin); CRect rectText = rect; rectText.DeflateRect (rectMargin); rectText.DeflateRect (m_ptMargin.x, m_ptMargin.y); COLORREF clrLine = m_Params.m_clrBorder == (COLORREF)-1 ? ::GetSysColor (COLOR_INFOTEXT) : m_Params.m_clrBorder; COLORREF clrText = m_Params.m_clrText == (COLORREF)-1 ? ::GetSysColor (COLOR_INFOTEXT) : m_Params.m_clrText; //----------------- // Fill background: //----------------- OnFillBackground (pDC, rect, clrText, clrLine); CPen penLine (PS_SOLID, 1, clrLine); CPen* pOldPen = pDC->SelectObject (&penLine); //------------- // Draw border: //------------- OnDrawBorder (pDC, rect, clrLine); //----------- // Draw icon: //----------- if (m_sizeImage != CSize (0, 0) && m_Params.m_bDrawIcon) { CRect rectImage = rectText; rectImage.right = rectImage.left + m_sizeImage.cx; rectImage.bottom = rectImage.top + m_sizeImage.cy; OnDrawIcon (pDC, rectImage); rectText.left += m_sizeImage.cx + m_ptMargin.x; } pDC->SetBkMode (TRANSPARENT); pDC->SetTextColor (clrText); //------------ // Draw label: //------------ int nTextHeight = OnDrawLabel (pDC, rectText, FALSE).cy; //------------------------------ // Draw separator + description: //------------------------------ if (!m_strDescription.IsEmpty () && m_Params.m_bDrawDescription) { CRect rectDescr = rectText; rectDescr.top += nTextHeight + 3 * m_ptMargin.y / 2; if (m_Params.m_bDrawSeparator) { OnDrawSeparator (pDC, rectDescr.left, rectDescr.right, rectDescr.top - m_ptMargin.y / 2); } OnDrawDescription (pDC, rectDescr, FALSE); } pDC->SelectObject (pOldPen); }
//********************************************************************** void CBCGPToolTipCtrl::OnShow(NMHDR* /*pNMHDR*/, LRESULT* pResult) { *pResult = 0; if (m_Params.m_bVislManagerTheme) { CBCGPVisualManager::GetInstance ()->GetToolTipParams (m_Params); m_Params.m_bVislManagerTheme = TRUE; } if (m_Params.m_bBallonTooltip) { return; } CPoint ptCursor; ::GetCursorPos (&ptCursor); GetHotButton (); m_sizeImage = m_Params.m_bDrawIcon ? GetIconSize () : CSize (0, 0); m_ptMargin = CPoint (6, 4); m_ptMargin.x += m_Params.m_nPaddingX; m_ptMargin.y += m_Params.m_nPaddingY; CRect rectMargin; GetMargin (rectMargin); CRect rectText; GetClientRect (rectText); CClientDC dc (this); CSize sizeText = OnDrawLabel (&dc, rectText, TRUE); int cx = sizeText.cx; int cy = sizeText.cy; CSize sizeDescr (0, 0); if (!m_Params.m_bDrawDescription || m_strDescription.IsEmpty ()) { cy = max (cy, m_sizeImage.cy); } else { sizeDescr = OnDrawDescription (&dc, rectText, TRUE); cy += sizeDescr.cy + 2 * m_ptMargin.y; cx = max (cx, sizeDescr.cx); cy = max (cy, m_sizeImage.cy); } if (m_sizeImage.cx > 0 && m_Params.m_bDrawIcon) { cx += m_sizeImage.cx + m_ptMargin.x; } cx += 2 * m_ptMargin.x; cy += 2 * m_ptMargin.y; int nFixedWidth = GetFixedWidth (); if (nFixedWidth > 0 && sizeDescr != CSize (0, 0)) { cx = max (cx, nFixedWidth); } CRect rectWindow; GetWindowRect (rectWindow); int x = rectWindow.left; int y = rectWindow.top; if (m_ptLocation != CPoint (-1, -1)) { x = m_ptLocation.x; y = m_ptLocation.y; *pResult = 1; } CRect rectScreen; MONITORINFO mi; mi.cbSize = sizeof (MONITORINFO); if (GetMonitorInfo (MonitorFromPoint (rectWindow.TopLeft (), MONITOR_DEFAULTTONEAREST), &mi)) { rectScreen = mi.rcWork; } else { ::SystemParametersInfo (SPI_GETWORKAREA, 0, &rectScreen, 0); } int nBottom = max ( ptCursor.y + cy + ::GetSystemMetrics (SM_CYCURSOR), y + cy + 2); if (nBottom > rectScreen.bottom) { y = ptCursor.y - cy - 1; #ifndef BCGP_EXCLUDE_RIBBON if (m_pRibbonButton != NULL && m_ptLocation != CPoint (-1, -1)) { ASSERT_VALID (m_pRibbonButton); CBCGPRibbonBar* pRibbon = m_pRibbonButton->GetTopLevelRibbonBar (); if (pRibbon->GetSafeHwnd () != NULL) { CRect rectRibbon; pRibbon->GetWindowRect (rectRibbon); y = rectRibbon.top - cy; } } #endif *pResult = 1; } if (x + cx + 2 > rectScreen.right) { if ((*pResult) == 1) // Y has been changed { x = ptCursor.x - cx - 1; } else { x = rectScreen.right - cx - 1; *pResult = 1; } } if ((*pResult) == 1) { SetWindowPos (NULL, x, y, cx, cy, SWP_NOZORDER | SWP_NOACTIVATE); } else { SetWindowPos (NULL, -1, -1, cx, cy, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); } m_sizeCornerRadius = CBCGPVisualManager::GetInstance()->GetSystemToolTipCornerRadius(this); SetWindowPos (&wndTop, -1, -1, -1, -1, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOSIZE | SWP_DRAWFRAME); }
/***************************************************************************** Determines bounding rectangle to draw a button in a cell. Used to draw cells and for mouse hit testing. If a fixed-size control can't fit within the cell, the control will shrink in the required x and / or y dimension. I do this because I'm not using a clipping region when I display the cell -- that would be a better solution. *****************************************************************************/ BOOL CGridBtnCellBase::CalcDrawCtlRects(CRect* apRect, // returns: CRects with coordinates // last entry has optional leftover rect // available for text, etc. int aiNbrRectEntries, // nbr of Rects in above array const CRect& arRectCell)// cell rectangle to work with // returns: success / fail { ASSERT( apRect != NULL); if( aiNbrRectEntries < GetDrawCtlNbrMax() ) { ASSERT( FALSE); // need to allow for leftover rect return FALSE; } const int iCtlNbr = GetDrawCtlNbr(); if( iCtlNbr <= 0) return FALSE; int i1, i2; int iSpinBoxDownIdx = -1; // can have zero or 1 spin box -- no more // identifies placment of down arrow of the spin box int iWidth = 0; CTL_ALIGN CtlAlign; UINT uiType; UINT uiState; CRect* pRectSav = apRect; // calculate the width layout of buttons by examining // all of them and noting important info int iFixedSum = 0; int iSizeToFitCount = 0; for( i1=0; i1 < iCtlNbr; i1++) { CtlAlign = GetDrawCtlAlign( i1); if( CtlAlign == CTL_ALIGN_CENTER) { // forget all calculations if any are centered, all controls // just overwrite each other and expand to fit cell for( i2=0; i2 < iCtlNbr; i2++) { apRect->operator=( arRectCell); // copy initial rectangle apRect++; } apRect->operator=( CRect(0,0,0,0) ); // no text leftover return TRUE; } iWidth = GetDrawCtlWidth( i1); if( iWidth > 0) iFixedSum += iWidth; else iSizeToFitCount++; // spin box rectangles are stacked on top of each other // thus, avoid doubling spin box width if( iSpinBoxDownIdx < 0) { uiState = GetDrawCtlState( i1); if( GetDrawCtlType( i1) == DFC_SCROLL && !( uiState & (DFCS_SCROLLCOMBOBOX | DFCS_SCROLLDOWN | DFCS_SCROLLLEFT | DFCS_SCROLLRIGHT | DFCS_SCROLLSIZEGRIP) ) ) // checking for DFCS_SCROLLUP // but it is not a bit, it is 0x0! { if( i1 + 1 < iCtlNbr) { // at least 1 more -- see if we got spin box match if( GetDrawCtlType( i1 + 1) == DFC_SCROLL && ( GetDrawCtlState( i1 + 1) & DFCS_SCROLLDOWN) ) { // it's a spin box i1++; // skip looking at next control iSpinBoxDownIdx = i1; } } } } } int iSizeToFitWidth = 0; int iFitWidthsTotal = arRectCell.Width() - iFixedSum; if( iSizeToFitCount > 0) { iSizeToFitWidth = iFitWidthsTotal / iSizeToFitCount; } int iSizeToFitCountWrk = iSizeToFitCount; int iWidthSoFar = 0; for( i1=0; i1 < iCtlNbr; i1++) { if( iSpinBoxDownIdx == i1) { // skip down arrow of spin box for calculations apRect++; continue; } apRect->operator=( arRectCell); // copy initial rectangle apRect->left += iWidthSoFar; apRect->right = apRect->left; iWidth = GetDrawCtlWidth( i1); if( iWidth > 0) iWidthSoFar += iWidth; // fixed width else { iSizeToFitCountWrk--; // found another one // may shrink width if control is square -- saves screen real-estate uiType = GetDrawCtlType( i1); uiState = GetDrawCtlState( i1); BOOL bIsRectangle = ( uiType == DFC_BUTTON && (uiState & DFCS_BUTTONPUSH) == DFCS_BUTTONPUSH); // all other buttons are square if( !bIsRectangle && arRectCell.Height() < iSizeToFitWidth) { // it is square -- make width the cell height iWidthSoFar += arRectCell.Height(); // recalulate size to fit iFitWidthsTotal -= arRectCell.Height(); if( iSizeToFitCountWrk > 0) iSizeToFitWidth = iFitWidthsTotal / iSizeToFitCountWrk; } else { iWidthSoFar += iSizeToFitWidth; iFitWidthsTotal -= iSizeToFitWidth; } } apRect->right = iWidthSoFar + arRectCell.left; apRect++; } if( iFitWidthsTotal < (int)GetMargin() ) { // no leftover rectangle available apRect->SetRectEmpty(); } else { // calc leftover rectangle apRect->operator=( arRectCell); apRect->left += iWidthSoFar; } // I've been assuming that all controls are left-aligned. Programmer // may have defined controls as right-aligned, too. Note that left // and right controls can be declared in the array in any order // Ok, here's the kludge. Since I know that the heights of each control // are the same, use these unused height values in the CRect array to // help me calculate the proper order of the widths apRect = pRectSav; int iSavedTop = arRectCell.left; // seed first result for( i1=0; i1 < iCtlNbr; i1++) { if( iSpinBoxDownIdx == i1) { // skip down arrow of spin box for calculations apRect++; continue; } // analyzing just Left-aligned controls CtlAlign = GetDrawCtlAlign( i1); ASSERT( CtlAlign != CTL_ALIGN_CENTER); // should've taken care of if( CtlAlign == CTL_ALIGN_LEFT) { apRect->top = iSavedTop; iSavedTop += apRect->Width(); apRect->bottom = iSavedTop; } apRect++; } // text rectangle appears between left and right aligned controls // and width has been saved in last rectangle apRect = pRectSav + iCtlNbr; apRect->top = iSavedTop + GetMargin(); // put some margin so doesn't overwrite iSavedTop += apRect->Width(); apRect->bottom = iSavedTop; iSavedTop += GetMargin(); // some more margin... apRect = pRectSav; for( i1=0; i1 < iCtlNbr; i1++) { if( iSpinBoxDownIdx == i1) { // skip down arrow of spin box for calculations apRect++; continue; } // finally, look at right-aligned controls CtlAlign = GetDrawCtlAlign( i1); if( CtlAlign == CTL_ALIGN_RIGHT) { apRect->top = iSavedTop; iSavedTop += apRect->Width(); apRect->bottom = iSavedTop; } apRect++; } // flip everything back and we're done apRect = pRectSav; for( i1=0; i1 <= iCtlNbr; i1++) // note that I'll get leftover rect, too { apRect->left = apRect->top; if( apRect->left < arRectCell.left ) apRect->left = arRectCell.left; // can't go beyond cell if( apRect->left > arRectCell.right ) apRect->left = arRectCell.right; apRect->right = apRect->bottom; if( apRect->right > arRectCell.right) apRect->right = arRectCell.right; if( apRect->right < arRectCell.left) apRect->right = arRectCell.left; apRect->bottom = arRectCell.bottom; apRect->top = arRectCell.top; apRect++; } // but wait -- special calculations for the spin box if( iSpinBoxDownIdx >= 0) { CRect* pRectSpinUp = pRectSav + iSpinBoxDownIdx - 1; apRect = pRectSav + iSpinBoxDownIdx; apRect->left = pRectSpinUp->left; apRect->right = pRectSpinUp->right; apRect->bottom = pRectSpinUp->bottom; int iHalf = apRect->top + ( (apRect->bottom - apRect->top) / 2); apRect->top = iHalf; pRectSpinUp->bottom = iHalf; } return TRUE; }
CSize CGridCellCheck::GetCellExtent(CDC* pDC) { // Using SM_CXHSCROLL as a guide to the size of the checkbox int nWidth = GetSystemMetrics(SM_CXHSCROLL) + 2*GetMargin(); return CGridCell::GetCellExtent(pDC) + CSize(nWidth, nWidth); }
void WebListBox::DrawThisOnly (DISPLAY_INT x, DISPLAY_INT y, WebGraphics *gc) { WebRect visibleRegion, oldClip, frame(mRect); CalculateTextMetrics(gc); SetupScrollBars(gc); WebColor hilite, lolite, black, blue, white; hilite = white = gc->RGBToColor(0xff, 0xff, 0xff); lolite = black = gc->RGBToColor(0, 0, 0); blue = gc->RGBToColor(0, 0, 0xff); frame.MoveTo(x,y); if (mFlags & DISPLAY_FLAG_FOCUS && !(mStyle & LISTBOX_STYLE_NOFOCUSFRAME)) { gc->Rectangle(&frame, black, black, WEBC_FALSE); } if (mStyle & LISTBOX_STYLE_NOT3D) { hilite = lolite = black; } frame.top += GetMargin(); frame.left += GetMargin(); frame.bottom -= GetMargin(); frame.right -= GetMargin(); // gc->StartBuffer(); gc->Rectangle(&frame, GetBgColor(gc), GetBgColor(gc), WEBC_TRUE); DrawFrame(&frame, gc); DISPLAY_INT windowX, windowY; GetScrollOffset(&windowX, &windowY); long firstVisible = windowY / (miTextHeight + GetSpacing()) - 1; if (firstVisible < 0) firstVisible = 0; gc->GetClip(&oldClip); GetOptionsRect(&visibleRegion); visibleRegion.Shift(x,y); WebRect clip(visibleRegion); clip.And(&oldClip); gc->SetClip(&clip); WEBC_BOOL invert; int offset = firstVisible * (miTextHeight + GetSpacing()); for (int t = firstVisible; t < miNumOptions; t++) { invert = ( ((t == GetSelected()) && !(mStyle & LISTBOX_STYLE_FOLLOW_MOUSE)) || ((t == miMouseOver) && (mStyle & LISTBOX_STYLE_FOLLOW_MOUSE)) ); if (invert) { PresetWebRect r (visibleRegion.left - windowX, visibleRegion.top + offset - windowY, visibleRegion.right - windowX, visibleRegion.top + offset - windowY + miTextHeight - 1); gc->Rectangle(&r, GetSelectColor(gc), GetSelectColor(gc), WEBC_TRUE); } gc->Text(visibleRegion.left - windowX, visibleRegion.top + offset - windowY, mppOption[t], (invert? GetBgColor(gc) : GetTextColor(gc)), blue, WEBC_FALSE, mFont.GetFont()); offset += miTextHeight + GetSpacing(); } gc->SetClip(&oldClip); // gc->EndBuffer(); }
BOOL CGridBtnCellBase::DrawBtnCell(CDC* pDC, int /* nRow */, int /* nCol */, CRect* prect, BOOL /* bEraseBkgnd */) { CGridCtrl* pGrid = GetGrid(); if (!pGrid || !pDC) return FALSE; if( prect->Width() <= 0 || prect->Height() <= 0) // prevents imagelist item from drawing even return FALSE; // though cell is hidden int nSavedDC = pDC->SaveDC(); // draw any button images ASSERT( MAX_NBR_CTLS_INCELL > GetDrawCtlNbrMax() ); // whoa! const int iCtlNbr = GetDrawCtlNbr(); CRect RectAry[ MAX_NBR_CTLS_INCELL]; if( iCtlNbr > 0) { if( GetState() & GVIS_SELECTED || GetState() & GVIS_DROPHILITED ) { // draw the rectangle around the grid -- // we may be filling cells with controls pDC->SelectStockObject(BLACK_PEN); pDC->SelectStockObject(NULL_BRUSH); pDC->Rectangle(*prect); } pDC->SetBkMode(TRANSPARENT); prect->DeflateRect( GetMargin(), 0); CFont* pOldFont = pDC->SelectObject(GetFontObject()); if( CalcDrawCtlRects( RectAry, // returns: CRects with coordinates // last entry has optional leftover rect // available for text, etc. MAX_NBR_CTLS_INCELL,// nbr of Rects in above array *prect) ) // cell rectangle to work with { for( int i1=0; i1 < iCtlNbr; i1++) { UINT uiType = GetDrawCtlType( i1); UINT uiState = GetDrawCtlState( i1); pDC->DrawFrameControl( RectAry[ i1], uiType, uiState); // if button has text, draw it, too const char* pszBtnText = GetDrawCtlBtnText( i1); if( pszBtnText != NULL) { COLORREF ColorCurrent = pDC->GetTextColor(); if( uiState & DFCS_INACTIVE) { // button is grayed-out // draw the text so that it matches MS's look RectAry[ i1].OffsetRect( 1, 1); pDC->SetTextColor( RGB( 255,255,255) ); pDC->DrawText( pszBtnText, -1, RectAry[ i1], DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS); RectAry[ i1].OffsetRect( -1, -1); pDC->SetTextColor( ::GetSysColor(COLOR_GRAYTEXT)); } else { pDC->SetTextColor( ::GetSysColor(COLOR_BTNTEXT)); } pDC->DrawText( pszBtnText, -1, RectAry[ i1], DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS); pDC->SetTextColor( ColorCurrent); } } // allowable text area has shrunk up *prect = RectAry[ iCtlNbr]; } pDC->SelectObject(pOldFont); // maybe there's nothing left to draw if( prect->Width() <= 0) { pDC->RestoreDC(nSavedDC); return TRUE; } } pDC->RestoreDC(nSavedDC); return TRUE; }
// This hack allows you to determine the height that a cell should be in order to display // stuff properly in the given width. CSize CGridCellMultiLine::GetTextExtentEx(int width, LPCTSTR szText, CDC* pDC /*= NULL*/) { CGridCtrl* pGrid = GetGrid(); ASSERT(pGrid); BOOL bReleaseDC = FALSE; if (pDC == NULL) { pDC = pGrid->GetDC(); if (!pDC) { CGridDefaultCell* pDefCell = (CGridDefaultCell*) GetDefaultCell(); ASSERT(pDefCell); return CSize(pDefCell->GetWidth(), pDefCell->GetHeight()); } bReleaseDC = TRUE; } CFont *pOldFont = NULL, *pFont = GetFontObject(); if (pFont) pOldFont = pDC->SelectObject(pFont); CSize size; int nFormat = GetFormat(); TEXTMETRIC tm; pDC->GetTextMetrics(&tm); int textWidth = width - (4*GetMargin ()); // corrects the bug if resizing column gives a text width smaller than (4*Getmargin()) if (textWidth <= 0) { textWidth = 1; } // If the cell is a multiline cell, then use the width of the cell // to get the height if ((nFormat & DT_WORDBREAK) && !(nFormat & DT_SINGLELINE)) { CRect rect; rect.SetRect(0, 0, textWidth, 0); pDC->DrawText(szText, -1, rect, nFormat | DT_CALCRECT); size.cx = rect.Width (); size.cy = rect.Height (); } else size = pDC->GetTextExtent(szText, _tcslen(szText)); size.cx += (tm.tmOverhang); if (pOldFont) pDC->SelectObject(pOldFont); size += CSize(4*GetMargin(), 2*GetMargin()); // Kludge for vertical text LOGFONT *pLF = GetFont(); if (pLF->lfEscapement == 900 || pLF->lfEscapement == -900) { int nTemp = size.cx; size.cx = size.cy; size.cy = nTemp; size += CSize(0, 4*GetMargin()); } if (bReleaseDC) pGrid->ReleaseDC(pDC); return size; }
void MultiButton::Paint(Draw& w) { Size sz = GetSize(); int border, lx, rx; bool frm = Metrics(border, lx, rx); int mst = ChState(MAIN); if(frm && !nobg) ChPaint(w, sz, style->edge[style->activeedge ? mst : 0]); bool left = false; bool right = false; for(int i = 0; i < button.GetCount(); i++) { SubButton& b = button[i]; int st = ChState(i); int x = 0, cx = 0; GetPos(b, lx, rx, x, cx); bool dopaint = true; Value v = b.left ? left ? style->lmiddle[st] : style->left[st] : right ? style->rmiddle[st] : style->right[st]; if(!nobg) { if(ComplexFrame()) ChPaint(w, x, border, cx, sz.cy - 2 * border, style->simple[st]); else if(frm) { if(IsTrivial() && style->usetrivial) dopaint = false; ChPaint(w, x, border, cx, sz.cy - 2 * border, dopaint ? v : style->trivial[st]); } else { w.Clip(x, 0, cx, sz.cy); ChPaint(w, sz, style->look[Frame() ? mst : st]); if(IsNull(v) || !Frame()) { if((!IsTrivial() || style->trivialsep) && IsEnabled()) { if(b.left) { if(left) ChPaint(w, x, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep1); ChPaint(w, x + cx - 1, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep2); } else { ChPaint(w, x, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep1); if(right) ChPaint(w, x + cx - 1, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep2); } } } else ChPaint(w, x, 0, cx, sz.cy, v); w.End(); } } if(dopaint) { Size tsz = GetTextSize(b.label, StdFont()); Image m = tsz.cx > 0 ? b.img : (Image)Nvl(b.img, CtrlsImg::DA()); Size isz = m.GetSize(); Point p = (st == CTRL_PRESSED) * style->pressoffset; p.x += x + (cx - isz.cx - tsz.cx - (tsz.cx > 0 && isz.cx > 0 ? LB_IMAGE : 0)) / 2; p.y += (sz.cy - isz.cy) / 2; if(b.left) { if(!left) p.x += style->loff; } else if(!right) p.x += style->roff; if(b.monoimg || IsNull(b.img)) w.DrawImage(p.x, p.y, m, frm ? style->fmonocolor[st] : style->monocolor[st]); else w.DrawImage(p.x, p.y, m); if(tsz.cx > 0) { if(isz.cx > 0) p.x += isz.cx + LB_IMAGE; w.DrawText(p.x, (sz.cy - tsz.cy) / 2, b.label); } } (b.left ? left : right) = true; } Rect r, cr; cr = GetSize(); cr.left = lx; cr.right = rx; Color text = SColorLabel(); Color paper = Null; if(!nobg) { if(ComplexFrame()) { r = cr; paper = HasFocus() ? SColorHighlight() : SColorPaper(); if(HasFocus()) text = SColorHighlightText(); w.DrawRect(r, paper); } else if(frm) { Rect m = GetMargin(); r = Rect(max(lx, m.left), m.top, min(rx, sz.cx - m.right), sz.cy - m.bottom); Color paper; if(mst == CTRL_HOT && !IsTrivial()) paper = Blend(SColorHighlight, SColorPaper, 235); else if(mst == CTRL_PRESSED && !IsTrivial()) paper = Blend(SColorHighlight, SColorFace, 235); else if(HasFocus()) { paper = SColorHighlight(); text = SColorHighlightText(); } else paper = SColorPaper(); w.DrawRect(r, paper); cr = r; } else { w.Clip(lx, 0, rx - lx, sz.cy); ChPaint(w, sz, style->look[mst]); Rect m = style->margin; r = Rect(max(lx, m.left), m.top, min(rx, sz.cx - m.right), sz.cy - m.bottom); if(!IsTrivial() || style->trivialsep) { if(left) { r.left++; if(IsEnabled()) ChPaint(w, lx, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep1); } if(right) { if(IsEnabled()) ChPaint(w, rx - 1, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep2); r.right--; } } w.End(); cr = r; } } cr.left++; Rect clr = cr; if(!IsNull(valuecy)) { cr.top += (cr.GetHeight() - valuecy + 1) / 2; cr.bottom = cr.top + valuecy; } Value v = convert->Format(value); bool f = HasFocus() && !push && frm; if(cr.left < cr.right && display) { w.Clip(clr); display->Paint(w, cr, v, IsShowEnabled() ? text : SColorDisabled, paper, f ? Display::CURSOR : Display::FOCUS|Display::CURSOR); w.End(); } if(!frm && HasFocus()) DrawFocus(w, r); }
void WebListBox::GetContentRect(WebRect *rect) { DISPLAY_INT pad = GetMargin() + GetPadding() + GetBorder(); rect->Set(pad, pad, Width() - pad - 1, Height() - pad - 1); }