source: trunk/Sibyl/Addon/CHECKLB.PAS@ 7

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

+ sibyl staff

  • Property svn:eol-style set to native
File size: 5.4 KB
Line 
1Unit CheckLB;
2
3Interface
4
5Uses Classes,Forms,Graphics,StdCtrls;
6
7Type
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
30Function InsertCheckListBox(parent:TControl;X,Y,W,H:LongInt):TCheckListBox;
31
32
33Implementation
34
35{$R CheckLB}
36
37Function InsertCheckListBox(parent:TControl;X,Y,W,H:LongInt):TCheckListBox;
38Begin
39 Result.Create(parent);
40 Result.SetWindowPos(X,Y,W,H);
41 Result.TabStop := True;
42 Result.parent := parent;
43End;
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
62Procedure TCheckListBox.SetupComponent;
63Begin
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');
73End;
74
75
76Destructor TCheckListBox.Destroy;
77Begin
78 Inherited Destroy;
79 FBitmapList.Destroy;
80End;
81
82Procedure TCheckListBox.DrawItem(Index:LongInt;rec:TRect;State:TOwnerDrawState);
83Var X,Y,y1,CX,CY,cx1,cy1:LongInt;
84 idx:LongInt;
85 Bitmap:TBitmap;
86 S:String;
87Begin
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;
137End;
138
139
140Procedure TCheckListBox.ItemSelect(Index:LongInt);
141Begin
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);
147End;
148
149
150Procedure TCheckListBox.CharEvent(Var key:Char;RepeatCount:Byte);
151Begin
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);
159End;
160
161
162Function TCheckListBox.GetState(Index:LongInt):TCheckListBoxState;
163Var obj:TObject;
164Begin
165 Result := clsUnchecked;
166 If (Index < 0) Or (Index >= Items.Count) Then Exit;
167 obj := Items.Objects[Index];
168 Result := TCheckListBoxState(obj);
169End;
170
171
172Procedure TCheckListBox.SetState(Index:LongInt;Value:TCheckListBoxState);
173Var obj:TObject;
174Begin
175 If (Index < 0) Or (Index >= Items.Count) Then Exit;
176 obj := TObject(Value);
177 Items.Objects[Index] := obj;
178
179 Invalidate;
180End;
181
182Begin
183End.
184
185
186
Note: See TracBrowser for help on using the repository browser.