summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-05-19 17:19:14 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-05-19 17:35:02 +0200
commitb97fb340b23e1b6a48c5c95c8d42e9f10ece1748 (patch)
tree00e89dc118cf804a0364d59b49e7cc22ca0f466e /sw
parent0549f250aac361075287d8acae9b7ee73c66256d (diff)
Add sw::DocumentDrawModelManager::Search()
Change-Id: Idcbbb9e049f0fbc5d6503b86fd506df9fb2ad3c5
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/IDocumentDrawModelAccess.hxx5
-rw-r--r--sw/source/core/doc/DocumentDrawModelManager.cxx59
-rw-r--r--sw/source/core/inc/DocumentDrawModelManager.hxx2
3 files changed, 66 insertions, 0 deletions
diff --git a/sw/inc/IDocumentDrawModelAccess.hxx b/sw/inc/IDocumentDrawModelAccess.hxx
index 7cf0b8607965..a8b5ba2a25d1 100644
--- a/sw/inc/IDocumentDrawModelAccess.hxx
+++ b/sw/inc/IDocumentDrawModelAccess.hxx
@@ -23,7 +23,9 @@
#include <svx/svdtypes.hxx>
class SwDrawModel;
+class SwPaM;
class SdrPageView;
+class SvxSearchItem;
class IDocumentDrawModelAccess
{
@@ -89,6 +91,9 @@ public:
*/
virtual SdrLayerID GetInvisibleLayerIdByVisibleOne( const SdrLayerID& _nVisibleLayerId ) = 0;
+ /// Searches text in shapes anchored inside rPaM.
+ virtual bool Search(const SwPaM& rPaM, const SvxSearchItem& rSearchItem) = 0;
+
protected:
virtual ~IDocumentDrawModelAccess() {};
diff --git a/sw/source/core/doc/DocumentDrawModelManager.cxx b/sw/source/core/doc/DocumentDrawModelManager.cxx
index 5cb1e0dfc637..bed970f0d55e 100644
--- a/sw/source/core/doc/DocumentDrawModelManager.cxx
+++ b/sw/source/core/doc/DocumentDrawModelManager.cxx
@@ -26,11 +26,15 @@
#include <IDocumentLinksAdministration.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <docsh.hxx>
+#include <wrtsh.hxx>
#include <swtypes.hxx>
+#include <ndtxt.hxx>
#include <swhints.hxx>
#include <viewsh.hxx>
+#include <view.hxx>
#include <drawdoc.hxx>
#include <rootfrm.hxx>
+#include <fmtanchr.hxx>
#include <editeng/eeitem.hxx>
#include <editeng/fhgtitem.hxx>
#include <svx/svdmodel.hxx>
@@ -38,7 +42,9 @@
#include <svx/svdoutl.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdpagv.hxx>
+#include <svx/svdotext.hxx>
#include <svl/smplhint.hxx>
+#include <svl/srchitem.hxx>
#include <tools/link.hxx>
class SdrOutliner;
@@ -364,6 +370,59 @@ SdrLayerID DocumentDrawModelManager::GetInvisibleLayerIdByVisibleOne( const SdrL
return nInvisibleLayerId;
}
+bool DocumentDrawModelManager::Search(const SwPaM& rPaM, const SvxSearchItem& rSearchItem)
+{
+ SwPosFlyFrms aFrames = m_rDoc.GetAllFlyFmts(&rPaM, /*bDrawAlso=*/true);
+
+ for (const SwPosFlyFrmPtr& pPosFlyFrm : aFrames)
+ {
+ // Filter for at-paragraph anchored draw frames.
+ const SwFrmFmt& rFrmFmt = pPosFlyFrm->GetFmt();
+ const SwFmtAnchor& rAnchor = rFrmFmt.GetAnchor();
+ if (rAnchor.GetAnchorId() != FLY_AT_PARA || rFrmFmt.Which() != RES_DRAWFRMFMT)
+ continue;
+
+ // Does the shape have matching text?
+ SdrOutliner& rOutliner = GetDrawModel()->GetDrawOutliner();
+ SdrObject* pObject = const_cast<SdrObject*>(rFrmFmt.FindSdrObject());
+ SdrTextObj* pTextObj = dynamic_cast<SdrTextObj*>(pObject);
+ if (!pTextObj)
+ continue;
+ const OutlinerParaObject* pParaObj = pTextObj->GetOutlinerParaObject();
+ if (!pParaObj)
+ continue;
+ rOutliner.SetText(*pParaObj);
+ SwDocShell* pDocShell = m_rDoc.GetDocShell();
+ if (!pDocShell)
+ return false;
+ SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+ if (!pWrtShell)
+ return false;
+ if (!rOutliner.HasText(rSearchItem))
+ continue;
+
+ // If so, then select highlight the search result.
+ pWrtShell->SelectObj(Point(), 0, pObject);
+ SwView* pView = pDocShell->GetView();
+ if (!pView)
+ return false;
+ if (!pView->EnterShapeDrawTextMode(pObject))
+ continue;
+ SdrView* pSdrView = pWrtShell->GetDrawView();
+ if (!pSdrView)
+ return false;
+ OutlinerView* pOutlinerView = pSdrView->GetTextEditOutlinerView();
+ if (!rSearchItem.GetBackward())
+ pOutlinerView->SetSelection(ESelection(0, 0, 0, 0));
+ else
+ pOutlinerView->SetSelection(ESelection(EE_PARA_MAX_COUNT, EE_TEXTPOS_MAX_COUNT, EE_PARA_MAX_COUNT, EE_TEXTPOS_MAX_COUNT));
+ pOutlinerView->StartSearchAndReplace(rSearchItem);
+ return true;
+ }
+
+ return false;
+}
+
void DocumentDrawModelManager::DrawNotifyUndoHdl()
{
mpDrawModel->SetNotifyUndoActionHdl( Link<>() );
diff --git a/sw/source/core/inc/DocumentDrawModelManager.hxx b/sw/source/core/inc/DocumentDrawModelManager.hxx
index b87b06ff25ac..32656a8a718a 100644
--- a/sw/source/core/inc/DocumentDrawModelManager.hxx
+++ b/sw/source/core/inc/DocumentDrawModelManager.hxx
@@ -63,6 +63,8 @@ public:
virtual SdrLayerID GetInvisibleLayerIdByVisibleOne( const SdrLayerID& _nVisibleLayerId ) SAL_OVERRIDE;
+ virtual bool Search(const SwPaM& rPaM, const SvxSearchItem& rSearchItem) SAL_OVERRIDE;
+
virtual ~DocumentDrawModelManager() {}
private: