performance enhancements for layouts

This commit is contained in:
Peter Schojer 2008-09-17 10:19:40 +00:00
parent b8489e9df1
commit 737331da3a
7 changed files with 56 additions and 138 deletions

View File

@ -45,6 +45,7 @@
namespace Poco {
namespace WebWidgets {
class GridLayout;
namespace ExtJS {
@ -60,6 +61,8 @@ public:
void renderHead(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr);
/// Emits code for the page header to the given output stream.
void renderParameters(const GridLayout* pLayout, const RenderContext& context, std::ostream& ostr);
};

View File

@ -45,6 +45,7 @@
namespace Poco {
namespace WebWidgets {
class HorizontalLayout;
namespace ExtJS {
@ -60,6 +61,8 @@ public:
void renderHead(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr);
/// Emits code for the page header to the given output stream.
void renderParameters(const HorizontalLayout* pLayout, const RenderContext& context, std::ostream& ostr);
};

View File

@ -66,16 +66,9 @@ public:
/// Emits code for the page body to the given output stream.
protected:
void renderLayoutHead(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, const std::string& layoutId, const std::string& layoutConfig, int cols, int horPad, int vertPad);
/// layoutId contains the id for the layout parameter (e.g. table for GridLayoutRenderer)
/// layoutConfig contains the string for the layoutConfig parameter (e.g. {columns:3})
/// htmlPadding contains the optional padding string to use, e.g.:'<p class=\"lbl\" style=\"padding-left:10px\">&nbsp;</p>'
void renderLayout(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, std::size_t cols, int padHorVal, int padVertVal);
void renderParameters(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, const std::string& layoutId, const std::string& layoutConfig, int cols, int horPad, int vertPad);
/// Render the config parameters
void visitChildren(const Layout* pLayout, int cols, int horPad, int vertPad, const RenderContext& context, std::ostream& ostr);
/// Visits children
void renderParameters(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, std::size_t cols, int padHorVal, int padVertVal);
};

View File

@ -37,6 +37,8 @@
#include "Poco/WebWidgets/ExtJS/GridLayoutRenderer.h"
#include "Poco/WebWidgets/ExtJS/Utility.h"
#include "Poco/WebWidgets/GridLayout.h"
#include "Poco/WebWidgets/Frame.h"
#include "Poco/WebWidgets/Panel.h"
#include <sstream>
@ -60,19 +62,8 @@ void GridLayoutRenderer::renderHead(const Renderable* pRenderable, const RenderC
poco_assert_dbg (pRenderable != 0);
poco_assert_dbg (pRenderable->type() == typeid(Poco::WebWidgets::GridLayout));
const GridLayout* pLayout = static_cast<const Poco::WebWidgets::GridLayout*>(pRenderable);
std::size_t cols = pLayout->columns();
int padHorVal = pLayout->getHorizontalPadding();
int padVertVal = pLayout->getVerticalPadding();
std::string padding;
if (padHorVal > 0)
{
cols = 2 * cols - 1;
}
std::ostringstream layoutConfig;
layoutConfig << "{columns:" << cols << "}";
std::string layout("table");
// when padding is used we can no longer use LayoutRenderer
LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig.str(), (int)cols, padHorVal, padVertVal);
renderLayout(pLayout, context, ostr, pLayout->columns(), pLayout->getHorizontalPadding(), pLayout->getVerticalPadding());
}

View File

@ -60,19 +60,8 @@ void HorizontalLayoutRenderer::renderHead(const Renderable* pRenderable, const R
poco_assert_dbg (pRenderable != 0);
poco_assert_dbg (pRenderable->type() == typeid(Poco::WebWidgets::HorizontalLayout));
const HorizontalLayout* pLayout = static_cast<const Poco::WebWidgets::HorizontalLayout*>(pRenderable);
std::ostringstream layoutConfig;
std::size_t cols = pLayout->size();
int padVal = pLayout->getPadding();
if (padVal > 0)
{
cols = 2 * cols - 1;
}
layoutConfig << "{columns:" << cols << "}";
static std::string layout("table");
//static std::string layout("column"); -> this works with firefox but fails with IE7!
LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig.str(), (int)cols, padVal, 0);
renderLayout(pLayout, context, ostr, pLayout->size(), pLayout->getPadding(), 0);
}

View File

@ -59,30 +59,6 @@ LayoutRenderer::~LayoutRenderer()
}
void LayoutRenderer::renderLayoutHead(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, const std::string& layoutId, const std::string& layoutConfig, int cols, int horPad, int vertPad)
{
poco_assert_dbg(pLayout != 0);
Renderable::ID id(0);
View::Ptr ptrParent = pLayout->parent();
if (!(ptrParent && (ptrParent.cast<Frame>() || ptrParent.cast<Panel>())))
{
// the parent is not a panel
// assume that the direct parent is a panel
ostr << "new Ext.Panel({border:false,bodyBorder:false,";
ostr << "id:'" << pLayout->id() << "',";
if (!pLayout->isVisible())
ostr << "hidden:true,";
renderParameters(pLayout, context, ostr, layoutId, layoutConfig, cols, horPad, vertPad);
ostr << "})";
}
else
{
renderParameters(pLayout, context, ostr, layoutId, layoutConfig, cols, horPad, vertPad);
}
}
void LayoutRenderer::renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr)
{
const Layout* pLayout = static_cast<const Layout*>(pRenderable);
@ -95,92 +71,64 @@ void LayoutRenderer::renderBody(const Renderable* pRenderable, const RenderConte
}
void LayoutRenderer::renderParameters(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, const std::string& layoutId, const std::string& layoutConfig, int cols, int horPad, int vertPad)
void LayoutRenderer::renderLayout(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, std::size_t cols, int padHorVal, int padVertVal)
{
poco_assert_dbg(pLayout != 0);
bool writeComma = false;
if (pLayout->getWidth() > 0)
ostr << "width:" << pLayout->getWidth() << ",";
if (!layoutId.empty())
poco_assert_dbg (pLayout != 0);
Renderable::ID id(0);
View::Ptr ptrParent = pLayout->parent();
bool parentIsNotPanel = !(ptrParent && (ptrParent.cast<Frame>() || ptrParent.cast<Panel>()));
if (parentIsNotPanel)
{
ostr << "layout:'" << layoutId << "'";
writeComma = true;
// the parent is not a panel
// assume that the direct parent is a panel
ostr << "new Ext.Panel({border:false,bodyBorder:false,";
ostr << "id:'" << pLayout->id() << "',";
if (!pLayout->isVisible())
ostr << "hidden:true,";
}
if (!layoutConfig.empty())
{
if (writeComma)
ostr << ",layoutConfig:" << layoutConfig;
else
ostr << ",layoutConfig:" << layoutConfig;
writeComma = true;
}
if (writeComma)
ostr << ",items:[";
else
ostr << "items:[";
visitChildren(pLayout, cols, horPad, vertPad, context, ostr);
ostr << "]";
renderParameters(pLayout, context, ostr, cols, padHorVal, padVertVal);
if (parentIsNotPanel)
ostr << "})";
}
void LayoutRenderer::visitChildren(const Layout* pLayout, int cols, int horPad, int vertPad, const RenderContext& context, std::ostream& ostr)
void LayoutRenderer::renderParameters(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, std::size_t cols, int padHorVal, int padVertVal)
{
std::string padHor;
poco_assert_dbg(pLayout != 0);
if (padHorVal < 0)
padHorVal = 0;
if (padVertVal < 0)
padVertVal = 0;
if (pLayout->getWidth() > 0)
ostr << "width:" << pLayout->getWidth() << ",";
if (horPad > 0)
ostr << "layout:'table'";
ostr << ",layoutConfig:" << "{columns:" << cols << "}";
if (padHorVal > 0 || padVertVal > 0)
{
std::ostringstream pad;
pad << "<p class=\"lbl\" style=\"margin-left:" << (horPad-4) << "px\">&nbsp;</p>"; // -4 fixes size of &nbsp;
padHor = pad.str();
ostr << ",defaults:{";
ostr << "bodyStyle:'";
ostr << "padding:" << padVertVal << "px " << padHorVal << "px";
ostr << "'";
ostr << "}";
}
std::string padVert;
if (vertPad > 0)
{
std::ostringstream pad;
pad << "<p style=\"margin-top:" << vertPad << "px\"></p>";
padVert = pad.str();
}
ostr << ",items:[";
ContainerView::ConstIterator it = pLayout->begin();
int cnt(0);
for (; it != pLayout->end(); ++it, ++cnt)
for (; it != pLayout->end(); ++it)
{
if (cnt > 0)
{
if (it != pLayout->begin())
ostr << ",";
if (cnt < cols && !padHor.empty())
{
ostr << "new Ext.Panel({border:false,bodyBorder:false,";
ostr << "html:'" << padHor << "'}),";
++cnt;
}
else
{
if (cnt >= cols)
{
if (cnt % cols == 0) //first row
{
if (!padVert.empty())
{
//insert a complete line!
for (int i= 0; i < cols; ++i)
{
ostr << "new Ext.Panel({border:false,bodyBorder:false,";
ostr << "html:'" << padVert << "'}),";
}
} // else no hor padding for first row!
}
else if (!padHor.empty())
{
ostr << "new Ext.Panel({border:false,bodyBorder:false,";
ostr << "html:'" << padHor << "'}),";
++cnt;
}
}
}
}
if (*it)
{
//horizontallayout works only when children are panels
ostr << "new Ext.Panel({border:false,bodyBorder:false,items:[";
(*it)->renderHead(context, ostr);
@ -188,9 +136,8 @@ void LayoutRenderer::visitChildren(const Layout* pLayout, int cols, int horPad,
}
else
ostr << "{}";
}
ostr << "]";
}
} } } // namespace Poco::WebWidgets::ExtJS

View File

@ -61,15 +61,7 @@ void VerticalLayoutRenderer::renderHead(const Renderable* pRenderable, const Ren
poco_assert_dbg (pRenderable->type() == typeid(Poco::WebWidgets::VerticalLayout));
const VerticalLayout* pLayout = static_cast<const Poco::WebWidgets::VerticalLayout*>(pRenderable);
int padVal = pLayout->getPadding();
std::string padding;
if (padVal > 0)
{
}
// a vertical layout is a table with one column
std::string layoutConfig("{columns:1}");
std::string layout("table");
LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig, 1, 0, padVal);
renderLayout(pLayout, context, ostr, 1, 0, pLayout->getPadding());
}