Webdar 1.0.0
Web user interface to libdar
html_menu.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_MENU_HPP
25#define HTML_MENU_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 <map>
36#include <deque>
37
38 // webdar headers
39#include "body_builder.hpp"
40#include "html_button.hpp"
41#include "html_div.hpp"
42#include "events.hpp"
43
45
49
50class html_menu : public html_div, protected events, protected actor
51{
52public:
54 static const std::string changed;
55
57 html_menu();
58 html_menu(const html_menu & ref) = delete;
59 html_menu(html_menu && ref) noexcept = delete;
60 html_menu & operator = (const html_menu & ref) = delete;
61 html_menu & operator = (html_menu && ref) noexcept = delete;
62
64 ~html_menu();
65
73 void add_entry(const std::string & label, const std::string & tag);
74
79 unsigned int get_current_mode() const { return current_mode; };
80
84 void set_current_mode(unsigned int mode, bool force = false);
85
87 unsigned int get_previous_mode() const { return previous_mode; };
88
90 std::string get_current_tag() const;
91
93 void set_current_tag(const std::string & tag);
94
96 std::string get_previous_tag() const;
97
99 std::string get_current_label() const;
100
103
105 virtual void on_event(const std::string & event_name) override;
106
107protected:
109 virtual std::string inherited_get_body_part(const chemin & path,
110 const request & req) override;
111
113 virtual void new_css_library_available() override;
114
115private:
116
118 struct cell
119 {
120 std::string itag;
121 html_button* ibtn;
122
123 cell(const std::string & label, const std::string & event_name, const std::string & tag)
124 {
125 ibtn = new (std::nothrow) html_button(label, event_name);
126 if(ibtn == nullptr)
127 throw exception_memory();
128 itag = tag;
129 };
130 cell(const cell &) = delete; // not implemented (not needed)
131 cell(cell && ref) noexcept { ibtn = nullptr; std::swap(ref.ibtn, ibtn); std::swap(ref.itag, itag); };
132 cell & operator = (const cell &) = delete; // not implemented (not needed)
133 cell & operator = (cell && ref) noexcept { std::swap(ref.ibtn, ibtn); std::swap(ref.itag, itag); return *this; };
134 ~cell()
135 {
136 if(ibtn != nullptr)
137 {
138 delete ibtn;
139 ibtn = nullptr;
140 }
141 };
142 };
143
144 unsigned int current_mode;
145 unsigned int previous_mode;
146 std::deque<cell> item;
147};
148
149#endif
class of object that are pointed/triggered to by others
Definition: actor.hpp:55
class chemin definition
Definition: chemin.hpp:51
class events
Definition: events.hpp:52
void record_actor_on_event(actor *ptr, const std::string &name)
record an actor for an given event
Definition: events.cpp:62
exception used to report memory allocation failures
Definition: exceptions.hpp:67
simple html component providing the usual button feature of GUIs, better using html_double_button ins...
Definition: html_button.hpp:48
class html_div is the implementation of
Definition: html_div.hpp:46
class html_menu shows a menu and provides events to act on other objects
Definition: html_menu.hpp:51
html_menu()
constructor
Definition: html_menu.cpp:49
void set_current_mode(unsigned int mode, bool force=false)
Definition: html_menu.cpp:90
static const std::string changed
the available event for this class
Definition: html_menu.hpp:54
std::string get_current_label() const
get current label (what is shown to the user)
Definition: html_menu.cpp:156
unsigned int get_previous_mode() const
returns the reference of the previous mode (the mode that was selected before current mode)
Definition: html_menu.hpp:87
void record_actor_on_event(actor *ptr)
modified wrapper from class events for our inherited classes
Definition: html_menu.hpp:102
virtual void new_css_library_available() override
inherited from body_builder, used to defines the css_class/css_selectors used by this class
Definition: html_menu.cpp:223
void add_entry(const std::string &label, const std::string &tag)
Definition: html_menu.cpp:62
~html_menu()
destructor
Definition: html_menu.cpp:57
virtual void on_event(const std::string &event_name) override
inherited from class actor
Definition: html_menu.cpp:167
void set_current_tag(const std::string &tag)
set the current selected mode giving its tag
Definition: html_menu.cpp:135
virtual std::string inherited_get_body_part(const chemin &path, const request &req) override
inherited from body_builder
Definition: html_menu.cpp:188
unsigned int get_current_mode() const
Definition: html_menu.hpp:79
std::string get_previous_tag() const
get previous tag
Definition: html_menu.cpp:148
std::string get_current_tag() const
return the tage of the currently selected item
Definition: html_menu.cpp:127
class holding fields of an HTTP request (method, URI, header, cookies, and so on)
Definition: request.hpp:45
defines the event class