DateTimePicker: add Alignment property

git-svn-id: trunk@64155 -
This commit is contained in:
zoran 2020-11-22 22:33:59 +00:00
parent fbbe9f55c3
commit 7e68563f75

View File

@ -139,6 +139,7 @@ type
cDefOptions = []; cDefOptions = [];
cCheckBoxBorder = 3; cCheckBoxBorder = 3;
private private
FAlignment: TAlignment;
FAutoAdvance: Boolean; FAutoAdvance: Boolean;
FAutoButtonSize: Boolean; FAutoButtonSize: Boolean;
FCalAlignment: TDTCalAlignment; FCalAlignment: TDTCalAlignment;
@ -215,6 +216,7 @@ type
function GetDateTime: TDateTime; function GetDateTime: TDateTime;
function GetDroppedDown: Boolean; function GetDroppedDown: Boolean;
function GetTime: TTime; function GetTime: TTime;
procedure SetAlignment(AValue: TAlignment);
procedure SetArrowShape(const AValue: TArrowShape); procedure SetArrowShape(const AValue: TArrowShape);
procedure SetAutoButtonSize(AValue: Boolean); procedure SetAutoButtonSize(AValue: Boolean);
procedure SetCalAlignment(AValue: TDTCalAlignment); procedure SetCalAlignment(AValue: TDTCalAlignment);
@ -420,6 +422,7 @@ type
read FShowMonthNames write SetShowMonthNames default False; read FShowMonthNames write SetShowMonthNames default False;
property DroppedDown: Boolean read GetDroppedDown; property DroppedDown: Boolean read GetDroppedDown;
property CalAlignment: TDTCalAlignment read FCalAlignment write SetCalAlignment default dtaDefault; property CalAlignment: TDTCalAlignment read FCalAlignment write SetCalAlignment default dtaDefault;
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
property Options: TDateTimePickerOptions read FOptions write SetOptions default cDefOptions; property Options: TDateTimePickerOptions read FOptions write SetOptions default cDefOptions;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
@ -501,6 +504,7 @@ type
property MonthNames; property MonthNames;
property ShowMonthNames; property ShowMonthNames;
property CalAlignment; property CalAlignment;
property Alignment;
property Options; property Options;
// events: // events:
property OnChange; property OnChange;
@ -1938,11 +1942,13 @@ function TCustomDateTimePicker.GetCheckBoxRect(
var var
Details: TThemedElementDetails; Details: TThemedElementDetails;
CSize: TSize; CSize: TSize;
begin begin
Details := ThemeServices.GetElementDetails(tbCheckBoxCheckedNormal); Details := ThemeServices.GetElementDetails(tbCheckBoxCheckedNormal);
CSize := ThemeServices.GetDetailSize(Details); CSize := ThemeServices.GetDetailSize(Details);
CSize.cx := ScaleScreenToFont(CSize.cx); CSize.cx := ScaleScreenToFont(CSize.cx);
CSize.cy := ScaleScreenToFont(CSize.cy); CSize.cy := ScaleScreenToFont(CSize.cy);
if IsRightToLeft and not IgnoreRightToLeft then if IsRightToLeft and not IgnoreRightToLeft then
begin begin
Result.Right := ClientWidth - (BorderSpacing.InnerBorder + BorderWidth); Result.Right := ClientWidth - (BorderSpacing.InnerBorder + BorderWidth);
@ -1962,23 +1968,60 @@ end;
Also used in calculating our preffered size. } Also used in calculating our preffered size. }
function TCustomDateTimePicker.GetTextOrigin(IgnoreRightToLeft: Boolean function TCustomDateTimePicker.GetTextOrigin(IgnoreRightToLeft: Boolean
): TPoint; ): TPoint;
var
R: TRect; var
Re: TRect;
B: Integer;
XL, XR: Integer;
AuxAlignment: TAlignment;
begin begin
Result.y := BorderSpacing.InnerBorder + BorderWidth; B := BorderSpacing.InnerBorder + BorderWidth;
if FShowCheckBox then Result.y := B;
begin
R := GetCheckBoxRect(IgnoreRightToLeft); if IgnoreRightToLeft or AutoSize then
if not IgnoreRightToLeft and IsRightToLeft then AuxAlignment := taLeftJustify
Result.x := R.Left - Scale96ToFont(cCheckBoxBorder) - FTextWidth else begin
else AuxAlignment := FAlignment;
Result.x := R.Right + Scale96ToFont(cCheckBoxBorder); if IsRightToLeft then begin
end else case AuxAlignment of
begin taRightJustify:
Result.x := Result.y; AuxAlignment := taLeftJustify;
if not IgnoreRightToLeft and IsRightToLeft then taLeftJustify:
Result.x := ClientWidth - Result.x - FTextWidth; AuxAlignment := taRightJustify;
end;
end;
end; end;
if FShowCheckBox then begin
Re := GetCheckBoxRect(IgnoreRightToLeft);
InflateRect(Re, Scale96ToFont(cCheckBoxBorder), 0);
XL := Re.Right;
XR := Re.Left;
end else begin
XL := B;
XR := ClientWidth - B;
end;
if Assigned(FUpDown) then
B := B + FUpDown.Width
else if Assigned(FArrowButton) then
B := B + FArrowButton.Width;
if IgnoreRightToLeft or not IsRightToLeft then begin
XR := ClientWidth - B;
end else begin
XL := B;
end;
case AuxAlignment of
taRightJustify:
Result.x := XR - FTextWidth;
taCenter:
Result.x := (XL + XR - FTextWidth) div 2;
else
Result.x := XL;
end;
end; end;
{ MoveSelectionLR { MoveSelectionLR
@ -2137,19 +2180,12 @@ end;
procedure TCustomDateTimePicker.MouseDown(Button: TMouseButton; procedure TCustomDateTimePicker.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); Shift: TShiftState; X, Y: Integer);
var
R: TRect;
begin begin
if FTextEnabled then if ShowCheckBox and PtInRect(GetCheckBoxRect, Point(X, Y)) then
Checked := not Checked
else if FTextEnabled then
SelectTextPartUnderMouse(X); SelectTextPartUnderMouse(X);
if ShowCheckBox then
begin
R := GetCheckBoxRect;
if PtInRect(R, Point(X, Y)) then
begin
Checked := not Checked;
end;
end;
SetFocusIfPossible; SetFocusIfPossible;
inherited MouseDown(Button, Shift, X, Y); inherited MouseDown(Button, Shift, X, Y);
end; end;
@ -2165,20 +2201,14 @@ begin
end; end;
procedure TCustomDateTimePicker.MouseMove(Shift: TShiftState; X, Y: Integer); procedure TCustomDateTimePicker.MouseMove(Shift: TShiftState; X, Y: Integer);
var
NewMouseInCheckBox: Boolean;
begin begin
inherited MouseMove(Shift, X, Y); inherited MouseMove(Shift, X, Y);
if ShowCheckBox then if ShowCheckBox and (FMouseInCheckBox xor PtInRect(GetCheckBoxRect, Point(X, Y))) then begin
begin FMouseInCheckBox := not FMouseInCheckBox;
NewMouseInCheckBox := PtInRect(GetCheckBoxRect, Point(X, Y)); Invalidate;
if FMouseInCheckBox <> NewMouseInCheckBox then
begin
FMouseInCheckBox := NewMouseInCheckBox;
Invalidate;
end;
end; end;
end; end;
function TCustomDateTimePicker.DoMouseWheel(Shift: TShiftState; function TCustomDateTimePicker.DoMouseWheel(Shift: TShiftState;
@ -2186,6 +2216,7 @@ function TCustomDateTimePicker.DoMouseWheel(Shift: TShiftState;
begin begin
Result := False; Result := False;
if FTextEnabled then begin if FTextEnabled then begin
SelectTextPartUnderMouse(MousePos.x); SelectTextPartUnderMouse(MousePos.x);
if not FReadOnly then begin if not FReadOnly then begin
Inc(FUserChanging); Inc(FUserChanging);
@ -2935,12 +2966,14 @@ var
TextStyle: TTextStyle; TextStyle: TTextStyle;
DTP: TDateTimePart; DTP: TDateTimePart;
S: String; S: String;
const const
CheckStates: array[Boolean, Boolean, Boolean] of TThemedButton = ( CheckStates: array[Boolean, Boolean, Boolean] of TThemedButton = (
((tbCheckBoxUncheckedDisabled, tbCheckBoxUncheckedDisabled), ((tbCheckBoxUncheckedDisabled, tbCheckBoxUncheckedDisabled),
(tbCheckBoxCheckedDisabled, tbCheckBoxCheckedDisabled)), (tbCheckBoxCheckedDisabled, tbCheckBoxCheckedDisabled)),
((tbCheckBoxUncheckedNormal, tbCheckBoxUncheckedHot), ((tbCheckBoxUncheckedNormal, tbCheckBoxUncheckedHot),
(tbCheckBoxCheckedNormal, tbCheckBoxCheckedHot))); (tbCheckBoxCheckedNormal, tbCheckBoxCheckedHot)));
begin begin
if ClientRectNeedsInterfaceUpdate then // In Qt widgetset, this solves the if ClientRectNeedsInterfaceUpdate then // In Qt widgetset, this solves the
DoAdjustClientRectChange; // problem of dispositioned client rect. DoAdjustClientRectChange; // problem of dispositioned client rect.
@ -2971,11 +3004,6 @@ begin
TextStyle.Opaque := False; TextStyle.Opaque := False;
TextStyle.RightToLeft := IsRightToLeft; TextStyle.RightToLeft := IsRightToLeft;
if ShowCheckBox then
ThemeServices.DrawElement(Canvas.Handle,
ThemeServices.GetElementDetails(CheckStates[Enabled, Checked, FMouseInCheckBox]),
GetCheckBoxRect);
if DateIsNull and (FTextForNullDate <> '') if DateIsNull and (FTextForNullDate <> '')
and (not (FTextEnabled and Focused)) then begin and (not (FTextEnabled and Focused)) then begin
@ -3127,6 +3155,11 @@ begin
end; end;
if ShowCheckBox then
ThemeServices.DrawElement(Canvas.Handle,
ThemeServices.GetElementDetails(CheckStates[Enabled, Checked, FMouseInCheckBox]),
GetCheckBoxRect);
inherited Paint; inherited Paint;
end; end;
@ -3222,6 +3255,14 @@ begin
Result := Abs(Frac(FDateTime)); Result := Abs(Frac(FDateTime));
end; end;
procedure TCustomDateTimePicker.SetAlignment(AValue: TAlignment);
begin
if FAlignment <> AValue then begin
FAlignment := AValue;
Invalidate;
end;
end;
procedure TCustomDateTimePicker.SetArrowShape(const AValue: TArrowShape); procedure TCustomDateTimePicker.SetArrowShape(const AValue: TArrowShape);
begin begin
if FArrowShape = AValue then Exit; if FArrowShape = AValue then Exit;
@ -3848,6 +3889,7 @@ begin
with GetControlClassDefaultSize do with GetControlClassDefaultSize do
SetInitialBounds(0, 0, cx, cy); SetInitialBounds(0, 0, cx, cy);
FAlignment := taLeftJustify;
FCalAlignment := dtaDefault; FCalAlignment := dtaDefault;
FCorrectedDTP := dtpAMPM; FCorrectedDTP := dtpAMPM;
FCorrectedValue := 0; FCorrectedValue := 0;