![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * D a t a T a r g e t * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1998,2009 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU Lesser General Public License as published by * 00010 * the Free Software Foundation; either version 3 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public License * 00019 * along with this program. If not, see <http://www.gnu.org/licenses/> * 00020 ********************************************************************************* 00021 * $Id: FXDataTarget.h,v 1.32 2009/01/06 13:07:22 fox Exp $ * 00022 ********************************************************************************/ 00023 #ifndef FXDATATARGET_H 00024 #define FXDATATARGET_H 00025 00026 #ifndef FXOBJECT_H 00027 #include "FXObject.h" 00028 #endif 00029 00030 namespace FX { 00031 00032 00033 /** 00034 * A Data Target allows a valuator widget such as a Slider or Text Field 00035 * to be directly connected with a variable in the program. 00036 * Whenever the valuator control changes, the variable connected through 00037 * the data target is automatically updated; conversely, whenever the program 00038 * changes a variable, all the connected valuator widgets will be updated 00039 * to reflect this new value on the display. 00040 * Data Targets also allow connecting Radio Buttons, Menu Commands, and so on 00041 * to a variable. In this case, the new value of the connected variable is computed 00042 * by subtracting ID_OPTION from the message ID. 00043 * A Data Target may be subclassed to handle additional, user-defined data types; to 00044 * this end, the message handlers return 1 if the type is one of DT_VOID...DT_STRING 00045 * and 0 otherwise. Thus subclasses can handle any data types not dealt with in the 00046 * default implementation. 00047 */ 00048 class FXAPI FXDataTarget : public FXObject { 00049 FXDECLARE(FXDataTarget) 00050 protected: 00051 void *data; // Associated data 00052 FXObject *target; // Target object 00053 FXSelector message; // Message ID 00054 FXuint type; // Type of data 00055 private: 00056 FXDataTarget(const FXDataTarget&); 00057 FXDataTarget& operator=(const FXDataTarget&); 00058 public: 00059 long onCmdValue(FXObject*,FXSelector,void*); 00060 long onUpdValue(FXObject*,FXSelector,void*); 00061 long onCmdOption(FXObject*,FXSelector,void*); 00062 long onUpdOption(FXObject*,FXSelector,void*); 00063 public: 00064 enum { 00065 DT_VOID=0, 00066 DT_BOOL, 00067 DT_CHAR, 00068 DT_UCHAR, 00069 DT_SHORT, 00070 DT_USHORT, 00071 DT_INT, 00072 DT_UINT, 00073 DT_LONG, 00074 DT_ULONG, 00075 DT_FLOAT, 00076 DT_DOUBLE, 00077 DT_STRING, 00078 DT_LAST 00079 }; 00080 public: 00081 enum { 00082 ID_VALUE=1, /// Will cause the FXDataTarget to ask sender for value 00083 ID_OPTION=ID_VALUE+10001, /// ID_OPTION+i will set the value to i where -10000<=i<=10000 00084 ID_LAST=ID_OPTION+10000 00085 }; 00086 public: 00087 00088 /// Associate with nothing 00089 FXDataTarget():data(NULL),target(NULL),message(0),type(DT_VOID){} 00090 00091 /// Associate with nothing 00092 FXDataTarget(FXObject* tgt,FXSelector sel):data(NULL),target(tgt),message(sel),type(DT_VOID){} 00093 00094 /// Associate with character variable 00095 FXDataTarget(FXbool& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_BOOL){} 00096 00097 /// Associate with character variable 00098 FXDataTarget(FXchar& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_CHAR){} 00099 00100 /// Associate with unsigned character variable 00101 FXDataTarget(FXuchar& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_UCHAR){} 00102 00103 /// Associate with signed short variable 00104 FXDataTarget(FXshort& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_SHORT){} 00105 00106 /// Associate with unsigned short variable 00107 FXDataTarget(FXushort& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_USHORT){} 00108 00109 /// Associate with int variable 00110 FXDataTarget(FXint& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_INT){} 00111 00112 /// Associate with unsigned int variable 00113 FXDataTarget(FXuint& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_UINT){} 00114 00115 /// Associate with long variable 00116 FXDataTarget(FXlong& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_LONG){} 00117 00118 /// Associate with unsigned long variable 00119 FXDataTarget(FXulong& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_ULONG){} 00120 00121 /// Associate with float variable 00122 FXDataTarget(FXfloat& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_FLOAT){} 00123 00124 /// Associate with double variable 00125 FXDataTarget(FXdouble& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_DOUBLE){} 00126 00127 /// Associate with string variable 00128 FXDataTarget(FXString& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_STRING){} 00129 00130 00131 /// Set the message target object for this data target 00132 void setTarget(FXObject *t){ target=t; } 00133 00134 /// Get the message target object for this data target, if any 00135 FXObject* getTarget() const { return target; } 00136 00137 00138 /// Set the message identifier for this data target 00139 void setSelector(FXSelector sel){ message=sel; } 00140 00141 /// Get the message identifier for this data target 00142 FXSelector getSelector() const { return message; } 00143 00144 00145 /// Return type of data its connected to 00146 FXuint getType() const { return type; } 00147 00148 /// Return pointer to data its connected to 00149 void* getData() const { return data; } 00150 00151 00152 /// Associate with nothing 00153 void connect(){ data=NULL; type=DT_VOID; } 00154 00155 /// Associate with FXbool variable 00156 void connect(FXbool& value){ data=&value; type=DT_BOOL; } 00157 00158 /// Associate with character variable 00159 void connect(FXchar& value){ data=&value; type=DT_CHAR; } 00160 00161 /// Associate with unsigned character variable 00162 void connect(FXuchar& value){ data=&value; type=DT_UCHAR; } 00163 00164 /// Associate with signed short variable 00165 void connect(FXshort& value){ data=&value; type=DT_SHORT; } 00166 00167 /// Associate with unsigned short variable 00168 void connect(FXushort& value){ data=&value; type=DT_USHORT; } 00169 00170 /// Associate with int variable 00171 void connect(FXint& value){ data=&value; type=DT_INT; } 00172 00173 /// Associate with unsigned int variable 00174 void connect(FXuint& value){ data=&value; type=DT_UINT; } 00175 00176 /// Associate with long variable 00177 void connect(FXlong& value){ data=&value; type=DT_LONG; } 00178 00179 /// Associate with unsigned long variable 00180 void connect(FXulong& value){ data=&value; type=DT_ULONG; } 00181 00182 /// Associate with float variable 00183 void connect(FXfloat& value){ data=&value; type=DT_FLOAT; } 00184 00185 /// Associate with double variable 00186 void connect(FXdouble& value){ data=&value; type=DT_DOUBLE; } 00187 00188 /// Associate with string variable 00189 void connect(FXString& value){ data=&value; type=DT_STRING; } 00190 00191 00192 /// Associate with nothing; also set target and message 00193 void connect(FXObject* tgt,FXSelector sel){ data=NULL; target=tgt; message=sel; type=DT_VOID; } 00194 00195 /// Associate with character variable; also set target and message 00196 void connect(FXbool& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_BOOL; } 00197 00198 /// Associate with character variable; also set target and message 00199 void connect(FXchar& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_CHAR; } 00200 00201 /// Associate with unsigned character variable; also set target and message 00202 void connect(FXuchar& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_UCHAR; } 00203 00204 /// Associate with signed short variable; also set target and message 00205 void connect(FXshort& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_SHORT; } 00206 00207 /// Associate with unsigned short variable; also set target and message 00208 void connect(FXushort& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_USHORT; } 00209 00210 /// Associate with int variable; also set target and message 00211 void connect(FXint& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_INT; } 00212 00213 /// Associate with unsigned int variable; also set target and message 00214 void connect(FXuint& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_UINT; } 00215 00216 /// Associate with long variable; also set target and message 00217 void connect(FXlong& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_LONG; } 00218 00219 /// Associate with unsigned long variable; also set target and message 00220 void connect(FXulong& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_ULONG; } 00221 00222 /// Associate with float variable; also set target and message 00223 void connect(FXfloat& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_FLOAT; } 00224 00225 /// Associate with double variable; also set target and message 00226 void connect(FXdouble& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_DOUBLE; } 00227 00228 /// Associate with string variable; also set target and message 00229 void connect(FXString& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_STRING; } 00230 00231 00232 /// Destroy 00233 virtual ~FXDataTarget(); 00234 }; 00235 00236 } 00237 00238 #endif
![]() |