LONG CLayoutRuleRelativeControl::Apply(CWindow wndLayout, UINT nDirection, const CRect& rcLayout) const { CWindow wndCtrl = wndLayout.GetDlgItem( m_nCtrlID ); ATLASSERT( ::IsWindow(wndCtrl) ); CRect rcPadding( 0, 0, m_nPadding, m_nPadding ); ::MapDialogRect( wndLayout, rcPadding ); HDWP hDwp = (HDWP) GetProp( wndLayout, MAKEINTATOM(g_atomPropHDWP) ); CRect rcCtrl; GetNewWindowRect( wndCtrl, hDwp, rcCtrl ); switch ( this->m_nDirection ) { case LAYOUT_DIRECTION_LEFT: ATLASSERT( nDirection == LAYOUT_DIRECTION_LEFT || nDirection == LAYOUT_DIRECTION_RIGHT ); return rcCtrl.left - rcPadding.Width(); case LAYOUT_DIRECTION_TOP: ATLASSERT( nDirection == LAYOUT_DIRECTION_TOP || nDirection == LAYOUT_DIRECTION_BOTTOM ); return rcCtrl.top - rcPadding.Height(); case LAYOUT_DIRECTION_RIGHT: ATLASSERT( nDirection == LAYOUT_DIRECTION_LEFT || nDirection == LAYOUT_DIRECTION_RIGHT ); return rcCtrl.right + rcPadding.Width(); case LAYOUT_DIRECTION_BOTTOM: ATLASSERT( nDirection == LAYOUT_DIRECTION_TOP || nDirection == LAYOUT_DIRECTION_BOTTOM ); return rcCtrl.bottom + rcPadding.Height(); default: ATLASSERT(FALSE); return 0; } }
void CMDITabsDialogBar::DrawItem(LPDRAWITEMSTRUCT pdis) { CRect rc = pdis->rcItem; int nTabIndex = pdis->itemID; bool fSelected = (nTabIndex == GetCurSel()); ODA_DRAWENTIRE; char label[64]; TCITEM tci; tci.mask = TCIF_TEXT | TCIF_PARAM; tci.pszText = label; tci.cchTextMax = ARRAYSIZE(label); if (GetItem(nTabIndex, &tci)) { CMDITabChildWnd *pActive = reinterpret_cast<CMDITabChildWnd*>(tci.lParam); CDC dc; dc.Attach(pdis->hDC); int iIndex = _GetBitmapIndex(pActive->GetTabType()); CExtBitmap &bitmapToUse = fSelected ? _tabBitmap[iIndex] : _tabBitmapNS[iIndex]; CRect rcSrc(CPoint(0, 0), bitmapToUse.GetSize()); //CRect rcPadding(2, 2, 2, 2); CRect rcPadding(0, 0, 0, 0); bitmapToUse.AlphaBlendSkinParts(pdis->hDC, rc, rcSrc, rcPadding, /*__EXT_BMP_FLAG_PREMULTIPLIED_RGB_CHANNELS |*/ CExtBitmap::__EDM_STRETCH, true, true, 0xFF); // Use a different font decoration depending on if this is the most recent version of this item. bool fNotMostRecent = false; CDocument *pDocAny = pActive->GetActiveDocument(); if (pDocAny && pDocAny->IsKindOf(RUNTIME_CLASS(CResourceDocument))) { CResourceDocument *pDoc = static_cast<CResourceDocument*>(pDocAny); fNotMostRecent = !theApp._resourceRecency.IsResourceMostRecent(pDoc); } if (fNotMostRecent) { // Draw a diagonal line across the thing. dc.MoveTo(rc.TopLeft()); dc.LineTo(rc.BottomRight()); } rc.OffsetRect(4, 1); // indent COLORREF crText = RGB(0, 0, 0); // g_PaintManager->PAINTPUSHBUTTONDATA::m_clrForceTextNormal; // green in release, black in debug! int nOldText = dc.SetTextColor(crText); int nOldBk = dc.SetBkMode(TRANSPARENT); dc.DrawText(tci.pszText, -1, &rc, DT_SINGLELINE); dc.SetBkMode(nOldBk); dc.SetTextColor(nOldText); dc.Detach(); } }
HRESULT CCUILayoutHorizontal::Layout(IUIFrame* pHostFrame) { DEBUG_ASSERT(pHostFrame) ; IF_RETURN(NULL == pHostFrame, E_INVALIDARG) ; CSize szContainer(0, 0) ; pHostFrame->GetSize(&szContainer) ; CRect rcPadding(0, 0, 0, 0) ; pHostFrame->GetPadding(&rcPadding) ; CRect rcExtPadding(0, 0, 0, 0) ; CComQIPtr<IUIFrameInternal> pFrameInternal = pHostFrame ; if (pFrameInternal) { pFrameInternal->GetExtPadding(&rcExtPadding) ; } CRect rcContainer(0, 0, 0, 0) ; rcContainer.left = rcPadding.left + rcExtPadding.left ; rcContainer.top = rcPadding.top + rcExtPadding.top ; rcContainer.right = szContainer.cx - rcPadding.right - rcExtPadding.right ; rcContainer.bottom = szContainer.cy - rcPadding.bottom - rcExtPadding.bottom ; INT nCurrentLayout = 0, nUsedSpace = 0 ; if (LAYOUT::ORIENTATION_NEAR == this->m_nOrientation) { nCurrentLayout = rcPadding.left + rcExtPadding.left ; } else if (LAYOUT::ORIENTATION_FAR == this->m_nOrientation) { nCurrentLayout = szContainer.cx - rcPadding.right - rcExtPadding.right ; } LONG lChildrenCount = 0 ; pHostFrame->GetChildrenCount(&lChildrenCount) ; for (INT i = 0; i < lChildrenCount; ++i) { CComPtr<IUIElement> pElement ; pHostFrame->GetChildByIndex(i, &pElement) ; CComQIPtr<IUIFrame> pFrameChild = pElement ; CComQIPtr<IUIFrameInternal> pFrameInternal = pElement ; IF_CONTINUE(NULL == pFrameChild || NULL == pFrameInternal) ; BOOL bHidden = FALSE ; pFrameChild->GetHidden(&bHidden) ; IF_CONTINUE(bHidden) ; BOOL bFloat = FALSE ; pFrameChild->GetFloat(&bFloat) ; IF_CONTINUE(bFloat) ; CRect rcChildMargin(0, 0, 0, 0) ; pFrameChild->GetMargin(&rcChildMargin) ; BOOL bChildHeightAsParent = FALSE ; pFrameChild->GetHeightAsParent(&bChildHeightAsParent) ; if (bChildHeightAsParent) { CSize szEstimateSize(0, 0) ; szEstimateSize.cx = -1 ; szEstimateSize.cy = rcContainer.Height() - rcChildMargin.top - rcChildMargin.bottom ; pFrameInternal->SetEstimateSize(szEstimateSize) ; } BOOL bChildWidthAsParent = FALSE ; pFrameChild->GetWidthAsParent(&bChildWidthAsParent) ; if (i == this->m_nFillItem -1 || -1 * lChildrenCount + i == this->m_nFillItem) { INT nFillSize = this->CalcFillSize(pHostFrame, rcContainer, nUsedSpace, i) ; CSize szEstimateSize(0, 0) ; szEstimateSize.cx = nFillSize - rcChildMargin.left - rcChildMargin.right ; szEstimateSize.cy = -1 ; pFrameInternal->SetEstimateSize(szEstimateSize) ; } else if (bChildWidthAsParent) { pFrameInternal->SetEstimateSize(CSize(0, -1)) ; } CRect rcTarget(0, 0, 0, 0) ; CSize szChildChild(0, 0) ; pFrameChild->GetSize(&szChildChild) ; nUsedSpace += szChildChild.cx + rcChildMargin.left + rcChildMargin.right ; INT nDrift = DRIFT::DRIFT_NEAR ; pFrameChild->GetDrift(&nDrift) ; if (LAYOUT::ORIENTATION_NEAR == this->m_nOrientation) { if (DRIFT::DRIFT_NEAR == nDrift) { rcTarget.top = rcContainer.top + rcChildMargin.top ; } else if (DRIFT::DRIFT_FAR == nDrift) { rcTarget.top = rcContainer.bottom - rcChildMargin.bottom - szChildChild.cy ; } else if (DRIFT::DRIFT_MIDDLE == nDrift) { rcTarget.top = (rcContainer.Height() - szChildChild.cy)/2 + rcContainer.top ; } rcTarget.left = nCurrentLayout + rcChildMargin.left ; rcTarget.right = rcTarget.left + szChildChild.cx ; rcTarget.bottom = rcTarget.top + szChildChild.cy ; nCurrentLayout += szChildChild.cx + rcChildMargin.left + rcChildMargin.right ; } else if (LAYOUT::ORIENTATION_FAR == this->m_nOrientation) { if (DRIFT::DRIFT_NEAR == nDrift) { rcTarget.top = rcContainer.top + rcChildMargin.top ; } else if (DRIFT::DRIFT_FAR == nDrift) { rcTarget.top = rcContainer.bottom - rcChildMargin.bottom - szChildChild.cy ; } else if (DRIFT::DRIFT_MIDDLE == nDrift) { rcTarget.top = (rcContainer.Height() - szChildChild.cy)/2 + rcContainer.top ; } rcTarget.right = nCurrentLayout - rcChildMargin.right ; rcTarget.left = rcTarget.right - szChildChild.cx ; rcTarget.bottom = rcTarget.top + szChildChild.cy ; nCurrentLayout -= szChildChild.cx + rcChildMargin.left + rcChildMargin.right ; } pFrameInternal->SetLayoutRect(rcTarget) ; } return S_OK ; }
void CColorPickerButton::_OnDraw(HDC hdc, RECT *prc, EGACOLOR color) { CDC *pDC = CDC::FromHandle(hdc); if (pDC) { // Figure out the right color - do color 1 for now. RGBQUAD color1 = EGA_TO_RGBQUAD(color.color1); RGBQUAD color2 = EGA_TO_RGBQUAD(color.color2); CBitmap bm; if (CreateDCCompatiblePattern(color1, color2, pDC, &bm)) { CBrush brushPat; if (brushPat.CreatePatternBrush(&bm)) { CRect rcShrunk(prc->left + 1, prc->top + 1, prc->right - 1, prc->bottom - 1); pDC->FillRect(&rcShrunk, &brushPat); } } //int cx = RECTWIDTH(*prc) / 2; //int cy = RECTHEIGHT(*prc) / 2; //RECT rectOverlay = { prc->left + cx, prc->top + cy, prc->right, prc->bottom }; int iModePrev = pDC->SetBkMode(TRANSPARENT); RGBQUAD colorCombine = _Combine(color1, color2); RGBQUAD colorTL = _Lighter(colorCombine); RGBQUAD colorBR = _Darker(colorCombine); // Draw an x maybe if (!_bOn) { /* RGBQUAD colorRedder = _Redden(colorCombine); CPen penX(PS_SOLID, 1, RGB_TO_COLORREF(colorRedder)); HGDIOBJ hgdiObjOld = pDC->SelectObject(&penX); pDC->MoveTo(prc->left, prc->bottom); pDC->LineTo(prc->right, prc->top); pDC->MoveTo(prc->left, prc->top); pDC->LineTo(prc->right, prc->bottom); pDC->SelectObject(hgdiObjOld);*/ } /* // Do highlights. CPen penTL(PS_SOLID, 2, RGB_TO_COLORREF(colorTL)); HGDIOBJ hgdiObj = pDC->SelectObject(&penTL); pDC->MoveTo(prc->left + 1, prc->bottom - 1); pDC->LineTo(prc->left + 1, prc->top + 1); pDC->LineTo(prc->right - 1, prc->top + 1); CPen penBR(PS_SOLID, 2, RGB_TO_COLORREF(colorBR)); pDC->SelectObject(&penBR); pDC->LineTo(prc->right -1 , prc->bottom - 1); pDC->LineTo(prc->left + 1, prc->bottom - 1); pDC->SelectObject(hgdiObj);*/ // Draw some text. int iColorPrev = pDC->SetTextColor(_GetTextColor(colorCombine)); CString text; GetWindowText(text); pDC->DrawText(text, prc, DT_CENTER | DT_VCENTER | DT_SINGLELINE); pDC->SetTextColor(iColorPrev); CRect rcPadding(0, 0, 0, 0); if (_bOn) { CRect rcSrc(CPoint(0, 0), g_bitmapHighlight.GetSize()); g_bitmapHighlight.AlphaBlendSkinParts(hdc, *prc, rcSrc, rcPadding, /*__EXT_BMP_FLAG_PREMULTIPLIED_RGB_CHANNELS |*/ CExtBitmap::__EDM_STRETCH, true, true, 0xFF); } else { CRect rcSrc(CPoint(0, 0), g_bitmapHighlightX.GetSize()); g_bitmapHighlightX.AlphaBlendSkinParts(hdc, *prc, rcSrc, rcPadding, /*__EXT_BMP_FLAG_PREMULTIPLIED_RGB_CHANNELS |*/ CExtBitmap::__EDM_STRETCH, true, true, 0xFF); } pDC->SetBkMode(iModePrev); } }
void ExtTabControl::DrawItem(LPDRAWITEMSTRUCT pdis) { bool isBottom = (TCS_BOTTOM & GetStyle()) != 0; CRect rc = pdis->rcItem; int nTabIndex = pdis->itemID; bool fSelected = (nTabIndex == GetCurSel()); ODA_DRAWENTIRE; char label[64]; TCITEM tci; tci.mask = TCIF_TEXT | TCIF_PARAM; tci.pszText = label; tci.cchTextMax = ARRAYSIZE(label); if (GetItem(nTabIndex, &tci)) { CDC dc; dc.Attach(pdis->hDC); CRect rcPadding(0, 0, 0, 0); CRect rcUsable = rc; rcUsable.left += 1; rcUsable.top += 1; if (fSelected) { rcUsable.OffsetRect(-1, -1); rcUsable.bottom++; } COLORREF accentColor = g_PaintManager->GetColor(COLOR_3DFACE); // TODO COLORREF backgroundColor = g_PaintManager->GetColor(COLOR_3DFACE); CRect rcGradient = rcUsable; TRIVERTEX *vertices; int vertexCount; GRADIENT_RECT *gradRects; int gradRectCount; if (!fSelected) { backgroundColor = CExtBitmap::stat_HLS_Adjust(backgroundColor, 0.0, -0.14, 0.0); accentColor = CExtBitmap::stat_HLS_Adjust(accentColor, 0.0, -0.22, 0.0); int dx = rcGradient.Width() * 3 / 10; int dy = rcGradient.Height() * 3 / 10; // Blend between our main color and the background color for the top part of the gradient (so the gradient isn't so extreme) TRIVERTEX selectedVertices[3] = { { rcGradient.left, rcGradient.top, GetRValue(accentColor) * 256, GetGValue(accentColor) * 256, GetBValue(accentColor) * 256, 65280 }, // -1 because using right again seems to cause some div by zero and mess up GDI { rcGradient.right - 1, rcGradient.top + dy, GetRValue(backgroundColor) * 256, GetGValue(backgroundColor) * 256, GetBValue(backgroundColor) * 256, 65280 }, { rcGradient.right, rcGradient.bottom, GetRValue(backgroundColor) * 256, GetGValue(backgroundColor) * 256, GetBValue(backgroundColor) * 256, 65280 }, }; vertices = selectedVertices; vertexCount = ARRAYSIZE(selectedVertices); GRADIENT_RECT selectedGradRects[2] = { { 0, 1 }, { 1, 2 } }; gradRects = selectedGradRects; gradRectCount = ARRAYSIZE(selectedGradRects); } else { backgroundColor = CExtBitmap::stat_HLS_Adjust(backgroundColor, 0.0, -0.12, 0.0); CPoint topLeft = rcGradient.TopLeft(); CPoint bottomRight = rcGradient.BottomRight(); if (!isBottom) { std::swap(topLeft, bottomRight); } // Blend between our main color and the background color for the top part of the gradient (so the gradient isn't so extreme) TRIVERTEX selectedVertices[2] = { { topLeft.x, topLeft.y, GetRValue(accentColor) * 256, GetGValue(accentColor) * 256, GetBValue(accentColor) * 256, 65280 }, { bottomRight.x, bottomRight.y, GetRValue(backgroundColor) * 256, GetGValue(backgroundColor) * 256, GetBValue(backgroundColor) * 256, 65280 }, }; vertices = selectedVertices; vertexCount = ARRAYSIZE(selectedVertices); GRADIENT_RECT selectedGradRects[1] = { 0, 1 }; gradRects = selectedGradRects; gradRectCount = ARRAYSIZE(selectedGradRects); } dc.FillSolidRect(rc, backgroundColor); // TODO: Turn these upside down if upside down... dc.GradientFill(vertices, vertexCount, gradRects, gradRectCount, GRADIENT_FILL_RECT_V); // Use a different font decoration depending on if this is the most recent version of this item. bool fNotMostRecent = false; rcUsable.OffsetRect(4, 1); // indent COLORREF crText = g_PaintManager->GetColor(fSelected ? COLOR_BTNTEXT : COLOR_BTNSHADOW); int nOldText = dc.SetTextColor(crText); int nOldBk = dc.SetBkMode(TRANSPARENT); dc.DrawText(tci.pszText, -1, &rcUsable, DT_SINGLELINE); dc.SetBkMode(nOldBk); dc.SetTextColor(nOldText); dc.Detach(); } }