class Fox::FXDataTarget

A data target allows a valuator widget such as an FXSlider or FXTextField to be directly connected with a variable in the program. Whenever the valuator control changes, the variable connected through the data target is automatically updated; conversely, whenever the program changes a variable, all the connected valuator widgets will be updated to reflect this new value on the display. For example:

data = FXDataTarget.new("Some Text")
textfield = FXTextField.new(p, 12, data, FXDataTarget::ID_VALUE)

Data targets also allow connecting other kinds of widgets (like FXRadioButton and FXMenuCommand) to a variable. In this case, the new value of the connected variable is computed by subtracting FXDataTarget::ID_OPTION from the message identifier. For example, to tie a group of radio buttons to a single data target’s value (so that the buttons are mutually exclusive), use code like this:

data = FXDataTarget.new(0)
radio1 = FXRadioButton.new(p, "1st choice", data, FXDataTarget::ID_OPTION)
radio2 = FXRadioButton.new(p, "2nd choice", data, FXDataTarget::ID_OPTION + 1)
radio3 = FXRadioButton.new(p, "3rd choice", data, FXDataTarget::ID_OPTION + 2)

Note that if you’d like the data target to “forward” its SEL_COMMAND or SEL_CHANGED to some other target object after it has updated the data target value, you can do that just as you would for any other widget. For example, continuing the previous code snippet:

data.connect(SEL_COMMAND) {
  puts "The new data target value is #{data.value}"
}

Events

The following messages are sent by FXDataTarget to its target:

SEL_COMMAND

Sent after the data target processes a SEL_COMMAND message itself

SEL_CHANGED

Sent after the data target processes a SEL_CHANGED message itself

Message identifiers

ID_VALUE

Causes the FXDataTarget to ask sender for value

ID_OPTION

ID_OPTION+i will set the value to i, where -10000 <= i <= 10000