29 #define YUILogComponent "ui" 34 #include "YShortcutManager.h" 35 #include "YPushButton.h" 36 #include "YButtonBox.h" 39 #include "YApplication.h" 40 #include "YWidgetFactory.h" 41 #include "YOptionalWidgetFactory.h" 42 #include "YLayoutBox.h" 43 #include "YRichText.h" 44 #include "YAlignment.h" 45 #include "YUIException.h" 46 #include "YEventFilter.h" 47 #include "YWidgetID.h" 51 #include <sys/types.h> 55 #define VERBOSE_DIALOGS 0 56 #define VERBOSE_DISCARDED_EVENTS 0 57 #define VERBOSE_EVENTS 0 60 typedef std::list<YEventFilter *> YEventFilterList;
66 : dialogType( dialogType )
67 , colorMode( colorMode )
68 , shortcutCheckPostponed(
false )
75 YDialogColorMode colorMode;
76 bool shortcutCheckPostponed;
80 YEventFilterList eventFilterList;
99 if ( event && event->
widget() )
130 if ( event && event->
widget() )
154 YUI_CHECK_NEW( priv );
159 yuiDebug() <<
"New " <<
this << std::endl;
170 yuiDebug() <<
"Destroying " <<
this << std::endl;
178 if ( priv->lastEvent )
198 yuiError() <<
"Not top of dialog stack: " <<
this << std::endl;
228 yuiError() <<
"Dialog stack empty, but dialog existing: " <<
this << std::endl;
239 while ( ! priv->eventFilterList.empty() )
244 yuiDebug() <<
"Deleting event filter " << std::std::hex << filter << std::dec << std::endl;
254 YUI_CHECK_WIDGET(
this );
275 return priv->dialogType;
282 switch ( priv->dialogType )
284 case YMainDialog:
return true;
285 case YWizardDialog:
return true;
286 case YPopupDialog:
return false;
300 return priv->colorMode;
307 priv->shortcutCheckPostponed =
true;
314 return priv->shortcutCheckPostponed;
321 if ( priv->shortcutCheckPostponed && ! force )
323 yuiDebug() <<
"Shortcut check postponed" << std::endl;
331 priv->shortcutCheckPostponed =
false;
339 return priv->defaultButton;
346 if ( newDefaultButton && priv->defaultButton )
348 yuiError() <<
"Too many `opt(`default) PushButtons: [" 349 << newDefaultButton->
label()
353 priv->defaultButton = newDefaultButton;
361 yuiDebug() <<
"Setting initial size for " <<
this << std::endl;
372 yuiDebug() <<
"Recalculating layout for " <<
this << std::endl;
384 if ( timeout_millisec < 0 )
385 timeout_millisec = 0;
392 yuiError() <<
"Performing missing keyboard shortcut check now in " 393 <<
this << std::endl;
412 priv->lastEvent = event;
432 priv->lastEvent = event;
451 if ( widgetEvent && widgetEvent->
widget() )
481 yuiDebug() <<
"Discarding event from widget from foreign dialog" << std::endl;
483 #if VERBOSE_DISCARDED_EVENTS 484 yuiDebug() <<
"Expected: " <<
this 488 yuiDebug() <<
"Event widget: " << widgetEvent->
widget() << std::endl;
489 yuiDebug() <<
"From:" << std::endl;
491 yuiDebug() <<
"Current dialog:" << std::endl;
510 if ( event == priv->lastEvent )
518 yuiDebug() <<
"Deleting " <<
event << std::endl;
524 yuiError() <<
"Attempt to delete invalid event " <<
event << std::endl;
574 YUI_CHECK_WIDGET( targetDialog );
582 if ( dialog == targetDialog )
602 YUI_CHECK_PTR( eventFilter );
604 if ( find( priv->eventFilterList.begin(), priv->eventFilterList.end(),
605 eventFilter ) != priv->eventFilterList.end() )
607 yuiError() <<
"event filter " << std::hex << eventFilter << std::dec
608 <<
" already added to " <<
this 614 yuiDebug() <<
"Adding event filter " << std::hex << eventFilter << std::dec << std::endl;
616 priv->eventFilterList.push_back( eventFilter );
624 YUI_CHECK_PTR( eventFilter );
627 yuiDebug() <<
"Removing event filter " << std::hex << eventFilter << std::dec << std::endl;
629 priv->eventFilterList.remove( eventFilter );
636 YEventFilterList::const_iterator it = priv->eventFilterList.begin();
638 while ( it != priv->eventFilterList.end() && event )
640 YEvent * oldEvent = event;
641 event = (*it)->filter( event );
643 if ( oldEvent != event )
659 unsigned int dialogWidth = 45;
660 unsigned int dialogHeight = 15;
665 dialogWidth = (
unsigned int) ( (
float) dialog->
preferredWidth() * 0.8 );
666 dialogHeight = (
unsigned int) ( (
float) dialog->
preferredHeight() * 0.8 );
670 if ( dialogWidth > 80 || dialogHeight > 25 )
684 okButton->
setRole( YOKButton );
694 YUI_CAUGHT( exception );
708 yuiDebug() <<
"Found help text for " << widget << std::endl;
712 widget = widget->
parent();
715 if ( ! helpText.empty() )
717 yuiMilestone() <<
"Showing help text" << std::endl;
720 yuiMilestone() <<
"Help dialog closed" << std::endl;
724 yuiWarning() <<
"No help text" << std::endl;
727 return ! helpText.empty();
733 yuiMilestone() <<
"Showing Release Notes" << std::endl;
737 unsigned int dialogWidth = 45;
738 unsigned int dialogHeight = 15;
743 dialogWidth = (
unsigned int) ( (
float) dialog->
preferredWidth() * 0.8 );
744 dialogHeight = (
unsigned int) ( (
float) dialog->
preferredHeight() * 0.8 );
748 if ( dialogWidth > 80 || dialogHeight > 25 )
757 if ( relnotes.size() == 0)
761 std::vector<std::string> keys;
762 for(std::map<std::string,std::string>::iterator it = relnotes.begin(); it != relnotes.end(); ++it) {
763 keys.push_back(it->first);
776 for(std::map<std::string,std::string>::const_iterator it = relnotes.begin(); it != relnotes.end(); it++)
790 okButton->
setRole( YOKButton );
795 if ( event && event->eventType() == YEvent::MenuEvent &&
event->item())
797 YItem * item =
dynamic_cast<YItem *
> (
event->item());
800 else if ( event && event->widget() )
805 if ( button->
role() == YOKButton)
818 YUI_CAUGHT( exception );
void deleteEvent(YEvent *event)
Delete an event.
static bool showHelpText(YWidget *widget)
Show the help text for the specified widget.
static YWidgetFactory * widgetFactory()
Return the widget factory that provides all the createXY() methods for standard (mandatory, i.e.
void deleteEventFilters()
Delete all (remaining) event filters.
A vertical or horizontal stacking of widgets, implementing HBox and VBox.
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.
DumbTab: A very simple tab widget that can display and switch between a number of tabs...
void setIndex(int index)
Set this item's index.
bool isValid() const
Check if this event is valid.
static YApplication * application()
Aliases for YUI::app()
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.
virtual void setValue(const std::string &newValue)
Change the text content of the RichText widget.
YEvent * filterInvalidEvents(YEvent *event)
Filter out invalid events: Return 0 if the event does not belong to this dialog or the unchanged even...
int index() const
Return the index of this item (as set with setIndex() ).
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.
virtual void addItem(YItem *item)
Add an item (a tab page).
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.
Implementation of all the alignment widgets:
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.
Simple item class for SelectionBox, ComboBox, MultiSelectionBox etc.
static YOptionalWidgetFactory * optionalWidgetFactory()
Return the widget factory that provides all the createXY() methods for optional ("special") widgets a...
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 void showText(const std::string &text, bool richText=false)
Show the specified text in a pop-up dialog with a local event loop.
static int openDialogsCount()
Returns the number of currently open dialogs (from 1 on), i.e., the depth of the dialog stack...
virtual ~YDialog()
Destructor.
Text formatted with simple HTML-like tags, with "links" generating events.
static YApplication * app()
Return the global YApplication object.
std::map< std::string, std::string > releaseNotes() const
Get the current release notes map.
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.
Base class for UI Exceptions.
bool destroy(bool doThrow=true)
Close and delete this dialog (and all its children) if it is the topmost dialog.
static std::stack< YDialog * > _dialogStack
Stack holding all currently existing dialogs.
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.