~ubuntu-branches/ubuntu/feisty/monodevelop/feisty

« back to all changes in this revision

Viewing changes to Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/BaseToolboxNode.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-08-18 00:51:23 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060818005123-5iit07y0j7wjg55f
Tags: 0.11+svn20060818-0ubuntu1
* New SVN snapshot
  + Works with Gtk# 2.9.0
* debian/control:
  + Updated Build-Depends
* debian/patches/use_nunit2.2.dpatch,
  debian/patches/use_real_libs.dpatch:
  + Updated
* debian/patches/versioncontrol_buildfix.dpatch:
  + Fix build failure in the version control addin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 /* 
 
2
 * ToolboxNode.cs - Base class for holding tree in a NodeStore, with columns for TreeView.
 
3
 *                                              Shared functionality for ItemToolboxNodes and CategoryToolboxNodes.
 
4
 * 
 
5
 * Authors: 
 
6
 *  Michael Hutchinson <m.j.hutchinson@gmail.com>
 
7
 *  
 
8
 * Copyright (C) 2006 Michael Hutchinson
 
9
 *
 
10
 * This sourcecode is licenced under The MIT License:
 
11
 * 
 
12
 * Permission is hereby granted, free of charge, to any person obtaining
 
13
 * a copy of this software and associated documentation files (the
 
14
 * "Software"), to deal in the Software without restriction, including
 
15
 * without limitation the rights to use, copy, modify, merge, publish,
 
16
 * distribute, sublicense, and/or sell copies of the Software, and to permit
 
17
 * persons to whom the Software is furnished to do so, subject to the
 
18
 * following conditions:
 
19
 * 
 
20
 * The above copyright notice and this permission notice shall be included in
 
21
 * all copies or substantial portions of the Software.
 
22
 *
 
23
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
24
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
25
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
 
26
 * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 
27
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 
28
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 
29
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 
30
 */
 
31
 
 
32
using System;
 
33
using System.Drawing.Design;
 
34
using Gtk;
 
35
 
 
36
namespace MonoDevelop.DesignerSupport.Toolbox
 
37
{
 
38
        [Serializable]
 
39
        public abstract class BaseToolboxNode : Gtk.ITreeNode
 
40
        {
 
41
                private static Gdk.Pixbuf _defaultIcon;
 
42
                private static Gdk.Color _defaultColor;
 
43
                private static int nextId = int.MinValue;
 
44
                [NonSerialized]
 
45
                private int id;
 
46
                [NonSerialized]
 
47
                private ITreeNode parent = null;
 
48
                
 
49
                public BaseToolboxNode ()
 
50
                {
 
51
                        id = nextId;
 
52
                        nextId++;
 
53
                        if (nextId == int.MaxValue)
 
54
                                throw new InvalidOperationException ("Have run out of integer indices for ToolboxNodes");
 
55
                }
 
56
                
 
57
                
 
58
                private Gdk.Pixbuf defaultIcon {
 
59
                        get {
 
60
                                if (_defaultIcon == null) {
 
61
                                        Gtk.Label lab = new Gtk.Label ();
 
62
                                        lab.EnsureStyle ();
 
63
                                        _defaultIcon = lab.RenderIcon (Stock.MissingImage, IconSize.SmallToolbar, string.Empty);
 
64
                                        lab.Destroy ();
 
65
                                }
 
66
                                return _defaultIcon;
 
67
                        }
 
68
                }
 
69
                
 
70
                private Gdk.Color defaultColor {
 
71
                        get {
 
72
                                if (_defaultIcon == null) {
 
73
                                        Gtk.Label lab = new Gtk.Label ();
 
74
                                        lab.EnsureStyle ();
 
75
                                        _defaultColor = lab.Style.Base (Gtk.StateType.Normal);
 
76
                                        lab.Destroy ();
 
77
                                }
 
78
                                return _defaultColor;
 
79
                        }
 
80
                }
 
81
 
 
82
                //return true if the search is successful
 
83
                //should remove children if they fail test
 
84
                public abstract bool Filter (string keyword);
 
85
                
 
86
                #region Tree columns
 
87
 
 
88
                [TreeNodeValue (Column=0)]
 
89
                public virtual Gdk.Pixbuf ViewIcon {
 
90
                        get { return defaultIcon; }
 
91
                }
 
92
                
 
93
                [TreeNodeValue (Column=1)]
 
94
                public abstract string Label {
 
95
                        get;
 
96
                }
 
97
                
 
98
                [TreeNodeValue (Column=2)]
 
99
                public virtual int FontWeight {
 
100
                        get { return 400; }
 
101
                }
 
102
                
 
103
                [TreeNodeValue (Column=3)]
 
104
                public virtual Gdk.Color BackgroundColour {
 
105
                        get { return defaultColor; }
 
106
                }
 
107
                
 
108
                [TreeNodeValue (Column=4)]
 
109
                public virtual bool IconVisible {
 
110
                        get { return true; }
 
111
                }
 
112
                
 
113
                [TreeNodeValue (Column=5)]
 
114
                public virtual bool ExpanderVisible {
 
115
                        get { return false; }
 
116
                }
 
117
                
 
118
                [TreeNodeValue (Column=6)]
 
119
                public virtual bool CanDrag {
 
120
                        get { return true; }
 
121
                }
 
122
                
 
123
                #endregion Tree columns
 
124
                
 
125
                #region ITreeNode Members
 
126
                
 
127
                public virtual int ChildCount {
 
128
                        get { return 0 ; }
 
129
                }
 
130
                
 
131
                public virtual int ID {
 
132
                        get { return id; }
 
133
                }
 
134
                
 
135
        public virtual ITreeNode this [int i] {
 
136
                get { throw new System.IndexOutOfRangeException (); }
 
137
        }
 
138
        
 
139
        public ITreeNode Parent {
 
140
                        get { return parent; }
 
141
        }
 
142
        
 
143
        internal void SetParent (ITreeNode parent)
 
144
        {
 
145
                this.parent = parent;
 
146
        }
 
147
        
 
148
        public virtual int IndexOf (object o)
 
149
        {
 
150
                return -1;
 
151
        }
 
152
        
 
153
        [field:NonSerialized]
 
154
        public event System.EventHandler Changed;
 
155
                [field:NonSerialized]
 
156
                public event TreeNodeAddedHandler ChildAdded;
 
157
                [field:NonSerialized]
 
158
                public event TreeNodeRemovedHandler ChildRemoved;
 
159
                
 
160
                protected void OnChanged ()
 
161
                {
 
162
                        if (Changed != null)
 
163
                                Changed (this, new EventArgs ());
 
164
                }
 
165
                
 
166
                protected void OnChildAdded (ITreeNode node)
 
167
                {
 
168
                        if (ChildAdded != null)
 
169
                                ChildAdded (this, node);
 
170
                }
 
171
                
 
172
                protected void OnChildRemoved (ITreeNode node, int oldPosition)
 
173
                {
 
174
                        if (ChildRemoved != null)
 
175
                                ChildRemoved (this, node, oldPosition);
 
176
                }
 
177
                
 
178
                #endregion ITreeNode Members
 
179
        }
 
180
}