[ Lit Window Library at SourceForge[ Lit Window Productions Homepage ]  [ wxWidgets Tips&Tricks ]  [  wxVisualSetup ]

Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

RSS Reader Tutorial Step 3: Adding RapidUI

In step 2 you've added data adapters for your own data types so that RapidUI can work with them. Now its time to create a RapidUI object and let it handle the UI.

Preparing to use RapidUI

The RapidUI class is designed like a Mediator Design Pattern. See the web for more information about this particular design pattern if you are unfamiliar with it. In short: A Mediator object is an object that encapsulates the interdependencies of several objects. Each individual object knows only about the Mediator. It passes any change requests to it along to the Mediator. The Mediator is the only participant that "knows the whole picture". It is the "conductor" of a symphonic "orchester" of individual objects.

Adding a RapidUI object to the frame window.

The first step to using the RapidUI mechanism is to instantiate a RapidUI object.

Add the rapidui.h include file to rssmainframe.h

////@end includes

#include <litwindow/wx/rapidui.h>
Add a RapidUI object to the class declaration RssMainFrame.
class RssMainFrame: public wxFrame
{    
public:
    RapidUI m_rapidUI;

Begin a 'rules' section

Rules - sometimes called constraints - are the power of RapidUI. Traditional UI coding uses a Properties, Methods, Events paradigm. RapidUI adds a fourth element: Properties, Methods, Events and Rules.

Add the following lines to rssmainframe.cpp to start a rules section

BEGIN_RULES(g_rules)
END_RULES()

The rules section is empty for now. We will fill in some rules in the next step, RSS Reader Tutorial Step 4: Filling in the rules

Initialising the RapidUI mechanism.

The RapidUI mediator object needs access to three sets of data:
  1. the windows you want it to manage
  2. the data that shall be managed
  3. the rules it shall follow

The windows is a collection of one or more wxWindow* pointers. The children of the window you pass to RapidUI are automatically assumed to be under RapidUIs control as well. The tutorial simply uses the top level frame window as the window root for RapidUI.

The data is a collection of data adapters that point to your actual data object. The members of a struct - direct or inherited - are automatically assumed to be part of the RapidUI data collection. The tutorial needs only one data adapter: the adapter to the global variable g_data.

The best place to pass these objects to the RapidUI object is in the RssMainFrame::Create() function in the file rssmainframe.cpp:

bool RssMainFrame::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{

    SetParent(parent);
    CreateControls();
    Centre();
    ////@end RssMainFrame creation
Add these lines here:
    m_rapidUI.AddWindow(this);                  // Add the main frame to RapidUI
    m_rapidUI.AddData(make_accessor(g_data));   // Add the list of channels
    m_rapidUI.AddRules(g_rules);                // Add rules
    m_rapidUI.Start();                          // Start the RapidUI mediator mechanism
Note:
make_accessor creates a data adapter for the global variable g_channels.

Here is an alternative version:

m_rapidUI << this << make_accessor(g_data) << g_rules << RapidUI::Go;

Build and run the program.

Build the program. If you are building with DLLs, you will get a linker warning.
 rssmainframe.obj : warning LNK4217: locally defined symbol ?get@?$prop_type_object@URssReaderData@@@
data_adapter@@SAPAVconverter_base@2@PBURssReaderData@@@Z (public: static class data_adapter::converter_base *
__cdecl data_adapter::prop_type_object<struct RssReaderData>::get(struct RssReaderData const *)) imported 
in function "class data_adapter::converter_base * __cdecl data_adapter::get_prop_type<struct RssReaderData>
(struct RssReaderData const *)" (??$get_prop_type@URssReaderData@@@data_adapter@@YAPAVconverter_base@0@PBURs
sReaderData@@@Z)
In plain english the warning says
A function was marked as 'to be imported from an external DLL', but later defined and exported from the program itself. In other words, the program imports its own function.
You can ignore this warning.

Step 3 Summary

Add a RapidUI object to the main frame, pass the window, data and rules to it and call RapidUI::Start.
    m_rapidUI.AddWindow(this);                  // Add the main frame to RapidUI
    m_rapidUI.AddData(make_accessor(g_data));   // Add the list of channels
    m_rapidUI.AddRules(g_rules);                // Add rules
    m_rapidUI.Start();                          // Start the RapidUI mediator mechanism

Continue with step 4 RSS Reader Tutorial Step 4: Filling in the rules


Copyright 2004, Hajo Kirchhoff, Lit Window Productions