26 #define YUILogComponent "ui" 31 #include "YShortcutManager.h" 32 #include "YPushButton.h" 34 #include "YEventFilter.h" 36 #define VERBOSE_DIALOGS 0 37 #define VERBOSE_DISCARDED_EVENTS 0 38 #define VERBOSE_EVENTS 0 40 typedef std::list<YEventFilter *> YEventFilterList;
48 : dialogType( dialogType )
49 , colorMode( colorMode )
50 , shortcutCheckPostponed(
false )
57 YDialogColorMode colorMode;
58 bool shortcutCheckPostponed;
62 YEventFilterList eventFilterList;
81 if ( event && event->
widget() )
112 if ( event && event->
widget() )
136 YUI_CHECK_NEW( priv );
141 yuiDebug() <<
"New " <<
this << endl;
152 yuiDebug() <<
"Destroying " <<
this << endl;
160 if ( priv->lastEvent )
180 yuiError() <<
"Not top of dialog stack: " <<
this << endl;
210 yuiError() <<
"Dialog stack empty, but dialog existing: " <<
this << endl;
221 while ( ! priv->eventFilterList.empty() )
226 yuiDebug() <<
"Deleting event filter " << hex << filter << dec << endl;
236 YUI_CHECK_WIDGET(
this );
257 return priv->dialogType;
264 switch ( priv->dialogType )
266 case YMainDialog:
return true;
267 case YWizardDialog:
return true;
268 case YPopupDialog:
return false;
282 return priv->colorMode;
289 priv->shortcutCheckPostponed =
true;
296 return priv->shortcutCheckPostponed;
303 if ( priv->shortcutCheckPostponed && ! force )
305 yuiDebug() <<
"Shortcut check postponed" << endl;
313 priv->shortcutCheckPostponed =
false;
321 return priv->defaultButton;
328 if ( newDefaultButton && priv->defaultButton )
330 yuiError() <<
"Too many `opt(`default) PushButtons: [" 331 << newDefaultButton->
label()
335 priv->defaultButton = newDefaultButton;
343 yuiDebug() <<
"Setting initial size for " <<
this << endl;
354 yuiDebug() <<
"Recalculating layout for " <<
this << endl;
366 if ( timeout_millisec < 0 )
367 timeout_millisec = 0;
374 yuiError() <<
"Performing missing keyboard shortcut check now in " 394 priv->lastEvent = event;
414 priv->lastEvent = event;
433 if ( widgetEvent && widgetEvent->
widget() )
463 yuiDebug() <<
"Discarding event from widget from foreign dialog" << endl;
465 #if VERBOSE_DISCARDED_EVENTS 466 yuiDebug() <<
"Expected: " <<
this 470 yuiDebug() <<
"Event widget: " << widgetEvent->
widget() << endl;
471 yuiDebug() <<
"From:" << endl;
473 yuiDebug() <<
"Current dialog:" << endl;
492 if ( event == priv->lastEvent )
500 yuiDebug() <<
"Deleting " <<
event << endl;
506 yuiError() <<
"Attempt to delete invalid event " <<
event << endl;
556 YUI_CHECK_WIDGET( targetDialog );
564 if ( dialog == targetDialog )
584 YUI_CHECK_PTR( eventFilter );
586 if ( find( priv->eventFilterList.begin(), priv->eventFilterList.end(),
587 eventFilter ) != priv->eventFilterList.end() )
589 yuiError() <<
"event filter " << std::hex << eventFilter << std::dec
590 <<
" already added to " <<
this 596 yuiDebug() <<
"Adding event filter " << hex << eventFilter << dec << endl;
598 priv->eventFilterList.push_back( eventFilter );
606 YUI_CHECK_PTR( eventFilter );
609 yuiDebug() <<
"Removing event filter " << hex << eventFilter << dec << endl;
611 priv->eventFilterList.remove( eventFilter );
618 YEventFilterList::const_iterator it = priv->eventFilterList.begin();
620 while ( it != priv->eventFilterList.end() && event )
622 YEvent * oldEvent = event;
623 event = (*it)->filter( event );
625 if ( oldEvent != event )
void deleteEvent(YEvent *event)
Delete an event.
static bool showHelpText(YWidget *widget)
Show the help text for the specified widget.
void deleteEventFilters()
Delete all (remaining) event filters.
YEventFilter(YDialog *dialog=0)
Constructor.
virtual void setDefaultButton(YPushButton *defaultButton)
Set this dialog's default button (the button that is activated when the user hits [Return] anywhere i...
YDialogType
Type of dialog: Main / Popup / Wizard.
bool isValid() const
Check if this event is valid.
Helper class to manage keyboard shortcuts within one dialog and resolve keyboard shortcut conflicts...
void postponeShortcutCheck()
From now on, postpone keyboard shortcut checks - i.e.
static bool deleteTopmostDialog(bool doThrow=true)
Delete the topmost dialog.
Abstract base class to filter events.
Abstract base class for events to be returned upon UI::UserInput() and related functions.
YEvent * filterInvalidEvents(YEvent *event)
Filter out invalid events: Return 0 if the event does not belong to this dialog or the unchanged even...
bool isTopmostDialog() const
Return 'true' if this dialog is the topmost dialog.
void checkShortcuts(bool force=false)
Checks the keyboard shortcuts of widgets in this dialog unless shortcut checks are postponed or 'forc...
void removeEventFilter(YEventFilter *eventFilter)
Remove an event filter.
YDialogColorMode colorMode() const
Return this dialog's color mode.
YDialog * dialog() const
Return the dialog this event filter belongs to.
virtual void openInternal()=0
Internal open() method.
static void deleteAllDialogs()
Delete all open dialogs.
bool isOpen() const
Return 'true' if open() has already been called for this dialog.
virtual YEvent * pollEventInternal()=0
Check if a user event is pending.
static YDialog * currentDialog(bool doThrow=true)
Return the current (topmost) dialog.
bool shortcutCheckPostponed() const
Return whether or not shortcut checking is currently postponed.
YEvent * callEventFilters(YEvent *event)
Call the installed event filters.
void checkShortcuts(bool autoResolve=true)
Check the keyboard shortcuts of all children of this dialog (not for sub-dialogs!).
void open()
Open a newly created dialog: Finalize it and make it visible on the screen.
void addEventFilter(YEventFilter *eventFilter)
Add an event filter.
static std::stack< YDialog * > _dialogStack
Stack holding all currently existing dialogs.
YDialog(YDialogType dialogType, YDialogColorMode colorMode=YDialogNormalColor)
Constructor.
void setInitialSize()
Set the initial dialog size, depending on dialogType: YMainDialog dialogs get the UI's "default main ...
static void deleteTo(YDialog *dialog)
Delete all dialogs from the topmost to the one specified.
static bool showRelNotesText()
Show the release notes.
YDialogType dialogType() const
Return this dialog's type (YMainDialog / YPopupDialog /YWizardDialog).
virtual void activate()=0
Activate this dialog: Make sure that it is shown as the topmost dialog of this application and that i...
static int openDialogsCount()
Returns the number of currently open dialogs (from 1 on), i.e., the depth of the dialog stack...
virtual ~YDialog()
Destructor.
void recalcLayout()
Recalculate the layout of the dialog and of all its children after children have been added or remove...
YPushButton * defaultButton() const
Return this dialog's default button: The button that is activated when the user hits [Return] anywher...
A window in the desktop environment.
virtual YEvent * waitForEventInternal(int timeout_millisec)=0
Wait for a user event.
YEvent * pollEvent()
Check if a user event is pending.
virtual YWidget * widget() const
Returns the widget that caused this event or 0 if there is none.
bool destroy(bool doThrow=true)
Close and delete this dialog (and all its children) if it is the topmost dialog.
YEvent * waitForEvent(int timeout_millisec=0)
Wait for a user event.
bool isMainDialog()
Return 'true' if this dialog is a dialog of main dialog size: YMainDialog or YWizardDialog.