[ Lit Window Library at SourceForge ] [ Lit Window Productions Homepage ] [ wxWidgets Tips&Tricks ] [ wxVisualSetup ]
Create a new file data.h with the following content:
/* * Copyright 2004, Hajo Kirchhoff - Lit Window Productions, http://www.litwindow.com * This file is part of the Lit Window Library. All use of this material - copying * in full or part, including in other works, using in non-profit or for-profit work * and other uses - is governed by the licence contained in the Lit Window Library * distribution, file LICENCE.TXT * $Id: data.h,v 1.1.1.1 2004/10/04 06:41:13 hajokirchhoff Exp $ */ #pragma once #include <vector> #include "wx/datetime.h" using namespace std; struct Headline { wxString m_title; // the headline title wxString m_body; // the news in html wxDateTime m_published; // date/time when this headline was published string m_url; // an associated URL }; struct Channel { string m_webAddress; // url of the channel wxString m_title; // the title of this channel wxTimeSpan m_cacheExpires; // timespan between two refreshes vector<Headline> m_headlines; // the list of headlines wxDateTime m_lastRead; // date/time when this channel was last read }; struct RssReaderData { vector<Channel> m_channels; // store all channels wxTimeSpan m_refreshAfter; // timespan between two refreshes wxDateTime m_nextRefresh; // time of next refresh }; extern RssReaderData g_data;
g_data.
Add the following lines to the main source file simple_rssreader_app.cpp
#include "data.h"
RssReaderData g_data;
bool SimpleRssReader::OnInit() { wx_redirect.insert(lw_log()); // add a test channel and a test headline Headline firstHeadline; firstHeadline.m_title="The 1st headline"; firstHeadline.m_body="<p>This is some news!</p>"; Channel testChannel; testChannel.m_webAddress="http://www.litwindow.com/rss.xml"; testChannel.m_title="Testtitle"; testChannel.m_headlines.push_back(firstHeadline); g_data.m_channels.push_back(testChannel);
struct we have just defined. We need an adapter between the data structures and the RapidUI mechanism. These adapter definitions can go into any source file of your project. Put them into simple_rssreader_app.cpp for this tutorial.#include <litwindow/dataadapter.h>
BEGIN_ADAPTER(Headline)
PROP(m_title)
PROP(m_body)
PROP(m_published)
PROP(m_url)
END_ADAPTER()
BEGIN_ADAPTER(Channel)
PROP(m_webAddress)
PROP(m_title)
PROP(m_cacheExpires)
PROP(m_headlines)
PROP(m_lastRead)
END_ADAPTER()
BEGIN_ADAPTER(RssReaderData)
PROP(m_channels)
PROP(m_refreshAfter)
PROP(m_nextRefresh)
END_ADAPTER()
The adapter definition is just a very simple repetition of the struct declaration. BEGIN_ADAPTER(name) / END_ADAPTER encloses the list of the struct properties. To add a struct member to the adapter, simply add PROP(name) to the adapter.
Channel datatype uses a vector<Headline> to store all headlines for a channel and the global variable g_channels uses a vector<Channel> to store all channels. RapidUI does not know anything about these containers, so we need to add another adapter. IMPLEMENT_ADAPTER_CONTAINER(vector<Headline>) IMPLEMENT_ADAPTER_CONTAINER(vector<Channel>)
These data adapter definitions are the price you have to pay to be able to use the RapidUI mechanism. But its worth it, as you'll see in the next step.
Build the project.
Headline, Channel and RssData. struct Headline { wxString m_title; // the headline title wxString m_body; // the news in html wxDateTime m_published; // date/time when this headline was published string m_url; // an associated URL }; struct Channel { string m_webAddress; // url of the channel wxString m_title; // the title of this channel wxTimeSpan m_cacheExpires; // timespan between two refreshes vector<Headline> m_headlines; // the list of headlines wxDateTime m_lastRead; // date/time when this channel was last read }; struct RssReaderData { vector<Channel> m_channels; // store all channels wxTimeSpan m_refreshAfter; // timespan between two refreshes wxDateTime m_nextRefresh; // time of next refresh }; extern RssReaderData g_data;
Add data adapters for struct Headline, struct Channel and struct RssData:
BEGIN_ADAPTER(Headline)
PROP(m_title)
PROP(m_body)
PROP(m_published)
PROP(m_url)
END_ADAPTER()
BEGIN_ADAPTER(Channel)
PROP(m_webAddress)
PROP(m_title)
PROP(m_cacheExpires)
PROP(m_headlines)
PROP(m_lastRead)
END_ADAPTER()
BEGIN_ADAPTER(RssReaderData)
PROP(m_channels)
PROP(m_refreshAfter)
PROP(m_nextRefresh)
END_ADAPTER()
Continue with RSS Reader Tutorial Step 3: Adding RapidUI
Copyright 2004, Hajo Kirchhoff, Lit Window Productions