-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTDROPLIS.INC
224 lines (200 loc) · 4.94 KB
/
TDROPLIS.INC
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
{ Copyright 2015 Jerome Shidel }
(*
This project and related files are subject to either the terms
specified in the included LICENSE.TXT file or the GNU GPLv2.0.
*)
{ ---TDropList --- }
{$IFDEF INTERFACE}
const
class_TDropList = 'TDropList';
type
PDropList = ^TDropList;
TDropList = object(TControl)
public { protected }
function ObjectClass ( AName : String ) : String; virtual;
public { protected }
procedure SetBounds(AValue : TBounds); virtual;
procedure AdjustChildren; virtual;
procedure CheckLocal(var AEvent : TEvent); virtual;
procedure SetFromList; virtual;
public
FEdit : TEdit;
FDrop : TButton;
FList : TPopUpList;
FMaxDrop : integer;
constructor Create(AParent : PControl; AName : String);
destructor Destroy; virtual;
procedure Draw; virtual;
function AddItem( AValue : String) : PListItem; virtual;
procedure SetSorted(AValue : boolean); virtual;
procedure SetCaption(AValue: String); virtual;
function GetCaption : String; virtual;
procedure SetReadOnly(AValue: Boolean); virtual;
function GetReadOnly : Boolean; virtual;
procedure ClearItems; virtual;
end;
{$ENDIF}
{$IFDEF IMPLEMENTATION}
function TDropList.ObjectClass(AName : String) : String;
begin
if (AName = '') or (AName = class_TDropList) then
ObjectClass := class_TDropList
else
ObjectClass := inherited ObjectClass(AName);
end;
constructor TDropList.Create;
var
B : TBounds;
C : integer;
begin
C := TextAttr;
inherited Create(AParent, AName);
TextAttr := C;
Bounds(1,1,1,1,B);
FEdit.Create(@Self, 'EDIT');
with FEdit do begin
SetFreeOnDestroy(False);
FRBounds := B;
end;
TextAttr := C;
FDrop.Create(@Self, 'BUTTON');
with FDrop do begin
FCaptionAsChar := True;
SetFreeOnDestroy(False);
FCaption := #$20#$1F#$20;
FRBounds := B;
FCommand := cmDoDropList;
end;
TextAttr := C;
FList.Create(@Self, 'LIST');
with FList do begin
SetFreeOnDestroy(False);
FList.SetAllowEmpty(False); { FList.FList }
end;
FMaxDrop := 5;
end;
destructor TDropList.Destroy;
begin
FList.Destroy;
FDrop.Destroy;
FEdit.Destroy;
inherited Destroy;
end;
procedure TDropList.AdjustChildren;
var
AValue : TBounds;
begin
GetBounds(AValue);
AValue.Top := 1;
AValue.Left := 1;
Dec(AValue.Width, Length(FDrop.GetCaption));
FEdit.SetBounds(AValue);
AValue.Left := AValue.Width + 1;
AValue.Width := Length(FDrop.GetCaption);
FDrop.SetBounds(AValue);
AValue.Left := 3;
Inc(AValue.Top);
AValue.Height := FMaxDrop;
AValue.Width := Width;
if not FList.GetShadow then Dec(AValue.Width, 2);
FList.SetBounds(AValue);
end;
procedure TDropList.Draw;
begin
inherited Draw;
AdjustChildren;
end;
procedure TDropList.SetBounds(AValue : TBounds);
begin
FMaxDrop := AValue.Height - 1;
AValue.Height := 1;
inherited SetBounds(AValue);
AdjustChildren;
end;
procedure TDropList.SetFromList;
var
S : String;
P : PListItem;
begin
S := '';
P := FList.GetCurrent;
if Assigned(P) then begin
S := P^.GetNameID;
end else begin
if not FList.FList.GetAllowEmpty then
FList.FList.Up(True);
P := FList.GetCurrent;
if Assigned(P) then
S := P^.GetNameID;
end;
FEdit.SetCaption(S);
FEdit.Update;
end;
procedure TDropList.CheckLocal(var AEvent : TEvent);
var
R : integer;
begin
if AEvent.What = evCommand then
case AEvent.Command of
cmDown : if (AEvent.InfoPtr = @FEdit) or
(Application^.FFocused = @Self) then begin
PutCommand(cmDoDropList, @FDrop);
ClearEvent(AEvent);
end;
cmDoDropList : if (AEvent.InfoPtr = @FDrop) then begin
FList.FList.ScrollTo(FEdit.GetCaption);
FList.Update;
R := FList.ShowModal;
ClearEvent(AEvent);
if R = mrOK then begin
SetFromList;
PutCommand(cmDropList, @Self);
end;
end;
cmEdit : begin
if (AEvent.InfoPtr = @FEdit) and GetReadOnly then begin
ClearEvent(AEvent);
PutCommand(cmDoDropList, @FDrop);
end else
if AEvent.InfoPtr = @FEdit then begin
FList.FList.ScrollTo(FEdit.GetCaption);
ClearEvent(AEvent);
PutCommand(cmEdit, @Self);
end;
end;
end;
inherited CheckLocal(AEvent);
end;
function TDropList.AddItem( AValue : String) : PListItem;
begin
if FList.FList.FItems.FindID(AValue) = nil then
AddItem := FList.AddItem(AValue)
else
AddItem := nil;
end;
procedure TDropList.SetSorted(AValue : boolean);
begin
FList.SetSorted(AValue);
end;
procedure TDropList.SetCaption(AValue: String);
begin
FEdit.SetCaption(AValue);
FList.ScrollTo(AValue);
end;
function TDropList.GetCaption : String;
begin
GetCaption := FEdit.GetCaption;
end;
procedure TDropList.SetReadOnly(AValue: Boolean);
begin
FEdit.SetReadOnly(AValue);
end;
function TDropList.GetReadOnly : Boolean;
begin
GetReadOnly := FEdit.GetReadOnly;
end;
procedure TDropList.ClearItems;
begin
FList.ClearItems;
end;
{$ENDIF}