diff --git a/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/ComboBoxCellRenderer.h b/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/ComboBoxCellRenderer.h index 92ed99e01..b8edae4c8 100644 --- a/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/ComboBoxCellRenderer.h +++ b/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/ComboBoxCellRenderer.h @@ -42,10 +42,15 @@ #include "Poco/WebWidgets/ExtJS/ExtJS.h" #include "Poco/WebWidgets/Renderer.h" +#include "Poco/Net/HTTPServerResponse.h" namespace Poco { namespace WebWidgets { + + class ComboBoxCell; + class ComboBox; + namespace ExtJS { @@ -53,6 +58,8 @@ class ExtJS_API ComboBoxCellRenderer: public Poco::WebWidgets::Renderer /// ComboBoxCellRenderer renders a ComboBox { public: + static const std::string EV_SELECTED; + ComboBoxCellRenderer(); /// Creates the ComboBoxCellRenderer. @@ -64,6 +71,15 @@ public: void renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr); /// Emits code for the page body to the given output stream. + + static void addSelectedServerCallback(ComboBox* pCombo, const std::string& onSuccess, const std::string& onFailure); + /// Adds a server callback for the selected event. The method signature for select is + /// select : ( Ext.form.ComboBox combo, Ext.data.Record record, Number index ) + +private: + static void onLoad(void* pSender, Poco::Net::HTTPServerResponse* &pResponse); + + static void serialize(const ComboBoxCell* pCell, std::ostream& out); }; diff --git a/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/TextFieldCellRenderer.h b/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/TextFieldCellRenderer.h index 11a680fe2..223c7fc05 100644 --- a/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/TextFieldCellRenderer.h +++ b/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/TextFieldCellRenderer.h @@ -68,7 +68,7 @@ public: void renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr); /// Emits code for the page body to the given output stream. - static void writeCellProperties(const TextFieldCell* pCell, std::ostream& ostr, bool writeValue=true); + static void writeCellProperties(const TextFieldCell* pCell, std::ostream& ostr, bool writeValue=true, bool writeListeners = true); /// Writes cell properties }; diff --git a/WebWidgets/ExtJS/src/ButtonCellRenderer.cpp b/WebWidgets/ExtJS/src/ButtonCellRenderer.cpp index 60e4f61ed..ca8990561 100644 --- a/WebWidgets/ExtJS/src/ButtonCellRenderer.cpp +++ b/WebWidgets/ExtJS/src/ButtonCellRenderer.cpp @@ -85,7 +85,21 @@ void ButtonCellRenderer::renderProperties(const ButtonCell* pButtonCell, const s //ostr << "handler: function(){Ext.getCmp('" << pForm->id() << "').getForm().submit({url:'" << pForm->getURI().toString() << "',waitMsg:'Loading'});},"; ostr << "handler: function(){Ext.getCmp('" << pForm->id() << "').getForm().submit();},"; } - Utility::writeCellProperties(pButtonCell, ostr, writeId); + if (writeId) + Utility::writeRenderableProperties(pButtonCell, ostr); + if (!pButtonCell->isEnabled()) + ostr << ",disabled:true"; + View* pOwner = pButtonCell->getOwner(); + if (pOwner) + { + if (!pOwner->getName().empty()) + ostr << ",name:'" << pOwner->getName() << "'"; + if (pOwner->getWidth() != 0) + ostr << ",minWidth:" << pOwner->getWidth(); + if (!pOwner->isVisible()) + ostr << ",hidden:true"; + } + std::string toolTip(pButtonCell->getToolTip()); if (!toolTip.empty()) ostr << ",tooltip:'" << Utility::safe(toolTip) << "'"; diff --git a/WebWidgets/ExtJS/src/ComboBoxCellRenderer.cpp b/WebWidgets/ExtJS/src/ComboBoxCellRenderer.cpp index 657baebe5..240990dd9 100644 --- a/WebWidgets/ExtJS/src/ComboBoxCellRenderer.cpp +++ b/WebWidgets/ExtJS/src/ComboBoxCellRenderer.cpp @@ -39,6 +39,12 @@ #include "Poco/WebWidgets/ExtJS/FormRenderer.h" #include "Poco/WebWidgets/ExtJS/Utility.h" #include "Poco/WebWidgets/ComboBoxCell.h" +#include "Poco/WebWidgets/ComboBox.h" +#include "Poco/WebWidgets/WebApplication.h" +#include "Poco/WebWidgets/RequestHandler.h" +#include "Poco/NumberFormatter.h" +#include "Poco/Delegate.h" +#include namespace Poco { @@ -46,6 +52,9 @@ namespace WebWidgets { namespace ExtJS { +const std::string ComboBoxCellRenderer::EV_SELECTED("select"); + + ComboBoxCellRenderer::ComboBoxCellRenderer() { } @@ -56,20 +65,80 @@ ComboBoxCellRenderer::~ComboBoxCellRenderer() } +void ComboBoxCellRenderer::addSelectedServerCallback(ComboBox* pCombo, const std::string& onSuccess, const std::string& onFailure) +{ + //select : ( Ext.form.ComboBox combo, Ext.data.Record record, Number index ) + static const std::string signature("function(combo,rec, idx)"); + std::map addParams; + addParams.insert(std::make_pair(ComboBoxCell::FIELD_VAL, "+rec.get('d')")); + addParams.insert(std::make_pair(RequestHandler::KEY_EVID, ComboBoxCell::EV_SELECTED)); + Utility::addServerCallback(pCombo->selected, signature, addParams, pCombo->id(), onSuccess, onFailure); +} + void ComboBoxCellRenderer::renderHead(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr) { poco_assert_dbg (pRenderable != 0); poco_assert_dbg (pRenderable->type() == typeid(Poco::WebWidgets::ComboBoxCell)); - const ComboBoxCell* pCell = static_cast(pRenderable); + ComboBoxCell* pCell = const_cast(static_cast(pRenderable)); + ComboBox* pOwner = dynamic_cast(pCell->getOwner()); + poco_check_ptr (pOwner); ostr << "new Ext.form.ComboBox({"; - TextFieldCellRenderer::writeCellProperties(pCell, ostr); - ostr << ", store: new Ext.data.SimpleStore({fields:['d'], data:["; + TextFieldCellRenderer::writeCellProperties(pCell, ostr, true, false); + ostr << ",store:new Ext.data.SimpleStore({autoLoad:true,fields:['d'],"; + ostr << "proxy:new Ext.data.HttpProxy({url:"; + std::map addParams; + addParams.insert(std::make_pair(RequestHandler::KEY_EVID,ComboBoxCell::EV_LOAD)); + + std::string url(Utility::createURI(addParams, pOwner->id())); + ostr << url << "}),"; + ostr << "reader:new Ext.data.ArrayReader()})"; + ostr << ",displayField:'d',typeAhead:true,triggerAction:'all'"; + + std::string tooltip (pCell->getToolTip()); + + if (!pOwner->selected.jsDelegates().empty()) + { + ostr << ",listeners:{"; + Utility::writeJSEvent(ostr, EV_SELECTED, pOwner->selected.jsDelegates()); + if (!tooltip.empty()) + ostr << ",render:function(c){Ext.QuickTips.register({target:c.getEl(),text:'" << Utility::safe(tooltip) << "'});}"; + ostr << "}"; + } + else if (!tooltip.empty()) + { + ostr << ",listeners:{"; + ostr << "render:function(c){Ext.QuickTips.register({target:c.getEl(),text:'" << Utility::safe(tooltip) << "'});}}"; + } + + + ostr << "})"; + pCell->beforeLoad += Poco::delegate(&ComboBoxCellRenderer::onLoad); + WebApplication::instance().registerAjaxProcessor(Poco::NumberFormatter::format(pOwner->id()), pCell); +} + + +void ComboBoxCellRenderer::onLoad(void* pSender, Poco::Net::HTTPServerResponse* &pResponse) +{ + poco_check_ptr (pSender); + poco_check_ptr (pResponse); + ComboBoxCell* pCell = reinterpret_cast(pSender); + poco_check_ptr (pCell); + pResponse->setChunkedTransferEncoding(true); + pResponse->setContentType("text/javascript"); + std::ostream& out = pResponse->send(); + serialize (pCell, out); +} + + +void ComboBoxCellRenderer::serialize(const ComboBoxCell* pCell, std::ostream& ostr) +{ //now serialize data std::vector::const_iterator it = pCell->begin(); std::vector::const_iterator itEnd = pCell->end(); Formatter::Ptr ptrFormatter = pCell->getFormatter(); + ostr << "["; for (; it != itEnd; ++it) { if (it != pCell->begin()) @@ -79,9 +148,7 @@ void ComboBoxCellRenderer::renderHead(const Renderable* pRenderable, const Rende else ostr << "['" << RefAnyCast(*it) << "']"; } - ostr << "]})"; - ostr << ",displayField:'d',typeAhead:true,mode:'local',triggerAction:'all'"; - ostr << "})"; + ostr << "]"; } diff --git a/WebWidgets/ExtJS/src/HorizontalLayoutRenderer.cpp b/WebWidgets/ExtJS/src/HorizontalLayoutRenderer.cpp index 4bc1ca075..5b1654a43 100644 --- a/WebWidgets/ExtJS/src/HorizontalLayoutRenderer.cpp +++ b/WebWidgets/ExtJS/src/HorizontalLayoutRenderer.cpp @@ -62,7 +62,8 @@ void HorizontalLayoutRenderer::renderHead(const Renderable* pRenderable, const R const HorizontalLayout* pLayout = static_cast(pRenderable); std::ostringstream layoutConfig; layoutConfig << "{columns:" << pLayout->size() << "}"; - std::string layout("column"); + + static std::string layout("column"); LayoutRenderer::renderLayoutHead(pLayout, context, ostr, layout, layoutConfig.str()); } diff --git a/WebWidgets/ExtJS/src/LabelRenderer.cpp b/WebWidgets/ExtJS/src/LabelRenderer.cpp index 358cfa5c0..e91703155 100644 --- a/WebWidgets/ExtJS/src/LabelRenderer.cpp +++ b/WebWidgets/ExtJS/src/LabelRenderer.cpp @@ -61,7 +61,11 @@ void LabelRenderer::renderHead(const Renderable* pRenderable, const RenderContex poco_assert_dbg (pRenderable->type() == typeid(Poco::WebWidgets::Label)); const Label* pLabel = static_cast(pRenderable); - ostr << "{xtype:'label', text:'" << Utility::safe(pLabel->getText()) << "'}"; + //ostr << "{xtype:'label', text:'" << Utility::safe(pLabel->getText()) << "'}"; + ostr << "new Ext.form.Label({text:'" << Utility::safe(pLabel->getText()) << "',cls:'lbl'"; + if (pLabel->getWidth() > 0) + ostr << ",width:" << pLabel->getWidth(); + ostr << "})"; } diff --git a/WebWidgets/ExtJS/src/LayoutRenderer.cpp b/WebWidgets/ExtJS/src/LayoutRenderer.cpp index 32a5111dc..e1bfc9941 100644 --- a/WebWidgets/ExtJS/src/LayoutRenderer.cpp +++ b/WebWidgets/ExtJS/src/LayoutRenderer.cpp @@ -119,7 +119,12 @@ void LayoutRenderer::visitChildren(const Layout* pLayout, const RenderContext& c if (it != pLayout->begin()) ostr << ","; if (*it) + { + //horizontallayout works only when children are panels + ostr << "{xtype:'panel',items:"; (*it)->renderHead(context, ostr); + ostr << "}"; + } else ostr << "{}"; diff --git a/WebWidgets/ExtJS/src/PageRenderer.cpp b/WebWidgets/ExtJS/src/PageRenderer.cpp index 4909e5799..fc0411950 100644 --- a/WebWidgets/ExtJS/src/PageRenderer.cpp +++ b/WebWidgets/ExtJS/src/PageRenderer.cpp @@ -59,7 +59,11 @@ PageRenderer::~PageRenderer() void PageRenderer::renderHead(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr) { - static const std::string STRO_HTML(""); static const std::string STRO_HEAD (""); static const std::string STRO_TITLE (""); static const std::string STRC_HEAD ("</head>"); static const std::string STRC_TITLE (""); + static const std::string STRO_HTML(""); + static const std::string STRO_HEAD (""); + static const std::string STRO_TITLE (""); + static const std::string STRC_HEAD ("</head>"); + static const std::string STRC_TITLE (""); poco_assert_dbg (pRenderable != 0); poco_assert_dbg (pRenderable->type() == typeid(Poco::WebWidgets::Page)); const Page* pPage = static_cast(pRenderable); @@ -70,11 +74,13 @@ void PageRenderer::renderHead(const Renderable* pRenderable, const RenderContext ostr << pPage->getName(); ostr << STRC_TITLE; //include javascript files: TODO: use ResourceManager - ostr << ""; ostr << ""; + ostr << ""; + ostr << ""; ostr << ""; ostr << ""; ostr << ""; ostr << ""; + ostr << ""; if (!pPage->empty()) { //start inline javascript block diff --git a/WebWidgets/ExtJS/src/TableRenderer.cpp b/WebWidgets/ExtJS/src/TableRenderer.cpp index 381fdd0fb..c9af832c3 100644 --- a/WebWidgets/ExtJS/src/TableRenderer.cpp +++ b/WebWidgets/ExtJS/src/TableRenderer.cpp @@ -244,13 +244,13 @@ void TableRenderer::renderStore(const Table* pTable, std::ostream& ostr) } ostr << ",{name:'" << i << "'}"; ostr << "],"; // close fields - ostr << "proxy: new Ext.data.HttpProxy({url:"; + ostr << "proxy:new Ext.data.HttpProxy({url:"; std::map addParams; addParams.insert(std::make_pair(RequestHandler::KEY_EVID,Table::EV_LOADDATA)); std::string url(Utility::createURI(addParams, pTable->id())); ostr << url << "}),"; - ostr << "reader: new Ext.data.ArrayReader()"; + ostr << "reader:new Ext.data.ArrayReader()"; //Write data /*ostr << "data:"; renderDataModel(pTable, ostr);*/ diff --git a/WebWidgets/ExtJS/src/TextFieldCellRenderer.cpp b/WebWidgets/ExtJS/src/TextFieldCellRenderer.cpp index 354a3a4e5..b4394855a 100644 --- a/WebWidgets/ExtJS/src/TextFieldCellRenderer.cpp +++ b/WebWidgets/ExtJS/src/TextFieldCellRenderer.cpp @@ -79,7 +79,7 @@ void TextFieldCellRenderer::renderBody(const Renderable* pRenderable, const Rend } -void TextFieldCellRenderer::writeCellProperties(const TextFieldCell* pCell, std::ostream& ostr, bool writeValue) +void TextFieldCellRenderer::writeCellProperties(const TextFieldCell* pCell, std::ostream& ostr, bool writeValue, bool writeListeners) { Utility::writeCellProperties(pCell, ostr); @@ -97,10 +97,13 @@ void TextFieldCellRenderer::writeCellProperties(const TextFieldCell* pCell, std: if (pCell->getMaxLength() > 0) ostr << ",maxLength:" << pCell->getMaxLength(); - //tooltip is not supported by textField, add listeners - std::string tooltip (pCell->getToolTip()); - if (!tooltip.empty()) - ostr << ",listeners:{render:function(c){Ext.QuickTips.register({target:c.getEl(),text:'" << Utility::safe(tooltip) << "'});}}"; + if (writeListeners) + { + //tooltip is not supported by textField, add listeners + std::string tooltip (pCell->getToolTip()); + if (!tooltip.empty()) + ostr << ",listeners:{render:function(c){Ext.QuickTips.register({target:c.getEl(),text:'" << Utility::safe(tooltip) << "'});}}"; + } } diff --git a/WebWidgets/ExtJS/src/ToggleButtonCellRenderer.cpp b/WebWidgets/ExtJS/src/ToggleButtonCellRenderer.cpp index 4b4c844f0..e06af5f91 100644 --- a/WebWidgets/ExtJS/src/ToggleButtonCellRenderer.cpp +++ b/WebWidgets/ExtJS/src/ToggleButtonCellRenderer.cpp @@ -66,6 +66,7 @@ void ToggleButtonCellRenderer::renderProperties(const ToggleButtonCell* pToggleB if (!pToggleButtonCell->getLabel().empty()) ostr << "boxLabel:'" << Utility::safe(pToggleButtonCell->getLabel()) << "',"; ostr << "checked:" << (pToggleButtonCell->isChecked()?"true":"false") << ","; + Utility::writeCellProperties(pToggleButtonCell, ostr); //tooltip is not supported by togglebutton std::string tooltip (pToggleButtonCell->getToolTip()); diff --git a/WebWidgets/ExtJS/src/Utility.cpp b/WebWidgets/ExtJS/src/Utility.cpp index c9b6eb9cd..17155c29f 100644 --- a/WebWidgets/ExtJS/src/Utility.cpp +++ b/WebWidgets/ExtJS/src/Utility.cpp @@ -142,6 +142,7 @@ const std::string& Utility::getTmpID() void Utility::writeRenderableProperties(const Renderable* pRend, std::ostream& ostr) { + poco_assert_dbg (pRend != 0); ostr << "id:'" << pRend->id() << "'"; } @@ -156,11 +157,12 @@ void Utility::writeRenderableProperties(const std::string& id, std::ostream& ost void Utility::writeCellProperties(const Cell* pCell, std::ostream& ostr, bool writeId) { if (writeId) - writeRenderableProperties(pCell, ostr); + writeRenderableProperties(pCell->getOwner(), ostr); //don't support label for cell, keep this separate ostr << ",hideLabel:true"; if (!pCell->isEnabled()) - ostr << ",disabled:true"; + ostr << ",disabled:true"; + View* pOwner = pCell->getOwner(); if (pOwner) { @@ -170,6 +172,8 @@ void Utility::writeCellProperties(const Cell* pCell, std::ostream& ostr, bool wr ostr << ",width:" << pOwner->getWidth(); if (pOwner->getHeight() != 0) ostr << ",height:" << pOwner->getHeight(); + if (!pOwner->isVisible()) + ostr << ",hidden:true"; } } diff --git a/WebWidgets/ExtJS/testsuite/TestSuite_VS80.vcproj b/WebWidgets/ExtJS/testsuite/TestSuite_VS80.vcproj index ed8b3f49e..6783cb836 100644 --- a/WebWidgets/ExtJS/testsuite/TestSuite_VS80.vcproj +++ b/WebWidgets/ExtJS/testsuite/TestSuite_VS80.vcproj @@ -40,7 +40,7 @@ @@ -58,6 +60,10 @@ class WebWidgets_API ComboBox: public TextField public: typedef Poco::AutoPtr Ptr; + typedef Event ComboBoxEvent; + + JavaScriptEvent selected; /// thrown whenever a new element is selected + ComboBox(); /// Creates the ComboBox. @@ -78,6 +84,17 @@ public: void setElements(const std::vector& elems); /// Initializes the combo box with the provided elements + + template + void setElements(const std::vector& elems) + /// Initializes the combo box with the provided elements + { + std::vector result; + typename std::vector::const_iterator it = elems.begin(); + for (; it != elems.end(); ++it) + result.push_back(*it); + setElements(result); + } const std::vector& getElements() const; /// Returns all elements @@ -106,6 +123,9 @@ protected: ~ComboBox(); /// Destroys the ComboBox. + + void fireSelected(void* pSender); + /// Fires the selected event. }; diff --git a/WebWidgets/include/Poco/WebWidgets/ComboBoxCell.h b/WebWidgets/include/Poco/WebWidgets/ComboBoxCell.h index c3ae204b8..decf8d06f 100644 --- a/WebWidgets/include/Poco/WebWidgets/ComboBoxCell.h +++ b/WebWidgets/include/Poco/WebWidgets/ComboBoxCell.h @@ -41,6 +41,9 @@ #include "Poco/WebWidgets/TextFieldCell.h" +#include "Poco/WebWidgets/Delegate.h" +#include "Poco/FIFOEvent.h" +#include "Poco/Net/HTTPServerResponse.h" #include @@ -53,6 +56,13 @@ class WebWidgets_API ComboBoxCell: public TextFieldCell { public: typedef Poco::AutoPtr Ptr; + + static const std::string EV_SELECTED; + static const std::string EV_LOAD; + static const std::string FIELD_VAL; + + Delegate selected; + FIFOEvent beforeLoad; /// thrown whenever a load is requested ComboBoxCell(View* pOwner); /// Creates the ComboBoxCell. @@ -89,6 +99,15 @@ public: const Any& getSelected() const; /// Returns the selected element, excpetion if none was selected + + void handleForm(const std::string& field, const std::string& value); + + void handleRequest(const Poco::Net::HTTPServerRequest& request); + /// Handles a complete HTTP request submitted by the client. + + void handleRequestAndResponse(const Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response); + /// Handles a complete HTTP request submitted by the client. Also takes care of handling the response, + /// e.g. if one wants to send back data. protected: ~ComboBoxCell(); @@ -96,6 +115,7 @@ protected: private: std::vector _elements; + std::string _ev; }; @@ -152,6 +172,7 @@ inline void ComboBoxCell::setSelected(const Any& elem) /// Selects the element. { setValue(elem); + selected(this); } diff --git a/WebWidgets/include/Poco/WebWidgets/Table.h b/WebWidgets/include/Poco/WebWidgets/Table.h index f45b48735..9e2dc1962 100644 --- a/WebWidgets/include/Poco/WebWidgets/Table.h +++ b/WebWidgets/include/Poco/WebWidgets/Table.h @@ -125,7 +125,7 @@ public: /// Handles a complete HTTP request submitted by the client. void handleRequestAndResponse(const Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response); - /// Handles a complete HTTP request submitted by the client. Also takes care of handing the response, + /// Handles a complete HTTP request submitted by the client. Also takes care of handling the response, /// e.g. if one wants to send back data. private: diff --git a/WebWidgets/include/Poco/WebWidgets/TextField.h b/WebWidgets/include/Poco/WebWidgets/TextField.h index 3a4561f46..679b6b61e 100644 --- a/WebWidgets/include/Poco/WebWidgets/TextField.h +++ b/WebWidgets/include/Poco/WebWidgets/TextField.h @@ -58,6 +58,9 @@ public: Poco::BasicEvent textChanged; + TextField(const std::string& name, const std::string& text); + /// Creates a TextField with the given name and content. + TextField(const std::string& name); /// Creates a TextField with the given name. diff --git a/WebWidgets/src/Button.cpp b/WebWidgets/src/Button.cpp index 4cd55bc97..aae49697e 100644 --- a/WebWidgets/src/Button.cpp +++ b/WebWidgets/src/Button.cpp @@ -115,7 +115,7 @@ void Button::init() void Button::fireButtonClicked(void* pSender) { - ButtonEvent clickedEvent(Button::Ptr(this, true)); + ButtonEvent clickedEvent(this); buttonClicked(this, clickedEvent); } diff --git a/WebWidgets/src/ComboBox.cpp b/WebWidgets/src/ComboBox.cpp index bfbef68c5..b043565b6 100644 --- a/WebWidgets/src/ComboBox.cpp +++ b/WebWidgets/src/ComboBox.cpp @@ -42,28 +42,35 @@ namespace Poco { namespace WebWidgets { - ComboBox::ComboBox(const std::string& name, const std::type_info& type): TextField(name, type, new ComboBoxCell(this)) { + ComboBoxCell::Ptr pCell = cell(); + pCell->selected = delegate(*this, &ComboBox::fireSelected); } ComboBox::ComboBox(const std::type_info& type): TextField(type, new ComboBoxCell(this)) { + ComboBoxCell::Ptr pCell = cell(); + pCell->selected = delegate(*this, &ComboBox::fireSelected); } ComboBox::ComboBox(const std::string& name): TextField(name, typeid(ComboBox), new ComboBoxCell(this)) { + ComboBoxCell::Ptr pCell = cell(); + pCell->selected = delegate(*this, &ComboBox::fireSelected); } ComboBox::ComboBox(): TextField(typeid(ComboBox), new ComboBoxCell(this)) { + ComboBoxCell::Ptr pCell = cell(); + pCell->selected = delegate(*this, &ComboBox::fireSelected); } @@ -72,4 +79,11 @@ ComboBox::~ComboBox() } +void ComboBox::fireSelected(void* pSender) +{ + ComboBoxEvent sel(this); + selected(this, sel); +} + + } } // namespace Poco::WebWidgets diff --git a/WebWidgets/src/ComboBoxCell.cpp b/WebWidgets/src/ComboBoxCell.cpp index 97f32371b..7565e46c3 100644 --- a/WebWidgets/src/ComboBoxCell.cpp +++ b/WebWidgets/src/ComboBoxCell.cpp @@ -35,12 +35,18 @@ #include "Poco/WebWidgets/ComboBoxCell.h" +#include "Poco/WebWidgets/RequestHandler.h" namespace Poco { namespace WebWidgets { +const std::string ComboBoxCell::FIELD_VAL("val"); +const std::string ComboBoxCell::EV_LOAD("load"); +const std::string ComboBoxCell::EV_SELECTED("sel"); + + ComboBoxCell::ComboBoxCell(View* pOwner): TextFieldCell(pOwner, typeid(ComboBoxCell)) { @@ -69,4 +75,42 @@ void ComboBoxCell::erase(const Any& elem) } +void ComboBoxCell::handleForm(const std::string& field, const std::string& value) +{ + if (field == FIELD_VAL) + { + Formatter::Ptr pForm(getFormatter()); + if (pForm) + { + setSelected(pForm->parse(value)); + } + } + else if (field == RequestHandler::KEY_EVID) + _ev = value; +} + + +void ComboBoxCell::handleRequest(const Poco::Net::HTTPServerRequest& request) +{ + //ev selected already handled in handleForm +} + + + +void ComboBoxCell::handleRequestAndResponse(const Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) +{ + // RequestHandler has already called all the handeForm stuff + if (_ev == EV_LOAD) + { + Poco::Net::HTTPServerResponse* pResponse = &response; + beforeLoad.notify(this, pResponse); + } + else + { + handleRequest(request); + response.send(); + } +} + + } } // namespace Poco::WebWidgets diff --git a/WebWidgets/src/Table.cpp b/WebWidgets/src/Table.cpp index 48f6f22a8..f72fb7173 100644 --- a/WebWidgets/src/Table.cpp +++ b/WebWidgets/src/Table.cpp @@ -190,7 +190,6 @@ void Table::handleRequestAndResponse(const Poco::Net::HTTPServerRequest& request } - void Table::handleValueChanged() { if (_col < 0 || _row < 0 || _col >= getColumnCount()) diff --git a/WebWidgets/src/TextField.cpp b/WebWidgets/src/TextField.cpp index 99f68976d..0f78ce85a 100644 --- a/WebWidgets/src/TextField.cpp +++ b/WebWidgets/src/TextField.cpp @@ -70,6 +70,15 @@ TextField::TextField(const std::type_info& type): } + +TextField::TextField(const std::string& name, const std::string& txt): + Control(name, typeid(TextField)) +{ + init(); + setString(txt); +} + + TextField::TextField(const std::string& name): Control(name, typeid(TextField)) {