Wt examples
3.3.1
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
koen
project
wt
public-git
wt
examples
wt-homepage
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
27
WtHome::WtHome
(
const
WEnvironment
& env,
Wt::Dbo::SqlConnectionPool
& blogDb)
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
52
WWidget
*
WtHome::helloWorldExample
()
53
{
54
return
example
(
"home.examples.hello"
,
"hello"
);
55
}
56
57
WWidget
*
WtHome::chartExample
()
58
{
59
return
example
(
"home.examples.chart"
,
"charts"
);
60
}
61
62
WWidget
*
WtHome::homepageExample
()
63
{
64
return
example
(
"home.examples.wt"
,
"wt-homepage"
);
65
}
66
67
WWidget
*
WtHome::treeviewExample
()
68
{
69
return
example
(
"home.examples.treeview"
,
"treeview-dragdrop"
);
70
}
71
72
WWidget
*
WtHome::gitExample
()
73
{
74
return
example
(
"home.examples.git"
,
"gitmodel"
);
75
}
76
77
WWidget
*
WtHome::chatExample
()
78
{
79
return
example
(
"home.examples.chat"
,
"simplechat"
);
80
}
81
82
WWidget
*
WtHome::composerExample
()
83
{
84
return
example
(
"home.examples.composer"
,
"composer"
);
85
}
86
87
WWidget
*
WtHome::widgetGalleryExample
()
88
{
89
return
example
(
"home.examples.widgetgallery"
,
"widgetgallery"
);
90
}
91
92
WWidget
*
WtHome::hangmanExample
()
93
{
94
return
example
(
"home.examples.hangman"
,
"hangman"
);
95
}
96
97
WWidget
*
WtHome::examples
()
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);
108
examplesMenu_
->
contentsStack
()->
setTransitionAnimation
(animation,
true
);
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
125
examplesMenu_
->
addTab
(
wrapView
(&
WtHome::helloWorldExample
),
126
tr
(
"hello-world"
))->
setPathComponent
(
""
);
127
examplesMenu_
->
addTab
(
wrapView
(&
WtHome::widgetGalleryExample
),
128
tr
(
"widget-gallery"
));
129
examplesMenu_
->
addTab
(
wrapView
(&
WtHome::chartExample
),
130
tr
(
"charts"
));
131
examplesMenu_
->
addTab
(
wrapView
(&
WtHome::homepageExample
),
132
tr
(
"wt-homepage"
));
133
examplesMenu_
->
addTab
(
wrapView
(&
WtHome::treeviewExample
),
134
tr
(
"treeview"
));
135
examplesMenu_
->
addTab
(
wrapView
(&
WtHome::gitExample
),
136
tr
(
"git"
));
137
examplesMenu_
->
addTab
(
wrapView
(&
WtHome::chatExample
),
138
tr
(
"chat"
));
139
examplesMenu_
->
addTab
(
wrapView
(&
WtHome::composerExample
),
140
tr
(
"mail-composer"
));
141
examplesMenu_
->
addTab
(
wrapView
(&
WtHome::hangmanExample
),
142
tr
(
"hangman"
));
143
144
// Enable internal paths for the example menu
145
examplesMenu_
->
setInternalPathEnabled
(
"/examples"
);
146
examplesMenu_
->
currentChanged
().
connect
(
this
, &
Home::googleAnalyticsLogger
);
147
148
return
result;
149
}
150
151
WWidget
*
WtHome::createQuoteForm
()
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
165
WWidget
*
WtHome::wrapView
(
WWidget
*(
WtHome
::*
createWidget
)())
166
{
167
return
makeStaticModel(boost::bind(createWidget,
this
));
168
}
169
170
WApplication
*
createWtHomeApplication
(
const
WEnvironment
& env,
171
Wt::Dbo::SqlConnectionPool
*blogDb)
172
{
173
return
new
WtHome
(env, *blogDb);
174
}
Generated on Tue Aug 20 2013 for
the C++ Web Toolkit (Wt)
by
1.8.4