<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>Wt examples: /home/koen/project/wt/public-git/wt/examples/form/FormExample.C Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">Wt examples  <span id="projectnumber">3.2.3</span> </div> </td> </tr> </tbody> </table> </div> <!-- Generated by Doxygen 1.7.5.1 --> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="header"> <div class="headertitle"> <div class="title">/home/koen/project/wt/public-git/wt/examples/form/FormExample.C</div> </div> </div> <div class="contents"> <a href="FormExample_8C.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.</span> <a name="l00003"></a>00003 <span class="comment"> *</span> <a name="l00004"></a>00004 <span class="comment"> * See the LICENSE file for terms of use.</span> <a name="l00005"></a>00005 <span class="comment"> */</span> <a name="l00006"></a>00006 <a name="l00007"></a>00007 <span class="preprocessor">#include "<a class="code" href="FormExample_8h.html">FormExample.h</a>"</span> <a name="l00008"></a>00008 <span class="preprocessor">#include "<a class="code" href="Form_8h.html">Form.h</a>"</span> <a name="l00009"></a>00009 <a name="l00010"></a>00010 <span class="preprocessor">#include <Wt/WApplication></span> <a name="l00011"></a>00011 <span class="preprocessor">#include <Wt/WText></span> <a name="l00012"></a>00012 <span class="preprocessor">#include <Wt/WStringUtil></span> <a name="l00013"></a>00013 <a name="l00014"></a><a class="code" href="classFormExample.html#a06229101d94ff644080db3bdea52bfd3">00014</a> <a class="code" href="classFormExample.html#a06229101d94ff644080db3bdea52bfd3" title="Instantiate a new form example.">FormExample::FormExample</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html">WContainerWidget</a> *parent) <a name="l00015"></a>00015 : <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html">WContainerWidget</a>(parent) <a name="l00016"></a>00016 { <a name="l00017"></a>00017 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html">WContainerWidget</a> *langLayout = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html#a520ba6e52a36a7f2efbef1a31a69e898">WContainerWidget</a>(<span class="keyword">this</span>); <a name="l00018"></a>00018 langLayout-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html#aba13c9e62c74bcba53519ee9cf41f40a">setContentAlignment</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#ab8f772c69bc8180c31f9e4f4593b143fab250310385383f0b2f68d4e0ad5567e1">AlignRight</a>); <a name="l00019"></a>00019 <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html">WText</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#aa651f107ec7cf080faef6c435705fc44">tr</a>(<span class="stringliteral">"language"</span>), langLayout); <a name="l00020"></a>00020 <a name="l00021"></a>00021 <span class="keyword">const</span> <span class="keywordtype">char</span> *lang[] = { <span class="stringliteral">"en"</span>, <span class="stringliteral">"nl"</span> }; <a name="l00022"></a>00022 <a name="l00023"></a>00023 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < 2; ++i) { <a name="l00024"></a>00024 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html">WText</a> *t = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html">WText</a>(widen(lang[i]), langLayout); <a name="l00025"></a>00025 t-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#a9795c18e926b26b97fcbabc62a1dd4e3">setMargin</a>(5); <a name="l00026"></a>00026 t-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WInteractWidget.html#ae11e050cce0d4a8f742afa3ef92bfe8c">clicked</a>().connect(<span class="keyword">this</span>, &<a class="code" href="classFormExample.html#a047867b2f3c5a749792469576773be65" title="Change the language.">FormExample::changeLanguage</a>); <a name="l00027"></a>00027 <a name="l00028"></a>00028 <a class="code" href="classFormExample.html#ad2cb9b1cfa26199a58f5635671fbb018">languageSelects_</a>.push_back(t); <a name="l00029"></a>00029 } <a name="l00030"></a>00030 <a name="l00031"></a>00031 <span class="comment">/*</span> <a name="l00032"></a>00032 <span class="comment"> * Start with the reported locale, if available</span> <a name="l00033"></a>00033 <span class="comment"> */</span> <a name="l00034"></a>00034 <a class="code" href="classFormExample.html#a6958d8310fa5d3c1fa2172ca867e1e50">setLanguage</a>(wApp->locale()); <a name="l00035"></a>00035 <a name="l00036"></a>00036 <a class="code" href="classForm.html" title="A simple Form.">Form</a> *form = <span class="keyword">new</span> <a class="code" href="classForm.html" title="A simple Form.">Form</a>(<span class="keyword">this</span>); <a name="l00037"></a>00037 form->setMargin(20); <a name="l00038"></a>00038 } <a name="l00039"></a>00039 <a name="l00040"></a><a class="code" href="classFormExample.html#a6958d8310fa5d3c1fa2172ca867e1e50">00040</a> <span class="keywordtype">void</span> <a class="code" href="classFormExample.html#a6958d8310fa5d3c1fa2172ca867e1e50">FormExample::setLanguage</a>(<span class="keyword">const</span> std::string lang) <a name="l00041"></a>00041 { <a name="l00042"></a>00042 <span class="keywordtype">bool</span> haveLang = <span class="keyword">false</span>; <a name="l00043"></a>00043 <a name="l00044"></a>00044 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i < <a class="code" href="classFormExample.html#ad2cb9b1cfa26199a58f5635671fbb018">languageSelects_</a>.size(); ++i) { <a name="l00045"></a>00045 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html">WText</a> *t = <a class="code" href="classFormExample.html#ad2cb9b1cfa26199a58f5635671fbb018">languageSelects_</a>[i]; <a name="l00046"></a>00046 <a name="l00047"></a>00047 <span class="comment">// prefix match, e.g. en matches en-us.</span> <a name="l00048"></a>00048 <span class="keywordtype">bool</span> isLang = lang.find(narrow(t-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html#a1081f42ae498fa8d23656cec207a4a76">text</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html#ab76d45947986f8aa20763cf99267ec23">value</a>())) == 0; <a name="l00049"></a>00049 t-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#afd3a3b359681111460a93d13979d17dd">setStyleClass</a>(isLang ? L<span class="stringliteral">"langcurrent"</span> : L<span class="stringliteral">"lang"</span>); <a name="l00050"></a>00050 <a name="l00051"></a>00051 haveLang = haveLang || isLang; <a name="l00052"></a>00052 } <a name="l00053"></a>00053 <a name="l00054"></a>00054 <span class="keywordflow">if</span> (!haveLang) { <a name="l00055"></a>00055 <a class="code" href="classFormExample.html#ad2cb9b1cfa26199a58f5635671fbb018">languageSelects_</a>[0]->setStyleClass(L<span class="stringliteral">"langcurrent"</span>); <a name="l00056"></a>00056 WApplication::instance() <a name="l00057"></a>00057 ->setLocale(narrow(<a class="code" href="classFormExample.html#ad2cb9b1cfa26199a58f5635671fbb018">languageSelects_</a>[0]->text().value())); <a name="l00058"></a>00058 } <span class="keywordflow">else</span> <a name="l00059"></a>00059 WApplication::instance()->setLocale(lang); <a name="l00060"></a>00060 } <a name="l00061"></a>00061 <a name="l00062"></a><a class="code" href="classFormExample.html#a047867b2f3c5a749792469576773be65">00062</a> <span class="keywordtype">void</span> <a class="code" href="classFormExample.html#a047867b2f3c5a749792469576773be65" title="Change the language.">FormExample::changeLanguage</a>() <a name="l00063"></a>00063 { <a name="l00064"></a>00064 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html">WText</a> *t = (<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html">WText</a> *)<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WObject.html#a413deb54de40ee278dd554e4960d58ca">sender</a>(); <a name="l00065"></a>00065 <a class="code" href="classFormExample.html#a6958d8310fa5d3c1fa2172ca867e1e50">setLanguage</a>(narrow(t-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html#a1081f42ae498fa8d23656cec207a4a76">text</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html#ab76d45947986f8aa20763cf99267ec23">value</a>())); <a name="l00066"></a>00066 } <a name="l00067"></a>00067 <a name="l00068"></a><a class="code" href="FormExample_8C.html#acb337c09cd35644b56da8b0e5bb17b9c">00068</a> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html">WApplication</a> *<a class="code" href="ComposeExample_8C.html#acb337c09cd35644b56da8b0e5bb17b9c">createApplication</a>(<span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WEnvironment.html">WEnvironment</a>& env) <a name="l00069"></a>00069 { <a name="l00070"></a>00070 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html">WApplication</a> *app = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html">WApplication</a>(env); <a name="l00071"></a>00071 app-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#a4f304244f6bc75be6cd5f41798ea5e2e">messageResourceBundle</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WMessageResourceBundle.html#a01368946b2a2aaceab3a64cddb1cb1e2">use</a>(WApplication::appRoot() + <span class="stringliteral">"form-example"</span>); <a name="l00072"></a>00072 app-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#a71a3f7da5abb9a76df94fab69ba61670">setTitle</a>(<span class="stringliteral">"Form example"</span>); <a name="l00073"></a>00073 <a name="l00074"></a>00074 app-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#a17e118a04d962459484a12989a80bc05">root</a>()-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html#a2cfe66d9b62940f889e99538a9f478d2">addWidget</a>(<span class="keyword">new</span> <a class="code" href="classFormExample.html" title="Main widget for the Form example.">FormExample</a>()); <a name="l00075"></a>00075 <a name="l00076"></a>00076 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WCssDecorationStyle.html">WCssDecorationStyle</a> langStyle; <a name="l00077"></a>00077 langStyle.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WCssDecorationStyle.html#a5e552350f0955212ea237994a98638dc">font</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFont.html#ab67fd247c1541c18a6b97f41007e5f4b">setSize</a>(WFont::Smaller); <a name="l00078"></a>00078 langStyle.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WCssDecorationStyle.html#afa12d38e05ad171e9ec718e7ae0d7b70">setCursor</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#a6dc0346a6ae888d6d4ab44f022e61eb6af860d39b9a2ba8f7d7359453bf15a37c">PointingHandCursor</a>); <a name="l00079"></a>00079 langStyle.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WCssDecorationStyle.html#a986681e0391d09bdf7f82d0cf283ae86">setForegroundColor</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/group__style.html#gga9686ea88ce4db2c0a12ea84452f60133a0cb88ce2189a8986f24a4409498e490e">blue</a>); <a name="l00080"></a>00080 langStyle.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WCssDecorationStyle.html#ae30cbd3f4306be25434c89f269551904">setTextDecoration</a>(WCssDecorationStyle::Underline); <a name="l00081"></a>00081 app-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#a6a9a20d65ce9e7c2f62b27387c94e10d">styleSheet</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WCssStyleSheet.html#ad2c989b38a7ee084a7c9b681e16e8a8c">addRule</a>(<span class="stringliteral">".lang"</span>, langStyle); <a name="l00082"></a>00082 <a name="l00083"></a>00083 langStyle.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WCssDecorationStyle.html#afa12d38e05ad171e9ec718e7ae0d7b70">setCursor</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#a6dc0346a6ae888d6d4ab44f022e61eb6ab8be050ebabfd528fce3c8b4ce972088">ArrowCursor</a>); <a name="l00084"></a>00084 langStyle.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WCssDecorationStyle.html#a5e552350f0955212ea237994a98638dc">font</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFont.html#ac27d9f5d3a23115e3881a2d0ac9cb771">setWeight</a>(WFont::Bold); <a name="l00085"></a>00085 app-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#a6a9a20d65ce9e7c2f62b27387c94e10d">styleSheet</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WCssStyleSheet.html#ad2c989b38a7ee084a7c9b681e16e8a8c">addRule</a>(<span class="stringliteral">".langcurrent"</span>, langStyle); <a name="l00086"></a>00086 <a name="l00087"></a>00087 <span class="keywordflow">return</span> app; <a name="l00088"></a>00088 } <a name="l00089"></a>00089 <a name="l00090"></a><a class="code" href="FormExample_8C.html#a3c04138a5bfe5d72780bb7e82a18e627">00090</a> <span class="keywordtype">int</span> <a class="code" href="ComposeExample_8C.html#a3c04138a5bfe5d72780bb7e82a18e627">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv) <a name="l00091"></a>00091 { <a name="l00092"></a>00092 <span class="keywordflow">return</span> WRun(argc, argv, &<a class="code" href="ComposeExample_8C.html#acb337c09cd35644b56da8b0e5bb17b9c">createApplication</a>); <a name="l00093"></a>00093 } <a name="l00094"></a>00094 </pre></div></div> </div> <hr size="1"><address style="text-align: right; margin: 3px"><small> Generated on Thu Nov 1 2012 for <a href="http://www.webtoolkit.eu/wt">the C++ Web Toolkit (Wt)</a> by <a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" border="0" style="vertical-align: middle; display: inline-block; height: 2em"></a> 1.7.5.1</small></address> </body> </html>