Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

355 lines
12 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. bltdc.hxx
  7. BLT display and device context wrappers: definition
  8. FILE HISTORY:
  9. beng 15-May-1991 Split from bltmisc.hxx
  10. terryk 18-Jul-1991 Add more function to DEVICE_CONTEXT.
  11. terryk 20-Jul-1991 Add PAINT_DEVICE_CONTEXT object
  12. Add fReleaseDC in DISPLAY_WINDOW
  13. johnl 09-Sep-1991 Added DrawFocusRect
  14. beng 26-Sep-1991 C7 delta
  15. KeithMo 07-Aug-1992 STRICTified.
  16. */
  17. #ifndef _BLT_HXX_
  18. #error "Don't include this file directly; instead, include it through blt.hxx"
  19. #endif // _BLT_HXX_
  20. #ifndef _BLTDC_HXX_
  21. #define _BLTDC_HXX_
  22. #include "base.hxx"
  23. #include "bltbitmp.hxx" // DISPLAY_MAP
  24. #include "bltmisc.hxx" // XYDIMENSION
  25. #include "string.hxx" // NLS_STR et al.
  26. #include "bltrect.hxx"
  27. DLL_CLASS WINDOW;
  28. #if !defined(MAKEINTRESOURCE) // was windows not yet included?
  29. struct TEXTMETRIC; // declared in windows.h as part of GDI
  30. #endif
  31. /**********************************************************************
  32. NAME: DEVICE_CONTEXT
  33. SYNOPSIS: Device context class (general GDI fun and games)
  34. INTERFACE: DEVICE_CONTEXT() - constructor
  35. ~DEVICE_CONTEXT() - destructor
  36. SelectPen() - select an HPEN into the DC
  37. SelectFont() - select an HFONT into the DC
  38. SelectBrush() - select an HBRUSH into the DC
  39. SelectBitmap() - select an HBITMAP into the DC
  40. QueryTextExtent() - get the width and height of a string
  41. QueryTextMetrics() - get the font information
  42. QueryHdc() - return the current HDC
  43. BitBlt() - call Window bitblt
  44. TextOut() - display text
  45. InvertRect() - invert the color within the
  46. given rectangle
  47. DrawFocusRect() - Draw Windows focus rectangle (this is
  48. an xor operation).
  49. DrawRect() - Draws a filled rectangle (using current
  50. selected brush)
  51. FrameRect() - Draws an unfilled rectangle using the
  52. passed brush
  53. SetBkMode() - Sets the background draw mode (OPAQUE
  54. or TRANSPARENT).
  55. GetBkMode() - Queries the background draw mode
  56. SetMapMode() - sets the mapping mode (e.g. MM_TEXT)
  57. GetMapMode() - queries the mapping mode
  58. SetBkColor() - set the background color
  59. GetBkColor() - query the background color
  60. SetTextColor() - set the text color
  61. GetTextColor() - query the text color
  62. ExtTextOut() - extension of text out function
  63. DrawText() - draws text
  64. USES: XYDIMENSION
  65. CAVEATS:
  66. Most of these functions are just thin wrappers around GDI functions.
  67. They don't have much on-line help. Go look it up in WinHelp!
  68. NOTES:
  69. Get functions should be Query. Yeah, yeah.
  70. HISTORY:
  71. RustanL 21-Nov-1990 Created
  72. terryk 10-Apr-1991 add QueryHdc
  73. terryk 11-Apr-1991 add GetPolyFillMode, SetPolyFillMode,
  74. Polygon, InvertRect
  75. beng 15-May-1991 Change QueryTextExtent; make
  76. QueryHdc const
  77. beng 10-Jul-1991 Remove Paint member; add QueryFontHeight,
  78. TextOut; additional forms of BitBlt
  79. terryk 18-Jul-1991 Add more functions:
  80. SetBkColor()
  81. SetTextColor()
  82. SetTextAlign()
  83. ExtTextOut()
  84. GetBkColor()
  85. Johnl 09-Sep-1991 Added DrawFocusRect()
  86. Johnl 11-Sep-1991 Added DrawRect(), FrameRect, SetBkMode &
  87. GetBkMode
  88. beng 04-Oct-1991 Win32 conversion
  89. beng 09-Oct-1991 Disabled Polygon member fcns
  90. beng 30-Mar-1992 All Color fcns take COLORREF parms; MapMode
  91. fcns; inline many fcns
  92. beng 05-May-1992 Added nls ExtTextOut; DrawText member
  93. beng 12-May-1992 Added LineTo, MoveTo, QueryAveCharWidth members
  94. KeithMo 07-Aug-1992 Added type-specific SelectXxx methods, made the
  95. generic SelectObject protected.
  96. **********************************************************************/
  97. DLL_CLASS DEVICE_CONTEXT
  98. {
  99. private:
  100. HDC _hDC;
  101. protected:
  102. HGDIOBJ SelectObject( HGDIOBJ hObject )
  103. { return ::SelectObject( _hDC, hObject ); }
  104. public:
  105. DEVICE_CONTEXT( HDC hDC ) : _hDC(hDC) {};
  106. HDC QueryHdc() const
  107. { return _hDC; }
  108. HPEN SelectPen( HPEN hPen )
  109. { return (HPEN)SelectObject( (HGDIOBJ)hPen ); }
  110. HFONT SelectFont( HFONT hFont )
  111. { return (HFONT)SelectObject( (HGDIOBJ)hFont ); }
  112. HBRUSH SelectBrush( HBRUSH hBrush )
  113. { return (HBRUSH)SelectObject( (HGDIOBJ)hBrush ); }
  114. HBITMAP SelectBitmap( HBITMAP hBitmap )
  115. { return (HBITMAP)SelectObject( (HGDIOBJ)hBitmap ); }
  116. XYDIMENSION QueryTextExtent( const TCHAR * psz, UINT cbTextLen ) const;
  117. XYDIMENSION QueryTextExtent( const NLS_STR &nls ) const;
  118. BOOL QueryTextMetrics( TEXTMETRIC * ptm ) const;
  119. INT QueryFontHeight() const;
  120. INT QueryAveCharWidth() const;
  121. BOOL TextOut( const NLS_STR &nls, XYPOINT xy ) const;
  122. BOOL TextOut( const NLS_STR &nls, XYPOINT xy,
  123. const RECT * prectClip ) const;
  124. BOOL TextOut( const TCHAR *psz, INT cch, INT xLeft, INT yTop ) const;
  125. BOOL TextOut( const TCHAR *psz, INT cch,
  126. INT xLeft, INT yTop, const RECT * prectClip ) const;
  127. BOOL BitBlt( INT xDest, INT yDest,
  128. INT dxDest, INT dyDest,
  129. const DEVICE_CONTEXT & dcSource,
  130. INT xSource, INT ySource,
  131. ULONG ulRasterOperation );
  132. BOOL BitBlt( const XYPOINT & xyDest,
  133. XYDIMENSION dxyDest,
  134. const DEVICE_CONTEXT & dcSource,
  135. const XYPOINT & xySource,
  136. ULONG ulRasterOperation );
  137. VOID DrawFocusRect( const RECT * pRect ) const;
  138. VOID DrawRect( const RECT * lpRect ) const;
  139. VOID FrameRect( const RECT * lpRect, HBRUSH hBrush ) const;
  140. VOID InvertRect( const RECT * lpRect ) const;
  141. #if 0 // (disabled - never used, too much trouble to wrap)
  142. BOOL Polygon( const POINT * ppt, INT cxy ) const;
  143. INT GetPolyFillMode() const;
  144. INT SetPolyFillMode( INT nPolyFillMode );
  145. #endif
  146. INT GetMapMode() const
  147. { return ::GetMapMode( _hDC ); }
  148. INT SetMapMode( INT nNewMapMode )
  149. { return ::SetMapMode( _hDC, nNewMapMode ); }
  150. INT GetBkMode() const
  151. { return ::GetBkMode( _hDC ); }
  152. INT SetBkMode( INT nNewBkMode )
  153. { return ::SetBkMode( _hDC, nNewBkMode ); }
  154. COLORREF GetBkColor() const
  155. { return ::GetBkColor( _hDC ); }
  156. COLORREF SetBkColor( COLORREF crColor )
  157. { return ::SetBkColor( _hDC, crColor ); }
  158. COLORREF GetTextColor() const
  159. { return ::GetTextColor( _hDC ); }
  160. COLORREF SetTextColor( COLORREF crColor )
  161. { return ::SetTextColor( _hDC, crColor ); }
  162. INT DrawText( const NLS_STR & nls, RECT * prc, UINT nStyles )
  163. { return ::DrawText( _hDC, nls.QueryPch(), -1, prc, nStyles ); }
  164. UINT SetTextAlign( UINT wFlag );
  165. BOOL ExtTextOut( INT x, INT y, UINT nOptions, const RECT * lpRect,
  166. const TCHAR * pszStr, INT cch, INT * pDx = NULL );
  167. BOOL ExtTextOut( INT x, INT y, UINT nOptions, const RECT * prect,
  168. const NLS_STR & nls, INT * pDx = NULL )
  169. { return ExtTextOut(x, y, nOptions, prect, nls.QueryPch(),
  170. nls.QueryTextLength(), pDx); }
  171. VOID LineTo( INT x, INT y ) const
  172. { ::LineTo( _hDC, x, y ); }
  173. VOID MoveTo( INT x, INT y ) const
  174. { ::MoveToEx( _hDC, x, y, NULL ); }
  175. };
  176. /**********************************************************************
  177. NAME: DISPLAY_CONTEXT
  178. SYNOPSIS: Display context
  179. INTERFACE: DISPLAY_CONTEXT() - constructor
  180. ~DISPLAY_CONTEXT() - destructor
  181. QueryTextWidth() - return the width of the given string
  182. in logical units on the screen
  183. PARENT: DEVICE_CONTEXT
  184. USES: WINDOW
  185. HISTORY:
  186. RustanL 21-Nov-1990 Created
  187. terryk 10-Apr-1991 Add querytextwidth
  188. beng 04-Oct-1991 Win32 conversion
  189. **********************************************************************/
  190. DLL_CLASS DISPLAY_CONTEXT : public DEVICE_CONTEXT
  191. {
  192. private:
  193. HWND _hwnd;
  194. BOOL _fReleaseDC;
  195. protected:
  196. HWND QueryHwnd() { return _hwnd; }
  197. public:
  198. DISPLAY_CONTEXT( HWND hwnd );
  199. DISPLAY_CONTEXT( WINDOW * pwin );
  200. DISPLAY_CONTEXT( WINDOW * pwin, HDC hdc );
  201. ~DISPLAY_CONTEXT();
  202. INT QueryTextWidth( const NLS_STR & nlsStr ) const;
  203. INT QueryTextWidth( const TCHAR * psz, UINT cbTextLen ) const;
  204. };
  205. /**********************************************************************
  206. NAME: PAINT_DISPLAY_CONTEXT
  207. SYNOPSIS: Replace BeginPaint and EndPaint in window
  208. INTERFACE: PAINT_DISPLAY_CONTEXT() - constructor. Call ::BeginPaint.
  209. ~PAINT_DISPLAY_CONTEXT() - destructor. Call ::EndPaint.
  210. PARENT: DISPLAY_CONTEXT
  211. USES: WINDOW
  212. HISTORY:
  213. terryk 20-Jul-1991 Created
  214. beng 09-Oct-1991 Shrank a bit
  215. beng 14-May-1992 Added QueryInvalidRect
  216. **********************************************************************/
  217. DLL_CLASS PAINT_DISPLAY_CONTEXT : public DISPLAY_CONTEXT
  218. {
  219. private:
  220. PAINTSTRUCT _ps;
  221. XYRECT _rNeedsPainting; // Has to copy into this just to
  222. // use the XYRECT member fcns.
  223. // CODEWORK: make an adopting XYRECT.
  224. public:
  225. PAINT_DISPLAY_CONTEXT( WINDOW * pwnd )
  226. : DISPLAY_CONTEXT( pwnd, ::BeginPaint( pwnd->QueryHwnd(), &_ps )),
  227. _rNeedsPainting(_ps.rcPaint)
  228. { ; }
  229. ~PAINT_DISPLAY_CONTEXT()
  230. { ::EndPaint( QueryHwnd(), &_ps ); }
  231. const XYRECT & QueryInvalidRect() const
  232. { return _rNeedsPainting; }
  233. };
  234. /**********************************************************************
  235. NAME: MEMORY_DC
  236. SYNOPSIS: "Memory" device context (copied from existing DC)
  237. INTERFACE: MEMORY_DC() - constructor
  238. ~MEMORY_DC() - destructor
  239. PARENT: DEVICE_CONTEXT
  240. HISTORY:
  241. RustanL 21-Nov-1990 Created
  242. **********************************************************************/
  243. DLL_CLASS MEMORY_DC : public DEVICE_CONTEXT
  244. {
  245. public:
  246. MEMORY_DC( DEVICE_CONTEXT & dc );
  247. ~MEMORY_DC();
  248. };
  249. /**********************************************************************
  250. NAME: SCREEN_DC
  251. SYNOPSIS: Screen device context
  252. INTERFACE: SCREEN_DC() - constructor
  253. ~SCREEN_DC() - destructor
  254. PARENT: DEVICE_CONTEXT
  255. HISTORY:
  256. RustanL 21-Nov-1990 Created
  257. **********************************************************************/
  258. DLL_CLASS SCREEN_DC : public DEVICE_CONTEXT
  259. {
  260. public:
  261. SCREEN_DC();
  262. ~SCREEN_DC();
  263. };
  264. #endif // _BLTDC_HXX_ - end of file