| 1 | (* ***** BEGIN LICENSE BLOCK *****
|
|---|
| 2 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|---|
| 3 | *
|
|---|
| 4 | * The contents of this file are subject to the Mozilla Public License Version
|
|---|
| 5 | * 1.1 (the "License"); you may not use this file except in compliance with
|
|---|
| 6 | * the License. You may obtain a copy of the License at
|
|---|
| 7 | * http://www.mozilla.org/MPL/
|
|---|
| 8 | *
|
|---|
| 9 | * Software distributed under the License is distributed on an "AS IS" basis,
|
|---|
| 10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|---|
| 11 | * for the specific language governing rights and limitations under the
|
|---|
| 12 | * License.
|
|---|
| 13 | *
|
|---|
| 14 | * The Original Code is GeckoComponents for Delphi.
|
|---|
| 15 | *
|
|---|
| 16 | * The Initial Developer of the Original Code is NOSE Takafumi.
|
|---|
| 17 | * Portions created by the Initial Developer are Copyright (C) 2008
|
|---|
| 18 | * the Initial Developer. All Rights Reserved.
|
|---|
| 19 | *
|
|---|
| 20 | * Contributor(s):
|
|---|
| 21 | *
|
|---|
| 22 | * Alternatively, the contents of this file may be used under the terms of
|
|---|
| 23 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
|---|
| 24 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|---|
| 25 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
|---|
| 26 | * of those above. If you wish to allow use of your version of this file only
|
|---|
| 27 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
|---|
| 28 | * use your version of this file under the terms of the MPL, indicate your
|
|---|
| 29 | * decision by deleting the provisions above and replace them with the notice
|
|---|
| 30 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
|---|
| 31 | * the provisions above, a recipient may use your version of this file under
|
|---|
| 32 | * the terms of any one of the MPL, the GPL or the LGPL.
|
|---|
| 33 | *
|
|---|
| 34 | * ***** END LICENSE BLOCK ***** *)
|
|---|
| 35 | unit GeckoSimpleHALDialog;
|
|---|
| 36 |
|
|---|
| 37 | interface
|
|---|
| 38 |
|
|---|
| 39 | uses
|
|---|
| 40 | Windows, Messages, SysUtils, Classes, Forms, nsTypes,
|
|---|
| 41 | nsXPCOM, nsHelperAppLauncher;
|
|---|
| 42 |
|
|---|
| 43 | type
|
|---|
| 44 | THelperAppLauncherDialogImpl = class(TInterfacedObject, nsIHelperAppLauncherDialog)
|
|---|
| 45 | procedure Show(aLauncher: nsIHelperAppLauncher; aContext: nsISupports; aReason: PRUint32); safecall;
|
|---|
| 46 | function PromptForSaveToFile(aLauncher: nsIHelperAppLauncher; aWindowContext: nsISupports; const aDefaultFile: PWideChar; const aSuggestedFileExtension: PWideChar): nsILocalFile; safecall;
|
|---|
| 47 | end;
|
|---|
| 48 |
|
|---|
| 49 | THelperDialogFactory = class(TInterfacedObject, nsIFactory)
|
|---|
| 50 | constructor Create;
|
|---|
| 51 | destructor Destroy; override;
|
|---|
| 52 | procedure CreateInstance(aOuter: nsISupports; const iid: TGUID; out _result); safecall;
|
|---|
| 53 | procedure LockFactory(lock: PRBool); safecall;
|
|---|
| 54 | end;
|
|---|
| 55 |
|
|---|
| 56 | TGeckoSimpleHALDialog = class(TComponent)
|
|---|
| 57 | private
|
|---|
| 58 | { Private �錾 }
|
|---|
| 59 | protected
|
|---|
| 60 | { Protected �錾 }
|
|---|
| 61 | public
|
|---|
| 62 | { Public �錾 }
|
|---|
| 63 | constructor Create(AOwner: TComponent); override;
|
|---|
| 64 | destructor Destroy; override;
|
|---|
| 65 | published
|
|---|
| 66 | { Published �錾 }
|
|---|
| 67 | end;
|
|---|
| 68 |
|
|---|
| 69 | implementation
|
|---|
| 70 |
|
|---|
| 71 | uses
|
|---|
| 72 | nsXPCOMGlue, nsError, nsGeckoStrings, nsInit, HelperDlg;
|
|---|
| 73 |
|
|---|
| 74 | var
|
|---|
| 75 | sHALDialogFactory: nsIFactory;
|
|---|
| 76 | sRefCnt: Integer = 0;
|
|---|
| 77 |
|
|---|
| 78 | constructor TGeckoSimpleHALDialog.Create(AOwner: TComponent);
|
|---|
| 79 | var
|
|---|
| 80 | rv: nsresult;
|
|---|
| 81 | factory: nsIFactory;
|
|---|
| 82 | compReg: nsIComponentRegistrar;
|
|---|
| 83 | begin
|
|---|
| 84 | inherited Create(AOwner);
|
|---|
| 85 |
|
|---|
| 86 | if not (csDesigning in ComponentState) then
|
|---|
| 87 | begin
|
|---|
| 88 | rv := GRE_Startup;
|
|---|
| 89 | if NS_FAILED(rv) then
|
|---|
| 90 | raise Exception.Create('GRE_Startup');
|
|---|
| 91 |
|
|---|
| 92 | if not Assigned(sHALDialogFactory) then
|
|---|
| 93 | begin
|
|---|
| 94 | factory := THelperDialogFactory.Create;
|
|---|
| 95 |
|
|---|
| 96 | if not Assigned(factory) then
|
|---|
| 97 | EOutOfMemory.Create('Cannot create THelperDialogFactory');
|
|---|
| 98 |
|
|---|
| 99 | sHALDialogFactory := factory;
|
|---|
| 100 |
|
|---|
| 101 | rv := NS_GetComponentRegistrar(compReg);
|
|---|
| 102 | compReg.RegisterFactory(NS_IHELPERAPPLAUNCHERDIALOG_IID, 'Bagel Helper App Launcher Dialog', '@mozilla.org/helperapplauncherdialog;1', factory);
|
|---|
| 103 |
|
|---|
| 104 | Inc(sRefCnt);
|
|---|
| 105 | end;
|
|---|
| 106 | end;
|
|---|
| 107 | end;
|
|---|
| 108 |
|
|---|
| 109 | destructor TGeckoSimpleHALDialog.Destroy;
|
|---|
| 110 | begin
|
|---|
| 111 | if not (csDesigning in ComponentState) then
|
|---|
| 112 | begin
|
|---|
| 113 | Dec(sRefCnt);
|
|---|
| 114 | if sRefCnt=0 then
|
|---|
| 115 | sHALDialogFactory := nil;
|
|---|
| 116 | end;
|
|---|
| 117 |
|
|---|
| 118 | inherited;
|
|---|
| 119 | end;
|
|---|
| 120 |
|
|---|
| 121 | constructor THelperDialogFactory.Create;
|
|---|
| 122 | begin
|
|---|
| 123 | inherited;
|
|---|
| 124 | end;
|
|---|
| 125 |
|
|---|
| 126 | destructor THelperDialogFactory.Destroy;
|
|---|
| 127 | begin
|
|---|
| 128 | inherited;
|
|---|
| 129 | end;
|
|---|
| 130 |
|
|---|
| 131 | procedure THelperDialogFactory.CreateInstance(aOuter: nsISupports; const iid: TGUID; out _result);
|
|---|
| 132 | var
|
|---|
| 133 | inst: THelperAppLauncherDialogImpl;
|
|---|
| 134 | begin
|
|---|
| 135 | Integer(_result) := 0;
|
|---|
| 136 |
|
|---|
| 137 | //TODO:
|
|---|
| 138 | inst := THelperAppLauncherDialogImpl.Create;
|
|---|
| 139 | if not Assigned(inst) then
|
|---|
| 140 | begin
|
|---|
| 141 | //Result := NS_ERROR_OUT_OF_MEMORY;
|
|---|
| 142 | Exit;
|
|---|
| 143 | end;
|
|---|
| 144 |
|
|---|
| 145 | //Result :=
|
|---|
| 146 | inst.QueryInterface(iid, _result);
|
|---|
| 147 | //if NS_FAILED(rv) then inst.Free;
|
|---|
| 148 | end;
|
|---|
| 149 |
|
|---|
| 150 | procedure THelperDialogFactory.LockFactory(lock: PRBool);
|
|---|
| 151 | begin
|
|---|
| 152 | //Result := NS_OK;
|
|---|
| 153 | end;
|
|---|
| 154 |
|
|---|
| 155 | procedure THelperAppLauncherDialogImpl.Show(aLauncher: nsIHelperAppLauncher; aContext: nsISupports; aReason: PRUint32); safecall;
|
|---|
| 156 | var
|
|---|
| 157 | sHelperForm:THelperDlg;
|
|---|
| 158 | begin
|
|---|
| 159 | sHelperForm := THelperDlg.Create(Application);
|
|---|
| 160 | sHelperForm.Show(aLauncher,aContext,aReason);
|
|---|
| 161 | sHelperForm.Free;
|
|---|
| 162 | end;
|
|---|
| 163 |
|
|---|
| 164 | function THelperAppLauncherDialogImpl.PromptForSaveToFile(aLauncher: nsIHelperAppLauncher; aWindowContext: nsISupports; const aDefaultFile: PWideChar; const aSuggestedFileExtension: PWideChar): nsILocalFile; safecall;
|
|---|
| 165 | var
|
|---|
| 166 | sHelperForm:THelperDlg;
|
|---|
| 167 | begin
|
|---|
| 168 | sHelperForm := THelperDlg.Create(Application);
|
|---|
| 169 | Result := sHelperForm.PromptForSaveToFile(aLauncher,aWindowContext,aDefaultFile,aSuggestedFileExtension);
|
|---|
| 170 | sHelperForm.Free;
|
|---|
| 171 | end;
|
|---|
| 172 |
|
|---|
| 173 | end.
|
|---|