mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-20 06:19:20 +02:00
LCL: Implement TextHint for TComboBox. Issue #30682.
git-svn-id: trunk@63731 -
This commit is contained in:
parent
32e975d46c
commit
0011948d52
@ -254,6 +254,7 @@ type
|
|||||||
property TabOrder;
|
property TabOrder;
|
||||||
property TabStop;
|
property TabStop;
|
||||||
property Text;
|
property Text;
|
||||||
|
property TextHint;
|
||||||
property Visible;
|
property Visible;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -392,6 +393,7 @@ type
|
|||||||
property TabOrder;
|
property TabOrder;
|
||||||
property TabStop;
|
property TabStop;
|
||||||
property Text;
|
property Text;
|
||||||
|
property TextHint;
|
||||||
property Visible;
|
property Visible;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -193,6 +193,7 @@ Type
|
|||||||
property ShowHint;
|
property ShowHint;
|
||||||
property TabOrder;
|
property TabOrder;
|
||||||
property TabStop;
|
property TabStop;
|
||||||
|
property TextHint;
|
||||||
property Visible;
|
property Visible;
|
||||||
{ events }
|
{ events }
|
||||||
property OnChange;
|
property OnChange;
|
||||||
|
@ -45,6 +45,10 @@ begin
|
|||||||
TWSCustomComboBoxClass(WidgetSetClass).SetReadOnly(Self, FReadOnly);
|
TWSCustomComboBoxClass(WidgetSetClass).SetReadOnly(Self, FReadOnly);
|
||||||
TWSCustomComboBoxClass(WidgetSetClass).SetMaxLength(Self, FMaxLength);
|
TWSCustomComboBoxClass(WidgetSetClass).SetMaxLength(Self, FMaxLength);
|
||||||
TWSCustomComboBoxClass(WidgetSetClass).SetDropDownCount(Self, FDropDownCount);
|
TWSCustomComboBoxClass(WidgetSetClass).SetDropDownCount(Self, FDropDownCount);
|
||||||
|
if WidgetSet.GetLCLCapability(lcTextHint) = LCL_CAPABILITY_YES then
|
||||||
|
TWSCustomComboBoxClass(WidgetSetClass).SetTextHint(Self, FTextHint)
|
||||||
|
else
|
||||||
|
ShowEmulatedTextHintIfYouCan;
|
||||||
|
|
||||||
if FSelLength<>0 then
|
if FSelLength<>0 then
|
||||||
begin
|
begin
|
||||||
@ -425,6 +429,32 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCustomComboBox.RealGetText: TCaption;
|
||||||
|
begin
|
||||||
|
if FEmulatedTextHintShowing then
|
||||||
|
Result := ''
|
||||||
|
else
|
||||||
|
Result := inherited RealGetText;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomComboBox.RealSetText(const AValue: TCaption);
|
||||||
|
// If the text AValue occurs in the list of strings, then sets the itemindex,
|
||||||
|
// otherwise does the default action
|
||||||
|
var
|
||||||
|
I: integer;
|
||||||
|
begin
|
||||||
|
// when items have same text, FItems.IndexOf(AValue) gives wrong index. Issue #28683.
|
||||||
|
if AValue<>'' then
|
||||||
|
begin
|
||||||
|
I := ItemIndex;
|
||||||
|
if (I < 0) or (I >= FItems.Count) or (FItems[I] <> AValue) then
|
||||||
|
if not (csLoading in ComponentState) then
|
||||||
|
ItemIndex := FItems.IndexOf(AValue);
|
||||||
|
HideEmulatedTextHint;
|
||||||
|
end;
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomComboBox.SetArrowKeysTraverseList(Value : Boolean);
|
procedure TCustomComboBox.SetArrowKeysTraverseList(Value : Boolean);
|
||||||
begin
|
begin
|
||||||
if Value <> FArrowKeysTraverseList then
|
if Value <> FArrowKeysTraverseList then
|
||||||
@ -446,6 +476,18 @@ begin
|
|||||||
inherited WMChar(Message);
|
inherited WMChar(Message);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomComboBox.WMKillFocus(var Message: TLMKillFocus);
|
||||||
|
begin
|
||||||
|
inherited WMKillFocus(Message);
|
||||||
|
ShowEmulatedTextHintIfYouCan;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomComboBox.WMSetFocus(var Message: TLMSetFocus);
|
||||||
|
begin
|
||||||
|
HideEmulatedTextHint;
|
||||||
|
inherited WMSetFocus(Message);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomComboBox.SetCharCase(eccCharCase: TEditCharCase);
|
procedure TCustomComboBox.SetCharCase(eccCharCase: TEditCharCase);
|
||||||
begin
|
begin
|
||||||
if (FCharCase <> eccCharCase) then
|
if (FCharCase <> eccCharCase) then
|
||||||
@ -468,6 +510,14 @@ begin
|
|||||||
RegisterPropertyToSkip(TCustomComboBox, 'ImeMode', 'VCL compatibility property', '');
|
RegisterPropertyToSkip(TCustomComboBox, 'ImeMode', 'VCL compatibility property', '');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCustomComboBox.CanShowEmulatedTextHint: Boolean;
|
||||||
|
begin
|
||||||
|
Result := HandleAllocated and
|
||||||
|
(WidgetSet.GetLCLCapability(lcTextHint)=LCL_CAPABILITY_NO) and
|
||||||
|
(([csDesigning,csLoading] * ComponentState) = []) and
|
||||||
|
(FTextHint <> '') and (Text = '') and not Focused;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomComboBox.CreateParams(var Params: TCreateParams);
|
procedure TCustomComboBox.CreateParams(var Params: TCreateParams);
|
||||||
const
|
const
|
||||||
ComboBoxStyles: array[TComboBoxStyle] of dword = (
|
ComboBoxStyles: array[TComboBoxStyle] of dword = (
|
||||||
@ -939,31 +989,6 @@ begin
|
|||||||
Result := FItemIndex;
|
Result := FItemIndex;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
|
||||||
Method: TCustomComboBox.RealSetText
|
|
||||||
Params: AValue -
|
|
||||||
Returns: nothing
|
|
||||||
|
|
||||||
If the text AValue occurs in the list of strings, then sets the itemindex,
|
|
||||||
otherwise does the default action
|
|
||||||
------------------------------------------------------------------------------}
|
|
||||||
procedure TCustomComboBox.RealSetText(const AValue: TCaption);
|
|
||||||
var
|
|
||||||
I: integer;
|
|
||||||
begin
|
|
||||||
// when items have same text, FItems.IndexOf(AValue) gives wrong index. Issue #28683.
|
|
||||||
I := ItemIndex;
|
|
||||||
if (I < 0) or (I >= FItems.Count) or (FItems[I] <> AValue) then
|
|
||||||
begin
|
|
||||||
I := FItems.IndexOf(AValue);
|
|
||||||
if I >= 0 then
|
|
||||||
ItemIndex := I
|
|
||||||
else if (not (csLoading in ComponentState)) then
|
|
||||||
ItemIndex := -1;
|
|
||||||
end;
|
|
||||||
inherited;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Method: TCustomComboBox.SetItemIndex
|
Method: TCustomComboBox.SetItemIndex
|
||||||
Params: Val -
|
Params: Val -
|
||||||
@ -1091,6 +1116,49 @@ begin
|
|||||||
TWSCustomComboBoxClass(WidgetSetClass).SetReadOnly(Self, FReadOnly);
|
TWSCustomComboBoxClass(WidgetSetClass).SetReadOnly(Self, FReadOnly);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// TextHint stuff
|
||||||
|
|
||||||
|
procedure TCustomComboBox.SetTextHint(const AValue: TTranslateString);
|
||||||
|
begin
|
||||||
|
if (FTextHint = AValue) then Exit;
|
||||||
|
FTextHint := AValue;
|
||||||
|
if (WidgetSet.GetLCLCapability(lcTextHint) = LCL_CAPABILITY_YES) and HandleAllocated then
|
||||||
|
TWSCustomComboBoxClass(WidgetSetClass).SetTextHint(Self, AValue);
|
||||||
|
if FTextHint = '' then
|
||||||
|
HideEmulatedTextHint
|
||||||
|
else
|
||||||
|
ShowEmulatedTextHintIfYouCan;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomComboBox.ShowEmulatedTextHintIfYouCan;
|
||||||
|
begin
|
||||||
|
if CanShowEmulatedTextHint then
|
||||||
|
ShowEmulatedTextHint;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomComboBox.ShowEmulatedTextHint;
|
||||||
|
var
|
||||||
|
HintFont: TFont;
|
||||||
|
begin
|
||||||
|
HintFont := CreateEmulatedTextHintFont;
|
||||||
|
try
|
||||||
|
TWSCustomComboBoxClass(WidgetSetClass).SetFont(Self, HintFont);
|
||||||
|
finally
|
||||||
|
HintFont.Free;
|
||||||
|
end;
|
||||||
|
TWSCustomComboBoxClass(WidgetSetClass).SetText(Self, Self.TextHint);
|
||||||
|
FEmulatedTextHintShowing := True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomComboBox.HideEmulatedTextHint;
|
||||||
|
begin
|
||||||
|
if not FEmulatedTextHintShowing then
|
||||||
|
Exit;
|
||||||
|
TWSCustomComboBoxClass(WidgetSetClass).SetFont(Self, Font);
|
||||||
|
TWSCustomComboBoxClass(WidgetSetClass).SetText(Self, '');
|
||||||
|
FEmulatedTextHintShowing := False;
|
||||||
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
procedure TCustomComboBox.UpdateSorted;
|
procedure TCustomComboBox.UpdateSorted;
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
|
@ -91,6 +91,7 @@ type
|
|||||||
class procedure SetMaxLength(const ACustomComboBox: TCustomComboBox; NewLength: integer); override;
|
class procedure SetMaxLength(const ACustomComboBox: TCustomComboBox; NewLength: integer); override;
|
||||||
class procedure SetStyle(const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle); override;
|
class procedure SetStyle(const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle); override;
|
||||||
class procedure SetReadOnly(const ACustomComboBox: TCustomComboBox; NewReadOnly: boolean); override;
|
class procedure SetReadOnly(const ACustomComboBox: TCustomComboBox; NewReadOnly: boolean); override;
|
||||||
|
class procedure SetTextHint(const ACustomComboBox: TCustomComboBox; const ATextHint: string); override;
|
||||||
|
|
||||||
class procedure Sort(const ACustomComboBox: TCustomComboBox; AList: TStrings; IsSorted: boolean); override;
|
class procedure Sort(const ACustomComboBox: TCustomComboBox; AList: TStrings; IsSorted: boolean); override;
|
||||||
|
|
||||||
@ -1601,6 +1602,17 @@ begin
|
|||||||
LineEdit.setReadOnly(NewReadOnly);
|
LineEdit.setReadOnly(NewReadOnly);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class procedure TQtWSCustomComboBox.SetTextHint(
|
||||||
|
const ACustomComboBox: TCustomComboBox; const ATextHint: string);
|
||||||
|
var
|
||||||
|
Widget: TQtWidget;
|
||||||
|
QtEdit: IQtEdit;
|
||||||
|
begin
|
||||||
|
Widget := TQtWidget(ACustomComboBox.Handle);
|
||||||
|
if Supports(Widget, IQtEdit, QtEdit) then
|
||||||
|
QtEdit.setTextHint(ATextHint);
|
||||||
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Method: TQtWSCustomComboBox.GetItems
|
Method: TQtWSCustomComboBox.GetItems
|
||||||
Params: None
|
Params: None
|
||||||
|
@ -277,16 +277,18 @@ type
|
|||||||
|
|
||||||
TCustomComboBox = class(TWinControl)
|
TCustomComboBox = class(TWinControl)
|
||||||
private
|
private
|
||||||
FCharCase: TEditCharCase;
|
FArrowKeysTraverseList: Boolean;
|
||||||
FAutoCompleteText: TComboBoxAutoCompleteText;
|
FAutoCompleteText: TComboBoxAutoCompleteText;
|
||||||
FAutoSelect: Boolean;
|
FAutoSelect: Boolean;
|
||||||
FAutoSelected: Boolean;
|
FAutoSelected: Boolean;
|
||||||
FAutoDropDown: Boolean;
|
FAutoDropDown: Boolean;
|
||||||
FCanvas: TCanvas;
|
FCanvas: TCanvas;
|
||||||
|
FCharCase: TEditCharCase;
|
||||||
FDropDownCount: Integer;
|
FDropDownCount: Integer;
|
||||||
FDroppedDown: boolean;
|
FDroppedDown: boolean;
|
||||||
FDroppingDown: Boolean;
|
FDroppingDown: Boolean;
|
||||||
FEditingDone: Boolean;
|
FEditingDone: Boolean;
|
||||||
|
FEmulatedTextHintShowing: Boolean;
|
||||||
FItemHeight: integer;
|
FItemHeight: integer;
|
||||||
FItemIndex: integer;
|
FItemIndex: integer;
|
||||||
FItemWidth: integer;
|
FItemWidth: integer;
|
||||||
@ -300,28 +302,35 @@ type
|
|||||||
FOnMeasureItem: TMeasureItemEvent;
|
FOnMeasureItem: TMeasureItemEvent;
|
||||||
FOnSelect: TNotifyEvent;
|
FOnSelect: TNotifyEvent;
|
||||||
FReadOnly: Boolean;
|
FReadOnly: Boolean;
|
||||||
|
FReturnArrowState: Boolean; //used to return the state of arrow keys from termporary change
|
||||||
FSelLength: integer;
|
FSelLength: integer;
|
||||||
FSelStart: integer;
|
FSelStart: integer;
|
||||||
FSorted: boolean;
|
FSorted: boolean;
|
||||||
FStyle: TComboBoxStyle;
|
FStyle: TComboBoxStyle;
|
||||||
FArrowKeysTraverseList: Boolean;
|
FTextHint: TTranslateString;
|
||||||
FReturnArrowState: Boolean; //used to return the state of arrow keys from termporary change
|
|
||||||
function GetAutoComplete: boolean;
|
function GetAutoComplete: boolean;
|
||||||
function GetDroppedDown: Boolean;
|
function GetDroppedDown: Boolean;
|
||||||
function GetItemWidth: Integer;
|
function GetItemWidth: Integer;
|
||||||
procedure SetAutoComplete(const AValue: boolean);
|
procedure SetAutoComplete(const AValue: boolean);
|
||||||
|
procedure SetArrowKeysTraverseList(Value: Boolean);
|
||||||
procedure SetItemWidth(const AValue: Integer);
|
procedure SetItemWidth(const AValue: Integer);
|
||||||
|
procedure SetCharCase(eccCharCase: TEditCharCase);
|
||||||
|
procedure SetReadOnly(const AValue: Boolean);
|
||||||
|
procedure SetTextHint(const AValue: TTranslateString);
|
||||||
|
procedure ShowEmulatedTextHintIfYouCan;
|
||||||
|
procedure ShowEmulatedTextHint;
|
||||||
|
procedure HideEmulatedTextHint;
|
||||||
|
procedure UpdateSorted;
|
||||||
procedure LMDrawListItem(var TheMessage: TLMDrawListItem); message LM_DrawListItem;
|
procedure LMDrawListItem(var TheMessage: TLMDrawListItem); message LM_DrawListItem;
|
||||||
procedure LMMeasureItem(var TheMessage: TLMMeasureItem); message LM_MeasureItem;
|
procedure LMMeasureItem(var TheMessage: TLMMeasureItem); message LM_MeasureItem;
|
||||||
procedure LMSelChange(var TheMessage); message LM_SelChange;
|
procedure LMSelChange(var TheMessage); message LM_SelChange;
|
||||||
procedure CNCommand(var TheMessage: TLMCommand); message CN_Command;
|
procedure CNCommand(var TheMessage: TLMCommand); message CN_Command;
|
||||||
procedure SetReadOnly(const AValue: Boolean);
|
|
||||||
procedure UpdateSorted;
|
|
||||||
procedure SetArrowKeysTraverseList(Value: Boolean);
|
|
||||||
procedure WMChar(var Message: TLMChar); message LM_CHAR;
|
procedure WMChar(var Message: TLMChar); message LM_CHAR;
|
||||||
procedure SetCharCase(eccCharCase: TEditCharCase);
|
procedure WMKillFocus(var Message: TLMKillFocus); message LM_KILLFOCUS;
|
||||||
|
procedure WMSetFocus(var Message: TLMSetFocus); message LM_SETFOCUS;
|
||||||
protected
|
protected
|
||||||
class procedure WSRegisterClass; override;
|
class procedure WSRegisterClass; override;
|
||||||
|
function CanShowEmulatedTextHint: Boolean; virtual;
|
||||||
procedure CreateParams(var Params: TCreateParams); override;
|
procedure CreateParams(var Params: TCreateParams); override;
|
||||||
procedure InitializeWnd; override;
|
procedure InitializeWnd; override;
|
||||||
procedure DestroyWnd; override;
|
procedure DestroyWnd; override;
|
||||||
@ -361,6 +370,7 @@ type
|
|||||||
procedure SetSelText(const Val: string); virtual;
|
procedure SetSelText(const Val: string); virtual;
|
||||||
procedure SetSorted(Val: boolean); virtual;
|
procedure SetSorted(Val: boolean); virtual;
|
||||||
procedure SetStyle(Val: TComboBoxStyle); virtual;
|
procedure SetStyle(Val: TComboBoxStyle); virtual;
|
||||||
|
function RealGetText: TCaption; override;
|
||||||
procedure RealSetText(const AValue: TCaption); override;
|
procedure RealSetText(const AValue: TCaption); override;
|
||||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||||
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
|
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
|
||||||
@ -420,6 +430,7 @@ type
|
|||||||
property Style: TComboBoxStyle read FStyle write SetStyle default csDropDown;
|
property Style: TComboBoxStyle read FStyle write SetStyle default csDropDown;
|
||||||
property TabStop default true;
|
property TabStop default true;
|
||||||
property Text;
|
property Text;
|
||||||
|
property TextHint: TTranslateString read FTextHint write SetTextHint;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -496,6 +507,7 @@ type
|
|||||||
property TabOrder;
|
property TabOrder;
|
||||||
property TabStop;
|
property TabStop;
|
||||||
property Text;
|
property Text;
|
||||||
|
property TextHint;
|
||||||
property Visible;
|
property Visible;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -87,6 +87,7 @@ type
|
|||||||
class procedure SetMaxLength(const ACustomComboBox: TCustomComboBox; NewLength: integer); virtual;
|
class procedure SetMaxLength(const ACustomComboBox: TCustomComboBox; NewLength: integer); virtual;
|
||||||
class procedure SetStyle(const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle); virtual;
|
class procedure SetStyle(const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle); virtual;
|
||||||
class procedure SetReadOnly(const ACustomComboBox: TCustomComboBox; NewReadOnly: boolean); virtual;
|
class procedure SetReadOnly(const ACustomComboBox: TCustomComboBox; NewReadOnly: boolean); virtual;
|
||||||
|
class procedure SetTextHint(const ACustomComboBox: TCustomComboBox; const ATextHint: string); virtual;
|
||||||
|
|
||||||
class function GetItems(const ACustomComboBox: TCustomComboBox): TStrings; virtual;
|
class function GetItems(const ACustomComboBox: TCustomComboBox): TStrings; virtual;
|
||||||
class procedure FreeItems(var AItems: TStrings); virtual;
|
class procedure FreeItems(var AItems: TStrings); virtual;
|
||||||
@ -495,6 +496,11 @@ class procedure TWSCustomComboBox.SetReadOnly(const ACustomComboBox: TCustomComb
|
|||||||
begin
|
begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class procedure TWSCustomComboBox.SetTextHint(
|
||||||
|
const ACustomComboBox: TCustomComboBox; const ATextHint: string);
|
||||||
|
begin
|
||||||
|
end;
|
||||||
|
|
||||||
class function TWSCustomComboBox.GetItems(const ACustomComboBox: TCustomComboBox
|
class function TWSCustomComboBox.GetItems(const ACustomComboBox: TCustomComboBox
|
||||||
): TStrings;
|
): TStrings;
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user