~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/xwt/Xwt.Mac/Xwt.Mac.CellViews/CompositeCell.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// CompositeCell.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez <lluis@xamarin.com>
 
6
// 
 
7
// Copyright (c) 2011 Xamarin Inc
 
8
// 
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
 
 
27
 
 
28
using System;
 
29
using MonoMac.AppKit;
 
30
using MonoMac.Foundation;
 
31
using Xwt.Backends;
 
32
using System.Collections.Generic;
 
33
using System.Drawing;
 
34
 
 
35
namespace Xwt.Mac
 
36
{
 
37
        class CompositeCell: NSCell
 
38
        {
 
39
                ICellSource source;
 
40
                NSObject val;
 
41
                List<ICellRenderer> cells = new List<ICellRenderer> ();
 
42
                Orientation direction;
 
43
                
 
44
                public CompositeCell (Orientation dir, ICellSource source)
 
45
                {
 
46
                        direction = dir;
 
47
                        this.source = source;
 
48
                }
 
49
                
 
50
                public CompositeCell (IntPtr p): base (p)
 
51
                {
 
52
                }
 
53
                
 
54
                public override NSObject ObjectValue {
 
55
                        get {
 
56
                                return val;
 
57
                        }
 
58
                        set {
 
59
                                val = value;
 
60
                                if (val is ITablePosition)
 
61
                                        Fill (((ITablePosition)val).Position);
 
62
                        }
 
63
                }
 
64
                
 
65
                public void AddCell (ICellRenderer cell)
 
66
                {
 
67
                        cells.Add (cell);
 
68
                }
 
69
                
 
70
                public void Fill (object pos)
 
71
                {
 
72
                        if (source == null || pos == null)
 
73
                                return;
 
74
                        var s = CellSize;
 
75
                        if (s.Height > source.RowHeight)
 
76
                                source.RowHeight = s.Height;
 
77
                        foreach (var c in cells)
 
78
                                c.Fill (source, pos);
 
79
                }
 
80
                
 
81
                public override void CalcDrawInfo (RectangleF aRect)
 
82
                {
 
83
                        base.CalcDrawInfo (aRect);
 
84
                }
 
85
                
 
86
                public override SizeF CellSizeForBounds (RectangleF bounds)
 
87
                {
 
88
                        return base.CellSizeForBounds (bounds);
 
89
                }
 
90
                
 
91
                public override SizeF CellSize {
 
92
                        get {
 
93
                                float w = 0;
 
94
                                float h = 0;
 
95
                                foreach (NSCell c in cells) {
 
96
                                        var s = c.CellSize;
 
97
                                        if (direction == Orientation.Horizontal) {
 
98
                                                w += s.Width;
 
99
                                                if (s.Height > h)
 
100
                                                        h = s.Height;
 
101
                                        } else {
 
102
                                                h += s.Height;
 
103
                                                if (s.Width > w)
 
104
                                                        w = s.Width;
 
105
                                        }
 
106
                                }
 
107
                                return new SizeF (w, h);
 
108
                        }
 
109
                }
 
110
                
 
111
                public override RectangleF DrawingRectForBounds (RectangleF theRect)
 
112
                {
 
113
                        return base.DrawingRectForBounds (theRect);
 
114
                }
 
115
                
 
116
                public override NSCellStateValue State {
 
117
                        get {
 
118
                                return base.State;
 
119
                        }
 
120
                        set {
 
121
                                base.State = value;
 
122
                                foreach (NSCell c in cells)
 
123
                                        c.State = value;
 
124
                        }
 
125
                }
 
126
                
 
127
                public override bool Highlighted {
 
128
                        get {
 
129
                                return base.Highlighted;
 
130
                        }
 
131
                        set {
 
132
                                base.Highlighted = value;
 
133
                                foreach (NSCell c in cells)
 
134
                                        c.Highlighted = value;
 
135
                        }
 
136
                }
 
137
                
 
138
                public override void DrawWithFrame (RectangleF cellFrame, NSView inView)
 
139
                {
 
140
                        foreach (CellPos cp in GetCells(cellFrame)) {
 
141
                                cp.Cell.DrawWithFrame (cp.Frame, inView);
 
142
                        }
 
143
                }
 
144
                
 
145
                public override void Highlight (bool flag, RectangleF withFrame, NSView inView)
 
146
                {
 
147
                        foreach (CellPos cp in GetCells(withFrame)) {
 
148
                                cp.Cell.Highlight (flag, cp.Frame, inView);
 
149
                        }
 
150
                }
 
151
                
 
152
                public override NSCellHit HitTest (NSEvent forEvent, RectangleF inRect, NSView ofView)
 
153
                {
 
154
                        foreach (CellPos cp in GetCells(inRect)) {
 
155
                                var h = cp.Cell.HitTest (forEvent, cp.Frame, ofView);
 
156
                                if (h != NSCellHit.None)
 
157
                                        return h;
 
158
                        }
 
159
                        return NSCellHit.None;
 
160
                }
 
161
                
 
162
                NSCell trackingCell;
 
163
                
 
164
                public override bool StartTracking (PointF startPoint, NSView inView)
 
165
                {
 
166
                        foreach (NSCell c in cells) {
 
167
                                if (c.StartTracking (startPoint, inView)) {
 
168
                                        trackingCell = c;
 
169
                                        return true;
 
170
                                }
 
171
                        }
 
172
                        return false;
 
173
                }
 
174
                
 
175
                public override void StopTracking (PointF lastPoint, PointF stopPoint, NSView inView, bool mouseIsUp)
 
176
                {
 
177
                        if (trackingCell != null) {
 
178
                                try {
 
179
                                        trackingCell.StopTracking (lastPoint, stopPoint, inView, mouseIsUp);
 
180
                                } finally {
 
181
                                        trackingCell = null;
 
182
                                }
 
183
                        }
 
184
                }
 
185
                
 
186
                public override bool ContinueTracking (PointF lastPoint, PointF currentPoint, NSView inView)
 
187
                {
 
188
                        if (trackingCell != null)
 
189
                                return trackingCell.ContinueTracking (lastPoint, currentPoint, inView);
 
190
                        else
 
191
                                return false;
 
192
                }
 
193
                
 
194
                IEnumerable<CellPos> GetCells (RectangleF cellFrame)
 
195
                {
 
196
                        if (direction == Orientation.Horizontal) {
 
197
                                float x = cellFrame.X;
 
198
                                foreach (NSCell c in cells) {
 
199
                                        var s = c.CellSize;
 
200
                                        RectangleF f = new RectangleF (x, cellFrame.Y, s.Width, s.Height);
 
201
                                        x += s.Width;
 
202
                                        yield return new CellPos () { Cell = c, Frame = f };
 
203
                                }
 
204
                        } else {
 
205
                                float y = cellFrame.Y;
 
206
                                foreach (NSCell c in cells) {
 
207
                                        var s = c.CellSize;
 
208
                                        RectangleF f = new RectangleF (cellFrame.X, y, s.Width, s.Height);
 
209
                                        y += s.Height;
 
210
                                        yield return new CellPos () { Cell = c, Frame = f };
 
211
                                }
 
212
                        }
 
213
                }
 
214
                
 
215
                struct CellPos
 
216
                {
 
217
                        public NSCell Cell;
 
218
                        public RectangleF Frame;
 
219
                }
 
220
        }
 
221
}