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(Component *parent, 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);
188
190
197
204
211
221 int createComponent(Component* parent, Bounds rect, long nCmd = -1, BOOL isVisible = TRUE);
222
223 void setFocus();
224
234 void setFont(long fontSize, BOOL isBold = FALSE, BOOL isItalic = FALSE, BOOL isUnderlined = FALSE, const wstring& fontName = L"Arial");
235
236 BOOL getCustomFont(long& fontSize, BOOL& isBold, BOOL& isItalic, BOOL& isUnderlined, wstring& fontName);
237
238 void showBorder(BOOL bShow = TRUE);
239
245 void setEnabled(BOOL bEnable = TRUE);
246
252 void setVisible(BOOL bShow = TRUE);
253
256
265 void moveWindow(long x, long y, long width, long height, BOOL bRedraw = TRUE);
266
271
277 void setMouseWheelDelta(int delta);
278
285
291 virtual int getMinimumHeight();
292
298 virtual int getPreferredHeight();
299
303 void repaint(Component* comp = NULL, BOOL repaintImmediately = FALSE); // Must be defaulted to FALSE
304
309
310 virtual BOOL getChildren(vector<Component*>& children) { return FALSE; };
311
312public: // Overridable event handlers
313
315 virtual void onPaint(Graphics *g) {}
316
318 virtual void onWindowResized() {}
319
321 virtual void onWindowMoved() {}
322
330 virtual void onAction(WinHandle hTarget, long actionId, const ProcParams& procParams) {}
331
341 virtual void onSelectionChanged(WinHandle hTarget, int itemIndex, const wstring& itemText, BOOL itemChecked, const ProcParams& procParams) {}
342
350 virtual void onDataChanged(WinHandle hTarget, const wstring& newValue, const ProcParams& procParams) {}
351
352// virtual BOOL onDrawMeasureItem(LPMEASUREITEMSTRUCT dis, const ProcParams& procParams) { return FALSE; }
353// virtual BOOL onDrawItem(LPDRAWITEMSTRUCT dis, const ProcParams& procParams) { return FALSE; }
354
356 virtual void onMousePressed(WinHandle hWnd, int x, int y, int clickCount, BOOL shiftPressed, BOOL ctrlPressed) {}
357
359 virtual void onMouseReleased(WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed) {}
360
362 virtual void onMouseRightClicked(WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed) {}
363
365 virtual void onMouseMoved(WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed) {}
366
376 virtual BOOL onMouseWheel(WinHandle hWnd, int x, int y, int delta) { return FALSE; }
377
378 // Keyboard key event handlers (shiftPressed and ctrlPressed indicate modifier key state)
379 virtual void onArrowLeft(BOOL shiftPressed, BOOL ctrlPressed) {}
380 virtual void onArrowRight(BOOL shiftPressed, BOOL ctrlPressed) {}
381 virtual void onArrowUp(BOOL shiftPressed, BOOL ctrlPressed) {}
382 virtual void onArrowDown(BOOL shiftPressed, BOOL ctrlPressed) {}
383 virtual void onPageUp(BOOL shiftPressed, BOOL ctrlPressed) {}
384 virtual void onPageDown(BOOL shiftPressed, BOOL ctrlPressed) {}
385 virtual void onKeyHome(BOOL shiftPressed, BOOL ctrlPressed) {}
386 virtual void onKeyEnd(BOOL shiftPressed, BOOL ctrlPressed) {}
387 virtual void onKeyInsert(BOOL shiftPressed, BOOL ctrlPressed) {}
388 virtual void onKeyDelete(BOOL shiftPressed, BOOL ctrlPressed) {}
389 virtual void onKeyBackSpace(BOOL shiftPressed, BOOL ctrlPressed) {}
390 virtual void onKeyTyped(wchar_t ch, BOOL shiftPressed, BOOL ctrlPressed) {}
391 virtual void onKeyTab(BOOL shiftPressed, BOOL ctrlPressed) {}
392 virtual void onKeyEnter(BOOL shiftPressed, BOOL ctrlPressed) {}
393 virtual void onKeyF1(BOOL shiftPressed, BOOL ctrlPressed) {}
394 virtual void onKeyF2(BOOL shiftPressed, BOOL ctrlPressed) {}
395 virtual void onKeyF3(BOOL shiftPressed, BOOL ctrlPressed) {}
396 virtual void onKeyF4(BOOL shiftPressed, BOOL ctrlPressed) {}
397 virtual void onKeyF5(BOOL shiftPressed, BOOL ctrlPressed) {}
398 virtual void onKeyF6(BOOL shiftPressed, BOOL ctrlPressed) {}
399 virtual void onKeyF7(BOOL shiftPressed, BOOL ctrlPressed) {}
400 virtual void onKeyF8(BOOL shiftPressed, BOOL ctrlPressed) {}
401 virtual void onKeyF9(BOOL shiftPressed, BOOL ctrlPressed) {}
402 virtual void onKeyF10(BOOL shiftPressed, BOOL ctrlPressed) {}
403 virtual void onKeyF11(BOOL shiftPressed, BOOL ctrlPressed) {}
404 virtual void onKeyF12(BOOL shiftPressed, BOOL ctrlPressed) {}
405
407 virtual void onFocusGained() {}
408
410 virtual void onFocusLost() {}
411
417 virtual void onTimer(unsigned int timerId) {}
418
419 // Scrollbar functionality
420
429 virtual BOOL getScrollingInfo(__int64& scrollMin, __int64& scrollMax, __int64& pageSize) { return FALSE; }
430
436 virtual void setScrollbarTopOffset(__int64 firstVisibleRow) {}
437
445 void updateScrollbarTopOffset(__int64 firstVisibleRow);
446
447protected: // Listener management
448
455
462
469
476
483 void protectedFireDataChangedEvent(const wstring& oldValue, const wstring& newValue);
484
492 void protectedFireSelectionChangedEvent(long selectionIndex = -1, const wstring& selectionValue = L"", BOOL checked = FALSE);
493
500 void protectedFireActionEvent(long actionId = -1, const wstring& actionName = L"");
501
508};
HWND WinHandle
Definition Common.h:16
Definition EventListeners.h:46
Definition Common.h:21
virtual void onKeyF9(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:401
virtual BOOL getChildren(vector< Component * > &children)
Definition Component.h:310
virtual void onFocusGained()
Called when the component gains keyboard focus.
Definition Component.h:407
virtual void onTimer(unsigned int timerId)
Called on timer events.
Definition Component.h:417
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:376
Component * getTopLevelParent()
virtual void onKeyF6(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:398
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:429
virtual void onSelectionChanged(WinHandle hTarget, int itemIndex, const wstring &itemText, BOOL itemChecked, const ProcParams &procParams)
Called when the selection changes.
Definition Component.h:341
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.
int createComponent(Component *parent, Bounds rect, long nCmd=-1, BOOL isVisible=TRUE)
Creates the component's native window as a child of hParent.
virtual void onWindowMoved()
Called when the component's window is moved.
Definition Component.h:321
virtual void onKeyF1(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:393
virtual ~Component()
Virtual destructor.
virtual void onKeyF12(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:404
virtual void onArrowUp(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:381
BOOL getCustomFont(long &fontSize, BOOL &isBold, BOOL &isItalic, BOOL &isUnderlined, wstring &fontName)
virtual void onPaint(Graphics *g)
Called to paint the component's client area.
Definition Component.h:315
virtual void onKeyBackSpace(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:389
virtual void onArrowDown(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:382
virtual void windowCreated()=0
Abstract method called after the window has been created.
virtual void onKeyEnd(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:386
virtual void onKeyTab(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:391
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:365
virtual void onWindowResized()
Called when the component's window is resized.
Definition Component.h:318
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:390
BOOL isWindowCreated()
Returns whether the native window has been created.
virtual void onFocusLost()
Called when the component loses keyboard focus.
Definition Component.h:410
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:356
void setFocus()
virtual void onKeyF8(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:400
void reconfigureScrollBar()
Forces the component to recalculate the scrollbar info.
virtual BOOL getCreateWindowOptions(wstring &title, UINT &widownStyles, wstring &wndClassName, BOOL &isCustomWndProc)=0
Abstract method to get window creation options.
void repaint(Component *comp=NULL, BOOL repaintImmediately=FALSE)
Requests the component to repaint itself.
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:383
virtual void onArrowRight(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:380
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:436
Component * getParent()
virtual void onKeyDelete(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:388
virtual void onKeyHome(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:385
virtual void onAction(WinHandle hTarget, long actionId, const ProcParams &procParams)
Called when an action occurs on the component.
Definition Component.h:330
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:403
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:379
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:387
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:394
virtual void onPageDown(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:384
virtual void onKeyF4(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:396
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 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:362
virtual void onKeyF7(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:399
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:392
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:395
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:359
void setVisible(BOOL bShow=TRUE)
Shows or hides the component.
virtual void onKeyF5(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:397
virtual void onKeyF10(BOOL shiftPressed, BOOL ctrlPressed)
Definition Component.h:402
void setParent(Component *parent)
long getId()
Gets the unique ID assigned to this component.
void bringWindowToTop()
virtual void onDataChanged(WinHandle hTarget, const wstring &newValue, const ProcParams &procParams)
Called when data changes in the component.
Definition Component.h:350
virtual int getMinimumHeight()
Returns the minimum height the component can have.
Definition EventListeners.h:15
Definition Graphics.h:171
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