home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kolekce / d56 / TDSOFT.ZIP / TDSuperLabel.pas < prev    next >
Pascal/Delphi Source File  |  2001-05-21  |  5KB  |  187 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       TDSoft Visual Component Library                 }
  4. {                                                       }
  5. {       Copyright (c) 2001 Daniele Teti                 }
  6. {                                                       }
  7. {-------------------------------------------------------}
  8. {       For suggest, request, bug or only for sport:    }
  9. {       Daniele_Teti@hotmail.com                        }
  10. {-------------------------------------------------------}
  11. {                                                       }
  12. {                                                       }
  13. {*******************************************************}
  14.  
  15. unit TDSuperLabel;
  16.  
  17. interface
  18.  
  19. uses
  20.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  21.   StdCtrls, DsgnIntf;
  22.  
  23. {$R *.dcr}
  24.  
  25. type
  26.   TTDSuperLabel = class(TCustomLabel)
  27.   private
  28.     FOnClickExecute: string;
  29.     FParameters: string;
  30.     FHoverFontStyle: TFontStyles;
  31.     FHoverColor: TColor;
  32.     procedure SetStyle(const Value: TFontStyles);
  33.     procedure SetHoverColor(const Value: TColor);
  34.     { Private declarations }
  35.   protected
  36.     { Protected declarations }
  37.     OldFontStyle: TFontStyles;
  38.     OldFontColor: TColor;
  39.     IsMouseOver: Boolean;
  40.     procedure WMLBUTTONUP(var Mes: TMessage); message WM_LBUTTONUP;
  41.     procedure CMMOUSEENTER(var Mes: TMessage); message CM_MOUSEENTER;
  42.     procedure CMMOUSELEAVE(var Mes: TMessage); message CM_MOUSELEAVE;
  43.     procedure ReDraw;
  44.   public
  45.     { Public declarations }
  46.     constructor Create(AOwner: TComponent); override;
  47.   published
  48.     property Align;
  49.     property Alignment;
  50.     property Anchors;
  51.     property AutoSize;
  52.     property BiDiMode;
  53.     property Caption;
  54.     property Color;
  55.     property Constraints;
  56.     property DragCursor;
  57.     property DragKind;
  58.     property DragMode;
  59.     property Enabled;
  60.     property FocusControl;
  61.     //property Font;
  62.     property ParentBiDiMode;
  63.     property ParentColor;
  64.     property ParentFont;
  65.     property ParentShowHint;
  66.     property PopupMenu;
  67.     property ShowAccelChar;
  68.     property ShowHint;
  69.     property Transparent;
  70.     property Layout;
  71.     property Visible;
  72.     property WordWrap;
  73.     property OnClick;
  74.     property OnContextPopup;
  75.     property OnDblClick;
  76.     property OnDragDrop;
  77.     property OnDragOver;
  78.     property OnEndDock;
  79.     property OnEndDrag;
  80.     property OnMouseDown;
  81.     property OnMouseMove;
  82.     property OnMouseUp;
  83.     property OnStartDock;
  84.     property OnStartDrag;
  85.  
  86.     { Published declarations }
  87.     property OnClickExecute: string read FOnClickExecute write FOnClickExecute;
  88.     property Parameters: string read FParameters write FParameters;
  89.     property HoverFontStyle: TFontStyles read FHoverFontStyle write SetStyle;
  90.     property HoverColor: TColor read FHoverColor write SetHoverColor;
  91.   end;
  92.  
  93.  
  94.   TAboutProperty = class(TStringProperty)
  95.   public
  96.     function GetAttributes: TPropertyAttributes; override;
  97.     procedure Edit; override;
  98.   end;
  99.  
  100.  
  101. procedure Register;
  102.  
  103. implementation
  104.  
  105. uses ShellApi;
  106.  
  107. procedure Register;
  108. begin
  109.   RegisterComponents('TDSoft', [TTDSuperLabel]);
  110.   RegisterPropertyEditor(TypeInfo(string), TTDSuperLabel, 'About', TAboutProperty);
  111. end;
  112.  
  113. { TTDSuperLabel }
  114.  
  115. procedure TTDSuperLabel.CMMOUSEENTER(var Mes: TMessage);
  116. begin
  117.   IsMouseOver := True;
  118.   ReDraw;
  119. end;
  120.  
  121. procedure TTDSuperLabel.CMMOUSELEAVE(var Mes: TMessage);
  122. begin
  123.   IsMouseOver := False;
  124.   ReDraw;
  125. end;
  126.  
  127. constructor TTDSuperLabel.Create(AOwner: TComponent);
  128. begin
  129.   inherited;
  130.   FHoverFontStyle := Font.Style + [fsUnderLine];
  131.   FHoverColor := clBlue;
  132.   IsMouseOver := False;
  133.   Redraw;
  134. end;
  135.  
  136. procedure TTDSuperLabel.ReDraw;
  137. begin
  138.   if IsMouseOver then
  139.   begin
  140.     OldFontStyle := Font.Style;
  141.     OldFontColor := Font.Color;
  142.     Font.Style := FHoverFontStyle;
  143.     Font.Color := FHoverColor;
  144.   end
  145.   else
  146.   begin
  147.     Font.Style := OldFontStyle;
  148.     Font.Color := OldFontColor;
  149.   end;
  150. end;
  151.  
  152.  
  153. procedure TTDSuperLabel.SetHoverColor(const Value: TColor);
  154. begin
  155.   FHoverColor := Value;
  156.   ReDraw;
  157. end;
  158.  
  159. procedure TTDSuperLabel.SetStyle(const Value: TFontStyles);
  160. begin
  161.   FHoverFontStyle := Value;
  162.   ReDraw;
  163. end;
  164.  
  165. procedure TTDSuperLabel.WMLBUTTONUP(var Mes: TMessage);
  166. begin
  167.   inherited;
  168.   if trim(FOnClickExecute) <> '' then
  169.     ShellExecute(0, 'open', PChar(FOnClickExecute), PChar(' ' + FParameters), nil, SW_SHOW);
  170. end;
  171.  
  172. { TAboutProperty }
  173.  
  174. procedure TAboutProperty.Edit;
  175. begin
  176.   MessageDlg('TTDSuperLabel 0.9' + #13 + '(06/Apr/2001)' + #13 + #13 +
  177.     'written by Teti Daniele (Daniele_Teti@Hotmail.com)', mtInformation, [mbOk], 0);
  178. end;
  179.  
  180. function TAboutProperty.GetAttributes: TPropertyAttributes;
  181. begin
  182.   Result := [paDialog];
  183. end;
  184.  
  185. end.
  186.  
  187.