SavvyUI C++ UI Library
Loading...
Searching...
No Matches
ButtonMenu Class Reference

A scrollable, interactive list of selectable menu items with optional styling as buttons or links. More...

#include <ButtonMenu.h>

Inheritance diagram for ButtonMenu:
Component

Public Member Functions

 ButtonMenu ()
 Constructor.
virtual ~ButtonMenu ()
 Destructor.
void enableButtonStyle ()
 Enables button-style rendering of items.
void enableLinkStyle ()
 Enables link-style rendering of items.
void setPinnable (BOOL isPinnable=TRUE)
 Enables pinnable button state.
void clear ()
 Removes all items from the menu.
void setTitle (const wstring &title)
 Sets the menu title.
void setImagePosition (const Direction &imagePosition)
 Sets the position of the image displayed on the button.
long addItem (const wstring &itemText, const wstring &itemId=L"", const IconSource &iconSource=IconSource())
 Adds a new item to the menu.
void enableItem (const wstring &itemText, BOOL enabled=TRUE)
 enables/disabled button.
long getItemCount ()
 Returns the number of items in the menu.
long getSelectedItem ()
 Gets the index of the currently selected item.
void onPaint (Graphics *g)
 Paints the component.
void onWindowResized ()
 Called when the window is resized.
BOOL getScrollingInfo (__int64 &scrollMin, __int64 &scrollMax, __int64 &pageSize)
 Retrieves information about scrolling limits and page size.
void setScrollbarTopOffset (__int64 firstVisibleRow)
 Sets the vertical scrollbar position by row offset.
void addSelectionChangedListener (SelectionChangeListener *l)
 Adds a listener to be notified when the selection changes.
Keyboard Navigation
void onArrowUp (BOOL shiftPressed, BOOL ctrlPressed)
void onArrowDown (BOOL shiftPressed, BOOL ctrlPressed)
void onPageUp (BOOL shiftPressed, BOOL ctrlPressed)
void onPageDown (BOOL shiftPressed, BOOL ctrlPressed)
void onKeyHome (BOOL shiftPressed, BOOL ctrlPressed)
void onKeyEnd (BOOL shiftPressed, BOOL ctrlPressed)
Mouse Interaction
void onMousePressed (WinHandle hWnd, int x, int y, int clickCount, BOOL shiftPressed, BOOL ctrlPressed)
 Called when the mouse is pressed within the component.
void onMouseReleased (WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed)
 Called when the mouse button is released within the component.
void onMouseRightClicked (WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed)
 Called when the right mouse button is clicked within the component.
void onMouseMoved (WinHandle hWnd, int x, int y, BOOL shiftPressed, BOOL ctrlPressed)
 Called when the mouse is moved within the component.
BOOL onMouseWheel (WinHandle hWnd, int x, int y, int delta)
 Called when the mouse wheel is used over the component.
Public Member Functions inherited from Component
 Component ()
 Constructs a new Component instance.
virtual ~Component ()
 Virtual destructor.
long getId ()
 Gets the unique ID assigned to this component.
void setParent (Component *parent)
ComponentgetParent ()
wstring getComponentType ()
 Gets the component type string.
BOOL isWindowCreated ()
 Returns whether the native window has been created.
WinHandle getWindowHandle ()
 Returns the native WinHandle for this component.
int createComponent (WinHandle hParent, Bounds rect, long nCmd=-1, BOOL isVisible=TRUE)
 Creates the component's native window as a child of hParent.
void setFont (long fontSize, BOOL isBold=FALSE, BOOL isItalic=FALSE, BOOL isUnderlined=FALSE, const wstring &fontName=L"Arial")
 Sets the font for the component.
void showBorder (BOOL bShow=TRUE)
void setEnabled (BOOL bEnable=TRUE)
 Enables or disables the component.
void setVisible (BOOL bShow=TRUE)
 Shows or hides the component.
void GetClientRect (Bounds &rect)
void GetWindowRect (Bounds &rect)
void moveWindow (long x, long y, long width, long height, BOOL bRedraw=TRUE)
 Moves and resizes the component window.
void reconfigureScrollBar ()
 Forces the component to recalculate the scrollbar info.
void setMouseWheelDelta (int delta)
 Sets the accumulated mouse wheel delta.
int getMouseWheelDelta ()
 Gets the current mouse wheel delta.
virtual int getMinimumHeight ()
 Returns the minimum height the component can have.
virtual int getPreferredHeight ()
 Returns the preferred height of the component.
void repaint (WinHandle hWnd=NULL)
 Requests the component to repaint itself.
void clearQueuedPaintRequest ()
 clears the queued paint request. This function should only be called internally from the library.
virtual void onWindowMoved ()
 Called when the component's window is moved.
virtual void onAction (WinHandle hTarget, long actionId, const ProcParams &procParams)
 Called when an action occurs on the component.
virtual void onSelectionChanged (WinHandle hTarget, int itemIndex, const wstring &itemText, BOOL itemChecked, const ProcParams &procParams)
 Called when the selection changes.
virtual void onDataChanged (WinHandle hTarget, const wstring &newValue, const ProcParams &procParams)
 Called when data changes in the component.
virtual BOOL onHorzScroll (WinHandle hTarget, const ProcParams &procParams)
 Called on horizontal scroll events.
virtual BOOL onDrawMeasureItem (LPMEASUREITEMSTRUCT dis, const ProcParams &procParams)
 Called when measuring an item for owner-draw controls.
virtual BOOL onDrawItem (LPDRAWITEMSTRUCT dis, const ProcParams &procParams)
 Called when drawing an item for owner-draw controls.
virtual void onArrowLeft (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onArrowRight (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyInsert (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyDelete (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyBackSpace (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyTyped (wchar_t ch, BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyTab (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyEnter (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF1 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF2 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF3 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF4 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF5 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF6 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF7 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF8 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF9 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF10 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF11 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onKeyF12 (BOOL shiftPressed, BOOL ctrlPressed)
virtual void onFocusGained ()
 Called when the component gains keyboard focus.
virtual void onFocusLost ()
 Called when the component loses keyboard focus.
virtual void onTimer (unsigned int timerId)
 Called on timer events.
void updateScrollbarTopOffset (__int64 firstVisibleRow)
 Updates the scrollbar's top offset based on the current first visible row.

Protected Member Functions

BOOL getCreateWindowOptions (wstring &title, UINT &windowStyles, wstring &wndClassName, BOOL &isCustomWndProc)
 Retrieves window creation options.
void windowCreated ()
 Called after the window has been created.
Protected Member Functions inherited from Component
long getActionId ()
 Returns the component's action command ID.
void doNotSubclass ()
 Marks this component's native window to avoid subclassing.
void startTimer (unsigned int timerId, unsigned int milliseconds)
 Starts a timer with the given ID and interval.
void stopTimer (unsigned int timerId)
 Stops the timer identified by timerId.
void protectedAddDataChangedListener (DataChangeListener *l)
 Adds a data change listener.
void protectedAddSelectionChangedListener (SelectionChangeListener *l)
 Adds a selection change listener.
void protectedAddActionListener (ActionListener *l)
 Adds an action listener.
void protectedAddItemDoubleClickedListener (RowDoubleClickListener *l)
 Adds a row double-click listener.
void protectedFireDataChangedEvent (const wstring &oldValue, const wstring &newValue)
 Fires a data changed event to registered listeners.
void protectedFireSelectionChangedEvent (long selectionIndex=-1, const wstring &selectionValue=L"", BOOL checked=FALSE)
 Fires a selection changed event to registered listeners.
void protectedFireActionEvent (long actionId=-1, const wstring &actionName=L"")
 Fires an action event to registered listeners.
void protectedFireItemDoubleClickedEvent (__int64 rowIndex)
 Fires a row double-click event to registered listeners.

Additional Inherited Members

Protected Attributes inherited from Component
WinHandle _hWnd
 Handle to the native window associated with this component.
wstring _componentType
 String representing the component type (e.g., "Button", "ComboBox").
BOOL _showBorder

Detailed Description

A scrollable, interactive list of selectable menu items with optional styling as buttons or links.

The ButtonMenu class is a GUI component that displays a list of selectable items, supports keyboard and mouse navigation, and notifies listeners when the selection changes. It is derived from the Component base class.

Constructor & Destructor Documentation

◆ ButtonMenu()

ButtonMenu::ButtonMenu ( )

Constructor.

◆ ~ButtonMenu()

virtual ButtonMenu::~ButtonMenu ( )
virtual

Destructor.

Member Function Documentation

◆ addItem()

long ButtonMenu::addItem ( const wstring & itemText,
const wstring & itemId = L"",
const IconSource & iconSource = IconSource() )

Adds a new item to the menu.

Parameters
itemTextDisplay text of the item.
itemIdOptional identifier string.
Returns
Index of the newly added item.

◆ addSelectionChangedListener()

void ButtonMenu::addSelectionChangedListener ( SelectionChangeListener * l)

Adds a listener to be notified when the selection changes.

Parameters
lPointer to a SelectionChangeListener.

◆ clear()

void ButtonMenu::clear ( )

Removes all items from the menu.

◆ enableButtonStyle()

void ButtonMenu::enableButtonStyle ( )

Enables button-style rendering of items.

◆ enableItem()

void ButtonMenu::enableItem ( const wstring & itemText,
BOOL enabled = TRUE )

enables/disabled button.

Parameters
itemTexttext of the item.
enabledTRUE to enable, FALSE to disable the item.

◆ enableLinkStyle()

void ButtonMenu::enableLinkStyle ( )

Enables link-style rendering of items.

◆ getCreateWindowOptions()

BOOL ButtonMenu::getCreateWindowOptions ( wstring & title,
UINT & windowStyles,
wstring & wndClassName,
BOOL & isCustomWndProc )
protectedvirtual

Retrieves window creation options.

Parameters
[out]titleThe window title.
[out]windowStylesThe style flags for the window.
[out]wndClassNameThe window class name.
[out]isCustomWndProcIndicates whether a custom window procedure is used.
Returns
TRUE if the options were set successfully.

Implements Component.

◆ getItemCount()

long ButtonMenu::getItemCount ( )

Returns the number of items in the menu.

◆ getScrollingInfo()

BOOL ButtonMenu::getScrollingInfo ( __int64 & scrollMin,
__int64 & scrollMax,
__int64 & pageSize )
virtual

Retrieves information about scrolling limits and page size.

Parameters
[out]scrollMinMinimum scroll position.
[out]scrollMaxMaximum scroll position.
[out]pageSizePage size in scroll units.
Returns
TRUE if successful.

Reimplemented from Component.

◆ getSelectedItem()

long ButtonMenu::getSelectedItem ( )

Gets the index of the currently selected item.

◆ onArrowDown()

void ButtonMenu::onArrowDown ( BOOL shiftPressed,
BOOL ctrlPressed )
virtual

Reimplemented from Component.

◆ onArrowUp()

void ButtonMenu::onArrowUp ( BOOL shiftPressed,
BOOL ctrlPressed )
virtual

Reimplemented from Component.

◆ onKeyEnd()

void ButtonMenu::onKeyEnd ( BOOL shiftPressed,
BOOL ctrlPressed )
virtual

Reimplemented from Component.

◆ onKeyHome()

void ButtonMenu::onKeyHome ( BOOL shiftPressed,
BOOL ctrlPressed )
virtual

Reimplemented from Component.

◆ onMouseMoved()

void ButtonMenu::onMouseMoved ( WinHandle hWnd,
int x,
int y,
BOOL shiftPressed,
BOOL ctrlPressed )
virtual

Called when the mouse is moved within the component.

Reimplemented from Component.

◆ onMousePressed()

void ButtonMenu::onMousePressed ( WinHandle hWnd,
int x,
int y,
int clickCount,
BOOL shiftPressed,
BOOL ctrlPressed )
virtual

Called when the mouse is pressed within the component.

Reimplemented from Component.

◆ onMouseReleased()

void ButtonMenu::onMouseReleased ( WinHandle hWnd,
int x,
int y,
BOOL shiftPressed,
BOOL ctrlPressed )
virtual

Called when the mouse button is released within the component.

Reimplemented from Component.

◆ onMouseRightClicked()

void ButtonMenu::onMouseRightClicked ( WinHandle hWnd,
int x,
int y,
BOOL shiftPressed,
BOOL ctrlPressed )
virtual

Called when the right mouse button is clicked within the component.

Reimplemented from Component.

◆ onMouseWheel()

BOOL ButtonMenu::onMouseWheel ( WinHandle hWnd,
int x,
int y,
int delta )
virtual

Called when the mouse wheel is used over the component.

Parameters
hWndHandle to the window receiving the event.
xX coordinate of the mouse.
yY coordinate of the mouse.
deltaMouse wheel delta.
Returns
TRUE if the event was handled, FALSE otherwise.

Reimplemented from Component.

◆ onPageDown()

void ButtonMenu::onPageDown ( BOOL shiftPressed,
BOOL ctrlPressed )
virtual

Reimplemented from Component.

◆ onPageUp()

void ButtonMenu::onPageUp ( BOOL shiftPressed,
BOOL ctrlPressed )
virtual

Reimplemented from Component.

◆ onPaint()

void ButtonMenu::onPaint ( Graphics * g)
virtual

Paints the component.

Parameters
hDCHandle to the device context.

Reimplemented from Component.

◆ onWindowResized()

void ButtonMenu::onWindowResized ( )
virtual

Called when the window is resized.

Reimplemented from Component.

◆ setImagePosition()

void ButtonMenu::setImagePosition ( const Direction & imagePosition)

Sets the position of the image displayed on the button.

Parameters
imagePositionThe position of the image displayed on the button (e.g. left|top|right|bottom).

◆ setPinnable()

void ButtonMenu::setPinnable ( BOOL isPinnable = TRUE)

Enables pinnable button state.

◆ setScrollbarTopOffset()

void ButtonMenu::setScrollbarTopOffset ( __int64 firstVisibleRow)
virtual

Sets the vertical scrollbar position by row offset.

Parameters
firstVisibleRowIndex of the top-most visible row.

Reimplemented from Component.

◆ setTitle()

void ButtonMenu::setTitle ( const wstring & title)

Sets the menu title.

Parameters
titleThe new title.

◆ windowCreated()

void ButtonMenu::windowCreated ( )
protectedvirtual

Called after the window has been created.

Implements Component.


The documentation for this class was generated from the following file: