Leaked source code of windows server 2003
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.

465 lines
16 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. bltwin.hxx
  7. Base of the BLT WINDOW hierarchy
  8. FILE HISTORY
  9. RustanL 20-Nov-1990 Created
  10. RustanL 04-Mar-1991 Added OWNER_WINDOW::QueryError mechanism
  11. Johnl 12-Mar-1991 Removed _hwndOwner member
  12. beng 14-May-1991 Hack for separate compilation
  13. terryk 10-Jul-1991 Add IsEnable to the window class
  14. terryk 20-Jul-1991 Add QueryClientRect in WINDOW class.
  15. terryk 02-Aug-1991 Add QueryWindowRect in WINDOW class.
  16. beng 30-Sep-1991 Added ASSOCHWNDTHIS helper class
  17. KeithMo 23-Oct-1991 Added forward references.
  18. terryk 04-Apr-1992 Added Z position in SetPos
  19. Yi-HsinS 10-Dec-1992 Added CalcFixedHeight
  20. */
  21. #ifndef _BLT_HXX_
  22. #error "Don't include this file directly; instead, include it through blt.hxx"
  23. #endif // _BLT_HXX_
  24. #ifndef _BLTWIN_HXX_
  25. #define _BLTWIN_HXX_
  26. #include "base.hxx"
  27. #include "bltglob.hxx" // for CID
  28. #include "bltmisc.hxx" // for XYPOINT, XYDIMENSION
  29. #include "bltevent.hxx"
  30. //
  31. // Forward references.
  32. //
  33. DLL_CLASS WINDOW;
  34. DLL_CLASS CONTROL_TABLE; // declared and defined in bltowin.cxx
  35. DLL_CLASS CONTROL_WINDOW; // declared in bltctrl.hxx
  36. DLL_CLASS ITER_CTRL;
  37. DLL_CLASS OWNER_WINDOW;
  38. DLL_CLASS ASSOCCHWNDTHIS;
  39. DLL_CLASS PROC_INSTANCE;
  40. DLL_CLASS NLS_STR; // (declared in string.hxx)
  41. DLL_CLASS XYRECT; // (declared in bltrect.hxx)
  42. /******************************************************************
  43. NAME: WINDOW
  44. SYNOPSIS: Base of the "window" hierarchy.
  45. This class provides access to general window-manipulation
  46. functionality common to control, client, and dialog windows.
  47. It represents a single "window" object in the system, either
  48. created by the system or explicitly by the client.
  49. INTERFACE:
  50. WINDOW() - constructor
  51. ~WINDOW() - destructor
  52. QueryHwnd() - return the window handle
  53. QueryOwnerHwnd() - return the owner window handle
  54. Command() - command
  55. Show() - show window
  56. QueryClientRect() - return the clinet window dimension and position
  57. QueryWindowRect() - return the clinet window dimension and position
  58. in screen coordinate.
  59. Enable() - enable the window
  60. IsEnabled() - return the current status of the window
  61. QueryStyle() - return the current window style
  62. SetStyle() - set the window's style bits (protected)
  63. SetText() - set the window caption
  64. QueryTextLength() - return caption length
  65. QueryTextSize() - return size of caption, in bytes
  66. QueryText() - return current caption
  67. ClearText() - clear caption
  68. SetRedraw() - redraw the window
  69. Invalidate() - invalidate some or all of the window,
  70. optionally erasing the window
  71. RepaintNow() - force an immediate repaint of the window
  72. IsChild() - check whether the window is a child window
  73. SetPos() - set window position
  74. QueryPos() - return current window position
  75. SetSize() - set the window size
  76. QuerySize() - return current window size
  77. IsClientGeneratedMessage() - Returns TRUE if the current
  78. message was generated by us, thus it
  79. should be ignored.
  80. HasFocus() - returns TRUE if the current window has the focus.
  81. Center() - centers the window above another window.
  82. PARENT: BASE
  83. USES: XYPOINT, XYDIMENSION
  84. CAVEATS:
  85. NOTES:
  86. Should destructor be virtual?
  87. HISTORY:
  88. rustanl 20-Nov-1990 Created
  89. rustanl 04-Mar-1991 Added OWNER_WINDOW::QueryError mechanism
  90. johnl 12-Mar-1991 Removed _hwndOwner member
  91. beng 25-Apr-1991 Relocated QueryOwnerHwnd implementation;
  92. removed unused constructor forms
  93. rustanl 27-Apr-1991 Changed SetText( PSZ ) to
  94. SetText( const TCHAR * )
  95. beng 07-May-1991 Added CreateWindow version of ctor
  96. beng 10-May-1991 Added ResetCreator for errors
  97. Johnl 10-May-1991 Moved client generated message flag here
  98. beng 15-May-1991 Pruned constructors; enhanced
  99. Query/Set Pos/Size to grok XY* objects
  100. beng 23-May-1991 Changed return type of QueryText
  101. beng 10-Jun-1991 Added QueryTextSize; changed QTxtLen
  102. return type to INT
  103. terryk 10-Jul-1991 Added IsEnable function to the window class
  104. terryk 20-Jul-1991 Added QueryClientRect function to the class
  105. beng 31-Jul-1991 Added ShowFirst, static _fClientGen'd
  106. terryk 02-Aug-1991 Added QueryWindowRect function to the class
  107. beng 04-Oct-1991 Win32 conversion
  108. Yi-HsinS 08-Jan-1992 Added HasFocus method
  109. beng 13-Feb-1992 Moved RepaintNow here from CLIENT_WINDOW;
  110. add SetStyle
  111. KeithMo 11-Nov-1992 Added new ctor form and Center method.
  112. **********************************************************************/
  113. DLL_CLASS WINDOW: public BASE
  114. {
  115. private:
  116. HWND _hwnd;
  117. BOOL _fCreator;
  118. // This flag indicates that the message was generated internally and not
  119. // by the user manipulating controls. It is used where we may want
  120. // to ignore internally generated changes (for example, in SetText,
  121. // windows sends out an EN_CHANGE message to the control, so anything
  122. // that responds and does a SetText will be caught in an infinite loop).
  123. //
  124. // See SetClientGeneratedMsgFlag and IsClientGeneratedMessage.
  125. //
  126. static BOOL _fClientGeneratedMessage;
  127. protected:
  128. VOID SetHwnd( HWND hwnd );
  129. VOID ResetCreator();
  130. static VOID SetClientGeneratedMsgFlag( BOOL fClientGeneratedMessage ) ;
  131. static BOOL CalcFixedHeight( HWND hwnd, UINT *pnHeight );
  132. public:
  133. WINDOW();
  134. WINDOW( const TCHAR * pszClassName,
  135. ULONG flStyle,
  136. const WINDOW * pwndOwner = 0,
  137. CID cid = 0 );
  138. WINDOW( HWND hwnd );
  139. ~WINDOW();
  140. // These two methods are prime candidates for inlining.
  141. //
  142. HWND QueryHwnd() const;
  143. HWND QueryOwnerHwnd() const;
  144. // Note. This method may change things in the window itself, but
  145. // will not change any data member per se. The method needs to be
  146. // const, however, since many other const methods may call it for
  147. // real const kind of operations, e.g. LIST_CONTROL::QueryCount.
  148. //
  149. // (Should this become a protected method?)
  150. // (Also, can I replace it with something that passes an EVENT?)
  151. //
  152. ULONG_PTR Command( UINT nMsg, WPARAM wParam = 0, LPARAM lParam = 0L ) const;
  153. BOOL Show( BOOL f = TRUE );
  154. VOID Enable( BOOL f = TRUE );
  155. BOOL IsEnabled() const;
  156. ULONG QueryStyle() const;
  157. VOID SetText( const TCHAR * psz );
  158. VOID SetText( const NLS_STR & nls );
  159. INT QueryTextLength() const;
  160. INT QueryTextSize() const;
  161. APIERR QueryText( TCHAR * pszBuffer, UINT cbBufSize ) const;
  162. APIERR QueryText( NLS_STR * pnls ) const;
  163. VOID ClearText();
  164. VOID SetRedraw( BOOL f = TRUE );
  165. VOID Invalidate( BOOL fErase = FALSE ); // entire client area
  166. VOID Invalidate( const XYRECT & rect ); // selective inval
  167. VOID RepaintNow();
  168. VOID ShowFirst();
  169. // Returns TRUE if child style bit is set
  170. //
  171. BOOL IsChild() const;
  172. VOID SetPos( XYPOINT xy, BOOL fRepaint = TRUE, WINDOW *pwin = NULL );
  173. XYPOINT QueryPos() const;
  174. VOID SetSize( INT nWidth, INT nHeight, BOOL fRepaint = TRUE );
  175. VOID SetSize( XYDIMENSION dxy, BOOL fRepaint = TRUE );
  176. VOID QuerySize( INT *pnWidth, INT * pnHeight ) const;
  177. XYDIMENSION QuerySize() const;
  178. VOID QueryClientRect( RECT * pRect ) const;
  179. VOID QueryClientRect( XYRECT * pxycd ) const;
  180. VOID QueryWindowRect( RECT * pRect ) const;
  181. VOID QueryWindowRect( XYRECT * pxycd ) const;
  182. static BOOL IsClientGeneratedMessage();
  183. BOOL HasFocus( VOID ) const;
  184. VOID SetStyle( ULONG nValue );
  185. VOID Center( HWND hwnd = NULL );
  186. // For the anglophiles & dyslexics in the crowd.
  187. // You know who you are...
  188. VOID Centre( HWND hwnd = NULL )
  189. { Center( hwnd ); }
  190. };
  191. /**********************************************************************
  192. NAME: OWNER_WINDOW
  193. SYNOPSIS: Owner window class - base of any window owning others.
  194. INTERFACE:
  195. OWNER_WINDOW() - constructor
  196. ~OWNER_WINDOW() - destructor
  197. QueryRobustHwnd() - return the handle
  198. SetFocus() - set window focus
  199. SetDialogFocus() - set window focus to a dialog control. Handles
  200. default pushbuttons correctly.
  201. PARENT: WINDOW
  202. USES: CONTROL_TABLE, ITER_CTRL
  203. CAVEATS:
  204. NOTES:
  205. HISTORY:
  206. rustanl 20-Nov-1990 Created
  207. rustanl 04-Mar-1991 Added OWNER_WINDOW::QueryError mechanism
  208. Johnl 12-Mar-1991 Removed _hwndOwner member
  209. beng 25-Apr-1991 Removed it from constructor as well;
  210. inherits from BASE
  211. beng 15-May-1991 Trimmed constructor
  212. beng 21-May-1991 Added sundry owner-draw support
  213. beng 15-Oct-1991 Win32 conversion
  214. beng 30-Oct-1991 Added ITER_CTRL as a friend
  215. KeithMo 14-Oct-1992 Added OnUserMessage.
  216. **********************************************************************/
  217. DLL_CLASS OWNER_WINDOW : public WINDOW
  218. {
  219. friend class CONTROL_WINDOW;
  220. friend class ITER_CTRL;
  221. private:
  222. CONTROL_TABLE * _pctrltable;
  223. // Generic control attributes word. By convention, BLT controls
  224. // lower 16 bits, users have upper 16 bits.
  225. DWORD _dwAttributes ;
  226. // This is called by the constructor of CONTROL_WINDOW
  227. //
  228. BOOL AddControl( CONTROL_WINDOW * pctrlwin );
  229. protected:
  230. CONTROL_WINDOW * CidToCtrlPtr( CID cid ) const;
  231. // Provide for custom drawn ("owner-draw" in Win parlance) controls.
  232. //
  233. INT OnCDMessages( UINT nMsg, WPARAM wParam, LPARAM lParam );
  234. static INT OnLBIMessages( UINT nMsg, WPARAM wParam, LPARAM lParam );
  235. static BOOL CalcFixedCDMeasure( HWND hwnd, MEASUREITEMSTRUCT * pmis );
  236. virtual BOOL OnUserMessage( const EVENT & );
  237. public:
  238. OWNER_WINDOW();
  239. OWNER_WINDOW( const TCHAR * pszClassName,
  240. ULONG flStyle,
  241. const WINDOW * pwndOwner );
  242. ~OWNER_WINDOW();
  243. // QueryRobustHwnd returns the hwnd of the window if it locks down the
  244. // parent window. Otherwise, it returns the hwnd of the parent
  245. // window.
  246. // This method is used (especially) by the MsgPopup API, which
  247. // may be called before a window has locked down its parent. If
  248. // QueryHwnd is called instead of this method, the MsgPopup may
  249. // accidentally become modeless if called before the window locks
  250. // down its parent.
  251. //
  252. virtual HWND QueryRobustHwnd() const = 0;
  253. VOID SetFocus( CID cid );
  254. VOID SetDialogFocus( CONTROL_WINDOW & ctrlwin );
  255. // Return the entire attributes DWORD
  256. DWORD QueryAttributeFlags ()
  257. { return _dwAttributes ; }
  258. // Set the entire attributes DWORD
  259. VOID SetAttributeFlags ( DWORD dwAttributes )
  260. { _dwAttributes = dwAttributes ; }
  261. // Set a single attribute
  262. VOID SetAttribute ( DWORD dwAttribute, BOOL fOn = TRUE )
  263. { if ( fOn )
  264. _dwAttributes |= dwAttribute ;
  265. else
  266. _dwAttributes &= ~ dwAttribute ;
  267. }
  268. // Test a single attribute
  269. BOOL QueryAttribute ( DWORD dwAttribute )
  270. { return (_dwAttributes & dwAttribute) > 0 ; }
  271. };
  272. /*************************************************************************
  273. NAME: ASSOCHWNDTHIS
  274. SYNOPSIS: Keeps a this-pointer in a window's properties
  275. INTERFACE: ASSOCHWNDTHIS() - ctor, associating the tuple
  276. ~ASSOCHWNDTHIS() - dtor, removing the wndprops
  277. HwndToThis() - given a hwnd, locates the
  278. corresponding this-pointer
  279. PARENT: BASE
  280. HISTORY:
  281. beng 30-Sep-1991 Created
  282. **************************************************************************/
  283. DLL_CLASS ASSOCHWNDTHIS: public BASE
  284. {
  285. private:
  286. static const TCHAR * _pszPropThisLo;
  287. static const TCHAR * _pszPropThisHi;
  288. HWND _hwnd;
  289. public:
  290. ASSOCHWNDTHIS( HWND hwnd, const VOID * pwnd );
  291. ~ASSOCHWNDTHIS();
  292. static VOID * HwndToThis( HWND hwnd );
  293. };
  294. /**********************************************************************
  295. NAME: PROC_INSTANCE
  296. SYNOPSIS: Procedure instance class
  297. INTERFACE:
  298. PROC_INSTANCE() - constructor
  299. ~PROC_INSTANCE() - destructor
  300. QueryProc() - return the procedure instance address
  301. PARENT: BASE
  302. NOTES:
  303. This is a simple wrapper around MakeProcInstance.
  304. MakeProcInstance is a no-op on Win32.
  305. HISTORY:
  306. RustanL 21-Nov-1990 Created
  307. beng 30-Sep-1991 Changed op() to QueryProc, inlined
  308. beng 17-Oct-1991 Made conditional on not-Win32
  309. **********************************************************************/
  310. DLL_CLASS PROC_INSTANCE : public BASE
  311. {
  312. private:
  313. MFARPROC _fpInstance;
  314. public:
  315. PROC_INSTANCE( MFARPROC fp );
  316. ~PROC_INSTANCE();
  317. MFARPROC QueryProc() const
  318. { return _fpInstance; }
  319. };
  320. /*************************************************************************
  321. NAME: ITER_CTRL
  322. SYNOPSIS: Iterate over each control within an owner window
  323. INTERFACE: ITER_CTRL() - ctor, taking owner window as argument
  324. Reset() - resets iterator to its initial state
  325. Next() - gets the next element in the sequence
  326. operator()() - synonym for "Next"
  327. USES: CONTROL_WINDOW, OWNBER_WINDOW, CONTROL_TABLE
  328. NOTES:
  329. The iterator returns controls in the order which they
  330. were constructed.
  331. CAVEATS:
  332. This is a pretty lightweight little iterator. It performs
  333. no locking or other checking in the case of overlapping control
  334. add/deletes in the window. Should you elect to add or remove
  335. a control, however, a Reset will correct the iterator.
  336. HISTORY:
  337. beng 30-Oct-1991 Created
  338. **************************************************************************/
  339. DLL_CLASS ITER_CTRL
  340. {
  341. private:
  342. const OWNER_WINDOW * _pwndOwning;
  343. const CONTROL_TABLE * _pctrltable;
  344. UINT _ictrl;
  345. UINT _cctrl;
  346. public:
  347. ITER_CTRL( const OWNER_WINDOW * pwnd );
  348. VOID Reset();
  349. CONTROL_WINDOW * Next();
  350. CONTROL_WINDOW * operator()() { return Next(); }
  351. };
  352. #endif // _BLTWIN_HXX_ - end of file