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

FXDataTarget.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                              D a t a   T a r g e t                            *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1998,2006 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.25 2006/01/22 17:58:00 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 private:
00053   FXDataTarget(const FXDataTarget&);
00054   FXDataTarget& operator=(const FXDataTarget&);
00055 public:
00056   long onCmdValue(FXObject*,FXSelector,void*);
00057   long onUpdValue(FXObject*,FXSelector,void*);
00058   long onCmdOption(FXObject*,FXSelector,void*);
00059   long onUpdOption(FXObject*,FXSelector,void*);
00060 public:
00061   enum {
00062     DT_VOID=0,
00063     DT_CHAR,
00064     DT_UCHAR,
00065     DT_SHORT,
00066     DT_USHORT,
00067     DT_INT,
00068     DT_UINT,
00069     DT_LONG,
00070     DT_ULONG,
00071     DT_FLOAT,
00072     DT_DOUBLE,
00073     DT_STRING,
00074     DT_LAST
00075     };
00076 public:
00077   enum {
00078     ID_VALUE=1,                   /// Will cause the FXDataTarget to ask sender for value
00079     ID_OPTION=ID_VALUE+10001,     /// ID_OPTION+i will set the value to i where -10000<=i<=10000
00080     ID_LAST=ID_OPTION+10000
00081     };
00082 public:
00083 
00084   /// Associate with nothing
00085   FXDataTarget():target(NULL),data(NULL),message(0),type(DT_VOID){}
00086 
00087   /// Associate with nothing
00088   FXDataTarget(FXObject* tgt,FXSelector sel):target(tgt),data(NULL),message(sel),type(DT_VOID){}
00089 
00090   /// Associate with character variable
00091   FXDataTarget(FXchar& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_CHAR){}
00092 
00093   /// Associate with unsigned character variable
00094   FXDataTarget(FXuchar& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_UCHAR){}
00095 
00096   /// Associate with signed short variable
00097   FXDataTarget(FXshort& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_SHORT){}
00098 
00099   /// Associate with unsigned short variable
00100   FXDataTarget(FXushort& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_USHORT){}
00101 
00102   /// Associate with int variable
00103   FXDataTarget(FXint& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_INT){}
00104 
00105   /// Associate with unsigned int variable
00106   FXDataTarget(FXuint& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_UINT){}
00107 
00108   /// Associate with long variable
00109   FXDataTarget(FXlong& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_LONG){}
00110 
00111   /// Associate with unsigned long variable
00112   FXDataTarget(FXulong& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_ULONG){}
00113 
00114   /// Associate with float variable
00115   FXDataTarget(FXfloat& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_FLOAT){}
00116 
00117   /// Associate with double variable
00118   FXDataTarget(FXdouble& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_DOUBLE){}
00119 
00120   /// Associate with string variable
00121   FXDataTarget(FXString& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_STRING){}
00122 
00123 
00124   /// Set the message target object for this data target
00125   void setTarget(FXObject *t){ target=t; }
00126 
00127   /// Get the message target object for this data target, if any
00128   FXObject* getTarget() const { return target; }
00129 
00130 
00131   /// Set the message identifier for this data target
00132   void setSelector(FXSelector sel){ message=sel; }
00133 
00134   /// Get the message identifier for this data target
00135   FXSelector getSelector() const { return message; }
00136 
00137 
00138   /// Return type of data its connected to
00139   FXuint getType() const { return type; }
00140 
00141   /// Return pointer to data its connected to
00142   void* getData() const { return data; }
00143 
00144 
00145   /// Associate with nothing
00146   void connect(){ data=NULL; type=DT_VOID; }
00147 
00148   /// Associate with character variable
00149   void connect(FXchar& value){ data=&value; type=DT_CHAR; }
00150 
00151   /// Associate with unsigned character variable
00152   void connect(FXuchar& value){ data=&value; type=DT_UCHAR; }
00153 
00154   /// Associate with signed short variable
00155   void connect(FXshort& value){ data=&value; type=DT_SHORT; }
00156 
00157   /// Associate with unsigned short variable
00158   void connect(FXushort& value){ data=&value; type=DT_USHORT; }
00159 
00160   /// Associate with int variable
00161   void connect(FXint& value){ data=&value; type=DT_INT; }
00162 
00163   /// Associate with unsigned int variable
00164   void connect(FXuint& value){ data=&value; type=DT_UINT; }
00165 
00166   /// Associate with long variable
00167   void connect(FXlong& value){ data=&value; type=DT_LONG; }
00168 
00169   /// Associate with unsigned long variable
00170   void connect(FXulong& value){ data=&value; type=DT_ULONG; }
00171 
00172   /// Associate with float variable
00173   void connect(FXfloat& value){ data=&value; type=DT_FLOAT; }
00174 
00175   /// Associate with double variable
00176   void connect(FXdouble& value){ data=&value; type=DT_DOUBLE; }
00177 
00178   /// Associate with string variable
00179   void connect(FXString& value){ data=&value; type=DT_STRING; }
00180 
00181 
00182   /// Associate with nothing; also set target and message
00183   void connect(FXObject* tgt,FXSelector sel){ target=tgt; data=NULL; message=sel; type=DT_VOID; }
00184 
00185   /// Associate with character variable; also set target and message
00186   void connect(FXchar& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_CHAR; }
00187 
00188   /// Associate with unsigned character variable; also set target and message
00189   void connect(FXuchar& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_UCHAR; }
00190 
00191   /// Associate with signed short variable; also set target and message
00192   void connect(FXshort& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_SHORT; }
00193 
00194   /// Associate with unsigned short variable; also set target and message
00195   void connect(FXushort& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_USHORT; }
00196 
00197   /// Associate with int variable; also set target and message
00198   void connect(FXint& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_INT; }
00199 
00200   /// Associate with unsigned int variable; also set target and message
00201   void connect(FXuint& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_UINT; }
00202 
00203   /// Associate with long variable; also set target and message
00204   void connect(FXlong& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_LONG; }
00205 
00206   /// Associate with unsigned long variable; also set target and message
00207   void connect(FXulong& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_ULONG; }
00208 
00209   /// Associate with float variable; also set target and message
00210   void connect(FXfloat& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_FLOAT; }
00211 
00212   /// Associate with double variable; also set target and message
00213   void connect(FXdouble& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_DOUBLE; }
00214 
00215   /// Associate with string variable; also set target and message
00216   void connect(FXString& value,FXObject* tgt,FXSelector sel){ target=tgt; data=&value; message=sel; type=DT_STRING; }
00217 
00218 
00219   /// Destroy
00220   virtual ~FXDataTarget();
00221   };
00222 
00223 }
00224 
00225 #endif

Copyright © 1997-2005 Jeroen van der Zijp