29 #define YUILogComponent "ui"
34 #include "YShortcutManager.h"
35 #include "YPushButton.h"
36 #include "YButtonBox.h"
39 #include "YWidgetFactory.h"
40 #include "YLayoutBox.h"
41 #include "YRichText.h"
42 #include "YAlignment.h"
43 #include "YUIException.h"
44 #include "YEventFilter.h"
47 #define VERBOSE_DIALOGS 0
48 #define VERBOSE_DISCARDED_EVENTS 0
49 #define VERBOSE_EVENTS 0
52 typedef std::list<YEventFilter *> YEventFilterList;
57 YDialogPrivate( YDialogType dialogType, YDialogColorMode colorMode )
58 : dialogType( dialogType )
59 , colorMode( colorMode )
60 , shortcutCheckPostponed(
false )
66 YDialogType dialogType;
67 YDialogColorMode colorMode;
68 bool shortcutCheckPostponed;
72 YEventFilterList eventFilterList;
91 if ( event && event->
widget() )
115 YUI_CHECK_NEW( priv );
120 yuiDebug() <<
"New " <<
this << std::endl;
130 yuiDebug() <<
"Destroying " <<
this << std::endl;
138 if ( priv->lastEvent )
158 yuiError() <<
"Not top of dialog stack: " <<
this << std::endl;
188 yuiError() <<
"Dialog stack empty, but dialog existing: " <<
this << std::endl;
199 while ( ! priv->eventFilterList.empty() )
204 yuiDebug() <<
"Deleting event filter " << std::std::hex << filter << std::dec << std::endl;
214 YUI_CHECK_WIDGET(
this );
235 return priv->dialogType;
242 switch ( priv->dialogType )
244 case YMainDialog:
return true;
245 case YWizardDialog:
return true;
246 case YPopupDialog:
return false;
260 return priv->colorMode;
267 priv->shortcutCheckPostponed =
true;
274 return priv->shortcutCheckPostponed;
281 if ( priv->shortcutCheckPostponed && ! force )
283 yuiDebug() <<
"Shortcut check postponed" << std::endl;
291 priv->shortcutCheckPostponed =
false;
299 return priv->defaultButton;
306 if ( newDefaultButton && priv->defaultButton )
308 yuiError() <<
"Too many `opt(`default) PushButtons: ["
309 << newDefaultButton->
label()
313 priv->defaultButton = newDefaultButton;
321 yuiDebug() <<
"Setting initial size for " <<
this << std::endl;
332 yuiDebug() <<
"Recalculating layout for " <<
this << std::endl;
344 if ( timeout_millisec < 0 )
345 timeout_millisec = 0;
352 yuiError() <<
"Performing missing keyboard shortcut check now in "
353 <<
this << std::endl;
372 priv->lastEvent = event;
392 priv->lastEvent = event;
411 if ( widgetEvent && widgetEvent->
widget() )
441 yuiDebug() <<
"Discarding event from widget from foreign dialog" << std::endl;
443 #if VERBOSE_DISCARDED_EVENTS
444 yuiDebug() <<
"Expected: " <<
this
448 yuiDebug() <<
"Event widget: " << widgetEvent->
widget() << std::endl;
449 yuiDebug() <<
"From:" << std::endl;
451 yuiDebug() <<
"Current dialog:" << std::endl;
470 if ( event == priv->lastEvent )
478 yuiDebug() <<
"Deleting " <<
event << std::endl;
484 yuiError() <<
"Attempt to delete invalid event " <<
event << std::endl;
534 YUI_CHECK_WIDGET( targetDialog );
542 if ( dialog == targetDialog )
562 YUI_CHECK_PTR( eventFilter );
564 if ( find( priv->eventFilterList.begin(), priv->eventFilterList.end(),
565 eventFilter ) != priv->eventFilterList.end() )
567 yuiError() <<
"event filter " << std::hex << eventFilter << std::dec
568 <<
" already added to " <<
this
574 yuiDebug() <<
"Adding event filter " << std::hex << eventFilter << std::dec << std::endl;
576 priv->eventFilterList.push_back( eventFilter );
584 YUI_CHECK_PTR( eventFilter );
587 yuiDebug() <<
"Removing event filter " << std::hex << eventFilter << std::dec << std::endl;
589 priv->eventFilterList.remove( eventFilter );
596 YEventFilterList::const_iterator it = priv->eventFilterList.begin();
598 while ( it != priv->eventFilterList.end() && event )
600 YEvent * oldEvent = event;
601 event = (*it)->filter( event );
603 if ( oldEvent != event )
619 unsigned int dialogWidth = 45;
620 unsigned int dialogHeight = 15;
625 dialogWidth = (
unsigned int) ( (
float) dialog->
preferredWidth() * 0.8 );
626 dialogHeight = (
unsigned int) ( (
float) dialog->
preferredHeight() * 0.8 );
630 if ( dialogWidth > 80 || dialogHeight > 25 )
644 okButton->
setRole( YOKButton );
654 YUI_CAUGHT( exception );
668 yuiDebug() <<
"Found help text for " << widget << std::endl;
672 widget = widget->
parent();
675 if ( ! helpText.empty() )
677 yuiMilestone() <<
"Showing help text" << std::endl;
680 yuiMilestone() <<
"Help dialog closed" << std::endl;
684 yuiWarning() <<
"No help text" << std::endl;
687 return ! helpText.empty();