mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-14 15:05:35 +02:00
added padding support to layouts
This commit is contained in:
@@ -60,10 +60,29 @@ 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 || padVertVal > 0)
|
||||
{
|
||||
std::ostringstream pad;
|
||||
// or style=\"background:#deecfd;padding-left:10px\"
|
||||
// or transparent gif: <img src=\"resources/images/default/s.gif\" width=\"10\" height=\"1\" alt=\"\">'
|
||||
pad << "<p style=\"";
|
||||
if (padHorVal > 0)
|
||||
pad << "padding-left:" << padHorVal << "px; ";
|
||||
if (padVertVal > 0)
|
||||
pad << "padding-top:" << padVertVal << "px ";
|
||||
pad << "\"> </p>";
|
||||
padding = pad.str();
|
||||
cols = 2 * cols - 1;
|
||||
}
|
||||
std::ostringstream layoutConfig;
|
||||
layoutConfig << "{columns:" << pLayout->columns() << "}";
|
||||
layoutConfig << "{columns:" << cols << "}";
|
||||
std::string layout("table");
|
||||
LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig.str());
|
||||
// when padding is used we can no longer use LayoutRenderer
|
||||
LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig.str(), (int)cols, padding);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -61,11 +61,23 @@ void HorizontalLayoutRenderer::renderHead(const Renderable* pRenderable, const R
|
||||
poco_assert_dbg (pRenderable->type() == typeid(Poco::WebWidgets::HorizontalLayout));
|
||||
const HorizontalLayout* pLayout = static_cast<const Poco::WebWidgets::HorizontalLayout*>(pRenderable);
|
||||
std::ostringstream layoutConfig;
|
||||
layoutConfig << "{columns:" << pLayout->size() << "}";
|
||||
std::size_t cols = pLayout->size();
|
||||
int padVal = pLayout->getPadding();
|
||||
std::string padding;
|
||||
if (padVal > 0)
|
||||
{
|
||||
std::ostringstream pad;
|
||||
// or style=\"background:#deecfd;padding-left:10px\"
|
||||
// or transparent gif: <img src=\"resources/images/default/s.gif\" width=\"10\" height=\"1\" alt=\"\">'
|
||||
pad << "<p style=\"padding-left:" << padVal << "px\"> </p>";
|
||||
padding = pad.str();
|
||||
cols = 2 * cols - 1;
|
||||
}
|
||||
layoutConfig << "{columns:" << cols << "}";
|
||||
|
||||
static std::string layout("table");
|
||||
//static std::string layout("column"); -> this works with firefox but faila with IE7!
|
||||
LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig.str());
|
||||
//static std::string layout("column"); -> this works with firefox but fails with IE7!
|
||||
LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig.str(), (int)cols, padding);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -38,6 +38,7 @@
|
||||
#include "Poco/WebWidgets/ExtJS/FormRenderer.h"
|
||||
#include "Poco/WebWidgets/ExtJS/Utility.h"
|
||||
#include "Poco/WebWidgets/Layout.h"
|
||||
#include "Poco/WebWidgets/VerticalLayout.h"
|
||||
#include "Poco/WebWidgets/Frame.h"
|
||||
#include "Poco/WebWidgets/Panel.h"
|
||||
|
||||
@@ -57,7 +58,7 @@ LayoutRenderer::~LayoutRenderer()
|
||||
}
|
||||
|
||||
|
||||
void LayoutRenderer::renderLayoutHead(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, const std::string& layoutId, const std::string& layoutConfig)
|
||||
void LayoutRenderer::renderLayoutHead(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, const std::string& layoutId, const std::string& layoutConfig, int cols, const std::string& htmlPadding)
|
||||
{
|
||||
poco_assert_dbg(pLayout != 0);
|
||||
Renderable::ID id(0);
|
||||
@@ -67,12 +68,12 @@ void LayoutRenderer::renderLayoutHead(const Layout* pLayout, const RenderContext
|
||||
// the parent is not a panel
|
||||
// assume that the direct parent is a panel
|
||||
ostr << "new Ext.Panel({border:false,bodyBorder:false,";
|
||||
renderParameters(pLayout, context, ostr, layoutId, layoutConfig);
|
||||
renderParameters(pLayout, context, ostr, layoutId, layoutConfig, cols, htmlPadding);
|
||||
ostr << "})";
|
||||
}
|
||||
else
|
||||
{
|
||||
renderParameters(pLayout, context, ostr, layoutId, layoutConfig);
|
||||
renderParameters(pLayout, context, ostr, layoutId, layoutConfig, cols, htmlPadding);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +84,7 @@ 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)
|
||||
void LayoutRenderer::renderParameters(const Layout* pLayout, const RenderContext& context, std::ostream& ostr, const std::string& layoutId, const std::string& layoutConfig, int cols, const std::string& htmlPadding)
|
||||
{
|
||||
poco_assert_dbg(pLayout != 0);
|
||||
bool writeComma = false;
|
||||
@@ -106,24 +107,36 @@ void LayoutRenderer::renderParameters(const Layout* pLayout, const RenderContext
|
||||
ostr << ",items:[";
|
||||
else
|
||||
ostr << "items:[";
|
||||
visitChildren(pLayout, context, ostr);
|
||||
visitChildren(pLayout, cols, htmlPadding, context, ostr);
|
||||
ostr << "]";
|
||||
}
|
||||
|
||||
|
||||
void LayoutRenderer::visitChildren(const Layout* pLayout, const RenderContext& context, std::ostream& ostr)
|
||||
void LayoutRenderer::visitChildren(const Layout* pLayout, int cols, const std::string& htmlPadding, const RenderContext& context, std::ostream& ostr)
|
||||
{
|
||||
ContainerView::ConstIterator it = pLayout->begin();
|
||||
for (; it != pLayout->end(); ++it)
|
||||
int cnt(0);
|
||||
const VerticalLayout* pVert = dynamic_cast<const VerticalLayout*>(pLayout);
|
||||
|
||||
for (; it != pLayout->end(); ++it, ++cnt)
|
||||
{
|
||||
if (it != pLayout->begin())
|
||||
{
|
||||
ostr << ",";
|
||||
if (!htmlPadding.empty() && (cnt % cols != 0 || pVert))
|
||||
{
|
||||
// if padding, insert an additional empty html element that defines padding
|
||||
ostr << "new Ext.Panel({border:false,bodyBorder:false,";
|
||||
ostr << "html:'" << htmlPadding << "'}),";
|
||||
++cnt;
|
||||
}
|
||||
}
|
||||
if (*it)
|
||||
{
|
||||
//horizontallayout works only when children are panels
|
||||
ostr << "{xtype:'panel',items:";
|
||||
ostr << "new Ext.Panel({border:false,bodyBorder:false,items:";
|
||||
(*it)->renderHead(context, ostr);
|
||||
ostr << "}";
|
||||
ostr << "})";
|
||||
}
|
||||
else
|
||||
ostr << "{}";
|
||||
|
@@ -189,6 +189,7 @@ void PageRenderer::renderHead(const Renderable* pRenderable, const RenderContext
|
||||
|
||||
ostr << STRC_HEAD;
|
||||
WebApplication::instance().registerAjaxProcessor(Poco::NumberFormatter::format(pPage->id()), pPage);
|
||||
pPage->afterPageRequested.notify(this, pPage);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -60,10 +60,21 @@ void VerticalLayoutRenderer::renderHead(const Renderable* pRenderable, const Ren
|
||||
poco_assert_dbg (pRenderable != 0);
|
||||
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)
|
||||
{
|
||||
std::ostringstream pad;
|
||||
// or style=\"background:#deecfd;padding-left:10px\"
|
||||
// or transparent gif: <img src=\"resources/images/default/s.gif\" width=\"10\" height=\"1\" alt=\"\">'
|
||||
pad << "<p style=\"padding-top:" << padVal << "px\"> </p>";
|
||||
padding = pad.str();
|
||||
}
|
||||
// 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);
|
||||
LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig, 1, padding);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user