Menu

[91660d]: / HSStaticText.pas  Maximize  Restore  History

Download this file

504 lines (420 with data), 15.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
{
HSButtons Suite - Two new buttons for Delphi!
Copyright (C) 2000-2010 Leif Bruder, Haitham Shatti
e-Mail: haitham.shatti@gmail.com
This file is part of HSButtons Suite.
HSButtons Suite is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
HSButtons Suite is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with HSButtons Suite; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
unit HSStaticText;
interface
uses
Windows, {$ifdef fpc} LMessages {$else} messages {$endif}, Classes, Graphics, Controls, Forms, HSButtons;
type
THSStaticText = class(TCustomControl)
private
FAlignment: TAlignment;
FFlat: boolean;
FWordWrap: boolean;
FGlyph: TBitmap;
FHotTrackColor: TColor;
FHTFont: TFont;
FLayout: THSButtonLayout;
FLightColor: TColor;
FNumGlyphs: integer;
FShadowColor: TColor;
FStyle: THSButtonStyle;
FUseHTFont: boolean;
FOnMouseEnter: TNotifyEvent;
FOnMouseExit: TNotifyEvent;
FDummyStyle: THSColorStyle;
bCursorOnButton: boolean;
FTimer: THSButtonTimer;
FSlowDecease: THSSlowDecease;
FHotTrackStep: integer;
FColor: TColor;
FBorder: SmallInt;
FSmooth: SmallInt;
procedure SetColor(const Value: TColor);
procedure SetBorder(const Value: SmallInt);
procedure SetSmooth(const Value: SmallInt);
public
constructor Create(aOwner: TComponent); override;
destructor Destroy; override;
procedure Click; override;
protected
procedure Paint; override;
procedure DoStep(Sender: TObject);
function GetCaption: TCaption;
procedure SetAlignment(fNew: TAlignment);
procedure SetFlat(fNew: boolean);
procedure SetColorStyle(fNew: THSColorStyle);
procedure SetCaption(const fNew: TCaption);
procedure SetGlyph(fNew: TBitmap);
procedure SetHTFont(fNew: TFont);
procedure SetLayout(fNew: THSButtonLayout);
procedure SetLightColor(fNew: TColor);
procedure SetNumGlyphs(fNew: integer);
procedure SetShadowColor(fNew: TColor);
procedure SetSlowDecease(fNew: THSSlowDecease);
procedure SetStyle(fNew: THSButtonStyle);
procedure SetWordWrap(fNew: boolean);
procedure DoMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure DoMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
procedure DoDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
published
property Align;
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
property Anchors;
property Border:Smallint read FBorder write SetBorder default 1;
property Caption: TCaption read GetCaption write SetCaption;
property Color:TColor read FColor write SetColor;
property ColorStyle: THSColorStyle read FDummyStyle write SetColorStyle default lcsCustom;
property Flat: boolean read FFlat write SetFlat default false;
property Font;
property Glyph: TBitmap read FGlyph write SetGlyph;
property HotTrackColor: TColor read FHotTrackColor write FHotTrackColor default clNone;
property HotTrackFont: TFont read FHTFont write SetHTFont;
property Hint;
property Layout: THSButtonLayout read FLayout write SetLayout default blGlyphLeft;
property LightColor: TColor read FLightColor write SetLightColor default clWhite;
property NumGlyphs: integer read FNumGlyphs write SetNumGlyphs default 0;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShadowColor: TColor read FShadowColor write SetShadowColor default clBlack;
property ShowHint;
property SlowDecease: THSSlowDecease read FSlowDecease write SetSlowDecease default sdNone;
property Smooth:SmallInt read FSmooth write SetSmooth;
property Style: THSButtonStyle read FStyle write SetStyle default bsNormal;
property UseHotTrackFont: boolean read FUseHTFont write FUseHTFont default false;
property Visible;
property WordWrap: boolean read FWordWrap write SetWordWrap default false;
property OnClick;
property OnDblClick;
property OnMouseDown;
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseExit: TNotifyEvent read FOnMouseExit write FOnMouseExit;
property OnMouseMove;
property OnMouseUp;
end;
procedure Register;
implementation
{##############################################################################}
procedure Register;
begin
RegisterComponents('HS', [THSStaticText]);
end;
{##############################################################################}
constructor THSStaticText.Create(aOwner: TComponent);
begin
inherited;
ControlStyle := ControlStyle + [csSetCaption];
ControlStyle := ControlStyle - [csOpaque];
Height := 23;
Width := 100;
FBorder:=1;
bCursorOnButton := false;
FLightColor := clWhite;
FShadowColor := clBlack;
FHotTrackColor := clNone;
FWordWrap := false;
FAlignment := taCenter;
FDummyStyle := lcsCustom;
FSlowDecease := sdNone;
FGlyph := TBitmap.Create;
FHtFont := TFont.Create;
FHotTrackStep := 0;
FTimer := THSButtonTimer.Create(DoStep);
// FThread.FreeOnTerminate := false;
if aOwner is TForm then FHtFont.Assign(TForm(aOwner).Font);
end;
{##############################################################################}
destructor THSStaticText.Destroy;
begin
if Assigned(FTimer) then
FTimer.Free;
FHtFont.Free;
FGlyph.Free;
inherited;
end;
{##############################################################################}
procedure THSStaticText.SetAlignment(fNew: TAlignment);
begin
FAlignment := fNew;
paint;
end;
procedure THSStaticText.SetBorder(const Value: SmallInt);
begin
FBorder := Value;
Paint
end;
{##############################################################################}
procedure THSStaticText.SetCaption(const fNew: TCaption);
begin
inherited Caption := fNew;
invalidate;
end;
{##############################################################################}
function THSStaticText.GetCaption: TCaption;
begin
Result := inherited Caption;
end;
{##############################################################################}
procedure THSStaticText.SetColor(const Value: TColor);
begin
FColor := Value;
{ if FStyle in [bsGlass,bsModern] then} begin
FLightColor:=ColorBright(FColor,128);
// FHotTrackColor:=ColorBright(FColor,$20);
FShadowColor:=ColorBright(FColor,-$80);
if GetGrayScale(FColor)<$606060 then
Font.Color:=clWhite
else
Font.Color:=clBlack;
end;
// ColorWhenDown:=clNone
end;
procedure THSStaticText.SetColorStyle(fNew: THSColorStyle);
var
bModern, bQuicken: boolean;
FColor, FontColor, FDummy: TColor;
begin
if fNew = lcsCustom then exit;
GetPreDefinedColors(fNew, FColor, FLightColor, FShadowColor, FDummy, FHotTrackColor, FontColor, FFlat, bModern, bQuicken);
// Color := FColor;
Font.Color := FontColor;
FStyle := bsNormal; if bModern then FStyle := bsModern; if bQuicken then FStyle := bsQuicken;
if fNew in [lcsGlassGold,lcsGlassChrome,lcsGlassBlue,lcsGlassRed,lcsGlassAqua] then
FStyle:=bsGlass;
Paint;
end;
{##############################################################################}
procedure THSStaticText.SetFlat(fNew: boolean);
begin
FFlat := fNew;
Invalidate;
end;
{##############################################################################}
procedure THSStaticText.SetGlyph(fNew: TBitmap);
begin
if fNew <> nil then
begin
FGlyph.Assign(fNew);
if fNew.Height <> 0 then FNumGlyphs := fNew.Width div fNew.Height else FNumGlyphs := 0;
end
else
begin
FGlyph.Height := 0;
FNumGlyphs := 0;
end;
invalidate;
end;
{##############################################################################}
procedure THSStaticText.SetHTFont(fNew: TFont);
begin
FHTFont.Assign(fNew);
end;
{##############################################################################}
procedure THSStaticText.SetLayout(fNew: THSButtonLayout);
begin
FLayout := fNew;
paint;
end;
{##############################################################################}
procedure THSStaticText.SetLightColor(fNew: TColor);
begin
FLightColor := fNew;
paint;
end;
{##############################################################################}
procedure THSStaticText.SetNumGlyphs(fNew: integer);
begin
FNumGlyphs := fNew;
invalidate;
end;
{##############################################################################}
procedure THSStaticText.SetShadowColor(fNew: TColor);
begin
FShadowColor := fNew;
paint;
end;
{##############################################################################}
procedure THSStaticText.SetSlowDecease(fNew: THSSlowDecease);
begin
FSlowDecease := fNew;
if FSlowDecease<>sdNone then
begin
if not Assigned(FTimer) then
begin
FTimer := THSButtonTimer.Create(DoStep);
// FThread.FreeOnTerminate := false;
end;
end
else
begin
if Assigned(FTimer) then
begin
FHotTrackStep := 0;
FTimer.Free;
FTimer := nil;
end;
end;
Invalidate;
end;
procedure THSStaticText.SetSmooth(const Value: SmallInt);
begin
FSmooth := Value;
Paint
end;
{##############################################################################}
procedure THSStaticText.SetStyle(fNew: THSButtonStyle);
begin
if fNew = bsModern then if GetDeviceCaps(Canvas.Handle, BITSPIXEL) <= 8 then if not (csDesigning in ComponentState) then fNew := bsNormal;
FStyle := fNew;
invalidate;
end;
{##############################################################################}
procedure THSStaticText.SetWordWrap(fNew: boolean);
begin
FWordwrap := fNew;
paint;
end;
{##############################################################################}
procedure THSStaticText.Paint;
var
// aStyle: THSButtonStyle;
// aLayout: THSButtonLayout;
aBitmap: TBitmap;
aFont: TFont;
{$ifdef FPC} mem:TMemoryStream;{$endif}
begin
if not (Visible or (csDesigning in ComponentState)) or (csLoading in ComponentState) then exit;
{ aStyle := HSButtons.bsNormal;
case FStyle of
bsEncarta: aStyle := HSButtons.bsEncarta;
bsModern: aStyle := HSButtons.bsModern;
bsOld: aStyle := HSButtons.bsOld;
bsShape: aStyle := HSButtons.bsShape;
bsQuicken: aStyle := HSButtons.bsQuicken;
end;}
{ aLayout := HSButtons.blGlyphLeft;
case FLayout of
blGlyphTop: aLayout := HSButtons.blGlyphTop;
blGlyphRight: aLayout := HSButtons.blGlyphRight;
blGlyphBottom: aLayout := HSButtons.blGlyphBottom;
end;}
aBitmap := TBitmap.Create;
aBitmap.PixelFormat:=pf32bit;
aBitmap.Height := Height;
aBitmap.Width := Width;
if FStyle in [bsModern, bsShape, bsQuicken, bsGlass] then
begin
aBitmap.TransparentMode := tmAuto;
aBitmap.Transparent := True;
aBitmap.Canvas.Brush.Color := clFuchsia;
aBitmap.Canvas.FillRect(Rect(0, 0, Width, Height));
aBitmap.TransparentColor := clFuchsia;
end;
aFont := Font; if bCursorOnButton and FUseHTFont then aFont := FHtFont;
HSPaintButton(aBitmap, Width, Height,FBorder, FHotTrackStep,FSmooth, FNumGlyphs, FGlyph, false, bCursorOnButton, false, true, Flat, FWordWrap, assigned(PopupMenu), FStyle, Color, clNone, FHotTrackColor, FLightColor, FShadowColor, aFont, FLayout, Caption, FAlignment);
{$ifdef FPC}
// for some reason FPC doesn't apply transparency
// except of a stream or file was loaded fooling FPC below
mem:=TMemoryStream.Create;
aBitmap.SaveToStream(mem);
mem.Position:=0;
aBitmap.Clear;
aBitmap.FreeImage;
aBitmap.Transparent:=true;
aBitmap.TransparentColor:=clFuchsia;
aBitmap.LoadFromStream(mem);
mem.Free;
{$endif}
Canvas.Draw(0, 0, aBitmap);
aBitmap.Free;
end;
{##############################################################################}
procedure THSStaticText.DoMouseEnter(var Msg: TMessage);
begin
if not(csDesigning in Componentstate) and Enabled and Visible and (Parent <> nil) and Parent.Showing then
begin
bCursorOnButton := true;
if FSlowDecease=sdEnterLeave then
if Assigned(FTimer) then
if (FTimer.Suspended) then FTimer.Start
else
else
else
begin
FHotTrackStep := cHotTrackSteps;
paint;
end;
if assigned(FOnMouseEnter) then FOnMouseEnter(self);
end;
end;
{##############################################################################}
procedure THSStaticText.DoMouseLeave(var Msg: TMessage);
begin
bCursorOnButton := false;
if FSlowDecease<>sdNone then
if Assigned(FTimer) then
if (FTimer.Suspended) then FTimer.Start
else
else
else
begin
FHotTrackStep := 0;
paint;
end;
if Enabled and Visible and (Parent <> nil) and Parent.Showing then if assigned(FOnMouseExit) then FOnMouseExit(self);
end;
{##############################################################################}
procedure THSStaticText.DoDialogChar(var Message: TCMDialogChar);
begin
with Message do
begin
if IsAccel(CharCode, Caption) and Visible and (Parent <> nil) and Parent.Showing then
begin
Click;
Result := 1;
end
else
inherited;
end;
end;
{##############################################################################}
procedure THSStaticText.Click;
begin
// if assigned(PopupMenu) then PopupMenu.PopUp(ClientToScreen(Point(0, Height)).X + Width, ClientToScreen(Point(0, Height)).Y);
if assigned(PopupMenu) then PopupMenu.PopUp(ClientToScreen(Point(0, Height)).X, ClientToScreen(Point(0, Height)).Y);
inherited; // just to make it public :-)
end;
{##############################################################################}
procedure THSStaticText.DoStep(Sender: TObject);
begin
if csDestroying in ComponentState then exit;
if bCursorOnButton then
inc(FHotTrackStep)
else
dec(FHotTrackStep);
if (0>=FHotTrackStep) or (FHotTrackStep>=cHotTrackSteps) then
begin
if Assigned(FTimer) and (not FTimer.Suspended) then
FTimer.Suspend;
if bCursorOnButton then FHotTrackStep:=cHotTrackSteps else FHotTrackStep := 0;
end;
paint;
end;
{##############################################################################}
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.