Webdar 1.0.0
Web user interface to libdar
html_derouleur.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_DEROULEUR_HPP
25#define HTML_DEROULEUR_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#include <list>
37#include <map>
38
39 // webdar headers
40#include "body_builder.hpp"
41#include "html_aiguille.hpp"
42#include "actor.hpp"
43#include "html_button.hpp"
44
46
51
52
54 public actor
55{
56public:
57 html_derouleur() { adopt(&switcher); clear(); };
58 html_derouleur(const html_derouleur & ref) = delete;
59 html_derouleur(html_derouleur && ref) noexcept = delete;
60 html_derouleur & operator = (const html_derouleur & ref) = delete;
61 html_derouleur & operator = (html_derouleur && ref) noexcept = delete;
62 ~html_derouleur() = default;
63
65 void clear();
66
67 void add_section(const std::string & name, const std::string & title);
68
69 void adopt_in_section(const std::string & section_name, body_builder* obj);
70
71 void adopt_in_section(signed int num, body_builder* obj);
72
73 void clear_section(const std::string & section_name) { switcher.clear_section(section_name); };
74
75 void clear_section(signed int num) { switcher.clear_section(num); };
76
77 void remove_section(const std::string & section_name);
78
79 void set_active_section(const std::string & name) { switcher.set_active_section(name); };
80
81 void set_active_section(signed int num) { switcher.set_active_section(num); };
82
83 unsigned int size() const { return switcher.size(); };
84
86
89 void section_set_visible(const std::string & name, bool visible);
90
93 void url_add_css_class(const std::string & name);
94 void url_add_css_class(const css_class_group & name);
95
96 // from actor
97 virtual void on_event(const std::string & event_name) override;
98
99protected:
100
101 // inherited from body_builder
102 virtual void css_classes_have_changed() override;
103
104 // inherited from body_builder
105 virtual std::string inherited_get_body_part(const chemin & path,
106 const request & req) override;
107
108 // inherited from body_builder
109 virtual void new_css_library_available() override;
110
111private:
112 static const std::string shrink_event;
113
115 struct section
116 {
117 html_button* title;
118 html_button* shrinker;
119 bool visible;
120
121 // by default shrinker is hidden and title is
122 // visible (when the section is not expanded)
123 // clicking on title expands the section
124 // and leads the shrinker button to show while
125 // title get invisible, and so on...
126
127 section() { title = nullptr; shrinker = nullptr; visible = true; };
128 section(const section & arg) = delete;
129 section(section && arg) = default;
130 section & operator = (const section & arg) = delete;
131 section & operator = (section && arg) = default;
132 ~section() { if(title != nullptr) delete title; if(shrinker != nullptr) delete shrinker; };
133 };
134
135 css_class_group css_url;
136 std::map<std::string, section> sections;
137
138 html_aiguille switcher;
139
140
142 std::string generate_html(const chemin & path,
143 const request & req);
144
145};
146
147#endif
class of object that are pointed/triggered to by others
Definition: actor.hpp:55
class body_builder is the root class of object generating HTML body
Definition: body_builder.hpp:99
void adopt(body_builder *obj)
Definition: body_builder.cpp:117
class chemin definition
Definition: chemin.hpp:51
manages a set of css class names
Definition: css_class_group.hpp:46
void clear_css_classes()
remove all classes
Definition: css_class_group.cpp:71
class html_aiguille is a pure virtual class
Definition: html_aiguille.hpp:61
unsigned int size() const
return the total number of section
Definition: html_aiguille.hpp:117
void set_active_section(const std::string &name)
manually set the visible section, based on section name
Definition: html_aiguille.cpp:188
void clear_section(const std::string &section_name)
foresake all adopted objets in the given section
Definition: html_aiguille.cpp:113
simple html component providing the usual button feature of GUIs, better using html_double_button ins...
Definition: html_button.hpp:48
class html_derouleur is a pure virtual class
Definition: html_derouleur.hpp:55
void url_clear_css_classes()
set css of URL titles
Definition: html_derouleur.hpp:92
virtual void on_event(const std::string &event_name) override
implementation in inherited class of the action triggered by the event given in argument
Definition: html_derouleur.cpp:204
virtual void new_css_library_available() override
Definition: html_derouleur.cpp:245
void clear()
clear all adopted data and remove all sections
Definition: html_derouleur.cpp:44
void section_set_visible(const std::string &name, bool visible)
hide/unhide a section (Warning! this is not the same thing as shrinking/expanding a section!...
Definition: html_derouleur.cpp:145
virtual std::string inherited_get_body_part(const chemin &path, const request &req) override
implementation of get_body_part() method for inherited classes
Definition: html_derouleur.cpp:233
virtual void css_classes_have_changed() override
Be informed about css class modification.
Definition: html_derouleur.cpp:214
class holding fields of an HTTP request (method, URI, header, cookies, and so on)
Definition: request.hpp:45