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();
413 propSet.
add(
YProperty( YUIProperty_Enabled, YBoolProperty ) );
414 propSet.
add(
YProperty( YUIProperty_Notify, YBoolProperty ) );
415 propSet.
add(
YProperty( YUIProperty_WidgetClass, YStringProperty,
true ) );
416 propSet.
add(
YProperty( YUIProperty_DebugLabel, YStringProperty,
true ) );
417 propSet.
add(
YProperty( YUIProperty_ID, YStringProperty,
true ) );
418 propSet.
add(
YProperty( YUIProperty_HelpText, YStringProperty ) );
419 propSet.
add(
YProperty( YUIProperty_HWeight, YIntegerProperty ) );
420 propSet.
add(
YProperty( YUIProperty_VWeight, YIntegerProperty ) );
421 propSet.
add(
YProperty( YUIProperty_HStretch, YBoolProperty ) );
422 propSet.
add(
YProperty( YUIProperty_VStretch, YBoolProperty ) );
442 if ( propertyName == YUIProperty_Enabled )
setEnabled( val.boolVal() );
443 else if ( propertyName == YUIProperty_Notify )
setNotify ( val.boolVal() );
445 else if ( propertyName == YUIProperty_HWeight )
setWeight( YD_HORIZ, val.integerVal() );
446 else if ( propertyName == YUIProperty_VWeight )
setWeight( YD_VERT , val.integerVal() );
447 else if ( propertyName == YUIProperty_HStretch )
setStretchable( YD_HORIZ, val.boolVal() );
448 else if ( propertyName == YUIProperty_VStretch )
setStretchable( YD_VERT , val.boolVal() );
477 if ( propertyName == YUIProperty_ID && this->
hasId() )
return YPropertyValue(this->
id()->toString());
486 return priv->toolkitWidgetRep;
493 priv->toolkitWidgetRep = rep;
500 priv->enabled = enabled;
507 return priv->enabled;
513 yuiError() <<
"Default setShortcutString() method called - " 514 <<
"this should be reimplemented in " 540 return priv->notifyContextMenu;
560 priv->stretch[ dim ] = newStretch;
566 priv->stretch[ dim ] |= newStretch;
572 return priv->stretch[ dim ];
578 return priv->weight[ dim ];
584 priv->weight[ dim ] =
weight;
599 yuiWarning() <<
this <<
" cannot accept the keyboard focus." << std::endl;
620 YUI_CHECK_WIDGET( child );
692 std::ostringstream str;
694 std::string indentation ( indentationLevel * 4,
' ' );
695 str <<
"Widget tree: " << indentation << w;
697 if ( w->widgetRep() )
699 str <<
" (widgetRep: " 700 << std::hex << w->
widgetRep() << std::dec
706 if ( w->stretchable( YD_HORIZ ) ) stretch +=
"hstretch ";
707 if ( w->stretchable( YD_VERT ) ) stretch +=
"vstretch";
709 if ( ! stretch.empty() )
710 str <<
" ( " << stretch <<
" ) ";
712 yuiMilestone() << str.str() << std::endl;
754 std::ostream & operator<<( std::ostream & stream,
const YWidget * w )
762 if ( debugLabel.empty() )
765 stream <<
" ID: \"" << w->
id() <<
"\"";
769 stream <<
" \"" << debugLabel <<
"\"";
772 stream <<
" at " << std::hex << (
void *) w << std::dec;
777 stream <<
" (widgetRep: " 778 << std::hex << w->
widgetRep() << std::dec
785 stream <<
"<NULL widget>";
Abstract base class for macro recorders.
bool isEmpty() const
Returns 'true' if this property set does not contain anything.
Transport class for the value of simple properties.
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...
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.
std::string stringVal() const
Methods to get the value of this property.
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.
A window in the desktop environment.
void check(const std::string &propertyName) const
Check if a property 'propertyName' exists in this property set.
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.
YPropertyType type() const
Returns the type of this property value.