[fxruby-users] [Foxgui-users] FXDataTarget: am I doing this fine?

Damián M. González gonzalezdamianm at hotmail.com
Fri Dec 28 12:48:00 UTC 2012

> Ok, I'm not 100% up on Ruby binding particulars, but some observations:
> 1) FXDataTarget should be connected to a variable (not a value) that will will not 
>    go out of scope sooner that FXDataTarget itself does.  The reason is FXDataTarget
>    keeps a pointer to this variable, so it can modify or read its value.
> 2) A SEL_COMMAND (or in some cases, a SEL_CHANGED) from a widget can change the
>    value of the connected variable (if there is one).
>    This works in either of two ways:
> 	a) an ID_VALUE message is received from the widget; the FXDataTarget will
>  	depending on the type of the connected variable.  
> 	b) an ID_OPTION + i message is received from the widget. In this case, the
> 	value is expected to be an integer type, and is plucked from the message
> 	itself by subtracting the ID_OPTION.  So the value is i in this case.
> 3) A SEL_UPDATE from a widget causes the widget's value to be updated through
>    the datatarget, from the value of its connected variable:
> 	a) if the message is ID_VALUE, a message is sent to the widget; the 
> 	message id depends on the type of variable connected to the datatarget:
> 	ID_SETINTVALUE is sent for small integer variables, ID_SETLONGVALUE is
> 	sent for long integers, ID_SETREALVALUE is sent for floating point
> 	variables, and ID_SETSTRINGVALUE is sent for string variables.
> 	b) if the message is ID_OPTION + i, the variable connected to the data-
> 	target is compared to i, and the widget is sent ID_CHECK or ID_UNCHECK
> 	if the value is equal or unequal to i.
> Hope this helps,
> 			-- JVZ
> +----------------------------------------------------------------------------+
> | Copyright (C) 11:40 12/27/2012 Jeroen van der Zijp.   All Rights Reserved. |
> +----------------------------------------------------------------------------+

 Okay, the explanation is very clean. I don't know how to interpret the point 3, since that is not easy to see how it works, because this happen:

 @datatarget = FXDataTarget.new @textwidget = FXTextField.new(parent, 10, target: @datatarget, selector: FXDataTarget::ID_VALUE)  #so if I do
 #it is supposed that the @textwidget will be filled with "Hello" right? because of the selector established, right? the ID_VALUE. It happens. #so what happen if I change the selector to an ID_OPTION
 #what happen now?
 @datatarget.value=("Hi there")
 #nothing happens #I've tried with another widget
 @checkbutton = FXCheckButton.new(parent, nil, target: @datatarget, selector: FXDataTarget::ID_VALUE) @datatarget.value=("Hi")
 #nothing happens
 #it becomes checked!! #if I change the selector to an ID_OPTION the widget will only activate when it receives the number asigned to it in his 'selector'
 @checkbutton.selector=(FXDataTarget::ID_OPTION.+(1)) @datatarget.value=("House")
 #nothing happens, but..  @datatarget.value=(1)
 #the widget becomes checked, interesting right? Is not a simples behaviour, but now I  have it more clear

 So, what I wanted to acomplish was not right with FXDataTargets, I just found another solution: I give each button a different selector: FXWindow::ID_LAST.+(1), and go on... Then I didn't establish any target for them, so the message is catched by it own. So to each button I did something like this:
@a_button.connect(SEL_COMMAND) do │sender, selector, data│  do_an_action(FXSELID(selector).-(FXWindow::ID_LAST))end
 So in that way I can identify which button was pressed an do some action related. I'm very thankfull for the explanation, see you around!! :) 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20121228/fd01da41/attachment-0001.html>

More information about the fxruby-users mailing list