5#ifndef INCLUDE_FIFECHAN_FOCUSHANDLER_HPP_
6#define INCLUDE_FIFECHAN_FOCUSHANDLER_HPP_
13#include "fifechan/events/event.hpp"
33 class FIFEGUI_API FocusHandler
36 virtual ~FocusHandler() =
default;
39 FocusHandler(FocusHandler
const &) =
delete;
40 FocusHandler& operator=(FocusHandler
const &) =
delete;
41 FocusHandler(FocusHandler&&) =
delete;
42 FocusHandler& operator=(FocusHandler&&) =
delete;
125 if (mHandler !=
nullptr) {
126 mHandler->pushModal(focusOwner, mouseOwner);
132 if (mHandler !=
nullptr && !mReleased) {
135 mHandler->popModal();
138 if (!mWasPopped && !mReleased) {
143 "Warning: ModalScope destroyed without calling release() or popModal(). Did you forget "
144 "to call release()?\n");
148 ModalScope(ModalScope
const &) =
delete;
149 ModalScope& operator=(ModalScope
const &) =
delete;
150 ModalScope(ModalScope&&) =
delete;
151 ModalScope& operator=(ModalScope&&) =
delete;
165 FocusHandler* mHandler{
nullptr};
166 bool mReleased{
false};
167 bool mWasPopped{
false};
Base class for all GUI event objects.
Modal scope management (RAII guard).
ModalScope(FocusHandler *handler, Widget *focusOwner, Widget *mouseOwner=nullptr)
RAII helper that pushes a modal state on construction and pops it on destruction unless release() is ...
void release()
Release ownership so the modal is not popped during destruction.
std::vector< ModalState > mModalStack
Holds the modal stack for nested modal dialogs.
Widget * mFocusedWidget
Holds the focused widget.
virtual bool hasModalFocus() const
Checks if any modal state is active.
virtual Widget * getLastWidgetWithMouse()
Gets the last widget with the mouse.
ModalScope InputModalScope
Alias for ModalScope to clarify its purpose for input handling.
std::vector< Widget * > WidgetVector
Vector of Widget pointers.
WidgetVector mWidgets
Holds the widgets currently being handled by the focus handler.
Widget * mDraggedWidget
Holds the dragged widget.
virtual Widget * getFocusOwner() const
Gets the active input root widget for focus routing.
virtual void focusPrevious()
Focuses the previous widget added to a container.
virtual void widgetHidden(Widget *widget)
Informs the focus handler that a widget was hidden.
virtual void setLastWidgetWithMouse(Widget *lastWidgetWithMouse)
Sets the last widget with the mouse.
virtual void popModal() noexcept
Pops the current modal state from the stack.
virtual void focusNone()
Focuses nothing.
virtual Widget * getDraggedWidget()
Gets the widget being dragged.
Widget * mLastWidgetWithModalMouseInputFocus
Holds the last widget with modal mouse input focus.
virtual void setFocusedWidget(Widget *widget)
Sets the focused widget directly.
Widget * mLastWidgetPressed
Holds the last widget pressed.
virtual void add(Widget *widget)
Adds a widget to by handles by the focus handler.
virtual void setLastWidgetWithModalFocus(Widget *lastWidgetWithModalFocus)
Sets the last widget with modal focus.
virtual void pushModal(Widget *focusOwner, Widget *mouseOwner=nullptr)
Pushes a new modal state onto the stack.
virtual void setLastWidgetPressed(Widget *lastWidgetPressed)
Sets the last widget pressed.
virtual Widget * getLastWidgetWithModalMouseInputFocus()
Gets the last widget with modal mouse input focus.
virtual Widget * getLastWidgetWithModalFocus()
Gets the last widget with modal focus.
virtual void remove(Widget *widget)
Removes a widget from the focus handler.
virtual bool isFocused(Widget const *widget) const
Checks if a widget is focused.
virtual void distributeFocusGainedEvent(Event const &focusEvent)
Distributes a focus gained event.
virtual void tabPrevious()
Focuses the previous widget which allows tabbing in unless current focused Widget disallows tabbing o...
Widget * mLastWidgetWithModalFocus
Holds the last widget with modal focus.
virtual Widget * getMouseCaptureOwner() const
Gets the widget with modal mouse input focus.
virtual void clearModal()
Clears all modal states from the stack.
virtual void tabNext()
Focuses the next widget which allows tabbing in unless the current focused Widget disallows tabbing o...
virtual void distributeFocusLostEvent(Event const &focusEvent)
Distributes a focus lost event.
virtual void focusNext()
Focuses the next widget added to a container.
WidgetVector::iterator WidgetIterator
Iterator for WidgetVector.
virtual void releaseFocus(Widget *widget)
Releases focus for the specified widget if it is currently focused.
virtual void setDraggedWidget(Widget *draggedWidget)
Sets the widget being dragged.
virtual void requestFocus(Widget *widget)
Requests focus for a widget.
virtual Widget * getLastWidgetPressed()
Gets the last widget pressed.
Widget * mLastWidgetWithMouse
Holds the last widget with the mouse.
virtual void setLastWidgetWithModalMouseInputFocus(Widget *lastWidgetWithModalMouseInputFocus)
Sets the last widget with modal mouse input focus.
virtual Widget * getFocused() const
Gets the widget with focus.
Used replacement tokens by configure_file():
Represents a single modal state level with focus and mouse owners.
Widget * focusOwner
Widget with modal focus at this level.
Widget * mouseOwner
Widget with modal mouse input at this level.