Wt examples  3.7.1
WtHome.C
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008 Emweb bv, Herent, 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 
43 WWidget *WtHome::example(const char *textKey, const std::string& sourceDir)
44 {
45  WContainerWidget *result = new WContainerWidget();
46  WText *w = new WText(tr(textKey), result);
47  w->setInternalPathEncoding(true);
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 
107  WAnimation animation(WAnimation::SlideInFromRight, WAnimation::EaseIn);
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 
160 WWidget *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 }
virtual WWidget * examples()
Definition: WtHome.C:97
A simple widget to visualise a set of example source files.
WWidget * helloWorldExample()
Definition: WtHome.C:52
WMenuItem * addTab(std::unique_ptr< WWidget > child, const WString &label, ContentLoading loadPolicy=ContentLoading::Lazy)
WWidget * linkSourceBrowser(const std::string &examplePath)
Definition: Home.C:200
virtual WWidget * sourceViewer(const std::string &internalPath)
Definition: WtHome.C:160
WWidget * chatExample()
Definition: WtHome.C:77
WWidget * homepageExample()
Definition: WtHome.C:62
Signal< int > & currentChanged()
WWidget * widgetGalleryExample()
Definition: WtHome.C:87
WWidget * composerExample()
Definition: WtHome.C:82
void setTransitionAnimation(const WAnimation &animation, bool autoReverse=false)
Definition: Home.h:23
WString tr(const char *key)
Definition: Home.C:421
WWidget * gitExample()
Definition: WtHome.C:72
virtual WWidget * createQuoteForm()
Definition: WtHome.C:151
Definition: Home.h:67
WWidget * example(const char *textKey, const std::string &sourceDir)
Definition: WtHome.C:43
WWidget * chartExample()
Definition: WtHome.C:57
WWidget * treeviewExample()
Definition: WtHome.C:67
void setInternalPathEnabled(const std::string &basePath="")
WApplication * createWtHomeApplication(const WEnvironment &env, Wt::Dbo::SqlConnectionPool *blogDb)
Definition: WtHome.C:170
WStackedWidget * contentsStack() const
void init()
Definition: Home.C:62
void setInternalPathEncoding(bool enabled)
WTabWidget * examplesMenu_
Definition: Home.h:89
WWidget * hangmanExample()
Definition: WtHome.C:92
WApplication * createWidget(const WEnvironment &env, SimpleChatServer &server)
Definition: simpleChat.C:145
std::string wtExamplePath_
Definition: WtHome.h:28
virtual void setPathComponent(const std::string &path)
void addLanguage(const Lang &l)
Definition: Home.h:86
virtual Wt::Signals::connection connect(WObject *target, WObject::Method method) override
virtual void addWidget(std::unique_ptr< WWidget > widget)
WtHome(const WEnvironment &env, Wt::Dbo::SqlConnectionPool &blogDb)
Definition: WtHome.C:27
WWidget * wrapView(WWidget *(WtHome::*createFunction)())
Definition: WtHome.C:165
Definition: WtHome.h:16
void googleAnalyticsLogger()
Definition: Home.C:426

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13