lcl, win32, wince: use system cut, copy, paste operations for TEdit control and descendants

git-svn-id: trunk@26480 -
This commit is contained in:
paul 2010-07-06 11:43:02 +00:00
parent 47760320eb
commit 321a2f3d30
4 changed files with 64 additions and 11 deletions

View File

@ -240,8 +240,8 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCustomEdit.CopyToClipboard; procedure TCustomEdit.CopyToClipboard;
begin begin
if (EchoMode = emNormal) and (SelLength > 0) then if HandleAllocated then
Clipboard.AsText := SelText; TWSCustomEditClass(WidgetSetClass).Copy(Self);
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -253,14 +253,14 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCustomEdit.CutToClipboard; procedure TCustomEdit.CutToClipboard;
begin begin
CopyToClipboard; if HandleAllocated then
ClearSelection; TWSCustomEditClass(WidgetSetClass).Cut(Self);
end; end;
procedure TCustomEdit.PasteFromClipboard; procedure TCustomEdit.PasteFromClipboard;
begin begin
if Clipboard.HasFormat(CF_TEXT) then if HandleAllocated then
SelText := Clipboard.AsText; TWSCustomEditClass(WidgetSetClass).Paste(Self);
end; end;
procedure TCustomEdit.Undo; procedure TCustomEdit.Undo;

View File

@ -174,6 +174,9 @@ type
class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); override; class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); override;
class procedure SetText(const AWinControl: TWinControl; const AText: string); override; class procedure SetText(const AWinControl: TWinControl; const AText: string); override;
class procedure Cut(const ACustomEdit: TCustomEdit); override;
class procedure Copy(const ACustomEdit: TCustomEdit); override;
class procedure Paste(const ACustomEdit: TCustomEdit); override;
class procedure Undo(const ACustomEdit: TCustomEdit); override; class procedure Undo(const ACustomEdit: TCustomEdit); override;
end; end;
@ -1185,10 +1188,23 @@ begin
TWin32WSWinControl.SetText(ACustomEdit, AText); TWin32WSWinControl.SetText(ACustomEdit, AText);
end; end;
class procedure TWin32WSCustomEdit.Cut(const ACustomEdit: TCustomEdit);
begin
SendMessage(ACustomEdit.Handle, WM_CUT, 0, 0)
end;
class procedure TWin32WSCustomEdit.Copy(const ACustomEdit: TCustomEdit);
begin
SendMessage(ACustomEdit.Handle, WM_COPY, 0, 0)
end;
class procedure TWin32WSCustomEdit.Paste(const ACustomEdit: TCustomEdit);
begin
SendMessage(ACustomEdit.Handle, WM_PASTE, 0, 0)
end;
class procedure TWin32WSCustomEdit.Undo(const ACustomEdit: TCustomEdit); class procedure TWin32WSCustomEdit.Undo(const ACustomEdit: TCustomEdit);
begin begin
if not WSCheckHandleAllocated(ACustomEdit, 'Undo') then
Exit;
SendMessage(ACustomEdit.Handle, EM_UNDO, 0, 0) SendMessage(ACustomEdit.Handle, EM_UNDO, 0, 0)
end; end;

View File

@ -162,6 +162,9 @@ type
class procedure SetSelStart(const ACustomEdit: TCustomEdit; NewStart: integer); override; class procedure SetSelStart(const ACustomEdit: TCustomEdit; NewStart: integer); override;
class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); override; class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); override;
class procedure Cut(const ACustomEdit: TCustomEdit); override;
class procedure Copy(const ACustomEdit: TCustomEdit); override;
class procedure Paste(const ACustomEdit: TCustomEdit); override;
class procedure Undo(const ACustomEdit: TCustomEdit); override; class procedure Undo(const ACustomEdit: TCustomEdit); override;
end; end;
@ -981,10 +984,23 @@ begin
EditSetSelLength(ACustomEdit.Handle, NewLength); EditSetSelLength(ACustomEdit.Handle, NewLength);
end; end;
class procedure TWinCEWSCustomEdit.Cut(const ACustomEdit: TCustomEdit);
begin
SendMessage(ACustomEdit.Handle, WM_CUT, 0, 0)
end;
class procedure TWinCEWSCustomEdit.Copy(const ACustomEdit: TCustomEdit);
begin
SendMessage(ACustomEdit.Handle, WM_COPY, 0, 0)
end;
class procedure TWinCEWSCustomEdit.Paste(const ACustomEdit: TCustomEdit);
begin
SendMessage(ACustomEdit.Handle, WM_PASTE, 0, 0)
end;
class procedure TWinCEWSCustomEdit.Undo(const ACustomEdit: TCustomEdit); class procedure TWinCEWSCustomEdit.Undo(const ACustomEdit: TCustomEdit);
begin begin
if not WSCheckHandleAllocated(ACustomEdit, 'Undo') then
Exit;
SendMessage(ACustomEdit.Handle, EM_UNDO, 0, 0) SendMessage(ACustomEdit.Handle, EM_UNDO, 0, 0)
end; end;

View File

@ -46,7 +46,7 @@ uses
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
StdCtrls, Graphics, StdCtrls, Graphics,
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
WSLCLClasses, WSControls, Classes, WSFactory; WSLCLClasses, WSControls, Classes, WSFactory, Clipbrd;
type type
{ TWSScrollBar } { TWSScrollBar }
@ -157,6 +157,9 @@ type
class procedure SetSelStart(const ACustomEdit: TCustomEdit; NewStart: integer); virtual; class procedure SetSelStart(const ACustomEdit: TCustomEdit; NewStart: integer); virtual;
class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); virtual; class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); virtual;
class procedure Cut(const ACustomEdit: TCustomEdit); virtual;
class procedure Copy(const ACustomEdit: TCustomEdit); virtual;
class procedure Paste(const ACustomEdit: TCustomEdit); virtual;
class procedure Undo(const ACustomEdit: TCustomEdit); virtual; class procedure Undo(const ACustomEdit: TCustomEdit); virtual;
end; end;
TWSCustomEditClass = class of TWSCustomEdit; TWSCustomEditClass = class of TWSCustomEdit;
@ -521,6 +524,24 @@ class procedure TWSCustomEdit.SetSelLength(const ACustomEdit: TCustomEdit; NewLe
begin begin
end; end;
class procedure TWSCustomEdit.Cut(const ACustomEdit: TCustomEdit);
begin
ACustomEdit.CopyToClipboard;
ACustomEdit.ClearSelection;
end;
class procedure TWSCustomEdit.Copy(const ACustomEdit: TCustomEdit);
begin
if (ACustomEdit.EchoMode = emNormal) and (ACustomEdit.SelLength > 0) then
Clipboard.AsText := ACustomEdit.SelText;
end;
class procedure TWSCustomEdit.Paste(const ACustomEdit: TCustomEdit);
begin
if Clipboard.HasFormat(CF_TEXT) then
ACustomEdit.SelText := Clipboard.AsText;
end;
class procedure TWSCustomEdit.Undo(const ACustomEdit: TCustomEdit); class procedure TWSCustomEdit.Undo(const ACustomEdit: TCustomEdit);
begin begin
// nothing // nothing