mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-10-03 09:59:28 +02:00
cocoa: changed the way MaxLength is being passed to cocoa interface (adding new method, instead of direct field access). Implemented ontextchange event for password field. bug #36158
git-svn-id: trunk@62054 -
This commit is contained in:
parent
36a89981da
commit
343916af31
@ -55,9 +55,13 @@ type
|
||||
|
||||
TCocoaFieldEditor = objcclass;
|
||||
|
||||
NSTextField_LCLExt = objcprotocol
|
||||
procedure lclSetMaxLength(amax: integer); message 'lclSetMaxLength:';
|
||||
end;
|
||||
|
||||
{ TCocoaTextField }
|
||||
|
||||
TCocoaTextField = objcclass(NSTextField)
|
||||
TCocoaTextField = objcclass(NSTextField, NSTextField_LCLExt)
|
||||
callback: ICommonCallback;
|
||||
maxLength: Integer;
|
||||
function acceptsFirstResponder: LCLObjCBoolean; override;
|
||||
@ -75,18 +79,22 @@ type
|
||||
procedure otherMouseUp(event: NSEvent); override;
|
||||
procedure mouseDragged(event: NSEvent); override;
|
||||
procedure mouseMoved(event: NSEvent); override;
|
||||
|
||||
procedure lclSetMaxLength(amax: integer);
|
||||
end;
|
||||
|
||||
{ TCocoaSecureTextField }
|
||||
|
||||
TCocoaSecureTextField = objcclass(NSSecureTextField)
|
||||
TCocoaSecureTextField = objcclass(NSSecureTextField, NSTextField_LCLExt)
|
||||
public
|
||||
maxLength: Integer;
|
||||
callback: ICommonCallback;
|
||||
function acceptsFirstResponder: LCLObjCBoolean; override;
|
||||
procedure resetCursorRects; override;
|
||||
function lclGetCallback: ICommonCallback; override;
|
||||
procedure lclClearCallback; override;
|
||||
// key
|
||||
procedure textDidChange(notification: NSNotification); override;
|
||||
// mouse
|
||||
procedure mouseDown(event: NSEvent); override;
|
||||
procedure mouseUp(event: NSEvent); override;
|
||||
@ -96,6 +104,8 @@ type
|
||||
procedure otherMouseUp(event: NSEvent); override;
|
||||
procedure mouseDragged(event: NSEvent); override;
|
||||
procedure mouseMoved(event: NSEvent); override;
|
||||
|
||||
procedure lclSetMaxLength(amax: integer);
|
||||
end;
|
||||
|
||||
{ TCocoaTextView }
|
||||
@ -981,6 +991,11 @@ begin
|
||||
inherited mouseMoved(event);
|
||||
end;
|
||||
|
||||
procedure TCocoaTextField.lclSetMaxLength(amax: integer);
|
||||
begin
|
||||
maxLength := amax;
|
||||
end;
|
||||
|
||||
{ TCocoaTextView }
|
||||
|
||||
procedure TCocoaTextView.changeColor(sender: id);
|
||||
@ -1174,6 +1189,15 @@ begin
|
||||
callback := nil;
|
||||
end;
|
||||
|
||||
procedure TCocoaSecureTextField.textDidChange(notification: NSNotification);
|
||||
begin
|
||||
inherited;
|
||||
if (maxLength>0) and Assigned(stringValue) and (stringValue.length > maxLength) then
|
||||
setStringValue(stringValue.substringWithRange(NSMakeRange(0,maxLength)));
|
||||
if callback <> nil then
|
||||
callback.SendOnTextChanged;
|
||||
end;
|
||||
|
||||
procedure TCocoaSecureTextField.mouseDown(event: NSEvent);
|
||||
begin
|
||||
if Assigned(callback) and not callback.MouseUpDownEvent(event) then
|
||||
@ -1227,6 +1251,11 @@ begin
|
||||
inherited mouseMoved(event);
|
||||
end;
|
||||
|
||||
procedure TCocoaSecureTextField.lclSetMaxLength(amax: integer);
|
||||
begin
|
||||
MaxLength := amax;
|
||||
end;
|
||||
|
||||
{ TCocoaEditComboBoxList }
|
||||
|
||||
procedure TCocoaEditComboBoxList.InsertItem(Index: Integer; const S: string;
|
||||
|
@ -1007,11 +1007,14 @@ end;
|
||||
class procedure TCocoaWSCustomEdit.SetMaxLength(const ACustomEdit: TCustomEdit;
|
||||
NewLength: integer);
|
||||
var
|
||||
field: TCocoaTextField;
|
||||
field: NSTextField;
|
||||
begin
|
||||
field := GetTextField(ACustomEdit);
|
||||
if not (ACustomEdit.HandleAllocated) then Exit;
|
||||
field := NSTextField(ACustomEdit.Handle);
|
||||
if not Assigned(field) then Exit;
|
||||
field.maxLength := NewLength;
|
||||
|
||||
if NSObject(field).respondsToSelector( ObjCSelector('lclSetMaxLength:') ) then
|
||||
{%H-}NSTextField_LCLExt(field).lclSetMaxLength(NewLength);
|
||||
end;
|
||||
|
||||
class procedure TCocoaWSCustomEdit.SetPasswordChar(const ACustomEdit: TCustomEdit; NewChar: char);
|
||||
|
Loading…
Reference in New Issue
Block a user