Browse Source

Merge branch 'master' of github.com:icsharpcode/SharpDevelop

pull/19/head
PeterForstmeier 14 years ago
parent
commit
982918bf32
  1. 74
      src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs
  2. 9
      src/AddIns/Analysis/CodeQuality/Src/Utility/Helper.cs

74
src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs

@ -11,6 +11,8 @@ using System.Windows.Controls;
using System.Windows.Controls.Primitives; using System.Windows.Controls.Primitives;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Interop;
using PointF = System.Drawing.PointF;
namespace ICSharpCode.CodeQualityAnalysis.Controls namespace ICSharpCode.CodeQualityAnalysis.Controls
{ {
@ -73,9 +75,9 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
HoveredCell = new HoveredCell<TValue>(); HoveredCell = new HoveredCell<TValue>();
} }
public void SetVisibleItems(HeaderType tree, ICollection<TItem> visibleItems) public void SetVisibleItems(HeaderType type, ICollection<TItem> visibleItems)
{ {
matrix.SetVisibleItems(tree, visibleItems); matrix.SetVisibleItems(type, visibleItems);
matrixHeight = matrix.HeaderRows.Count; matrixHeight = matrix.HeaderRows.Count;
matrixWidth = matrix.HeaderColumns.Count; matrixWidth = matrix.HeaderColumns.Count;
@ -92,17 +94,27 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
} }
if (changedCoords) { if (changedCoords) {
HoveredCell.RowIndex = currentCell.Y; SetHoveredCell();
HoveredCell.ColumnIndex = currentCell.X;
HoveredCell.Value = matrix[HoveredCell.RowIndex, HoveredCell.ColumnIndex];
if (HoveredCellChanged != null)
HoveredCellChanged(this, new HoveredCellEventArgs<TValue>(HoveredCell));
} }
if (matrixHeight >= 0 && matrixWidth >= 0) if (matrixHeight >= 0 && matrixWidth >= 0)
InvalidateVisual(); InvalidateVisual();
} }
public void HighlightLine(HeaderType type, INode node)
{
var items = type == HeaderType.Columns ? matrix.HeaderColumns : matrix.HeaderRows;
for (int i = 0; i < items.Count; i++) {
if (node.Equals(items[i])) {
currentCell = type == HeaderType.Columns ?
new Coords(i, currentCell.Y) :
new Coords(currentCell.X, i);
SetHoveredCell();
}
}
}
protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e) protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e)
{ {
base.OnMouseMove(e); base.OnMouseMove(e);
@ -120,15 +132,19 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
currentCell.Y != HoveredCell.ColumnIndex) currentCell.Y != HoveredCell.ColumnIndex)
{ {
InvalidateVisual(); InvalidateVisual();
SetHoveredCell();
HoveredCell.RowIndex = currentCell.Y;
HoveredCell.ColumnIndex = currentCell.X;
HoveredCell.Value = matrix[HoveredCell.RowIndex, HoveredCell.ColumnIndex];
if (HoveredCellChanged != null)
HoveredCellChanged(this, new HoveredCellEventArgs<TValue>(HoveredCell));
} }
} }
protected void SetHoveredCell()
{
HoveredCell.RowIndex = currentCell.Y;
HoveredCell.ColumnIndex = currentCell.X;
HoveredCell.Value = matrix[HoveredCell.RowIndex, HoveredCell.ColumnIndex];
if (HoveredCellChanged != null)
HoveredCellChanged(this, new HoveredCellEventArgs<TValue>(HoveredCell));
}
protected override void OnRender(DrawingContext drawingContext) protected override void OnRender(DrawingContext drawingContext)
{ {
base.OnRender(drawingContext); base.OnRender(drawingContext);
@ -138,6 +154,8 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
var maxHeight = ((int) viewport.Height / CellHeight) + 1; var maxHeight = ((int) viewport.Height / CellHeight) + 1;
// how many cells we will draw // how many cells we will draw
// sometimes happens when half of cell is hidden in scroll so text isnt drawn
// so lets drawn one more cell
var cellsHorizontally = maxWidth > matrixWidth ? matrixWidth : maxWidth + 1; var cellsHorizontally = maxWidth > matrixWidth ? matrixWidth : maxWidth + 1;
var cellsVertically = maxHeight > matrixHeight ? matrixHeight : maxHeight + 1; var cellsVertically = maxHeight > matrixHeight ? matrixHeight : maxHeight + 1;
@ -155,11 +173,6 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
backgroundColor.Freeze(); backgroundColor.Freeze();
drawingContext.DrawRectangle(backgroundColor, null, background); drawingContext.DrawRectangle(backgroundColor, null, background);
// sometimes happens when half of cell is hidden in scroll so text isnt drawn
// so lets drawn one more cell
// cellsHorizontally = maxWidth > matrixWidth ? matrixWidth : maxWidth + 1;
// cellsVertically = maxHeight > matrixHeight ? matrixHeight : maxHeight + 1;
var currentXLine = (currentCell.X - scaledOffsetX) * CellWidth - offsetDiffX; var currentXLine = (currentCell.X - scaledOffsetX) * CellWidth - offsetDiffX;
var currentYLine = (currentCell.Y - scaledOffsetY) * CellHeight - offsetDiffY; var currentYLine = (currentCell.Y - scaledOffsetY) * CellHeight - offsetDiffY;
@ -168,9 +181,9 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
// hover y line // hover y line
var rect = new Rect(0, var rect = new Rect(0,
currentYLine, currentYLine,
CellWidth * cellsHorizontally, CellWidth * cellsHorizontally,
CellHeight); CellHeight);
var brush = new SolidColorBrush(Colors.GreenYellow); var brush = new SolidColorBrush(Colors.GreenYellow);
brush.Freeze(); brush.Freeze();
@ -204,7 +217,7 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
int rowIndex = j; int rowIndex = j;
int columnIndex = i; int columnIndex = i;
var value = matrix[rowIndex, columnIndex]; var value = matrix[rowIndex, columnIndex];
if (Colorizer != null) { if (Colorizer != null) {
var rect = new Rect( var rect = new Rect(
i * CellWidth - offsetDiffX, i * CellWidth - offsetDiffX,
@ -217,7 +230,7 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
// ((i * CellWidth - offsetDiffX) == currentXLine)) // ((i * CellWidth - offsetDiffX) == currentXLine))
// brush = Brushes.Pink; //Colorizer.GetColorBrushMixedWith(Colors.GreenYellow, value); // brush = Brushes.Pink; //Colorizer.GetColorBrushMixedWith(Colors.GreenYellow, value);
// else // else
brush = Colorizer.GetColorBrush(value); brush = Colorizer.GetColorBrush(value);
drawingContext.DrawRectangle(brush, null, rect); drawingContext.DrawRectangle(brush, null, rect);
} }
@ -248,7 +261,7 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
} }
public ImageSource CreateText(string text) public ImageSource CreateText(string text)
{ {
if (imgs.ContainsKey(text)) if (imgs.ContainsKey(text))
return imgs[text]; return imgs[text];
@ -264,16 +277,19 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls
var spanWidth = (CellWidth - size.Width) / 2; var spanWidth = (CellWidth - size.Width) / 2;
var spanHeight = (CellHeight - size.Height) / 2; var spanHeight = (CellHeight - size.Height) / 2;
g.DrawString(text, fontOjb, System.Drawing.Brushes.Black, new System.Drawing.PointF(spanWidth, spanHeight)); g.DrawString(text, fontOjb, System.Drawing.Brushes.Black, new PointF(spanWidth, spanHeight));
g.Dispose(); g.Dispose();
var img = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), var bitmap = bmp.GetHbitmap();
IntPtr.Zero, var img = Imaging.CreateBitmapSourceFromHBitmap(bitmap,
Int32Rect.Empty, IntPtr.Zero,
BitmapSizeOptions.FromWidthAndHeight(bmp.Width, bmp.Height)); Int32Rect.Empty,
BitmapSizeOptions.FromWidthAndHeight(bmp.Width, bmp.Height));
img.Freeze(); img.Freeze();
imgs.Add(text, img); imgs.Add(text, img);
Helper.DeleteObject(bitmap);
return img; return img;
} }

9
src/AddIns/Analysis/CodeQuality/Src/Utility/Helper.cs

@ -5,15 +5,20 @@ using System;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using ICSharpCode.TreeView;
using System.Runtime.InteropServices;
namespace ICSharpCode.CodeQualityAnalysis namespace ICSharpCode.CodeQualityAnalysis.Utility
{ {
/// <summary> /// <summary>
/// Description of Helper. /// Description of Helper.
/// </summary> /// </summary>
public static class Helper public static class Helper
{ {
public static void FillTree(ICSharpCode.TreeView.SharpTreeView tree,Module module) [DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr hObject);
public static void FillTree(SharpTreeView tree, Module module)
{ {
var root = CreateTreeItem(module); var root = CreateTreeItem(module);
tree.Root = root; tree.Root = root;

Loading…
Cancel
Save