Wt examples 3.3.12
WtHome.C
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
3 *
4 * See the LICENSE file for terms of use.
5 */
6
7#include "WtHome.h"
8
9#ifdef WT_EMWEB_BUILD
10#include "QuoteForm.h"
11#endif // WT_EMWEB_BUILD
12
13#include <Wt/WAnchor>
14#include <Wt/WEnvironment>
15#include <Wt/WLogger>
16#include <Wt/WMenuItem>
17#include <Wt/WStackedWidget>
18#include <Wt/WTable>
19#include <Wt/WTabWidget>
20#include <Wt/WText>
21#include <Wt/WTreeNode>
22#include <Wt/WViewWidget>
23#include <Wt/WWidget>
24
25#include "ExampleSourceViewer.h"
26
28 : Home(env, blogDb, "Wt, C++ Web Toolkit", "wt-home", "css/wt")
29{
30 addLanguage(Lang("en", "/", "en", "English"));
31 addLanguage(Lang("cn", "/cn/", "汉语", "中文 (Chinese)"));
32 addLanguage(Lang("ru", "/ru/", "ру", "Русский (Russian)"));
33
34 char* wtExamplePath = getenv("WT_EXAMPLE_PATH");
35 if (wtExamplePath)
36 wtExamplePath_ = wtExamplePath;
37 else
38 wtExamplePath_ = "..";
39
40 init();
41}
42
43WWidget *WtHome::example(const char *textKey, const std::string& sourceDir)
44{
45 WContainerWidget *result = new WContainerWidget();
46 WText *w = new WText(tr(textKey), result);
48 result->addWidget(linkSourceBrowser(sourceDir));
49 return result;
50}
51
53{
54 return example("home.examples.hello", "hello");
55}
56
58{
59 return example("home.examples.chart", "charts");
60}
61
63{
64 return example("home.examples.wt", "wt-homepage");
65}
66
68{
69 return example("home.examples.treeview", "treeview-dragdrop");
70}
71
73{
74 return example("home.examples.git", "gitmodel");
75}
76
78{
79 return example("home.examples.chat", "simplechat");
80}
81
83{
84 return example("home.examples.composer", "composer");
85}
86
88{
89 return example("home.examples.widgetgallery", "widgetgallery");
90}
91
93{
94 return example("home.examples.hangman", "hangman");
95}
96
98{
99 WContainerWidget *result = new WContainerWidget();
100
101 WText *intro = new WText(tr("home.examples"));
102 intro->setInternalPathEncoding(true);
103 result->addWidget(intro);
104
105 examplesMenu_ = new WTabWidget(result);
106
109
110 /*
111 * The following code is functionally equivalent to:
112 *
113 * examplesMenu_->addTab(helloWorldExample(), "Hello world");
114 *
115 * However, we optimize here for memory consumption (it is a homepage
116 * after all, and we hope to be slashdotted some day)
117 *
118 * Therefore, we wrap all the static content (including the tree
119 * widgets), into WViewWidgets with static models. In this way the
120 * widgets are not actually stored in memory on the server.
121 */
122
123 // The call ->setPathComponent() is to use "/examples/" instead of
124 // "/examples/hello_world" as internal path
126 tr("hello-world"))->setPathComponent("");
128 tr("widget-gallery"));
130 tr("charts"));
132 tr("wt-homepage"));
134 tr("treeview"));
136 tr("git"));
138 tr("chat"));
140 tr("mail-composer"));
142 tr("hangman"));
143
144 // Enable internal paths for the example menu
147
148 return result;
149}
150
152{
153#ifdef WT_EMWEB_BUILD
154 return new QuoteForm(QuoteForm::Wt);
155#else
156 return 0;
157#endif
158}
159
160WWidget *WtHome::sourceViewer(const std::string& deployPath)
161{
162 return new ExampleSourceViewer(deployPath, wtExamplePath_ + "/", "CPP");
163}
164
166{
167 return makeStaticModel(boost::bind(createWidget, this));
168}
169
172{
173 return new WtHome(env, *blogDb);
174}
WApplication * createWtHomeApplication(const WEnvironment &env, Wt::Dbo::SqlConnectionPool *blogDb)
Definition WtHome.C:170
A simple widget to visualise a set of example source files.
Definition Home.h:68
void addLanguage(const Lang &l)
Definition Home.h:86
WTabWidget * examplesMenu_
Definition Home.h:89
void googleAnalyticsLogger()
Definition Home.C:426
void init()
Definition Home.C:62
WWidget * linkSourceBrowser(const std::string &examplePath)
Definition Home.C:200
WString tr(const char *key)
Definition Home.C:421
virtual WWidget * createQuoteForm()
Definition WtHome.C:151
WWidget * example(const char *textKey, const std::string &sourceDir)
Definition WtHome.C:43
WWidget * homepageExample()
Definition WtHome.C:62
WWidget * chatExample()
Definition WtHome.C:77
virtual WWidget * examples()
Definition WtHome.C:97
WWidget * wrapView(WWidget *(WtHome::*createFunction)())
Definition WtHome.C:165
WtHome(const WEnvironment &env, Wt::Dbo::SqlConnectionPool &blogDb)
Definition WtHome.C:27
WWidget * helloWorldExample()
Definition WtHome.C:52
virtual WWidget * sourceViewer(const std::string &internalPath)
Definition WtHome.C:160
WWidget * treeviewExample()
Definition WtHome.C:67
WWidget * chartExample()
Definition WtHome.C:57
WWidget * gitExample()
Definition WtHome.C:72
std::string wtExamplePath_
Definition WtHome.h:28
WWidget * hangmanExample()
Definition WtHome.C:92
WWidget * widgetGalleryExample()
Definition WtHome.C:87
WWidget * composerExample()
Definition WtHome.C:82
virtual Wt::Signals::connection connect(WObject *target, WObject::Method method)
virtual void addWidget(WWidget *widget)
virtual void setPathComponent(const std::string &path)
void setTransitionAnimation(const WAnimation &animation, bool autoReverse=false)
void setInternalPathEnabled(const std::string &basePath="")
WMenuItem * addTab(WWidget *child, const WString &label, LoadPolicy=LazyLoading)
Signal< int > & currentChanged()
WStackedWidget * contentsStack() const
void setInternalPathEncoding(bool enabled)
WApplication * createWidget(const WEnvironment &env, SimpleChatServer &server)
Definition simpleChat.C:145
Definition Home.h:23

Generated on Fri May 17 2024 for the C++ Web Toolkit (Wt) by doxygen 1.9.8