void CDrawContext::SelectBrush( COLORREF cr ) { if( !m_bBrushSelected || cr != m_crCurrentBrush ) { VAPI( ::SelectObject( m_hdc, GetBrush( cr ) ) ); m_crCurrentBrush = cr; m_bBrushSelected = true; } }
void CDrawContext::Rectangle( const CRect &rc, COLORREF cr ) { SelectPen( cr ); // Save and restore the brush because otherwise the caching system (GetBrush) still thinks // a coloured brush is selected! HGDIOBJ hOld = ::SelectObject( m_hdc, GetStockObject( HOLLOW_BRUSH ) ); VAPI( ::Rectangle( m_hdc, rc.left, rc.top, rc.right, rc.bottom ) ); ::SelectObject( m_hdc, hOld ); }
void CDrawContext::DrawText( int x, int y, LPCTSTR pcszText, int nLength, COLORREF crFore ) { if( crFore != m_crCurrentText ) { ::SetTextColor( m_hdc, 0x02000000 | crFore ); m_crCurrentText = crFore; } VAPI( ::TextOut( m_hdc, x, y, pcszText, nLength ) ); }
void CDrawContext::SetClipRect( const CRect &rc ) { HRGN hrgn = CreateRectRgnIndirect( &rc ); ::SelectClipRgn( m_hdc, hrgn ); POINT pt; GetWindowOrgEx( m_hdc, &pt ); OffsetClipRgn( m_hdc, -pt.x, -pt.y ); VAPI( ::DeleteObject( hrgn ) ); }
void CDrawContext::SelectPen( COLORREF cr ) { if( !m_bPenSelected || cr != m_crCurrentPen ) { VAPI( ::SelectObject( m_hdc, GetPen( cr ) ) ); m_crCurrentPen = cr; m_bPenSelected = true; } }
void ResizeDlg::UpdateWindowSize(const int cx, const int cy, HWND hwnd) { DialogData *pdd = (DialogData*)dd; if( pdd ) { const int nDeltaX = cx - pdd->m_sizeClient.cx; const int nDeltaY = cy - pdd->m_sizeClient.cy; WinHelper::CDeferWindowPos def( pdd->nItemCount ); WinHelper::CRect rc; const DialogSizerSizingItem *psd = pdd->psd; while( psd->uSizeInfo != 0xFFFFFFFF ) { HWND hwndChild = ::GetDlgItem( *this, psd->uControlID ); if( ::IsWindow( hwndChild ) ) { VAPI( ::GetWindowRect( hwndChild, rc ) ); (void)::MapWindowPoints( ::GetDesktopWindow(), hwnd, (LPPOINT)&rc, 2 ); // // Adjust the window horizontally if( psd->uSizeInfo & DS_MoveX ) { rc.left += nDeltaX; rc.right += nDeltaX; } // // Adjust the window vertically if( psd->uSizeInfo & DS_MoveY ) { rc.top += nDeltaY; rc.bottom += nDeltaY; } // // Size the window horizontally if( psd->uSizeInfo & DS_SizeX ) { rc.right += nDeltaX; } // // Size the window vertically if( psd->uSizeInfo & DS_SizeY ) { rc.bottom += nDeltaY; } (void)def.DeferWindowPos( hwndChild, NULL, rc, SWP_NOACTIVATE | SWP_NOZORDER ); } psd++; } pdd->m_sizeClient.cx = cx; pdd->m_sizeClient.cy = cy; // // If we have a sizing grip enabled then adjust it's position ResizeDlgUpdateGripper( hwnd, pdd ); } }
void CHTMLSectionLink::DrawFocus( GS::CDrawContext &dc ) { HRGN rgn; if( m_pParent->IsFocused() && GetRegion( rgn ) ) { dc.DrawFocus( rgn ); VAPI( DeleteObject( rgn ) ); } }
void CDrawContext::PolyFillOutlined( const POINT *pt, int nCount, COLORREF cr, COLORREF crOutline ) { ASSERT( nCount > 0 ); ASSERT_VALID_READPTR( pt, sizeof( POINT) * nCount ); SelectBrush( cr ); SelectPen( crOutline ); VAPI( ::Polygon( m_hdc, pt, nCount ) ); }
void CHTMLSectionLink::GetObjectRect( WinHelper::CRect &rcBounds ) const { HRGN rgn; if( GetRegion( rgn ) ) { GetRgnBox( rgn, rcBounds ); VAPI( DeleteObject( rgn ) ); } else { ASSERT( FALSE ); } }
HPEN CDrawContext::GetPen( COLORREF cr ) { HPEN *pPen = m_mapPens.Lookup( cr ); if( pPen ) { return *pPen; } HPEN hPen = CreatePen( PS_SOLID, 1, 0x02000000 | cr ); VAPI( hPen ); m_arrObjToDelete.Add( hPen ); m_mapPens.SetAt( cr, hPen ); return hPen; }
HBRUSH CDrawContext::GetBrush( COLORREF cr ) { HBRUSH *pBrush = m_mapBrushes.Lookup( cr ); if( pBrush ) { return *pBrush; } HBRUSH hbr = ::CreateSolidBrush( 0x02000000 | cr ); VAPI( hbr ); m_arrObjToDelete.Add( hbr ); m_mapBrushes.SetAt( cr, hbr ); return hbr; }
void StopSubclassing() { #ifdef QHTM_COOLTIPS if( g_lpfnOldWndProc ) { HWND hwndTip = CreateTip(); if( hwndTip ) { (void)SetClassLong(hwndTip, GCL_WNDPROC, (DWORD) g_lpfnOldWndProc); VAPI( ::DestroyWindow( hwndTip ) ); } g_lpfnOldWndProc = NULL; } #endif // QHTM_COOLTIPS }
CDrawContext::~CDrawContext() { if( m_hdc ) VAPI( ::RestoreDC( m_hdc, -1 ) ); const UINT uSize = m_arrObjToDelete.GetSize(); for( UINT n = 0; n < uSize; n++ ) { VAPI( ::DeleteObject( m_arrObjToDelete[ n ] ) ); } if( m_bWeCreatedDC ) { ::ReleaseDC( g_hwnd, m_hdc ); m_hdc = NULL; } // TRACENL("DrawContext: There were %d fonts cached.\n", m_mapFonts.GetSize()); for( Container::CMapIter<FontDef, FontInfo*> itr( m_mapFonts ); !itr.EOL(); itr.Next() ) { delete itr.GetValue(); } }
CDrawContext::CDrawContext( const CRect *prcClip, HDC hdc, bool bIsPrinting /*= false */ ) : m_bWeCreatedDC( false ) , m_hdc( hdc ) , m_pFontInfo( NULL ) , m_bBrushSelected( false ) , m_bPenSelected( false ) , m_cxDeviceScaleNumer( 1 ) , m_cxDeviceScaleDenom( 1 ) , m_cyDeviceScaleNumer( 1 ) , m_cyDeviceScaleDenom( 1 ) , m_crCurrentText( 0 ) , m_bIsPrinting( bIsPrinting ) { if( prcClip ) m_rcClip = *prcClip; else m_rcClip.Set(0,0,0,0); if( !m_hdc ) { m_hdc = ::GetDC( g_hwnd ); m_bWeCreatedDC = true; } // Set the device scale if needed if( IsPrinting() ) { HDC screenDC = ::GetDC(g_hwnd); m_cxDeviceScaleNumer = ::GetDeviceCaps(m_hdc, LOGPIXELSX); m_cxDeviceScaleDenom = ::GetDeviceCaps(screenDC, LOGPIXELSX); m_cyDeviceScaleNumer = ::GetDeviceCaps(m_hdc, LOGPIXELSY); m_cyDeviceScaleDenom = ::GetDeviceCaps(screenDC, LOGPIXELSY); ::ReleaseDC(g_hwnd, screenDC); } VAPI( ::SaveDC( m_hdc ) ); ::SetBkMode( m_hdc, TRANSPARENT ); }
void CDefaults::SetFont( HFONT hFont ) { LOGFONT lf; VAPI( GetObject( hFont, sizeof( lf ), &lf ) ); SetFont( lf ); }
LONG FAR PASCAL SubClassFunc( HWND hwnd, WORD msg, WORD wParam, LONG lParam ) { switch( msg ) { case WM_CREATE: { Property *pProp = new Property; pProp->m_defaults.m_rcMargins.Set( 2, 2, 5, 5 ); VAPI( ::SetProp( hwnd, g_pcszProperty, reinterpret_cast<HANDLE>( pProp ) ) ); } break; case WM_DESTROY: { Property *pProp = reinterpret_cast<Property *>( RemoveProp( hwnd, g_pcszProperty ) ); delete pProp; } break; case WM_WINDOWPOSCHANGING: { WINDOWPOS &pos = *(WINDOWPOS *)lParam; Property *pProp = reinterpret_cast<Property *>( GetProp( hwnd, g_pcszProperty ) ); if( !(pos.flags & SWP_NOSIZE) && !( pos.flags & SWP_NOMOVE ) && pProp ) { CWindowText text( hwnd ); if( text.GetLength() ) { HFONT hFont = (HFONT)SendMessage( hwnd, WM_GETFONT, 0, 0 ); pProp->m_defaults.SetFont( hFont ); pProp->m_sectHTML.SetHTML( text, text.GetLength(), NULL ); } return 0; } } break; case WM_WINDOWPOSCHANGED: { static bool bDealingWithIt = false; Property *pProp = reinterpret_cast<Property *>( GetProp( hwnd, g_pcszProperty ) ); if( pProp && !bDealingWithIt ) { bDealingWithIt = true; WinHelper::CRect rcTip( 0, 0, 300, 5 ); GS::CDrawContext dc; pProp->m_sectHTML.OnLayout( rcTip, dc ); const WinHelper::CSize size( pProp->m_sectHTML.GetSize() ); rcTip.SetSize( size ); pProp->m_sectHTML.bottom = size.cy; pProp->m_sectHTML.right = size.cx; WinHelper::CPoint ptCursor; VAPI( ::GetCursorPos( ptCursor ) ); ptCursor.x += g_knTipClearanceX; ptCursor.y += g_knTipClearanceY; rcTip.Offset( ptCursor.x, ptCursor.y ); WinHelper::CRect rcDesktop; GetDisplayWorkArea( hwnd, rcDesktop ); if( rcTip.right >= rcDesktop.right ) { rcTip.Offset( -(rcTip.right - rcDesktop.right) - g_knTipClearanceX, 0 ); } if( rcTip.bottom >= rcDesktop.bottom ) { rcTip.Offset( 0, -rcTip.Height() - g_knTipClearanceY ); } VAPI( ::SetWindowPos( hwnd, NULL, rcTip.left, rcTip.top, rcTip.Width(), rcTip.Height(), SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_NOZORDER ) ); bDealingWithIt = false; } return 0; } case TTM_UPDATE: { //LRESULT lr = CallWindowProc( g_lpfnOldWndProc, hwnd, msg, wParam, lParam); //::SetWindowPos( hwnd, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | InvalidateRect( hwnd, NULL, TRUE ); break; } case WM_PAINT: { Property *pProp = reinterpret_cast<Property *>( GetProp( hwnd, g_pcszProperty ) ); if( pProp ) { PAINTSTRUCT ps; VAPI( ::BeginPaint( hwnd, &ps ) ); WinHelper::CRect rcPaint( ps.rcPaint ); if( rcPaint.IsEmpty() ) { VAPI( ::GetClientRect( hwnd, &rcPaint ) ); } // // Scoped to allow the draw context to go out of scope before EndPaint is called. { GS::CDrawContext dc( &rcPaint, ps.hdc ); (void)SelectPalette( ps.hdc, GS::GetCurrentWindowsPalette(), TRUE ); (void)RealizePalette( ps.hdc ); pProp->m_sectHTML.OnDraw( dc ); } (void)EndPaint( hwnd, &ps ); return 0; } break; } } return CallWindowProc( g_lpfnOldWndProc, hwnd, msg, wParam, lParam); }
BOOL ResizeDlg::SetData(const DialogSizerSizingItem *psd, BOOL bShowSizingGrip, HKEY hkRootSave, LPCTSTR pcszName, SIZE *psizeMax) // // Setting a dialog sizeable involves subclassing the window and handling it's // WM_SIZE messages, if we have a hkRootSave and pcszName then we will also be loading/saving // the size and position of the window from the registry. We load from the registry when we // subclass the window and we save to the registry when we get a WM_DESTROY. // // It will return non-zero for success and zero if it fails { R_ASSERT( psd ); R_ASSERT( ( hkRootSave != NULL && pcszName != NULL ) || ( hkRootSave == NULL && pcszName == NULL ) ); // // Make sure all of the parameters are valid. if( ::IsWindow( *this ) && psd && ( ( hkRootSave != NULL && pcszName != NULL && !IsBadStringPtr( pcszName, 0xFFFF ) ) || ( hkRootSave == NULL && pcszName == NULL ) ) && ( psizeMax == NULL || !IsBadReadPtr( psizeMax, sizeof( SIZE ) ) ) ) { DialogData *pdd = (DialogData *)AddDialogData(); if( pdd ) { pdd->hkRootSave = hkRootSave; pdd->pcszName = pcszName; pdd->m_bShowSizingGrip = bShowSizingGrip; pdd->nItemCount = ResizeDlgGetItemCount( psd ) + 1; pdd->psd = (DialogSizerSizingItem *) calloc(pdd->nItemCount, sizeof(DialogSizerSizingItem )); if( pdd->psd ) { // // Copy all of the user controls etc. for later, this way the user can quite happily // let the structure go out of scope. ResizeDlgCopyItems( pdd->psd, psd ); if( psizeMax ) { pdd->m_ptLargest.x = psizeMax->cx; pdd->m_ptLargest.y = psizeMax->cy; pdd->m_bLargestSet = true; } // // If the there was save info passed in then we need to make damn good use of it // by attempting to load the RegistryData structure if( hkRootSave && pcszName ) { RegistryData rd; DWORD dwSize = sizeof( RegistryData ); DWORD dwType = REG_BINARY; if( RegQueryValueExRecursive( hkRootSave, pcszName, NULL, &dwType, reinterpret_cast<LPBYTE>( &rd ), &dwSize ) == ERROR_SUCCESS && dwSize == sizeof( rd ) ) { if( !(GetWindowLong( *this, GWL_STYLE ) & WS_VISIBLE) ) rd.m_wpl.showCmd = SW_HIDE; VAPI( SetWindowPlacement( &rd.m_wpl ) ); } } return TRUE; } else { free(pdd); } } } return FALSE; }
BOOL ResizeDlg::OnWndMsg(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *res ) // Actual window procedure that will handle saving window size/position and moving // the controls whilst the window sizes. { if(dd == NULL) { return CDialog::OnWndMsg(msg, wParam, lParam, res); } switch( msg ) { case WM_ERASEBKGND: { BOOL r = CDialog::OnWndMsg(msg, wParam, lParam, res); DialogData *pdd = (DialogData*)dd; if( pdd && pdd->m_bShowSizingGrip && !pdd->m_bMaximised ) { VAPI( ::DrawFrameControl( reinterpret_cast<HDC>( wParam ), pdd->m_rcGrip, DFC_SCROLL, DFCS_SCROLLSIZEGRIP ) ); } return r; } case WM_SIZE: { DialogData *pdd = (DialogData*)dd; if( pdd && wParam != SIZE_MINIMIZED ) { pdd->m_bMaximised = ( wParam == SIZE_MAXIMIZED ? true : false ); UpdateWindowSize( LOWORD( lParam ), HIWORD( lParam ), *this); } } break; case WM_NCHITTEST: { // // If the gripper is enabled then perform a simple hit test on our gripper area. DialogData *pdd = (DialogData*)dd; if( pdd && pdd->m_bShowSizingGrip ) { POINT pt = { LOWORD(lParam), HIWORD(lParam) }; (void)ScreenToClient( &pt ); if( PtInRect( pdd->m_rcGrip, pt ) ) return (BOOL)HTBOTTOMRIGHT; } } break; case WM_GETMINMAXINFO: { // // Our opportunity to say that we do not want the dialog to grow or shrink any more. DialogData *pdd = (DialogData*)dd; LPMINMAXINFO lpmmi = reinterpret_cast<LPMINMAXINFO>( lParam ); lpmmi->ptMinTrackSize = pdd->m_ptSmallest; if( pdd->m_bLargestSet ) { lpmmi->ptMaxTrackSize = pdd->m_ptLargest; } } return (BOOL)0; case WM_NOTIFY: { if( reinterpret_cast<LPNMHDR>(lParam)->code == PSN_SETACTIVE ) { CRect rc; VAPI( ::GetClientRect( *GetParent( ), &rc ) ); UpdateWindowSize( rc.Width(), rc.Height(), *GetParent( ) ); } } break; case WM_DESTROY: { // // Our opportunty for cleanup. // Simply acquire all of our objects, free the appropriate memory and remove the // properties from the window. If we do not remove the properties then they will constitute // a resource leak. DialogData *pdd = (DialogData*)dd; if( pdd ) { RegistryData rd; rd.m_wpl.length = sizeof( rd.m_wpl ); VAPI( GetWindowPlacement( &rd.m_wpl ) ); if( pdd->hkRootSave && pdd->pcszName ) { (void)RegSetValueExRecursive( pdd->hkRootSave, pdd->pcszName, NULL, REG_BINARY, reinterpret_cast<LPBYTE>( &rd ), sizeof( rd ) ); } if( pdd->psd ) { free(pdd->psd); } free(pdd); } } break; } return CDialog::OnWndMsg(msg, wParam, lParam, res); }
void CDrawContext::PolyLine( const POINT *pt, int nCount, COLORREF cr ) { SelectPen( cr ); VAPI( ::Polyline( m_hdc, pt, nCount ) ); }
void CDrawContext::FillRect( const CRect &rc, COLORREF cr ) { VAPI( ::FillRect( m_hdc, &rc, GetBrush( cr ) ) ); }