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");
230 (
"function(o, e) { setTimeout(function() {"
250 WInPlaceEdit *nameEdit =
new WInPlaceEdit();
251 nameEdit->addStyleClass(
"name-edit");
252 nameEdit->setButtonsEnabled(
false);
253 nameEdit->setText(
user_);
256 WTemplate *joinMsg =
new WTemplate(tr(
"join-msg.template"),
messages_);
257 joinMsg->bindWidget(
"name", nameEdit);
258 joinMsg->setStyleClass(
"chat-msg");
270 if (!logoutButton->parent())
304 for (SimpleChatServer::UserSet::iterator i = users.begin();
305 i != users.end(); ++i) {
306 WCheckBox *w =
new WCheckBox(escapeText(*i),
userList_);
309 UserMap::const_iterator j = oldUsers.find(*i);
310 if (j != oldUsers.end())
311 w->setChecked(j->second);
315 users_[*i] = w->isChecked();
319 w->setStyleClass(
"chat-self");
329 WCheckBox *b =
dynamic_cast<WCheckBox *
>(sender());
330 users_[b->text()] = b->isChecked();
335 WApplication *app = WApplication::instance();
367 app->triggerUpdate();
389 w->setTextFormat(XHTMLText);
393 w->setStyleClass(
"chat-msg");
404 app->doJavaScript(
messages_->jsRef() +
".scrollTop += "
405 +
messages_->jsRef() +
".scrollHeight;");
void sendMessage(const Wt::WString &user, const Wt::WString &message)
Send a message on behalve of a user.
bool connect(Client *client, const ChatEventCallback &handleEvent)
Connects to the chat server.
Encapsulate a chat event.
const Wt::WString formattedHTML(const Wt::WString &user, Wt::TextFormat format) const
Get the message formatted as HTML, rendered for the given user.
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 & user() const
Get the user who caused the event.
Type type() const
Get the event type.
const Wt::WString & data() const
Get the extra data for this event.