5
// Thomas Ziegler <ziegler.thomas@web.de>
6
// Eric Maupin <ermau@xamarin.com>
8
// Copyright (c) 2012 Thomas Ziegler
9
// Copyright (c) 2012 Xamarin, Inc.
11
// Permission is hereby granted, free of charge, to any person obtaining a copy
12
// of this software and associated documentation files (the "Software"), to deal
13
// in the Software without restriction, including without limitation the rights
14
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
// copies of the Software, and to permit persons to whom the Software is
16
// furnished to do so, subject to the following conditions:
18
// The above copyright notice and this permission notice shall be included in
19
// all copies or substantial portions of the Software.
21
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29
using System.Collections.Generic;
32
using System.Windows.Controls;
34
using SWC = System.Windows.Controls;
37
namespace Xwt.WPFBackend
39
public class NotebookBackend : WidgetBackend, INotebookBackend
41
public NotebookBackend ()
43
TabControl = new WpfNotebook ();
46
public int CurrentTab {
47
get { return TabControl.SelectedIndex; }
48
set { TabControl.SelectedIndex = value; }
51
public Xwt.NotebookTabOrientation TabOrientation {
53
Xwt.NotebookTabOrientation tabPos = Xwt.NotebookTabOrientation.Top;
54
Enum.TryParse (TabControl.TabStripPlacement.ToString (), out tabPos);
58
SWC.Dock tabPos = SWC.Dock.Top;
59
Enum.TryParse (value.ToString (), out tabPos);
60
TabControl.TabStripPlacement = tabPos;
64
public void Add (IWidgetBackend widget, NotebookTab tab)
66
UIElement element = (UIElement)widget.NativeWidget;
67
TabItem ti = new TabItem {
73
FrameworkElement felement = element as FrameworkElement;
74
if (felement != null) {
75
felement.Tag = widget;
76
felement.Loaded += OnContentLoaded;
79
TabControl.Items.Add (ti);
81
if (TabControl.SelectedIndex == -1)
82
TabControl.SelectedIndex = 0;
85
public void Remove (IWidgetBackend widget)
87
UIElement element = widget.NativeWidget as UIElement;
89
throw new ArgumentException ();
91
FrameworkElement felement = element as FrameworkElement;
93
felement.Loaded -= OnContentLoaded;
95
for (int i = 0; i < TabControl.Items.Count; ++i) {
96
TabItem tab = (TabItem)TabControl.Items [i];
97
if (tab.Content == widget.NativeWidget) {
98
TabControl.Items.RemoveAt (i);
104
public void UpdateLabel (NotebookTab tab, string hint)
106
TabItem item = TabControl.Items.Cast<TabItem> ().FirstOrDefault (t => t.Tag == tab);
108
item.Header = tab.Label;
111
public override void EnableEvent (object eventId)
113
base.EnableEvent (eventId);
114
if (eventId is NotebookEvent) {
115
switch ((NotebookEvent)eventId) {
116
case NotebookEvent.CurrentTabChanged:
117
TabControl.SelectionChanged += OnCurrentTabChanged;
123
public override void DisableEvent (object eventId)
125
base.DisableEvent (eventId);
126
if (eventId is NotebookEvent) {
127
switch ((NotebookEvent)eventId) {
128
case NotebookEvent.CurrentTabChanged:
129
TabControl.SelectionChanged -= OnCurrentTabChanged;
135
private void OnCurrentTabChanged (object sender, SelectionChangedEventArgs e)
137
Toolkit.Invoke (NotebookEventSink.OnCurrentTabChanged);
140
protected TabControl TabControl {
141
get { return (TabControl)Widget; }
142
set { Widget = value; }
145
protected INotebookEventSink NotebookEventSink {
146
get { return (INotebookEventSink) EventSink; }
149
private void OnContentLoaded (object sender, RoutedEventArgs routedEventArgs)
151
WidgetBackend backend = (WidgetBackend)((FrameworkElement) sender).Tag;
153
var surface = backend.Frontend as IWidgetSurface;
157
surface.Reallocate();
161
class WpfNotebook : SWC.TabControl, IWpfWidget
163
public WidgetBackend Backend { get; set; }
165
protected override System.Windows.Size MeasureOverride (System.Windows.Size constraint)
167
var s = base.MeasureOverride (constraint);
168
return Backend.MeasureOverride (constraint, s);
b'\\ No newline at end of file'