2
// CanvasCellViewBackend.cs
5
// David Karlaš <david.karlas@gmail.com>
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
9
// of this software and associated documentation files (the "Software"), to deal
10
// in the Software without restriction, including without limitation the rights
11
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
// copies of the Software, and to permit persons to whom the Software is
13
// furnished to do so, subject to the following conditions:
15
// The above copyright notice and this permission notice shall be included in
16
// all copies or substantial portions of the Software.
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2
using System.Collections.Generic;
26
5
using System.Windows;
29
8
namespace Xwt.WPFBackend
31
class CanvasCellViewBackend : ExCanvas, ICellDataSource
33
public CanvasCellViewBackend()
35
DataContextChanged += OnDataChanged;
38
void OnDataChanged(object sender, DependencyPropertyChangedEventArgs e)
40
if (e.OldValue != null)
41
((ValuesContainer)e.OldValue).PropertyChanged -= CanvasCellRenderer_PropertyChanged;
42
((ValuesContainer)DataContext).PropertyChanged += CanvasCellRenderer_PropertyChanged;
45
void CanvasCellRenderer_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
51
public event DependencyPropertyChangedEventHandler CellViewChanged;
53
public static readonly DependencyProperty CellViewProperty =
54
DependencyProperty.Register("CellView", typeof(CanvasCellView),
55
typeof(CanvasCellViewBackend), new FrameworkPropertyMetadata(new PropertyChangedCallback(OnCellViewChanged)));
57
public ICanvasCellViewFrontend CellView
59
get { return (ICanvasCellViewFrontend)GetValue (CellViewProperty); }
60
set { SetValue(CellViewProperty, value); }
63
public static void OnCellViewChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
65
var sl = sender as CanvasCellViewBackend;
67
sl.RaiseCellViewChangedEvent(e);
70
private void RaiseCellViewChangedEvent(DependencyPropertyChangedEventArgs e)
72
if (this.CellViewChanged != null)
73
this.CellViewChanged(this, e);
76
protected override void OnRender(System.Windows.Media.DrawingContext dc)
79
CellView.Initialize(this);
80
CellView.ApplicationContext.InvokeUserCode (delegate
82
DrawingContext ctx = new DrawingContext(dc, 1);
83
CellView.Draw (ctx, new Rectangle (this.RenderTransform.Value.OffsetX, this.RenderTransform.Value.OffsetY, this.RenderSize.Width, this.RenderSize.Height));
87
protected override System.Windows.Size MeasureOverride(System.Windows.Size constraint)
89
var size = new System.Windows.Size();
90
CellView.Initialize (this);
91
CellView.ApplicationContext.InvokeUserCode (delegate
93
var s = CellView.GetRequiredSize ();
94
size = new System.Windows.Size(s.Width, s.Height);
96
if (size.Width > constraint.Width)
97
size.Width = constraint.Width;
98
if (size.Height > constraint.Height)
99
size.Height = constraint.Height;
103
public object GetValue(IDataField field)
105
if (DataContext == null)
107
return ((ValuesContainer)DataContext)[field.Index];
10
class CanvasCellViewBackend: CellViewBackend, ICanvasCellViewBackend
12
public void QueueDraw()