SavvyUI C++ UI Library
Loading...
Searching...
No Matches
Component.h
Go to the documentation of this file.
1#pragma once
2
3#include "Common.h"
4#include "UICommon.h"
5#include "EventListeners.h"
6#include "Graphics.h"
7
9{
10public:
12 WPARAM wParam;
13 LPARAM lParam;
14};
15
32{
34 static long NextId;
35
37 long _id;
38
39 Component* _parent;
40
42 BOOL _doNotSubclass;
43
45 long _nCommand;
46
48 DataChangeListener* _dataChangeListener;
49
51 SelectionChangeListener* _selectionChangeListener;
52
54 ActionListener* _actionListener;
55
57 RowDoubleClickListener* _rowDoubleClickListener;
58
60 int _mouseWheelDelta;
61
63 BOOL _isPaintQueued;
64
66 BOOL _isCustomFont;
67
69 HFONT _customFont;
70
72 long _fontSize;
73
75 wstring _fontName;
76
78 BOOL _fontIsBold;
79 BOOL _fontIsItalic;
80 BOOL _fontIsUnderlined;
81
82 long _lastResizeX, _lastResizeY, _lastResizeWidth, _lastResizeHeight;
83
84 vector<NumberCollection> _scheduledTimers;
85
91 void interceptStandardControlEvents(WinHandle hWndControl);
92
106 BOOL createNativeWindow(WinHandle hParent, Bounds rect, const wstring& title, UINT windowStyles,
107 const wstring& wndClassName = L"", BOOL isCustomWndProc = FALSE,
108 long nCmdId = -1, BOOL isVisible = TRUE);
109
110protected:
113
116
118
131 virtual BOOL getCreateWindowOptions(wstring& title, UINT& widownStyles, wstring& wndClassName, BOOL& isCustomWndProc) = 0;
132
138 virtual void windowCreated() = 0;
139
146
151
158 void startTimer(unsigned int timerId, unsigned int milliseconds);
159
165 void stopTimer(unsigned int timerId);
166
167public:
172
176 virtual ~Component();
177
183 long getId();
184
185 void setParent(Component* parent);
187
194
201
208
218 int createComponent(WinHandle hParent, Bounds rect, long nCmd = -1, BOOL isVisible = TRUE);
219
229 void setFont(long fontSize, BOOL isBold = FALSE, BOOL isItalic = FALSE, BOOL isUnderlined = FALSE, const wstring& fontName = L"Arial");
230
231 void showBorder(BOOL bShow = TRUE);
232
238 void setEnabled(BOOL bEnable = TRUE);
239
245 void setVisible(BOOL bShow = TRUE);
246
249
258 void moveWindow(long x, long y, long width, long height, BOOL bRedraw = TRUE);
259
264
270 void setMouseWheelDelta(int delta);
271
278
284 virtual int getMinimumHeight();
285
291 virtual int getPreferredHeight();
292
296 void repaint(WinHandle hWnd = NULL);
297
302
303public: // Overridable event handlers
304
306 virtual void onPaint(Graphics *g) {}
307
309 virtual void onWindowResized() {}
310
312 virtual void onWindowMoved() {}
313
321 virtual void onAction(WinHandle hTarget, long actionId, const ProcParams& procParams) {}
322
332 virtual void onSelectionChanged(WinHandle hTarget, int itemIndex, const wstring& itemText, BOOL itemChecked, const ProcParams& procParams) {}
333
341 virtual void onDataChanged(WinHandle hTarget, const wstring& newValue, const ProcParams& procParams) {}
342
350 virtual BOOL onHorzScroll(WinHandle hTarget, const ProcParams& procParams) { return FALSE; }
351
359 virtual BOOL onDrawMeasureItem(LPMEASUREITEMSTRUCT dis, const ProcParams& procParams) { return FALSE; }
360
368 virtual BOOL onDrawItem(LPDRAWITEMSTRUCT dis, const ProcParams& procParams) { return FALSE; }
369
371 virtual void onMousePressed(WinHandle hWnd, int x, int y, int clickCount, BOOL shiftPressed, BOOL ctrlPressed) {}
372
374 virtual void onMouseReleased(WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed) {}
375
377 virtual void onMouseRightClicked(WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed) {}
378
380 virtual void onMouseMoved(WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed) {}
381
391 virtual BOOL onMouseWheel(WinHandle hWnd, int x, int y, int delta) { return FALSE; }
392
393 // Keyboard key event handlers (shiftPressed and ctrlPressed indicate modifier key state)
394 virtual void onArrowLeft(BOOL shiftPressed, BOOL ctrlPressed) {}
395 virtual void onArrowRight(BOOL shiftPressed, BOOL ctrlPressed) {}
396 virtual void onArrowUp(BOOL shiftPressed, BOOL ctrlPressed) {}
397 virtual void onArrowDown(BOOL shiftPressed, BOOL ctrlPressed) {}
398 virtual void onPageUp(BOOL shiftPressed, BOOL ctrlPressed) {}
399 virtual void onPageDown(BOOL shiftPressed, BOOL ctrlPressed) {}
400 virtual void onKeyHome(BOOL shiftPressed, BOOL ctrlPressed) {}
401 virtual void onKeyEnd(BOOL shiftPressed, BOOL ctrlPressed) {}
402 virtual void onKeyInsert(BOOL shiftPressed, BOOL ctrlPressed) {}
403 virtual void onKeyDelete(BOOL shiftPressed, BOOL ctrlPressed) {}
404 virtual void onKeyBackSpace(BOOL shiftPressed, BOOL ctrlPressed) {}
405 virtual void onKeyTyped(wchar_t ch, BOOL shiftPressed, BOOL ctrlPressed) {}
406 virtual void onKeyTab(BOOL shiftPressed, BOOL ctrlPressed) {}
407 virtual void onKeyEnter(BOOL shiftPressed, BOOL ctrlPressed) {}
408 virtual void onKeyF1(BOOL shiftPressed, BOOL ctrlPressed) {}
409 virtual void onKeyF2(BOOL shiftPressed, BOOL ctrlPressed) {}
410 virtual void onKeyF3(BOOL shiftPressed, BOOL ctrlPressed) {}
411 virtual void onKeyF4(BOOL shiftPressed, BOOL ctrlPressed) {}
412 virtual void onKeyF5(BOOL shiftPressed, BOOL ctrlPressed) {}
413 virtual void onKeyF6(BOOL shiftPressed, BOOL ctrlPressed) {}
414 virtual void onKeyF7(BOOL shiftPressed, BOOL ctrlPressed) {}
415 virtual void onKeyF8(BOOL shiftPressed, BOOL ctrlPressed) {}
416 virtual void onKeyF9(BOOL shiftPressed, BOOL ctrlPressed) {}
417 virtual void onKeyF10(BOOL shiftPressed, BOOL ctrlPressed) {}
418 virtual void onKeyF11(BOOL shiftPressed, BOOL ctrlPressed) {}
419 virtual void onKeyF12(BOOL shiftPressed, BOOL ctrlPressed) {}
420
422 virtual void onFocusGained() {}
423
425 virtual void onFocusLost() {}
426
432 virtual void onTimer(unsigned int timerId) {}
433
434 // Scrollbar functionality
435
444 virtual BOOL getScrollingInfo(__int64& scrollMin, __int64& scrollMax, __int64& pageSize) { return FALSE; }
445
451 virtual void setScrollbarTopOffset(__int64 firstVisibleRow) {}
452
460 void updateScrollbarTopOffset(__int64 firstVisibleRow);
461
462protected: // Listener management
463
470
477
484
491
498 void protectedFireDataChangedEvent(const wstring& oldValue, const wstring& newValue);
499
507 void protectedFireSelectionChangedEvent(long selectionIndex = -1, const wstring& selectionValue = L"", BOOL checked = FALSE);
508
515 void protectedFireActionEvent(long actionId = -1, const wstring& actionName = L"");
516
523};
HWND WinHandle
Definition Common.h:16
Definition EventListeners.h:46
Definition Common.h:20
virtual void onKeyF9(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:416
virtual void onFocusGained()
Called when the component gains keyboard focus.
Definition Component.h:422
virtual void onTimer(unsigned int timerId)
Called on timer events.
Definition Component.h:432
virtual int getPreferredHeight()
Returns the preferred height of the component.
int getMouseWheelDelta()
Gets the current mouse wheel delta.
virtual BOOL onMouseWheel(WinHandle hWnd, int x, int y, int delta)
Called when the mouse wheel is used over the component.
Definition Component.h:391
virtual void onKeyF6(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:413
void GetWindowRect(Bounds &rect)
void setFont(long fontSize, BOOL isBold=FALSE, BOOL isItalic=FALSE, BOOL isUnderlined=FALSE, const wstring &fontName=L"Arial")
Sets the font for the component.
virtual BOOL getScrollingInfo(__int64 &scrollMin, __int64 &scrollMax, __int64 &pageSize)
Provides scrolling information if supported.
Definition Component.h:444
virtual void onSelectionChanged(WinHandle hTarget, int itemIndex, const wstring &itemText, BOOL itemChecked, const ProcParams &procParams)
Called when the selection changes.
Definition Component.h:332
void GetClientRect(Bounds &rect)
wstring _componentType
String representing the component type (e.g., "Button", "ComboBox").
Definition Component.h:115
void protectedFireItemDoubleClickedEvent(__int64 rowIndex)
Fires a row double-click event to registered listeners.
virtual void onWindowMoved()
Called when the component's window is moved.
Definition Component.h:312
virtual void onKeyF1(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:408
virtual ~Component()
Virtual destructor.
virtual void onKeyF12(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:419
virtual void onArrowUp(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:396
virtual void onPaint(Graphics *g)
Called to paint the component's client area.
Definition Component.h:306
virtual void onKeyBackSpace(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:404
virtual void onArrowDown(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:397
virtual void windowCreated()=0
Abstract method called after the window has been created.
virtual void onKeyEnd(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:401
int createComponent(WinHandle hParent, Bounds rect, long nCmd=-1, BOOL isVisible=TRUE)
Creates the component's native window as a child of hParent.
virtual void onKeyTab(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:406
BOOL _showBorder
Definition Component.h:117
virtual void onMouseMoved(WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed)
Called when the mouse is moved within the component.
Definition Component.h:380
virtual void onWindowResized()
Called when the component's window is resized.
Definition Component.h:309
void clearQueuedPaintRequest()
clears the queued paint request. This function should only be called internally from the library.
virtual void onKeyTyped(wchar_t ch, BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:405
BOOL isWindowCreated()
Returns whether the native window has been created.
virtual void onFocusLost()
Called when the component loses keyboard focus.
Definition Component.h:425
void setMouseWheelDelta(int delta)
Sets the accumulated mouse wheel delta.
virtual void onMousePressed(WinHandle hWnd, int x, int y, int clickCount, BOOL shiftPressed, BOOL ctrlPressed)
Called when the mouse is pressed within the component.
Definition Component.h:371
virtual void onKeyF8(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:415
void reconfigureScrollBar()
Forces the component to recalculate the scrollbar info.
virtual BOOL onHorzScroll(WinHandle hTarget, const ProcParams &procParams)
Called on horizontal scroll events.
Definition Component.h:350
virtual BOOL getCreateWindowOptions(wstring &title, UINT &widownStyles, wstring &wndClassName, BOOL &isCustomWndProc)=0
Abstract method to get window creation options.
void stopTimer(unsigned int timerId)
Stops the timer identified by timerId.
long getActionId()
Returns the component's action command ID.
virtual void onPageUp(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:398
virtual void onArrowRight(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:395
Component()
Constructs a new Component instance.
void doNotSubclass()
Marks this component's native window to avoid subclassing.
virtual void setScrollbarTopOffset(__int64 firstVisibleRow)
Sets the scrollbar's top offset.
Definition Component.h:451
Component * getParent()
virtual void onKeyDelete(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:403
virtual void onKeyHome(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:400
virtual void onAction(WinHandle hTarget, long actionId, const ProcParams &procParams)
Called when an action occurs on the component.
Definition Component.h:321
WinHandle getWindowHandle()
Returns the native WinHandle for this component.
void protectedAddSelectionChangedListener(SelectionChangeListener *l)
Adds a selection change listener.
void protectedFireActionEvent(long actionId=-1, const wstring &actionName=L"")
Fires an action event to registered listeners.
virtual void onKeyF11(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:418
void startTimer(unsigned int timerId, unsigned int milliseconds)
Starts a timer with the given ID and interval.
virtual void onArrowLeft(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:394
virtual BOOL onDrawMeasureItem(LPMEASUREITEMSTRUCT dis, const ProcParams &procParams)
Called when measuring an item for owner-draw controls.
Definition Component.h:359
void protectedAddDataChangedListener(DataChangeListener *l)
Adds a data change listener.
void protectedAddItemDoubleClickedListener(RowDoubleClickListener *l)
Adds a row double-click listener.
virtual void onKeyInsert(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:402
wstring getComponentType()
Gets the component type string.
void updateScrollbarTopOffset(__int64 firstVisibleRow)
Updates the scrollbar's top offset based on the current first visible row.
void protectedAddActionListener(ActionListener *l)
Adds an action listener.
virtual void onKeyF2(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:409
virtual void onPageDown(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:399
virtual void onKeyF4(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:411
void showBorder(BOOL bShow=TRUE)
void protectedFireSelectionChangedEvent(long selectionIndex=-1, const wstring &selectionValue=L"", BOOL checked=FALSE)
Fires a selection changed event to registered listeners.
virtual BOOL onDrawItem(LPDRAWITEMSTRUCT dis, const ProcParams &procParams)
Called when drawing an item for owner-draw controls.
Definition Component.h:368
virtual void onMouseRightClicked(WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed)
Called when the right mouse button is clicked within the component.
Definition Component.h:377
virtual void onKeyF7(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:414
WinHandle _hWnd
Handle to the native window associated with this component.
Definition Component.h:112
void moveWindow(long x, long y, long width, long height, BOOL bRedraw=TRUE)
Moves and resizes the component window.
void setEnabled(BOOL bEnable=TRUE)
Enables or disables the component.
virtual void onKeyEnter(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:407
void protectedFireDataChangedEvent(const wstring &oldValue, const wstring &newValue)
Fires a data changed event to registered listeners.
virtual void onKeyF3(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:410
virtual void onMouseReleased(WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed)
Called when the mouse button is released within the component.
Definition Component.h:374
void setVisible(BOOL bShow=TRUE)
Shows or hides the component.
virtual void onKeyF5(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:412
virtual void onKeyF10(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:417
void repaint(WinHandle hWnd=NULL)
Requests the component to repaint itself.
void setParent(Component *parent)
long getId()
Gets the unique ID assigned to this component.
virtual void onDataChanged(WinHandle hTarget, const wstring &newValue, const ProcParams &procParams)
Called when data changes in the component.
Definition Component.h:341
virtual int getMinimumHeight()
Returns the minimum height the component can have.
Definition EventListeners.h:15
Definition Graphics.h:161
Definition Component.h:9
LPARAM lParam
Definition Component.h:13
WinHandle hwnd
Definition Component.h:11
WPARAM wParam
Definition Component.h:12
Definition EventListeners.h:60
Definition EventListeners.h:31