/*********************************************************************** * FXRuby -- the Ruby language bindings for the FOX GUI toolkit. * Copyright (c) 2001-2003 by J. Lyle Johnson. All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * For further information please contact the author by e-mail * at "lyle@users.sourceforge.net". ***********************************************************************/ /*********************************************************************** * $Id: FXRbDataTarget.cpp,v 1.1 2004/08/07 10:55:26 lyle Exp $ ***********************************************************************/ #include "FXRbCommon.h" /** * Data targets for FXRuby are implemented slightly different from * those in the C++ implementation since we don't have the concept * of C++ references for immutable types (like integers, floats and * strings). */ // Initialize a data target with this value FXRbDataTarget::FXRbDataTarget(VALUE value,FXObject* tgt,FXSelector sel) : FXDataTarget(tgt,sel), intValue(0), doubleValue(0.0), boolValue(FALSE) { setValue(value); } // Set new value for data target void FXRbDataTarget::setValue(VALUE value){ switch (TYPE(value)) { case T_NIL: connect(); break; case T_FIXNUM: intValue=NUM2LONG(value); connect(intValue); break; case T_BIGNUM: /* still not sure about this conversion */ intValue=NUM2ULONG(value); connect(intValue); break; case T_FLOAT: doubleValue=NUM2DBL(value); connect(doubleValue); break; case T_STRING: stringValue=STR2CSTR(value); connect(stringValue); break; case T_TRUE: boolValue=TRUE; connect(boolValue); break; case T_FALSE: boolValue=FALSE; connect(boolValue); break; default: rb_raise(rb_eTypeError, "can't initialize FXDataTarget with type %s.", rb_class2name(CLASS_OF(value))); } } // Return current value for this data target VALUE FXRbDataTarget::getValue() const { switch(type){ case DT_VOID: return Qnil; case DT_CHAR: return to_ruby(*reinterpret_cast(data)); case DT_UCHAR: return to_ruby(*reinterpret_cast(data)); case DT_SHORT: return to_ruby(*reinterpret_cast(data)); case DT_USHORT: return to_ruby(*reinterpret_cast(data)); case DT_INT: return to_ruby(*reinterpret_cast(data)); case DT_UINT: return to_ruby(*reinterpret_cast(data)); case DT_FLOAT: return to_ruby(*reinterpret_cast(data)); case DT_DOUBLE: return to_ruby(*reinterpret_cast(data)); case DT_STRING: return to_ruby(*reinterpret_cast(data)); default: fxerror("unknown data type in FXRbDataTarget::getValue()"); } return Qnil; }