-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathuScaleControlsEx.pas
267 lines (249 loc) · 7.61 KB
/
uScaleControlsEx.pas
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
unit uScaleControlsEx;
interface
implementation
{$define sf_colorpickerbutton}
{$define sf_dnSplitter}
// define, if using DBCtrlsEh
{.$define sf_EhLib}
// define, if using Vcl.Grids.pas
{.$define sf_Grids}
//{$define sf_StdCtrls}
// define, if using tb2k components
{$define sf_tb2k}
{$define sf_tbx}
{$define sf_VirtualTrees}
uses
{$ifdef HAS_UNITSCOPE}
System.Classes,
Vcl.Controls,
{$else}
Classes,
Controls,
{$endif}
{$ifdef sf_colorpickerbutton}ColorPickerButton,{$endif}
{$ifdef sf_dnSplitter}dnSplitter,{$endif}
{$ifdef sf_EhLib}DBCtrlsEh,{$endif}
{$ifdef sf_Grids}{$ifdef HAS_UNITSCOPE}Vcl.Grids,{$else}Grids,{$endif}{$endif}
// {$ifdef sf_StdCtrls}{$ifdef HAS_UNITSCOPE}Vcl.StdCtrls,{$else}StdCtrls,{$endif}{$endif}
{$ifdef sf_tb2k}TB2Item, TB2Toolbar, TB2ToolWindow,{$endif}
{$ifdef sf_tbx}TBXDkPanels, TBXStatusBars, TBXExtItems,{$endif}
{$ifdef sf_VirtualTrees}VirtualTrees,{$endif}
uScaleControls;
{$ifdef sf_colorpickerbutton}
procedure ScaleColorPickerButton(AControl: TControl; const AScaler: TIntScaler; var AHandled: Boolean);
begin
if not (AControl is TColorPickerButton) then
Exit;
with TColorPickerButton(AControl) do
begin
DropDownWidth := AScaler.Scale(DropDownWidth);
BoxSize := AScaler.Scale(BoxSize);
//Margin := -1;
PopupSpacing := AScaler.Scale(PopupSpacing);
Spacing := AScaler.Scale(Spacing);
Changed;
end;
end;
{$endif}
{$ifdef sf_dnSplitter}
procedure ScalednSplitter(AControl: TControl; const AScaler: TIntScaler; var AHandled: Boolean);
begin
if not (AControl is TdnSplitter) then
Exit;
with TdnSplitter(AControl) do
begin
if ButtonWidthType = btwPixels then
ButtonWidth := AScaler.Scale(ButtonWidth);
MinSize := AScaler.Scale(MinSize);
Size := AScaler.Scale(Size);
end;
end;
{$endif}
{$ifdef sf_EhLib}
procedure ScaleDBEditEh(AControl: TControl; const AScaler: TIntScaler; var AHandled: Boolean);
begin
if not (AControl is TCustomDBEditEh) then
Exit;
with TCustomDBEditEh(AControl).ControlLabelLocation do
begin
Offset := AScaler.Scale(Offset);
Spacing := AScaler.Scale(Spacing);
end;
end;
{$endif}
{$ifdef sf_Grids}
type
TFriendlyCustomGrid = class(TCustomGrid);
procedure ScaleCustomGrid(AControl: TControl; const AScaler: TIntScaler; var AHandled: Boolean);
var
i: Integer;
begin
if not (AControl is TCustomGrid) then
Exit;
with TFriendlyCustomGrid(AControl) do
begin
for i := 0 to ColCount - 1 do
ColWidths[i] := AScaler.Scale(ColWidths[i]);
DefaultColWidth := AScaler.Scale(DefaultColWidth);
for i := 0 to RowCount - 1 do
RowHeights[i] := AScaler.Scale(RowHeights[i]);
DefaultRowHeight := AScaler.Scale(DefaultRowHeight);
end;
end;
{$endif}
//{$ifdef sf_StdCtrls}
//procedure ScaleStdCtrls(AControl: TControl; const AScaler: TIntScaler; var AHandled: Boolean);
//begin
// if AControl is TCustomComboBox then
// begin
// with TComboBox(AControl) do
// ItemHeight := AScaler.Scale(ItemHeight);
// end;
//end;
//{$endif}
{$ifdef sf_tb2k}
procedure ScaleTBToolWindow(AControl: TControl; const AScaler: TIntScaler; var AHandled: Boolean);
begin
if not (AControl is TTBToolWindow) then
Exit;
with TTBToolWindow(AControl) do
begin
MaxClientWidth := AScaler.Scale(MaxClientWidth);
MinClientWidth := AScaler.Scale(MinClientWidth);
MaxClientHeight := AScaler.Scale(MaxClientHeight);
MinClientHeight := AScaler.Scale(MinClientHeight);
end;
end;
{$endif}
{$ifdef sf_tbx}
procedure ScaleTBX(AControl: TControl; const AScaler: TIntScaler; var AHandled: Boolean);
var
i: Integer;
LSize: Integer;
LPanel: TTBXStatusPanel;
LToolBar: TTBCustomToolbar;
LTBItem: TTBCustomItem;
begin
if AControl is TTBXAlignmentPanel then
begin
with TTBXAlignmentPanel(AControl) do
begin
Margins.Left := AScaler.Scale(Margins.Left);
Margins.Top := AScaler.Scale(Margins.Top);
Margins.Right := AScaler.Scale(Margins.Right);
Margins.Bottom := AScaler.Scale(Margins.Bottom);
end
end else if AControl is TTBXCustomStatusBar then
begin
with TTBXCustomStatusBar(AControl) do
if Panels.Count > 0 then
begin
Panels.BeginUpdate;
try
for i := 0 to Panels.Count - 1 do
begin
LPanel := Panels[i];
LSize := AScaler.Scale(LPanel.Size);
LPanel.MaxSize := AScaler.Scale(LPanel.MaxSize);
LPanel.Size := LSize;
end;
finally
Panels.EndUpdate;
end;
end
end else if AControl is TTBCustomToolbar then
begin
LToolBar := TTBCustomToolbar(AControl);
for i := 0 to LToolBar.Items.Count - 1 do
begin
LTBItem := LToolBar.Items.Items[i];
if LTBItem is TTBXComboBoxItem then
with TTBXComboBoxItem(LTBItem) do
begin
EditWidth := AScaler.Scale(EditWidth);
MinListWidth := AScaler.Scale(MinListWidth);
MaxListWidth := AScaler.Scale(MaxListWidth);
end;
end;
end;
end;
{$endif}
{$ifdef sf_VirtualTrees}
type
TfrBVT = class(TBaseVirtualTree);
procedure ScaleVirtualTree(AControl: TControl; const AScaler: TIntScaler; var AHandled: Boolean);
var
LTree: TBaseVirtualTree;
LHeader: TVTHeader;
LColumn: TVirtualTreeColumn;
i: Integer;
begin
if not (AControl is TBaseVirtualTree) then
Exit;
LTree := TBaseVirtualTree(AControl);
LTree.BeginUpdate;
try
TfrBVT(LTree).BackgroundOffsetX := AScaler.Scale(TfrBVT(LTree).BackgroundOffsetX);
TfrBVT(LTree).BackgroundOffsetY := AScaler.Scale(TfrBVT(LTree).BackgroundOffsetY);
TfrBVT(LTree).DefaultNodeHeight := AScaler.Scale(TfrBVT(LTree).DefaultNodeHeight);
// DragHeight
// DragWidth
TfrBVT(LTree).Indent := AScaler.Scale(TfrBVT(LTree).Indent);
TfrBVT(LTree).Margin := AScaler.Scale(TfrBVT(LTree).Margin);
// TextMargin íå ó÷èòûâàåòñÿ ïðè îòðèñîâêè õèíòà, áàã â VTV?
//TfrBVT(LTree).TextMargin := AScaler.Scale(TfrBVT(LTree).TextMargin);
LHeader := LTree.Header;
LHeader.DefaultHeight := AScaler.Scale(LHeader.DefaultHeight);
//LHeader.FixedAreaConstraints.
LHeader.Height := AScaler.Scale(LHeader.Height);
LHeader.MaxHeight := AScaler.Scale(LHeader.MaxHeight);
LHeader.MinHeight := AScaler.Scale(LHeader.MinHeight);
LHeader.SplitterHitTolerance := AScaler.Scale(LHeader.SplitterHitTolerance);
if LHeader.Columns.Count > 0 then
begin
LHeader.Columns.BeginUpdate;
try
for i := 0 to LHeader.Columns.Count - 1 do
begin
LColumn := LTree.Header.Columns.Items[i];
LColumn.Margin := AScaler.Scale(LColumn.Margin);
LColumn.MaxWidth := AScaler.Scale(LColumn.MaxWidth);
LColumn.MinWidth := AScaler.Scale(LColumn.MinWidth);
LColumn.Spacing := AScaler.Scale(LColumn.Spacing);
LColumn.Width := AScaler.Scale(LColumn.Width);
end;
finally
LTree.Header.Columns.EndUpdate;
end;
end;
finally
LTree.EndUpdate;
end;
end;
{$endif}
initialization
{$ifdef sf_colorpickerbutton}
TScaleControls.RegisterScaleCallback(ScaleColorPickerButton);
{$endif}
{$ifdef sf_dnSplitter}
TScaleControls.RegisterScaleCallback(ScalednSplitter);
{$endif}
{$ifdef sf_EhLib}
TScaleControls.RegisterScaleCallback(ScaleDBEditEh);
{$endif}
{$ifdef sf_Grids}
TScaleControls.RegisterScaleCallback(ScaleCustomGrid);
{$endif}
// {$ifdef sf_StdCtrls}
// TScaleControls.RegisterScaleCallback(ScaleStdCtrls);
// {$endif}
{$ifdef sf_tb2k}
TScaleControls.RegisterScaleCallback(ScaleTBToolWindow);
{$endif}
{$ifdef sf_tbx}
TScaleControls.RegisterScaleCallback(ScaleTBX);
{$endif}
{$ifdef sf_VirtualTrees}
TScaleControls.RegisterScaleCallback(ScaleVirtualTree);
{$endif}
end.