Hey,

2011/6/16 Graeme Gill <[email protected]>:
>> +     m_body->setStyleClass("text");
>> +     styleSheet().addRule(".text", "overflow: auto;");
>
> Hmm. I'm afraid this doesn't work for me. With JavaScript enabled, I don't
> get a scroll bar when I narrow the window. I'm not sure how I would discover
> this approach either, since it goes outside the toolkit API and starts
> messing with CSS, something I'm trying to avoid, and one of the reasons I'm
> interested in using Wt.

I've double checked this solution really works as expected. You will
only get a vertical scrollbar since the text wraps horizontally. Can
you provide a screenshot of the wrong behaviour ?

As to the API usage, I believe the situation is a bit artificial.
Usually you will add a WContainerWidget to the layout (when the
application is more complex), which gets the scrollbar if its contents
(which could be the text or any combination of widgets) starts
overflowing, and then you can use the API (setOverflow()) to achieve
the same effect as the CSS declarations supra. We should probably add
this method also to WText which is kind of the exception as a basic
widget which may benefit from scrollbars. The attached test-case shows
a solution without CSS.

As to CSS, in many scenarios, designers (which are all too familiar
with CSS) will be responsible for styling an application and then this
is a benefit. I also believe it works well when you limit your usage
of CSS to decorative aspects rather than layout.

But I agree that CSS appears deceptively simple but is in fact rather
complex, and the more so with browser quirks.

Regards,
koen
/*
 * Copyright (C) 2008 Emweb bvba, Heverlee, Belgium.
 *
 * See the LICENSE file for terms of use.
 */

#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WHBoxLayout>
#include <Wt/WVBoxLayout>
#include <Wt/WText>
#include <Wt/WImage>

// c++0x only, for std::bind
// #include <functional>

using namespace Wt;

/*
 * A simple hello world application class which demonstrates how to react
 * to events, read input, and give feed-back.
 */
class HelloApplication : public WApplication
{
public:
  HelloApplication(const WEnvironment& env);

private:
	
	WHBoxLayout *m_layout;		// Horizontal layout

	WContainerWidget *m_vstrip;	// Left vertical graphical strip

	WText  *m_body;				// Right body text
};

/*
 * The env argument contains information about the new session, and
 * the initial request. It must be passed to the WApplication
 * constructor so it is typically also an argument for your custom
 * application constructor.
*/
HelloApplication::HelloApplication(const WEnvironment& env)
  : WApplication(env)
{
	// Create the horizontal Layout
	m_layout = new WHBoxLayout();

	root()->setLayout(m_layout);

	// Make it scroll if the text overflows 
	// The left hand vertical graphic strip
	m_vstrip = new WContainerWidget();
	m_vstrip->decorationStyle().setBackgroundImage("vstrip.jpg",
                   Wt::WCssDecorationStyle::RepeatY);

	// If we don't set a minimum size, the strip vanishes
	m_vstrip->setMinimumSize(Wt::WLength("40px"), Wt::WLength("1px"));

	m_layout->addWidget(m_vstrip, 0);	// Minimize strip width

	// Some text to the right of the graphical strip
	m_body = new WText("The first line starts here. xxxxxxxxxxxxxxx"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The last line ends here. xxxxxxxxxxxxxxxxxx");

	WContainerWidget *bb = new WContainerWidget();
	bb->setOverflow(WContainerWidget::OverflowAuto);
	bb->addWidget(m_body);

	m_layout->addWidget(bb, 1);	// Maximize text width
}

WApplication *createApplication(const WEnvironment& env)
{
  /*
   * You could read information from the environment to decide whether
   * the user has permission to start a new application
   */
  return new HelloApplication(env);
}

int main(int argc, char **argv)
{
  /*
   * Your main method may set up some shared resources, but should then
   * start the server application (FastCGI or httpd) that starts listening
   * for requests, and handles all of the application life cycles.
   *
   * The last argument to WRun specifies the function that will instantiate
   * new application objects. That function is executed when a new user surfs
   * to the Wt application, and after the library has negotiated browser
   * support. The function should return a newly instantiated application
   * object.
   */
  return WRun(argc, argv, &createApplication);
}

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to