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
43
45{
46public:
47 vector<wstring> _values;
49};
50
58class Grid : public Component
59{
60 GridChangeListener* _gridChangeListener;
61
62 Pager* _pager;
63 PagerRequest _pagerRequest;
64 BOOL _pageFetched;
65 BOOL _isLoadingPage;
66 __int64 _totalRowCount;
67
68 wstring _sortedBy;
69 SortType _sortDirection;
70
71 Bounds _pageHomeBtnRect;
72 Bounds _pagePrevBtnRect;
73 Bounds _pageNextBtnRect;
74 Bounds _pageEndBtnRect;
75
76 vector<GridColumn> _columns;
77 vector<GridRow> _rows;
78
79 long _maxVisibleRows;
80 __int64 _firstVisibleRow;
81 __int64 _lastVisibleRow;
82 __int64 _currentRow;
83 long _currentColumn;
84
85 BOOL _isStriped;
86
87 TextField _textEditor;
88 MaskedField _maskEditor;
89 ComboBox _comboEditor;
90 Component* _currentCellEditor;
91 long _currentCellEditorStyle;
92 __int64 _editorRowIndex, _editorColumnIndex;
93
94 void FixRow(__int64 rowIndex);
95 void LayoutColumns();
96
97 void ResetPaging();
98 void LoadPage(BOOL doPaint = TRUE);
99
100 void SetCurrentCell(__int64 rowIndex, long columnIndex, BOOL& isNewCellEditable);
101 void HideEditor();
102
103 BOOL FireCellValueChangeEvent(__int64 rowIndex, const wstring& columnName, const wstring& oldValue, const wstring& newValue);
104
105protected:
106 BOOL getCreateWindowOptions(wstring& title, UINT& widownStyles, wstring& wndClassName, BOOL& isCustomWndProc) override;
107 void windowCreated() override;
108
109public:
111 virtual ~Grid();
112
113 void setPager(Pager* pager);
115
116 void setStriped(BOOL isStriped);
117
118 void clear();
119
120 vector<GridColumn> getColumns();
121 void addColumn(const wstring& name, const wstring& title, BOOL isVisible, UINT widthRatio, long alignment = -1,
122 BOOL isSortable = FALSE, BOOL isFilterable = FALSE, BOOL isEditable = FALSE,
123 const EditType& editStyle = EditType::TEXTFIELD,
124 const vector<wstring>& editOptions = {},
125 const wstring& computedColumnExpression = L"");
126
127 void setColumnEditor(long columnIndex, Component* component);
128 Component* getColumnEditor(long columnIndex);
129
130 __int64 getRowCount();
131 __int64 getSelectedRow();
132 __int64 addRow();
133
134 void setCellValue(__int64 rowIndex, long columnIndex, const wstring& value);
135 wstring getCellValue(__int64 rowIndex, long columnIndex);
136 void setCellValue(__int64 rowIndex, const wstring& columnName, const wstring& value);
137 wstring getCellValue(__int64 rowIndex, const wstring& columnName);
138
139 BOOL deleteRow(__int64 rowIndex);
140
141public: // Overridables
142
143 void onPaint(Graphics *g) override;
144 void onWindowResized() override;
145
146 void onArrowUp(BOOL shiftPressed, BOOL ctrlPressed) override;
147 void onArrowDown(BOOL shiftPressed, BOOL ctrlPressed) override;
148 void onPageUp(BOOL shiftPressed, BOOL ctrlPressed) override;
149 void onPageDown(BOOL shiftPressed, BOOL ctrlPressed) override;
150 void onKeyHome(BOOL shiftPressed, BOOL ctrlPressed) override;
151 void onKeyEnd(BOOL shiftPressed, BOOL ctrlPressed) override;
152 void onKeyTab(BOOL shiftPressed, BOOL ctrlPressed) override;
153
154 void onMousePressed(WinHandle hWnd, int x, int y, int clickCount, BOOL shiftPressed, BOOL ctrlPressed) override;
155 BOOL onMouseWheel(WinHandle hWnd, int x, int y, int delta) override;
156
157 void onFocusGained() override;;
158 void onFocusLost() override;;
159
160 BOOL getScrollingInfo(__int64& scrollMin, __int64& scrollMax, __int64& pageSize) override;
161 void setScrollbarTopOffset(__int64 firstVisibleRow) override;
162
165
167};
HWND WinHandle
Definition Common.h:16
EditType
Definition Common.h:139
@ TEXTFIELD
Definition Common.h:140
SortType
Definition Models.h:6
Definition Common.h:20
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:161
Definition EventListeners.h:82
BOOL _isSortable
Definition Grid.h:35
BOOL _isFilterable
Definition Grid.h:36
vector< wstring > _editOptions
Definition Grid.h:40
BOOL _isEditable
Definition Grid.h:37
long _calculatedWidth
Definition Grid.h:30
long _alignment
Definition Grid.h:28
wstring _name
Definition Grid.h:27
wstring _computedColumnExpression
Definition Grid.h:38
int _columnEndX
Definition Grid.h:31
GridColumn()
Definition Grid.h:14
EditType _editStyle
Definition Grid.h:39
long _widthRatio
Definition Grid.h:29
Bounds _sortIndicatorRect
Definition Grid.h:32
wstring _title
Definition Grid.h:27
BOOL _isVisible
Definition Grid.h:34
int _columnStartX
Definition Grid.h:31
Component * _editor
Definition Grid.h:41
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.
BOOL getScrollingInfo(__int64 &scrollMin, __int64 &scrollMax, __int64 &pageSize) override
Provides scrolling information if supported.
void onPaint(Graphics *g) override
Called to paint the component's client area.
virtual ~Grid()
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 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
void setScrollbarTopOffset(__int64 firstVisibleRow) override
Sets the scrollbar's top offset.
__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 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 onWindowResized() override
Called when the component's window is resized.
Definition Grid.h:45
vector< wstring > _values
Definition Grid.h:47
Bounds _rect
Definition Grid.h:48
Input field that supports input masking and numeric input.
Definition MaskedField.h:15
Definition Models.h:44
Definition Models.h:33
Definition EventListeners.h:60
Definition EventListeners.h:31
A text input field component.
Definition TextField.h:9