Webdar 1.0.0
Web user interface to libdar
html_form_select.hpp
1/*********************************************************************/
2// webdar - a web server and interface program to libdar
3// Copyright (C) 2013-2025 Denis Corbin
4//
5// This file is part of Webdar
6//
7// Webdar is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// Webdar is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Webdar. If not, see <http://www.gnu.org/licenses/>
19//
20//----
21// to contact the author: dar.linux@free.fr
22/*********************************************************************/
23
24#ifndef HTML_FORM_SELECT_HPP
25#define HTML_FORM_SELECT_HPP
26
27 // C system header files
28#include "my_config.h"
29extern "C"
30{
31
32}
33
34 // C++ system header files
35
37
47
48 // webdar headers
49#include "html_form_radio.hpp"
50#include "html_label.hpp"
51
53{
54public:
55 static const std::string changed;
56
58
63 html_form_select(const std::string & label, const std::string & x_event_name = "");
65 html_form_select(html_form_select && ref) noexcept = delete;
66 html_form_select & operator = (const html_form_select & ref) = delete;
67 html_form_select & operator = (html_form_select && ref) noexcept = delete;
68 ~html_form_select() = default;
69
70 void change_label(const std::string & label) { x_label.set_label(label); my_body_part_has_changed(); };
71
72 // inherit from html_form_radio the following methods to feed contents
73 // . add_choice
74 // . clear
75 // . set_selected
76 // . get_selected_id
77 // . get_selected_num
78
79
81 virtual void on_event(const std::string & x_event_name) override { act(event_name); };
82
84 unsigned int size() const { return get_choices().size(); };
85
87
89 const std::string & get_id(unsigned int index) const { return get_choices()[index].id; };
90
92
94 const std::string & get_label(unsigned int index) const { return get_choices()[index].label.get_label(); };
95
97 void set_enabled(bool val);
98
100 void set_tooltip(const std::string & msg) { x_label.set_tooltip(msg); };
101
102protected:
104 virtual std::string inherited_get_body_part(const chemin & path,
105 const request & req) override;
106
107
108private:
109 bool enabled;
110 html_label x_label;
111 std::string event_name;
112
113};
114
115
116
117#endif
class of object that are pointed/triggered to by others
Definition: actor.hpp:55
void my_body_part_has_changed()
let a class record a change in what inherited_get_body_part() would return if it was called again wit...
Definition: body_builder.cpp:420
class chemin definition
Definition: chemin.hpp:51
void act(const std::string &name)
trigger a given event
Definition: events.cpp:151
class html_form_radio implements HTML "input" of type "radio"
Definition: html_form_radio.hpp:53
class html_form_select implements HTML input of type "select"
Definition: html_form_select.hpp:53
virtual void on_event(const std::string &x_event_name) override
inherited from actor
Definition: html_form_select.hpp:81
void set_tooltip(const std::string &msg)
set tooltip for the html label of the input form
Definition: html_form_select.hpp:100
const std::string & get_label(unsigned int index) const
provides recorded item label
Definition: html_form_select.hpp:94
virtual std::string inherited_get_body_part(const chemin &path, const request &req) override
inherited from body_builder
Definition: html_form_select.cpp:78
void set_enabled(bool val)
set whether the HTML control is enable or disabled
Definition: html_form_select.cpp:68
const std::string & get_id(unsigned int index) const
provides recorded item id
Definition: html_form_select.hpp:89
html_form_select(const std::string &label, const std::string &x_event_name="")
default event name for all object of this class
Definition: html_form_select.cpp:45
unsigned int size() const
number of available choices provided to the web user by this object
Definition: html_form_select.hpp:84
class html_label implements label and tooltips (helper string showing when mouse hovering)
Definition: html_label.hpp:47
void set_label(const std::string &val)
change the label value from the value provided at construction time
Definition: html_label.hpp:62
void set_tooltip(const std::string &helper)
set the helper to the tooltip (helper popup)
Definition: html_tooltip.cpp:45
class holding fields of an HTTP request (method, URI, header, cookies, and so on)
Definition: request.hpp:45