Removed a few of the SimpleVector lists.

This commit is contained in:
2025-04-09 13:02:23 -04:00
parent 36d04ad1c4
commit f29c4f3992
3 changed files with 57 additions and 65 deletions

View File

@ -27,6 +27,9 @@
#include "uicmd.hh" #include "uicmd.hh"
#include "dialog.hh" #include "dialog.hh"
#include <memory>
#include <vector>
using namespace lout; using namespace lout;
using namespace dw; using namespace dw;
using namespace dw::core; using namespace dw::core;
@ -102,7 +105,7 @@ public: //BUG: for now everything is public
DilloHtmlEnc content_type; DilloHtmlEnc content_type;
char *submit_charset; char *submit_charset;
lout::misc::SimpleVector<DilloHtmlInput*> *inputs; std::vector< std::shared_ptr< DilloHtmlInput > > inputs;
int num_entry_fields; int num_entry_fields;
@ -114,12 +117,12 @@ public:
DilloHtmlEnc content_type, const char *charset, DilloHtmlEnc content_type, const char *charset,
bool enabled); bool enabled);
~DilloHtmlForm (); ~DilloHtmlForm ();
DilloHtmlInput *getInput (Resource *resource); std::shared_ptr< DilloHtmlInput > getInput (Resource *resource);
DilloHtmlInput *getRadioInput (const char *name); std::shared_ptr< DilloHtmlInput > getRadioInput (const char *name);
void submit(DilloHtmlInput *active_input, EventButton *event); void submit(DilloHtmlInput *active_input, EventButton *event);
void reset (); void reset ();
void display_hiddens(bool display); void display_hiddens(bool display);
void addInput(DilloHtmlInput *input, DilloHtmlInputType type); void addInput(std::unique_ptr< DilloHtmlInput > input, DilloHtmlInputType type);
void setEnabled(bool enabled); void setEnabled(bool enabled);
}; };
@ -278,58 +281,56 @@ static void Html_add_input(DilloHtml *html, DilloHtmlInputType type,
const char *init_str, bool init_val) const char *init_str, bool init_val)
{ {
_MSG("name=[%s] init_str=[%s] init_val=[%d]\n", name, init_str, init_val); _MSG("name=[%s] init_str=[%s] init_val=[%d]\n", name, init_str, init_val);
DilloHtmlInput *input = new DilloHtmlInput(type, embed, name, init_str, auto input = std::make_unique< DilloHtmlInput >(type, embed, name, init_str,
init_val); init_val);
if (html->InFlags & IN_FORM) { if (html->InFlags & IN_FORM) {
html->getCurrentForm()->addInput(input, type); html->getCurrentForm()->addInput( std::move( input ), type );
} else { } else {
int ni = html->inputs_outside_form->size();
html->inputs_outside_form->increase();
html->inputs_outside_form->set(ni, input);
if (html->bw->NumPendingStyleSheets > 0) { if (html->bw->NumPendingStyleSheets > 0) {
input->setEnabled(false); input->setEnabled(false);
} }
html->inputs_outside_form.push_back( std::move( input ) );
} }
} }
/** /**
* Find radio input by name * Find radio input by name
*/ */
static DilloHtmlInput *Html_get_radio_input(DilloHtml *html, const char *name) static std::shared_ptr< DilloHtmlInput > Html_get_radio_input(DilloHtml *html, const char *name)
{ {
if (name) { if (name) {
lout::misc::SimpleVector<DilloHtmlInput*>* inputs; std::vector< std::shared_ptr< DilloHtmlInput > > *inputs;
if (html->InFlags & IN_FORM) if (html->InFlags & IN_FORM)
inputs = html->getCurrentForm()->inputs; inputs = &html->getCurrentForm()->inputs;
else else
inputs = html->inputs_outside_form; inputs = &html->inputs_outside_form;
for (int idx = 0; idx < inputs->size(); idx++) { for (int idx = 0; idx < inputs->size(); idx++) {
DilloHtmlInput *input = inputs->get(idx); auto input = inputs->at(idx);
if (input->type == DILLO_HTML_INPUT_RADIO && if (input->type == DILLO_HTML_INPUT_RADIO &&
input->name && !dStrAsciiCasecmp(input->name, name)) input->name && !dStrAsciiCasecmp(input->name, name))
return input; return input;
} }
} }
return NULL; return nullptr;
} }
/** /**
* Get the current input if available. * Get the current input if available.
*/ */
static DilloHtmlInput *Html_get_current_input(DilloHtml *html) static std::shared_ptr< DilloHtmlInput > Html_get_current_input(DilloHtml &html)
{ {
lout::misc::SimpleVector<DilloHtmlInput*>* inputs; std::vector< std::shared_ptr< DilloHtmlInput > > *inputs;
if (html->InFlags & IN_FORM) if (html.InFlags & IN_FORM)
inputs = html->getCurrentForm()->inputs; inputs = &html.getCurrentForm()->inputs;
else else
inputs = html->inputs_outside_form; inputs = &html.inputs_outside_form;
return (inputs && inputs->size() > 0) ? return (inputs && inputs->size() > 0) ?
inputs->get (inputs->size() - 1) : NULL; inputs->at (inputs->size() - 1) : nullptr;
} }
/** /**
@ -472,7 +473,7 @@ void Html_tag_open_input(DilloHtml *html, const char *tag, int tagsize)
} else if (!dStrAsciiCasecmp(type, "radio")) { } else if (!dStrAsciiCasecmp(type, "radio")) {
inp_type = DILLO_HTML_INPUT_RADIO; inp_type = DILLO_HTML_INPUT_RADIO;
RadioButtonResource *rb_r = NULL; RadioButtonResource *rb_r = NULL;
DilloHtmlInput *input = Html_get_radio_input(html, name); std::shared_ptr input = Html_get_radio_input(html, name);
if (input) if (input)
rb_r = (RadioButtonResource*) input->embed->getResource(); rb_r = (RadioButtonResource*) input->embed->getResource();
resource = factory->createRadioButtonResource(rb_r, false); resource = factory->createRadioButtonResource(rb_r, false);
@ -695,7 +696,6 @@ void Html_tag_content_textarea(DilloHtml *html, const char *tag, int tagsize)
void Html_tag_close_textarea(DilloHtml *html) void Html_tag_close_textarea(DilloHtml *html)
{ {
char *str; char *str;
DilloHtmlInput *input;
int i; int i;
if (html->InFlags & IN_TEXTAREA && !S_TOP(html)->display_none) { if (html->InFlags & IN_TEXTAREA && !S_TOP(html)->display_none) {
@ -718,7 +718,7 @@ void Html_tag_close_textarea(DilloHtml *html)
/* The HTML3.2 spec says it can have "text and character entities". */ /* The HTML3.2 spec says it can have "text and character entities". */
str = a_Html_parse_entities(html, html->Stash->str, html->Stash->len); str = a_Html_parse_entities(html, html->Stash->str, html->Stash->len);
input = Html_get_current_input(html); auto input = Html_get_current_input(*html);
if (input) { if (input) {
input->init_str = str; input->init_str = str;
((MultiLineTextResource *)input->embed->getResource ())->setText(str); ((MultiLineTextResource *)input->embed->getResource ())->setText(str);
@ -793,7 +793,7 @@ void Html_tag_close_select(DilloHtml *html)
html->InFlags &= ~IN_SELECT; html->InFlags &= ~IN_SELECT;
html->InFlags &= ~IN_OPTION; html->InFlags &= ~IN_OPTION;
DilloHtmlInput *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;
if (input->type == DILLO_HTML_INPUT_SELECT) { if (input->type == DILLO_HTML_INPUT_SELECT) {
@ -822,7 +822,7 @@ void Html_tag_open_optgroup(DilloHtml *html, const char *tag, int tagsize)
html->InFlags |= IN_OPTGROUP; html->InFlags |= IN_OPTGROUP;
DilloHtmlInput *input = Html_get_current_input(html); auto input = Html_get_current_input(*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)) {
@ -851,7 +851,7 @@ void Html_tag_close_optgroup(DilloHtml *html)
html->InFlags &= ~IN_OPTION; html->InFlags &= ~IN_OPTION;
} }
DilloHtmlInput *input = Html_get_current_input(html); auto input = Html_get_current_input(*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)) {
@ -875,7 +875,7 @@ void Html_tag_open_option(DilloHtml *html, const char *tag, int tagsize)
Html_option_finish(html); Html_option_finish(html);
html->InFlags |= IN_OPTION; html->InFlags |= IN_OPTION;
DilloHtmlInput *input = Html_get_current_input(html); auto input = Html_get_current_input(*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)) {
@ -1000,7 +1000,6 @@ DilloHtmlForm::DilloHtmlForm (DilloHtml *html2,
action = a_Url_dup(action2); action = a_Url_dup(action2);
content_type = content_type2; content_type = content_type2;
submit_charset = dStrdup(charset); submit_charset = dStrdup(charset);
inputs = new misc::SimpleVector <DilloHtmlInput*> (4);
num_entry_fields = 0; num_entry_fields = 0;
showing_hiddens = false; showing_hiddens = false;
this->enabled = enabled; this->enabled = enabled;
@ -1014,9 +1013,7 @@ DilloHtmlForm::~DilloHtmlForm ()
{ {
a_Url_free(action); a_Url_free(action);
dFree(submit_charset); dFree(submit_charset);
for (int j = 0; j < inputs->size(); j++) inputs.clear();
delete inputs->get(j);
delete(inputs);
if (form_receiver) if (form_receiver)
delete(form_receiver); delete(form_receiver);
} }
@ -1027,7 +1024,7 @@ void DilloHtmlForm::eventHandler(Resource *resource, EventButton *event)
if (event && (event->button == 3)) { if (event && (event->button == 3)) {
a_UIcmd_form_popup(html->bw, html->page_url, this, showing_hiddens); a_UIcmd_form_popup(html->bw, html->page_url, this, showing_hiddens);
} else { } else {
DilloHtmlInput *input = getInput(resource); auto input = getInput(resource);
if (input) { if (input) {
input->activate (this, num_entry_fields, event); input->activate (this, num_entry_fields, event);
} else { } else {
@ -1166,10 +1163,10 @@ Dstr *DilloHtmlForm::buildQueryData(DilloHtmlInput *active_submit)
Dlist *values = dList_new(5); Dlist *values = dList_new(5);
DataStr = dStr_sized_new(4096); DataStr = dStr_sized_new(4096);
for (int i = 0; i < inputs->size(); i++) { for (int i = 0; i < inputs.size(); i++) {
DilloHtmlInput *input = inputs->get (i); auto input = inputs.at (i);
Dstr *name = dStr_new(input->name); Dstr *name = dStr_new(input->name);
bool is_active_submit = (input == active_submit); bool is_active_submit = (input.get() == active_submit);
int valcount; int valcount;
name = encodeText(char_encoder, &name); name = encodeText(char_encoder, &name);
@ -1282,10 +1279,10 @@ char *DilloHtmlForm::makeMultipartBoundary(iconv_t char_encoder,
char *ret = NULL; char *ret = NULL;
/* fill DataStr with names, filenames, and values */ /* fill DataStr with names, filenames, and values */
for (int i = 0; i < inputs->size(); i++) { for (int i = 0; i < inputs.size(); i++) {
Dstr *dstr; Dstr *dstr;
DilloHtmlInput *input = inputs->get (i); auto input = inputs.at (i);
bool is_active_submit = (input == active_submit); bool is_active_submit = (input.get() == active_submit);
input->appendValuesTo(values, is_active_submit); input->appendValuesTo(values, is_active_submit);
if (input->name) { if (input->name) {
@ -1533,9 +1530,9 @@ void DilloHtmlForm::imageInputMultipartAppend(Dstr *data, const char *boundary,
*/ */
void DilloHtmlForm::reset () void DilloHtmlForm::reset ()
{ {
int size = inputs->size(); int size = inputs.size();
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
inputs->get(i)->reset(); inputs.at(i)->reset();
} }
/** /**
@ -1543,9 +1540,9 @@ void DilloHtmlForm::reset ()
*/ */
void DilloHtmlForm::display_hiddens(bool display) void DilloHtmlForm::display_hiddens(bool display)
{ {
int size = inputs->size(); int size = inputs.size();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
DilloHtmlInput *input = inputs->get(i); auto input = inputs.at(i);
if (input->type == DILLO_HTML_INPUT_HIDDEN) { if (input->type == DILLO_HTML_INPUT_HIDDEN) {
input->embed->setDisplayed(display); input->embed->setDisplayed(display);
} }
@ -1555,20 +1552,18 @@ void DilloHtmlForm::display_hiddens(bool display)
void DilloHtmlForm::setEnabled(bool enabled) void DilloHtmlForm::setEnabled(bool enabled)
{ {
for (int i = 0; i < inputs->size(); i++) for (int i = 0; i < inputs.size(); i++)
inputs->get(i)->setEnabled(enabled); inputs.at(i)->setEnabled(enabled);
} }
/** /**
* Add a new input. * Add a new input.
*/ */
void DilloHtmlForm::addInput(DilloHtmlInput *input, DilloHtmlInputType type) void DilloHtmlForm::addInput(std::unique_ptr< DilloHtmlInput > input, DilloHtmlInputType type)
{ {
input->connectTo (form_receiver); input->connectTo (form_receiver);
input->setEnabled (enabled); input->setEnabled (enabled);
int ni = inputs->size (); inputs.push_back( std::move( input ) );
inputs->increase ();
inputs->set (ni,input);
/* some stats */ /* some stats */
if (type == DILLO_HTML_INPUT_PASSWORD || if (type == DILLO_HTML_INPUT_PASSWORD ||
@ -1580,29 +1575,29 @@ void DilloHtmlForm::addInput(DilloHtmlInput *input, DilloHtmlInputType type)
/** /**
* Return the input with a given resource. * Return the input with a given resource.
*/ */
DilloHtmlInput *DilloHtmlForm::getInput (Resource *resource) std::shared_ptr< DilloHtmlInput > DilloHtmlForm::getInput (Resource *resource)
{ {
for (int idx = 0; idx < inputs->size(); idx++) { for (int idx = 0; idx < inputs.size(); idx++) {
DilloHtmlInput *input = inputs->get(idx); auto input = inputs.at(idx);
if (input->embed && if (input->embed &&
resource == input->embed->getResource()) resource == input->embed->getResource())
return input; return input;
} }
return NULL; return nullptr;
} }
/** /**
* Return a Radio input for the given name. * Return a Radio input for the given name.
*/ */
DilloHtmlInput *DilloHtmlForm::getRadioInput (const char *name) std::shared_ptr< DilloHtmlInput > DilloHtmlForm::getRadioInput (const char *name)
{ {
for (int idx = 0; idx < inputs->size(); idx++) { for (int idx = 0; idx < inputs.size(); idx++) {
DilloHtmlInput *input = inputs->get(idx); auto input = inputs.at(idx);
if (input->type == DILLO_HTML_INPUT_RADIO && if (input->type == DILLO_HTML_INPUT_RADIO &&
input->name && !dStrAsciiCasecmp(input->name, name)) input->name && !dStrAsciiCasecmp(input->name, name))
return input; return input;
} }
return NULL; return nullptr;
} }
/* /*
@ -1624,7 +1619,7 @@ void DilloHtmlReceiver::activate (Resource *resource)
void DilloHtmlReceiver::enter (Resource *resource) void DilloHtmlReceiver::enter (Resource *resource)
{ {
DilloHtml *html = form->html; DilloHtml *html = form->html;
DilloHtmlInput *input = form->getInput(resource); auto input = form->getInput(resource);
const char *msg = ""; const char *msg = "";
if ((input->type == DILLO_HTML_INPUT_SUBMIT) || if ((input->type == DILLO_HTML_INPUT_SUBMIT) ||
@ -2057,7 +2052,7 @@ static Embed *Html_input_image(DilloHtml *html, const char *tag, int tagsize)
*/ */
static void Html_option_finish(DilloHtml *html) static void Html_option_finish(DilloHtml *html)
{ {
DilloHtmlInput *input = Html_get_current_input(html); auto input = Html_get_current_input(*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)) {

View File

@ -507,7 +507,6 @@ DilloHtml::DilloHtml(BrowserWindow *p_bw, const DilloUrl *url,
/* Init page-handling variables */ /* Init page-handling variables */
forms.reserve(1); forms.reserve(1);
inputs_outside_form = new misc::SimpleVector <DilloHtmlInput*> (1);
links.reserve(64); links.reserve(64);
images = new misc::SimpleVector <DilloHtmlImage*> (16); images = new misc::SimpleVector <DilloHtmlImage*> (16);
@ -553,9 +552,7 @@ DilloHtml::~DilloHtml()
a_Html_form_delete (forms.at(i)); a_Html_form_delete (forms.at(i));
forms.clear(); forms.clear();
for (int i = 0; i < inputs_outside_form->size(); i++) inputs_outside_form.clear();
a_Html_input_delete(inputs_outside_form->get(i));
delete(inputs_outside_form);
for (auto &link: links) for (auto &link: links)
// TODO: `DilloUrl` has to become RAII... // TODO: `DilloUrl` has to become RAII...

View File

@ -214,7 +214,7 @@ public: //BUG: for now everything is public
/* Variables required after parsing (for page functionality) */ /* Variables required after parsing (for page functionality) */
/* -------------------------------------------------------------------*/ /* -------------------------------------------------------------------*/
std::vector< DilloHtmlForm * > forms; std::vector< DilloHtmlForm * > forms;
lout::misc::SimpleVector<DilloHtmlInput*> *inputs_outside_form; std::vector< std::shared_ptr< DilloHtmlInput > > inputs_outside_form;
std::vector< std::unique_ptr< DilloUrl > > links; std::vector< std::unique_ptr< DilloUrl > > links;
lout::misc::SimpleVector<DilloHtmlImage*> *images; lout::misc::SimpleVector<DilloHtmlImage*> *images;
dw::ImageMapsList maps; dw::ImageMapsList maps;