mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-12 14:00:38 +02:00
LCL: Move function CreateEmulatedTextHintFont to TWinControl for future. Replace emulated hint status with a boolean.
git-svn-id: trunk@63729 -
This commit is contained in:
parent
0ba97f3388
commit
953b2ef2b1
@ -2313,6 +2313,7 @@ type
|
||||
procedure DockDrop(DragDockObject: TDragDockObject; X, Y: Integer); virtual;
|
||||
function CanFocus: Boolean; virtual;
|
||||
function CanSetFocus: Boolean; virtual;
|
||||
function CreateEmulatedTextHintFont: TFont; // To show TextHint in some controls / widgetsets.
|
||||
function GetControlIndex(AControl: TControl): integer;
|
||||
procedure SetControlIndex(AControl: TControl; NewIndex: integer);
|
||||
function Focused: Boolean; virtual;
|
||||
|
@ -382,7 +382,7 @@ begin
|
||||
else
|
||||
EchoMode:=emPassword;
|
||||
end;
|
||||
if HandleAllocated and (FEmulatedTextHintStatus=thsHidden) then
|
||||
if HandleAllocated and not FEmulatedTextHintShowing then
|
||||
TWSCustomEditClass(WidgetSetClass).SetPasswordChar(Self, AValue);
|
||||
end;
|
||||
|
||||
@ -403,12 +403,7 @@ begin
|
||||
Result := HandleAllocated and
|
||||
(WidgetSet.GetLCLCapability(lcTextHint)=LCL_CAPABILITY_NO) and
|
||||
(([csDesigning,csLoading] * ComponentState) = []) and
|
||||
(Text = '') and not Focused;
|
||||
end;
|
||||
|
||||
function TCustomEdit.CreateEmulatedTextHintFont: TFont;
|
||||
begin
|
||||
Result := TWSCustomEditClass(WidgetSetClass).CreateEmulatedTextHintFont(Self);
|
||||
(FTextHint <> '') and (Text = '') and not Focused;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -519,8 +514,9 @@ end;
|
||||
|
||||
procedure TCustomEdit.WndProc(var Message: TLMessage);
|
||||
begin
|
||||
if not((Message.msg=CM_TEXTCHANGED) and (FEmulatedTextHintStatus<>thsHidden)) then //eat CM_TEXTCHANGED
|
||||
inherited WndProc(Message);
|
||||
if (Message.msg=CM_TEXTCHANGED) and FEmulatedTextHintShowing then //eat CM_TEXTCHANGED
|
||||
Exit;
|
||||
inherited WndProc(Message);
|
||||
end;
|
||||
|
||||
procedure TCustomEdit.ShouldAutoAdjust(var AWidth, AHeight: Boolean);
|
||||
@ -594,7 +590,7 @@ end;
|
||||
|
||||
function TCustomEdit.RealGetText: TCaption;
|
||||
begin
|
||||
if FEmulatedTextHintStatus=thsShowing then
|
||||
if FEmulatedTextHintShowing then
|
||||
Result := ''
|
||||
else
|
||||
Result := inherited RealGetText;
|
||||
@ -665,7 +661,7 @@ begin
|
||||
begin
|
||||
SelectAll;
|
||||
if (SelText = Text) then FAutoSelected := True;
|
||||
end;//End if FAutoSelect
|
||||
end;
|
||||
inherited DoEnter;
|
||||
end;
|
||||
|
||||
@ -685,9 +681,7 @@ procedure TCustomEdit.FontChanged(Sender: TObject);
|
||||
var
|
||||
HintFont: TObject;
|
||||
begin
|
||||
if (FEmulatedTextHintStatus=thsHidden) then
|
||||
inherited FontChanged(Sender)
|
||||
else
|
||||
if FEmulatedTextHintShowing then
|
||||
begin
|
||||
HintFont := CreateEmulatedTextHintFont;
|
||||
try
|
||||
@ -695,7 +689,9 @@ begin
|
||||
finally
|
||||
HintFont.Free;
|
||||
end;
|
||||
end;
|
||||
end
|
||||
else
|
||||
inherited FontChanged(Sender);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -721,8 +717,6 @@ begin
|
||||
FTextHint := AValue;
|
||||
if (WidgetSet.GetLCLCapability(lcTextHint) = LCL_CAPABILITY_YES) and HandleAllocated then
|
||||
TWSCustomEditClass(WidgetSetClass).SetTextHint(Self, AValue);
|
||||
// ToDo: thsChanging is not really used and can be removed.
|
||||
Assert(FEmulatedTextHintStatus<>thsChanging, 'TCustomEdit.SetTextHint: Status=thsChanging');
|
||||
if FTextHint = '' then
|
||||
HideEmulatedTextHint
|
||||
else
|
||||
@ -739,7 +733,6 @@ procedure TCustomEdit.ShowEmulatedTextHint;
|
||||
var
|
||||
HintFont: TFont;
|
||||
begin
|
||||
FEmulatedTextHintStatus := thsChanging;
|
||||
HintFont := CreateEmulatedTextHintFont;
|
||||
try
|
||||
TWSCustomEditClass(WidgetSetClass).SetFont(Self, HintFont);
|
||||
@ -748,18 +741,17 @@ begin
|
||||
end;
|
||||
TWSCustomEditClass(WidgetSetClass).SetText(Self, Self.TextHint);
|
||||
TWSCustomEditClass(WidgetSetClass).SetPasswordChar(Self, #0);
|
||||
FEmulatedTextHintStatus := thsShowing;
|
||||
FEmulatedTextHintShowing := True;
|
||||
end;
|
||||
|
||||
procedure TCustomEdit.HideEmulatedTextHint;
|
||||
begin
|
||||
if FEmulatedTextHintStatus<>thsShowing then
|
||||
if not FEmulatedTextHintShowing then
|
||||
Exit;
|
||||
FEmulatedTextHintStatus := thsChanging;
|
||||
TWSCustomEditClass(WidgetSetClass).SetFont(Self, Font);
|
||||
TWSCustomEditClass(WidgetSetClass).SetPasswordChar(Self, PasswordChar);
|
||||
TWSCustomEditClass(WidgetSetClass).SetText(Self, '');
|
||||
FEmulatedTextHintStatus := thsHidden;
|
||||
FEmulatedTextHintShowing := False;
|
||||
end;
|
||||
|
||||
procedure TCustomEdit.SetAlignment(const AValue: TAlignment);
|
||||
|
@ -3689,6 +3689,18 @@ begin
|
||||
Result := Control is TCustomForm;//the very top parent must be a form
|
||||
end;
|
||||
|
||||
function TWinControl.CreateEmulatedTextHintFont: TFont;
|
||||
begin
|
||||
Result := TFont.Create;
|
||||
try
|
||||
Result.Assign(Font);
|
||||
Result.Color := clGrayText;
|
||||
except
|
||||
FreeAndNil(Result);
|
||||
raise;
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
TWinControl CreateSubClass
|
||||
------------------------------------------------------------------------------}
|
||||
|
@ -266,14 +266,6 @@ type
|
||||
published
|
||||
end;
|
||||
|
||||
{ TEditHelper }
|
||||
|
||||
TEditHelper = class helper for TCustomEdit
|
||||
public
|
||||
function EmulatedTextHintStatus: TCustomEdit.TEmulatedTextHintStatus;
|
||||
function CreateEmulatedTextHintFont: TFont;
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
uses qtint;
|
||||
@ -300,19 +292,6 @@ const
|
||||
QFrameSunken
|
||||
);
|
||||
|
||||
{ TEditHelper }
|
||||
|
||||
function TEditHelper.EmulatedTextHintStatus: TCustomEdit.TEmulatedTextHintStatus;
|
||||
begin
|
||||
Result := FEmulatedTextHintStatus;
|
||||
end;
|
||||
|
||||
function TEditHelper.CreateEmulatedTextHintFont: TFont;
|
||||
begin
|
||||
Result := inherited CreateEmulatedTextHintFont;
|
||||
end;
|
||||
|
||||
|
||||
{ TQtWSScrollBar }
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -1064,9 +1043,9 @@ begin
|
||||
|
||||
TQtWSWinControl.ShowHide(AWinControl);
|
||||
if AWinControl.HandleObjectShouldBeVisible
|
||||
and (TCustomEdit(AWinControl).EmulatedTextHintStatus=thsShowing) then
|
||||
and TCustomEdit(AWinControl).EmulatedTextHintShowing then
|
||||
begin
|
||||
EditFont := TCustomEdit(AWinControl).CreateEmulatedTextHintFont;
|
||||
EditFont := AWinControl.CreateEmulatedTextHintFont;
|
||||
try
|
||||
SetFont(AWinControl, EditFont);
|
||||
finally
|
||||
|
@ -1397,9 +1397,9 @@ begin
|
||||
if ChildWinControl <> nil then
|
||||
begin
|
||||
if (ChildWinControl is TCustomEdit)
|
||||
and (TAccessCustomEdit(ChildWinControl).FEmulatedTextHintStatus=thsShowing) then
|
||||
and TCustomEdit(ChildWinControl).EmulatedTextHintShowing then
|
||||
begin
|
||||
EditFont := TAccessCustomEdit(ChildWinControl).CreateEmulatedTextHintFont;
|
||||
EditFont := ChildWinControl.CreateEmulatedTextHintFont;
|
||||
try
|
||||
WindowColor := EditFont.Color;
|
||||
finally
|
||||
|
@ -746,6 +746,7 @@ type
|
||||
FCharCase: TEditCharCase;
|
||||
fCaretPos: TPoint;
|
||||
FEchoMode: TEchoMode;
|
||||
FEmulatedTextHintShowing: Boolean;
|
||||
FHideSelection: Boolean;
|
||||
FMaxLength: Integer;
|
||||
FModified: Boolean;
|
||||
@ -769,14 +770,9 @@ type
|
||||
procedure SetMaxLength(Value: Integer);
|
||||
procedure SetModified(Value: Boolean);
|
||||
procedure SetPasswordChar(const AValue: Char);
|
||||
protected type
|
||||
TEmulatedTextHintStatus = (thsHidden, thsShowing, thsChanging);
|
||||
protected
|
||||
FEmulatedTextHintStatus: TEmulatedTextHintStatus;
|
||||
|
||||
class procedure WSRegisterClass; override;
|
||||
function CanShowEmulatedTextHint: Boolean; virtual;
|
||||
function CreateEmulatedTextHintFont: TFont; virtual;
|
||||
procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;
|
||||
WithThemeSpace: Boolean); override;
|
||||
procedure CreateParams(var Params: TCreateParams); override;
|
||||
@ -842,6 +838,7 @@ type
|
||||
property CaretPos: TPoint read GetCaretPos write SetCaretPos;
|
||||
property CharCase: TEditCharCase read FCharCase write SetCharCase default ecNormal;
|
||||
property EchoMode: TEchoMode read FEchoMode write SetEchoMode default emNormal;
|
||||
property EmulatedTextHintShowing: Boolean read FEmulatedTextHintShowing;
|
||||
property HideSelection: Boolean read FHideSelection write SetHideSelection default True;
|
||||
property MaxLength: Integer read FMaxLength write SetMaxLength default 0;
|
||||
property Modified: Boolean read GetModified write SetModified;
|
||||
|
@ -164,7 +164,6 @@ type
|
||||
class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); virtual;
|
||||
class procedure SetSelText(const ACustomEdit: TCustomEdit; const NewSelText: string); virtual;
|
||||
class procedure SetTextHint(const ACustomEdit: TCustomEdit; const ATextHint: string); virtual;
|
||||
class function CreateEmulatedTextHintFont(const ACustomEdit: TCustomEdit): TFont; virtual;
|
||||
|
||||
class procedure Cut(const ACustomEdit: TCustomEdit); virtual;
|
||||
class procedure Copy(const ACustomEdit: TCustomEdit); virtual;
|
||||
@ -624,20 +623,6 @@ begin
|
||||
Clipboard.AsText := ACustomEdit.SelText;
|
||||
end;
|
||||
|
||||
class function TWSCustomEdit.CreateEmulatedTextHintFont(
|
||||
const ACustomEdit: TCustomEdit): TFont;
|
||||
begin
|
||||
Result := TFont.Create;
|
||||
try
|
||||
Result.Assign(ACustomEdit.Font);
|
||||
Result.Color := clGrayText;
|
||||
except
|
||||
Result.Free;
|
||||
Result := nil;
|
||||
raise;
|
||||
end;
|
||||
end;
|
||||
|
||||
class procedure TWSCustomEdit.Paste(const ACustomEdit: TCustomEdit);
|
||||
begin
|
||||
if Clipboard.HasFormat(CF_TEXT) then
|
||||
|
Loading…
Reference in New Issue
Block a user