-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunitformchoosestring.pas
167 lines (137 loc) · 3.79 KB
/
unitformchoosestring.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
unit UnitFormChooseString;
// Copyright 2022-2025 Zoran Vučenović
// SPDX-License-Identifier: Apache-2.0
{$mode ObjFPC}{$H+}
{$i zxinc.inc}
interface
uses
Classes, SysUtils, CommonFunctionsLCL, Forms, Controls, Graphics, Dialogs,
ExtCtrls, ButtonPanel, StdCtrls, Grids;
type
TFormChooseString = class(TForm)
ButtonPanel1: TButtonPanel;
Label1: TLabel;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
procedure FormShow(Sender: TObject);
private
Grid: TCustomStringGrid;
procedure GridOnDblClick(Sender: TObject);
procedure AfterShow(Data: PtrInt);
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
class function ShowFormChooseString(const SA: array of String; const ACaption,
ATitle: AnsiString; out N: Integer): Boolean; static;
end;
implementation
{$R *.lfm}
type
TGridChooseString = class(TCustomStringGrid)
protected
function MouseButtonAllowed(Button: TMouseButton): boolean; override;
public
constructor Create(AOwner: TComponent); override;
end;
{ TFormChooseString }
procedure TFormChooseString.FormShow(Sender: TObject);
begin
AfterShow(1);
end;
procedure TFormChooseString.GridOnDblClick(Sender: TObject);
var
P: TPoint;
begin
if TCommonFunctionsLCL.GridMouseToCellRegular(Grid, Grid.ScreenToClient(Mouse.CursorPos), P) then begin
if P.Y >= Grid.FixedRows then begin
Grid.Row := P.Y;
ModalResult := mrOK;
end;
end;
end;
procedure TFormChooseString.AfterShow(Data: PtrInt);
begin
CommonFunctionsLCL.TCommonFunctionsLCL.FormToScreenCentre(Self);
if Data > 0 then
Application.QueueAsyncCall(@AfterShow, Data - 1);
end;
constructor TFormChooseString.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
Label1.Caption := ' ';
Grid := TGridChooseString.Create(nil);
Grid.Anchors := [];
Grid.AnchorParallel(akLeft, 0, Panel2);
Grid.AnchorParallel(akTop, 0, Panel2);
Grid.AnchorParallel(akRight, 0, Panel2);
Grid.AnchorParallel(akBottom, 0, Panel2);
Grid.Parent := Panel2;
Grid.OnDblClick := @GridOnDblClick;
AfterShow(-1);
end;
destructor TFormChooseString.Destroy;
begin
Grid.Free;
inherited Destroy;
end;
class function TFormChooseString.ShowFormChooseString(
const SA: array of String; const ACaption, ATitle: AnsiString; out N: Integer
): Boolean;
var
I: Integer;
F: TFormChooseString;
begin
Result := False;
N := -1;
if Length(SA) > 0 then begin
if Length(SA) = 1 then begin
N := 0;
Exit(True);
end;
F := TFormChooseString.Create(nil);
try
F.Caption := ACaption;
F.Label1.Caption := Trim(ATitle);
if F.Label1.Caption = '' then begin
F.Panel3.Hide;
F.Panel2.AnchorParallel(akTop, 0, F.Panel1);
end else begin
F.Panel3.Show;
end;
F.Grid.RowCount := F.Grid.FixedRows + Length(SA);
for I := Low(SA) to High(SA) do begin
F.Grid.Cells[F.Grid.FixedCols, F.Grid.FixedRows + I] := SA[I];
end;
F.Grid.Row := F.Grid.FixedRows;
if F.ShowModal <> mrOK then
Result := True // user cancelled
else begin
N := F.Grid.Row - F.Grid.FixedRows;
Result := N >= 0;
end;
finally
F.Free;
end;
end;
end;
{ TFileListGrid }
function TGridChooseString.MouseButtonAllowed(Button: TMouseButton): boolean;
begin
Result := TCommonFunctionsLCL.GridMouseButtonAllowed(Self, Button);
end;
constructor TGridChooseString.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Options := Options
+ [goSelectionActive, goRowSelect, goDrawFocusSelected]
- [goFixedHorzLine, goFixedVertLine,
goHorzLine, goVertLine, goRangeSelect];
FixedCols := 0;
FixedRows := 0;
ColCount := 1;
AllowOutboundEvents := False;
AutoFillColumns := True;
Flat := True;
end;
end.