/// <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?
                }
            }
        }
        /// <summary>
        /// Sets the shape for modification to the given observer.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="silent">if set to <c>true</c> no audio feedback about the selection is given.</param>
        /// <param name="immediatly">if set to <c>true</c> the audio feedback is immediately given and all other audio feedback is aborted.</param>
        /// <returns>
        /// the currently selected Shape observer
        /// </returns>
        public bool SetShapeForModification(OoShapeObserver shape, bool silent = true, bool immediately = true)
        {
            if (shape != null)
            {
                if (shapeManipulatorFunctionProxy != null && !ImageData.Instance.Active)
                {
                    if (!silent)
                    {
                        if (immediately)
                        {
                            OoElementSpeaker.PlayElementImmediately(shape, LL.GetTrans("tangram.lector.oo_observer.selected", String.Empty));
                        }
                        else
                        {
                            OoElementSpeaker.PlayElement(shape, LL.GetTrans("tangram.lector.oo_observer.selected", String.Empty));
                        }
                    }
                    //audioRenderer.PlaySound("Form kann manipuliert werden");
                    shapeManipulatorFunctionProxy.LastSelectedShape = shape;
                    return(shapeManipulatorFunctionProxy.LastSelectedShape == shape);
                }
                else // title+desc dialog handling
                {
                    ImageData.Instance.NewSelectionHandling(shape);
                }
            }

            return(false);
        }
 /// <summary>
 /// Communicates the selection to the user as detail-region-message and audio output.
 /// </summary>
 /// <param name="e">The e.</param>
 /// <param name="immediately">if set to <c>true</c> immediately.</param>
 public void CommunicateSelection(List <OoShapeObserver> e, bool immediately = true)
 {
     if (e.Count > 1)
     {
         String audioText = LL.GetTrans("tangram.lector.oo_observer.selected_elements", e.Count);
         if (immediately)
         {
             audioRenderer.PlaySoundImmediately(audioText);
         }
         else
         {
             audioRenderer.PlaySound(audioText);
         }
         windowManager.SetDetailRegionContent(audioText);
     }
     else if (e.Count == 1)
     {
         String elementText = OoElementSpeaker.GetElementAudioText(e[0]);
         String audioText   = LL.GetTrans("tangram.lector.oo_observer.selected", elementText);
         if (immediately)
         {
             audioRenderer.PlaySoundImmediately(audioText);
         }
         else
         {
             audioRenderer.PlaySound(audioText);
         }
         windowManager.SetDetailRegionContent(elementText);
     }
 }
        void shapeManipulatorFunctionProxy_SelectedShapeChanged(object sender, SelectedShapeChangedEventArgs e)
        {
            if (sender != null && sender is OpenOfficeDrawShapeManipulator)
            {
                StopFocusHighlightModes();
                try
                {
                    if (e.Reason != ChangeReson.Property)
                    {
                        ((OpenOfficeDrawShapeManipulator)sender).SayLastSelectedShape(false);
                    }

                    if (((OpenOfficeDrawShapeManipulator)sender).IsShapeSelected)
                    {
                        OoShapeObserver _shape = ((OpenOfficeDrawShapeManipulator)sender).LastSelectedShape;
                        if (_shape != null)
                        {
                            if (e.Reason != ChangeReson.Property) // shape changed
                            {
                                BrailleDomFocusRenderer.CurrentPolyPoint = null;
                                focusHighlightPaused = false;
                            }
                            InitBrailleDomFocusHighlightMode(null, e.Reason != ChangeReson.Property);

                            if (e.Reason != ChangeReson.Property && ((OpenOfficeDrawShapeManipulator)sender).LastSelectedShapePolygonPoints == null) // in other cases the detailed infos for the  point is sent by the manipulator itself
                            {
                                WindowManager.Instance.SetDetailRegionContent(OoElementSpeaker.GetElementAudioText(_shape));
                            }

                            if (WindowManager.Instance.FocusMode == FollowFocusModes.FOLLOW_BRAILLE_FOCUS)
                            {
                                jumpToDomFocus();
                            }

                            Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] new DOM focus " + _shape.Name + " " + _shape.Text);
                        }
                    }
                    else
                    {
                        WindowManager.Instance.SetDetailRegionContent(LL.GetTrans("tangram.lector.oo_observer.selected_no"));
                    }
                }
                catch (System.Exception ex)
                {
                    Logger.Instance.Log(LogPriority.OFTEN, this, "[DRAW INTERACTION] new DOM focus error --> shape is null", ex);
                }
            }
        }
 /// <summary>
 /// Brings the last selected shape to the audio output.
 /// <param name="immediately">determine if the text should palyed immediately or not.</param>
 /// </summary>
 public void SayLastSelectedShape(bool immediately = true)
 {
     if (LastSelectedShape != null)
     {
         if (immediately)
         {
             OoElementSpeaker.PlayElementImmediately(LastSelectedShape, LL.GetTrans("tangram.oomanipulation.selected"));
         }
         else
         {
             OoElementSpeaker.PlayElement(LastSelectedShape, LL.GetTrans("tangram.oomanipulation.selected"));
         }
     }
     else
     {
         play(LL.GetTrans("tangram.oomanipulation.no_element_selected"), immediately);
     }
 }
        void shape_ObserverDisposing(object sender, EventArgs e)
        {
            if (sender == LastSelectedShape)
            {
                try
                {
                    string name = OoElementSpeaker.GetElementAudioText(LastSelectedShape);
                    play(LL.GetTrans("tangram.oomanipulation.shape.deleted", name), true);
                }
                catch (ObjectDisposedException)
                {
                    play(LL.GetTrans("tangram.oomanipulation.shape.deleted", LL.GetTrans("tangram.oomanipulation.shape")), true);
                }
                catch (Exception ex) { }

                resetSelectedShapeProperties(true);
                LastSelectedShape = null;
            }
        }
        /// <summary>
        /// Gets the shape observer for modification.
        /// </summary>
        /// <param name="c">The component to get the corresponding observer to.</param>
        /// <param name="observed">The observed window / draw document.</param>
        /// <param name="silent">if set to <c>true</c> no audio feedback about the selection is given.</param>
        /// <param name="immediatly">if set to <c>true</c> the audio feedback is immediately given and all other audio feedback is aborted.</param>
        /// <returns>The corresponding observer to the shape in the given Draw document.</returns>
        public OoShapeObserver GetShapeForModification(OoAccComponent c, OoAccessibleDocWnd observed, bool silent = true, bool immediately = true)
        {
            if (observed != null && c.Role != AccessibleRole.INVALID)
            {
                //TODO: prepare name:

                OoShapeObserver shape = observed.GetRegisteredShapeObserver(c);
                if (shape != null)
                {
                    return(GetShapeForModification(shape, observed, silent, immediately));

                    //if (shapeManipulatorFunctionProxy != null && !ImageData.Instance.Active)
                    //{
                    //    OoElementSpeaker.PlayElementImmediately(shape, LL.GetTrans("tangram.lector.oo_observer.selected", String.Empty));
                    //    //audioRenderer.PlaySound("Form kann manipuliert werden");
                    //    shapeManipulatorFunctionProxy.LastSelectedShape = shape;
                    //    return shape;
                    //}
                    //else // title+desc dialog handling
                    //{
                    //    ImageData.Instance.NewSelectionHandling(shape);
                    //}
                }
                else
                {
                    // disable the pageShapes
                    if (c.Name.StartsWith("PageShape:"))
                    {
                        return(null);
                    }

                    OoElementSpeaker.PlayElementImmediately(c, LL.GetTrans("tangram.lector.oo_observer.selected"));
                    audioRenderer.PlaySound(LL.GetTrans("tangram.lector.oo_observer.selected_element.locked"));
                }
            }
            return(null);
        }
        /// <summary>
        /// Groups the current selected obejct into a group
        /// </summary>
        /// <returns><c>true</c> if the shape was added to a group successfully; otherwise, <c>false</c>.</returns>
        private bool grouping()
        {
            if (IsShapeSelected && LastSelectedShape != null)
            {
                OoAccessibleDocWnd  draw = null;
                OoDrawPagesObserver doc  = null;
                OoDrawPageObserver  page = null;
                page = LastSelectedShape.Page;
                if (page != null)
                {
                    doc = page.PagesObserver;
                    if (doc != null)
                    {
                        draw = doc.DocWnd;
                        if (draw != null && draw.DrawPageSupplier != null)
                        {
                            var undoManager = draw.DrawPageSupplier;

                            if (_group == null) // start grouping
                            {
                                _group = createGroup();
                            }

                            if (_group != null && _group.IsGroup)
                            {
                                // set Title bar

                                // size & position
                                var size = LastSelectedShape.Size;
                                var pos  = LastSelectedShape.Position;

                                // TODO: check if this is a group
                                if (OoDrawUtils.AddShapeToGroupUndoable(_group.DomShape, LastSelectedShape.DomShape, undoManager, "Add shape to group"))
                                {
                                    LastSelectedShape.Size     = size;
                                    LastSelectedShape.Position = pos;

                                    var b = _group.Bounds;
                                    _group.Position = b.Location;

                                    play(LL.GetTrans("tangram.oomanipulation.group.added", OoElementSpeaker.GetElementAudioText(LastSelectedShape)), false);

                                    LastSelectedShape = _group;
                                    // sayLastSelectedShape(false);
                                    return(true);
                                }
                                return(false);
                            }
                        }
                    }
                }
            }
            return(false);
        }
        private bool handleButtonCombination(Object sender, ButtonReleasedEventArgs e)
        {
            #region InteractionMode.Normal

            if (InteractionManager.Instance.Mode == InteractionMode.Normal)
            {
                switch (e.ReleasedGenericKeys.Count)
                {
                    #region 1 Key
                case 1:
                    switch (e.ReleasedGenericKeys[0])
                    {
                    case "k4":
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] set Braille focus to mouse focus");
                        chooseElementWithGuiFocus();
                        e.Cancel = true;
                        break;

                    case "k5":
                        // TODO: Taste ist noch frei
                        break;

                    case "cru":
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] handle up button");
                        e.Cancel = handleUP();
                        break;

                    case "crr":
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] handle right button");
                        e.Cancel = handleRIGHT();
                        break;

                    case "crd":
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] handle down button");
                        e.Cancel = handleDOWN();
                        break;

                    case "crl":
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] handle left button");
                        e.Cancel = handleLEFT();
                        break;

                    case "crc":

                        if (_group != null)
                        {
                            Logger.Instance.Log(LogPriority.DEBUG, this, "[NOTICE]\t[INTERACTION]\t[MANIPULATION]\t" + "start grouping");
                            grouping();
                        }
                        else
                        {
                            Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] rotate element manipulation dialog");
                            RotateThroughModes();
                        }
                        e.Cancel = true;
                        //TODO: open element manipulation dialog
                        break;

                    case "hbr":

                        // start gesture recognition for tabs
                        break;

                    default:
                        break;
                    }
                    break;

                    #endregion

                    #region 2 Keys

                case 2:

                    if (e.ReleasedGenericKeys.Intersect(new List <String> {
                        "k4", "k5"
                    }).ToList().Count == 2)
                    {
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] choose next element");
                        ChooseNextElement();
                        e.Cancel = true;
                    }
                    else if (e.ReleasedGenericKeys.Intersect(new List <String> {
                        "k1", "k2"
                    }).ToList().Count == 2)
                    {
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] choose previous element");
                        ChoosePreviousElement();
                        e.Cancel = true;
                    }
                    else if (e.ReleasedGenericKeys.Intersect(new List <String> {
                        "k5", "k6"
                    }).ToList().Count == 2)
                    {
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] speak description");
                        string desc = OoElementSpeaker.GetElementDescriptionText(LastSelectedShape);
                        if (!String.IsNullOrEmpty(desc))
                        {
                            sendTextNotification(desc);
                            sendAudioFeedback(desc);
                        }
                        e.Cancel = true;
                    }
                    else if (e.ReleasedGenericKeys.Intersect(new List <String> {
                        "k3", "k6"
                    }).ToList().Count == 2)
                    {
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] send element to background");
                        if (sentToBackground())
                        {
                            sendAudioFeedback(LL.GetTrans("tangram.oomanipulation.zOrder.toBackground"));
                        }
                        else
                        {
                            playError();
                        }
                        e.Cancel = true;
                    }

                    #region crc with direction button

                    else if (e.ReleasedGenericKeys.Contains("crc"))
                    {
                        if (e.ReleasedGenericKeys.Contains("cru") ||
                            e.ReleasedGenericKeys.Contains("crr") ||
                            e.ReleasedGenericKeys.Contains("crd") ||
                            e.ReleasedGenericKeys.Contains("crl")
                            )
                        {
                            Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] rotate element manipulation dialog (weak handling)");
                            RotateThroughModes();
                            e.Cancel = true;
                        }
                    }

                    #endregion

                    #region Diagonal Interactions

                    else if (e.ReleasedGenericKeys.Intersect(new List <String>(2)
                    {
                        "cru", "crr"
                    }).ToList().Count == 2)
                    {
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] handle top right");
                        e.Cancel = handleUP_RIGHT();
                    }
                    else if (e.ReleasedGenericKeys.Intersect(new List <String>(2)
                    {
                        "cru", "crl"
                    }).ToList().Count == 2)
                    {
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] handle top left");
                        e.Cancel = handleUP_LEFT();
                    }
                    else if (e.ReleasedGenericKeys.Intersect(new List <String>(2)
                    {
                        "crd", "crr"
                    }).ToList().Count == 2)
                    {
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] handle down right");
                        e.Cancel = handleDOWN_RIGHT();
                    }
                    else if (e.ReleasedGenericKeys.Intersect(new List <String>(2)
                    {
                        "crd", "crl"
                    }).ToList().Count == 2)
                    {
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] handle down left");
                        e.Cancel = handleDOWN_LEFT();
                    }

                    #endregion

                    break;

                    #endregion

                    #region 3 Keys

                case 3:
                    if (e.ReleasedGenericKeys.Intersect(new List <String> {
                        "k1", "k2", "k3"
                    }).ToList().Count == 3)
                    {
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] choose parent group");
                        ChooseParentOfElement();
                        e.Cancel = true;
                    }
                    else if (e.ReleasedGenericKeys.Intersect(new List <String> {
                        "k4", "k5", "k6"
                    }).ToList().Count == 3)
                    {
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] choose first child in group");
                        ChooseFirstChildOfElement();
                        e.Cancel = true;
                    }
                    else if (e.ReleasedGenericKeys.Intersect(new List <String> {
                        "k1", "k4", "k5"
                    }).ToList().Count == 3)
                    {
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] delete selected shape");
                        deleteSelectedObject();
                        e.Cancel = true;
                    }
                    else if (e.ReleasedGenericKeys.Intersect(new List <String> {
                        "k2", "k3", "k5"
                    }).ToList().Count == 3)
                    {
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] bring element to front");
                        if (bringToFront())
                        {
                            sendAudioFeedback(LL.GetTrans("tangram.oomanipulation.zOrder.toFront"));
                        }
                        else
                        {
                            playError();
                        }
                        e.Cancel = true;
                    }
                    break;

                    #endregion

                    #region 4 Keys

                case 4:
                    // unfocus DOM element (no element is selected on the pin device) //
                    if (e.ReleasedGenericKeys.Intersect(new List <String> {
                        "k1", "k2", "k4", "k5"
                    }).ToList().Count == 4)
                    {
                        Logger.Instance.Log(LogPriority.MIDDLE, this, "[DRAW INTERACTION] unfocus DOM element");
                        LastSelectedShape = null;
                        playEdit();
                        AudioRenderer.Instance.PlaySoundImmediately(LL.GetTrans("tangram.oomanipulation.clear_braille_focus"));
                        sentTextFeedback(LL.GetTrans("tangram.oomanipulation.no_element_selected"));
                        e.Cancel = true;
                    }
                    break;

                    #endregion

                    #region 5 Keys
                case 5:

                    string command = String.Join(",", e.ReleasedGenericKeys);

                    switch (command)
                    {
                    case "k1,k2,k4,k5,k7":
                        if (_group == null)
                        {
                            play(LL.GetTrans("tangram.oomanipulation.group.start"));
                            if (!grouping())
                            {
                                playError();
                            }
                        }
                        else
                        {
                            stopGrouing();
                        }
                        break;

                    default:
                        break;
                    }


                    break;
                    #endregion

                default:
                    break;
                }
            }

            #endregion

            return(e != null ? e.Cancel : false);
        }