Wt examples  3.2.1
Public Member Functions | Private Member Functions | Private Attributes
FormExample Class Reference

Main widget for the Form example. More...

#include <FormExample.h>

Inheritance diagram for FormExample:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 FormExample (WContainerWidget *parent=0)
 Instantiate a new form example.

Private Member Functions

void changeLanguage ()
 Change the language.
void setLanguage (const std::string lang)

Private Attributes

std::vector< WText * > languageSelects_

Detailed Description

Main widget for the Form example.

This class demonstrates, next instantiating the form itself, handling of different languages.

Definition at line 29 of file FormExample.h.


Constructor & Destructor Documentation

FormExample::FormExample ( WContainerWidget parent = 0)

Instantiate a new form example.

Definition at line 14 of file FormExample.C.

  : WContainerWidget(parent)
{
  WContainerWidget *langLayout = new WContainerWidget(this);
  langLayout->setContentAlignment(AlignRight);
  new WText(tr("language"), langLayout);

  const char *lang[] = { "en", "nl" };

  for (int i = 0; i < 2; ++i) {
    WText *t = new WText(widen(lang[i]), langLayout);
    t->setMargin(5);
    t->clicked().connect(this, &FormExample::changeLanguage);

    languageSelects_.push_back(t);
  }

  /*
   * Start with the reported locale, if available
   */
  setLanguage(wApp->locale());

  Form *form = new Form(this);
  form->setMargin(20);
}

Member Function Documentation

void FormExample::changeLanguage ( ) [private]

Change the language.

Definition at line 62 of file FormExample.C.

{
  WText *t = (WText *)sender();
  setLanguage(narrow(t->text().value()));
}
void FormExample::setLanguage ( const std::string  lang) [private]

Definition at line 40 of file FormExample.C.

{
  bool haveLang = false;

  for (unsigned i = 0; i < languageSelects_.size(); ++i) {
    WText *t = languageSelects_[i];

    // prefix match, e.g. en matches en-us.
    bool isLang = lang.find(narrow(t->text().value())) == 0;
    t->setStyleClass(isLang ? L"langcurrent" : L"lang");

    haveLang = haveLang || isLang;
  }

  if (!haveLang) {
    languageSelects_[0]->setStyleClass(L"langcurrent");
    WApplication::instance()
      ->setLocale(narrow(languageSelects_[0]->text().value()));
  } else
    WApplication::instance()->setLocale(lang);
}

Member Data Documentation

std::vector<WText *> FormExample::languageSelects_ [private]

Definition at line 37 of file FormExample.h.


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

Generated on Fri Mar 30 2012 for the C++ Web Toolkit (Wt) by doxygen 1.7.5.1