Kaydet (Commit) 7596e26f authored tarafından Miklos Vajna's avatar Miklos Vajna

Add SwTextBoxHelper::findShapes

It builds a textbox -> shape map, so methods interested to pick the
shape instead of a shape's textbox can call it and act accordingly if
their textbox is in the map.

Change-Id: I0f30d64a284eb461f462ed6c0a36c88271153f04
üst 212dce21
...@@ -69,6 +69,8 @@ public: ...@@ -69,6 +69,8 @@ public:
/// Look up TextFrames in a document, which are in fact TextBoxes. /// Look up TextFrames in a document, which are in fact TextBoxes.
static std::list<SwFrmFmt*> findTextBoxes(const SwDoc* pDoc); static std::list<SwFrmFmt*> findTextBoxes(const SwDoc* pDoc);
/// Build a textbox -> shape format map.
static std::map<SwFrmFmt*, SwFrmFmt*> findShapes(const 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. /// Get a shape by index, excluding TextBoxes.
......
...@@ -17,8 +17,10 @@ ...@@ -17,8 +17,10 @@
#include <redline.hxx> #include <redline.hxx>
#include <section.hxx> #include <section.hxx>
#include <fmtclds.hxx> #include <fmtclds.hxx>
#include <dcontact.hxx>
#include <svx/svdpage.hxx> #include <svx/svdpage.hxx>
#include <svx/svdview.hxx>
#include "UndoManager.hxx" #include "UndoManager.hxx"
...@@ -39,6 +41,7 @@ public: ...@@ -39,6 +41,7 @@ public:
void testFdo75110(); void testFdo75110();
void testFdo75898(); void testFdo75898();
void testFdo74981(); void testFdo74981();
void testShapeTextboxSelect();
void testShapeTextboxDelete(); void testShapeTextboxDelete();
void testCp1000071(); void testCp1000071();
...@@ -52,6 +55,7 @@ public: ...@@ -52,6 +55,7 @@ public:
CPPUNIT_TEST(testFdo75110); CPPUNIT_TEST(testFdo75110);
CPPUNIT_TEST(testFdo75898); CPPUNIT_TEST(testFdo75898);
CPPUNIT_TEST(testFdo74981); CPPUNIT_TEST(testFdo74981);
CPPUNIT_TEST(testShapeTextboxSelect);
CPPUNIT_TEST(testShapeTextboxDelete); CPPUNIT_TEST(testShapeTextboxDelete);
CPPUNIT_TEST(testCp1000071); CPPUNIT_TEST(testCp1000071);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
...@@ -282,9 +286,27 @@ void SwUiWriterTest::testFdo74981() ...@@ -282,9 +286,27 @@ void SwUiWriterTest::testFdo74981()
CPPUNIT_ASSERT(!pTxtNode->HasHints()); CPPUNIT_ASSERT(!pTxtNode->HasHints());
} }
void SwUiWriterTest::testShapeTextboxSelect()
{
SwDoc* pDoc = createDoc("shape-textbox.odt");
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
SdrObject* pObject = pPage->GetObj(1);
SwDrawContact* pTextBox = static_cast<SwDrawContact*>(pObject->GetUserCall());
// First, make sure that pTextBox is a fly frame (textbox of a shape).
CPPUNIT_ASSERT_EQUAL(RES_FLYFRMFMT, static_cast<RES_FMT>(pTextBox->GetFmt()->Which()));
// Then select it.
pWrtShell->SelectObj(Point(), 0, pObject);
const SdrMarkList& rMarkList = pWrtShell->GetDrawView()->GetMarkedObjectList();
SwDrawContact* pShape = static_cast<SwDrawContact*>(rMarkList.GetMark(0)->GetMarkedSdrObj()->GetUserCall());
// And finally make sure the shape got selected, not just the textbox itself.
CPPUNIT_ASSERT_EQUAL(RES_DRAWFRMFMT, static_cast<RES_FMT>(pShape->GetFmt()->Which()));
}
void SwUiWriterTest::testShapeTextboxDelete() void SwUiWriterTest::testShapeTextboxDelete()
{ {
SwDoc* pDoc = createDoc("shape-textbox-delete.odt"); SwDoc* pDoc = createDoc("shape-textbox.odt");
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0); SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
SdrObject* pObject = pPage->GetObj(0); SdrObject* pObject = pPage->GetObj(0);
......
...@@ -126,6 +126,21 @@ std::list<SwFrmFmt*> SwTextBoxHelper::findTextBoxes(const SwDoc* pDoc) ...@@ -126,6 +126,21 @@ std::list<SwFrmFmt*> SwTextBoxHelper::findTextBoxes(const SwDoc* pDoc)
return aRet; return aRet;
} }
std::map<SwFrmFmt*, SwFrmFmt*> SwTextBoxHelper::findShapes(const SwDoc* pDoc)
{
std::map<SwFrmFmt*, SwFrmFmt*> aRet;
const SwFrmFmts& rSpzFrmFmts = *pDoc->GetSpzFrmFmts();
for (SwFrmFmts::const_iterator it = rSpzFrmFmts.begin(); it != rSpzFrmFmts.end(); ++it)
{
SwFrmFmt* pTextBox = findTextBox(*it);
if (pTextBox)
aRet[pTextBox] = *it;
}
return aRet;
}
/// If the passed SdrObject is in fact a TextFrame, that is used as a TextBox. /// If the passed SdrObject is in fact a TextFrame, that is used as a TextBox.
bool lcl_isTextBox(SdrObject* pSdrObject, std::list<SwFrmFmt*>& rTextBoxes) bool lcl_isTextBox(SdrObject* pSdrObject, std::list<SwFrmFmt*>& rTextBoxes)
{ {
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <DocumentSettingManager.hxx> #include <DocumentSettingManager.hxx>
#include <cmdid.h> #include <cmdid.h>
#include <drawdoc.hxx> #include <drawdoc.hxx>
#include <textboxhelper.hxx>
#include <poolfmt.hrc> #include <poolfmt.hrc>
#include <frmfmt.hxx> #include <frmfmt.hxx>
#include <frmatr.hxx> #include <frmatr.hxx>
...@@ -220,6 +221,22 @@ bool SwFEShell::SelectObj( const Point& rPt, sal_uInt8 nFlag, SdrObject *pObj ) ...@@ -220,6 +221,22 @@ bool SwFEShell::SelectObj( const Point& rPt, sal_uInt8 nFlag, SdrObject *pObj )
} }
} }
// If the fly frame is a textbox of a shape, then select the shape instead.
std::map<SwFrmFmt*, SwFrmFmt*> aTextBoxShapes = SwTextBoxHelper::findShapes(mpDoc);
for (sal_uInt16 i = 0; i < rMrkList.GetMarkCount(); ++i)
{
SdrObject* pObject = rMrkList.GetMark(i)->GetMarkedSdrObj();
SwDrawContact* pDrawContact = static_cast<SwDrawContact*>(GetUserCall(pObject));
SwFrmFmt* pFmt = pDrawContact->GetFmt();
if (aTextBoxShapes.find(pFmt) != aTextBoxShapes.end())
{
SdrObject* pShape = aTextBoxShapes[pFmt]->FindSdrObject();
pDView->UnmarkAll();
pDView->MarkObj(pShape, Imp()->GetPageView(), bAddSelect, bEnterGroup);
break;
}
}
if ( bRet ) if ( bRet )
{ {
::lcl_GrabCursor(this, pOldSelFly); ::lcl_GrabCursor(this, pOldSelFly);
......
...@@ -76,6 +76,8 @@ ...@@ -76,6 +76,8 @@
#include <wrtsh.hxx> #include <wrtsh.hxx>
#include <IDocumentSettingAccess.hxx> #include <IDocumentSettingAccess.hxx>
#include <IDocumentDrawModelAccess.hxx> #include <IDocumentDrawModelAccess.hxx>
#include <textboxhelper.hxx>
#include <dcontact.hxx>
#include <fldbas.hxx> #include <fldbas.hxx>
#include <swmodule.hxx> #include <swmodule.hxx>
#include <docsh.hxx> #include <docsh.hxx>
...@@ -4241,8 +4243,21 @@ void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt) ...@@ -4241,8 +4243,21 @@ void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt)
SdrPageView* pPV; SdrPageView* pPV;
if (pSdrView->PickObj(aDocPos, pSdrView->getHitTolLog(), pObj, pPV, SDRSEARCH_ALSOONMASTER )) if (pSdrView->PickObj(aDocPos, pSdrView->getHitTolLog(), pObj, pPV, SDRSEARCH_ALSOONMASTER ))
{ {
pSdrView->UnmarkAllObj(); std::map<SwFrmFmt*, SwFrmFmt*> aTextBoxShapes = SwTextBoxHelper::findShapes(rSh.GetDoc());
pSdrView->MarkObj(pObj,pPV,false,false); SwDrawContact* pDrawContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
SwFrmFmt* pFmt = pDrawContact->GetFmt();
if (aTextBoxShapes.find(pFmt) == aTextBoxShapes.end())
{
pSdrView->UnmarkAllObj();
pSdrView->MarkObj(pObj,pPV,false,false);
}
else
{
// If the fly frame is a textbox of a shape, then select the shape instead.
SdrObject* pShape = aTextBoxShapes[pFmt]->FindSdrObject();
pSdrView->UnmarkAllObj();
pSdrView->MarkObj(pShape, pPV, false, false);
}
} }
} }
ReleaseMouse(); ReleaseMouse();
......
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