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 )
53 , multiPassLayout(
false )
59 YDialogColorMode colorMode;
60 bool shortcutCheckPostponed;
66 YEventFilterList eventFilterList;
85 if ( event && event->
widget() )
116 if ( event && event->
widget() )
140 YUI_CHECK_NEW( priv );
145 yuiDebug() <<
"New " <<
this << endl;
156 yuiDebug() <<
"Destroying " <<
this << endl;
164 if ( priv->lastEvent )
184 yuiError() <<
"Not top of dialog stack: " <<
this << endl;
214 yuiError() <<
"Dialog stack empty, but dialog existing: " <<
this << endl;
225 while ( ! priv->eventFilterList.empty() )
230 yuiDebug() <<
"Deleting event filter " << hex << filter << dec << endl;
240 YUI_CHECK_WIDGET(
this );
261 return priv->dialogType;
268 switch ( priv->dialogType )
270 case YMainDialog:
return true;
271 case YWizardDialog:
return true;
272 case YPopupDialog:
return false;
286 return priv->colorMode;
293 priv->shortcutCheckPostponed =
true;
300 return priv->shortcutCheckPostponed;
307 if ( priv->shortcutCheckPostponed && ! force )
309 yuiDebug() <<
"Shortcut check postponed" << endl;
317 priv->shortcutCheckPostponed =
false;
325 return priv->defaultButton;
332 if ( newDefaultButton && priv->defaultButton )
334 yuiError() <<
"Too many `opt(`default) PushButtons: ["
335 << newDefaultButton->
label()
339 priv->defaultButton = newDefaultButton;
347 yuiDebug() <<
"Setting initial size for " <<
this << endl;
358 yuiDebug() <<
"Recalculating layout for " <<
this << endl;
366 priv->layoutPass = 1;
369 if ( priv->multiPassLayout )
371 priv->layoutPass = 2;
375 priv->layoutPass = 0;
382 return priv->layoutPass;
392 if ( timeout_millisec < 0 )
393 timeout_millisec = 0;
400 yuiError() <<
"Performing missing keyboard shortcut check now in "
420 priv->lastEvent = event;
440 priv->lastEvent = event;
459 if ( widgetEvent && widgetEvent->
widget() )
489 yuiDebug() <<
"Discarding event from widget from foreign dialog" << endl;
491 #if VERBOSE_DISCARDED_EVENTS
492 yuiDebug() <<
"Expected: " <<
this
496 yuiDebug() <<
"Event widget: " << widgetEvent->
widget() << endl;
497 yuiDebug() <<
"From:" << endl;
499 yuiDebug() <<
"Current dialog:" << endl;
518 if ( event == priv->lastEvent )
526 yuiDebug() <<
"Deleting " <<
event << endl;
532 yuiError() <<
"Attempt to delete invalid event " <<
event << endl;
582 YUI_CHECK_WIDGET( targetDialog );
590 if ( dialog == targetDialog )
610 YUI_CHECK_PTR( eventFilter );
612 if ( find( priv->eventFilterList.begin(), priv->eventFilterList.end(),
613 eventFilter ) != priv->eventFilterList.end() )
615 yuiError() <<
"event filter " << std::hex << eventFilter << std::dec
616 <<
" already added to " <<
this
622 yuiDebug() <<
"Adding event filter " << hex << eventFilter << dec << endl;
624 priv->eventFilterList.push_back( eventFilter );
632 YUI_CHECK_PTR( eventFilter );
635 yuiDebug() <<
"Removing event filter " << hex << eventFilter << dec << endl;
637 priv->eventFilterList.remove( eventFilter );
644 YEventFilterList::const_iterator it = priv->eventFilterList.begin();
646 while ( it != priv->eventFilterList.end() && event )
648 YEvent * oldEvent = event;
649 event = (*it)->filter( event );
651 if ( oldEvent != event )
664 if ( ! priv->multiPassLayout )
665 yuiDebug() <<
"Multiple layout passes requested" << endl;
667 priv->multiPassLayout =
true;
YDialogType
Type of dialog: Main / Popup / Wizard.
A window in the desktop environment.
void open()
Open a newly created dialog: Finalize it and make it visible on the screen.
virtual void setDefaultButton(YPushButton *defaultButton)
Set this dialog's default button (the button that is activated when the user hits [Return] anywhere i...
void checkShortcuts(bool force=false)
Checks the keyboard shortcuts of widgets in this dialog unless shortcut checks are postponed or 'forc...
static bool showRelNotesText()
Show the release notes.
virtual YEvent * pollEventInternal()=0
Check if a user event is pending.
virtual void activate()=0
Activate this dialog: Make sure that it is shown as the topmost dialog of this application and that i...
static YDialog * currentDialog(bool doThrow=true)
Return the current (topmost) dialog.
static std::stack< YDialog * > _dialogStack
Stack holding all currently existing dialogs.
void deleteEventFilters()
Delete all (remaining) event filters.
static int openDialogsCount()
Returns the number of currently open dialogs (from 1 on), i.e., the depth of the dialog stack.
bool destroy(bool doThrow=true)
Close and delete this dialog (and all its children) if it is the topmost dialog.
YEvent * filterInvalidEvents(YEvent *event)
Filter out invalid events: Return 0 if the event does not belong to this dialog or the unchanged even...
YDialogType dialogType() const
Return this dialog's type (YMainDialog / YPopupDialog /YWizardDialog).
void deleteEvent(YEvent *event)
Delete an event.
YEvent * waitForEvent(int timeout_millisec=0)
Wait for a user event.
bool isOpen() const
Return 'true' if open() has already been called for this dialog.
int layoutPass() const
Return the number of the current layout pass: 0: No layout going on right now 1: First pass 2: Second...
static void deleteAllDialogs()
Delete all open dialogs.
static bool showHelpText(YWidget *widget)
Show the help text for the specified widget.
YEvent * pollEvent()
Check if a user event is pending.
virtual ~YDialog()
Destructor.
void postponeShortcutCheck()
From now on, postpone keyboard shortcut checks - i.e.
void setInitialSize()
Set the initial dialog size, depending on dialogType: YMainDialog dialogs get the UI's "default main ...
static bool deleteTopmostDialog(bool doThrow=true)
Delete the topmost dialog.
static void deleteTo(YDialog *dialog)
Delete all dialogs from the topmost to the one specified.
void addEventFilter(YEventFilter *eventFilter)
Add an event filter.
bool shortcutCheckPostponed() const
Return whether or not shortcut checking is currently postponed.
YEvent * callEventFilters(YEvent *event)
Call the installed event filters.
bool isTopmostDialog() const
Return 'true' if this dialog is the topmost dialog.
void doLayout()
Calculate the layout and set the size of the dialog and all widgets.
void removeEventFilter(YEventFilter *eventFilter)
Remove an event filter.
virtual void openInternal()=0
Internal open() method.
bool isMainDialog()
Return 'true' if this dialog is a dialog of main dialog size: YMainDialog or YWizardDialog.
YPushButton * defaultButton() const
Return this dialog's default button: The button that is activated when the user hits [Return] anywher...
void recalcLayout()
Recalculate the layout of the dialog and of all its children after children have been added or remove...
void requestMultiPassLayout()
Request multiple passes of the layout engine.
YDialogColorMode colorMode() const
Return this dialog's color mode.
YDialog(YDialogType dialogType, YDialogColorMode colorMode=YDialogNormalColor)
Constructor.
virtual YEvent * waitForEventInternal(int timeout_millisec)=0
Wait for a user event.
Abstract base class to filter events.
YEventFilter(YDialog *dialog=0)
Constructor.
YDialog * dialog() const
Return the dialog this event filter belongs to.
Abstract base class for events to be returned upon UI::UserInput() and related functions.
virtual YWidget * widget() const
Returns the widget that caused this event or 0 if there is none.
bool isValid() const
Check if this event is valid.
Helper class to manage keyboard shortcuts within one dialog and resolve keyboard shortcut conflicts.
void checkShortcuts(bool autoResolve=true)
Check the keyboard shortcuts of all children of this dialog (not for sub-dialogs!).