Another SimpleVector down.
This commit is contained in:
73
src/form.cc
73
src/form.cc
@ -213,12 +213,12 @@ public:
|
|||||||
class DilloHtmlSelect {
|
class DilloHtmlSelect {
|
||||||
friend class DilloHtmlInput;
|
friend class DilloHtmlInput;
|
||||||
private:
|
private:
|
||||||
lout::misc::SimpleVector<DilloHtmlOptbase *> *opts;
|
std::vector< std::unique_ptr< DilloHtmlOptbase > > opts;
|
||||||
DilloHtmlSelect ();
|
|
||||||
|
DilloHtmlSelect ()= default;
|
||||||
public:
|
public:
|
||||||
~DilloHtmlSelect ();
|
|
||||||
DilloHtmlOptbase *getCurrentOpt ();
|
DilloHtmlOptbase *getCurrentOpt ();
|
||||||
void addOpt (DilloHtmlOptbase *opt);
|
void addOpt (std::unique_ptr< DilloHtmlOptbase > opt);
|
||||||
void ensureSelection ();
|
void ensureSelection ();
|
||||||
void addOptsTo (SelectionResource *res);
|
void addOptsTo (SelectionResource *res);
|
||||||
void reset (SelectionResource *res);
|
void reset (SelectionResource *res);
|
||||||
@ -813,10 +813,9 @@ void Html_tag_open_optgroup(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
label = "";
|
label = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
DilloHtmlOptgroup *opt =
|
auto opt= std::make_unique< DilloHtmlOptgroup >( dStrdup( label.value().c_str() ), enabled );
|
||||||
new DilloHtmlOptgroup (dStrdup(label.value().c_str()), enabled);
|
|
||||||
|
|
||||||
input->select->addOpt(opt);
|
input->select->addOpt( std::move( opt ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -834,9 +833,9 @@ void Html_tag_close_optgroup(DilloHtml *html)
|
|||||||
if (input &&
|
if (input &&
|
||||||
(input->type == DILLO_HTML_INPUT_SELECT ||
|
(input->type == DILLO_HTML_INPUT_SELECT ||
|
||||||
input->type == DILLO_HTML_INPUT_SEL_LIST)) {
|
input->type == DILLO_HTML_INPUT_SEL_LIST)) {
|
||||||
DilloHtmlOptgroupClose *opt = new DilloHtmlOptgroupClose ();
|
auto opt= std::make_unique< DilloHtmlOptgroupClose >();
|
||||||
|
|
||||||
input->select->addOpt(opt);
|
input->select->addOpt( std::move( opt ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -863,10 +862,10 @@ void Html_tag_open_option(DilloHtml *html, const char *tag, int tagsize)
|
|||||||
bool selected = (a_Html_get_attr(html, tag, tagsize,"selected") != NULL);
|
bool selected = (a_Html_get_attr(html, tag, tagsize,"selected") != NULL);
|
||||||
bool enabled = (a_Html_get_attr(html, tag, tagsize, "disabled") == NULL);
|
bool enabled = (a_Html_get_attr(html, tag, tagsize, "disabled") == NULL);
|
||||||
|
|
||||||
DilloHtmlOption *option =
|
auto option =
|
||||||
new DilloHtmlOption (value ? dStrdup( value.value().c_str() ) : nullptr, label ? dStrdup( label.value().c_str() ) : nullptr, selected, enabled);
|
std::make_unique< DilloHtmlOption >(value ? dStrdup( value.value().c_str() ) : nullptr, label ? dStrdup( label.value().c_str() ) : nullptr, selected, enabled );
|
||||||
|
|
||||||
input->select->addOpt(option);
|
input->select->addOpt( std::move( option ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
a_Html_stash_init(html);
|
a_Html_stash_init(html);
|
||||||
@ -1833,35 +1832,17 @@ void DilloHtmlInput::reset ()
|
|||||||
* DilloHtmlSelect
|
* DilloHtmlSelect
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* Constructor
|
DilloHtmlOptbase *
|
||||||
*/
|
DilloHtmlSelect::getCurrentOpt()
|
||||||
DilloHtmlSelect::DilloHtmlSelect ()
|
|
||||||
{
|
{
|
||||||
opts = new misc::SimpleVector<DilloHtmlOptbase *> (4);
|
return opts.back().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
void
|
||||||
* Destructor
|
DilloHtmlSelect::addOpt( std::unique_ptr< DilloHtmlOptbase > opt )
|
||||||
*/
|
|
||||||
DilloHtmlSelect::~DilloHtmlSelect ()
|
|
||||||
{
|
{
|
||||||
int size = opts->size ();
|
opts.push_back( std::move( opt ) );
|
||||||
for (int k = 0; k < size; k++)
|
|
||||||
delete opts->get (k);
|
|
||||||
delete opts;
|
|
||||||
}
|
|
||||||
|
|
||||||
DilloHtmlOptbase *DilloHtmlSelect::getCurrentOpt ()
|
|
||||||
{
|
|
||||||
return opts->get (opts->size() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DilloHtmlSelect::addOpt (DilloHtmlOptbase *opt)
|
|
||||||
{
|
|
||||||
int size = opts->size ();
|
|
||||||
opts->increase ();
|
|
||||||
opts->set (size, opt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1869,15 +1850,15 @@ void DilloHtmlSelect::addOpt (DilloHtmlOptbase *opt)
|
|||||||
*/
|
*/
|
||||||
void DilloHtmlSelect::ensureSelection()
|
void DilloHtmlSelect::ensureSelection()
|
||||||
{
|
{
|
||||||
int size = opts->size ();
|
int size = opts.size ();
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
DilloHtmlOptbase *opt = opts->get (i);
|
DilloHtmlOptbase *opt = opts.at (i).get();
|
||||||
if (opt->isSelected())
|
if (opt->isSelected())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
DilloHtmlOptbase *opt = opts->get (i);
|
DilloHtmlOptbase *opt = opts.at (i).get();
|
||||||
if (opt->select())
|
if (opt->select())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1886,28 +1867,28 @@ void DilloHtmlSelect::ensureSelection()
|
|||||||
|
|
||||||
void DilloHtmlSelect::addOptsTo (SelectionResource *res)
|
void DilloHtmlSelect::addOptsTo (SelectionResource *res)
|
||||||
{
|
{
|
||||||
int size = opts->size ();
|
int size = opts.size ();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
DilloHtmlOptbase *opt = opts->get (i);
|
DilloHtmlOptbase *opt = opts.at (i).get();
|
||||||
opt->addSelf(res);
|
opt->addSelf(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DilloHtmlSelect::reset (SelectionResource *res)
|
void DilloHtmlSelect::reset (SelectionResource *res)
|
||||||
{
|
{
|
||||||
int size = opts->size ();
|
int size = opts.size ();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
DilloHtmlOptbase *opt = opts->get (i);
|
DilloHtmlOptbase *opt = opts.at (i).get();
|
||||||
res->setItem(i, opt->isSelected());
|
res->setItem(i, opt->isSelected());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DilloHtmlSelect::appendValuesTo (std::vector< std::string > &values, SelectionResource *res)
|
void DilloHtmlSelect::appendValuesTo (std::vector< std::string > &values, SelectionResource *res)
|
||||||
{
|
{
|
||||||
int size = opts->size ();
|
int size = opts.size ();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
if (res->isSelected (i)) {
|
if (res->isSelected (i)) {
|
||||||
DilloHtmlOptbase *opt = opts->get (i);
|
DilloHtmlOptbase *opt = opts.at (i).get();
|
||||||
const char *val = opt->getValue();
|
const char *val = opt->getValue();
|
||||||
|
|
||||||
if (val)
|
if (val)
|
||||||
|
Reference in New Issue
Block a user