event fixes

This commit is contained in:
Peter Schojer 2008-09-04 10:13:16 +00:00
parent b16f06168b
commit 3e3ff2766c
4 changed files with 27 additions and 18 deletions

View File

@ -61,8 +61,9 @@ public:
typedef Poco::AutoPtr<ComboBox> Ptr;
typedef Event<ComboBox> ComboBoxEvent;
typedef ComboBoxCell::OldNewValue SelectEvent; /// a pair of old, then new value
JavaScriptEvent<ComboBoxEvent> selected; /// thrown whenever a new element is selected
JavaScriptEvent<const SelectEvent> selected; /// thrown whenever a new element is selected
JavaScriptEvent<ComboBoxEvent> afterLoad; // thrown after data was loaded
@ -126,11 +127,12 @@ protected:
~ComboBox();
/// Destroys the ComboBox.
void fireSelected(void* pSender);
void fireSelected(const void* pSender, const SelectEvent& oldNewPair);
/// Fires the selected event.
void fireAfterLoad(void* pSender);
/// Fires the afterLoad event.
};

View File

@ -56,13 +56,15 @@ class WebWidgets_API ComboBoxCell: public TextFieldCell
{
public:
typedef Poco::AutoPtr<ComboBoxCell> Ptr;
typedef std::pair<Poco::Any, Poco::Any> OldNewValue;
static const std::string EV_SELECTED;
static const std::string EV_LOAD;
static const std::string EV_AFTERLOAD;
static const std::string FIELD_VAL;
Delegate selected;
FIFOEvent<const OldNewValue> selected; /// thrown whenever a new element is selected
Delegate afterLoad;
FIFOEvent<Poco::Net::HTTPServerResponse*> beforeLoad; /// thrown whenever a load is requested
@ -177,14 +179,6 @@ inline void ComboBoxCell::insert(const Any& elem)
}
inline void ComboBoxCell::setSelected(const Any& elem)
/// Selects the element.
{
setValue(elem);
selected(this);
}
inline const Any& ComboBoxCell::getSelected() const
/// Returns the selected element, excpetion if none was selected
{

View File

@ -36,6 +36,7 @@
#include "Poco/WebWidgets/ComboBox.h"
#include "Poco/WebWidgets/ComboBoxCell.h"
#include "Poco/Delegate.h"
namespace Poco {
@ -46,7 +47,7 @@ ComboBox::ComboBox(const std::string& name, const std::type_info& type):
TextField(name, type, new ComboBoxCell(this))
{
ComboBoxCell::Ptr pCell = cell<ComboBoxCell>();
pCell->selected = delegate(*this, &ComboBox::fireSelected);
pCell->selected += Poco::delegate(this, &ComboBox::fireSelected);
pCell->afterLoad = delegate(*this, &ComboBox::fireAfterLoad);
}
@ -55,7 +56,8 @@ ComboBox::ComboBox(const std::type_info& type):
TextField(type, new ComboBoxCell(this))
{
ComboBoxCell::Ptr pCell = cell<ComboBoxCell>();
pCell->selected = delegate(*this, &ComboBox::fireSelected);
pCell->selected += Poco::delegate(this, &ComboBox::fireSelected);
pCell->afterLoad = delegate(*this, &ComboBox::fireAfterLoad);
}
@ -63,7 +65,8 @@ ComboBox::ComboBox(const std::string& name):
TextField(name, typeid(ComboBox), new ComboBoxCell(this))
{
ComboBoxCell::Ptr pCell = cell<ComboBoxCell>();
pCell->selected = delegate(*this, &ComboBox::fireSelected);
pCell->selected += Poco::delegate(this, &ComboBox::fireSelected);
pCell->afterLoad = delegate(*this, &ComboBox::fireAfterLoad);
}
@ -71,7 +74,8 @@ ComboBox::ComboBox():
TextField(typeid(ComboBox), new ComboBoxCell(this))
{
ComboBoxCell::Ptr pCell = cell<ComboBoxCell>();
pCell->selected = delegate(*this, &ComboBox::fireSelected);
pCell->selected += Poco::delegate(this, &ComboBox::fireSelected);
pCell->afterLoad = delegate(*this, &ComboBox::fireAfterLoad);
}
@ -80,10 +84,9 @@ ComboBox::~ComboBox()
}
void ComboBox::fireSelected(void* pSender)
void ComboBox::fireSelected(const void* pSender, const ComboBoxCell::OldNewValue& oldNewPair)
{
ComboBoxEvent sel(this);
selected(this, sel);
selected(this, oldNewPair);
}

View File

@ -113,4 +113,14 @@ void ComboBoxCell::handleAjaxRequest(const Poco::Net::NameValueCollection& args,
}
void ComboBoxCell::setSelected(const Any& elem)
{
Poco::Any old;
if (hasSelected())
old = getSelected();
OldNewValue aPair = std::make_pair(old, elem);
setValue(elem);
selected(this, aPair);
}
} } // namespace Poco::WebWidgets