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

« back to all changes in this revision

Viewing changes to src/addins/Mono.Texteditor/Mono.TextEditor/IconMargin.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
// BookmarkMargin.cs
 
2
//
 
3
// Author:
 
4
//   Mike Krüger <mkrueger@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
using Gdk;
 
31
 
 
32
namespace Mono.TextEditor
 
33
{
 
34
        public class IconMargin : Margin
 
35
        {
 
36
                TextEditor editor;
 
37
                Gdk.GC backgroundGC, seperatorGC;
 
38
                Pango.Layout layout;
 
39
                int marginWidth = 18;
 
40
                
 
41
                public IconMargin (TextEditor editor)
 
42
                {
 
43
                        this.editor = editor;
 
44
                        layout = new Pango.Layout (editor.PangoContext);
 
45
                }
 
46
                
 
47
                public override int Width {
 
48
                        get {
 
49
                                return marginWidth;
 
50
                        }
 
51
                }
 
52
                
 
53
                public override void Dispose ()
 
54
                {
 
55
                        layout = layout.Kill ();
 
56
                        DisposeGCs ();
 
57
                }
 
58
                
 
59
                void DisposeGCs ()
 
60
                {
 
61
                        backgroundGC = backgroundGC.Kill ();
 
62
                        seperatorGC  = seperatorGC.Kill ();
 
63
                }
 
64
                
 
65
                internal protected override void OptionsChanged ()
 
66
                {
 
67
                        DisposeGCs ();
 
68
                        backgroundGC = new Gdk.GC (editor.GdkWindow);
 
69
                        backgroundGC.RgbFgColor = editor.ColorStyle.IconBarBg;
 
70
                        
 
71
                        seperatorGC = new Gdk.GC (editor.GdkWindow);
 
72
                        seperatorGC.RgbFgColor = editor.ColorStyle.IconBarSeperator;
 
73
                        
 
74
                        layout.FontDescription = editor.Options.Font;
 
75
                        layout.SetText ("!");
 
76
                        int tmp;
 
77
                        layout.GetPixelSize (out tmp, out this.marginWidth);
 
78
                        marginWidth *= 12;
 
79
                        marginWidth /= 10;
 
80
                }
 
81
                
 
82
                internal protected override void MousePressed (MarginMouseEventArgs args)
 
83
                {
 
84
                        base.MousePressed (args);
 
85
                        
 
86
                        LineSegment lineSegment = args.LineSegment;
 
87
                        if (lineSegment != null && lineSegment.Markers != null) {
 
88
                                foreach (TextMarker marker in lineSegment.Markers) {
 
89
                                        if (marker is IIconBarMarker) 
 
90
                                                ((IIconBarMarker)marker).MousePress (args);
 
91
                                }
 
92
                        }
 
93
                }
 
94
                
 
95
                internal protected override void MouseReleased (MarginMouseEventArgs args)
 
96
                {
 
97
                        base.MouseReleased (args);
 
98
                        
 
99
                        LineSegment lineSegment = args.LineSegment;
 
100
                        if (lineSegment != null && lineSegment.Markers != null) {
 
101
                                foreach (TextMarker marker in lineSegment.Markers) {
 
102
                                        if (marker is IIconBarMarker) 
 
103
                                                ((IIconBarMarker)marker).MouseRelease (args);
 
104
                                }
 
105
                        }
 
106
                }
 
107
                
 
108
                internal protected override void Draw (Gdk.Drawable win, Gdk.Rectangle area, int line, int x, int y)
 
109
                {
 
110
                        Gdk.Rectangle drawArea = new Gdk.Rectangle (x, y, Width, editor.LineHeight);
 
111
                        
 
112
                        win.DrawRectangle (backgroundGC, true, drawArea);
 
113
                        win.DrawLine (seperatorGC, x + Width - 1, drawArea.Top, x + Width - 1, drawArea.Bottom);
 
114
                        
 
115
                        if (line < editor.Document.LineCount) {
 
116
                                LineSegment lineSegment = editor.Document.GetLine (line);
 
117
                                
 
118
                                if (lineSegment.Markers != null) {
 
119
                                        foreach (TextMarker marker in lineSegment.Markers) {
 
120
                                                if (marker is IIconBarMarker) 
 
121
                                                        ((IIconBarMarker)marker).DrawIcon (editor, win, lineSegment, line, x, y, Width, editor.LineHeight);
 
122
                                        }
 
123
                                }
 
124
                                if (DrawEvent != null) 
 
125
                                        DrawEvent (this, new BookmarkMarginDrawEventArgs (editor, win, lineSegment, line, x, y));
 
126
                                
 
127
                        }
 
128
                        
 
129
                }
 
130
                
 
131
                public EventHandler<BookmarkMarginDrawEventArgs> DrawEvent;
 
132
        }
 
133
        
 
134
        public class BookmarkMarginDrawEventArgs : EventArgs
 
135
        {
 
136
                TextEditor editor;
 
137
                Gdk.Drawable win;
 
138
                LineSegment lineSegment;
 
139
                int line;
 
140
                int x;
 
141
                int y;
 
142
                
 
143
                public TextEditor Editor {
 
144
                        get {
 
145
                                return editor;
 
146
                        }
 
147
                }
 
148
 
 
149
                public Drawable Win {
 
150
                        get {
 
151
                                return win;
 
152
                        }
 
153
                }
 
154
 
 
155
                public int Line {
 
156
                        get {
 
157
                                return line;
 
158
                        }
 
159
                }
 
160
 
 
161
                public int X {
 
162
                        get {
 
163
                                return x;
 
164
                        }
 
165
                }
 
166
 
 
167
                public int Y {
 
168
                        get {
 
169
                                return y;
 
170
                        }
 
171
                }
 
172
 
 
173
                public LineSegment LineSegment {
 
174
                        get {
 
175
                                return lineSegment;
 
176
                        }
 
177
                }
 
178
                
 
179
                public BookmarkMarginDrawEventArgs (TextEditor editor, Gdk.Drawable win, LineSegment line, int lineNumber, int xPos, int yPos)
 
180
                {
 
181
                        this.editor = editor;
 
182
                        this.win    = win;
 
183
                        this.lineSegment = line;
 
184
                        this.line   = lineNumber;
 
185
                        this.x      = xPos;
 
186
                        this.y      = yPos;
 
187
                }
 
188
        }
 
189
        
 
190
}