diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2016-10-25 12:52:08 +0300 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2016-10-25 12:52:08 +0300 |
commit | ad37324b881f84ede2b9b086d340ebf596aa2a6b (patch) | |
tree | 94e149ef443761ecdcae7a48ae770b504570ff2c /main/src/addins/MonoDevelop.HexEditor | |
parent | 52def8741cedd7d46004c68be453de1504fa7205 (diff) | |
parent | 4edfcc3d5192f2b66745572cf3dbeabc4485299e (diff) |
Merge branch 'master' into textmate
Diffstat (limited to 'main/src/addins/MonoDevelop.HexEditor')
3 files changed, 56 insertions, 8 deletions
diff --git a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/HexEditorMargin.cs b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/HexEditorMargin.cs index 9f5f74925d..d88c72b109 100644 --- a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/HexEditorMargin.cs +++ b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/HexEditorMargin.cs @@ -102,14 +102,18 @@ namespace Mono.MHex.Rendering Margin.LayoutWrapper result = new LayoutWrapper (layout); if (Data.IsSomethingSelected) { ISegment selection = Data.MainSelection.Segment; - HandleSelection (selection.Offset, selection.EndOffset, startOffset, endOffset, null, delegate(long start, long end) { - result.Layout.SetForeground (Style.Selection, (int)(start - startOffset) * 3, (int)(end - start) * 3 - 1); - result.Layout.SetBackground (Style.SelectionBg, (int)(start - startOffset) * 3, (int)(end - start) * 3 - 1); - }); + HandleSelection (selection.Offset, selection.EndOffset, startOffset, endOffset, this, new LayoutOffsetPair(startOffset, result.Layout), null, OnSelected); } return result; } + static void OnSelected (long start, long end, Margin margin, LayoutOffsetPair arg) + { + var style = ((HexEditorMargin)margin).Style;
+ arg.Layout.SetForeground (style.Selection, (int)(start - arg.StartOffset) * 3, (int)(end - start) * 3 - 1);
+ arg.Layout.SetBackground (style.SelectionBg, (int)(start - arg.StartOffset) * 3, (int)(end - start) * 3 - 1); + } + uint TranslateColumn (long column) { return (uint)(column * 3); diff --git a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/Margin.cs b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/Margin.cs index d57aad8255..f0022c5803 100644 --- a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/Margin.cs +++ b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/Margin.cs @@ -192,6 +192,46 @@ namespace Mono.MHex.Rendering handleNotSelected (startOffset, endOffset); } } + + protected delegate void HandleSelectionArgsDelegate<T> (long start, long end, Margin margin, T arg); + protected struct LayoutOffsetPair + { + public readonly long StartOffset; + public readonly TextLayout Layout; + + public LayoutOffsetPair (long startOffset, TextLayout layout) + { + StartOffset = startOffset; + Layout = layout; + } + }
+ protected static void HandleSelection<T> (long selectionStart, long selectionEnd, long startOffset, long endOffset, Margin margin, T args, HandleSelectionArgsDelegate<T> handleNotSelected, HandleSelectionArgsDelegate<T> handleSelected) + { + if (startOffset >= selectionStart && endOffset <= selectionEnd) { + if (handleSelected != null) + handleSelected (startOffset, endOffset, margin, args); + } else if (startOffset >= selectionStart && startOffset < selectionEnd && endOffset > selectionEnd) { + if (handleSelected != null) + handleSelected (startOffset, selectionEnd, margin, args); + if (handleNotSelected != null) + handleNotSelected (selectionEnd, endOffset, margin, args); + } else if (startOffset < selectionStart && endOffset > selectionStart && endOffset <= selectionEnd) { + if (handleNotSelected != null) + handleNotSelected (startOffset, selectionStart, margin, args); + if (handleSelected != null) + handleSelected (selectionStart, endOffset, margin, args); + } else if (startOffset < selectionStart && endOffset > selectionEnd) { + if (handleNotSelected != null) + handleNotSelected (startOffset, selectionStart, margin, args); + if (handleSelected != null) + handleSelected (selectionStart, selectionEnd, margin, args); + if (handleNotSelected != null) + handleNotSelected (selectionEnd, endOffset, margin, args); + } else { + if (handleNotSelected != null) + handleNotSelected (startOffset, endOffset, margin, args); + } + } protected static uint TranslateToUTF8Index (char[] charArray, uint textIndex, ref uint curIndex, ref uint byteIndex) { diff --git a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/TextEditorMargin.cs b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/TextEditorMargin.cs index 930a3a470b..ccdce7df99 100644 --- a/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/TextEditorMargin.cs +++ b/main/src/addins/MonoDevelop.HexEditor/Mono.MHex.Rendering/TextEditorMargin.cs @@ -105,14 +105,18 @@ namespace Mono.MHex.Rendering Margin.LayoutWrapper result = new LayoutWrapper (layout); if (Data.IsSomethingSelected) { ISegment selection = Data.MainSelection.Segment; - HandleSelection (selection.Offset, selection.EndOffset, startOffset, endOffset, null, delegate(long start, long end) { - result.Layout.SetForeground (Style.Selection, (int)(start - startOffset)/2, (int)(end - start)/2); - result.Layout.SetBackground (Style.SelectionBg, (int)(start - startOffset)/2, (int)(end - start)/2); - }); + HandleSelection (selection.Offset, selection.EndOffset, startOffset, endOffset, this, new LayoutOffsetPair (startOffset, result.Layout), null, OnSelected); } return result; } + static void OnSelected (long start, long end, Margin margin, LayoutOffsetPair arg) + { + var style = ((TextEditorMargin)margin).Style; + arg.Layout.SetForeground (style.Selection, (int)(start - arg.StartOffset) / 2, (int)(end - start) / 2);
+ arg.Layout.SetBackground (style.SelectionBg, (int)(start - arg.StartOffset) / 2, (int)(end - start) / 2); + } + internal protected override void Draw (Context ctx, Rectangle area, long line, double x, double y) { ctx.Rectangle (x, y, Width, Editor.LineHeight); |