ExCtrls: clean-up.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7482 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-06-15 21:52:31 +00:00
parent c3495b2a0b
commit 0797f6f315

View File

@ -72,37 +72,7 @@ type
property ColorFocusedFrom: TColor read FColorFocusedFrom write FColorFocusedFrom; property ColorFocusedFrom: TColor read FColorFocusedFrom write FColorFocusedFrom;
property ColorFocusedTo: TColor read FColorFocusedTo write FColorFocusedTo; property ColorFocusedTo: TColor read FColorFocusedTo write FColorFocusedTo;
end; end;
{
TButtonExPictures = class(TPersistent)
private
FButton: TButtonEx;
FAlignment: TLeftRight;
FTransparent: boolean;
FPictureNormal: TPicture;
FPictureHot: TPicture;
FPictureDown: TPicture;
FPictureDisabled: TPicture;
FPictureFocused: TPicture;
procedure SetPictureNormal(const Value: TPicture);
procedure SetPictureDisabled(const Value: TPicture);
procedure SetPictureDown(const Value: TPicture);
procedure SetPictureFocused(const Value: TPicture);
procedure SetPictureHot(const Value: TPicture);
procedure SetAlignment(const Value: TLeftRight);
procedure SetTransparent(const Value: boolean);
public
constructor Create(AButton: TButtonEx);
destructor Destroy; override;
published
property PictureNormal: TPicture read FPictureNormal write SetPictureNormal;
property PictureHot: TPicture read FPictureHot write SetPictureHot;
property PictureDown: TPicture read FPictureDown write SetPictureDown;
property PictureDisabled: TPicture read FPictureDisabled write SetPictureDisabled;
property PictureFocused: TPicture read FPictureFocused write SetPictureFocused;
property Alignment: TLeftRight read FAlignment write SetAlignment default taLeftJustify;
property Transparent: boolean read FTransparent write SetTransparent default False;
end;
}
TButtonEx = class(TCustomButton) TButtonEx = class(TCustomButton)
private private
FAlignment: TAlignment; FAlignment: TAlignment;
@ -123,7 +93,6 @@ type
procedure SetDefaultDrawing(const Value: Boolean); procedure SetDefaultDrawing(const Value: Boolean);
procedure SetGradient(const Value: Boolean); procedure SetGradient(const Value: Boolean);
procedure SetShowFocusRect(const Value: Boolean); procedure SetShowFocusRect(const Value: Boolean);
// procedure SetSpacing(const Value: integer);
procedure SetMargin(const Value: integer); procedure SetMargin(const Value: integer);
procedure SetWordWrap(const Value: Boolean); procedure SetWordWrap(const Value: Boolean);
protected protected
@ -142,7 +111,6 @@ type
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
//procedure Click; override;
published published
property Align; property Align;
property Anchors; property Anchors;
@ -154,7 +122,7 @@ type
property Constraints; property Constraints;
property Cursor; property Cursor;
property Default; property Default;
// property DoubleBuffered; // PaintButton is not called when this is set. //property DoubleBuffered; // PaintButton is not called when this is set.
property DragCursor; property DragCursor;
property DragKind; property DragKind;
property DragMode; property DragMode;
@ -168,7 +136,7 @@ type
property Left; property Left;
property ModalResult; property ModalResult;
property ParentBiDiMode; property ParentBiDiMode;
// property ParentDoubleBuffered; //property ParentDoubleBuffered;
property ParentFont; property ParentFont;
property ParentShowHint; property ParentShowHint;
property PopupMenu; property PopupMenu;
@ -269,74 +237,6 @@ begin
end; end;
(*
{ TButtonExPictures }
constructor TButtonExPictures.Create(AButton: TButtonEx);
begin
inherited Create;
FButton := AButton;
FAlignment := taLeftJustify;
FTransparent := False;
FPictureNormal := TPicture.Create;
FPictureHot := TPicture.Create;
FPictureDown := TPicture.Create;
FPictureDisabled := TPicture.Create;
FPictureFocused := TPicture.Create;
end;
destructor TButtonExPictures.Destroy;
begin
FPictureNormal.Free;
FPictureHot.Free;
FPictureDown.Free;
FPictureDisabled.Free;
FPictureFocused.Free;
inherited;
end;
procedure TButtonExPictures.SetAlignment(const Value: TLeftRight);
begin
if FAlignment = Value then
exit;
FAlignment := Value;
FButton.Invalidate;
end;
procedure TButtonExPictures.SetPictureDisabled(const Value: TPicture);
begin
FPictureDisabled.Assign(Value);
end;
procedure TButtonExPictures.SetPictureDown(const Value: TPicture);
begin
FPictureDown.Assign(Value);
end;
procedure TButtonExPictures.SetPictureFocused(const Value: TPicture);
begin
FPictureFocused.Assign(Value);
end;
procedure TButtonExPictures.SetPictureHot(const Value: TPicture);
begin
FPictureHot.Assign(Value);
end;
procedure TButtonExPictures.SetPictureNormal(const Value: TPicture);
begin
FPictureNormal.Assign(Value);
FButton.Invalidate;
end;
procedure TButtonExPictures.SetTransparent(const Value: boolean);
begin
FTransparent := Value;
FButton.Invalidate;
end;
*)
{ TButtonEx } { TButtonEx }
constructor TButtonEx.Create(AOwner: TComponent); constructor TButtonEx.Create(AOwner: TComponent);
@ -350,11 +250,8 @@ begin
FGradient := true; FGradient := true;
FShowFocusRect := true; FShowFocusRect := true;
FBorder := TButtonExBorder.Create(Self); // Background colors
FColors := TButtonExColors.Create(Self); FColors := TButtonExColors.Create(Self);
//FPictures := TButtonExPictures.Create(Self);
// Button
FColors.ColorNormalFrom := $00FCFCFC; FColors.ColorNormalFrom := $00FCFCFC;
FColors.ColorNormalTo := $00CFCFCF; FColors.ColorNormalTo := $00CFCFCF;
FColors.ColorHotFrom := $00FCFCFC; FColors.ColorHotFrom := $00FCFCFC;
@ -382,6 +279,7 @@ begin
FFontHot.OnChange := @FontChanged; FFontHot.OnChange := @FontChanged;
// Border // Border
FBorder := TButtonExBorder.Create(Self);
FBorder.ColorNormal := $00707070; FBorder.ColorNormal := $00707070;
FBorder.ColorHot := $00B17F3C; FBorder.ColorHot := $00B17F3C;
FBorder.ColorDown := $008B622C; FBorder.ColorDown := $008B622C;
@ -394,16 +292,9 @@ begin
FBorder.WidthFocused := 1; FBorder.WidthFocused := 1;
// Other // Other
// FSpacing := 5;
FMargin := 5; FMargin := 5;
FAlignment := taCenter; FAlignment := taCenter;
FState := bxsNormal; FState := bxsNormal;
// TabStop := True;
// FModalResult := 0;
// FCancel := False;
// FDefault := False;
// Width := 85;
// Height := 30;
end; end;
destructor TButtonEx.Destroy; destructor TButtonEx.Destroy;
@ -412,7 +303,6 @@ begin
FFontDown.Free; FFontDown.Free;
FFontDisabled.Free; FFontDisabled.Free;
FFontFocused.Free; FFontFocused.Free;
//FPictures.Free;
FColors.Free; FColors.Free;
FBorder.Free; FBorder.Free;
FCanvas.Free; FCanvas.Free;
@ -454,36 +344,8 @@ begin
if not FWordWrap then if not FWordWrap then
PreferredHeight := 0; PreferredHeight := 0;
{
if FWordWrap then //and AutoSize then
begin
PreferredWidth := 0 ;
PreferredHeight := txtSize.CY + 2*FMargin;
end else
begin
PreferredWidth := txtSize.CX + 2 * FMargin;
PreferredHeight := 0;
end;
}
end; end;
(*
procedure TButtonEx.Click;
var
Form: TCustomForm;
begin
Form := GetParentForm(Self);
if Form <> nil then
Form.ModalResult := FModalResult;
inherited;
end;
procedure TButtonEx.FontChanged(Sender: TObject);
begin
Invalidate;
end;
*)
class function TButtonEx.GetControlClassDefaultSize: TSize; class function TButtonEx.GetControlClassDefaultSize: TSize;
begin begin
Result.CX := 75; Result.CX := 75;
@ -492,7 +354,7 @@ end;
function TButtonEx.GetDrawTextFlags: Cardinal; function TButtonEx.GetDrawTextFlags: Cardinal;
begin begin
Result := DT_VCENTER; Result := DT_VCENTER or DT_NOPREFIX;
case FAlignment of case FAlignment of
taLeftJustify: taLeftJustify:
if IsRightToLeft then Result := Result or DT_RIGHT else Result := Result or DT_LEFT; if IsRightToLeft then Result := Result or DT_RIGHT else Result := Result or DT_LEFT;
@ -605,6 +467,7 @@ var
lColorFrom: TColor; lColorFrom: TColor;
lColorTo: TColor; lColorTo: TColor;
lTextFont: TFont; lTextFont: TFont;
lAlignment: TAlignment;
flags: Cardinal; flags: Cardinal;
i: integer; i: integer;
txtSize: TSize; txtSize: TSize;
@ -625,7 +488,6 @@ begin
lColorTo := Colors.ColorNormalTo; lColorTo := Colors.ColorNormalTo;
lTextFont := Font; lTextFont := Font;
lBorderWidth := Border.WidthNormal; lBorderWidth := Border.WidthNormal;
//lPicture := FPictures.PictureNormal;
if not (csDesigning in ComponentState) then if not (csDesigning in ComponentState) then
begin begin
@ -637,10 +499,6 @@ begin
lColorTo := FColors.ColorFocusedTo; lColorTo := FColors.ColorFocusedTo;
lTextFont := FFontFocused; lTextFont := FFontFocused;
lBorderWidth := FBorder.WidthFocused; lBorderWidth := FBorder.WidthFocused;
{
if FPictures.PictureFocused.Graphic <> nil then
lPicture := FPictures.PictureFocused;
}
end; end;
bxsHot: bxsHot:
begin begin
@ -649,10 +507,6 @@ begin
lColorTo := FColors.ColorHotTo; lColorTo := FColors.ColorHotTo;
lTextFont := FFontHot; lTextFont := FFontHot;
lBorderWidth := FBorder.WidthHot; lBorderWidth := FBorder.WidthHot;
{
if FPictures.PictureHot.Graphic <> nil then
lPicture := FPictures.PictureHot;
}
end; end;
bxsDown: bxsDown:
begin begin
@ -661,10 +515,6 @@ begin
lColorTo := FColors.ColorDownTo; lColorTo := FColors.ColorDownTo;
lTextFont := FFontDown; lTextFont := FFontDown;
lBorderWidth := FBorder.WidthDown; lBorderWidth := FBorder.WidthDown;
{
if FPictures.PictureDown.Graphic <> nil then
lPicture := FPictures.PictureDown;
}
end; end;
bxsDisabled: bxsDisabled:
begin begin
@ -673,10 +523,6 @@ begin
lColorTo := FColors.ColorDisabledTo; lColorTo := FColors.ColorDisabledTo;
lTextFont := FFontDisabled; lTextFont := FFontDisabled;
lBorderWidth := FBorder.WidthDisabled; lBorderWidth := FBorder.WidthDisabled;
{
if FPictures.PictureDisabled.Graphic <> nil then
lPicture := FPictures.PictureDisabled;
}
end; end;
end; end;
end; end;
@ -684,8 +530,8 @@ begin
// Background // Background
lRect.Left := 0; lRect.Left := 0;
lRect.Right := Width; lRect.Right := Width;
lRect.Top := 0; //lBorderWidth; lRect.Top := 0;
lRect.Bottom := Height; // - lBorderWidth; lRect.Bottom := Height;
if FGradient then if FGradient then
lCanvas.GradientFill(lRect, lColorFrom, lColorTo, gdVertical) lCanvas.GradientFill(lRect, lColorFrom, lColorTo, gdVertical)
@ -696,20 +542,6 @@ begin
lCanvas.FillRect(lRect); lCanvas.FillRect(lRect);
end; end;
{
// Image
lPicLeft := 0;
if lPicture.Graphic <> nil then
begin
lPicture.Graphic.Transparent := FPictures.Transparent;
case FPictures.Alignment of
taLeftJustify : lPicLeft := Border.WidthNormal + FMargin;
taRightJustify: lPicLeft := Width - Border.WidthNormal - FMargin - lPicture.Graphic.Width;
end;
lPicTop := (Height - lPicture.Height) div 2;
lCanvas.Draw(lPicLeft, lPicTop, lPicture.Graphic);
end;
}
// Border // Border
lCanvas.Pen.Width := 1; lCanvas.Pen.Width := 1;
lCanvas.Pen.Color := lBorderColor; lCanvas.Pen.Color := lBorderColor;
@ -722,19 +554,7 @@ begin
lCanvas.LineTo(i - 1, i - 1); lCanvas.LineTo(i - 1, i - 1);
end; end;
(* // Caption
// Corner
lCanvas.Pixels[0, 0] := Color;
lCanvas.Pixels[lBorderWidth, lBorderWidth] := lBorderColor;
lCanvas.Pixels[Width - 1, 0] := Color;
lCanvas.Pixels[Width - 1 - lBorderWidth, lBorderWidth] := lBorderColor;
lCanvas.Pixels[0, Height - 1] := Color;
lCanvas.Pixels[lBorderWidth, Height - 1 - lBorderWidth] := lBorderColor;
lCanvas.Pixels[Width - 1, Height - 1] := Color;
lCanvas.Pixels[Width - 1 - lBorderWidth, Height - 1 - lBorderWidth] := lBorderColor;
*)
// Text
lCanvas.Pen.Width := 1; lCanvas.Pen.Width := 1;
lCanvas.Brush.Style := bsClear; lCanvas.Brush.Style := bsClear;
lCanvas.Font.Assign(lTextFont); lCanvas.Font.Assign(lTextFont);
@ -745,53 +565,30 @@ begin
txtSize.CX := R.Right - R.Left; txtSize.CX := R.Right - R.Left;
txtSize.CY := R.Bottom - R.Top; txtSize.CY := R.Bottom - R.Top;
case FAlignment of lAlignment := FAlignment;
if IsRightToLeft then begin
if lAlignment = taLeftJustify then
lAlignment := taRightJustify
else if lAlignment = taRightJustify then
lAlignment := taLeftJustify;
end;
case lAlignment of
taLeftJustify: taLeftJustify:
if IsRightToLeft then txtPt.X := FMargin;
txtPt.X := Width - txtSize.CX - FMargin
else
txtPt.X := FMargin;
taRightJustify: taRightJustify:
if IsRightToLeft then txtPt.X := Width - txtSize.CX - FMargin;
txtPt.X := FMargin
else
txtPt.X := Width - txtSize.CX - FMargin;
taCenter: taCenter:
txtPt.X := (Width - txtSize.CX) div 2; txtPt.X := (Width - txtSize.CX) div 2;
end; end;
txtPt.Y := (Height - txtSize.CY + 1) div 2; txtPt.Y := (Height - txtSize.CY + 1) div 2;
R := Rect(txtPt.X, txtPt.Y, txtPt.X + txtSize.CX, txtPt.Y + txtSize.CY); R := Rect(txtPt.X, txtPt.Y, txtPt.X + txtSize.CX, txtPt.Y + txtSize.CY);
(* DrawText(lCanvas.Handle, PChar(Caption), -1, R, flags);
case FAlignment of
taLeftJustify:
begin
lRect.Left := lRect.Left + FBorder.WidthNormal + FMargin;
lAlignment := DT_LEFT;
end;
taRightJustify:
begin
lRect.Right := lRect.Right - FBorder.WidthNormal - FMargin;
lAlignment := DT_RIGHT;
end;
else
lAlignment := DT_CENTER;
end;
*)
{
if (lPicture.Graphic <> nil) and (Alignment <> taCenter) then
begin
case FPictures.Alignment of
taLeftJustify: lRect.Left := lPicLeft + lPicture.Graphic.Width + FSpacing;
taRightJustify: lRect.Right := lPicLeft - FSpacing;
end;
end;
}
DrawText(lCanvas.Handle, PChar(Caption), -1, R, flags); //lAlignment or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE);
// Draw focus rectangle // Draw focus rectangle
if FShowFocusRect and Focused then if FShowFocusRect and Focused then
begin begin
InflateRect(lRect, -3, -2); InflateRect(lRect, -2, -2);
DrawFocusRect(lCanvas.Handle, lRect); DrawFocusRect(lCanvas.Handle, lRect);
end; end;
@ -841,22 +638,11 @@ begin
Invalidate; Invalidate;
end; end;
{
procedure TButtonEx.SetSpacing(const Value: integer);
begin
if FSpacing = Value then
exit;
FSpacing := Value;
Invalidate;
end;
}
procedure TButtonEx.SetWordWrap(const Value: Boolean); procedure TButtonEx.SetWordWrap(const Value: Boolean);
begin begin
if FWordWrap = Value then if FWordWrap = Value then
exit; exit;
FWordWrap := Value; FWordWrap := Value;
//if AutoSize then AdjustSize;
Invalidate; Invalidate;
end; end;
@ -891,118 +677,51 @@ end;
procedure TButtonEx.WndProc(var Message: TLMessage); procedure TButtonEx.WndProc(var Message: TLMessage);
begin begin
{
if Message.Msg = LM_PAINT then
PaintButton;
if Message.Msg = CM_TEXTCHANGED then
PaintButton;
if Message.Msg = CM_COLORCHANGED then
PaintButton;
if Message.Msg = CM_BORDERCHANGED then
PaintButton;
if Message.Msg = LM_ERASEBKGND then
Exit;
}
if not (csDesigning in ComponentState) then if not (csDesigning in ComponentState) then
begin begin
case Message.Msg of case Message.Msg of
LM_KEYDOWN: LM_KEYDOWN:
begin begin
if (Message.WParam = VK_RETURN) or (Message.WParam = VK_SPACE) then if (Message.WParam = VK_RETURN) or (Message.WParam = VK_SPACE) then
if FState <> bxsDisabled then if FState <> bxsDisabled then
FState := bxsDown; FState := bxsDown;
Invalidate; Invalidate;
end; end;
LM_KEYUP: LM_KEYUP:
begin
if (Message.WParam = VK_RETURN) or (Message.WParam = VK_SPACE) then
if FState <> bxsDisabled then
FState := bxsFocused;
Invalidate;
end;
{
LM_CHAR:
begin
if (Message.WParam = VK_RETURN) or (Message.WParam = VK_SPACE) and (FState <> bxsDisabled) then
begin begin
Click; if (Message.WParam = VK_RETURN) or (Message.WParam = VK_SPACE) then
if FState <> bxsDisabled then
FState := bxsFocused;
Invalidate;
end;
CM_DIALOGKEY:
begin
if (Message.WParam = VK_RETURN) and Default and (not Focused) and (FState <> bxsDisabled) then
Click;
if (Message.WParam = VK_ESCAPE) and Cancel and (FState <> bxsDisabled) then
Click;
end; end;
end; CM_ENABLEDCHANGED:
CM_MOUSEENTER:
begin
FState := bxsHot;
PaintButton;
end;
CM_MOUSELEAVE:
begin
if (FState <> bxsDisabled) then
begin begin
if Focused then if not Enabled then
FState := bxsFocused FState := bxsDisabled
else else
FState := bxsNormal; FState := bxsNormal;
PaintButton;
end;
end;
}
CM_DIALOGKEY:
begin
if (Message.WParam = VK_RETURN) and Default and (not Focused) and (FState <> bxsDisabled) then
Click;
if (Message.WParam = VK_ESCAPE) and Cancel and (FState <> bxsDisabled) then
Click;
end;
{
CM_FOCUSCHANGED:
begin
if Focused and (FState = bxsNormal) then
FState := bxsFocused;
if (not Focused) and (FState = bxsFocused) then
FState := bxsNormal;
PaintButton;
end;
}
CM_ENABLEDCHANGED:
begin
if not Enabled then
FState := bxsDisabled
else
FState := bxsNormal;
Invalidate;
// PaintButton;
end;
LM_LBUTTONDOWN:
begin
FState := bxsDown;
Invalidate;
// PaintButton;
end;
LM_LBUTTONUP:
begin
if (FState <> bxsNormal) and (FState <> bxsFocused) and (FState <> bxsDisabled) then
begin
FState := bxsHot;
Invalidate; Invalidate;
//PaintButton;
end; end;
LM_LBUTTONDOWN:
begin
FState := bxsDown;
Invalidate;
end;
LM_LBUTTONUP:
begin
if (FState <> bxsNormal) and (FState <> bxsFocused) and (FState <> bxsDisabled) then
begin
FState := bxsHot;
Invalidate;
end;
end; end;
{
LM_LBUTTONDBLCLK:
begin
FState := bxsDown;
PaintButton;
Click;
end;
}
end; end;
end; end;