Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes

PopupChatWidget Class Reference
[Chat example]

A popup chat widget. More...

#include <PopupChatWidget.h>

Inheritance diagram for PopupChatWidget:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 PopupChatWidget (SimpleChatServer &server)
void setName (const Wt::WString &name)

Protected Member Functions

virtual void createLayout (Wt::WWidget *messages, Wt::WWidget *userList, Wt::WWidget *messageEdit, Wt::WWidget *sendButton, Wt::WWidget *logoutButton)
virtual void updateUsers ()

Private Member Functions

void toggleSize ()
void minimize ()
void maximize ()
Wt::WContainerWidgetcreateBar ()

Private Attributes

Wt::WString name_
Wt::WTexttitle_
bool online_

Detailed Description

A popup chat widget.

Definition at line 20 of file PopupChatWidget.h.


Constructor & Destructor Documentation

PopupChatWidget::PopupChatWidget ( SimpleChatServer server )

Definition at line 20 of file PopupChatWidget.C.

  : SimpleChatWidget(server)
{
  if (Wt::WApplication::instance()->environment().agentIsIE()) {
    if (Wt::WApplication::instance()->environment().agent() == Wt::WEnvironment::IE6)
      setPositionScheme(Wt::Absolute);
    else
      setPositionScheme(Wt::Fixed);
  }

  online_ = false;

  minimize();
}

Member Function Documentation

Wt::WContainerWidget * PopupChatWidget::createBar (  ) [private]

Definition at line 62 of file PopupChatWidget.C.

{
  Wt::WContainerWidget *bar = new Wt::WContainerWidget();
  bar->setStyleClass("chat-bar");

  Wt::WText *toggleButton = new Wt::WText();
  toggleButton->setInline(false);
  toggleButton->setStyleClass("chat-minmax");
  bar->clicked().connect(this, &PopupChatWidget::toggleSize);

  bar->addWidget(toggleButton);

  title_ = new Wt::WText(bar);

  return bar;
}
void PopupChatWidget::createLayout ( Wt::WWidget messages,
Wt::WWidget userList,
Wt::WWidget messageEdit,
Wt::WWidget sendButton,
Wt::WWidget logoutButton 
) [protected, virtual]

Reimplemented from SimpleChatWidget.

Definition at line 87 of file PopupChatWidget.C.

{
  Wt::WVBoxLayout *layout = new Wt::WVBoxLayout();
  layout->setContentsMargins(0, 0, 0, 0);
  layout->setSpacing(0);

  Wt::WContainerWidget *bar = createBar();

  layout->addWidget(bar);
  layout->addWidget(messages, 1);
  layout->addWidget(messageEdit);

  setLayout(layout);
}
void PopupChatWidget::maximize (  ) [private]

Definition at line 119 of file PopupChatWidget.C.

{
  if (!online_) {
    online_ = true;

    int tries = 1;
    Wt::WString name = name_;
    if (name.empty())
      name = server().suggestGuest();

    while (!startChat(name)) {
      if (name_.empty())
        name = server().suggestGuest();
      else
        name = name_ + boost::lexical_cast<std::string>(++tries);
    }

    name_ = name;
  }

  setStyleClass("chat-widget chat-maximized");
}
void PopupChatWidget::minimize (  ) [private]

Definition at line 51 of file PopupChatWidget.C.

{
  if (!online_) {
    clear();
    addWidget(createBar());
    title_->setText("Thoughts? Ventilate.");
  }

  setStyleClass("chat-widget chat-minimized");
}
void PopupChatWidget::setName ( const Wt::WString name )

Definition at line 35 of file PopupChatWidget.C.

{
  if (name.empty())
    return;

  if (online_) {
    int tries = 1;
    Wt::WString n = name;
    while (!server().changeName(name_, n))
      n = name + boost::lexical_cast<std::string>(++tries);

    name_ = n;
  } else
    name_ = name;
}
void PopupChatWidget::toggleSize (  ) [private]

Definition at line 79 of file PopupChatWidget.C.

{
  if (styleClass() == "chat-widget chat-minimized")
    maximize();
  else
    minimize();
}
void PopupChatWidget::updateUsers (  ) [protected, virtual]

Reimplemented from SimpleChatWidget.

Definition at line 106 of file PopupChatWidget.C.

{
  SimpleChatWidget::updateUsers();

  int count = server().users().size();

  if (count == 1)
    title_->setText("Chat: 1 user online");
  else
    title_->setText("Chat: "
                    + boost::lexical_cast<std::string>(count) + " users online");
}

Member Data Documentation

Definition at line 35 of file PopupChatWidget.h.

bool PopupChatWidget::online_ [private]

Definition at line 37 of file PopupChatWidget.h.

Definition at line 36 of file PopupChatWidget.h.


The documentation for this class was generated from the following files:

Generated on Fri Jul 8 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.2