Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXDataTarget.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * D a t a T a r g e t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1998,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXDataTarget.h,v 1.25 2006/01/22 17:58:00 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXDATATARGET_H
25 #define FXDATATARGET_H
26 
27 #ifndef FXOBJECT_H
28 #include "FXObject.h"
29 #endif
30 
31 namespace FX {
32 
33 
34 /**
35 * A Data Target allows a valuator widget such as a Slider or Text Field
36 * to be directly connected with a variable in the program.
37 * Whenever the valuator control changes, the variable connected through
38 * the data target is automatically updated; conversely, whenever the program
39 * changes a variable, all the connected valuator widgets will be updated
40 * to reflect this new value on the display.
41 * Data Targets also allow connecting Radio Buttons, Menu Commands, and so on
42 * to a variable. In this case, the new value of the connected variable is computed
43 * by subtracting ID_OPTION from the message ID.
44 */
45 class FXAPI FXDataTarget : public FXObject {
47 protected:
48  FXObject *target; // Target object
49  void *data; // Associated data
50  FXSelector message; // Message ID
51  FXuint type; // Type of data
52 private:
53  FXDataTarget(const FXDataTarget&);
54  FXDataTarget& operator=(const FXDataTarget&);
55 public:
56  long onCmdValue(FXObject*,FXSelector,void*);
57  long onUpdValue(FXObject*,FXSelector,void*);
58  long onCmdOption(FXObject*,FXSelector,void*);
59  long onUpdOption(FXObject*,FXSelector,void*);
60 public:
61  enum {
62  DT_VOID=0,
63  DT_CHAR,
64  DT_UCHAR,
65  DT_SHORT,
66  DT_USHORT,
67  DT_INT,
68  DT_UINT,
69  DT_LONG,
70  DT_ULONG,
71  DT_FLOAT,
72  DT_DOUBLE,
73  DT_STRING,
74  DT_LAST
75  };
76 public:
77  enum {
78  ID_VALUE=1, /// Will cause the FXDataTarget to ask sender for value
79  ID_OPTION=ID_VALUE+10001, /// ID_OPTION+i will set the value to i where -10000<=i<=10000
80  ID_LAST=ID_OPTION+10000
81  };
82 public:
83 
84  /// Associate with nothing
85  FXDataTarget():target(NULL),data(NULL),message(0),type(DT_VOID){}
86 
87  /// Associate with nothing
88  FXDataTarget(FXObject* tgt,FXSelector sel):target(tgt),data(NULL),message(sel),type(DT_VOID){}
89 
90  /// Associate with character variable
91  FXDataTarget(FXchar& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_CHAR){}
92 
93  /// Associate with unsigned character variable
94  FXDataTarget(FXuchar& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_UCHAR){}
95 
96  /// Associate with signed short variable
97  FXDataTarget(FXshort& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_SHORT){}
98 
99  /// Associate with unsigned short variable
100  FXDataTarget(FXushort& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_USHORT){}
101 
102  /// Associate with int variable
103  FXDataTarget(FXint& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_INT){}
104 
105  /// Associate with unsigned int variable
106  FXDataTarget(FXuint& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_UINT){}
107 
108  /// Associate with long variable
109  FXDataTarget(FXlong& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_LONG){}
110 
111  /// Associate with unsigned long variable
112  FXDataTarget(FXulong& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_ULONG){}
113 
114  /// Associate with float variable
115  FXDataTarget(FXfloat& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_FLOAT){}
117  /// Associate with double variable
118  FXDataTarget(FXdouble& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_DOUBLE){}
120  /// Associate with string variable
121  FXDataTarget(FXString& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_STRING){}
122 
124  /// Set the message target object for this data target
125  void setTarget(FXObject *t){ target=t; }
127  /// Get the message target object for this data target, if any
128  FXObject* getTarget() const { return target; }
130 
131  /// Set the message identifier for this data target
132  void setSelector(FXSelector sel){ message=sel; }
133 
134  /// Get the message identifier for this data target
135  FXSelector getSelector() const { return message; }
136 
137 
138  /// Return type of data its connected to
139  FXuint getType() const { return type; }
140 
141  /// Return pointer to data its connected to
142  void* getData() const { return data; }
143 
145  /// Associate with nothing
146  void connect(){ data=NULL; type=DT_VOID; }
148  /// Associate with character variable
149  void connect(FXchar& value){ data=&value; type=DT_CHAR; }
151  /// Associate with unsigned character variable
152  void connect(FXuchar& value){ data=&value; type=DT_UCHAR; }
154  /// Associate with signed short variable
155  void connect(FXshort& value){ data=&value; type=DT_SHORT; }
157  /// Associate with unsigned short variable
158  void connect(FXushort& value){ data=&value; type=DT_USHORT; }
159 
160  /// Associate with int variable
161  void connect(FXint& value){ data=&value; type=DT_INT; }
162 
163  /// Associate with unsigned int variable
164  void connect(FXuint& value){ data=&value; type=DT_UINT; }
165 
166  /// Associate with long variable
167  void connect(FXlong& value){ data=&value; type=DT_LONG; }
168 
169  /// Associate with unsigned long variable
170  void connect(FXulong& value){ data=&value; type=DT_ULONG; }
171 
172  /// Associate with float variable
173  void connect(FXfloat& value){ data=&value; type=DT_FLOAT; }
174 
175  /// Associate with double variable
176  void connect(FXdouble& value){ data=&value; type=DT_DOUBLE; }
177 
178  /// Associate with string variable
179  void connect(FXString& value){ data=&value; type=DT_STRING; }
180 
182  /// Associate with nothing; also set target and message
183  void connect(FXObject* tgt,FXSelector sel){ target=tgt; data=NULL; message=sel; type=DT_VOID; }
185  /// Associate with character variable; also set target and message
186  void connect(FXchar& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_CHAR; }
188  /// Associate with unsigned character variable; also set target and message
189  void connect(FXuchar& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_UCHAR; }
191  /// Associate with signed short variable; also set target and message
192  void connect(FXshort& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_SHORT; }
194  /// Associate with unsigned short variable; also set target and message
195  void connect(FXushort& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_USHORT; }
196 
197  /// Associate with int variable; also set target and message
198  void connect(FXint& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_INT; }
199 
200  /// Associate with unsigned int variable; also set target and message
201  void connect(FXuint& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_UINT; }
202 
203  /// Associate with long variable; also set target and message
204  void connect(FXlong& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_LONG; }
205 
206  /// Associate with unsigned long variable; also set target and message
207  void connect(FXulong& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_ULONG; }
208 
209  /// Associate with float variable; also set target and message
210  void connect(FXfloat& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_FLOAT; }
211 
212  /// Associate with double variable; also set target and message
213  void connect(FXdouble& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_DOUBLE; }
214 
215  /// Associate with string variable; also set target and message
216  void connect(FXString& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_STRING; }
217 
218 
219  /// Destroy
220  virtual ~FXDataTarget();
221  };
222 
223 }
224 
225 #endif
unsigned short FXushort
Definition: fxdefs.h:387
A Data Target allows a valuator widget such as a Slider or Text Field to be directly connected with a...
Definition: FXDataTarget.h:45
char FXchar
Definition: fxdefs.h:380
short FXshort
Definition: fxdefs.h:388
unsigned int FXuint
Definition: fxdefs.h:389
FXuint FXSelector
Association key.
Definition: FXObject.h:53
#define FXAPI
Definition: fxdefs.h:122
#define NULL
Definition: fxdefs.h:41
double FXdouble
Definition: fxdefs.h:392
Definition: FX4Splitter.h:31
int FXint
Definition: fxdefs.h:390
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:166
unsigned char FXuchar
Definition: fxdefs.h:385
float FXfloat
Definition: fxdefs.h:391
#define FXDECLARE(classname)
Macro to set up class declaration.
Definition: FXObject.h:92
FXString provides essential string manipulation capabilities.
Definition: FXString.h:33

Copyright © 1997-2005 Jeroen van der Zijp