|
Wt examples
3.3.5
|
00001 /* 00002 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium. 00003 * 00004 * See the LICENSE file for terms of use. 00005 */ 00006 00007 #include "WtHome.h" 00008 00009 #ifdef WT_EMWEB_BUILD 00010 #include "QuoteForm.h" 00011 #endif // WT_EMWEB_BUILD 00012 00013 #include <Wt/WAnchor> 00014 #include <Wt/WEnvironment> 00015 #include <Wt/WLogger> 00016 #include <Wt/WMenuItem> 00017 #include <Wt/WStackedWidget> 00018 #include <Wt/WTable> 00019 #include <Wt/WTabWidget> 00020 #include <Wt/WText> 00021 #include <Wt/WTreeNode> 00022 #include <Wt/WViewWidget> 00023 #include <Wt/WWidget> 00024 00025 #include "ExampleSourceViewer.h" 00026 00027 WtHome::WtHome(const WEnvironment& env, Wt::Dbo::SqlConnectionPool& blogDb) 00028 : Home(env, blogDb, "Wt, C++ Web Toolkit", "wt-home", "css/wt") 00029 { 00030 addLanguage(Lang("en", "/", "en", "English")); 00031 addLanguage(Lang("cn", "/cn/", "汉语", "中文 (Chinese)")); 00032 addLanguage(Lang("ru", "/ru/", "ру", "Русский (Russian)")); 00033 00034 char* wtExamplePath = getenv("WT_EXAMPLE_PATH"); 00035 if (wtExamplePath) 00036 wtExamplePath_ = wtExamplePath; 00037 else 00038 wtExamplePath_ = ".."; 00039 00040 init(); 00041 } 00042 00043 WWidget *WtHome::example(const char *textKey, const std::string& sourceDir) 00044 { 00045 WContainerWidget *result = new WContainerWidget(); 00046 WText *w = new WText(tr(textKey), result); 00047 w->setInternalPathEncoding(true); 00048 result->addWidget(linkSourceBrowser(sourceDir)); 00049 return result; 00050 } 00051 00052 WWidget *WtHome::helloWorldExample() 00053 { 00054 return example("home.examples.hello", "hello"); 00055 } 00056 00057 WWidget *WtHome::chartExample() 00058 { 00059 return example("home.examples.chart", "charts"); 00060 } 00061 00062 WWidget *WtHome::homepageExample() 00063 { 00064 return example("home.examples.wt", "wt-homepage"); 00065 } 00066 00067 WWidget *WtHome::treeviewExample() 00068 { 00069 return example("home.examples.treeview", "treeview-dragdrop"); 00070 } 00071 00072 WWidget *WtHome::gitExample() 00073 { 00074 return example("home.examples.git", "gitmodel"); 00075 } 00076 00077 WWidget *WtHome::chatExample() 00078 { 00079 return example("home.examples.chat", "simplechat"); 00080 } 00081 00082 WWidget *WtHome::composerExample() 00083 { 00084 return example("home.examples.composer", "composer"); 00085 } 00086 00087 WWidget *WtHome::widgetGalleryExample() 00088 { 00089 return example("home.examples.widgetgallery", "widgetgallery"); 00090 } 00091 00092 WWidget *WtHome::hangmanExample() 00093 { 00094 return example("home.examples.hangman", "hangman"); 00095 } 00096 00097 WWidget *WtHome::examples() 00098 { 00099 WContainerWidget *result = new WContainerWidget(); 00100 00101 WText *intro = new WText(tr("home.examples")); 00102 intro->setInternalPathEncoding(true); 00103 result->addWidget(intro); 00104 00105 examplesMenu_ = new WTabWidget(result); 00106 00107 WAnimation animation(WAnimation::SlideInFromRight, WAnimation::EaseIn); 00108 examplesMenu_->contentsStack()->setTransitionAnimation(animation, true); 00109 00110 /* 00111 * The following code is functionally equivalent to: 00112 * 00113 * examplesMenu_->addTab(helloWorldExample(), "Hello world"); 00114 * 00115 * However, we optimize here for memory consumption (it is a homepage 00116 * after all, and we hope to be slashdotted some day) 00117 * 00118 * Therefore, we wrap all the static content (including the tree 00119 * widgets), into WViewWidgets with static models. In this way the 00120 * widgets are not actually stored in memory on the server. 00121 */ 00122 00123 // The call ->setPathComponent() is to use "/examples/" instead of 00124 // "/examples/hello_world" as internal path 00125 examplesMenu_->addTab(wrapView(&WtHome::helloWorldExample), 00126 tr("hello-world"))->setPathComponent(""); 00127 examplesMenu_->addTab(wrapView(&WtHome::widgetGalleryExample), 00128 tr("widget-gallery")); 00129 examplesMenu_->addTab(wrapView(&WtHome::chartExample), 00130 tr("charts")); 00131 examplesMenu_->addTab(wrapView(&WtHome::homepageExample), 00132 tr("wt-homepage")); 00133 examplesMenu_->addTab(wrapView(&WtHome::treeviewExample), 00134 tr("treeview")); 00135 examplesMenu_->addTab(wrapView(&WtHome::gitExample), 00136 tr("git")); 00137 examplesMenu_->addTab(wrapView(&WtHome::chatExample), 00138 tr("chat")); 00139 examplesMenu_->addTab(wrapView(&WtHome::composerExample), 00140 tr("mail-composer")); 00141 examplesMenu_->addTab(wrapView(&WtHome::hangmanExample), 00142 tr("hangman")); 00143 00144 // Enable internal paths for the example menu 00145 examplesMenu_->setInternalPathEnabled("/examples"); 00146 examplesMenu_->currentChanged().connect(this, &Home::googleAnalyticsLogger); 00147 00148 return result; 00149 } 00150 00151 WWidget *WtHome::createQuoteForm() 00152 { 00153 #ifdef WT_EMWEB_BUILD 00154 return new QuoteForm(QuoteForm::Wt); 00155 #else 00156 return 0; 00157 #endif 00158 } 00159 00160 WWidget *WtHome::sourceViewer(const std::string& deployPath) 00161 { 00162 return new ExampleSourceViewer(deployPath, wtExamplePath_ + "/", "CPP"); 00163 } 00164 00165 WWidget *WtHome::wrapView(WWidget *(WtHome::*createWidget)()) 00166 { 00167 return makeStaticModel(boost::bind(createWidget, this)); 00168 } 00169 00170 WApplication *createWtHomeApplication(const WEnvironment& env, 00171 Wt::Dbo::SqlConnectionPool *blogDb) 00172 { 00173 return new WtHome(env, *blogDb); 00174 }
1.7.6.1