sptk2 logo
SPTK Home Page
CListView.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 <FL/Fl_Group.H>
30
31#include <sptk5/CSmallPixmapIDs.h>
32#include <sptk5/DataSource.h>
33
34#include <sptk5/PackedStrings.h>
35#include <sptk5/gui/CColumn.h>
36#include <sptk5/gui/CControl.h>
37#include <sptk5/gui/CDataControl.h>
38#include <sptk5/gui/CListViewRows.h>
39#include <sptk5/gui/CListViewSelection.h>
40#include <sptk5/gui/CScrollBar.h>
41#include <sptk5/sptk.h>
42
43namespace sptk {
44
53enum class CRefreshKind : uint8_t
54{
59
64
65};
66
67class CInternalComboBoxPanel;
68
69class CDBDropDownList;
70
75enum class CListViewDataMode : uint8_t
76{
81
86
91
96
97};
98
105class SP_EXPORT CListView
106 : public CControl
107 , public SharedMutex
108{
109 friend class CInternalComboBoxPanel;
110
111 friend class CDBDropDownList;
112
116 void ctor_init();
117
121 bool m_fillInProgress {false};
122
126 bool m_fillTerminated {false};
127
128protected:
132 bool m_capitalizeColumnNames {false};
133
137 bool m_multipleSelection {false};
138
142 int m_horizPosition {0};
143
147 int m_realHorizPosition {0};
148
152 int m_maxWidth {0};
153
157 int m_redraw1 {0};
158
162 int m_redraw2 {0};
163
167 uint32_t m_top {0};
168
173
177 int m_currentTextFont {0};
178
182 int m_currentTextSize {0};
183
188
195
199 int m_mousePressedX {0};
200
205
209 std::string m_searchPhrase;
210
214 uint32_t m_activeRow {0};
215
219 uint32_t m_headerHeight {0};
220
225
230
234 int m_draggingColumn {0};
235
239 int m_draggingStarted {0};
240
244 Fl_Font m_textFont {0};
245
249 uchar m_textSize {0};
250
254 Fl_Color m_textColor {0};
255
259 bool m_showStripes {false};
260
264 bool m_showGrid {false};
265
269 bool m_showSelection {false};
270
274 bool m_autoRowHeight {false};
275
281 int columnAt(int x);
282
288 int find_item(int y);
289
297 void bbox(int& X, int& Y, int& W, int& H) const;
298
302 static void scrollbar_callback(Fl_Widget* s, void*);
303
307 static void hscrollbar_callback(Fl_Widget* s, void*);
308
312 CScrollBar scrollbar {0, 0, 0, 0};
313
317 CScrollBar hscrollbar {0, 0, 0, 0};
318
322 int hposition() const
323 {
324 return m_horizPosition;
325 }
326
331 void hposition(int hpos); // pan to here
332
337 static void scrollbar_width(int b);
338
342 static int scrollbar_width();
343
349 int find_id(int id) const;
350
354 virtual int get_focus();
355
360 virtual bool item_selected(uint32_t index) const;
361
367 virtual void item_select(uint32_t index, bool select);
368
373
379 virtual int item_compute_height(CPackedStrings* rowData);
380
386 virtual int item_height(uint32_t index) const;
387
393 virtual int item_width(uint32_t index) const;
394
408 virtual void item_draw(uint32_t index, const CPackedStrings* rowData, int x, int y, int w, int h, int focusMode,
409 int verticalAlign, bool paintBackground) const;
410
414 virtual void item_clicked(int mouse_btn);
415
422 virtual Fl_Color item_color(int column, const CPackedStrings& rowData) const;
423
430 virtual void header_draw(int x, int y, int hh) const;
431
436 virtual void header_clicked(int x);
437
441 virtual bool header_drag_position(int x);
442
447 virtual void header_dragged(int x);
448
453 virtual void header_released(int x);
454
459 void redraw_line(uint32_t index);
460
465 {
466 damage(FL_DAMAGE_SCROLL);
467 }
468
472 void draw() override;
473
477 void key_changed(uint32_t index);
478
479public:
486 CListView(const char* label = nullptr, int layoutSize = 20, CLayoutAlign layoutAlign = CLayoutAlign::TOP);
487
488#ifdef __COMPATIBILITY_MODE__
497 CListView(int, int, int, int, const char* = 0);
498#endif
499
503 ~CListView() override
504 {
506 }
507
511 int handle(int) override;
512
520 void resize(int x, int y, int w, int h) override;
521
526 virtual void removeRow(uint32_t index);
527
534 virtual void addRow(CPackedStrings* row);
535
544 virtual void addRow(int ident, const Strings& row);
545
555 virtual void insertRow(uint32_t position, const Strings& row, int ident);
556
564 virtual void updateRow(uint32_t position, CPackedStrings* row);
565
572 virtual void updateRow(uint32_t position, const Strings& row, int ident = 0);
573
577 virtual void clear();
578
582 virtual uint32_t size() const
583 {
584 return m_rows.size();
585 }
586
590 virtual int top() const
591 {
592 return (int) m_top;
593 }
594
599 virtual void top(int index);
600
605 int selected(int index) const;
606
611 void show(int index);
612
616 void show() override
617 {
618 CControl::show();
619 }
620
625 void hide(int index);
626
630 void hide() override
631 {
632 Fl_Widget::hide();
633 }
634
639 int visible(int index) const;
640
644 int visible() const
645 {
646 return (int) Fl_Widget::visible();
647 }
648
652 std::string textValue() const;
653
658 void textValue(const std::string& text);
659
666 {
667 m_dataMode = dm;
668 }
669
676 {
677 return m_dataMode;
678 }
679
684 Variant data() const override;
685
690 void data(const Variant& v) override;
691
697 CPackedStrings* row(uint32_t index) const;
698
702 const CSelection& selection() const
703 {
704 return m_selection;
705 }
706
712
716 int selectedIndex() const;
717
724 bool selectRow(uint32_t index, bool sel = true)
725 {
726 return select(index, sel, true);
727 }
728
733 bool displayed(uint32_t index) const;
734
739 virtual void displayRow(uint32_t index);
740
745 void redrawRow(uint32_t index)
746 {
747 redraw_line(index);
748 }
749
750protected:
754 void load(Query*) override;
755
759 void save(Query*) override;
760
769 void load(const xdoc::SNode& node, CLayoutXMLmode xmlMode) override;
770
779 void save(const xdoc::SNode& node, CLayoutXMLmode xmlMode) const override;
780
784 bool valid() const override
785 {
786 return true;
787 }
788
792 virtual uint32_t cellBorderWidth() const;
793
801 bool select(uint32_t index, bool sel = true, int docallbacks = false);
802
809 bool select_only(uint32_t index, bool docallbacks = false);
810
816 bool activate_row(uint32_t index);
817
823
829
835
841
847
853
854public:
859 void columns(const CColumnList& columns);
860
865 {
866 return m_columnList;
867 }
868
873 CColumn& column(uint32_t col)
874 {
875 return m_columnList[col];
876 }
877
882 CColumn& column(const char* colname);
883
888 void addColumn(const CColumn& column)
889 {
890 m_columnList.push_back(column);
891 }
892
900 void addColumn(const String& colname, VariantDataType type, uint32_t cwidth = 100, bool cvisible = true)
901 {
902 m_columnList.push_back(CColumn(colname, type, (short) cwidth, cvisible));
903 }
904
910 CControlKind kind() const override
911 {
913 }
914
918 bool autoRowHeight() const
919 {
920 return m_autoRowHeight;
921 }
922
926 void autoRowHeight(bool arh);
927
931 Fl_Font textFont() const override
932 {
933 return m_textFont;
934 }
935
939 void textFont(Fl_Font f) override
940 {
941 m_textFont = f;
942 }
943
947 uchar textSize() const override
948 {
949 return m_textSize;
950 }
951
955 void textSize(uchar s) override
956 {
957 m_textSize = s;
958 }
959
963 Fl_Color textColor() const override
964 {
965 return m_textColor;
966 }
967
971 void textColor(Fl_Color n) override
972 {
973 m_textColor = n;
974 }
975
979 bool showGrid() const
980 {
981 return m_showGrid;
982 }
983
987 void showGrid(bool flag);
988
992 bool showStripes() const
993 {
994 return m_showStripes;
995 }
996
1000 void showStripes(bool flag);
1001
1005 bool showSelection() const
1006 {
1007 return m_showSelection;
1008 }
1009
1013 void showSelection(bool flag)
1014 {
1015 m_showSelection = flag;
1016 }
1017
1021 bool multiSelect() const
1022 {
1023 return m_multipleSelection;
1024 }
1025
1029 void multiSelect(bool ms)
1030 {
1031 m_multipleSelection = ms;
1032 }
1033
1037 void getSelections(std::vector<uint64_t>& selection) const;
1038
1042 void setSelections(const std::vector<uint64_t>& selection);
1043
1050
1056 CPackedStrings* findKey(int keyValue);
1057
1061 [[nodiscard]] uint32_t fullWidth() const; // current width of all items
1062
1066 [[nodiscard]] uint32_t fullHeight() const; // current height of all items
1067
1076 virtual int findString(const std::string& str, bool select = true, uint32_t startRow = 0, uint32_t endRow = 0);
1077
1082
1088 void sortColumn(int column, bool sortNow);
1089
1093 int sortColumn() const;
1094
1098 bool sortAscending() const
1099 {
1100 return m_rows.sortAscending();
1101 }
1102
1108 void sortAscending(bool ascending, bool sortNow);
1109
1110
1114 void sort()
1115 {
1116 m_rows.sort();
1117 }
1118
1131 void fill(DataSource& ds, const String& keyFieldName = "", uint32_t recordsLimit = 0, uint32_t recordsEstimated = 0,
1133
1140 void loadList(const xdoc::SNode& node);
1141
1148 void saveList(const xdoc::SNode& node) const;
1149
1156 bool preferredSize(int& w, int& h) override;
1157
1161 uint32_t headerHeight() const
1162 {
1163 return m_headerHeight;
1164 }
1165
1169 void headerHeight(uint32_t hh)
1170 {
1171 m_headerHeight = hh;
1172 }
1173
1177 uint32_t activeRow() const
1178 {
1179 return m_activeRow;
1180 }
1181
1186 {
1187 return m_capitalizeColumnNames;
1188 }
1189
1195 {
1196 m_capitalizeColumnNames = ccn;
1197 }
1198
1203 {
1204 m_fillTerminated = true;
1205 }
1206
1210 String className() const override
1211 {
1212 return "list_view";
1213 }
1214
1219 void imageCollection(Strings& iconNames);
1220};
1224} // namespace sptk
Definition: CColumn.h:178
Class CColumn represents a column descriptor for CListView.
Definition: CColumn.h:45
Base class for most of SPTK widgets.
Definition: CControl.h:222
Drop-down window with CListView widget inside.
Definition: CDropDownBox.h:95
Definition: CListViewRows.h:48
uint32_t size() const
Definition: CListViewRows.h:186
bool sortAscending() const
Definition: CListViewRows.h:217
List view widget.
Definition: CListView.h:108
void save(const xdoc::SNode &node, CLayoutXMLmode xmlMode) const override
Saves control data to XML.
virtual void insertRow(uint32_t position, const Strings &row, int ident)
Inserts new row.
int columnAt(int x)
Computes which column contains x-coordinate.
int find_id(int id) const
Finds item with ID.
bool select_next()
Selects the next row. Executes the callbacks. Internal.
void resize(int x, int y, int w, int h) override
Resizes the control and inside widgets.
int handle(int) override
Overwritten handle()
bool displayed(uint32_t index) const
virtual void addRow(CPackedStrings *row)
Adds new row.
virtual void item_clicked(int mouse_btn)
bool preferredSize(int &w, int &h) override
Computes the optimal widgets size.
int selected(int index) const
virtual void item_select(uint32_t index, bool select)
Selects or deselects the item.
static void scrollbar_width(int b)
Changes the default scrollbar width for the class.
void load(const xdoc::SNode &node, CLayoutXMLmode xmlMode) override
Loads control data from XML.
virtual void header_draw(int x, int y, int hh) const
Draws header (internal)
void key_changed(uint32_t index)
Internal callback if selected another item with the different user _data (key).
int sortColumn() const
Returns the sort column number.
static int m_scrollbarWidth
Definition: CListView.h:172
void sortColumn(int column, bool sortNow)
Sets the sort column.
CColumnList & columns()
Returns column list.
Definition: CListView.h:864
bool select(uint32_t index, bool sel=true, int docallbacks=false)
Selects the row. Internal.
virtual int findString(const std::string &str, bool select=true, uint32_t startRow=0, uint32_t endRow=0)
Finds a string in the sort column of list view defined with sortColumn()
void load(Query *) override
Loads the key value from the query.
bool select_next_page()
Selects the next page row. Executes the callbacks. Internal.
Fl_Font textFont() const override
Returns text font type.
Definition: CListView.h:931
CColumn & column(uint32_t col)
Returns column informartion.
Definition: CListView.h:873
CPackedStrings * findCaption(const String &caption)
Finds an item with the caption (a string in the first column).
virtual int top() const
Returns the scroll position.
Definition: CListView.h:590
void bbox(int &X, int &Y, int &W, int &H) const
Returns the actual size of the drawing area (internal)
CPackedStrings * selectedRow() const
void addColumn(const CColumn &column)
Adds a new column as a copy of column.
Definition: CListView.h:888
int selectedIndex() const
CListViewRows m_rows
Definition: CListView.h:224
uint32_t headerHeight() const
Returns header height.
Definition: CListView.h:1161
void autoRowHeight(bool arh)
Sets auto row height mode as true/false.
CPackedStrings * findKey(int keyValue)
Finds an item with the key (an integer associated with the item - argument()).
bool select_first()
Selects the first row. Executes the callbacks. Internal.
uint32_t fullHeight() const
Returns summary height of all items including the header row.
void redraw_lines()
Redraw all the lines.
Definition: CListView.h:464
void saveList(const xdoc::SNode &node) const
Saves the list data into XML node.
void show() override
Definition: CListView.h:616
void draw() override
General draw function. Draws everything.
virtual void addRow(int ident, const Strings &row)
Adds new row.
void addColumn(const String &colname, VariantDataType type, uint32_t cwidth=100, bool cvisible=true)
Adds a new column as a copy of column.
Definition: CListView.h:900
bool valid() const override
True if the data is valid.
Definition: CListView.h:784
void fill(DataSource &ds, const String &keyFieldName="", uint32_t recordsLimit=0, uint32_t recordsEstimated=0, CRefreshKind refreshKind=CRefreshKind::LV_REFRESH_FULL)
Fills the list view with the data from datasource.
void terminateFill()
Terminate the current fill() operation (if in progress)
Definition: CListView.h:1202
void redrawRow(uint32_t index)
Definition: CListView.h:745
void sort()
Sorts ListView rows using existing information about sort column and direction.
Definition: CListView.h:1114
virtual int get_focus()
Get focus callback (internal)
CColumnList m_columnList
Definition: CListView.h:229
virtual Fl_Color item_color(int column, const CPackedStrings &rowData) const
The function that allows to overwrite the default text color for the cell.
void hide(int index)
bool activate_row(uint32_t index)
Selects the row. Executes the callbacks. Internal.
virtual int item_width(uint32_t index) const
Returns item width.
void save(Query *) override
Saves the key value from the query.
static void hscrollbar_callback(Fl_Widget *s, void *)
Internal horizontal scrollback callback.
uchar textSize() const override
Definition: CListView.h:947
void getSelections(std::vector< uint64_t > &selection) const
Returns a selected rows ID list.
virtual uint32_t cellBorderWidth() const
Returns the cell border width.
virtual bool header_drag_position(int x)
Returns true if x is the drag-sensitive area.
void hide() override
Definition: CListView.h:630
void capitalizeColumnNames(bool ccn)
Defines if column names should be auto-capitilized.
Definition: CListView.h:1194
bool showSelection() const
Returns show selection mode.
Definition: CListView.h:1005
bool select_prior()
Selects the prior row. Executes the callbacks. Internal.
CListViewDataMode dataMode() const
Definition: CListView.h:675
void textValue(const std::string &text)
virtual uint32_t size() const
Returns the row count.
Definition: CListView.h:582
Fl_Color textColor() const override
Returns text color.
Definition: CListView.h:963
void setSelections(const std::vector< uint64_t > &selection)
Sets a selected rows ID list.
virtual void header_dragged(int x)
Header dragged to position x notification.
bool sortAscending() const
Returns the sort direction - ascending/descending.
Definition: CListView.h:1098
static int scrollbar_width()
Returns the default scrollbar width for the class.
void multiSelect(bool ms)
Sets multiple selection enabled or disabled.
Definition: CListView.h:1029
bool autoRowHeight() const
Returns auto row height mode as true/false.
Definition: CListView.h:918
CSelection m_selection
Definition: CListView.h:204
CColumn & column(const char *colname)
Returns column informartion.
bool select_prior_page()
Selects the prior page row. Executes the callbacks. Internal.
virtual int item_height(uint32_t index) const
Recomputes items height.
void textSize(uchar s) override
Sets text font size.
Definition: CListView.h:955
bool selectRow(uint32_t index, bool sel=true)
Definition: CListView.h:724
bool capitalizeColumnNames() const
Returns true if column names are auto-capitilized.
Definition: CListView.h:1185
void dataMode(CListViewDataMode dm)
Definition: CListView.h:665
virtual void header_clicked(int x)
Header clicked mouse callback.
std::string m_searchPhrase
Definition: CListView.h:209
String sortColumnName() const
Returns sort column name.
String className() const override
Returns widget class name (internal SPTK RTTI).
Definition: CListView.h:1210
void show(int index)
virtual void removeRow(uint32_t index)
Removes row.
int visible(int index) const
uint32_t activeRow() const
Returns the currently active row.
Definition: CListView.h:1177
int hposition() const
Returns horizontal position of the scroll.
Definition: CListView.h:322
void headerHeight(uint32_t hh)
Sets the header height, 0 to hide headers.
Definition: CListView.h:1169
virtual void updateRow(uint32_t position, CPackedStrings *row)
Updates a row.
void hposition(int hpos)
Sets horizontal position of the scroll.
int find_item(int y)
Finds an item in vertical position y.
bool showStripes() const
Returns show stripes.
Definition: CListView.h:992
bool select_last()
Selects the last row. Executes the callbacks. Internal.
void loadList(const xdoc::SNode &node)
Fills the list with the data from XML node.
CPackedStrings * row(uint32_t index) const
void data(const Variant &v) override
Variant data() const override
virtual void clear()
Removes all the rows.
void textFont(Fl_Font f) override
Sets text font type.
Definition: CListView.h:939
virtual void header_released(int x)
Header released in position x notification.
std::string textValue() const
void showSelection(bool flag)
Sets show selection mode.
Definition: CListView.h:1013
int visible() const
Definition: CListView.h:644
virtual int item_compute_height(CPackedStrings *rowData)
Recomputes items height.
~CListView() override
Destructor.
Definition: CListView.h:503
virtual int item_compute_height_all()
Recomputes all items height.
void showStripes(bool flag)
Sets show stripes mode.
bool showGrid() const
Returns show grid mode.
Definition: CListView.h:979
void showGrid(bool flag)
Sets show grid mode.
bool select_only(uint32_t index, bool docallbacks=false)
Selects the only row. Internal.
uint32_t fullWidth() const
Returns maximum width of all items including the header row.
void textColor(Fl_Color n) override
Sets text color.
Definition: CListView.h:971
void imageCollection(Strings &iconNames)
Sets the images that may be referred from items.
static void scrollbar_callback(Fl_Widget *s, void *)
Internal vertical scrollback callback.
virtual void displayRow(uint32_t index)
void columns(const CColumnList &columns)
Sets a new column list.
virtual bool item_selected(uint32_t index) const
Returns true if item is selected.
CControlKind kind() const override
SPTK RTTI information.
Definition: CListView.h:910
const CSelection & selection() const
Definition: CListView.h:702
Strings m_iconNames
Definition: CListView.h:187
CListView(const char *label=nullptr, int layoutSize=20, CLayoutAlign layoutAlign=CLayoutAlign::TOP)
Constructor in SPTK style.
virtual void updateRow(uint32_t position, const Strings &row, int ident=0)
Updates a row. Optional row argument may be defined inside row parameter.
void redraw_line(uint32_t index)
Request to redraw line index.
bool multiSelect() const
Returns multiple selection enabled or disabled.
Definition: CListView.h:1021
virtual void top(int index)
Sets the scroll position.
void sortAscending(bool ascending, bool sortNow)
Sets the sort direction - ascending/descending.
virtual void item_draw(uint32_t index, const CPackedStrings *rowData, int x, int y, int w, int h, int focusMode, int verticalAlign, bool paintBackground) const
Draws a row in coordinates (internal)
Packed strings list.
Definition: PackedStrings.h:58
Definition: CScrollBar.h:45
List view & friend items selection.
Definition: CListViewSelection.h:50
Definition: DataSource.h:49
Definition: Query.h:239
Definition: String.h:49
Definition: Strings.h:52
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
CLayoutXMLmode
Definition: CLayoutClient.h:57
CListViewDataMode
The data mode for the data() methods.
Definition: CListView.h:76
CRefreshKind
The refersh kind.
Definition: CListView.h:54
@ TOP
Align to the right.
VariantDataType
Definition: VariantData.h:44

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