/// <summary> /// Executes a dispatch. /// The dispatch call is executed in a time limited way <see cref="TimeLimitExecutor"/> (200 ms). /// </summary> /// <param name="commandUrl">The command URL to dispatch. Describes the /// feature which should be supported by internally used dispatch object. /// <see cref="https://wiki.openoffice.org/wiki/Framework/Article/OpenOffice.org_2.x_Commands#Draw.2FImpress_commands"/></param> /// <param name="docViewContrl">The document view controller. Points to /// the provider, which should be asked for valid dispatch objects.</param> /// <param name="_frame">Specifies the frame which should be the target /// for this request.</param> /// <param name="_sFlag">Optional search parameter for finding the frame /// if no special TargetFrameName was used.</param> /// <param name="args">Optional arguments for this request They depend on /// the real implementation of the dispatch object.</param> /// <remarks>This function is time limited to 200 ms.</remarks> internal static bool CallDispatch(string commandUrl, XDispatchProvider docViewContrl, String _frame = "", int _sFlag = 0, PropertyValue[] args = null) { bool successs = false; if (!String.IsNullOrWhiteSpace(commandUrl)) { bool abort = TimeLimitExecutor.WaitForExecuteWithTimeLimit( 200, new Action(() => { var disp = GetDispatcher(OO.GetMultiServiceFactory()); if (disp != null) { // A possible result of the executed internal dispatch. // The information behind this any depends on the dispatch! var result = disp.executeDispatch(docViewContrl, commandUrl, _frame, _sFlag, args); if (result.hasValue() && result.Value is unoidl.com.sun.star.frame.DispatchResultEvent) { var val = result.Value as unoidl.com.sun.star.frame.DispatchResultEvent; if (val != null && val.State == (short)DispatchResultState.SUCCESS) { successs = true; } } } }), "Dispatch Call"); successs &= abort; } return(successs); }
/// <summary> /// News the doc component. /// </summary> /// <param name="docType">Type of the doc.</param> /// <param name="xMsFactory"> </param> /// <param name="xContext"> </param> /// <returns></returns> public static XComponent OpenNewDocumentComponent(String docType, XComponentContext xContext = null, XMultiComponentFactory xMsFactory = null) { try { if (xContext == null) { xContext = OO.GetContext(); } if (xMsFactory == null) { xMsFactory = OO.GetMultiComponentFactory(xContext); } var desktop = xMsFactory.createInstanceWithContext(OO.Services.FRAME_DESKTOP, xContext); var mxCompLoader = desktop as XComponentLoader; String loadUrl = OO.DocTypes.DOC_TYPE_BASE + docType; var loadProps = new unoidl.com.sun.star.beans.PropertyValue[0]; if (mxCompLoader != null) { return(mxCompLoader.loadComponentFromURL(loadUrl, "_blank", 0, loadProps)); } } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine("Desktop to XComponentLoader cast Exeption: " + ex); } return(null); }
/// <summary> /// /// </summary> /// <param name="url"></param> public static Object GetGraphicFromUrl(string url) { try { var msf = OO.GetMultiComponentFactory(); if (msf != null) { var graphicProvider = msf.createInstanceWithContext(OO.Services.GRAPHIC_GRAPHICPROVIDER, OO.GetContext()); if (graphicProvider != null && graphicProvider is XGraphicProvider) { PropertyValue val = new PropertyValue(); val.Name = "URL"; val.Value = Any.Get(CreateBitmapUrl(url)); PropertyValue val2 = new PropertyValue(); val2.Name = "MimeType"; val2.Value = Any.Get(@"image/png"); var graphic = ((XGraphicProvider)graphicProvider).queryGraphic(new PropertyValue[] { val }); return(graphic); } } } catch (Exception ex) { Logger.Instance.Log(LogPriority.DEBUG, "oOUtils", "Cannot get Graphic provider: " + ex); } return(null); }
internal static Object CreateObjectFromService(Object _msf, String[] services) { try { // get MSF XMultiServiceFactory msf = _msf as XMultiServiceFactory; if (msf == null) { msf = OO.GetMultiServiceFactory(); } if (msf != null && services != null && services.Length > 0) { string[] serv = msf.getAvailableServiceNames(); System.Diagnostics.Debug.WriteLine("Available Service Names: " + String.Join("\n\t", serv)); //object component = msf.createInstance(services[0]); // object component = msf.createInstance("com.sun.star.document.ExportGraphicObjectResolver"); object component = msf.createInstance("com.sun.star.document.ImportEmbeddedObjectResolver"); //Debug.GetAllServicesOfObject(component); Debug.GetAllInterfacesOfObject(component); var n = ((XNameAccess)component).getElementNames(); return(component); } } catch (Exception ex) { } return(null); }
public ResizingContainer(int width, int height, string sName) { #region inner Container // create a control model at the multi service factory of the dialog model... innerScrlContrModel = OO.GetMultiServiceFactory(MXContext).createInstance(AWT_UNO_CONTROL_CONTAINER_Model) as XControlModel; innerScrlContr = OO.GetMultiServiceFactory(MXContext).createInstance(AWT_UNO_CONTROL_CONTAINER) as XControl; if (innerScrlContr != null && innerScrlContrModel != null) { innerScrlContr.setModel(innerScrlContrModel); } XMultiPropertySet xinnerScrlContMPSet = innerScrlContrModel as XMultiPropertySet; if (xinnerScrlContMPSet != null) { xinnerScrlContMPSet.setPropertyValues( new String[] { "Name", "State" }, Any.Get(new Object[] { sName, ((short)0) })); } innerWidth = width; innerHeight = height; // Set the size of the surrounding container if (innerScrlContr is XWindow) { ((XWindow)innerScrlContr).setPosSize(0, 0, innerWidth, innerHeight, PosSize.POSSIZE); } #endregion }
public void Bills03() { // When im writing in the bills text StreamWriter yc; try { yc = File.AppendText("C:\\Users\\RON TAYLOR\\Desktop\\Computer Programing\\Bills.txt"); yc.WriteLine(total_charges); yc.WriteLine("Total charges{0}:", total_charges); yc.Close(); } catch { Console.WriteLine(" file not writtten "); } Console.ReadLine(); // When im reading in the bills text StreamReader OO; OO = File.OpenText("C:\\Users\\RON TAYLOR\\Desktop\\Computer Programing\\Bills.txt"); while ((totalchargesdisplay = OO.ReadLine()) != null) { Console.WriteLine(); totalchargesdisplay = OO.ReadLine(); } OO.Close(); }
public ChessBoard(List <List <string> > cells, Side side) { Cells = cells; SideToMove = side; OOEnable = new OO(); IDKWTF = "-"; HalfTurns = 0; Turns = 1; }
/// <summary> /// Return the currently active top-level window, i.e. which has currently the input focus. /// </summary> /// <returns>The returned reference may be empty when no top-level window is active.</returns> public static object GetActiveTopWindow() { var etk = OO.GetExtTooklkit(); if (etk != null) { return(etk.getActiveTopWindow()); } return(null); }
void FillEditType(DataRow R) { cmbEdit.Items.Clear(); MetaData ToMeta = MetaData.GetMetaData(this, R["totable"].ToString()); foreach (object OO in ToMeta.EditTypes) { cmbEdit.Items.Add(OO.ToString()); } }
/// <summary> /// Provides an easy way to dispatch an URL using one call instead of multiple ones. /// Normally a complete dispatch is splitted into different parts: /// - converting and parsing the URL /// - searching for a valid dispatch object available on a dispatch provider /// - dispatching of the URL and it's parameters /// </summary> /// <param name="_msf">The MSF.</param> /// <returns>The dispatch helper or <c>null</c></returns> internal static XDispatchHelper GetDispatcher(XMultiServiceFactory _msf = null) { if (_msf == null) { _msf = OO.GetMultiServiceFactory(); } if (_msf != null) { //Create the Dispatcher return(_msf.createInstance("com.sun.star.frame.DispatchHelper") as XDispatchHelper); } return(null); }
/// <summary> /// To get the shape (may also be a group...) as a translucent png in a byte array. /// </summary> /// <param name="pngFileData">The png file data as byte array.</value> /// <returns>the png file size (only > 0 if successful)</returns> virtual public int GetShapeAsPng(out byte[] pngFileData) { pngFileData = new byte[0]; object doc = GetDocument(); // see https://blog.oio.de/2010/10/27/copy-and-paste-without-clipboard-using-openoffice-org-api/ if (IsValid(false) && doc != null && Shape != null) { System.Drawing.Rectangle rectDom = GetRelativeScreenBoundsByDom(); // See <http://www.oooforum.org/forum/viewtopic.phtml?t=50783> // properties for the png export filter: PropertyValue[] aFilterData = new PropertyValue[5]; aFilterData[0] = new PropertyValue(); aFilterData[0].Name = "PixelWidth"; aFilterData[0].Value = tud.mci.tangram.models.Any.Get(rectDom.Width); // bounding box width aFilterData[1] = new PropertyValue(); aFilterData[1].Name = "PixelHeight"; aFilterData[1].Value = tud.mci.tangram.models.Any.Get(rectDom.Height); // bounding box height aFilterData[2] = new PropertyValue(); aFilterData[2].Name = "Translucent"; aFilterData[2].Value = new uno.Any(true); // png with translucent background aFilterData[3] = new PropertyValue(); aFilterData[3].Name = "Compression"; aFilterData[3].Value = new uno.Any(0); // png compression level 0..9 (set to 0 to be fastest, smallest files would be produced by 9) aFilterData[4] = new PropertyValue(); aFilterData[4].Name = "Interlaced"; aFilterData[4].Value = new uno.Any(0); // png interlacing (off=0) /* create com.sun.star.comp.MemoryStream, Debug.GetAllInterfacesOfObject(memoryOutStream) gets: * unoidl.com.sun.star.io.XStream * unoidl.com.sun.star.io.XSeekableInputStream * unoidl.com.sun.star.io.XOutputStream * unoidl.com.sun.star.io.XTruncate * unoidl.com.sun.star.lang.XTypeProvider * unoidl.com.sun.star.uno.XWeak */ //XMultiServiceFactory xmsf = OO.GetMultiServiceFactory(OO.GetContext(), OO.GetMultiComponentFactory(OO.GetContext())); XStream memoryStream = (XStream)OO.GetContext().getServiceManager().createInstanceWithContext("com.sun.star.comp.MemoryStream", OO.GetContext()); //XStream memoryStream = (XStream)xmsf.createInstance("com.sun.star.comp.MemoryStream"); // the filter media descriptor: media type, destination, and filterdata containing the export settings from above PropertyValue[] aArgs = new PropertyValue[3]; aArgs[0] = new PropertyValue(); aArgs[0].Name = "MediaType"; aArgs[0].Value = tud.mci.tangram.models.Any.Get("image/png"); aArgs[1] = new PropertyValue(); aArgs[1].Name = "OutputStream"; aArgs[1].Value = tud.mci.tangram.models.Any.Get(memoryStream); // filter to our memory stream aArgs[2] = new PropertyValue(); aArgs[2].Name = "FilterData"; aArgs[2].Value = tud.mci.tangram.models.Any.GetAsOne(aFilterData); // create exporter service XExporter exporter = (XExporter)OO.GetContext().getServiceManager().createInstanceWithContext("com.sun.star.drawing.GraphicExportFilter", OO.GetContext()); exporter.setSourceDocument((XComponent)Shape); // call the png export filter ((XFilter)exporter).filter(aArgs); // read all bytes from stream into byte array int pngFileSize = ((XInputStream)memoryStream).available(); ((XInputStream)memoryStream).readBytes(out pngFileData, pngFileSize); return(pngFileSize); } return(0); }
/// <summary> /// Connect to a running office that is accepting connections. /// </summary> /// <param name="args">The args.</param> /// <returns>The ServiceManager to instantiate office components.</returns> public XMultiComponentFactory Connect(String[] args) { if (MXContext == null) { return(null); } try { return((XMultiComponentFactory)MXContext.getServiceManager()); } catch (unoidl.com.sun.star.lang.DisposedException) { return(OO.GetMultiComponentFactory()); } }
/// <summary> /// Returns all services of the object. /// </summary> /// <param name="obj">The obj.</param> /// <param name="debug">if set to <c>true</c> the services will be printed /// to the System.Diagnostics.Debug output.</param> /// <returns>List of all supported service names.</returns> /// <remarks>This function is time limited to 200 ms.</remarks> public static string[] GetAllServicesOfObject(Object obj, bool debug = true) { String output = ""; string[] services = new string[0]; if (obj != null) { try { TimeLimitExecutor.WaitForExecuteWithTimeLimit(200, () => { XServiceInfo si = obj as XServiceInfo; if (si != null) { // FIXME: Access violation on service request try { services = si.getSupportedServiceNames(); if (debug) { output += (services.Length + "\tServices:"); foreach (var item in services) { output += "\n" + ("\tService: " + item); } System.Diagnostics.Debug.WriteLine(output); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception happened: " + ex.ToString()); } } else { System.Diagnostics.Debug.WriteLine("Can't get services of Object because it is not a XServiceInfo provider."); } }, "GetAllServices"); } catch (unoidl.com.sun.star.lang.DisposedException) { OO.CheckConnection(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Can't get services of Object: " + e); } } return(services); }
void IDisposable.Dispose() { this.refreshPagePropertiesTimer.Stop(); this.AcccessibleCounterpart = null; try { foreach (var oS in shapeList) { oS.Dispose(); } } catch { } this.shapeList.Clear(); Disposed = true; fire_DisposingEvent(); OO.CheckConnection(); }
/// <summary> /// This convert an URL (formated as a string) to a struct com.sun.star.util.URL. /// It use a special service to do that: the URLTransformer. /// Because some API calls need it and it's not allowed to set "Complete" /// part of the util struct only. The URL must be parsed. /// </summary> /// <param name="sUrl">URL for parsing in string notation</param> /// <returns>URL in UNO struct notation </returns> public static URL ParseUrl(String sUrl) { URL aUrl; if (sUrl == null || sUrl.Equals("", StringComparison.CurrentCulture)) { System.Diagnostics.Debug.WriteLine("wrong using of URL parser"); return(null); } try { XComponentContext xOfficeCtx = OO.GetContext(); // Create special service for parsing of given URL. var xParser = (XURLTransformer)xOfficeCtx.getServiceManager().createInstanceWithContext( OO.Services.UTIL_URL_TRANSFORMER, xOfficeCtx); // Because it's an in/out parameter we must use an array of URL objects. var aParseUrl = new URL[1]; aParseUrl[0] = new URL { Complete = sUrl }; // Parse the URL xParser.parseStrict(ref aParseUrl[0]); aUrl = aParseUrl[0]; } catch (RuntimeException) { // Any UNO method of this scope can throw this exception. // Reset the return value only. aUrl = null; } catch (unoidl.com.sun.star.uno.Exception) { // "createInstance()" method of used service manager can throw it. // Then it wasn't possible to get the URL transformer. // Return default instead of realy parsed URL. aUrl = null; } return(aUrl); }
/// <summary> /// Initializes a new instance of the <see cref="ToolBar"/> class. /// </summary> /// <param name="xMsf">the XMultiComponentFactory.</param> /// <param name="name">The UIName Parameter of the ToolBar.</param> /// <param name="documentModluleIdentifier">The document modlule identifier for the ToolBar. /// E.g. "com.sun.star.text.TextDocument" to add the ToolBar to all text documents</param> public ToolBar(string name, string documentModluleIdentifier, XMultiComponentFactory xMsf = null) { if (name.Trim().Length < 1) { throw new NullReferenceException("Name for ToolBar creation is empty"); } XMcf = xMsf ?? OO.GetMultiComponentFactory(); Name = name; RecourceUrl = GetToolBarUrl(name); // Retrieve the module configuration manager supplier to get // the configuration setting from the module _xModCfgMgrSupplier = (XModuleUIConfigurationManagerSupplier) XMcf.createInstanceWithContext(OO.Services.UI_MOD_UI_CONF_MGR_SUPPLIER, OO.GetContext()); // Retrieve the module configuration manager XCfgMgr = _xModCfgMgrSupplier.getUIConfigurationManager(documentModluleIdentifier); if (XCfgMgr.hasSettings(RecourceUrl) == false) { // Creates a copy of the user interface configuration manager Settings = XCfgMgr.createSettings(); // Defines the name of the toolbar var xToolbarProperties = (XPropertySet)Settings; xToolbarProperties.setPropertyValue("UIName", Any.Get(name)); // Makes the toolbar to the UI manager available try { XCfgMgr.insertSettings(RecourceUrl, Settings); } catch (ElementExistException) { Settings = XCfgMgr.getSettings(RecourceUrl, true) as XIndexContainer; } } else { Settings = XCfgMgr.getSettings(RecourceUrl, true) as XIndexContainer; } }
protected virtual XFixedText CreateFixedLabel(String text, int _nPosX, int _nPosY, int _nWidth, int _nHeight, int _nStep, XMouseListener _xMouseListener, String sName = "") { XFixedText xFixedText = null; try { // create a controlmodel at the multiservicefactory of the dialog model... Object oFTModel = OO.GetMultiServiceFactory().createInstance(OO.Services.AWT_CONTROL_TEXT_FIXED_MODEL); Object xFTControl = OO.GetMultiServiceFactory().createInstance(OO.Services.AWT_CONTROL_TEXT_FIXED); XMultiPropertySet xFTModelMPSet = (XMultiPropertySet)oFTModel; // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xFTModelMPSet.setPropertyValues( new String[] { "Height", "Name", "PositionX", "PositionY", "Step", "Width", "Label" }, Any.Get(new Object[] { _nHeight, sName, _nPosX, _nPosY, _nStep, _nWidth, text })); if (oFTModel != null && xFTControl != null && xFTControl is XControl) { ((XControl)xFTControl).setModel(oFTModel as XControlModel); } xFixedText = xFTControl as XFixedText; if (_xMouseListener != null && xFTControl is XWindow) { XWindow xWindow = (XWindow)xFTControl; xWindow.addMouseListener(_xMouseListener); } } catch (unoidl.com.sun.star.uno.Exception ex) { System.Diagnostics.Debug.WriteLine("uno.Exception:"); System.Diagnostics.Debug.WriteLine(ex); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine("System.Exception:"); System.Diagnostics.Debug.WriteLine(ex); } return(xFixedText); }
public ChessBoard(string fen = StartFen) { Moves = ""; Figure = new Figures(this); Fen = fen; var splitedFenBySpace = fen.Split(FenSpace); var splitedFen = splitedFenBySpace[Convert.ToInt32(FenSpliter.fen)].Split(FenSeparator); SideToMove = new Side(splitedFenBySpace[Convert.ToInt32(FenSpliter.side)]); OOEnable = new OO(splitedFenBySpace[Convert.ToInt32(FenSpliter.oo)]); IDKWTF = splitedFenBySpace[Convert.ToInt32(FenSpliter.idkwtf)]; HalfTurns = Convert.ToInt32(splitedFenBySpace[Convert.ToInt32(FenSpliter.halfTurn)]); Turns = Convert.ToInt32(splitedFenBySpace[Convert.ToInt32(FenSpliter.turn)]); Cells = new List <List <string> >(); for (var i = SettingsStore.BoardLenght - 1; i >= 0; i--) { var fenRow = splitedFen[i]; var row = new List <string>(); for (var j = 0; j < SettingsStore.BoardLenght; j++) { if (int.TryParse(fenRow[0].ToString(), out int result)) { row.Add(Figures.Space); fenRow = fenRow.Substring(1); if (result > 1) { fenRow = (result - 1).ToString() + fenRow; } } else { row.Add(Figure.Key(fenRow[0].ToString())); fenRow = fenRow.Substring(1); } } Cells.Add(row); } }
//static readonly Object _selectionLock = new Object(); /// <summary> /// Get the current selection. /// </summary> /// <param name="selectionSupplier">The selection supplier.</param> /// <returns><c>false</c> if no selection could be achieved; otherwise and [XShapes] collection</returns> /// <remarks>This request is locked and time limited to 100 ms.</remarks> public static Object GetSelection(XSelectionSupplier selectionSupplier) { Object selection = false; if (selectionSupplier != null) { //FIXME: you cannot do this in a time limited execution this will lead to an hang on -- why?????? try { lock (selectionSupplier) { TimeLimitExecutor.WaitForExecuteWithTimeLimit(100, () => { Thread.BeginCriticalRegion(); var anySelection = selectionSupplier.getSelection(); Thread.EndCriticalRegion(); if (anySelection.hasValue()) { selection = anySelection.Value; } else { selection = null; } }, "GetSelection"); } } catch (DisposedException) { Logger.Instance.Log(LogPriority.DEBUG, "OoSelectionObserver", "Selection supplier disposed"); OO.CheckConnection(); } catch (ThreadAbortException) { } catch (ThreadInterruptedException) { } } return(selection); }
private void initialize() { extTollkit = OO.GetExtTooklkit(); if (extTollkit != null) { try { extTollkit.removeTopWindowListener(xTopWindowListener); } catch { try { extTollkit.removeTopWindowListener(xTopWindowListener); } catch { try { System.Threading.Thread.Sleep(20); extTollkit.removeTopWindowListener(xTopWindowListener); } catch (Exception ex) { Logger.Instance.Log(LogPriority.DEBUG, this, "can't remove top window listener form extToolkit", ex); } } } try { extTollkit.addTopWindowListener(xTopWindowListener); } catch { try { System.Threading.Thread.Sleep(20); extTollkit.addTopWindowListener(xTopWindowListener); } catch (Exception ex) { Logger.Instance.Log(LogPriority.DEBUG, this, "can't add top window listener to extToolkit", ex); } } } else { Logger.Instance.Log(LogPriority.ALWAYS, this, "[FATAL ERROR] Can't get EXTENDEDTOOLKIT!!"); } }
/// <summary> /// Try to find an unique frame name, which isn't currently used inside /// remote office instance. Because we create top level frames /// only, it's enough to check the names of existing child frames on the /// desktop only. /// </summary> /// <returns> /// should represent an unique frame name, which currently isn't /// used inside the remote office frame tree /// (Couldn't guaranteed for a real multi threaded environment. /// But we try it ...) /// </returns> public static String GetUniqueFrameName() { String sName = null; XComponentContext xCtx = OO.GetContext(); try { var xSupplier = (XFramesSupplier)xCtx.getServiceManager().createInstanceWithContext("com.sun.star.frame.Desktop", xCtx); var xContainer = (XIndexAccess)xSupplier.getFrames(); int nCount = xContainer.getCount(); for (int i = 0; i < nCount; ++i) { XFrame xFrame = (XFrame)xContainer.getByIndex(i).Value; sName = BASEFRAMENAME + _mnViewCount; while (String.Compare(sName, xFrame.getName(), System.StringComparison.Ordinal) == 0) { ++_mnViewCount; sName = BASEFRAMENAME + _mnViewCount; } } } catch (unoidl.com.sun.star.uno.Exception) { sName = BASEFRAMENAME; } if (sName == null) { System.Diagnostics.Debug.WriteLine("invalid name!"); sName = BASEFRAMENAME; } return(sName); }
//可以像普通方法一样传递 public void Do(OO oo) { //可以像普通方法一样调用 oo(hi); }
/// <summary> /// Gets the dispatch helper as anonymous object. /// </summary> /// <returns>The XDispatchHelper as Object.</returns> public static Object GetDispatchHelper_anonymous() { return(GetDispatcher(OO.GetMultiServiceFactory())); }
public void chi() { Wo W = new Wo("老徐"); OO O = new OO(); }
/// <summary> /// It try to export given document in HTML format. /// Current document will be converted to HTML and moved to new place on disk. /// A "new" file will be created by given URL (may be overwritten /// if it already exist). Right filter will be used automatically if factory of /// this document support it. If no valid filter can be found for export, /// nothing will be done here. /// </summary> /// <param name="xDocument">document which should be exported</param> /// <param name="sUrl">target URL for converted document</param> public static void SaveAsHtml(XComponent xDocument, String sUrl) { try { // First detect factory of this document. // Ask for the supported service name of this document. // If information is available it can be used to find out which // filter exist for HTML export. Normally this filter should be searched // inside the filter configuration but this little demo doesn't do so. // (see service com.sun.star.document.FilterFactory for further // informations too) // Well known filter names are used directly. They must exist in current // office installation. Otherwise this code will fail. But to prevent // this code against missing filters it check for existing state of it. XServiceInfo xInfo = (XServiceInfo)xDocument; if (xInfo != null) { // Find out possible filter name. String sFilter = null; if (xInfo.supportsService(OO.Services.DOCUMENT_TEXT)) { sFilter = "HTML (StarWriter)"; } else if (xInfo.supportsService(OO.Services.DOCUMENT_WEB)) { sFilter = "HTML"; } else if (xInfo.supportsService(OO.Services.DOCUMENT_SPREADSHEET)) { sFilter = "HTML (StarCalc)"; } // Check for existing state of this filter. if (sFilter != null) { XComponentContext xCtx = OO.GetContext(); var xFilterContainer = (XNameAccess)xCtx.getServiceManager().createInstanceWithContext( OO.Services.DOCUMENT_FILTER_FACTORY, xCtx); if (xFilterContainer.hasByName(sFilter) == false) { sFilter = null; } } // Use this filter for export. if (sFilter != null) { // Export can be forced by saving the document and using a // special filter name which can write needed format. Build // necessary argument list now. // Use special flag "Overwrite" too, to prevent operation // against possible exceptions, if file already exist. var lProperties = new PropertyValue[2]; lProperties[0] = new PropertyValue { Name = "FilterName", Value = Any.Get(sFilter) }; lProperties[1] = new PropertyValue { Name = "Overwrite", Value = Any.Get(true) }; XStorable xStore = (XStorable)xDocument; xStore.storeAsURL(sUrl, lProperties); } } } catch (unoidl.com.sun.star.io.IOException exIo) { // Can be thrown by "store()" call. // Do nothing then. Saving failed - that's it. System.Diagnostics.Debug.WriteLine(exIo); } catch (RuntimeException exRuntime) { // Can be thrown by any uno call. // Do nothing here. Saving failed - that's it. System.Diagnostics.Debug.WriteLine(exRuntime); } catch (unoidl.com.sun.star.uno.Exception exUno) { // Can be thrown by "createInstance()" call of service manager. // Do nothing here. Saving failed - that's it. System.Diagnostics.Debug.WriteLine(exUno); } }
/// <summary> /// Load document specified by an URL into given frame synchronously. /// The result of this operation will be the loaded document for success /// or null if loading failed. /// </summary> /// <param name="xFrame">frame wich should be the target of this load call</param> /// <param name="sUrl">unparsed URL for loading</param> /// <param name="lProperties">optional arguments</param> /// <returns> /// the loaded document for success or null if it's failed /// </returns> public static XComponent LoadDocument(XFrame xFrame, String sUrl, PropertyValue[] lProperties) { XComponent xDocument; String sOldName = null; try { XComponentContext xCtx = OO.GetContext(); // First prepare frame for loading // We must address it inside the frame tree without any complications. // So we set an unambiguous (we hope it) name and use it later. // Don't forget to reset original name after that. sOldName = xFrame.getName(); String sTarget = "odk_officedev_desk"; xFrame.setName(sTarget); // Get access to the global component loader of the office // for synchronous loading the document. var xLoader = (XComponentLoader)xCtx.getServiceManager().createInstanceWithContext(OO.Services.FRAME_DESKTOP, xCtx); // Load the document into the target frame by using his name and // special search flags. xDocument = xLoader.loadComponentFromURL( sUrl, sTarget, FrameSearchFlag.CHILDREN, lProperties); // don't forget to restore old frame name ... xFrame.setName(sOldName); } catch (unoidl.com.sun.star.io.IOException exIo) { // Can be thrown by "loadComponentFromURL()" call. // The only thing we should do then is to reset changed frame name! System.Diagnostics.Debug.WriteLine(exIo); xDocument = null; if (sOldName != null) { xFrame.setName(sOldName); } } catch (IllegalArgumentException exIllegal) { // Can be thrown by "loadComponentFromURL()" call. // The only thing we should do then is to reset changed frame name! System.Diagnostics.Debug.WriteLine(exIllegal); xDocument = null; if (sOldName != null) { xFrame.setName(sOldName); } } catch (RuntimeException exRuntime) { // Any UNO method of this scope can throw this exception. // The only thing we can try(!) is to reset changed frame name. System.Diagnostics.Debug.WriteLine(exRuntime); xDocument = null; if (sOldName != null) { xFrame.setName(sOldName); } } catch (unoidl.com.sun.star.uno.Exception exUno) { // "createInstance()" method of used service manager can throw it. // The only thing we should do then is to reset changed frame name! System.Diagnostics.Debug.WriteLine(exUno); xDocument = null; if (sOldName != null) { xFrame.setName(sOldName); } } return(xDocument); }
public AbstactUnoDialogBase(XComponentContext xContext) : this(xContext, OO.GetMultiComponentFactory(xContext)) { }
public AbstactUnoDialogBase() : this(OO.GetContext()) { }
public void CreateScrollableContainer(int _nPosX, int _nPosY, int _nWidth, int _nHeight, String sName) { try { // create a unique id by means of an own implementation... if (String.IsNullOrWhiteSpace(sName)) { sName = AbstactUnoDialogBase.createUniqueName(MXDlgModelNameContainer, "SCROLL_CONTAINER"); } else { sName = AbstactUnoDialogBase.createUniqueName(MXDlgModelNameContainer, sName); } //XMultiServiceFactory _xMSF = OO.GetMultiServiceFactory(MXContext); XMultiComponentFactory _xMcf = OO.GetMultiComponentFactory(MXContext, true); #region Outer Container // create a UnoControlContainerModel. A thing which differs from other dialog-controls in many aspects // Position and size of the model have no effect, so we apply setPosSize() on it's view later. // Unlike a dialog-model the container-model can not have any control-models. // As an instance of a dialog-model it can have the property "Step"(among other things), // provided by service awt.UnoControlDialogElement, without actually supporting this service! // create a control model at the multi service factory of the dialog model... outerScrlContrModel = _xMcf.createInstanceWithContext(AWT_UNO_CONTROL_CONTAINER_Model, MXContext) as XControlModel; OuterScrlContr = _xMcf.createInstanceWithContext(AWT_UNO_CONTROL_CONTAINER, MXContext) as XControl; if (OuterScrlContr != null && outerScrlContrModel != null) { OuterScrlContr.setModel(outerScrlContrModel); } XMultiPropertySet xoScrlContMPSet = outerScrlContrModel as XMultiPropertySet; if (xoScrlContMPSet != null) { // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xoScrlContMPSet.setPropertyValues( new String[] { "Height", "Name", "PositionX", "PositionY", "State", "Width" }, Any.Get(new Object[] { 0, sName, 0, 0, ((short)0), 0, 0 })); } //add to the dialog XControlContainer xCntrCont = parentCnt as XControlContainer; if (xCntrCont != null) { xCntrCont.addControl(sName, OuterScrlContr as XControl); } #endregion #region Scroll bars //insert scroll bars HorizontalScrlBar = insertHorizontalScrollBar(this, _nPosX, _nPosY + _nHeight, _nWidth); VerticalScrlBar = insertVerticalScrollBar(this, _nPosX + _nWidth, _nPosY, _nHeight); #endregion #region Set Size of outer Container //make the outer container pos and size via the pos and size of the scroll bars if (HorizontalScrlBar is XWindow) { Rectangle hSBPos = ((XWindow)HorizontalScrlBar).getPosSize(); _width = hSBPos.Width; _posX = hSBPos.X; } if (VerticalScrlBar is XWindow) { Rectangle vSBPos = ((XWindow)VerticalScrlBar).getPosSize(); _height = vSBPos.Height; _posY = vSBPos.Y; } // Set the size of the surrounding container if (OuterScrlContr is XWindow) { ((XWindow)OuterScrlContr).setPosSize(PosX, PosY, Width, Height, PosSize.POSSIZE); ((XWindow)OuterScrlContr).addMouseListener(this); } #endregion #region inner Container // create a control model at the multi service factory of the dialog model... innerScrlContrModel = _xMcf.createInstanceWithContext(AWT_UNO_CONTROL_CONTAINER_Model, MXContext) as XControlModel; InnerScrlContr = _xMcf.createInstanceWithContext(AWT_UNO_CONTROL_CONTAINER, MXContext) as XControl; if (InnerScrlContr != null && innerScrlContrModel != null) { InnerScrlContr.setModel(innerScrlContrModel); } XMultiPropertySet xinnerScrlContMPSet = innerScrlContrModel as XMultiPropertySet; if (xinnerScrlContMPSet != null) { xinnerScrlContMPSet.setPropertyValues( new String[] { "Name", "State" }, Any.Get(new Object[] { sName + "_S", ((short)0) })); } //// FIXME: only for fixing //util.Debug.GetAllServicesOfObject(parentCnt); //Object oDialogModel = OO.GetMultiComponentFactory().createInstanceWithContext(OO.Services.AWT_CONTROL_DIALOG_MODEL, MXContext); //// The named container is used to insert the created controls into... //MXDlgModelNameContainer = (XNameContainer)oDialogModel; //System.Diagnostics.Debug.WriteLine("_________"); //util.Debug.GetAllServicesOfObject(MXDlgModelNameContainer); //// END //add inner container to the outer scroll container XControlContainer outerCntrCont = OuterScrlContr as XControlContainer; if (outerCntrCont != null) { outerCntrCont.addControl(sName + "_S", InnerScrlContr as XControl); InnerWidth = Width; InnerHeight = Height; // Set the size of the surrounding container if (InnerScrlContr is XWindow) { ((XWindow)InnerScrlContr).setPosSize(0, 0, InnerWidth, InnerHeight, PosSize.POSSIZE); ((XWindow)InnerScrlContr).addMouseListener(this); } } #endregion } catch (System.Exception) { } }
public XWindow createItemWindow(XWindow xWindow) { // xMSF is set by initialize(Object[]) try { // get XWindowPeer XWindowPeer xWinPeer = (XWindowPeer)xWindow; Object o = _xMsf.createInstanceWithContext("com.sun.star.awt.Toolkit", OO.GetContext()); XToolkit xToolkit = (XToolkit)o; // create WindowDescriptor WindowDescriptor wd = new WindowDescriptor(); wd.Type = WindowClass.SIMPLE; wd.Parent = xWinPeer; wd.Bounds = new Rectangle(0, 0, 20, 23); wd.ParentIndex = (short)-1; wd.WindowAttributes = WindowAttribute.SHOW; wd.WindowServiceName = "pushbutton"; // create Button XWindowPeer cBox_xWinPeer = xToolkit.createWindow(wd);// null here var xButton = (XButton)cBox_xWinPeer; xButton.setLabel("My Texte"); XWindow cBox_xWindow = (XWindow)cBox_xWinPeer; cBox_xWindow.addKeyListener(this); return(cBox_xWindow); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("createItemWindow left not o.k.\n" + e); return(null); } }