wxPanel
-derived class which holds the tree buttons OK, Cancel, Apply (mgOptionsBtnPanel) laid out in the botton-right side of the dialog wxTreeCtrl
-derived class for the tree list which holds all option's families: ( mgOptionsTreeCtrl) laid out in the left side of the dialog wxPanel
-derived class holding the options value specific for the selected item in the treelist controlFont
item displays an option's panel that contains options values specific for a font.
Every item in the treelist is associated with a custom wxTreeItemData
-derived class that holds informations about the relevant option's panel. The m_panel
data member of this structure is used to store the pointer of the wxPanel-derived option's panel. This pointer may be NULL so that the relevant panel was not yet created.
The other data member is m_className
that is a string containing the class name of the mgOptBasePanel
derived class to be instantiated when the user selects the treelist item. Specialized classes are created at run-time using the wxWindow's RTTI facility: it can create an object of a wxObject derived class by supplying the className as a string. WARNING: because this feature seems to work only on some platform, the m_className
member is not used. Instead, an enum is used and stored in the m_classID
memebr of this structure.
At dialog startup, the mgOptDlg
class constructs the treelist control and the button panel but no option's panel are constructed: they are constructed only on request when the user clicks the relevant item in the treelist control.
Then, the ctor constructs three wxLayoutConstraints
(or, if OPTIONSDLG_USE_LAYOUTCONSTRAINTS is not defined, sizers) objects, one for each child window and bounds the treelist control and the button panel to their respective layout objects. The layout object for option's panels is stored in a data member because no option's panel was yet been created. Each newly created option's panel object will be bound to a copy of the layout object.
When the user selects an item in the treelist, the event handler (located in the dialog box itself, and not in the child window) obtains the associated item-data structure and calls the DisplayPanel
function passing a pointer to the item-data as argument. This function checks the item-data's m_panel
data member for NULL. If it is not NULL, the option's panel was already created and its Show(TRUE)
function is called followed by a Show(FALSE)
call to the actually displayed option's panel (stored in the m_actualPanel
data member).
If the m_panel
data member is NULL the CreatePanel
function is called passing the itemID as argument. This function returns a pointer to the newly created option's panel. The pointer is stored in the itam-data m_panel
data member.
The changes made in the option's panels by the user are not stored immediatly in the configuration object because the user might discard changes by clicking the Cancel button.
When the user clicks Apply the event handler calls mgOptDlg::CommitChanges function. If OK is clicked the function above is called and then the EndModal
function. If Cancel is clicked only EndModal
is called and the dialog destroyed.
In order to have the maximum flexibility, this function does nothing special: it iterates through all items in the treelist control retriving the m_panel
item-data's data member and, if not NULL, calls the CommitChnages
pure virtual function of the mgOptBasePanel-derived class. In this way, the real work is delegated to the specialized option's panel which should also refresh the GUI if the changes affect it.
To add a new panel in the Options dialog box you have to:
mgOptTreeCtrlItemData
wxTreeItemId id; id = AppendItem( idRoot, "ANewPanel", -1, -1, new mgOptTreeCtrlItemData( "Id_ANewPanelClass" ) );
mgOptBasePanel
and declare only the default ctor. You do not have to setup your panel design in the ctor but in the Setup fucntion. mgOptionsDl::CreatePanel
function add a case statement in wich you construct the derived class for the new ID of your panel (that is, Id_AnewPanelClass). [ Top ] |