Wt examples 3.3.12
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
17namespace Wt {
18 class WApplication;
19 class WPushButton;
20 class WText;
21 class WLineEdit;
22 class WTextArea;
23}
24
25class ChatEvent;
26
31
36{
37public:
41
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
63
64 int userCount() { return users_.size(); }
65
66 const Wt::WString& userName() const { return user_; }
67
68protected:
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
78protected:
79 bool loggedIn() const;
80
81private:
82 typedef std::map<Wt::WString, bool> UserMap;
84
87
89
91
94
99
101
102 void login();
103 void changeName(const Wt::WString& name);
104 void send();
105 void updateUser();
106
107 /* called from another session */
108 void processChatEvent(const ChatEvent& event);
109};
110
113#endif // SIMPLECHATWIDGET
Encapsulate a chat event.
A simple chat server.
A self-contained chat widget.
bool startChat(const Wt::WString &user)
Start a chat for the given user.
virtual void updateUsers()
SimpleChatServer & server()
Wt::WContainerWidget * messages_
Wt::WTextArea * messageEdit_
Wt::WLineEdit * userNameEdit_
void letLogin()
Show a simple login screen.
bool loggedIn() const
Wt::WText * statusMsg_
virtual void render(Wt::WFlags< Wt::RenderFlag > flags)
Wt::WPushButton * sendButton_
virtual void createLayout(Wt::WWidget *messages, Wt::WWidget *userList, Wt::WWidget *messageEdit, Wt::WWidget *sendButton, Wt::WWidget *logoutButton)
SimpleChatServer & server_
virtual void newMessage()
void changeName(const Wt::WString &name)
const Wt::WString & userName() const
void processChatEvent(const ChatEvent &event)
std::map< Wt::WString, bool > UserMap
Wt::WContainerWidget * userList_
Wt::WSound * messageReceived_
~SimpleChatWidget()
Delete a chat widget.
WWidget * parent() const

Generated on Fri May 17 2024 for the C++ Web Toolkit (Wt) by doxygen 1.9.8