@@ -52,6 +52,7 @@ interface
5252 , Vcl.Styles.Utils.ComCtrls
5353 , Vcl.Styles.Utils.StdCtrls
5454 , Vcl.Styles.Ext
55+ , uDragDropUtils
5556 ;
5657
5758const
@@ -96,7 +97,7 @@ TEditingFile = class
9697 property Extension : string read FExtension;
9798 end ;
9899
99- TfrmMain = class (TForm)
100+ TfrmMain = class (TForm, IDragDrop )
100101 OpenDialog: TOpenDialog;
101102 ActionList: TActionList;
102103 acOpenFile: TAction;
@@ -182,6 +183,7 @@ TfrmMain = class(TForm)
182183 StatusStaticText: TStaticText;
183184 StatusSplitter: TSplitter;
184185 CloseAll1: TMenuItem;
186+ procedure WMGetMinMaxInfo (var Message: TWMGetMinMaxInfo); message WM_GETMINMAXINFO;
185187 procedure acOpenFileExecute (Sender: TObject);
186188 procedure acSaveExecute (Sender: TObject);
187189 procedure FormDestroy (Sender: TObject);
@@ -255,6 +257,7 @@ TfrmMain = class(TForm)
255257 MousePos: TPoint; var Handled: Boolean);
256258 procedure FormClose (Sender: TObject; var Action: TCloseAction);
257259 private
260+ MinFormWidth, MinFormHeight, MaxFormWidth, MaxFormHeight: Integer;
258261 FProcessingFiles: Boolean;
259262 FEditorSettings: TEditorSettings;
260263 currentDir: string;
@@ -272,6 +275,10 @@ TfrmMain = class(TForm)
272275 gsReplaceTextHistory: string;
273276 FEditorOptions: TSynEditorOptionsContainer;
274277 FFontSize: Integer;
278+ FDropTarget: TDropTarget;
279+ // implement IDragDrop
280+ function DropAllowed (const FileNames: array of string): Boolean;
281+ procedure Drop (const FileNames: array of string);
275282 procedure CloseSplitViewMenu ;
276283 procedure UpdateHighlighters ;
277284 procedure UpdateFromSettings (AEditor: TSynEdit);
@@ -297,7 +304,12 @@ TfrmMain = class(TForm)
297304 procedure UpdateHighlighter (ASynEditor: TSynEdit);
298305 procedure SetEditorFontSize (const Value : Integer);
299306 procedure LoadOpenedFiles ;
307+ function CanAcceptFileName (const AFileName: string): Boolean;
308+ function AcceptedExtensions : string;
300309 property EditorFontSize: Integer read FFontSize write SetEditorFontSize;
310+ protected
311+ procedure CreateWindowHandle (const Params: TCreateParams); override;
312+ procedure DestroyWindowHandle ; override;
301313 end ;
302314
303315var
@@ -428,6 +440,17 @@ procedure TfrmMain.acOpenFileExecute(Sender: TObject);
428440 AssignSVGToImage;
429441end ;
430442
443+ function TfrmMain.CanAcceptFileName (const AFileName: string): Boolean;
444+ begin
445+ Result := pos(ExtractFileExt(AFileName), AcceptedExtensions) <> 0 ;
446+ end ;
447+
448+ function TfrmMain.AcceptedExtensions : string;
449+ begin
450+ // Check file extension
451+ Result := ' .svg;.xml' ;
452+ end ;
453+
431454function TfrmMain.OpenFile (const FileName : string;
432455 const ARaiseError: Boolean = True): Boolean;
433456var
@@ -439,6 +462,10 @@ function TfrmMain.OpenFile(const FileName : string;
439462 FProcessingFiles := True;
440463 if FileExists(FileName) then
441464 begin
465+ if not CanAcceptFileName(FileName) then
466+ raise Exception.CreateFmt(' Cannot open file with extensions different from "%s"' ,
467+ [AcceptedExtensions]);
468+
442469 // looking for the file already opened
443470 EditingFile := nil ;
444471 I := -1 ;
@@ -505,10 +532,10 @@ procedure TfrmMain.acSaveExecute(Sender: TObject);
505532
506533procedure TfrmMain.FormDestroy (Sender: TObject);
507534begin
508- EditFileList.Free ;
509- SynEditPrint.Free ;
510- FEditorSettings.Free ;
511- FEditorOptions.Free ;
535+ FreeAndNil( EditFileList) ;
536+ FreeAndNil( SynEditPrint) ;
537+ FreeAndNil( FEditorSettings) ;
538+ FreeAndNil( FEditorOptions) ;
512539 inherited ;
513540end ;
514541
@@ -632,6 +659,12 @@ procedure TfrmMain.SVOpening(Sender: TObject);
632659 catMenuItems.ButtonOptions := catMenuItems.ButtonOptions + [boShowCaptions];
633660end ;
634661
662+ procedure TfrmMain.DestroyWindowHandle ;
663+ begin
664+ FreeAndNil(FDropTarget);
665+ inherited ;
666+ end ;
667+
635668function TfrmMain.DialogPosRect : TRect;
636669begin
637670 GetWindowRect(Self.Handle, Result);
@@ -670,6 +703,32 @@ procedure TfrmMain.DoSearchReplaceText(AReplace: boolean;
670703 ConfirmReplaceDialog.Free;
671704end ;
672705
706+ procedure TfrmMain.Drop (const FileNames: array of string);
707+ var
708+ LFileName: string;
709+ i: Integer;
710+ begin
711+ for i := 0 to Length(FileNames)-1 do
712+ begin
713+ if CanAcceptFileName(FileNames[i]) then
714+ OpenFile(FileNames[i], False);
715+ end ;
716+ AssignSVGToImage;
717+ end ;
718+
719+ function TfrmMain.DropAllowed (const FileNames: array of string): Boolean;
720+ var
721+ i: Integer;
722+ begin
723+ Result := False;
724+ for i := 0 to Length(FileNames)-1 do
725+ begin
726+ Result := CanAcceptFileName(FileNames[i]);
727+ if Result then
728+ Break;
729+ end ;
730+ end ;
731+
673732procedure TfrmMain.ExportToPNGActionExecute (Sender: TObject);
674733var
675734 LFileName: string;
@@ -1005,6 +1064,12 @@ procedure TfrmMain.CloseSplitViewMenu;
10051064 Screen.Cursor := crDefault;
10061065end ;
10071066
1067+ procedure TfrmMain.CreateWindowHandle (const Params: TCreateParams);
1068+ begin
1069+ inherited ;
1070+ FDropTarget := TDropTarget.Create(WindowHandle, Self);
1071+ end ;
1072+
10081073function TfrmMain.CurrentEditFile : TEditingFile;
10091074begin
10101075 if (PageControl.ActivePage <> nil ) then
@@ -1388,6 +1453,32 @@ procedure TfrmMain.UpdateStatusBarPanels;
13881453 end ;
13891454end ;
13901455
1456+ procedure TfrmMain.WMGetMinMaxInfo (var Message: TWMGetMinMaxInfo);
1457+ var
1458+ LMinMaxInfo: PMinMaxInfo;
1459+ begin
1460+ if not (csReading in ComponentState) then
1461+ begin
1462+ LMinMaxInfo := Message.MinMaxInfo;
1463+ with LMinMaxInfo^ do
1464+ begin
1465+ with ptMinTrackSize do
1466+ begin
1467+ if MinFormWidth > 0 then X := MinFormWidth;
1468+ if MinFormHeight > 0 then Y := MinFormHeight;
1469+ end ;
1470+ with ptMaxTrackSize do
1471+ begin
1472+ if MaxFormWidth > 0 then X := MaxFormWidth;
1473+ if MaxFormHeight > 0 then Y := MaxFormHeight;
1474+ end ;
1475+ ConstrainedResize(ptMinTrackSize.X, ptMinTrackSize.Y, ptMaxTrackSize.X,
1476+ ptMaxTrackSize.Y);
1477+ end ;
1478+ end ;
1479+ inherited ;
1480+ end ;
1481+
13911482procedure TfrmMain.ActionListExecute (Action: TBasicAction;
13921483 var Handled: Boolean);
13931484begin
0 commit comments