summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@suse.com>2011-08-12 00:08:26 -0400
committerKohei Yoshida <kohei.yoshida@suse.com>2011-08-16 21:22:41 -0400
commit39b2de7545780d8897c9f28cbedfefd672cd53d7 (patch)
tree14a4dd58f4e9c8fc0b8f01560032bfaa79b023bc
parentbc01bc636d104b435ea5ad1dcc7cab85d6dc4b9a (diff)
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.
-rw-r--r--forms/source/misc/InterfaceContainer.cxx10
-rw-r--r--offapi/com/sun/star/document/XCodeNameQuery.idl4
-rw-r--r--sc/source/ui/unoobj/servuno.cxx34
3 files changed, 47 insertions, 1 deletions
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<XInterface> xThis = static_cast<XContainer*>(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<SCTAB>(nIndex), aName))
+ return rtl::OUString();
+ return aName;
+ }
+
+ sal_Int32 SAL_CALL getPageIndexForObject( const uno::Reference<uno::XInterface>& xIf ) throw(uno::RuntimeException)
+ {
+ if (!mpDocShell)
+ return -1;
+
+ uno::Reference<drawing::XDrawPagesSupplier> xSupplier(mpDocShell->GetModel(), uno::UNO_QUERY_THROW);
+ uno::Reference<container::XIndexAccess> xIndex(xSupplier->getDrawPages(), uno::UNO_QUERY_THROW);
+
+ for (sal_Int32 i = 0, n = xIndex->getCount(); i < n; ++i)
+ {
+ try
+ {
+ uno::Reference<form::XFormsSupplier> xFormSupplier(xIndex->getByIndex(i), uno::UNO_QUERY_THROW);
+ uno::Reference<container::XIndexAccess> xFormIndex(xFormSupplier->getForms(), uno::UNO_QUERY_THROW);
+ // get the www-standard container
+ uno::Reference<container::XIndexAccess> xFormControls(xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW);
+ if (xFormControls == xIf)
+ return i;
+ }
+ catch( uno::Exception& ) {}
+ }
+ return -1;
+ }
};
//------------------------------------------------------------------------