Wt examples
3.3.0
Main Page
Modules
Namespaces
Classes
Files
File List
File Members
build
buildd
witty-3.3.0
examples
simplechat
SimpleChatWidget.h
Go to the documentation of this file.
1
// This may look like C code, but it's really -*- C++ -*-
2
/*
3
* Copyright (C) 2008 Emweb bvba, Heverlee, Belgium.
4
*
5
* See the LICENSE file for terms of use.
6
*/
7
8
#ifndef SIMPLECHATWIDGET_H_
9
#define SIMPLECHATWIDGET_H_
10
11
#include <Wt/WContainerWidget>
12
#include <Wt/WJavaScript>
13
#include <Wt/WSound>
14
15
#include "
SimpleChatServer.h
"
16
17
namespace
Wt {
18
class
WApplication;
19
class
WPushButton;
20
class
WText;
21
class
WLineEdit;
22
class
WTextArea;
23
}
24
25
class
ChatEvent
;
26
31
34
class
SimpleChatWidget
:
public
Wt::WContainerWidget
,
35
public
SimpleChatServer::Client
36
{
37
public
:
40
SimpleChatWidget
(
SimpleChatServer
&
server
,
Wt::WContainerWidget
*parent = 0);
41
44
~SimpleChatWidget
();
45
46
void
connect
();
47
void
disconnect
();
48
49
52
void
letLogin
();
53
58
bool
startChat
(
const
Wt::WString
& user);
59
60
void
logout
();
61
62
SimpleChatServer
&
server
() {
return
server_
; }
63
64
int
userCount
() {
return
users_
.size(); }
65
66
const
Wt::WString
&
userName
()
const
{
return
user_
; }
67
68
protected
:
69
virtual
void
createLayout
(
Wt::WWidget
*messages,
Wt::WWidget
*userList,
70
Wt::WWidget
*messageEdit,
71
Wt::WWidget
*sendButton,
Wt::WWidget
*logoutButton);
72
73
virtual
void
updateUsers
();
74
virtual
void
newMessage
();
75
76
virtual
void
render
(Wt::WFlags<Wt::RenderFlag> flags);
77
78
protected
:
79
bool
loggedIn
()
const
;
80
81
private
:
82
typedef
std::map<Wt::WString, bool>
UserMap
;
83
UserMap
users_
;
84
85
SimpleChatServer
&
server_
;
86
bool
loggedIn_
;
87
88
Wt::JSlot
clearInput_
;
89
90
Wt::WString
user_
;
91
92
Wt::WLineEdit
*
userNameEdit_
;
93
Wt::WText
*
statusMsg_
;
94
95
Wt::WContainerWidget
*
messages_
;
96
Wt::WContainerWidget
*
messageEditArea_
;
97
Wt::WTextArea
*
messageEdit_
;
98
Wt::WPushButton
*
sendButton_
;
99
Wt::WContainerWidget
*
userList_
;
100
101
Wt::WSound
*
messageReceived_
;
102
103
void
login
();
104
void
send
();
105
void
updateUser
();
106
107
/* called from another session */
108
void
processChatEvent
(
const
ChatEvent
& event);
109
};
110
113
#endif // SIMPLECHATWIDGET
Generated on Fri May 31 2013 for
the C++ Web Toolkit (Wt)
by
1.8.3.1