private static void resetScreenObserver(tud.mci.tangram.TangramLector.WindowManager wm)
 {
     if (wm != null)
     {
         if (wm.ScreenObserver != null)
         {
             wm.ScreenObserver.ObserveScreen();
         }
         wm.SetTopRegionContent("");
     }
 }
 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_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);
            }
        }
        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 handleWindowEvents()
        {
            while (!stack.IsEmpty)
            {
                OoWindowEventArgs e;
                bool result = stack.TryPop(out e);
                if (!result)
                {
                    continue;
                }
                stack.Clear();
                if (e != null && e.Window != null && !e.Window.Disposed)
                {
                    if (!e.Window.IsVisible() || e.Type.HasFlag(WindowEventType.CLOSED) || e.Type.HasFlag(WindowEventType.MINIMIZED))
                    {
                        resetScreenObserver(windowManager);
                    }
                    else
                    {
                        Thread.Sleep(50); // gives the element the chance to finish the changes before requesting the new properties. Should prevent a hang on.

                        tud.mci.tangram.TangramLector.WindowManager wm = tud.mci.tangram.TangramLector.WindowManager.Instance;
                        try
                        {
                            Logger.Instance.Log(LogPriority.DEBUG, this, "ooDraw wnd property changed " + e.Window.ToString());

                            if (windowManager != null && e.Type.HasFlag(WindowEventType.ACTIVATED))
                            {
                                setTitelregionToDocTitle(e.Window);
                            }

                            var bounds = e.Window.DocumentComponent.ScreenBounds;
                            var whndl  = e.Window.Whnd;

                            if (bounds.Height < 1 || bounds.Width < 1)
                            {
                                //TODO: check if minimized
                                if (boundsCache.ContainsKey(whndl))
                                {
                                    bounds = boundsCache[whndl];
                                }
                            }
                            else
                            {
                                boundsCache.AddOrUpdate(whndl, bounds, (key, existingVal) => { return(bounds); });
                            }

                            DocumentBorderHook.Wnd = e.Window;
                            wm.ScreenObserver.SetPartOfWhnd(bounds, whndl);
                        }
                        catch (System.Exception ex)
                        {
                            resetScreenObserver(wm);
                            Logger.Instance.Log(LogPriority.DEBUG, ex);
                        }
                    }
                }
            }

            windowEventThread = null;
            return;
        }