From 39b2de7545780d8897c9f28cbedfefd672cd53d7 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Fri, 12 Aug 2011 00:08:26 -0400 Subject: Code page should be the same for the same drawing page. This removes O(n^2) from the process of querying the code pages for form elements. --- forms/source/misc/InterfaceContainer.cxx | 10 +++++++- offapi/com/sun/star/document/XCodeNameQuery.idl | 4 +++ sc/source/ui/unoobj/servuno.cxx | 34 +++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/forms/source/misc/InterfaceContainer.cxx b/forms/source/misc/InterfaceContainer.cxx index 9c25049affb8..e1608ec1d4d2 100644 --- a/forms/source/misc/InterfaceContainer.cxx +++ b/forms/source/misc/InterfaceContainer.cxx @@ -148,7 +148,15 @@ void OInterfaceContainer::impl_addVbEvents_nolck_nothrow( const sal_Int32 i_nIn if ( xElementAsForm.is() ) break; - ::rtl::OUString sCodeName( xNameQuery->getCodeNameForObject( xElement ) ); + rtl::OUString sCodeName; + { + Reference xThis = static_cast(this); + sal_Int32 nPageIndex = xNameQuery->getPageIndexForObject(xThis); + if (nPageIndex >= 0) + sCodeName = xNameQuery->getCodeNameByIndex(nPageIndex); + else + sCodeName = xNameQuery->getCodeNameForObject(xElement); + } Reference< XPropertySet > xProps( xElement, UNO_QUERY_THROW ); ::rtl::OUString sServiceName; diff --git a/offapi/com/sun/star/document/XCodeNameQuery.idl b/offapi/com/sun/star/document/XCodeNameQuery.idl index 6c3c992e32e8..4cddafee9da8 100644 --- a/offapi/com/sun/star/document/XCodeNameQuery.idl +++ b/offapi/com/sun/star/document/XCodeNameQuery.idl @@ -39,6 +39,10 @@ interface XCodeNameQuery { //------------------------------------------------------------------------- string getCodeNameForObject( [in] com::sun::star::uno::XInterface aObj ); + + string getCodeNameByIndex( [in] long nIndex ); + + long getPageIndexForObject( [in] com::sun::star::uno::XInterface aObj ); }; //============================================================================= diff --git a/sc/source/ui/unoobj/servuno.cxx b/sc/source/ui/unoobj/servuno.cxx index e83c19437215..f53fd9de43ab 100644 --- a/sc/source/ui/unoobj/servuno.cxx +++ b/sc/source/ui/unoobj/servuno.cxx @@ -239,6 +239,40 @@ public: return sCodeName; } + rtl::OUString SAL_CALL getCodeNameByIndex( sal_Int32 nIndex ) throw (uno::RuntimeException) + { + if (!mpDocShell) + return rtl::OUString(); + + String aName; + if (!mpDocShell->GetDocument()->GetCodeName(static_cast(nIndex), aName)) + return rtl::OUString(); + return aName; + } + + sal_Int32 SAL_CALL getPageIndexForObject( const uno::Reference& xIf ) throw(uno::RuntimeException) + { + if (!mpDocShell) + return -1; + + uno::Reference xSupplier(mpDocShell->GetModel(), uno::UNO_QUERY_THROW); + uno::Reference xIndex(xSupplier->getDrawPages(), uno::UNO_QUERY_THROW); + + for (sal_Int32 i = 0, n = xIndex->getCount(); i < n; ++i) + { + try + { + uno::Reference xFormSupplier(xIndex->getByIndex(i), uno::UNO_QUERY_THROW); + uno::Reference xFormIndex(xFormSupplier->getForms(), uno::UNO_QUERY_THROW); + // get the www-standard container + uno::Reference xFormControls(xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW); + if (xFormControls == xIf) + return i; + } + catch( uno::Exception& ) {} + } + return -1; + } }; //------------------------------------------------------------------------ -- cgit v1.2.3