From 862a04296badcae61229eef1cb28af1fc7545f83 Mon Sep 17 00:00:00 2001 From: mattias Date: Mon, 22 Aug 2005 19:02:06 +0000 Subject: [PATCH] added TComboBox.ReadOnly - only partially working under gtk1 git-svn-id: trunk@7546 - --- lcl/include/customcombobox.inc | 15 ++++++-- lcl/interfaces/gtk/gtkwsstdctrls.pp | 13 ++++++- lcl/stdctrls.pp | 6 ++- lcl/widgetset/wsstdctrls.pp | 59 +++++++++++++++++++---------- 4 files changed, 68 insertions(+), 25 deletions(-) diff --git a/lcl/include/customcombobox.inc b/lcl/include/customcombobox.inc index c0835338fd..c0c8abe897 100644 --- a/lcl/include/customcombobox.inc +++ b/lcl/include/customcombobox.inc @@ -46,9 +46,9 @@ begin TWSCustomComboBoxClass(WidgetSetClass).SetItemIndex(Self, FItemIndex); TWSCustomComboBoxClass(WidgetSetClass).SetStyle(Self, FStyle); TWSCustomComboBoxClass(WidgetSetClass).SetArrowKeysTraverseList(Self, FArrowKeysTraverseList); + TWSCustomComboBoxClass(WidgetSetClass).SetReadOnly(Self, FReadOnly); end; - {------------------------------------------------------------------------------ Method: TCustomComboBox.DestroyWnd Params: --- @@ -213,7 +213,8 @@ end; procedure TCustomComboBox.CloseUp; begin if [csLoading,csDestroying,csDesigning]*ComponentState<>[] then exit; - EditingDone; + if not ReadOnly then + EditingDone; if Assigned(FOnCloseUp) then FOnCloseUp(Self); end; @@ -376,7 +377,7 @@ procedure TCustomComboBox.WMChar(var Message: TLMChar); begin // all normal characters are handled by the ComboBox //debugln('TCustomEdit.WMChar ',DbgSName(Self),' ',dbgs(Message.CharCode)); - if Message.CharCode in [ord('A')..ord('Z'),ord('a')..ord('z')] then + if (Message.CharCode in [ord('A')..ord('Z'),ord('a')..ord('z')]) then // eat normal keys, so they don't trigger accelerators Message.Result := 1 else @@ -817,6 +818,14 @@ begin end; end; +procedure TCustomComboBox.SetReadOnly(const AValue: Boolean); +begin + if FReadOnly=AValue then exit; + FReadOnly:=AValue; + if HandleAllocated then + TWSCustomComboBoxClass(WidgetSetClass).SetReadOnly(Self, AValue); +end; + {------------------------------------------------------------------------------ procedure TCustomComboBox.UpdateSorted; ------------------------------------------------------------------------------} diff --git a/lcl/interfaces/gtk/gtkwsstdctrls.pp b/lcl/interfaces/gtk/gtkwsstdctrls.pp index 0254a263bb..71df87f50b 100644 --- a/lcl/interfaces/gtk/gtkwsstdctrls.pp +++ b/lcl/interfaces/gtk/gtkwsstdctrls.pp @@ -84,7 +84,8 @@ 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; end; @@ -692,6 +693,16 @@ begin end; end; +procedure TGtkWSCustomComboBox.SetReadOnly(const ACustomComboBox: TCustomComboBox; + NewReadOnly: boolean); +var + Widget: PGtkWidget; +begin + Widget:=PGtkCombo(ACustomComboBox.Handle)^.entry; + if GtkWidgetIsA(Widget,{$ifdef GTK1}GTK_ENTRY_TYPE{$else}GTK_TYPE_ENTRY{$endif}) then + gtk_entry_set_editable(PGtkEntry(Widget), not ACustomComboBox.ReadOnly); +end; + function TGtkWSCustomComboBox.GetItems( const ACustomComboBox: TCustomComboBox): TStrings; begin diff --git a/lcl/stdctrls.pp b/lcl/stdctrls.pp index c3188c2b7c..0865acb35d 100644 --- a/lcl/stdctrls.pp +++ b/lcl/stdctrls.pp @@ -238,6 +238,7 @@ type FOnDropDown: TNotifyEvent; FOnMeasureItem: TMeasureItemEvent; FOnSelect: TNotifyEvent; + FReadOnly: Boolean; FSelLength: integer; FSelStart: integer; FSorted: boolean; @@ -251,6 +252,7 @@ type procedure LMDrawListItem(var TheMessage: TLMDrawListItem); message LM_DrawListItem; procedure LMMeasureItem(var TheMessage: TLMMeasureItem); message LM_MeasureItem; 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; @@ -258,7 +260,7 @@ type procedure CreateWnd; override; procedure DestroyWnd; override; procedure DrawItem(Index: Integer; ARect: TRect; - State: TOwnerDrawState); virtual; + State: TOwnerDrawState); virtual; procedure LMChange(var msg); message LM_CHANGED; procedure Change; dynamic; procedure Select; dynamic; @@ -321,6 +323,7 @@ type property Canvas: TCanvas read FCanvas; 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; property SelStart: integer read GetSelStart write SetSelStart; property SelText: String read GetSelText write SetSelText; @@ -370,6 +373,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 7dbc593e1c..a078aa1c3d 100644 --- a/lcl/widgetset/wsstdctrls.pp +++ b/lcl/widgetset/wsstdctrls.pp @@ -81,6 +81,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 Sort(const ACustomComboBox: TCustomComboBox; AList: TStrings; IsSorted: boolean); virtual; @@ -251,67 +252,85 @@ procedure TWSCustomListBox.SetStyle(const ACustomListBox: TCustomListBox); begin end; -procedure TWSCustomListBox.SetSorted(const ACustomListBox: TCustomListBox; AList: TStrings; ASorted: boolean); +procedure TWSCustomListBox.SetSorted(const ACustomListBox: TCustomListBox; + AList: TStrings; ASorted: boolean); begin end; -procedure TWSCustomListBox.SetTopIndex(const ACustomListBox: TCustomListBox; const NewTopIndex: integer); +procedure TWSCustomListBox.SetTopIndex(const ACustomListBox: TCustomListBox; + const NewTopIndex: integer); begin end; { TWSCustomComboBox } -function TWSCustomComboBox.GetSelStart(const ACustomComboBox: TCustomComboBox): integer; +function TWSCustomComboBox.GetSelStart(const ACustomComboBox: TCustomComboBox + ): integer; begin - result := -1; + Result := -1; end; -function TWSCustomComboBox.GetSelLength(const ACustomComboBox: TCustomComboBox): integer; +function TWSCustomComboBox.GetSelLength(const ACustomComboBox: TCustomComboBox + ): integer; begin - result := 0; + Result := 0; end; -function TWSCustomComboBox.GetItemIndex(const ACustomComboBox: TCustomComboBox): integer; +function TWSCustomComboBox.GetItemIndex(const ACustomComboBox: TCustomComboBox + ): integer; begin - result := -1; + Result := -1; end; -function TWSCustomComboBox.GetMaxLength(const ACustomComboBox: TCustomComboBox): integer; +function TWSCustomComboBox.GetMaxLength(const ACustomComboBox: TCustomComboBox + ): integer; begin - result := 0; + Result := 0; end; -procedure TWSCustomComboBox.SetArrowKeysTraverseList(const ACustomComboBox: TCustomComboBox; - NewTraverseList: boolean); +procedure TWSCustomComboBox.SetArrowKeysTraverseList( + const ACustomComboBox: TCustomComboBox; NewTraverseList: boolean); begin end; -procedure TWSCustomComboBox.SetMaxLength(const ACustomComboBox: TCustomComboBox; NewLength: integer); +procedure TWSCustomComboBox.SetMaxLength(const ACustomComboBox: TCustomComboBox; + NewLength: integer); begin end; -procedure TWSCustomComboBox.SetSelStart(const ACustomComboBox: TCustomComboBox; NewStart: integer); +procedure TWSCustomComboBox.SetSelStart(const ACustomComboBox: TCustomComboBox; + NewStart: integer); begin end; -procedure TWSCustomComboBox.SetSelLength(const ACustomComboBox: TCustomComboBox; NewLength: integer); +procedure TWSCustomComboBox.SetSelLength(const ACustomComboBox: TCustomComboBox; + NewLength: integer); begin end; -procedure TWSCustomComboBox.SetItemIndex(const ACustomComboBox: TCustomComboBox; NewIndex: integer); +procedure TWSCustomComboBox.SetItemIndex(const ACustomComboBox: TCustomComboBox; + NewIndex: integer); begin end; -procedure TWSCustomComboBox.SetStyle(const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle); +procedure TWSCustomComboBox.SetStyle(const ACustomComboBox: TCustomComboBox; + NewStyle: TComboBoxStyle); begin end; -function TWSCustomComboBox.GetItems(const ACustomComboBox: TCustomComboBox): TStrings; +procedure TWSCustomComboBox.SetReadOnly(const ACustomComboBox: TCustomComboBox; + NewReadOnly: boolean); begin - result := nil; end; -procedure TWSCustomComboBox.Sort(const ACustomComboBox: TCustomComboBox; AList: TStrings; IsSorted: boolean); +function TWSCustomComboBox.GetItems(const ACustomComboBox: TCustomComboBox + ): TStrings; +begin + Result := nil; +end; + +procedure TWSCustomComboBox.Sort(const ACustomComboBox: TCustomComboBox; + AList: TStrings; IsSorted: boolean); begin end;