From 19ff119be9aa566efd3ae40a4cdd768c76cfc028 Mon Sep 17 00:00:00 2001 From: macpgmr Date: Sun, 2 Jan 2011 03:03:08 +0000 Subject: [PATCH] Added support to sample apps for shelling on OS X; activated LCL DropFiles in sample apps git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1417 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/thtmlport/demo_src/demounit.pas | 57 ++++++++++++++++------ components/thtmlport/demo_src/fdemunit.pas | 57 ++++++++++++++-------- 2 files changed, 78 insertions(+), 36 deletions(-) diff --git a/components/thtmlport/demo_src/demounit.pas b/components/thtmlport/demo_src/demounit.pas index 7ba6f672c..0c6d1dbd3 100755 --- a/components/thtmlport/demo_src/demounit.pas +++ b/components/thtmlport/demo_src/demounit.pas @@ -139,7 +139,12 @@ type HintWindow: THintWindow; HintVisible: boolean; +{$IFNDEF LCL} procedure wmDropFiles(var Message: TMessage); message wm_DropFiles; +{$ELSE} + procedure DropFiles( Sender : TObject; + const FileNames: array of string); +{$ENDIF} procedure CloseAll; public { Public declarations } @@ -206,8 +211,11 @@ for I := 0 to MaxHistories-1 do SelectAllItem.ShortCut := ShortCut(VK_A, [ssMeta]); {$ENDIF} -{$IFDEF MSWINDOWS} +{$IFNDEF LCL} DragAcceptFiles(Handle, True); +{$ELSE} +AllowDropFiles := True; +OnDropFiles := DropFiles; {$ENDIF} HintWindow := THintWindow.Create(Self); HintWindow.Color := $C0FFFF; @@ -218,8 +226,8 @@ var S: string; I: integer; begin -{$IFNDEF DARWIN} //Launched file name not passed via command line with OS X. -if (ParamCount >= 1) then +// With OS X app, ParamStr not meaningful unless launched with --args switch. +if (ParamCount >= 1) {$IFDEF LCLCarbon} and (Copy(ParamStr(1), 1, 4) <> '-psn') {$ENDIF} then begin {Parameter is file to load} {$IFNDEF LCL} S := CmdLine; @@ -238,7 +246,6 @@ if (ParamCount >= 1) then {$ENDIF} Viewer.LoadFromFile(HtmlToDos(Trim(S))); end; -{$ENDIF} end; procedure TForm1.OpenFileClick(Sender: TObject); @@ -336,8 +343,12 @@ if (I <= 2) or (J > 0) then {$IFDEF MSWINDOWS} ShellExecute(Handle, nil, StrPCopy(PC, S), StrPCopy(PC2, Params), nil, SW_SHOWNORMAL); - {$ELSE} - Shell('Open ' + S); + {$ELSE} //Not sure if this makes any sense since executable won't have .exe. + {$IFDEF LCLCarbon} + Shell('open -n "' + S + '" --args "' + Params + '"'); + {$ELSE} + Shell('"' + S + '" "' + Params + '"'); + {$ENDIF} {$ENDIF} {$ENDIF} end @@ -366,7 +377,11 @@ if (I > 0) or (J > 0) then {$IFDEF MSWINDOWS} ShellExecute(0, nil, pchar(URL), nil, nil, SW_SHOWNORMAL); {$ELSE} - Shell('Open ' + URL); + {$IFDEF LCLCarbon} + Shell('open "' + URL + '"'); + {$ELSE} + Shell('"' + URL + '"'); //use LCL's OpenURL? + {$ENDIF} {$ENDIF} Handled := True; Exit; @@ -620,22 +635,27 @@ if OpenDialog.Execute then end; end; +{$IFNDEF LCL} procedure TForm1.wmDropFiles(var Message: TMessage); var S: string[200]; Ext: string; Count: integer; begin -{$IFDEF MSWINDOWS} Count := DragQueryFile(Message.WParam, 0, @S[1], 200); -{$IFNDEF LCL} Length(S) := Count; -{$ELSE} -S[0] := Char(Count); -{$ENDIF} DragFinish(Message.WParam); if Count >0 then begin +{$ELSE} +procedure TForm1.DropFiles( Sender : TObject; + const FileNames : array of string); +var + S : string; + Ext: string; +begin + S := FileNames[0]; +{$ENDIF} Ext := LowerCase(ExtractFileExt(S)); if (Ext = '.htm') or (Ext = '.html') then Viewer.LoadFromFile(S) @@ -644,9 +664,10 @@ if Count >0 then else if (Ext = '.bmp') or (Ext = '.gif') or (Ext = '.jpg') or (Ext = '.jpeg') or (Ext = '.png') then Viewer.LoadImageFile(S); +{$IFNDEF LCL} end; -{$ENDIF} Message.Result := 0; +{$ENDIF} end; procedure TForm1.MediaPlayerNotify(Sender: TObject); @@ -837,13 +858,19 @@ var {$ENDIF} begin {$IFNDEF LCL} -WinExec(StrPCopy(PC, ParamStr(0)+' "'+NewWindowFile+'"'), sw_Show); + WinExec(StrPCopy(PC, ParamStr(0)+' "'+NewWindowFile+'"'), sw_Show); {$ELSE} {$IFDEF MSWINDOWS} ShellExecute(Handle, nil, StrPCopy(PC, ParamStr(0)), StrPCopy(PC2, NewWindowFile), nil, SW_SHOWNORMAL); {$ELSE} - Shell('Open ' + ParamStr(0)); + {$IFDEF LCLCarbon} + Shell('open -n "' + + ExtractFileDir(ExtractFileDir(ExtractFileDir(ParamStr(0)))) + + '" --args "' + NewWindowFile + '"'); + {$ELSE} + Shell('"' + ParamStr(0) + '" "' + NewWindowFile + '"'); + {$ENDIF} {$ENDIF} {$ENDIF} end; diff --git a/components/thtmlport/demo_src/fdemunit.pas b/components/thtmlport/demo_src/fdemunit.pas index fea09a720..8996846b4 100755 --- a/components/thtmlport/demo_src/fdemunit.pas +++ b/components/thtmlport/demo_src/fdemunit.pas @@ -146,7 +146,12 @@ const HintVisible: boolean; TitleViewer: ThtmlViewer; +{$IFNDEF LCL} procedure wmDropFiles(var Message: TMessage); message wm_DropFiles; +{$ELSE} + procedure DropFiles( Sender : TObject; + const FileNames: array of string); +{$ENDIF} procedure CloseAll; public { Public declarations } @@ -199,8 +204,11 @@ for I := 0 to MaxHistories-1 do SelectAll1.ShortCut := ShortCut(VK_A, [ssMeta]); {$ENDIF} -{$IFDEF MSWINDOWS} +{$IFNDEF LCL} DragAcceptFiles(Handle, True); +{$ELSE} +AllowDropFiles := True; +OnDropFiles := DropFiles; {$ENDIF} HintWindow := THintWindow.Create(Self); HintWindow.Color := $CCFFFF; @@ -281,9 +289,9 @@ if (I <= 2) or (J > 0) then {$IFDEF MSWINDOWS} ShellExecute(Handle, nil, StrPCopy(PC, S), StrPCopy(PC2, Params), nil, SW_SHOWNORMAL); - {$ELSE} + {$ELSE} //Not sure if this makes any sense since executable won't have .exe. {$IFDEF LCLCarbon} - Shell('Open "' + S + '.app"'); + Shell('open -n "' + S + '" --args "' + Params + '"'); {$ELSE} Shell('"' + S + '" "' + Params + '"'); {$ENDIF} @@ -316,9 +324,9 @@ if (I > 0) or (J > 0) then ShellExecute(Handle, nil, StrPCopy(PC, URL), nil, nil, SW_SHOWNORMAL); {$ELSE} {$IFDEF LCLCarbon} - Shell('Open "' + URL + '.app"'); + Shell('open "' + URL + '"'); {$ELSE} - Shell('"' + URL + '"'); + Shell('"' + URL + '"'); //use LCL's OpenURL? {$ENDIF} {$ENDIF} Handled := True; @@ -347,7 +355,7 @@ else OpenDialog.InitialDir := ExtractFilePath(ParamStr(0)); {$ELSE} //Don't default to within app bundle. else OpenDialog.InitialDir := ExtractFilePath(ParamStr(0)) + '../../../'; {$ENDIF} -//OpenDialog.FilterIndex := 1; //Form's Filter wasn't right, so set here +//OpenDialog.FilterIndex := 1; //Form's Filter isn't right, so set here OpenDialog.Filter := 'HTML Files (*.htm,*.html)|*.htm;*.html'+ '|All Files (*.*)|*.*'; if OpenDialog.Execute then @@ -372,10 +380,10 @@ var S: string; I: integer; begin -{$IFNDEF LCLCarbon} //Launched file name not passed via command line with app bundle. -if (ParamCount >= 1) then +// With OS X app, ParamStr not meaningful unless launched with --args switch. +if (ParamCount >= 1) {$IFDEF LCLCarbon} and (Copy(ParamStr(1), 1, 4) <> '-psn') {$ENDIF} then begin {Parameter is file to load} -{$IFNDEF LCL} + {$IFNDEF LCL} S := CmdLine; I := Pos('" ', S); if I > 0 then @@ -387,15 +395,15 @@ if (ParamCount >= 1) then Delete(S, I, 1); I := Pos('"', S); end; -{$ELSE} + {$ELSE} S := ParamStr(1); -{$ENDIF} + {$ENDIF} FrameViewer.LoadFromFile(HtmlToDos(Trim(S))); end -else {$ENDIF} if FileExists(ExtractFilePath(ParamStr(0))+'demo.htm') then +else if FileExists(ExtractFilePath(ParamStr(0))+'demo.htm') then FrameViewer.LoadFromFile(ExtractFilePath(ParamStr(0))+'demo.htm') {If run from Lazarus IDE, HTML files probably won't be in executable's folder, - so look for them one level up (or 4 levels up with Carbon app bundle).} + so look for them one level up (or 4 levels up with OS X app bundle).} else if FileExists(ExtractFilePath(ParamStr(0)) + '..' + PathDelim + {$IFDEF LCLCarbon} '../../../' + {$ENDIF} 'demo.htm') then FrameViewer.LoadFromFile(ExtractFilePath(ParamStr(0)) + '..' + PathDelim + @@ -623,7 +631,9 @@ if FileExists(S) then StrPCopy(PC2, S+Dest), nil, SW_SHOWNORMAL); {$ELSE} {$IFDEF LCLCarbon} - Shell('Open "' + ParamStr(0) + '.app"'); + Shell('open -n "' + + ExtractFileDir(ExtractFileDir(ExtractFileDir(ParamStr(0)))) + + '" --args "' + S+Dest + '"'); {$ELSE} Shell('"' + ParamStr(0) + '" "' + S+Dest + '"'); {$ENDIF} @@ -631,24 +641,27 @@ if FileExists(S) then {$ENDIF} end; +{$IFNDEF LCL} procedure TForm1.wmDropFiles(var Message: TMessage); var S: string[200]; Count: integer; begin -{$IFDEF MSWINDOWS} Count := DragQueryFile(Message.WParam, 0, @S[1], 200); -{$IFNDEF LCL} Length(S) := Count; -{$ELSE} -S[0] := Char(Count); -{$ENDIF} DragFinish(Message.WParam); if Count >0 then FrameViewer.LoadFromFile(S); -{$ENDIF} Message.Result := 0; end; +{$ELSE} +procedure TForm1.DropFiles( Sender : TObject; + const FileNames : array of string); +begin + if High(FileNames) >= 0 then {At least one file passed?} + FrameViewer.LoadFromFile(FileNames[0]); +end; +{$ENDIF} procedure TForm1.CopyImagetoclipboardClick(Sender: TObject); begin @@ -860,7 +873,9 @@ begin StrPCopy(PC2, NewWindowFile), nil, SW_SHOWNORMAL); {$ELSE} {$IFDEF LCLCarbon} - Shell('Open "' + ParamStr(0) + '.app"'); + Shell('open -n "' + + ExtractFileDir(ExtractFileDir(ExtractFileDir(ParamStr(0)))) + + '" --args "' + NewWindowFile + '"'); {$ELSE} Shell('"' + ParamStr(0) + '" "' + NewWindowFile + '"'); {$ENDIF}