sptk2 logo
SPTK Home Page
CTreeView.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 <sptk5/gui/CDataControl.h>
30#include <sptk5/gui/CPngImage.h>
31#include <sptk5/gui/CTreeControl.h>
32
33namespace sptk {
34
45class SP_EXPORT CTreeView
46 : public CControl
47{
48
52 CTreeControl* m_treeControl {nullptr};
53
57 void ctor_init();
58
59protected:
63 static void internal_callback(Fl_Widget*, void*);
64
65public:
72 CTreeView(const char* label = nullptr, int layoutSize = 10, CLayoutAlign layoutAlign = CLayoutAlign::TOP);
73
74#ifdef __COMPATIBILITY_MODE__
83 CTreeView(int x, int y, int w, int h, const char* label = 0);
84#endif
85
89 ~CTreeView() override = default;
90
94 CControlKind kind() const override
95 {
97 }
98
102 String className() const override
103 {
104 return "CTreeView";
105 }
106
115 CTreeItem* addItem(const String& label, const Fl_Image* openedImage, const Fl_Image* closedImage = nullptr,
116 void* data = nullptr)
117 {
118 return m_treeControl->addItem(label.c_str(), openedImage, closedImage, data);
119 }
120
130 CTreeItem* addPath(const std::vector<String>& path, const Fl_Image* openedImage, const Fl_Image* closedImage,
131 const Fl_Image* itemImage = nullptr, void* data = nullptr)
132 {
133 return m_treeControl->addPath(path, openedImage, closedImage, itemImage, data);
134 }
135
143 CTreeItem* addPath(const std::vector<String>& path, const Fl_Image* itemImage = 0L, void* data = nullptr)
144 {
145 return m_treeControl->addPath(path, itemImage, itemImage, itemImage, data);
146 }
147
152 {
153 m_treeControl->removeItem(item);
154 }
155
160 {
161 return m_treeControl->selected();
162 }
163
168
172 virtual void clear()
173 {
174 m_treeControl->clear();
175 }
176
180 void relayout()
181 {
182 m_treeControl->relayout();
183 redraw();
184 }
185
193 void resize(int x, int y, int w, int h) override;
194
198 Variant data() const override;
199
203 void data(const Variant& v) override;
204
208 void load(Query*) override;
209
213 void save(Query*) override;
214
222 void load(const xdoc::SNode& node) override;
223
231 void save(const xdoc::SNode& node) const override;
232
236 bool valid() const override
237 {
238 return true;
239 }
240
245 static CLayoutClient* creator(const xdoc::SNode& node);
246};
250} // namespace sptk
Base class for most of SPTK widgets.
Definition: CControl.h:222
Definition: CLayoutClient.h:82
Tree widget.
Definition: CTreeControl.h:463
Tree widget item.
Definition: CTreeControl.h:66
bool selected() const
Returns selection state of the item.
Definition: CTreeControl.h:352
CTreeItem * addItem(const char *label, const Fl_Image *openedImage=nullptr, const Fl_Image *closedImage=nullptr, void *data=nullptr)
CTreeItem * addPath(const std::vector< String > &path, const Fl_Image *openedImage, const Fl_Image *closedImage, const Fl_Image *itemImage=0L, void *data=0L)
Tree view widget.
Definition: CTreeView.h:47
void relayout()
Relayouts the tree. May be necessary after you've changed items data a lot.
Definition: CTreeView.h:180
bool valid() const override
Returns true if data is valid.
Definition: CTreeView.h:236
~CTreeView() override=default
Destructor.
Variant data() const override
Returns the currently selected item ID (or user_data)
CTreeItem * addPath(const std::vector< String > &path, const Fl_Image *itemImage=0L, void *data=nullptr)
Adds a child item to the item using the default folder images.
Definition: CTreeView.h:143
CTreeItem * addPath(const std::vector< String > &path, const Fl_Image *openedImage, const Fl_Image *closedImage, const Fl_Image *itemImage=nullptr, void *data=nullptr)
Adds a child item to the item using the path. The required path items are created automatically.
Definition: CTreeView.h:130
void load(const xdoc::SNode &node) override
Loads the the widget from XML node.
String selectedPath() const
Returns currently selected item path in the tree.
static CLayoutClient * creator(const xdoc::SNode &node)
Creates a widget based on the XML node information.
CTreeView(const char *label=nullptr, int layoutSize=10, CLayoutAlign layoutAlign=CLayoutAlign::TOP)
Constructor in SPTK style.
static void internal_callback(Fl_Widget *, void *)
Internal tree control callback.
CTreeItem * selected() const
Returns currently selected item.
Definition: CTreeView.h:159
void data(const Variant &v) override
Selects the item with matching ID (or user_data)
void resize(int x, int y, int w, int h) override
Resizes the control and inside widgets.
String className() const override
Returns controls' class name (internal SPTK RTTI).
Definition: CTreeView.h:102
void save(Query *) override
Data connection isn't implemented yet.
virtual void clear()
Removes all the tree items.
Definition: CTreeView.h:172
CTreeItem * addItem(const String &label, const Fl_Image *openedImage, const Fl_Image *closedImage=nullptr, void *data=nullptr)
Adds a child item to the item. If the closedImage parameter is omitted the openedImage is used instea...
Definition: CTreeView.h:115
void save(const xdoc::SNode &node) const override
Saves the the widget to XML node.
void removeItem(CTreeItem *item)
Removes an item from the parent tree item.
Definition: CTreeView.h:151
CControlKind kind() const override
Returns controls' kind (internal SPTK RTTI).
Definition: CTreeView.h:94
void load(Query *) override
Data connection isn't implemented yet.
Definition: Query.h:239
Definition: String.h:49
Definition: Variant.h:372
CControlKind
Control kind is the constant to report the internal SPTK RTTI.
Definition: CControl.h:50
CLayoutAlign
Definition: CLayoutClient.h:44
@ TOP
Align to the right.

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