We add two new classes to do the actual processing. Counter
which will look for the text_changed
event and updates a
display field. ReverseCommand
which is a tbx::Command
that will be executed by the button to reverse the text.
These classes are members of the Reverser class and are hooked up with the following code
void Reverser::auto_created(std::string template_name, Object object) { // object references the toolbox object that was created // so we construct a tbx::Window object from it so we can // use the Window gadget method. Window window(object); // Set variable for the gadgets on the window we wish to access WritableField input(window.gadget(1)); DisplayField count(window.gadget(3)); // Let the counter class know where to put the count _counter.display_to(count); // Add the counter as a text listener to the input field input.add_text_changed_listener(&_counter); // Let the reverser command know what field it is dealing with _reverser.reverse_field(input); // Finally add the reverser command to the window. Any gadget // (including our push button) on the window that generates // the event number 1 will cause the object to run. window.add_command(1, &_reverser); }