5
// Lluis Sanchez <lluis@xamarin.com>
7
// Copyright (c) 2011 Xamarin Inc
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
30
using MonoMac.Foundation;
32
using System.Collections.Generic;
37
class CompositeCell: NSCell
41
List<ICellRenderer> cells = new List<ICellRenderer> ();
42
Orientation direction;
44
public CompositeCell (Orientation dir, ICellSource source)
50
public CompositeCell (IntPtr p): base (p)
54
public override NSObject ObjectValue {
60
if (val is ITablePosition)
61
Fill (((ITablePosition)val).Position);
65
public void AddCell (ICellRenderer cell)
70
public void Fill (object pos)
72
if (source == null || pos == null)
75
if (s.Height > source.RowHeight)
76
source.RowHeight = s.Height;
77
foreach (var c in cells)
81
public override void CalcDrawInfo (RectangleF aRect)
83
base.CalcDrawInfo (aRect);
86
public override SizeF CellSizeForBounds (RectangleF bounds)
88
return base.CellSizeForBounds (bounds);
91
public override SizeF CellSize {
95
foreach (NSCell c in cells) {
97
if (direction == Orientation.Horizontal) {
107
return new SizeF (w, h);
111
public override RectangleF DrawingRectForBounds (RectangleF theRect)
113
return base.DrawingRectForBounds (theRect);
116
public override NSCellStateValue State {
122
foreach (NSCell c in cells)
127
public override bool Highlighted {
129
return base.Highlighted;
132
base.Highlighted = value;
133
foreach (NSCell c in cells)
134
c.Highlighted = value;
138
public override void DrawWithFrame (RectangleF cellFrame, NSView inView)
140
foreach (CellPos cp in GetCells(cellFrame)) {
141
cp.Cell.DrawWithFrame (cp.Frame, inView);
145
public override void Highlight (bool flag, RectangleF withFrame, NSView inView)
147
foreach (CellPos cp in GetCells(withFrame)) {
148
cp.Cell.Highlight (flag, cp.Frame, inView);
152
public override NSCellHit HitTest (NSEvent forEvent, RectangleF inRect, NSView ofView)
154
foreach (CellPos cp in GetCells(inRect)) {
155
var h = cp.Cell.HitTest (forEvent, cp.Frame, ofView);
156
if (h != NSCellHit.None)
159
return NSCellHit.None;
164
public override bool StartTracking (PointF startPoint, NSView inView)
166
foreach (NSCell c in cells) {
167
if (c.StartTracking (startPoint, inView)) {
175
public override void StopTracking (PointF lastPoint, PointF stopPoint, NSView inView, bool mouseIsUp)
177
if (trackingCell != null) {
179
trackingCell.StopTracking (lastPoint, stopPoint, inView, mouseIsUp);
186
public override bool ContinueTracking (PointF lastPoint, PointF currentPoint, NSView inView)
188
if (trackingCell != null)
189
return trackingCell.ContinueTracking (lastPoint, currentPoint, inView);
194
IEnumerable<CellPos> GetCells (RectangleF cellFrame)
196
if (direction == Orientation.Horizontal) {
197
float x = cellFrame.X;
198
foreach (NSCell c in cells) {
200
RectangleF f = new RectangleF (x, cellFrame.Y, s.Width, s.Height);
202
yield return new CellPos () { Cell = c, Frame = f };
205
float y = cellFrame.Y;
206
foreach (NSCell c in cells) {
208
RectangleF f = new RectangleF (cellFrame.X, y, s.Width, s.Height);
210
yield return new CellPos () { Cell = c, Frame = f };
218
public RectangleF Frame;