/// <summary> /// Gets the last shape of document. /// </summary> /// <param name="doc">The doc.</param> /// <param name="pages">The pages.</param> /// <returns></returns> public static OoShapeObserver GetLastShapeOfDocument(OoAccessibleDocWnd doc, OoDrawPageObserver pages = null) { if (doc != null) { if (pages == null) { pages = doc.GetActivePage(); } if (pages != null && doc.DocumentComponent != null && doc.DocumentComponent.ChildCount > 0) { // a page doesn't have children in the accessible tree --> damn // so we have to go through the shape structure return pages.GetLastChild(); } else { Logger.Instance.Log(LogPriority.DEBUG, "AccDomWalker", "The document to walk through seems to have no child shapes"); } } return null; }
/// <summary> /// Initializes a new instance of the <see cref="OoWindowEventArgs" /> class. /// </summary> /// <param name="window">The corresponding and event throwing window.</param> /// <param name="_type">The type of event.</param> public OoWindowEventArgs(OoAccessibleDocWnd window, WindowEventType _type = WindowEventType.UNKNOWN) { Window = window; Type = _type; }
private void fireDrawSelectionChangedEvent(OoAccessibleDocWnd doc, List<OoShapeObserver> selectedShapeObservers, bool silent = false) { if (DrawSelectionChanged != null) { try { if (LastSelection != null) { foreach (OoShapeObserver shapeObs in LastSelection.SelectedItems) { shapeObs.BoundRectChangeEventHandlers -= OnShapeBoundRectChange; } } LastSelection = new OoAccessibilitySelectionEventArgs(doc, selectedShapeObservers, silent); DrawSelectionChanged.DynamicInvoke(this, LastSelection); foreach (OoShapeObserver shapeObs in LastSelection.SelectedItems) { shapeObs.BoundRectChangeEventHandlers += OnShapeBoundRectChange; } } catch (Exception ex) { Logger.Instance.Log(LogPriority.DEBUG, this, "cant fire selection changed event", ex); } } }
private void fireDrawWindowActivatedEvent(OoAccessibleDocWnd window) { if (DrawWindowActivated != null) { try { DrawWindowActivated.DynamicInvoke(this, new OoWindowEventArgs(window, WindowEventType.ACTIVATED)); } catch (Exception ex) { Logger.Instance.Log(LogPriority.DEBUG, this, "cant fire window activated event", ex); } } // also, get selection on document switch handleSelectionChanged(window, null); }
private void fireDrawWindowMinimizedEvent(OoAccessibleDocWnd window) { if (DrawWindowMinimized != null) { try { DrawWindowMinimized.DynamicInvoke(this, new OoWindowEventArgs(window, WindowEventType.MINIMIZED | WindowEventType.DEACTIVATED)); } catch (Exception ex) { Logger.Instance.Log(LogPriority.DEBUG, this, "cant fire window minimized event", ex); } } }
/// <summary> /// Resets the cache for text elements. /// </summary> public void ResetCache() { lastCachedDoc = null; }
/// <summary> /// Gets the infos about the amount of pages and the current page number of a window. /// </summary> /// <param name="win">The DRAW doc window.</param> /// <returns>a String of type ' X/Y', where X is the current page and Y the amount of pages; otherwise the empty string.</returns> private static string getPageNumInfosOfWindow(OoAccessibleDocWnd win) { String result = String.Empty; if (win != null) { int pC = win.GetPageCount(); if (pC > 1) { var aPObs = win.GetActivePage(); if (aPObs != null) { int cP = aPObs.GetPageNum(); if (cP > 0) { result += " " + cP + "/" + pC; } } } } return result; }
private void setTitelregionToDocTitle(OoAccessibleDocWnd wnd) { if (windowManager != null && wnd != null) { string appTitle = wnd.Title; appTitle += getPageNumInfosOfWindow(wnd); windowManager.SetTopRegionContent(appTitle); } }
private void handleSelectionChanged(OoAccessibleDocWnd doc, AccessibleEventObject aEvent) { // check the global selection supplier if (doc != null) { try { var controller = doc.Controller; if (controller != null && controller is XSelectionSupplier) { XShapes selectedShapes = OoSelectionObserver.GetSelection(controller as XSelectionSupplier) as XShapes; OoDrawPagesObserver pagesObserver = doc.DrawPagesObs; if (selectedShapes != null && pagesObserver != null) { List<OoShapeObserver> selectedShapesList = new List<OoShapeObserver>(); int count = selectedShapes.getCount(); for (int i = 0; i < count; i++) { XShape shape = selectedShapes.getByIndex(i).Value as XShape; if (shape != null) { OoShapeObserver shapeObserver = pagesObserver.GetRegisteredShapeObserver(shape, null); if (shapeObserver != null //&& shapeObserver.IsValid() ) { if (shapeObserver.IsValid()) { selectedShapesList.Add(shapeObserver); } else { shapeObserver.Dispose(); XDrawPage page = OoDrawUtils.GetPageForShape(shape); OoDrawPageObserver dpObs = pagesObserver.GetRegisteredPageObserver(page); OoShapeObserver so = new OoShapeObserver(shape, dpObs); pagesObserver.RegisterUniqueShape(so); } } } } fireDrawSelectionChangedEvent(doc, selectedShapesList, aEvent == null); } else { // no selection fireDrawSelectionChangedEvent(doc, new List<OoShapeObserver>(), aEvent == null); return; } } } catch (unoidl.com.sun.star.lang.DisposedException ex) { System.Diagnostics.Debug.WriteLine(ex.Source + " " + ex.Message); } } }
/// <summary> /// add a new selection event th the selection stack /// </summary> /// <param name="doc"></param> /// <param name="aEvent"></param> private void selectionChanged(OoAccessibleDocWnd doc, AccessibleEventObject aEvent) { if (aEvent != null) { selectionStack.Push(new KeyValuePair<OoAccessibleDocWnd, AccessibleEventObject>(doc, aEvent)); initSelectionHandlerThread(); } }
private void stateChanged(OoAccessibleDocWnd doc, AccessibleEventObject aEvent) { if (doc != null && aEvent != null) { if (aEvent.Source != null) { // fire window activated when document gets mouse focus var role = OoAccessibility.GetAccessibleRole(aEvent.Source as XAccessible); if (role == Accessibility.AccessibleRole.DOCUMENT) { if (OoAccessibility.HasAccessibleState(aEvent.Source as XAccessible, Accessibility.AccessibleStateType.FOCUSED)) { fireDrawWindowActivatedEvent(doc); } } } } }
private void handleAccessibleEvent(OoAccessibleDocWnd doc, tud.mci.tangram.Accessibility.AccessibleEventId id, AccessibleEventObject aEvent) { System.Diagnostics.Debug.WriteLine("Accessible event from DrawDocWnd :'" + doc.Title + "' ID: " + id); switch (id) { //case tud.mci.tangram.Accessibility.AccessibleEventId.NONE: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.ACTION_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.ACTIVE_DESCENDANT_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.ACTIVE_DESCENDANT_CHANGED_NOFOCUS: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.BOUNDRECT_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.CARET_CHANGED: // break; case tud.mci.tangram.Accessibility.AccessibleEventId.CHILD: //handleAccessibleChildEvent(doc, aEvent.Source, aEvent.NewValue, aEvent.OldValue); break; //case tud.mci.tangram.Accessibility.AccessibleEventId.COLUMN_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.CONTENT_FLOWS_FROM_RELATION_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.CONTENT_FLOWS_TO_RELATION_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.CONTROLLED_BY_RELATION_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.CONTROLLER_FOR_RELATION_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.DESCRIPTION_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.HYPERTEXT_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.INVALIDATE_ALL_CHILDREN: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.LABEL_FOR_RELATION_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.LABELED_BY_RELATION_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.LISTBOX_ENTRY_COLLAPSED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.LISTBOX_ENTRY_EXPANDED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.MEMBER_OF_RELATION_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.NAME_CHANGED: // break; case tud.mci.tangram.Accessibility.AccessibleEventId.PAGE_CHANGED: fireDrawWindowActivatedEvent(doc); break; //case tud.mci.tangram.Accessibility.AccessibleEventId.SECTION_CHANGED: // break; case tud.mci.tangram.Accessibility.AccessibleEventId.SELECTION_CHANGED: selectionChanged(doc, aEvent); break; case tud.mci.tangram.Accessibility.AccessibleEventId.SELECTION_CHANGED_ADD: selectionChanged(doc, aEvent); break; case tud.mci.tangram.Accessibility.AccessibleEventId.SELECTION_CHANGED_REMOVE: selectionChanged(doc, aEvent); break; case tud.mci.tangram.Accessibility.AccessibleEventId.SELECTION_CHANGED_WITHIN: selectionChanged(doc, aEvent); break; case tud.mci.tangram.Accessibility.AccessibleEventId.STATE_CHANGED: stateChanged(doc, aEvent); break; //case tud.mci.tangram.Accessibility.AccessibleEventId.SUB_WINDOW_OF_RELATION_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.TABLE_CAPTION_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.TABLE_COLUMN_DESCRIPTION_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.TABLE_COLUMN_HEADER_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.TABLE_MODEL_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.TABLE_ROW_DESCRIPTION_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.TABLE_ROW_HEADER_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.TABLE_SUMMARY_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.TEXT_ATTRIBUTE_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.TEXT_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.TEXT_SELECTION_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.VALUE_CHANGED: // break; //case tud.mci.tangram.Accessibility.AccessibleEventId.VISIBLE_DATA_CHANGED: // break; default: break; } }
private void addListeners(OoAccessibleDocWnd doc) { if (doc != null) { doc.AccessibleEvent += new EventHandler<OoAccessibleDocAccessibleEventArgs>(doc_AccessibleEvent); doc.WindowEvent += new EventHandler<OoAccessibleDocWindowEventArgs>(doc_WindowEvent); doc.ObserverDisposing += new EventHandler(doc_Disposing); doc.SelectionEvent += new EventHandler<OoSelectionChandedEventArgs>(doc_SelectionEvent); } }
/// <summary> /// Registers a new draw window. /// </summary> /// <param name="source">The source.</param> /// <param name="dw">The dw.</param> private void registerNewDrawWindow(XAccessible source, Object dw) { if (source != null && dw != null && !dw.Equals(false)) { Logger.Instance.Log(LogPriority.DEBUG, this, "Draw window check: '" + OoAccessibility.GetAccessibleName(source)); if (getCorrespondingAccessibleDocForXaccessible(source) == null) { Logger.Instance.Log(LogPriority.DEBUG, this, "Register new Draw window: '" + OoAccessibility.GetAccessibleName(source)); OoAccessibleDocWnd doc = new OoAccessibleDocWnd(source, dw as XAccessible); drawWnds[source] = doc; // add main window to list if (doc.Document != null) { drawDocs[source] = doc; } if (doc.DocumentWindow != null) { drawDocWnds[doc.DocumentWindow] = doc; } //drawPgSuppl.Clear(); //drawPgSuppl.AddRange(OoDrawUtils.GetDrawPageSuppliers(OO.GetDesktop())); //TODO: call the observers addListeners(doc); fireDrawWindowOpendEvent(doc); } } }
void IBailleIORendererHook.PostRenderHook(IViewBoxModel view, object content, ref bool[,] result, params object[] additionalParams) { if (Active && Wnd != null) { if (Wnd.Disposed) { Wnd = null; //TODO: maybe set this as not active return; } if (!ask) // refresh regularly { if ((DateTime.Now - last) > refresh) ask = true; } // check if the bound have to be updated or not if (ask || pos.Width < 1 || pos.Height < 1) { var activePage = Wnd.GetActivePage(); if (activePage != null) { System.Drawing.Rectangle pageBoundsInPx = OoDrawUtils.convertToPixel( new System.Drawing.Rectangle( -activePage.PagesObserver.ViewOffset.X + activePage.BorderLeft, -activePage.PagesObserver.ViewOffset.Y + activePage.BorderTop, activePage.Width - activePage.BorderLeft - activePage.BorderRight, activePage.Height - activePage.BorderTop - activePage.BorderBottom), activePage.PagesObserver.ZoomValue, OoDrawPagesObserver.PixelPerMeterY, OoDrawPagesObserver.PixelPerMeterY); var spos = new System.Drawing.Rectangle(pageBoundsInPx.X, pageBoundsInPx.Y, pageBoundsInPx.Width, pageBoundsInPx.Height); if (spos.Width > 0 && spos.Height > 0) { pos = spos; } ask = false; last = DateTime.Now; } } // make the document bounds relative to the chosen zoom level double zoom = view is BrailleIO.Interface.IZoomable ? zoom = ((BrailleIO.Interface.IZoomable)view).GetZoom() : 1; if (((BrailleIOViewRange)view).Name.Equals(WindowManager.VR_CENTER_NAME) && ((BrailleIOViewRange)view).Parent.Name.Equals(WindowManager.BS_MINIMAP_NAME)) { if (WindowManager.Instance != null) { zoom = WindowManager.Instance.MinimapScalingFactor; // handling for minimap mode } } Rectangle zPos = new Rectangle( (int)(pos.X * zoom), (int)(pos.Y * zoom), (int)(pos.Width * zoom), (int)(pos.Height * zoom) ); // add the panning offsets if (view is IPannable) { zPos.X += ((IPannable)view).GetXOffset(); zPos.Y += ((IPannable)view).GetYOffset(); } //TODO: decide in inner frame or outer frame int y1 = zPos.Y - 1; int y2 = zPos.Y + zPos.Height; int x1 = 0; int width = result.GetLength(1); int height = result.GetLength(0); //horizontal lines for (int x = 0; x < zPos.Width; x += 2) { x1 = zPos.X + x; if (x1 >= 0 && x1 < width) { if (y1 >= 0 && y1 < height) { result[y1, x1] = true; } if (y2 >= 0 && y2 < height) { result[y2, x1] = true; } } } x1 = zPos.X - 1; int x2 = zPos.X + zPos.Width; //vertical lines for (int y = 0; y < zPos.Height; y += 2) { y1 = zPos.Y + y; if (y1 >= 0 && y1 < height) { if (x1 >= 0 && x1 < width) { result[y1, x1] = true; } if (x2 >= 0 && x2 < width) { result[y1, x2] = true; } } } } }
/// <summary> /// Initializes a new instance of the <see cref="OoAccessibilitySelectionEventArgs"/> class. /// </summary> /// <param name="source">The corresponding window/document the event is thrown from.</param> /// <param name="selectedItems">The selected items.</param> /// <param name="type">The accessibility event type resulting in this event.</param> public OoAccessibilitySelectionEventArgs(OoAccessibleDocWnd source, List<OoShapeObserver> selectedShapeObservers, bool silent) { Source = source; SelectedItems = selectedShapeObservers; updateBounds(selectedShapeObservers); this.Silent = silent; }
/// <summary> /// Initializes a new instance of the <see cref="OoDrawPagesObserver"/> class. /// </summary> /// <param name="dp">The Draw document.</param> /// <param name="doc">The document related accessibility component.</param> /// <param name="docWnd">The related document accessible window component.</param> public OoDrawPagesObserver(XDrawPagesSupplier dp, OoAccComponent doc, OoAccessibleDocWnd docWnd = null) { this.PagesSupplier = dp; Document = doc; DocWnd = docWnd; // get Zoom and ViewOffset first time if (Controller != null) { if (Controller is XPropertySet) { refreshDrawViewProperties((XPropertySet)(Controller)); } // try to get dpi settings from openoffice XWindow componentWindow = Controller.ComponentWindow; if (componentWindow != null && componentWindow is XDevice) { DeviceInfo deviceInfo = (DeviceInfo)((XDevice)componentWindow).getInfo(); if (deviceInfo != null) { PixelPerMeterX = deviceInfo.PixelPerMeterX; PixelPerMeterY = deviceInfo.PixelPerMeterY; } } } // register for Zoom and ViewOffset updates addVisibleAreaPropertyChangeListener(); if (this.PagesSupplier != null) { List<XDrawPage> dpL = OoDrawUtils.DrawDocGetXDrawPageList(dp); if (PagesSupplier is unoidl.com.sun.star.frame.XTitle) { Title = ((unoidl.com.sun.star.frame.XTitle)PagesSupplier).getTitle(); } Logger.Instance.Log(LogPriority.DEBUG, this, "create DrawPagesObserver for supplier " + dp.GetHashCode() + " width title '" + Title + "' - having " + dpL.Count + " pages"); //FIXME: Do this if the api enable parallel access //Parallel.ForEach(dpL, (drawPage) => //{ // OoDrawPageObserver dpobs = new OoDrawPageObserver(drawPage, this); // DrawPageobservers[drawPage] = dpobs; // DrawPages.Add(dpobs); //}); foreach (var drawPage in dpL) { OoDrawPageObserver dpobs = new OoDrawPageObserver(drawPage, this); RegisterDrawPage(dpobs); } XModifyBroadcaster mdfBc = PagesSupplier as XModifyBroadcaster; if (mdfBc != null) { mdfBc.addModifyListener(eventForwarder); } } }
private void fireDrawWindowOpendEvent(OoAccessibleDocWnd window) { if (DrawWindowOpend != null) { try { DrawWindowOpend.DynamicInvoke(this, new OoWindowEventArgs(window, WindowEventType.OPENED)); } catch (Exception ex) { Logger.Instance.Log(LogPriority.DEBUG, this, "can't fire window opened event", ex); } } // also, get selection after window opened, but wait a bit to first get the model and controller registered // and register for view offset / zoom changes Task t = new Task( () => { Thread.Sleep(4000); handleSelectionChanged(window, null); if (window.DrawPagesObs != null) { window.DrawPagesObs.ViewOrZoomChangeEventHandlers -= OnViewOrZoomChange; window.DrawPagesObs.ViewOrZoomChangeEventHandlers += OnViewOrZoomChange; } } ); t.Start(); }
/// <summary> /// Gets the shape for modification. /// </summary> /// <param name="c">The c.</param> /// <param name="observed">The observed.</param> public OoShapeObserver GetShapeForModification(OoAccComponent c, OoAccessibleDocWnd observed) { if (observed != null && c.Role != AccessibleRole.INVALID) { //TODO: prepare name: //var shape = observed.DrawPagesObs.GetRegisteredShapeObserver(c.AccComp); OoShapeObserver shape = observed.GetRegisteredShapeObserver(c); if (shape != null) { 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; }
private void fireDrawWindowPropertyChangeEvent(OoAccessibleDocWnd window) { if (DrawWindowPropertyChange != null) { try { DrawWindowPropertyChange.DynamicInvoke(this, new OoWindowEventArgs(window, WindowEventType.CHANGED)); } catch (Exception ex) { Logger.Instance.Log(LogPriority.DEBUG, this, "cant fire window property change event", ex); } } }
private void fireDrawWindowClosedEvent(OoAccessibleDocWnd window) { if (DrawWindowClosed != null) { try { DrawWindowClosed.DynamicInvoke(this, new OoWindowEventArgs(window, WindowEventType.CLOSED | WindowEventType.DEACTIVATED)); } catch (Exception ex) { Logger.Instance.Log(LogPriority.DEBUG, this, "cant fire window closed event", ex); } } if (window.DrawPagesObs != null) { window.DrawPagesObs.ViewOrZoomChangeEventHandlers -= OnViewOrZoomChange; } }
/// <summary> /// Get a list of available Observers of elements containing text. This listed is cached. /// </summary> /// <returns>a cached list of text containing elements</returns> private List<TextElemet> getAllTextElementsOfDoc() { List<TextElemet> textElements = new List<TextElemet>(); OoAccessibleDocWnd doc = null; try { doc = OoConnector.Instance.Observer.GetActiveDocument(); } catch (System.Exception ex) { Logger.Instance.Log(LogPriority.DEBUG, this, "[ERROR] can't get active DRAW document", ex); } if (doc != null) { //check for caching DateTime now = DateTime.Now; if (doc != lastCachedDoc || (now - lastCache > cachingPeriode)) { // get text elements var pageObs = doc.GetActivePage(); if (pageObs != null) { // clone the list to enable disposing of elements from the list without destroying the iterator List<OoShapeObserver> shapes = new List<OoShapeObserver>(pageObs.shapeList); if (shapes != null && shapes.Count > 0) { foreach (OoShapeObserver shape in shapes) { if (shape != null && !shape.Disposed ) { if(shape.IsVisible()) if (shape.HasText) { textElements.Add(new TextElemet(shape)); } //else //{ // //if (!shape.IsValid()) // shape.Dispose(); //} } } } // cache lastCache = now; lastCachedDoc = doc; cachedtextElements = textElements; } } } return cachedtextElements; }