30 #define YUILogComponent "ui"
33 #include "YUISymbols.h"
34 #include "YShortcut.h"
39 #include "YUIException.h"
40 #include "YWidgetID.h"
42 #include "YMacroRecorder.h"
44 #include "YChildrenManager.h"
46 #define MAX_DEBUG_LABEL_LEN 50
47 #define YWIDGET_MAGIC 42
49 #define CHECK_FOR_DUPLICATE_CHILDREN 1
50 #define LOG_WIDGET_REP 0
60 : childrenManager( manager )
61 , parent( parentWidget )
62 , beingDestroyed( false )
65 , notifyContextMenu( false )
66 , sendKeyEvents( false )
67 , autoShortcut( false )
68 , toolkitWidgetRep( 0 )
87 bool notifyContextMenu;
90 void * toolkitWidgetRep;
101 bool YWidget::_usedOperatorNew =
false;
105 : _magic( YWIDGET_MAGIC )
108 YUI_CHECK_NEW( priv );
109 YUI_CHECK_NEW( priv->childrenManager );
111 if ( ! _usedOperatorNew )
113 yuiError() <<
"FATAL: Widget at "
114 << std::hex << (
void *)
this << std::dec
115 <<
" not created with operator new !"
117 yuiError() <<
"Check core dump for a backtrace." << std::endl;
121 _usedOperatorNew =
false;
128 void * YWidget::operator
new(
size_t size )
130 _usedOperatorNew =
true;
131 return ::operator
new( size );
137 YUI_CHECK_WIDGET(
this );
147 delete priv->childrenManager;
159 return priv->childrenManager;
166 YUI_CHECK_PTR( newChildrenManager );
168 delete priv->childrenManager;
169 priv->childrenManager = newChildrenManager;
176 #if CHECK_FOR_DUPLICATE_CHILDREN
179 yuiError() <<
this <<
" already contains " << child << std::endl;
225 if ( label.size() > MAX_DEBUG_LABEL_LEN )
227 label.resize( MAX_DEBUG_LABEL_LEN );
228 label.append(
"..." );
231 for (
unsigned i=0; i < label.size(); i++ )
233 if ( label[i] ==
'\n' )
244 return _magic == YWIDGET_MAGIC;
249 YWidget::invalidate()
258 return priv->beingDestroyed;
264 priv->beingDestroyed =
true;
285 if ( newParent && priv->parent )
288 yuiWarning() <<
"Reparenting " <<
this
289 <<
" from " << priv->parent
290 <<
" to " << newParent << std::endl;
294 priv->parent = newParent;
300 return priv->sendKeyEvents;
306 priv->sendKeyEvents = doSend;
312 return priv->autoShortcut;
318 priv->autoShortcut = newAutoShortcut;
324 return priv->functionKey;
330 return priv->functionKey > 0;
336 priv->functionKey = fkey_no;
342 return priv->helpText;
370 return priv->id != 0;
385 widget = widget->
parent();
412 propSet.
add(
YProperty( YUIProperty_Enabled, YBoolProperty ) );
413 propSet.
add(
YProperty( YUIProperty_Notify, YBoolProperty ) );
414 propSet.
add(
YProperty( YUIProperty_WidgetClass, YStringProperty,
true ) );
415 propSet.
add(
YProperty( YUIProperty_DebugLabel, YStringProperty,
true ) );
416 propSet.
add(
YProperty( YUIProperty_HelpText, YStringProperty ) );
417 propSet.
add(
YProperty( YUIProperty_HWeight, YIntegerProperty ) );
418 propSet.
add(
YProperty( YUIProperty_VWeight, YIntegerProperty ) );
419 propSet.
add(
YProperty( YUIProperty_HStretch, YBoolProperty ) );
420 propSet.
add(
YProperty( YUIProperty_VStretch, YBoolProperty ) );
440 if ( propertyName == YUIProperty_Enabled )
setEnabled( val.boolVal() );
441 else if ( propertyName == YUIProperty_Notify )
setNotify ( val.boolVal() );
443 else if ( propertyName == YUIProperty_HWeight )
setWeight( YD_HORIZ, val.integerVal() );
444 else if ( propertyName == YUIProperty_VWeight )
setWeight( YD_VERT , val.integerVal() );
445 else if ( propertyName == YUIProperty_HStretch )
setStretchable( YD_HORIZ, val.boolVal() );
446 else if ( propertyName == YUIProperty_VStretch )
setStretchable( YD_VERT , val.boolVal() );
483 return priv->toolkitWidgetRep;
490 priv->toolkitWidgetRep = rep;
497 priv->enabled = enabled;
504 return priv->enabled;
510 yuiError() <<
"Default setShortcutString() method called - "
511 <<
"this should be reimplemented in "
537 return priv->notifyContextMenu;
557 priv->stretch[ dim ] = newStretch;
563 priv->stretch[ dim ] |= newStretch;
569 return priv->stretch[ dim ];
575 return priv->weight[ dim ];
581 priv->weight[ dim ] =
weight;
596 yuiWarning() <<
this <<
" cannot accept the keyboard focus." << std::endl;
617 YUI_CHECK_WIDGET( child );
689 std::ostringstream str;
691 std::string indentation ( indentationLevel * 4,
' ' );
692 str <<
"Widget tree: " << indentation << w;
694 if ( w->widgetRep() )
696 str <<
" (widgetRep: "
697 << std::hex << w->
widgetRep() << std::dec
703 if ( w->stretchable( YD_HORIZ ) ) stretch +=
"hstretch ";
704 if ( w->stretchable( YD_VERT ) ) stretch +=
"vstretch";
706 if ( ! stretch.empty() )
707 str <<
" ( " << stretch <<
" ) ";
709 yuiMilestone() << str.str() << std::endl;
751 std::ostream & operator<<( std::ostream & stream,
const YWidget * w )
759 if ( debugLabel.empty() )
762 stream <<
" ID: \"" << w->
id() <<
"\"";
766 stream <<
" \"" << debugLabel <<
"\"";
769 stream <<
" at " << std::hex << (
void *) w << std::dec;
774 stream <<
" (widgetRep: "
775 << std::hex << w->
widgetRep() << std::dec
782 stream <<
"<NULL widget>";
Abstract base class for macro recorders.
Transport class for the value of simple properties.
void check(const std::string &propertyName) const
Check if a property 'propertyName' exists in this property set.
void add(const YProperty &prop)
Add a property to this property set.
void setWidget(YWidget *w)
Set the corresponding widget.
A set of properties to check names and types against.
virtual std::string getShortcutString()
Obtain the the shortcut property of this shortcut's widget - the string that contains "&" to designat...
std::string stringVal() const
Methods to get the value of this property.
Exception class for "value other than YD_HORIZ or YD_VERT used for dimension".
Abstract base template class for children management, such as child widgets.
virtual void add(T *child)
Add a new child.
std::string cleanShortcutString()
Returns the shortcut string ( from the widget's shortcut property ) without any "&" markers...
static YDialog * currentDialog(bool doThrow=true)
Return the current (topmost) dialog.
bool isEmpty() const
Returns 'true' if this property set does not contain anything.
virtual void recordWidgetProperty(YWidget *widget, const char *propertyName)=0
Record one widget property.
Class for widget properties.
virtual void deleteNotify(YWidget *widget)
Notification that a widget is being deleted.
Exception class for "invalid child".
Children manager that rejects all children.
YPropertyType type() const
Returns the type of this property value.
Abstract base class for widget property exceptions.
virtual void remove(T *child)
Remove a child.
static YUI * ui()
Access the global UI.
virtual void clear()
Remove all children.
Base class for UI Exceptions.