-
Notifications
You must be signed in to change notification settings - Fork 277
Expand file tree
/
Copy pathVirtualTrees.BaseAncestorFMX.pas
More file actions
553 lines (448 loc) · 19.4 KB
/
VirtualTrees.BaseAncestorFMX.pas
File metadata and controls
553 lines (448 loc) · 19.4 KB
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
unit VirtualTrees.BaseAncestorFMX;
{$SCOPEDENUMS ON}
{****************************************************************************************************************}
{ Project : VirtualTrees }
{ }
{ author : Karol Bieniaszewski }
{ year : 2022 }
{ contibutors : }
{****************************************************************************************************************}
interface
uses
{$IFDEF MSWINDOWS}
WinApi.Windows,
{$ENDIF}
System.Classes, System.UITypes,
FMX.Objects, FMX.Graphics, FMX.Controls, FMX.StdCtrls, FMX.Forms, FMX.ImgList,
VirtualTrees.Types, VirtualTrees.FMX;
type
TVTBaseAncestorFMX = class abstract(TRectangle)
strict private
FFont: TFont;
procedure SetFont(const Value: TFont);
private
FDottedBrushTreeLines: TStrokeBrush; // used to paint dotted lines without special pens
FDottedBrushGridLines: TStrokeBrush; // used to paint dotted lines without special pens
FInCreate: Boolean;
function GetFillColor: TAlphaColor;
procedure SetFillColor(const Value: TAlphaColor);
protected
FBevelEdges: TBevelEdges;
FBevelInner: TBevelCut;
FBevelOuter: TBevelCut;
FBevelKind: TBevelKind;
FBevelWidth: TBevelWidth;
FBorderWidth: TBorderWidth;
FHandleAllocated: Boolean;
FBiDiMode: TBiDiMode;
FHScrollBar: TScrollBar;
FVScrollBar: TScrollBar;
FUseRightToLeftAlignment: Boolean;
procedure SetBevelCut(Index: Integer; const Value: TBevelCut);
procedure SetBevelEdges(const Value: TBevelEdges);
procedure SetBevelKind(const Value: TBevelKind);
procedure SetBevelWidth(const Value: TBevelWidth);
procedure SetBorderWidth(Value: TBorderWidth);
procedure SetBiDiMode(Value: TBiDiMode);
function GetClientHeight: Single; virtual; abstract;
function GetClientWidth: Single; virtual; abstract;
function GetClientRect: TRect; virtual; abstract;
procedure UpdateStyleElements; virtual; abstract;
procedure DoStartDrag(var DragObject: TVTDragDataObject); virtual; abstract;
procedure DoEndDrag(Target: TObject; X, Y: TDimension); virtual; abstract;
procedure DragCanceled; virtual; abstract;
procedure Resize; override;
function CreateSystemImageSet(): TImageList;
procedure SetWindowTheme(const Theme: string); virtual;
procedure ChangeScale(M, D: Integer{$if CompilerVersion >= 31}; isDpiChange: Boolean{$ifend}); virtual; abstract;
function GetControlsAlignment: TAlignment; virtual; abstract;
function PrepareDottedBrush(CurrentDottedBrush: TBrush; Bits: Pointer; const BitsLinesCount: Word): TBrush; virtual; abstract;
function GetSelectedCount(): Integer; virtual; abstract;
procedure MarkCutCopyNodes; virtual; abstract;
function GetSortedCutCopySet(Resolve: Boolean): TNodeArray; virtual; abstract;
function GetSortedSelection(Resolve: Boolean): TNodeArray; virtual; abstract;
procedure WriteNode(Stream: TStream; Node: PVirtualNode); virtual; abstract;
procedure DoMouseEnter(); reintroduce; overload; virtual; abstract;
procedure DoMouseLeave(); reintroduce; overload; virtual; abstract;
protected //properties
property DottedBrushTreeLines: TStrokeBrush read FDottedBrushTreeLines write FDottedBrushTreeLines;
property DottedBrushGridLines: TStrokeBrush read FDottedBrushGridLines write FDottedBrushGridLines;
public //methods
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function ClientToScreen(P: TPoint): TPoint;
function ScreenToClient(P: TPoint): TPoint;
procedure RecreateWnd;
procedure ShowScrollBar(Bar: Integer; AShow: Boolean);
function SetScrollInfo(Bar: Integer; const ScrollInfo: TScrollInfo; Redraw: Boolean): TDimension;
function GetScrollInfo(Bar: Integer; var ScrollInfo: TScrollInfo): Boolean;
function GetScrollPos(Bar: Integer): TDimension;
function GetScrollBarForBar(Bar: Integer): TScrollBar;
procedure HScrollChangeProc(Sender: TObject); virtual; abstract;
procedure VScrollChangeProc(Sender: TObject); virtual; abstract;
procedure CopyToClipboard; virtual; abstract;
procedure CutToClipboard; virtual; abstract;
function PasteFromClipboard: Boolean; virtual; abstract;
/// <summary>
/// Alias for IsFocused to make same as Vcl Focused
/// </summary>
function Focused(): Boolean; inline;
/// <summary>
/// Convert mouse message to TMouseButton
/// Created as method, to be available in whole hierarchy without specifing Unit file name (prevent circular unit ref).
/// </summary>
class function KeysToShiftState(Keys: LongInt): TShiftState; static;
function GetParentForm(Control: TControl; TopForm: Boolean = True): TCustomForm;
/// <summary>
/// Alias for Repaint on FMX to be compatible with VCL
/// </summary>
procedure Invalidate(); inline;
/// <summary>
/// Alias for Repaint on FMX to be compatible with VCL
/// </summary>
function InvalidateRect(lpRect: PRect; bErase: Boolean): Boolean; inline;
/// <summary>
/// Alias for Repaint on FMX to be compatible with VCL
/// </summary>
function UpdateWindow(): Boolean; inline;
/// <summary>
/// Alias for Repaint on FMX to be compatible with VCL
/// </summary>
function RedrawWindow(lprcUpdate: PRect; hrgnUpdate: NativeUInt; flags: UINT): Boolean; overload; inline;
/// <summary>
/// Alias for Repaint on FMX to be compatible with VCL
/// </summary>
function RedrawWindow(const lprcUpdate: TRect; hrgnUpdate: NativeUInt; flags: UINT): Boolean; overload; inline;
/// <summary>
/// Alias for Repaint on FMX to be compatible with VCL
/// </summary>
function SendWM_SETREDRAW(Updating: Boolean): NativeUInt; inline;
/// <summary>
/// Simulate Windows GetSystemMetrics
/// </summary>
function GetSystemMetrics(nIndex: Integer): Integer;
procedure Sort(Node: PVirtualNode; Column: TColumnIndex; Direction: TSortDirection; DoInit: Boolean = True); reintroduce; overload; virtual; abstract;
public //properties
property Font: TFont read FFont write SetFont;
property ClientRect: TRect read GetClientRect;
property ClientWidth: Single read GetClientWidth;
property ClientHeight: Single read GetClientHeight;
property UseRightToLeftAlignment: Boolean read FUseRightToLeftAlignment write FUseRightToLeftAlignment default false;
property BevelEdges: TBevelEdges read FBevelEdges write SetBevelEdges default [TBevelEdge.beLeft, TBevelEdge.beTop, TBevelEdge.beRight, TBevelEdge.beBottom];
property BevelInner: TBevelCut index 0 read FBevelInner write SetBevelCut default TBevelCut.bvRaised;
property BevelOuter: TBevelCut index 1 read FBevelOuter write SetBevelCut default TBevelCut.bvLowered;
property BevelKind: TBevelKind read FBevelKind write SetBevelKind default TBevelKind.bkNone;
property BevelWidth: TBevelWidth read FBevelWidth write SetBevelWidth default 1;
property BorderWidth: TBorderWidth read FBorderWidth write SetBorderWidth;
property BiDiMode: TBiDiMode read FBiDiMode write SetBiDiMode;
property HScrollBar: TScrollBar read FHScrollBar;
property VScrollBar: TScrollBar read FVScrollBar;
property HandleAllocated: Boolean read FHandleAllocated;
/// <summary>
/// Alias for Fill.Color to make same use as Vcl Color property
/// </summary>
property Color: TAlphaColor read GetFillColor write SetFillColor;
end;
{$IFNDEF MSWINDOWS}
const
{ GetSystemMetrics() codes }
SM_CXVSCROLL = 2;
SM_CYHSCROLL = 3;
{$ENDIF}
implementation
uses FMX.TextLayout, FMX.Utils
{$IFNDEF MSWINDOWS}
, WinApi.Windows
{$ENDIF}
;
//-------- TVTBaseAncestorFMX ------------------------------------------------------------------------------------------
class function TVTBaseAncestorFMX.KeysToShiftState(Keys: LongInt): TShiftState;
begin
Result := TShiftState(Word(Keys));
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTBaseAncestorFMX.GetFillColor: TAlphaColor;
begin
Result:= Fill.Color;
end;
//----------------------------------------------------------------------------------------------------------------------
constructor TVTBaseAncestorFMX.Create(AOwner: TComponent);
begin
FInCreate:= true;
inherited;
FHandleAllocated:= true;
FUseRightToLeftAlignment:= false;
FBevelEdges:= [TBevelEdge.beLeft, TBevelEdge.beTop, TBevelEdge.beRight, TBevelEdge.beBottom];
FBevelInner:= TBevelCut.bvRaised;
FBevelOuter:= TBevelCut.bvLowered;
FBevelKind:= TBevelKind.bkNone;
FBevelWidth:= 1;
FBorderWidth:= 0;
FFont:= TFont.Create;
DisableFocusEffect := True;
CanFocus := True;
AutoCapture := True;
FHScrollBar:= TScrollBar.Create(Self);
FHScrollBar.Parent:= Self;
FHScrollBar.Orientation:= TOrientation.Horizontal;
FHScrollBar.Align:= TAlignLayout.MostBottom;
FHScrollBar.Visible:= true;
FHScrollBar.OnChange:= HScrollChangeProc;
FHScrollBar.Margins.Right:= FHScrollBar.Height;
FVScrollBar:= TScrollBar.Create(Self);
FVScrollBar.Parent:= Self;
FVScrollBar.Orientation:= TOrientation.Vertical;
FVScrollBar.Align:= TAlignLayout.MostRight;
FVScrollBar.Visible:= true;
FVScrollBar.OnChange:= VScrollChangeProc;
//FVScrollBar.Margins.Bottom:= FVScrollBar.Width;
SetAcceptsControls(false);
FInCreate:= false;
end;
//----------------------------------------------------------------------------------------------------------------------
destructor TVTBaseAncestorFMX.Destroy();
begin
inherited;
if FDottedBrushTreeLines <> nil then
FreeAndNil(FDottedBrushTreeLines);
if FDottedBrushGridLines <> nil then
FreeAndNil(FDottedBrushGridLines);
FreeAndNil(FFont);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TVTBaseAncestorFMX.SetBevelCut(Index: Integer; const Value: TBevelCut);
begin
case Index of
0: { BevelInner }
if Value <> FBevelInner then
begin
FBevelInner := Value;
Repaint;
end;
1: { BevelOuter }
if Value <> FBevelOuter then
begin
FBevelOuter := Value;
Repaint;
end;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TVTBaseAncestorFMX.SetBevelEdges(const Value: TBevelEdges);
begin
if Value <> FBevelEdges then
begin
FBevelEdges := Value;
Repaint;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TVTBaseAncestorFMX.SetBevelKind(const Value: TBevelKind);
begin
if Value <> FBevelKind then
begin
FBevelKind := Value;
Repaint;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TVTBaseAncestorFMX.SetBevelWidth(const Value: TBevelWidth);
begin
if Value <> FBevelWidth then
begin
FBevelWidth := Value;
Repaint;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTBaseAncestorFMX.ScreenToClient(P: TPoint): TPoint;
begin
Result:= AbsoluteToLocal(P);
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTBaseAncestorFMX.ClientToScreen(P: TPoint): TPoint;
begin
Result:= LocalToAbsolute(P);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TVTBaseAncestorFMX.Invalidate();
begin
Repaint;
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTBaseAncestorFMX.InvalidateRect(lpRect: PRect; bErase: Boolean): Boolean;
begin
Repaint;
Result:= true;
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTBaseAncestorFMX.UpdateWindow(): Boolean;
begin
Repaint;
Result:= true;
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTBaseAncestorFMX.RedrawWindow(lprcUpdate: PRect; hrgnUpdate: NativeUInt; flags: UINT): Boolean;
begin
Repaint;
Result:= true;
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTBaseAncestorFMX.RedrawWindow(const lprcUpdate: TRect; hrgnUpdate: NativeUInt; flags: UINT): Boolean;
begin
Repaint;
Result:= true;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TVTBaseAncestorFMX.RecreateWnd();
begin
Repaint;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TVTBaseAncestorFMX.ShowScrollBar(Bar: Integer; AShow: Boolean);
begin
if (Bar=SB_HORZ) or (Bar=SB_BOTH) then
FHScrollBar.Visible:= AShow;
if (Bar=SB_VERT) or (Bar=SB_BOTH) then
FVScrollBar.Visible:= AShow;
if FHScrollBar.Visible and FVScrollBar.Visible then
FHScrollBar.Margins.Right:= FHScrollBar.Height else
FHScrollBar.Margins.Right:= 0;
Repaint;
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTBaseAncestorFMX.SetScrollInfo(Bar: Integer; const ScrollInfo: TScrollInfo; Redraw: Boolean): TDimension;
Var ScrollBar: TScrollBar;
begin
ScrollBar:= GetScrollBarForBar(Bar);
if ScrollBar=nil then
Exit(0); //!!!
if ScrollInfo.fMask and SIF_PAGE<>0 then
begin
ScrollBar.SmallChange:= ScrollInfo.nPage;
end;
if ScrollInfo.fMask and SIF_RANGE<>0 then
begin
ScrollBar.Min:= ScrollInfo.nMin;
ScrollBar.Max:= ScrollInfo.nMax;
end;
if ScrollInfo.fMask and SIF_POS<>0 then
begin
ScrollBar.Value:= ScrollInfo.nPos;
end;
Result:= ScrollBar.Value;
Repaint;
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTBaseAncestorFMX.GetScrollInfo(Bar: Integer; var ScrollInfo: TScrollInfo): Boolean;
Var ScrollBar: TScrollBar;
begin
ScrollBar:= GetScrollBarForBar(Bar);
if ScrollBar=nil then
Exit(False); //!!!
Result:= true;
ScrollInfo.cbSize:= SizeOf(TScrollInfo);
ScrollInfo.fMask:= SIF_ALL;
ScrollInfo.nMin:= ScrollBar.Min;
ScrollInfo.nMax:= ScrollBar.Max;
ScrollInfo.nPage:= ScrollBar.SmallChange;
ScrollInfo.nPos:= ScrollBar.Value;
ScrollInfo.nTrackPos:= ScrollBar.Value;
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTBaseAncestorFMX.GetScrollPos(Bar: Integer): TDimension;
Var ScrollInfo: TScrollInfo;
begin
GetScrollInfo(Bar, ScrollInfo); //ignore result
Result:= ScrollInfo.nPos;
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTBaseAncestorFMX.GetScrollBarForBar(Bar: Integer): TScrollBar;
begin
if (Bar=SB_HORZ) then
Result:= FHScrollBar else
if (Bar=SB_VERT) then
Result:= FVScrollBar else
Result:= nil;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TVTBaseAncestorFMX.SetBiDiMode(Value: TBiDiMode);
begin
if FBiDiMode <> Value then
begin
FBiDiMode := Value;
Repaint;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TVTBaseAncestorFMX.SetBorderWidth(Value: TBorderWidth);
begin
if FBorderWidth <> Value then
begin
FBorderWidth := Value;
Repaint;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TVTBaseAncestorFMX.SetFillColor(const Value: TAlphaColor);
begin
Fill.Color:= Value;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TVTBaseAncestorFMX.SetFont(const Value: TFont);
begin
FFont.Assign(Value);
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTBaseAncestorFMX.Focused(): Boolean;
begin
Result:= IsFocused;
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTBaseAncestorFMX.GetParentForm(Control: TControl; TopForm: Boolean = True): TCustomForm;
begin
Result:= Control.Root.GetObject as TCustomForm;
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTBaseAncestorFMX.SendWM_SETREDRAW(Updating: Boolean): NativeUInt;
begin
Repaint;
Result:= 0;
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTBaseAncestorFMX.GetSystemMetrics(nIndex: Integer): Integer;
begin
{$IFDEF MSWINDOWS}
Result:= GetSystemMetrics(nIndex);
{$ELSE}
case nIndex of
SM_CXVSCROLL: Result:= 16;
SM_CYHSCROLL: Result:= 3;
else
raise Exception.Create('Unknown code for GetSystemMetrics: ' + IntToStr(nIndex));
end;
{$ENDIF}
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTBaseAncestorFMX.CreateSystemImageSet(): TImageList;
begin
Result:= TImageList.Create(Self);
FillSystemCheckImages(Self, Result);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TVTBaseAncestorFMX.SetWindowTheme(const Theme: string);
begin
//nothing
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTBaseAncestorFMX.CreateSystemImageSet(): TImageList;
begin
Result:= TImageList.Create(Self);
FillSystemCheckImages(Self, Result);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TVTBaseAncestorFMX.SetWindowTheme(const Theme: string);
begin
//nothing
end;
end.