This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LayoutViewCustomButtonViewInfo.cs
93 lines (88 loc) · 4.68 KB
/
LayoutViewCustomButtonViewInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraGrid.Views.Layout.ViewInfo;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Layout;
using System.Drawing;
using DevExpress.XtraGrid.Views.Base.ViewInfo;
namespace CustomButtonsLayoutView
{
public class LayoutViewCustomButtonViewInfo : LayoutViewInfo
{
public LayoutViewCustomButtonViewInfo(LayoutView gridView) : base(gridView) { }
protected override void CalcButtonRects(System.Drawing.Rectangle buttonsRect)
{
Size buttonSize = Painter.ElementsPainter.HeaderPanel.GetButtonSize();
Stack<Rectangle> btnRects = new Stack<Rectangle>();
LayoutViewCustomButton CurrentView = Owner as LayoutViewCustomButton;
int iCustomButtonsCount = 0;
if (CurrentView != null)
{
iCustomButtonsCount = CurrentView.ButtonsCollection.Count;
}
for (int i = 8 + iCustomButtonsCount; i >= 0; i--) btnRects.Push(
new Rectangle(buttonsRect.Location + new Size(i * (buttonSize.Width + 1), 0), buttonSize)
);
if (View.OptionsHeaderPanel.ShowSingleModeButton) ViewRects.SingleModeButton = btnRects.Pop();
if (View.OptionsHeaderPanel.ShowRowModeButton) ViewRects.RowModeButton = btnRects.Pop();
if (View.OptionsHeaderPanel.ShowColumnModeButton) ViewRects.ColumnModeButton = btnRects.Pop();
if (View.OptionsHeaderPanel.ShowMultiRowModeButton) ViewRects.MultiRowModeButton = btnRects.Pop();
if (View.OptionsHeaderPanel.ShowMultiColumnModeButton) ViewRects.MultiColumnModeButton = btnRects.Pop();
if (View.OptionsHeaderPanel.ShowCarouselModeButton) ViewRects.CarouselModeButton = btnRects.Pop();
if (btnRects.Peek().Left != buttonsRect.Left)
{
Rectangle separatorRect = btnRects.Pop();
ViewRects.Separator = new Rectangle(separatorRect.Location + new Size(5, 3), new Size(6, buttonSize.Height - 6));
}
if (View.OptionsBehavior.AllowPanCards && View.OptionsHeaderPanel.ShowPanButton) ViewRects.PanButton = btnRects.Pop();
if (View.OptionsBehavior.AllowRuntimeCustomization && View.OptionsHeaderPanel.ShowCustomizeButton) ViewRects.CustomizeButton = btnRects.Pop();
// let's fill custom buttons rect
int iWidthGap = 0;
for (int i = 0; i < iCustomButtonsCount; i++)
{
Rectangle currentRect = btnRects.Pop();
if (CurrentView.ButtonsCollection[i].Width > 0)
{
CurrentView.ButtonsCollection[i].Bounds = new Rectangle(currentRect.X + iWidthGap, currentRect.Y, CurrentView.ButtonsCollection[i].Width, currentRect.Height);
iWidthGap += (CurrentView.ButtonsCollection[i].Width - currentRect.Width);
}
else CurrentView.ButtonsCollection[i].Bounds = new Rectangle(currentRect.X + iWidthGap, currentRect.Y, currentRect.Width, currentRect.Height);
if (CurrentView.ButtonsCollection[i].Bounds.Right > buttonsRect.Right)
{ break; }
}
btnRects.Clear();
btnRects = null;
int clearBtnLeftBound = buttonsRect.Right;
if (View.IsDetailView)
{
Rectangle closeZoomRect = new Rectangle(buttonsRect.Location + new Size(buttonsRect.Width - buttonSize.Width, 1), buttonSize);
ViewRects.CloseZoomButton = closeZoomRect;
clearBtnLeftBound = closeZoomRect.Left;
}
if (ViewRects.CustomizeButton.Right > clearBtnLeftBound) ViewRects.ClearButtons();
}
public override LayoutViewHitInfo CalcHitInfo(Point pt)
{
LayoutViewHitInfo returnedValue = base.CalcHitInfo(pt);
LayoutViewCustomButton CurrentView = Owner as LayoutViewCustomButton;
if (CurrentView != null)
{
for (int i = 1; i <= CurrentView.ButtonsCollection.Count; i++)
{
if (CurrentView.ButtonsCollection[i - 1].Bounds.Contains(pt))
{
returnedValue.HitTest = (LayoutViewHitTest)CurrentView.ButtonsCollection[i - 1].GetHashCode();
returnedValue.HitRect = CurrentView.ButtonsCollection[i - 1].Bounds;
}
}
}
return returnedValue;
}
protected override BaseSelectionInfo CreateSelectionInfo()
{
return new LayoutViewCustomButtonSelectionInfo(View as LayoutViewCustomButton);
}
}
}