home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kolekce / d6 / FRCLX.ZIP / SOURCE / FR_Ctrls.pas < prev    next >
Pascal/Delphi Source File  |  2001-07-09  |  5KB  |  213 lines

  1.  
  2. {******************************************}
  3. {                                          }
  4. {           FastReport CLX v2.4            }
  5. {              Tool controls               }
  6. {                                          }
  7. { Copyright (c) 1998-2001 by Tzyganenko A. }
  8. {                                          }
  9. {******************************************}
  10.  
  11. unit FR_Ctrls;
  12.  
  13. interface
  14.  
  15. {$I FR.inc}
  16.  
  17. uses
  18.   SysUtils, Classes, Types, QControls, QGraphics, QButtons, QStdCtrls, QExtCtrls;
  19.  
  20. type
  21.   TfrSpeedButton = class(TSpeedButton)
  22.   private
  23.     FGrayed: Boolean;
  24.   public
  25.     constructor Create(AOwner: TComponent); override;
  26.   published
  27.     property GrayedInactive: Boolean read FGrayed write FGrayed;
  28.   end;
  29.  
  30.   TfrComboBox = class(TComboBox)
  31.   end;
  32.  
  33.   TfrFontComboBox = class(TComboBox)
  34.   private
  35.     FTrueTypeBMP: TBitmap;
  36.   protected
  37.     function DrawItem(Index: Integer; ARect: TRect;
  38.       State: TOwnerDrawState): Boolean; override;
  39.   public
  40.     constructor Create(AOwner: TComponent); override;
  41.     destructor Destroy; override;
  42.   end;
  43.  
  44.   TfrComboEdit = class(TEdit)
  45.   private
  46.     FPanel: TWinControl;
  47.     FButton: TfrSpeedButton;
  48.     FButtonEnabled: Boolean;
  49.     FOnButtonClick: TNotifyEvent;
  50.     function GetGlyph: TBitmap;
  51.     procedure SetGlyph(Value: TBitmap);
  52.     function GetButtonHint: String;
  53.     procedure SetButtonHint(Value: String);
  54.     procedure SetButtonEnabled(Value: Boolean);
  55.     procedure ButtonClick(Sender: TObject);
  56.   public
  57.     constructor Create(AOwner: TComponent); override;
  58.     procedure Resize; override;
  59.     procedure EnabledChanged; override;
  60.   published
  61.     property Glyph: TBitmap read GetGlyph write SetGlyph;
  62.     property ButtonEnabled: Boolean read FButtonEnabled write SetButtonEnabled default True;
  63.     property ButtonHint: String read GetButtonHint write SetButtonHint;
  64.     property OnButtonClick: TNotifyEvent read FOnButtonClick write FOnButtonClick;
  65.   end;
  66.  
  67. procedure frDrawTransparent(Canvas: TCanvas; x, y: Integer; bmp: TBitmap);
  68.  
  69.  
  70. implementation
  71.  
  72. uses QForms, QImgList, QDialogs;
  73.  
  74. {$R *.res}
  75.  
  76.  
  77. procedure frDrawTransparent(Canvas: TCanvas; x, y: Integer; bmp: TBitmap);
  78. var
  79.   img: TImageList;
  80. begin
  81.   img := TImageList.Create(nil);
  82.   img.Width := bmp.Width;
  83.   img.Height := bmp.Height;
  84.   img.AddMasked(bmp, bmp.TransparentColor);
  85.   img.Draw(Canvas, x, y, 0);
  86.   img.Clear;
  87.   img.Free;
  88. end;
  89.  
  90.  
  91. { TfrSpeedButton }
  92.  
  93. constructor TfrSpeedButton.Create(AOwner: TComponent);
  94. begin
  95.   inherited Create(AOwner);
  96.   Transparent := False;
  97. end;
  98.  
  99.  
  100. { TfrComboEdit }
  101.  
  102. constructor TfrComboEdit.Create(AOwner: TComponent);
  103. begin
  104.   inherited Create(AOwner);
  105.   Height := 21;
  106.   Cursor := crIBeam;
  107.   FPanel := TPanel.Create(Self);
  108.   FPanel.Parent := Self;
  109.   FPanel.SetBounds(Width - Height + 2, 2, Height - 4, Height - 4);
  110.   FButton := TfrSpeedButton.Create(Self);
  111.   FButton.Parent := FPanel;
  112.   FButton.SetBounds(0, 0, FPanel.Width, FPanel.Height);
  113.   FButton.OnClick := ButtonClick;
  114.   FButtonEnabled := True;
  115. end;
  116.  
  117. procedure TfrComboEdit.Resize;
  118. begin
  119.   inherited;
  120.   if FPanel = nil then Exit;
  121.   FPanel.SetBounds(Width - Height + 2, 2, Height - 4, Height - 4);
  122. end;
  123.  
  124. procedure TfrComboEdit.EnabledChanged;
  125. begin
  126.   inherited;
  127.   if FButton = nil then Exit;
  128.   FButton.Enabled := Enabled;
  129. end;
  130.  
  131. function TfrComboEdit.GetGlyph: TBitmap;
  132. begin
  133.   Result := FButton.Glyph;
  134. end;
  135.  
  136. procedure TfrComboEdit.SetGlyph(Value: TBitmap);
  137. begin
  138.   FButton.Glyph := Value;
  139. end;
  140.  
  141. function TfrComboEdit.GetButtonHint: String;
  142. begin
  143.   Result := FButton.Hint;
  144. end;
  145.  
  146. procedure TfrComboEdit.SetButtonHint(Value: String);
  147. begin
  148.   FButton.Hint := Value;
  149. end;
  150.  
  151. procedure TfrComboEdit.SetButtonEnabled(Value: Boolean);
  152. begin
  153.   FButtonEnabled := Value;
  154.   FButton.Enabled := Value;
  155. end;
  156.  
  157. procedure TfrComboEdit.ButtonClick(Sender: TObject);
  158. begin
  159.   SetFocus;
  160.   if Assigned(FOnButtonClick) then
  161.     FOnButtonClick(Self);
  162. end;
  163.  
  164.  
  165. { TfrFontComboBox }
  166.  
  167. constructor TfrFontComboBox.Create(AOwner: TComponent);
  168. begin
  169.   inherited Create(AOwner);
  170.   FTrueTypeBMP := TBitmap.Create;
  171.   FTrueTypeBMP.LoadFromResourceName(HInstance, 'FTRUETYPE_FNT');
  172.   Style := csOwnerDrawFixed;
  173.   DropDownCount := 12;
  174.   Width := 150;
  175.   Sorted := True;
  176.   Items.Assign(Screen.Fonts);
  177. end;
  178.  
  179. destructor TfrFontComboBox.Destroy;
  180. begin
  181.   FTrueTypeBMP.Free;
  182.   inherited Destroy;
  183. end;
  184.  
  185. function TfrFontComboBox.DrawItem(Index: Integer; ARect: TRect;
  186.   State: TOwnerDrawState): Boolean;
  187. var
  188.   Bitmap: TBitmap;
  189.   BmpWidth: Integer;
  190. begin
  191.   with Canvas do
  192.   begin
  193.     BmpWidth := 15;
  194.     if odFocused in State then
  195.       FillRect(ARect);
  196.     Bitmap := FTrueTypeBMP;
  197.     if Bitmap <> nil then
  198.     begin
  199.       BmpWidth := Bitmap.Width;
  200.       frDrawTransparent(Canvas, ARect.Left + 1, (ARect.Top + ARect.Bottom - Bitmap.Height) div 2, Bitmap);
  201.     end;
  202.     ARect.Left := ARect.Left + BmpWidth + 2;
  203.     if not Focused then
  204.       Font.Color := clBlack;
  205.     TextOut(ARect.Left, ARect.Top, Items[Index]);
  206.   end;
  207.   Result := True;
  208. end;
  209.  
  210.  
  211. end.
  212.  
  213.