mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-16 23:49:28 +02:00
Improved TSpeedButton (Glyph, Spacing, Margin, drawing)
Added PageCount to TNotebook Optimized component selection buttons a bit. git-svn-id: trunk@1456 -
This commit is contained in:
parent
b84b0b9b70
commit
8d718a011d
@ -26,13 +26,14 @@ program checkbox;
|
||||
|
||||
uses
|
||||
classes, stdctrls, forms, buttons, menus, comctrls, sysutils,
|
||||
extctrls, graphtype, controls;
|
||||
extctrls, graphtype, graphics, controls;
|
||||
|
||||
type
|
||||
TForm1 = class(TFORM)
|
||||
public
|
||||
Button2: TButton;
|
||||
Button3: TButton;
|
||||
Button11, Button12, Button13 : TSpeedButton;
|
||||
Panel1: TPanel;
|
||||
mnuMain: TMainMenu;
|
||||
itmFileQuit: TMenuItem;
|
||||
@ -45,7 +46,8 @@ type
|
||||
RadioGroup2 : TRadioGroup;
|
||||
ToggleBox : TToggleBox;
|
||||
label1 : TLabel;
|
||||
label2 : TLabel;
|
||||
label2 : TLabel;
|
||||
FPixmap : TPixMap;
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
procedure LoadMainMenu;
|
||||
Procedure FormKill(Sender : TObject);
|
||||
@ -215,6 +217,44 @@ begin
|
||||
Button2.Caption := 'Toggle checkbox';
|
||||
Button2.OnClick := @Button2Click;
|
||||
|
||||
FPixMap:= TPixmap.Create;
|
||||
FPixmap.LoadFromFile('../images/btn_newform.xpm');
|
||||
|
||||
Button11 := TSpeedButton.Create(Self);
|
||||
Button11.GroupIndex:= 1;
|
||||
Button11.Layout:= blGlyphTop;
|
||||
// Button11.Caption:= 'Option 1';
|
||||
Button11.Parent := Self;
|
||||
Button11.Left := 5;
|
||||
Button11.Top := 5;
|
||||
Button11.Width:= 45;
|
||||
Button11.Height:= 55;
|
||||
Button11.Flat:= true;
|
||||
Button11.Glyph:= FPixmap;
|
||||
// Button11.Spacing:= -1;
|
||||
// Button11.Margin:= 4;
|
||||
Button11.Visible:= true;
|
||||
|
||||
Button12 := TSpeedButton.Create(Self);
|
||||
Button12.GroupIndex:= 1;
|
||||
Button12.Caption:= '2';
|
||||
Button12.Parent := Self;
|
||||
Button12.Left := 55;
|
||||
Button12.Top := 5;
|
||||
// Button12.Flat:= true;
|
||||
Button12.Visible:= true;
|
||||
|
||||
Button13 := TSpeedButton.Create(Self);
|
||||
Button13.GroupIndex:= 1;
|
||||
Button13.Caption:= '3';
|
||||
Button13.Parent := Self;
|
||||
Button13.Left := 95;
|
||||
Button13.Top := 5;
|
||||
Button13.Flat:= true;
|
||||
Button13.AllowAllUp:= true;
|
||||
Button13.Visible:= true;
|
||||
|
||||
|
||||
{ Create a label which shows the caption of the active radiobutton }
|
||||
label2 := TLabel.Create(Self);
|
||||
label2.Parent := self;
|
||||
@ -365,6 +405,11 @@ end.
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.3 2002/02/24 20:51:23 lazarus
|
||||
Improved TSpeedButton (Glyph, Spacing, Margin, drawing)
|
||||
Added PageCount to TNotebook
|
||||
Optimized component selection buttons a bit.
|
||||
|
||||
Revision 1.2 2002/02/03 00:24:00 lazarus
|
||||
TPanel implemented.
|
||||
Basic graphic primitives split into GraphType package, so that we can
|
||||
|
112
ide/main.pp
112
ide/main.pp
@ -642,7 +642,7 @@ begin
|
||||
GlobalMouseSpeedButton := TSpeedButton.Create(Self);
|
||||
SelectionPointerPixmap:=LoadSpeedBtnPixMap('tmouse');
|
||||
with GlobalMouseSpeedButton do
|
||||
Begin
|
||||
begin
|
||||
Parent := ComponentNotebook.Page[PageCount];
|
||||
Parent.OnMouseMove := @MainMouseMoved; //this is for the hints
|
||||
Enabled := True;
|
||||
@ -652,6 +652,7 @@ begin
|
||||
Glyph := SelectionPointerPixmap;
|
||||
Visible := True;
|
||||
Flat := True;
|
||||
GroupIndex:= 1;
|
||||
Down := True;
|
||||
Name := 'GlobalMouseSpeedButton'+IntToStr(PageCount);
|
||||
Hint := 'Selection tool';
|
||||
@ -668,6 +669,7 @@ begin
|
||||
IDEComponent.SpeedButton.Hint := RegComp.ComponentClass.ClassName;
|
||||
IDEComponent.SpeedButton.Name := IDEComponent.SpeedButton.Hint;
|
||||
IDEComponent.SpeedButton.ShowHint := True;
|
||||
IDEComponent.SpeedButton.GroupIndex := 1;
|
||||
IDECompList.Add(IDEComponent);
|
||||
end;
|
||||
inc(PageCount);
|
||||
@ -1634,119 +1636,32 @@ end;
|
||||
------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
Procedure TMainIDE.ControlClick(Sender : TObject);
|
||||
procedure TMainIDE.ControlClick(Sender : TObject);
|
||||
var
|
||||
I : Integer;
|
||||
IDECOmp : TIDEComponent;
|
||||
Speedbutton : TSpeedbutton;
|
||||
Temp : TControl;
|
||||
i : integer;
|
||||
begin
|
||||
if Sender is TSpeedButton then
|
||||
Begin
|
||||
// Writeln('sender is a speedbutton');
|
||||
// Writeln('The name is '+TSpeedbutton(sender).name);
|
||||
begin
|
||||
SpeedButton := TSpeedButton(Sender);
|
||||
// Writeln('Speedbutton s Name is '+SpeedButton.name);
|
||||
//find the IDECOmponent that has this speedbutton
|
||||
IDEComp := IDECompList.FindCompBySpeedButton(SpeedButton);
|
||||
if SelectedComponent <> nil then
|
||||
TIDeComponent(
|
||||
IdeCompList.FindCompByRegComponent(SelectedComponent)).SpeedButton.Down
|
||||
:= False
|
||||
else begin
|
||||
Temp := nil;
|
||||
for i := 0 to
|
||||
ComponentNotebook.Page[ComponentNotebook.Pageindex].ControlCount-1
|
||||
do begin
|
||||
if CompareText(
|
||||
TControl(ComponentNotebook.
|
||||
Page[ComponentNotebook.Pageindex].Controls[I]).Name
|
||||
,'GlobalMouseSpeedButton'
|
||||
+IntToStr(ComponentNotebook.Pageindex)) = 0 then
|
||||
begin
|
||||
temp := TControl(ComponentNotebook.
|
||||
Page[ComponentNotebook.Pageindex].Controls[i]);
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
if temp <> nil then
|
||||
TSpeedButton(Temp).down := False
|
||||
else begin
|
||||
Writeln('[TMainIDE.ControlClick] ERROR - Control ',
|
||||
'GlobalMouseSpeedButton',
|
||||
IntToStr(ComponentNotebook.PageIndex),' not found');
|
||||
Halt;
|
||||
end;
|
||||
end;
|
||||
if IDECOmp <> nil then Begin
|
||||
//draw this button down
|
||||
SpeedButton.Down := True;
|
||||
if IDECOmp <> nil then begin
|
||||
SelectedComponent := IDEComp.RegisteredComponent;
|
||||
end else begin
|
||||
SelectedComponent := nil;
|
||||
Temp := nil;
|
||||
for i := 0 to
|
||||
ComponentNotebook.Page[ComponentNotebook.Pageindex].ControlCount-1 do
|
||||
begin
|
||||
if CompareText(
|
||||
TControl(ComponentNotebook.
|
||||
Page[ComponentNotebook.Pageindex].Controls[I]).Name
|
||||
,'GlobalMouseSpeedButton'
|
||||
+IntToStr(ComponentNotebook.Pageindex)) = 0 then
|
||||
begin
|
||||
temp := TControl(ComponentNotebook.
|
||||
Page[ComponentNotebook.Pageindex].Controls[i]);
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
if temp <> nil then
|
||||
TSpeedButton(Temp).down := True
|
||||
else begin
|
||||
Writeln('[TMainIDE.ControlClick] ERROR - Control '
|
||||
+'GlobalMouseSpeedButton'
|
||||
+IntToStr(ComponentNotebook.Pageindex)+' not found');
|
||||
Halt;
|
||||
end;
|
||||
end;
|
||||
end
|
||||
else
|
||||
Begin
|
||||
// Writeln('must be nil');
|
||||
//draw old speedbutton up
|
||||
if SelectedComponent <> nil then
|
||||
TIDeComponent(
|
||||
IdeCompList.FindCompByRegComponent(SelectedComponent)).SpeedButton.Down
|
||||
:= False;
|
||||
else
|
||||
begin
|
||||
SelectedComponent := nil;
|
||||
Temp := nil;
|
||||
for i := 0 to
|
||||
ComponentNotebook.Page[ComponentNotebook.Pageindex].ControlCount-1 do
|
||||
begin
|
||||
if CompareText(
|
||||
TControl(ComponentNotebook.
|
||||
Page[ComponentNotebook.Pageindex].Controls[I]).Name
|
||||
,'GlobalMouseSpeedButton'
|
||||
+IntToStr(ComponentNotebook.Pageindex)) = 0 then
|
||||
begin
|
||||
temp := TControl(ComponentNotebook.
|
||||
Page[ComponentNotebook.Pageindex].Controls[i]);
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
if temp <> nil then
|
||||
TSpeedButton(Temp).down := True
|
||||
else begin
|
||||
Writeln('[TMainIDE.ControlClick] ERROR - Control '
|
||||
+'GlobalMouseSpeedButton'
|
||||
+IntToStr(ComponentNotebook.Pageindex)+' not found');
|
||||
Halt;
|
||||
for i:= 0 to ComponentNotebook.PageCount - 1 do begin
|
||||
(ComponentNotebook.Page[i].Controls[0] as TSpeedButton).Down:= true;
|
||||
end;
|
||||
end;
|
||||
// Writeln('Exiting ControlClick');
|
||||
end;
|
||||
|
||||
|
||||
|
||||
{------------------------------------------------------------------------------}
|
||||
procedure TMainIDE.mnuFindDeclarationClicked(Sender : TObject);
|
||||
begin
|
||||
@ -6107,6 +6022,11 @@ end.
|
||||
|
||||
{ =============================================================================
|
||||
$Log$
|
||||
Revision 1.231 2002/02/24 20:51:22 lazarus
|
||||
Improved TSpeedButton (Glyph, Spacing, Margin, drawing)
|
||||
Added PageCount to TNotebook
|
||||
Optimized component selection buttons a bit.
|
||||
|
||||
Revision 1.230 2002/02/22 17:39:40 lazarus
|
||||
MG: improved LinkScanner error messages
|
||||
|
||||
|
@ -33,7 +33,8 @@ interface
|
||||
{$ASSERTIONS ON}
|
||||
{$endif}
|
||||
|
||||
uses stdctrls, vclglobals, classes, LCLType, LCLLinux,graphics,sysutils, controls, lMessages,Forms, messages;
|
||||
uses StdCtrls, VCLGlobals, Classes, LCLType, LCLLinux,
|
||||
GraphType, Graphics, SysUtils, Controls, lMessages, Forms, Messages;
|
||||
|
||||
type
|
||||
TButtonLayout = (blGlyphLeft, blGlyphRight, blGlyphTop, blGlyphBottom);
|
||||
@ -96,16 +97,14 @@ type
|
||||
FNumGlyphs : TNumGlyphs;
|
||||
|
||||
FOnChange : TNotifyEvent;
|
||||
|
||||
Procedure SetGlyph(Value : TBitmap);
|
||||
Procedure SetNumGlyphs(Value : TNumGlyphs);
|
||||
procedure SetGlyph(Value : TBitmap);
|
||||
procedure SetNumGlyphs(Value : TNumGlyphs);
|
||||
protected
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
|
||||
function Draw(Canvas: TCanvas; const Client: TRect; const Offset: TPoint;
|
||||
const Caption: string; Layout: TButtonLayout; Margin, Spacing: Integer;
|
||||
State: TButtonState; Transparent: Boolean; BiDiFlags: Longint): TRect;
|
||||
property Glyph : TBitmap read FOriginal write SetGlyph;
|
||||
property NumGlyphs : TNumGlyphs read FNumGlyphs write SetNumGlyphs;
|
||||
@ -155,51 +154,58 @@ type
|
||||
FGlyph: TButtonGlyph;
|
||||
FGroupIndex : Integer;
|
||||
FLayout: TButtonLayout;
|
||||
FMargin : Integer;
|
||||
FMargin : integer;
|
||||
FMouseInControl : Boolean;
|
||||
FSpacing : Integer;
|
||||
FSpacing : integer;
|
||||
FState : TButtonState;
|
||||
FTransparent : Boolean;
|
||||
Function GetGlyph : TBitmap;
|
||||
Procedure UpdateExclusive;
|
||||
Procedure UpdateTracking;
|
||||
Procedure SetAllowAllUp(Value : Boolean);
|
||||
Procedure SetGlyph(value : TBitmap);
|
||||
//there should be a procedure called settransparent but it's not used at this point
|
||||
Procedure CMButtonPressed(var MEssage : TLMessage); message CM_BUTTONPRESSED;
|
||||
Procedure CMMouseEnter(var Message :TLMessage); message CM_MouseEnter;
|
||||
Procedure CMMouseLeave(var Message :TLMessage); message CM_MouseLeave;
|
||||
Procedure CMEnabledChanged(var Message: TLMessage); message CM_ENABLEDCHANGED;
|
||||
function GetGlyph : TBitmap;
|
||||
procedure UpdateExclusive;
|
||||
procedure UpdateTracking;
|
||||
procedure SetAllowAllUp(Value : Boolean);
|
||||
procedure SetGlyph(value : TBitmap);
|
||||
procedure SetLayout(const Value : TButtonLayout);
|
||||
procedure SetTransparent(const Value : boolean);
|
||||
procedure CMButtonPressed(var MEssage : TLMessage); message CM_BUTTONPRESSED;
|
||||
procedure CMMouseEnter(var Message :TLMessage); message CM_MouseEnter;
|
||||
procedure CMMouseLeave(var Message :TLMessage); message CM_MouseLeave;
|
||||
procedure CMEnabledChanged(var Message: TLMessage); message CM_ENABLEDCHANGED;
|
||||
protected
|
||||
function GetNumGlyphs : Integer;
|
||||
Procedure GlyphChanged(Sender : TObject);
|
||||
procedure GlyphChanged(Sender : TObject);
|
||||
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
|
||||
X, Y: Integer); override;
|
||||
X, Y: Integer); override;
|
||||
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
|
||||
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
|
||||
X, Y: Integer); override;
|
||||
Procedure Paint; override;
|
||||
X, Y: Integer); override;
|
||||
procedure Paint; override;
|
||||
procedure SetDown(Value : Boolean);
|
||||
procedure SetGroupIndex(Value : Integer);
|
||||
procedure SetFlat(Value : Boolean);
|
||||
procedure SetNumGlyphs(Value : Integer);
|
||||
procedure SetGroupIndex(const Value : Integer);
|
||||
procedure SetFlat(const Value : Boolean);
|
||||
procedure SetMargin(const Value : integer);
|
||||
procedure SetNumGlyphs(Value : integer);
|
||||
procedure SetSpacing(const Value : integer);
|
||||
property MouseInControl : Boolean read FMOuseInControl;
|
||||
public
|
||||
constructor Create(AOwner : TComponent); override;
|
||||
destructor Destroy; override;
|
||||
procedure Click; override;
|
||||
property Down : Boolean read FDown write SetDown default false;
|
||||
property GroupIndex : Integer read FGroupIndex write SetGroupIndex default 0;
|
||||
property Flat : Boolean read FFlat write SetFlat default false;
|
||||
property NumGlyphs : Integer read GetNumGlyphs write SetNumGlyphs default 1;
|
||||
published
|
||||
property AllowAllUp : Boolean read FAllowAllUp write SetAllowAllUp default false;
|
||||
property Caption;
|
||||
property Down : Boolean read FDown write SetDown default false;
|
||||
property Enabled;
|
||||
property Flat : Boolean read FFlat write SetFlat default false;
|
||||
property Glyph : TBitmap read GetGlyph write SetGlyph;
|
||||
property Transparent : Boolean read FTransparent write FTransparent default false;
|
||||
property GroupIndex : Integer read FGroupIndex write SetGroupIndex default 0;
|
||||
property Layout : TButtonLayout read FLayout write SetLayout default blGlyphLeft;
|
||||
property Margin : integer read FMargin write SetMargin default -1;
|
||||
property NumGlyphs : Integer read GetNumGlyphs write SetNumGlyphs default 1;
|
||||
property Spacing : integer read FSpacing write SetSpacing default 4;
|
||||
property Transparent : Boolean read FTransparent write SetTransparent default false;
|
||||
property Visible;
|
||||
property OnClick;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
{$I defaultbitbtnimages.inc}
|
||||
@ -237,6 +243,11 @@ end.
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.13 2002/02/24 20:51:23 lazarus
|
||||
Improved TSpeedButton (Glyph, Spacing, Margin, drawing)
|
||||
Added PageCount to TNotebook
|
||||
Optimized component selection buttons a bit.
|
||||
|
||||
Revision 1.12 2002/02/06 08:58:29 lazarus
|
||||
MG: fixed compiler warnings and asking to create non existing files
|
||||
|
||||
|
@ -121,6 +121,7 @@ type
|
||||
Procedure CNNotify(var Message : TLMNotify); message CN_NOTIFY;
|
||||
function GetActivePage: String;
|
||||
function GetPage(aIndex: Integer): TPage;
|
||||
function GetPageCount : integer;
|
||||
function GetPageIndex: Integer;
|
||||
//function InternalSetMultiLine(Value: boolean): boolean;
|
||||
procedure SetActivePage(const Value: String);
|
||||
@ -141,6 +142,7 @@ type
|
||||
property ActivePage: String read GetActivePage write SetActivePage;
|
||||
//property MultiLine: boolean read fMultiLine write SetMultiLine default false;
|
||||
property Page[Index: Integer]: TPage read GetPage;
|
||||
property PageCount : integer read GetPageCount;
|
||||
property PageIndex: Integer read GetPageIndex write SetPageIndex default 0;
|
||||
property PageList: TList read fPageList;
|
||||
property Pages: TStrings read fAccess write SetPages;
|
||||
@ -163,6 +165,7 @@ type
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
property Page;
|
||||
property PageCount;
|
||||
property Pages;
|
||||
published
|
||||
property ActivePage;
|
||||
@ -432,6 +435,11 @@ end.
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.18 2002/02/24 20:51:23 lazarus
|
||||
Improved TSpeedButton (Glyph, Spacing, Margin, drawing)
|
||||
Added PageCount to TNotebook
|
||||
Optimized component selection buttons a bit.
|
||||
|
||||
Revision 1.17 2002/02/03 00:24:00 lazarus
|
||||
TPanel implemented.
|
||||
Basic graphic primitives split into GraphType package, so that we can
|
||||
|
@ -19,21 +19,28 @@ end;
|
||||
{------------------------------------------------------------------------------}
|
||||
{ TButtonGlyph SetGlyph }
|
||||
{------------------------------------------------------------------------------}
|
||||
Procedure TButtonGlyph.SetGlyph(Value : TBitmap);
|
||||
Begin
|
||||
procedure TButtonGlyph.SetGlyph(Value : TBitmap);
|
||||
var GlyphCount : integer;
|
||||
begin
|
||||
if FOriginal = Value then exit;
|
||||
//Invalidate;
|
||||
// FOriginal.Assign(Value);
|
||||
FOriginal.Free;
|
||||
FOriginal := Value;
|
||||
//FOriginal.Assign(Value);
|
||||
FOriginal:= Value;
|
||||
if (Value <> nil) and (Value.Height > 0) then begin
|
||||
if Value.Width mod Value.Height = 0 then begin
|
||||
GlyphCount:= Value.Width div Value.Height;
|
||||
if GlyphCount > 4 then GlyphCount:= 1;
|
||||
NumGlyphs:= GlyphCount;
|
||||
end;
|
||||
end;
|
||||
//Invalidate;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------}
|
||||
{ TButtonGlyph Draw }
|
||||
{------------------------------------------------------------------------------}
|
||||
Function TButtonGlyph.Draw(Canvas: TCanvas; const Client: TRect;
|
||||
const Offset: TPoint; const Caption: string; Layout: TButtonLayout;
|
||||
Margin, Spacing: Integer; State: TButtonState; Transparent: Boolean;
|
||||
const Offset: TPoint; State: TButtonState; Transparent: Boolean;
|
||||
BiDiFlags: Longint): TRect;
|
||||
var
|
||||
gWidth : integer;
|
||||
@ -41,6 +48,9 @@ var
|
||||
DestRect: TRect;
|
||||
ImgID: integer;
|
||||
begin
|
||||
if FOriginal = nil then Exit;
|
||||
if (FOriginal.Width = 0) or (FOriginal.Height = 0) then Exit;
|
||||
|
||||
gWidth := TPixMap(FOriginal).Width;
|
||||
gHeight := TPixMap(FOriginal).Height;
|
||||
if NumGlyphs > 1 then
|
||||
@ -68,13 +78,10 @@ end;
|
||||
{------------------------------------------------------------------------------}
|
||||
{ TButtonGlyph SetNumGlyphs }
|
||||
{------------------------------------------------------------------------------}
|
||||
Procedure TButtonGlyph.SetNumGlyphs(Value : TNumGlyphs);
|
||||
Begin
|
||||
if Value <> FNumGlyphs then
|
||||
Begin
|
||||
FNumGlyphs := Value;
|
||||
if Assigned(FOnChange) then FOnChange(Glyph);
|
||||
end;
|
||||
|
||||
procedure TButtonGlyph.SetNumGlyphs(Value : TNumGlyphs);
|
||||
begin
|
||||
if Value <> FNumGlyphs then begin
|
||||
FNumGlyphs := Value;
|
||||
if Assigned(FOnChange) then FOnChange(Glyph);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -348,6 +348,15 @@ begin
|
||||
Result := fPageIndex;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
TCustomNotebook GetPageCount
|
||||
------------------------------------------------------------------------------}
|
||||
function TCustomNotebook.GetPageCount: Integer;
|
||||
begin
|
||||
Result := fPageList.Count;
|
||||
end;
|
||||
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
TCustomNotebook SetPages
|
||||
------------------------------------------------------------------------------}
|
||||
@ -526,6 +535,11 @@ end;}
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.13 2002/02/24 20:51:24 lazarus
|
||||
Improved TSpeedButton (Glyph, Spacing, Margin, drawing)
|
||||
Added PageCount to TNotebook
|
||||
Optimized component selection buttons a bit.
|
||||
|
||||
Revision 1.12 2002/01/01 15:50:14 lazarus
|
||||
MG: fixed initial component aligning
|
||||
|
||||
|
@ -28,6 +28,8 @@ begin
|
||||
|
||||
{set default alignment}
|
||||
Align := alNone;
|
||||
FLayout:= blGlyphLeft;
|
||||
FAllowAllUp:= false;
|
||||
FMouseInControl := False;
|
||||
FDragging := False;
|
||||
FSpacing := 4;
|
||||
@ -82,15 +84,14 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TSpeedButton.SetDown(Value : Boolean);
|
||||
begin
|
||||
if FDown <> value
|
||||
then begin
|
||||
if FGroupIndex = 0 then Value:= false;
|
||||
if FDown <> Value then begin
|
||||
if FDown and not FAllowAllUp then Exit;
|
||||
FDown := Value;
|
||||
if FDown
|
||||
then begin
|
||||
if FDown then begin
|
||||
if FState = bsUp then Invalidate;
|
||||
fState := bsExclusive;
|
||||
end
|
||||
else begin
|
||||
end else begin
|
||||
FState := bsUp;
|
||||
Repaint;
|
||||
end;
|
||||
@ -104,10 +105,12 @@ end;
|
||||
Returns: nothing
|
||||
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TSpeedButton.SetFlat(Value : Boolean);
|
||||
procedure TSpeedButton.SetFlat(const Value : boolean);
|
||||
begin
|
||||
FFlat := Value;
|
||||
Invalidate;
|
||||
if FFlat <> Value then begin
|
||||
FFlat := Value;
|
||||
Invalidate;
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -128,7 +131,7 @@ end;
|
||||
Returns: nothing
|
||||
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TSpeedButton.SetGroupIndex(Value : Integer);
|
||||
procedure TSpeedButton.SetGroupIndex(const Value : Integer);
|
||||
begin
|
||||
if FGroupIndex <> Value
|
||||
then begin
|
||||
@ -137,13 +140,27 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TSpeedButton.SetMargin
|
||||
Params: Value:
|
||||
Returns: nothing
|
||||
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TSpeedButton.SetMargin(const Value : Integer);
|
||||
begin
|
||||
if FMargin <> Value then begin
|
||||
FMargin := Value;
|
||||
Invalidate;
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TSpeedButton.SetNumGlyphs
|
||||
Params: Value : Integer = Number of glyphs in the file/resource
|
||||
Returns: nothing
|
||||
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TSpeedButton.SetNumGlyphs(Value : Integer);
|
||||
procedure TSpeedButton.SetNumGlyphs(Value : integer);
|
||||
Begin
|
||||
if Value < 0 then Value := 1;
|
||||
if Value > 4 then Value := 4;
|
||||
@ -155,6 +172,19 @@ Begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TSpeedButton.SetSpacing
|
||||
Params: Value:
|
||||
Returns: nothing
|
||||
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TSpeedButton.SetSpacing(const Value : Integer);
|
||||
begin
|
||||
if FSpacing <> Value then begin
|
||||
FSpacing := Value;
|
||||
Invalidate;
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TSpeedButton.UpdateExclusive
|
||||
@ -219,23 +249,21 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TSpeedbutton.Paint;
|
||||
const
|
||||
// DownStyles: array[Boolean] of Integer = (BDR_RAISEDINNER, BDR_SUNKENOUTER);
|
||||
DownStyles: array[Boolean] of Integer = (BDR_RAISEDINNER, BDR_SUNKENINNER);
|
||||
FillStyles: array[Boolean] of Integer = (BF_MIDDLE, 0);
|
||||
var
|
||||
PaintRect: TRect;
|
||||
DrawFlags, GlyphWidth, GlyphHeight: Integer;
|
||||
//R : TRect;
|
||||
Offset: TPoint;
|
||||
Offset, OffsetCap: TPoint;
|
||||
ClientSize, TotalSize, TextSize: TSize;
|
||||
BrushStyle : TBrushStyle;
|
||||
M, S : integer;
|
||||
|
||||
begin
|
||||
if not Enabled
|
||||
then begin
|
||||
if not Enabled then begin
|
||||
FState := bsDisabled;
|
||||
FDragging := False;
|
||||
end
|
||||
// else
|
||||
// if not Visible then exit
|
||||
else begin
|
||||
end else begin
|
||||
if FState = bsDisabled
|
||||
then begin
|
||||
if FDown and (GroupIndex <> 0)
|
||||
@ -248,64 +276,126 @@ begin
|
||||
PaintRect := Bounds(Left, Top, Width, Height);
|
||||
// PaintRect := Rect(0, 0, Width, Height);
|
||||
|
||||
if not FFlat then
|
||||
begin
|
||||
if Transparent and not (csDesigning in ComponentState) then
|
||||
BrushStyle:= bsClear
|
||||
else
|
||||
BrushStyle:= bsSolid;
|
||||
|
||||
Canvas.Brush.Color:= clBtnFace;
|
||||
Canvas.FillRect(PaintRect);
|
||||
|
||||
if FFlat then begin
|
||||
if (FState in [bsDown, bsExclusive])
|
||||
or (FMouseInControl and (FState <> bsDisabled))
|
||||
or (csDesigning in ComponentState)
|
||||
then begin
|
||||
DrawEdge(Canvas.Handle, PaintRect,
|
||||
DOWNSTYLES[FState in [bsDown, bsExclusive]],
|
||||
FILLSTYLES[Transparent] or BF_RECT)
|
||||
end;
|
||||
InflateRect(PaintRect, -1, -1);
|
||||
end else begin
|
||||
DrawFlags := DFCS_BUTTONPUSH or DFCS_ADJUSTRECT;
|
||||
if FState in [bsDown, bsExclusive]
|
||||
then DrawFlags := DrawFlags or DFCS_PUSHED;
|
||||
DrawFrameControl(Canvas.Handle, PaintRect, DFC_BUTTON, DrawFlags);
|
||||
end
|
||||
else begin //flat
|
||||
if (FState in [bsDown, bsExclusive])
|
||||
or (FMouseInControl and (FState <> bsDisabled))
|
||||
or (csDesigning in ComponentState)
|
||||
then begin
|
||||
Canvas.Brush.Color := clbtnface;//color;
|
||||
// Fillrect doesnt paint the outer right and bottom border
|
||||
Canvas.FillRect(PaintRect);
|
||||
DrawEdge(Canvas.Handle, PaintRect,
|
||||
DOWNSTYLES[FState in [bsDown, bsExclusive]],
|
||||
FILLSTYLES[Transparent] or BF_RECT)
|
||||
end else
|
||||
if not Transparent
|
||||
then begin
|
||||
Canvas.Brush.Color := clbtnface;//color;
|
||||
// Fillrect doesnt paint the outer right and bottom border
|
||||
Canvas.FillRect(PaintRect);
|
||||
end;
|
||||
InflateRect(PaintRect, -1, -1);
|
||||
end;
|
||||
|
||||
if FState in [bsDown, bsExclusive] then begin
|
||||
if (FState = bsExclusive)
|
||||
and (not FFlat or not FMouseInControl)
|
||||
if (FState = bsExclusive) and (not FFlat or not FMouseInControl)
|
||||
then begin
|
||||
//this needs to be done yet.
|
||||
Assert(False,'Trace:TODO: ALLOCPATTERNBITMAP');
|
||||
// Canvas.Brush.Bitmap := AllocPatternBitmap(clBtnFace, clBtnHighlight);
|
||||
Canvas.Brush.Color:= clBtnHighlight;
|
||||
Canvas.FillRect(PaintRect);
|
||||
end;
|
||||
Offset.X := 1;
|
||||
Offset.Y := 1;
|
||||
end
|
||||
else begin
|
||||
Offset.X := 0;
|
||||
Offset.Y := 0;
|
||||
end;
|
||||
|
||||
|
||||
GlyphWidth:=TButtonGlyph(FGlyph).Glyph.Width;
|
||||
if TButtonGlyph(FGlyph).NumGlyphs>1 then
|
||||
GlyphWidth:= TButtonGlyph(FGlyph).Glyph.Width;
|
||||
if TButtonGlyph(FGlyph).NumGlyphs > 1 then
|
||||
GlyphWidth:=GlyphWidth div NumGlyphs;
|
||||
GlyphHeight:=TButtonGlyph(FGlyph).Glyph.Height;
|
||||
|
||||
inc(Offset.X,(PaintRect.Right-PaintRect.Left-GlyphWidth) div 2);
|
||||
inc(Offset.Y,(PaintRect.Bottom-PaintRect.Top-GlyphHeight) div 2);
|
||||
ClientSize.cx:= PaintRect.Right - PaintRect.Left;
|
||||
ClientSize.cy:= PaintRect.Bottom - PaintRect.Top;
|
||||
|
||||
if Caption <> '' then
|
||||
TextSize:= Canvas.TextExtent(Caption)
|
||||
else begin
|
||||
TextSize.cx:= 0;
|
||||
TextSize.cy:= 0;
|
||||
end;
|
||||
|
||||
if (GlyphWidth = 0) or (GlyphHeight = 0) or (TextSize.cx = 0) or (TextSize.cy = 0) then
|
||||
S:= 0
|
||||
else
|
||||
S:= Spacing;
|
||||
|
||||
{ Calculate caption and glyph layout }
|
||||
|
||||
if Margin = -1 then begin
|
||||
if S = -1 then begin
|
||||
TotalSize.cx:= TextSize.cx + GlyphWidth;
|
||||
TotalSize.cy:= TextSize.cy + GlyphHeight;
|
||||
if Layout in [blGlyphLeft, blGlyphRight] then
|
||||
M:= (ClientSize.cx - TotalSize.cx) div 3
|
||||
else
|
||||
M:= (ClientSize.cy - TotalSize.cy) div 3;
|
||||
S:= M;
|
||||
end else begin
|
||||
TotalSize.cx:= GlyphWidth + S + TextSize.cx;
|
||||
TotalSize.cy:= GlyphHeight + S + TextSize.cy;
|
||||
if Layout in [blGlyphLeft, blGlyphRight] then
|
||||
M:= (ClientSize.cx - TotalSize.cx + 1) div 2
|
||||
else
|
||||
M:= (ClientSize.cy - TotalSize.cy + 1) div 2
|
||||
end;
|
||||
end else begin
|
||||
if S = -1 then begin
|
||||
TotalSize.cx:= ClientSize.cx - (Margin + GlyphWidth);
|
||||
TotalSize.cy:= ClientSize.cy - (Margin + GlyphHeight);
|
||||
if Layout in [blGlyphLeft, blGlyphRight] then
|
||||
S:= (TotalSize.cx - TextSize.cx) div 2
|
||||
else
|
||||
S:= (TotalSize.cy - TextSize.cy) div 2;
|
||||
end;
|
||||
M:= Margin
|
||||
end;
|
||||
|
||||
case Layout of
|
||||
blGlyphLeft : begin
|
||||
Offset.X:= M;
|
||||
Offset.Y:= (ClientSize.cy - GlyphHeight + 1) div 2;
|
||||
OffsetCap.X:= Offset.X + GlyphWidth + S;
|
||||
OffsetCap.Y:= (ClientSize.cy - TextSize.cy) div 2;
|
||||
end;
|
||||
blGlyphRight : begin
|
||||
Offset.X:= ClientSize.cx - M - GlyphWidth;
|
||||
Offset.Y:= (ClientSize.cy - GlyphHeight + 1) div 2;
|
||||
OffsetCap.X:= Offset.X - S - TextSize.cx;
|
||||
OffsetCap.Y:= (ClientSize.cy - TextSize.cy) div 2;
|
||||
end;
|
||||
blGlyphTop : begin
|
||||
Offset.X:= (ClientSize.cx - GlyphWidth + 1) div 2;
|
||||
Offset.Y:= M;
|
||||
OffsetCap.X:= (ClientSize.cx - TextSize.cx + 1) div 2;
|
||||
OffsetCap.Y:= Offset.Y + GlyphHeight + S;
|
||||
end;
|
||||
blGlyphBottom : begin
|
||||
Offset.X:= (ClientSize.cx - GlyphWidth + 1) div 2;
|
||||
Offset.Y:= ClientSize.cy - M - GlyphHeight;
|
||||
OffsetCap.X:= (ClientSize.cx - TextSize.cx + 1) div 2;
|
||||
OffsetCap.Y:= Offset.Y - S - TextSize.cy;
|
||||
end;
|
||||
end;
|
||||
|
||||
//this needs to be done yet.
|
||||
Assert(False,'Trace:TODO: DRAWTEXTBIDIMODEFLAGS');
|
||||
TButtonGlyph(FGlyph).Draw(Canvas, PaintRect, Offset, Caption, FLayout, FMargin,
|
||||
FSpacing, FState, Transparent, (0));
|
||||
//Assert(False,'Trace:TODO: DRAWTEXTBIDIMODEFLAGS');
|
||||
|
||||
FGlyph.Draw(Canvas, PaintRect, Offset, FState, Transparent, 0);
|
||||
if Caption <> '' then
|
||||
Canvas.TextOut(PaintRect.Left + OffsetCap.X, PaintRect.Top + OffsetCap.Y, Caption);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -443,6 +533,36 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TSpeedButton.SetLayout
|
||||
Params: Value: new layout value
|
||||
Returns: nothing
|
||||
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TSpeedButton.SetLayout(const Value : TButtonLayout);
|
||||
begin
|
||||
if Value <> FLayout then begin
|
||||
FLayout:= Value;
|
||||
Invalidate;
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TSpeedButton.SetTransparent
|
||||
Params: Value: new transparency value
|
||||
Returns: nothing
|
||||
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TSpeedButton.SetTransparent(const Value : boolean);
|
||||
begin
|
||||
if Value <> FTransparent then begin
|
||||
FTransparent:= Value;
|
||||
if Value then ControlStyle:= ControlStyle + [csOpaque]
|
||||
else ControlStyle:= ControlStyle - [csOpaque];
|
||||
Invalidate;
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TSpeedButton.CMButtonPressed
|
||||
Params: Message:
|
||||
@ -533,6 +653,11 @@ end;
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.12 2002/02/24 20:51:24 lazarus
|
||||
Improved TSpeedButton (Glyph, Spacing, Margin, drawing)
|
||||
Added PageCount to TNotebook
|
||||
Optimized component selection buttons a bit.
|
||||
|
||||
Revision 1.11 2001/11/22 14:33:26 lazarus
|
||||
MG: fixed painting background of flat speedbuttons
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user