Wt examples  3.3.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
FormExample Class Reference

Main widget for the Form example. More...

#include <FormExample.h>

Inheritance diagram for FormExample:
Inheritance graph
[legend]

Public Member Functions

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

Private Member Functions

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

Private Attributes

std::vector< WText * > languageSelects_
 

Additional Inherited Members

- Protected Member Functions inherited from Wt::WWidget
virtual void enableAjax ()=0
 
virtual void propagateSetEnabled (bool enabled)=0
 
virtual void render (WFlags< RenderFlag > flags)
 

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.

15  : WContainerWidget(parent)
16 {
17  WContainerWidget *langLayout = new WContainerWidget(this);
18  langLayout->setContentAlignment(AlignRight);
19  new WText(tr("language"), langLayout);
20 
21  const char *lang[] = { "en", "nl" };
22 
23  for (int i = 0; i < 2; ++i) {
24  WText *t = new WText(widen(lang[i]), langLayout);
25  t->setMargin(5);
26  t->clicked().connect(this, &FormExample::changeLanguage);
27 
28  languageSelects_.push_back(t);
29  }
30 
31  /*
32  * Start with the reported locale, if available
33  */
34  setLanguage(wApp->locale().name());
35 
36  Form *form = new Form(this);
37  form->setMargin(20);
38 }

Member Function Documentation

void FormExample::changeLanguage ( )
private

Change the language.

Definition at line 62 of file FormExample.C.

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

Definition at line 40 of file FormExample.C.

41 {
42  bool haveLang = false;
43 
44  for (unsigned i = 0; i < languageSelects_.size(); ++i) {
45  WText *t = languageSelects_[i];
46 
47  // prefix match, e.g. en matches en-us.
48  bool isLang = lang.find(narrow(t->text().value())) == 0;
49  t->setStyleClass(isLang ? L"langcurrent" : L"lang");
50 
51  haveLang = haveLang || isLang;
52  }
53 
54  if (!haveLang) {
55  languageSelects_[0]->setStyleClass(L"langcurrent");
56  WApplication::instance()
57  ->setLocale(narrow(languageSelects_[0]->text().value()));
58  } else
59  WApplication::instance()->setLocale(lang);
60 }

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 May 31 2013 for the C++ Web Toolkit (Wt) by doxygen 1.8.3.1