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

« back to all changes in this revision

Viewing changes to external/xwt/Xwt/Xwt/ListView.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
// ListView.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
using System;
 
28
using Xwt.Backends;
 
29
using System.ComponentModel;
 
30
using Xwt.Engine;
 
31
 
 
32
namespace Xwt
 
33
{
 
34
        public class ListView: Widget, IColumnContainer, IScrollableWidget
 
35
        {
 
36
                ListViewColumnCollection columns;
 
37
                IListDataSource dataSource;
 
38
                SelectionMode mode;
 
39
                
 
40
                protected new class WidgetBackendHost: Widget.WidgetBackendHost<ListView,IListViewBackend>, IListViewEventSink
 
41
                {
 
42
                        protected override void OnBackendCreated ()
 
43
                        {
 
44
                                base.OnBackendCreated ();
 
45
                                Parent.columns.Attach (Backend);
 
46
                        }
 
47
                        
 
48
                        public void OnSelectionChanged ()
 
49
                        {
 
50
                                ((ListView)Parent).OnSelectionChanged (EventArgs.Empty);
 
51
                        }
 
52
                        
 
53
                        public override Size GetDefaultNaturalSize ()
 
54
                        {
 
55
                                return Xwt.Backends.DefaultNaturalSizes.ListView;
 
56
                        }
 
57
                }
 
58
                
 
59
                static ListView ()
 
60
                {
 
61
                        MapEvent (TableViewEvent.SelectionChanged, typeof(ListView), "OnSelectionChanged");
 
62
                }
 
63
                
 
64
                public ListView (IListDataSource source): this ()
 
65
                {
 
66
                        DataSource = source;
 
67
                }
 
68
                
 
69
                public ListView ()
 
70
                {
 
71
                        columns = new ListViewColumnCollection (this);
 
72
                        VerticalScrollPolicy = HorizontalScrollPolicy = ScrollPolicy.Automatic;
 
73
                }
 
74
                
 
75
                protected override BackendHost CreateBackendHost ()
 
76
                {
 
77
                        return new WidgetBackendHost ();
 
78
                }
 
79
                
 
80
                IListViewBackend Backend {
 
81
                        get { return (IListViewBackend) BackendHost.Backend; }
 
82
                }
 
83
 
 
84
                public bool BorderVisible
 
85
                {
 
86
                        get { return Backend.BorderVisible; }
 
87
                        set { Backend.BorderVisible = value; }
 
88
                }
 
89
 
 
90
                public ScrollPolicy VerticalScrollPolicy {
 
91
                        get { return Backend.VerticalScrollPolicy; }
 
92
                        set { Backend.VerticalScrollPolicy = value; }
 
93
                }
 
94
                
 
95
                public ScrollPolicy HorizontalScrollPolicy {
 
96
                        get { return Backend.HorizontalScrollPolicy; }
 
97
                        set { Backend.HorizontalScrollPolicy = value; }
 
98
                }
 
99
                
 
100
                public ListViewColumnCollection Columns {
 
101
                        get {
 
102
                                return columns;
 
103
                        }
 
104
                }
 
105
                
 
106
                public IListDataSource DataSource {
 
107
                        get {
 
108
                                return dataSource;
 
109
                        }
 
110
                        set {
 
111
                                if (dataSource != value) {
 
112
                                        dataSource = value;
 
113
                                        Backend.SetSource (dataSource, dataSource is IFrontend ? (IBackend) WidgetRegistry.GetBackend (dataSource) : null);
 
114
                                }
 
115
                        }
 
116
                }
 
117
                
 
118
                public bool HeadersVisible {
 
119
                        get {
 
120
                                return Backend.HeadersVisible;
 
121
                        }
 
122
                        set {
 
123
                                Backend.HeadersVisible = value;
 
124
                        }
 
125
                }
 
126
                
 
127
                public SelectionMode SelectionMode {
 
128
                        get {
 
129
                                return mode;
 
130
                        }
 
131
                        set {
 
132
                                mode = value;
 
133
                                Backend.SetSelectionMode (mode);
 
134
                        }
 
135
                }
 
136
                
 
137
                public int SelectedRow {
 
138
                        get {
 
139
                                var items = SelectedRows;
 
140
                                if (items.Length == 0)
 
141
                                        return -1;
 
142
                                else
 
143
                                        return items [0];
 
144
                        }
 
145
                }
 
146
                
 
147
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
 
148
                public int[] SelectedRows {
 
149
                        get {
 
150
                                return Backend.SelectedRows;
 
151
                        }
 
152
                }
 
153
                
 
154
                public void SelectRow (int row)
 
155
                {
 
156
                        Backend.SelectRow (row);
 
157
                }
 
158
                
 
159
                public void UnselectRow (int row)
 
160
                {
 
161
                        Backend.UnselectRow (row);
 
162
                }
 
163
                
 
164
                public void SelectAll ()
 
165
                {
 
166
                        Backend.SelectAll ();
 
167
                }
 
168
                
 
169
                public void UnselectAll ()
 
170
                {
 
171
                        Backend.UnselectAll ();
 
172
                }
 
173
                
 
174
                void IColumnContainer.NotifyColumnsChanged ()
 
175
                {
 
176
                }
 
177
                
 
178
                protected virtual void OnSelectionChanged (EventArgs a)
 
179
                {
 
180
                        if (selectionChanged != null)
 
181
                                selectionChanged (this, a);
 
182
                }
 
183
                
 
184
                EventHandler selectionChanged;
 
185
                
 
186
                public event EventHandler SelectionChanged {
 
187
                        add {
 
188
                                BackendHost.OnBeforeEventAdd (TableViewEvent.SelectionChanged, selectionChanged);
 
189
                                selectionChanged += value;
 
190
                        }
 
191
                        remove {
 
192
                                selectionChanged -= value;
 
193
                                BackendHost.OnAfterEventRemove (TableViewEvent.SelectionChanged, selectionChanged);
 
194
                        }
 
195
                }       
 
196
        }
 
197
}
 
198