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

« back to all changes in this revision

Viewing changes to external/xwt/Xwt.Mac/Xwt.Mac/NotebookBackend.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
// NotebookBackend.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 MonoMac.AppKit;
 
29
using Xwt.Backends;
 
30
using System.Collections.Generic;
 
31
using Xwt.Engine;
 
32
 
 
33
namespace Xwt.Mac
 
34
{
 
35
        public class NotebookBackend: ViewBackend<NSTabView,IWidgetEventSink>, INotebookBackend
 
36
        {
 
37
                public NotebookBackend ()
 
38
                {
 
39
                        ViewObject = new TabView ();
 
40
                        Widget.AutoresizesSubviews = true;
 
41
                }
 
42
                
 
43
                public override void EnableEvent (object eventId)
 
44
                {
 
45
                        if (eventId is NotebookEvent) {
 
46
                                NotebookEvent ev = (NotebookEvent) eventId;
 
47
                                if (ev == NotebookEvent.CurrentTabChanged) {
 
48
                                        Widget.WillSelect += HandleWidgetWillSelect;
 
49
                                }
 
50
                        }
 
51
                        base.EnableEvent (eventId);
 
52
                }
 
53
                
 
54
                public override void DisableEvent (object eventId)
 
55
                {
 
56
                        if (eventId is NotebookEvent) {
 
57
                                NotebookEvent ev = (NotebookEvent) eventId;
 
58
                                if (ev == NotebookEvent.CurrentTabChanged) {
 
59
                                        Widget.WillSelect -= HandleWidgetWillSelect;
 
60
                                }
 
61
                        }
 
62
                        base.DisableEvent (eventId);
 
63
                }
 
64
 
 
65
                void HandleWidgetWillSelect (object sender, NSTabViewItemEventArgs e)
 
66
                {
 
67
                        ((INotebookEventSink)EventSink).OnCurrentTabChanged ();
 
68
                }
 
69
 
 
70
                #region INotebookBackend implementation
 
71
                public void Add (IWidgetBackend widget, NotebookTab tab)
 
72
                {
 
73
                        NSTabViewItem item = new NSTabViewItem ();
 
74
                        item.Label = tab.Label;
 
75
                        item.View = GetWidget (widget);
 
76
                        Widget.Add (item);
 
77
                }
 
78
 
 
79
                public void Remove (IWidgetBackend widget)
 
80
                {
 
81
                        var v = GetWidget (widget);
 
82
                        var t = FindTab (v);
 
83
                        if (t != null)
 
84
                                Widget.Remove (t);
 
85
                }
 
86
                
 
87
                public void UpdateLabel (NotebookTab tab, string hint)
 
88
                {
 
89
                        IWidgetBackend widget = (IWidgetBackend) WidgetRegistry.GetBackend (tab.Child);
 
90
                        var v = GetWidget (widget);
 
91
                        var t = FindTab (v);
 
92
                        if (t != null)
 
93
                                t.Label = tab.Label;
 
94
                }
 
95
                
 
96
                public int CurrentTab {
 
97
                        get {
 
98
                                return Widget.IndexOf (Widget.Selected);
 
99
                        }
 
100
                        set {
 
101
                                Widget.SelectAt (value);
 
102
                        }
 
103
                }
 
104
 
 
105
                public Xwt.NotebookTabOrientation TabOrientation {
 
106
                        get {
 
107
                                NotebookTabOrientation tabPos = NotebookTabOrientation.Top;
 
108
                                switch (Widget.TabViewType) {
 
109
                                case NSTabViewType.NSBottomTabsBezelBorder:
 
110
                                        tabPos = NotebookTabOrientation.Bottom;
 
111
                                        break;
 
112
                                case NSTabViewType.NSLeftTabsBezelBorder:
 
113
                                        tabPos = NotebookTabOrientation.Left;
 
114
                                        break;
 
115
                                case NSTabViewType.NSRightTabsBezelBorder:
 
116
                                        tabPos = NotebookTabOrientation.Right;
 
117
                                        break;
 
118
                                }
 
119
                                return tabPos;
 
120
                        }
 
121
                        set {
 
122
                                NSTabViewType type = NSTabViewType.NSTopTabsBezelBorder;
 
123
                                switch (value) {
 
124
                                case NotebookTabOrientation.Bottom:
 
125
                                        type = NSTabViewType.NSBottomTabsBezelBorder;
 
126
                                        break;
 
127
                                case NotebookTabOrientation.Left:
 
128
                                        type = NSTabViewType.NSLeftTabsBezelBorder;
 
129
                                        break;
 
130
                                case NotebookTabOrientation.Right:
 
131
                                        type = NSTabViewType.NSRightTabsBezelBorder;
 
132
                                        break;
 
133
                                }
 
134
                                Widget.TabViewType = type;
 
135
                        }
 
136
                }
 
137
                #endregion
 
138
                
 
139
                NSTabViewItem FindTab (NSView v)
 
140
                {
 
141
                        foreach (var t in Widget.Items) {
 
142
                                if (t.View == v)
 
143
                                        return t;
 
144
                        }
 
145
                        return null;
 
146
                }
 
147
        }
 
148
        
 
149
        class TabView: NSTabView, IViewObject
 
150
        {
 
151
                public Widget Frontend { get; set; }
 
152
                public NSView View {
 
153
                        get { return this; }
 
154
                }
 
155
        }
 
156
}
 
157