Kaydet (Commit) 69578bf0 authored tarafından Miklos Vajna's avatar Miklos Vajna

SwXDrawPage::getByIndex(): ignore textboxes

Change-Id: I643ca4268e15af1882adb168af152835ef216cd9
üst f1dae10c
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <com/sun/star/uno/Any.h> #include <com/sun/star/uno/Any.h>
#include <com/sun/star/uno/Type.h> #include <com/sun/star/uno/Type.h>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
class SdrPage; class SdrPage;
class SwFrmFmt; class SwFrmFmt;
...@@ -43,6 +44,8 @@ public: ...@@ -43,6 +44,8 @@ public:
static std::list<SwFrmFmt*> findTextBoxes(SwDoc* pDoc); static std::list<SwFrmFmt*> findTextBoxes(SwDoc* pDoc);
/// Count number of shapes in the document, excluding TextBoxes. /// Count number of shapes in the document, excluding TextBoxes.
static sal_Int32 getCount(SdrPage* pPage, std::list<SwFrmFmt*>& rTextBoxes); 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 #endif // INCLUDED_SW_INC_TEXTBOXHELPER_HXX
......
...@@ -98,19 +98,47 @@ std::list<SwFrmFmt*> SwTextBoxHelper::findTextBoxes(SwDoc* pDoc) ...@@ -98,19 +98,47 @@ std::list<SwFrmFmt*> SwTextBoxHelper::findTextBoxes(SwDoc* pDoc)
return aRet; 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 SwTextBoxHelper::getCount(SdrPage* pPage, std::list<SwFrmFmt*>& rTextBoxes)
{ {
sal_Int32 nRet = 0; sal_Int32 nRet = 0;
for (size_t i = 0; i < pPage->GetObjCount(); ++i) for (size_t i = 0; i < pPage->GetObjCount(); ++i)
{ {
SwVirtFlyDrawObj* pObject = PTR_CAST(SwVirtFlyDrawObj, pPage->GetObj(i)); if (lcl_isTextBox(pPage->GetObj(i), rTextBoxes))
if (pObject && std::find(rTextBoxes.begin(), rTextBoxes.end(), pObject->GetFmt()) != rTextBoxes.end())
continue; continue;
++nRet; ++nRet;
} }
return 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* SwTextBoxHelper::findTextBox(SwFrmFmt* pShape)
{ {
SwFrmFmt* pRet = 0; SwFrmFmt* pRet = 0;
......
...@@ -538,7 +538,11 @@ uno::Any SwXDrawPage::getByIndex(sal_Int32 nIndex) ...@@ -538,7 +538,11 @@ uno::Any SwXDrawPage::getByIndex(sal_Int32 nIndex)
throw lang::IndexOutOfBoundsException(); throw lang::IndexOutOfBoundsException();
((SwXDrawPage*)this)->GetSvxPage(); ((SwXDrawPage*)this)->GetSvxPage();
std::list<SwFrmFmt*> aTextBoxes = SwTextBoxHelper::findTextBoxes(pDoc);
if (aTextBoxes.empty())
return pDrawPage->getByIndex( nIndex ); return pDrawPage->getByIndex( nIndex );
else
return SwTextBoxHelper::getByIndex(pDrawPage->GetSdrPage(), nIndex, aTextBoxes);
} }
uno::Type SwXDrawPage::getElementType(void) throw( uno::RuntimeException, std::exception ) uno::Type SwXDrawPage::getElementType(void) throw( uno::RuntimeException, std::exception )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment