mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-29 23:30:22 +02:00
LCL: dialogs: create a generic solution for dialog copy to clipboard.
git-svn-id: trunk@52308 -
This commit is contained in:
parent
5b3cd06ae3
commit
f6175a256f
@ -25,7 +25,7 @@ uses
|
|||||||
Types, typinfo, Classes, SysUtils, LMessages,
|
Types, typinfo, Classes, SysUtils, LMessages,
|
||||||
LResources, LCLIntf, InterfaceBase, LCLStrConsts, LCLType, LCLProc, Forms,
|
LResources, LCLIntf, InterfaceBase, LCLStrConsts, LCLType, LCLProc, Forms,
|
||||||
Controls, Themes, GraphType, Graphics, Buttons, ButtonPanel, StdCtrls,
|
Controls, Themes, GraphType, Graphics, Buttons, ButtonPanel, StdCtrls,
|
||||||
ExtCtrls, LCLClasses, ClipBrd,
|
ExtCtrls, LCLClasses, ClipBrd, Menus,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
FileUtil, LazFileUtils;
|
FileUtil, LazFileUtils;
|
||||||
|
|
||||||
@ -535,6 +535,17 @@ function DefaultMessageBox(Text, Caption: PChar; Flags: Longint) : Integer;// wi
|
|||||||
function InputBox(const ACaption, APrompt, ADefault : String) : String;
|
function InputBox(const ACaption, APrompt, ADefault : String) : String;
|
||||||
function PasswordBox(const ACaption, APrompt : String) : String;
|
function PasswordBox(const ACaption, APrompt : String) : String;
|
||||||
|
|
||||||
|
type
|
||||||
|
TCustomCopyToClipboardDialog = class(TForm)
|
||||||
|
protected
|
||||||
|
procedure DoCreate; override;
|
||||||
|
public
|
||||||
|
function GetMessageText: string; virtual; abstract;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure RegisterDialogForCopyToClipboard(const ADlg: TCustomForm);
|
||||||
|
procedure DialogCopyToClipboard(Self, Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||||
|
|
||||||
const
|
const
|
||||||
cInputQueryEditSizePixels: integer = 260; // Edit size in pixels
|
cInputQueryEditSizePixels: integer = 260; // Edit size in pixels
|
||||||
cInputQueryEditSizePercents: integer = 25; // Edit size in % of monitor width
|
cInputQueryEditSizePercents: integer = 25; // Edit size in % of monitor width
|
||||||
@ -753,6 +764,14 @@ begin
|
|||||||
FCopies:=1;
|
FCopies:=1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TCustomCopyToClipboardDialog }
|
||||||
|
|
||||||
|
procedure TCustomCopyToClipboardDialog.DoCreate;
|
||||||
|
begin
|
||||||
|
inherited DoCreate;
|
||||||
|
|
||||||
|
RegisterDialogForCopyToClipboard(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
Forms.MessageBoxFunction := @DefaultMessageBox;
|
Forms.MessageBoxFunction := @DefaultMessageBox;
|
||||||
|
@ -178,8 +178,8 @@ begin
|
|||||||
Result:=MessageDlg(aCaption, aMsg, DlgType, Buttons, 0);
|
Result:=MessageDlg(aCaption, aMsg, DlgType, Buttons, 0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function MessageDlgPos(const aMsg: String; DlgType: TMsgDlgType;
|
function MessageDlgPos(const aMsg: string; DlgType: TMsgDlgType;
|
||||||
Buttons: TMsgDlgButtons; Helpctx : Longint; X,Y : Integer): TModalResult;
|
Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer): TModalResult;
|
||||||
var
|
var
|
||||||
DefaultIndex,
|
DefaultIndex,
|
||||||
CancelValue,
|
CancelValue,
|
||||||
@ -231,6 +231,55 @@ begin
|
|||||||
InputQuery(ACaption, APrompt, True, Result);
|
InputQuery(ACaption, APrompt, True, Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure DialogCopyToClipboard(Self, Sender: TObject; var Key: Word;
|
||||||
|
Shift: TShiftState);
|
||||||
|
var
|
||||||
|
S: string;
|
||||||
|
Dlg: TCustomForm;
|
||||||
|
Cnt, LastCnt: TControl;
|
||||||
|
begin
|
||||||
|
if not ((Key=VK_C) and (Shift = [ssModifier])) then
|
||||||
|
Exit;
|
||||||
|
|
||||||
|
Dlg := Self as TCustomForm;
|
||||||
|
|
||||||
|
S := Format('[%s]', [Dlg.Caption]) + sLineBreak;
|
||||||
|
LastCnt := nil;
|
||||||
|
|
||||||
|
if Dlg is TCustomCopyToClipboardDialog then
|
||||||
|
S := S + sLineBreak + TCustomCopyToClipboardDialog(Dlg).GetMessageText + sLineBreak;
|
||||||
|
|
||||||
|
for Cnt in Dlg.GetEnumeratorControls do
|
||||||
|
begin
|
||||||
|
if (Cnt is TCustomLabel) then
|
||||||
|
begin
|
||||||
|
S := S + sLineBreak + Cnt.Caption + sLineBreak;
|
||||||
|
LastCnt := nil;
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
if (LastCnt=nil) or (LastCnt.Top > Cnt.Top) then
|
||||||
|
S := S + sLineBreak+sLineBreak
|
||||||
|
else
|
||||||
|
S := S + ' ';
|
||||||
|
|
||||||
|
S := S + Format('[%s]', [StripHotKey(Cnt.Caption)]);
|
||||||
|
LastCnt := Cnt;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Clipboard.AsText := TrimRight(S);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure RegisterDialogForCopyToClipboard(const ADlg: TCustomForm);
|
||||||
|
var
|
||||||
|
Mtd: TMethod;
|
||||||
|
begin
|
||||||
|
ADlg.KeyPreview := True;
|
||||||
|
Mtd.Code := @DialogCopyToClipboard;
|
||||||
|
Mtd.Data := ADlg;
|
||||||
|
ADlg.AddHandlerOnKeyDown(TKeyEvent(Mtd));
|
||||||
|
end;
|
||||||
|
|
||||||
function SelectDirectory(const Caption, InitialDirectory: string;
|
function SelectDirectory(const Caption, InitialDirectory: string;
|
||||||
out Directory: string): boolean;
|
out Directory: string): boolean;
|
||||||
begin
|
begin
|
||||||
|
@ -13,12 +13,10 @@ type
|
|||||||
|
|
||||||
{ TPromptDialog }
|
{ TPromptDialog }
|
||||||
|
|
||||||
TPromptDialog = class(TForm)
|
TPromptDialog = class(TCustomCopyToClipboardDialog)
|
||||||
private
|
private
|
||||||
FCancelKind: TBitBtnKind;
|
FCancelKind: TBitBtnKind;
|
||||||
function CreateButtons(AVerticalLayout: Boolean; ASpacing: Integer): Integer;
|
function CreateButtons(AVerticalLayout: Boolean; ASpacing: Integer): Integer;
|
||||||
protected
|
|
||||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
|
||||||
public
|
public
|
||||||
IsSmallDevice: Boolean;
|
IsSmallDevice: Boolean;
|
||||||
|
|
||||||
@ -38,6 +36,7 @@ type
|
|||||||
constructor CreateMessageDialog(const ACaption, aMsg: string;
|
constructor CreateMessageDialog(const ACaption, aMsg: string;
|
||||||
DialogType: Longint; TheButtons: PLongint; ButtonCount, DefaultIndex : Longint);
|
DialogType: Longint; TheButtons: PLongint; ButtonCount, DefaultIndex : Longint);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
function GetMessageText: string; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -91,16 +90,6 @@ begin
|
|||||||
DefaultButton.Default := True;
|
DefaultButton.Default := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPromptDialog.KeyDown(var Key: Word; Shift: TShiftState);
|
|
||||||
begin
|
|
||||||
inherited KeyDown(Key, Shift);
|
|
||||||
if (Shift = [ssModifier]) and (Key = VK_C) then
|
|
||||||
begin
|
|
||||||
Key := 0;
|
|
||||||
ClipBoard.AsText := MSG;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TPromptDialog.Paint;
|
procedure TPromptDialog.Paint;
|
||||||
var
|
var
|
||||||
UseMaskHandle: HBitmap;
|
UseMaskHandle: HBitmap;
|
||||||
@ -130,7 +119,6 @@ var
|
|||||||
curKind: TBitBtnKind;
|
curKind: TBitBtnKind;
|
||||||
begin
|
begin
|
||||||
inherited CreateNew(nil, 1);
|
inherited CreateNew(nil, 1);
|
||||||
KeyPreview := True; //needed for capturing Ctrl+C in KeyDown
|
|
||||||
IsSmallDevice := (Screen.Width <= 300);
|
IsSmallDevice := (Screen.Width <= 300);
|
||||||
|
|
||||||
AutoScroll := False;
|
AutoScroll := False;
|
||||||
@ -217,6 +205,11 @@ begin
|
|||||||
inherited destroy;
|
inherited destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TPromptDialog.GetMessageText: string;
|
||||||
|
begin
|
||||||
|
Result := MSG;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TPromptDialog.LayoutDialog;
|
procedure TPromptDialog.LayoutDialog;
|
||||||
const
|
const
|
||||||
cBtnCalcWidth = 50;
|
cBtnCalcWidth = 50;
|
||||||
@ -544,7 +537,7 @@ type
|
|||||||
|
|
||||||
{ TQuestionDlg }
|
{ TQuestionDlg }
|
||||||
|
|
||||||
TQuestionDlg = class(TForm)
|
TQuestionDlg = class(TCustomCopyToClipboardDialog)
|
||||||
private
|
private
|
||||||
FButtons: TList;
|
FButtons: TList;
|
||||||
FBitmap: TCustomBitmap;
|
FBitmap: TCustomBitmap;
|
||||||
@ -563,6 +556,7 @@ type
|
|||||||
procedure Paint; override;
|
procedure Paint; override;
|
||||||
procedure LayoutDialog;
|
procedure LayoutDialog;
|
||||||
function ShowModal: TModalResult; override;
|
function ShowModal: TModalResult; override;
|
||||||
|
function GetMessageText: string; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TQuestionDlg }
|
{ TQuestionDlg }
|
||||||
@ -863,6 +857,11 @@ begin
|
|||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TQuestionDlg.GetMessageText: string;
|
||||||
|
begin
|
||||||
|
Result := MessageTxt;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TQuestionDlg.KeyDown(var Key: Word; Shift: TShiftState);
|
procedure TQuestionDlg.KeyDown(var Key: Word; Shift: TShiftState);
|
||||||
begin
|
begin
|
||||||
if (Key = VK_ESCAPE) and (CancelControl = nil) then
|
if (Key = VK_ESCAPE) and (CancelControl = nil) then
|
||||||
|
Loading…
Reference in New Issue
Block a user