FormExample Class Reference
[Form example]

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.

00015   : WContainerWidget(parent)
00016 {
00017   WContainerWidget *langLayout = new WContainerWidget(this);
00018   langLayout->setContentAlignment(AlignRight);
00019   new WText(tr("language"), langLayout);
00020 
00021   const char *lang[] = { "en", "nl" };
00022 
00023   for (int i = 0; i < 2; ++i) {
00024     WText *t = new WText(widen(lang[i]), langLayout);
00025     t->setMargin(5);
00026     t->clicked().connect(SLOT(this, FormExample::changeLanguage));
00027 
00028     languageSelects_.push_back(t);
00029   }
00030 
00031   /*
00032    * Start with the reported locale, if available
00033    */
00034   setLanguage(wApp->locale());
00035 
00036   Form *form = new Form(this);
00037   form->setMargin(20);
00038 }


Member Function Documentation

void FormExample::changeLanguage (  )  [private]

Change the language.

Definition at line 62 of file FormExample.C.

00063 {
00064   WText *t = (WText *)sender();
00065   setLanguage(narrow(t->text().value()));
00066 }

void FormExample::setLanguage ( const std::string  lang  )  [private]

Definition at line 40 of file FormExample.C.

00041 {
00042   bool haveLang = false;
00043 
00044   for (unsigned i = 0; i < languageSelects_.size(); ++i) {
00045     WText *t = languageSelects_[i];
00046 
00047     // prefix match, e.g. en matches en-us.
00048     bool isLang = lang.find(narrow(t->text().value())) == 0;
00049     t->setStyleClass(isLang ? L"langcurrent" : L"lang");
00050 
00051     haveLang = haveLang || isLang;
00052   }
00053 
00054   if (!haveLang) {
00055     languageSelects_[0]->setStyleClass(L"langcurrent");
00056     WApplication::instance()
00057       ->setLocale(narrow(languageSelects_[0]->text().value()));
00058   } else
00059     WApplication::instance()->setLocale(lang);
00060 }


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 Thu May 20 18:14:57 2010 for Wt by doxygen 1.5.6