Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / func / fusearch.cxx
blob741d3ba439bce747aeea8e081e06dd22d626fd9f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <fusearch.hxx>
22 #include <sfx2/viewfrm.hxx>
24 #include <svx/svxids.hrc>
25 #include <svl/srchitem.hxx>
26 #include <svx/srchdlg.hxx>
27 #include <sfx2/bindings.hxx>
28 #include <fupoor.hxx>
29 #include <Window.hxx>
30 #include <drawdoc.hxx>
31 #include <app.hrc>
32 #include <sdmod.hxx>
33 #include <View.hxx>
34 #include <Outliner.hxx>
35 #include <DrawViewShell.hxx>
36 #include <OutlineViewShell.hxx>
37 #include <ViewShellBase.hxx>
39 class SfxRequest;
41 namespace sd {
43 static const sal_uInt16 SidArraySpell[] = {
44 SID_DRAWINGMODE,
45 SID_OUTLINE_MODE,
46 SID_SLIDE_SORTER_MODE,
47 SID_NOTES_MODE,
48 SID_HANDOUT_MASTER_MODE,
49 SID_SLIDE_MASTER_MODE,
50 SID_NOTES_MASTER_MODE,
51 0 };
53 FuSearch::FuSearch (
54 ViewShell* pViewSh,
55 ::sd::Window* pWin,
56 ::sd::View* pView,
57 SdDrawDocument* pDoc,
58 SfxRequest& rReq )
59 : FuPoor(pViewSh, pWin, pView, pDoc, rReq),
60 pSdOutliner(nullptr),
61 bOwnOutliner(false)
65 rtl::Reference<FuPoor> FuSearch::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
67 rtl::Reference<FuPoor> xFunc( new FuSearch( pViewSh, pWin, pView, pDoc, rReq ) );
68 xFunc->DoExecute(rReq);
69 return xFunc;
72 void FuSearch::DoExecute( SfxRequest& )
74 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArraySpell );
76 if ( dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr )
78 bOwnOutliner = true;
79 pSdOutliner = new SdOutliner( mpDoc, OutlinerMode::TextObject );
81 else if ( dynamic_cast< const OutlineViewShell *>( mpViewShell ) != nullptr )
83 bOwnOutliner = false;
84 pSdOutliner = mpDoc->GetOutliner();
87 if (pSdOutliner)
88 pSdOutliner->PrepareSpelling();
91 FuSearch::~FuSearch()
93 if ( ! mpDocSh->IsInDestruction() && mpDocSh->GetViewShell()!=nullptr)
94 mpDocSh->GetViewShell()->GetViewFrame()->GetBindings().Invalidate( SidArraySpell );
96 if (pSdOutliner)
97 pSdOutliner->EndSpelling();
99 if (bOwnOutliner)
100 delete pSdOutliner;
103 void FuSearch::SearchAndReplace( const SvxSearchItem* pSearchItem )
105 ViewShellBase* pBase = dynamic_cast<ViewShellBase*>( SfxViewShell::Current() );
106 ViewShell* pViewShell = nullptr;
107 if (pBase != nullptr)
108 pViewShell = pBase->GetMainViewShell().get();
110 if (pViewShell != nullptr)
112 if ( pSdOutliner && dynamic_cast< const DrawViewShell *>( pViewShell ) != nullptr && !bOwnOutliner )
114 pSdOutliner->EndSpelling();
116 bOwnOutliner = true;
117 pSdOutliner = new SdOutliner( mpDoc, OutlinerMode::TextObject );
118 pSdOutliner->PrepareSpelling();
120 else if ( pSdOutliner && dynamic_cast< const OutlineViewShell *>( pViewShell ) != nullptr && bOwnOutliner )
122 pSdOutliner->EndSpelling();
123 delete pSdOutliner;
125 bOwnOutliner = false;
126 pSdOutliner = mpDoc->GetOutliner();
127 pSdOutliner->PrepareSpelling();
130 if (pSdOutliner)
132 bool bEndSpelling = pSdOutliner->StartSearchAndReplace(pSearchItem);
134 if (bEndSpelling)
136 pSdOutliner->EndSpelling();
137 pSdOutliner->PrepareSpelling();
143 } // end of namespace sd
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */