void fireWindowClosedEvent(OoWindowEventArgs e)
 {
     if (WindowClosed != null)
     {
         try { WindowClosed.Invoke(this, e); }
         catch { }
     }
 }
 void OoDrawAccessibilityObserver_DrawWindowOpend(object sender, OoWindowEventArgs e)
 {
     tud.mci.tangram.TangramLector.WindowManager wm = tud.mci.tangram.TangramLector.WindowManager.Instance;
     try
     {
         Logger.Instance.Log(LogPriority.DEBUG, this, "ooDraw wnd opened " + e.Window.ToString());
         wm.ScreenObserver.SetPartOfWhnd(e.Window.DocumentComponent.ScreenBounds, e.Window.Whnd);
         DocumentBorderHook.Update();
     }
     catch (System.Exception ex)
     {
         wm.ScreenObserver.ObserveScreen();
         Logger.Instance.Log(LogPriority.DEBUG, ex);
     }
 }
        void OoDrawAccessibilityObserver_DrawWindowMinimized(object sender, OoWindowEventArgs e)
        {
            try
            {
                Logger.Instance.Log(LogPriority.DEBUG, this, "ooDraw wnd minimized " + e.Window.ToString());
            }
            catch (System.Exception ex)
            {
                Logger.Instance.Log(LogPriority.DEBUG, ex);
            }
            //tud.mci.tangram.TangramLector.WindowManager wm = tud.mci.tangram.TangramLector.WindowManager.Instance;
            ////TODO: check why the screenobserver does not capture the screen
            //wm.ScreenObserver.ObserveScreen();

            addWindowEvent(e);

            audioRenderer.PlaySound(LL.GetTrans("tangram.lector.oo_observer.window_minimized", e.Window.Title));
        }
        void OoDrawAccessibilityObserver_DrawWindowActivated(object sender, OoWindowEventArgs e)
        {
            tud.mci.tangram.TangramLector.WindowManager wm = tud.mci.tangram.TangramLector.WindowManager.Instance;
            try
            {
                DocumentBorderHook.Active = true;
                addWindowEvent(e);
                Logger.Instance.Log(LogPriority.DEBUG, this, "ooDraw wnd activated " + e.Window.ToString());

                if (e != null && e.Window != null)
                {
                    fireWindowActivatedEvent(e);
                    setTitelregionToDocTitle(e.Window);
                }
            }
            catch (System.Exception ex)
            {
                wm.ScreenObserver.ObserveScreen();
                Logger.Instance.Log(LogPriority.DEBUG, ex);
            }
        }
        private void addWindowEvent(OoWindowEventArgs e)
        {
            if (e != null)
            {
                stack.Push(e);
            }

            if (windowEventThread == null || !windowEventThread.IsAlive)
            {
                windowEventThread = new Thread(new ThreadStart(handleWindowEvents));
                int trys = 0;
                while (trys++ < 10)
                {
                    try
                    {
                        windowEventThread.Start();
                        break;
                    }
                    catch
                    {
                        if (windowEventThread != null)
                        {
                            Thread.Sleep(10);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                if (trys > 9)
                {
                    Logger.Instance.Log(LogPriority.IMPORTANT, this, "[FATAL ERROR] cannot start window event handling thread");
                }
            }
            else
            {
            }
        }
        void OoDrawAccessibilityObserver_DrawWindowClosed(object sender, OoWindowEventArgs e)
        {
            try
            {
                tud.mci.tangram.TangramLector.WindowManager wm = tud.mci.tangram.TangramLector.WindowManager.Instance;
                if (e != null && e.Window != null && wm != null && wm.ScreenObserver != null && wm.ScreenObserver.Whnd == e.Window.Whnd)
                {
                    fireWindowClosedEvent(e);
                    if (windowManager != null)
                    {
                        windowManager.SetTopRegionContent(WindowManager.MAINSCREEN_TITLE);
                    }

                    //TODO: check for other windows
                    wm.ScreenObserver.ObserveScreen();
                }
                Logger.Instance.Log(LogPriority.DEBUG, this, "[NOTICE] ooDraw wnd closed" + e.Window.ToString());
            }
            catch (System.Exception ex)
            {
                Logger.Instance.Log(LogPriority.DEBUG, ex);
            }
            audioRenderer.PlaySound(LL.GetTrans("tangram.lector.oo_observer.window_closed"));
        }
 void OoDrawAccessibilityObserver_DrawWindowPropertyChange(object sender, OoWindowEventArgs e)
 {
     addWindowEvent(e);
 }