The portable dialog scheme

I really like the portable dialog format. We always write apps that cohere to the document/view paradigm but as soon as we start writing dialogs, Visual Studio puts everything in the view (dialog) class. Why is that? Most things that Microsoft does “helps” you to tie your code to windows, maybe it’s just a case of that helpfulness.

 

Consider a dialog defined as:

 

<?xml version="1.0" encoding="ISO-8859-1" ?>

 <UIEnvironment FontSize="12">

  <UIDialog Area="200, 100, 246, 120" Caption="FSM State">

   <UIStatic Area="10, 10, 80, 20" Caption="State &Name:"/>

   <UIEdit Area="90, 10, 120, 20" Tag="Name"/>

   <UICheckBox Area="10, 35, 200, 20" Caption="&Entry Point (first state)" Tag="EntryPoint"/>

   <UIButton Area="50, 60, 60, 25" Caption="OK" Tag="OK"/>

   <UIButton Area="150,60, 60, 25" Caption="Cancel" Tag="Cancel"/>

  </UIDialog>

 </UIEnvironment>

 

Lets concentrate on the tags here: we’ve got an edit window tagged “Name” and a checkbox tagged “EntryPoint”. We’ll want to bind these to data values. So we create a class derived from DialogDoc (which declares a pure virtual bind method):

 

struct state_data : public DialogDoc

{

      bool              entry_point_;

      std::string       name_;

 

      state_data() : entry_point_(false)  {}

 

      void bind(UIDialog &dialog)

      {

            dialog.BindValue("Name", property_base::Ptr(new property_function_variable<std::string>(name_)));

            dialog.BindCB("EntryPoint", property_t<bool>::Ptr(new property_t<bool>(entry_point_)));

      }

};

 

OK, lets run a modal dialog box:

 

state_data  state;

 

if    (do_modal(state, "FSMState.txt")) // the user clicked OK

{

      // ...

}

 

That’s it for now. The above is found in the FSM Sample, which is available for download.