1*cdf0e10cSrcweirimportClass(Packages.com.sun.star.uno.UnoRuntime); 2*cdf0e10cSrcweirimportClass(Packages.com.sun.star.lang.XMultiComponentFactory); 3*cdf0e10cSrcweirimportClass(Packages.com.sun.star.awt.XDialogProvider); 4*cdf0e10cSrcweirimportClass(Packages.com.sun.star.awt.XDialog); 5*cdf0e10cSrcweirimportClass(Packages.com.sun.star.uno.Exception); 6*cdf0e10cSrcweirimportClass(Packages.com.sun.star.script.provider.XScriptContext); 7*cdf0e10cSrcweir 8*cdf0e10cSrcweirimportClass(java.lang.Thread); 9*cdf0e10cSrcweirimportClass(java.lang.System); 10*cdf0e10cSrcweir 11*cdf0e10cSrcweirfunction tryLoadingLibrary( xmcf, context, name ) 12*cdf0e10cSrcweir{ 13*cdf0e10cSrcweir try 14*cdf0e10cSrcweir { 15*cdf0e10cSrcweir obj = xmcf.createInstanceWithContext( 16*cdf0e10cSrcweir "com.sun.star.script.Application" + name + "LibraryContainer", 17*cdf0e10cSrcweir context.getComponentContext()); 18*cdf0e10cSrcweir 19*cdf0e10cSrcweir xLibraryContainer = UnoRuntime.queryInterface(XLibraryContainer, obj); 20*cdf0e10cSrcweir 21*cdf0e10cSrcweir System.err.println("Got XLibraryContainer"); 22*cdf0e10cSrcweir 23*cdf0e10cSrcweir serviceObj = context.getComponentContext().getValueByName( 24*cdf0e10cSrcweir "/singletons/com.sun.star.util.theMacroExpander"); 25*cdf0e10cSrcweir 26*cdf0e10cSrcweir xme = AnyConverter.toObject(new Type(XMacroExpander), serviceObj); 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir bootstrapName = "bootstraprc"; 29*cdf0e10cSrcweir if (System.getProperty("os.name").startsWith("Windows")) 30*cdf0e10cSrcweir { 31*cdf0e10cSrcweir bootstrapName = "bootstrap.ini"; 32*cdf0e10cSrcweir } 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir libURL = xme.expandMacros( 35*cdf0e10cSrcweir "${$BRAND_BASE_DIR/program/" + bootstrapName + "::BaseInstallation}" + 36*cdf0e10cSrcweir "/share/basic/ScriptBindingLibrary/" + 37*cdf0e10cSrcweir name.toLowerCase() + ".xlb/"); 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir System.err.println("libURL is: " + libURL); 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir xLibraryContainer.createLibraryLink( 42*cdf0e10cSrcweir "ScriptBindingLibrary", libURL, false); 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir System.err.println("liblink created"); 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir } 47*cdf0e10cSrcweir catch (e) 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir System.err.println("Got an exception loading lib: " + e.getMessage()); 50*cdf0e10cSrcweir return false; 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir return true; 53*cdf0e10cSrcweir} 54*cdf0e10cSrcweir 55*cdf0e10cSrcweirfunction getDialogProvider() 56*cdf0e10cSrcweir{ 57*cdf0e10cSrcweir // UNO awt components of the Highlight dialog 58*cdf0e10cSrcweir //get the XMultiServiceFactory 59*cdf0e10cSrcweir xmcf = XSCRIPTCONTEXT.getComponentContext().getServiceManager(); 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir args = new Array; 62*cdf0e10cSrcweir //get the XDocument from the context 63*cdf0e10cSrcweir args[0] = XSCRIPTCONTEXT.getDocument(); 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir //try to create the DialogProvider 66*cdf0e10cSrcweir try { 67*cdf0e10cSrcweir obj = xmcf.createInstanceWithArgumentsAndContext( 68*cdf0e10cSrcweir "com.sun.star.awt.DialogProvider", args, 69*cdf0e10cSrcweir XSCRIPTCONTEXT.getComponentContext()); 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir catch (e) { 72*cdf0e10cSrcweir System.err.println("Error getting DialogProvider object"); 73*cdf0e10cSrcweir return null; 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir return UnoRuntime.queryInterface(XDialogProvider, obj); 77*cdf0e10cSrcweir} 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir//get the DialogProvider 80*cdf0e10cSrcweirxDialogProvider = getDialogProvider(); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweirif (xDialogProvider != null) 83*cdf0e10cSrcweir{ 84*cdf0e10cSrcweir //try to create the Highlight dialog (found in the ScriptBinding library) 85*cdf0e10cSrcweir try 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" + 88*cdf0e10cSrcweir "ScriptBindingLibrary.Highlight?location=application"); 89*cdf0e10cSrcweir if( findDialog == null ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir if (tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Dialog") == false || 92*cdf0e10cSrcweir tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Script") == false) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir System.err.println("Error loading ScriptBindingLibrary"); 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir else 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir // try to create the Highlight dialog (found in the 99*cdf0e10cSrcweir // ScriptBindingLibrary) 100*cdf0e10cSrcweir findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" + 101*cdf0e10cSrcweir "ScriptBindingLibrary.Highlight?location=application"); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir //launch the dialog 106*cdf0e10cSrcweir if ( findDialog != null ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir findDialog.execute(); 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir catch (e) { 112*cdf0e10cSrcweir System.err.println("Got exception on first creating dialog: " + 113*cdf0e10cSrcweir e.getMessage()); 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir} 116