Kaydet (Commit) abebf10e authored tarafından Michael Stahl's avatar Michael Stahl

sw: move implementation of SwXTextView::select into unocore

Change-Id: Ica2758ea48945e024d9e8636bede31cca0cf0057
üst ddc9b4d1
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
* except in compliance with the License. You may obtain a copy of * except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#ifndef _UNOCRSRHELPER_HXX #ifndef SW_UNOCRSRHELPER_HXX
#define _UNOCRSRHELPER_HXX #define SW_UNOCRSRHELPER_HXX
#include <map> #include <map>
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySet.hpp>
#include <swtypes.hxx> #include <swtypes.hxx>
#include <flyenum.hxx>
#include <pam.hxx> #include <pam.hxx>
...@@ -32,14 +33,18 @@ class String; ...@@ -32,14 +33,18 @@ class String;
class SfxItemSet; class SfxItemSet;
class SfxItemPropertySet; class SfxItemPropertySet;
struct SfxItemPropertySimpleEntry; struct SfxItemPropertySimpleEntry;
class SdrObject;
class SwTxtNode; class SwTxtNode;
class SwPaM; class SwPaM;
class SwCursor; class SwCursor;
class SwUnoCrsr; class SwUnoCrsr;
class SwUnoTableCrsr;
class SwFmtColl; class SwFmtColl;
struct SwSortOptions; struct SwSortOptions;
class SwDoc; class SwDoc;
namespace sw { namespace mark { class IMark; } }
namespace com{ namespace sun{ namespace star{ namespace com{ namespace sun{ namespace star{
namespace uno{ namespace uno{
class Any; class Any;
...@@ -212,6 +217,18 @@ namespace SwUnoCursorHelper ...@@ -212,6 +217,18 @@ namespace SwUnoCursorHelper
SwPaM & rPam, SfxItemSet & rItemSet) SwPaM & rPam, SfxItemSet & rItemSet)
throw (::com::sun::star::lang::IllegalArgumentException); throw (::com::sun::star::lang::IllegalArgumentException);
/// try to get something that can be selected out of the XInterface
/// at most one of the out parameters gets assigned a non-null value
/// o_rpPaM is newly allocated and must be deleted; other parameters not
SW_DLLPUBLIC void GetSelectableFromAny(
::com::sun::star::uno::Reference<
::com::sun::star::uno::XInterface> const& xIfc,
SwDoc & rTargetDoc,
SwPaM *& o_rpPaM, std::pair<OUString, FlyCntType> & o_rFrame,
OUString & o_rTableName, SwUnoTableCrsr const*& o_rpTableCursor,
::sw::mark::IMark const*& o_rpMark,
std::vector<SdrObject *> & o_rSdrObjects);
} // namespace SwUnoCursorHelper } // namespace SwUnoCursorHelper
#endif #endif
......
...@@ -17,12 +17,23 @@ ...@@ -17,12 +17,23 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <svx/svxids.hrc> #include <unocrsrhelper.hxx>
#include <map> #include <map>
#include <com/sun/star/beans/PropertyState.hpp>
#include <com/sun/star/embed/ElementModes.hpp>
#include <com/sun/star/embed/XStorage.hpp>
#include <com/sun/star/text/XTextSection.hpp> #include <com/sun/star/text/XTextSection.hpp>
#include <svx/svxids.hrc>
#include <svx/unoshape.hxx>
#include <cmdid.h> #include <cmdid.h>
#include <unocrsrhelper.hxx> #include <unotextrange.hxx>
#include <unodraw.hxx>
#include <unofootnote.hxx> #include <unofootnote.hxx>
#include <unobookmark.hxx>
#include <unorefmark.hxx> #include <unorefmark.hxx>
#include <unostyle.hxx> #include <unostyle.hxx>
#include <unoidx.hxx> #include <unoidx.hxx>
...@@ -62,15 +73,12 @@ ...@@ -62,15 +73,12 @@
#include <sfx2/docfile.hxx> #include <sfx2/docfile.hxx>
#include <sfx2/fcontnr.hxx> #include <sfx2/fcontnr.hxx>
#include <svl/stritem.hxx> #include <svl/stritem.hxx>
#include <com/sun/star/beans/PropertyState.hpp>
#include <SwStyleNameMapper.hxx> #include <SwStyleNameMapper.hxx>
#include <redline.hxx> #include <redline.hxx>
#include <numrule.hxx> #include <numrule.hxx>
#include <comphelper/storagehelper.hxx> #include <comphelper/storagehelper.hxx>
#include <comphelper/mediadescriptor.hxx> #include <comphelper/mediadescriptor.hxx>
#include <comphelper/sequenceashashmap.hxx> #include <comphelper/sequenceashashmap.hxx>
#include <com/sun/star/embed/ElementModes.hpp>
#include <com/sun/star/embed/XStorage.hpp>
#include <SwNodeNum.hxx> #include <SwNodeNum.hxx>
#include <fmtmeta.hxx> #include <fmtmeta.hxx>
...@@ -87,6 +95,177 @@ using ::rtl::OUString; ...@@ -87,6 +95,177 @@ using ::rtl::OUString;
namespace SwUnoCursorHelper namespace SwUnoCursorHelper
{ {
static SwPaM* lcl_createPamCopy(const SwPaM& rPam)
{
SwPaM *const pRet = new SwPaM(*rPam.GetPoint());
::sw::DeepCopyPaM(rPam, *pRet);
return pRet;
}
void GetSelectableFromAny(uno::Reference<uno::XInterface> const& xIfc,
SwDoc & rTargetDoc,
SwPaM *& o_rpPaM, std::pair<OUString, FlyCntType> & o_rFrame,
OUString & o_rTableName, SwUnoTableCrsr const*& o_rpTableCursor,
::sw::mark::IMark const*& o_rpMark,
std::vector<SdrObject *> & o_rSdrObjects)
{
uno::Reference<drawing::XShapes> const xShapes(xIfc, UNO_QUERY);
if (xShapes.is())
{
sal_Int32 nShapes(xShapes->getCount());
for (sal_Int32 i = 0; i < nShapes; ++i)
{
uno::Reference<lang::XUnoTunnel> xShape;
xShapes->getByIndex(i) >>= xShape;
if (xShape.is())
{
SvxShape *const pSvxShape(
::sw::UnoTunnelGetImplementation<SvxShape>(xShape));
if (pSvxShape)
{
SdrObject *const pSdrObject = pSvxShape->GetSdrObject();
if (pSdrObject)
{ // hmm... needs view to verify it's in right doc...
o_rSdrObjects.push_back(pSdrObject);
}
}
}
}
return;
}
uno::Reference<lang::XUnoTunnel> const xTunnel(xIfc, UNO_QUERY);
if (!xTunnel.is()) // everything below needs tunnel
{
return;
}
SwXShape *const pShape(::sw::UnoTunnelGetImplementation<SwXShape>(xTunnel));
if (pShape)
{
uno::Reference<uno::XAggregation> const xAgg(
pShape->GetAggregationInterface());
if (xAgg.is())
{
SvxShape *const pSvxShape(
::sw::UnoTunnelGetImplementation<SvxShape>(xTunnel));
if (pSvxShape)
{
SdrObject *const pSdrObject = pSvxShape->GetSdrObject();
if (pSdrObject)
{ // hmm... needs view to verify it's in right doc...
o_rSdrObjects.push_back(pSdrObject);
}
}
}
return;
}
OTextCursorHelper *const pCursor(
::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xTunnel));
if (pCursor)
{
if (pCursor->GetDoc() == &rTargetDoc)
{
o_rpPaM = lcl_createPamCopy(*pCursor->GetPaM());
}
return;
}
SwXTextRanges *const pRanges(
::sw::UnoTunnelGetImplementation<SwXTextRanges>(xTunnel));
if (pRanges)
{
SwUnoCrsr const* pUnoCrsr = pRanges->GetCursor();
if (pUnoCrsr->GetDoc() == &rTargetDoc)
{
o_rpPaM = lcl_createPamCopy(*pUnoCrsr);
}
return;
}
// check these before Range to prevent misinterpretation of text frames
// and cells also implement XTextRange
SwXFrame *const pFrame(
::sw::UnoTunnelGetImplementation<SwXFrame>(xTunnel));
if (pFrame)
{
SwFrmFmt *const pFrmFmt(pFrame->GetFrmFmt());
if (pFrmFmt && pFrmFmt->GetDoc() == &rTargetDoc)
{
o_rFrame = std::make_pair(pFrmFmt->GetName(), pFrame->GetFlyCntType());
}
return;
}
SwXTextTable *const pTextTable(
::sw::UnoTunnelGetImplementation<SwXTextTable>(xTunnel));
if (pTextTable)
{
SwFrmFmt *const pFrmFmt(pTextTable->GetFrmFmt());
if (pFrmFmt && pFrmFmt->GetDoc() == &rTargetDoc)
{
o_rTableName = pFrmFmt->GetName();
}
return;
}
SwXCell *const pCell(
::sw::UnoTunnelGetImplementation<SwXCell>(xTunnel));
if (pCell)
{
SwFrmFmt *const pFrmFmt(pCell->GetFrmFmt());
if (pFrmFmt && pFrmFmt->GetDoc() == &rTargetDoc)
{
SwTableBox * pBox = pCell->GetTblBox();
SwTable *const pTable = SwTable::FindTable(pFrmFmt);
// ??? what's the benefit of setting pBox in this convoluted way?
pBox = pCell->FindBox(pTable, pBox);
if (pBox)
{
SwPosition const aPos(*pBox->GetSttNd());
SwPaM aPam(aPos);
aPam.Move(fnMoveForward, fnGoNode);
o_rpPaM = lcl_createPamCopy(aPam);
}
}
return;
}
uno::Reference<text::XTextRange> const xTextRange(xTunnel, UNO_QUERY);
if (xTextRange.is())
{
SwUnoInternalPaM aPam(rTargetDoc);
if (::sw::XTextRangeToSwPaM(aPam, xTextRange))
{
o_rpPaM = lcl_createPamCopy(aPam);
}
return;
}
SwXCellRange *const pCellRange(
::sw::UnoTunnelGetImplementation<SwXCellRange>(xTunnel));
if (pCellRange)
{
SwUnoCrsr const*const pUnoCrsr(pCellRange->GetTblCrsr());
if (pUnoCrsr && pUnoCrsr->GetDoc() == &rTargetDoc)
{
// probably can't copy it to o_rpPaM for this since it's
// a SwTableCursor
o_rpTableCursor = dynamic_cast<SwUnoTableCrsr const*>(pUnoCrsr);
}
return;
}
::sw::mark::IMark const*const pMark(
SwXBookmark::GetBookmarkInDoc(& rTargetDoc, xTunnel));
if (pMark)
{
o_rpMark = pMark;
return;
}
}
uno::Reference<text::XTextContent> uno::Reference<text::XTextContent>
GetNestedTextContent(SwTxtNode & rTextNode, xub_StrLen const nIndex, GetNestedTextContent(SwTxtNode & rTextNode, xub_StrLen const nIndex,
bool const bParent) bool const bParent)
......
...@@ -65,7 +65,6 @@ ...@@ -65,7 +65,6 @@
#include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp>
#include <editeng/outliner.hxx> #include <editeng/outliner.hxx>
#include <editeng/editview.hxx> #include <editeng/editview.hxx>
#include <unobookmark.hxx>
#include <unoparagraph.hxx> #include <unoparagraph.hxx>
#include <unocrsrhelper.hxx> #include <unocrsrhelper.hxx>
#include <unotextrange.hxx> #include <unotextrange.hxx>
...@@ -88,12 +87,6 @@ using comphelper::HelperBaseNoState; ...@@ -88,12 +87,6 @@ using comphelper::HelperBaseNoState;
using ::rtl::OUString; using ::rtl::OUString;
static SwPaM* lcl_createPamCopy(const SwPaM& rPam)
{
SwPaM *const pRet = new SwPaM(*rPam.GetPoint());
::sw::DeepCopyPaM(rPam, *pRet);
return pRet;
}
/****************************************************************** /******************************************************************
* SwXTextView * SwXTextView
...@@ -239,244 +232,98 @@ uno::Any SAL_CALL SwXTextView::queryInterface( const uno::Type& aType ) ...@@ -239,244 +232,98 @@ uno::Any SAL_CALL SwXTextView::queryInterface( const uno::Type& aType )
sal_Bool SwXTextView::select(const uno::Any& aInterface) throw( lang::IllegalArgumentException, uno::RuntimeException ) sal_Bool SwXTextView::select(const uno::Any& aInterface) throw( lang::IllegalArgumentException, uno::RuntimeException )
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
uno::Reference< uno::XInterface > xInterface; uno::Reference< uno::XInterface > xInterface;
if(GetView() && (aInterface >>= xInterface)) if (!GetView() || !(aInterface >>= xInterface))
{ {
SwWrtShell& rSh = GetView()->GetWrtShell(); return sal_False;
SwDoc* pDoc = GetView()->GetDocShell()->GetDoc(); }
uno::Reference< lang::XUnoTunnel > xIfcTunnel(xInterface, uno::UNO_QUERY);
uno::Reference< text::XTextCursor > xCrsr(xInterface, uno::UNO_QUERY);
uno::Reference< container::XIndexAccess > xPosN(xInterface, uno::UNO_QUERY);
uno::Reference< text::XTextRange > xPos(xInterface, uno::UNO_QUERY);
SwXFrame* pFrame = xIfcTunnel.is() ? reinterpret_cast<SwXFrame*>(
xIfcTunnel->getSomething(SwXFrame::getUnoTunnelId())) : 0;
SwXCell* pCell = xIfcTunnel.is() ? reinterpret_cast<SwXCell*>(
xIfcTunnel->getSomething(SwXCell::getUnoTunnelId())) : 0;
SwPaM * pPam = 0;
SwXTextRanges* pPosN = 0;
if(xCrsr.is())
{
//
OTextCursorHelper* pCursor =
xIfcTunnel.is() ?
reinterpret_cast<OTextCursorHelper*>(xIfcTunnel->getSomething(OTextCursorHelper::getUnoTunnelId()))
: 0;
if(pCursor && pCursor->GetDoc() == GetView()->GetDocShell()->GetDoc()) SwWrtShell& rSh = GetView()->GetWrtShell();
{ SwDoc* pDoc = GetView()->GetDocShell()->GetDoc();
pPam = lcl_createPamCopy(*pCursor->GetPaM()); std::vector<SdrObject *> sdrObjects;
} uno::Reference<awt::XControlModel> const xCtrlModel(xInterface,
} UNO_QUERY);
else if(xPosN.is() && if (xCtrlModel.is())
xIfcTunnel.is() && {
0 != (pPosN = reinterpret_cast<SwXTextRanges*>(xIfcTunnel->getSomething(SwXTextRanges::getUnoTunnelId())))) uno::Reference<awt::XControl> xControl;
{ SdrObject *const pSdrObject = GetControl(xCtrlModel, xControl);
const SwUnoCrsr* pUnoCrsr = pPosN->GetCursor(); if (pSdrObject) // hmm... needs view to verify it's in right doc...
if(pUnoCrsr)
{
pPam = lcl_createPamCopy(*pUnoCrsr);
}
}
// prevent misinterpretation of text frames that provide a XTextRange interface, too
else if(!pFrame && !pCell && xPos.is())
{ {
SwUnoInternalPaM aPam(*pDoc); sdrObjects.push_back(pSdrObject);
if (::sw::XTextRangeToSwPaM(aPam, xPos))
{
pPam = lcl_createPamCopy(aPam);
}
} }
if(pPam) }
else
{
SwPaM * pPaM(0);
std::pair<OUString, FlyCntType> frame;
OUString tableName;
SwUnoTableCrsr const* pTableCursor(0);
::sw::mark::IMark const* pMark(0);
SwUnoCursorHelper::GetSelectableFromAny(xInterface, *pDoc,
pPaM, frame, tableName, pTableCursor, pMark, sdrObjects);
if (pPaM)
{ {
rSh.EnterStdMode(); rSh.EnterStdMode();
rSh.SetSelection(*pPam); rSh.SetSelection(*pPaM);
while( pPam->GetNext() != pPam ) // the pPaM has been copied - delete it
delete pPam->GetNext(); while (pPaM->GetNext() != pPaM)
delete pPam; delete pPaM->GetNext();
delete pPaM;
return sal_True; return sal_True;
} }
if(pFrame) else if (!frame.first.isEmpty())
{ {
bool const bSuccess(rSh.GotoFly(frame.first, frame.second));
SwFrmFmt* pFrmFmt = pFrame->GetFrmFmt(); if (bSuccess)
if(pFrmFmt && pFrmFmt->GetDoc() == pDoc)
{
sal_Bool bSuccess = rSh.GotoFly( pFrmFmt->GetName(), pFrame->GetFlyCntType());
if (bSuccess)
{
rSh.HideCrsr();
rSh.EnterSelFrmMode();
}
return sal_True;
}
}
uno::Reference< text::XTextTable > xTbl(xInterface, uno::UNO_QUERY);
if(xTbl.is() && xIfcTunnel.is())
{
SwXTextTable* pTable = reinterpret_cast<SwXTextTable*>(
xIfcTunnel->getSomething(SwXTextTable::getUnoTunnelId()));
SwFrmFmt* pTblFrmFmt = pTable ? ((SwXTextTable*)pTable)->GetFrmFmt() : 0;
if(pTblFrmFmt &&pTblFrmFmt->GetDoc() == pDoc)
{ {
rSh.EnterStdMode(); rSh.HideCrsr();
rSh.GotoTable(pTblFrmFmt->GetName()); rSh.EnterSelFrmMode();
} }
return sal_True; return sal_True;
} }
else if (!tableName.isEmpty())
if(pCell)
{
SwFrmFmt* pTblFrmFmt = pCell->GetFrmFmt();
if(pTblFrmFmt && pTblFrmFmt->GetDoc() == pDoc)
{
SwTableBox* pBox = pCell->GetTblBox();
SwTable* pTable = SwTable::FindTable( pTblFrmFmt );
pBox = pCell->FindBox(pTable, pBox);
if(pBox)
{
const SwStartNode* pSttNd = pBox->GetSttNd();
SwPosition aPos(*pSttNd);
SwPaM aPam(aPos);
aPam.Move(fnMoveForward, fnGoNode);
rSh.EnterStdMode();
rSh.SetSelection(aPam);
return sal_True;
}
}
}
SwXCellRange* pRange = xIfcTunnel.is() ? reinterpret_cast<SwXCellRange*>(
xIfcTunnel->getSomething(SwXCellRange::getUnoTunnelId())) : 0;
if(pRange)
{ {
const SwUnoCrsr* pUnoCrsr = pRange->GetTblCrsr(); rSh.EnterStdMode();
if(pUnoCrsr) rSh.GotoTable(tableName);
{ return sal_True;
UnoActionRemoveContext aContext(pDoc);
rSh.EnterStdMode();
rSh.SetSelection(*pUnoCrsr);
return sal_True;
}
} }
uno::Reference< text::XTextContent > xBkm(xInterface, uno::UNO_QUERY); else if (pTableCursor)
if(xBkm.is() && xIfcTunnel.is())
{ {
::sw::mark::IMark const*const pMark( UnoActionRemoveContext const aContext(pDoc);
SwXBookmark::GetBookmarkInDoc(pDoc, xIfcTunnel) ); rSh.EnterStdMode();
if (pMark) rSh.SetSelection(*pTableCursor);
{ return sal_True;
rSh.EnterStdMode();
rSh.GotoMark(pMark);
return sal_True;
}
} }
// IndexMark, Index, TextField, Draw, Section, Footnote, Paragraph else if (pMark)
//
// detect controls
uno::Reference< awt::XControlModel > xCtrlModel(xInterface, UNO_QUERY);
if(xCtrlModel.is())
{ {
uno::Reference<awt::XControl> XControl; rSh.EnterStdMode();
SdrObject* pObj = GetControl(xCtrlModel, XControl); rSh.GotoMark(pMark);
if(pObj) return sal_True;
{
SdrView* pDrawView = rSh.GetDrawView();
SdrPageView* pPV = pDrawView->GetSdrPageView();
if ( pPV && pObj->GetPage() == pPV->GetPage() )
{
pDrawView->SdrEndTextEdit();
pDrawView->UnmarkAll();
pDrawView->MarkObj( pObj, pPV );
}
return sal_True;
}
} }
// sdrObjects handled below
}
sal_Bool bRet(sal_False);
if (sdrObjects.size())
{
uno::Reference< drawing::XShapes > xShapeColl( xInterface, uno::UNO_QUERY ); SdrView *const pDrawView = rSh.GetDrawView();
uno::Reference< beans::XPropertySet > xTmpProp(xInterface, uno::UNO_QUERY); SdrPageView *const pPV = pDrawView->GetSdrPageView();
SwXShape* pSwXShape = 0;
if(xIfcTunnel.is())
pSwXShape = reinterpret_cast<SwXShape*>(xIfcTunnel->getSomething(SwXShape::getUnoTunnelId()));
SvxShape* pSvxShape = 0;
if(pSwXShape)
{
uno::Reference< uno::XAggregation > xAgg = pSwXShape->GetAggregationInterface();
if(xAgg.is())
{
pSvxShape = reinterpret_cast<SvxShape*>(xIfcTunnel->getSomething(SvxShape::getUnoTunnelId()));
}
}
if ( pSvxShape || xShapeColl.is() ) // Drawing drawing::Layer for (size_t i = 0; i < sdrObjects.size(); ++i)
{ {
SdrView* pDrawView = rSh.GetDrawView(); SdrObject *const pSdrObject(sdrObjects[i]);
if (pDrawView) // GetSelectableFromAny did not check pSdrObject is in right doc!
if (pPV && pSdrObject->GetPage() == pPV->GetPage())
{ {
pDrawView->SdrEndTextEdit(); pDrawView->SdrEndTextEdit();
pDrawView->UnmarkAll(); pDrawView->UnmarkAll();
pDrawView->MarkObj(pSdrObject, pPV);
if (pSvxShape) // einzelnes Shape bRet = sal_True;
{
SdrObject *pObj = pSvxShape->GetSdrObject();
if (pObj)
{
SdrPageView* pPV = pDrawView->GetSdrPageView();
if ( pPV && pObj->GetPage() == pPV->GetPage() )
{
pDrawView->MarkObj( pObj, pPV );
return sal_True;
}
}
}
else // Shape Collection
{
sal_Bool bSelected = sal_False;
SdrPageView* pPV = NULL;
long nCount = xShapeColl->getCount();
for ( long i = 0; i < nCount; i++ )
{
uno::Reference< drawing::XShape > xShapeInt;
uno::Any aAny = xShapeColl->getByIndex(i);
aAny >>= xShapeInt;
if (xShapeInt.is())
{
uno::Reference< lang::XUnoTunnel> xShapeTunnel(xShapeInt, uno::UNO_QUERY);
SvxShape* pShape = xShapeTunnel.is() ?
reinterpret_cast<SvxShape*>(xShapeTunnel->getSomething(SvxShape::getUnoTunnelId())) : 0;
if (pShape)
{
SdrObject *pObj = pShape->GetSdrObject();
if (pObj)
{
if (!pPV) // erstes Objekt
{
pPV = pDrawView->GetSdrPageView();
}
if ( pPV && pObj->GetPage() == pPV->GetPage() )
{
pDrawView->MarkObj( pObj, pPV );
bSelected = sal_True;
}
}
}
}
}
return bSelected;
}
} }
} }
} }
return sal_False; return bRet;
} }
uno::Any SwXTextView::getSelection(void) throw( uno::RuntimeException ) uno::Any SwXTextView::getSelection(void) throw( uno::RuntimeException )
......
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