/* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ import java.util.ArrayList; import javax.swing.event.TreeModelEvent; import javax.swing.tree.TreePath; import com.sun.star.accessibility.XAccessible; import com.sun.star.accessibility.XAccessibleContext; import com.sun.star.accessibility.XAccessibleEventBroadcaster; import com.sun.star.accessibility.XAccessibleEventListener; import com.sun.star.uno.UnoRuntime; public class AccessibilityTreeModel extends AccessibilityTreeModelBase { private boolean mbVerbose = false; public AccessibilityTreeModel (AccessibleTreeNode aRoot) { // create default node (unless we have a 'proper' node) setRoot (aRoot); maNodeMap = new NodeMap(); mxListener = new QueuedListener(new EventListener (this)); } public void clear () { maNodeMap.Clear(); } /** Lock the tree. While the tree is locked, events from the outside are not processed. Lock the tree when you change its internal structure. */ public void lock () { mnLockCount += 1; } /** Unlock the tree. After unlocking the tree as many times as locking it, a treeStructureChange event is sent to the event listeners. @param aNodeHint If not null and treeStructureChange events are thrown then this node is used as root of the modified subtree. */ public void unlock (AccessibleTreeNode aNodeHint) { mnLockCount -= 1; if (mnLockCount == 0) fireTreeStructureChanged ( new TreeModelEvent (this, new TreePath (aNodeHint.createPath()))); } @Override public synchronized void setRoot (AccessibleTreeNode aRoot) { if (getRoot() == null) super.setRoot (aRoot); else { lock (); maNodeMap.ForEach (new NodeMapCallback () { @Override public void Apply (AccTreeNode aNode) { if (maCanvas != null) maCanvas.removeNode (aNode); removeAccListener (aNode); } }); maNodeMap.Clear (); setRoot (aRoot); unlock (aRoot); } } // child management: /** Delegate the request to the parent and then register listeners at the child and add the child to the canvas. */ @Override public synchronized Object getChild (Object aParent, int nIndex) { AccessibleTreeNode aChild = (AccessibleTreeNode)super.getChild (aParent, nIndex); if (aChild == null) System.out.println ("getChild: child not found"); else // Keep translation table up-to-date. addNode (aChild); return aChild; } /** Remove a node (and all children) from the tree model. */ private boolean removeChild (AccessibleTreeNode aNode) { try { if( aNode == null ) { System.out.println ("can't remove null node"); return false; } else { // depth-first removal of children while (aNode.getChildCount() > 0) { if ( ! removeChild (aNode.getChildNoCreate (0))) break; } // Remove node from its parent. AccessibleTreeNode aParent = aNode.getParent(); if (aParent != null) { int nIndex = aParent.indexOf(aNode); aParent.removeChild (nIndex); } maNodeMap.RemoveNode (aNode); } } catch (Exception e) { System.out.println ("caught exception while removing child " + aNode + " : " + e); e.printStackTrace (); return false; } return true; } public void removeNode (XAccessibleContext xNode) { if (xNode != null) { AccessibleTreeNode aNode = maNodeMap.GetNode (xNode); AccessibleTreeNode aRootNode = (AccessibleTreeNode)getRoot(); TreeModelEvent aEvent = createEvent (aRootNode, aNode); removeChild (aNode); if (mbVerbose) System.out.println (aNode); fireTreeNodesRemoved (aEvent); maCanvas.repaint (); } } /** Add add a new child to a parent. @return Returns the new or existing representation of the specified accessible object. */ private AccessibleTreeNode addChild (AccTreeNode aParentNode, XAccessible xNewChild) { AccessibleTreeNode aChildNode = null; try { // First make sure that the accessible object does not already have // a representation. aChildNode = maNodeMap.GetNode(xNewChild); if (aChildNode == null) aChildNode = aParentNode.addAccessibleChild (xNewChild); else System.out.println ("node already present"); } catch (Exception e) { System.out.println ("caught exception while adding child " + xNewChild + " to parent " + aParentNode + ": " + e); e.printStackTrace (); } return aChildNode; } public void addChild (XAccessibleContext xParent, XAccessible xChild) { AccessibleTreeNode aParentNode = maNodeMap.GetNode (xParent); if (aParentNode instanceof AccTreeNode) { AccessibleTreeNode aChild = addChild ((AccTreeNode)aParentNode, xChild); if (addNode (aChild)) { if (maCanvas != null) maCanvas.updateNode ((AccTreeNode)aParentNode); // A call to fireTreeNodesInserted for xNew // should be sufficient but at least the // StringNode object that contains the number of // children also changes and we do not know its // index relative to its parent. Therefore the // more expensive fireTreeStructureChanged is // necessary. fireTreeNodesInserted (createChildUpdateEvent (xParent)); updateNode (xParent, AccessibleTreeHandler.class); } maCanvas.repaint (); } } /** Add the child node to the internal tree structure. @param aNode The node to insert into the internal tree structure. */ private boolean addNode (AccessibleTreeNode aNode) { boolean bRet = false; try { if ( ! maNodeMap.ValueIsMember (aNode)) { if (aNode instanceof AccTreeNode) { AccTreeNode aChild = (AccTreeNode)aNode; XAccessibleContext xChild = aChild.getContext(); registerAccListener (aChild); if (maCanvas != null) maCanvas.addNode (aChild); maNodeMap.InsertNode (xChild, aChild); } bRet = true; } } catch (Exception e) { System.out.println ("caught exception while adding node " + aNode + ": " + e); e.printStackTrace (); } return bRet; } /** create path to node, suitable for TreeModelEvent constructor * @see javax.swing.event.TreeModelEvent#TreeModelEvent */ private Object[] createPath (AccessibleTreeNode aNode) { ArrayList aPath = new ArrayList(); aNode.createPath (aPath); return aPath.toArray(); } // listeners (and helper methods) // We are registered with listeners as soon as objects are in the // tree cache, and we should get removed as soon as they are out. private void fireTreeNodesChanged(TreeModelEvent e) { for(int i = 0; i < maTMListeners.size(); i++) { maTMListeners.get(i).treeNodesChanged(e); } } protected void fireTreeNodesInserted(final TreeModelEvent e) { for(int i = 0; i < maTMListeners.size(); i++) { maTMListeners.get(i).treeNodesInserted(e); } } private void fireTreeNodesRemoved(final TreeModelEvent e) { for(int i = 0; i < maTMListeners.size(); i++) { maTMListeners.get(i).treeNodesRemoved(e); } } private void fireTreeStructureChanged(final TreeModelEvent e) { for(int i = 0; i < maTMListeners.size(); i++) { maTMListeners.get(i).treeStructureChanged(e); } } /** Create a TreeModelEvent object that informs listeners that one child has been removed from or inserted into its parent. */ private TreeModelEvent createChildUpdateEvent (XAccessibleContext xParent) { AccessibleTreeNode aParentNode = maNodeMap.GetNode (xParent); return createEvent (aParentNode, xParent); } private TreeModelEvent createEvent (AccessibleTreeNode aParentNode, XAccessibleContext xChild) { AccessibleTreeNode aChildNode = null; if (xChild != null) aChildNode = maNodeMap.GetNode (xChild); return createEvent (aParentNode, aChildNode); } protected TreeModelEvent createEvent ( AccessibleTreeNode aParentNode, AccessibleTreeNode aChildNode) { Object[] aPathToParent = createPath (aParentNode); int nIndexInParent = -1; if (aChildNode != null) nIndexInParent = aParentNode.indexOf (aChildNode); if (mbVerbose) System.out.println (aChildNode + " " + nIndexInParent); if (nIndexInParent == -1) // This event may be passed only to treeStructureChanged of the listeners. return new TreeModelEvent (this, aPathToParent); else // General purpose event for removing or inserting known nodes. return new TreeModelEvent (this, aPathToParent, new int[] {nIndexInParent}, new Object[] {aChildNode} ); } /** Create a TreeModelEvent that indicates changes at those children of the specified node with the specified indices. */ private TreeModelEvent createChangeEvent (AccTreeNode aNode, java.util.List aChildIndices) { // Build a list of child objects that are indicated by the given indices. int nCount = aChildIndices.size(); Object aChildObjects[] = new Object[nCount]; int nChildIndices[] = new int[nCount]; for (int i=0; i class2) { AccessibleTreeNode aTreeNode = maNodeMap.GetNode (xSource); AccTreeNode aNode = null; if (mbVerbose) System.out.println ("updating node " + xSource + " " + aTreeNode); if (aTreeNode instanceof AccTreeNode) { aNode = (AccTreeNode) aTreeNode; // Get list of affected children. java.util.List aChildIndices = aNode.updateChildren ( class1, class2); // Fire events that these children may have changed. fireTreeNodesChanged ( createChangeEvent (aNode, aChildIndices)); } return aNode; } /** The listener to be registered with the accessible objects. * Could be set to 'this' for same-thread event delivery, or to an * instance of QueuedListener for multi-threaded delivery. May * not be changed, since this would trip the * register/removeAccListener logic. */ private final XAccessibleEventListener mxListener; // Map to translate from accessible object to corresponding tree node. private final NodeMap maNodeMap; // If the lock count is higher then zero, then no events are processed. private int mnLockCount; private Canvas maCanvas; } widgets LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-07-28 01:16:00 +0500
committerMike Kaganski <mike.kaganski@collabora.com>2024-07-28 01:14:42 +0200
commit233af54afb6e493c3538efe7c93d0f53f1b4c3ab (patch)
treef31908c2b29995e6ea7f0d51edb4877a2773ae54 /sw/UITest_sw_findReplace.mk
parent5373679b695e5bd4f68fe4554234dd9facc3e54f (diff)
tdf#162219: pass correct DecimalDigits value to SQLBindParameter HEADmaster
... when setting DECIMAL / NUMERIC. Passing 'scale' from setObjectWithInfo to SQLBindParameter was wrong anyway: in setObjectWithInfo, the scale is needed if it converts the object 'x' to the requested format before sending to the database. In this case, it mismatched with the actual count of decimals in the string sent to ODBC: it could be "1" or "1.2"; but 'scale' is always equal to the scale of the parameter in the database (4 in the bugdoc), which resulted in the error returned by driver. Note that there is code that truncates excessive decimals - it is in OKeySet::impl_convertValue_throw, implemented for i#106772; it would be best to remove that code, and let the database do its magic: e.g., passing a string like "1.99999" to a DECIMAL(19,4) field in MS SQL Server would round it to 2, while our code truncates it to 1.9999. The ODBC driver can handle more digits itself. But that isn't in the scope here, and may need to tweak other database connectors. Change-Id: Ib50c6d78bfd0cbf5ecd59f46f300107076ec0037 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171127 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>