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> /// Gets the active top window. /// </summary> /// <param name="extTollkit">The ext tollkit.</param> /// <returns></returns> public static Object GetActiveTopWindow(XExtendedToolkit extTollkit = null) { if (extTollkit == null) extTollkit = OO.GetExtTooklkit(); if (extTollkit != null) { try { return extTollkit.getActiveTopWindow(); } catch (Exception e) { Logger.Instance.Log(LogPriority.IMPORTANT, "OoAccessibility", "[ERROR] while trying to get the active top window", e); extTollkit = null; return null; } } return null; }
/// <summary> /// Gets all OpenOffice top windows. /// </summary> /// <param name="extTollkit">The XExtendedToolkit if available.</param> /// <returns>List of top windows.</returns> public static List<Object> GetAllTopWindows(XExtendedToolkit extTollkit = null) { List<Object> result = new List<Object>(); if (extTollkit == null) extTollkit = OO.GetExtTooklkit(); if (extTollkit != null && extTollkit.getTopWindowCount() > 0) { for (int i = 0; i < extTollkit.getTopWindowCount(); i++) { var tpw = extTollkit.getTopWindow(i); if (tpw != null) result.Add(tpw); } } return result; }
/// <summary> /// Resets this instance. And kills the OpenOffice process. /// BE CAREFULL!! /// </summary> static void reset() { Logger.Instance.Log(LogPriority.OFTEN, "OO", "Request for OpenOffice connection reset"); try { _context = null; kill(); _xMcf = null; _xDesktop = null; _xToolkit = null; // _xMsf = null; _xDesktop = GetDesktop(); addListener(GetContext()); } catch (System.Exception){ } }
/// <summary> /// Gets the ExtendedToolkit. /// </summary> /// <param name="xMcf">The ServiceManager.</param> /// <param name="xContext">The context.</param> /// <returns></returns> public static XExtendedToolkit GetExtTooklkit(XMultiComponentFactory xMcf = null, XComponentContext xContext = null) { if (_xToolkit == null) { Logger.Instance.Log(LogPriority.DEBUG, "Oo.BasicObjects", "renew XExtendedToolkit"); try { if (xContext == null) { xContext = GetContext(); } if (xMcf == null) { xMcf = GetMultiComponentFactory(xContext); } object toolkit = xMcf.createInstanceWithContext(Services.VCLX_EXT_TOOLKIT, xContext); _xToolkit = toolkit as XExtendedToolkit; addListener(_xToolkit); } catch (Exception ex) { Logger.Instance.Log(LogPriority.ALWAYS, "Can't create ExtendedToolkit ", ex); return null; } } return _xToolkit; }