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
|
{ $Id: FpGuiwsbuttons.pp 5682 2004-07-15 10:43:39Z mattias $}
{
*****************************************************************************
* FpGuiWSButtons.pp *
* -------------- *
* *
* *
*****************************************************************************
*****************************************************************************
This file is part of the Lazarus Component Library (LCL)
See the file COPYING.LCL, included in this distribution,
for details about the license.
*****************************************************************************
}
unit FpGuiWSButtons;
{$mode objfpc}{$H+}
interface
uses
// Bindings
fpguiwsprivate, fpg_main, fpg_button,
// RTL
SysUtils,
// LCL
Buttons, LCLType, Controls, Graphics, ImgList,
// LazUtils
GraphType,
// Widgetset
WSButtons, WSLCLClasses;
type
{ TFpGuiWSBitBtn }
TFpGuiWSBitBtn = class(TWSBitBtn)
private
protected
FButImageName: string;
public
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class procedure DestroyHandle(const AWinControl: TWinControl); override;
class procedure SetGlyph(const ABitBtn: TCustomBitBtn; const AValue: TButtonGlyph); override;
class procedure SetLayout(const ABitBtn: TCustomBitBtn; const AValue: TButtonLayout);
override;
end;
{ TFpGuiWSSpeedButton }
TFpGuiWSSpeedButton = class(TWSSpeedButton)
private
protected
public
published
end;
implementation
{ TFpGuiWSBitBtn }
class function TFpGuiWSBitBtn.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle;
begin
Result := TLCLHandle(TFPGUIPrivateButton.Create(AWinControl, AParams));
end;
class procedure TFpGuiWSBitBtn.DestroyHandle(const AWinControl: TWinControl);
begin
TFPGUIPrivateButton(AWinControl.Handle).Free;
AWinControl.Handle := 0;
end;
class procedure TFpGuiWSBitBtn.SetGlyph(const ABitBtn: TCustomBitBtn;
const AValue: TButtonGlyph);
var
lButton: TFPGUIPrivateButton;
lBitmap: TBitmap=nil;
fpgImage: TfpgImage;
lButImageName: string;
lButtonState: TButtonState;
lIndex: integer;
lEffect: TGraphicsDrawEffect;
lImageRes: TScaledImageListResolution;
begin
if not Assigned(AValue.Images) then exit;
lButton := TFPGUIPrivateButton(ABitBtn.Handle);
lButtonState := bsUp;
AValue.GetImageIndexAndEffect(lButtonState, ABitBtn.Font.PixelsPerInch,
ABitBtn.GetCanvasScaleFactor, lImageRes, lIndex, lEffect);
lBitmap:=TBitmap.Create;
AValue.Images.GetBitmap(lIndex,lBitmap);
fpgImage:=TfpgImage.Create;
fpgImage.AllocateImage(32,lBitmap.Width,lBitmap.Height);
move(lBitmap.RawImage.Data^,fpgImage.ImageData^,fpgImage.ImageDataSize);
fpgImage.CreateMaskFromSample(0,0);
fpgImage.UpdateImage;
lBitmap.Free;
if lButton.Button.ImageName<>'' then begin
fpgImages.DeleteImage(lButton.Button.ImageName,true);
end;
lButImageName:='lcl.bitbtn.'+IntToStr(PtrInt(ABitBtn.Handle));
fpgImages.AddImage(lButImageName,fpgImage);
lButton.Button.ImageName:=lButImageName;
lButton.Button.ShowImage:=true;
end;
class procedure TFpGuiWSBitBtn.SetLayout(const ABitBtn: TCustomBitBtn;
const AValue: TButtonLayout);
var
lButton: TFPGUIPrivateButton;
begin
lButton := TFPGUIPrivateButton(ABitBtn.Handle);
case AValue of
blGlyphLeft: lButton.Button.ImageLayout:=ilImageLeft;
blGlyphRight: lButton.Button.ImageLayout:=ilImageRight;
blGlyphTop: lButton.Button.ImageLayout:=ilImageTop;
blGlyphBottom: lButton.Button.ImageLayout:=ilImageBottom;
end;
end;
initialization
////////////////////////////////////////////////////
// I M P O R T A N T
////////////////////////////////////////////////////
// To improve speed, register only classes
// which actually implement something
////////////////////////////////////////////////////
// RegisterWSComponent(TCustomBitBtn, TFpGuiWSBitBtn);
// RegisterWSComponent(TCustomSpeedButton, TFpGuiWSSpeedButton);
////////////////////////////////////////////////////
end.
|