Minor changes. Capture focus pressing calendar button. Allow paste from contextual menu

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8373 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
jujibo
2022-08-09 07:35:15 +00:00
parent 4c732f36c1
commit 814cf93414
11 changed files with 68 additions and 20 deletions

View File

@ -15,7 +15,7 @@
different kinds of data, floats, dates, etc. while working with different kinds of data, floats, dates, etc. while working with
db and non db controls."/> db and non db controls."/>
<License Value="LGPL with link exception. Read files license-jujiboutils and COPYING.LGPL"/> <License Value="LGPL with link exception. Read files license-jujiboutils and COPYING.LGPL"/>
<Version Major="2" Minor="5"/> <Version Major="2" Minor="5" Release="1"/>
<Files Count="36"> <Files Count="36">
<Item1> <Item1>
<Filename Value="src/jcontrolutils.pas"/> <Filename Value="src/jcontrolutils.pas"/>

View File

@ -35,7 +35,6 @@ type
theValue: TDateTime; theValue: TDateTime;
fFormat: string; fFormat: string;
FButton: TSpeedButton; FButton: TSpeedButton;
FButtonNeedsFocus: boolean;
function GetButtonWidth: integer; function GetButtonWidth: integer;
function getFormat: string; function getFormat: string;
function getValue: TDateTime; function getValue: TDateTime;
@ -311,6 +310,7 @@ var
PopupOrigin: TPoint; PopupOrigin: TPoint;
ADate: TDateTime; ADate: TDateTime;
begin begin
Self.SetFocus;
PopupOrigin := Self.ControlToScreen(Point(0, Self.Height)); PopupOrigin := Self.ControlToScreen(Point(0, Self.Height));
if isNull then if isNull then
ADate := now ADate := now

View File

@ -37,7 +37,6 @@ type
theValue: TDateTime; theValue: TDateTime;
fFormat: string; fFormat: string;
FButton: TSpeedButton; FButton: TSpeedButton;
FButtonNeedsFocus: boolean;
function GetButtonWidth: integer; function GetButtonWidth: integer;
function getFormat: string; function getFormat: string;
function getValue: TDateTime; function getValue: TDateTime;
@ -331,6 +330,7 @@ var
PopupOrigin: TPoint; PopupOrigin: TPoint;
ADate: TDateTime; ADate: TDateTime;
begin begin
Self.SetFocus;
PopupOrigin := Self.ControlToScreen(Point(0, Self.Height)); PopupOrigin := Self.ControlToScreen(Point(0, Self.Height));
if isNull then if isNull then
ADate := Now ADate := Now

View File

@ -35,7 +35,6 @@ type
FDataLink: TFieldDataLink; FDataLink: TFieldDataLink;
FButton: TSpeedButton; FButton: TSpeedButton;
FButtonNeedsFocus: boolean;
function GetButtonWidth: integer; function GetButtonWidth: integer;
procedure SetButtonWidth(AValue: integer); procedure SetButtonWidth(AValue: integer);
procedure WMSetFocus(var Message: TLMSetFocus); message LM_SETFOCUS; procedure WMSetFocus(var Message: TLMSetFocus); message LM_SETFOCUS;
@ -332,6 +331,7 @@ var
begin begin
if (not Assigned(FDataLink.Field)) or IsReadOnly then if (not Assigned(FDataLink.Field)) or IsReadOnly then
exit; exit;
Self.SetFocus;
PopupOrigin := Self.ControlToScreen(Point(0, Self.Height)); PopupOrigin := Self.ControlToScreen(Point(0, Self.Height));
if FDataLink.Field.IsNull then if FDataLink.Field.IsNull then
ADate := now ADate := now

View File

@ -35,7 +35,6 @@ type
FDataLink: TFieldDataLink; FDataLink: TFieldDataLink;
FButton: TSpeedButton; FButton: TSpeedButton;
FButtonNeedsFocus: boolean;
function GetButtonWidth: integer; function GetButtonWidth: integer;
procedure SetButtonWidth(AValue: integer); procedure SetButtonWidth(AValue: integer);
procedure WMSetFocus(var Message: TLMSetFocus); message LM_SETFOCUS; procedure WMSetFocus(var Message: TLMSetFocus); message LM_SETFOCUS;
@ -339,6 +338,7 @@ var
begin begin
if (not Assigned(FDataLink.Field)) or IsReadOnly then if (not Assigned(FDataLink.Field)) or IsReadOnly then
exit; exit;
Self.SetFocus;
PopupOrigin := Self.ControlToScreen(Point(0, Self.Height)); PopupOrigin := Self.ControlToScreen(Point(0, Self.Height));
if FDataLink.Field.IsNull then if FDataLink.Field.IsNull then
ADate := now ADate := now

View File

@ -32,6 +32,7 @@ type
TJDBEdit = class(TCustomEdit) TJDBEdit = class(TCustomEdit)
private private
FDataLink: TFieldDataLink; FDataLink: TFieldDataLink;
FUpdatingDisplayText: boolean;
procedure DataChange(Sender: TObject); procedure DataChange(Sender: TObject);
procedure UpdateData(Sender: TObject); procedure UpdateData(Sender: TObject);
@ -54,6 +55,7 @@ type
procedure KeyDown(var Key: word; Shift: TShiftState); override; procedure KeyDown(var Key: word; Shift: TShiftState); override;
procedure KeyPress(var Key: char); override; procedure KeyPress(var Key: char); override;
procedure DoEnter; override; procedure DoEnter; override;
procedure Change; override;
function GetReadOnly: boolean; override; function GetReadOnly: boolean; override;
procedure SetReadOnly(Value: boolean); override; procedure SetReadOnly(Value: boolean); override;
public public
@ -128,7 +130,11 @@ end;
procedure TJDBEdit.DataChange(Sender: TObject); procedure TJDBEdit.DataChange(Sender: TObject);
begin begin
if FDataLink.Field <> nil then if FDataLink.Field <> nil then
Caption := FDataLink.Field.AsString begin
FUpdatingDisplayText := True;
Caption := FDataLink.Field.AsString;
FUpdatingDisplayText := False;
end
else else
Text := ''; Text := '';
end; end;
@ -227,9 +233,7 @@ begin
else else
if Key in [VK_DELETE, VK_BACK] then if Key in [VK_DELETE, VK_BACK] then
begin begin
if not IsReadOnly then if IsReadOnly then
FDatalink.Edit
else
Key := VK_UNKNOWN; Key := VK_UNKNOWN;
end; end;
end; end;
@ -246,10 +250,30 @@ begin
if not FieldIsEditable(Field) or IsReadOnly then if not FieldIsEditable(Field) or IsReadOnly then
exit; exit;
if FDataLink.Field <> nil then if FDataLink.Field <> nil then
begin
FUpdatingDisplayText := True;
Caption := FDataLink.Field.AsString; Caption := FDataLink.Field.AsString;
FUpdatingDisplayText := False;
end;
inherited DoEnter; inherited DoEnter;
end; end;
procedure TJDBEdit.Change;
var
s: string;
apos: integer;
begin
if (not IsReadOnly) and (not FUpdatingDisplayText) and (not FDataLink.Editing) then
begin
s := Caption;
apos:= SelStart;
FDatalink.Edit;
Caption := s;
SelStart:= apos;
end;
inherited Change;
end;
function TJDBEdit.GetReadOnly: boolean; function TJDBEdit.GetReadOnly: boolean;
begin begin
Result := FDataLink.ReadOnly; Result := FDataLink.ReadOnly;
@ -270,6 +294,7 @@ begin
FDataLink.OnDataChange := @DataChange; FDataLink.OnDataChange := @DataChange;
FDataLink.OnUpdateData := @UpdateData; FDataLink.OnUpdateData := @UpdateData;
FDataLInk.OnActiveChange := @ActiveChange; FDataLInk.OnActiveChange := @ActiveChange;
FUpdatingDisplayText := False;
end; end;
destructor TJDBEdit.Destroy; destructor TJDBEdit.Destroy;
@ -289,4 +314,3 @@ begin
end; end;
end. end.

View File

@ -35,7 +35,6 @@ type
FDataLink: TFieldDataLink; FDataLink: TFieldDataLink;
FButton: TSpeedButton; FButton: TSpeedButton;
FButtonNeedsFocus: boolean;
function GetButtonWidth: integer; function GetButtonWidth: integer;
procedure SetButtonWidth(AValue: integer); procedure SetButtonWidth(AValue: integer);
procedure WMSetFocus(var Message: TLMSetFocus); message LM_SETFOCUS; procedure WMSetFocus(var Message: TLMSetFocus); message LM_SETFOCUS;
@ -335,6 +334,7 @@ var
begin begin
if (not Assigned(FDataLink.Field)) or IsReadOnly then if (not Assigned(FDataLink.Field)) or IsReadOnly then
exit; exit;
Self.SetFocus;
PopupOrigin := Self.ControlToScreen(Point(0, Self.Height)); PopupOrigin := Self.ControlToScreen(Point(0, Self.Height));
if FDataLink.Field.IsNull then if FDataLink.Field.IsNull then
ADate := now ADate := now

View File

@ -35,7 +35,6 @@ type
FDataLink: TFieldDataLink; FDataLink: TFieldDataLink;
FButton: TSpeedButton; FButton: TSpeedButton;
FButtonNeedsFocus: boolean;
function GetButtonWidth: integer; function GetButtonWidth: integer;
procedure SetButtonWidth(AValue: integer); procedure SetButtonWidth(AValue: integer);
procedure WMSetFocus(var Message: TLMSetFocus); message LM_SETFOCUS; procedure WMSetFocus(var Message: TLMSetFocus); message LM_SETFOCUS;
@ -342,6 +341,7 @@ var
begin begin
if (not Assigned(FDataLink.Field)) or IsReadOnly then if (not Assigned(FDataLink.Field)) or IsReadOnly then
exit; exit;
Self.SetFocus;
PopupOrigin := Self.ControlToScreen(Point(0, Self.Height)); PopupOrigin := Self.ControlToScreen(Point(0, Self.Height));
if FDataLink.Field.IsNull then if FDataLink.Field.IsNull then
ADate := now ADate := now

View File

@ -32,6 +32,7 @@ type
TJDBLabeledEdit = class(TCustomLabeledEdit) TJDBLabeledEdit = class(TCustomLabeledEdit)
private private
FDataLink: TFieldDataLink; FDataLink: TFieldDataLink;
FUpdatingDisplayText: boolean;
procedure DataChange(Sender: TObject); procedure DataChange(Sender: TObject);
procedure UpdateData(Sender: TObject); procedure UpdateData(Sender: TObject);
@ -54,6 +55,7 @@ type
procedure KeyDown(var Key: word; Shift: TShiftState); override; procedure KeyDown(var Key: word; Shift: TShiftState); override;
procedure KeyPress(var Key: char); override; procedure KeyPress(var Key: char); override;
procedure DoEnter; override; procedure DoEnter; override;
procedure Change; override;
function GetReadOnly: boolean; override; function GetReadOnly: boolean; override;
procedure SetReadOnly(Value: boolean); override; procedure SetReadOnly(Value: boolean); override;
public public
@ -131,7 +133,11 @@ end;
procedure TJDBLabeledEdit.DataChange(Sender: TObject); procedure TJDBLabeledEdit.DataChange(Sender: TObject);
begin begin
if FDataLink.Field <> nil then if FDataLink.Field <> nil then
Caption := FDataLink.Field.AsString begin
FUpdatingDisplayText := True;
Caption := FDataLink.Field.AsString;
FUpdatingDisplayText := False;
end
else else
Text := ''; Text := '';
end; end;
@ -230,9 +236,7 @@ begin
else else
if Key in [VK_DELETE, VK_BACK] then if Key in [VK_DELETE, VK_BACK] then
begin begin
if not IsReadOnly then if IsReadOnly then
FDatalink.Edit
else
Key := VK_UNKNOWN; Key := VK_UNKNOWN;
end; end;
end; end;
@ -249,10 +253,30 @@ begin
if not FieldIsEditable(Field) or IsReadOnly then if not FieldIsEditable(Field) or IsReadOnly then
exit; exit;
if FDataLink.Field <> nil then if FDataLink.Field <> nil then
begin
FUpdatingDisplayText := True;
Caption := FDataLink.Field.AsString; Caption := FDataLink.Field.AsString;
FUpdatingDisplayText := False;
end;
inherited DoEnter; inherited DoEnter;
end; end;
procedure TJDBLabeledEdit.Change;
var
s: string;
apos: integer;
begin
if (not IsReadOnly) and (not FUpdatingDisplayText) and (not FDataLink.Editing) then
begin
s := Caption;
apos:= SelStart;
FDatalink.Edit;
Caption := s;
SelStart:= apos;
end;
inherited Change;
end;
function TJDBLabeledEdit.GetReadOnly: boolean; function TJDBLabeledEdit.GetReadOnly: boolean;
begin begin
Result := FDataLink.ReadOnly; Result := FDataLink.ReadOnly;
@ -273,6 +297,7 @@ begin
FDataLink.OnDataChange := @DataChange; FDataLink.OnDataChange := @DataChange;
FDataLink.OnUpdateData := @UpdateData; FDataLink.OnUpdateData := @UpdateData;
FDataLInk.OnActiveChange := @ActiveChange; FDataLInk.OnActiveChange := @ActiveChange;
FUpdatingDisplayText := False;
end; end;
destructor TJDBLabeledEdit.Destroy; destructor TJDBLabeledEdit.Destroy;
@ -292,4 +317,3 @@ begin
end; end;
end. end.

View File

@ -35,7 +35,6 @@ type
theValue: TDateTime; theValue: TDateTime;
fFormat: string; fFormat: string;
FButton: TSpeedButton; FButton: TSpeedButton;
FButtonNeedsFocus: boolean;
function GetButtonWidth: integer; function GetButtonWidth: integer;
function getFormat: string; function getFormat: string;
function getValue: TDateTime; function getValue: TDateTime;
@ -314,6 +313,7 @@ var
PopupOrigin: TPoint; PopupOrigin: TPoint;
ADate: TDateTime; ADate: TDateTime;
begin begin
Self.SetFocus;
PopupOrigin := Self.ControlToScreen(Point(0, Self.Height)); PopupOrigin := Self.ControlToScreen(Point(0, Self.Height));
if isNull then if isNull then
ADate := now ADate := now

View File

@ -37,7 +37,6 @@ type
theValue: TDateTime; theValue: TDateTime;
fFormat: string; fFormat: string;
FButton: TSpeedButton; FButton: TSpeedButton;
FButtonNeedsFocus: boolean;
function GetButtonWidth: integer; function GetButtonWidth: integer;
function getFormat: string; function getFormat: string;
function getValue: TDateTime; function getValue: TDateTime;
@ -334,6 +333,7 @@ var
PopupOrigin: TPoint; PopupOrigin: TPoint;
ADate: TDateTime; ADate: TDateTime;
begin begin
Self.SetFocus;
PopupOrigin := Self.ControlToScreen(Point(0, Self.Height)); PopupOrigin := Self.ControlToScreen(Point(0, Self.Height));
if isNull then if isNull then
ADate := Now ADate := Now