23 #include <boost/property_tree/json_parser.hpp>
48 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
52 #include <strings.hrc>
73 static void lcl_addContainerToJson(boost::property_tree::ptree& rTree,
const OString& rKey,
const std::vector<OString>& rMatches)
75 boost::property_tree::ptree aChildren;
77 for (
const OString& rMatch : rMatches)
79 boost::property_tree::ptree aChild;
80 aChild.put(
"part",
"0");
81 aChild.put(
"rectangles", rMatch.getStr());
82 aChildren.push_back(std::make_pair(
"", aChild));
85 rTree.add_child(rKey.getStr(), aChildren);
96 std::vector<OString> aMatches;
99 if (
SwShellCursor* pShellCursor = dynamic_cast<SwShellCursor*>(&rPaM))
101 std::vector<OString> aSelectionRectangles;
102 pShellCursor->SwSelPaintRects::Show(&aSelectionRectangles);
103 std::vector<OString> aRect;
104 for (
const OString & rSelectionRectangle : aSelectionRectangles)
106 if (rSelectionRectangle.isEmpty())
108 aRect.push_back(rSelectionRectangle);
111 aMatches.push_back(sRect);
114 boost::property_tree::ptree aTree;
115 aTree.put(
"searchString", pSearchItem->
GetSearchString().toUtf8().getStr());
116 aTree.put(
"highlightAll", bHighlightAll);
119 std::stringstream aStream;
120 boost::property_tree::write_json(aStream, aTree);
121 OString aPayload = aStream.str().c_str();
134 GetWrtShell().addCurrentPosition();
139 if(pArgs && SfxItemState::SET == pArgs->
GetItemState(SID_SEARCH_QUIET,
false, &pItem))
140 bQuiet = static_cast<const SfxBoolItem*>( pItem)->GetValue();
142 sal_uInt16 nSlot = rReq.
GetSlot();
151 if( m_pWrtShell->IsBlockMode() )
152 m_pWrtShell->LeaveBlockMode();
156 case SID_SEARCH_ITEM:
159 s_pSrchItem = pArgs->
Get(SID_SEARCH_ITEM).
Clone();
164 s_bJustOpened =
true;
165 GetViewFrame()->GetBindings().Invalidate(SID_SEARCH_ITEM);
173 s_pSrchItem = pArgs->
Get(SID_SEARCH_ITEM).
Clone();
175 s_xSearchList.reset();
176 s_xReplaceList.reset();
183 if(
nullptr != pList && pList->
Count() )
187 if (
nullptr != pList && pList->
Count())
198 if(FID_SEARCH_NOW == nSlot && !rReq.
IsAPI())
205 s_xSearchList.reset();
206 s_xReplaceList.reset();
209 if(
nullptr != pList && pList->
Count() )
213 if (
nullptr != pList && pList->
Count())
219 OSL_ENSURE(s_pSrchItem,
"SearchItem missing");
226 OSL_ENSURE(pArgs,
"Args missing");
230 s_pSrchItem = pArgs->
Get(SID_SEARCH_ITEM).
Clone();
236 case SvxSearchCmd::FIND:
238 bool bRet = SearchAndWrap(bQuiet);
241 Scroll(m_pWrtShell->GetCharRect().SVRect());
247 GetDocShell()->Broadcast(
SfxHint(SfxHintId::SwNavigatorUpdateTracking));
250 case SvxSearchCmd::FIND_ALL:
253 m_pWrtShell->GetSfxViewShell()->setTiledSearching(
true);
254 bool bRet = SearchAll();
255 m_pWrtShell->GetSfxViewShell()->setTiledSearching(
false);
257 GetDocShell()->Broadcast(
258 SfxHint(SfxHintId::SwNavigatorUpdateTracking));
259 GetDocShell()->Broadcast(
260 SfxHint(SfxHintId::SwNavigatorSelectOutlinesWithSelections));
264 #if HAVE_FEATURE_DESKTOP
267 m_pWrtShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_NOT_FOUND, s_pSrchItem->GetSearchString().toUtf8().getStr());
278 case SvxSearchCmd::REPLACE:
286 if( !s_pSrchItem->GetReplaceString().isEmpty() ||
291 bool bBack = s_pSrchItem->GetBackward();
294 OUString aReplace( s_pSrchItem->GetReplaceString() );
297 m_pWrtShell->GetCursor(), m_pWrtShell->GetLayout());
299 s_pSrchItem->SetReplaceString( *xBackRef );
303 s_pSrchItem->SetReplaceString( aReplace );
308 m_pWrtShell->SwapPam();
311 else if( s_xReplaceList )
312 nCmd = SvxSearchCmd::REPLACE;
317 s_pSrchItem->SetCommand( nCmd );
318 bool bRet = SearchAndWrap(bQuiet);
320 Scroll( m_pWrtShell->GetCharRect().SVRect());
321 s_pSrchItem->SetCommand( nOldCmd );
326 case SvxSearchCmd::REPLACE_ALL:
328 SwSearchOptions aOpts( m_pWrtShell.get(), s_pSrchItem->GetBackward() );
333 SwWait aWait( *GetDocShell(),
true );
334 m_pWrtShell->StartAllAction();
340 if (!s_pSrchItem->GetSelection())
343 m_pWrtShell->KillSelection(
nullptr,
false);
346 m_pWrtShell->EndOfSection();
350 m_pWrtShell->StartOfSection();
353 nFound = FUNC_Search( aOpts );
355 m_pWrtShell->CreateCursor();
358 m_pWrtShell->EndAllAction();
364 #if HAVE_FEATURE_DESKTOP
367 m_pWrtShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_NOT_FOUND, s_pSrchItem->GetSearchString().toUtf8().getStr());
376 if( !bQuiet && ULONG_MAX != nFound)
378 OUString sText(
SwResId( STR_NB_REPLACED ) );
379 sText = sText.replaceFirst(
"XX", OUString::number( nFound ));
386 uno::Reference< frame::XDispatchRecorder > xRecorder =
387 GetViewFrame()->GetBindings().GetRecorder();
389 if ( xRecorder.is() )
393 m_eLastSearchCommand = s_pSrchItem->GetCommand();
397 case FID_SEARCH_SEARCHSET:
398 case FID_SEARCH_REPLACESET:
413 SID_ATTR_PARA_MODEL, SID_ATTR_PARA_KEEP
416 SfxItemSet aSet(m_pWrtShell->GetAttrPool(), aNormalAttr);
418 if(
SW_MOD()->GetCTLOptions().IsCTLFontEnabled() )
431 if ( FID_SEARCH_REPLACESET == nSlot )
433 nWhich = SID_SEARCH_REPLACESET;
435 if ( s_xReplaceList )
437 s_xReplaceList->Get( aSet );
438 s_xReplaceList.reset();
441 else if ( s_xSearchList )
443 s_xSearchList->Get( aSet );
444 s_xSearchList.reset();
450 SAL_WARN_IF( nSlot,
"sw",
"nSlot: " << nSlot <<
" wrong Dispatcher (viewsrch.cxx)" );
457 SwSearchOptions aOpts( m_pWrtShell.get(), s_pSrchItem->GetBackward() );
461 m_pWrtShell->StartAllAction();
467 if( m_eLastSearchCommand == SvxSearchCmd::FIND_ALL )
470 m_pWrtShell->EndOfSection();
472 m_pWrtShell->StartOfSection();
479 m_pWrtShell->GetCursor()->Normalize( s_pSrchItem->GetBackward() );
481 if (!m_pWrtShell->HasSelection() && (s_pSrchItem->HasStartPoint()))
487 Point aPosition(s_pSrchItem->GetStartPointX(), s_pSrchItem->GetStartPointY());
492 if (!s_pSrchItem->GetSelection())
493 m_pWrtShell->KillSelection(
nullptr,
false);
495 std::unique_ptr<SwWait> pWait(
new SwWait( *GetDocShell(),
true ));
496 if( FUNC_Search( aOpts ) )
499 if(m_pWrtShell->IsSelFrameMode())
501 m_pWrtShell->UnSelectFrame();
502 m_pWrtShell->LeaveSelFrameMode();
505 m_pWrtShell->EndAllAction();
512 bool bHasSrchInOther = s_bExtra;
513 if (!s_pSrchItem->GetSelection() && !s_bExtra )
516 if( FUNC_Search( aOpts ) )
520 m_pWrtShell->EndAllAction();
526 s_bExtra = !s_bExtra;
531 m_pWrtShell->EndAllAction();
534 #if HAVE_FEATURE_DESKTOP
535 m_pWrtShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_NOT_FOUND, s_pSrchItem->GetSearchString().toUtf8().getStr());
543 m_pWrtShell->EndAllAction();
546 m_pWrtShell->StartAllAction();
548 pWait.reset(
new SwWait( *GetDocShell(),
true ));
557 m_pWrtShell->ClearMark();
560 m_pWrtShell->SttEndDoc(
false);
562 m_pWrtShell->SttEndDoc(
true);
565 s_bFound = bool(FUNC_Search( aOpts ));
569 if (!s_bFound && !s_pSrchItem->GetSelection() && !s_bExtra)
572 if (FUNC_Search(aOpts))
578 m_pWrtShell->EndAllAction();
580 #if HAVE_FEATURE_DESKTOP
590 m_pWrtShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_NOT_FOUND, s_pSrchItem->GetSearchString().toUtf8().getStr());
599 SwWait aWait( *GetDocShell(),
true );
600 m_pWrtShell->StartAllAction();
602 SwSearchOptions aOpts( m_pWrtShell.get(), s_pSrchItem->GetBackward() );
604 if (!s_pSrchItem->GetSelection())
607 m_pWrtShell->KillSelection(
nullptr,
false);
610 m_pWrtShell->EndOfSection();
612 m_pWrtShell->StartOfSection();
615 sal_uInt16 nFound = o3tl::narrowing<sal_uInt16>(FUNC_Search( aOpts ));
616 s_bFound = 0 != nFound;
618 m_pWrtShell->EndAllAction();
624 SwWait aWait( *GetDocShell(),
true );
626 m_pWrtShell->StartAllAction();
628 if( s_pSrchItem->GetPattern() )
637 m_pWrtShell->SetTextFormatColl( m_pWrtShell->GetParaStyle(
638 s_pSrchItem->GetReplaceString(),
641 m_pWrtShell->EndUndo();
645 if (GetPostItMgr()->HasActiveSidebarWin())
646 GetPostItMgr()->Replace(s_pSrchItem);
648 bool bReqReplace =
true;
650 if(m_pWrtShell->HasSelection())
654 SwPosition aStartPos = * m_pWrtShell->GetCursor()->Start();
655 SwPosition aEndPos = * m_pWrtShell->GetCursor()->End();
656 bool bHasSelection = s_pSrchItem->GetSelection();
660 s_pSrchItem->SetCommand( SvxSearchCmd::FIND );
661 s_pSrchItem->SetSelection(
true);
664 SwSearchOptions aOpts( m_pWrtShell.get(), s_pSrchItem->GetBackward() );
665 if( ! FUNC_Search(aOpts) )
671 if(! s_pSrchItem->GetBackward() )
673 (* m_pWrtShell->GetCursor()->Start()) = aStartPos;
674 (* m_pWrtShell->GetCursor()->End()) = aEndPos;
678 (* m_pWrtShell->GetCursor()->Start()) = aEndPos;
679 (* m_pWrtShell->GetCursor()->End()) = aStartPos;
685 s_pSrchItem->SetCommand( nOldCmd );
686 s_pSrchItem->SetSelection(bHasSelection);
698 bool bReplaced = m_pWrtShell->SwEditShell::Replace( s_pSrchItem->GetReplaceString(),
699 s_pSrchItem->GetRegExp());
700 if( bReplaced && s_xReplaceList && s_xReplaceList->Count() && m_pWrtShell->HasSelection() )
702 SfxItemSet aReplSet( m_pWrtShell->GetAttrPool(),
704 if( s_xReplaceList->Get( aReplSet ).Count() )
707 m_pWrtShell->SwEditShell::SetAttrSet( aReplSet );
713 m_pWrtShell->EndAllAction();
733 #if HAVE_FEATURE_DESKTOP
753 SID_ATTR_PARA_MODEL, SID_ATTR_PARA_KEEP
765 std::optional<SfxItemSet> xReplSet;
768 xReplSet.emplace(
m_pWrtShell->GetAttrPool(), aSearchAttrRange );
774 if( !xReplSet->Count() )
783 aSearchOpt.replaceString.clear();
786 if( aSrchSet.Count() || ( xReplSet && xReplSet->Count() ))
795 xReplSet ? &*xReplSet : nullptr );
805 bDoReplace ? &sRplStr : nullptr );
822 #if HAVE_FEATURE_DESKTOP
823 const sal_uInt16
nId = SvxSearchDialogWrapper::GetChildWindowId();
825 auto pSrchDlg = pWrp ? pWrp->
getDialog() :
nullptr;
841 case SID_SEARCH_OPTIONS:
846 SearchOptionFlags::REPLACE_ALL );
847 rSet.
Put(
SfxUInt16Item( SID_SEARCH_OPTIONS, static_cast<sal_uInt16>(nOpt) ));
850 case SID_SEARCH_ITEM:
863 !( aText =
m_pWrtShell->SwCursorShell::GetSelText() ).isEmpty() )
std::optional< OUString > ReplaceBackReferences(const i18nutil::SearchOptions2 &rSearchOpt, SwPaM *const pPam, SwRootFrame const *const pLayout)
Helperfunction to resolve backward references in regular expressions.
constexpr TypedWhichId< SvxBlinkItem > RES_CHRATR_BLINK(18)
static void lcl_addContainerToJson(boost::property_tree::ptree &rTree, const OString &rKey, const std::vector< OString > &rMatches)
Adds rMatches using rKey as a key to the rTree tree.
Marks a position in the document model.
WhichRangesContainer const aTextFormatCollSetRange(svl::Items< RES_CHRATR_BEGIN, RES_CHRATR_END-1, RES_PARATR_BEGIN, RES_PARATR_END-1, RES_PARATR_LIST_LEVEL, RES_PARATR_LIST_LEVEL, RES_FRMATR_BEGIN, RES_FRMATR_END-1, RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1, XATTR_FILL_FIRST, XATTR_FILL_LAST >)
SfxChildWindow * GetChildWindow(sal_uInt16)
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_CTL_FONT(27)
static sal_uInt16 GetMoveType()
static void lcl_emitSearchResultCallbacks(SvxSearchItem const *pSearchItem, SwWrtShell const *pWrtShell, bool bHighlightAll)
Emits LOK callbacks (count, selection) for search results.
static constexpr auto Items
std::unique_ptr< SwWrtShell > m_pWrtShell
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
void SetSearchString(const OUString &rNewString)
bool IsStartOfDoc() const
Find "all" in Footer/Header/Fly...
constexpr TypedWhichId< SwRegisterItem > RES_PARATR_REGISTER(71)
SAL_DLLPRIVATE void Replace()
static SvxSearchDialog * GetSearchDialog()
constexpr sal_uInt16 RES_FRMATR_END(133)
static std::unique_ptr< SearchAttrItemList > s_xSearchList
void Done(bool bRemove=false)
static std::unique_ptr< SearchAttrItemList > s_xReplaceList
SfxViewShell * GetSfxViewShell() const
void StateSearch(SfxItemSet &)
const SfxItemSet * GetArgs() const
constexpr TypedWhichId< SvxTwoLinesItem > RES_CHRATR_TWO_LINES(34)
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
const i18nutil::SearchOptions2 & GetSearchOptions() const
Used by the UI to modify the document model.
OUString SwResId(TranslateId aId)
constexpr TypedWhichId< SvxCaseMapItem > RES_CHRATR_CASEMAP(RES_CHRATR_BEGIN)
void MergeRange(sal_uInt16 nFrom, sal_uInt16 nTo)
constexpr sal_uInt16 RES_PARATR_BEGIN(RES_TXTATR_END)
OString join(std::string_view rSeparator, const std::vector< OString > &rSequence)
constexpr OUStringLiteral IsReadOnly(u"IsReadOnly")
virtual void libreOfficeKitViewCallback(int nType, const char *pPayload) const override
int SetCursor(const Point &rPt, bool bOnlyText=false, bool bBlock=true)
constexpr TypedWhichId< SvxCharReliefItem > RES_CHRATR_RELIEF(36)
static bool s_bJustOpened
constexpr TypedWhichId< SvxHyphenZoneItem > RES_PARATR_HYPHENZONE(69)
constexpr TypedWhichId< SvxParaVertAlignItem > RES_PARATR_VERTALIGN(76)
PaM is Point and Mark: a selection of the document model.
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
SvxSearchCmd GetCommand() const
constexpr TypedWhichId< SvxShadowedItem > RES_CHRATR_SHADOWED(13)
const OUString & GetReplaceString() const
All (only in non-body and selections).
bool GetSelection() const
static void notifyOtherViewsUpdatePerViewId(SfxViewShell const *pViewShell, int nType)
void AddRule(SwUndoArg eWhat, const OUString &rWith)
constexpr TypedWhichId< SvxLineSpacingItem > RES_PARATR_LINESPACING(RES_PARATR_BEGIN)
ring_container GetRingContainer()
static void SetMoveType(sal_uInt16 nSet)
constexpr TypedWhichId< SvxOverlineItem > RES_CHRATR_OVERLINE(38)
constexpr TypedWhichId< SvxEmphasisMarkItem > RES_CHRATR_EMPHASIS_MARK(33)
static void SetSearchLabel(const SearchLabel &rSL)
void SetFamily(SfxStyleFamily eNewFamily)
SwDocShell * GetDocShell()
constexpr TypedWhichId< SvxCharScaleWidthItem > RES_CHRATR_SCALEW(35)
SAL_DLLPRIVATE bool SearchAndWrap(bool bApi)
void SetReturnValue(const SfxPoolItem &)
const LanguageTag & GetAppLanguageTag()
constexpr TypedWhichId< SvxColorItem > RES_CHRATR_COLOR(3)
constexpr TypedWhichId< SvxScriptSpaceItem > RES_PARATR_SCRIPTSPACE(73)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
constexpr TypedWhichId< SvxBrushItem > RES_CHRATR_BACKGROUND(21)
sal_uInt16 GetSlot() const
SAL_DLLPRIVATE sal_uLong FUNC_Search(const SwSearchOptions &rOptions)
static SfxViewFrame * Current()
SwCursor * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
constexpr sal_uInt16 RES_CHRATR_BEGIN(HINT_BEGIN)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_CJK_WEIGHT(26)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
#define SAL_WARN_IF(condition, area, stream)
constexpr TypedWhichId< SvxWordLineModeItem > RES_CHRATR_WORDLINEMODE(16)
constexpr TypedWhichId< SvxWeightItem > RES_CHRATR_CTL_WEIGHT(31)
constexpr TypedWhichId< SvxForbiddenRuleItem > RES_PARATR_FORBIDDEN_RULES(75)
void ExecSearch(SfxRequest &)
SvxSearchDialog * getDialog()
const OUString & GetSearchString() const
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_CJK_FONT(22)
constexpr sal_uInt16 RES_PARATR_END(82)
void SetSelection(bool bNewSelection)
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(91)
constexpr sal_uInt16 RES_CHRATR_END(46)
Find "one" only in body text.
static void notifyUpdate(SfxViewShell const *pViewShell, int nType)
void AppendItem(const SfxPoolItem &)
const SearchAttrItemList * GetReplaceItemList() const
constexpr TypedWhichId< SvxCharRotateItem > RES_CHRATR_ROTATE(32)
SAL_DLLPRIVATE bool SearchAll()
static SvxSearchItem * s_pSrchItem
constexpr sal_uInt16 RES_FRMATR_BEGIN(RES_PARATR_LIST_END)
constexpr TypedWhichId< SvxULSpaceItem > RES_UL_SPACE(92)
SwSearchOptions(SwWrtShell const *pSh, bool bBackward)
constexpr TypedWhichId< SvxPostureItem > RES_CHRATR_POSTURE(11)
const SearchAttrItemList * GetSearchItemList() const