Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "fusearch.hxx"
21 :
22 : #include <sfx2/viewfrm.hxx>
23 :
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"
38 :
39 : class SfxRequest;
40 :
41 : namespace sd {
42 :
43 : static sal_uInt16 SidArraySpell[] = {
44 : SID_DRAWINGMODE,
45 : SID_OUTLINEMODE,
46 : SID_DIAMODE,
47 : SID_NOTESMODE,
48 : SID_HANDOUTMODE,
49 : 0 };
50 :
51 0 : TYPEINIT1( FuSearch, FuPoor );
52 :
53 1 : 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(NULL),
61 1 : bOwnOutliner(false)
62 : {
63 1 : }
64 :
65 1 : rtl::Reference<FuPoor> FuSearch::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
66 : {
67 1 : rtl::Reference<FuPoor> xFunc( new FuSearch( pViewSh, pWin, pView, pDoc, rReq ) );
68 1 : xFunc->DoExecute(rReq);
69 1 : return xFunc;
70 : }
71 :
72 1 : void FuSearch::DoExecute( SfxRequest& )
73 : {
74 1 : mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArraySpell );
75 :
76 1 : if ( mpViewShell->ISA(DrawViewShell) )
77 : {
78 1 : bOwnOutliner = true;
79 1 : pSdOutliner = new ::sd::Outliner( mpDoc, OUTLINERMODE_TEXTOBJECT );
80 : }
81 0 : else if ( mpViewShell->ISA(OutlineViewShell) )
82 : {
83 0 : bOwnOutliner = false;
84 0 : pSdOutliner = mpDoc->GetOutliner();
85 : }
86 :
87 1 : if (pSdOutliner)
88 1 : pSdOutliner->PrepareSpelling();
89 1 : }
90 :
91 3 : FuSearch::~FuSearch()
92 : {
93 1 : if ( ! mpDocSh->IsInDestruction() && mpDocSh->GetViewShell()!=NULL)
94 1 : mpDocSh->GetViewShell()->GetViewFrame()->GetBindings().Invalidate( SidArraySpell );
95 :
96 1 : if (pSdOutliner)
97 1 : pSdOutliner->EndSpelling();
98 :
99 1 : if (bOwnOutliner)
100 1 : delete pSdOutliner;
101 2 : }
102 :
103 3 : void FuSearch::SearchAndReplace( const SvxSearchItem* pSearchItem )
104 : {
105 3 : ViewShellBase* pBase = PTR_CAST(ViewShellBase, SfxViewShell::Current());
106 3 : ViewShell* pViewShell = NULL;
107 3 : if (pBase != NULL)
108 3 : pViewShell = pBase->GetMainViewShell().get();
109 :
110 3 : if (pViewShell != NULL)
111 : {
112 3 : if ( pSdOutliner && pViewShell->ISA(DrawViewShell) && !bOwnOutliner )
113 : {
114 0 : pSdOutliner->EndSpelling();
115 :
116 0 : bOwnOutliner = true;
117 0 : pSdOutliner = new ::sd::Outliner( mpDoc, OUTLINERMODE_TEXTOBJECT );
118 0 : pSdOutliner->PrepareSpelling();
119 : }
120 3 : else if ( pSdOutliner && pViewShell->ISA(OutlineViewShell) && bOwnOutliner )
121 : {
122 0 : pSdOutliner->EndSpelling();
123 0 : delete pSdOutliner;
124 :
125 0 : bOwnOutliner = false;
126 0 : pSdOutliner = mpDoc->GetOutliner();
127 0 : pSdOutliner->PrepareSpelling();
128 : }
129 :
130 3 : if (pSdOutliner)
131 : {
132 3 : bool bEndSpelling = pSdOutliner->StartSearchAndReplace(pSearchItem);
133 :
134 3 : if (bEndSpelling)
135 : {
136 1 : pSdOutliner->EndSpelling();
137 1 : pSdOutliner->PrepareSpelling();
138 : }
139 : }
140 : }
141 3 : }
142 :
143 66 : } // end of namespace sd
144 :
145 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|