source: branches/2.20_branch/Components/MultiColumnListBoxRDS.pas

Last change on this file was 15, checked in by RBRi, 19 years ago

+ components stuff

  • Property svn:eol-style set to native
File size: 23.6 KB
Line 
1Unit MultiColumnListBox;
2
3Interface
4
5Uses
6 Classes, Forms, ExtCtrls, StdCtrls, ComCtrls, SysUtils, Dialogs, Graphics;
7
8{Declare new class}
9Type
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
34Type
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}
141Exports
142 MultiColumnList,'User','';
143
144
145Implementation
146
147Procedure 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
172Var
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
359Var
360 I, C: LongInt;
361 s:string;
362Begin
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;
389End;
390
391Procedure TMultiColumnListBox.SetupComponent;
392Begin
393 Inherited SetupComponent;
394 Style:=lbOwnerdrawFixed;
395 BmpList:=TList.Create;
396 sep_char:='|';
397End;
398
399Destructor TMultiColumnListBox.Destroy;
400Begin
401 Inherited Destroy;
402 BmpList.Free;
403End;
404
405Procedure TMultiColumnListBox.Clear;
406Begin
407 Inherited Clear;
408 BmpList.Clear;
409End;
410
411Function TMultiColumnListBox.Add(s:string):LongInt;
412Begin
413 Result:=Items.Add(s);
414 If BmpList.Count<Items.Count then
415 BmpList.Count:=Items.Count;
416End;
417
418Function TMultiColumnListBox.AddObject(s:string;o:TObject):LongInt;
419Begin
420 Result:=Items.AddObject(s,o);
421 If BmpList.Count<Items.Count then
422 BmpList.Count:=Items.Count;
423End;
424
425Procedure TMultiColumnListBox.DrawItem(Index:LONGINT;Rec:TRect;State:TOwnerDrawState);
426Var
427 x,y,y1,cx,cy,cx1,cy1:LONGINT;
428 idx,i:LONGINT;
429 s,s1:STRING;
430 rec1:TRect;
431 bmp:TBitmap;
432Begin
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;
508End;
509
510Function TMultiColumnListBox.GetSepChar:string;
511Begin
512 Result:=sep_char;
513End;
514
515Procedure TMultiColumnListBox.SetSepChar(Value:string);
516Begin
517 sep_char:=Value;
518End;
519
520Function TMultiColumnListBox.GetBitmap(Index:LongInt):TBitmap;
521Begin
522 If (Index<0) Or (Index>=BmpList.Count) then
523 Result:=Nil
524 Else
525 Result:=BmpList[Index];
526End;
527
528Procedure TMultiColumnListBox.SetBitmap(Index:LongInt; bmp:TBitmap);
529Begin
530 If BmpList.Count<Items.Count then
531 BmpList.Count:=Items.Count;
532 If BmpList.Count>Index then
533 BmpList[Index]:=bmp;
534End;
535
536Procedure TMultiColumnListBox.SetHeader(s: THeaderSections);
537Begin
538 sections:=s;
539End;
540
541Function MultiColumnList.GetValue(field,index:LongInt):string;
542Var
543 i, p: LongInt;
544Begin
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;
565End;
566
567Procedure MultiColumnList.SetValue(field,index:LongInt;Value:string);
568Var
569 i, p: LongInt;
570 sl,sr,s:string;
571Begin
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;
596End;
597
598Function MultiColumnList.GetSepChar:string;
599Begin
600 Result:=List.Separator;
601End;
602
603Procedure MultiColumnList.SetSepChar(Value:string);
604Begin
605 List.Separator:=Value;
606End;
607
608Function MultiColumnList.GetHint:string;
609Begin
610 Result:=List.Hint;
611End;
612
613Procedure MultiColumnList.SetHint(Value:string);
614Begin
615 List.Hint:=Value;
616End;
617
618Procedure MultiColumnList.SetEnabled(Value:Boolean);
619Begin
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;
632End;
633
634Function MultiColumnList.GetHeaderHint:string;
635Begin
636 Result:=Header.Hint;
637End;
638
639Procedure MultiColumnList.SetHeaderHint(Value:string);
640Begin
641 Header.Hint:=Value;
642End;
643
644Function MultiColumnList.GetShowDragRects:Boolean;
645Begin
646 Result:=List.ShowDragRects;
647End;
648
649Procedure MultiColumnList.SetShowDragRects(Value:Boolean);
650Begin
651 List.ShowDragRects:=Value;
652End;
653
654Function MultiColumnList.GetTheFont:TFont;
655Begin
656 Result:=List.Font;
657End;
658
659Procedure MultiColumnList.SetTheFont(Value:TFont);
660Begin
661 List.Font:=Value;
662 Header.Font:=Value;
663End;
664
665Function MultiColumnList.GetSections:THeaderSections;
666Begin
667 Result := Header.sections;
668End;
669
670//gehn
671Function MultiColumnList.GetSectionsCount:LongInt;
672Begin
673 Result := GetSections.Count;
674End;
675
676//gehn
677Function MultiColumnList.GetSectionsItem(Index:LongInt):THeaderSection;
678Begin
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;
687End;
688//gehn
689Procedure MultiColumnList.SetSectionsItemText(Index:LongInt; NewText:String);
690Var
691 SectionsItem: THeaderSection;
692Begin
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;
699End;
700
701Procedure MultiColumnList.SetSections(Value:THeaderSections);
702Begin
703 Header.sections := Value;
704End;
705
706Function MultiColumnList.GetDuplicates:Boolean;
707Begin
708 Result:=List.Duplicates;
709End;
710
711Procedure MultiColumnList.SetDuplicates(Value:Boolean);
712Begin
713 List.Duplicates:=Value;
714End;
715
716Function MultiColumnList.GetExtendedSelect:Boolean;
717Begin
718 Result:= List.ExtendedSelect;
719End;
720
721Procedure MultiColumnList.SetExtendedSelect(Value:Boolean);
722Begin
723 List.ExtendedSelect:= Value;
724End;
725
726Function MultiColumnList.GetItemIndex:LongInt;
727Begin
728 Result:= List.ItemIndex;
729End;
730
731Procedure MultiColumnList.SetItemIndex(Value:LongInt);
732Begin
733 List.ItemIndex:= Value;
734End;
735
736Function MultiColumnList.GetMultiSelect:Boolean;
737Begin
738 Result:= List.MultiSelect;
739End;
740
741Procedure MultiColumnList.SetMultiSelect(Value:Boolean);
742Begin
743 List.MultiSelect:= Value;
744End;
745
746Function MultiColumnList.GetOnItemFocus:TItemFocusEvent;
747Begin
748 Result:= List.OnItemFocus;
749End;
750
751Procedure MultiColumnList.SetOnItemFocus(Value:TItemFocusEvent);
752Begin
753 List.OnItemFocus:= Value;
754End;
755
756Function MultiColumnList.GetOnItemSelect:TItemSelectEvent;
757Begin
758 Result:= List.OnItemSelect;
759End;
760
761Procedure MultiColumnList.SetOnItemSelect(Value:TItemSelectEvent);
762Begin
763 List.OnItemSelect:= Value;
764End;
765
766Function MultiColumnList.GetSelCount:LongInt;
767Begin
768 Result:= List.SelCount;
769End;
770
771Function MultiColumnList.GetSelected(Index:LongInt):Boolean;
772Begin
773 Result:= List.Selected[Index];
774End;
775
776Procedure MultiColumnList.SetSelected(Index:LongInt;Value:Boolean);
777Begin
778 List.Selected[Index]:= Value;
779End;
780
781Function MultiColumnList.GetBitmap(Index:LongInt):TBitmap;
782Begin
783 Result:=List.Bitmaps[Index];
784End;
785
786Procedure MultiColumnList.SetBitmap(Index:LongInt; bmp:TBitmap);
787Begin
788 List.Bitmaps[Index]:=bmp;
789End;
790
791Function MultiColumnList.GetObjects(Index:LongInt):TObject;
792Begin
793 Result:=List.Items.Objects[Index];
794End;
795
796Procedure MultiColumnList.SetObjects(Index:LongInt;Value:TObject);
797Begin
798 List.Items.Objects[Index]:=Value;
799End;
800
801Function MultiColumnList.GetCount;
802Begin
803 Result:=List.Items.Count;
804End;
805
806Procedure MultiColumnList.EvSectionPressed(sender: THeaderControl; section: THeaderSection);
807Begin
808 Sort(section.Index);
809End;
810
811Procedure MultiColumnList.EvSectionTrack(sender: THeaderControl; section: THeaderSection; width: LongInt; State:TSectionTrackState);
812Begin
813 If state = tsTrackEnd then Invalidate;
814End;
815
816Procedure MultiColumnList.SetupComponent;
817Begin
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);
849End;
850
851Procedure MultiColumnList.SetupShow;
852Begin
853 Inherited SetupShow;
854
855 Resize;
856End;
857
858Procedure MultiColumnList.Resize;
859Begin
860 Inherited Resize;
861
862 Header.height:=25;
863 List.height:=height-24;
864End;
865
866
867Constructor MultiColumnList.Create(AOwner: TComponent);
868Begin
869 Inherited Create(AOwner);
870 Fenabled:=True;
871End;
872
873Destructor MultiColumnList.Destroy;
874Begin
875 Inherited Destroy;
876End;
877
878Function MultiColumnList.WriteSCUResource(Stream:TResourceStream):Boolean;
879Begin
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);
885End;
886
887Procedure MultiColumnList.ReadSCUResource(Const ResName:TResourceName;Var Data;DataLen:LongInt);
888Begin
889 List.ReadSCUResource(ResName,Data,DataLen);
890 Header.ReadSCUResource(ResName,Data,DataLen);
891 Inherited ReadSCUResource(ResName,Data,DataLen);
892End;
893
894Procedure MultiColumnList.SelectAll;
895Var
896 i:LongInt;
897Begin
898 List.BeginUpdate;
899 For i:=0 to List.Items.Count-1 do
900 Selected[i]:=True;
901 List.EndUpdate;
902End;
903
904Procedure MultiColumnList.DeselectAll;
905Var
906 i:LongInt;
907Begin
908 List.BeginUpdate;
909 For i:=0 to List.Items.Count-1 do
910 Selected[i]:=False;
911 List.EndUpdate;
912End;
913
914Function MultiColumnList.Add(s:string):LongInt;
915Begin
916 Result:=List.Add(s);
917End;
918
919Function MultiColumnList.AddObject(s:string;o:TObject):LongInt;
920Begin
921 Result:=List.AddObject(s,o);
922End;
923
924Procedure MultiColumnList.Delete(Index:LongInt);
925Begin
926 List.Items.Delete(Index);
927End;
928
929Procedure MultiColumnList.Clear;
930Begin
931 List.Clear;
932End;
933
934Function MultiColumnList.ItemRect(Index:LongInt):TRect;
935Begin
936 Result:=List.ItemRect(Index);
937End;
938
939Procedure MultiColumnList.SetDragMode(Value:TDragMode);
940Begin
941 drag_mode:=Value;
942 List.DragMode:=Value;
943End;
944
945Procedure MultiColumnList.EvCanDrag(sender: TObject; X,Y: LongInt; var Accept: Boolean);
946Begin
947 If OnCanDrag<>Nil then
948 OnCanDrag(Self,X,Y,Accept);
949End;
950
951Procedure MultiColumnList.EvDragDrop(sender: TObject; source: TObject; X,Y: LongInt);
952Begin
953 If OnDragDrop<>Nil then
954 OnDragDrop(Self,source,X,Y);
955End;
956
957Procedure MultiColumnList.EvDragOver(sender: TObject; source: TObject; X,Y: LongInt; State: TDragState; var Accept: Boolean);
958Begin
959 If OnDragOver<>Nil then
960 OnDragOver(Self,source,X,Y,state,Accept);
961End;
962
963Function MultiColumnList.IsDraggedSourceMe(source: TObject):Boolean;
964Begin
965 Result:=(source=Self) Or (source=List);
966End;
967
968Procedure MultiColumnList.Sort(section:Integer);
969Begin
970 List.Sort(section);
971End;
972
973Function MultiColumnList.IndexOf(s:string):LongInt;
974Begin
975 Result:=List.Items.IndexOf(s);
976End;
977
978Procedure MultiColumnList.BeginUpdate;
979Begin
980 List.BeginUpdate;
981End;
982
983Procedure MultiColumnList.EndUpdate;
984Begin
985 List.EndUpdate;
986End;
987
988Initialization
989 {Register classes}
990 RegisterClasses([MultiColumnList,TMultiColumnListBox]);
991End.
992
Note: See TracBrowser for help on using the repository browser.