sw/inc/textboxhelper.hxx | 3 +++ sw/source/core/doc/textboxhelper.cxx | 32 ++++++++++++++++++++++++++++++-- sw/source/core/unocore/unodraw.cxx | 6 +++++- 3 files changed, 38 insertions(+), 3 deletions(-)
New commits: commit 83857d750b9205db02d4b8bfc3c304364fae0619 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Tue May 20 19:15:29 2014 +0200 SwXDrawPage::getByIndex(): ignore textboxes Change-Id: Ie91619e1f44694a547bfbbc5ff8110099c8002e6 diff --git a/sw/inc/textboxhelper.hxx b/sw/inc/textboxhelper.hxx index bac2dcc..d3532c0 100644 --- a/sw/inc/textboxhelper.hxx +++ b/sw/inc/textboxhelper.hxx @@ -14,6 +14,7 @@ #include <com/sun/star/uno/Any.h> #include <com/sun/star/uno/Type.h> +#include <com/sun/star/lang/IndexOutOfBoundsException.hpp> class SdrPage; class SwFrmFmt; @@ -43,6 +44,8 @@ public: static std::list<SwFrmFmt*> findTextBoxes(SwDoc* pDoc); /// Count number of shapes in the document, excluding TextBoxes. static sal_Int32 getCount(SdrPage* pPage, std::list<SwFrmFmt*>& rTextBoxes); + /// Get a shape by index, excluding TextBoxes. + static css::uno::Any getByIndex(SdrPage* pPage, sal_Int32 nIndex, std::list<SwFrmFmt*>& rTextBoxes) throw(css::lang::IndexOutOfBoundsException); }; #endif // INCLUDED_SW_INC_TEXTBOXHELPER_HXX diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx index 4671580..d2cd4d7 100644 --- a/sw/source/core/doc/textboxhelper.cxx +++ b/sw/source/core/doc/textboxhelper.cxx @@ -98,19 +98,47 @@ std::list<SwFrmFmt*> SwTextBoxHelper::findTextBoxes(SwDoc* pDoc) return aRet; } +/// If the passed SdrObject is in fact a TextFrame, that is used as a TextBox. +bool lcl_isTextBox(SdrObject* pSdrObject, std::list<SwFrmFmt*>& rTextBoxes) +{ + SwVirtFlyDrawObj* pObject = PTR_CAST(SwVirtFlyDrawObj, pSdrObject); + return pObject && std::find(rTextBoxes.begin(), rTextBoxes.end(), pObject->GetFmt()) != rTextBoxes.end(); +} + sal_Int32 SwTextBoxHelper::getCount(SdrPage* pPage, std::list<SwFrmFmt*>& rTextBoxes) { sal_Int32 nRet = 0; for (size_t i = 0; i < pPage->GetObjCount(); ++i) { - SwVirtFlyDrawObj* pObject = PTR_CAST(SwVirtFlyDrawObj, pPage->GetObj(i)); - if (pObject && std::find(rTextBoxes.begin(), rTextBoxes.end(), pObject->GetFmt()) != rTextBoxes.end()) + if (lcl_isTextBox(pPage->GetObj(i), rTextBoxes)) continue; ++nRet; } return nRet; } +uno::Any SwTextBoxHelper::getByIndex(SdrPage* pPage, sal_Int32 nIndex, std::list<SwFrmFmt*>& rTextBoxes) throw(lang::IndexOutOfBoundsException) +{ + if (nIndex < 0 || nIndex >= getCount(pPage, rTextBoxes)) + throw lang::IndexOutOfBoundsException(); + + SdrObject* pRet = 0; + sal_Int32 nCount = 0; // Current logical index. + for (size_t i = 0; i < pPage->GetObjCount(); ++i) + { + if (lcl_isTextBox(pPage->GetObj(i), rTextBoxes)) + continue; + if (nCount == nIndex) + { + pRet = pPage->GetObj(i); + break; + } + ++nCount; + } + assert(pRet); + return uno::makeAny(uno::Reference<drawing::XShape>(pRet->getUnoShape(), uno::UNO_QUERY)); +} + SwFrmFmt* SwTextBoxHelper::findTextBox(SwFrmFmt* pShape) { SwFrmFmt* pRet = 0; diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx index 0c639fa..f3851d9 100644 --- a/sw/source/core/unocore/unodraw.cxx +++ b/sw/source/core/unocore/unodraw.cxx @@ -538,7 +538,11 @@ uno::Any SwXDrawPage::getByIndex(sal_Int32 nIndex) throw lang::IndexOutOfBoundsException(); ((SwXDrawPage*)this)->GetSvxPage(); - return pDrawPage->getByIndex( nIndex ); + std::list<SwFrmFmt*> aTextBoxes = SwTextBoxHelper::findTextBoxes(pDoc); + if (aTextBoxes.empty()) + return pDrawPage->getByIndex( nIndex ); + else + return SwTextBoxHelper::getByIndex(pDrawPage->GetSdrPage(), nIndex, aTextBoxes); } uno::Type SwXDrawPage::getElementType(void) throw( uno::RuntimeException, std::exception ) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits