Browse Source

WpfDesigner

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2221 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
b54ee353de
  1. 5
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml
  2. 2
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml.cs
  3. 105
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs
  4. 32
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs
  5. 22
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Linq.cs
  6. 91
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/ComponentService.cs
  7. 136
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/ToolService.cs
  8. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  9. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/XamlDesignSite.cs
  10. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs
  11. 35
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs
  12. 28
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlPropertyInfo.cs
  13. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DefaultServiceProvider.cs
  14. 11
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignSite.cs
  15. 12
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/EventArgs.cs
  16. 27
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs
  17. 124
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Tools.cs
  18. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj

5
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml

@ -13,7 +13,10 @@
<Canvas Height="50" Background="White"></Canvas> <Canvas Height="50" Background="White"></Canvas>
<Button>Button 1</Button> <Button>Button 1</Button>
<Button>Button 2</Button> <Button>Button 2</Button>
<Canvas Height="50"></Canvas> <TabControl Width="300" Height="300">
<TabItem Header="Page 1" />
<TabItem Header="Page 2"><Button>button on page 2</Button></TabItem>
</TabControl>
</StackPanel> </StackPanel>
</Border> </Border>
]]> ]]>

2
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
@ -20,6 +21,7 @@ namespace StandaloneDesigner
void tabControlSelectionChanged(object sender, RoutedEventArgs e) void tabControlSelectionChanged(object sender, RoutedEventArgs e)
{ {
if (e.Source != tabControl) return;
if (tabControl.SelectedItem == designTab) { if (tabControl.SelectedItem == designTab) {
designSurface.LoadDesigner(new XmlTextReader(new StringReader(CodeTextBox.Text))); designSurface.LoadDesigner(new XmlTextReader(new StringReader(CodeTextBox.Text)));
} else { } else {

105
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs

@ -6,31 +6,130 @@
// </file> // </file>
using System; using System;
using System.Diagnostics;
using System.Windows; using System.Windows;
using System.Windows.Input;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Threading;
using ICSharpCode.WpfDesign.Designer.Controls; using ICSharpCode.WpfDesign.Designer.Controls;
namespace ICSharpCode.WpfDesign.Designer namespace ICSharpCode.WpfDesign.Designer
{ {
sealed class DesignPanel : SingleVisualChildElement sealed class DesignPanel : SingleVisualChildElement, IDesignPanel
{ {
sealed class InnerDesignPanel : SingleVisualChildElement
{
internal void SetElement(UIElement element)
{
this.VisualChild = element;
}
}
DefaultServiceProvider _services;
InnerDesignPanel _innerDesignPanel;
UIElement _designedElement; UIElement _designedElement;
public DesignPanel(DefaultServiceProvider services)
{
this._services = services;
this.Focusable = true;
_innerDesignPanel = new InnerDesignPanel();
this.VisualChild = _innerDesignPanel;
}
public UIElement DesignedElement { public UIElement DesignedElement {
get { get {
return _designedElement; return _designedElement;
} }
set { set {
_designedElement = value; _designedElement = value;
this.VisualChild = value; _innerDesignPanel.SetElement(value);
} }
} }
protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters) protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters)
{ {
return new PointHitTestResult(this, hitTestParameters.HitPoint);
}
return base.HitTestCore(hitTestParameters); protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
{
return new GeometryHitTestResult(this, IntersectionDetail.NotCalculated);
}
protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
{
base.OnPreviewMouseDown(e);
if (!_isInInputAction) {
Debug.WriteLine("DesignPanel.PreviewMouseDown Source=" + e.Source.GetType().Name + " OriginalSource=" + e.OriginalSource.GetType().Name);
DesignSite site = FindDesignedElementForOriginalSource(e.OriginalSource);
if (site != null) {
Debug.WriteLine(" Found designed element: " + site.Component.GetType().Name);
} }
_services.Tool.CurrentTool.OnMouseDown(this, e);
}
}
public DesignSite FindDesignedElementForOriginalSource(object originalSource)
{
if (originalSource == null)
return null;
DesignSite site = _services.Component.GetSite(originalSource);
if (site != null)
return site;
if (originalSource == _innerDesignPanel)
return null;
DependencyObject dObj = originalSource as DependencyObject;
if (dObj == null)
return null;
return FindDesignedElementForOriginalSource(VisualTreeHelper.GetParent(dObj));
} }
/// <summary>
/// prevent designed controls from getting the keyboard focus
/// </summary>
protected override void OnPreviewGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
{
if (e.NewFocus != this) {
if (e.NewFocus is TabItem) {
Dispatcher.BeginInvoke(DispatcherPriority.Normal,
new Action(delegate { Focus(); }));
} else {
e.Handled = true;
Focus();
}
}
}
#region IDesignPanel implementation
public UIElement DesignPanelUI {
get { return this; }
}
public DefaultServiceProvider Services {
get { return _services; }
}
#endregion
bool _isInInputAction;
void IDesignPanel.StartInputAction()
{
if (_isInInputAction) throw new InvalidOperationException();
_isInInputAction = true;
_innerDesignPanel.IsHitTestVisible = false;
}
void IDesignPanel.StopInputAction()
{
if (!_isInInputAction) throw new InvalidOperationException();
_isInInputAction = false;
_innerDesignPanel.IsHitTestVisible = true;
}
}
internal delegate void Action();
} }

32
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs

@ -22,7 +22,8 @@ namespace ICSharpCode.WpfDesign.Designer
/// </summary> /// </summary>
public sealed class DesignSurface : SingleVisualChildElement public sealed class DesignSurface : SingleVisualChildElement
{ {
readonly DefaultServiceProvider _defaultServiceProvider; readonly DefaultServiceProvider _services;
readonly DefaultComponentService _componentService;
readonly ScrollViewer _scrollViewer; readonly ScrollViewer _scrollViewer;
readonly DesignPanel _designPanel; readonly DesignPanel _designPanel;
@ -32,13 +33,16 @@ namespace ICSharpCode.WpfDesign.Designer
public DesignSurface() public DesignSurface()
{ {
DesignServiceContainer serviceContainer = new DesignServiceContainer(); DesignServiceContainer serviceContainer = new DesignServiceContainer();
_services = new DefaultServiceProvider(serviceContainer);
serviceContainer.AddService(typeof(IVisualDesignService), new DefaultVisualDesignService()); serviceContainer.AddService(typeof(IVisualDesignService), new DefaultVisualDesignService());
serviceContainer.AddService(typeof(ISelectionService), new DefaultSelectionService()); serviceContainer.AddService(typeof(ISelectionService), new DefaultSelectionService());
serviceContainer.AddService(typeof(IToolService), new DefaultToolService());
_defaultServiceProvider = new DefaultServiceProvider(serviceContainer); _componentService = new DefaultComponentService(this);
serviceContainer.AddService(typeof(IComponentService), _componentService);
_scrollViewer = new ScrollViewer(); _scrollViewer = new ScrollViewer();
_designPanel = new DesignPanel(); _designPanel = new DesignPanel(_services);
_scrollViewer.Content = _designPanel; _scrollViewer.Content = _designPanel;
this.VisualChild = _scrollViewer; this.VisualChild = _scrollViewer;
} }
@ -46,8 +50,8 @@ namespace ICSharpCode.WpfDesign.Designer
/// <summary> /// <summary>
/// Gets the service provider. /// Gets the service provider.
/// </summary> /// </summary>
public DefaultServiceProvider DefaultServiceProvider { public DefaultServiceProvider Services {
get { return _defaultServiceProvider; } get { return _services; }
} }
/// <summary> /// <summary>
@ -68,9 +72,20 @@ namespace ICSharpCode.WpfDesign.Designer
InitializeDesigner(XamlParser.Parse(xamlReader)); InitializeDesigner(XamlParser.Parse(xamlReader));
} }
/// <summary>
/// Saves the designer content into the specified XmlWriter.
/// </summary>
public void SaveDesigner(XmlWriter writer)
{
_currentDocument.Save(writer);
}
XamlDocument _currentDocument;
void InitializeDesigner(XamlDocument document) void InitializeDesigner(XamlDocument document)
{ {
DesignSite rootSite = new XamlDesignSite(document.RootElement, this); _currentDocument = document;
DesignSite rootSite = _componentService.RegisterXamlComponentRecursive(document.RootElement);
_designPanel.DesignedElement = DefaultVisualDesignService.CreateUIElementFor(rootSite); _designPanel.DesignedElement = DefaultVisualDesignService.CreateUIElementFor(rootSite);
} }
@ -79,10 +94,11 @@ namespace ICSharpCode.WpfDesign.Designer
/// </summary> /// </summary>
public void UnloadDesigner() public void UnloadDesigner()
{ {
_currentDocument = null;
UIElement designedElement = this.DesignedElement; UIElement designedElement = this.DesignedElement;
if (designedElement != null) { if (designedElement != null) {
_componentService.UnregisterAllComponents();
_designPanel.DesignedElement = null; _designPanel.DesignedElement = null;
} }
} }
} }

22
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Linq.cs

@ -0,0 +1,22 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
namespace ICSharpCode.WpfDesign.Designer
{
static class Linq
{
public static T[] ToArray<T>(ICollection<T> collection)
{
T[] arr = new T[collection.Count];
collection.CopyTo(arr, 0);
return arr;
}
}
}

91
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/ComponentService.cs

@ -0,0 +1,91 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using ICSharpCode.WpfDesign.XamlDom;
namespace ICSharpCode.WpfDesign.Designer.Services
{
sealed class DefaultComponentService : IComponentService
{
readonly DesignSurface _surface;
public DefaultComponentService(DesignSurface surface)
{
this._surface = surface;
}
public event EventHandler<SiteEventArgs> ComponentRegistered;
public event EventHandler<SiteEventArgs> ComponentUnregistered;
Dictionary<object, XamlDesignSite> _sites = new Dictionary<object, XamlDesignSite>();
public DesignSite GetSite(object component)
{
if (component == null)
throw new ArgumentNullException("component");
XamlDesignSite site;
_sites.TryGetValue(component, out site);
return site;
}
public DesignSite RegisterComponentForDesigner(object component)
{
if (component == null)
throw new ArgumentNullException("component");
throw new NotImplementedException();
}
/// <summary>
/// currently for use by UnregisterAllComponents only because it doesn't update the XAML
/// </summary>
void UnregisterComponentFromDesigner(DesignSite site)
{
if (site == null)
throw new ArgumentNullException("site");
if (!_sites.Remove(site.Component))
throw new ArgumentException("The site was not registered here!");
if (ComponentUnregistered != null) {
ComponentUnregistered(this, new SiteEventArgs(site));
}
}
/// <summary>
/// registers components from an existing XAML tree
/// </summary>
internal XamlDesignSite RegisterXamlComponentRecursive(XamlObject obj)
{
if (obj == null) return null;
foreach (XamlProperty prop in obj.Properties) {
RegisterXamlComponentRecursive(prop.PropertyValue as XamlObject);
foreach (XamlPropertyValue val in prop.CollectionElements) {
RegisterXamlComponentRecursive(val as XamlObject);
}
}
XamlDesignSite site = new XamlDesignSite(obj, _surface);
_sites.Add(site.Component, site);
if (ComponentRegistered != null) {
ComponentRegistered(this, new SiteEventArgs(site));
}
return site;
}
/// <summary>
/// unregisters all components
/// </summary>
internal void UnregisterAllComponents()
{
Array.ForEach(Linq.ToArray(_sites.Values), UnregisterComponentFromDesigner);
_sites.Clear();
}
}
}

136
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/ToolService.cs

@ -0,0 +1,136 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows.Input;
namespace ICSharpCode.WpfDesign.Designer.Services
{
/// <summary>
/// See <see cref="IToolService"/> for description.
/// </summary>
sealed class DefaultToolService : IToolService
{
PointerTool _pointerTool;
ITool _currentTool;
public DefaultToolService()
{
_currentTool = _pointerTool = new PointerTool();
}
public ITool PointerTool {
get { return _pointerTool; }
}
public ITool CurrentTool {
get { return _currentTool; }
set {
if (value == null)
throw new ArgumentNullException("value");
_currentTool = value;
}
}
}
sealed class PointerTool : ITool
{
public InputHandlingLayer InputLayer {
get { return InputHandlingLayer.Tool; }
}
public Cursor Cursor {
get { return Cursors.Arrow; }
}
public void OnMouseDown(IDesignPanel designPanel, MouseButtonEventArgs e)
{
e.Handled = true;
new SelectionTask().Start(designPanel, e);
}
}
abstract class TaskBase
{
protected IDesignPanel designPanel;
bool isStarted;
public void Start(IDesignPanel designPanel, MouseButtonEventArgs e)
{
this.designPanel = designPanel;
isStarted = true;
designPanel.StartInputAction();
RegisterEvents();
if (designPanel.CaptureMouse()) {
OnStarted(e);
} else {
Stop();
}
}
void RegisterEvents()
{
designPanel.LostMouseCapture += OnLostMouseCapture;
designPanel.MouseDown += OnMouseDown;
designPanel.MouseMove += OnMouseMove;
designPanel.MouseUp += OnMouseUp;
}
void UnRegisterEvents()
{
designPanel.LostMouseCapture -= OnLostMouseCapture;
designPanel.MouseDown -= OnMouseDown;
designPanel.MouseMove -= OnMouseMove;
designPanel.MouseUp -= OnMouseUp;
}
protected virtual void OnLostMouseCapture(object sender, MouseEventArgs e)
{
Stop();
}
protected virtual void OnMouseDown(object sender, MouseButtonEventArgs e)
{
}
protected virtual void OnMouseMove(object sender, MouseEventArgs e)
{
}
protected virtual void OnMouseUp(object sender, MouseButtonEventArgs e)
{
Stop();
}
protected void Stop()
{
if (!isStarted) return;
isStarted = false;
designPanel.ReleaseMouseCapture();
UnRegisterEvents();
designPanel.StopInputAction();
OnStopped();
}
protected virtual void OnStarted(MouseButtonEventArgs e) {}
protected virtual void OnStopped() {}
}
sealed class SelectionTask : TaskBase
{
protected override void OnStarted(MouseButtonEventArgs e)
{
base.OnStarted(e);
}
protected override void OnStopped()
{
//designPanel.cur
base.OnStopped();
}
}
}

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

@ -59,8 +59,11 @@
<Compile Include="Controls\SingleVisualChildElement.cs" /> <Compile Include="Controls\SingleVisualChildElement.cs" />
<Compile Include="DesignPanel.cs" /> <Compile Include="DesignPanel.cs" />
<Compile Include="HashSet.cs" /> <Compile Include="HashSet.cs" />
<Compile Include="Linq.cs" />
<Compile Include="Services\ComponentService.cs" />
<Compile Include="Services\DesignServiceContainer.cs" /> <Compile Include="Services\DesignServiceContainer.cs" />
<Compile Include="Services\SelectionService.cs" /> <Compile Include="Services\SelectionService.cs" />
<Compile Include="Services\ToolService.cs" />
<Compile Include="Services\VisualDesignService.cs" /> <Compile Include="Services\VisualDesignService.cs" />
<Compile Include="XamlDesignSite.cs" /> <Compile Include="XamlDesignSite.cs" />
<Compile Include="DesignSurface.cs" /> <Compile Include="DesignSurface.cs" />

9
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/XamlDesignSite.cs

@ -6,6 +6,7 @@
// </file> // </file>
using System; using System;
using System.Windows;
using ICSharpCode.WpfDesign.XamlDom; using ICSharpCode.WpfDesign.XamlDom;
namespace ICSharpCode.WpfDesign.Designer namespace ICSharpCode.WpfDesign.Designer
@ -27,9 +28,15 @@ namespace ICSharpCode.WpfDesign.Designer
} }
} }
public override UIElement View {
get {
return null;
}
}
public override object GetService(Type serviceType) public override object GetService(Type serviceType)
{ {
return designSurface.DefaultServiceProvider.GetService(serviceType); return designSurface.Services.GetService(serviceType);
} }
} }
} }

10
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs

@ -124,8 +124,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
XamlPropertyInfo defaultProperty = GetDefaultProperty(elementType); XamlPropertyInfo defaultProperty = GetDefaultProperty(elementType);
XamlPropertyValue setDefaultValueTo = null; XamlPropertyValue setDefaultValueTo = null;
object defaultPropertyValue = null; object defaultPropertyValue = null;
XamlProperty defaultCollectionProperty = null;
if (defaultProperty != null && defaultProperty.IsCollection && !element.IsEmpty) { if (defaultProperty != null && defaultProperty.IsCollection && !element.IsEmpty) {
defaultPropertyValue = defaultProperty.GetValue(instance); defaultPropertyValue = defaultProperty.GetValue(instance);
obj.AddProperty(defaultCollectionProperty = new XamlProperty(obj, defaultProperty, null));
} }
foreach (XmlNode childNode in element.ChildNodes) { foreach (XmlNode childNode in element.ChildNodes) {
@ -145,6 +148,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (childValue != null) { if (childValue != null) {
if (defaultProperty != null && defaultProperty.IsCollection) { if (defaultProperty != null && defaultProperty.IsCollection) {
defaultProperty.AddValue(defaultPropertyValue, childValue); defaultProperty.AddValue(defaultPropertyValue, childValue);
defaultCollectionProperty.AddCollectionElement(childValue);
} else { } else {
if (setDefaultValueTo != null) if (setDefaultValueTo != null)
throw new XamlLoadException("default property may have only one value assigned"); throw new XamlLoadException("default property may have only one value assigned");
@ -164,6 +168,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
throw new XamlLoadException("This element does not have a default value, cannot assign to it"); throw new XamlLoadException("This element does not have a default value, cannot assign to it");
} }
defaultProperty.SetValue(instance, setDefaultValueTo.GetValueFor(defaultProperty)); defaultProperty.SetValue(instance, setDefaultValueTo.GetValueFor(defaultProperty));
obj.AddProperty(new XamlProperty(obj, defaultProperty, setDefaultValueTo));
} }
if (iSupportInitializeInstance != null) { if (iSupportInitializeInstance != null) {
@ -216,7 +221,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
MethodInfo getMethod = elementType.GetMethod("Get" + propertyName, BindingFlags.Public | BindingFlags.Static); MethodInfo getMethod = elementType.GetMethod("Get" + propertyName, BindingFlags.Public | BindingFlags.Static);
MethodInfo setMethod = elementType.GetMethod("Set" + propertyName, BindingFlags.Public | BindingFlags.Static); MethodInfo setMethod = elementType.GetMethod("Set" + propertyName, BindingFlags.Public | BindingFlags.Static);
if (getMethod != null && setMethod != null) { if (getMethod != null && setMethod != null) {
return new XamlAttachedPropertyInfo(getMethod, setMethod); return new XamlAttachedPropertyInfo(getMethod, setMethod, propertyName);
} }
return null; return null;
} }
@ -283,12 +288,14 @@ namespace ICSharpCode.WpfDesign.XamlDom
bool valueWasSet = false; bool valueWasSet = false;
object collectionInstance = null; object collectionInstance = null;
XamlProperty collectionProperty = null;
if (propertyInfo.IsCollection) { if (propertyInfo.IsCollection) {
if (defaultProperty.FullyQualifiedName == propertyInfo.FullyQualifiedName) { if (defaultProperty.FullyQualifiedName == propertyInfo.FullyQualifiedName) {
collectionInstance = defaultPropertyValue; collectionInstance = defaultPropertyValue;
} else { } else {
collectionInstance = propertyInfo.GetValue(obj.Instance); collectionInstance = propertyInfo.GetValue(obj.Instance);
} }
obj.AddProperty(collectionProperty = new XamlProperty(obj, propertyInfo, null));
} }
XmlSpace oldXmlSpace = currentXmlSpace; XmlSpace oldXmlSpace = currentXmlSpace;
@ -301,6 +308,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (childValue != null) { if (childValue != null) {
if (propertyInfo.IsCollection) { if (propertyInfo.IsCollection) {
propertyInfo.AddValue(collectionInstance, childValue); propertyInfo.AddValue(collectionInstance, childValue);
collectionProperty.AddCollectionElement(childValue);
} else { } else {
if (valueWasSet) if (valueWasSet)
throw new XamlLoadException("non-collection property may have only one child element"); throw new XamlLoadException("non-collection property may have only one child element");

35
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs

@ -6,6 +6,7 @@
// </file> // </file>
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Text; using System.Text;
using System.Xml; using System.Xml;
@ -20,6 +21,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
XamlObject parentObject; XamlObject parentObject;
XamlPropertyInfo propertyInfo; XamlPropertyInfo propertyInfo;
XamlPropertyValue propertyValue; XamlPropertyValue propertyValue;
List<XamlPropertyValue> collectionElements = new List<XamlPropertyValue>();
internal XamlProperty(XamlObject parentObject, XamlPropertyInfo propertyInfo, XamlPropertyValue propertyValue) internal XamlProperty(XamlObject parentObject, XamlPropertyInfo propertyInfo, XamlPropertyValue propertyValue)
{ {
@ -35,6 +37,36 @@ namespace ICSharpCode.WpfDesign.XamlDom
get { return parentObject; } get { return parentObject; }
} }
/// <summary>
/// Gets the property name.
/// </summary>
public string PropertyName {
get { return propertyInfo.Name; }
}
/// <summary>
/// Gets the value of the property. Can be null if the property is a collection property.
/// </summary>
public XamlPropertyValue PropertyValue {
get { return propertyValue; }
}
/// <summary>
/// Gets the collection elements of the property. Is empty if the property is not a collection.
/// </summary>
public IList<XamlPropertyValue> CollectionElements {
get { return collectionElements.AsReadOnly(); }
}
/// <summary>
/// used internally by the XamlParser.
/// Add a collection element that already is part of the XML DOM.
/// </summary>
internal void AddCollectionElement(XamlPropertyValue val)
{
collectionElements.Add(val);
}
/*public bool IsAttributeSyntax { /*public bool IsAttributeSyntax {
get { get {
return attribute != null; return attribute != null;
@ -60,6 +92,9 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// </summary> /// </summary>
public abstract class XamlPropertyValue public abstract class XamlPropertyValue
{ {
/// <summary>
/// used internally by the XamlParser.
/// </summary>
internal abstract object GetValueFor(XamlPropertyInfo targetProperty); internal abstract object GetValueFor(XamlPropertyInfo targetProperty);
} }

28
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlPropertyInfo.cs

@ -23,7 +23,9 @@ namespace ICSharpCode.WpfDesign.XamlDom
public abstract object GetValue(object instance); public abstract object GetValue(object instance);
public abstract void SetValue(object instance, object value); public abstract void SetValue(object instance, object value);
public abstract TypeConverter TypeConverter { get; } public abstract TypeConverter TypeConverter { get; }
public abstract string Name { get; }
public abstract string FullyQualifiedName { get; } public abstract string FullyQualifiedName { get; }
public abstract bool IsAttached { get; }
public abstract bool IsCollection { get; } public abstract bool IsCollection { get; }
internal abstract void AddValue(object collectionInstance, XamlPropertyValue newElement); internal abstract void AddValue(object collectionInstance, XamlPropertyValue newElement);
} }
@ -32,11 +34,13 @@ namespace ICSharpCode.WpfDesign.XamlDom
{ {
MethodInfo _getMethod; MethodInfo _getMethod;
MethodInfo _setMethod; MethodInfo _setMethod;
string _name;
public XamlAttachedPropertyInfo(MethodInfo getMethod, MethodInfo setMethod) public XamlAttachedPropertyInfo(MethodInfo getMethod, MethodInfo setMethod, string name)
{ {
this._getMethod = getMethod; this._getMethod = getMethod;
this._setMethod = setMethod; this._setMethod = setMethod;
this._name = name;
} }
public override TypeConverter TypeConverter { public override TypeConverter TypeConverter {
@ -47,14 +51,20 @@ namespace ICSharpCode.WpfDesign.XamlDom
public override string FullyQualifiedName { public override string FullyQualifiedName {
get { get {
return _getMethod.DeclaringType.FullName + "." + _getMethod.Name; return _getMethod.DeclaringType.FullName + "." + _name;
} }
} }
public override bool IsCollection { public override string Name {
get { get { return _name; }
return false;
} }
public override bool IsAttached {
get { return true; }
}
public override bool IsCollection {
get { return false; }
} }
public override object GetValue(object instance) public override object GetValue(object instance)
@ -107,6 +117,14 @@ namespace ICSharpCode.WpfDesign.XamlDom
} }
} }
public override string Name {
get { return _propertyDescriptor.Name; }
}
public override bool IsAttached {
get { return false; }
}
public override bool IsCollection { public override bool IsCollection {
get { get {
return CollectionSupport.IsCollectionType(_propertyDescriptor.PropertyType); return CollectionSupport.IsCollectionType(_propertyDescriptor.PropertyType);

20
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DefaultServiceProvider.cs

@ -81,5 +81,25 @@ namespace ICSharpCode.WpfDesign
return GetServiceChecked<ISelectionService>(); return GetServiceChecked<ISelectionService>();
} }
} }
/// <summary>
/// Gets the <see cref="IToolService"/>.
/// This service is guaranteed to always exist -> this property will never return null.
/// </summary>
public IToolService Tool {
get {
return GetServiceChecked<IToolService>();
}
}
/// <summary>
/// Gets the <see cref="IComponentService"/>.
/// This service is guaranteed to always exist -> this property will never return null.
/// </summary>
public IComponentService Component {
get {
return GetServiceChecked<IComponentService>();
}
}
} }
} }

11
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignSite.cs

@ -7,12 +7,18 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows;
namespace ICSharpCode.WpfDesign namespace ICSharpCode.WpfDesign
{ {
/// <summary> /// <summary>
/// The DesignSite connects a component with the service system and the designers. /// The DesignSite connects a component with the service system and the designers.
/// </summary> /// </summary>
/// <remarks>
/// About the Cider extension system:
/// http://blogs.msdn.com/jnak/archive/2006/04/24/580393.aspx
/// http://blogs.msdn.com/jnak/archive/2006/08/04/687166.aspx
/// </remarks>
public abstract class DesignSite : IServiceProvider public abstract class DesignSite : IServiceProvider
{ {
/// <summary> /// <summary>
@ -20,6 +26,11 @@ namespace ICSharpCode.WpfDesign
/// </summary> /// </summary>
public abstract object Component { get; } public abstract object Component { get; }
/// <summary>
/// Gets the view used for the component.
/// </summary>
public abstract UIElement View { get; }
DefaultServiceProvider _defaultServiceProvider; DefaultServiceProvider _defaultServiceProvider;
/// <summary> /// <summary>

12
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ComponentEventArgs.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/EventArgs.cs

@ -13,23 +13,23 @@ namespace ICSharpCode.WpfDesign
/// <summary> /// <summary>
/// Event arguments specifying a component as parameter. /// Event arguments specifying a component as parameter.
/// </summary> /// </summary>
public class ComponentEventArgs : EventArgs public class SiteEventArgs : EventArgs
{ {
readonly object _component; readonly DesignSite _site;
/// <summary> /// <summary>
/// Creates a new ComponentEventArgs instance. /// Creates a new ComponentEventArgs instance.
/// </summary> /// </summary>
public ComponentEventArgs(object component) public SiteEventArgs(DesignSite site)
{ {
_component = component; _site = site;
} }
/// <summary> /// <summary>
/// The component affected by the event. /// The component affected by the event.
/// </summary> /// </summary>
public object Component { public DesignSite Site {
get { return _component; } get { return _site; }
} }
} }

27
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs

@ -123,6 +123,8 @@ namespace ICSharpCode.WpfDesign
/// <summary> /// <summary>
/// Gets the collection of selected components. /// Gets the collection of selected components.
/// This is a copy of the actual selected components collection, the returned copy
/// of the collection will not reflect future changes to the selection.
/// </summary> /// </summary>
ICollection<object> SelectedComponents { get; } ICollection<object> SelectedComponents { get; }
@ -145,4 +147,29 @@ namespace ICSharpCode.WpfDesign
int SelectionCount { get; } int SelectionCount { get; }
} }
#endregion #endregion
#region IComponentService
/// <summary>Supports adding and removing components</summary>
public interface IComponentService
{
/// <summary>
/// Gets the site of an existing, registered component.
/// </summary>
/// <returns>
/// The site of the component, or null if the component is not registered.
/// </returns>
DesignSite GetSite(object component);
/// <summary>Registers a component for usage in the designer.</summary>
DesignSite RegisterComponentForDesigner(object component);
// /// <summary>Unregisters a component from usage in the designer.</summary>
// void UnregisterComponentFromDesigner(DesignSite site);
/// <summary>Event raised whenever a component is registered</summary>
event EventHandler<SiteEventArgs> ComponentRegistered;
/// <summary>Event raised whenever a component is unregistered</summary>
event EventHandler<SiteEventArgs> ComponentUnregistered;
}
#endregion
} }

124
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Tools.cs

@ -0,0 +1,124 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows.Input;
using System.Windows;
namespace ICSharpCode.WpfDesign
{
/// <summary>
/// Describes the layer of input handling.
/// When multiple actions are possible, that with the highest layer will be used.
/// </summary>
public enum InputHandlingLayer
{
/// <summary>
/// No layer specified. This layer is lower than all other layers.
/// </summary>
None,
/// <summary>
/// Layer used for passing the input to the component.
/// Normally never receives actions because there is always a <see cref="Tool"/>.
/// </summary>
Component,
/// <summary>
/// Layer used for tools.
/// </summary>
Tool,
/// <summary>
/// Layer used for certain components that should get input, for example scroll thumbs
/// in user-defined ScrollViewers and the headers inside a TabControl.
/// </summary>
ComponentHigh,
/// <summary>
/// This layer is higher than all other layers.
/// </summary>
Highest
}
/// <summary>
/// Describes a tool that can handle input on the design surface.
/// Modelled after the description on http://urbanpotato.net/Default.aspx/document/2300
/// </summary>
public interface ITool
{
/// <summary>
/// Gets the input handling layer of the tool.
/// </summary>
InputHandlingLayer InputLayer { get; }
/// <summary>
/// Gets the cursor used by the tool.
/// </summary>
Cursor Cursor { get; }
/// <summary>
/// Notifies the tool of the MouseDown event.
/// </summary>
void OnMouseDown(IDesignPanel designPanel, MouseButtonEventArgs e);
}
/// <summary>
/// Service that manages tool selection.
/// </summary>
public interface IToolService
{
/// <summary>
/// Gets the 'pointer' tool.
/// The pointer tool is the default tool for selecting and moving elements.
/// </summary>
ITool PointerTool { get; }
/// <summary>
/// Gets/Sets the currently selected tool.
/// </summary>
ITool CurrentTool { get; set; }
}
/// <summary>
/// Interface for the design panel. The design panel is the UIElement containing the
/// designed elements and is responsible for handling mouse and keyboard events.
/// </summary>
public interface IDesignPanel : IInputElement
{
/// <summary>
/// Gets the service provider used by the DesignPanel.
/// </summary>
DefaultServiceProvider Services { get; }
/// <summary>
/// Starts an input action. This prevents components and tools from getting input events,
/// leaving input handling to event handlers attached to the design panel.
/// </summary>
void StartInputAction();
/// <summary>
/// Stops an input action. This reenables input handling of
/// </summary>
void StopInputAction();
/// <summary>
/// Finds the designed element for the specified original source.
/// </summary>
DesignSite FindDesignedElementForOriginalSource(object originalSource);
// The following members were missing in <see cref="IInputElement"/>, but of course
// are supported on the DesignPanel:
/// <summary>
/// Occurs when a mouse button is pressed.
/// </summary>
event MouseButtonEventHandler MouseDown;
/// <summary>
/// Occurs when a mouse button is released.
/// </summary>
event MouseButtonEventHandler MouseUp;
}
}

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj

@ -55,12 +55,13 @@
<Compile Include="..\..\..\..\..\Main\GlobalAssemblyInfo.cs"> <Compile Include="..\..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>Configuration\GlobalAssemblyInfo.cs</Link> <Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile> </Compile>
<Compile Include="ComponentEventArgs.cs" /> <Compile Include="EventArgs.cs" />
<Compile Include="Configuration\AssemblyInfo.cs" /> <Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="DesignerException.cs" /> <Compile Include="DesignerException.cs" />
<Compile Include="DefaultServiceProvider.cs" /> <Compile Include="DefaultServiceProvider.cs" />
<Compile Include="DesignSite.cs" /> <Compile Include="DesignSite.cs" />
<Compile Include="Services.cs" /> <Compile Include="Services.cs" />
<Compile Include="Tools.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Configuration" /> <Folder Include="Configuration" />

Loading…
Cancel
Save