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.Windows.Markup;
33
public class Notebook: Widget
35
ChildrenCollection<NotebookTab> tabs;
36
EventHandler currentTabChanged;
38
protected new class WidgetBackendHost: Widget.WidgetBackendHost, INotebookEventSink, ICollectionEventSink<NotebookTab>, IContainerEventSink<NotebookTab>
40
public void AddedItem (NotebookTab item, int index)
42
((Notebook)Parent).OnAdd (item);
45
public void RemovedItem (NotebookTab item, int index)
47
((Notebook)Parent).OnRemove (item.Child);
50
public void ChildChanged (NotebookTab child, string hint)
52
((Notebook)Parent).Backend.UpdateLabel (child, hint);
53
((Notebook)Parent).OnPreferredSizeChanged ();
56
public void ChildReplaced (NotebookTab child, Widget oldWidget, Widget newWidget)
58
((Notebook)Parent).OnReplaceChild (child, oldWidget, newWidget);
61
public void OnCurrentTabChanged ()
63
((Notebook)Parent).OnCurrentTabChanged (EventArgs.Empty);
69
MapEvent (NotebookEvent.CurrentTabChanged, typeof(Notebook), "OnCurrentTabChanged");
74
tabs = new ChildrenCollection <NotebookTab> ((WidgetBackendHost) BackendHost);
77
protected override BackendHost CreateBackendHost ()
79
return new WidgetBackendHost ();
82
INotebookBackend Backend {
83
get { return (INotebookBackend) BackendHost.Backend; }
86
public void Add (Widget w, string label)
88
NotebookTab t = new NotebookTab ((WidgetBackendHost)BackendHost, w);
93
void OnRemove (Widget child)
95
UnregisterChild (child);
96
Backend.Remove ((IWidgetBackend)GetBackend (child));
97
OnPreferredSizeChanged ();
100
void OnAdd (NotebookTab tab)
102
RegisterChild (tab.Child);
103
Backend.Add ((IWidgetBackend)GetBackend (tab.Child), tab);
104
OnPreferredSizeChanged ();
107
void OnReplaceChild (NotebookTab tab, Widget oldWidget, Widget newWidget)
109
if (oldWidget != null)
110
OnRemove (oldWidget);
114
public ChildrenCollection<NotebookTab> Tabs {
118
public NotebookTab CurrentTab {
120
return tabs [Backend.CurrentTab];
123
for (int n=0; n<tabs.Count; n++) {
124
if (tabs[n] == value) {
125
Backend.CurrentTab = n;
129
CurrentTabIndex = -1;
133
public int CurrentTabIndex {
134
get { return Backend.CurrentTab; }
135
set { Backend.CurrentTab = value; }
138
public NotebookTabOrientation TabOrientation {
139
get { return Backend.TabOrientation; }
140
set { Backend.TabOrientation = value; }
143
protected virtual void OnCurrentTabChanged (EventArgs e)
145
if (currentTabChanged != null)
146
currentTabChanged (this, e);
149
public event EventHandler CurrentTabChanged {
151
BackendHost.OnBeforeEventAdd (NotebookEvent.CurrentTabChanged, currentTabChanged);
152
currentTabChanged += value;
155
currentTabChanged -= value;
156
BackendHost.OnAfterEventRemove (NotebookEvent.CurrentTabChanged, currentTabChanged);
161
[ContentProperty("Child")]
162
public class NotebookTab
164
IContainerEventSink<NotebookTab> parent;
168
internal NotebookTab (IContainerEventSink<NotebookTab> parent, Widget child)
171
this.parent = parent;
174
public string Label {
180
parent.ChildChanged (this, "Label");
184
public Widget Child {
191
parent.ChildReplaced (this, oldVal, value);
196
public enum NotebookTabOrientation {