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,2004 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.19 2004/02/08 17:17:33 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 substracting 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_FLOAT, 00067 DT_DOUBLE, 00068 DT_STRING, 00069 DT_LAST 00070 }; 00071 public: 00072 enum { 00073 ID_VALUE=1, /// Will cause the FXDataTarget to ask sender for value 00074 ID_OPTION=ID_VALUE+10001, /// ID_OPTION+i will set the value to i where -10000<=i<=10000 00075 ID_LAST=ID_OPTION+10000 00076 }; 00077 public: 00078 00079 /// Associate with nothing 00080 FXDataTarget(FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(NULL),message(sel),type(DT_VOID){} 00081 00082 /// Associate with character variable 00083 FXDataTarget(FXchar& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_CHAR){} 00084 00085 /// Associate with unsigned character variable 00086 FXDataTarget(FXuchar& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_UCHAR){} 00087 00088 /// Associate with signed short variable 00089 FXDataTarget(FXshort& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_SHORT){} 00090 00091 /// Associate with unsigned short variable 00092 FXDataTarget(FXushort& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_USHORT){} 00093 00094 /// Associate with int variable 00095 FXDataTarget(FXint& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_INT){} 00096 00097 /// Associate with unsigned int variable 00098 FXDataTarget(FXuint& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_UINT){} 00099 00100 /// Associate with float variable 00101 FXDataTarget(FXfloat& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_FLOAT){} 00102 00103 /// Associate with double variable 00104 FXDataTarget(FXdouble& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_DOUBLE){} 00105 00106 /// Associate with string variable 00107 FXDataTarget(FXString& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_STRING){} 00108 00109 00110 /// Set the message target object for this data target 00111 void setTarget(FXObject *t){ target=t; } 00112 00113 /// Get the message target object for this data target, if any 00114 FXObject* getTarget() const { return target; } 00115 00116 /// Set the message identifier for this data target 00117 void setSelector(FXSelector sel){ message=sel; } 00118 00119 /// Get the message identifier for this data target 00120 FXSelector getSelector() const { return message; } 00121 00122 00123 /// Return type of data its connected to 00124 FXuint getType() const { return type; } 00125 00126 /// Return pointer to data its connected to 00127 void* getData() const { return data; } 00128 00129 00130 /// Associate with nothing 00131 void connect(){ type=DT_VOID; data=NULL; } 00132 00133 /// Associate with character variable 00134 void connect(FXchar& value){ type=DT_CHAR; data=&value; } 00135 00136 /// Associate with unsigned character variable 00137 void connect(FXuchar& value){ type=DT_UCHAR; data=&value; } 00138 00139 /// Associate with signed short variable 00140 void connect(FXshort& value){ type=DT_SHORT; data=&value; } 00141 00142 /// Associate with unsigned short variable 00143 void connect(FXushort& value){ type=DT_USHORT; data=&value; } 00144 00145 /// Associate with int variable 00146 void connect(FXint& value){ type=DT_INT; data=&value; } 00147 00148 /// Associate with unsigned int variable 00149 void connect(FXuint& value){ type=DT_UINT; data=&value; } 00150 00151 /// Associate with float variable 00152 void connect(FXfloat& value){ type=DT_FLOAT; data=&value; } 00153 00154 /// Associate with double variable 00155 void connect(FXdouble& value){ type=DT_DOUBLE; data=&value; } 00156 00157 /// Associate with string variable 00158 void connect(FXString& value){ type=DT_STRING; data=&value; } 00159 00160 /// Destroy 00161 virtual ~FXDataTarget(); 00162 }; 00163 00164 } 00165 00166 #endif
Copyright © 1997-2004 Jeroen van der Zijp |