UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
RadioGroup.H
1 /* RadioGroup.H */
2 /* $Revision: 1.10 $ RadioGroup.H $Date: 2004/08/17 14:07:14 $ */
3 #ifndef __RadioGroup_H
4 #define __RadioGroup_H
5 
6 
7 /*************************************************************
8  * Group of states with rule ``ONE OF MANY''.
9  * Each state is identified by programmer defined number (any).
10  * Each state have 0 or more control elements (widgets).
11  * When state is being changed, NewStateHook is called.
12  * Visual state of control element is mainteined by
13  * ChangeArmState() function. It's assumed that all control
14  * elements are disarmed when added into RadioGroup.
15  * Do not change its states manually!!!
16  * When a programmer add new state object check it for
17  * uniquiness and do not duplicate state. When programmer
18  * try to set unknown state or want to add control to unknown
19  * state -- be silent.
20  *************************************************************/
21 
22 #include <X11/Intrinsic.h>
23 #include <mix/IntAr.H>
24 
25 
26 /* Forward descriptions */
27 class ZtObject;
28 class QfBrick;
29 
30 
31 /* State handle procedure */
32 typedef void (*RadioHandleProc)(int idPrevState, int idNewState);
33 
34 
35 /*************************************************************
36  * Description of each control element.
37  *************************************************************/
39 {
40  int state; /* state id */
41  Widget w; /* Widget is a control element */
42  ZtObject *z; /* ZtObject is a control element */
43  QfBrick *q; /* QfBrick is a control element */
44  Widget w_optm; /* Widget of OptionMenu or NULL if w is not an
45  item in Option Menu */
46 };
47 
48 
49 /*************************************************************
50  * Array of control elements with sorting by widget.
51  *************************************************************/
52 #define AnyType RadioControlElement
53 #define AnyAr ArrayOfRCE
54 #define AnyCmp(x,y) (!((x.w == y.w) && (x.z == y.z) && (x.q == y.q)))
55 #define AnyFormatSpec "\n%d @ state=%d: w=%p; z=%p; q=%p"
56 #define AnyPrintList i, item.state, item.w, item.z, item.q
57 #include <mix/AnyAr.H>
58 
59 
61 {
62 protected:
63 
64  /* Current active state */
65  int state;
66 
67  /* Array of states */
68  IntAr states;
69 
70  /* Array of control elements */
71  ArrayOfRCE controls;
72 
73  /* Current active state */
74  RadioHandleProc event_handler;
75 
76  /* Change state of pointed control element */
77  void ChangeState (unsigned i);
78 
79  /* Remove control entry from all states */
80  void RemoveAnyControl (void* ptr);
81 
82  /* Set current state of option menu item w */
83  static void SetCurrentInOptionMenu (Widget w, Widget w_optm);
84 
85 
86  /*************************************************************
87  * Callbacks for control elements.
88  *************************************************************/
89 
90  static void
91  UniversalCB (Widget w, RadioGroup* self, XtPointer pCallData);
92  static void
93  ToggleButtonCB (Widget w, RadioGroup* self, XtPointer pCallData);
94  static void
95  DrawnButtonCB (Widget w, RadioGroup* self, XtPointer pCallData);
96  static void
97  PushButtonCB (Widget w, RadioGroup* self, XtPointer pCallData);
98  static void
99  OptionMenuButtonCB (Widget w, RadioGroup* self, XtPointer pCallData);
100 
101 public:
102 
103  RadioGroup ();
104 
105  /* Register the only event handler for this radio group */
106  void SetHandler (RadioHandleProc handler);
107  void ResetHandler ();
108 
109  void AddState (int idState);
110  void AddControl (int idState, Widget w, Widget w_optm = NULL);
111  void AddControl (int idState, ZtObject* zobj);
112  void AddControl (int idState, QfBrick* qobj);
113 
114  void SetState (int idState);
115  int GetState () const
116  {return state;}
117 
118  void RemoveState (int idState);
119  void RemoveControl (Widget w);
120  void RemoveControl (ZtObject* zobj);
121  void RemoveControl (QfBrick* qobj);
122 
123  virtual void NewStateHook (int idPrevState, int idNewState);
124 
125 };
126 
127 
128 #endif /* RadioGroup.H */
Definition: IntAr.H:14
Definition: QfBrick.H:54
Definition: RadioGroup.H:38
Definition: ZtObject.H:57
Definition: RadioGroup.H:60