HtmlInput ownership.

This commit is contained in:
2025-08-09 18:03:43 -04:00
parent f4281aea39
commit 0d99c78908

View File

@ -147,7 +147,7 @@ public: //BUG: for now everything is public
std::optional< std::string > init_str; /* note: some overloading - for buttons, init_str std::optional< std::string > init_str; /* note: some overloading - for buttons, init_str
is simply the value of the button; for text is simply the value of the button; for text
entries, it is the initial value */ entries, it is the initial value */
DilloHtmlSelect *select; std::unique_ptr< DilloHtmlSelect > select;
bool init_val; /* only meaningful for buttons */ bool init_val; /* only meaningful for buttons */
std::string file_data; /* only meaningful for file inputs. std::string file_data; /* only meaningful for file inputs.
TODO: may become a list... */ TODO: may become a list... */
@ -160,7 +160,6 @@ private:
public: public:
DilloHtmlInput (DilloHtmlInputType type, Embed *embed, DilloHtmlInput (DilloHtmlInputType type, Embed *embed,
const std::optional< std::string > &name, const std::optional< std::string > &init_str, bool init_val); const std::optional< std::string > &name, const std::optional< std::string > &init_str, bool init_val);
~DilloHtmlInput ();
void appendValuesTo(std::vector< std::string > &values, bool is_active_submit); void appendValuesTo(std::vector< std::string > &values, bool is_active_submit);
void reset(); void reset();
void setEnabled(bool enabled) {if (embed) embed->setEnabled(enabled); }; void setEnabled(bool enabled) {if (embed) embed->setEnabled(enabled); };
@ -216,8 +215,8 @@ class DilloHtmlSelect {
private: private:
lout::misc::SimpleVector<DilloHtmlOptbase *> *opts; lout::misc::SimpleVector<DilloHtmlOptbase *> *opts;
DilloHtmlSelect (); DilloHtmlSelect ();
~DilloHtmlSelect ();
public: public:
~DilloHtmlSelect ();
DilloHtmlOptbase *getCurrentOpt (); DilloHtmlOptbase *getCurrentOpt ();
void addOpt (DilloHtmlOptbase *opt); void addOpt (DilloHtmlOptbase *opt);
void ensureSelection (); void ensureSelection ();
@ -775,7 +774,7 @@ void Html_tag_close_select(DilloHtml *html)
auto input = Html_get_current_input(*html); auto input = Html_get_current_input(*html);
if (input) { if (input) {
DilloHtmlSelect *select = input->select; DilloHtmlSelect *select = input->select.get();
if (input->type == DILLO_HTML_INPUT_SELECT) { if (input->type == DILLO_HTML_INPUT_SELECT) {
// option menu interface requires that something be selected */ // option menu interface requires that something be selected */
select->ensureSelection (); select->ensureSelection ();
@ -1632,7 +1631,7 @@ DilloHtmlInput::DilloHtmlInput (DilloHtmlInputType type2, Embed *embed2,
switch (type) { switch (type) {
case DILLO_HTML_INPUT_SELECT: case DILLO_HTML_INPUT_SELECT:
case DILLO_HTML_INPUT_SEL_LIST: case DILLO_HTML_INPUT_SEL_LIST:
select = new DilloHtmlSelect; select.reset( new DilloHtmlSelect );
break; break;
default: default:
break; break;
@ -1640,15 +1639,6 @@ DilloHtmlInput::DilloHtmlInput (DilloHtmlInputType type2, Embed *embed2,
reset (); reset ();
} }
/*
* Destructor
*/
DilloHtmlInput::~DilloHtmlInput ()
{
if (select)
delete select;
}
/** /**
* Connect to a receiver. * Connect to a receiver.
*/ */