Webdar 1.0.0
Web user interface to libdar
html_button.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_BUTTON_HPP
25#define HTML_BUTTON_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 <string>
36
37 // webdar headers
38#include "events.hpp"
39#include "html_static_url.hpp"
40#include "html_div.hpp"
41#include "css_class_group.hpp"
42
44
47class html_button : public body_builder, public events
48{
49public:
50 html_button(const std::string & x_label, const std::string & x_event_name);
51 html_button(const html_button & ref) = delete;
52 html_button(html_button && ref) noexcept = delete;
53 html_button & operator = (const html_button & ref) = delete;
54 html_button & operator = (html_button && ref) noexcept = delete;
55 ~html_button() = default;
56
58 void url_add_css_class(const std::string & name) { inside.add_css_class(name); outside.add_css_class(name); };
59
61 void url_add_css_class(const css_class_group & cg) { inside.add_css_class(cg); outside.add_css_class(cg); };
62
64 void url_remove_css_class(const std::string & name) { inside.remove_css_class(name); outside.remove_css_class(name); };
65
68
70 void change_label(const std::string & x_label);
71
72 const std::string & get_label() const { return label; };
73
75 std::string get_url() const { return inside.get_url(); };
76
78
80 void change_event_name_to(const std::string & x_event_name) { rename_name(event_name, x_event_name); event_name = x_event_name; };
81
83 const std::string & get_event_name() const { return event_name; };
84
86 void set_download(bool mode) { inside.set_download(mode); };
87
89 void set_enabled(bool val) { reset_adoption_tree(val); };
90
93 void set_filename(const std::string & name) { inside.set_filename(name); };
94
96 virtual void bind_to_anchor(const std::string & val) override { inside.bind_to_anchor(val); };
97
98protected:
99
101 virtual std::string inherited_get_body_part(const chemin & path,
102 const request & req) override;
103
105 virtual void path_has_changed() override;
106
108 virtual void css_classes_have_changed() override;
109
110
111private:
112 std::string label;
113
114 html_div outside;
115 html_text text;
116 html_url inside;
117 std::string event_name;
118
120 void reset_adoption_tree(bool enabled);
121
122 static const std::string action;
123};
124
125#endif
class body_builder is the root class of object generating HTML body
Definition: body_builder.hpp:99
void clear_css_classes()
clear the whole list of css_class names
Definition: body_builder.hpp:205
void remove_css_class(const std::string &name)
remove the provided css_class name from the list of css_class names this object has been assigned to
Definition: body_builder.cpp:273
void add_css_class(const std::string &name)
set this object with a additional css_class (assuming it is defined in a css_library available for th...
Definition: body_builder.cpp:247
class chemin definition
Definition: chemin.hpp:51
manages a set of css class names
Definition: css_class_group.hpp:46
class events
Definition: events.hpp:52
void rename_name(const std::string &old_name, const std::string &new_name)
rename an event and keep all existing peering to this new event
Definition: events.cpp:133
simple html component providing the usual button feature of GUIs, better using html_double_button ins...
Definition: html_button.hpp:48
void set_filename(const std::string &name)
Definition: html_button.hpp:93
void url_add_css_class(const css_class_group &cg)
add a several CSS classes at once for the url inside the button
Definition: html_button.hpp:61
void change_label(const std::string &x_label)
the label is the text show for the URL
Definition: html_button.cpp:58
void url_clear_css_classes()
the inherited add_css_class() applies to the html_div around, this one to the url inside
Definition: html_button.hpp:67
virtual void path_has_changed() override
inherited from body_builder
Definition: html_button.cpp:87
void url_add_css_class(const std::string &name)
the inherited add_css_class() applies to the html_div around, this one to the url inside
Definition: html_button.hpp:58
void url_remove_css_class(const std::string &name)
the inherited add_css_class() applies to the html_div around, this one to the url inside
Definition: html_button.hpp:64
void set_enabled(bool val)
if disabled, the button has no hyperlink to click on
Definition: html_button.hpp:89
virtual std::string inherited_get_body_part(const chemin &path, const request &req) override
inherited from body_builder
Definition: html_button.cpp:67
void set_download(bool mode)
whether to download or display the URL target
Definition: html_button.hpp:86
virtual void bind_to_anchor(const std::string &val) override
inherited from body_builder
Definition: html_button.hpp:96
void change_event_name_to(const std::string &x_event_name)
change the name of the event generating by a click on the html_button
Definition: html_button.hpp:80
virtual void css_classes_have_changed() override
inherited from body_builder
Definition: html_button.cpp:95
std::string get_url() const
get the URL that will lead this button to be clicked
Definition: html_button.hpp:75
const std::string & get_event_name() const
get the name of the event generated by this object
Definition: html_button.hpp:83
class html_div is the implementation of
Definition: html_div.hpp:46
class html_text manage text and header in html document
Definition: html_text.hpp:52
html component implementing the usual hyperlink component
Definition: html_url.hpp:43
void set_filename(const std::string &name)
Definition: html_url.hpp:63
void set_download(bool mode)
whether to download or display the URL target
Definition: html_url.hpp:59
virtual void bind_to_anchor(const std::string &val) override
inherited from body_builder
Definition: html_url.hpp:56
class holding fields of an HTTP request (method, URI, header, cookies, and so on)
Definition: request.hpp:45
defines the event class