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;
65 YDialogPrivate( YDialogType dialogType, YDialogColorMode colorMode )
66 : dialogType( dialogType )
67 , colorMode( colorMode )
68 , shortcutCheckPostponed(
false )
74 YDialogType dialogType;
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 );
YPushButton * defaultButton() const
void deleteEvent(YEvent *event)
static bool showHelpText(YWidget *widget)
static YWidgetFactory * widgetFactory()
void deleteEventFilters()
YEventFilter(YDialog *dialog=0)
virtual void setDefaultButton(YPushButton *defaultButton)
static YApplication * application()
std::map< std::string, std::string > releaseNotes() const
void postponeShortcutCheck()
static bool deleteTopmostDialog(bool doThrow=true)
virtual YWidget * widget() const
YDialogType dialogType() const
virtual void setValue(const std::string &newValue)
YEvent * filterInvalidEvents(YEvent *event)
void checkShortcuts(bool force=false)
void removeEventFilter(YEventFilter *eventFilter)
virtual void addItem(YItem *item)
virtual void openInternal()=0
static void deleteAllDialogs()
bool shortcutCheckPostponed() const
virtual YEvent * pollEventInternal()=0
static YDialog * currentDialog(bool doThrow=true)
bool isTopmostDialog() const
YEvent * callEventFilters(YEvent *event)
void checkShortcuts(bool autoResolve=true)
void addEventFilter(YEventFilter *eventFilter)
static YOptionalWidgetFactory * optionalWidgetFactory()
YDialog(YDialogType dialogType, YDialogColorMode colorMode=YDialogNormalColor)
static void deleteTo(YDialog *dialog)
static bool showRelNotesText()
virtual void activate()=0
static void showText(const std::string &text, bool richText=false)
static int openDialogsCount()
static YApplication * app()
virtual YEvent * waitForEventInternal(int timeout_millisec)=0
bool destroy(bool doThrow=true)
static std::stack< YDialog * > _dialogStack
YEvent * waitForEvent(int timeout_millisec=0)
YDialogColorMode colorMode() const