File: FormExample_8C-source.html

package info (click to toggle)
witty 3.1.2-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 45,512 kB
  • ctags: 35,832
  • sloc: cpp: 69,469; ansic: 66,945; xml: 4,383; sh: 594; perl: 108; makefile: 106
file content (115 lines) | stat: -rw-r--r-- 16,578 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Wt examples: /home/koen/project/wt/public-git/wt/examples/form/FormExample.C Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;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>
<h1>/home/koen/project/wt/public-git/wt/examples/form/FormExample.C</h1><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 &lt;Wt/WApplication&gt;</span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &lt;Wt/WText&gt;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;Wt/WStringUtil&gt;</span>
<a name="l00013"></a>00013 
<a name="l00014"></a><a class="code" href="classFormExample.html#06229101d94ff644080db3bdea52bfd3">00014</a> <a class="code" href="classFormExample.html#06229101d94ff644080db3bdea52bfd3" 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#520ba6e52a36a7f2efbef1a31a69e898">WContainerWidget</a>(<span class="keyword">this</span>);
<a name="l00018"></a>00018   langLayout-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WContainerWidget.html#ba13c9e62c74bcba53519ee9cf41f40a">setContentAlignment</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/namespaceWt.html#b8f772c69bc8180c31f9e4f4593b143fb250310385383f0b2f68d4e0ad5567e1">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#a651f107ec7cf080faef6c435705fc44">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 &lt; 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-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WWebWidget.html#07719d06da0dd17af2381c663e8fb0b7">setMargin</a>(5);
<a name="l00026"></a>00026     t-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WInteractWidget.html#e11e050cce0d4a8f742afa3ef92bfe8c">clicked</a>().connect(SLOT(<span class="keyword">this</span>, <a class="code" href="classFormExample.html#047867b2f3c5a749792469576773be65" title="Change the language.">FormExample::changeLanguage</a>));
<a name="l00027"></a>00027 
<a name="l00028"></a>00028     <a class="code" href="classFormExample.html#d2cb9b1cfa26199a58f5635671fbb018">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#6958d8310fa5d3c1fa2172ca867e1e50">setLanguage</a>(wApp-&gt;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-&gt;setMargin(20);
<a name="l00038"></a>00038 }
<a name="l00039"></a>00039 
<a name="l00040"></a><a class="code" href="classFormExample.html#6958d8310fa5d3c1fa2172ca867e1e50">00040</a> <span class="keywordtype">void</span> <a class="code" href="classFormExample.html#6958d8310fa5d3c1fa2172ca867e1e50">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 &lt; <a class="code" href="classFormExample.html#d2cb9b1cfa26199a58f5635671fbb018">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#d2cb9b1cfa26199a58f5635671fbb018">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-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WText.html#1081f42ae498fa8d23656cec207a4a76">text</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WString.html#b76d45947986f8aa20763cf99267ec23">value</a>())) == 0;
<a name="l00049"></a>00049     t-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WWebWidget.html#6fd43dced1a62f7e79bc3522eeb16216">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#d2cb9b1cfa26199a58f5635671fbb018">languageSelects_</a>[0]-&gt;setStyleClass(L<span class="stringliteral">"langcurrent"</span>);
<a name="l00056"></a>00056     WApplication::instance()
<a name="l00057"></a>00057       -&gt;setLocale(narrow(<a class="code" href="classFormExample.html#d2cb9b1cfa26199a58f5635671fbb018">languageSelects_</a>[0]-&gt;text().value()));
<a name="l00058"></a>00058   } <span class="keywordflow">else</span>
<a name="l00059"></a>00059     WApplication::instance()-&gt;setLocale(lang);
<a name="l00060"></a>00060 }
<a name="l00061"></a>00061 
<a name="l00062"></a><a class="code" href="classFormExample.html#047867b2f3c5a749792469576773be65">00062</a> <span class="keywordtype">void</span> <a class="code" href="classFormExample.html#047867b2f3c5a749792469576773be65" 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#413deb54de40ee278dd554e4960d58ca">sender</a>();
<a name="l00065"></a>00065   <a class="code" href="classFormExample.html#6958d8310fa5d3c1fa2172ca867e1e50">setLanguage</a>(narrow(t-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WText.html#1081f42ae498fa8d23656cec207a4a76">text</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WString.html#b76d45947986f8aa20763cf99267ec23">value</a>()));
<a name="l00066"></a>00066 }
<a name="l00067"></a>00067 
<a name="l00068"></a><a class="code" href="FormExample_8C.html#cb337c09cd35644b56da8b0e5bb17b9c">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#cb337c09cd35644b56da8b0e5bb17b9c">createApplication</a>(<span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WEnvironment.html">WEnvironment</a>&amp; 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-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WApplication.html#5386565e35a58c94ccbbfab48f2212a4">messageResourceBundle</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WMessageResourceBundle.html#01368946b2a2aaceab3a64cddb1cb1e2">use</a>(<span class="stringliteral">"form-example"</span>);
<a name="l00072"></a>00072   app-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WApplication.html#71a3f7da5abb9a76df94fab69ba61670">setTitle</a>(<span class="stringliteral">"Form example"</span>);
<a name="l00073"></a>00073 
<a name="l00074"></a>00074   app-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WApplication.html#17e118a04d962459484a12989a80bc05">root</a>()-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WContainerWidget.html#2cfe66d9b62940f889e99538a9f478d2">addWidget</a>(<span class="keyword">new</span> <a class="code" href="classFormExample.html#06229101d94ff644080db3bdea52bfd3" title="Instantiate a new 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#5e552350f0955212ea237994a98638dc">font</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WFont.html#d449c8c5c3b78e66d51fe6db0c0b9d58">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#fa12d38e05ad171e9ec718e7ae0d7b70">setCursor</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/namespaceWt.html#6dc0346a6ae888d6d4ab44f022e61eb6f860d39b9a2ba8f7d7359453bf15a37c">PointingHandCursor</a>);
<a name="l00079"></a>00079   langStyle.<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WCssDecorationStyle.html#986681e0391d09bdf7f82d0cf283ae86">setForegroundColor</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/group__style.html#gg9686ea88ce4db2c0a12ea84452f601330cb88ce2189a8986f24a4409498e490e">blue</a>);
<a name="l00080"></a>00080   langStyle.<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WCssDecorationStyle.html#e30cbd3f4306be25434c89f269551904">setTextDecoration</a>(WCssDecorationStyle::Underline);
<a name="l00081"></a>00081   app-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WApplication.html#6a9a20d65ce9e7c2f62b27387c94e10d">styleSheet</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WCssStyleSheet.html#d2c989b38a7ee084a7c9b681e16e8a8c">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#fa12d38e05ad171e9ec718e7ae0d7b70">setCursor</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/namespaceWt.html#6dc0346a6ae888d6d4ab44f022e61eb6b8be050ebabfd528fce3c8b4ce972088">ArrowCursor</a>);
<a name="l00084"></a>00084   langStyle.<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WCssDecorationStyle.html#5e552350f0955212ea237994a98638dc">font</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WFont.html#c27d9f5d3a23115e3881a2d0ac9cb771">setWeight</a>(WFont::Bold);
<a name="l00085"></a>00085   app-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WApplication.html#6a9a20d65ce9e7c2f62b27387c94e10d">styleSheet</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html/" href="../../reference/html/classWt_1_1WCssStyleSheet.html#d2c989b38a7ee084a7c9b681e16e8a8c">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#3c04138a5bfe5d72780bb7e82a18e627">00090</a> <span class="keywordtype">int</span> <a class="code" href="ComposeExample_8C.html#3c04138a5bfe5d72780bb7e82a18e627">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, &amp;<a class="code" href="ComposeExample_8C.html#cb337c09cd35644b56da8b0e5bb17b9c">createApplication</a>);
<a name="l00093"></a>00093 }
<a name="l00094"></a>00094 
</pre></div></div>
<hr size="1"><address style="align: right;"><small>
Generated on Fri Mar 26 17:12:12 2010 for <a href="http://www.webtoolkit.eu/wt/">Wt</a> by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6</small></address>
</body>
</html>