1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
<HTML>
<head><title>Example 2: Property form view</title></head>
<BODY BGCOLOR=#FFFFFF>
<A NAME="topic107"></A><CENTER>
<A HREF="prop.htm"><img align=center src="contents.gif" BORDER=0 ALT="Contents"></A> <A HREF="prop189.htm#propertyoverview"><img align=center src="up.gif" BORDER=0 ALT="Up"></A> <A HREF="prop190.htm#topic106"><img align=center src="back.gif" BORDER=0 ALT="Previous"></A> <A HREF="prop192.htm#validatoroverview"><img align=center src="forward.gif" BORDER=0 ALT="Next"></A> </CENTER><HR>
<H3>Example 2: Property form view</H3>
<P>
This example is similar to Example 1, but uses a property form view to
edit a property sheet using a predefined dialog box.<P>
<PRE>
void RegisterValidators(void)
{
myFormValidatorRegistry.RegisterValidator((wxString)"real", new wxRealFormValidator);
myFormValidatorRegistry.RegisterValidator((wxString)"string", new wxStringFormValidator);
myFormValidatorRegistry.RegisterValidator((wxString)"integer", new wxIntegerFormValidator);
myFormValidatorRegistry.RegisterValidator((wxString)"bool", new wxBoolFormValidator);
}
void PropertyFormTest(Bool useDialog)
{
wxPropertySheet *sheet = new wxPropertySheet;
sheet->AddProperty(new wxProperty("fred", 25.0, "real", new wxRealFormValidator(0.0, 100.0)));
sheet->AddProperty(new wxProperty("tough choice", (Bool)TRUE, "bool"));
sheet->AddProperty(new wxProperty("ian", (long)45, "integer", new wxIntegerFormValidator(-50, 50)));
sheet->AddProperty(new wxProperty("julian", "one", "string"));
wxStringList *strings = new wxStringList("one", "two", "three", NULL);
sheet->AddProperty(new wxProperty("constrained", "one", "string", new wxStringFormValidator(strings)));
wxPropertyFormView *view = new wxPropertyFormView(NULL);
wxDialogBox *propDialog = NULL;
wxPropertyFormFrame *propFrame = NULL;
if (useDialog)
{
propDialog = new wxPropertyFormDialog(view, NULL, "Property Form Test", TRUE, -1, -1, 400, 300);
}
else
{
propFrame = new wxPropertyFormFrame(view, NULL, "Property Form Test", -1, -1, 400, 300);
propFrame->Initialize();
}
wxPanel *panel = propDialog ? propDialog : propFrame->GetPropertyPanel();
panel->SetLabelPosition(wxVERTICAL);
// Add items to the panel
(void) new wxButton(panel, (wxFunction)NULL, "OK", -1, -1, -1, -1, 0, "ok");
(void) new wxButton(panel, (wxFunction)NULL, "Cancel", -1, -1, 80, -1, 0, "cancel");
(void) new wxButton(panel, (wxFunction)NULL, "Update", -1, -1, 80, -1, 0, "update");
(void) new wxButton(panel, (wxFunction)NULL, "Revert", -1, -1, -1, -1, 0, "revert");
panel->NewLine();
// The name of this text item matches the "fred" property
(void) new wxText(panel, (wxFunction)NULL, "Fred", "", -1, -1, 90, -1, 0, "fred");
(void) new wxCheckBox(panel, (wxFunction)NULL, "Yes or no", -1, -1, -1, -1, 0, "tough choice");
(void) new wxSlider(panel, (wxFunction)NULL, "Sliding scale", 0, -50, 50, 100, -1, -1, wxHORIZONTAL, "ian");
panel->NewLine();
(void) new wxListBox(panel, (wxFunction)NULL, "Constrained", wxSINGLE, -1, -1, 100, 90, 0, NULL, 0, "constrained");
view->AddRegistry(&myFormValidatorRegistry);
if (useDialog)
{
view->ShowView(sheet, propDialog);
view->AssociateNames();
view->TransferToDialog();
propDialog->Centre(wxBOTH);
propDialog->Show(TRUE);
}
else
{
view->ShowView(sheet, propFrame->GetPropertyPanel());
view->AssociateNames();
view->TransferToDialog();
propFrame->Centre(wxBOTH);
propFrame->Show(TRUE);
}
}
</PRE>
</BODY></HTML>
|