listbox fixes

This commit is contained in:
Peter Schojer
2008-09-26 09:23:43 +00:00
parent 585a7f147b
commit 22e337614c
17 changed files with 1608 additions and 1250 deletions

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="9.00" Version="9,00"
Name="ExtJS" Name="ExtJS"
ProjectGUID="{19FA461F-7419-4653-8A6B-B93002F7DB14}" ProjectGUID="{19FA461F-7419-4653-8A6B-B93002F7DB14}"
RootNamespace="ExtJS" RootNamespace="ExtJS"
@@ -53,7 +53,6 @@
RuntimeTypeInfo="true" RuntimeTypeInfo="true"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4" DebugInformationFormat="4"
CompileAs="0" CompileAs="0"
/> />
@@ -76,7 +75,7 @@
GenerateDebugInformation="true" GenerateDebugInformation="true"
ProgramDatabaseFile="..\..\bin\Poco$(ProjectName)d.pdb" ProgramDatabaseFile="..\..\bin\Poco$(ProjectName)d.pdb"
SubSystem="1" SubSystem="1"
OptimizeForWindows98="1" OptimizeForWindows98="0"
RandomizedBaseAddress="1" RandomizedBaseAddress="1"
DataExecutionPrevention="0" DataExecutionPrevention="0"
ImportLibrary="..\..\lib\Poco$(ProjectName)d.lib" ImportLibrary="..\..\lib\Poco$(ProjectName)d.lib"
@@ -145,7 +144,6 @@
RuntimeTypeInfo="true" RuntimeTypeInfo="true"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="0" DebugInformationFormat="0"
CompileAs="0" CompileAs="0"
/> />
@@ -170,7 +168,7 @@
SubSystem="1" SubSystem="1"
OptimizeReferences="2" OptimizeReferences="2"
EnableCOMDATFolding="2" EnableCOMDATFolding="2"
OptimizeForWindows98="1" OptimizeForWindows98="0"
RandomizedBaseAddress="1" RandomizedBaseAddress="1"
DataExecutionPrevention="0" DataExecutionPrevention="0"
ImportLibrary="..\..\lib\Poco$(ProjectName).lib" ImportLibrary="..\..\lib\Poco$(ProjectName).lib"

View File

@@ -42,12 +42,17 @@
#include "Poco/WebWidgets/ExtJS/ExtJS.h" #include "Poco/WebWidgets/ExtJS/ExtJS.h"
#include "Poco/WebWidgets/Renderer.h" #include "Poco/WebWidgets/Renderer.h"
#include "Poco/WebWidgets/JSDelegate.h"
namespace Poco { namespace Poco {
namespace Net {
class HTTPServerResponse;
}
namespace WebWidgets { namespace WebWidgets {
class ListBoxCell; class ListBoxCell;
class ListBox;
namespace ExtJS { namespace ExtJS {
@@ -56,6 +61,9 @@ class ExtJS_API ListBoxCellRenderer: public Poco::WebWidgets::Renderer
/// ListBoxCellRenderer renders a button /// ListBoxCellRenderer renders a button
{ {
public: public:
static const std::string EV_ROWSELECT;
static const std::string EV_ROWDESELECT;
ListBoxCellRenderer(); ListBoxCellRenderer();
/// Creates the ListBoxCellRenderer. /// Creates the ListBoxCellRenderer.
@@ -70,6 +78,14 @@ public:
static void renderProperties(const ListBoxCell* pCell, std::ostream& ostr); static void renderProperties(const ListBoxCell* pCell, std::ostream& ostr);
/// Renders button properties /// Renders button properties
static Poco::WebWidgets::JSDelegate createRowSelectionServerCallback(const ListBox* pList);
static void onBeforeLoad(void* pSender, std::pair<ListBoxCell*, Poco::Net::HTTPServerResponse*>& ld);
static Poco::WebWidgets::JSDelegate createAfterLoadServerCallback(const ListBox* pList);
/// Adds a javascript callback to inform the WebServer that the client has finished loading data
/// Method signature is ( Store this, Ext.data.Record[] records, Object options )
}; };

View File

@@ -41,6 +41,7 @@
#include "Poco/WebWidgets/Button.h" #include "Poco/WebWidgets/Button.h"
#include "Poco/WebWidgets/RequestHandler.h" #include "Poco/WebWidgets/RequestHandler.h"
#include "Poco/WebWidgets/WebApplication.h" #include "Poco/WebWidgets/WebApplication.h"
#include "Poco/WebWidgets/WebWidgetsException.h"
#include "Poco/NumberFormatter.h" #include "Poco/NumberFormatter.h"
@@ -89,6 +90,8 @@ void ButtonCellRenderer::renderProperties(const ButtonCell* pButtonCell, const s
{ {
ostr << "type:'submit',"; ostr << "type:'submit',";
Form::Ptr pForm = Utility::insideForm(pButtonCell); Form::Ptr pForm = Utility::insideForm(pButtonCell);
if (!pForm)
throw WebWidgetsException("SubmitButton must be used inside a form!");
ostr << "handler: function(){Ext.getCmp('" << pForm->id() << "').getForm().submit();},"; ostr << "handler: function(){Ext.getCmp('" << pForm->id() << "').getForm().submit();},";
} }
View* pView = pButtonCell->getOwner(); View* pView = pButtonCell->getOwner();

View File

@@ -36,8 +36,15 @@
#include "Poco/WebWidgets/ExtJS/ListBoxCellRenderer.h" #include "Poco/WebWidgets/ExtJS/ListBoxCellRenderer.h"
#include "Poco/WebWidgets/ExtJS/FormRenderer.h" #include "Poco/WebWidgets/ExtJS/FormRenderer.h"
#include "Poco/WebWidgets/ExtJS/TableRenderer.h"
#include "Poco/WebWidgets/ExtJS/Utility.h" #include "Poco/WebWidgets/ExtJS/Utility.h"
#include "Poco/WebWidgets/ListBoxCell.h" #include "Poco/WebWidgets/ListBoxCell.h"
#include "Poco/WebWidgets/ListBox.h"
#include "Poco/WebWidgets/RequestHandler.h"
#include "Poco/WebWidgets/Table.h"
#include "Poco/Net/HTTPServerResponse.h"
#include "Poco/Delegate.h"
#include "Poco/NumberFormatter.h"
#include <sstream> #include <sstream>
@@ -46,6 +53,10 @@ namespace WebWidgets {
namespace ExtJS { namespace ExtJS {
const std::string ListBoxCellRenderer::EV_ROWSELECT("rowselect");
const std::string ListBoxCellRenderer::EV_ROWDESELECT("rowdeselect");
ListBoxCellRenderer::ListBoxCellRenderer() ListBoxCellRenderer::ListBoxCellRenderer()
{ {
} }
@@ -77,45 +88,123 @@ void ListBoxCellRenderer::renderBody(const Renderable* pRenderable, const Render
void ListBoxCellRenderer::renderProperties(const ListBoxCell* pListBoxCell, std::ostream& ostr) void ListBoxCellRenderer::renderProperties(const ListBoxCell* pListBoxCell, std::ostream& ostr)
{ {
Utility::writeRenderableProperties(pListBoxCell, ostr); Utility::writeCellProperties(pListBoxCell, ostr);
if (pListBoxCell->getHeight() > 0)
ostr << ",height:" << pListBoxCell->getHeight();
if (pListBoxCell->getWidth() > 0)
ostr << ",width:" << pListBoxCell->getWidth();
const View* pOwner = pListBoxCell->getOwner(); const View* pOwner = pListBoxCell->getOwner();
poco_check_ptr (pOwner); poco_check_ptr (pOwner);
const ListBox* pList = dynamic_cast<const ListBox*>(pOwner);
if (pOwner->hasPosition()) if (pOwner->hasPosition())
ostr << ",x:" << pOwner->getPosition().posX << ",y:" << pOwner->getPosition().posY; ostr << ",x:" << pOwner->getPosition().posX << ",y:" << pOwner->getPosition().posY;
ostr << ",dataFields:['i','d'],data:["; if (pList)
{
bool hasListeners = (pList->rowDeselected.hasJavaScriptCode() ||
pList->rowSelected.hasJavaScriptCode());
if (hasListeners)
{
ostr << ",listeners:{";
bool comma = false;
if (pList->rowDeselected.hasJavaScriptCode())
comma = Utility::writeJSEvent(ostr, EV_ROWDESELECT, pList->rowDeselected, &ListBoxCellRenderer::createRowSelectionServerCallback, pList);
if (pList->rowDeselected.hasJavaScriptCode())
{
if (comma) ostr << ",";
comma = Utility::writeJSEvent(ostr, EV_ROWSELECT, pList->rowSelected, &ListBoxCellRenderer::createRowSelectionServerCallback, pList);
}
ostr << "}";
}
}
// store: afterLoad, beforeLaod event
ostr << ",store:new Ext.data.SimpleStore({autoLoad:true,fields:[{name:'i'},{name:'d'}]";
ostr << ",proxy:new Ext.data.HttpProxy({url:";
std::map<std::string, std::string> addParams;
addParams.insert(std::make_pair(RequestHandler::KEY_EVID, ListBoxCell::EV_LOADDATA));
std::string url(Utility::createURI(addParams, pList->id()));
ostr << url << "})";
ostr << ",reader:new Ext.data.ArrayReader()";
if (pList->afterLoad.hasJavaScriptCode())
{
ostr << ",listeners:{";
Utility::writeJSEvent(ostr, Table::EV_AFTERLOAD, pList->afterLoad, &ListBoxCellRenderer::createAfterLoadServerCallback, pList);
ostr << "}";
}
ostr << "})";
ostr << ",dataFields:['i','d'],initVal:'";
//now serialize data, use cached content for that //now serialize data, use cached content for that
ListBoxCell::StringData::const_iterator it = pListBoxCell->beginString();
ListBoxCell::StringData::const_iterator itEnd = pListBoxCell->endString();
ListBoxCell::Data::const_iterator itV = pListBoxCell->begin(); ListBoxCell::Data::const_iterator itV = pListBoxCell->begin();
ListBoxCell::Data::const_iterator itVEnd = pListBoxCell->end(); ListBoxCell::Data::const_iterator itVEnd = pListBoxCell->end();
int cnt = 0;
bool selected=false; bool selected=false;
std::ostringstream initValue; int cnt(0);
initValue << "'"; for (; itV != itVEnd; ++itV, ++cnt)
for (; it != itEnd; ++it, ++cnt, ++itV)
{ {
if (it != pListBoxCell->beginString())
ostr << ",";
if (itV->second) if (itV->second)
{ {
if (selected) if (selected)
initValue << ","; ostr << ",";
initValue << cnt; ostr << cnt;
selected = true; selected = true;
} }
}
ostr << "'";
ostr << ",valueField:'i',displayField:'d'";
ListBoxCell* pL = const_cast<ListBoxCell*>(pListBoxCell);
pL->beforeLoad += Poco::delegate(&ListBoxCellRenderer::onBeforeLoad);
WebApplication::instance().registerAjaxProcessor(Poco::NumberFormatter::format(pList->id()), pL);
if (!pOwner->getName().empty())
{
WebApplication::instance().registerFormProcessor(pOwner->getName(), pL);
}
}
Poco::WebWidgets::JSDelegate ListBoxCellRenderer::createRowSelectionServerCallback(const ListBox* pList)
{
// rowselect : ( Ext.ux.Multiselect field, Int idx, bool selected )
static const std::string signature("function(field,idx,sel)");
std::map<std::string, std::string> addParams;
addParams.insert(std::make_pair(ListBoxCell::ARG_ROW, "+idx"));
addParams.insert(std::make_pair(ListBoxCell::ARG_SELECTED, "+(sel?'1':'0')"));
addParams.insert(std::make_pair(RequestHandler::KEY_EVID, ListBoxCell::EV_ROWSELECTED));
return Utility::createServerCallback(signature, addParams, pList->id(), pList->rowSelected.getOnSuccess(), pList->rowSelected.getOnFailure());
}
Poco::WebWidgets::JSDelegate ListBoxCellRenderer::createAfterLoadServerCallback(const ListBox* pList)
{
poco_check_ptr (pList);
static const std::string signature("function(aStore, recs, op)");
std::map<std::string, std::string> addParams;
addParams.insert(std::make_pair(RequestHandler::KEY_EVID, ListBoxCell::EV_AFTERLOAD));
return Utility::createServerCallback(signature, addParams, pList->id(), pList->afterLoad.getOnSuccess(), pList->afterLoad.getOnFailure());
}
void ListBoxCellRenderer::onBeforeLoad(void* pSender, std::pair<ListBoxCell*, Poco::Net::HTTPServerResponse*>& ld)
{
ld.second->setChunkedTransferEncoding(true);
ld.second->setContentType("text/javascript");
std::ostream& ostr = ld.second->send();
//[
// ['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
// ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am']
//]
ostr << "[";
ListBoxCell::StringData::const_iterator it = ld.first->beginString();
ListBoxCell::StringData::const_iterator itEnd = ld.first->endString();
int cnt = 0;
for (; it != itEnd; ++it, ++cnt)
{
if (it != ld.first->beginString())
ostr << ",";
ostr << "['" << cnt << "','" << *it << "']"; ostr << "['" << cnt << "','" << *it << "']";
} }
initValue << "'";
ostr << "]"; ostr << "]";
ostr << ",valueField:'i',displayField:'d',initVal:" << initValue.str();
} }

View File

@@ -170,7 +170,6 @@ Poco::WebWidgets::JSDelegate TableRenderer::createAfterLoadServerCallback(const
} }
Poco::WebWidgets::JSDelegate TableRenderer::createRenderServerCallback(const Table* pTable) Poco::WebWidgets::JSDelegate TableRenderer::createRenderServerCallback(const Table* pTable)
{ {
poco_check_ptr (pTable); poco_check_ptr (pTable);

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="9.00" Version="9,00"
Name="TestSuite" Name="TestSuite"
ProjectGUID="{AB43A995-70FA-4297-BD01-6C88938AA86D}" ProjectGUID="{AB43A995-70FA-4297-BD01-6C88938AA86D}"
Keyword="Win32Proj" Keyword="Win32Proj"
@@ -52,7 +52,6 @@
RuntimeTypeInfo="true" RuntimeTypeInfo="true"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4" DebugInformationFormat="4"
/> />
<Tool <Tool
@@ -139,7 +138,6 @@
RuntimeTypeInfo="true" RuntimeTypeInfo="true"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3" DebugInformationFormat="3"
/> />
<Tool <Tool

View File

@@ -46,6 +46,7 @@ Ext.extend(Ext.ux.DDView, Ext.DataView, {
/** @cfg {String/Array} dropGroup The ddgroup name(s) for the View's DropZone. */ /** @cfg {String/Array} dropGroup The ddgroup name(s) for the View's DropZone. */
/** @cfg {Boolean} copy Causes drag operations to copy nodes rather than move. */ /** @cfg {Boolean} copy Causes drag operations to copy nodes rather than move. */
/** @cfg {Boolean} allowCopy Causes ctrl/drag operations to copy nodes rather than move. */ /** @cfg {Boolean} allowCopy Causes ctrl/drag operations to copy nodes rather than move. */
dragDisabled:false,
sortDir: 'ASC', sortDir: 'ASC',
@@ -82,20 +83,24 @@ Ext.extend(Ext.ux.DDView, Ext.DataView, {
return true; return true;
}, },
destroy: function() { onDestroy: function() {
this.purgeListeners(); this.purgeListeners();
this.getEl().removeAllListeners(); this.getEl().removeAllListeners();
this.getEl().remove(); this.getEl().remove();
if (this.dragZone) { if (this.dragZone) {
Ext.dd.ScrollManager.unregister(this.dragZone.el);
if (this.dragZone.destroy) { if (this.dragZone.destroy) {
this.dragZone.destroy(); this.dragZone.destroy();
this.dragZone.proxy.el.destroy();
} }
} }
if (this.dropZone) { if (this.dropZone) {
Ext.dd.ScrollManager.unregister(this.dropZone.el);
if (this.dropZone.destroy) { if (this.dropZone.destroy) {
this.dropZone.destroy(); this.dropZone.destroy();
} }
} }
Ext.ux.DDView.superclass.onDestroy.call(this);
}, },
/** Allows this class to be an Ext.form.Field so it can be found using {@link Ext.form.BasicForm#findField}. */ /** Allows this class to be an Ext.form.Field so it can be found using {@link Ext.form.BasicForm#findField}. */
@@ -278,6 +283,7 @@ Ext.extend(Ext.ux.DDView, Ext.DataView, {
}, },
isValidDropPoint: function(pt, n, data) { isValidDropPoint: function(pt, n, data) {
if (this.dragDisabled) return false;
if (!data.viewNodes || (data.viewNodes.length != 1)) { if (!data.viewNodes || (data.viewNodes.length != 1)) {
return true; return true;
} }
@@ -333,6 +339,7 @@ Ext.extend(Ext.ux.DDView, Ext.DataView, {
}, },
onNodeDrop : function(n, dd, e, data){ onNodeDrop : function(n, dd, e, data){
if (this.dragDisabled) return false;
if (this.fireEvent("drop", this, n, dd, e, data) === false) { if (this.fireEvent("drop", this, n, dd, e, data) === false) {
return false; return false;
} }

View File

@@ -1,4 +1,4 @@
//version 3.0 //version 3.0.2
Ext.ux.Multiselect = Ext.extend(Ext.form.Field, { Ext.ux.Multiselect = Ext.extend(Ext.form.Field, {
store:null, store:null,
@@ -27,7 +27,6 @@ Ext.ux.Multiselect = Ext.extend(Ext.form.Field, {
appendOnly:false, appendOnly:false,
sortField:null, sortField:null,
sortDir:'ASC', sortDir:'ASC',
initVal:null,
defaultAutoCreate : {tag: "div"}, defaultAutoCreate : {tag: "div"},
initComponent: function(){ initComponent: function(){
@@ -36,15 +35,15 @@ Ext.ux.Multiselect = Ext.extend(Ext.form.Field, {
'dblclick' : true, 'dblclick' : true,
'click' : true, 'click' : true,
'change' : true, 'change' : true,
'drop' : true 'drop' : true,
'rowselect' : true,
'rowdeselect' : true
}); });
}, },
onRender: function(ct, position){ onRender: function(ct, position){
var fs, cls, tpl; var fs, cls, tpl;
Ext.ux.Multiselect.superclass.onRender.call(this, ct, position); Ext.ux.Multiselect.superclass.onRender.call(this, ct, position);
cls = 'ux-mselect'; cls = 'ux-mselect';
fs = new Ext.form.FieldSet({ fs = new Ext.form.FieldSet({
@@ -55,7 +54,10 @@ Ext.ux.Multiselect = Ext.extend(Ext.form.Field, {
style:"padding:1px;", style:"padding:1px;",
tbar:this.tbar tbar:this.tbar
}); });
if(!this.legend) { var e = fs.el.down('.'+fs.headerCls); if(e) {e.remove();}} if(!this.legend){
var x = fs.el.down('.'+fs.headerCls);
if (x) x.remove();
}
fs.body.addClass(cls); fs.body.addClass(cls);
tpl = '<tpl for="."><div class="' + cls + '-item'; tpl = '<tpl for="."><div class="' + cls + '-item';
@@ -78,8 +80,6 @@ Ext.ux.Multiselect = Ext.extend(Ext.form.Field, {
sortField:this.sortField, sortDir:this.sortDir sortField:this.sortField, sortDir:this.sortDir
}); });
fs.add(this.view);
this.view.on('click', this.onViewClick, this); this.view.on('click', this.onViewClick, this);
this.view.on('beforeClick', this.onViewBeforeClick, this); this.view.on('beforeClick', this.onViewBeforeClick, this);
this.view.on('dblclick', this.onViewDblClick, this); this.view.on('dblclick', this.onViewDblClick, this);
@@ -94,11 +94,6 @@ Ext.ux.Multiselect = Ext.extend(Ext.form.Field, {
} else { } else {
this.hiddenField = Ext.get(document.body).createChild(hiddenTag); this.hiddenField = Ext.get(document.body).createChild(hiddenTag);
} }
if (this.initVal != null)
{
this.setValue(this.initVal);
this.initVal = null;
}
fs.doLayout(); fs.doLayout();
}, },
@@ -111,6 +106,11 @@ Ext.ux.Multiselect = Ext.extend(Ext.form.Field, {
this.preClickSelections.splice(arrayIndex, 1); this.preClickSelections.splice(arrayIndex, 1);
this.view.clearSelections(true); this.view.clearSelections(true);
this.view.select(this.preClickSelections); this.view.select(this.preClickSelections);
var sel = this.view.isSelected(arrayIndex);
if (sel)
this.fireEvent('rowselect', this, arrayIndex, sel);
else
this.fireEvent('rowdeselect', this, arrayIndex, sel);
} }
this.fireEvent('change', this, this.getValue(), this.hiddenField.dom.value); this.fireEvent('change', this, this.getValue(), this.hiddenField.dom.value);
this.hiddenField.dom.value = this.getValue(); this.hiddenField.dom.value = this.getValue();
@@ -194,7 +194,26 @@ Ext.ux.Multiselect = Ext.extend(Ext.form.Field, {
return false; return false;
} }
return true; return true;
},
onDestroy : function(){
if( this.view ) {
this.view.destroy();
} }
if (this.hiddenField) {
this.hiddenField.remove();
}
Ext.ux.Multiselect.superclass.onDestroy.call(this);
},
onEnable : function(){
this.el.unmask();
},
onDisable : function(){
this.el.mask();
}
}); });
Ext.reg("multiselect", Ext.ux.Multiselect); Ext.reg("multiselect", Ext.ux.Multiselect);
@@ -257,7 +276,7 @@ Ext.ux.ItemSelector = Ext.extend(Ext.form.Field, {
copy: this.allowDup, copy: this.allowDup,
allowTrash: this.allowDup, allowTrash: this.allowDup,
dragGroup: this.readOnly ? null : "drop2-"+this.el.dom.id, dragGroup: this.readOnly ? null : "drop2-"+this.el.dom.id,
dropGroup: this.readOnly ? null : "drop1-"+this.el.dom.id, dropGroup: this.readOnly ? null : "drop2-"+this.el.dom.id+",drop1-"+this.el.dom.id,
width: this.msWidth, width: this.msWidth,
height: this.msHeight, height: this.msHeight,
dataFields: this.dataFields, dataFields: this.dataFields,
@@ -288,7 +307,6 @@ Ext.ux.ItemSelector = Ext.extend(Ext.form.Field, {
delimiter: this.delimiter, delimiter: this.delimiter,
allowDup: this.allowDup, allowDup: this.allowDup,
dragGroup: this.readOnly ? null : "drop1-"+this.el.dom.id, dragGroup: this.readOnly ? null : "drop1-"+this.el.dom.id,
//dropGroup: this.readOnly ? null : "drop2-"+this.el.dom.id+(this.toSortField ? "" : ",drop1-"+this.el.dom.id),
dropGroup: this.readOnly ? null : "drop2-"+this.el.dom.id+",drop1-"+this.el.dom.id, dropGroup: this.readOnly ? null : "drop2-"+this.el.dom.id+",drop1-"+this.el.dom.id,
width: this.msWidth, width: this.msWidth,
height: this.msHeight, height: this.msHeight,
@@ -369,6 +387,7 @@ Ext.ux.ItemSelector = Ext.extend(Ext.form.Field, {
initValue:Ext.emptyFn, initValue:Ext.emptyFn,
toTop : function() { toTop : function() {
if(this.disabled)return;
var selectionsArray = this.toMultiselect.view.getSelectedIndexes(); var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
var records = []; var records = [];
if (selectionsArray.length > 0) { if (selectionsArray.length > 0) {
@@ -390,6 +409,7 @@ Ext.ux.ItemSelector = Ext.extend(Ext.form.Field, {
}, },
toBottom : function() { toBottom : function() {
if(this.disabled)return;
var selectionsArray = this.toMultiselect.view.getSelectedIndexes(); var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
var records = []; var records = [];
if (selectionsArray.length > 0) { if (selectionsArray.length > 0) {
@@ -411,6 +431,7 @@ Ext.ux.ItemSelector = Ext.extend(Ext.form.Field, {
}, },
up : function() { up : function() {
if(this.disabled)return;
var record = null; var record = null;
var selectionsArray = this.toMultiselect.view.getSelectedIndexes(); var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
selectionsArray.sort(); selectionsArray.sort();
@@ -430,6 +451,7 @@ Ext.ux.ItemSelector = Ext.extend(Ext.form.Field, {
}, },
down : function() { down : function() {
if(this.disabled)return;
var record = null; var record = null;
var selectionsArray = this.toMultiselect.view.getSelectedIndexes(); var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
selectionsArray.sort(); selectionsArray.sort();
@@ -450,6 +472,7 @@ Ext.ux.ItemSelector = Ext.extend(Ext.form.Field, {
}, },
fromTo : function() { fromTo : function() {
if(this.disabled)return;
var selectionsArray = this.fromMultiselect.view.getSelectedIndexes(); var selectionsArray = this.fromMultiselect.view.getSelectedIndexes();
var records = []; var records = [];
if (selectionsArray.length > 0) { if (selectionsArray.length > 0) {
@@ -480,6 +503,7 @@ Ext.ux.ItemSelector = Ext.extend(Ext.form.Field, {
}, },
toFrom : function() { toFrom : function() {
if(this.disabled)return;
var selectionsArray = this.toMultiselect.view.getSelectedIndexes(); var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
var records = []; var records = [];
if (selectionsArray.length > 0) { if (selectionsArray.length > 0) {
@@ -530,7 +554,28 @@ Ext.ux.ItemSelector = Ext.extend(Ext.form.Field, {
this.fromMultiselect.store.sort(this.displayField,'ASC'); this.fromMultiselect.store.sort(this.displayField,'ASC');
} }
this.valueChanged(this.toMultiselect.store); this.valueChanged(this.toMultiselect.store);
},
onDestroy : function(){
if( this.fromMultiselect ) {
this.fromMultiselect.destroy();
} }
if( this.toMultiselect ) {
this.toMultiselect.destroy();
}
Ext.ux.ItemSelector.superclass.onDestroy.call(this);
},
onEnable : function(){
this.fromMultiselect.enable();
this.toMultiselect.enable();
},
onDisable : function(){
this.fromMultiselect.disable();
this.toMultiselect.disable();
}
}); });
Ext.reg("itemselector", Ext.ux.ItemSelector); Ext.reg("itemselector", Ext.ux.ItemSelector);

View File

@@ -69,6 +69,7 @@
#include "Poco/WebWidgets/SimpleTableModel.h" #include "Poco/WebWidgets/SimpleTableModel.h"
#include "Poco/WebWidgets/JSDelegate.h" #include "Poco/WebWidgets/JSDelegate.h"
#include "Poco/WebWidgets/ResourceManager.h" #include "Poco/WebWidgets/ResourceManager.h"
#include "Poco/WebWidgets/SubmitButton.h"
#include "Poco/TeeStream.h" #include "Poco/TeeStream.h"
#include "Poco/DateTimeFormat.h" #include "Poco/DateTimeFormat.h"
#include "Poco/DateTime.h" #include "Poco/DateTime.h"
@@ -1127,6 +1128,39 @@ void ExtJSTest::testListBox()
} }
void ExtJSTest::testFormListBox()
{
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);
Utility::initialize(laf);
Page::Ptr ptr = new Page("test");
webApp.setCurrentPage(ptr);
Form::Ptr ptrF = new Form(Poco::URI("/test"));
ptrF->setHeight(600);
ptrF->setWidth(800);
ptr->add(ptrF);
ListBox::Ptr ptrList(new ListBox("MyWindow"));
ptrList->setWidth(640);
ptrList->setHeight(400);
ptrF->add(ptrList);
ptrList->insert(std::string("First"), false);
ptrList->insert(std::string("FirstSelected"), true);
ptrList->insert(std::string("Second"), false);
ptrList->insert(std::string("SecondSelected"), true);
ptrF->add(new SubmitButton("", "Click"));
std::ostringstream ostr;
std::ofstream fstr("testFormListBox.html");
TeeOutputStream out(ostr);
out.addStream(fstr);
ptr->renderHead(context, out);
ptr->renderBody(context, out);
std::string result = ostr.str();
}
void ExtJSTest::testDateFormatConversion() void ExtJSTest::testDateFormatConversion()
{ {
std::string result = Utility::convertPocoDateToPHPDate(Poco::DateTimeFormat::ISO8601_FORMAT); std::string result = Utility::convertPocoDateToPHPDate(Poco::DateTimeFormat::ISO8601_FORMAT);
@@ -1606,6 +1640,7 @@ CppUnit::Test* ExtJSTest::suite()
CppUnit_addTest(pSuite, ExtJSTest, testFormFrameVerticalLayout); CppUnit_addTest(pSuite, ExtJSTest, testFormFrameVerticalLayout);
CppUnit_addTest(pSuite, ExtJSTest, testFormGridLayoutNullElements); CppUnit_addTest(pSuite, ExtJSTest, testFormGridLayoutNullElements);
CppUnit_addTest(pSuite, ExtJSTest, testFormImage); CppUnit_addTest(pSuite, ExtJSTest, testFormImage);
CppUnit_addTest(pSuite, ExtJSTest, testFormListBox);
CppUnit_addTest(pSuite, ExtJSTest, testDateFormatConversion); CppUnit_addTest(pSuite, ExtJSTest, testDateFormatConversion);
CppUnit_addTest(pSuite, ExtJSTest, testCollapsible); CppUnit_addTest(pSuite, ExtJSTest, testCollapsible);
CppUnit_addTest(pSuite, ExtJSTest, testCollapsible2); CppUnit_addTest(pSuite, ExtJSTest, testCollapsible2);

View File

@@ -68,6 +68,7 @@ public:
void testFormFrameHorizontalLayout(); void testFormFrameHorizontalLayout();
void testFormFrameVerticalLayout(); void testFormFrameVerticalLayout();
void testFormImage(); void testFormImage();
void testFormListBox();
void testTabView(); void testTabView();
void testCollapsible(); void testCollapsible();
void testCollapsible2(); void testCollapsible2();

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="9.00" Version="9,00"
Name="WebWidgets" Name="WebWidgets"
ProjectGUID="{8962DAD7-4F7B-46D0-A451-8D3476606890}" ProjectGUID="{8962DAD7-4F7B-46D0-A451-8D3476606890}"
RootNamespace="WebWidgets" RootNamespace="WebWidgets"
@@ -53,7 +53,6 @@
RuntimeTypeInfo="true" RuntimeTypeInfo="true"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4" DebugInformationFormat="4"
CompileAs="0" CompileAs="0"
/> />
@@ -76,7 +75,7 @@
GenerateDebugInformation="true" GenerateDebugInformation="true"
ProgramDatabaseFile="..\bin\Poco$(ProjectName)d.pdb" ProgramDatabaseFile="..\bin\Poco$(ProjectName)d.pdb"
SubSystem="1" SubSystem="1"
OptimizeForWindows98="1" OptimizeForWindows98="0"
RandomizedBaseAddress="1" RandomizedBaseAddress="1"
DataExecutionPrevention="0" DataExecutionPrevention="0"
ImportLibrary="..\lib\Poco$(ProjectName)d.lib" ImportLibrary="..\lib\Poco$(ProjectName)d.lib"
@@ -145,7 +144,6 @@
RuntimeTypeInfo="true" RuntimeTypeInfo="true"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="0" DebugInformationFormat="0"
CompileAs="0" CompileAs="0"
/> />
@@ -170,7 +168,7 @@
SubSystem="1" SubSystem="1"
OptimizeReferences="2" OptimizeReferences="2"
EnableCOMDATFolding="2" EnableCOMDATFolding="2"
OptimizeForWindows98="1" OptimizeForWindows98="0"
RandomizedBaseAddress="1" RandomizedBaseAddress="1"
DataExecutionPrevention="0" DataExecutionPrevention="0"
ImportLibrary="..\lib\Poco$(ProjectName).lib" ImportLibrary="..\lib\Poco$(ProjectName).lib"

View File

@@ -42,6 +42,8 @@
#include "Poco/WebWidgets/Control.h" #include "Poco/WebWidgets/Control.h"
#include "Poco/WebWidgets/ListBoxCell.h" #include "Poco/WebWidgets/ListBoxCell.h"
#include "Poco/WebWidgets/JavaScriptEvent.h"
#include "Poco/FIFOEvent.h"
#include <vector> #include <vector>
@@ -54,7 +56,16 @@ class WebWidgets_API ListBox: public Control
{ {
public: public:
typedef Poco::AutoPtr<ListBox> Ptr; typedef Poco::AutoPtr<ListBox> Ptr;
typedef ListBoxCell::Data Data; /// An element plus its selected flag as pair typedef ListBoxCell::Data Data; /// An element plus its selected flag as std::pair
typedef ListBoxCell::RowValueChange RowValueChange; /// the row plus old and new value
FIFOEvent<Poco::Net::HTTPServerResponse*> beforeLoad; /// thrown whenever a load is requested, internal event to which the ListBoxCellRenderer must register
JavaScriptEvent<ListBox*> afterLoad; // thrown after data was loaded
JavaScriptEvent<int> rowSelected; /// fires the row selected event
JavaScriptEvent<int> rowDeselected; /// fires the row deselected event
ListBox(const std::string& name); ListBox(const std::string& name);
/// Creates a ListBox with the given name. /// Creates a ListBox with the given name.
@@ -62,18 +73,6 @@ public:
ListBox(); ListBox();
/// Creates an anonymous TextField. /// Creates an anonymous TextField.
void setHeight(int height);
/// Sets the height in pixel. A negative value equals autoSize.
int getHeight() const;
/// Returns the height in pixel. A negative value equals autoSize.
void setWidth(int width);
/// Sets the width in pixel. A negative value equals autoSize.
int getWidth() const;
/// Returns the width in pixel. A negative value equals autoSize.
Data::const_iterator begin() const; Data::const_iterator begin() const;
/// ConstIterator to all elements /// ConstIterator to all elements
@@ -104,6 +103,18 @@ public:
void deselect(const Any& elem); void deselect(const Any& elem);
/// Deselects the element. /// Deselects the element.
void selectByIndex(int idx, bool sel = true);
/// Selects the element by Index. idx values that are out of range are ignored
void deselectByIndex(int idx);
/// Deselects the element. idx values that are out of range are ignored
void selectAll(bool sel= true);
/// Selects all elements
void deselectAll();
/// Deselects all elements
bool hasSelected() const; bool hasSelected() const;
/// Returns true if at least one selected element exists /// Returns true if at least one selected element exists
@@ -117,10 +128,10 @@ protected:
ListBox(const std::type_info& type); ListBox(const std::type_info& type);
/// Creates a ListBox. /// Creates a ListBox.
ListBox(const std::string& name, const std::type_info& type, Cell::Ptr ptrCell); ListBox(const std::string& name, const std::type_info& type, ListBoxCell::Ptr ptrCell);
/// Creates a ListBox and assigns it the given name. /// Creates a ListBox and assigns it the given name.
ListBox(const std::type_info& type, Cell::Ptr ptrCell); ListBox(const std::type_info& type, ListBoxCell::Ptr ptrCell);
/// Creates a ListBox. /// Creates a ListBox.
~ListBox(); ~ListBox();
@@ -131,6 +142,17 @@ protected:
void init(Cell::Ptr pCell); void init(Cell::Ptr pCell);
/// Common init code for all ctors. /// Common init code for all ctors.
void fireBeforeLoad(std::pair<ListBoxCell*, Poco::Net::HTTPServerResponse*>& data);
void fireAfterLoad(void* pSender);
void fireRowSelected(int& pos);
void fireRowDeselected(int& pos);
private:
ListBoxCell* _pLBCell;
}; };
@@ -138,101 +160,103 @@ protected:
// inlines // inlines
// //
inline void ListBox::setHeight(int height)
{
cell<ListBoxCell>()->setHeight(height);
}
inline int ListBox::getHeight() const
{
return cell<ListBoxCell>()->getHeight();
}
inline void ListBox::setWidth(int width)
{
cell<ListBoxCell>()->setWidth(width);
}
inline int ListBox::getWidth() const
{
return cell<ListBoxCell>()->getWidth();
}
inline bool ListBox::hasSelected() const inline bool ListBox::hasSelected() const
{ {
return cell<ListBoxCell>()->hasSelected(); return _pLBCell->hasSelected();
} }
inline ListBox::Data::const_iterator ListBox::begin() const inline ListBox::Data::const_iterator ListBox::begin() const
{ {
return cell<ListBoxCell>()->begin(); return _pLBCell->begin();
} }
inline ListBox::Data::iterator ListBox::begin() inline ListBox::Data::iterator ListBox::begin()
{ {
return cell<ListBoxCell>()->begin(); return _pLBCell->begin();
} }
inline ListBox::Data::const_iterator ListBox::end() const inline ListBox::Data::const_iterator ListBox::end() const
{ {
return cell<ListBoxCell>()->end(); return _pLBCell->end();
} }
inline ListBox::Data::iterator ListBox::end() inline ListBox::Data::iterator ListBox::end()
{ {
return cell<ListBoxCell>()->end(); return _pLBCell->end();
} }
inline void ListBox::setElements(const ListBox::Data& elems) inline void ListBox::setElements(const ListBox::Data& elems)
{ {
cell<ListBoxCell>()->setElements(elems); _pLBCell->setElements(elems);
} }
inline const ListBox::Data& ListBox::getElements() const inline const ListBox::Data& ListBox::getElements() const
{ {
return cell<ListBoxCell>()->getElements(); return _pLBCell->getElements();
} }
inline void ListBox::insert(const Any& elem, bool selected) inline void ListBox::insert(const Any& elem, bool selected)
{ {
cell<ListBoxCell>()->insert(elem, selected); _pLBCell->insert(elem, selected);
} }
inline void ListBox::erase(const Any& elem) inline void ListBox::erase(const Any& elem)
{ {
cell<ListBoxCell>()->erase(elem); _pLBCell->erase(elem);
} }
inline void ListBox::select(const Any& elem) inline void ListBox::select(const Any& elem)
{ {
cell<ListBoxCell>()->select(elem); _pLBCell->select(elem);
} }
inline void ListBox::deselect(const Any& elem) inline void ListBox::deselect(const Any& elem)
{ {
cell<ListBoxCell>()->deselect(elem); _pLBCell->deselect(elem);
} }
inline const Any& ListBox::getSelected() const inline const Any& ListBox::getSelected() const
{ {
return cell<ListBoxCell>()->getSelected(); return _pLBCell->getSelected();
} }
inline void ListBox::selectByIndex(int idx, bool sel)
{
_pLBCell->selectByIndex(idx, sel);
}
inline void ListBox::deselectByIndex(int idx)
{
_pLBCell->deselectByIndex(idx);
}
inline void ListBox::selectAll(bool sel)
{
_pLBCell->selectAll(sel);
}
inline void ListBox::deselectAll()
{
_pLBCell->deselectAll();
}
} } // namespace Poco::WebWidgets } } // namespace Poco::WebWidgets

View File

@@ -41,10 +41,15 @@
#include "Poco/WebWidgets/Cell.h" #include "Poco/WebWidgets/Cell.h"
#include "Poco/WebWidgets/Delegate.h"
#include "Poco/FIFOEvent.h"
#include <vector> #include <vector>
namespace Poco { namespace Poco {
namespace Net {
class HTTPServerResponse;
}
namespace WebWidgets { namespace WebWidgets {
@@ -57,21 +62,34 @@ public:
typedef std::vector<std::pair<Any, bool> > Data; /// An element plus its selected flag typedef std::vector<std::pair<Any, bool> > Data; /// An element plus its selected flag
typedef std::vector<std::string> StringData; typedef std::vector<std::string> StringData;
static const std::string EV_LOADDATA;
static const std::string EV_AFTERLOAD;
static const std::string EV_ROWSELECTED;
static const std::string ARG_SELECTED;
static const std::string ARG_ROW;
static const std::string VAL_SELECTED;
static const std::string VAL_DESELECTED;
FIFOEvent<std::pair<ListBoxCell*, Poco::Net::HTTPServerResponse*> > beforeLoad; /// thrown whenever a load is requested, internal event to which the ListBoxCellRenderer must register
Delegate afterLoad; // thrown after data was loaded
FIFOEvent<int> rowSelected; /// fires the row selected event
FIFOEvent<int> rowDeselected; /// fires the row selected event
struct WebWidgets_API RowValueChange
/// Data sent with a rowValueChanged event.
{
std::size_t row;
const Poco::Any oldValue;
const Poco::Any newValue;
RowValueChange(std::size_t row, const Poco::Any& oldValue, const Poco::Any& newValue);
};
ListBoxCell(View* pOwner); ListBoxCell(View* pOwner);
/// Creates a ListBoxCell. /// Creates a ListBoxCell.
void setHeight(int height);
/// Sets the height in pixel. A negative value equals autoSize.
int getHeight() const;
/// Returns the height in pixel. A negative value equals autoSize.
void setWidth(int width);
/// Sets the width in pixel. A negative value equals autoSize.
int getWidth() const;
/// Returns the width in pixel. A negative value equals autoSize.
Data::const_iterator begin() const; Data::const_iterator begin() const;
/// ConstIterator to all elements /// ConstIterator to all elements
@@ -108,15 +126,31 @@ public:
void deselect(const Any& elem); void deselect(const Any& elem);
/// Deselects the element. /// Deselects the element.
void selectByIndex(int idx, bool sel = true);
/// Selects the element by Index. idx values that are out of range are ignored
void deselectByIndex(int idx);
/// Deselects the element. idx values that are out of range are ignored
void selectAll(bool sel= true);
/// Selects all elements
void deselectAll();
/// Deselects all elements
bool hasSelected() const; bool hasSelected() const;
/// Returns true if at least one selected element exists /// Returns true if at least one selected element exists
const Any& getSelected() const; const Any& getSelected() const;
/// Returns the first selected element, exception if none was selected /// Returns the first selected element, exception if none was selected.
/// To get all selected elements use getElements and iterate over the
/// returned vector
// Cell // Cell
void handleForm(const std::string& field, const std::string& value); void handleForm(const std::string& field, const std::string& value);
void handleAjaxRequest(const Poco::Net::NameValueCollection& args, Poco::Net::HTTPServerResponse& response);
bool serializeJSON(std::ostream& out, const std::string& name); bool serializeJSON(std::ostream& out, const std::string& name);
protected: protected:
@@ -135,37 +169,12 @@ protected:
private: private:
Data _data; Data _data;
StringData _fmtCache; StringData _fmtCache;
int _height;
int _width;
}; };
// //
// inlines // inlines
// //
inline void ListBoxCell::setHeight(int height)
{
_height = height;
}
inline int ListBoxCell::getHeight() const
{
return _height;
}
inline void ListBoxCell::setWidth(int width)
{
_width = width;
}
inline int ListBoxCell::getWidth() const
{
return _width;
}
inline ListBoxCell::Data::const_iterator ListBoxCell::begin() const inline ListBoxCell::Data::const_iterator ListBoxCell::begin() const
{ {
@@ -216,6 +225,18 @@ inline ListBoxCell::StringData::const_iterator ListBoxCell::endString() const
} }
inline void ListBoxCell::deselectByIndex(int idx)
{
selectByIndex(idx, false);
}
inline void ListBoxCell::deselectAll()
{
selectAll(false);
}
} } // namespace Poco::WebWidgets } } // namespace Poco::WebWidgets

View File

@@ -36,20 +36,21 @@
#include "Poco/WebWidgets/ListBox.h" #include "Poco/WebWidgets/ListBox.h"
#include "Poco/WebWidgets/ListBoxCell.h" #include "Poco/WebWidgets/ListBoxCell.h"
#include "Poco/Delegate.h"
namespace Poco { namespace Poco {
namespace WebWidgets { namespace WebWidgets {
ListBox::ListBox(const std::string& name, const std::type_info& type, Cell::Ptr ptrCell): ListBox::ListBox(const std::string& name, const std::type_info& type, ListBoxCell::Ptr ptrCell):
Control(name, type) Control(name, type)
{ {
init(ptrCell); init(ptrCell);
} }
ListBox::ListBox(const std::type_info& type, Cell::Ptr ptrCell): ListBox::ListBox(const std::type_info& type, ListBoxCell::Ptr ptrCell):
Control(type) Control(type)
{ {
init(ptrCell); init(ptrCell);
@@ -91,8 +92,12 @@ ListBox::~ListBox()
void ListBox::init() void ListBox::init()
{ {
ListBoxCell* pCell = new ListBoxCell(this); _pLBCell = new ListBoxCell(this);
setCell(pCell); _pLBCell->afterLoad = delegate(*this, &ListBox::fireAfterLoad);
_pLBCell->beforeLoad += Poco::delegate(this, &ListBox::fireBeforeLoad);
_pLBCell->rowDeselected += Poco::delegate(this, &ListBox::fireRowDeselected);
_pLBCell->rowSelected += Poco::delegate(this, &ListBox::fireRowSelected);
setCell(_pLBCell);
} }
@@ -100,11 +105,38 @@ void ListBox::init(Cell::Ptr ptrCell)
{ {
ListBoxCell::Ptr ptr = ptrCell.cast<ListBoxCell>(); ListBoxCell::Ptr ptr = ptrCell.cast<ListBoxCell>();
poco_check_ptr (ptr); poco_check_ptr (ptr);
_pLBCell = ptr;
_pLBCell->afterLoad = delegate(*this, &ListBox::fireAfterLoad);
_pLBCell->beforeLoad += Poco::delegate(this, &ListBox::fireBeforeLoad);
_pLBCell->rowDeselected += Poco::delegate(this, &ListBox::fireRowDeselected);
_pLBCell->rowSelected += Poco::delegate(this, &ListBox::fireRowSelected);
setCell(ptrCell); setCell(ptrCell);
} }
void ListBox::fireBeforeLoad(std::pair<ListBoxCell*, Poco::Net::HTTPServerResponse*>& data)
{
beforeLoad(this, data.second);
}
void ListBox::fireAfterLoad(void* pSender)
{
ListBox* pThis = this;
afterLoad(this, pThis);
}
void ListBox::fireRowSelected(int& pos)
{
rowSelected(this, pos);
}
void ListBox::fireRowDeselected(int& pos)
{
rowDeselected(this, pos);
}
} } // namespace Poco::WebWidgets } } // namespace Poco::WebWidgets

View File

@@ -35,20 +35,29 @@
#include "Poco/WebWidgets/ListBoxCell.h" #include "Poco/WebWidgets/ListBoxCell.h"
#include "Poco/WebWidgets/RequestHandler.h"
#include "Poco/DateTime.h" #include "Poco/DateTime.h"
#include "Poco/StringTokenizer.h"
#include "Poco/NumberParser.h"
namespace Poco { namespace Poco {
namespace WebWidgets { namespace WebWidgets {
const std::string ListBoxCell::EV_LOADDATA("load");
const std::string ListBoxCell::EV_AFTERLOAD("afterLoad");
const std::string ListBoxCell::EV_ROWSELECTED("rowSel");
const std::string ListBoxCell::ARG_SELECTED("sel");
const std::string ListBoxCell::ARG_ROW("row");
const std::string ListBoxCell::VAL_SELECTED("1");
const std::string ListBoxCell::VAL_DESELECTED("0");
ListBoxCell::ListBoxCell(View* pOwner): ListBoxCell::ListBoxCell(View* pOwner):
Cell(pOwner, typeid(ListBoxCell)), Cell(pOwner, typeid(ListBoxCell)),
_data(), _data(),
_fmtCache(), _fmtCache()
_height(-1),
_width(-1)
{ {
} }
@@ -56,9 +65,7 @@ ListBoxCell::ListBoxCell(View* pOwner):
ListBoxCell::ListBoxCell(View* pOwner, const std::type_info& type): ListBoxCell::ListBoxCell(View* pOwner, const std::type_info& type):
Cell(pOwner, type), Cell(pOwner, type),
_data(), _data(),
_fmtCache(), _fmtCache()
_height(-1),
_width(-1)
{ {
} }
@@ -70,7 +77,25 @@ ListBoxCell::~ListBoxCell()
void ListBoxCell::handleForm(const std::string& field, const std::string& value) void ListBoxCell::handleForm(const std::string& field, const std::string& value)
{ {
throw Poco::NotImplementedException(); // a ListBox inside a form will just send the selected values
// may contain multiple values like "field: 1,3"
// a deselectAll() would be wrong event wise
Poco::StringTokenizer tok(value, ",", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
std::set<int> selected;
for (Poco::StringTokenizer::Iterator it = tok.begin(); it != tok.end(); ++it)
{
int val(-1);
bool ok = Poco::NumberParser::tryParse(*it, val);
if (ok)
selected.insert(val);
}
for (int i = 0; i < _data.size(); ++i)
{
if (selected.find(i) != selected.end())
selectByIndex(i);
else
deselectByIndex(i);
}
} }
@@ -138,7 +163,14 @@ void ListBoxCell::select(const Any& elem)
{ {
Data::iterator it = find(elem); Data::iterator it = find(elem);
if (it != _data.end()) if (it != _data.end())
{
if (it->second != true)
{
it->second = true; it->second = true;
int idx = it - _data.begin();
rowSelected(this, idx);
}
}
} }
@@ -146,7 +178,14 @@ void ListBoxCell::deselect(const Any& elem)
{ {
Data::iterator it = find(elem); Data::iterator it = find(elem);
if (it != _data.end()) if (it != _data.end())
{
if (it->second != false)
{
it->second = false; it->second = false;
int idx = it - _data.begin();
rowDeselected(this, idx);
}
}
} }
@@ -172,18 +211,73 @@ const Any& ListBoxCell::getSelected() const
bool ListBoxCell::serializeJSON(std::ostream& out, const std::string& name) bool ListBoxCell::serializeJSON(std::ostream& out, const std::string& name)
{ {
out << name << ":"; out << name << ":";
if (hasSelected()) Data::const_iterator it = _data.begin();
bool written = false;
for (std::size_t i = 0; i < _data.size(); ++i)
{ {
const Poco::Any& sel = getSelected(); if (_data[i].second)
if (sel.type() == typeid(std::string) || sel.type() == typeid(Poco::DateTime)) {
out << ":'" << getFormatter()->format(sel) << "'"; if (written)
out << ",";
else else
out << ":" << getFormatter()->format(sel); written = true;
out << i;
} }
else }
if (!written)
out << "''"; out << "''";
return true; return true;
} }
void ListBoxCell::selectByIndex(int idx, bool sel)
{
if (idx >= 0 && idx < _data.size())
{
if (_data[idx].second != sel)
{
_data[idx].second = sel;
if (sel)
rowSelected(this, idx);
else
rowDeselected(this, idx);
}
}
}
void ListBoxCell::selectAll(bool sel)
{
Data::iterator it = _data.begin();
for (; it != _data.end(); ++it)
it->second = sel;
}
void ListBoxCell::handleAjaxRequest(const Poco::Net::NameValueCollection& args, Poco::Net::HTTPServerResponse& response)
{
const std::string& ev = args[RequestHandler::KEY_EVID];
if (ev == EV_LOADDATA)
{
Poco::Net::HTTPServerResponse* pResp = &response;
std::pair<ListBoxCell*, Poco::Net::HTTPServerResponse*> data = std::make_pair(this, pResp);
beforeLoad(this, data);
}
else if (ev == EV_AFTERLOAD)
{
afterLoad(this);
response.send();
}
else if (ev == EV_ROWSELECTED)
{
int row = Poco::NumberParser::parse(args[ARG_ROW]);
bool sel = (args.get(ARG_SELECTED) == VAL_SELECTED);
selectByIndex(row, sel);
response.send();
}
else
response.send();
}
} } // namespace Poco::WebWidgets } } // namespace Poco::WebWidgets

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="9.00" Version="9,00"
Name="TestSuite" Name="TestSuite"
ProjectGUID="{09255B72-C314-4E57-BCF8-73698222F042}" ProjectGUID="{09255B72-C314-4E57-BCF8-73698222F042}"
Keyword="Win32Proj" Keyword="Win32Proj"
@@ -52,7 +52,6 @@
RuntimeTypeInfo="true" RuntimeTypeInfo="true"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4" DebugInformationFormat="4"
/> />
<Tool <Tool
@@ -139,7 +138,6 @@
RuntimeTypeInfo="true" RuntimeTypeInfo="true"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3" DebugInformationFormat="3"
/> />
<Tool <Tool