diff --git a/docs/xml/lcl/stdctrls.xml b/docs/xml/lcl/stdctrls.xml index 95200fb0ff..2b3f80aa55 100644 --- a/docs/xml/lcl/stdctrls.xml +++ b/docs/xml/lcl/stdctrls.xml @@ -775,6 +775,7 @@ properties + @@ -1466,6 +1467,20 @@ properties + + Disallows entry of free text into ComboBox edit field. + When True, the text can be changed only by selecting an item from the comboBox items list. + When False the text can be changed by free form entry. + + Changing the property value doesn't affect the style in any manner. + Changing the style doesn't affect the property as well. + For some styles (such as csDropDownList) the property might have no effect at all and is ignored. + + + + + + The number of selected UTF-8 characters in the edit box. @@ -1547,6 +1562,7 @@ Assign an new string to replace the selected text.

+ @@ -1636,6 +1652,7 @@ Assign an new string to replace the selected text. + diff --git a/lcl/include/customcombobox.inc b/lcl/include/customcombobox.inc index 14f03ece4f..bfa1d56707 100644 --- a/lcl/include/customcombobox.inc +++ b/lcl/include/customcombobox.inc @@ -42,6 +42,7 @@ begin TWSCustomComboBoxClass(WidgetSetClass).SetItemIndex(Self, FItemIndex); TWSCustomComboBoxClass(WidgetSetClass).SetStyle(Self, FStyle); TWSCustomComboBoxClass(WidgetSetClass).SetArrowKeysTraverseList(Self, FArrowKeysTraverseList); + TWSCustomComboBoxClass(WidgetSetClass).SetReadOnly(Self, FReadOnly); TWSCustomComboBoxClass(WidgetSetClass).SetMaxLength(Self, FMaxLength); TWSCustomComboBoxClass(WidgetSetClass).SetDropDownCount(Self, FDropDownCount); @@ -1080,6 +1081,16 @@ begin end; end; +procedure TCustomComboBox.SetReadOnly(const AValue: Boolean); +begin + if FReadOnly = AValue then + Exit; + FReadOnly := AValue; + if (not HandleAllocated) or (csLoading in ComponentState) then + Exit; + TWSCustomComboBoxClass(WidgetSetClass).SetReadOnly(Self, FReadOnly); +end; + {------------------------------------------------------------------------------ procedure TCustomComboBox.UpdateSorted; ------------------------------------------------------------------------------} diff --git a/lcl/interfaces/cocoa/cocoawsstdctrls.pas b/lcl/interfaces/cocoa/cocoawsstdctrls.pas index ae59703c0f..a36a17e400 100644 --- a/lcl/interfaces/cocoa/cocoawsstdctrls.pas +++ b/lcl/interfaces/cocoa/cocoawsstdctrls.pas @@ -86,8 +86,9 @@ type class procedure SetSelStart(const ACustomComboBox: TCustomComboBox; NewStart: integer); override; class procedure SetSelLength(const ACustomComboBox: TCustomComboBox; NewLength: integer); override;} class procedure SetItemIndex(const ACustomComboBox: TCustomComboBox; NewIndex: integer); override; - {class procedure SetMaxLength(const ACustomComboBox: TCustomComboBox; NewLength: integer); override; - class procedure SetStyle(const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle); override;} + {class procedure SetMaxLength(const ACustomComboBox: TCustomComboBox; NewLength: integer); override;} + class procedure SetStyle(const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle); override; + class procedure SetReadOnly(const ACustomComboBox: TCustomComboBox; NewReadOnly: boolean); override; class procedure SetDropDownCount(const ACustomComboBox: TCustomComboBox; NewCount: Integer); override; class function GetItems(const ACustomComboBox: TCustomComboBox): TStrings; override; @@ -1854,6 +1855,27 @@ begin TCocoaComboBox(ACustomComboBox.Handle).selectItemAtIndex(NewIndex); end; +class procedure TCocoaWSCustomComboBox.SetStyle( + const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle); +begin + if (not Assigned(ACustomComboBox)) or (not ACustomComboBox.HandleAllocated) then + Exit; + RecreateWnd(ACustomComboBox); +end; + +class procedure TCocoaWSCustomComboBox.SetReadOnly( + const ACustomComboBox: TCustomComboBox; NewReadOnly: boolean); +var + box : NSComboBox; +begin + if (not Assigned(ACustomComboBox)) or (not ACustomComboBox.HandleAllocated) then + Exit; + if not (NSObject(ACustomComboBox.Handle).isKindOfClass(NSComboBox)) then Exit; + box := NSComboBox(ACustomComboBox.Handle); + box.setEditable(not NewReadOnly); + box.setSelectable_(1); +end; + class procedure TCocoaWSCustomComboBox.SetDropDownCount(const ACustomComboBox: TCustomComboBox;NewCount:Integer); begin diff --git a/lcl/interfaces/gtk2/gtk2wsstdctrls.pp b/lcl/interfaces/gtk2/gtk2wsstdctrls.pp index 4f38cc428b..585977aeaf 100644 --- a/lcl/interfaces/gtk2/gtk2wsstdctrls.pp +++ b/lcl/interfaces/gtk2/gtk2wsstdctrls.pp @@ -129,6 +129,7 @@ type class procedure SetItemIndex(const ACustomComboBox: TCustomComboBox; NewIndex: integer); override; class procedure SetMaxLength(const ACustomComboBox: TCustomComboBox; NewLength: integer); override; class procedure SetStyle(const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle); override; + class procedure SetReadOnly(const ACustomComboBox: TCustomComboBox; NewReadOnly: boolean); override; class function GetItems(const ACustomComboBox: TCustomComboBox): TStrings; override; class procedure Sort(const ACustomComboBox: TCustomComboBox; {%H-}AList: TStrings; IsSorted: boolean); override; @@ -2014,6 +2015,19 @@ begin ReCreateCombo(ACustomComboBox, NeedEntry, WidgetInfo); end; +class procedure TGtk2WSCustomComboBox.SetReadOnly( + const ACustomComboBox: TCustomComboBox; NewReadOnly: boolean); +var + WidgetInfo: PWidgetInfo; + Entry: PGtkEntry; +begin + WidgetInfo := GetWidgetInfo({%H-}Pointer(ACustomComboBox.Handle)); + + Entry := GetComboBoxEntry(WidgetInfo^.CoreWidget); + if (Entry<>nil) and (ACustomComboBox.Style in [csDropDown, csOwnerDrawEditableFixed, csOwnerDrawEditableVariable, csSimple]) then + gtk_entry_set_editable(PGtkEditable(Entry), not NewReadOnly); +end; + class function TGtk2WSCustomComboBox.GetItems( const ACustomComboBox: TCustomComboBox): TStrings; var diff --git a/lcl/interfaces/qt5/qtwsstdctrls.pp b/lcl/interfaces/qt5/qtwsstdctrls.pp index fb9e298974..38709a61b7 100644 --- a/lcl/interfaces/qt5/qtwsstdctrls.pp +++ b/lcl/interfaces/qt5/qtwsstdctrls.pp @@ -90,6 +90,7 @@ type class procedure SetItemIndex(const ACustomComboBox: TCustomComboBox; NewIndex: integer); override; class procedure SetMaxLength(const ACustomComboBox: TCustomComboBox; NewLength: integer); override; class procedure SetStyle(const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle); override; + class procedure SetReadOnly(const ACustomComboBox: TCustomComboBox; NewReadOnly: boolean); override; class procedure Sort(const ACustomComboBox: TCustomComboBox; AList: TStrings; IsSorted: boolean); override; @@ -1589,6 +1590,17 @@ begin inherited SetStyle(ACustomComboBox, NewStyle); end; +class procedure TQtWSCustomComboBox.SetReadOnly(const ACustomComboBox: TCustomComboBox; NewReadOnly: boolean); +var + LineEdit : TQtLineEdit; +begin + if not WSCheckHandleAllocated(ACustomComboBox, 'SetReadOnly') then + Exit; + LineEdit := TQtComboBox(ACustomComboBox.Handle).LineEdit; + if LineEdit <> nil then + LineEdit.setReadOnly(NewReadOnly); +end; + {------------------------------------------------------------------------------ Method: TQtWSCustomComboBox.GetItems Params: None diff --git a/lcl/interfaces/win32/win32wsstdctrls.pp b/lcl/interfaces/win32/win32wsstdctrls.pp index 800d82328c..ebe3999431 100644 --- a/lcl/interfaces/win32/win32wsstdctrls.pp +++ b/lcl/interfaces/win32/win32wsstdctrls.pp @@ -99,6 +99,7 @@ type class procedure SetItemIndex(const ACustomComboBox: TCustomComboBox; NewIndex: integer); override; class procedure SetMaxLength(const ACustomComboBox: TCustomComboBox; NewLength: integer); override; class procedure SetStyle(const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle); override; + class procedure SetReadOnly(const ACustomComboBox: TCustomComboBox; NewReadOnly: boolean); override; class function GetItems(const ACustomComboBox: TCustomComboBox): TStrings; override; class procedure Sort(const ACustomComboBox: TCustomComboBox; AList: TStrings; IsSorted: boolean); override; @@ -1091,6 +1092,20 @@ begin RecreateWnd(ACustomComboBox); end; +class procedure TWin32WSCustomComboBox.SetReadOnly(const ACustomComboBox: TCustomComboBox; + NewReadOnly: boolean); +var + Info: TComboboxInfo; +begin + if not ACustomComboBox.HandleAllocated then + Exit; + + Info.cbSize := SizeOf(Info); + Win32Extra.GetComboBoxInfo(ACustomComboBox.Handle, @Info); + if (info.hwndItem<>0) and (info.hwndItem<>INVALID_HANDLE_VALUE) then + SendMessage(info.hwndItem, EM_SETREADONLY, WParam(NewReadOnly), 0); +end; + class function TWin32WSCustomComboBox.GetItemIndex(const ACustomComboBox: TCustomComboBox): integer; begin Result := SendMessage(ACustomComboBox.Handle, CB_GETCURSEL, 0, 0); diff --git a/lcl/stdctrls.pp b/lcl/stdctrls.pp index 1651316665..55bf5a909d 100644 --- a/lcl/stdctrls.pp +++ b/lcl/stdctrls.pp @@ -299,6 +299,7 @@ type FOnGetItems: TNotifyEvent; FOnMeasureItem: TMeasureItemEvent; FOnSelect: TNotifyEvent; + FReadOnly: Boolean; FSelLength: integer; FSelStart: integer; FSorted: boolean; @@ -314,6 +315,7 @@ type procedure LMMeasureItem(var TheMessage: TLMMeasureItem); message LM_MeasureItem; procedure LMSelChange(var TheMessage); message LM_SelChange; 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; @@ -411,6 +413,7 @@ type property DropDownCount: Integer read FDropDownCount write SetDropDownCount default 8; property Items: TStrings read FItems write SetItems; property ItemIndex: integer read GetItemIndex write SetItemIndex default -1; + property ReadOnly: Boolean read FReadOnly write SetReadOnly default False; property SelLength: integer read GetSelLength write SetSelLength;// UTF-8 length property SelStart: integer read GetSelStart write SetSelStart;// UTF-8 position property SelText: String read GetSelText write SetSelText; @@ -486,6 +489,7 @@ type property ParentFont; property ParentShowHint; property PopupMenu; + property ReadOnly; property ShowHint; property Sorted; property Style; diff --git a/lcl/widgetset/wsstdctrls.pp b/lcl/widgetset/wsstdctrls.pp index 61b446bf53..d0f2506aa4 100644 --- a/lcl/widgetset/wsstdctrls.pp +++ b/lcl/widgetset/wsstdctrls.pp @@ -86,6 +86,7 @@ type class procedure SetItemIndex(const ACustomComboBox: TCustomComboBox; NewIndex: integer); virtual; class procedure SetMaxLength(const ACustomComboBox: TCustomComboBox; NewLength: integer); virtual; class procedure SetStyle(const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle); virtual; + class procedure SetReadOnly(const ACustomComboBox: TCustomComboBox; NewReadOnly: boolean); virtual; class function GetItems(const ACustomComboBox: TCustomComboBox): TStrings; virtual; class procedure FreeItems(var AItems: TStrings); virtual; @@ -470,6 +471,11 @@ class procedure TWSCustomComboBox.SetStyle(const ACustomComboBox: TCustomComboBo begin end; +class procedure TWSCustomComboBox.SetReadOnly(const ACustomComboBox: TCustomComboBox; + NewReadOnly: boolean); +begin +end; + class function TWSCustomComboBox.GetItems(const ACustomComboBox: TCustomComboBox ): TStrings; begin