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.

530 lines
17 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. bltbutn.hxx
  7. BLT button control class definitions
  8. FILE HISTORY:
  9. beng 17-Sep-1991 Separated from bltctrl.hxx
  10. KeithMo 23-Oct-1991 Added forward references.
  11. */
  12. #ifndef _BLT_HXX_
  13. #error "Don't include this file directly; instead, include it through blt.hxx"
  14. #endif // _BLT_HXX_
  15. #ifndef _BLTBUTN_HXX_
  16. #define _BLTBUTN_HXX_
  17. #include "bltctrl.hxx"
  18. #include "bltbitmp.hxx"
  19. //
  20. // Forward references.
  21. //
  22. DLL_CLASS BUTTON_CONTROL;
  23. DLL_CLASS PUSH_BUTTON;
  24. DLL_CLASS GRAPHICAL_BUTTON;
  25. DLL_CLASS GRAPHICAL_BUTTON_WITH_DISABLE;
  26. DLL_CLASS STATE_BUTTON_CONTROL;
  27. DLL_CLASS STATE2_BUTTON_CONTROL;
  28. DLL_CLASS STATE3_BUTTON_CONTROL;
  29. DLL_CLASS RADIO_BUTTON;
  30. DLL_CLASS RADIO_GROUP;
  31. DLL_CLASS CHECKBOX;
  32. DLL_CLASS TRISTATE;
  33. /*********************************************************************
  34. NAME: BUTTON_CONTROL
  35. SYNOPSIS: Base class for all button-type controls
  36. INTERFACE: BUTTON_CONTROL() - constructor
  37. PARENT: CONTROL_WINDOW
  38. NOTES:
  39. This class provides the Windows winclass name for all
  40. children of the class.
  41. HISTORY:
  42. rustanl 20-Nov-90 Creation
  43. beng 17-May-1991 Added app-window constructor
  44. beng 17-Sep-1991 Rephrased classname argument;
  45. made ctor protected
  46. KeithMo 27-Oct-1992 Moved QueryEventEffects here from
  47. STATE_BUTTON_CONTROL.
  48. **********************************************************************/
  49. DLL_CLASS BUTTON_CONTROL : public CONTROL_WINDOW
  50. {
  51. protected:
  52. BUTTON_CONTROL( OWNER_WINDOW * powin, CID cid );
  53. BUTTON_CONTROL( OWNER_WINDOW * powin, CID cid,
  54. XYPOINT xy, XYDIMENSION dxy, ULONG flStyle );
  55. virtual UINT QueryEventEffects( const CONTROL_EVENT & e );
  56. };
  57. /*********************************************************************
  58. NAME: PUSH_BUTTON
  59. SYNOPSIS: push button control class
  60. INTERFACE:
  61. PUSH_BUTTON() - constructor
  62. MakeDefault() - send a DM_SETDEFID to the system
  63. PARENT: BUTTON_CONTROL
  64. CAVEATS:
  65. NOTES:
  66. HISTORY:
  67. rustanl 20-Nov-90 Creation
  68. beng 17-May-1991 Added app-window constructor
  69. beng 17-Sep-1991 Elided unnecessary classname arg
  70. **********************************************************************/
  71. DLL_CLASS PUSH_BUTTON : public BUTTON_CONTROL
  72. {
  73. public:
  74. PUSH_BUTTON( OWNER_WINDOW * powin, CID cid );
  75. PUSH_BUTTON( OWNER_WINDOW * powin, CID cid,
  76. XYPOINT xy, XYDIMENSION dxy, ULONG flStyle );
  77. VOID MakeDefault();
  78. };
  79. /*********************************************************************
  80. NAME: GRAPHICAL_BUTTON (gb)
  81. SYNOPSIS: Graphical push button control class
  82. INTERFACE: GRAPHICAL_BUTTON(powin, cid, hbmMain, hbmStatus) - constructor
  83. QueryMain() - return bitmap of picture
  84. QueryStatus() - return status light bitmap
  85. SetStatus() - set status light bitmap
  86. PARENT: PUSH_BUTTON
  87. CAVEATS: Once a graphical button is constructed, the bitmap
  88. belongs to the button and will be deleted when the
  89. button is destroyed. The status light bitmap, however,
  90. is NOT destroyed, since the same bitmaps will probably
  91. be used by several buttons simultaneously.
  92. NOTES: For best results, the status light bitmap (if any)
  93. should be a 10x10 color bitmap.
  94. HISTORY:
  95. gregj 04-Apr-91 Created
  96. gregj 01-May-91 Added GUILTT support
  97. beng 17-May-1991 Added app-window constructor
  98. terryk 20-Jun-1991 Change HBITMAP to BIT_MAP
  99. terryk 21-Jun-1991 Added more constructors
  100. terryk 17-Jul-1991 Added another SetStatus with take hbitmap as
  101. a parameter
  102. beng 17-Sep-1991 Elided unnecessary classname arg
  103. beng 30-Mar-1992 Completely elide GUILTT support
  104. beng 01-Jun-1992 Change to CD_Draw as part of GUILTT change
  105. beng 04-Apr-1992 Pruned HBITMAP versions
  106. KeithMo 13-Dec-1992 Moved ctor guts to CtAux(), uses DISPLAY_MAP.
  107. **********************************************************************/
  108. DLL_CLASS GRAPHICAL_BUTTON : public PUSH_BUTTON
  109. {
  110. private:
  111. DISPLAY_MAP * _pdmMain;
  112. DISPLAY_MAP * _pdmStatus;
  113. DISPLAY_MAP * _pdmMainDisabled;
  114. VOID CtAux( const TCHAR * pszMainName,
  115. const TCHAR * pszMainDisabledName,
  116. const TCHAR * pszStatusName );
  117. protected:
  118. virtual BOOL CD_Draw(DRAWITEMSTRUCT *pdis);
  119. public:
  120. GRAPHICAL_BUTTON( OWNER_WINDOW * powin,
  121. CID cid,
  122. const TCHAR * pszMainName,
  123. const TCHAR * pszMainDisabledName = NULL,
  124. const TCHAR * pszStatusName = NULL );
  125. GRAPHICAL_BUTTON( OWNER_WINDOW * powin,
  126. CID cid,
  127. const TCHAR * pszMainName,
  128. const TCHAR * pszMainDisabledName,
  129. XYPOINT xy,
  130. XYDIMENSION dxy,
  131. ULONG flStyle,
  132. const TCHAR * pszStatusName = NULL );
  133. ~GRAPHICAL_BUTTON();
  134. HBITMAP QueryMain() const
  135. { return (_pdmMain != NULL)
  136. ? _pdmMain->QueryBitmapHandle()
  137. : NULL; }
  138. HBITMAP QueryMainDisabled() const
  139. { return (_pdmMainDisabled != NULL)
  140. ? _pdmMainDisabled->QueryBitmapHandle()
  141. : NULL; }
  142. HBITMAP QueryStatus() const
  143. { return (_pdmStatus != NULL)
  144. ? _pdmStatus->QueryBitmapHandle()
  145. : NULL; }
  146. VOID SetStatus( BMID bmidNewStatus );
  147. VOID SetStatus( HBITMAP hbitmap );
  148. };
  149. /**********************************************************************
  150. NAME: GRAPHICAL_BUTTON_WITH_DISABLE
  151. SYNOPSIS: This graphical button is similar to GRAPHICAL_BUTTON.
  152. The differences are:
  153. 1. It will expand the main bitmap and try to cover the
  154. whole button.
  155. 2. It allow the user specified a disable bitmap. It will
  156. display the bitmap when the button is disable.
  157. INTERFACE:
  158. GRAPHICAL_BUTTON_WITH_DISABLE() - constructor
  159. QuerybmpDisable() - get the HBITMAP of the disable bitmap
  160. QueryMain() - Query the handle of the Main bitmap
  161. QueryMainInvert() - Query the handle of the inverted bitmap
  162. QueryDisable() - Query the handle of the disable bitmap
  163. SetSelected( ) - set the current status of the bitmap
  164. QuerySelected() - query the current status of the
  165. bitmap
  166. PARENT: PUSH_BUTTON
  167. USES: BIT_MAP
  168. HISTORY:
  169. terryk 22-May-91 Created
  170. terryk 20-Jun-91 Change HBITMAP to BIT_MAP
  171. terryk 21-Jun-91 Added more constructor
  172. terryk 18-JUl-91 Check the parent class the PUSH_BUTTON
  173. beng 17-Sep-1991 Elided unnecessary classname arg
  174. beng 01-Jun-1992 Change to CD_Draw as part of GUILTT change
  175. beng 04-Aug-1992 Loads bitmaps by ordinal; prune HBITMAP ver
  176. ***********************************************************************/
  177. DLL_CLASS GRAPHICAL_BUTTON_WITH_DISABLE : public PUSH_BUTTON
  178. {
  179. private:
  180. BIT_MAP _bmMain; // Main bitmap
  181. BIT_MAP _bmMainInvert; // invert bitmap
  182. BIT_MAP _bmDisable; // disable bitmap
  183. BOOL _fSelected; // selected flag
  184. protected:
  185. virtual BOOL CD_Draw( DRAWITEMSTRUCT * pdis );
  186. public:
  187. GRAPHICAL_BUTTON_WITH_DISABLE( OWNER_WINDOW *powin, CID cid,
  188. BMID nIdMain, BMID nIdInvert,
  189. BMID nIdDisable );
  190. GRAPHICAL_BUTTON_WITH_DISABLE( OWNER_WINDOW *powin, CID cid,
  191. BMID nIdMain, BMID nIdInvert,
  192. BMID nIdDisable,
  193. XYPOINT xy, XYDIMENSION dxy,
  194. ULONG flStyle );
  195. ~GRAPHICAL_BUTTON_WITH_DISABLE();
  196. HBITMAP QueryMain() const
  197. { return (!_bmMain) ? NULL : _bmMain.QueryHandle(); }
  198. HBITMAP QueryMainInvert() const
  199. { return (!_bmMainInvert) ? NULL : _bmMainInvert.QueryHandle(); }
  200. HBITMAP QueryDisable() const
  201. { return (!_bmDisable) ? NULL : _bmDisable.QueryHandle(); }
  202. // set the selected condition
  203. VOID SetSelected( BOOL fSelected )
  204. { _fSelected = fSelected; }
  205. BOOL QuerySelected() const
  206. { return _fSelected; }
  207. };
  208. /*********************************************************************
  209. NAME: STATE_BUTTON_CONTROL
  210. SYNOPSIS: State button control base class
  211. INTERFACE: STATE_BUTTON_CONTROL() - constructor.
  212. SetState() - set the state
  213. QueryState() - query the state
  214. PARENT: BUTTON_CONTROL
  215. CAVEATS:
  216. You probably don't want to call this class directly.
  217. See CHECKBOX, RADIO_BUTTON, and TRISTATE for more
  218. appetizing alternatives.
  219. NOTES:
  220. This is a base class,
  221. HISTORY:
  222. rustanl 20-Nov-90 Creation
  223. Johnl 25-Apr-91 Made SetCheck protected (Set buttons
  224. through RADIO_GROUP or the public
  225. CHECKBOX::SetCheck).
  226. beng 17-May-1991 Added app-window constructor
  227. beng 31-Jul-1991 Renamed QMessageInfo to QEventEffects
  228. beng 17-Sep-1991 Elided unnecessary classname arg
  229. beng 18-Sep-1991 Made "state" n-way; moved BOOL-ness to
  230. a separate subclass
  231. beng 04-Oct-1991 Win32 conversion
  232. KeithMo 27-Oct-1992 Moved QueryEventEffects to BUTTON_CONTROL.
  233. *********************************************************************/
  234. DLL_CLASS STATE_BUTTON_CONTROL : public BUTTON_CONTROL
  235. {
  236. private:
  237. // Used to save value when control is Inactive.
  238. //
  239. UINT _nSaveCheck;
  240. protected:
  241. STATE_BUTTON_CONTROL( OWNER_WINDOW * powin, CID cid );
  242. STATE_BUTTON_CONTROL( OWNER_WINDOW * powin, CID cid,
  243. XYPOINT xy, XYDIMENSION dxy, ULONG flStyle );
  244. VOID SetState( UINT nValue );
  245. UINT QueryState() const;
  246. /* Redefine CONTROL_VALUE defaults.
  247. */
  248. virtual VOID SaveValue( BOOL fInvisible = TRUE );
  249. virtual VOID RestoreValue( BOOL fInvisible = TRUE );
  250. };
  251. /*************************************************************************
  252. NAME: STATE2_BUTTON_CONTROL
  253. SYNOPSIS: Base class for state buttons with binary state.
  254. INTERFACE: SetCheck() - sets and resets the button
  255. QueryCheck()- returns the "checked" state of the button
  256. PARENT: STATE_BUTTON_CONTROL
  257. CAVEATS:
  258. Do not instantiate this class directly. See CHECKBOX
  259. or RADIO_BUTTON for uses.
  260. NOTES:
  261. This is a base class.
  262. HISTORY:
  263. beng 18-Sep-1991 Created, when adding tristates.
  264. **************************************************************************/
  265. DLL_CLASS STATE2_BUTTON_CONTROL : public STATE_BUTTON_CONTROL
  266. {
  267. protected:
  268. STATE2_BUTTON_CONTROL( OWNER_WINDOW * powin, CID cid )
  269. : STATE_BUTTON_CONTROL(powin, cid) { }
  270. STATE2_BUTTON_CONTROL( OWNER_WINDOW * powin, CID cid,
  271. XYPOINT xy, XYDIMENSION dxy, ULONG flStyle )
  272. : STATE_BUTTON_CONTROL( powin, cid, xy, dxy, flStyle ) { }
  273. public:
  274. VOID SetCheck( BOOL fValue = TRUE )
  275. { STATE_BUTTON_CONTROL::SetState( (UINT)!!fValue ); }
  276. BOOL QueryCheck() const
  277. { return (STATE_BUTTON_CONTROL::QueryState() != 0); }
  278. };
  279. /*********************************************************************
  280. NAME: RADIO_BUTTON
  281. SYNOPSIS: Radio button control.
  282. INTERFACE: RADIO_BUTTON() - constructor
  283. PARENT: STATE2_BUTTON_CONTROL
  284. CAVEATS:
  285. See RADIO_GROUP.
  286. NOTES:
  287. The RADIO_BUTTON class is primarily meant to be used by
  288. the RADIO_GROUP class. It hides its SetCheck member, then
  289. makes it visible to the group only.
  290. HISTORY:
  291. rustanl 20-Nov-90 Creation
  292. Johnl 23-Apr-91 Removed OnUserAction (shell dialog proc
  293. will call the group OnUserAction auto-
  294. matically).
  295. beng 17-May-1991 Added app-window constructor
  296. beng 17-Sep-1991 Elided unnecessary classname arg
  297. beng 18-Sep-1991 Adjust hierarchy for tristates
  298. *********************************************************************/
  299. DLL_CLASS RADIO_BUTTON : public STATE2_BUTTON_CONTROL
  300. {
  301. friend class RADIO_GROUP; // Grant access to SetCheck method.
  302. private: // Hide from clients (who should set radio
  303. // buttons through their group).
  304. VOID SetCheck(BOOL fValue)
  305. { STATE2_BUTTON_CONTROL::SetCheck(fValue); }
  306. public:
  307. RADIO_BUTTON( OWNER_WINDOW * powin, CID cid )
  308. : STATE2_BUTTON_CONTROL(powin, cid) { }
  309. RADIO_BUTTON( OWNER_WINDOW * powin, CID cid,
  310. XYPOINT xy, XYDIMENSION dxy, ULONG flStyle )
  311. : STATE2_BUTTON_CONTROL( powin, cid, xy, dxy, flStyle ) { }
  312. };
  313. /*********************************************************************
  314. NAME: CHECKBOX
  315. SYNOPSIS: Check box control.
  316. INTERFACE: CHECKBOX() - constructor
  317. Toggle() - toggle the check status
  318. PARENT: STATE2_BUTTON_CONTROL
  319. HISTORY:
  320. rustanl 20-Nov-90 Creation
  321. beng 17-May-1991 Added app-window constructor
  322. beng 17-Sep-1991 Elided unnecessary classname arg
  323. beng 18-Sep-1991 Adjust hierarchy for tristates
  324. *********************************************************************/
  325. DLL_CLASS CHECKBOX : public STATE2_BUTTON_CONTROL
  326. {
  327. public:
  328. CHECKBOX( OWNER_WINDOW * powin, CID cid )
  329. : STATE2_BUTTON_CONTROL(powin, cid) { }
  330. CHECKBOX( OWNER_WINDOW * powin, CID cid,
  331. XYPOINT xy, XYDIMENSION dxy, ULONG flStyle )
  332. : STATE2_BUTTON_CONTROL( powin, cid, xy, dxy, flStyle ) { }
  333. BOOL Toggle();
  334. };
  335. /*************************************************************************
  336. NAME: STATE3_BUTTON_CONTROL
  337. SYNOPSIS: Base class for state buttons with 3-way state.
  338. INTERFACE: SetCheck() - sets and resets the button
  339. SetIndeterminate() - puts the button into "indeterminate"
  340. state.
  341. IsIndeterminate() - returns whether button has any setting.
  342. IsChecked() - returns whether button has a check.
  343. PARENT: STATE_BUTTON_CONTROL
  344. CAVEATS:
  345. Do not instantiate this class directly; instead, use TRISTATE.
  346. NOTES:
  347. This is a base class.
  348. HISTORY:
  349. beng 18-Sep-1991 Created, when adding tristates.
  350. beng 19-Sep-1991 Renamed SetGrey to SetIndeterminate
  351. **************************************************************************/
  352. DLL_CLASS STATE3_BUTTON_CONTROL : public STATE_BUTTON_CONTROL
  353. {
  354. protected:
  355. STATE3_BUTTON_CONTROL( OWNER_WINDOW * powin, CID cid )
  356. : STATE_BUTTON_CONTROL(powin, cid) { }
  357. STATE3_BUTTON_CONTROL( OWNER_WINDOW * powin, CID cid,
  358. XYPOINT xy, XYDIMENSION dxy, ULONG flStyle )
  359. : STATE_BUTTON_CONTROL( powin, cid, xy, dxy, flStyle ) { }
  360. public:
  361. VOID SetCheck( BOOL fValue )
  362. { STATE_BUTTON_CONTROL::SetState( (UINT) !!fValue ); }
  363. VOID SetIndeterminate()
  364. { STATE_BUTTON_CONTROL::SetState( 2 ); }
  365. BOOL IsIndeterminate() const
  366. { return (STATE_BUTTON_CONTROL::QueryState() == 2); }
  367. BOOL IsChecked() const
  368. { return (STATE_BUTTON_CONTROL::QueryState() == 1); }
  369. };
  370. /*************************************************************************
  371. NAME: TRISTATE
  372. SYNOPSIS: 3-way checkbox control.
  373. INTERFACE: EnableThirdState() - allows client to suppress 3-state
  374. operation
  375. PARENT: STATE3_BUTTON_CONTROL
  376. HISTORY:
  377. beng 18-Sep-1991 Created
  378. beng 19-Sep-1991 Added EnableThirdState member
  379. **************************************************************************/
  380. DLL_CLASS TRISTATE: public STATE3_BUTTON_CONTROL
  381. {
  382. public:
  383. TRISTATE( OWNER_WINDOW * powin, CID cid )
  384. : STATE3_BUTTON_CONTROL(powin, cid) { }
  385. TRISTATE( OWNER_WINDOW * powin, CID cid,
  386. XYPOINT xy, XYDIMENSION dxy, ULONG flStyle )
  387. : STATE3_BUTTON_CONTROL( powin, cid, xy, dxy, flStyle ) { }
  388. VOID EnableThirdState(BOOL fEnable);
  389. };
  390. #endif // _BLTBUTN_HXX_ - end of file