diff --git a/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/Utility.h b/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/Utility.h index 31a10bc21..44d57efcc 100644 --- a/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/Utility.h +++ b/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/Utility.h @@ -43,6 +43,8 @@ #include "Poco/WebWidgets/ExtJS/ExtJS.h" #include "Poco/WebWidgets/Form.h" #include "Poco/WebWidgets/LookAndFeel.h" +#include "Poco/WebWidgets/ResourceManager.h" +#include "Poco/Path.h" #include "Poco/WebWidgets/JavaScriptEvent.h" #include #include @@ -65,6 +67,9 @@ class ExtJS_API Utility public: static void initialize(LookAndFeel::Ptr ptr); /// Initializes the LookAndFeel object to use ExtJS renderers + + static void initialize(ResourceManager::Ptr ptr, const Poco::Path& extJSDir); + /// Initializes the ResourceManager object to include ExtJS resources static LookAndFeel& getDefaultRenderers(); /// Returns the defaultrenderers; diff --git a/WebWidgets/ExtJS/src/FrameRenderer.cpp b/WebWidgets/ExtJS/src/FrameRenderer.cpp index 77f544b55..c535bfdd3 100644 --- a/WebWidgets/ExtJS/src/FrameRenderer.cpp +++ b/WebWidgets/ExtJS/src/FrameRenderer.cpp @@ -92,7 +92,7 @@ void FrameRenderer::renderBody(const Renderable* pRenderable, const RenderContex void FrameRenderer::writeProperties(const Frame* pFrame, std::ostream& ostr) { Utility::writeRenderableProperties(pFrame, ostr); - ostr << ",frame:true"; + ostr << ",frame:true,header:true"; if (pFrame->getWidth() > 0) ostr << ",width:" << pFrame->getWidth(); if (pFrame->getHeight() > 0) diff --git a/WebWidgets/ExtJS/src/PageRenderer.cpp b/WebWidgets/ExtJS/src/PageRenderer.cpp index a6385fb3d..09643070a 100644 --- a/WebWidgets/ExtJS/src/PageRenderer.cpp +++ b/WebWidgets/ExtJS/src/PageRenderer.cpp @@ -73,18 +73,41 @@ void PageRenderer::renderHead(const Renderable* pRenderable, const RenderContext const Page* pPage = static_cast(pRenderable); poco_assert_dbg (WebApplication::instance().getCurrentPage().get() == pPage); const LookAndFeel& laf = context.lookAndFeel(); + ResourceManager::Ptr pRM = context.application().getResourceManager(); ostr << STRO_HTML << STRO_HEAD << STRO_TITLE; ostr << pPage->getName(); ostr << STRC_TITLE; - //include javascript files: TODO: use ResourceManager - ostr << ""; - ostr << ""; - ostr << ""; - ostr << ""; - ostr << ""; - ostr << ""; + //include javascript files: + const ResourceManager::Includes& jsIncl = pRM->jsIncludes(); + ResourceManager::Includes::const_iterator itJS = jsIncl.begin(); + for (; itJS != jsIncl.end(); ++itJS) + { + ostr << ""; + } + const ResourceManager::Includes& myJSIncl = pPage->resourceManager().jsIncludes(); + ResourceManager::Includes::const_iterator itMyJS = myJSIncl.begin(); + for (; itMyJS != myJSIncl.end(); ++itMyJS) + { + ostr << ""; + } + + // write css includes + const ResourceManager::Includes& cssIncl = pRM->cssIncludes(); + ResourceManager::Includes::const_iterator itCSS = cssIncl.begin(); + for (; itCSS != cssIncl.end(); ++itCSS) + { + ostr << ""; + } + const ResourceManager::Includes& myCSSIncl = pPage->resourceManager().cssIncludes(); + ResourceManager::Includes::const_iterator itMyCSS = myCSSIncl.begin(); + for (; itMyCSS != myCSSIncl.end(); ++itMyCSS) + { + ostr << ""; + } + // extra css for label ostr << ""; + if (!pPage->empty()) { //start inline javascript block @@ -97,14 +120,10 @@ void PageRenderer::renderHead(const Renderable* pRenderable, const RenderContext { ostr << ",listeners:{"; bool written = Utility::writeJSEvent(ostr, EV_BEFORERENDER, pPage->beforeRender.jsDelegates()); - //auto-show all windows - JavaScriptEvent::JSDelegates js = pPage->afterRender.jsDelegates(); - js.push_front(jsDelegate("function(){Ext.WindowMgr.each( function(w) {w.show(this);});}")); - if (written && !js.empty()) - { + if (written) ostr << ","; - } - Utility::writeJSEvent(ostr, EV_AFTERRENDER, js); + + Utility::writeJSEvent(ostr, EV_AFTERRENDER, pPage->afterRender.jsDelegates()); ostr << "}"; } if (pPage->getHeight() > 0) diff --git a/WebWidgets/ExtJS/src/TableRenderer.cpp b/WebWidgets/ExtJS/src/TableRenderer.cpp index 28fd2fd9f..2ff41b1d5 100644 --- a/WebWidgets/ExtJS/src/TableRenderer.cpp +++ b/WebWidgets/ExtJS/src/TableRenderer.cpp @@ -79,7 +79,8 @@ void TableRenderer::renderHead(const Renderable* pRenderable, const RenderContex bool editable = false; for (Table::TableColumns::const_iterator it = cols.begin(); it != cols.end() && !editable; ++it) { - editable |= (*it)->isEditable(); + if ((*it) && (*it)->getCell()) + editable |= (*it)->isEditable(); } if (editable) ostr << "new Ext.grid.EditorGridPanel({"; @@ -156,7 +157,8 @@ void TableRenderer::renderProperties(const Table* pTable, const RenderContext& c bool editable = false; for (Table::TableColumns::const_iterator it = cols.begin(); it != cols.end() && !editable; ++it) { - editable |= (*it)->isEditable(); + if ((*it) && (*it)->getCell()) + editable |= (*it)->isEditable(); } ostr << ",listeners:{"; bool written = false; @@ -279,7 +281,7 @@ void TableRenderer::renderStore(const Table* pTable, std::ostream& ostr) { if (i != 0) ostr << ","; - if ((*it)->getCell()->type() == typeid(Poco::WebWidgets::DateFieldCell)) + if ((*it)->getCell() && (*it)->getCell()->type() == typeid(Poco::WebWidgets::DateFieldCell)) { Poco::WebWidgets::DateFieldCell::Ptr pDf = (*it)->getCell().cast(); diff --git a/WebWidgets/ExtJS/src/Utility.cpp b/WebWidgets/ExtJS/src/Utility.cpp index b7b347233..dda9ac709 100644 --- a/WebWidgets/ExtJS/src/Utility.cpp +++ b/WebWidgets/ExtJS/src/Utility.cpp @@ -134,6 +134,27 @@ void Utility::initialize(LookAndFeel::Ptr ptr) } +void Utility::initialize(ResourceManager::Ptr ptr, const Poco::Path& extJSDir) +{ + Poco::Path aDir(extJSDir); + aDir.makeDirectory(); + aDir.setFileName("ext-base.js"); + ptr->appendJSInclude(aDir); + aDir.setFileName("ext-all.js"); + ptr->appendJSInclude(aDir); + aDir.setFileName("DDView.js"); + ptr->appendJSInclude(aDir); + aDir.setFileName("MultiSelect.js"); + ptr->appendJSInclude(aDir); + + Poco::Path cssAll("resources/css/ext-all.css"); + cssAll.makeFile(); + + ptr->appendCSSInclude(Poco::Path(extJSDir, cssAll)); + ptr->appendCSSInclude(Poco::Path(extJSDir, "MultiSelect.css")); +} + + const std::string& Utility::getTmpID() { static const std::string tmp("tmp"); diff --git a/WebWidgets/ExtJS/testsuite/src/ExtJSTest.cpp b/WebWidgets/ExtJS/testsuite/src/ExtJSTest.cpp index e24934682..11b7c3f5a 100644 --- a/WebWidgets/ExtJS/testsuite/src/ExtJSTest.cpp +++ b/WebWidgets/ExtJS/testsuite/src/ExtJSTest.cpp @@ -68,6 +68,7 @@ #include "Poco/WebWidgets/TextEditCell.h" #include "Poco/WebWidgets/SimpleTableModel.h" #include "Poco/WebWidgets/JSDelegate.h" +#include "Poco/WebWidgets/ResourceManager.h" #include "Poco/TeeStream.h" #include "Poco/DateTimeFormat.h" #include "Poco/DateTime.h" @@ -92,7 +93,9 @@ ExtJSTest::~ExtJSTest() void ExtJSTest::testPage() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager()); + Utility::initialize(pRM, Poco::Path()); + WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -119,7 +122,9 @@ void ExtJSTest::testPage() void ExtJSTest::testPage2() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager()); + Utility::initialize(pRM, Poco::Path()); + WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -152,7 +157,9 @@ void ExtJSTest::testPage2() void ExtJSTest::testButton() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager()); + Utility::initialize(pRM, Poco::Path()); + WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -194,7 +201,9 @@ void ExtJSTest::testButton() void ExtJSTest::testFormTextField() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager()); + Utility::initialize(pRM, Poco::Path()); + WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -241,7 +250,7 @@ void ExtJSTest::testFormTextField() void ExtJSTest::testFormTimeField() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -276,7 +285,7 @@ void ExtJSTest::testFormTimeField() void ExtJSTest::testFormDateField() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -314,7 +323,7 @@ void ExtJSTest::testFormDateField() void ExtJSTest::testFormPassword() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -348,7 +357,7 @@ void ExtJSTest::testFormPassword() void ExtJSTest::testFormNumberField() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -383,7 +392,7 @@ void ExtJSTest::testFormNumberField() void ExtJSTest::testFormComboBox() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -426,7 +435,7 @@ void ExtJSTest::testFormComboBox() void ExtJSTest::testFormImageButton() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -475,7 +484,7 @@ void ExtJSTest::testFormImageButton() void ExtJSTest::testFormTextEdit() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -522,7 +531,7 @@ void ExtJSTest::testFormTextEdit() void ExtJSTest::testFormCheckButton() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -554,7 +563,7 @@ void ExtJSTest::testFormCheckButton() void ExtJSTest::testFormRadioButton() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -586,7 +595,7 @@ void ExtJSTest::testFormRadioButton() void ExtJSTest::testFormGridLayout() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -619,7 +628,7 @@ void ExtJSTest::testFormGridLayout() void ExtJSTest::testFormHorizontalLayout() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -652,7 +661,7 @@ void ExtJSTest::testFormHorizontalLayout() void ExtJSTest::testFormVerticalLayout() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -685,7 +694,7 @@ void ExtJSTest::testFormVerticalLayout() void ExtJSTest::testFormFrameGridLayout() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -720,7 +729,7 @@ void ExtJSTest::testFormFrameGridLayout() void ExtJSTest::testFormFrameHorizontalLayout() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -755,7 +764,7 @@ void ExtJSTest::testFormFrameHorizontalLayout() void ExtJSTest::testFormFrameVerticalLayout() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -790,7 +799,7 @@ void ExtJSTest::testFormFrameVerticalLayout() void ExtJSTest::testFormGridLayoutNullElements() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -823,7 +832,7 @@ void ExtJSTest::testFormGridLayoutNullElements() void ExtJSTest::testFormImage() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -859,7 +868,7 @@ void ExtJSTest::testFormImage() void ExtJSTest::testTabView() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -903,7 +912,7 @@ void ExtJSTest::testTabView() void ExtJSTest::testCollapsible() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -937,7 +946,7 @@ void ExtJSTest::testCollapsible() void ExtJSTest::testCollapsible2() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -972,7 +981,7 @@ void ExtJSTest::testCollapsible2() void ExtJSTest::testPanel() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -1011,7 +1020,7 @@ void ExtJSTest::testPanel() void ExtJSTest::testRootPanel() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -1047,7 +1056,7 @@ void ExtJSTest::testRootPanel() void ExtJSTest::testNestedPanels() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -1087,7 +1096,7 @@ void ExtJSTest::testNestedPanels() void ExtJSTest::testListBox() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -1159,7 +1168,7 @@ void ExtJSTest::testFunction() void ExtJSTest::testTable() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -1190,7 +1199,7 @@ void ExtJSTest::testTable() void ExtJSTest::testTableEdit() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -1221,7 +1230,7 @@ void ExtJSTest::testTableEdit() void ExtJSTest::testTableComboBox() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -1256,7 +1265,7 @@ void ExtJSTest::testTableComboBox() void ExtJSTest::testTableButton() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); @@ -1287,7 +1296,7 @@ void ExtJSTest::testTableButton() void ExtJSTest::testTableImageButton() { - WebApplication webApp(Poco::URI("/")); + ResourceManager::Ptr pRM(new ResourceManager());Utility::initialize(pRM, Poco::Path());WebApplication webApp(Poco::URI("/"), pRM); LookAndFeel::Ptr laf(new LookAndFeel()); webApp.setLookAndFeel(laf); RenderContext context(*laf, webApp); diff --git a/WebWidgets/Makefile b/WebWidgets/Makefile index 076245978..1a7f2565d 100644 --- a/WebWidgets/Makefile +++ b/WebWidgets/Makefile @@ -22,7 +22,7 @@ objects = Renderable Renderer RenderContext LookAndFeel Type Event Delegate \ TableModel TableColumn SimpleTableModel \ PasswordField PasswordFieldCell TimeField TimeFieldCell \ WebApplication RequestProcessor RequestHandler \ - SubmitButton SubmitButtonCell + SubmitButton SubmitButtonCell ResourceManager target = PocoWebWidgets target_version = $(LIBVERSION) diff --git a/WebWidgets/WebWidgets_VS80.vcproj b/WebWidgets/WebWidgets_VS80.vcproj index 9ff7860f6..f20d4ee10 100644 --- a/WebWidgets/WebWidgets_VS80.vcproj +++ b/WebWidgets/WebWidgets_VS80.vcproj @@ -265,6 +265,10 @@ RelativePath=".\include\Poco\WebWidgets\RequestProcessor.h" > + + @@ -329,6 +333,10 @@ RelativePath=".\src\RequestProcessor.cpp" > + + diff --git a/WebWidgets/WebWidgets_VS90.vcproj b/WebWidgets/WebWidgets_VS90.vcproj index 8b403873d..ef47f1db2 100644 --- a/WebWidgets/WebWidgets_VS90.vcproj +++ b/WebWidgets/WebWidgets_VS90.vcproj @@ -264,6 +264,10 @@ RelativePath=".\include\Poco\WebWidgets\RequestProcessor.h" > + + @@ -328,6 +332,10 @@ RelativePath=".\src\RequestProcessor.cpp" > + + diff --git a/WebWidgets/include/Poco/WebWidgets/Page.h b/WebWidgets/include/Poco/WebWidgets/Page.h index 8c69f7eaa..5f801f1d1 100644 --- a/WebWidgets/include/Poco/WebWidgets/Page.h +++ b/WebWidgets/include/Poco/WebWidgets/Page.h @@ -42,6 +42,7 @@ #include "Poco/WebWidgets/ContainerView.h" #include "Poco/WebWidgets/JavaScriptEvent.h" +#include "Poco/WebWidgets/ResourceManager.h" namespace Poco { @@ -71,6 +72,12 @@ public: std::string getText() const; + ResourceManager& resourceManager(); + /// Returns the ResourceManager + + const ResourceManager& resourceManager() const; + /// Returns the ResourceManager + protected: Page(const std::string& name, const std::type_info& type); /// Creates a Page and assigns it the given name. @@ -82,10 +89,27 @@ protected: /// Destroys the Page. private: - std::string _text; + std::string _text; + ResourceManager _rm; }; +// +// Inlines +// + +inline ResourceManager& Page::resourceManager() +{ + return _rm; +} + + +inline const ResourceManager& Page::resourceManager() const +{ + return _rm; +} + + } } // namespace Poco::WebWidgets diff --git a/WebWidgets/include/Poco/WebWidgets/ResourceManager.h b/WebWidgets/include/Poco/WebWidgets/ResourceManager.h new file mode 100644 index 000000000..c7db6cb7c --- /dev/null +++ b/WebWidgets/include/Poco/WebWidgets/ResourceManager.h @@ -0,0 +1,124 @@ +// +// ResourceManager.h +// +// $Id: //poco/Main/WebWidgets/include/Poco/WebWidgets/ResourceManager.h#2 $ +// +// Library: WebWidgets +// Package: Core +// Module: ResourceManager +// +// Definition of the ResourceManager class. +// +// Copyright (c) 2008, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef WebWidgets_ResourceManager_INCLUDED +#define WebWidgets_ResourceManager_INCLUDED + + +#include "Poco/WebWidgets/WebWidgets.h" +#include "Poco/RefCountedObject.h" +#include "Poco/AutoPtr.h" +#include +#include + + +namespace Poco { + + class Path; + +namespace WebWidgets { + + +class WebApplication; + + +class WebWidgets_API ResourceManager: public Poco::RefCountedObject + /// The ResourceManager manages JS and CSS includes. Please note that there are two ResourceManagers: + /// There is a global ResourceManager that provides common includes for all WebPages (like the rendering JS library), + /// and there is a local ResourceManager on a per WebPage that allows to define additional includes. + /// + /// TODO: It would be nice if it also provides some sort of automatic + /// mapping from local files to web uris, i.e you provide the server root dir + /// and it converts local files automatically to a relative web server path. + /// + /// - how to handle requests to files inside Zips? + /// + /// - how to handle requests to files outside the root dir? + /// (would be nice to have a tool that collects all the referenced files into one bundle and have requests + /// only into zip, or alternatively: simply copy all the files into one directory, decompress ZIP files + /// where requested) +{ +public: + typedef std::vector Includes; + typedef Poco::AutoPtr Ptr; + + ResourceManager(); + /// Creates the ResourceManager, + + ~ResourceManager(); + /// Destroys the ResourceManager. + + void appendJSInclude(const Poco::Path& aPath); + /// Adds a JS include, no check for duplicates + + void appendCSSInclude(const Poco::Path& aPath); + /// Adds a CSS include, no check for duplicates + + const Includes& jsIncludes() const; + /// Returns all JS includes + + const Includes& cssIncludes() const; + /// Returns all CSS includes + +private: + + Includes _js; + Includes _css; +}; + + +// +// Inlines +// + +inline const ResourceManager::Includes& ResourceManager::jsIncludes() const +{ + return _js; +} + + +inline const ResourceManager::Includes& ResourceManager::cssIncludes() const +{ + return _css; +} + + +} } // namespace Poco::WebWidgets + + +#endif // WebWidgets_ResourceManager_INCLUDED diff --git a/WebWidgets/include/Poco/WebWidgets/WebApplication.h b/WebWidgets/include/Poco/WebWidgets/WebApplication.h index 9d57b2dc4..0f555ae07 100644 --- a/WebWidgets/include/Poco/WebWidgets/WebApplication.h +++ b/WebWidgets/include/Poco/WebWidgets/WebApplication.h @@ -43,6 +43,7 @@ #include "Poco/WebWidgets/WebWidgets.h" #include "Poco/WebWidgets/Page.h" #include "Poco/WebWidgets/LookAndFeel.h" +#include "Poco/WebWidgets/ResourceManager.h" #include "Poco/ThreadLocal.h" #include "Poco/URI.h" #include @@ -62,7 +63,7 @@ class WebWidgets_API WebApplication /// WebApplication class { public: - WebApplication(const Poco::URI& uri); + WebApplication(const Poco::URI& uri, ResourceManager::Ptr pRM); /// Creates the WebApplication. virtual ~WebApplication(); @@ -79,6 +80,12 @@ public: Page::Ptr getCurrentPage() const; /// Returns the currently active page. + + void setResourceManager(ResourceManager::Ptr pRM); + /// Sets the ResourceManager + + ResourceManager::Ptr getResourceManager() const; + /// Gets the ResourceManager void registerFormProcessor(const std::string& fieldName, RequestProcessor* pProc); /// Registers a RequestProcessor for a given form field. @@ -111,6 +118,7 @@ private: typedef std::map RequestProcessorMap; + ResourceManager::Ptr _pResource; LookAndFeel::Ptr _pLookAndFeel; Page::Ptr _pCurrentPage; Poco::URI _uri; @@ -141,6 +149,19 @@ inline const Poco::URI& WebApplication::getURI() const } +inline void WebApplication::setResourceManager(ResourceManager::Ptr pRM) +{ + poco_check_ptr (pRM); + _pResource = pRM; +} + + +inline ResourceManager::Ptr WebApplication::getResourceManager() const +{ + return _pResource; +} + + } } // namespace Poco::WebWidgets diff --git a/WebWidgets/src/Page.cpp b/WebWidgets/src/Page.cpp index 5241adeae..1a8d2887f 100644 --- a/WebWidgets/src/Page.cpp +++ b/WebWidgets/src/Page.cpp @@ -42,25 +42,33 @@ namespace WebWidgets { Page::Page(): - ContainerView(typeid(Page)) + ContainerView(typeid(Page)), + _text(), + _rm() { } Page::Page(const std::string& name): - ContainerView(name, typeid(Page)) + ContainerView(name, typeid(Page)), + _text(), + _rm() { } Page::Page(const std::string& name, const std::type_info& type): - ContainerView(name, type) + ContainerView(name, type), + _text(), + _rm() { } Page::Page(const std::type_info& type): - ContainerView(type) + ContainerView(type), + _text(), + _rm() { } diff --git a/WebWidgets/src/ResourceManager.cpp b/WebWidgets/src/ResourceManager.cpp new file mode 100644 index 000000000..3983edc2e --- /dev/null +++ b/WebWidgets/src/ResourceManager.cpp @@ -0,0 +1,69 @@ +// +// ResourceManager.cpp +// +// $Id: //poco/Main/WebWidgets/src/ResourceManager.cpp#4 $ +// +// Library: WebWidgets +// Package: Core +// Module: ResourceManager +// +// Definition of the ResourceManager class. +// +// Copyright (c) 2008, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/WebWidgets/ResourceManager.h" +#include "Poco/Path.h" + + +namespace Poco { +namespace WebWidgets { + + +ResourceManager::ResourceManager() +{ +} + + +ResourceManager::~ResourceManager() +{ +} + + +void ResourceManager::appendJSInclude(const Poco::Path& aPath) +{ + _js.push_back(aPath.toString(Path::PATH_UNIX)); +} + + +void ResourceManager::appendCSSInclude(const Poco::Path& aPath) +{ + _css.push_back(aPath.toString(Path::PATH_UNIX)); +} + + +} } // namespace Poco::WebWidgets diff --git a/WebWidgets/src/WebApplication.cpp b/WebWidgets/src/WebApplication.cpp index 86b4c348c..b76b517e0 100644 --- a/WebWidgets/src/WebApplication.cpp +++ b/WebWidgets/src/WebApplication.cpp @@ -46,11 +46,13 @@ namespace WebWidgets { Poco::ThreadLocal WebApplication::_pInstance; -WebApplication::WebApplication(const Poco::URI& uri): +WebApplication::WebApplication(const Poco::URI& uri,ResourceManager::Ptr pRM): + _pResource(pRM), _pLookAndFeel(), _pCurrentPage(), _uri(uri) { + poco_check_ptr (pRM); attachToThread(); }