sptk2 logo
SPTK Home Page
CLayoutManager.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include <map>
30#include <sptk5/Exception.h>
31#include <sptk5/gui/CFrame.h>
32#include <sptk5/gui/CLayoutClient.h>
33#include <sptk5/xdoc/Node.h>
34#include <string>
35
36class Fl_Image;
37
38namespace sptk {
39
50using createControlCallback = CLayoutClient* (*) (const xdoc::SNode& node);
51
55using createControlCallbackMap = std::map<std::string, createControlCallback>;
56
60using CWidgetNamesMap = std::map<std::string, Fl_Widget*>;
61
68enum class CLayoutGrowMode : uint8_t
69{
73 LGM_NONE = 0,
74
79
84
89
90};
91
101class SP_EXPORT CLayoutManager
102 : public CLayoutClient
103{
104 friend class CLayoutManagerInitializer;
105
106protected:
111
116
120 Fl_Group* m_group;
121
126
131
136
137
141 static std::map<std::string, Fl_Boxtype> m_boxTypeNames;
142
147
148
158 bool autoLayout(int x, int y, int& w, int& h, bool resizeWidgets) const;
159
163 virtual void paintBackground();
164
165public:
172 CLayoutManager(Fl_Group* group, int layoutSize, CLayoutAlign ca);
173
177 ~CLayoutManager() override = default;
178
182 virtual void clear();
183
187 int layoutSpacing() const
188 {
189 return m_layoutSpacing;
190 }
191
196 void layoutSpacing(int ls)
197 {
198 m_layoutSpacing = ls;
199 }
200
207 {
208 m_layoutGrowMode = gm;
209 }
210
216 {
217 return m_layoutGrowMode;
218 }
219
224 void relayout();
225
231 void frame(CFrame* frame, bool drawBackground = true)
232 {
233 m_frame = frame;
234 m_frameDrawBackground = drawBackground;
235 }
236
240 const CFrame* frame() const
241 {
242 return m_frame;
243 }
244
248 uint32_t frameWidth() const;
249
256 virtual void loadLayout(const xdoc::SNode& node, CLayoutXMLmode xmlMode);
257
264 virtual void saveLayout(const xdoc::SNode& node, CLayoutXMLmode xmlMode) const;
265
275 void nameIndex(CWidgetNamesMap& index, bool recursive, bool clean = true) const;
276
282 bool noXml() const
283 {
284 return m_noXml;
285 }
286
295 void noXml(bool noXml)
296 {
297 m_noXml = noXml;
298 }
299
309 static void registerControl(std::string typeName, createControlCallback creator) noexcept;
310
314 static const std::map<std::string, Fl_Boxtype>& boxTypeNames();
315};
319} // namespace sptk
Frame information class.
Definition: CFrame.h:48
Definition: CLayoutClient.h:82
Layout Manager.
Definition: CLayoutManager.h:103
virtual void paintBackground()
void layoutGrowMode(CLayoutGrowMode gm=CLayoutGrowMode::LGM_AUTO_GROW)
Definition: CLayoutManager.h:206
void layoutSpacing(int ls)
Definition: CLayoutManager.h:196
CFrame * m_frame
Definition: CLayoutManager.h:125
void frame(CFrame *frame, bool drawBackground=true)
Defines frame.
Definition: CLayoutManager.h:231
void noXml(bool noXml)
Sets flag of blocking XML processing.
Definition: CLayoutManager.h:295
CLayoutManager(Fl_Group *group, int layoutSize, CLayoutAlign ca)
virtual void saveLayout(const xdoc::SNode &node, CLayoutXMLmode xmlMode) const
Saves group controls data into XML node.
virtual void loadLayout(const xdoc::SNode &node, CLayoutXMLmode xmlMode)
Loads group controls data from XML node.
const CFrame * frame() const
Returnes the current frame.
Definition: CLayoutManager.h:240
int m_layoutSpacing
Definition: CLayoutManager.h:110
bool noXml() const
Returns flag of blocking XML processing.
Definition: CLayoutManager.h:282
bool autoLayout(int x, int y, int &w, int &h, bool resizeWidgets) const
static std::map< std::string, Fl_Boxtype > m_boxTypeNames
Definition: CLayoutManager.h:141
static void registerControl(std::string typeName, createControlCallback creator) noexcept
Register control type for loading layouts.
int layoutSpacing() const
Definition: CLayoutManager.h:187
static createControlCallbackMap controlCreator
Definition: CLayoutManager.h:146
virtual void clear()
Removes all the children.
void nameIndex(CWidgetNamesMap &index, bool recursive, bool clean=true) const
Builds an index of internal widget names.
uint32_t frameWidth() const
Returns frame width.
CLayoutGrowMode m_layoutGrowMode
Definition: CLayoutManager.h:115
bool m_noXml
Definition: CLayoutManager.h:135
Fl_Group * m_group
Definition: CLayoutManager.h:120
static const std::map< std::string, Fl_Boxtype > & boxTypeNames()
Returns a read-only map of box type names and corresponding constants.
~CLayoutManager() override=default
CLayoutGrowMode layoutGrowMode() const
Definition: CLayoutManager.h:215
bool m_frameDrawBackground
Definition: CLayoutManager.h:130
std::map< std::string, createControlCallback > createControlCallbackMap
A callback map that stores type names and control create functions.
Definition: CLayoutManager.h:55
std::map< std::string, Fl_Widget * > CWidgetNamesMap
a map of widget names to widgets
Definition: CLayoutManager.h:60
CLayoutAlign
Definition: CLayoutClient.h:44
CLayoutXMLmode
Definition: CLayoutClient.h:57
CLayoutClient *(*)(const xdoc::SNode &node) createControlCallback
A callback that creates a control of the required type.
Definition: CLayoutManager.h:50
CLayoutGrowMode
Layout manager grow mode.
Definition: CLayoutManager.h:69

Fri Oct 14 2022 09:58:31: SPTK 5.4.1