Example #1
0
        private void SetWidget(MatrixLoc location, WidgetData widget)
        {
            WidgetData removedWidget = null;

            Validate();

            // the same widget is being inserted at the same spot where it is already located,
            // let not do anything and just exit
            if (widget != null && widget.Parent == this && widget.Location == location)
            {
                return;
            }

            MatrixRect neededBounds = _containerBounds.GrowTo(location);

            // If the cell being modified within the bounds of the current array, let's make sure
            // the existing cell is empty.  Otherwise, we need to reallocate the array before
            // we can assign the widget to it.
            if (neededBounds.Size == _containerBounds.Size)
            {
                removedWidget = ClearWidget(location);
            }
            else if (widget != null)
            {
                WidgetContainerResizeJustify resizeJustify =
                    (_containerBounds.Row == neededBounds.Row ?
                     WidgetContainerResizeJustify.Top : WidgetContainerResizeJustify.Bottom) |
                    (_containerBounds.Column == neededBounds.Column ?
                     WidgetContainerResizeJustify.Left : WidgetContainerResizeJustify.Right);

                Resize(neededBounds.Size, resizeJustify);
            }

            Validate();

            if (widget != null)
            {
                if (widget.HasOwner)
                {
                    widget.Parent.Remove(widget);
                }

                _widgetArray[_containerBounds.ToIndex(location)] = widget;

                widget.SetOwner(this, location);
                widget.IsDirtyChanged += OnChildIsDirtyChanged;

                if (removedWidget != null)
                {
                    OnWidgetReplaced(location, removedWidget, widget);
                    removedWidget = null;
                }
                else
                {
                    OnWidgetAdded(location, widget);
                }
            }

            if (removedWidget != null)
            {
                OnWidgetRemoved(location, removedWidget);
            }

            Validate();

            IsDirty = true;
        }
Example #2
0
        private void SetWidget( MatrixLoc location, WidgetData widget )
        {
            WidgetData  removedWidget = null;

            Validate();

            // the same widget is being inserted at the same spot where it is already located,
            // let not do anything and just exit
            if( widget != null && widget.Parent == this && widget.Location == location ) return;

            MatrixRect neededBounds = _containerBounds.GrowTo( location );

            // If the cell being modified within the bounds of the current array, let's make sure
            // the existing cell is empty.  Otherwise, we need to reallocate the array before
            // we can assign the widget to it.
            if( neededBounds.Size == _containerBounds.Size )
            {
                removedWidget = ClearWidget( location );
            }
            else if( widget != null )
            {
                WidgetContainerResizeJustify resizeJustify =
                    ( _containerBounds.Row == neededBounds.Row ?
                            WidgetContainerResizeJustify.Top : WidgetContainerResizeJustify.Bottom ) |
                    ( _containerBounds.Column == neededBounds.Column ?
                            WidgetContainerResizeJustify.Left : WidgetContainerResizeJustify.Right );

                Resize( neededBounds.Size, resizeJustify );
            }

            Validate();

            if( widget != null )
            {
                if( widget.HasOwner )
                {
                    widget.Parent.Remove( widget );
                }

                _widgetArray[ _containerBounds.ToIndex( location ) ] = widget;

                widget.SetOwner( this, location );
                widget.IsDirtyChanged += OnChildIsDirtyChanged;

                if( removedWidget != null )
                {
                    OnWidgetReplaced( location, removedWidget, widget );
                    removedWidget = null;
                }
                else
                {
                    OnWidgetAdded( location, widget );
                }
            }

            if( removedWidget != null )
            {
                OnWidgetRemoved( location, removedWidget );
            }

            Validate();

            IsDirty = true;
        }