10 #include <Wt/WApplication> 11 #include <Wt/WContainerWidget> 12 #include <Wt/WEnvironment> 13 #include <Wt/WInPlaceEdit> 14 #include <Wt/WHBoxLayout> 15 #include <Wt/WVBoxLayout> 17 #include <Wt/WLineEdit> 18 #include <Wt/WTemplate> 20 #include <Wt/WTextArea> 21 #include <Wt/WPushButton> 22 #include <Wt/WCheckBox> 29 Wt::WContainerWidget *parent)
30 : WContainerWidget(parent),
50 Wt::WApplication::instance()->enableUpdates(
true);
56 Wt::WApplication::instance()->enableUpdates(
false);
63 WVBoxLayout *vLayout =
new WVBoxLayout();
66 WHBoxLayout *hLayout =
new WHBoxLayout();
67 vLayout->addLayout(hLayout, 0, AlignTop | AlignLeft);
69 hLayout->addWidget(
new WLabel(
"User name:"), 0, AlignMiddle);
73 WPushButton *b =
new WPushButton(
"Login");
74 hLayout->addWidget(b, 0, AlignMiddle);
92 statusMsg_->setText(
"Sorry, name '" + escapeText(name) +
93 "' is already taken.");
109 WWidget *messageEdit,
110 WWidget *sendButton, WWidget *logoutButton)
130 WVBoxLayout *vLayout =
new WVBoxLayout();
133 WHBoxLayout *hLayout =
new WHBoxLayout();
136 hLayout->addWidget(messages, 1);
137 messages->setStyleClass(
"chat-msgs");
140 hLayout->addWidget(userList);
141 userList->setStyleClass(
"chat-users");
143 hLayout->setResizable(0,
true);
146 vLayout->addLayout(hLayout, 1);
149 vLayout->addWidget(messageEdit);
150 messageEdit->setStyleClass(
"chat-noedit");
153 hLayout =
new WHBoxLayout();
156 hLayout->addWidget(sendButton);
159 hLayout->addWidget(logoutButton);
162 vLayout->addLayout(hLayout, 0, AlignLeft);
174 if (flags & RenderFull) {
178 doJavaScript(
"setTimeout(function() { " 180 +
messages_->jsRef() +
".scrollHeight;}, 0);");
184 WContainerWidget::render(flags);
209 messages_->setOverflow(WContainerWidget::OverflowAuto);
210 userList_->setOverflow(WContainerWidget::OverflowAuto);
213 WPushButton *logoutButton =
new WPushButton(
"Logout");
231 (
"function(o, e) { setTimeout(function() {" 244 WApplication::instance()->setConnectionMonitor(
246 "'onChange':function(type, newV) {" 247 "var connected = window.monitor.status.connectionStatus != 0;" 253 +
messageEdit_->jsRef() +
".placeholder='connection lost';" 275 WInPlaceEdit *nameEdit =
new WInPlaceEdit();
276 nameEdit->addStyleClass(
"name-edit");
277 nameEdit->setButtonsEnabled(
false);
278 nameEdit->setText(
user_);
281 WTemplate *joinMsg =
new WTemplate(tr(
"join-msg.template"),
messages_);
282 joinMsg->bindWidget(
"name", nameEdit);
283 joinMsg->setStyleClass(
"chat-msg");
295 if (!logoutButton->parent())
329 for (SimpleChatServer::UserSet::iterator i = users.begin();
330 i != users.end(); ++i) {
331 WCheckBox *w =
new WCheckBox(escapeText(*i),
userList_);
334 UserMap::const_iterator j = oldUsers.find(*i);
335 if (j != oldUsers.end())
336 w->setChecked(j->second);
340 users_[*i] = w->isChecked();
344 w->setStyleClass(
"chat-self");
354 WCheckBox *b =
dynamic_cast<WCheckBox *
>(sender());
355 users_[b->text()] = b->isChecked();
360 WApplication *app = WApplication::instance();
392 app->triggerUpdate();
414 w->setTextFormat(XHTMLText);
418 w->setStyleClass(
"chat-msg");
429 app->doJavaScript(
messages_->jsRef() +
".scrollTop += " 430 +
messages_->jsRef() +
".scrollHeight;");
Type type() const
Get the event type.
void sendMessage(const Wt::WString &user, const Wt::WString &message)
Send a message on behalve of a user.
const Wt::WString & data() const
Get the extra data for this event.
bool connect(Client *client, const ChatEventCallback &handleEvent)
Connects to the chat server.
Encapsulate a chat event.
UserSet users()
Get the users currently logged in.
std::set< Wt::WString > UserSet
Typedef for a collection of user names.
bool changeName(const Wt::WString &user, const Wt::WString &newUser)
Changes the name.
Wt::WString suggestGuest()
Get a suggestion for a guest user name.
bool login(const Wt::WString &user)
Try to login with given user name.
bool disconnect(Client *client)
Disconnect from the chat server.
void logout(const Wt::WString &user)
Logout from the server.
const Wt::WString formattedHTML(const Wt::WString &user, Wt::TextFormat format) const
Get the message formatted as HTML, rendered for the given user.
const Wt::WString & user() const
Get the user who caused the event.