LCL: added OnFilesDrop event to TCustomForm, TApplication and TApplicationProperties

* created example application
* implemented in Win32 interface

git-svn-id: trunk@11365 -
This commit is contained in:
tombo 2007-06-24 10:17:46 +00:00
parent 1d07b0dfd1
commit 6860a97e2b
16 changed files with 435 additions and 2 deletions

8
.gitattributes vendored
View File

@ -1171,6 +1171,14 @@ examples/exploremenu/exploreidemenu.pas svneol=native#text/plain
examples/exploremenu/frmexploremenu.lfm svneol=native#text/plain
examples/exploremenu/frmexploremenu.lrs svneol=native#text/plain
examples/exploremenu/frmexploremenu.pas svneol=native#text/plain
examples/filesdrop/filesdrop.lpi svneol=native#text/plain
examples/filesdrop/filesdrop.lpr svneol=native#text/pascal
examples/filesdrop/unit1.lfm svneol=native#text/plain
examples/filesdrop/unit1.lrs svneol=native#text/plain
examples/filesdrop/unit1.pas svneol=native#text/pascal
examples/filesdrop/unit2.lfm svneol=native#text/plain
examples/filesdrop/unit2.lrs svneol=native#text/plain
examples/filesdrop/unit2.pas svneol=native#text/pascal
examples/fontenum/fontenumeration.lpi svneol=native#text/plain
examples/fontenum/fontenumeration.lpr svneol=native#text/pascal
examples/fontenum/mainunit.lfm svneol=native#text/plain

1
.gitignore vendored
View File

@ -262,6 +262,7 @@ examples/easter/*.bak
examples/easter/units
examples/exploremenu/*.bak
examples/exploremenu/units
examples/filesdrop/units[!!-~]*.bak
examples/fontenum/*.bak
examples/fontenum/units
examples/grid_semaphor/*.bak

View File

@ -0,0 +1,116 @@
<?xml version="1.0"?>
<CONFIG>
<ProjectOptions>
<PathDelim Value="\"/>
<Version Value="5"/>
<General>
<MainUnit Value="0"/>
<TargetFileExt Value=".exe"/>
<ActiveEditorIndexAtStart Value="0"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
<Language Value=""/>
<CharSet Value=""/>
</VersionInfo>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</RunParams>
<RequiredPackages Count="1">
<Item1>
<PackageName Value="LCL"/>
</Item1>
</RequiredPackages>
<Units Count="4">
<Unit0>
<Filename Value="filesdrop.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="filesdrop"/>
<CursorPos X="13" Y="17"/>
<TopLine Value="1"/>
<UsageCount Value="20"/>
</Unit0>
<Unit1>
<Filename Value="unit1.pas"/>
<ComponentName Value="Form1"/>
<IsPartOfProject Value="True"/>
<ResourceFilename Value="unit1.lrs"/>
<UnitName Value="Unit1"/>
<CursorPos X="82" Y="48"/>
<TopLine Value="24"/>
<EditorIndex Value="0"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit1>
<Unit2>
<Filename Value="..\..\lcl\forms.pp"/>
<UnitName Value="Forms"/>
<CursorPos X="3" Y="567"/>
<TopLine Value="627"/>
<UsageCount Value="10"/>
</Unit2>
<Unit3>
<Filename Value="unit2.pas"/>
<ComponentName Value="Form2"/>
<IsPartOfProject Value="True"/>
<ResourceFilename Value="unit2.lrs"/>
<UnitName Value="Unit2"/>
<CursorPos X="89" Y="37"/>
<TopLine Value="17"/>
<EditorIndex Value="1"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit3>
</Units>
<JumpHistory Count="3" HistoryIndex="2">
<Position1>
<Filename Value="unit1.pas"/>
<Caret Line="43" Column="9" TopLine="17"/>
</Position1>
<Position2>
<Filename Value="unit2.pas"/>
<Caret Line="28" Column="7" TopLine="13"/>
</Position2>
<Position3>
<Filename Value="unit1.pas"/>
<Caret Line="38" Column="70" TopLine="27"/>
</Position3>
</JumpHistory>
</ProjectOptions>
<CompilerOptions>
<Version Value="5"/>
<PathDelim Value="\"/>
<CodeGeneration>
<Generate Value="Faster"/>
</CodeGeneration>
<Linking>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions Count="2">
<Item1>
<Name Value="ECodetoolError"/>
</Item1>
<Item2>
<Name Value="EFOpenError"/>
</Item2>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,20 @@
program filesdrop;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms
{ add your units here }, Unit1, Unit2;
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm2, Form2);
Form2.Show;
Application.Run;
end.

View File

@ -0,0 +1,39 @@
object Form1: TForm1
Left = 299
Height = 353
Top = 155
Width = 701
HorzScrollBar.Page = 700
VertScrollBar.Page = 352
Caption = 'On Files Drop event example'
ClientHeight = 353
ClientWidth = 701
OnFilesDrop = FormFilesDrop
object Label1: TLabel
Left = 13
Height = 14
Top = 18
Width = 296
Caption = 'Drag and drop files on this form and see the results in memo. '
ParentColor = False
end
object Memo1: TMemo
Left = 12
Height = 287
Top = 48
Width = 666
ScrollBars = ssVertical
TabOrder = 0
end
object ApplicationProperties1: TApplicationProperties
CaptureExceptions = True
HintColor = clInfoBk
HintHidePause = 2500
HintPause = 500
HintShortCuts = True
ShowHint = True
OnFilesDrop = ApplicationProperties1FilesDrop
left = 126
top = 300
end
end

View File

@ -0,0 +1,16 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TForm1','FORMDATA',[
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'+'#1#6'Height'#3'a'#1#3'Top'#3#155#0#5'Wi'
+'dth'#3#189#2#18'HorzScrollBar.Page'#3#188#2#18'VertScrollBar.Page'#3'`'#1#7
+'Caption'#6#27'On Files Drop event example'#12'ClientHeight'#3'a'#1#11'Clien'
+'tWidth'#3#189#2#11'OnFilesDrop'#7#13'FormFilesDrop'#0#6'TLabel'#6'Label1'#4
+'Left'#2#13#6'Height'#2#14#3'Top'#2#18#5'Width'#3'('#1#7'Caption'#6'>Drag an'
+'d drop files on this form and see the results in memo. '#11'ParentColor'#8#0
+#0#5'TMemo'#5'Memo1'#4'Left'#2#12#6'Height'#3#31#1#3'Top'#2'0'#5'Width'#3#154
+#2#10'ScrollBars'#7#10'ssVertical'#8'TabOrder'#2#0#0#0#22'TApplicationProper'
+'ties'#22'ApplicationProperties1'#17'CaptureExceptions'#9#9'HintColor'#7#8'c'
+'lInfoBk'#13'HintHidePause'#3#196#9#9'HintPause'#3#244#1#13'HintShortCuts'#9
+#8'ShowHint'#9#11'OnFilesDrop'#7#31'ApplicationProperties1FilesDrop'#4'left'
+#2'~'#3'top'#3','#1#0#0#0
]);

View File

@ -0,0 +1,57 @@
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
ApplicationProperties1: TApplicationProperties;
Label1: TLabel;
Memo1: TMemo;
procedure ApplicationProperties1FilesDrop(Sender: TObject;
const FileNames: array of String);
procedure FormFilesDrop(Sender: TObject; const FileNames: array of String);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.FormFilesDrop(Sender: TObject; const FileNames: array of String);
var
I: Integer;
begin
Memo1.Lines.Add(IntToStr(Length(FileNames)) + ' file(s) dropped on ' + Name + ':');
for I := 0 to High(FileNames) do
Memo1.Lines.Add(FileNames[I]);
end;
procedure TForm1.ApplicationProperties1FilesDrop(Sender: TObject;
const FileNames: array of String);
var
I: Integer;
begin
Memo1.Lines.Add(IntToStr(Length(FileNames)) + ' file(s) dropped on Application:');
for I := 0 to High(FileNames) do
Memo1.Lines.Add(FileNames[I]);
end;
initialization
{$I unit1.lrs}
end.

View File

@ -0,0 +1,20 @@
object Form2: TForm2
Left = 422
Height = 56
Top = 592
Width = 473
HorzScrollBar.Page = 472
VertScrollBar.Page = 55
Caption = 'Form2'
ClientHeight = 56
ClientWidth = 473
OnFilesDrop = FormFilesDrop
object Label1: TLabel
Left = 13
Height = 14
Top = 18
Width = 296
Caption = 'Drag and drop files on this form and see the results in memo. '
ParentColor = False
end
end

View File

@ -0,0 +1,10 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TForm2','FORMDATA',[
'TPF0'#6'TForm2'#5'Form2'#4'Left'#3#166#1#6'Height'#2'8'#3'Top'#3'P'#2#5'Widt'
+'h'#3#217#1#18'HorzScrollBar.Page'#3#216#1#18'VertScrollBar.Page'#2'7'#7'Cap'
+'tion'#6#5'Form2'#12'ClientHeight'#2'8'#11'ClientWidth'#3#217#1#11'OnFilesDr'
+'op'#7#13'FormFilesDrop'#0#6'TLabel'#6'Label1'#4'Left'#2#13#6'Height'#2#14#3
+'Top'#2#18#5'Width'#3'('#1#7'Caption'#6'>Drag and drop files on this form an'
+'d see the results in memo. '#11'ParentColor'#8#0#0#0
]);

View File

@ -0,0 +1,46 @@
unit Unit2;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm2 }
TForm2 = class(TForm)
Label1: TLabel;
procedure FormFilesDrop(Sender: TObject; const FileNames: array of String);
private
{ private declarations }
public
{ public declarations }
end;
var
Form2: TForm2;
implementation
uses
Unit1;
{ TForm2 }
procedure TForm2.FormFilesDrop(Sender: TObject; const FileNames: array of String);
var
I: Integer;
begin
Form1.Memo1.Lines.Add(IntToStr(Length(FileNames)) + ' file(s) dropped on ' + Name + ':');
for I := 0 to High(FileNames) do
Form1.Memo1.Lines.Add(FileNames[I]);
end;
initialization
{$I unit2.lrs}
end.

View File

@ -318,6 +318,8 @@ type
var CanClose : boolean) of object;
THelpEvent = function(Command: Word; Data: Longint;
var CallHelp: Boolean): Boolean of object;
TFilesDropEvent = procedure (Sender: TObject; const FileNames: Array of String) of object;
TShortCutEvent = procedure (var Msg: TLMKey; var Handled: Boolean) of object;
@ -371,6 +373,7 @@ type
FOnCreate: TNotifyEvent;
FOnDeactivate: TNotifyEvent;
FOnDestroy: TNotifyEvent;
FOnFilesDrop: TFilesDropEvent;
FOnHelp: THelpEvent;
FOnHide: TNotifyEvent;
FOnShortcut: TShortCutEvent;
@ -498,6 +501,7 @@ type
procedure AddHandlerCreate(OnCreateHandler: TNotifyEvent; AsLast: Boolean=true);
procedure RemoveHandlerCreate(OnCreateHandler: TNotifyEvent);
function IsShortcut(var Message: TLMKey): boolean; virtual;
procedure IntfFilesDrop(const FileNames: Array of String);
procedure IntfHelp(AComponent: TComponent);
public
// drag and dock
@ -532,6 +536,7 @@ type
property OnCreate: TNotifyEvent read FOnCreate write FOnCreate;
property OnDeactivate: TNotifyEvent read FOnDeactivate write FOnDeactivate;
property OnDestroy: TNotifyEvent read FOnDestroy write FOnDestroy;
property OnFilesDrop: TFilesDropEvent read FOnFilesDrop write FOnFilesDrop;
property OnHelp: THelpEvent read FOnHelp write FOnHelp;
property OnHide: TNotifyEvent read FOnHide write FOnHide;
property OnResize stored IsForm;
@ -603,6 +608,7 @@ type
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnFilesDrop;
property OnGetSiteInfo;
property OnHide;
property OnKeyDown;
@ -922,6 +928,7 @@ type
FOnActivate: TNotifyEvent;
FOnDeactivate: TNotifyEvent;
FOnDestroy: TNotifyEvent;
FOnFilesDrop: TFilesDropEvent;
FOnHelp: THelpEvent;
FOnHint: TNotifyEvent;
FOnIdle: TIdleEvent;
@ -1055,6 +1062,7 @@ type
procedure IntfEndSession;
procedure IntfAppMinimize;
procedure IntfAppRestore;
procedure IntfFilesDrop(const FileNames: Array of String);
public
procedure DoEscapeKey(AControl: TWinControl; var Key: Word;
Shift: TShiftState);
@ -1087,6 +1095,7 @@ type
property OnQueryEndSession: TQueryEndSessionEvent read FOnQueryEndSession write FOnQueryEndSession;
property OnMinimize: TNotifyEvent read FOnMinimize write FOnMinimize;
property OnRestore: TNotifyEvent read FOnRestore write FOnRestore;
property OnFilesDrop: TFilesDropEvent read FOnFilesDrop write FOnFilesDrop;
property OnHelp: THelpEvent read FOnHelp write FOnHelp;
property OnHint: TNotifyEvent read FOnHint write FOnHint;
property OnShortcut: TShortcutEvent read FOnShortcut write FOnShortcut;
@ -1112,6 +1121,7 @@ type
FHintPause: Integer;
FHintShortCuts: Boolean;
FHintShortPause: Integer;
FOnFilesDrop: TFilesDropEvent;
FShowHint: Boolean;
FShowMainForm: Boolean;
FTitle: String;
@ -1147,6 +1157,7 @@ type
Procedure SetOnQueryEndSession(Const AValue : TQueryEndSessionEvent);
Procedure SetOnMinimize(Const AValue : TNotifyEvent);
Procedure SetOnRestore(Const AValue : TNotifyEvent);
Procedure SetOnFilesDrop(const AValue: TFilesDropEvent);
Procedure SetOnHelp(Const AValue : THelpEvent);
Procedure SetOnHint(Const AValue : TNotifyEvent);
Procedure SetOnShowHint(Const AValue : TShowHintEvent);
@ -1174,6 +1185,7 @@ type
property OnQueryEndSession : TQueryEndSessionEvent read FOnQueryEndSession write SetOnQueryEndSession;
property OnMinimize : TNotifyEvent read FOnMinimize write SetOnMinimize;
property OnRestore : TNotifyEvent read FOnRestore write SetOnRestore;
property OnFilesDrop: TFilesDropEvent read FOnFilesDrop write SetOnFilesDrop;
property OnHelp: THelpEvent read FOnHelp write SetOnHelp;
property OnHint: TNotifyEvent read FOnHint write SetOnHint;
property OnShowHint: TShowHintEvent read FOnShowHint write SetOnShowHint;

View File

@ -1449,7 +1449,17 @@ begin
if Assigned(FOnRestore) then FOnRestore(Self);
end;
{------------------------------------------------------------------------------
Method: TApplication.IntfFilesDrop
Params: FileNames - Dropped files
Invokes OnFilesDropEvent of the application.
This function is called by the interface.
------------------------------------------------------------------------------}
procedure TApplication.IntfFilesDrop(const FileNames: array of String);
begin
if Assigned(FOnFilesDrop) then FOnFilesDrop(Self, FileNames);
end;
{------------------------------------------------------------------------------
procedure TApplication.DoBeforeMouseMessage(CurMouseControl: TControl);

View File

@ -163,6 +163,13 @@ begin
Application.OnRestore := AValue;
end;
Procedure TApplicationProperties.SetOnFilesDrop(const AValue: TFilesDropEvent);
begin
FOnFilesDrop := AValue;
If not (csDesigning in ComponentState) then
Application.OnFilesDrop := AValue;
end;
Procedure TApplicationProperties.SetOnHelp(Const AValue : THelpEvent);
begin

View File

@ -1686,6 +1686,18 @@ begin
end;
end;
{------------------------------------------------------------------------------
Method: TCustomForm.IntfFilesDrop
Params: FileNames - Dropped files
Invokes OnFilesDropEvent of the form.
This function is called by the interface.
------------------------------------------------------------------------------}
procedure TCustomForm.IntfFilesDrop(const FileNames: array of String);
begin
if Assigned(FOnFilesDrop) then FOnFilesDrop(Self, FileNames);
end;
{------------------------------------------------------------------------------
procedure TCustomForm.IntfHelp(AComponent: TComponent);

View File

@ -931,6 +931,61 @@ Var
then lmNotify.result := lmNotify.result or CDRFRESULT[ResultFlag];
end;
end;
procedure HandleDropFiles;
var
Files: Array of String;
Drop: HDROP;
L: LongWord;
I, C: Integer;
{$IFDEF WindowsUnicodeSupport}
AnsiBuffer: string;
WideBuffer: WideString;
{$ENDIF}
begin
Drop := HDROP(WParam);
try
C := DragQueryFile(Drop, $FFFFFFFF, nil, 0); // get dropped files count
if C <= 0 then Exit;
SetLength(Files, C);
for I := 0 to C - 1 do
begin
{$IFDEF WindowsUnicodeSupport}
if UnicodeEnabledOS then
begin
L := DragQueryFileW(Drop, I, nil, 0); // get I. file name length
SetLength(WideBuffer, L);
L := DragQueryFileW(Drop, I, @WideBuffer[1], L + 1);
SetLength(WideBuffer, L);
Files[I] := UTF8Encode(WideBuffer);
end
else
begin
L := DragQueryFile(Drop, I, nil, 0); // get I. file name length
SetLength(AnsiBuffer, L);
L := DragQueryFile(Drop, I, @AnsiBuffer[1], L + 1);
SetLength(WideBuffer, L);
Files[I] := ANSIToUTF8(AnsiBuffer);
end;
{$ELSE}
L := DragQueryFile(Drop, I, nil, 0); // get I. file name length
SetLength(Files[I], L);
DragQueryFile(Drop, I, PChar(Files[I]), L + 1);
{$ENDIF}
end;
if Length(Files) > 0 then
begin
if lWinControl is TCustomForm then
(lWinControl as TCustomForm).IntfFilesDrop(Files);
if Application <> nil then
Application.IntfFilesDrop(Files);
end;
finally
DragFinish(Drop);
end;
end;
// Gets the cursor position relative to a given window
function GetClientCursorPos(ClientWindow: HWND) : TSmallPoint;
@ -1614,14 +1669,16 @@ begin
WinProcess := false;
end;
end;
{$IFDEF EnableWMDropFiles}
WM_DROPFILES:
begin
{$IFDEF EnableWMDropFiles}
LMessage.Msg := LM_DROPFILES;
LMessage.WParam := WParam;
LMessage.LParam := LParam;
{$ENDIF}
HandleDropFiles;
end;
{$ENDIF}
//TODO:LM_MOVEPAGE,LM_MOVETOROW,LM_MOVETOCOLUMN
WM_NCACTIVATE:
begin

View File

@ -257,6 +257,8 @@ begin
FinishCreateWindow(AWinControl, Params, false);
// TODO: proper icon, for now set default icon
SetIcon(TCustomForm(AWinControl), 0);
// enable accepting files drop
DragAcceptFiles(Params.Window, True);
Result := Params.Window;
end;