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,2005 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (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 GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: FXDataTarget.h,v 1.22 2005/01/16 16:06:06 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXDATATARGET_H 00025 #define FXDATATARGET_H 00026 00027 #ifndef FXOBJECT_H 00028 #include "FXObject.h" 00029 #endif 00030 00031 namespace FX { 00032 00033 00034 /** 00035 * A Data Target allows a valuator widget such as a Slider or Text Field 00036 * to be directly connected with a variable in the program. 00037 * Whenever the valuator control changes, the variable connected through 00038 * the data target is automatically updated; conversely, whenever the program 00039 * changes a variable, all the connected valuator widgets will be updated 00040 * to reflect this new value on the display. 00041 * Data Targets also allow connecting Radio Buttons, Menu Commands, and so on 00042 * to a variable. In this case, the new value of the connected variable is computed 00043 * by subtracting ID_OPTION from the message ID. 00044 */ 00045 class FXAPI FXDataTarget : public FXObject { 00046 FXDECLARE(FXDataTarget) 00047 protected: 00048 FXObject *target; // Target object 00049 void *data; // Associated data 00050 FXSelector message; // Message ID 00051 FXuint type; // Type of data 00052 public: 00053 long onCmdValue(FXObject*,FXSelector,void*); 00054 long onUpdValue(FXObject*,FXSelector,void*); 00055 long onCmdOption(FXObject*,FXSelector,void*); 00056 long onUpdOption(FXObject*,FXSelector,void*); 00057 public: 00058 enum { 00059 DT_VOID=0, 00060 DT_CHAR, 00061 DT_UCHAR, 00062 DT_SHORT, 00063 DT_USHORT, 00064 DT_INT, 00065 DT_UINT, 00066 DT_LONG, 00067 DT_ULONG, 00068 DT_FLOAT, 00069 DT_DOUBLE, 00070 DT_STRING, 00071 DT_LAST 00072 }; 00073 public: 00074 enum { 00075 ID_VALUE=1, /// Will cause the FXDataTarget to ask sender for value 00076 ID_OPTION=ID_VALUE+10001, /// ID_OPTION+i will set the value to i where -10000<=i<=10000 00077 ID_LAST=ID_OPTION+10000 00078 }; 00079 public: 00080 00081 /// Associate with nothing 00082 FXDataTarget(FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(NULL),message(sel),type(DT_VOID){} 00083 00084 /// Associate with character variable 00085 FXDataTarget(FXchar& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_CHAR){} 00086 00087 /// Associate with unsigned character variable 00088 FXDataTarget(FXuchar& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_UCHAR){} 00089 00090 /// Associate with signed short variable 00091 FXDataTarget(FXshort& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_SHORT){} 00092 00093 /// Associate with unsigned short variable 00094 FXDataTarget(FXushort& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_USHORT){} 00095 00096 /// Associate with int variable 00097 FXDataTarget(FXint& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_INT){} 00098 00099 /// Associate with unsigned int variable 00100 FXDataTarget(FXuint& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_UINT){} 00101 00102 /// Associate with long variable 00103 FXDataTarget(FXlong& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_LONG){} 00104 00105 /// Associate with unsigned long variable 00106 FXDataTarget(FXulong& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_ULONG){} 00107 00108 /// Associate with float variable 00109 FXDataTarget(FXfloat& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_FLOAT){} 00110 00111 /// Associate with double variable 00112 FXDataTarget(FXdouble& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_DOUBLE){} 00113 00114 /// Associate with string variable 00115 FXDataTarget(FXString& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_STRING){} 00116 00117 00118 /// Set the message target object for this data target 00119 void setTarget(FXObject *t){ target=t; } 00120 00121 /// Get the message target object for this data target, if any 00122 FXObject* getTarget() const { return target; } 00123 00124 /// Set the message identifier for this data target 00125 void setSelector(FXSelector sel){ message=sel; } 00126 00127 /// Get the message identifier for this data target 00128 FXSelector getSelector() const { return message; } 00129 00130 00131 /// Return type of data its connected to 00132 FXuint getType() const { return type; } 00133 00134 /// Return pointer to data its connected to 00135 void* getData() const { return data; } 00136 00137 00138 /// Associate with nothing 00139 void connect(){ type=DT_VOID; data=NULL; } 00140 00141 /// Associate with character variable 00142 void connect(FXchar& value){ type=DT_CHAR; data=&value; } 00143 00144 /// Associate with unsigned character variable 00145 void connect(FXuchar& value){ type=DT_UCHAR; data=&value; } 00146 00147 /// Associate with signed short variable 00148 void connect(FXshort& value){ type=DT_SHORT; data=&value; } 00149 00150 /// Associate with unsigned short variable 00151 void connect(FXushort& value){ type=DT_USHORT; data=&value; } 00152 00153 /// Associate with int variable 00154 void connect(FXint& value){ type=DT_INT; data=&value; } 00155 00156 /// Associate with unsigned int variable 00157 void connect(FXuint& value){ type=DT_UINT; data=&value; } 00158 00159 /// Associate with long variable 00160 void connect(FXlong& value){ type=DT_LONG; data=&value; } 00161 00162 /// Associate with unsigned long variable 00163 void connect(FXulong& value){ type=DT_ULONG; data=&value; } 00164 00165 /// Associate with float variable 00166 void connect(FXfloat& value){ type=DT_FLOAT; data=&value; } 00167 00168 /// Associate with double variable 00169 void connect(FXdouble& value){ type=DT_DOUBLE; data=&value; } 00170 00171 /// Associate with string variable 00172 void connect(FXString& value){ type=DT_STRING; data=&value; } 00173 00174 /// Destroy 00175 virtual ~FXDataTarget(); 00176 }; 00177 00178 } 00179 00180 #endif
Copyright © 1997-2005 Jeroen van der Zijp |