~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Components/MonoDevelop.Components/NotebookButtonBar.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// NotebookButtonBar.cs
 
2
//
 
3
// Author:
 
4
//   Lluis Sanchez Gual <lluis@novell.com>
 
5
//
 
6
// Copyright (c) 2007 Novell, Inc (http://www.novell.com)
 
7
//
 
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
9
// of this software and associated documentation files (the "Software"), to deal
 
10
// in the Software without restriction, including without limitation the rights
 
11
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
12
// copies of the Software, and to permit persons to whom the Software is
 
13
// furnished to do so, subject to the following conditions:
 
14
//
 
15
// The above copyright notice and this permission notice shall be included in
 
16
// all copies or substantial portions of the Software.
 
17
//
 
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
23
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
24
// THE SOFTWARE.
 
25
//
 
26
//
 
27
 
 
28
using System;
 
29
using Gtk;
 
30
 
 
31
namespace MonoDevelop.Components
 
32
{
 
33
        [System.ComponentModel.Category("MonoDevelop.Components")]
 
34
        [System.ComponentModel.ToolboxItem(true)]
 
35
        public class NotebookButtonBar: Toolbar
 
36
        {
 
37
                Notebook notebook;
 
38
                bool updating;
 
39
                
 
40
                public NotebookButtonBar()
 
41
                {
 
42
                        IconSize = IconSize.Menu;
 
43
                        ToolbarStyle = ToolbarStyle.BothHoriz;
 
44
                        ShowArrow = false;
 
45
                        ShowAll ();
 
46
                }
 
47
                
 
48
                public Widget Notebook {
 
49
                        get { return notebook; }
 
50
                        set {
 
51
                                notebook = value as Notebook;
 
52
                                notebook.SwitchPage += OnPageChanged;
 
53
                                UpdateButtons ();
 
54
                                ShowPage (notebook.Page);
 
55
                        }
 
56
                }
 
57
                
 
58
                void OnPageChanged (object s, Gtk.SwitchPageArgs args)
 
59
                {
 
60
                        if (updating) return;
 
61
                        updating = true;
 
62
                        
 
63
                        Gtk.Widget[] buttons = Children;
 
64
                        for (int n=0; n<buttons.Length; n++) {
 
65
                                ToggleToolButton b = (ToggleToolButton) buttons [n];
 
66
                                b.Active = (n == args.PageNum);
 
67
                        }
 
68
 
 
69
                        updating = false;
 
70
                }
 
71
                
 
72
                void UpdateButtons ()
 
73
                {
 
74
                        updating = true;
 
75
                        
 
76
                        foreach (Gtk.Widget c in Children)
 
77
                                Remove (c);
 
78
                        foreach (Gtk.Widget page in notebook.Children) {
 
79
                                Gtk.Widget t = notebook.GetTabLabel (page);
 
80
                                notebook.SetTabLabel (page, new Gtk.Label (""));
 
81
                                Gtk.Widget nw;
 
82
                                if (t is Gtk.Label)
 
83
                                        nw = new Gtk.Label (((Gtk.Label)t).Text);
 
84
                                else
 
85
                                        nw = new Gtk.Label ("");
 
86
                                ToggleToolButton button = new ToggleToolButton ();
 
87
                                button.IsImportant = true;
 
88
                                button.LabelWidget = t;
 
89
                                button.Clicked += new EventHandler (OnButtonToggled);
 
90
                                button.ShowAll ();
 
91
                                Insert (button, -1);
 
92
                        }
 
93
                        updating = false;
 
94
                }
 
95
                
 
96
                public void SetButton (int index, string label, string icon)
 
97
                {
 
98
                        ToggleToolButton button = (ToggleToolButton) Children [index];
 
99
                        button.Label = label;
 
100
                        button.StockId = icon;
 
101
                }
 
102
                
 
103
                protected ToggleToolButton AddButton (string label, Gtk.Widget page)
 
104
                {
 
105
                        if (notebook == null)
 
106
                                return null;
 
107
                        updating = true;
 
108
                        ToggleToolButton button = new ToggleToolButton ();
 
109
                        button.Label = label;
 
110
                        button.IsImportant = true;
 
111
                        button.Clicked += new EventHandler (OnButtonToggled);
 
112
                        button.ShowAll ();
 
113
                        Insert (button, -1);
 
114
                        if (page != null)
 
115
                                notebook.AppendPage (page, new Gtk.Label ());
 
116
                        updating = false;
 
117
                        return button;
 
118
                }
 
119
                
 
120
                public void RemoveButton (int npage)
 
121
                {
 
122
                        if (notebook == null)
 
123
                                return;
 
124
                        notebook.RemovePage (npage);
 
125
                        Gtk.Widget cw = Children [npage];
 
126
                        Remove (cw);
 
127
                        cw.Destroy ();
 
128
                        ShowPage (0);
 
129
                }
 
130
                
 
131
                void OnButtonToggled (object s, EventArgs args)
 
132
                {
 
133
                        int i = Array.IndexOf (Children, s);
 
134
                        if (i != -1)
 
135
                                ShowPage (i);
 
136
                }
 
137
                
 
138
                public virtual void ShowPage (int npage)
 
139
                {
 
140
                        if (notebook.CurrentPage == npage) {
 
141
                                ToggleToolButton but = (ToggleToolButton) Children [npage];
 
142
                                but.Active = true;
 
143
                                return;
 
144
                        }
 
145
                                
 
146
                        if (updating) return;
 
147
                        
 
148
                        notebook.CurrentPage = npage;
 
149
                }
 
150
                
 
151
                protected override bool OnExposeEvent (Gdk.EventExpose evnt)
 
152
                {
 
153
                    GdkWindow.DrawRectangle (Style.BackgroundGC (State), true, Allocation);
 
154
            
 
155
            foreach (Widget child in Children) {
 
156
                PropagateExpose (child, evnt);
 
157
            }
 
158
                
 
159
                    return true;
 
160
                }
 
161
        }
 
162
}