SophiaFramework UNIVERSE 5.3 |
Control is the Responder class located inside the Window.
Table 10.6. Control Types
Class Name | Description |
---|---|
SFRButtonControl | Responder which represents a button control |
SFRCheckboxControl | Responder which represents a checkbox |
SFRRadiobuttonControl | Responder which represents a radiobutton |
SFRLabelControl | Responder which represents a label control |
SFRComboboxControl | Responder which represents a combobox control |
SFREditboxControl | Responder which represents an editbox control that displays editable text |
SFRTabControl | Responder which represents a tab control |
SFRBrowserControl | Responder which represents a simple web browser |
The method to create and destroy the Control instance is similar to Creating and Destroying the Responder
Example 10.26. Define the Button
SFMTYPEDEFCLASS(MyWindow) class MyWindow : public SFRTitleWindow { SFMSEALCOPY(MyWindow) public: MyWindow(Void) static_throws; virtual ~MyWindow(Void) { return; } // define button as member variable of "pointer to button" type SFRButtonControlPtr _button; // button };
Example 10.27. Create the Button
// Constructor (No error handling) MyWindow::MyWindow(Void) : SFRTitleWindow(SFRApplication::GetInstance(), SFXRectangle(20, 20, 200, 250), "my window") static_throws { // create button // 1st arg: parent responder // 2nd arg: button position and size // 3rd arg: button name _button = new SFRButtonControl(this, SFXRectangle(20, 50, 150, 25), "button"); return; }
Reference: Development with SFR GUI Framework: Button
Example 10.28. Define the Checkbox
SFMTYPEDEFCLASS(MyWindow) class MyWindow : public SFRTitleWindow { SFMSEALCOPY(MyWindow) public: MyWindow(Void) static_throws; virtual ~MyWindow(Void) { return; } // define checkbox as member variable of "pointer to checkbox" type SFRCheckboxControlPtr _checkbox; // checkbox };
Example 10.29. Create the Checkbox
// Constructor (No error handling) MyWindow::MyWindow(Void) : SFRTitleWindow(SFRApplication::GetInstance(), SFXRectangle(20, 20, 200, 250), "my window") static_throws { // create checkbox // 1st arg: parent responder // 2nd arg: checkbox position and size // 3rd arg: button name _checkbox = new SFRCheckboxControl(this, SFXRectangle(20, 50, 150, 25), "checkbox"); return; }
Reference: Development with SFR GUI Framework: Checkbox
Example 10.30. Define the Radiobutton
SFMTYPEDEFCLASS(MyWindow) class MyWindow : public SFRTitleWindow { SFMSEALCOPY(MyWindow) public: MyWindow(Void) static_throws; virtual ~MyWindow(Void) { return; } // define radiobutton member variable of "pointer to radiobutton" type SFRRadiobuttonControlPtr _radiobutton1; // radiobutton 1 SFRRadiobuttonControlPtr _radiobutton2; // radiobutton 2 };
Example 10.31. Create the Radiobutton
// Constructor (No error handling) MyWindow::MyWindow(Void) : SFRTitleWindow(SFRApplication::GetInstance(), SFXRectangle(20, 20, 200, 250), "my window") static_throws { // create radiobutton // 1st arg: parent responder // 2nd arg: radiobutton position and size // 3rd arg: radiobutton name _radiobutton1 = new SFRRadiobuttonControl(this, SFXRectangle(20, 50, 150, 25), "radiobutton1"); _radiobutton2 = new SFRRadiobuttonControl(this, SFXRectangle(20, 80, 150, 25), "radiobutton2"); // group together radiobuttons _radiobutton2->Group(_radiobutton1); // set radiobutton1 to selected status _radiobutton1->SetStatusCheck(true); return; }
Example 10.32. Define the Label
SFMTYPEDEFCLASS(MyWindow) class MyWindow : public SFRTitleWindow { SFMSEALCOPY(MyWindow) public: MyWindow(Void) static_throws; virtual ~MyWindow(Void) { return; } // define label as member variable of "pointer to label" type SFRLabelControlPtr _label; // label };
Example 10.33. Create the Label
// Constructor (No error handling) MyWindow::MyWindow(Void) : SFRTitleWindow(SFRApplication::GetInstance(), SFXRectangle(20, 20, 200, 250), "my window") static_throws { // create label // 1st arg: parent responder // 2nd arg: label position and size // 3rd arg: label name _label = ::new SFRLabelControl(this, SFXRectangle(30, 50, 150, 25), "LabelControl"); return; }
Example 10.34. Define the Combobox
SFMTYPEDEFCLASS(MyWindow) class MyWindow : public SFRTitleWindow { SFMSEALCOPY(MyWindow) public: MyWindow(Void) static_throws; virtual ~MyWindow(Void) { return; } // define combobox as member variable of "pointer to combobox" type SFRComboboxControlPtr _combobox; // combobox };
Example 10.35. Create the Combobox
// Constructor (No error handling) MyWindow::MyWindow(Void) : SFRTitleWindow(SFRApplication::GetInstance(), SFXRectangle(20, 20, 200, 250), "my window") static_throws { SFXWideString item[] = {"combobox1", "combobox2", "combobox3"}; // create combobox // 1st arg: parent responder // 2nd arg: combobox position and size // 3rd arg: combobox name _combobox = new SFRComboboxControl(this, SFXRectangle(20, 50, 150, 25), item, lengthof(item)); return; }
Reference: Development with SFR GUI Framework: Combobox
Example 10.36. Define the Textbox
SFMTYPEDEFCLASS(MyWindow) class MyWindow : public SFRTitleWindow { SFMSEALCOPY(MyWindow) public: MyWindow(Void) static_throws; virtual ~MyWindow(Void) { return; } // define text box as member variable of "pointer to textbox" type SFREditboxControlPtr _editbox; // textbox };
Example 10.37. Create the Textbox
// Constructor (No error handling) MyWindow::MyWindow(Void) : SFRTitleWindow(SFRApplication::GetInstance(), SFXRectangle(20, 20, 200, 250), "my window") static_throws { // create textbox // 1st arg: parent responder // 2nd arg: text box position and size // 3rd arg: text box name _editbox = new SFREditboxControl(this, SFXRectangle(20, 50, 150, 25), "Editbox"); return; }
Reference: Development with SFR GUI Framework: Text box
Example 10.38. Define the Tab
SFMTYPEDEFCLASS(MyWindow) class MyWindow : public SFRTitleWindow { SFMSEALCOPY(MyWindow) public: MyWindow(Void) static_throws; virtual ~MyWindow(Void) { return; } // define tab as member variable of "pointer to tab" type SFRTabControlPtr _tab; // tab SFRTabPanePtr _pane; // tab pane };
Example 10.39. Create the Tab
// Constructor (No error handling) MyWindow::MyWindow(Void) : SFRTitleWindow(SFRApplication::GetInstance(), SFXRectangle(20, 20, 200, 250), "my window") static_throws { // create tab // 1st arg: parent responder // 2nd arg: tab position and size _tab = ::new SFRTabControl(this, SFXRectangle(20, 30, 150, 150)); // create tabpanes _pane = new SFRTabPane(_tab, "page1"); _pane = new SFRTabPane(_tab, "page2"); return; }
Example 10.40. Define the Simple Web Browse
SFMTYPEDEFCLASS(MyWindow) class MyWindow : public SFRTitleWindow { SFMSEALCOPY(MyWindow) public: MyWindow(Void) static_throws; virtual ~MyWindow(Void) { return; } // define web browser as member variable of "pointer to web browser" type SFRBrowserControlPtr _browser; // web browser };
Example 10.41. Create the Simple Web Browser
// Constructor (No error handling) MyWindow::MyWindow(Void) : SFRTitleWindow(SFRApplication::GetInstance(), SFXRectangle(20, 20, 200, 250), "my window") static_throws { // input string for browser SFXAnsiString buffer( "BrowserControl<br /><br />" "<a href=\"/example/tabbrowser/\">ソフィアクレイドル</a><br /><br />" ); // create web browser // 1st arg: parent responder // 2nd arg: browser position and size _browser = ::new SFRBrowserControl(this, rect); // read string as HTML, then start rendering _browser->Load(buffer); return; }
In order to select the Control instance, move focus by using the ARROW keys. When the Control instance is focused, its color is also changed.
The table below is the list of functions for moving the focus.
Table 10.7. Functions for Moving Focus
Function Name | Description |
---|---|
FocusPrevious | Move focus back to the previous control. |
FocusNext | Move focus forward to the next control. |
FocusUp | Move focus up. |
FocusDown | Move focus down. |
FocusLeft | Move focus to the left. |
FocusRight | Move focus to the right. |
Example 10.42. Focus Moving Code
// Key handler HANDLER_IMPLEMENT_BOOLEVENT(MyWindow, OnKey, event) { switch (event.GetP16()) { // move focus case AVK_UP: // up FocusUp(); return true; case AVK_LEFT: // left FocusLeft(); return true; case AVK_DOWN: // down FocusDown(); return true; case AVK_RIGHT: // right FocusRight(); return true; } return false; }
To check whether or not the Control instance is being focused or get the Control instance focused, use the following functions.
Default actions are set to the Control in advance.
For example, the diagram below shows the default action of the focused Control for when the "Select" key is pressed.
The Control class has member functions to get its status.
Example 10.44. Process according to control status
// _checkbox is SFRCheckboxControlPtr type if (_checkbox->GetStatusCheck()) { // if checkbox is checked //...some processing } // _combobox is SFRComboboxControlPtr type switch (_combobox->GetValue()) { // which item has been selected? case 0: // processing according to selected item ... case 1: ... }
The Control instance can be disabled not to be selected, or can be invisible.
Table 10.9. Functions to make the Control instance enable/disable or visible/invisible
Function Name | Description |
---|---|
SetStatusEnable | Set the "enable/disable" status of Responder instance. (true : enable, false : disable) |
GetStatusEnable | Get the "enable/disable" status of Responder instance. (true : enable, false : disable) |
SetStatusVisible | Set the "visible/invisible" status of Responder instance. (true: visible, false: invisible) |
GetStatusVisible | Get the "visible/invisible" status of Responder instance. (true: visible, false: invisible) |
An event handler can be registered in the Control instance.
In the example below, register the handlers for when the button is pressed and for when the selected item of combobox is changed in the SFRButtonControl and SFRComboboxControl instances respectively.
Example 10.46. Button Event Handler
class MyWindow : public SFRTitleWindow { private: SFRButtonControlPtr _button; // pointer to button public: // declare button handler HANDLER_DECLARE_VOIDCONTROL(OnButtonControl) }; // Button handler // 1st arg: class it belongs to, 2nd arg: handler name, 3rd arg: result value (UInt16), 4th arg: pointer to button HANDLER_IMPLEMENT_VOIDCONTROL(MyWindow, OnButtonControl, result, control) { TRACE("Hello Button"); // display "Hello Button" on BREW Output Window } // Constructor MyWindow::MyWindow(Void) : SFRTitleWindow(SFRApplication::GetInstance(), SFXRectangle(20, 20, 200, 250), "my window") static_throws { // create button _button = new SFRButtonControl(this, SFXRectangle(10, 10, 50, 25), "button name"); // register button handler _button->RegisterHandler(SREVT_CONTROL, HANDLER_BEFORE, HANDLER_FUNCTION(OnButtonControl))); }
For declaring and implementing the handler, the HANDLER_DECLARE_?????? and HANDLER_IMPLEMENT_?????? macros are used respectively. For registering the handler, the RegisterHandler function is used.
Example 10.47. Combobox Event Handler
class MyWindow : public SFRTitleWindow { private: SFRComboboxControlPtr _combobox; // pointer to combobox public: // dealare combobox handler HANDLER_DECLARE_VOIDCONTROL(OnComboboxControl) }; // Combobox handler HANDLER_IMPLEMENT_VOIDCONTROL(MyWindow, OnComboboxControl, result, control) { if (result == SRP16_ESCAPE) { // if item is not selected // do nothing } else { // result: index of selected item // control: pointer to combobox // GetTitle: to get title of selected item SFXAnsiString string(static_cast<SFRComboboxControlPtr>(control)->GetTitle(result)); // display string on BREW Output Window // string.GetCString() is to get C string TRACE("'%d: %s' is selected.", result, string.GetCString()); } } // Constructor MyWindow::MyWindow(Void) : SFRTitleWindow(SFRApplication::GetInstance(), SFXRectangle(20, 20, 200, 250), "my window") static_throws { // combobox items SFXWideString item[] = {"item1", "item2", "item3"}; // create combobox _combobox = new SFRComboboxControl(this, SFXRectangle(10, 165, 90, 20), item, lengthof(item)); // register combobox handler _combobox->RegisterHandler(SREVT_CONTROL, HANDLER_BEFORE, HANDLER_FUNCTION(OnComboboxControl))); }
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |