~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/Main/ICSharpCode.SharpDevelop.Widgets/Project/SideBar/SideTabItem.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Drawing;
 
6
using System.Windows.Forms;
 
7
 
 
8
namespace ICSharpCode.SharpDevelop.Widgets.SideBar
 
9
{
 
10
        public enum SideTabItemStatus {
 
11
                Normal,
 
12
                Selected,
 
13
                Choosed,
 
14
                Drag
 
15
        }
 
16
        
 
17
        public class SideTabItem
 
18
        {
 
19
                string name;
 
20
                object tag;
 
21
                SideTabItemStatus sideTabItemStatus;
 
22
                Bitmap icon;
 
23
                bool canBeRenamed = true;
 
24
                bool canBeDeleted = true;
 
25
                
 
26
                public Bitmap Icon {
 
27
                        get {
 
28
                                return icon;
 
29
                        } //
 
30
                        set {
 
31
                                icon = value;
 
32
                        }
 
33
                }
 
34
                
 
35
                public SideTabItemStatus SideTabItemStatus {
 
36
                        get {
 
37
                                return sideTabItemStatus;
 
38
                        }
 
39
                        set {
 
40
                                sideTabItemStatus = value;
 
41
                        }
 
42
                }
 
43
                
 
44
                public string Name {
 
45
                        get {
 
46
                                return name;
 
47
                        }
 
48
                        set {
 
49
                                name = value;
 
50
                        }
 
51
                }
 
52
                
 
53
                public object Tag {
 
54
                        get {
 
55
                                return tag;
 
56
                        }
 
57
                        set {
 
58
                                tag = value;
 
59
                        }
 
60
                }
 
61
                
 
62
                public bool CanBeRenamed {
 
63
                        get {
 
64
                                return canBeRenamed;
 
65
                        }
 
66
                        set {
 
67
                                canBeRenamed = value;
 
68
                        }
 
69
                }
 
70
                
 
71
                public bool CanBeDeleted {
 
72
                        get {
 
73
                                return canBeDeleted;
 
74
                        }
 
75
                        set {
 
76
                                canBeDeleted = value;
 
77
                        }
 
78
                }
 
79
                
 
80
                public SideTabItem(string name)
 
81
                {
 
82
                        int idx = name.IndexOf("\n");
 
83
                        if (idx > 0) {
 
84
                                this.name = name.Substring(0, idx);
 
85
                        } else {
 
86
                                this.name = name;
 
87
                        }                       
 
88
                }
 
89
                
 
90
                public SideTabItem(string name, object tag) : this(name)
 
91
                {
 
92
                        this.tag = tag;
 
93
                }
 
94
                
 
95
                public SideTabItem(string name, object tag, Bitmap icon) : this(name, tag)
 
96
                {
 
97
                        this.icon = new Bitmap(icon);
 
98
                }
 
99
                
 
100
                public SideTabItem Clone()
 
101
                {
 
102
                        return (SideTabItem)MemberwiseClone();
 
103
                }
 
104
                
 
105
                public virtual void DrawItem(Graphics g, Font f, Rectangle rectangle)
 
106
                {
 
107
                        int width = 0;
 
108
                        switch (sideTabItemStatus) {
 
109
                                case SideTabItemStatus.Normal:
 
110
                                        if (Icon != null) {
 
111
                                                g.DrawImage(Icon, 0, rectangle.Y);
 
112
                                                width = Icon.Width;
 
113
                                        }
 
114
                                        g.DrawString(name, f, SystemBrushes.ControlText, new PointF(rectangle.X + width + 1, rectangle.Y + 1));
 
115
                                        break;
 
116
                                case SideTabItemStatus.Drag:
 
117
                                        ControlPaint.DrawBorder3D(g, rectangle, Border3DStyle.RaisedInner);
 
118
                                        rectangle.X += 1;
 
119
                                        rectangle.Y += 1;
 
120
                                        rectangle.Width  -= 2;
 
121
                                        rectangle.Height -= 2;
 
122
                                        
 
123
                                        g.FillRectangle(SystemBrushes.ControlDarkDark, rectangle);
 
124
                                        if (Icon != null) {
 
125
                                                g.DrawImage(Icon, 0, rectangle.Y);
 
126
                                                width = Icon.Width;
 
127
                                        }
 
128
                                        g.DrawString(name, f, SystemBrushes.HighlightText, new PointF(rectangle.X + width + 1, rectangle.Y + 1));
 
129
                                        break;
 
130
                                case SideTabItemStatus.Selected:
 
131
                                        ControlPaint.DrawBorder3D(g, rectangle, Border3DStyle.RaisedInner);
 
132
                                        if (Icon != null) {
 
133
                                                g.DrawImage(Icon, 0, rectangle.Y);
 
134
                                                width = Icon.Width;
 
135
                                        }
 
136
                                        g.DrawString(name, f, SystemBrushes.ControlText, new PointF(rectangle.X + width + 1, rectangle.Y + 1));
 
137
                                        break;
 
138
                                case SideTabItemStatus.Choosed:
 
139
                                        ControlPaint.DrawBorder3D(g, rectangle, Border3DStyle.Sunken);
 
140
                                        rectangle.X += 1;
 
141
                                        rectangle.Y += 1;
 
142
                                        rectangle.Width  -= 2;
 
143
                                        rectangle.Height -= 2;
 
144
                                        
 
145
                                        using (Brush brush = new SolidBrush(ControlPaint.Light(SystemColors.Control))) {
 
146
                                                g.FillRectangle(brush , rectangle);
 
147
                                        }
 
148
                                        
 
149
                                        if (Icon != null) {
 
150
                                                g.DrawImage(Icon, 1, rectangle.Y + 1);
 
151
                                                width = Icon.Width;
 
152
                                        }
 
153
                                        g.DrawString(name, f, SystemBrushes.ControlText, new PointF(rectangle.X + width + 2, rectangle.Y + 2));
 
154
                                        break;
 
155
                        }
 
156
                }
 
157
        }
 
158
}