This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
LayoutViewCustomButtonPainter.cs
64 lines (60 loc) · 2.83 KB
/
LayoutViewCustomButtonPainter.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraGrid.Views.Layout.Drawing;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.Utils.Drawing;
using DevExpress.XtraGrid.Views.Layout.ViewInfo;
using System.Drawing;
namespace CustomButtonsLayoutView
{
class LayoutViewCustomButtonPainter : LayoutViewPainter
{
public LayoutViewCustomButtonPainter(BaseView view) : base(view) { }
protected override void DrawHeader(DevExpress.XtraGrid.Views.Layout.ViewInfo.LayoutViewDrawArgs e)
{
if (!e.ViewInfo.ViewRects.HeaderRect.IsEmpty)
{
LayoutViewHeaderObjectInfoArgs info = new LayoutViewHeaderObjectInfoArgs(View);
info.Bounds = e.ViewInfo.ViewRects.HeaderRect;
info.SetAppearance(View.PaintAppearance.HeaderPanel);
List<ButtonInfo> buttons = new List<ButtonInfo>();
PrepareSingleModeButton(e, buttons);
PrepareRowModeButton(e, buttons);
PrepareColumnModeButton(e, buttons);
PrepareMultiRowModeButton(e, buttons);
PrepareMultiColumnModeButton(e, buttons);
PrepareCarouselModeButton(e, buttons);
if (View.OptionsBehavior.AllowPanCards) PreparePanButton(e, buttons);
if (View.OptionsBehavior.AllowRuntimeCustomization) PrepareCustomizeButton(e, buttons);
// add custom button collections of the current layout view
PrepareCustomButtons(e, buttons);
info.Buttons = buttons.ToArray();
ObjectPainter.DrawObject(e.Cache, ElementsPainter.HeaderPanel, info);
DrawHeaderSeparator(e);
if (View.IsDetailView) DrawCloseZoomButton(e);
}
}
protected virtual void PrepareCustomButtons(LayoutViewDrawArgs e, List<ButtonInfo> buttons)
{
LayoutViewCustomButton CurrentView = View as LayoutViewCustomButton;
if (CurrentView == null) return;
foreach (CustomViewButton item in CurrentView.ButtonsCollection)
{
if (item.Bounds != Rectangle.Empty)
{
ButtonInfo buttonInfo = new ButtonInfo(item.Bounds, item.Image);
buttonInfo.State = CalcCustomButtonState(e, item.GetHashCode());
buttons.Add(buttonInfo);
}
}
}
public virtual ObjectState CalcCustomButtonState(LayoutViewDrawArgs e, int iCurrentHitTest)
{
ObjectState state = ObjectState.Normal;
if (e.ViewInfo.SelectionInfo.HotTrackedInfo != null && (int)e.ViewInfo.SelectionInfo.HotTrackedInfo.HitTest == iCurrentHitTest) { state |= ObjectState.Hot; }
return state;
}
}
}