[ Lit Window Library at SourceForge ] [ Lit Window Productions Homepage ] [ wxWidgets Tips&Tricks ] [ wxVisualSetup ]
ASSIGN("m_channelsList.Items", "m_channels")m_channelsList. The Items property of the listbox control contains the list of elements. Therefore the left side of the assignment rule is m_channelsList.Items.m_channels is the name of the vector<Channels> member variable containing the channels, so the right side of the assignment is m_channels.Add this rule to the rules section.
BEGIN_RULES(g_rules) RULE("m_channelsList.Items", make_expr<accessor>("m_channels")) // listbox uses elements from m_channels END_RULES()
Channel reads: BEGIN_ADAPTER(Channel)
PROP(m_webAddress)
PROP(m_title)
PROP(m_cacheExpires)
PROP(m_headlines)
PROP(m_lastRead)
END_ADAPTER()
By default the listbox will choose the first member variable of the data adapter, the member variable m_webAddress, and display it for all elements. The listbox property Column allows you to select a different member variable. Add the following rule:
RULE("m_channelsList.Column", make_const(string("m_title"))) // listbox displays "Channel::m_title"
Build and run the application. The listbox will now show the title instead of the URL.
Current channel and list of headlines linked together
m_headlinesList.Items = m_channels.Current.m_headlines
void MyFrame::OnChannelsChanged(wxCommandEvent &evt) { m_headlinesList.Clear(); int selectedChannelIndex=m_channelsList.GetSelection(); if (selectedChannelIndex>=0) { Channel ¤t=g_data.m_channels[selectedChannelIndex]; size_t i; for (i=0; i<current.m_headlines.size(); ++i) { m_headlinesList.Append(current.m_headlines[i].m_title); } } }
RULE("m_headlinesList.Items", make_expr<accessor>("m_channelsList.Current.m_headlines"))
This is a very good (and working!) example of why I hope to reduce coding time by a factor of 10.
m_body member of the currently selected headline, i.e. the "Current" property of the headlines listbox.
Current headline and html window linked together
m_newsItem.Page = m_headlinesList.Current.m_body
void MyFrame::OnHeadlinesChanged(wxCommandEvent &evt) { int channelIndex=m_channelsList.GetSelection(); int headlineIndex=m_headlinesList.GetSelection(); m_newsItem.SetPage((channelIndex>=0 && headlineIndex>=0) ? g_data.m_channels[channelIndex].m_headlines[headlineIndex].m_body); }
RULE("m_newsItem.Page", make_expr<wxString>("m_headlinesList.Current.m_body"))
ID_FRAME.Title = wxString("Headline: ")+m_headlinesList.Current.m_title
this->SetTitle(wxString("Headline: ")+g_data.m_channels[channelIndex].m_headlines[headlineIndex].m_title);
RULE("ID_FRAME.Title", make_const<wxString>("Headline: ")+make_expr<wxString>("m_channelsList.Current.m_title"))
BEGIN_RULES(g_rules) RULE("m_channelsList.Items", make_expr<accessor>("m_channels")) // listbox uses elements from m_channels RULE("m_channelsList.Column", make_const(string("m_title"))) // listbox displays "Channel::m_title" RULE("ID_FRAME.Title", make_const<wxString>("Headline: ")+make_expr<wxString>("m_channelsList.Current.m_title")) // the next rule connects the headlines listbox with the m_headlines // member of the currently selected channel RULE("m_headlinesList.Items", make_expr<accessor>("m_channelsList.Current.m_headlines")) // the following rule connects the content of the html window m_newsItem with // the body of the currently selected headline RULE("m_newsItem.Page", make_expr<wxString>("m_headlinesList.Current.m_body")) END_RULES()
Copyright 2004, Hajo Kirchhoff, Lit Window Productions