SavvyUI C++ UI Library
Loading...
Searching...
No Matches
ListBox.h
Go to the documentation of this file.
1#pragma once
2
3#include "Component.h"
4#include "Scrollbar.h"
5
7{
8public:
9 wstring _text;
10 COLORREF _color;
12};
13
21class ListBox : public Component, public ScrollbarListener
22{
23 Scrollbar _scrollBar;
24
25 std::vector<ListBoxItem> _selections;
26
27 long _maxVisibleRows;
28 __int64 _firstVisibleRow;
29 __int64 _lastVisibleRow;
30 __int64 _currentRow;
31
32 BOOL _isColorList;
33
37 BOOL _isPopup;
38 BOOL _hidePopupOnFocusLoss;
39
40protected:
41
51 BOOL getCreateWindowOptions(wstring& title, UINT& widownStyles, wstring& wndClassName, BOOL& isCustomWndProc);
52
57
58public:
59
64
68 virtual ~ListBox();
69
71
77 void setAsPopup(BOOL isPopup, BOOL hidePopupOnFocusLoss = TRUE);
78
82 BOOL isPopup();
83
85
86 void clear();
87
94 void addItem(const wstring& text, COLORREF color = Theme::BackgroundColor);
95 BOOL getItem(int index, wstring& text);
97
103 void setSelectedItem(const wstring& text);
104
111
112public: // Overridables
113
114 void onPaint(Graphics* g) override;
115 void onWindowResized() override;
116
117 void onArrowUp(BOOL shiftPressed, BOOL ctrlPressed) override;
118 void onArrowDown(BOOL shiftPressed, BOOL ctrlPressed) override;
119 void onPageUp(BOOL shiftPressed, BOOL ctrlPressed) override;
120 void onPageDown(BOOL shiftPressed, BOOL ctrlPressed) override;
121 void onKeyHome(BOOL shiftPressed, BOOL ctrlPressed) override;
122 void onKeyEnd(BOOL shiftPressed, BOOL ctrlPressed) override;
123
124 void onMousePressed(WinHandle hWnd, int x, int y, int clickCount, BOOL shiftPressed, BOOL ctrlPressed) override;
125 void onMouseReleased(WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed);
126 void onMouseMoved(WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed);
127 BOOL onMouseWheel(WinHandle hWnd, int x, int y, int delta) override;
128
129 void onFocusGained() override;
130 void onFocusLost() override;
131
132public:
133
136
137public:
138
139 void scrollBarActivity(__int64 firstVisibleItem);
141};
HWND WinHandle
Definition Common.h:16
Definition Common.h:21
Component()
Constructs a new Component instance.
Definition Graphics.h:171
void addItem(const wstring &text, COLORREF color=Theme::BackgroundColor)
Adds to the list of selectable options.
int getPreferredHeight()
Returns the preferred height of the component.
void onKeyHome(BOOL shiftPressed, BOOL ctrlPressed) override
void onFocusGained() override
Called when the component gains keyboard focus.
virtual ~ListBox()
Destructor.
ListBox()
Constructs an empty ListBox component.
void onPageDown(BOOL shiftPressed, BOOL ctrlPressed) override
BOOL getItem(int index, wstring &text)
void onFocusLost() override
Called when the component loses keyboard focus.
void windowCreated()
Called once the native window has been created.
void onMousePressed(WinHandle hWnd, int x, int y, int clickCount, BOOL shiftPressed, BOOL ctrlPressed) override
Called when the mouse is pressed within the component.
void setAsPopup(BOOL isPopup, BOOL hidePopupOnFocusLoss=TRUE)
Sets whether the listbox is used in a popup context.
void clear()
void onArrowDown(BOOL shiftPressed, BOOL ctrlPressed) override
void onArrowUp(BOOL shiftPressed, BOOL ctrlPressed) override
long getItemCount()
BOOL isPopup()
Return TRUE if this component is displayed as a popup (e.g. dropdown from CheckComboBox).
BOOL onMouseWheel(WinHandle hWnd, int x, int y, int delta) override
Called when the mouse wheel is used over the component.
void onPageUp(BOOL shiftPressed, BOOL ctrlPressed) override
void setSelectedItem(const wstring &text)
Sets the currently selected item by text.
void setColorsListType()
wstring getSelectedItem()
Retrieves the currently selected item text.
void onPaint(Graphics *g) override
Called to paint the component's client area.
void onKeyEnd(BOOL shiftPressed, BOOL ctrlPressed) override
void scrollBarActivity(__int64 firstVisibleItem)
void addItemDoubleClickedListener(RowDoubleClickListener *l)
void onMouseReleased(WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed)
Called when the mouse button is released within the component.
void scrollBarRepaint()
BOOL getCreateWindowOptions(wstring &title, UINT &widownStyles, wstring &wndClassName, BOOL &isCustomWndProc)
Provides native window creation options for the ListBox control.
void onMouseMoved(WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed)
Called when the mouse is moved within the component.
void addSelectionChangedListener(SelectionChangeListener *l)
void onWindowResized() override
Called when the component's window is resized.
Definition ListBox.h:7
wstring _text
Definition ListBox.h:9
COLORREF _color
Definition ListBox.h:10
Bounds _rect
Definition ListBox.h:11
Definition EventListeners.h:60
Definition Scrollbar.h:14
Definition Scrollbar.h:6
Definition EventListeners.h:31
static COLORREF BackgroundColor
Definition Theme.h:126