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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
|
<!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/simplechat/SimpleChatWidget.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.1</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/simplechat/SimpleChatWidget.C</div> </div>
</div>
<div class="contents">
<a href="SimpleChatWidget_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, Heverlee, 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="SimpleChatWidget_8h.html">SimpleChatWidget.h</a>"</span>
<a name="l00008"></a>00008 <span class="preprocessor">#include "<a class="code" href="SimpleChatServer_8h.html">SimpleChatServer.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/WContainerWidget></span>
<a name="l00012"></a>00012 <span class="preprocessor">#include <Wt/WEnvironment></span>
<a name="l00013"></a>00013 <span class="preprocessor">#include <Wt/WHBoxLayout></span>
<a name="l00014"></a>00014 <span class="preprocessor">#include <Wt/WVBoxLayout></span>
<a name="l00015"></a>00015 <span class="preprocessor">#include <Wt/WLabel></span>
<a name="l00016"></a>00016 <span class="preprocessor">#include <Wt/WLineEdit></span>
<a name="l00017"></a>00017 <span class="preprocessor">#include <Wt/WText></span>
<a name="l00018"></a>00018 <span class="preprocessor">#include <Wt/WTextArea></span>
<a name="l00019"></a>00019 <span class="preprocessor">#include <Wt/WPushButton></span>
<a name="l00020"></a>00020 <span class="preprocessor">#include <Wt/WCheckBox></span>
<a name="l00021"></a>00021
<a name="l00022"></a>00022 <span class="preprocessor">#include <iostream></span>
<a name="l00023"></a>00023
<a name="l00024"></a>00024 <span class="keyword">using namespace </span>Wt;
<a name="l00025"></a>00025
<a name="l00026"></a><a class="code" href="classSimpleChatWidget.html#aa1cdfd4ad4b7442304c6f44b3346f2e0">00026</a> <a class="code" href="classSimpleChatWidget.html#aa1cdfd4ad4b7442304c6f44b3346f2e0" title="Create a chat widget that will connect to the given server.">SimpleChatWidget::SimpleChatWidget</a>(<a class="code" href="classSimpleChatServer.html" title="A simple chat server.">SimpleChatServer</a>& server,
<a name="l00027"></a>00027 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html">Wt::WContainerWidget</a> *parent)
<a name="l00028"></a>00028 : <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html">WContainerWidget</a>(parent),
<a name="l00029"></a>00029 server_(server),
<a name="l00030"></a>00030 loggedIn_(false),
<a name="l00031"></a>00031 userList_(0),
<a name="l00032"></a>00032 messageReceived_(0)
<a name="l00033"></a>00033 {
<a name="l00034"></a>00034 <a class="code" href="classSimpleChatWidget.html#a596f7cbf70f45da9af017ac9d6f55ebc">user_</a> = <a class="code" href="classSimpleChatWidget.html#ab29db4cbc3935964daf6b6c264ce68d3">server_</a>.<a class="code" href="classSimpleChatServer.html#abf692567706118193111c2b2589c8d3f" title="Get a suggestion for a guest user name.">suggestGuest</a>();
<a name="l00035"></a>00035 <a class="code" href="classSimpleChatWidget.html#a71d98bf20e007af247f3b5a74f35efa2" title="Show a simple login screen.">letLogin</a>();
<a name="l00036"></a>00036 }
<a name="l00037"></a>00037
<a name="l00038"></a><a class="code" href="classSimpleChatWidget.html#afdf56768400ee025d0b71ccce476b1bf">00038</a> <a class="code" href="classSimpleChatWidget.html#afdf56768400ee025d0b71ccce476b1bf" title="Delete a chat widget.">SimpleChatWidget::~SimpleChatWidget</a>()
<a name="l00039"></a>00039 {
<a name="l00040"></a>00040 <span class="keyword">delete</span> <a class="code" href="classSimpleChatWidget.html#af877bf2951965ee6832d7c5f5c5f885a">messageReceived_</a>;
<a name="l00041"></a>00041 <a class="code" href="classSimpleChatWidget.html#abff498a5a43a7e0caac5f2140f14e301">logout</a>();
<a name="l00042"></a>00042 <a class="code" href="classSimpleChatWidget.html#a7706247f4a599cd995003a260fd36b0a">disconnect</a>();
<a name="l00043"></a>00043 }
<a name="l00044"></a>00044
<a name="l00045"></a><a class="code" href="classSimpleChatWidget.html#a5fa75ab733ce294065a1233dfcbe83d6">00045</a> <span class="keywordtype">void</span> <a class="code" href="classSimpleChatWidget.html#a5fa75ab733ce294065a1233dfcbe83d6">SimpleChatWidget::connect</a>()
<a name="l00046"></a>00046 {
<a name="l00047"></a>00047 <span class="keywordflow">if</span> (<a class="code" href="classSimpleChatWidget.html#ab29db4cbc3935964daf6b6c264ce68d3">server_</a>.<a class="code" href="classSimpleChatServer.html#a916cec08c2aeb2d2ccf413e9c9a45036" title="Connects to the chat server.">connect</a>
<a name="l00048"></a>00048 (<span class="keyword">this</span>, boost::bind(&<a class="code" href="classSimpleChatWidget.html#acda2bbe138c3119e4c62a6132801a232">SimpleChatWidget::processChatEvent</a>, <span class="keyword">this</span>, _1)))
<a name="l00049"></a>00049 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#a38d922da0a0d83395519f3eaab85d0f6">Wt::WApplication::instance</a>()-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#ad9631ca64e68d30d40cb49c90e55223d">enableUpdates</a>(<span class="keyword">true</span>);
<a name="l00050"></a>00050 }
<a name="l00051"></a>00051
<a name="l00052"></a><a class="code" href="classSimpleChatWidget.html#a7706247f4a599cd995003a260fd36b0a">00052</a> <span class="keywordtype">void</span> <a class="code" href="classSimpleChatWidget.html#a7706247f4a599cd995003a260fd36b0a">SimpleChatWidget::disconnect</a>()
<a name="l00053"></a>00053 {
<a name="l00054"></a>00054 <span class="keywordflow">if</span> (<a class="code" href="classSimpleChatWidget.html#ab29db4cbc3935964daf6b6c264ce68d3">server_</a>.<a class="code" href="classSimpleChatServer.html#a070e07e1a2a5ec5ecc4e944a761256c9" title="Disconnect from the chat server.">disconnect</a>(<span class="keyword">this</span>))
<a name="l00055"></a>00055 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#a38d922da0a0d83395519f3eaab85d0f6">Wt::WApplication::instance</a>()-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#ad9631ca64e68d30d40cb49c90e55223d">enableUpdates</a>(<span class="keyword">false</span>);
<a name="l00056"></a>00056 }
<a name="l00057"></a>00057
<a name="l00058"></a><a class="code" href="classSimpleChatWidget.html#a71d98bf20e007af247f3b5a74f35efa2">00058</a> <span class="keywordtype">void</span> <a class="code" href="classSimpleChatWidget.html#a71d98bf20e007af247f3b5a74f35efa2" title="Show a simple login screen.">SimpleChatWidget::letLogin</a>()
<a name="l00059"></a>00059 {
<a name="l00060"></a>00060 <a class="code" href="classSimpleChatWidget.html#a7706247f4a599cd995003a260fd36b0a">disconnect</a>();
<a name="l00061"></a>00061
<a name="l00062"></a>00062 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html#a608f748cbdda763f1a11556ddad9fbe1">clear</a>();
<a name="l00063"></a>00063
<a name="l00064"></a>00064 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WVBoxLayout.html">WVBoxLayout</a> *vLayout = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WVBoxLayout.html">WVBoxLayout</a>();
<a name="l00065"></a>00065 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html#a1c84e0ffe330d4798f0ce217f75be08c">setLayout</a>(vLayout, <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#ab8f772c69bc8180c31f9e4f4593b143fad033ef69b45d0b75633be34168c9b606">AlignLeft</a> | <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#ab8f772c69bc8180c31f9e4f4593b143fa58fe5182bd266132c59718c6d30945a9">AlignTop</a>);
<a name="l00066"></a>00066
<a name="l00067"></a>00067 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WHBoxLayout.html">WHBoxLayout</a> *hLayout = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WHBoxLayout.html">WHBoxLayout</a>();
<a name="l00068"></a>00068 vLayout-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a062d26b432841995a0be7b7d7aac6413">addLayout</a>(hLayout);
<a name="l00069"></a>00069
<a name="l00070"></a>00070 hLayout-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a7c1ec58e25d0b7add93f5f4342844db6">addWidget</a>(<span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WLabel.html">WLabel</a>(<span class="stringliteral">"User name:"</span>), 0, <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#ab8f772c69bc8180c31f9e4f4593b143fa2ed90f01dbf74049f428d33769d48e3f">AlignMiddle</a>);
<a name="l00071"></a>00071 hLayout-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a7c1ec58e25d0b7add93f5f4342844db6">addWidget</a>(<a class="code" href="classSimpleChatWidget.html#a6216e8cf4d368c1550562e1c5525d34b">userNameEdit_</a> = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WLineEdit.html">WLineEdit</a>(<a class="code" href="classSimpleChatWidget.html#a596f7cbf70f45da9af017ac9d6f55ebc">user_</a>), 0, <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#ab8f772c69bc8180c31f9e4f4593b143fa2ed90f01dbf74049f428d33769d48e3f">AlignMiddle</a>);
<a name="l00072"></a>00072 <a class="code" href="classSimpleChatWidget.html#a6216e8cf4d368c1550562e1c5525d34b">userNameEdit_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFormWidget.html#afe33f5c3658ddbd08fec9f6c203c578b">setFocus</a>();
<a name="l00073"></a>00073
<a name="l00074"></a>00074 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WPushButton.html">WPushButton</a> *b = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WPushButton.html">WPushButton</a>(<span class="stringliteral">"Login"</span>);
<a name="l00075"></a>00075 hLayout-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a7c1ec58e25d0b7add93f5f4342844db6">addWidget</a>(b, 0, <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#ab8f772c69bc8180c31f9e4f4593b143fa2ed90f01dbf74049f428d33769d48e3f">AlignMiddle</a>);
<a name="l00076"></a>00076
<a name="l00077"></a>00077 b-><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="classSimpleChatWidget.html#ae085fda18af441e1630342395499478c">SimpleChatWidget::login</a>);
<a name="l00078"></a>00078 <a class="code" href="classSimpleChatWidget.html#a6216e8cf4d368c1550562e1c5525d34b">userNameEdit_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WInteractWidget.html#a38f06d1ad95e7599b055f49931236c10">enterPressed</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1EventSignal.html#a36896f54a4db342af24efa6e9d703455">connect</a>(<span class="keyword">this</span>, &<a class="code" href="classSimpleChatWidget.html#ae085fda18af441e1630342395499478c">SimpleChatWidget::login</a>);
<a name="l00079"></a>00079
<a name="l00080"></a>00080 vLayout-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a7c1ec58e25d0b7add93f5f4342844db6">addWidget</a>(<a class="code" href="classSimpleChatWidget.html#a98f69adc6f2381cd98584566ed4c497e">statusMsg_</a> = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html">WText</a>());
<a name="l00081"></a>00081 <a class="code" href="classSimpleChatWidget.html#a98f69adc6f2381cd98584566ed4c497e">statusMsg_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html#af22c64c4c5fed3d2aef0915a7e5c5866">setTextFormat</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#a140dea437d52d3d7c438ea3bd16a1480ae06bb9ae9a26d13c3dcf9f20d5067885">PlainText</a>);
<a name="l00082"></a>00082 }
<a name="l00083"></a>00083
<a name="l00084"></a><a class="code" href="classSimpleChatWidget.html#ae085fda18af441e1630342395499478c">00084</a> <span class="keywordtype">void</span> <a class="code" href="classSimpleChatWidget.html#ae085fda18af441e1630342395499478c">SimpleChatWidget::login</a>()
<a name="l00085"></a>00085 {
<a name="l00086"></a>00086 <span class="keywordflow">if</span> (!<a class="code" href="classSimpleChatWidget.html#aa05605599e6eb9e6a7aeb51234533241">loggedIn</a>()) {
<a name="l00087"></a>00087 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">WString</a> name = <a class="code" href="classSimpleChatWidget.html#a6216e8cf4d368c1550562e1c5525d34b">userNameEdit_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WLineEdit.html#ac74b58779cb635898cac13e81d8b0c7a">text</a>();
<a name="l00088"></a>00088
<a name="l00089"></a>00089 <span class="keywordflow">if</span> (!<a class="code" href="classSimpleChatWidget.html#af877bf2951965ee6832d7c5f5c5f885a">messageReceived_</a>)
<a name="l00090"></a>00090 <a class="code" href="classSimpleChatWidget.html#af877bf2951965ee6832d7c5f5c5f885a">messageReceived_</a> = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WSound.html">WSound</a>(<span class="stringliteral">"sounds/message_received.mp3"</span>);
<a name="l00091"></a>00091
<a name="l00092"></a>00092 <span class="keywordflow">if</span> (!<a class="code" href="classSimpleChatWidget.html#a19c0deeaf8952ec36791c3f444964878" title="Start a chat for the given user.">startChat</a>(name))
<a name="l00093"></a>00093 <a class="code" href="classSimpleChatWidget.html#a98f69adc6f2381cd98584566ed4c497e">statusMsg_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html#a2f788aa524d51b3962642c9f565e66e6">setText</a>(<span class="stringliteral">"Sorry, name '"</span> + <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#a6cd1b8a84c7aaf72e5d44cb47ae90e9c">escapeText</a>(name) +
<a name="l00094"></a>00094 <span class="stringliteral">"' is already taken."</span>);
<a name="l00095"></a>00095 }
<a name="l00096"></a>00096 }
<a name="l00097"></a>00097
<a name="l00098"></a><a class="code" href="classSimpleChatWidget.html#abff498a5a43a7e0caac5f2140f14e301">00098</a> <span class="keywordtype">void</span> <a class="code" href="classSimpleChatWidget.html#abff498a5a43a7e0caac5f2140f14e301">SimpleChatWidget::logout</a>()
<a name="l00099"></a>00099 {
<a name="l00100"></a>00100 <span class="keywordflow">if</span> (<a class="code" href="classSimpleChatWidget.html#aa05605599e6eb9e6a7aeb51234533241">loggedIn</a>()) {
<a name="l00101"></a>00101 <a class="code" href="classSimpleChatWidget.html#a8f56993c5967b22aff04009f4613a155">loggedIn_</a> = <span class="keyword">false</span>;
<a name="l00102"></a>00102 <a class="code" href="classSimpleChatWidget.html#ab29db4cbc3935964daf6b6c264ce68d3">server_</a>.<a class="code" href="classSimpleChatServer.html#a5d376e3ff441f24843be648dd420e027" title="Logout from the server.">logout</a>(<a class="code" href="classSimpleChatWidget.html#a596f7cbf70f45da9af017ac9d6f55ebc">user_</a>);
<a name="l00103"></a>00103
<a name="l00104"></a>00104 <a class="code" href="classSimpleChatWidget.html#a71d98bf20e007af247f3b5a74f35efa2" title="Show a simple login screen.">letLogin</a>();
<a name="l00105"></a>00105 }
<a name="l00106"></a>00106 }
<a name="l00107"></a>00107
<a name="l00108"></a><a class="code" href="classSimpleChatWidget.html#aad5e7beb8f1aa6a26715d93fa3a9952e">00108</a> <span class="keywordtype">void</span> <a class="code" href="classSimpleChatWidget.html#aad5e7beb8f1aa6a26715d93fa3a9952e">SimpleChatWidget::createLayout</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html">WWidget</a> *messages, <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html">WWidget</a> *userList,
<a name="l00109"></a>00109 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html">WWidget</a> *messageEdit,
<a name="l00110"></a>00110 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html">WWidget</a> *sendButton, <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html">WWidget</a> *logoutButton)
<a name="l00111"></a>00111 {
<a name="l00112"></a>00112 <span class="comment">/*</span>
<a name="l00113"></a>00113 <span class="comment"> * Create a vertical layout, which will hold 3 rows,</span>
<a name="l00114"></a>00114 <span class="comment"> * organized like this:</span>
<a name="l00115"></a>00115 <span class="comment"> *</span>
<a name="l00116"></a>00116 <span class="comment"> * WVBoxLayout</span>
<a name="l00117"></a>00117 <span class="comment"> * --------------------------------------------</span>
<a name="l00118"></a>00118 <span class="comment"> * | nested WHBoxLayout (vertical stretch=1) |</span>
<a name="l00119"></a>00119 <span class="comment"> * | | |</span>
<a name="l00120"></a>00120 <span class="comment"> * | messages | userList |</span>
<a name="l00121"></a>00121 <span class="comment"> * | (horizontal stretch=1) | |</span>
<a name="l00122"></a>00122 <span class="comment"> * | | |</span>
<a name="l00123"></a>00123 <span class="comment"> * --------------------------------------------</span>
<a name="l00124"></a>00124 <span class="comment"> * | message edit area |</span>
<a name="l00125"></a>00125 <span class="comment"> * --------------------------------------------</span>
<a name="l00126"></a>00126 <span class="comment"> * | WHBoxLayout |</span>
<a name="l00127"></a>00127 <span class="comment"> * | send | logout |</span>
<a name="l00128"></a>00128 <span class="comment"> * --------------------------------------------</span>
<a name="l00129"></a>00129 <span class="comment"> */</span>
<a name="l00130"></a>00130 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WVBoxLayout.html">WVBoxLayout</a> *vLayout = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WVBoxLayout.html">WVBoxLayout</a>();
<a name="l00131"></a>00131
<a name="l00132"></a>00132 <span class="comment">// Create a horizontal layout for the messages | userslist.</span>
<a name="l00133"></a>00133 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WHBoxLayout.html">WHBoxLayout</a> *hLayout = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WHBoxLayout.html">WHBoxLayout</a>();
<a name="l00134"></a>00134
<a name="l00135"></a>00135 <span class="comment">// Add widget to horizontal layout with stretch = 1</span>
<a name="l00136"></a>00136 hLayout-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a7c1ec58e25d0b7add93f5f4342844db6">addWidget</a>(messages, 1);
<a name="l00137"></a>00137 messages-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#a4be23ecf48d5968efb5d926e38e01708">setStyleClass</a>(<span class="stringliteral">"chat-msgs"</span>);
<a name="l00138"></a>00138
<a name="l00139"></a>00139 <span class="comment">// Add another widget to horizontal layout with stretch = 0</span>
<a name="l00140"></a>00140 hLayout-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a7c1ec58e25d0b7add93f5f4342844db6">addWidget</a>(userList);
<a name="l00141"></a>00141 userList-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#a4be23ecf48d5968efb5d926e38e01708">setStyleClass</a>(<span class="stringliteral">"chat-users"</span>);
<a name="l00142"></a>00142
<a name="l00143"></a>00143 hLayout-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a00bdfb4d442bd8e8ad9c33b72692763f">setResizable</a>(0, <span class="keyword">true</span>);
<a name="l00144"></a>00144
<a name="l00145"></a>00145 <span class="comment">// Add nested layout to vertical layout with stretch = 1</span>
<a name="l00146"></a>00146 vLayout-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a062d26b432841995a0be7b7d7aac6413">addLayout</a>(hLayout, 1);
<a name="l00147"></a>00147
<a name="l00148"></a>00148 <span class="comment">// Add widget to vertical layout with stretch = 0</span>
<a name="l00149"></a>00149 vLayout-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a7c1ec58e25d0b7add93f5f4342844db6">addWidget</a>(messageEdit);
<a name="l00150"></a>00150 messageEdit-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#a4be23ecf48d5968efb5d926e38e01708">setStyleClass</a>(<span class="stringliteral">"chat-noedit"</span>);
<a name="l00151"></a>00151
<a name="l00152"></a>00152 <span class="comment">// Create a horizontal layout for the buttons.</span>
<a name="l00153"></a>00153 hLayout = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WHBoxLayout.html">WHBoxLayout</a>();
<a name="l00154"></a>00154
<a name="l00155"></a>00155 <span class="comment">// Add button to horizontal layout with stretch = 0</span>
<a name="l00156"></a>00156 hLayout-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a7c1ec58e25d0b7add93f5f4342844db6">addWidget</a>(sendButton);
<a name="l00157"></a>00157
<a name="l00158"></a>00158 <span class="comment">// Add button to horizontal layout with stretch = 0</span>
<a name="l00159"></a>00159 hLayout-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a7c1ec58e25d0b7add93f5f4342844db6">addWidget</a>(logoutButton);
<a name="l00160"></a>00160
<a name="l00161"></a>00161 <span class="comment">// Add nested layout to vertical layout with stretch = 0</span>
<a name="l00162"></a>00162 vLayout-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a062d26b432841995a0be7b7d7aac6413">addLayout</a>(hLayout, 0, <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#ab8f772c69bc8180c31f9e4f4593b143fad033ef69b45d0b75633be34168c9b606">AlignLeft</a> | <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#ab8f772c69bc8180c31f9e4f4593b143fa58fe5182bd266132c59718c6d30945a9">AlignTop</a>);
<a name="l00163"></a>00163
<a name="l00164"></a>00164 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html#a1c84e0ffe330d4798f0ce217f75be08c">setLayout</a>(vLayout);
<a name="l00165"></a>00165 }
<a name="l00166"></a>00166
<a name="l00167"></a><a class="code" href="classSimpleChatWidget.html#aa05605599e6eb9e6a7aeb51234533241">00167</a> <span class="keywordtype">bool</span> <a class="code" href="classSimpleChatWidget.html#aa05605599e6eb9e6a7aeb51234533241">SimpleChatWidget::loggedIn</a>()<span class="keyword"> const</span>
<a name="l00168"></a>00168 <span class="keyword"></span>{
<a name="l00169"></a>00169 <span class="keywordflow">return</span> <a class="code" href="classSimpleChatWidget.html#a8f56993c5967b22aff04009f4613a155">loggedIn_</a>;
<a name="l00170"></a>00170 }
<a name="l00171"></a>00171
<a name="l00172"></a><a class="code" href="classSimpleChatWidget.html#aa1a93dff4800d783c80a9846cdc591b7">00172</a> <span class="keywordtype">void</span> <a class="code" href="classSimpleChatWidget.html#aa1a93dff4800d783c80a9846cdc591b7">SimpleChatWidget::render</a>(WFlags<RenderFlag> flags)
<a name="l00173"></a>00173 {
<a name="l00174"></a>00174 <span class="keywordflow">if</span> (flags & RenderFull) {
<a name="l00175"></a>00175 <span class="keywordflow">if</span> (<a class="code" href="classSimpleChatWidget.html#aa05605599e6eb9e6a7aeb51234533241">loggedIn</a>()) {
<a name="l00176"></a>00176 <span class="comment">/* Handle a page refresh correctly */</span>
<a name="l00177"></a>00177 <a class="code" href="classSimpleChatWidget.html#a4b658b56ef4ba1862765b9ad84fd9a9c">messageEdit_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WTextArea.html#a1f05060c037d13c2c6c26f51f1fb9640">setText</a>(WString::Empty);
<a name="l00178"></a>00178 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#a159456e656af966117936b9024de4ca2">doJavaScript</a>(<span class="stringliteral">"setTimeout(function() { "</span>
<a name="l00179"></a>00179 + <a class="code" href="classSimpleChatWidget.html#a32a593ed511997f32a33a55d651ce79d">messages_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#aa2b7078b3b43d53a85e5244b45d504f7">jsRef</a>() + <span class="stringliteral">".scrollTop += "</span>
<a name="l00180"></a>00180 + <a class="code" href="classSimpleChatWidget.html#a32a593ed511997f32a33a55d651ce79d">messages_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#aa2b7078b3b43d53a85e5244b45d504f7">jsRef</a>() + <span class="stringliteral">".scrollHeight;}, 0);"</span>);
<a name="l00181"></a>00181 }
<a name="l00182"></a>00182 }
<a name="l00183"></a>00183
<a name="l00184"></a>00184 <a class="code" href="classSimpleChatWidget.html#aa1a93dff4800d783c80a9846cdc591b7">WContainerWidget::render</a>(flags);
<a name="l00185"></a>00185 }
<a name="l00186"></a>00186
<a name="l00187"></a><a class="code" href="classSimpleChatWidget.html#a19c0deeaf8952ec36791c3f444964878">00187</a> <span class="keywordtype">bool</span> <a class="code" href="classSimpleChatWidget.html#a19c0deeaf8952ec36791c3f444964878" title="Start a chat for the given user.">SimpleChatWidget::startChat</a>(<span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html">WString</a>& user)
<a name="l00188"></a>00188 {
<a name="l00189"></a>00189 <span class="comment">/*</span>
<a name="l00190"></a>00190 <span class="comment"> * When logging in, we pass our processChatEvent method as the function that</span>
<a name="l00191"></a>00191 <span class="comment"> * is used to indicate a new chat event for this user.</span>
<a name="l00192"></a>00192 <span class="comment"> */</span>
<a name="l00193"></a>00193 <span class="keywordflow">if</span> (<a class="code" href="classSimpleChatWidget.html#ab29db4cbc3935964daf6b6c264ce68d3">server_</a>.<a class="code" href="classSimpleChatServer.html#ada0ab17464e1711ca15f30b381ede57c" title="Try to login with given user name.">login</a>(user)) {
<a name="l00194"></a>00194 <a class="code" href="classSimpleChatWidget.html#a8f56993c5967b22aff04009f4613a155">loggedIn_</a> = <span class="keyword">true</span>;
<a name="l00195"></a>00195 <a class="code" href="classSimpleChatWidget.html#a5fa75ab733ce294065a1233dfcbe83d6">connect</a>();
<a name="l00196"></a>00196
<a name="l00197"></a>00197 <a class="code" href="classSimpleChatWidget.html#a596f7cbf70f45da9af017ac9d6f55ebc">user_</a> = user;
<a name="l00198"></a>00198
<a name="l00199"></a>00199 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html#a608f748cbdda763f1a11556ddad9fbe1">clear</a>();
<a name="l00200"></a>00200 <a class="code" href="classSimpleChatWidget.html#a6216e8cf4d368c1550562e1c5525d34b">userNameEdit_</a> = 0;
<a name="l00201"></a>00201
<a name="l00202"></a>00202 <a class="code" href="classSimpleChatWidget.html#a32a593ed511997f32a33a55d651ce79d">messages_</a> = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html#a520ba6e52a36a7f2efbef1a31a69e898">WContainerWidget</a>();
<a name="l00203"></a>00203 <a class="code" href="classSimpleChatWidget.html#aee074d5eb739091af79eb8dccc90853e">userList_</a> = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html#a520ba6e52a36a7f2efbef1a31a69e898">WContainerWidget</a>();
<a name="l00204"></a>00204 <a class="code" href="classSimpleChatWidget.html#a4b658b56ef4ba1862765b9ad84fd9a9c">messageEdit_</a> = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WTextArea.html">WTextArea</a>();
<a name="l00205"></a>00205 <a class="code" href="classSimpleChatWidget.html#a4b658b56ef4ba1862765b9ad84fd9a9c">messageEdit_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WTextArea.html#ade46b47350f427f45c9b53ac7e41c5b2">setRows</a>(2);
<a name="l00206"></a>00206 <a class="code" href="classSimpleChatWidget.html#a4b658b56ef4ba1862765b9ad84fd9a9c">messageEdit_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFormWidget.html#afe33f5c3658ddbd08fec9f6c203c578b">setFocus</a>();
<a name="l00207"></a>00207
<a name="l00208"></a>00208 <span class="comment">// Display scroll bars if contents overflows</span>
<a name="l00209"></a>00209 <a class="code" href="classSimpleChatWidget.html#a32a593ed511997f32a33a55d651ce79d">messages_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html#ae269f870992c5843d3097a63795b10d6">setOverflow</a>(WContainerWidget::OverflowAuto);
<a name="l00210"></a>00210 <a class="code" href="classSimpleChatWidget.html#aee074d5eb739091af79eb8dccc90853e">userList_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html#ae269f870992c5843d3097a63795b10d6">setOverflow</a>(WContainerWidget::OverflowAuto);
<a name="l00211"></a>00211
<a name="l00212"></a>00212 <a class="code" href="classSimpleChatWidget.html#aa9a81423eda8238f8aa37be1a5a5bee8">sendButton_</a> = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WPushButton.html">WPushButton</a>(<span class="stringliteral">"Send"</span>);
<a name="l00213"></a>00213 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WPushButton.html">WPushButton</a> *logoutButton = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WPushButton.html">WPushButton</a>(<span class="stringliteral">"Logout"</span>);
<a name="l00214"></a>00214
<a name="l00215"></a>00215 <a class="code" href="classSimpleChatWidget.html#aad5e7beb8f1aa6a26715d93fa3a9952e">createLayout</a>(<a class="code" href="classSimpleChatWidget.html#a32a593ed511997f32a33a55d651ce79d">messages_</a>, <a class="code" href="classSimpleChatWidget.html#aee074d5eb739091af79eb8dccc90853e">userList_</a>, <a class="code" href="classSimpleChatWidget.html#a4b658b56ef4ba1862765b9ad84fd9a9c">messageEdit_</a>, <a class="code" href="classSimpleChatWidget.html#aa9a81423eda8238f8aa37be1a5a5bee8">sendButton_</a>, logoutButton);
<a name="l00216"></a>00216
<a name="l00217"></a>00217 <span class="comment">/*</span>
<a name="l00218"></a>00218 <span class="comment"> * Connect event handlers:</span>
<a name="l00219"></a>00219 <span class="comment"> * - click on button</span>
<a name="l00220"></a>00220 <span class="comment"> * - enter in text area</span>
<a name="l00221"></a>00221 <span class="comment"> *</span>
<a name="l00222"></a>00222 <span class="comment"> * We will clear the input field using a small custom client-side</span>
<a name="l00223"></a>00223 <span class="comment"> * JavaScript invocation.</span>
<a name="l00224"></a>00224 <span class="comment"> */</span>
<a name="l00225"></a>00225
<a name="l00226"></a>00226 <span class="comment">// Create a JavaScript 'slot' (JSlot). The JavaScript slot always takes</span>
<a name="l00227"></a>00227 <span class="comment">// 2 arguments: the originator of the event (in our case the</span>
<a name="l00228"></a>00228 <span class="comment">// button or text area), and the JavaScript event object.</span>
<a name="l00229"></a>00229 <a class="code" href="classSimpleChatWidget.html#a7e58bf2312b413d2d649500c26a6f8d6">clearInput_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1JSlot.html#a4e28a8ef6d2965aeaac0c5dcf587bbbb">setJavaScript</a>
<a name="l00230"></a>00230 (<span class="stringliteral">"function(o, e) { setTimeout(function() {"</span>
<a name="l00231"></a>00231 <span class="stringliteral">""</span> + <a class="code" href="classSimpleChatWidget.html#a4b658b56ef4ba1862765b9ad84fd9a9c">messageEdit_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#aa2b7078b3b43d53a85e5244b45d504f7">jsRef</a>() + <span class="stringliteral">".value='';"</span>
<a name="l00232"></a>00232 <span class="stringliteral">"}, 0); }"</span>);
<a name="l00233"></a>00233
<a name="l00234"></a>00234 <span class="comment">// Bind the C++ and JavaScript event handlers.</span>
<a name="l00235"></a>00235 <a class="code" href="classSimpleChatWidget.html#aa9a81423eda8238f8aa37be1a5a5bee8">sendButton_</a>-><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="classSimpleChatWidget.html#ad1c4dc9e6aca0c5b8e1db81ee7c5fad3">SimpleChatWidget::send</a>);
<a name="l00236"></a>00236 <a class="code" href="classSimpleChatWidget.html#a4b658b56ef4ba1862765b9ad84fd9a9c">messageEdit_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WInteractWidget.html#a38f06d1ad95e7599b055f49931236c10">enterPressed</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1EventSignal.html#a36896f54a4db342af24efa6e9d703455">connect</a>(<span class="keyword">this</span>, &<a class="code" href="classSimpleChatWidget.html#ad1c4dc9e6aca0c5b8e1db81ee7c5fad3">SimpleChatWidget::send</a>);
<a name="l00237"></a>00237 <a class="code" href="classSimpleChatWidget.html#aa9a81423eda8238f8aa37be1a5a5bee8">sendButton_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WInteractWidget.html#ae11e050cce0d4a8f742afa3ef92bfe8c">clicked</a>().connect(<a class="code" href="classSimpleChatWidget.html#a7e58bf2312b413d2d649500c26a6f8d6">clearInput_</a>);
<a name="l00238"></a>00238 <a class="code" href="classSimpleChatWidget.html#a4b658b56ef4ba1862765b9ad84fd9a9c">messageEdit_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WInteractWidget.html#a38f06d1ad95e7599b055f49931236c10">enterPressed</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1EventSignal.html#a36896f54a4db342af24efa6e9d703455">connect</a>(<a class="code" href="classSimpleChatWidget.html#a7e58bf2312b413d2d649500c26a6f8d6">clearInput_</a>);
<a name="l00239"></a>00239 <a class="code" href="classSimpleChatWidget.html#aa9a81423eda8238f8aa37be1a5a5bee8">sendButton_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WInteractWidget.html#ae11e050cce0d4a8f742afa3ef92bfe8c">clicked</a>().connect(<a class="code" href="classSimpleChatWidget.html#a4b658b56ef4ba1862765b9ad84fd9a9c">messageEdit_</a>, &WLineEdit::setFocus);
<a name="l00240"></a>00240 <a class="code" href="classSimpleChatWidget.html#a4b658b56ef4ba1862765b9ad84fd9a9c">messageEdit_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WInteractWidget.html#a38f06d1ad95e7599b055f49931236c10">enterPressed</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1EventSignal.html#a36896f54a4db342af24efa6e9d703455">connect</a>(<a class="code" href="classSimpleChatWidget.html#a4b658b56ef4ba1862765b9ad84fd9a9c">messageEdit_</a>, &WLineEdit::setFocus);
<a name="l00241"></a>00241
<a name="l00242"></a>00242 <span class="comment">// Prevent the enter from generating a new line, which is its default</span>
<a name="l00243"></a>00243 <span class="comment">// action</span>
<a name="l00244"></a>00244 <a class="code" href="classSimpleChatWidget.html#a4b658b56ef4ba1862765b9ad84fd9a9c">messageEdit_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WInteractWidget.html#a38f06d1ad95e7599b055f49931236c10">enterPressed</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1EventSignalBase.html#afd8983929683ffc4c6dda8a91a7bda7b">preventDefaultAction</a>();
<a name="l00245"></a>00245
<a name="l00246"></a>00246 logoutButton-><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="classSimpleChatWidget.html#abff498a5a43a7e0caac5f2140f14e301">SimpleChatWidget::logout</a>);
<a name="l00247"></a>00247
<a name="l00248"></a>00248 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html">WText</a> *msg = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html">WText</a>
<a name="l00249"></a>00249 (<span class="stringliteral">"<div><span class='chat-info'>You are joining as "</span>
<a name="l00250"></a>00250 + <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#a6cd1b8a84c7aaf72e5d44cb47ae90e9c">escapeText</a>(<a class="code" href="classSimpleChatWidget.html#a596f7cbf70f45da9af017ac9d6f55ebc">user_</a>) + <span class="stringliteral">".</span></div>"</span>,
<a name="l00251"></a>00251 <a class="code" href="classSimpleChatWidget.html#a32a593ed511997f32a33a55d651ce79d">messages_</a>);
<a name="l00252"></a>00252 msg-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#afd3a3b359681111460a93d13979d17dd">setStyleClass</a>(<span class="stringliteral">"chat-msg"</span>);
<a name="l00253"></a>00253
<a name="l00254"></a>00254 <span class="keywordflow">if</span> (!<a class="code" href="classSimpleChatWidget.html#aee074d5eb739091af79eb8dccc90853e">userList_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#a3461e31818c4d2f516641bdaf508312a">parent</a>()) {
<a name="l00255"></a>00255 <span class="keyword">delete</span> <a class="code" href="classSimpleChatWidget.html#aee074d5eb739091af79eb8dccc90853e">userList_</a>;
<a name="l00256"></a>00256 <a class="code" href="classSimpleChatWidget.html#aee074d5eb739091af79eb8dccc90853e">userList_</a> = 0;
<a name="l00257"></a>00257 }
<a name="l00258"></a>00258
<a name="l00259"></a>00259 <span class="keywordflow">if</span> (!<a class="code" href="classSimpleChatWidget.html#aa9a81423eda8238f8aa37be1a5a5bee8">sendButton_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#a3461e31818c4d2f516641bdaf508312a">parent</a>()) {
<a name="l00260"></a>00260 <span class="keyword">delete</span> <a class="code" href="classSimpleChatWidget.html#aa9a81423eda8238f8aa37be1a5a5bee8">sendButton_</a>;
<a name="l00261"></a>00261 <a class="code" href="classSimpleChatWidget.html#aa9a81423eda8238f8aa37be1a5a5bee8">sendButton_</a> = 0;
<a name="l00262"></a>00262 }
<a name="l00263"></a>00263
<a name="l00264"></a>00264 <span class="keywordflow">if</span> (!logoutButton-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#a3461e31818c4d2f516641bdaf508312a">parent</a>())
<a name="l00265"></a>00265 <span class="keyword">delete</span> logoutButton;
<a name="l00266"></a>00266
<a name="l00267"></a>00267 <a class="code" href="classSimpleChatWidget.html#a282d3fa5a7aceea89558de31db4bb6e0">updateUsers</a>();
<a name="l00268"></a>00268
<a name="l00269"></a>00269 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00270"></a>00270 } <span class="keywordflow">else</span>
<a name="l00271"></a>00271 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00272"></a>00272 }
<a name="l00273"></a>00273
<a name="l00274"></a><a class="code" href="classSimpleChatWidget.html#ad1c4dc9e6aca0c5b8e1db81ee7c5fad3">00274</a> <span class="keywordtype">void</span> <a class="code" href="classSimpleChatWidget.html#ad1c4dc9e6aca0c5b8e1db81ee7c5fad3">SimpleChatWidget::send</a>()
<a name="l00275"></a>00275 {
<a name="l00276"></a>00276 <span class="keywordflow">if</span> (!<a class="code" href="classSimpleChatWidget.html#a4b658b56ef4ba1862765b9ad84fd9a9c">messageEdit_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WTextArea.html#ad8b89ce30df2b02894c53b6ed71fe4a6">text</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WString.html#a87a90e69ab25d62ba029e10ea244abaf">empty</a>())
<a name="l00277"></a>00277 <a class="code" href="classSimpleChatWidget.html#ab29db4cbc3935964daf6b6c264ce68d3">server_</a>.<a class="code" href="classSimpleChatServer.html#aab42074f7904397b3547a6df89c16d9d" title="Send a message on behalve of a user.">sendMessage</a>(<a class="code" href="classSimpleChatWidget.html#a596f7cbf70f45da9af017ac9d6f55ebc">user_</a>, <a class="code" href="classSimpleChatWidget.html#a4b658b56ef4ba1862765b9ad84fd9a9c">messageEdit_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WTextArea.html#ad8b89ce30df2b02894c53b6ed71fe4a6">text</a>());
<a name="l00278"></a>00278 }
<a name="l00279"></a>00279
<a name="l00280"></a><a class="code" href="classSimpleChatWidget.html#a282d3fa5a7aceea89558de31db4bb6e0">00280</a> <span class="keywordtype">void</span> <a class="code" href="classSimpleChatWidget.html#a282d3fa5a7aceea89558de31db4bb6e0">SimpleChatWidget::updateUsers</a>()
<a name="l00281"></a>00281 {
<a name="l00282"></a>00282 <span class="keywordflow">if</span> (<a class="code" href="classSimpleChatWidget.html#aee074d5eb739091af79eb8dccc90853e">userList_</a>) {
<a name="l00283"></a>00283 <a class="code" href="classSimpleChatWidget.html#aee074d5eb739091af79eb8dccc90853e">userList_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html#a608f748cbdda763f1a11556ddad9fbe1">clear</a>();
<a name="l00284"></a>00284
<a name="l00285"></a>00285 <a class="code" href="classSimpleChatServer.html#a911329f24472ca7ed245ab18611488d4" title="Typedef for a collection of user names.">SimpleChatServer::UserSet</a> users = <a class="code" href="classSimpleChatWidget.html#ab29db4cbc3935964daf6b6c264ce68d3">server_</a>.<a class="code" href="classSimpleChatServer.html#a40f5c6465b1edb44278be93c97a29a39" title="Get the users currently logged in.">users</a>();
<a name="l00286"></a>00286
<a name="l00287"></a>00287 <a class="code" href="classSimpleChatWidget.html#ae3fdaeefe19e26c6c6ad9f7c0445af57">UserMap</a> oldUsers = <a class="code" href="classSimpleChatWidget.html#afe3350a7929733a5b93db803dee8704b">users_</a>;
<a name="l00288"></a>00288 <a class="code" href="classSimpleChatWidget.html#afe3350a7929733a5b93db803dee8704b">users_</a>.clear();
<a name="l00289"></a>00289
<a name="l00290"></a>00290 <span class="keywordflow">for</span> (SimpleChatServer::UserSet::iterator i = users.begin();
<a name="l00291"></a>00291 i != users.end(); ++i) {
<a name="l00292"></a>00292 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WCheckBox.html">WCheckBox</a> *w = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WCheckBox.html">WCheckBox</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#a6cd1b8a84c7aaf72e5d44cb47ae90e9c">escapeText</a>(*i), <a class="code" href="classSimpleChatWidget.html#aee074d5eb739091af79eb8dccc90853e">userList_</a>);
<a name="l00293"></a>00293 w-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#ad0957c892e70c6bf5399cf71e66f3e11">setInline</a>(<span class="keyword">false</span>);
<a name="l00294"></a>00294
<a name="l00295"></a>00295 UserMap::const_iterator j = oldUsers.find(*i);
<a name="l00296"></a>00296 <span class="keywordflow">if</span> (j != oldUsers.end())
<a name="l00297"></a>00297 w-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractToggleButton.html#a6838c9a37f3e9e3c466e9f48bde55e62">setChecked</a>(j->second);
<a name="l00298"></a>00298 <span class="keywordflow">else</span>
<a name="l00299"></a>00299 w-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractToggleButton.html#a6838c9a37f3e9e3c466e9f48bde55e62">setChecked</a>(<span class="keyword">true</span>);
<a name="l00300"></a>00300
<a name="l00301"></a>00301 <a class="code" href="classSimpleChatWidget.html#afe3350a7929733a5b93db803dee8704b">users_</a>[*i] = w-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractToggleButton.html#abd40ce7a6c4b4e924c9097015f4971ea">isChecked</a>();
<a name="l00302"></a>00302 w-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFormWidget.html#a5216ba1594b5dc525cc47cad593c7ba8">changed</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1EventSignal.html#a36896f54a4db342af24efa6e9d703455">connect</a>(<span class="keyword">this</span>, &<a class="code" href="classSimpleChatWidget.html#a76509fdffaf6a244c99977cf587c42e0">SimpleChatWidget::updateUser</a>);
<a name="l00303"></a>00303
<a name="l00304"></a>00304 <span class="keywordflow">if</span> (*i == <a class="code" href="classSimpleChatWidget.html#a596f7cbf70f45da9af017ac9d6f55ebc">user_</a>)
<a name="l00305"></a>00305 w-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#afd3a3b359681111460a93d13979d17dd">setStyleClass</a>(<span class="stringliteral">"chat-self"</span>);
<a name="l00306"></a>00306 }
<a name="l00307"></a>00307 }
<a name="l00308"></a>00308 }
<a name="l00309"></a>00309
<a name="l00310"></a><a class="code" href="classSimpleChatWidget.html#ab5f02d352a4f461edbe9a8f70859edd7">00310</a> <span class="keywordtype">void</span> <a class="code" href="classSimpleChatWidget.html#ab5f02d352a4f461edbe9a8f70859edd7">SimpleChatWidget::newMessage</a>()
<a name="l00311"></a>00311 { }
<a name="l00312"></a>00312
<a name="l00313"></a><a class="code" href="classSimpleChatWidget.html#a76509fdffaf6a244c99977cf587c42e0">00313</a> <span class="keywordtype">void</span> <a class="code" href="classSimpleChatWidget.html#a76509fdffaf6a244c99977cf587c42e0">SimpleChatWidget::updateUser</a>()
<a name="l00314"></a>00314 {
<a name="l00315"></a>00315 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WCheckBox.html">WCheckBox</a> *b = <span class="keyword">dynamic_cast<</span><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WCheckBox.html">WCheckBox</a> *<span class="keyword">></span>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WObject.html#a413deb54de40ee278dd554e4960d58ca">sender</a>());
<a name="l00316"></a>00316 <a class="code" href="classSimpleChatWidget.html#afe3350a7929733a5b93db803dee8704b">users_</a>[b-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractToggleButton.html#a3ef9682b5fe66d802380ccd6c698725d">text</a>()] = b-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractToggleButton.html#abd40ce7a6c4b4e924c9097015f4971ea">isChecked</a>();
<a name="l00317"></a>00317 }
<a name="l00318"></a>00318
<a name="l00319"></a><a class="code" href="classSimpleChatWidget.html#acda2bbe138c3119e4c62a6132801a232">00319</a> <span class="keywordtype">void</span> <a class="code" href="classSimpleChatWidget.html#acda2bbe138c3119e4c62a6132801a232">SimpleChatWidget::processChatEvent</a>(<span class="keyword">const</span> <a class="code" href="classChatEvent.html" title="Encapsulate a chat event.">ChatEvent</a>& event)
<a name="l00320"></a>00320 {
<a name="l00321"></a>00321 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html">WApplication</a> *app = WApplication::instance();
<a name="l00322"></a>00322
<a name="l00323"></a>00323 <span class="comment">/*</span>
<a name="l00324"></a>00324 <span class="comment"> * This is where the "server-push" happens. The chat server posts to this</span>
<a name="l00325"></a>00325 <span class="comment"> * event from other sessions, see SimpleChatServer::postChatEvent()</span>
<a name="l00326"></a>00326 <span class="comment"> */</span>
<a name="l00327"></a>00327
<a name="l00328"></a>00328 <span class="comment">/*</span>
<a name="l00329"></a>00329 <span class="comment"> * Format and append the line to the conversation.</span>
<a name="l00330"></a>00330 <span class="comment"> *</span>
<a name="l00331"></a>00331 <span class="comment"> * This is also the step where the automatic XSS filtering will kick in:</span>
<a name="l00332"></a>00332 <span class="comment"> * - if another user tried to pass on some JavaScript, it is filtered away.</span>
<a name="l00333"></a>00333 <span class="comment"> * - if another user did not provide valid XHTML, the text is automatically</span>
<a name="l00334"></a>00334 <span class="comment"> * interpreted as PlainText</span>
<a name="l00335"></a>00335 <span class="comment"> */</span>
<a name="l00336"></a>00336
<a name="l00337"></a>00337 <span class="comment">/*</span>
<a name="l00338"></a>00338 <span class="comment"> * If it is not a plain message, also update the user list.</span>
<a name="l00339"></a>00339 <span class="comment"> */</span>
<a name="l00340"></a>00340 <span class="keywordflow">if</span> (event.<a class="code" href="classChatEvent.html#ac932234e63d23080f4f91f7ae1167418" title="Get the event type.">type</a>() != <a class="code" href="classChatEvent.html#afa84446dae17c08fe15cf932fc0b7d61ab8894351cd11a316e25495f677eb9ae1">ChatEvent::Message</a>) {
<a name="l00341"></a>00341 <span class="keywordflow">if</span> (event.<a class="code" href="classChatEvent.html#ac932234e63d23080f4f91f7ae1167418" title="Get the event type.">type</a>() == <a class="code" href="classChatEvent.html#afa84446dae17c08fe15cf932fc0b7d61ab168d89affa0c72ba9a37d2881479ed8">ChatEvent::Rename</a> && <span class="keyword">event</span>.user() == <a class="code" href="classSimpleChatWidget.html#a596f7cbf70f45da9af017ac9d6f55ebc">user_</a>)
<a name="l00342"></a>00342 <a class="code" href="classSimpleChatWidget.html#a596f7cbf70f45da9af017ac9d6f55ebc">user_</a> = event.<a class="code" href="classChatEvent.html#a7a16dc199e1da813b8fc6bc155dc04e2" title="Get the extra data for this event.">data</a>();
<a name="l00343"></a>00343
<a name="l00344"></a>00344 <a class="code" href="classSimpleChatWidget.html#a282d3fa5a7aceea89558de31db4bb6e0">updateUsers</a>();
<a name="l00345"></a>00345 }
<a name="l00346"></a>00346
<a name="l00347"></a>00347 <a class="code" href="classSimpleChatWidget.html#ab5f02d352a4f461edbe9a8f70859edd7">newMessage</a>();
<a name="l00348"></a>00348
<a name="l00349"></a>00349 <span class="comment">/*</span>
<a name="l00350"></a>00350 <span class="comment"> * Anything else doesn't matter if we are not logged in.</span>
<a name="l00351"></a>00351 <span class="comment"> */</span>
<a name="l00352"></a>00352 <span class="keywordflow">if</span> (!<a class="code" href="classSimpleChatWidget.html#aa05605599e6eb9e6a7aeb51234533241">loggedIn</a>()) {
<a name="l00353"></a>00353 app-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#a51f50e0641a6d702a7c6ab7f8dd5946a">triggerUpdate</a>();
<a name="l00354"></a>00354 <span class="keywordflow">return</span>;
<a name="l00355"></a>00355 }
<a name="l00356"></a>00356
<a name="l00357"></a>00357 <span class="keywordtype">bool</span> display = <span class="keyword">event</span>.type() != <a class="code" href="classChatEvent.html#afa84446dae17c08fe15cf932fc0b7d61ab8894351cd11a316e25495f677eb9ae1">ChatEvent::Message</a>
<a name="l00358"></a>00358 || !<a class="code" href="classSimpleChatWidget.html#aee074d5eb739091af79eb8dccc90853e">userList_</a>
<a name="l00359"></a>00359 || (<a class="code" href="classSimpleChatWidget.html#afe3350a7929733a5b93db803dee8704b">users_</a>.find(event.<a class="code" href="classChatEvent.html#adbeff19aece69e75ab0b69f2adecc5b6" title="Get the user who caused the event.">user</a>()) != <a class="code" href="classSimpleChatWidget.html#afe3350a7929733a5b93db803dee8704b">users_</a>.end() && <a class="code" href="classSimpleChatWidget.html#afe3350a7929733a5b93db803dee8704b">users_</a>[<span class="keyword">event</span>.user()]);
<a name="l00360"></a>00360
<a name="l00361"></a>00361 <span class="keywordflow">if</span> (display) {
<a name="l00362"></a>00362 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html">WText</a> *w = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html">WText</a>(<a class="code" href="classSimpleChatWidget.html#a32a593ed511997f32a33a55d651ce79d">messages_</a>);
<a name="l00363"></a>00363
<a name="l00364"></a>00364 <span class="comment">/*</span>
<a name="l00365"></a>00365 <span class="comment"> * If it fails, it is because the content wasn't valid XHTML</span>
<a name="l00366"></a>00366 <span class="comment"> */</span>
<a name="l00367"></a>00367 <span class="keywordflow">if</span> (!w-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html#a2f788aa524d51b3962642c9f565e66e6">setText</a>(event.<a class="code" href="classChatEvent.html#a459911a1ba1c3e793c6c797e534691b7" title="Get the message formatted as HTML, rendered for the given user.">formattedHTML</a>(<a class="code" href="classSimpleChatWidget.html#a596f7cbf70f45da9af017ac9d6f55ebc">user_</a>, <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#a140dea437d52d3d7c438ea3bd16a1480a847ab5a73b906fea275bd16877b420a4">XHTMLText</a>))) {
<a name="l00368"></a>00368 w-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html#a2f788aa524d51b3962642c9f565e66e6">setText</a>(event.<a class="code" href="classChatEvent.html#a459911a1ba1c3e793c6c797e534691b7" title="Get the message formatted as HTML, rendered for the given user.">formattedHTML</a>(<a class="code" href="classSimpleChatWidget.html#a596f7cbf70f45da9af017ac9d6f55ebc">user_</a>, <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#a140dea437d52d3d7c438ea3bd16a1480ae06bb9ae9a26d13c3dcf9f20d5067885">PlainText</a>));
<a name="l00369"></a>00369 w-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html#af22c64c4c5fed3d2aef0915a7e5c5866">setTextFormat</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#a140dea437d52d3d7c438ea3bd16a1480a847ab5a73b906fea275bd16877b420a4">XHTMLText</a>);
<a name="l00370"></a>00370 }
<a name="l00371"></a>00371
<a name="l00372"></a>00372 w-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#ad0957c892e70c6bf5399cf71e66f3e11">setInline</a>(<span class="keyword">false</span>);
<a name="l00373"></a>00373 w-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#afd3a3b359681111460a93d13979d17dd">setStyleClass</a>(<span class="stringliteral">"chat-msg"</span>);
<a name="l00374"></a>00374
<a name="l00375"></a>00375 <span class="comment">/*</span>
<a name="l00376"></a>00376 <span class="comment"> * Leave no more than 100 messages in the back-log</span>
<a name="l00377"></a>00377 <span class="comment"> */</span>
<a name="l00378"></a>00378 <span class="keywordflow">if</span> (<a class="code" href="classSimpleChatWidget.html#a32a593ed511997f32a33a55d651ce79d">messages_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html#a85abd4d928575717052ff7fa04c3c2c9">count</a>() > 100)
<a name="l00379"></a>00379 <span class="keyword">delete</span> <a class="code" href="classSimpleChatWidget.html#a32a593ed511997f32a33a55d651ce79d">messages_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#a72c4cd4ce0a6ed1ff2d7b6ddf2dbd917">children</a>()[0];
<a name="l00380"></a>00380
<a name="l00381"></a>00381 <span class="comment">/*</span>
<a name="l00382"></a>00382 <span class="comment"> * Little javascript trick to make sure we scroll along with new content</span>
<a name="l00383"></a>00383 <span class="comment"> */</span>
<a name="l00384"></a>00384 app-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#a2a92457b9212cef4057cb54e56183967">doJavaScript</a>(<a class="code" href="classSimpleChatWidget.html#a32a593ed511997f32a33a55d651ce79d">messages_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#aa2b7078b3b43d53a85e5244b45d504f7">jsRef</a>() + <span class="stringliteral">".scrollTop += "</span>
<a name="l00385"></a>00385 + <a class="code" href="classSimpleChatWidget.html#a32a593ed511997f32a33a55d651ce79d">messages_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#aa2b7078b3b43d53a85e5244b45d504f7">jsRef</a>() + <span class="stringliteral">".scrollHeight;"</span>);
<a name="l00386"></a>00386
<a name="l00387"></a>00387 <span class="comment">/* If this message belongs to another user, play a received sound */</span>
<a name="l00388"></a>00388 <span class="keywordflow">if</span> (event.<a class="code" href="classChatEvent.html#adbeff19aece69e75ab0b69f2adecc5b6" title="Get the user who caused the event.">user</a>() != <a class="code" href="classSimpleChatWidget.html#a596f7cbf70f45da9af017ac9d6f55ebc">user_</a> && <a class="code" href="classSimpleChatWidget.html#af877bf2951965ee6832d7c5f5c5f885a">messageReceived_</a>)
<a name="l00389"></a>00389 <a class="code" href="classSimpleChatWidget.html#af877bf2951965ee6832d7c5f5c5f885a">messageReceived_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WSound.html#a6ca6b48ebc9e49ee6745228961df3817">play</a>();
<a name="l00390"></a>00390 }
<a name="l00391"></a>00391
<a name="l00392"></a>00392 <span class="comment">/*</span>
<a name="l00393"></a>00393 <span class="comment"> * This is the server push action: we propagate the updated UI to the client,</span>
<a name="l00394"></a>00394 <span class="comment"> * (when the event was triggered by another user)</span>
<a name="l00395"></a>00395 <span class="comment"> */</span>
<a name="l00396"></a>00396 app-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#a51f50e0641a6d702a7c6ab7f8dd5946a">triggerUpdate</a>();
<a name="l00397"></a>00397 }
</pre></div></div>
</div>
<hr size="1"><address style="text-align: right; margin: 3px"><small>
Generated on Fri Mar 30 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>
|