Webdar 1.0.0
Web user interface to libdar
html_form_radio.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_RADIO_HPP
25#define HTML_FORM_RADIO_HPP
26
27 // C system header files
28#include "my_config.h"
29extern "C"
30{
31
32}
33
34 // C++ system header files
35#include <vector>
36
37 // webdar headers
38#include "body_builder.hpp"
39#include "events.hpp"
40#include "html_label.hpp"
41
43
51
52class html_form_radio : public body_builder, public events
53{
54public:
55 static const std::string changed;
56
58 html_form_radio(const html_form_radio & ref) = default;
59 html_form_radio(html_form_radio && ref) noexcept = delete;
60 html_form_radio & operator = (const html_form_radio & ref) = default;
61 html_form_radio & operator = (html_form_radio && ref) noexcept = delete;
62 ~html_form_radio() = default;
63
64 void add_choice(const std::string & id, const std::string & label);
65 void clear() { choices.clear(); unset_selected(); emphase = -1; my_body_part_has_changed(); };
66
68
70 void set_selected_num(unsigned int x);
71
73
78 void set_selected_id(const std::string & id);
79
81 void set_selected_id_with_warning(const std::string & id, const std::string & jlabel);
82
84 void unset_selected();
85
87 bool is_selected() const { return selected < choices.size(); };
88
90
93 unsigned int get_selected_num() const { return selected; };
94
96
99 const std::string & get_selected_id() const;
100
102 void set_emphase(unsigned int num);
103
105 void set_emphase() { emphase = -1; my_body_part_has_changed(); };
106
108 const unsigned int num_choices() const { return choices.size(); };
109
111 void set_change_event_name(const std::string & name);
112
114 void set_enabled(bool val);
115
118 void set_tooltip(unsigned int index, const std::string & msg);
119
120protected:
121
123 virtual std::string inherited_get_body_part(const chemin & path,
124 const request & req) override;
125
127 virtual void css_classes_have_changed() override;
128
129
131 virtual void new_css_library_available() override;
132
133
135 struct record
136 {
137 std::string id;
138 html_label label;
139
140 record(const std::string x_id,
141 const std::string & x_label): id(x_id), label(x_label) {};
142 };
143
144 const std::vector<record> & get_choices() const { return choices; };
145 void update_field_from_request(const request & req);
146
148
156
157private:
158 bool enabled;
159 std::vector<record> choices;
160 unsigned int selected;
161 bool value_set;
162 int emphase;
163
164 std::string modif_changed;
165 void my_act();
166};
167
168
169#endif
class body_builder is the root class of object generating HTML body
Definition: body_builder.hpp:99
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
class events
Definition: events.hpp:52
class html_form_radio implements HTML "input" of type "radio"
Definition: html_form_radio.hpp:53
virtual std::string inherited_get_body_part(const chemin &path, const request &req) override
inherited from body_builder
Definition: html_form_radio.cpp:176
void set_enabled(bool val)
set whether the HTML control is enable or disabled
Definition: html_form_radio.cpp:158
const std::string & get_selected_id() const
obtain the id of the selected radio button
Definition: html_form_radio.cpp:122
virtual void new_css_library_available() override
inherited from html_div/body_builder
Definition: html_form_radio.cpp:225
void set_change_event_name(const std::string &name)
change the default value for the "changed" event
Definition: html_form_radio.cpp:145
void set_selected_id(const std::string &id)
set the radio buttons to the item id given in argument
Definition: html_form_radio.cpp:89
void set_tooltip(unsigned int index, const std::string &msg)
Definition: html_form_radio.cpp:168
bool is_selected() const
returns whether a radio button is selected
Definition: html_form_radio.hpp:87
void set_emphase()
disable emphasing a particular item (default behavior)
Definition: html_form_radio.hpp:105
void unset_selected()
unselect all radio buttons
Definition: html_form_radio.cpp:113
const unsigned int num_choices() const
the number of currently available options
Definition: html_form_radio.hpp:108
void set_selected_id_with_warning(const std::string &id, const std::string &jlabel)
same as set_selected_id but issue a friendly warning build with jlabel for user understanding
Definition: html_form_radio.cpp:101
virtual void css_classes_have_changed() override
inherited from body_builder
Definition: html_form_radio.cpp:214
html_form_radio()
default event name for all object of this class
Definition: html_form_radio.cpp:44
void set_selected_num(unsigned int x)
set the radio buttons to item given in argument
Definition: html_form_radio.cpp:64
void unlock_update_field_from_request()
unlock update_field_from_request()
Definition: html_form_radio.cpp:262
unsigned int get_selected_num() const
obtain the index (starts at zero) of the selected radio button
Definition: html_form_radio.hpp:93
class html_label implements label and tooltips (helper string showing when mouse hovering)
Definition: html_label.hpp:47
class holding fields of an HTTP request (method, URI, header, cookies, and so on)
Definition: request.hpp:45
defines the event class
used to record parameters of each option of the radio button
Definition: html_form_radio.hpp:136