1 | Unit MultiColumnListBox;
|
---|
2 |
|
---|
3 | Interface
|
---|
4 |
|
---|
5 | Uses
|
---|
6 | Classes, Forms, ExtCtrls, StdCtrls, ComCtrls, SysUtils, Dialogs, Graphics;
|
---|
7 |
|
---|
8 | {Declare new class}
|
---|
9 | Type
|
---|
10 | TMultiColumnListBox=Class(TListBox)
|
---|
11 | Private
|
---|
12 | BmpList: TList;
|
---|
13 | sections: THeaderSections;
|
---|
14 | sep_char: string;
|
---|
15 |
|
---|
16 | Function GetBitmap(Index:LongInt):TBitmap;
|
---|
17 | Procedure SetBitmap(index:LongInt;bmp:TBitmap);
|
---|
18 | Function GetSepChar:string;
|
---|
19 | Procedure SetSepChar(Value:string);
|
---|
20 | Protected
|
---|
21 | Procedure SetupComponent;Override;
|
---|
22 | Procedure DrawItem(Index:LONGINT;Rec:TRect;State:TOwnerDrawState);Override;
|
---|
23 | Public
|
---|
24 | Function Add(s:string):LongInt;
|
---|
25 | Function AddObject(s:string;o:TObject):LongInt;
|
---|
26 | Property Bitmaps[index:LongInt]:TBitmap write SetBitmap read GetBitmap;
|
---|
27 | Procedure SetHeader(s: THeaderSections);
|
---|
28 | Procedure Sort(section:Integer);
|
---|
29 | Destructor Destroy; Override;
|
---|
30 | Procedure Clear; Override;
|
---|
31 | Property Separator:string read GetSepChar write SetSepChar;
|
---|
32 | End;
|
---|
33 |
|
---|
34 | Type
|
---|
35 | MultiColumnList=Class(TPanel)
|
---|
36 | Private
|
---|
37 | List: TMultiColumnListBox;
|
---|
38 | Header: THeaderControl;
|
---|
39 | Fenabled: Boolean;
|
---|
40 | drag_mode:TDragMode;
|
---|
41 | Function GetSections:THeaderSections;
|
---|
42 | Function GetSectionsItem(Index:LongInt):THeaderSection;//gehn
|
---|
43 | Function GetSectionsCount:LongInt;//gehn
|
---|
44 | Procedure SetSections(Value:THeaderSections);
|
---|
45 | Function GetDuplicates:Boolean;
|
---|
46 | Procedure SetDuplicates(Value:Boolean);
|
---|
47 | Function GetExtendedSelect:Boolean;
|
---|
48 | Procedure SetExtendedSelect(Value:Boolean);
|
---|
49 | Function GetItemIndex:LongInt;
|
---|
50 | Procedure SetItemIndex(Value:LongInt);
|
---|
51 | Function GetMultiSelect:Boolean;
|
---|
52 | Procedure SetMultiSelect(Value:Boolean);
|
---|
53 | Function GetOnItemFocus:TItemFocusEvent;
|
---|
54 | Procedure SetOnItemFocus(Value:TItemFocusEvent);
|
---|
55 | Function GetOnItemSelect:TItemSelectEvent;
|
---|
56 | Procedure SetOnItemSelect(Value:TItemSelectEvent);
|
---|
57 | Function GetSelCount:LongInt;
|
---|
58 | Function GetSelected(Index:LongInt):Boolean;
|
---|
59 | Procedure SetSelected(Index:LongInt;Value:Boolean);
|
---|
60 | Function GetTheFont:TFont;
|
---|
61 | Procedure SetTheFont(Value:TFont);
|
---|
62 | Function GetValue(field,index:LongInt):string;
|
---|
63 | Procedure SetValue(field,index:LongInt;Value:string);
|
---|
64 | Function GetBitmap(index:LongInt):TBitmap;
|
---|
65 | Procedure SetBitmap(index:LongInt; bmp:TBitmap);
|
---|
66 | Function GetHint:string;
|
---|
67 | Procedure SetHint(Value:string);
|
---|
68 | Function GetObjects(Index:LongInt):TObject;
|
---|
69 | Procedure SetObjects(Index:LongInt;Value:TObject);
|
---|
70 | Function GetShowDragRects:Boolean;
|
---|
71 | Procedure SetShowDragRects(Value:Boolean);
|
---|
72 | Function GetHeaderHint:string;
|
---|
73 | Procedure SetHeaderHint(Value:string);
|
---|
74 | Procedure SetEnabled(Value:Boolean);
|
---|
75 | Function GetCount:LongInt;
|
---|
76 | Procedure SetDragMode(Value:TDragMode);
|
---|
77 | Procedure EvSectionPressed(sender: THeaderControl; section: THeaderSection);
|
---|
78 | Procedure EvSectionTrack(sender: THeaderControl; section: THeaderSection; width: LongInt; State:TSectionTrackState);
|
---|
79 | Procedure EvCanDrag(sender: TObject; X,Y: LongInt; var Accept: Boolean);
|
---|
80 | Procedure EvDragDrop(sender: TObject; source: TObject; X,Y: LongInt);
|
---|
81 | Procedure EvDragOver(sender: TObject; source: TObject; X,Y: LongInt; State: TDragState; var Accept: Boolean);
|
---|
82 |
|
---|
83 | Function GetSepChar:string;
|
---|
84 | Procedure SetSepChar(Value:string);
|
---|
85 |
|
---|
86 | Protected
|
---|
87 | Procedure SetupComponent; Override;
|
---|
88 | Procedure SetupShow;Override;
|
---|
89 | Procedure Resize;Override;
|
---|
90 |
|
---|
91 | Public
|
---|
92 | Procedure ReadSCUResource(Const ResName:TResourceName;Var Data;DataLen:LongInt);Override;
|
---|
93 | Function WriteSCUResource(Stream:TResourceStream):Boolean;Override;
|
---|
94 | Destructor Destroy; Override;
|
---|
95 | Constructor Create(AOwner:TComponent); Override;
|
---|
96 | Procedure SelectAll;
|
---|
97 | Procedure DeselectAll;
|
---|
98 | Function Add(s:string):LongInt;
|
---|
99 | Function AddObject(s:string;o:TObject):LongInt;
|
---|
100 | Procedure Delete(Index:LongInt);
|
---|
101 | Procedure Clear;
|
---|
102 | Function ItemRect(Index:LongInt):TRect;
|
---|
103 | Function IsDraggedSourceMe(source: TObject):Boolean;
|
---|
104 | Procedure Sort(section:Integer);
|
---|
105 | Function IndexOf(s:string):LongInt;
|
---|
106 | Procedure BeginUpdate;
|
---|
107 | Procedure EndUpdate;
|
---|
108 | //gehn
|
---|
109 | Procedure SetSectionsItemText(Index:LongInt; NewText:String);
|
---|
110 |
|
---|
111 | Property ListBox: TMultiColumnListBox read List;
|
---|
112 | Property HeaderControl: THeaderControl read Header;
|
---|
113 | Property SelCount: LongInt read GetSelCount;
|
---|
114 | Property Selected[Index: LongInt]: Boolean read GetSelected write SetSelected;
|
---|
115 | Property Values[field,index:LongInt]: string read GetValue write SetValue;default;
|
---|
116 | Property Bitmaps[index:LongInt]:TBitmap write SetBitmap read GetBitmap;
|
---|
117 | Property Objects[index:LongInt]:TObject read GetObjects write SetObjects;
|
---|
118 | Property Count:LongInt read GetCount;
|
---|
119 | Property ItemIndex: LongInt read GetItemIndex write SetItemIndex;
|
---|
120 | Property TabStop;
|
---|
121 |
|
---|
122 | Published
|
---|
123 | Property Sections: THeaderSections read GetSections write SetSections;
|
---|
124 | Property Duplicates: Boolean read GetDuplicates write SetDuplicates;
|
---|
125 | Property ExtendedSelect: Boolean read GetExtendedSelect write SetExtendedSelect;
|
---|
126 | Property MultiSelect: Boolean read GetMultiSelect write SetMultiSelect;
|
---|
127 | Property OnItemFocus: TItemFocusEvent read GetOnItemFocus write SetOnItemFocus;
|
---|
128 | Property OnItemSelect: TItemSelectEvent read GetOnItemSelect write SetOnItemSelect;
|
---|
129 | Property Font:TFont read GetTheFont write SetTheFont;
|
---|
130 | Property Hint:string read GetHint write SetHint;
|
---|
131 | Property HeaderHint:string read GetHeaderHint write SetHeaderHint;
|
---|
132 | Property Enabled:Boolean read Fenabled write SetEnabled;
|
---|
133 | Property ShowDragRects:Boolean read GetShowDragRects write SetShowDragRects;
|
---|
134 | Property DragMode:TDragMode read drag_mode write SetDragMode;
|
---|
135 | Property Separator:string read GetSepChar write SetSepChar;
|
---|
136 | End;
|
---|
137 |
|
---|
138 |
|
---|
139 | {Define components to export}
|
---|
140 | {You may define a page of the component palette and a component bitmap file}
|
---|
141 | Exports
|
---|
142 | MultiColumnList,'User','';
|
---|
143 |
|
---|
144 |
|
---|
145 | Implementation
|
---|
146 |
|
---|
147 | Procedure TMultiColumnListBox.Sort(section:Integer);
|
---|
148 | Function CurrencyToFloat(s:string):double;
|
---|
149 | Var
|
---|
150 | i:LongInt;
|
---|
151 | Begin
|
---|
152 | // Get rid of any non numeric symbols...
|
---|
153 | i:=1;
|
---|
154 | If s[i]='-' then
|
---|
155 | Inc(i);
|
---|
156 | While (i<=Length(s)) do
|
---|
157 | Begin
|
---|
158 | /* gehn
|
---|
159 | If ((s[i]<'0') Or (s[i]>'9')) And (s[i]<>'.') then
|
---|
160 | */
|
---|
161 | If ((s[i]<'0') Or (s[i]>'9')) And (s[i]<>DecimalSeparator) then
|
---|
162 | Delete(s,i,1);
|
---|
163 | i:=i+1;
|
---|
164 | End;
|
---|
165 | Try
|
---|
166 | Result:=StrToFloat(s);
|
---|
167 | Except
|
---|
168 | Result:=0.0;
|
---|
169 | End;
|
---|
170 | End;
|
---|
171 |
|
---|
172 | Var
|
---|
173 | strings:TStringList;
|
---|
174 |
|
---|
175 | Function DoCompare(Const S, T: String): Integer;
|
---|
176 | Var
|
---|
177 | s1,s2,ds1,ds2,tmp: string;
|
---|
178 | indx,i:Integer;
|
---|
179 | dt1,dt2:TDateTime;
|
---|
180 | f1,f2:Extended;
|
---|
181 | h1,m1,h2,m2:LongInt;
|
---|
182 | Begin
|
---|
183 | s1:= S;
|
---|
184 | s2:= T;
|
---|
185 | // Remove the T/F flag that occupies the first char
|
---|
186 | // and remove the bitmap number at the start.
|
---|
187 | Delete(s1,1,1);
|
---|
188 | Delete(s2,1,1);
|
---|
189 | For i:=1 To section Do
|
---|
190 | Begin
|
---|
191 | indx:=Pos(sep_char,s1);
|
---|
192 | if indx>0 then System.Delete(s1,1,indx);
|
---|
193 | indx:=Pos(sep_char,s2);
|
---|
194 | if indx>0 then System.Delete(s2,1,indx);
|
---|
195 | End;
|
---|
196 | Try
|
---|
197 | ds1:=s1;
|
---|
198 | indx:=Pos(sep_char,ds1);
|
---|
199 | if indx>0 then System.SubStr(ds1,1,indx-1);
|
---|
200 | ds2:=s2;
|
---|
201 | indx:=Pos(sep_char,ds2);
|
---|
202 | if indx>0 then System.SubStr(ds2,1,indx-1);
|
---|
203 | dt1:=StrToDate(ds1);
|
---|
204 | dt2:=StrToDate(ds2);
|
---|
205 | If dt1<dt2 then
|
---|
206 | Result:=1
|
---|
207 | Else If dt1>dt2 then
|
---|
208 | Result:=-1
|
---|
209 | Else
|
---|
210 | Result:=0;
|
---|
211 | Except
|
---|
212 | Try
|
---|
213 | If ds1[2]=':' then
|
---|
214 | Begin
|
---|
215 | tmp:=ds1;
|
---|
216 | SubStr(tmp,1,1);
|
---|
217 | h1:=StrToInt(tmp);
|
---|
218 | tmp:=ds1;
|
---|
219 | SubStr(tmp,3,2);
|
---|
220 | m1:=StrToInt(tmp);
|
---|
221 | If h1=12 then h1:=0;
|
---|
222 | tmp:=ds1;
|
---|
223 | SubStr(tmp,5,2);
|
---|
224 | If CompareText(tmp,'pm')=0 then
|
---|
225 | h1:=h1+12
|
---|
226 | Else If CompareText(tmp,'am')<>0 then
|
---|
227 | Raise EConvertError.Create('');
|
---|
228 | End Else If ds1[3]=':' then
|
---|
229 | Begin
|
---|
230 | tmp:=ds1;
|
---|
231 | SubStr(tmp,1,2);
|
---|
232 | h1:=StrToInt(tmp);
|
---|
233 | tmp:=ds1;
|
---|
234 | SubStr(tmp,4,2);
|
---|
235 | m1:=StrToInt(tmp);
|
---|
236 | If h1=12 then h1:=0;
|
---|
237 | tmp:=ds1;
|
---|
238 | SubStr(tmp,6,2);
|
---|
239 | If CompareText(tmp,'pm')=0 then
|
---|
240 | h1:=h1+12
|
---|
241 | Else If CompareText(tmp,'am')<>0 then
|
---|
242 | Raise EConvertError.Create('');
|
---|
243 | End Else
|
---|
244 | Raise EConvertError.Create('');
|
---|
245 | If ds2[2]=':' then
|
---|
246 | Begin
|
---|
247 | tmp:=ds2;
|
---|
248 | SubStr(tmp,1,1);
|
---|
249 | h2:=StrToInt(tmp);
|
---|
250 | tmp:=ds2;
|
---|
251 | SubStr(tmp,3,2);
|
---|
252 | m2:=StrToInt(tmp);
|
---|
253 | If h2=12 then h2:=0;
|
---|
254 | tmp:=ds2;
|
---|
255 | SubStr(tmp,5,2);
|
---|
256 | If CompareText(tmp,'pm')=0 then
|
---|
257 | h2:=h2+12
|
---|
258 | Else If CompareText(tmp,'am')<>0 then
|
---|
259 | Raise EConvertError.Create('');
|
---|
260 | End Else If ds2[3]=':' then
|
---|
261 | Begin
|
---|
262 | tmp:=ds2;
|
---|
263 | SubStr(tmp,1,2);
|
---|
264 | h2:=StrToInt(tmp);
|
---|
265 | tmp:=ds2;
|
---|
266 | SubStr(tmp,4,2);
|
---|
267 | m2:=StrToInt(tmp);
|
---|
268 | If h2=12 then h2:=0;
|
---|
269 | tmp:=ds2;
|
---|
270 | SubStr(tmp,6,2);
|
---|
271 | If CompareText(tmp,'pm')=0 then
|
---|
272 | h2:=h2+12
|
---|
273 | Else If CompareText(tmp,'am')<>0 then
|
---|
274 | Raise EConvertError.Create('');
|
---|
275 | End Else
|
---|
276 | Raise EConvertError.Create('');
|
---|
277 | If h1<h2 then
|
---|
278 | Result:=1
|
---|
279 | Else If h1>h2 then
|
---|
280 | Result:=-1
|
---|
281 | Else If m1<m2 then
|
---|
282 | Result:=1
|
---|
283 | Else If m1>m2 then
|
---|
284 | Result:=-1
|
---|
285 | Else
|
---|
286 | Result:=0;
|
---|
287 | Except
|
---|
288 | // Then try currency!
|
---|
289 | Try
|
---|
290 | f1:=CurrencyToFloat(ds1);
|
---|
291 | f2:=CurrencyToFloat(ds2);
|
---|
292 | If f1<f2 then
|
---|
293 | Result:=-1
|
---|
294 | Else If f1>f2 then
|
---|
295 | Result:=1
|
---|
296 | Else
|
---|
297 | Raise EConvertError.Create('');
|
---|
298 | Except
|
---|
299 | // Or a number.
|
---|
300 | Try
|
---|
301 | f1:=StrToFloat(ds1);
|
---|
302 | f2:=StrToFloat(ds2);
|
---|
303 | If f1<f2 then
|
---|
304 | Result:=-1
|
---|
305 | Else If f1>f2 then
|
---|
306 | Result:=1
|
---|
307 | Else
|
---|
308 | Raise EConvertError.Create('');
|
---|
309 | Except
|
---|
310 | // Then just compare the text!
|
---|
311 | Result:=CompareText(s1,s2);
|
---|
312 | End;
|
---|
313 | End;
|
---|
314 | End;
|
---|
315 | End;
|
---|
316 | If Result=0 then
|
---|
317 | Result:=CompareText(S,T);
|
---|
318 | End;
|
---|
319 |
|
---|
320 | Procedure Exchange(I, J:LongInt);
|
---|
321 | Var
|
---|
322 | p:Pointer;
|
---|
323 | Begin
|
---|
324 | strings.Exchange(I,J);
|
---|
325 | Try
|
---|
326 | p:=BmpList[I];
|
---|
327 | BmpList[I]:=BmpList[J];
|
---|
328 | BmpList[J]:=p;
|
---|
329 | Except
|
---|
330 | If BmpList.Count<Items.Count then
|
---|
331 | BmpList.Count:=Items.Count;
|
---|
332 | End;
|
---|
333 | End;
|
---|
334 |
|
---|
335 | Procedure Reheap(I, K: LongInt);
|
---|
336 | Var
|
---|
337 | J: LongInt;
|
---|
338 | Begin
|
---|
339 | J := I;
|
---|
340 | While J Shl 1 < K Do
|
---|
341 | Begin
|
---|
342 | If DoCompare(strings[J Shl 1 - 1], strings[J Shl 1 + 1 - 1]) > 0 Then J := J Shl 1
|
---|
343 | Else J := J Shl 1 + 1;
|
---|
344 | End;
|
---|
345 | If J Shl 1 = K Then J := K;
|
---|
346 |
|
---|
347 | While DoCompare(strings[I - 1], strings[J - 1]) > 0 Do J := J Shr 1;
|
---|
348 |
|
---|
349 | Exchange(I - 1, J - 1);
|
---|
350 | J := J Shr 1;
|
---|
351 |
|
---|
352 | While J >= I Do
|
---|
353 | Begin
|
---|
354 | Exchange(I - 1, J - 1);
|
---|
355 | J := J Shr 1;
|
---|
356 | End;
|
---|
357 | End;
|
---|
358 |
|
---|
359 | Var
|
---|
360 | I, C: LongInt;
|
---|
361 | s:string;
|
---|
362 | Begin
|
---|
363 |
|
---|
364 | strings.Create;
|
---|
365 | For I:=0 to Items.Count-1 do
|
---|
366 | Begin
|
---|
367 | // Save the selected flag to be restored later.
|
---|
368 | If Selected[I] then
|
---|
369 | strings.AddObject('T'+Items[I],Items.Objects[I])
|
---|
370 | Else
|
---|
371 | strings.AddObject('F'+Items[I],Items.Objects[I]);
|
---|
372 | End;
|
---|
373 | C := strings.Count;
|
---|
374 | For I := C Shr 1 DownTo 1 Do Reheap(I, C);
|
---|
375 | For I := C DownTo 2 Do
|
---|
376 | Begin
|
---|
377 | Exchange(0, I - 1);
|
---|
378 | Reheap(1, I - 1);
|
---|
379 | End;
|
---|
380 | Items.Clear;
|
---|
381 | For I:=0 to strings.Count-1 do
|
---|
382 | Begin
|
---|
383 | s:=strings[I];
|
---|
384 | Delete(s,1,1);
|
---|
385 | Items.AddObject(s,strings.Objects[I]);
|
---|
386 | Selected[I]:=(strings[I][1]='T');
|
---|
387 | End;
|
---|
388 | strings.Free;
|
---|
389 | End;
|
---|
390 |
|
---|
391 | Procedure TMultiColumnListBox.SetupComponent;
|
---|
392 | Begin
|
---|
393 | Inherited SetupComponent;
|
---|
394 | Style:=lbOwnerdrawFixed;
|
---|
395 | BmpList:=TList.Create;
|
---|
396 | sep_char:='|';
|
---|
397 | End;
|
---|
398 |
|
---|
399 | Destructor TMultiColumnListBox.Destroy;
|
---|
400 | Begin
|
---|
401 | Inherited Destroy;
|
---|
402 | BmpList.Free;
|
---|
403 | End;
|
---|
404 |
|
---|
405 | Procedure TMultiColumnListBox.Clear;
|
---|
406 | Begin
|
---|
407 | Inherited Clear;
|
---|
408 | BmpList.Clear;
|
---|
409 | End;
|
---|
410 |
|
---|
411 | Function TMultiColumnListBox.Add(s:string):LongInt;
|
---|
412 | Begin
|
---|
413 | Result:=Items.Add(s);
|
---|
414 | If BmpList.Count<Items.Count then
|
---|
415 | BmpList.Count:=Items.Count;
|
---|
416 | End;
|
---|
417 |
|
---|
418 | Function TMultiColumnListBox.AddObject(s:string;o:TObject):LongInt;
|
---|
419 | Begin
|
---|
420 | Result:=Items.AddObject(s,o);
|
---|
421 | If BmpList.Count<Items.Count then
|
---|
422 | BmpList.Count:=Items.Count;
|
---|
423 | End;
|
---|
424 |
|
---|
425 | Procedure TMultiColumnListBox.DrawItem(Index:LONGINT;Rec:TRect;State:TOwnerDrawState);
|
---|
426 | Var
|
---|
427 | x,y,y1,cx,cy,cx1,cy1:LONGINT;
|
---|
428 | idx,i:LONGINT;
|
---|
429 | s,s1:STRING;
|
---|
430 | rec1:TRect;
|
---|
431 | bmp:TBitmap;
|
---|
432 | Begin
|
---|
433 | If State * [odSelected] <> [] Then
|
---|
434 | Begin
|
---|
435 | Canvas.Pen.Color := clHighLightText;
|
---|
436 | Canvas.Brush.Color := clHighLight;
|
---|
437 | End Else
|
---|
438 | Begin
|
---|
439 | If Not Enabled then
|
---|
440 | Canvas.Pen.Color := clDkGray
|
---|
441 | Else
|
---|
442 | Canvas.Pen.Color := PenColor;
|
---|
443 | Canvas.Brush.Color := Color;
|
---|
444 | End;
|
---|
445 | Rec.Top:=Rec.Top-1;
|
---|
446 | Canvas.FillRect(Rec,Canvas.Brush.Color);
|
---|
447 |
|
---|
448 | x := Rec.Left + 2;
|
---|
449 | y := Rec.Bottom;
|
---|
450 | cx := Rec.Right - x;
|
---|
451 | cy := Rec.Top - y;
|
---|
452 |
|
---|
453 | Try
|
---|
454 | bmp:=TBitmap(BmpList[Index]);
|
---|
455 | Except
|
---|
456 | bmp:=Nil;
|
---|
457 | End;
|
---|
458 | i := 1;
|
---|
459 | s := Items.Strings[Index];
|
---|
460 | While (i<=sections.Count) And (s<>'') do
|
---|
461 | Begin
|
---|
462 | idx:=Pos(sep_char,s);
|
---|
463 | If idx=0 Then
|
---|
464 | Begin
|
---|
465 | s1:=s;
|
---|
466 | s:='';
|
---|
467 | End Else
|
---|
468 | Begin
|
---|
469 | s1:=s;
|
---|
470 | SubStr(s1,1,idx-1);
|
---|
471 | Delete(s,1,idx);
|
---|
472 | End;
|
---|
473 | rec1.top:=rec.top+50;
|
---|
474 | If rec1.top<2 then
|
---|
475 | Exit;
|
---|
476 | rec1.bottom:=rec.bottom;
|
---|
477 | If rec1.bottom<2 then
|
---|
478 | rec1.bottom:=2;
|
---|
479 | rec1.left:=sections.Items[i-1].Left;
|
---|
480 | rec1.right:=sections.Items[i-1].Right;
|
---|
481 | If (i=1) And (bmp<>Nil) then
|
---|
482 | Begin
|
---|
483 | cx1:=bmp.Width;
|
---|
484 | cy1:=bmp.Height;
|
---|
485 | End Else
|
---|
486 | Canvas.GetTextExtent(s1,cx1,cy1);
|
---|
487 | If sections[i-1].Alignment=taRightJustify then
|
---|
488 | Begin
|
---|
489 | x:=sections[i-1].Right-2-cx1;
|
---|
490 | End Else
|
---|
491 | Begin
|
---|
492 | If sections[i-1].Alignment=taLeftJustify then
|
---|
493 | x:=sections[i-1].Left+2
|
---|
494 | Else
|
---|
495 | x:=(sections[i-1].Left+sections[i-1].Right-cx1)/2+2;
|
---|
496 | End;
|
---|
497 | y1 := y + ((cy - cy1) Div 2);
|
---|
498 | If y1 < Rec.Bottom Then y1 := Rec.Bottom;
|
---|
499 | If (i=1) And (bmp<>Nil) then
|
---|
500 | Begin
|
---|
501 | Canvas.Draw(x,y1,bmp);
|
---|
502 | End Else Begin
|
---|
503 | Canvas.Brush.Mode := bmTransparent;
|
---|
504 | Canvas.TextRect(rec1,x,y1,s1);
|
---|
505 | End;
|
---|
506 | i := i + 1;
|
---|
507 | End;
|
---|
508 | End;
|
---|
509 |
|
---|
510 | Function TMultiColumnListBox.GetSepChar:string;
|
---|
511 | Begin
|
---|
512 | Result:=sep_char;
|
---|
513 | End;
|
---|
514 |
|
---|
515 | Procedure TMultiColumnListBox.SetSepChar(Value:string);
|
---|
516 | Begin
|
---|
517 | sep_char:=Value;
|
---|
518 | End;
|
---|
519 |
|
---|
520 | Function TMultiColumnListBox.GetBitmap(Index:LongInt):TBitmap;
|
---|
521 | Begin
|
---|
522 | If (Index<0) Or (Index>=BmpList.Count) then
|
---|
523 | Result:=Nil
|
---|
524 | Else
|
---|
525 | Result:=BmpList[Index];
|
---|
526 | End;
|
---|
527 |
|
---|
528 | Procedure TMultiColumnListBox.SetBitmap(Index:LongInt; bmp:TBitmap);
|
---|
529 | Begin
|
---|
530 | If BmpList.Count<Items.Count then
|
---|
531 | BmpList.Count:=Items.Count;
|
---|
532 | If BmpList.Count>Index then
|
---|
533 | BmpList[Index]:=bmp;
|
---|
534 | End;
|
---|
535 |
|
---|
536 | Procedure TMultiColumnListBox.SetHeader(s: THeaderSections);
|
---|
537 | Begin
|
---|
538 | sections:=s;
|
---|
539 | End;
|
---|
540 |
|
---|
541 | Function MultiColumnList.GetValue(field,index:LongInt):string;
|
---|
542 | Var
|
---|
543 | i, p: LongInt;
|
---|
544 | Begin
|
---|
545 | If (index>=List.Items.Count) Or (field<0) Or (index<0) then
|
---|
546 | Result:=''
|
---|
547 | Else Begin
|
---|
548 | Result:=List.Items[index];
|
---|
549 | For i:=0 to field-1 do
|
---|
550 | Begin
|
---|
551 | If Length(Result)>0 then
|
---|
552 | Begin
|
---|
553 | p:=Pos(List.Separator,Result);
|
---|
554 | If p>0 then
|
---|
555 | System.Delete(Result,1,p);
|
---|
556 | End;
|
---|
557 | End;
|
---|
558 | If Length(Result)>0 then
|
---|
559 | Begin
|
---|
560 | p:=Pos(List.Separator,Result);
|
---|
561 | If p>0 then
|
---|
562 | SubStr(Result,1,p-1);
|
---|
563 | End;
|
---|
564 | End;
|
---|
565 | End;
|
---|
566 |
|
---|
567 | Procedure MultiColumnList.SetValue(field,index:LongInt;Value:string);
|
---|
568 | Var
|
---|
569 | i, p: LongInt;
|
---|
570 | sl,sr,s:string;
|
---|
571 | Begin
|
---|
572 | If (field<sections.Count) And (index<List.Items.Count) And
|
---|
573 | (field>=0) And (index>=0) then
|
---|
574 | Begin
|
---|
575 | sr:=List.Items[index];
|
---|
576 | sl:='';
|
---|
577 | For i:=0 to field-1 do
|
---|
578 | Begin
|
---|
579 | p:=Pos(List.Separator,sr);
|
---|
580 | If p>0 then
|
---|
581 | Begin
|
---|
582 | s:=sr;
|
---|
583 | System.SubStr(s,1,p-1);
|
---|
584 | System.Delete(sr,1,p);
|
---|
585 | End;
|
---|
586 | sl:=sl+s+List.Separator;
|
---|
587 | End;
|
---|
588 | p:=Pos(List.Separator,sr);
|
---|
589 | If p>0 then
|
---|
590 | Begin
|
---|
591 | System.Delete(sr,1,p);
|
---|
592 | List.Items[Index]:=sl+Value+List.Separator+sr;
|
---|
593 | End Else
|
---|
594 | List.Items[Index]:=sl+Value;
|
---|
595 | End;
|
---|
596 | End;
|
---|
597 |
|
---|
598 | Function MultiColumnList.GetSepChar:string;
|
---|
599 | Begin
|
---|
600 | Result:=List.Separator;
|
---|
601 | End;
|
---|
602 |
|
---|
603 | Procedure MultiColumnList.SetSepChar(Value:string);
|
---|
604 | Begin
|
---|
605 | List.Separator:=Value;
|
---|
606 | End;
|
---|
607 |
|
---|
608 | Function MultiColumnList.GetHint:string;
|
---|
609 | Begin
|
---|
610 | Result:=List.Hint;
|
---|
611 | End;
|
---|
612 |
|
---|
613 | Procedure MultiColumnList.SetHint(Value:string);
|
---|
614 | Begin
|
---|
615 | List.Hint:=Value;
|
---|
616 | End;
|
---|
617 |
|
---|
618 | Procedure MultiColumnList.SetEnabled(Value:Boolean);
|
---|
619 | Begin
|
---|
620 | Fenabled:=Value;
|
---|
621 | If Fenabled then
|
---|
622 | Begin
|
---|
623 | Header.Enabled:=True;
|
---|
624 | List.Enabled:=True;
|
---|
625 | Header.PenColor:=clBlack;
|
---|
626 | End Else
|
---|
627 | Begin
|
---|
628 | Header.Enabled:=False;
|
---|
629 | List.Enabled:=False;
|
---|
630 | Header.PenColor:=clDkGray;
|
---|
631 | End;
|
---|
632 | End;
|
---|
633 |
|
---|
634 | Function MultiColumnList.GetHeaderHint:string;
|
---|
635 | Begin
|
---|
636 | Result:=Header.Hint;
|
---|
637 | End;
|
---|
638 |
|
---|
639 | Procedure MultiColumnList.SetHeaderHint(Value:string);
|
---|
640 | Begin
|
---|
641 | Header.Hint:=Value;
|
---|
642 | End;
|
---|
643 |
|
---|
644 | Function MultiColumnList.GetShowDragRects:Boolean;
|
---|
645 | Begin
|
---|
646 | Result:=List.ShowDragRects;
|
---|
647 | End;
|
---|
648 |
|
---|
649 | Procedure MultiColumnList.SetShowDragRects(Value:Boolean);
|
---|
650 | Begin
|
---|
651 | List.ShowDragRects:=Value;
|
---|
652 | End;
|
---|
653 |
|
---|
654 | Function MultiColumnList.GetTheFont:TFont;
|
---|
655 | Begin
|
---|
656 | Result:=List.Font;
|
---|
657 | End;
|
---|
658 |
|
---|
659 | Procedure MultiColumnList.SetTheFont(Value:TFont);
|
---|
660 | Begin
|
---|
661 | List.Font:=Value;
|
---|
662 | Header.Font:=Value;
|
---|
663 | End;
|
---|
664 |
|
---|
665 | Function MultiColumnList.GetSections:THeaderSections;
|
---|
666 | Begin
|
---|
667 | Result := Header.sections;
|
---|
668 | End;
|
---|
669 |
|
---|
670 | //gehn
|
---|
671 | Function MultiColumnList.GetSectionsCount:LongInt;
|
---|
672 | Begin
|
---|
673 | Result := GetSections.Count;
|
---|
674 | End;
|
---|
675 |
|
---|
676 | //gehn
|
---|
677 | Function MultiColumnList.GetSectionsItem(Index:LongInt):THeaderSection;
|
---|
678 | Begin
|
---|
679 | If (Index < 0) or (Index > GetSectionsCount-1) then
|
---|
680 | Begin
|
---|
681 | Result := Nil;
|
---|
682 | End
|
---|
683 | else
|
---|
684 | Begin
|
---|
685 | Result := Header.Sections.Items[Index];
|
---|
686 | End;
|
---|
687 | End;
|
---|
688 | //gehn
|
---|
689 | Procedure MultiColumnList.SetSectionsItemText(Index:LongInt; NewText:String);
|
---|
690 | Var
|
---|
691 | SectionsItem: THeaderSection;
|
---|
692 | Begin
|
---|
693 | If (Index > 0) or (Index < GetSectionsCount-1) then
|
---|
694 | Begin
|
---|
695 | SectionsItem := GetSectionsItem(Index);
|
---|
696 | SectionsItem.Text := NewText;
|
---|
697 | Header.Sections.Items[Index] := SectionsItem;
|
---|
698 | End;
|
---|
699 | End;
|
---|
700 |
|
---|
701 | Procedure MultiColumnList.SetSections(Value:THeaderSections);
|
---|
702 | Begin
|
---|
703 | Header.sections := Value;
|
---|
704 | End;
|
---|
705 |
|
---|
706 | Function MultiColumnList.GetDuplicates:Boolean;
|
---|
707 | Begin
|
---|
708 | Result:=List.Duplicates;
|
---|
709 | End;
|
---|
710 |
|
---|
711 | Procedure MultiColumnList.SetDuplicates(Value:Boolean);
|
---|
712 | Begin
|
---|
713 | List.Duplicates:=Value;
|
---|
714 | End;
|
---|
715 |
|
---|
716 | Function MultiColumnList.GetExtendedSelect:Boolean;
|
---|
717 | Begin
|
---|
718 | Result:= List.ExtendedSelect;
|
---|
719 | End;
|
---|
720 |
|
---|
721 | Procedure MultiColumnList.SetExtendedSelect(Value:Boolean);
|
---|
722 | Begin
|
---|
723 | List.ExtendedSelect:= Value;
|
---|
724 | End;
|
---|
725 |
|
---|
726 | Function MultiColumnList.GetItemIndex:LongInt;
|
---|
727 | Begin
|
---|
728 | Result:= List.ItemIndex;
|
---|
729 | End;
|
---|
730 |
|
---|
731 | Procedure MultiColumnList.SetItemIndex(Value:LongInt);
|
---|
732 | Begin
|
---|
733 | List.ItemIndex:= Value;
|
---|
734 | End;
|
---|
735 |
|
---|
736 | Function MultiColumnList.GetMultiSelect:Boolean;
|
---|
737 | Begin
|
---|
738 | Result:= List.MultiSelect;
|
---|
739 | End;
|
---|
740 |
|
---|
741 | Procedure MultiColumnList.SetMultiSelect(Value:Boolean);
|
---|
742 | Begin
|
---|
743 | List.MultiSelect:= Value;
|
---|
744 | End;
|
---|
745 |
|
---|
746 | Function MultiColumnList.GetOnItemFocus:TItemFocusEvent;
|
---|
747 | Begin
|
---|
748 | Result:= List.OnItemFocus;
|
---|
749 | End;
|
---|
750 |
|
---|
751 | Procedure MultiColumnList.SetOnItemFocus(Value:TItemFocusEvent);
|
---|
752 | Begin
|
---|
753 | List.OnItemFocus:= Value;
|
---|
754 | End;
|
---|
755 |
|
---|
756 | Function MultiColumnList.GetOnItemSelect:TItemSelectEvent;
|
---|
757 | Begin
|
---|
758 | Result:= List.OnItemSelect;
|
---|
759 | End;
|
---|
760 |
|
---|
761 | Procedure MultiColumnList.SetOnItemSelect(Value:TItemSelectEvent);
|
---|
762 | Begin
|
---|
763 | List.OnItemSelect:= Value;
|
---|
764 | End;
|
---|
765 |
|
---|
766 | Function MultiColumnList.GetSelCount:LongInt;
|
---|
767 | Begin
|
---|
768 | Result:= List.SelCount;
|
---|
769 | End;
|
---|
770 |
|
---|
771 | Function MultiColumnList.GetSelected(Index:LongInt):Boolean;
|
---|
772 | Begin
|
---|
773 | Result:= List.Selected[Index];
|
---|
774 | End;
|
---|
775 |
|
---|
776 | Procedure MultiColumnList.SetSelected(Index:LongInt;Value:Boolean);
|
---|
777 | Begin
|
---|
778 | List.Selected[Index]:= Value;
|
---|
779 | End;
|
---|
780 |
|
---|
781 | Function MultiColumnList.GetBitmap(Index:LongInt):TBitmap;
|
---|
782 | Begin
|
---|
783 | Result:=List.Bitmaps[Index];
|
---|
784 | End;
|
---|
785 |
|
---|
786 | Procedure MultiColumnList.SetBitmap(Index:LongInt; bmp:TBitmap);
|
---|
787 | Begin
|
---|
788 | List.Bitmaps[Index]:=bmp;
|
---|
789 | End;
|
---|
790 |
|
---|
791 | Function MultiColumnList.GetObjects(Index:LongInt):TObject;
|
---|
792 | Begin
|
---|
793 | Result:=List.Items.Objects[Index];
|
---|
794 | End;
|
---|
795 |
|
---|
796 | Procedure MultiColumnList.SetObjects(Index:LongInt;Value:TObject);
|
---|
797 | Begin
|
---|
798 | List.Items.Objects[Index]:=Value;
|
---|
799 | End;
|
---|
800 |
|
---|
801 | Function MultiColumnList.GetCount;
|
---|
802 | Begin
|
---|
803 | Result:=List.Items.Count;
|
---|
804 | End;
|
---|
805 |
|
---|
806 | Procedure MultiColumnList.EvSectionPressed(sender: THeaderControl; section: THeaderSection);
|
---|
807 | Begin
|
---|
808 | Sort(section.Index);
|
---|
809 | End;
|
---|
810 |
|
---|
811 | Procedure MultiColumnList.EvSectionTrack(sender: THeaderControl; section: THeaderSection; width: LongInt; State:TSectionTrackState);
|
---|
812 | Begin
|
---|
813 | If state = tsTrackEnd then Invalidate;
|
---|
814 | End;
|
---|
815 |
|
---|
816 | Procedure MultiColumnList.SetupComponent;
|
---|
817 | Begin
|
---|
818 | Inherited SetupComponent;
|
---|
819 |
|
---|
820 | Name:='MultiColumnList';
|
---|
821 | Width:=150;
|
---|
822 | Height:=150;
|
---|
823 | ParentPenColor := True;
|
---|
824 | ParentColor := True;
|
---|
825 | ParentFont := True;
|
---|
826 | TabStop := False;
|
---|
827 |
|
---|
828 | Header.Create(Self);
|
---|
829 | Header.Align:=alTop;
|
---|
830 | Header.parent:=Self;
|
---|
831 | Header.height:=25;
|
---|
832 | Header.OnSectionClick:=EvSectionPressed;
|
---|
833 | Header.OnSectionTrack:=EvSectionTrack;
|
---|
834 | Header.ParentFont:=True;
|
---|
835 | Header.TabStop:=False;
|
---|
836 | If Designed Then Include(Header.ComponentState, csDetail);
|
---|
837 |
|
---|
838 | List.Create(Self);
|
---|
839 | List.SetHeader(Header.Sections);
|
---|
840 | List.Align:=alBottom;
|
---|
841 | List.parent:=Self;
|
---|
842 | List.height:=height-24;
|
---|
843 | List.ParentFont:=True;
|
---|
844 | List.OnDragDrop:=EvDragDrop;
|
---|
845 | List.OnCanDrag:=EvCanDrag;
|
---|
846 | List.OnDragOver:=EvDragOver;
|
---|
847 | List.TabStop:=True;
|
---|
848 | If Designed Then Include(List.ComponentState, csDetail);
|
---|
849 | End;
|
---|
850 |
|
---|
851 | Procedure MultiColumnList.SetupShow;
|
---|
852 | Begin
|
---|
853 | Inherited SetupShow;
|
---|
854 |
|
---|
855 | Resize;
|
---|
856 | End;
|
---|
857 |
|
---|
858 | Procedure MultiColumnList.Resize;
|
---|
859 | Begin
|
---|
860 | Inherited Resize;
|
---|
861 |
|
---|
862 | Header.height:=25;
|
---|
863 | List.height:=height-24;
|
---|
864 | End;
|
---|
865 |
|
---|
866 |
|
---|
867 | Constructor MultiColumnList.Create(AOwner: TComponent);
|
---|
868 | Begin
|
---|
869 | Inherited Create(AOwner);
|
---|
870 | Fenabled:=True;
|
---|
871 | End;
|
---|
872 |
|
---|
873 | Destructor MultiColumnList.Destroy;
|
---|
874 | Begin
|
---|
875 | Inherited Destroy;
|
---|
876 | End;
|
---|
877 |
|
---|
878 | Function MultiColumnList.WriteSCUResource(Stream:TResourceStream):Boolean;
|
---|
879 | Begin
|
---|
880 | Result := Inherited WriteSCUResource(Stream);
|
---|
881 | If Not Result Then Exit;
|
---|
882 | Result := List.WriteSCUResource(Stream);
|
---|
883 | If Not Result Then Exit;
|
---|
884 | Result := Header.WriteSCUResource(Stream);
|
---|
885 | End;
|
---|
886 |
|
---|
887 | Procedure MultiColumnList.ReadSCUResource(Const ResName:TResourceName;Var Data;DataLen:LongInt);
|
---|
888 | Begin
|
---|
889 | List.ReadSCUResource(ResName,Data,DataLen);
|
---|
890 | Header.ReadSCUResource(ResName,Data,DataLen);
|
---|
891 | Inherited ReadSCUResource(ResName,Data,DataLen);
|
---|
892 | End;
|
---|
893 |
|
---|
894 | Procedure MultiColumnList.SelectAll;
|
---|
895 | Var
|
---|
896 | i:LongInt;
|
---|
897 | Begin
|
---|
898 | List.BeginUpdate;
|
---|
899 | For i:=0 to List.Items.Count-1 do
|
---|
900 | Selected[i]:=True;
|
---|
901 | List.EndUpdate;
|
---|
902 | End;
|
---|
903 |
|
---|
904 | Procedure MultiColumnList.DeselectAll;
|
---|
905 | Var
|
---|
906 | i:LongInt;
|
---|
907 | Begin
|
---|
908 | List.BeginUpdate;
|
---|
909 | For i:=0 to List.Items.Count-1 do
|
---|
910 | Selected[i]:=False;
|
---|
911 | List.EndUpdate;
|
---|
912 | End;
|
---|
913 |
|
---|
914 | Function MultiColumnList.Add(s:string):LongInt;
|
---|
915 | Begin
|
---|
916 | Result:=List.Add(s);
|
---|
917 | End;
|
---|
918 |
|
---|
919 | Function MultiColumnList.AddObject(s:string;o:TObject):LongInt;
|
---|
920 | Begin
|
---|
921 | Result:=List.AddObject(s,o);
|
---|
922 | End;
|
---|
923 |
|
---|
924 | Procedure MultiColumnList.Delete(Index:LongInt);
|
---|
925 | Begin
|
---|
926 | List.Items.Delete(Index);
|
---|
927 | End;
|
---|
928 |
|
---|
929 | Procedure MultiColumnList.Clear;
|
---|
930 | Begin
|
---|
931 | List.Clear;
|
---|
932 | End;
|
---|
933 |
|
---|
934 | Function MultiColumnList.ItemRect(Index:LongInt):TRect;
|
---|
935 | Begin
|
---|
936 | Result:=List.ItemRect(Index);
|
---|
937 | End;
|
---|
938 |
|
---|
939 | Procedure MultiColumnList.SetDragMode(Value:TDragMode);
|
---|
940 | Begin
|
---|
941 | drag_mode:=Value;
|
---|
942 | List.DragMode:=Value;
|
---|
943 | End;
|
---|
944 |
|
---|
945 | Procedure MultiColumnList.EvCanDrag(sender: TObject; X,Y: LongInt; var Accept: Boolean);
|
---|
946 | Begin
|
---|
947 | If OnCanDrag<>Nil then
|
---|
948 | OnCanDrag(Self,X,Y,Accept);
|
---|
949 | End;
|
---|
950 |
|
---|
951 | Procedure MultiColumnList.EvDragDrop(sender: TObject; source: TObject; X,Y: LongInt);
|
---|
952 | Begin
|
---|
953 | If OnDragDrop<>Nil then
|
---|
954 | OnDragDrop(Self,source,X,Y);
|
---|
955 | End;
|
---|
956 |
|
---|
957 | Procedure MultiColumnList.EvDragOver(sender: TObject; source: TObject; X,Y: LongInt; State: TDragState; var Accept: Boolean);
|
---|
958 | Begin
|
---|
959 | If OnDragOver<>Nil then
|
---|
960 | OnDragOver(Self,source,X,Y,state,Accept);
|
---|
961 | End;
|
---|
962 |
|
---|
963 | Function MultiColumnList.IsDraggedSourceMe(source: TObject):Boolean;
|
---|
964 | Begin
|
---|
965 | Result:=(source=Self) Or (source=List);
|
---|
966 | End;
|
---|
967 |
|
---|
968 | Procedure MultiColumnList.Sort(section:Integer);
|
---|
969 | Begin
|
---|
970 | List.Sort(section);
|
---|
971 | End;
|
---|
972 |
|
---|
973 | Function MultiColumnList.IndexOf(s:string):LongInt;
|
---|
974 | Begin
|
---|
975 | Result:=List.Items.IndexOf(s);
|
---|
976 | End;
|
---|
977 |
|
---|
978 | Procedure MultiColumnList.BeginUpdate;
|
---|
979 | Begin
|
---|
980 | List.BeginUpdate;
|
---|
981 | End;
|
---|
982 |
|
---|
983 | Procedure MultiColumnList.EndUpdate;
|
---|
984 | Begin
|
---|
985 | List.EndUpdate;
|
---|
986 | End;
|
---|
987 |
|
---|
988 | Initialization
|
---|
989 | {Register classes}
|
---|
990 | RegisterClasses([MultiColumnList,TMultiColumnListBox]);
|
---|
991 | End.
|
---|
992 |
|
---|