SavvyUI C++ UI Library
Loading...
Searching...
No Matches
Grid.h
Go to the documentation of this file.
1#pragma once
2
3#include "Component.h"
4#include "TextField.h"
5#include "MaskedField.h"
6#include "ComboBox.h"
7#include "Models.h"
8#include "DateTimePicker.h"
9#include "CheckBox.h"
10#include "Scrollbar.h"
11
44
46{
47public:
48 vector<wstring> _values;
50};
51
59class Grid : public Component, public ScrollbarListener
60{
61 Scrollbar _scrollBar;
62
63 GridChangeListener* _gridChangeListener;
64
65 Pager* _pager;
66 PagerRequest _pagerRequest;
67 BOOL _pageFetched;
68 BOOL _isLoadingPage;
69 __int64 _lastLoadedFirstVisibleRow;
70 __int64 _lastLoadedMaxVisibleRows;
71 __int64 _totalRowCount;
72
73 wstring _sortedBy;
74 SortType _sortDirection;
75
76 Bounds _pageHomeBtnRect;
77 Bounds _pagePrevBtnRect;
78 Bounds _pageNextBtnRect;
79 Bounds _pageEndBtnRect;
80
81 vector<GridColumn> _columns;
82 vector<GridRow> _rows;
83
84 long _maxVisibleRows;
85 __int64 _firstVisibleRow;
86 __int64 _lastVisibleRow;
87 __int64 _currentRow;
88 long _currentColumn;
89
90 BOOL _isStriped;
91
92 TextField _textEditor;
93 MaskedField _maskEditor;
94 ComboBox _comboEditor;
95 Component* _currentCellEditor;
96 EditType _currentCellEditorStyle;
97 __int64 _editorRowIndex, _editorColumnIndex;
98
99 void FixRow(__int64 rowIndex);
100 void LayoutColumns();
101
102 void ResetPaging();
103 void LoadPage(BOOL doPaint = TRUE);
104
105 void SetCurrentCell(__int64 rowIndex, long columnIndex, BOOL& isNewCellEditable);
106 void HideEditor();
107
108 BOOL FireCellValueChangeEvent(__int64 rowIndex, const wstring& columnName, const wstring& oldValue, const wstring& newValue);
109
110protected:
111 BOOL getCreateWindowOptions(wstring& title, UINT& widownStyles, wstring& wndClassName, BOOL& isCustomWndProc) override;
112 void windowCreated() override;
113
114public:
116 virtual ~Grid();
117
118 void setPager(Pager* pager);
121
122 void setStriped(BOOL isStriped);
123
124 void clear();
125 void clearRows();
126
127 vector<GridColumn> getColumns();
128 void addColumn(const wstring& name, const wstring& title, BOOL isVisible, UINT widthRatio, long alignment = -1,
129 BOOL isSortable = FALSE, BOOL isFilterable = FALSE, BOOL isEditable = FALSE,
130 const EditType& editStyle = EditType::TEXTFIELD,
131 const vector<wstring>& editOptions = {},
132 const wstring& computedColumnExpression = L"");
133
134 void setColumnEditor(long columnIndex, Component* component);
135 Component* getColumnEditor(long columnIndex);
136
137 __int64 getRowCount();
138 __int64 getSelectedRow();
139 __int64 addRow();
140
141 void setCellValue(__int64 rowIndex, long columnIndex, const wstring& value);
142 wstring getCellValue(__int64 rowIndex, long columnIndex);
143 void setCellValue(__int64 rowIndex, const wstring& columnName, const wstring& value);
144 wstring getCellValue(__int64 rowIndex, const wstring& columnName);
145
146 BOOL deleteRow(__int64 rowIndex);
147
148public: // Overridables
149
150 void onPaint(Graphics *g) override;
151 void onWindowResized() override;
152
153 void onArrowUp(BOOL shiftPressed, BOOL ctrlPressed) override;
154 void onArrowDown(BOOL shiftPressed, BOOL ctrlPressed) override;
155 void onPageUp(BOOL shiftPressed, BOOL ctrlPressed) override;
156 void onPageDown(BOOL shiftPressed, BOOL ctrlPressed) override;
157 void onKeyHome(BOOL shiftPressed, BOOL ctrlPressed) override;
158 void onKeyEnd(BOOL shiftPressed, BOOL ctrlPressed) override;
159 void onKeyTab(BOOL shiftPressed, BOOL ctrlPressed) override;
160
161 void onMousePressed(WinHandle hWnd, int x, int y, int clickCount, BOOL shiftPressed, BOOL ctrlPressed) override;
162 void onMouseReleased(WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed);
163 void onMouseMoved(WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed);
164 BOOL onMouseWheel(WinHandle hWnd, int x, int y, int delta) override;
165
166 void onFocusGained() override;
167 void onFocusLost() override;
168
171
173
174public:
175
176 void scrollBarActivity(__int64 firstVisibleItem);
178};
HWND WinHandle
Definition Common.h:16
EditType
Definition Common.h:147
@ TEXTFIELD
Definition Common.h:148
SortType
Definition Models.h:6
Definition Common.h:21
A UI component that allows users to select a single item from a dropdown list.
Definition ComboBox.h:13
Base class for all UI components providing window creation, event handling, and listener management.
Definition Component.h:32
Component()
Constructs a new Component instance.
Definition Graphics.h:171
Definition EventListeners.h:82
BOOL _isSortable
Definition Grid.h:36
BOOL _isFilterable
Definition Grid.h:37
vector< wstring > _editOptions
Definition Grid.h:41
BOOL _isEditable
Definition Grid.h:38
long _calculatedWidth
Definition Grid.h:31
long _alignment
Definition Grid.h:29
wstring _name
Definition Grid.h:28
wstring _computedColumnExpression
Definition Grid.h:39
int _columnEndX
Definition Grid.h:32
GridColumn()
Definition Grid.h:15
EditType _editStyle
Definition Grid.h:40
long _widthRatio
Definition Grid.h:30
Bounds _sortIndicatorRect
Definition Grid.h:33
wstring _title
Definition Grid.h:28
BOOL _isVisible
Definition Grid.h:35
int _columnStartX
Definition Grid.h:32
Component * _editor
Definition Grid.h:42
void setCellValue(__int64 rowIndex, const wstring &columnName, const wstring &value)
Sets the value of a specific cell.
void setPager(Pager *pager)
Assigns a pager for handling data loading.
void addGridChangeListener(GridChangeListener *l)
void clear()
Clears all rows and resets the grid.
wstring getCellValue(__int64 rowIndex, long columnIndex)
Gets the value of a specific cell.
void onArrowUp(BOOL shiftPressed, BOOL ctrlPressed) override
__int64 getRowCount()
Returns the number of rows currently loaded.
vector< GridColumn > getColumns()
Returns all grid columns.
void onPaint(Graphics *g) override
Called to paint the component's client area.
void resetPaging()
virtual ~Grid()
void scrollBarRepaint()
void setCellValue(__int64 rowIndex, long columnIndex, const wstring &value)
Sets the value of a specific cell.
void onPageUp(BOOL shiftPressed, BOOL ctrlPressed) override
void reloadPage()
Component * getColumnEditor(long columnIndex)
Gets the editor component for a column.
wstring getCellValue(__int64 rowIndex, const wstring &columnName)
Gets the value of a specific cell.
void clearRows()
void onPageDown(BOOL shiftPressed, BOOL ctrlPressed) override
void onKeyEnd(BOOL shiftPressed, BOOL ctrlPressed) override
void onFocusLost() override
Called when the component loses keyboard focus.
void onArrowDown(BOOL shiftPressed, BOOL ctrlPressed) override
void onKeyHome(BOOL shiftPressed, BOOL ctrlPressed) override
__int64 addRow()
Adds a new row and returns its index.
void setColumnEditor(long columnIndex, Component *component)
Sets an editor component for a column.
void addColumn(const wstring &name, const wstring &title, BOOL isVisible, UINT widthRatio, long alignment=-1, BOOL isSortable=FALSE, BOOL isFilterable=FALSE, BOOL isEditable=FALSE, const EditType &editStyle=EditType::TEXTFIELD, const vector< wstring > &editOptions={}, const wstring &computedColumnExpression=L"")
Adds a new column.
BOOL onMouseWheel(WinHandle hWnd, int x, int y, int delta) override
Called when the mouse wheel is used over the component.
void onMousePressed(WinHandle hWnd, int x, int y, int clickCount, BOOL shiftPressed, BOOL ctrlPressed) override
Called when the mouse is pressed within the component.
BOOL deleteRow(__int64 rowIndex)
Deletes a row at the given index.
void windowCreated() override
Abstract method called after the window has been created.
void scrollBarActivity(__int64 firstVisibleItem)
void addItemDoubleClickedListener(RowDoubleClickListener *l)
BOOL getCreateWindowOptions(wstring &title, UINT &widownStyles, wstring &wndClassName, BOOL &isCustomWndProc) override
Abstract method to get window creation options.
void addSelectionChangedListener(SelectionChangeListener *l)
void setStriped(BOOL isStriped)
void onKeyTab(BOOL shiftPressed, BOOL ctrlPressed) override
__int64 getSelectedRow()
Returns the index of the currently selected row.
void onFocusGained() override
Called when the component gains keyboard focus.
void onMouseMoved(WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed)
Called when the mouse is moved within the component.
void onWindowResized() override
Called when the component's window is resized.
void onMouseReleased(WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed)
Called when the mouse button is released within the component.
Definition Grid.h:46
vector< wstring > _values
Definition Grid.h:48
Bounds _rect
Definition Grid.h:49
Input field that supports input masking and numeric input.
Definition MaskedField.h:15
Definition Models.h:45
Definition Models.h:33
Definition EventListeners.h:60
Definition Scrollbar.h:14
Definition Scrollbar.h:6
Definition EventListeners.h:31
A text input field component.
Definition TextField.h:9