mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 09:19:32 +02:00
lcl: MaxLength redo:
- MaxLength = 0 => no limit, MaxLength > 0 => limit. Default = 0 for memo, combo and edit - fix gtk, gtk2 code where MaxLength = -1 was used for unlimited length in Memo (why? combo and edit used 0) - fix qt combobox SetLength (was occasional forgotten?) - cleanup git-svn-id: trunk@17365 -
This commit is contained in:
parent
cd39f7986e
commit
25e9426c10
@ -149,13 +149,15 @@ end;
|
||||
|
||||
Set the maximum length for user input.
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TCustomComboBox.SetMaxLength(Val : integer);
|
||||
procedure TCustomComboBox.SetMaxLength(AValue: integer);
|
||||
begin
|
||||
if Val < 0 then Val:= 0;
|
||||
if Val<>MaxLength then begin
|
||||
fMaxlength:=Val;
|
||||
if AValue < 0 then
|
||||
AValue := 0;
|
||||
if AValue <> MaxLength then
|
||||
begin
|
||||
FMaxlength := AValue;
|
||||
if HandleAllocated then
|
||||
TWSCustomComboBoxClass(WidgetSetClass).SetMaxLength(Self, Val);
|
||||
TWSCustomComboBoxClass(WidgetSetClass).SetMaxLength(Self, AValue);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -166,11 +168,11 @@ end;
|
||||
|
||||
Get the maximum length for user input.
|
||||
------------------------------------------------------------------------------}
|
||||
function TCustomComboBox.GetMaxLength : integer;
|
||||
function TCustomComboBox.GetMaxLength: integer;
|
||||
begin
|
||||
if HandleAllocated then
|
||||
FMaxLength := TWSCustomComboBoxClass(WidgetSetClass).GetMaxLength(Self);
|
||||
Result:=FMaxLength;
|
||||
Result := FMaxLength;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -749,9 +751,9 @@ begin
|
||||
ControlStyle := ControlStyle - [csCaptureMouse];
|
||||
SetInitialBounds(0,0,GetControlClassDefaultSize.X,GetControlClassDefaultSize.Y);
|
||||
FItems := TStringlist.Create;
|
||||
FItemIndex:=-1;
|
||||
FMaxLength := -1;
|
||||
FDropDownCount:=8;
|
||||
FItemIndex := -1;
|
||||
FMaxLength := 0;
|
||||
FDropDownCount := 8;
|
||||
FCanvas := TControlCanvas.Create;
|
||||
TControlCanvas(FCanvas).Control := Self;
|
||||
ArrowKeysTraverseList := True;
|
||||
|
@ -50,7 +50,7 @@ begin
|
||||
//TCustomMemo also inherits from here but it's create changes fcompstyle to csMemo
|
||||
ControlStyle := ControlStyle - [csCaptureMouse];
|
||||
FCompStyle := csEdit;
|
||||
FMaxLength:= -1;
|
||||
FMaxLength := 0;
|
||||
ParentColor := false;
|
||||
TabStop := true;
|
||||
SetInitialBounds(0,0,GetControlClassDefaultSize.X,GetControlClassDefaultSize.Y);
|
||||
@ -294,10 +294,14 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TCustomEdit.SetMaxLength(Value : Integer);
|
||||
begin
|
||||
if Value=MaxLength then exit;
|
||||
FMaxLength := Value;
|
||||
if HandleAllocated then
|
||||
TWSCustomEditClass(WidgetSetClass).SetMaxLength(Self, Value);
|
||||
if Value < 0 then
|
||||
Value := 0;
|
||||
if Value <> MaxLength then
|
||||
begin
|
||||
FMaxLength := Value;
|
||||
if HandleAllocated then
|
||||
TWSCustomEditClass(WidgetSetClass).SetMaxLength(Self, Value);
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
|
@ -1972,17 +1972,16 @@ begin
|
||||
if (NewTextLength = 1) and (char^ = #13) and (LineEnding = #10) then
|
||||
char^ := #10;
|
||||
Memo:= TCustomMemo(Data);
|
||||
if Memo.MaxLength < 0 then Exit;
|
||||
if Memo.MaxLength <= 0 then Exit;
|
||||
|
||||
CurrLength:= gtk_text_get_length(PGtkText(widget));
|
||||
if CurrLength + NewTextLength <= Memo.MaxLength then Exit;
|
||||
|
||||
CutLength:= CurrLength + NewTextLength - Memo.MaxLength;
|
||||
|
||||
if NewTextLength - CutLength > 0 then begin
|
||||
if NewTextLength - CutLength > 0 then
|
||||
gtk_editable_insert_text(PGtkEditable(widget), char,
|
||||
NewTextLength - CutLength, Position);
|
||||
end;
|
||||
|
||||
g_signal_stop_emission_by_name(PGtkObject(widget), 'insert_text');
|
||||
end;
|
||||
|
@ -1817,17 +1817,16 @@ end;
|
||||
class procedure TGtkWSCustomMemo.SetMaxLength(const ACustomEdit: TCustomEdit;
|
||||
NewLength: integer);
|
||||
var
|
||||
ImplWidget : PGtkWidget;
|
||||
ImplWidget: PGtkWidget;
|
||||
i: integer;
|
||||
begin
|
||||
if (ACustomEdit.MaxLength >= 0) then begin
|
||||
//debugln('TGtkWSCustomMemo.SetMaxLength ',DbgSName(ACustomEdit));
|
||||
ImplWidget:= GetWidgetInfo(PGtkWidget(ACustomEdit.Handle), true)^.CoreWidget;
|
||||
i:= gtk_text_get_length(GTK_TEXT(ImplWidget));
|
||||
if i > ACustomEdit.MaxLength then begin
|
||||
if (ACustomEdit.MaxLength > 0) then
|
||||
begin
|
||||
ImplWidget := GetWidgetInfo(PGtkWidget(ACustomEdit.Handle), true)^.CoreWidget;
|
||||
i := gtk_text_get_length(GTK_TEXT(ImplWidget));
|
||||
if i > ACustomEdit.MaxLength then
|
||||
gtk_editable_delete_text(PGtkOldEditable(ImplWidget),
|
||||
ACustomEdit.MaxLength, i);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -50,18 +50,19 @@ begin
|
||||
{ GTK2 does not provide its own max. length for memos
|
||||
so we have to do our own. }
|
||||
|
||||
if TControl(WidgetInfo^.LCLObject) is TCustomMemo then begin
|
||||
Memo:= TCustomMemo(WidgetInfo^.LCLObject);
|
||||
if Memo.MaxLength < 0 then Exit;
|
||||
if TControl(WidgetInfo^.LCLObject) is TCustomMemo then
|
||||
begin
|
||||
Memo := TCustomMemo(WidgetInfo^.LCLObject);
|
||||
if Memo.MaxLength <= 0 then Exit;
|
||||
|
||||
CurrLength:= gtk_text_buffer_get_char_count(TextBuffer);
|
||||
if CurrLength + NewTextLength <= Memo.MaxLength then Exit;
|
||||
CurrLength := gtk_text_buffer_get_char_count(TextBuffer);
|
||||
if CurrLength + NewTextLength <= Memo.MaxLength then
|
||||
Exit;
|
||||
|
||||
CutLength:= CurrLength + NewTextLength - Memo.MaxLength;
|
||||
CutLength := CurrLength + NewTextLength - Memo.MaxLength;
|
||||
|
||||
if NewTextLength - CutLength > 0 then begin
|
||||
if NewTextLength - CutLength > 0 then
|
||||
gtk_text_buffer_insert(TextBuffer, StartIter, TheText, NewTextLength - CutLength);
|
||||
end;
|
||||
|
||||
g_signal_stop_emission_by_name(PGtkObject(Textbuffer), 'insert-text');
|
||||
end;
|
||||
|
@ -4336,8 +4336,10 @@ end;
|
||||
|
||||
------------------------------------------------------------------------------}
|
||||
function TQtWidgetSet.SetFocus(hWnd: HWND): HWND;
|
||||
{$IFDEF UNIX}
|
||||
var
|
||||
QtEdit: IQtEdit;
|
||||
{$ENDIF}
|
||||
begin
|
||||
if hwnd<>0 then
|
||||
begin
|
||||
|
@ -96,6 +96,7 @@ type
|
||||
NewTraverseList: boolean); override;
|
||||
class procedure SetDropDownCount(const ACustomComboBox: TCustomComboBox; NewCount: 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 Sort(const ACustomComboBox: TCustomComboBox; AList: TStrings; IsSorted: boolean); override;
|
||||
@ -1320,6 +1321,28 @@ begin
|
||||
TQtComboBox(ACustomComboBox.Handle).setCurrentIndex(NewIndex);
|
||||
end;
|
||||
|
||||
class procedure TQtWSCustomComboBox.SetMaxLength(
|
||||
const ACustomComboBox: TCustomComboBox; NewLength: integer);
|
||||
var
|
||||
Widget: TQtWidget;
|
||||
QtEdit: IQtEdit;
|
||||
MaxLength: Integer;
|
||||
begin
|
||||
if not WSCheckHandleAllocated(ACustomComboBox, 'SetMaxLength') then
|
||||
Exit;
|
||||
|
||||
Widget := TQtWidget(ACustomComboBox.Handle);
|
||||
if Supports(Widget, IQtEdit, QtEdit) then
|
||||
begin
|
||||
// qt doesn't accept -1
|
||||
MaxLength := QtEdit.getMaxLength;
|
||||
if (NewLength <= 0) or (NewLength > QtMaxEditLength) then
|
||||
NewLength := QtMaxEditLength;
|
||||
if NewLength <> MaxLength then
|
||||
QtEdit.setMaxLength(NewLength);
|
||||
end;
|
||||
end;
|
||||
|
||||
class procedure TQtWSCustomComboBox.SetStyle(
|
||||
const ACustomComboBox: TCustomComboBox; NewStyle: TComboBoxStyle);
|
||||
begin
|
||||
|
@ -322,7 +322,7 @@ type
|
||||
procedure SetDroppedDown(const AValue: Boolean); virtual;
|
||||
procedure SetItemHeight(const AValue: Integer); virtual;
|
||||
procedure SetItemIndex(Val: integer); virtual;
|
||||
procedure SetMaxLength(Val: integer); virtual;
|
||||
procedure SetMaxLength(AValue: integer); virtual;
|
||||
procedure SetSelLength(Val: integer); virtual;
|
||||
procedure SetSelStart(Val: integer); virtual;
|
||||
procedure SetSelText(const Val: string); virtual;
|
||||
@ -384,9 +384,8 @@ type
|
||||
property SelStart: integer read GetSelStart write SetSelStart;// byte position
|
||||
property SelText: String read GetSelText write SetSelText;
|
||||
property Style: TComboBoxStyle read FStyle write SetStyle;
|
||||
property Text;
|
||||
published
|
||||
property TabStop default true;
|
||||
property Text;
|
||||
end;
|
||||
|
||||
|
||||
@ -729,7 +728,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 MaxLength: Integer read FMaxLength write SetMaxLength default -1;
|
||||
property MaxLength: Integer read FMaxLength write SetMaxLength default 0;
|
||||
property Modified: Boolean read GetModified write SetModified;
|
||||
property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
||||
property PasswordChar: Char read FPasswordChar write SetPasswordChar default #0;
|
||||
|
Loading…
Reference in New Issue
Block a user