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,2010 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 #ifndef FXDATATARGET_H
00022 #define FXDATATARGET_H
00023 
00024 #ifndef FXOBJECT_H
00025 #include "FXObject.h"
00026 #endif
00027 
00028 namespace FX {
00029 
00030 
00031 /**
00032 * A Data Target allows a valuator widget such as a Slider or Text Field
00033 * to be directly connected with a variable in the program.
00034 * Whenever the valuator control changes, the variable connected through
00035 * the data target is automatically updated; conversely, whenever the program
00036 * changes a variable, all the connected valuator widgets will be updated
00037 * to reflect this new value on the display.
00038 * Data Targets also allow connecting Radio Buttons, Menu Commands, and so on
00039 * to a variable.  In this case, the new value of the connected variable is computed
00040 * by subtracting ID_OPTION from the message ID.
00041 * A Data Target may be subclassed to handle additional, user-defined data types; to
00042 * this end, the message handlers return 1 if the type is one of DT_VOID...DT_STRING
00043 * and 0 otherwise.  Thus subclasses can handle any data types not dealt with in the
00044 * default implementation.
00045 */
00046 class FXAPI FXDataTarget : public FXObject {
00047   FXDECLARE(FXDataTarget)
00048 protected:
00049   void         *data;           // Associated data
00050   FXObject     *target;         // Target object
00051   FXSelector    message;        // Message ID
00052   FXuint        type;           // Type of data
00053 private:
00054   FXDataTarget(const FXDataTarget&);
00055   FXDataTarget& operator=(const FXDataTarget&);
00056 public:
00057   long onCmdValue(FXObject*,FXSelector,void*);
00058   long onUpdValue(FXObject*,FXSelector,void*);
00059   long onCmdOption(FXObject*,FXSelector,void*);
00060   long onUpdOption(FXObject*,FXSelector,void*);
00061 public:
00062   enum {
00063     DT_VOID=0,
00064     DT_BOOL,
00065     DT_CHAR,
00066     DT_UCHAR,
00067     DT_SHORT,
00068     DT_USHORT,
00069     DT_INT,
00070     DT_UINT,
00071     DT_LONG,
00072     DT_ULONG,
00073     DT_FLOAT,
00074     DT_DOUBLE,
00075     DT_STRING,
00076     DT_LAST
00077     };
00078 public:
00079   enum {
00080     ID_VALUE=1,                   /// Will cause the FXDataTarget to ask sender for value
00081     ID_OPTION=ID_VALUE+10001,     /// ID_OPTION+i will set the value to i where -10000<=i<=10000
00082     ID_LAST=ID_OPTION+10000
00083     };
00084 public:
00085 
00086   /// Associate with nothing
00087   FXDataTarget():data(NULL),target(NULL),message(0),type(DT_VOID){}
00088 
00089   /// Associate with nothing
00090   FXDataTarget(FXObject* tgt,FXSelector sel):data(NULL),target(tgt),message(sel),type(DT_VOID){}
00091 
00092   /// Associate with character variable
00093   FXDataTarget(FXbool& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_BOOL){}
00094 
00095   /// Associate with character variable
00096   FXDataTarget(FXchar& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_CHAR){}
00097 
00098   /// Associate with unsigned character variable
00099   FXDataTarget(FXuchar& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_UCHAR){}
00100 
00101   /// Associate with signed short variable
00102   FXDataTarget(FXshort& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_SHORT){}
00103 
00104   /// Associate with unsigned short variable
00105   FXDataTarget(FXushort& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_USHORT){}
00106 
00107   /// Associate with int variable
00108   FXDataTarget(FXint& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_INT){}
00109 
00110   /// Associate with unsigned int variable
00111   FXDataTarget(FXuint& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_UINT){}
00112 
00113   /// Associate with long variable
00114   FXDataTarget(FXlong& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_LONG){}
00115 
00116   /// Associate with unsigned long variable
00117   FXDataTarget(FXulong& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_ULONG){}
00118 
00119   /// Associate with float variable
00120   FXDataTarget(FXfloat& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_FLOAT){}
00121 
00122   /// Associate with double variable
00123   FXDataTarget(FXdouble& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_DOUBLE){}
00124 
00125   /// Associate with string variable
00126   FXDataTarget(FXString& value,FXObject* tgt=NULL,FXSelector sel=0):data(&value),target(tgt),message(sel),type(DT_STRING){}
00127 
00128 
00129   /// Set the message target object for this data target
00130   void setTarget(FXObject *t){ target=t; }
00131 
00132   /// Get the message target object for this data target, if any
00133   FXObject* getTarget() const { return target; }
00134 
00135 
00136   /// Set the message identifier for this data target
00137   void setSelector(FXSelector sel){ message=sel; }
00138 
00139   /// Get the message identifier for this data target
00140   FXSelector getSelector() const { return message; }
00141 
00142 
00143   /// Return type of data its connected to
00144   FXuint getType() const { return type; }
00145 
00146   /// Return pointer to data its connected to
00147   void* getData() const { return data; }
00148 
00149 
00150   /// Associate with nothing
00151   void connect(){ data=NULL; type=DT_VOID; }
00152 
00153   /// Associate with FXbool variable
00154   void connect(FXbool& value){ data=&value; type=DT_BOOL; }
00155 
00156   /// Associate with character variable
00157   void connect(FXchar& value){ data=&value; type=DT_CHAR; }
00158 
00159   /// Associate with unsigned character variable
00160   void connect(FXuchar& value){ data=&value; type=DT_UCHAR; }
00161 
00162   /// Associate with signed short variable
00163   void connect(FXshort& value){ data=&value; type=DT_SHORT; }
00164 
00165   /// Associate with unsigned short variable
00166   void connect(FXushort& value){ data=&value; type=DT_USHORT; }
00167 
00168   /// Associate with int variable
00169   void connect(FXint& value){ data=&value; type=DT_INT; }
00170 
00171   /// Associate with unsigned int variable
00172   void connect(FXuint& value){ data=&value; type=DT_UINT; }
00173 
00174   /// Associate with long variable
00175   void connect(FXlong& value){ data=&value; type=DT_LONG; }
00176 
00177   /// Associate with unsigned long variable
00178   void connect(FXulong& value){ data=&value; type=DT_ULONG; }
00179 
00180   /// Associate with float variable
00181   void connect(FXfloat& value){ data=&value; type=DT_FLOAT; }
00182 
00183   /// Associate with double variable
00184   void connect(FXdouble& value){ data=&value; type=DT_DOUBLE; }
00185 
00186   /// Associate with string variable
00187   void connect(FXString& value){ data=&value; type=DT_STRING; }
00188 
00189 
00190   /// Associate with nothing; also set target and message
00191   void connect(FXObject* tgt,FXSelector sel){ data=NULL; target=tgt; message=sel; type=DT_VOID; }
00192 
00193   /// Associate with character variable; also set target and message
00194   void connect(FXbool& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_BOOL; }
00195 
00196   /// Associate with character variable; also set target and message
00197   void connect(FXchar& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_CHAR; }
00198 
00199   /// Associate with unsigned character variable; also set target and message
00200   void connect(FXuchar& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_UCHAR; }
00201 
00202   /// Associate with signed short variable; also set target and message
00203   void connect(FXshort& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_SHORT; }
00204 
00205   /// Associate with unsigned short variable; also set target and message
00206   void connect(FXushort& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_USHORT; }
00207 
00208   /// Associate with int variable; also set target and message
00209   void connect(FXint& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_INT; }
00210 
00211   /// Associate with unsigned int variable; also set target and message
00212   void connect(FXuint& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_UINT; }
00213 
00214   /// Associate with long variable; also set target and message
00215   void connect(FXlong& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_LONG; }
00216 
00217   /// Associate with unsigned long variable; also set target and message
00218   void connect(FXulong& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_ULONG; }
00219 
00220   /// Associate with float variable; also set target and message
00221   void connect(FXfloat& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_FLOAT; }
00222 
00223   /// Associate with double variable; also set target and message
00224   void connect(FXdouble& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_DOUBLE; }
00225 
00226   /// Associate with string variable; also set target and message
00227   void connect(FXString& value,FXObject* tgt,FXSelector sel){ data=&value; target=tgt; message=sel; type=DT_STRING; }
00228 
00229 
00230   /// Destroy
00231   virtual ~FXDataTarget();
00232   };
00233 
00234 }
00235 
00236 #endif

Copyright © 1997-2010 Jeroen van der Zijp