void interactionManager_GesturePerformed(object sender, GestureEventArgs e)
 {
     if (e != null)
     {
         sentGesturePerformedToRegisteredSpecifiedFunctionProxies(sender, e);
     }
 }
        /// <summary>
        /// Handles the touch request for an OpenOoffice draw object.
        /// </summary>
        /// <param name="element">The element at a specific location.</param>
        /// <param name="p">The point, that was touched.</param>
        /// <param name="e">The <see cref="tud.mci.tangram.TangramLector.GestureEventArgs"/> instance containing the event data.</param>
        /// <returns>it is handleable by openOffice observers or should be handles by UIA picker</returns>
        private bool handleTouchRequestForOO(AutomationElement element, Point p, GestureEventArgs e)
        {
            if (element != null)
            {
                int wHndl = element.Current.NativeWindowHandle;
                int pid = element.Current.ProcessId;
                int sofficePid = OoUtils.GetOoProcessID();
                int sofficeBinPid = OoUtils.GetOoBinProcessID();

                // check if the element seems to be an OpenOffice element
                if (pid != sofficePid && pid != sofficeBinPid)
                {
                    // if not, than check if the parent process is OpenOffice
                    var pp = getParentProcess(pid);
                    if (pp == null || pp.Id != sofficePid)
                    {
                        return false;
                    }
                    else // use the wHndl of the parent process
                    {
                        wHndl = (pp != null) ? pp.MainWindowHandle.ToInt32() : wHndl;
                    }
                }


                // check the window handle
                if (wHndl == 0)
                {
                    // get the main window of the process
                    Process process = Process.GetProcessById(pid);
                    if (process != null)
                    {
                        wHndl = process.MainWindowHandle.ToInt32();
                    }
                }

                // get the 
                if (OoConnector.Instance != null && OoConnector.Instance.Observer != null)
                {
                    var observed = OoConnector.Instance.Observer.ObservesWHndl(wHndl);
                    if (observed != null)
                    {
                        handleSelectedOoAccItem(observed, p, e);
                        Logger.Instance.Log(LogPriority.DEBUG, this, "[NOTICE] touched element is in a known Open Office window");
                        return true;
                    }
                }
            }
            return false;
        }
        protected override void im_GesturePerformed(object sender, GestureEventArgs e)
        {
            if (e != null)
            {
                if (e.Gesture.Name.Equals("tap"))
                {
                    BrailleIOScreen vs = GetVisibleScreen();
                    if (vs != null)
                    {
                        BrailleIOViewRange vr = GetTouchedViewRange(e.Gesture.NodeParameters[0].X, e.Gesture.NodeParameters[0].Y, vs);
                        if (vr != null)
                        {

                            CheckForTouchedBrailleText(vr, e);

                            String vrName = vr.Name;
                            Logger.Instance.Log(LogPriority.DEBUG, this, "[INTERACTION] tap in " + vrName);

                            // handling for top and detail region
                            if (vrName.Equals(VR_TOP_NAME) || vrName.Equals(VR_DETAIL_NAME))
                            {
                                String text = GetTextContentOfRegion(vs, vrName);
                                audioRenderer.PlaySoundImmediately(text);
                                return;
                            }

                            // handling for status region
                            else if (vrName.Equals(VR_STATUS_NAME))
                            {
                                String text = GetTextContentOfRegion(vs, vrName);
                                switch (text)
                                {
                                    case LectorStateNames.BRAILLE_MODE:
                                        text = LL.GetTrans("tangram.lector.wm.modes.BRAILLE_MODE");
                                        break;

                                    case LectorStateNames.FOLLOW_BRAILLE_FOCUS_MODE:
                                        text = LL.GetTrans("tangram.lector.wm.modes.FOLLOW_BRAILLE_FOCUS_MODE");
                                        break;

                                    case LectorStateNames.FOLLOW_MOUSE_FOCUS_MODE:
                                        text = LL.GetTrans("tangram.lector.wm.modes.FOLLOW_MOUSE_FOCUS_MODE");
                                        break;

                                    case LectorStateNames.STANDARD_MODE:
                                        text = LL.GetTrans("tangram.lector.wm.modes.STANDARD_MODE");
                                        break;

                                    default:
                                        break;
                                }
                                audioRenderer.PlaySoundImmediately(text);
                                return;
                            }

                            Point p = GetTapPositionOnScreen(e.Gesture.NodeParameters[0].X, e.Gesture.NodeParameters[0].Y, vr);

                            //check if a OpenOffice Window is presented
                            if (ScreenObserver != null && ScreenObserver.Whnd != null)
                            {
                                var observed = isObservedOpebnOfficeDrawWindow(ScreenObserver.Whnd.ToInt32());
                                if (observed != null)
                                {
                                    handleSelectedOoAccItem(observed, p, e);
                                    return;
                                }
                            }

                            // if no OpenOfficeDraw Window could be found
                            var element = UiaPicker.GetElementFromScreenPosition(p.X, p.Y);

                            if (element != null)
                            {
                                string className = element.Current.ClassName;
                                if (String.IsNullOrEmpty(className) || className.Equals(OO_DOC_WND_CLASS_NAME))
                                {
                                    if (handleTouchRequestForOO(element, p, e)) return;
                                }

                                //generic handling
                                if (e.ReleasedGenericKeys.Count < 2 &&
                                    e.PressedGenericKeys.Count < 1 &&
                                    e.ReleasedGeneralKeys.Contains(BrailleIO.Interface.BrailleIO_DeviceButton.Gesture))
                                {
                                    UiaPicker.SpeakElement(element);
                                }
                            }
                        }
                    }
                }
            }
        }
        internal bool fireGestureEvent(Object sender, GestureEventArgs args)
        {
            bool cancel = false;
            if (GesturePerformed != null && args != null)
            {
                foreach (EventHandler<GestureEventArgs> hndl in GesturePerformed.GetInvocationList())
                {
                    if (cancel) return cancel;

                    if (hndl != null && hndl.Target is IInteractionContextProxy)
                    {
                        if (!((IInteractionContextProxy)hndl.Target).Active)
                        {
                            continue;
                        }
                    }

                    try
                    {
                        if (hndl != null) { hndl.Invoke(sender, args); }
                        if (args.Cancel == true)
                        {
                            cancel = args.Cancel;
                            break;
                        }
                    }
                    catch (Exception) { }
                }
            }
            return cancel;
        }
 private void sentGesturePerformedToRegisteredSpecifiedFunctionProxies(object sender, GestureEventArgs e)
 {
     if (eventForwarder != null) { eventForwarder.fireGestureEvent(sender, e); }
 }
        /// <summary>
        /// If Braille text is at the requested position in the given view range that this function tries to get the corresponding text.
        /// </summary>
        /// <param name="vr">The viewrange to check.</param>
        /// <param name="e">the gestrure evnet</param>
        private String CheckForTouchedBrailleText(BrailleIOViewRange vr, GestureEventArgs e)
        {
            if (vr.ContentRender is ITouchableRenderer)
            {
                var touchRendeer = (ITouchableRenderer)vr.ContentRender;

                // calculate the position in the content
                int x = (int)e.Gesture.NodeParameters[0].X;
                int y = (int)e.Gesture.NodeParameters[0].Y;

                x = x - vr.ViewBox.X - vr.ContentBox.X - vr.GetXOffset();
                y = y - vr.ViewBox.Y - vr.ContentBox.Y - vr.GetYOffset();

                var touchedElement = touchRendeer.GetContentAtPosition(x, y);
                if (touchedElement != null && touchedElement is RenderElement)
                {
                    var touchedValue = ((RenderElement)touchedElement).GetValue();
                    if (((RenderElement)touchedElement).HasSubParts())
                    {
                        List<RenderElement> touchedSubparts = ((RenderElement)touchedElement).GetSubPartsAtPoint(x, y);
                        if (touchedSubparts != null && touchedSubparts.Count > 0)
                        {
                            touchedValue = touchedSubparts[0].GetValue();
                        }
                    }

                    System.Diagnostics.Debug.WriteLine("----- [BRAILLE TEXT TOUCHED] : '" + touchedValue.ToString() + "'");
                    return touchedValue.ToString();
                }
            }
            return String.Empty;
        }
        /// <summary>
        /// Reads a selected oo acc item aloud.
        /// </summary>
        /// <param name="observed">The observed Open Office window.</param>
        /// <param name="p">The point to check.</param>
        private void handleSelectedOoAccItem(Accessibility.OoAccessibleDocWnd observed, Point p, GestureEventArgs eventData = null)
        {
            if (observed != null && observed.DocumentComponent != null)
            {
                //try to get the touched element
                tud.mci.tangram.Accessibility.OoAccComponent c = observed.DocumentComponent.GetAccessibleFromScreenPos(p);

                if (eventData == null || ( // selection for reading
                    eventData.PressedGenericKeys.Count < 1 && eventData.ReleasedGenericKeys.Count == 1
                    && eventData.ReleasedGeneralKeys.Contains(BrailleIO_DeviceButton.Gesture)
                    ))
                {
                    // try to get a shape observer for better audio output
                    if (c != null && observed.DrawPagesObs != null)
                    {
                        OoShapeObserver sObs = observed.DrawPagesObs.GetRegisteredShapeObserver(c);
                        String text = "";
                        if (sObs != null)
                        {
                            text = OoElementSpeaker.PlayElementTitleAndDescriptionImmediately(sObs);
                        }
                        else
                        {
                            text = OoElementSpeaker.PlayElementImmediately(c);
                        }
                        SetDetailRegionContent(text);
                    }
                }
                else if (eventData != null && eventData.ReleasedGenericKeys.Contains("hbr"))
                {
                    OoShapeObserver shape = OoConnector.Instance.Observer.GetShapeForModification(c, observed);
                    //TODO: what to do if shape is null?
                }
            }
        }
 protected bool fireGestureEvent(BrailleIO.BrailleIODevice device, List<BrailleIO_DeviceButton> releasedGeneralKeys, List<String> releasedGenericKeys, List<BrailleIO_DeviceButton> pressedGeneralKeys, List<String> pressedGenericKeys, Gestures.Recognition.Interfaces.IClassificationResult gesture)
 {
     var args = new GestureEventArgs(device, pressedGeneralKeys, pressedGenericKeys, releasedGeneralKeys, releasedGenericKeys, gesture);
     Logger.Instance.Log(LogPriority.OFTEN, this, "Gesture performed: " + args.Gesture.ToString());
     bool cancel = base.fireGestureEvent(args);
     if (cancel) { System.Diagnostics.Debug.WriteLine("InteractionManager Event canceled"); }
     return cancel;
 }
 protected virtual bool fireGestureEvent(GestureEventArgs args)
 {
     bool cancel = false;
     if (GesturePerformed != null && args != null)
     {
         foreach (EventHandler<GestureEventArgs> hndl in GesturePerformed.GetInvocationList())
         {
             try
             {
                 if (hndl != null) { hndl.DynamicInvoke(this, args); }
                 if (args.Cancel == true)
                 {
                     cancel = args.Cancel;
                     break;
                 }
             }
             catch (Exception) { }
         }
     }
     return cancel;
 }
 void im_GesturePerformedEvent(object sender, GestureEventArgs e)
 {
     if (e.Gesture.Name.Equals("tap") && _shape != null)
     {
         var shape = getSelectedShape();
         if (!shape.Equals(_shape))
         {
             // after saving old data, new data has to be loaded
             loadImageData();
             setContent(TITLE_DESC_VIEW_NAME, Property.Title);
         }
     }
 }