forked from TurboPack/Orpheus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOvcFlCbx.pas
330 lines (286 loc) · 9.19 KB
/
OvcFlCbx.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
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
{*********************************************************}
{* OVCFLCBX.PAS 4.06 *}
{*********************************************************}
{* ***** BEGIN LICENSE BLOCK ***** *}
{* Version: MPL 1.1 *}
{* *}
{* The contents of this file are subject to the Mozilla Public License *}
{* Version 1.1 (the "License"); you may not use this file except in *}
{* compliance with the License. You may obtain a copy of the License at *}
{* http://www.mozilla.org/MPL/ *}
{* *}
{* Software distributed under the License is distributed on an "AS IS" basis, *}
{* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License *}
{* for the specific language governing rights and limitations under the *}
{* License. *}
{* *}
{* The Original Code is TurboPower Orpheus *}
{* *}
{* The Initial Developer of the Original Code is TurboPower Software *}
{* *}
{* Portions created by TurboPower Software Inc. are Copyright (C)1995-2002 *}
{* TurboPower Software Inc. All Rights Reserved. *}
{* *}
{* Contributor(s): *}
{* *}
{* ***** END LICENSE BLOCK ***** *}
{$I OVC.INC}
{$B-} {Complete Boolean Evaluation}
{$I+} {Input/Output-Checking}
{$P+} {Open Parameters}
{$T-} {Typed @ Operator}
{.W-} {Windows Stack Frame}
{$X+} {Extended Syntax}
unit ovcflcbx;
{-file ComboBox}
interface
uses
Types, Windows, Messages, SysUtils, Classes, Graphics, OvcCmbx, StdCtrls;
type
TOvcCbxFileAttribute = (cbxReadOnly, cbxHidden, cbxSysFile, cbxArchive,
cbxAnyFile);
TOvcCbxFileAttributes = set of TOvcCbxFileAttribute;
type
TOvcFileComboBox = class(TOvcBaseComboBox)
protected {private}
{property variables}
FAttributes : TOvcCbxFileAttributes;
FDirName : string;
FFileMask : string;
FShowIcons : Boolean;
procedure SetAttributes(Value : TOvcCbxFileAttributes);
procedure SetDirectory(const Value : string);
procedure SetFileMask(const Value : string);
procedure SetShowIcons(Value : Boolean);
procedure DrawItem(Index : Integer; ItemRect : TRect; State : TOwnerDrawState);
override;
protected
procedure Loaded;
override;
public
constructor Create(AOwner : TComponent);
override;
procedure Populate;
published
property Attributes : TOvcCbxFileAttributes
read FAttributes
write SetAttributes
default [cbxAnyFile];
property Directory : string
read FDirName
write SetDirectory;
property FileMask : string
read FFileMask
write SetFileMask;
property ShowIcons : Boolean
read FShowIcons
write SetShowIcons
default True;
property Anchors;
property Constraints;
property DragKind;
property About;
property AutoSearch;
property Color;
property Ctl3D;
property Cursor;
property DragCursor;
property DragMode;
property DropDownCount;
property Enabled;
property Font;
property HotTrack;
property ImeMode;
property ImeName;
property ItemHeight;
property KeyDelay;
property LabelInfo;
property MRUListColor;
property MRUListCount;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Style default ocsDropDown;
property TabOrder;
property TabStop;
property Text;
property Visible;
{events}
property AfterEnter;
property AfterExit;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDropDown;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnSelectionChange;
property OnStartDrag;
property OnMouseWheel;
end;
implementation
uses
ShellApi;
function FullName(const Directory, Str : string) : string;
begin
if Directory = '' then
Result := GetCurrentDir + Str
else
if Directory[Length(Directory)] = ':' then
Result := Directory + Str
else
if Directory[Length(Directory)] = '\' then
Result := Directory + Str
else
Result := Directory + '\' + Str;
end;
function vLoadIcon(const Str : string) : HIcon;
var
FileName : array[0..255] of char;
IconNum : Word;
begin
StrPCopy(FileName, Str);
IconNum := 0;
Result := ExtractAssociatedIcon(MainInstance, FileName, IconNum
);
end;
{*** TOvcFileComboBox ***}
constructor TOvcFileComboBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FAttributes := [cbxAnyFile];
FDirName := '.';
FFileMask := '*.*';
FShowIcons := True;
end;
procedure TOvcFileComboBox.Loaded;
begin
inherited Loaded;
if not (csDesigning in ComponentState) then
Populate;
end;
procedure TOvcFileComboBox.DrawItem(Index : Integer; ItemRect: TRect;
State : TOwnerDrawState);
var
Icon : HIcon;
SepRect : TRect;
BkColor : TColor;
TxtRect : TRect;
TxtItem : array [0..255] of char;
BkMode : Integer;
begin
with Canvas do begin
if (FMRUList.Items.Count > 0) and (Index < FMRUList.Items.Count) then
BkColor := FMRUListColor
else
BkColor := Color;
if odSelected in State then
Brush.Color := clHighlight
else
Brush.Color := BkColor;
FillRect(ItemRect);
if FShowIcons then begin
with Items do
Icon := vLoadIcon(FullName(Directory, Items[Index]));
if Icon <> 0 then begin
DrawIconEx(
Handle, ItemRect.Left, ItemRect.Top, Icon,
ItemHeight - 2,
ItemHeight - 2,
0,
0,
DI_NORMAL
);
end;
with ItemRect do
TxtRect := Rect(Left + ItemHeight, Top, Right, Bottom);
end else
TxtRect := ItemRect;
StrPCopy(TxtItem, Items[Index]);
BkMode := GetBkMode(Canvas.Handle);
SetBkMode(Canvas.Handle, TRANSPARENT);
DrawText(Canvas.Handle, TxtItem, StrLen(TxtItem), TxtRect,
DT_SINGLELINE or DT_VCENTER or DT_LEFT);
SetBkMode(Canvas.Handle, BkMode);
if (FMRUList.Items.Count > 0) and (Index = FMRUList.Items.Count - 1) then begin
SepRect := ItemRect;
SepRect.Top := SepRect.Bottom - cbxSeparatorHeight;
SepRect.Bottom := SepRect.Bottom;
Pen.Color := clGrayText;
if not DrawingEdit then
with SepRect do
Rectangle(Left-1, Top, Right+1, Bottom);
end;
end;
end;
procedure TOvcFileComboBox.Populate;
var
SR : TSearchRec;
lAttributes : Word;
StrFiles : TStringList;
begin
ClearItems;
lAttributes := 0;
if cbxReadOnly in FAttributes then
lAttributes := lAttributes or faReadOnly;
if cbxHidden in FAttributes then
lAttributes := lAttributes or faHidden;
if cbxSysFile in FAttributes then
lAttributes := lAttributes or faSysFile;
if cbxArchive in FAttributes then
lAttributes := lAttributes or faArchive;
if cbxAnyFile in FAttributes then
lAttributes := lAttributes or faAnyFile;
if FindFirst(FullName(Directory, FileMask), lAttributes, SR) = 0 then begin
StrFiles := TStringList.Create;
try
repeat
if (SR.Attr and faDirectory) = 0 then
StrFiles.AddObject(SR.Name, Pointer(SR.Attr));
until FindNext(SR) <> 0;
StrFiles.Sort;
Items.AddStrings(StrFiles);
finally
StrFiles.Free;
end;
end;
FindClose(SR);
end;
procedure TOvcFileComboBox.SetAttributes(Value : TOvcCbxFileAttributes);
begin
if Value <> FAttributes then begin
FAttributes := Attributes;
Populate;
end;
end;
procedure TOvcFileComboBox.SetDirectory(const Value : string);
begin
if Value <> FDirName then begin
FDirName := Value;
Populate;
end;
end;
procedure TOvcFileComboBox.SetFileMask(const Value : string);
begin
if Value <> FFileMask then begin
FFileMask := Value;
Populate;
end;
end;
procedure TOvcFileComboBox.SetShowIcons(Value : Boolean);
begin
if Value <> FShowIcons then begin
FShowIcons := Value;
DroppedDown := False;
end;
end;
end.