1 11 package org.eclipse.swt.browser; 12 13 import org.eclipse.swt.*; 14 import org.eclipse.swt.internal.C; 15 import org.eclipse.swt.internal.mozilla.*; 16 import org.eclipse.swt.widgets.*; 17 18 class HelperAppLauncherDialog { 19 XPCOMObject supports; 20 XPCOMObject helperAppLauncherDialog; 21 int refCount = 0; 22 23 public HelperAppLauncherDialog () { 24 createCOMInterfaces (); 25 } 26 27 int AddRef () { 28 refCount++; 29 return refCount; 30 } 31 32 void createCOMInterfaces () { 33 34 supports = new XPCOMObject (new int[] {2, 0, 0}) { 35 public int method0 (int [] args) {return QueryInterface (args[0], args[1]);} 36 public int method1 (int [] args) {return AddRef ();} 37 public int method2 (int [] args) {return Release ();} 38 }; 39 40 helperAppLauncherDialog = new XPCOMObject (new int[] {2, 0, 0, 3, 5}) { 41 public int method0 (int [] args) {return QueryInterface (args[0], args[1]);} 42 public int method1 (int [] args) {return AddRef ();} 43 public int method2 (int [] args) {return Release ();} 44 public int method3 (int [] args) {return Show (args[0], args[1], args[2]);} 45 public int method4 (int [] args) {return PromptForSaveToFile (args[0], args[1], args[2], args[3], args[4]);} 46 }; 47 } 48 49 void disposeCOMInterfaces () { 50 if (supports != null) { 51 supports.dispose (); 52 supports = null; 53 } 54 if (helperAppLauncherDialog != null) { 55 helperAppLauncherDialog.dispose (); 56 helperAppLauncherDialog = null; 57 } 58 } 59 60 int getAddress () { 61 return helperAppLauncherDialog.getAddress (); 62 } 63 64 int QueryInterface (int riid, int ppvObject) { 65 if (riid == 0 || ppvObject == 0) return XPCOM.NS_ERROR_NO_INTERFACE; 66 nsID guid = new nsID (); 67 XPCOM.memmove (guid, riid, nsID.sizeof); 68 69 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { 70 XPCOM.memmove (ppvObject, new int [] {supports.getAddress ()}, C.PTR_SIZEOF); 71 AddRef (); 72 return XPCOM.NS_OK; 73 } 74 if (guid.Equals (nsIHelperAppLauncherDialog.NS_IHELPERAPPLAUNCHERDIALOG_IID)) { 75 XPCOM.memmove (ppvObject, new int [] {helperAppLauncherDialog.getAddress ()}, C.PTR_SIZEOF); 76 AddRef (); 77 return XPCOM.NS_OK; 78 } 79 80 XPCOM.memmove (ppvObject, new int [] {0}, C.PTR_SIZEOF); 81 return XPCOM.NS_ERROR_NO_INTERFACE; 82 } 83 84 int Release () { 85 refCount--; 86 93 if (refCount == 0) disposeCOMInterfaces (); 94 return refCount; 95 } 96 97 98 99 public int Show (int aLauncher, int aContext, int aReason) { 100 105 nsISupports supports = new nsISupports (aLauncher); 106 int [] result = new int [1]; 107 int rc = supports.QueryInterface (nsIHelperAppLauncher_1_8.NS_IHELPERAPPLAUNCHER_IID, result); 108 if (rc == 0) { 109 nsIHelperAppLauncher_1_8 helperAppLauncher = new nsIHelperAppLauncher_1_8 (aLauncher); 110 rc = helperAppLauncher.SaveToDisk (0, false); 111 helperAppLauncher.Release (); 112 return rc; 113 } 114 nsIHelperAppLauncher helperAppLauncher = new nsIHelperAppLauncher (aLauncher); 115 return helperAppLauncher.SaveToDisk (0, false); 116 } 117 118 public int PromptForSaveToFile (int arg0, int arg1, int arg2, int arg3, int arg4) { 119 int aDefaultFile, aSuggestedFileExtension, _retval; 120 boolean hasLauncher = false; 121 122 131 135 nsISupports support = new nsISupports (arg0); 136 int [] result = new int [1]; 137 int rc = support.QueryInterface (nsIHelperAppLauncher_1_8.NS_IHELPERAPPLAUNCHER_IID, result); 138 boolean usingMozilla18 = rc == 0; 139 if (usingMozilla18) { 140 hasLauncher = true; 141 nsISupports supports = new nsISupports (result[0]); 142 supports.Release (); 143 } else { 144 result[0] = 0; 145 rc = support.QueryInterface (nsIHelperAppLauncher.NS_IHELPERAPPLAUNCHER_IID, result); 146 if (rc == 0) { 147 hasLauncher = true; 148 nsISupports supports = new nsISupports (result[0]); 149 supports.Release (); 150 } 151 } 152 result[0] = 0; 153 154 if (hasLauncher) { 155 aDefaultFile = arg2; 156 aSuggestedFileExtension = arg3; 157 _retval = arg4; 158 } else { 159 aDefaultFile = arg1; 160 aSuggestedFileExtension = arg2; 161 _retval = arg3; 162 } 163 164 int length = XPCOM.strlen_PRUnichar (aDefaultFile); 165 char[] dest = new char[length]; 166 XPCOM.memmove (dest, aDefaultFile, length * 2); 167 String defaultFile = new String (dest); 168 169 length = XPCOM.strlen_PRUnichar (aSuggestedFileExtension); 170 dest = new char[length]; 171 XPCOM.memmove (dest, aSuggestedFileExtension, length * 2); 172 String suggestedFileExtension = new String (dest); 173 174 Shell shell = new Shell (); 175 FileDialog fileDialog = new FileDialog (shell, SWT.SAVE); 176 fileDialog.setFileName (defaultFile); 177 fileDialog.setFilterExtensions (new String [] {suggestedFileExtension}); 178 String name = fileDialog.open (); 179 shell.close (); 180 if (name == null) { 181 if (hasLauncher) { 182 if (usingMozilla18) { 183 nsIHelperAppLauncher_1_8 launcher = new nsIHelperAppLauncher_1_8 (arg0); 184 rc = launcher.Cancel (XPCOM.NS_BINDING_ABORTED); 185 } else { 186 nsIHelperAppLauncher launcher = new nsIHelperAppLauncher (arg0); 187 rc = launcher.Cancel (); 188 } 189 if (rc != XPCOM.NS_OK) Mozilla.error (rc); 190 return XPCOM.NS_OK; 191 } 192 return XPCOM.NS_ERROR_FAILURE; 193 } 194 nsEmbedString path = new nsEmbedString (name); 195 rc = XPCOM.NS_NewLocalFile (path.getAddress (), true, result); 196 path.dispose (); 197 if (rc != XPCOM.NS_OK) Mozilla.error (rc); 198 if (result[0] == 0) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); 199 200 XPCOM.memmove (_retval, result, C.PTR_SIZEOF); 201 return XPCOM.NS_OK; 202 } 203 } 204 | Popular Tags |