Wt examples 3.1.10
Public Member Functions | Private Member Functions | Private Attributes
AddresseeEdit Class Reference

An edit field for an email addressee. More...

#include <AddresseeEdit.h>

Inheritance diagram for AddresseeEdit:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 AddresseeEdit (const WString &label, WContainerWidget *parent, WContainerWidget *labelParent)
 Create a new addressee edit with the given label.
void setAddressees (const std::vector< Contact > &contacts)
 Set a list of addressees.
std::vector< Contactaddressees () const
 Get a list of addressees.
virtual void setHidden (bool hidden, const WAnimation &animation)
 Reimplement hide() and show() to also hide() and show() the label.

Private Member Functions

bool parse (std::vector< Contact > &contacts) const
 Parse the addressees into a list of contacts.

Private Attributes

Labellabel_
 The label associated with this edit.

Detailed Description

An edit field for an email addressee.

This widget is part of the Wt composer example.

Definition at line 31 of file AddresseeEdit.h.


Constructor & Destructor Documentation

AddresseeEdit::AddresseeEdit ( const WString label,
WContainerWidget parent,
WContainerWidget labelParent 
)

Create a new addressee edit with the given label.

Constructs also a widget to hold the label in the labelParent. The label will be hidden and shown together with this field.

Definition at line 15 of file AddresseeEdit.C.

  : WTextArea(parent)
{
  label_ = new Label(label, labelParent);

  setRows(3); setColumns(55);
  resize(WLength(99, WLength::Percentage), WLength::Auto);

  setInline(false); // for IE to position the suggestions well
}

Member Function Documentation

std::vector< Contact > AddresseeEdit::addressees ( ) const

Get a list of addressees.

Definition at line 74 of file AddresseeEdit.C.

{
  std::vector<Contact> result;
  parse(result);

  return result;
}
bool AddresseeEdit::parse ( std::vector< Contact > &  contacts) const [private]

Parse the addressees into a list of contacts.

Definition at line 40 of file AddresseeEdit.C.

{
  typedef boost::tokenizer<boost::escaped_list_separator<wchar_t>,
                           std::wstring::const_iterator, std::wstring>
    CsvTokenizer;

  std::wstring t = text();
  CsvTokenizer tok(t);
  
  for (CsvTokenizer::iterator i = tok.begin(); i != tok.end(); ++i) {
    std::wstring addressee = *i;

    boost::trim(addressee);
    std::wstring::size_type pos = addressee.find_last_of(' ');
    if (pos != std::string::npos) {
      std::wstring email = addressee.substr(pos + 1);
      std::wstring name = addressee.substr(0, pos);

      boost::trim(email);
      boost::trim(name);
      if (email[0] == '<')
        email = email.substr(1);
      if (email[email.length() - 1] == '>')
        email = email.substr(0, email.length() - 1);

      if (!email.empty())
        contacts.push_back(Contact(name, email));
    } else
      if (!addressee.empty())
        contacts.push_back(Contact(L"", addressee));
  }
  return true;
}
void AddresseeEdit::setAddressees ( const std::vector< Contact > &  contacts)

Set a list of addressees.

Definition at line 27 of file AddresseeEdit.C.

{
  std::wstring text;

  for (unsigned i = 0; i < contacts.size(); ++i) {
    if (i != 0)
      text += L", ";
    text += contacts[i].formatted();
  }

  setText(text);
}
void AddresseeEdit::setHidden ( bool  hidden,
const WAnimation animation 
) [virtual]

Reimplement hide() and show() to also hide() and show() the label.

Reimplemented from Wt::WFormWidget.

Definition at line 82 of file AddresseeEdit.C.

{
  WTextArea::setHidden(hidden, animation);
  label_->setHidden(hidden, animation);
}

Member Data Documentation

The label associated with this edit.

Definition at line 55 of file AddresseeEdit.h.


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

Generated on Mon Nov 14 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.4