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
namespace Xwt.GtkBackend
32
public class ComboBoxBackend: WidgetBackend, IComboBoxBackend, ICellRendererTarget
34
public ComboBoxBackend ()
38
public override void Initialize ()
40
Widget = (Gtk.ComboBox) CreateWidget ();
41
var cr = new Gtk.CellRendererText ();
42
Widget.PackStart (cr, false);
43
Widget.AddAttribute (cr, "text", 0);
45
Widget.RowSeparatorFunc = IsRowSeparator;
48
protected virtual Gtk.Widget CreateWidget ()
50
return new Gtk.ComboBox ();
53
protected new Gtk.ComboBox Widget {
54
get { return (Gtk.ComboBox)base.Widget; }
55
set { base.Widget = value; }
58
protected new IComboBoxEventSink EventSink {
59
get { return (IComboBoxEventSink)base.EventSink; }
62
bool IsRowSeparator (Gtk.TreeModel model, Gtk.TreeIter iter)
64
Gtk.TreePath path = model.GetPath (iter);
66
Toolkit.Invoke (delegate {
67
res = EventSink.RowIsSeparator (path.Indices[0]);
72
public override void EnableEvent (object eventId)
74
base.EnableEvent (eventId);
75
if (eventId is ComboBoxEvent) {
76
if ((ComboBoxEvent)eventId == ComboBoxEvent.SelectionChanged)
77
Widget.Changed += HandleChanged;
81
public override void DisableEvent (object eventId)
83
base.DisableEvent (eventId);
84
if (eventId is ComboBoxEvent) {
85
if ((ComboBoxEvent)eventId == ComboBoxEvent.SelectionChanged)
86
Widget.Changed -= HandleChanged;
90
void HandleChanged (object sender, EventArgs e)
92
Toolkit.Invoke (delegate {
93
EventSink.OnSelectionChanged ();
97
#region IComboBoxBackend implementation
98
public void SetViews (CellViewCollection views)
101
foreach (var v in views)
102
CellUtil.CreateCellRenderer (this, null, v);
105
public void SetSource (IListDataSource source, IBackend sourceBackend)
107
ListStoreBackend b = sourceBackend as ListStoreBackend;
109
CustomListModel model = new CustomListModel (source, Widget);
110
Widget.Model = model.Store;
112
Widget.Model = b.Store;
115
public int SelectedRow {
117
return Widget.Active;
120
Widget.Active = value;
125
#region ICellRendererTarget implementation
126
public void PackStart (object target, Gtk.CellRenderer cr, bool expand)
128
Widget.PackStart (cr, expand);
131
public void PackEnd (object target, Gtk.CellRenderer cr, bool expand)
133
Widget.PackEnd (cr, expand);
136
public void AddAttribute (object target, Gtk.CellRenderer cr, string field, int column)
138
Widget.AddAttribute (cr, field, column);