void wxCaret::Refresh() { wxClientDC dcWin(GetWindow()); // this is the new code, switch to 0 if this gives problems #ifdef wxHAS_CARET_USING_OVERLAYS wxDCOverlay dcOverlay( m_overlay, &dcWin, m_x, m_y, m_width , m_height ); if ( m_blinkedOut ) { dcOverlay.Clear(); } else { DoDraw( &dcWin ); } #else wxMemoryDC dcMem; dcMem.SelectObject(m_bmpUnderCaret); if ( m_blinkedOut ) { // restore the old image dcWin.Blit(m_xOld, m_yOld, m_width, m_height, &dcMem, 0, 0); m_xOld = m_yOld = -1; } else { if ( m_xOld == -1 && m_yOld == -1 ) { // save the part we're going to overdraw int x = m_x, y = m_y; #if defined(__WXGTK__) && !defined(__WX_DC_BLIT_FIXED__) wxPoint pt = dcWin.GetDeviceOrigin(); x += pt.x; y += pt.y; #endif // broken wxGTK wxDC::Blit dcMem.Blit(0, 0, m_width, m_height, &dcWin, x, y); m_xOld = m_x; m_yOld = m_y; } //else: we already saved the image below the caret, don't do it any // more // and draw the caret there DoDraw(&dcWin); } #endif }
void CCaptionPainter::DrawCustomNcBtn( UINT btnType, int state ) { CRect rcSrc, rcDest; CPImageControl *curImgCtrl = NULL; switch (btnType) { case CAC_HTCLOSE: rcSrc = rcDest = m_rcCloseBtn; // make src rectangle zero based rcSrc -= CPoint(m_rcCloseBtn.left, m_rcCloseBtn.top); curImgCtrl = m_pCloseBxImgCtrl; break; case HTMINBUTTON: rcSrc = rcDest = m_rcMinBtn; // make src rectangle zero based rcSrc -= CPoint(m_rcMinBtn.left, m_rcMinBtn.top); curImgCtrl = m_pMinBxImgCtrl; break; case HTMAXBUTTON: rcSrc = rcDest = m_rcMaxBtn; // make src rectangle zero based rcSrc -= CPoint(m_rcMaxBtn.left, m_rcMaxBtn.top); curImgCtrl = (m_pParentDlg->IsZoomed() ? m_pRestoreBxImgCtrl : m_pMaxBxImgCtrl); break; case HTSYSMENU: default: return; } if (curImgCtrl) { CWindowDC dcWin((CWnd*)m_pParentDlg); // window DC //create a drawing surface from my dc RDcDrawingSurface destDS; destDS.Initialize(dcWin.m_hDC, dcWin.m_hAttribDC); curImgCtrl->Draw(state, destDS, rcSrc, rcDest); destDS.RestoreDefaults(); } }
void CCaptionPainter::PaintSolidCaption(CRect& capRect, COLORREF theColor) { ASSERT(m_pParentDlg); CWnd& wnd = (CWnd&)*m_pParentDlg; // Get caption DC and rectangle CWindowDC dcWin(&wnd); // window DC CDC dcMem; // memory DC dcMem.CreateCompatibleDC(&dcWin); // ...create it CBitmap bm; CBitmap* pOldBitmap; int cxCap = capRect.Width(); int cyCap = capRect.Height(); bm.CreateCompatibleBitmap(&dcWin, cxCap, cyCap); // create one pOldBitmap = dcMem.SelectObject(&bm); // select bitmap into memory DC if (!m_bActive) { // Inactive caption PaintRect(dcMem, 0, 0, cxCap, cyCap, GetSysColor(COLOR_INACTIVECAPTION)); } else { PaintRect(dcMem, 0, 0, cxCap, cyCap, theColor); } // draw icon and buttons int cxIcon = DrawIcon( &dcMem ); int cxButns = DrawButtons( &dcMem, capRect.Size() ); CRect rc(CPoint(0,0), capRect.Size()); // text rectangle rc.left += cxIcon+2; // start after icon rc.right -= cxButns; // don't draw past buttons // draw text DrawWindowText(&dcMem, rc); // blast bits to screen dcWin.BitBlt(capRect.left, capRect.top, capRect.Width(),capRect.Height(),&dcMem,0,0,SRCCOPY); dcMem.SelectObject(pOldBitmap); // restore DC }
void wxCaret::Refresh() { wxClientDC dcWin(GetWindow()); // this is the new code, switch to 0 if this gives problems #ifdef wxHAS_CARET_USING_OVERLAYS wxDCOverlay dcOverlay( m_overlay, &dcWin, m_x, m_y, m_width , m_height ); if ( m_blinkedOut ) { dcOverlay.Clear(); } else { DoDraw( &dcWin, GetWindow() ); } #else wxMemoryDC dcMem; dcMem.SelectObject(m_bmpUnderCaret); if ( m_blinkedOut ) { // restore the old image dcWin.Blit(m_xOld, m_yOld, m_width, m_height, &dcMem, 0, 0); m_xOld = m_yOld = -1; } else { if ( m_xOld == -1 && m_yOld == -1 ) { // save the part we're going to overdraw dcMem.Blit(0, 0, m_width, m_height, &dcWin, m_x, m_y); m_xOld = m_x; m_yOld = m_y; } //else: we already saved the image below the caret, don't do it any // more // and draw the caret there DoDraw(&dcWin, GetWindow()); } #endif }
////////////////// // Create the drag image: create an image list and call virtual darw function // to draw the data into the image list. Will then use this during dragging. // CImageList* CDragDropData::CreateDragImage(CWnd* pWnd, CRect& rc) { m_bitmap.DeleteObject(); // const COLORREF BGCOLOR = GetSysColor(COLOR_3DLIGHT); // create memory dc compatible w/source window CWindowDC dcWin(pWnd); CDC dcMem; dcMem.CreateCompatibleDC(&dcWin); // use same font as source window CFont* pFont = pWnd->GetFont(); CFont* pOldFont = dcMem.SelectObject(pFont); // get size of drag image CSize sz = OnGetDragSize(dcMem); // call virtual fn to get size rc = CRect(CPoint(0,0), sz); // create image list: create bitmap and draw into it m_bitmap.CreateCompatibleBitmap(&dcWin, sz.cx, sz.cy); CBitmap* pOldBitmap = dcMem.SelectObject(&m_bitmap); dcMem.FillSolidRect(rc, GetSysColor(COLOR_HIGHLIGHT)); dcMem.SetBkMode(TRANSPARENT); dcMem.SetTextColor(GetSysColor(COLOR_WINDOWTEXT)); COLORREF crMask; OnDrawData(dcMem, rc, crMask); // call virtual fn to draw dcMem.SelectObject(pOldFont); dcMem.SelectObject(pOldBitmap); // create image list and add bitmap to it CImageList *pil = new CImageList(); pil->Create(sz.cx, sz.cy, ILC_COLOR24|ILC_MASK, 0, 1); pil->Add(&m_bitmap, crMask); return pil; }
void CCaptionPainter::DrawStandardNcBtn( UINT btnType, int state ) { ASSERT(m_pParentDlg); CWnd& wnd = (CWnd&)*m_pParentDlg; CRect rcDest; UINT uCtrlType; switch (btnType) { case CAC_HTCLOSE: rcDest = m_rcCloseBtn; uCtrlType = DFCS_CAPTIONCLOSE; break; case HTMINBUTTON: rcDest = m_rcMinBtn; uCtrlType = DFCS_CAPTIONMIN; break; case HTMAXBUTTON: rcDest = m_rcMaxBtn; uCtrlType = (wnd.IsZoomed()? DFCS_CAPTIONRESTORE :DFCS_CAPTIONMAX); break; case HTSYSMENU: default: return; } UINT uBtnState = 0; if (state == CCaptionPainter::DOWN) uBtnState = DFCS_PUSHED; CWindowDC dcWin((CWnd*)m_pParentDlg); // window DC dcWin.DrawFrameControl(&rcDest, DFC_CAPTION, uCtrlType | uBtnState); }
void wxCaret::Refresh() { wxClientDC dcWin(GetWindow()); wxMemoryDC dcMem; dcMem.SelectObject(m_bmpUnderCaret); if ( m_blinkedOut ) { // restore the old image dcWin.Blit(m_xOld, m_yOld, m_width, m_height, &dcMem, 0, 0); m_xOld = m_yOld = -1; } else { if ( m_xOld == -1 && m_yOld == -1 ) { // save the part we're going to overdraw int x = m_x, y = m_y; #if defined(__WXGTK__) && !defined(__WX_DC_BLIT_FIXED__) wxPoint pt = dcWin.GetDeviceOrigin(); x += pt.x; y += pt.y; #endif // broken wxGTK wxDC::Blit dcMem.Blit(0, 0, m_width, m_height, &dcWin, x, y); m_xOld = m_x; m_yOld = m_y; } //else: we already saved the image below the caret, don't do it any // more // and draw the caret there DoDraw(&dcWin); } }
void CCaptionPainter::PaintPictureCaption( CRect& capRect ) { ASSERT(m_pTitleBkImgCtrl); ASSERT(m_pParentDlg); CWnd& wnd = (CWnd&)*m_pParentDlg; // Get caption DC and rectangle CWindowDC dcWin(&wnd); // window DC // scale it to the right size CRect srcRect(0,0,capRect.Width(),capRect.Height()); m_pTitleBkImgCtrl->SetControlSize(srcRect); // draw it int retVal = m_pTitleBkImgCtrl->Draw(CPImageControl::UP, dcWin, srcRect, capRect); // take care of those control btns DrawCustomButtons(&dcWin, capRect); // draw text capRect.left += 2; DrawWindowText(&dcWin, capRect); }
////////////////// // Paint custom caption. // This is the function that actually does the shading. It creates a // bitmap that's used to paint the caption. It looks horrible, but it's // just a lot of bit-twiddling GDI stuff. // void CCaptionPainter::PaintGradiantCaption(CRect& capRect) { ASSERT(m_pParentDlg); CWnd& wnd = (CWnd&)*m_pParentDlg; // Get caption DC and rectangle CWindowDC dcWin(&wnd); // window DC CDC dcMem; // memory DC dcMem.CreateCompatibleDC(&dcWin); // ...create it CBitmap bm; CBitmap* pOldBitmap; int cxCap = capRect.Width(); int cyCap = capRect.Height(); bm.CreateCompatibleBitmap(&dcWin, cxCap, cyCap); // create one pOldBitmap = dcMem.SelectObject(&bm); // select bitmap into memory DC if (!m_bActive) { // Inactive caption: don't do shading, just fill w/bg color PaintRect(dcMem, 0, 0, cxCap, cyCap, GetSysColor(COLOR_INACTIVECAPTION)); } else { // Active caption: do shading // COLORREF clrBG = GetSysColor(COLOR_ACTIVECAPTION); // background color int r = GetRValue(clrBG); // red.. int g = GetGValue(clrBG); // ..green int b = GetBValue(clrBG); // ..blue color vals int x = 5*cxCap/6; // start 5/6 of the way right int w = x; // width of area to shade int xDelta= max(w/NCOLORSHADES,1); // width of one shade band // Paint far right 1/6 of caption the background color PaintRect(dcMem, x, 0, cxCap-x, cyCap, clrBG); // Compute new color brush for each band from x to x + xDelta. // Excel uses a linear algorithm from black to normal, i.e. // // color = CaptionColor * r // // where r is the ratio x/w, which ranges from 0 (x=0, left) // to 1 (x=w, right). This results in a mostly black title bar, // since we humans don't distinguish dark colors as well as light // ones. So instead, I use the formula // // color = CaptionColor * [1-(1-r)^2] // // which still equals black when r=0 and CaptionColor when r=1, // but spends more time near CaptionColor. For example, when r=.5, // the multiplier is [1-(1-.5)^2] = .75, closer to 1 than .5. // I leave the algebra to the reader to verify that the above formula // is equivalent to // // color = CaptionColor - (CaptionColor*(w-x)*(w-x))/(w*w) // // The computation looks horrendous, but it's only done once each // time the caption changes size; thereafter BitBlt'ed to the screen. // while (x > xDelta) // paint bands right to left { x -= xDelta; // next band int wmx2 = (w-x)*(w-x); // w minus x squared int w2 = w*w; // w squared PaintRect(dcMem, x, 0, xDelta, cyCap, RGB(r-(r*wmx2)/w2, g-(g*wmx2)/w2, b-(b*wmx2)/w2)); } PaintRect(dcMem,0,0,x,cyCap,COLOR_BLACK); // whatever's left ==> black } // draw icon and buttons int cxIcon = DrawIcon( &dcMem ); int cxButns = DrawButtons( &dcMem, capRect.Size() ); CRect rc(CPoint(0,0), capRect.Size()); // text rectangle rc.left += cxIcon+2; // start after icon rc.right -= cxButns; // don't draw past buttons // draw text DrawWindowText(&dcMem, rc); // blast bits to screen dcWin.BitBlt(capRect.left, capRect.top, capRect.Width(),capRect.Height(),&dcMem,0,0,SRCCOPY); dcMem.SelectObject(pOldBitmap); // restore DC }
void CExtMiniDockFrameWnd::OnNcPaint() { CExtControlBar * pExtBar = GetControlBarExt(); bool bExtBar = false; if( pExtBar != NULL && !pExtBar->m_bFixedMode ) bExtBar = true; CRect rcClient, rcBar; GetClientRect(rcClient); ClientToScreen(rcClient); GetWindowRect(rcBar); rcClient.OffsetRect(-rcBar.TopLeft()); rcBar.OffsetRect(-rcBar.TopLeft()); CWindowDC dc( this ); dc.ExcludeClipRect(rcClient); CExtMemoryDC dcWin(&dc); g_PaintManager->PaintDockingFrame( dcWin, rcBar, rcClient, true, bExtBar ); CString sCaption; if( pExtBar != NULL ) pExtBar->GetWindowText(sCaption); if( sCaption.IsEmpty() ) GetWindowText(sCaption); CRect rcCapt( m_rcFrameCaption ); CRect rcText( m_rcFrameCaption ); rcText.right = m_rcBtnHideBar.left; if( pExtBar != NULL ) { INT nCountOfNcButtons = pExtBar->NcButtons_GetCount(); if( nCountOfNcButtons > 0 ) { CExtBarNcAreaButton * pBtn = pExtBar->NcButtons_GetAt( nCountOfNcButtons - 1 ); const CRect & rcBtn = *pBtn; rcText.right = rcBtn.left - 2; if( rcText.left > rcText.right ) rcText.left = rcText.right; } // if( nCountOfNcButtons > 0 ) } bool bActive = false; HWND hTmpWndFocus = ::GetFocus(); if( hTmpWndFocus != NULL && ( GetSafeHwnd() == hTmpWndFocus || ::IsChild( GetSafeHwnd(), hTmpWndFocus ) ) ) bActive = true; rcText.DeflateRect(2,0); g_PaintManager->PaintGripper( dcWin, rcCapt, rcText, bActive, true, false, bExtBar, sCaption.IsEmpty() ? NULL : (LPCTSTR)sCaption ); if( pExtBar != NULL ) { pExtBar->NcButtons_Paint( dcWin ); } // if( pExtBar != NULL ) else { bool bPushed = false, bEnabled = true; g_PaintManager->PaintDockingCaptionButton( dcWin, m_rcBtnHideBar, CExtPaintManager::__DCBT_CLOSE, m_bBtnHideBar, bPushed, bEnabled, bExtBar, bActive ); } // else from if( pExtBar != NULL ) }
void CSAPrefsStatic::MakeCaptionBitmap() { if (m_bm.m_hObject) return; // already have bitmap; return CRect cr; GetClientRect(cr); int w = cr.Width(); int h = cr.Height(); // Create bitmap same size as caption area and select into memory DC // CWindowDC dcWin(this); CDC dc; dc.CreateCompatibleDC(&dcWin); m_bm.DeleteObject(); m_bm.CreateCompatibleBitmap(&dcWin, w, h); CBitmap* pOldBitmap = dc.SelectObject(&m_bm); COLORREF clrBG = ::GetSysColor(COLOR_3DFACE); // background color int r = GetRValue(clrBG); // red.. int g = GetGValue(clrBG); // ..green int b = GetBValue(clrBG); // ..blue color vals int x = 8*cr.right/8; // start 5/6 of the way right int w1 = x - cr.left; // width of area to shade int NCOLORSHADES = 128; // this many shades in gradient int xDelta= max( w / NCOLORSHADES , 1); // width of one shade band PaintRect(dc, x, 0, cr.right-x, h, clrBG); while (x > xDelta) { // paint bands right to left x -= xDelta; // next band int wmx2 = (w1-x)*(w1-x); // w minus x squared int w2 = w1*w1; // w squared PaintRect(dc, x, 0, xDelta, h, RGB(r-(r*wmx2)/w2, g-(g*wmx2)/w2, b-(b*wmx2)/w2)); } PaintRect(dc,0,0,x,h,RGB(0,0,0)); // whatever's left ==> black // draw the 'constant' text // create a font, if we need to if (m_nameFont.GetSafeHandle()==NULL) { m_nameFont.CreateFont( 18, 0, 0, 0, FW_BOLD, 0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_MODERN, m_csFontName); } CFont * OldFont = dc.SelectObject(&m_nameFont); // back up a little cr.right-=5; // draw text in DC dc.SetBkMode(TRANSPARENT); dc.SetTextColor( ::GetSysColor( COLOR_3DHILIGHT)); dc.DrawText( m_csConstantText, cr + CPoint(1,1), DT_SINGLELINE | DT_RIGHT | DT_VCENTER); dc.SetTextColor( ::GetSysColor( COLOR_3DSHADOW)); dc.DrawText( m_csConstantText, cr, DT_SINGLELINE | DT_RIGHT | DT_VCENTER); // restore old font dc.SelectObject(OldFont); // Restore DC dc.SelectObject(pOldBitmap); }
void CExtMiniDockFrameWnd::OnNcPaint() { CExtControlBar * pExtBar = GetControlBarExt(); bool bExtBar = false; if( pExtBar != NULL && !pExtBar->IsFixedMode() ) bExtBar = true; CRect rcClient, rcBar; GetClientRect(rcClient); ClientToScreen(rcClient); GetWindowRect(rcBar); rcClient.OffsetRect(-rcBar.TopLeft()); rcBar.OffsetRect(-rcBar.TopLeft()); CWindowDC dcSrc( this ); dcSrc.ExcludeClipRect( &rcClient ); CExtMemoryDC dcWin( &dcSrc, &rcBar ); CExtPaintManager::PAINTDOCKINGFRAMEDATA _pdfd( this, rcBar, rcClient, true, bExtBar ); g_PaintManager->PaintDockingFrame( dcWin, _pdfd ); bool bEnableCaptionText = true; CExtSafeString sCaption; if( pExtBar != NULL ) { if( pExtBar->IsKindOf(RUNTIME_CLASS(CExtDynControlBar)) #if (!defined __EXT_MFC_NO_TAB_CONTROLBARS) && ( !pExtBar->IsKindOf(RUNTIME_CLASS(CExtDynTabControlBar)) ) #endif // (!defined __EXT_MFC_NO_TAB_CONTROLBARS) ) bEnableCaptionText = false; else { pExtBar->OnGetBarCaptionText( CExtControlBar::__EBCT_SINGLE_CAPTION_FLOATING, sCaption ); } } if( !bEnableCaptionText ) { if( pExtBar != NULL && pExtBar->IsKindOf(RUNTIME_CLASS(CExtDynControlBar)) ) bEnableCaptionText = _GetSingleVisibleCaptionText( sCaption ); } else if( bEnableCaptionText && sCaption.IsEmpty() ) { if( pExtBar != NULL ) { pExtBar->OnGetBarCaptionText( CExtControlBar::__EBCT_SINGLE_CAPTION_FLOATING, sCaption ); } // if( pExtBar != NULL ) else { int nTextLen = GetWindowTextLength(); if( nTextLen > 0 ) { GetWindowText( sCaption.GetBuffer( nTextLen+2 ), nTextLen+1 ); sCaption.ReleaseBuffer(); } // if( nTextLen > 0 ) } // else from if( pExtBar != NULL ) } CRect rcCapt( m_rcFrameCaption ); CRect rcText( m_rcFrameCaption ); rcText.right = m_rcBtnHideBar.left; if( pExtBar != NULL ) pExtBar->NcButtons_CalcGripperTextLocation( rcText ); bool bActive = false; HWND hTmpWndFocus = ::GetFocus(); if( hTmpWndFocus != NULL && ( GetSafeHwnd() == hTmpWndFocus || ::IsChild( GetSafeHwnd(), hTmpWndFocus ) ) ) bActive = true; rcText.DeflateRect(2,0); CExtPaintManager::PAINTGRIPPERDATA _pgd( this, rcCapt, rcText, bActive, true, false, bExtBar, sCaption.IsEmpty() ? LPCTSTR( NULL ) : sCaption ); g_PaintManager->PaintGripper( dcWin, _pgd ); if( pExtBar != NULL ) { pExtBar->NcButtons_Paint( dcWin ); } // if( pExtBar != NULL ) else { CExtPaintManager::PAINTDOCKINGCAPTIONBUTTONDATA _pdcbd( this, m_rcBtnHideBar, CExtPaintManager::__DCBT_CLOSE, m_bBtnHideBar, false, true, bExtBar, bActive, true ); g_PaintManager->PaintDockingCaptionButton( dcWin, _pdcbd ); } // else from if( pExtBar != NULL ) g_PaintManager->OnPaintSessionComplete( this ); }
//***************************************************************************** void CBCGPCaptionBar::OnNcPaint() { CWindowDC dcWin(this); DoNcPaint(&dcWin); }