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
29
using System.ComponentModel;
34
public class ListView: Widget, IColumnContainer, IScrollableWidget
36
ListViewColumnCollection columns;
37
IListDataSource dataSource;
40
protected new class WidgetBackendHost: Widget.WidgetBackendHost<ListView,IListViewBackend>, IListViewEventSink
42
protected override void OnBackendCreated ()
44
base.OnBackendCreated ();
45
Parent.columns.Attach (Backend);
48
public void OnSelectionChanged ()
50
((ListView)Parent).OnSelectionChanged (EventArgs.Empty);
53
public override Size GetDefaultNaturalSize ()
55
return Xwt.Backends.DefaultNaturalSizes.ListView;
61
MapEvent (TableViewEvent.SelectionChanged, typeof(ListView), "OnSelectionChanged");
64
public ListView (IListDataSource source): this ()
71
columns = new ListViewColumnCollection (this);
72
VerticalScrollPolicy = HorizontalScrollPolicy = ScrollPolicy.Automatic;
75
protected override BackendHost CreateBackendHost ()
77
return new WidgetBackendHost ();
80
IListViewBackend Backend {
81
get { return (IListViewBackend) BackendHost.Backend; }
84
public bool BorderVisible
86
get { return Backend.BorderVisible; }
87
set { Backend.BorderVisible = value; }
90
public ScrollPolicy VerticalScrollPolicy {
91
get { return Backend.VerticalScrollPolicy; }
92
set { Backend.VerticalScrollPolicy = value; }
95
public ScrollPolicy HorizontalScrollPolicy {
96
get { return Backend.HorizontalScrollPolicy; }
97
set { Backend.HorizontalScrollPolicy = value; }
100
public ListViewColumnCollection Columns {
106
public IListDataSource DataSource {
111
if (dataSource != value) {
113
Backend.SetSource (dataSource, dataSource is IFrontend ? (IBackend) WidgetRegistry.GetBackend (dataSource) : null);
118
public bool HeadersVisible {
120
return Backend.HeadersVisible;
123
Backend.HeadersVisible = value;
127
public SelectionMode SelectionMode {
133
Backend.SetSelectionMode (mode);
137
public int SelectedRow {
139
var items = SelectedRows;
140
if (items.Length == 0)
147
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
148
public int[] SelectedRows {
150
return Backend.SelectedRows;
154
public void SelectRow (int row)
156
Backend.SelectRow (row);
159
public void UnselectRow (int row)
161
Backend.UnselectRow (row);
164
public void SelectAll ()
166
Backend.SelectAll ();
169
public void UnselectAll ()
171
Backend.UnselectAll ();
174
void IColumnContainer.NotifyColumnsChanged ()
178
protected virtual void OnSelectionChanged (EventArgs a)
180
if (selectionChanged != null)
181
selectionChanged (this, a);
184
EventHandler selectionChanged;
186
public event EventHandler SelectionChanged {
188
BackendHost.OnBeforeEventAdd (TableViewEvent.SelectionChanged, selectionChanged);
189
selectionChanged += value;
192
selectionChanged -= value;
193
BackendHost.OnAfterEventRemove (TableViewEvent.SelectionChanged, selectionChanged);