Webdar 1.0.0
Web user interface to libdar
html_form_input_unit.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_INPUT_UNIT_HPP
25#define HTML_FORM_INPUT_UNIT_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 <dar/libdar.hpp>
36
37 // webdar headers
38#include "html_form_input.hpp"
39#include "html_size_unit.hpp"
40#include "events.hpp"
41#include "actor.hpp"
42#include "html_div.hpp"
43
45
49
50class html_form_input_unit : public html_div, public events, public actor
51{
52public:
53 // default event name used to signal component change
54 static const std::string changed;
55
56 html_form_input_unit(const std::string & label,
57 const libdar::infinint & initial_value,
58 const std::string & size);
59 html_form_input_unit(const html_form_input_unit & ref) = delete;
60 html_form_input_unit(html_form_input_unit && ref) noexcept = delete;
61 html_form_input_unit & operator = (const html_form_input_unit & ref) = delete;
62 html_form_input_unit & operator = (html_form_input_unit && ref) noexcept = delete;
63 ~html_form_input_unit() = default;
64
66
68 void set_range(const libdar::infinint & x_min, const libdar::infinint & x_max);
69
71 void set_min_only(const libdar::infinint & x_min);
72
74
76 void set_max_only(const libdar::infinint & x_max);
77
79 void box_set_css_class(const std::string & val) { field.box_set_css_class(val); };
80
82 void change_label(const std::string & label) { field.change_label(label); };
83
84 void set_value_as_infinint(const libdar::infinint & x_val);
85 libdar::infinint get_value_as_infinint() const { return val; };
86
88 const std::string & get_raw_value() const { return field.get_value(); };
89
91 const std::string get_unit_string() const { return unit_box.get_string(); };
92
94 void set_enabled(bool val) { field.set_enabled(val); unit_box.set_enabled(val); };
95
97
104 void set_change_event_name(const std::string & name);
105
107 std::string get_event_name() const { return modif_change.empty()? changed: modif_change; };
108
110 virtual void on_event(const std::string & event_name) override;
111
113 void set_tooltip(const std::string & val) { field.set_tooltip(val); };
114
115protected:
116
118 virtual void new_css_library_available() override;
119
120private:
121 bool ignore_events;
122 bool no_act;
123 html_form_input field;
124 html_size_unit unit_box;
125 libdar::infinint val;
126 libdar::infinint min;
127 libdar::infinint max;
128
129 std::string modif_change;
130
131 void my_act() { if(!no_act) act(modif_change.empty() ? changed: modif_change); };
132 void reduce_val_and_unit();
133 void set_field_val();
134 void set_value_to_largest_unit();
135 void check_min_max_compliance();
136
137
139 static libdar::infinint reduce_to_unit(const libdar::infinint & val, const libdar::infinint & unit);
140
142 static libdar::infinint reduce_to_unit_above(const libdar::infinint & val, const libdar::infinint & unit);
143
144 static const std::string css_input;
145 static const std::string css_unit;
146
147
148};
149
150#endif
class of object that are pointed/triggered to by others
Definition: actor.hpp:55
class events
Definition: events.hpp:52
void act(const std::string &name)
trigger a given event
Definition: events.cpp:151
class html_div is the implementation of
Definition: html_div.hpp:46
class html_form_input_unit implements HTML input::number feature with added unit box
Definition: html_form_input_unit.hpp:51
void set_change_event_name(const std::string &name)
change the name of the event generated when this control changes
Definition: html_form_input_unit.cpp:203
void set_tooltip(const std::string &val)
surfacing the tooltip feature of the input form
Definition: html_form_input_unit.hpp:113
void set_enabled(bool val)
whether the HTML control is enable or disabled
Definition: html_form_input_unit.hpp:94
void set_max_only(const libdar::infinint &x_max)
set the max value (by default there is no maximum constraint applied
Definition: html_form_input_unit.cpp:123
void set_range(const libdar::infinint &x_min, const libdar::infinint &x_max)
set both min and max
Definition: html_form_input_unit.cpp:90
void change_label(const std::string &label)
change the label
Definition: html_form_input_unit.hpp:82
const std::string get_unit_string() const
get unit display string
Definition: html_form_input_unit.hpp:91
virtual void new_css_library_available() override
inherited from body_builder
Definition: html_form_input_unit.cpp:181
virtual void on_event(const std::string &event_name) override
inherited from actor
Definition: html_form_input_unit.cpp:140
std::string get_event_name() const
get the event name used when the component changes
Definition: html_form_input_unit.hpp:107
const std::string & get_raw_value() const
get the displayed number value (not taking into account the unit)
Definition: html_form_input_unit.hpp:88
void set_min_only(const libdar::infinint &x_min)
set min, min cannot be negative nor less than max if set
Definition: html_form_input_unit.cpp:112
void box_set_css_class(const std::string &val)
apply css to the box (text box if checkbox, but not to the label)
Definition: html_form_input_unit.hpp:79
class html_form_input implements HTML input feature
Definition: html_form_input.hpp:57
void set_enabled(bool val)
set whether the HTML control is enable or disabled
Definition: html_form_input.cpp:168
void set_tooltip(const std::string &msg)
set tooltip for the html label of the input form
Definition: html_form_input.hpp:122
void box_set_css_class(const std::string &val)
apply css to the box (text box if checkbox, but not to the label)
Definition: html_form_input.hpp:94
html component in a form a couple of dropdown list for user to define a size in byte or larger units
Definition: html_size_unit.hpp:44
std::string get_string() const
return the unit label
Definition: html_size_unit.hpp:59
void set_enabled(bool val)
whether the HTML control is enable or disabled
Definition: html_size_unit.hpp:85
unsigned int size() const
the number of peers
Definition: reference.hpp:97
defines the event class