Example

The following is an example of a form definition, taken from the form demo. Here, a new form MyForm has been derived, and a new member EditForm has been defined to edit objects of the type MyObject, given a panel to display it on.

void MyForm::EditForm(MyObject *object, wxPanel *panel)
{
  Add(wxMakeFormString("string 1", &(object->string1), wxFORM_DEFAULT,
                       new wxList(wxMakeConstraintFunction(MyConstraint), 0)));
  Add(wxMakeFormNewLine());

  Add(wxMakeFormString("string 2", &(object->string2), wxFORM_DEFAULT,
                  new wxList(wxMakeConstraintStrings("One", "Two", "Three", 0), 0)));
  Add(wxMakeFormString("string 3", &(object->string3), wxFORM_CHOICE,
                       new wxList(wxMakeConstraintStrings("Pig", "Cow",
                                  "Aardvark", "Gorilla", 0), 0)));
  Add(wxMakeFormNewLine());
  Add(wxMakeFormShort("int 1", &(object->int1), wxFORM_DEFAULT,
                       new wxList(wxMakeConstraintRange(0.0, 50.0), 0)));
  Add(wxMakeFormNewLine());

  Add(wxMakeFormFloat("float 1", &(object->float1), wxFORM_DEFAULT,
                       new wxList(wxMakeConstraintRange(-100.0, 100.0), 0)));
  Add(wxMakeFormBool("bool 1", &(object->bool1)));
  Add(wxMakeFormNewLine());

  Add(wxMakeFormButton("Test button", (wxFunction)MyButtonProc));

  AssociatePanel(panel);
}

wxForm::wxForm

voidwxForm

Constructor.

wxForm::wxForm

voidwxForm

Destructor. Does not delete the associated panel or any panel items, but does delete all form items.

wxForm::Add

voidAddwxFormItem *item, long id = -1

Adds a form item to the form. If an id is given this is associated with the form item; otherwise a new id is generated, by which the item may be identified later.

wxForm::FindItem

wxNode *FindItemlong id

Given a form item id, returns a list node containing the form item.

wxForm::Set

BoolSetlong id, wxFormItem *item

Given a form item id, replaces an existing item with that id with the given form item. Returns TRUE if successful.

wxForm::Delete

BoolDeletelong id

Deletes the given form item by id. Returns TRUE if successful.

wxForm::AssociatePanel

voidAssociatePanelwxPanel *panel

Associates the form with the given panel (or window derived from wxPanel, such as wxDialogBox). This causes a number of items to be created on the panel using information from the list of form items. The panel should be shown after this has been called.

wxForm::OnCancel

voidOnCancel

This member may be derived by the application. When the user presses the Cancel button, this is called, allowing the application to take action. By default, OnCancel deletes the form and the panel associated with it, probably the normal desired behaviour.

wxForm::OnOk

voidOnOk

This member may be derived by the application. When the user presses the OK button, this is called, allowing the application to take action. By default, OnOk deletes the form and the panel associated with it, probably the normal desired behaviour. Note that if any form item constraints were violated when the user pressed OK, the member does not get called.

wxForm::OnRevert

voidOnRevert

This member may be derived by the application. When the user presses the Revert button, the C++ form item variable values in effect before the last Update are restored. Then this member is called, allowing the application to take further action.

wxForm::OnUpdate

voidOnUpdate

This member may be derived by the application. When the user presses the Update button, the C++ form item variable values are updated to the values on the panel. Then this member is called, allowing the application to take further action.

wxForm::RevertValues

voidRevertValues

Internal function for displaying the C++ form item values in the displayed panel items. Should not need to be called by the user.

wxForm::UpdateValues

BoolUpdateValues

Internal function for setting the C++ form item values to the values set in the panel items. Should not need to be called by the user.