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

FXDataTarget.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *                              D a t a   T a r g e t                            *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1998,2002 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.14 2002/01/18 22:42:52 jeroen Exp $                   *
00023 ********************************************************************************/
00024 #ifndef FXDATATARGET_H
00025 #define FXDATATARGET_H
00026 
00027 #ifndef FXOBJECT_H
00028 #include "FXObject.h"
00029 #endif
00030 
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 substracting ID_OPTION from the message ID.
00043 */
00044 class FXAPI FXDataTarget : public FXObject {
00045   FXDECLARE(FXDataTarget)
00046 protected:
00047   FXObject     *target;                 // Target object
00048   void         *data;                   // Associated data
00049   FXSelector    message;                // Message ID
00050   FXuint        type;                   // Type of data
00051 public:
00052   long onCmdValue(FXObject*,FXSelector,void*);
00053   long onUpdValue(FXObject*,FXSelector,void*);
00054   long onCmdOption(FXObject*,FXSelector,void*);
00055   long onUpdOption(FXObject*,FXSelector,void*);
00056 public:
00057   enum {
00058     DT_VOID=0,
00059     DT_CHAR,
00060     DT_UCHAR,
00061     DT_SHORT,
00062     DT_USHORT,
00063     DT_INT,
00064     DT_UINT,
00065     DT_FLOAT,
00066     DT_DOUBLE,
00067     DT_STRING,
00068     DT_LAST
00069     };
00070 public:
00071   enum {
00072     ID_VALUE=1,                   /// Will cause the FXDataTarget to ask sender for value
00073     ID_OPTION=ID_VALUE+10001,     /// ID_OPTION+i will set the value to i where -10000<=i<=10000
00074     ID_LAST=ID_OPTION+10000
00075     };
00076 public:
00077 
00078   /// Associate with nothing
00079   FXDataTarget(FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(NULL),message(sel),type(DT_VOID){}
00080 
00081   /// Associate with character variable
00082   FXDataTarget(FXchar& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_CHAR){}
00083 
00084   /// Associate with unsigned character variable
00085   FXDataTarget(FXuchar& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_UCHAR){}
00086 
00087   /// Associate with signed short variable
00088   FXDataTarget(FXshort& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_SHORT){}
00089 
00090   /// Associate with unsigned short variable
00091   FXDataTarget(FXushort& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_USHORT){}
00092 
00093   /// Associate with int variable
00094   FXDataTarget(FXint& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_INT){}
00095 
00096   /// Associate with unsigned int variable
00097   FXDataTarget(FXuint& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_UINT){}
00098 
00099   /// Associate with float variable
00100   FXDataTarget(FXfloat& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_FLOAT){}
00101 
00102   /// Associate with double variable
00103   FXDataTarget(FXdouble& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_DOUBLE){}
00104 
00105   /// Associate with string variable
00106   FXDataTarget(FXString& value,FXObject* tgt=NULL,FXSelector sel=0):target(tgt),data(&value),message(sel),type(DT_STRING){}
00107 
00108 
00109   /// Set the message target object for this data target
00110   void setTarget(FXObject *t){ target=t; }
00111 
00112   /// Get the message target object for this data target, if any
00113   FXObject* getTarget() const { return target; }
00114 
00115   /// Set the message identifier for this data target
00116   void setSelector(FXSelector sel){ message=sel; }
00117 
00118   /// Get the message identifier for this data target
00119   FXSelector getSelector() const { return message; }
00120 
00121 
00122   /// Return type of data its connected to
00123   FXuint getType() const { return type; }
00124 
00125   /// Return pointer to data its connected to
00126   void* getData() const { return data; }
00127 
00128 
00129   /// Associate with nothing
00130   void connect(){ type=DT_VOID; data=NULL; }
00131 
00132   /// Associate with character variable
00133   void connect(FXchar& value){ type=DT_CHAR; data=&value; }
00134 
00135   /// Associate with unsigned character variable
00136   void connect(FXuchar& value){ type=DT_UCHAR; data=&value; }
00137 
00138   /// Associate with signed short variable
00139   void connect(FXshort& value){ type=DT_SHORT; data=&value; }
00140 
00141   /// Associate with unsigned short variable
00142   void connect(FXushort& value){ type=DT_USHORT; data=&value; }
00143 
00144   /// Associate with int variable
00145   void connect(FXint& value){ type=DT_INT; data=&value; }
00146 
00147   /// Associate with unsigned int variable
00148   void connect(FXuint& value){ type=DT_UINT; data=&value; }
00149 
00150   /// Associate with float variable
00151   void connect(FXfloat& value){ type=DT_FLOAT; data=&value; }
00152 
00153   /// Associate with double variable
00154   void connect(FXdouble& value){ type=DT_DOUBLE; data=&value; }
00155 
00156   /// Associate with string variable
00157   void connect(FXString& value){ type=DT_STRING; data=&value; }
00158   };
00159 
00160 
00161 
00162 #endif