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.

435 lines
14 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. bltgroup.hxx
  7. This file contains the basic CONTROL_GROUP definition plus RADIO_GROUP
  8. and MAGIC_GROUP.
  9. FILE HISTORY:
  10. Johnl 23-Apr-1991 Created
  11. beng 14-May-1991 Made client inclusion depend on blt.hxx
  12. KeithMo 23-Oct-1991 Added forward references.
  13. */
  14. #ifndef _BLT_HXX_
  15. #error "Don't include this file directly; instead, include it through blt.hxx"
  16. #endif // _BLT_HXX_
  17. #ifndef _BLTGROUP_HXX_
  18. #define _BLTGROUP_HXX_
  19. #include "bltdlg.hxx"
  20. #include "uibuffer.hxx"
  21. #include "heap.hxx"
  22. #include "array.hxx"
  23. /* GROUP_NO_CHANGE is the manifest returned by the OnUserAction & OnGroupAction
  24. * of groups. It is used in ShellDlgProc to quit parent group notification.
  25. * It should never be in the range of valid errors.
  26. */
  27. #define GROUP_NO_CHANGE (0xffff)
  28. /* Indicates no selection in a radio group
  29. */
  30. #define RG_NO_SEL (0xFFFF)
  31. //
  32. // Forward references.
  33. //
  34. DLL_CLASS CONTROL_GROUP;
  35. DLL_CLASS CONTROL_WINDOW;
  36. DLL_CLASS RADIO_BUTTON;
  37. DLL_CLASS BUFFER;
  38. DLL_CLASS MAGIC_GROUP;
  39. DLL_CLASS CONTROLVAL_CID_PAIR;
  40. /*************************************************************************
  41. NAME: CONTROL_GROUP
  42. SYNOPSIS: The CONTROL_GROUP class defines a set of one or more controls that
  43. act as a single conglomeration (i.e., inactivating this group
  44. inactivates all of the controls in this group). This class
  45. is primarily an abstract superclass that brings together
  46. the common elements from CONTROL_VALUE and BASE.
  47. INTERFACE:
  48. CONTROL_GROUP()
  49. Constructor - does nothing.
  50. OnUserAction()
  51. A Control that says it belongs to this group (i.e., its group
  52. pointer points to this group) received the message
  53. contained in lParam (this is the same lParam sent to the
  54. control). If pcw->QueryEventEffects( lParam ) returns
  55. CVMI_NO_VALUE_CHANGE (the control has in fact, not changed),
  56. the client should return GROUP_NO_CHANGE. This will prevent
  57. the parent groups from being notified.
  58. OnGroupAction()
  59. BLT calls OnGroupAction to let this group know that some action
  60. may have caused the group pointed to by pgroup to be modified.
  61. AfterGroupActions()
  62. This virtual allows the group to do something after all of its
  63. parent groups have been notified. For example, set the focus
  64. to the appropriate control.
  65. CVSaveValue()
  66. By passing a pointer to the control value, this function will
  67. call the SaveValue function of the control value object.
  68. The boolean passed in is TRUE if we want to make the controls
  69. invisible, FALSE otherwise.
  70. CVRestoreValue()
  71. By passing a pointer to the control value, this function will
  72. call the RestoreValue function of the control value object.
  73. The boolean passed in is TRUE if the controls are invisible,
  74. FALSE otherwise.
  75. PARENT: CONTROL_VALUE, BASE
  76. CAVEATS:
  77. NOTES:
  78. HISTORY:
  79. Johnl 23-Apr-1991 Created
  80. beng 14-May-1991 Changed friends
  81. terryk 11-Jul-1991 Add the CVSaveValue and CVRestoreValue
  82. protected member to the function.
  83. beng 08-Oct-1991 Win32 conversion
  84. **************************************************************************/
  85. DLL_CLASS CONTROL_GROUP : public CONTROL_VALUE, public BASE
  86. {
  87. friend class CONTROL_WINDOW; // Give CONTROL_WINDOW::NotifyGroups access
  88. friend BOOL DIALOG_WINDOW::DlgProc( HWND hDlg, UINT nMsg,
  89. WPARAM wParam, LPARAM lParam );
  90. protected:
  91. virtual APIERR OnUserAction( CONTROL_WINDOW *, const CONTROL_EVENT & );
  92. virtual APIERR OnGroupAction( CONTROL_GROUP * pgroup );
  93. virtual VOID AfterGroupActions();
  94. VOID CVSaveValue( CONTROL_VALUE * pcv, BOOL fInvisible = TRUE );
  95. VOID CVRestoreValue( CONTROL_VALUE * pcv, BOOL fInvisible = TRUE );
  96. public:
  97. CONTROL_GROUP( CONTROL_GROUP * pgroupOwner = NULL )
  98. : CONTROL_VALUE( pgroupOwner )
  99. { /* Nothing to do */; }
  100. };
  101. /**********************************************************************
  102. NAME: RADIO_GROUP
  103. SYNOPSIS: radio control group
  104. INTERFACE:
  105. RADIO_GROUP() - constructor
  106. ~RADIO_GROUP() - destructor
  107. OnUserAction() - replacement of control_window::OnUserAction
  108. QueryCount() - query the total radio button in the group
  109. IsMember() - check a radio button is in the group or not
  110. SetSelection() - set the radio button seletion
  111. QuerySelection() - Query the current radio button selection
  112. operator[]() - return pointer to the specified button
  113. PARENT: CONTROL_GROUP
  114. USES: RADIO_BUTTON
  115. CAVEATS:
  116. NOTES:
  117. HISTORY:
  118. rustanl 20-Nov-90 Creation
  119. Johnl 23-Apr-91 Moved to bltgroup.hxx & converted to use
  120. CONTROL_GROUP hierarchy.
  121. beng 08-Oct-1991 Win32 conversion
  122. JohnL 05-May-1992 Added Enable method
  123. **********************************************************************/
  124. DLL_CLASS RADIO_GROUP : public CONTROL_GROUP
  125. {
  126. friend class MAGIC_GROUP;
  127. private:
  128. CID _cidBase; // control ID for the first radio button
  129. INT _crbSize; // Number of radio buttons in group
  130. /* Contains the CID of the radio button that is currently selected
  131. * or RG_NO_SEL
  132. */
  133. CID _cidCurrentSelection;
  134. /* Gets the current selection when SaveValue is called on the RADIO_GROUP.
  135. * It is the value that sets the selection when RestoreValue is called.
  136. */
  137. CID _cidSavedSelection;
  138. RADIO_BUTTON * _prb; // Array of RADIO_BUTTONs
  139. protected:
  140. /* OnUserAction is called after a button receives a message. If the
  141. * message is a change of state, then set the
  142. * button & return NERR_Success, else return GROUP_NO_CHANGE.
  143. */
  144. virtual APIERR OnUserAction( CONTROL_WINDOW *, const CONTROL_EVENT & );
  145. /* Redefine CONTROL_VALUE defaults.
  146. */
  147. virtual VOID SaveValue( BOOL fInvisible = TRUE );
  148. virtual VOID RestoreValue( BOOL fInvisible = TRUE );
  149. /* Sets the selection without automatically notifying parent groups, used
  150. * internally.
  151. */
  152. VOID SetSelectionDontNotifyGroups( CID cid );
  153. public:
  154. /* Constructor:
  155. * powin - pointer to owner window
  156. * cidBase - First button of Radio group
  157. * cSize - Count of radio buttons in group
  158. * cidInitialSelection - Radio button of group that is initially selected
  159. * pgroupOwner - Pointer to the group that controls this RADIO_GROUP
  160. */
  161. RADIO_GROUP( OWNER_WINDOW * powin,
  162. CID cidBase,
  163. INT cSize,
  164. CID cidInitialSelection = RG_NO_SEL,
  165. CONTROL_GROUP * pgroupOwner = NULL );
  166. ~RADIO_GROUP();
  167. // QueryCount returns the number of radio buttons in the group.
  168. // The return value is negative if the object is in an error
  169. // state.
  170. INT QueryCount();
  171. // IsMember returns whether or not a given CID is a member of this
  172. // radio group.
  173. BOOL IsMember( CID cid );
  174. // SetSelection sets the selection in the radio group to the button
  175. // whose ID is cid. If cid is passed in as RG_NO_SEL, the selection
  176. // is cleared.
  177. VOID SetSelection( CID cid );
  178. // QuerySelection returns the current selection of the radio group.
  179. // It is RG_NO_SEL if there is no selection or an error occurred.
  180. CID QuerySelection() const ;
  181. // operator[] returns a pointer to the individual radio button
  182. // whose ID is cid. The return value is NULL if cid is an invalid
  183. // control ID in this group, or if an error occurred.
  184. RADIO_BUTTON * operator[]( CID cid );
  185. /* Replace CONTROL_VALUE::SetControlValueFocus
  186. */
  187. virtual VOID SetControlValueFocus();
  188. //
  189. // Enables or Disables all of the controls in this radio group
  190. //
  191. void Enable( BOOL fEnable = TRUE ) ;
  192. };
  193. /*************************************************************************
  194. NAME: CONTROLVAL_CID_PAIR
  195. SYNOPSIS: Simple storage class for MAGIC_GROUP.
  196. Associates a radio Button CID with a control value pointer.
  197. HISTORY:
  198. Johnl 24-Apr-1991 Created
  199. **************************************************************************/
  200. DLL_CLASS CONTROLVAL_CID_PAIR
  201. {
  202. private:
  203. CID _cidRadioButton;
  204. CONTROL_VALUE * _pcontvalue;
  205. public:
  206. CONTROLVAL_CID_PAIR()
  207. : _cidRadioButton( 0 ), _pcontvalue( NULL )
  208. { /* Nothing to do */; }
  209. CONTROLVAL_CID_PAIR( CID cidRadioButton, CONTROL_VALUE * pcontvalue )
  210. : _cidRadioButton( cidRadioButton ), _pcontvalue( pcontvalue )
  211. { /* Nothing to do */; }
  212. CID QueryRBCID() const
  213. { return _cidRadioButton; }
  214. CONTROL_VALUE * QueryContVal() const
  215. { return _pcontvalue; }
  216. INT Compare( const CONTROLVAL_CID_PAIR * pval ) const
  217. { UNREFERENCED( pval ); return 0; }
  218. };
  219. /*************************************************************************
  220. NAME: MAGIC_GROUP
  221. SYNOPSIS: A MAGIC_GROUP contains a set of RADIO_BUTTONS that have
  222. zero or more controls associated with each RADIO_BUTTON.
  223. Associated means when the radio button is selected,
  224. RestoreValue is called on the control(s) and when the controls
  225. are messed with, the radio button is notified (and gets
  226. selected and selects the other controls in this group).
  227. INTERFACE:
  228. MAGIC_GROUP
  229. Constructor - Same parameters & meaning as RADIO_GROUP
  230. AddAssociation - Associates a radio button with a control
  231. cidRadio is the radio button to associate this control with
  232. (radio button must be in this MAGIC_GROUP).
  233. pcontval is the pointer to the control value
  234. QuerySelection - Same as for RADIO_GROUP
  235. SetSelection - Sets the radio button that has the initial selection
  236. PARENT: CONTROL_GROUP
  237. USES: RADIO_GROUP, CONTROLVAL_CID_PAIR
  238. CAVEATS:
  239. All associated controls should be initialized with their
  240. default values *before* making the associations (AddAssociation).
  241. NOTES:
  242. HISTORY:
  243. Johnl 23-Apr-1991 Created (designed by Rustan and Johnl).
  244. beng 05-Oct-1991 Win32 conversion
  245. JohnL 05-May-1992 Added Enable method
  246. **************************************************************************/
  247. DECL_ARRAY_LIST_OF(CONTROLVAL_CID_PAIR,DLL_BASED);
  248. DLL_CLASS MAGIC_GROUP : public CONTROL_GROUP
  249. {
  250. private:
  251. /* Set of radio buttons the controls are associated with
  252. * Since this RADIO_GROUP is itself a group, we tell it that "this"
  253. * is its parent group. Thus when a radio button is clicked, we are
  254. * notified in our OnGroup method.
  255. */
  256. RADIO_GROUP _rg;
  257. /* Keeps track of the current radio button selection. When a new
  258. * selection is made, the controls associated with this radio button
  259. * are Inactivated.
  260. */
  261. CID _cidCurrentRBSelection;
  262. /* This array contains the Radio button CID and CONTROL_VALUE * pairs.
  263. * This is where a radio button gets associated with a particular control.
  264. * Note that is is a two way lookup table, i.e., you can search for
  265. * the Radio button CID and find all associated controls, or you can
  266. * look for a CONTROL_VALUE * and find its associated Radio button CID.
  267. */
  268. ARRAY_LIST_OF( CONTROLVAL_CID_PAIR ) _actrlcidAssociations;
  269. /* Returns the CID this control value pointer is associated with.
  270. */
  271. CID FindAssocRadioButton( CONTROL_VALUE * pcontvalue );
  272. /* Activates (call RestoreValue) on controls associated with
  273. * cidNewRBSelection and Inactivate (call SaveValue) on
  274. * the controls associated with cidOldRBSelection.
  275. * cidNewRBSelection is the CID of the radio button that was just selected
  276. * cidOldRBSelection is the CID of the radio button that just lost
  277. * the selection
  278. * pccontvalHasFocus is optional, the current operation will not Save/Restore
  279. * the control pointed to by pcontvalHasFocus.
  280. */
  281. VOID ActivateAssocControls( CID cidNewRBSelection,
  282. CID cidOldRBSelection,
  283. CONTROL_VALUE * pcontvalHasFocus = NULL );
  284. protected:
  285. /* OnUserAction will be called when an associated control
  286. * is tampered with. We need to find the radio button this
  287. * control belongs to and select it (if appropriate). Do this
  288. * by looking up the CID of the radio button in the _aassocentry
  289. * array that is associated with pcwinControl.
  290. */
  291. virtual APIERR OnUserAction( CONTROL_WINDOW *, const CONTROL_EVENT & );
  292. /* OnGroupAction will be called when a group has been
  293. * tampered with. It will restore/save controls.
  294. * It is automatically called by the shell dialog proc.
  295. */
  296. virtual APIERR OnGroupAction( CONTROL_GROUP * pGroup );
  297. /* Replacement of CONTROL_VALUE virtuals
  298. */
  299. virtual VOID SaveValue( BOOL fInvisible = TRUE );
  300. virtual VOID RestoreValue( BOOL fInvisible = TRUE );
  301. public:
  302. MAGIC_GROUP( OWNER_WINDOW * powin,
  303. CID cidBase,
  304. INT cSize,
  305. CID cidInitialSelection = RG_NO_SEL,
  306. CONTROL_GROUP * pgroupOwner = NULL );
  307. APIERR AddAssociation( CID cidRadio, CONTROL_VALUE * pcontval );
  308. /* Replace CONTROL_VALUE::SetControlValueFocus
  309. */
  310. virtual VOID SetControlValueFocus();
  311. CID QuerySelection() const
  312. { return _rg.QuerySelection(); }
  313. VOID SetSelection( CID cidSelectRb )
  314. {
  315. _rg.SetSelection( cidSelectRb );
  316. _cidCurrentRBSelection = cidSelectRb;
  317. }
  318. //
  319. // Enables or Disables all of the controls in this radio group
  320. //
  321. void Enable( BOOL fEnable = TRUE ) ;
  322. // operator[] returns a pointer to the individual radio button
  323. // whose ID is cid. The return value is NULL if cid is an invalid
  324. // control ID in this group, or if an error occurred.
  325. RADIO_BUTTON * operator[]( CID cid )
  326. { return _rg[ cid ]; }
  327. };
  328. #endif // _BLTGROUP_HXX_ - end of file