Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.AvalonEdit/5.0.1/AvalonEdit-5.0.1/Folding/FoldingMarginMarker.cs @ 12850

Last change on this file since 12850 was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 3.9 KB
Line 
1// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4// software and associated documentation files (the "Software"), to deal in the Software
5// without restriction, including without limitation the rights to use, copy, modify, merge,
6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7// to whom the Software is furnished to do so, subject to the following conditions:
8//
9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11//
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19using System;
20using System.Windows;
21using System.Windows.Controls;
22using System.Windows.Input;
23using System.Windows.Media;
24
25using ICSharpCode.AvalonEdit.Rendering;
26using ICSharpCode.AvalonEdit.Utils;
27
28namespace ICSharpCode.AvalonEdit.Folding
29{
30  sealed class FoldingMarginMarker : UIElement
31  {
32    internal VisualLine VisualLine;
33    internal FoldingSection FoldingSection;
34   
35    bool isExpanded;
36   
37    public bool IsExpanded {
38      get { return isExpanded; }
39      set {
40        if (isExpanded != value) {
41          isExpanded = value;
42          InvalidateVisual();
43        }
44        if (FoldingSection != null)
45          FoldingSection.IsFolded = !value;
46      }
47    }
48   
49    protected override void OnMouseDown(MouseButtonEventArgs e)
50    {
51      base.OnMouseDown(e);
52      if (!e.Handled) {
53        if (e.ChangedButton == MouseButton.Left) {
54          IsExpanded = !IsExpanded;
55          e.Handled = true;
56        }
57      }
58    }
59   
60    const double MarginSizeFactor = 0.7;
61   
62    protected override Size MeasureCore(Size availableSize)
63    {
64      double size = MarginSizeFactor * FoldingMargin.SizeFactor * (double)GetValue(TextBlock.FontSizeProperty);
65      size = PixelSnapHelpers.RoundToOdd(size, PixelSnapHelpers.GetPixelSize(this).Width);
66      return new Size(size, size);
67    }
68   
69    protected override void OnRender(DrawingContext drawingContext)
70    {
71      FoldingMargin margin = VisualParent as FoldingMargin;
72      Pen activePen = new Pen(margin.SelectedFoldingMarkerBrush, 1);
73      Pen inactivePen = new Pen(margin.FoldingMarkerBrush, 1);
74      activePen.StartLineCap = inactivePen.StartLineCap = PenLineCap.Square;
75      activePen.EndLineCap = inactivePen.EndLineCap = PenLineCap.Square;
76      Size pixelSize = PixelSnapHelpers.GetPixelSize(this);
77      Rect rect = new Rect(pixelSize.Width / 2,
78                           pixelSize.Height / 2,
79                           this.RenderSize.Width - pixelSize.Width,
80                           this.RenderSize.Height - pixelSize.Height);
81      drawingContext.DrawRectangle(
82        IsMouseDirectlyOver ? margin.SelectedFoldingMarkerBackgroundBrush : margin.FoldingMarkerBackgroundBrush,
83        IsMouseDirectlyOver ? activePen : inactivePen, rect);
84      double middleX = rect.Left + rect.Width / 2;
85      double middleY = rect.Top + rect.Height / 2;
86      double space = PixelSnapHelpers.Round(rect.Width / 8, pixelSize.Width) + pixelSize.Width;
87      drawingContext.DrawLine(activePen,
88                              new Point(rect.Left + space, middleY),
89                              new Point(rect.Right - space, middleY));
90      if (!isExpanded) {
91        drawingContext.DrawLine(activePen,
92                                new Point(middleX, rect.Top + space),
93                                new Point(middleX, rect.Bottom - space));
94      }
95    }
96   
97    protected override void OnIsMouseDirectlyOverChanged(DependencyPropertyChangedEventArgs e)
98    {
99      base.OnIsMouseDirectlyOverChanged(e);
100      InvalidateVisual();
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.