/// <summary> /// This method is invoked whenever a widget is removed /// </summary> /// <param name="location">Location where a widget is being removed</param> /// <param name="widget">Reference to a widget that was removed</param> protected virtual void OnWidgetRemoved(MatrixLoc location, WidgetData widget) { if (_containerChangedEvent != null) { _containerChangedEvent(this, new WidgetContainerChangedEventArgs( NotifyCollectionChangedAction.Remove, location, widget, null)); } }
/// <summary> /// Initializing constructor /// </summary> /// <param name="action">Specifies if a widget was added, removed or replaced</param> /// <param name="location">Location of the changed widget</param> /// <param name="oldWidget">Reference to the original widget, or null if there wasn't any</param> /// <param name="newWidget">Reference to the new widget, or null if there isn't any</param> public WidgetContainerChangedEventArgs(NotifyCollectionChangedAction action, MatrixLoc location, WidgetData oldWidget, WidgetData newWidget) { _location = location; _action = action; _oldWidget = oldWidget; _newWidget = newWidget; }
private WidgetData ClearWidget(MatrixLoc loc) { MatrixLoc arrayIndex = _containerBounds.ToIndex(loc); WidgetData widget = _widgetArray[arrayIndex]; _widgetArray[arrayIndex] = null; if (widget != null) { widget.ClearOwner(); widget.IsDirtyChanged -= OnChildIsDirtyChanged; } return(widget); }
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; }
/// <summary> /// Gets/sets a widget at a specified location in the container /// </summary> /// <param name="location">Location to access/modify</param> public WidgetData this[MatrixLoc location] { get { return(_widgetArray[_containerBounds.ToIndex(location)]); } set { SetWidget(location, value); } }
/// <summary> /// Gets/sets an element at a specified location in the array /// </summary> /// <param name="index">Identifies the location</param> public T this[MatrixLoc index] { get { return(_arrayData[index.Row, index.Column]); } set { _arrayData[index.Row, index.Column] = value; } }
/// <summary> /// Sets parent container information on the current widget /// </summary> /// <param name="parent">Reference to the parent widget container</param> /// <param name="location">Location of the widget within the parent container</param> public void SetOwner(WidgetContainerData parent, MatrixLoc location) { _location = location; _parent = parent; }
/// <summary> /// Removes any association between the widget and its parent /// </summary> public void ClearOwner() { _parent = null; _location = new MatrixLoc(); }