Project

General

Profile

Support #1001 ยป proba.cpp

Anonymous, 09/26/2011 05:01 PM

 
#include <Wt/WApplication>
#include <Wt/WBreak>
#include <Wt/WContainerWidget>
#include <Wt/WLineEdit>
#include <Wt/WPushButton>
#include <Wt/WText>
#include <Wt/WScrollArea>
#include <Wt/WScrollBar>

#include <stdlib.h>

using namespace Wt;
using namespace std;

class HelloApplication : public WApplication {
public:
HelloApplication(const WEnvironment& env);

private:
WLineEdit *edit_;
WText *greeting_;
WScrollArea *sa;
WScrollArea *sb;
WContainerWidget *a, *b;
void greet();
};

HelloApplication::HelloApplication(const WEnvironment& env) : WApplication(env) {
setTitle("Hello world");
sa = new WScrollArea();
sb = new WScrollArea();
root()->addWidget( sa );
root()->addWidget( sb );
sa->setWidth( 100 );
sa->setHeight( 100 );
sb->setWidth( 100 );
sb->setHeight( 100 );
sa->horizontalScrollBar()->tie( sa->verticalScrollBar(), sb->verticalScrollBar() );
a = new WContainerWidget();
b = new WContainerWidget();
sa->setWidget( a );
sb->setWidget( b );
for (int i=0; i<100; i++) {
stringstream ss;
ss << i << endl;
a->addWidget( new WText( ss.str() ) );
a->addWidget(new WBreak());
b->addWidget( new WText( ss.str() ) );
b->addWidget(new WBreak());
}


edit_ = new WLineEdit( root() );
WPushButton *p = new WPushButton("set", root());
p->clicked().connect(this, &HelloApplication::greet);
edit_->enterPressed().connect(boost::bind(&HelloApplication::greet, this));
}

void HelloApplication::greet() {
cerr << "setting value" << endl;
sa->verticalScrollBar()->setValue( atoi(edit_->text().narrow().c_str()) );
}

WApplication *createApplication(const WEnvironment& env) {
return new HelloApplication(env);
}

int main(int argc, char **argv) {
return WRun(argc, argv, &createApplication);
}


    (1-1/1)