Browse Source

Allow users to change the AvalonEdit selection style.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4965 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
23db63a30e
  1. 10
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/CaretLayer.cs
  2. 7
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/SelectionColorizer.cs
  3. 9
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/SelectionLayer.cs
  4. 70
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs
  5. 14
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.xaml

10
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/CaretLayer.cs

@ -75,11 +75,11 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -75,11 +75,11 @@ namespace ICSharpCode.AvalonEdit.Editing
Brush caretBrush = this.CaretBrush;
if (caretBrush == null)
caretBrush = (Brush)textView.GetValue(TextBlock.ForegroundProperty);
drawingContext.DrawRectangle(caretBrush, null,
new Rect(caretRectangle.X - textView.HorizontalOffset,
caretRectangle.Y - textView.VerticalOffset,
caretRectangle.Width,
caretRectangle.Height));
Rect r = new Rect(caretRectangle.X - textView.HorizontalOffset,
caretRectangle.Y - textView.VerticalOffset,
caretRectangle.Width,
caretRectangle.Height);
drawingContext.DrawRectangle(caretBrush, null, PixelSnapHelpers.ToPixels(r));
}
}
}

7
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/SelectionColorizer.cs

@ -25,6 +25,10 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -25,6 +25,10 @@ namespace ICSharpCode.AvalonEdit.Editing
protected override void Colorize(ITextRunConstructionContext context)
{
// if SelectionForeground is null, keep the existing foreground color
if (textArea.SelectionForeground == null)
return;
int lineStartOffset = context.VisualLine.FirstDocumentLine.Offset;
int lineEndOffset = context.VisualLine.LastDocumentLine.Offset + context.VisualLine.LastDocumentLine.TotalLength;
@ -40,8 +44,7 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -40,8 +44,7 @@ namespace ICSharpCode.AvalonEdit.Editing
ChangeVisualElements(
startColumn, endColumn,
element => {
element.TextRunProperties.SetForegroundBrush(SystemColors.HighlightTextBrush);
//element.TextRunProperties.SetBackgroundBrush(SystemColors.HighlightBrush);
element.TextRunProperties.SetForegroundBrush(textArea.SelectionForeground);
});
}
}

9
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/SelectionLayer.cs

@ -42,18 +42,13 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -42,18 +42,13 @@ namespace ICSharpCode.AvalonEdit.Editing
base.OnRender(drawingContext);
BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder();
geoBuilder.CornerRadius = textArea.SelectionCornerRadius;
foreach (var segment in textArea.Selection.Segments) {
geoBuilder.AddSegment(textView, segment);
}
Geometry geometry = geoBuilder.CreateGeometry();
if (geometry != null) {
SolidColorBrush lightHighlightBrush = new SolidColorBrush(SystemColors.HighlightColor);
lightHighlightBrush.Opacity = 0.7;
lightHighlightBrush.Freeze();
Pen pen = new Pen(SystemColors.HighlightBrush, 1);
//pen.LineJoin = PenLineJoin.Round;
pen.Freeze();
drawingContext.DrawGeometry(lightHighlightBrush, pen, geometry);
drawingContext.DrawGeometry(textArea.SelectionBrush, textArea.SelectionBorder, geometry);
}
}
}

70
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs

@ -321,6 +321,63 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -321,6 +321,63 @@ namespace ICSharpCode.AvalonEdit.Editing
}
}
}
/// <summary>
/// The <see cref="SelectionBrush"/> property.
/// </summary>
public static readonly DependencyProperty SelectionBrushProperty =
DependencyProperty.Register("SelectionBrush", typeof(Brush), typeof(TextArea));
/// <summary>
/// Gets/Sets the background brush used for the selection.
/// </summary>
public Brush SelectionBrush {
get { return (Brush)GetValue(SelectionBrushProperty); }
set { SetValue(SelectionBrushProperty, value); }
}
/// <summary>
/// The <see cref="SelectionForeground"/> property.
/// </summary>
public static readonly DependencyProperty SelectionForegroundProperty =
DependencyProperty.Register("SelectionForeground", typeof(Brush), typeof(TextArea));
/// <summary>
/// Gets/Sets the foreground brush used selected text.
/// </summary>
public Brush SelectionForeground {
get { return (Brush)GetValue(SelectionForegroundProperty); }
set { SetValue(SelectionForegroundProperty, value); }
}
/// <summary>
/// The <see cref="SelectionBorder"/> property.
/// </summary>
public static readonly DependencyProperty SelectionBorderProperty =
DependencyProperty.Register("SelectionBorder", typeof(Pen), typeof(TextArea));
/// <summary>
/// Gets/Sets the background brush used for the selection.
/// </summary>
public Pen SelectionBorder {
get { return (Pen)GetValue(SelectionBorderProperty); }
set { SetValue(SelectionBorderProperty, value); }
}
/// <summary>
/// The <see cref="SelectionCornerRadius"/> property.
/// </summary>
public static readonly DependencyProperty SelectionCornerRadiusProperty =
DependencyProperty.Register("SelectionCornerRadius", typeof(double), typeof(TextArea),
new FrameworkPropertyMetadata(3.0));
/// <summary>
/// Gets/Sets the corner radius of the selection.
/// </summary>
public double SelectionCornerRadius {
get { return (double)GetValue(SelectionCornerRadiusProperty); }
set { SetValue(SelectionCornerRadiusProperty, value); }
}
#endregion
#region Force caret to stay inside selection
@ -773,6 +830,19 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -773,6 +830,19 @@ namespace ICSharpCode.AvalonEdit.Editing
}
#endregion
/// <inheritdoc/>
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.Property == SelectionBrushProperty
|| e.Property == SelectionBorderProperty
|| e.Property == SelectionForegroundProperty
|| e.Property == SelectionCornerRadiusProperty)
{
textView.Redraw();
}
}
/// <summary>
/// Gets the requested service.
/// </summary>

14
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.xaml

@ -34,6 +34,20 @@ @@ -34,6 +34,20 @@
<Style TargetType="{x:Type editing:TextArea}">
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="SelectionBrush">
<Setter.Value>
<SolidColorBrush
Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"
Opacity="0.7"/>
</Setter.Value>
</Setter>
<Setter Property="SelectionBorder">
<Setter.Value>
<Pen Brush="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
Thickness="1"/>
</Setter.Value>
</Setter>
<Setter Property="SelectionForeground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type editing:TextArea}">

Loading…
Cancel
Save