Code Coverage Statistics for Source File
c:\Tools\SD3\src\Libraries\ICSharpCode.TextEditor\Project\Src\Gui\InsightWindow\InsightWindow.cs
|
Sequence Point Coverage
N/A
0 of 0
|
Branch Coverage
N/A
0 of 0
|
Lines
203
|
Highlight:
Uncovered Code
Covered Code
| L | V | Source |
|---|---|---|
1 |
// <file> |
|
2 |
// <copyright see="prj:///doc/copyright.txt"/> |
|
3 |
// <license see="prj:///doc/license.txt"/> |
|
4 |
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/> |
|
5 |
// <version>$Revision: 2681 $</version> |
|
6 |
// </file> |
|
7 |
||
8 |
using System; |
|
9 |
using System.Collections.Generic; |
|
10 |
using System.Drawing; |
|
11 |
using System.Windows.Forms; |
|
12 |
||
13 |
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
|
14 |
using ICSharpCode.TextEditor.Util; |
|
15 |
||
16 |
namespace ICSharpCode.TextEditor.Gui.InsightWindow |
|
17 |
{ |
|
18 |
public class InsightWindow : AbstractCompletionWindow |
|
19 |
{ |
|
20 |
public InsightWindow(Form parentForm, TextEditorControl control) : base(parentForm, control) |
|
21 |
{ |
|
22 |
SetStyle(ControlStyles.UserPaint, true); |
|
23 |
SetStyle(ControlStyles.OptimizedDoubleBuffer, true); |
|
24 |
} |
|
25 |
||
26 |
public void ShowInsightWindow() |
|
27 |
{ |
|
28 |
if (!Visible) { |
|
29 |
if (insightDataProviderStack.Count > 0) { |
|
30 |
ShowCompletionWindow(); |
|
31 |
} |
|
32 |
} else { |
|
33 |
Refresh(); |
|
34 |
} |
|
35 |
} |
|
36 |
||
37 |
#region Event handling routines |
|
38 |
protected override bool ProcessTextAreaKey(Keys keyData) |
|
39 |
{ |
|
40 |
if (!Visible) { |
|
41 |
return false; |
|
42 |
} |
|
43 |
switch (keyData) { |
|
44 |
case Keys.Down: |
|
45 |
if (DataProvider != null && DataProvider.InsightDataCount > 0) { |
|
46 |
CurrentData = (CurrentData + 1) % DataProvider.InsightDataCount; |
|
47 |
Refresh(); |
|
48 |
} |
|
49 |
return true; |
|
50 |
case Keys.Up: |
|
51 |
if (DataProvider != null && DataProvider.InsightDataCount > 0) { |
|
52 |
CurrentData = (CurrentData + DataProvider.InsightDataCount - 1) % DataProvider.InsightDataCount; |
|
53 |
Refresh(); |
|
54 |
} |
|
55 |
return true; |
|
56 |
} |
|
57 |
return base.ProcessTextAreaKey(keyData); |
|
58 |
} |
|
59 |
||
60 |
protected override void CaretOffsetChanged(object sender, EventArgs e) |
|
61 |
{ |
|
62 |
// move the window under the caret (don't change the x position) |
|
63 |
TextLocation caretPos = control.ActiveTextAreaControl.Caret.Position; |
|
64 |
int y = (int)((1 + caretPos.Y) * control.ActiveTextAreaControl.TextArea.TextView.FontHeight) |
|
65 |
- control.ActiveTextAreaControl.TextArea.VirtualTop.Y - 1 |
|
66 |
+ control.ActiveTextAreaControl.TextArea.TextView.DrawingPosition.Y; |
|
67 |
||
68 |
int xpos = control.ActiveTextAreaControl.TextArea.TextView.GetDrawingXPos(caretPos.Y, caretPos.X); |
|
69 |
int ypos = (control.ActiveTextAreaControl.Document.GetVisibleLine(caretPos.Y) + 1) * control.ActiveTextAreaControl.TextArea.TextView.FontHeight |
|
70 |
- control.ActiveTextAreaControl.TextArea.VirtualTop.Y; |
|
71 |
int rulerHeight = control.TextEditorProperties.ShowHorizontalRuler ? control.ActiveTextAreaControl.TextArea.TextView.FontHeight : 0; |
|
72 |
||
73 |
Point p = control.ActiveTextAreaControl.PointToScreen(new Point(xpos, ypos + rulerHeight)); |
|
74 |
if (p.Y != Location.Y) { |
|
75 |
Location = p; |
|
76 |
} |
|
77 |
||
78 |
while (DataProvider != null && DataProvider.CaretOffsetChanged()) { |
|
79 |
CloseCurrentDataProvider(); |
|
80 |
} |
|
81 |
} |
|
82 |
||
83 |
protected override void OnMouseDown(MouseEventArgs e) |
|
84 |
{ |
|
85 |
base.OnMouseDown(e); |
|
86 |
control.ActiveTextAreaControl.TextArea.Focus(); |
|
87 |
if (TipPainterTools.DrawingRectangle1.Contains(e.X, e.Y)) { |
|
88 |
CurrentData = (CurrentData + DataProvider.InsightDataCount - 1) % DataProvider.InsightDataCount; |
|
89 |
Refresh(); |
|
90 |
} |
|
91 |
if (TipPainterTools.DrawingRectangle2.Contains(e.X, e.Y)) { |
|
92 |
CurrentData = (CurrentData + 1) % DataProvider.InsightDataCount; |
|
93 |
Refresh(); |
|
94 |
} |
|
95 |
} |
|
96 |
||
97 |
#endregion |
|
98 |
||
99 |
||
100 |
public void HandleMouseWheel(MouseEventArgs e) |
|
101 |
{ |
|
102 |
if (DataProvider != null && DataProvider.InsightDataCount > 0) { |
|
103 |
if (e.Delta > 0) { |
|
104 |
if (control.TextEditorProperties.MouseWheelScrollDown) { |
|
105 |
CurrentData = (CurrentData + 1) % DataProvider.InsightDataCount; |
|
106 |
} else { |
|
107 |
CurrentData = (CurrentData + DataProvider.InsightDataCount - 1) % DataProvider.InsightDataCount; |
|
108 |
} |
|
109 |
} if (e.Delta < 0) { |
|
110 |
if (control.TextEditorProperties.MouseWheelScrollDown) { |
|
111 |
CurrentData = (CurrentData + DataProvider.InsightDataCount - 1) % DataProvider.InsightDataCount; |
|
112 |
} else { |
|
113 |
CurrentData = (CurrentData + 1) % DataProvider.InsightDataCount; |
|
114 |
} |
|
115 |
} |
|
116 |
Refresh(); |
|
117 |
} |
|
118 |
} |
|
119 |
||
120 |
#region Insight Window Drawing routines |
|
121 |
protected override void OnPaint(PaintEventArgs pe) |
|
122 |
{ |
|
123 |
string methodCountMessage = null, description; |
|
124 |
if (DataProvider == null || DataProvider.InsightDataCount < 1) { |
|
125 |
description = "Unknown Method"; |
|
126 |
} else { |
|
127 |
if (DataProvider.InsightDataCount > 1) { |
|
128 |
methodCountMessage = control.GetRangeDescription(CurrentData + 1, DataProvider.InsightDataCount); |
|
129 |
} |
|
130 |
description = DataProvider.GetInsightData(CurrentData); |
|
131 |
} |
|
132 |
||
133 |
drawingSize = TipPainterTools.GetDrawingSizeHelpTipFromCombinedDescription(this, |
|
134 |
pe.Graphics, |
|
135 |
Font, |
|
136 |
methodCountMessage, |
|
137 |
description); |
|
138 |
if (drawingSize != Size) { |
|
139 |
SetLocation(); |
|
140 |
} else { |
|
141 |
TipPainterTools.DrawHelpTipFromCombinedDescription(this, pe.Graphics, Font, methodCountMessage, description); |
|
142 |
} |
|
143 |
} |
|
144 |
||
145 |
protected override void OnPaintBackground(PaintEventArgs pe) |
|
146 |
{ |
|
147 |
pe.Graphics.FillRectangle(SystemBrushes.Info, pe.ClipRectangle); |
|
148 |
} |
|
149 |
#endregion |
|
150 |
||
151 |
#region InsightDataProvider handling |
|
152 |
Stack<InsightDataProviderStackElement> insightDataProviderStack = new Stack<InsightDataProviderStackElement>(); |
|
153 |
||
154 |
int CurrentData { |
|
155 |
get { |
|
156 |
return insightDataProviderStack.Peek().currentData; |
|
157 |
} |
|
158 |
set { |
|
159 |
insightDataProviderStack.Peek().currentData = value; |
|
160 |
} |
|
161 |
} |
|
162 |
||
163 |
IInsightDataProvider DataProvider { |
|
164 |
get { |
|
165 |
if (insightDataProviderStack.Count == 0) { |
|
166 |
return null; |
|
167 |
} |
|
168 |
return insightDataProviderStack.Peek().dataProvider; |
|
169 |
} |
|
170 |
} |
|
171 |
||
172 |
public void AddInsightDataProvider(IInsightDataProvider provider, string fileName) |
|
173 |
{ |
|
174 |
provider.SetupDataProvider(fileName, control.ActiveTextAreaControl.TextArea); |
|
175 |
if (provider.InsightDataCount > 0) { |
|
176 |
insightDataProviderStack.Push(new InsightDataProviderStackElement(provider)); |
|
177 |
} |
|
178 |
} |
|
179 |
||
180 |
void CloseCurrentDataProvider() |
|
181 |
{ |
|
182 |
insightDataProviderStack.Pop(); |
|
183 |
if (insightDataProviderStack.Count == 0) { |
|
184 |
Close(); |
|
185 |
} else { |
|
186 |
Refresh(); |
|
187 |
} |
|
188 |
} |
|
189 |
||
190 |
class InsightDataProviderStackElement |
|
191 |
{ |
|
192 |
public int currentData; |
|
193 |
public IInsightDataProvider dataProvider; |
|
194 |
||
195 |
public InsightDataProviderStackElement(IInsightDataProvider dataProvider) |
|
196 |
{ |
|
197 |
this.currentData = Math.Max(dataProvider.DefaultIndex, 0); |
|
198 |
this.dataProvider = dataProvider; |
|
199 |
} |
|
200 |
} |
|
201 |
#endregion |
|
202 |
} |
|
203 |
} |