1 | Unit XplorBtn;
|
---|
2 |
|
---|
3 | Interface
|
---|
4 |
|
---|
5 | Uses
|
---|
6 | Classes, Forms, Buttons, Graphics;
|
---|
7 |
|
---|
8 | {Declare new class}
|
---|
9 | Type
|
---|
10 | TExplorerButton=Class(TSpeedButton)
|
---|
11 | Private
|
---|
12 | FMouseInside:Boolean;
|
---|
13 | FMouseTimer:TTimer;
|
---|
14 | FCapture:Boolean;
|
---|
15 | FFlat:Boolean;
|
---|
16 | FBitmapDown:TBitmap;
|
---|
17 | FBitmapUp:TBitmap;
|
---|
18 | Procedure EvFMouseTimer(Sender:TObject);
|
---|
19 | Function GetGlyphDown:TBitmap;
|
---|
20 | Procedure SetGlyphDown(NewBitmap:TBitmap);
|
---|
21 | Function GetGlyphUp:TBitmap;
|
---|
22 | Procedure SetGlyphUp(NewBitmap:TBitmap);
|
---|
23 | Procedure SetFlat(Value:Boolean);
|
---|
24 | Protected
|
---|
25 | Procedure SetupComponent; Override;
|
---|
26 | Procedure MouseDown(Button:TMouseBUtton;ShiftState:TShiftState;X,Y:LongInt); Override;
|
---|
27 | Procedure MouseMove(ShiftState:TShiftState;X,Y:LongInt); Override;
|
---|
28 | Procedure MouseUp(Button:TMouseBUtton;ShiftState:TShiftState;X,Y:LongInt); Override;
|
---|
29 | Procedure DrawFrame(Down:Boolean); Override;
|
---|
30 | Procedure DrawBitmap(Bitmap:TBitmap;Mask:TBitmap;Down:Boolean); Override;
|
---|
31 | Property Cancel;
|
---|
32 | Property Default;
|
---|
33 | Property Kind;
|
---|
34 | Property TabOrder;
|
---|
35 | Property TabStop;
|
---|
36 | Property ZOrder;
|
---|
37 | Property OnKeyPress;
|
---|
38 | Property OnScan;
|
---|
39 | Public
|
---|
40 | Procedure ReadSCUResource(Const ResName:TResourceName;Var Data;DataLen:LongInt);Override;
|
---|
41 | Function WriteSCUResource(Stream:TResourceStream):Boolean;Override;
|
---|
42 | Property Flat:Boolean read FFlat write SetFlat;
|
---|
43 | Published
|
---|
44 | Property GlyphDown:TBitmap read GetGlyphDown write SetGlyphDown;
|
---|
45 | Property GlyphUp:TBitmap read GetGlyphUp write SetGlyphUp;
|
---|
46 | End;
|
---|
47 |
|
---|
48 |
|
---|
49 | {Define components to export}
|
---|
50 | {You may define a navigator page and a component bitmap file}
|
---|
51 | Exports
|
---|
52 | TExplorerButton,'User','';
|
---|
53 |
|
---|
54 |
|
---|
55 | Implementation
|
---|
56 |
|
---|
57 |
|
---|
58 | Procedure TExplorerButton.SetupComponent;
|
---|
59 | Begin
|
---|
60 | Inherited SetupComponent;
|
---|
61 |
|
---|
62 | Name := 'ExplorerButton';
|
---|
63 | Caption := '';
|
---|
64 | Width := 40;
|
---|
65 | Height := 40;
|
---|
66 | FFlat := True;
|
---|
67 | FMouseTimer.Create(Self);
|
---|
68 | Include(FMouseTimer.ComponentState, csDetail);
|
---|
69 | FMouseTimer.Interval := 50;
|
---|
70 | FMouseTimer.OnTimer := EvFMouseTimer;
|
---|
71 | End;
|
---|
72 |
|
---|
73 | Procedure TExplorerButton.MouseDown(Button:TMouseBUtton;ShiftState:TShiftState;X,Y:LongInt);
|
---|
74 | Begin
|
---|
75 | Inherited MouseDown(Button,ShiftState,X,Y);
|
---|
76 |
|
---|
77 | If Button = mbLeft Then FCapture := True;
|
---|
78 | End;
|
---|
79 |
|
---|
80 | Procedure TExplorerButton.MouseMove(ShiftState:TShiftState;X,Y:LongInt);
|
---|
81 | Begin
|
---|
82 | FMouseTimer.Stop;
|
---|
83 |
|
---|
84 | Inherited MouseMove(ShiftState,X,Y);
|
---|
85 | If Application <> Nil Then
|
---|
86 | If Not Application.HasFocus Then exit;
|
---|
87 |
|
---|
88 | If (not FMouseInside) And (not FCapture) Then
|
---|
89 | Begin
|
---|
90 | FMouseInside := True;
|
---|
91 | Redraw(ClientRect);
|
---|
92 | End;
|
---|
93 |
|
---|
94 | {Start Timer}
|
---|
95 | If FFlat Then FMouseTimer.Start;
|
---|
96 | End;
|
---|
97 |
|
---|
98 | Procedure TExplorerButton.MouseUp(Button:TMouseBUtton;ShiftState:TShiftState;X,Y:LongInt);
|
---|
99 | Begin
|
---|
100 | Inherited MouseUp(Button,ShiftState,X,Y);
|
---|
101 |
|
---|
102 | If Button = mbLeft Then FCapture := False;
|
---|
103 | End;
|
---|
104 |
|
---|
105 | Procedure TExplorerButton.EvFMouseTimer(Sender:TObject);
|
---|
106 | Var
|
---|
107 | AControl:TControl;
|
---|
108 | Begin
|
---|
109 | FMouseTimer.Stop;
|
---|
110 |
|
---|
111 | If FCapture Then AControl := Self
|
---|
112 | Else AControl := Screen.GetControlFromPoint(Screen.MousePos);
|
---|
113 |
|
---|
114 | If AControl <> Self Then
|
---|
115 | Begin
|
---|
116 | FMouseInside := False;
|
---|
117 | Redraw(ClientRect);
|
---|
118 | End
|
---|
119 | Else FMouseTimer.Start;
|
---|
120 | End;
|
---|
121 |
|
---|
122 | Procedure TExplorerButton.SetGlyphDown(NewBitmap:TBitmap);
|
---|
123 | Var OldBitmap:TBitmap;
|
---|
124 | Begin
|
---|
125 | OldBitmap := FBitmapDown;
|
---|
126 |
|
---|
127 | {create internal copy}
|
---|
128 | If NewBitmap <> Nil Then FBitmapDown := NewBitmap.Copy
|
---|
129 | Else FBitmapDown := Nil;
|
---|
130 |
|
---|
131 | If FBitmapDown <> Nil Then Include(FBitmapDown.ComponentState, csDetail);
|
---|
132 |
|
---|
133 | If OldBitmap <> Nil Then
|
---|
134 | If OldBitmap <> NewBitmap Then OldBitmap.Destroy;
|
---|
135 |
|
---|
136 | Arrange;
|
---|
137 | Invalidate;
|
---|
138 | end;
|
---|
139 |
|
---|
140 | Function TExplorerButton.GetGlyphDown:TBitmap;
|
---|
141 | Begin
|
---|
142 | If FBitmapDown = Nil Then
|
---|
143 | Begin
|
---|
144 | FBitmapDown.Create;
|
---|
145 | Include(FBitmapDown.ComponentState, csDetail);
|
---|
146 | End;
|
---|
147 | Result := FBitmapDown;
|
---|
148 | End;
|
---|
149 |
|
---|
150 | Procedure TExplorerButton.SetGlyphUp(NewBitmap:TBitmap);
|
---|
151 | Var OldBitmap:TBitmap;
|
---|
152 | Begin
|
---|
153 | OldBitmap := FBitmapUp;
|
---|
154 |
|
---|
155 | {create internal copy}
|
---|
156 | If NewBitmap <> Nil Then FBitmapUp := NewBitmap.Copy
|
---|
157 | Else FBitmapUp := Nil;
|
---|
158 |
|
---|
159 | If FBitmapUp <> Nil Then Include(FBitmapUp.ComponentState, csDetail);
|
---|
160 |
|
---|
161 | If OldBitmap <> Nil Then
|
---|
162 | If OldBitmap <> NewBitmap Then OldBitmap.Destroy;
|
---|
163 |
|
---|
164 | Arrange;
|
---|
165 | Invalidate;
|
---|
166 | end;
|
---|
167 |
|
---|
168 | Function TExplorerButton.GetGlyphUp:TBitmap;
|
---|
169 | Begin
|
---|
170 | If FBitmapUp = Nil Then
|
---|
171 | Begin
|
---|
172 | FBitmapUp.Create;
|
---|
173 | Include(FBitmapUp.ComponentState, csDetail);
|
---|
174 | End;
|
---|
175 | Result := FBitmapUp;
|
---|
176 | End;
|
---|
177 |
|
---|
178 | Procedure TExplorerButton.SetFlat(Value:Boolean);
|
---|
179 | Begin
|
---|
180 | FFlat := Value;
|
---|
181 | FMouseInside := False;
|
---|
182 | End;
|
---|
183 |
|
---|
184 | Procedure TExplorerButton.DrawFrame(Down:Boolean);
|
---|
185 | Var
|
---|
186 | rec:TRect;
|
---|
187 | FrameColor:TColor;
|
---|
188 | Begin
|
---|
189 | If ((not Down) And (FFlat) And
|
---|
190 | (((not FMouseInside) And (not FCapture)) Or (not Enabled))) Then
|
---|
191 | Begin
|
---|
192 | // dont draw the Frame
|
---|
193 | rec := ClientRect;
|
---|
194 | If Parent <> Nil Then FrameColor := Parent.Color
|
---|
195 | Else FrameColor := clBackGround;
|
---|
196 |
|
---|
197 | If Designed Then
|
---|
198 | Begin
|
---|
199 | Canvas.Brush.Color := FrameColor;
|
---|
200 | Canvas.Pen.Color := clBlack;
|
---|
201 | Canvas.Pen.Style := psDash;
|
---|
202 | Canvas.Brush.Style := bsClear;
|
---|
203 | Canvas.Rectangle(rec);
|
---|
204 | End
|
---|
205 | Else Canvas.ShadowedBorder(rec,FrameColor,FrameColor);
|
---|
206 |
|
---|
207 | InflateRect(rec,-1,-1);
|
---|
208 | Canvas.ShadowedBorder(rec,FrameColor,FrameColor);
|
---|
209 |
|
---|
210 | Canvas.ClipRect := IntersectRect(Canvas.ClipRect,rec);
|
---|
211 | End
|
---|
212 | Else Inherited DrawFrame(Down);
|
---|
213 | End;
|
---|
214 |
|
---|
215 | Procedure TExplorerButton.DrawBitmap(Bitmap:TBitmap;Mask:TBitmap;Down:Boolean);
|
---|
216 | Begin
|
---|
217 | If ((not Down) And
|
---|
218 | (((not FMouseInside) And (not FCapture)) Or (not Enabled))) Then
|
---|
219 | Begin
|
---|
220 | // inactive state
|
---|
221 | Bitmap := Glyph;
|
---|
222 | End
|
---|
223 | Else
|
---|
224 | Begin
|
---|
225 | If Down Then Bitmap := FBitmapDown
|
---|
226 | Else Bitmap := FBitmapUp;
|
---|
227 |
|
---|
228 | If Bitmap <> Nil Then
|
---|
229 | Begin
|
---|
230 | If Bitmap.Empty Then Bitmap := Glyph;
|
---|
231 | End
|
---|
232 | Else Bitmap := Glyph;
|
---|
233 | End;
|
---|
234 |
|
---|
235 | Inherited DrawBitmap(Bitmap,nil,Down);
|
---|
236 | End;
|
---|
237 |
|
---|
238 | Procedure TExplorerButton.ReadSCUResource(Const ResName:TResourceName;Var Data;DataLen:LongInt);
|
---|
239 | Begin
|
---|
240 | If ResName = 'rnGlyphDown' THEN
|
---|
241 | Begin
|
---|
242 | If DataLen <> 0 Then GlyphDown.ReadSCUResource(rnBitmap,Data,DataLen);
|
---|
243 | End
|
---|
244 | Else
|
---|
245 | If ResName = 'rnGlyphUp' Then
|
---|
246 | Begin
|
---|
247 | If DataLen <> 0 Then GlyphUp.ReadSCUResource(rnBitmap,Data,DataLen);
|
---|
248 | End
|
---|
249 | Else Inherited ReadSCUResource(ResName,Data,DataLen);
|
---|
250 | End;
|
---|
251 |
|
---|
252 | Function TExplorerButton.WriteSCUResource(Stream:TResourceStream):Boolean;
|
---|
253 | Begin
|
---|
254 | Result := Inherited WriteSCUResource(Stream);
|
---|
255 | If not Result Then exit;
|
---|
256 |
|
---|
257 | If (FBitmapDown <> Nil) And (ComponentState * [csDetail] = [])
|
---|
258 | Then Result := FBitmapDown.WriteSCUResourceName(Stream,'rnGlyphDown');
|
---|
259 | If not Result Then exit;
|
---|
260 |
|
---|
261 | If (FBitmapUp <> Nil) And (ComponentState * [csDetail] = [])
|
---|
262 | Then Result := FBitmapUp.WriteSCUResourceName(Stream,'rnGlyphUp');
|
---|
263 | End;
|
---|
264 |
|
---|
265 |
|
---|
266 | Initialization
|
---|
267 | {Register classes}
|
---|
268 | RegisterClasses([TExplorerButton]);
|
---|
269 | End.
|
---|
270 |
|
---|
271 |
|
---|