| 1 | Unit CheckLB;
|
|---|
| 2 |
|
|---|
| 3 | Interface
|
|---|
| 4 |
|
|---|
| 5 | Uses Classes,Forms,Graphics,StdCtrls;
|
|---|
| 6 |
|
|---|
| 7 | Type
|
|---|
| 8 | TCheckListBoxState=(clsUnchecked,clsChecked,cls3State);
|
|---|
| 9 |
|
|---|
| 10 | TCheckListBox=Class(TListBox)
|
|---|
| 11 | Private
|
|---|
| 12 | FBitmapList:TBitmapList;
|
|---|
| 13 | FOnStateChanged:TNotifyEvent;
|
|---|
| 14 | Private
|
|---|
| 15 | Function GetState(Index:LongInt):TCheckListBoxState;
|
|---|
| 16 | Procedure SetState(Index:LongInt;Value:TCheckListBoxState);
|
|---|
| 17 | Property Style;
|
|---|
| 18 | Protected
|
|---|
| 19 | Procedure SetupComponent;Override;
|
|---|
| 20 | Destructor Destroy;Override;
|
|---|
| 21 | Procedure ItemSelect(Index:LongInt);Override;
|
|---|
| 22 | Procedure DrawItem(Index:LongInt;rec:TRect;State:TOwnerDrawState);Override;
|
|---|
| 23 | Procedure CharEvent(Var key:Char;RepeatCount:Byte);Override;
|
|---|
| 24 | Public
|
|---|
| 25 | Property State[Index:LongInt]:TCheckListBoxState Read GetState Write SetState;
|
|---|
| 26 | Published
|
|---|
| 27 | Property OnStateChanged:TNotifyEvent Read FOnStateChanged Write FOnStateChanged;
|
|---|
| 28 | End;
|
|---|
| 29 |
|
|---|
| 30 | Function InsertCheckListBox(parent:TControl;X,Y,W,H:LongInt):TCheckListBox;
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 | Implementation
|
|---|
| 34 |
|
|---|
| 35 | {$R CheckLB}
|
|---|
| 36 |
|
|---|
| 37 | Function InsertCheckListBox(parent:TControl;X,Y,W,H:LongInt):TCheckListBox;
|
|---|
| 38 | Begin
|
|---|
| 39 | Result.Create(parent);
|
|---|
| 40 | Result.SetWindowPos(X,Y,W,H);
|
|---|
| 41 | Result.TabStop := True;
|
|---|
| 42 | Result.parent := parent;
|
|---|
| 43 | End;
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | {
|
|---|
| 47 | ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
|
|---|
| 48 | º º
|
|---|
| 49 | º Speed-Pascal/2 Version 2.0 º
|
|---|
| 50 | º º
|
|---|
| 51 | º Speed-Pascal Component Classes (SPCC) º
|
|---|
| 52 | º º
|
|---|
| 53 | º This section: TCheckListBox Class Implementation º
|
|---|
| 54 | º º
|
|---|
| 55 | º Last Modified: December 1996 º
|
|---|
| 56 | º º
|
|---|
| 57 | º (C) 1995 SpeedSoft. All rights reserved. Disclosure probibited ! º
|
|---|
| 58 | º º
|
|---|
| 59 | ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍŒ
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | Procedure TCheckListBox.SetupComponent;
|
|---|
| 63 | Begin
|
|---|
| 64 | Inherited SetupComponent;
|
|---|
| 65 |
|
|---|
| 66 | Name := 'CheckListBox';
|
|---|
| 67 | Style := lbOwnerdrawFixed;
|
|---|
| 68 | ItemHeight := 20;
|
|---|
| 69 | FBitmapList.Create;
|
|---|
| 70 | FBitmapList.AddResourceName('BmpLBUnChecked');
|
|---|
| 71 | FBitmapList.AddResourceName('BmpLBChecked');
|
|---|
| 72 | FBitmapList.AddResourceName('BmpLB3State');
|
|---|
| 73 | End;
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 | Destructor TCheckListBox.Destroy;
|
|---|
| 77 | Begin
|
|---|
| 78 | Inherited Destroy;
|
|---|
| 79 | FBitmapList.Destroy;
|
|---|
| 80 | End;
|
|---|
| 81 |
|
|---|
| 82 | Procedure TCheckListBox.DrawItem(Index:LongInt;rec:TRect;State:TOwnerDrawState);
|
|---|
| 83 | Var X,Y,y1,CX,CY,cx1,cy1:LongInt;
|
|---|
| 84 | idx:LongInt;
|
|---|
| 85 | Bitmap:TBitmap;
|
|---|
| 86 | S:String;
|
|---|
| 87 | Begin
|
|---|
| 88 | If OnDrawItem <> Nil Then Exit;
|
|---|
| 89 |
|
|---|
| 90 | If State * [odSelected] <> [] Then
|
|---|
| 91 | Begin
|
|---|
| 92 | Canvas.Pen.color := clHighlightText;
|
|---|
| 93 | Canvas.Brush.color := clHighlight;
|
|---|
| 94 | End Else
|
|---|
| 95 | Begin
|
|---|
| 96 | Canvas.Pen.color := PenColor;
|
|---|
| 97 | Canvas.Brush.color := color;
|
|---|
| 98 | End;
|
|---|
| 99 |
|
|---|
| 100 | Canvas.FillRect(Rec,Canvas.Brush.Color);
|
|---|
| 101 | //Canvas.ClipRect:=rec;
|
|---|
| 102 | X := rec.Left + 2;
|
|---|
| 103 | Y := rec.Bottom + 1;
|
|---|
| 104 | CX := rec.Right - X;
|
|---|
| 105 | CY := rec.Top - Y;
|
|---|
| 106 |
|
|---|
| 107 | idx := LongInt(Items.Objects[Index]);
|
|---|
| 108 | If idx >= 0 Then Bitmap := FBitmapList.Bitmaps[idx]
|
|---|
| 109 | Else Bitmap := Nil;
|
|---|
| 110 |
|
|---|
| 111 | If Bitmap<>Nil Then Inc(X,Bitmap.Width + 5);
|
|---|
| 112 | S := Items.Strings[Index];
|
|---|
| 113 | Canvas.GetTextExtent(S,cx1,cy1);
|
|---|
| 114 | y1 := Y + ((CY - cy1) Div 2);
|
|---|
| 115 | If y1 < rec.Bottom Then y1 := rec.Bottom;
|
|---|
| 116 | //Canvas.TextOut(X,y1,S);
|
|---|
| 117 | //Canvas.ExcludeClipRect(Rect(X,y1,X+cx1-1,Y+cy1-1));
|
|---|
| 118 | Canvas.Brush.Mode := bmTransparent;
|
|---|
| 119 | Canvas.TextOut(x,y1,s);
|
|---|
| 120 |
|
|---|
| 121 | If Bitmap <> Nil Then
|
|---|
| 122 | Begin
|
|---|
| 123 | X := rec.Left + 2;
|
|---|
| 124 | Y := rec.Bottom + 1;
|
|---|
| 125 | CX := rec.Right - X;
|
|---|
| 126 | CY := rec.Top - Y;
|
|---|
| 127 | cy1 := Bitmap.Height;
|
|---|
| 128 | y1 := Y + ((CY - cy1) Div 2);
|
|---|
| 129 | If y1 <= rec.Bottom Then y1 := rec.Bottom + 1;
|
|---|
| 130 | Canvas.StretchDraw(X,y1,Bitmap.Width,Bitmap.Height,Bitmap);
|
|---|
| 131 | //Canvas.ExcludeClipRect(Rect(X,y1,X+Bitmap.Width-1,y1+Bitmap.Height-1));
|
|---|
| 132 | End;
|
|---|
| 133 |
|
|---|
| 134 | //Canvas.FillRect(rec,Canvas.Brush.color);
|
|---|
| 135 |
|
|---|
| 136 | //Canvas.DeleteClipRegion;
|
|---|
| 137 | End;
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 | Procedure TCheckListBox.ItemSelect(Index:LongInt);
|
|---|
| 141 | Begin
|
|---|
| 142 | Inherited ItemSelect(Index);
|
|---|
| 143 |
|
|---|
| 144 | If State[ItemIndex] <> clsUnchecked Then State[ItemIndex] := clsUnchecked
|
|---|
| 145 | Else State[ItemIndex] := clsChecked;
|
|---|
| 146 | If OnStateChanged <> Nil Then OnStateChanged(Self);
|
|---|
| 147 | End;
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 | Procedure TCheckListBox.CharEvent(Var key:Char;RepeatCount:Byte);
|
|---|
| 151 | Begin
|
|---|
| 152 | If key=#32 Then
|
|---|
| 153 | Begin
|
|---|
| 154 | If State[ItemIndex] <> clsUnchecked Then State[ItemIndex] := clsUnchecked
|
|---|
| 155 | Else State[ItemIndex] := clsChecked;
|
|---|
| 156 | If OnStateChanged <> Nil Then OnStateChanged(Self);
|
|---|
| 157 | End;
|
|---|
| 158 | Inherited CharEvent(key,RepeatCount);
|
|---|
| 159 | End;
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 | Function TCheckListBox.GetState(Index:LongInt):TCheckListBoxState;
|
|---|
| 163 | Var obj:TObject;
|
|---|
| 164 | Begin
|
|---|
| 165 | Result := clsUnchecked;
|
|---|
| 166 | If (Index < 0) Or (Index >= Items.Count) Then Exit;
|
|---|
| 167 | obj := Items.Objects[Index];
|
|---|
| 168 | Result := TCheckListBoxState(obj);
|
|---|
| 169 | End;
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 | Procedure TCheckListBox.SetState(Index:LongInt;Value:TCheckListBoxState);
|
|---|
| 173 | Var obj:TObject;
|
|---|
| 174 | Begin
|
|---|
| 175 | If (Index < 0) Or (Index >= Items.Count) Then Exit;
|
|---|
| 176 | obj := TObject(Value);
|
|---|
| 177 | Items.Objects[Index] := obj;
|
|---|
| 178 |
|
|---|
| 179 | Invalidate;
|
|---|
| 180 | End;
|
|---|
| 181 |
|
|---|
| 182 | Begin
|
|---|
| 183 | End.
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|