This repository has been archived by the owner on Jun 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MyPivotGrid.cs
167 lines (151 loc) · 6.95 KB
/
MyPivotGrid.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.XtraPivotGrid;
using DevExpress.XtraPivotGrid.Data;
using DevExpress.XtraPivotGrid.ViewInfo;
using DevExpress.XtraPivotGrid.Printing;
using DevExpress.XtraPrinting;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.PivotGrid.Printing;
using DevExpress.XtraPrinting.Native;
namespace WindowsApplication53
{
public class MyPivotGridControl : PivotGridControl
{
public static string ImagePlaceHolder { get { return "*Image*"; } }
public MyPivotGridControl() : base() { }
public MyPivotGridControl(PivotGridViewInfoData viewInfoData) : base(viewInfoData) { }
protected override PivotGridViewInfoData CreateData()
{
return new MyPivotGridViewInfoData(this);
}
protected override PivotGridPrinter CreatePrinter()
{
MyPivotGridPrinter printer = new MyPivotGridPrinter(this);
printer.Owner = this;
return printer;
}
}
public class MyPivotGridViewInfoData : PivotGridViewInfoData
{
public MyPivotGridViewInfoData() : base() { }
public MyPivotGridViewInfoData(IViewInfoControl control) : base(control) { }
protected override PivotGridViewInfo CreateViewInfo()
{
return new MyPivotGridViewInfo(this);
}
}
public class MyPivotGridViewInfo : PivotGridViewInfo
{
public MyPivotGridViewInfo(PivotGridViewInfoData data) : base(data) { }
}
public class MyPivotGridPrinter : PivotGridPrinter
{
public MyPivotGridPrinter(PivotGridControl pivotGridControl) : base(pivotGridControl) { }
protected override IVisualBrick DrawHeaderBrick(PivotFieldItemBase field, Rectangle bounds)
{
IPivotPrintAppearance appearance = GetFieldAppearance(field);
SetDefaultBrickStyle(appearance, CellSizeProvider.FieldValueTextOffset, 0, 0, 0);
string text = field.Caption;
IVisualBrick brick = CreateTextBrick();
brick.Text = text.Substring(MyPivotGridControl.ImagePlaceHolder.Length);
if (text != null)
brick.TextValue = text;
brick.TextValueFormatString = "";
int imageIndex = ((PivotGridField)this.Data.GetField(field)).ImageIndex;
if (imageIndex > -1)
{
ImageBrick ib = new ImageBrick(BorderSide.None, 0, Color.Red, Color.Transparent);
ib.Image = ((ImageList)this.PivotGridControl.HeaderImages).Images[imageIndex];
int imageWidth = ib.Image.Width;
int imageHeight = ib.Image.Height;
ib.BackColor = brick.BackColor;
ib.BorderColor = brick.BorderColor;
brick.Sides = BorderSide.Top | BorderSide.Right | BorderSide.Bottom;
ib.BorderStyle = brick.BorderStyle;
ib.BorderWidth = brick.BorderWidth;
ib.Sides = BorderSide.Top | BorderSide.Left | BorderSide.Bottom;
ib.SizeMode = ImageSizeMode.CenterImage;
//Graph.DrawBrick(ib, new Rectangle(bounds.X, bounds.Y + (bounds.Height - imageHeight) / 2, imageWidth, imageHeight));
Graph.DrawBrick(ib, new Rectangle(bounds.X, bounds.Y, imageWidth, bounds.Height));
Graph.DrawBrick(brick, new Rectangle(bounds.X + imageWidth, bounds.Y, bounds.Width - imageWidth, bounds.Height));
}
else
Graph.DrawBrick(brick, new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height));
brick.Separable = false;
if (Owner != null)
{
if (Owner.CustomExportHeader(ref brick, field, appearance, ref bounds))
ApplyAppearanceToBrickStyle(brick, appearance);
}
return brick;
}
void ApplyAppearanceToBrickStyle(IVisualBrick brick, IPivotPrintAppearance appearance)
{
IPanelBrick panelBrick = brick as IPanelBrick;
if (panelBrick != null)
{
foreach (IVisualBrick item in panelBrick.Bricks)
ApplyAppearanceToBrickStyleCore(item, appearance);
}
ApplyAppearanceToBrickStyleCore(brick, appearance);
}
void ApplyAppearanceToBrickStyleCore(IVisualBrick brick, IPivotPrintAppearance appearance)
{
BrickStyle brickStyle = brick.Style != null ?
(BrickStyle)brick.Style.Clone() :
(BrickStyle)Graph.DefaultBrickStyle.Clone();
if (appearance.Options.UseBackColor)
brickStyle.BackColor = appearance.BackColor;
if (appearance.Options.UseBorderColor)
brickStyle.BorderColor = appearance.BorderColor;
if (appearance.Options.UseBorderWidth)
brickStyle.BorderWidth = appearance.BorderWidth;
if (appearance.Options.UseBorderStyle)
brickStyle.BorderStyle = appearance.BorderStyle;
if (appearance.Options.UseFont)
brickStyle.Font = appearance.Font;
if (appearance.Options.UseForeColor)
brickStyle.ForeColor = appearance.ForeColor;
if (appearance.Options.UseTextOptions)
{
brickStyle.TextAlignment = TextAlignmentConverter.ToTextAlignment(appearance.TextHorizontalAlignment, appearance.TextVerticalAlignment);
brickStyle.StringFormat = new BrickStringFormat(brickStyle.StringFormat, brickStyle.StringFormat.FormatFlags, BrickStringFormatPrototypeKind.GenericTypographic);
}
brick.Style = brickStyle;
}
void SetDefaultBrickStyle(IPivotPrintAppearance appearance, int left, int top, int right, int bottom)
{
if (appearance == null)
return;
Graph.DefaultBrickStyle = CreateBrickStyle(appearance, left, top, right, bottom);
}
protected override PivotPrintBestFitter CreatePivotPrintBestFitter()
{
return new MyPivotPrintBestFitter(Data, this);
}
}
public class MyPivotPrintBestFitter : PivotPrintBestFitter
{
public MyPivotPrintBestFitter(PivotGridData data, PivotGridPrinterBase printer)
: base(data, printer, new MyPrintCellSizeProvider(data, data.VisualItems, printer))
{
}
}
public class MyPrintCellSizeProvider : PrintCellSizeProvider
{
int imageHeight;
public MyPrintCellSizeProvider(PivotGridData data, PivotVisualItemsBase visualItems, PivotGridPrinterBase printer)
: base(data, visualItems, printer) {
imageHeight = ((ImageList)data.HeaderImages).ImageSize.Height;
}
protected override int CalculateHeaderHeight(PivotFieldItemBase field)
{
int baseHeight = base.CalculateHeaderHeight(field);
return Math.Max(baseHeight, imageHeight + 4);
}
}
}