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
62 : childrenManager( manager )
63 , parent( parentWidget )
64 , beingDestroyed( false )
67 , notifyContextMenu( false )
68 , sendKeyEvents( false )
69 , autoShortcut( false )
70 , toolkitWidgetRep( 0 )
89 bool notifyContextMenu;
92 void * toolkitWidgetRep;
103 bool YWidget::_usedOperatorNew =
false;
107 : _magic( YWIDGET_MAGIC )
110 YUI_CHECK_NEW( priv );
111 YUI_CHECK_NEW( priv->childrenManager );
113 if ( ! _usedOperatorNew )
115 yuiError() <<
"FATAL: Widget at "
116 << std::hex << (
void *)
this << std::dec
117 <<
" not created with operator new !"
119 yuiError() <<
"Check core dump for a backtrace." << endl;
123 _usedOperatorNew =
false;
130 void * YWidget::operator
new(
size_t size )
132 _usedOperatorNew =
true;
133 return ::operator
new( size );
139 YUI_CHECK_WIDGET(
this );
149 delete priv->childrenManager;
161 return priv->childrenManager;
168 YUI_CHECK_PTR( newChildrenManager );
170 delete priv->childrenManager;
171 priv->childrenManager = newChildrenManager;
178 #if CHECK_FOR_DUPLICATE_CHILDREN
181 yuiError() <<
this <<
" already contains " << child << endl;
227 if ( label.size() > MAX_DEBUG_LABEL_LEN )
229 label.resize( MAX_DEBUG_LABEL_LEN );
230 label.append(
"..." );
233 for (
unsigned i=0; i < label.size(); i++ )
235 if ( label[i] ==
'\n' )
246 return _magic == YWIDGET_MAGIC;
251 YWidget::invalidate()
260 return priv->beingDestroyed;
266 priv->beingDestroyed =
true;
287 if ( newParent && priv->parent )
290 yuiWarning() <<
"Reparenting " <<
this
291 <<
" from " << priv->parent
292 <<
" to " << newParent << endl;
296 priv->parent = newParent;
302 return priv->sendKeyEvents;
308 priv->sendKeyEvents = doSend;
314 return priv->autoShortcut;
320 priv->autoShortcut = newAutoShortcut;
326 return priv->functionKey;
332 return priv->functionKey > 0;
338 priv->functionKey = fkey_no;
344 return priv->helpText;
372 return priv->id != 0;
387 widget = widget->
parent();
415 propSet.
add(
YProperty( YUIProperty_Enabled, YBoolProperty ) );
416 propSet.
add(
YProperty( YUIProperty_Notify, YBoolProperty ) );
417 propSet.
add(
YProperty( YUIProperty_WidgetClass, YStringProperty,
true ) );
418 propSet.
add(
YProperty( YUIProperty_DebugLabel, YStringProperty,
true ) );
419 propSet.
add(
YProperty( YUIProperty_ID, YStringProperty,
true ) );
420 propSet.
add(
YProperty( YUIProperty_HelpText, YStringProperty ) );
421 propSet.
add(
YProperty( YUIProperty_HWeight, YIntegerProperty ) );
422 propSet.
add(
YProperty( YUIProperty_VWeight, YIntegerProperty ) );
423 propSet.
add(
YProperty( YUIProperty_HStretch, YBoolProperty ) );
424 propSet.
add(
YProperty( YUIProperty_VStretch, YBoolProperty ) );
444 if ( propertyName == YUIProperty_Enabled )
setEnabled( val.boolVal() );
445 else if ( propertyName == YUIProperty_Notify )
setNotify ( val.boolVal() );
447 else if ( propertyName == YUIProperty_HWeight )
setWeight( YD_HORIZ, val.integerVal() );
448 else if ( propertyName == YUIProperty_VWeight )
setWeight( YD_VERT , val.integerVal() );
449 else if ( propertyName == YUIProperty_HStretch )
setStretchable( YD_HORIZ, val.boolVal() );
450 else if ( propertyName == YUIProperty_VStretch )
setStretchable( YD_VERT , val.boolVal() );
479 if ( propertyName == YUIProperty_ID && this->
hasId() )
return YPropertyValue(this->
id()->toString());
488 return priv->toolkitWidgetRep;
495 priv->toolkitWidgetRep = rep;
502 priv->enabled = enabled;
509 return priv->enabled;
515 yuiError() <<
"Default setShortcutString() method called - "
516 <<
"this should be reimplemented in "
542 return priv->notifyContextMenu;
562 priv->stretch[ dim ] = newStretch;
568 priv->stretch[ dim ] |= newStretch;
574 return priv->stretch[ dim ];
580 return priv->weight[ dim ];
586 priv->weight[ dim ] =
weight;
601 yuiWarning() <<
this <<
" cannot accept the keyboard focus." << endl;
622 YUI_CHECK_WIDGET( child );
694 std::ostringstream str;
696 string indentation ( indentationLevel * 4,
' ' );
697 str <<
"Widget tree: " << indentation << w;
701 str <<
" (widgetRep: "
702 << std::hex << w->
widgetRep() << std::dec
708 if ( w->
stretchable( YD_HORIZ ) ) stretch +=
"hstretch ";
709 if ( w->
stretchable( YD_VERT ) ) stretch +=
"vstretch";
711 if ( ! stretch.empty() )
712 str <<
" ( " << stretch <<
" ) ";
714 yuiMilestone() << str.str() << endl;
756 std::ostream & operator<<( std::ostream & stream,
const YWidget * w )
764 if ( debugLabel.empty() )
767 stream <<
" ID: \"" << w->
id() <<
"\"";
771 stream <<
" \"" << debugLabel <<
"\"";
774 stream <<
" at " << std::hex << (
void *) w << std::dec;
779 stream <<
" (widgetRep: "
787 stream <<
"<NULL widget>";
Abstract base template class for children management, such as child widgets.
virtual void clear()
Remove all children.
virtual void add(T *child)
Add a new child.
virtual void remove(T *child)
Remove a child.
Children manager that rejects all children.
A window in the desktop environment.
static YDialog * currentDialog(bool doThrow=true)
Return the current (topmost) dialog.
Abstract base class for macro recorders.
virtual void recordWidgetProperty(YWidget *widget, const char *propertyName)=0
Record one widget property.
A set of properties to check names and types against.
void check(const std::string &propertyName) const
Check if a property 'propertyName' exists in this property set.
bool isEmpty() const
Returns 'true' if this property set does not contain anything.
void add(const YProperty &prop)
Add a property to this property set.
Transport class for the value of simple properties.
std::string stringVal() const
Methods to get the value of this property.
YPropertyType type() const
Returns the type of this property value.
Class for widget properties.
virtual std::string getShortcutString()
Obtain the the shortcut property of this shortcut's widget - the string that contains "&" to designat...
std::string cleanShortcutString()
Returns the shortcut string ( from the widget's shortcut property ) without any "&" markers.
Base class for UI Exceptions.
Exception class for "invalid child".
Exception class for "value other than YD_HORIZ or YD_VERT used for dimension".
Abstract base class for widget property exceptions.
void setWidget(YWidget *w)
Set the corresponding widget.
static YUI * ui()
Access the global UI.
virtual void deleteNotify(YWidget *widget)
Notification that a widget is being deleted.