xref: /aoo41x/main/sd/source/ui/func/fusearch.cxx (revision 5b190011)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 
28 #include "fusearch.hxx"
29 
30 #include <sfx2/viewfrm.hxx>
31 
32 #include <svx/svxids.hrc>
33 #include <svl/srchitem.hxx>
34 #include <svx/srchdlg.hxx>
35 #include <sfx2/bindings.hxx>
36 #include "fupoor.hxx"
37 #ifndef SD_WINDOW_SHELL_HXX
38 #include "Window.hxx"
39 #endif
40 #include "drawdoc.hxx"
41 #include "app.hrc"
42 #include "app.hxx"
43 #include "View.hxx"
44 #include "Outliner.hxx"
45 #include "DrawViewShell.hxx"
46 #include "OutlineViewShell.hxx"
47 #include "ViewShellBase.hxx"
48 
49 class SfxRequest;
50 
51 namespace sd {
52 
53 static sal_uInt16 SidArraySpell[] = {
54 			SID_DRAWINGMODE,
55 			SID_OUTLINEMODE,
56 			SID_DIAMODE,
57 			SID_NOTESMODE,
58 			SID_HANDOUTMODE,
59 			0 };
60 
61 TYPEINIT1( FuSearch, FuPoor );
62 
63 /*************************************************************************
64 |*
65 |* Konstruktor
66 |*
67 \************************************************************************/
68 
69 FuSearch::FuSearch (
70     ViewShell* pViewSh,
71     ::sd::Window* pWin,
72     ::sd::View* pView,
73     SdDrawDocument* pDoc,
74     SfxRequest& rReq )
75     : FuPoor(pViewSh, pWin, pView, pDoc, rReq),
76       pSdOutliner(NULL),
77       bOwnOutliner(sal_False)
78 {
79 }
80 
81 FunctionReference FuSearch::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
82 {
83 	FunctionReference xFunc( new FuSearch( pViewSh, pWin, pView, pDoc, rReq ) );
84 	xFunc->DoExecute(rReq);
85 	return xFunc;
86 }
87 
88 void FuSearch::DoExecute( SfxRequest& )
89 {
90 	mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArraySpell );
91 
92 	if ( mpViewShell->ISA(DrawViewShell) )
93 	{
94 		bOwnOutliner = sal_True;
95 		pSdOutliner = new ::sd::Outliner( mpDoc, OUTLINERMODE_TEXTOBJECT );
96 	}
97 	else if ( mpViewShell->ISA(OutlineViewShell) )
98 	{
99 		bOwnOutliner = sal_False;
100 		pSdOutliner = mpDoc->GetOutliner();
101 	}
102 
103 	if (pSdOutliner)
104 	   pSdOutliner->PrepareSpelling();
105 }
106 
107 /*************************************************************************
108 |*
109 |* Destruktor
110 |*
111 \************************************************************************/
112 
113 FuSearch::~FuSearch()
114 {
115     if ( ! mpDocSh->IsInDestruction() && mpDocSh->GetViewShell()!=NULL)
116         mpDocSh->GetViewShell()->GetViewFrame()->GetBindings().Invalidate( SidArraySpell );
117 
118 	if (pSdOutliner)
119 		pSdOutliner->EndSpelling();
120 
121 	if (bOwnOutliner)
122 		delete pSdOutliner;
123 }
124 
125 
126 /*************************************************************************
127 |*
128 |* Suchen&Ersetzen
129 |*
130 \************************************************************************/
131 
132 void FuSearch::SearchAndReplace( const SvxSearchItem* pSearchItem )
133 {
134 	ViewShellBase* pBase = PTR_CAST(ViewShellBase, SfxViewShell::Current());
135     ViewShell* pViewShell = NULL;
136     if (pBase != NULL)
137         pViewShell = pBase->GetMainViewShell().get();
138 
139 	if (pViewShell != NULL)
140 	{
141 		if ( pSdOutliner && pViewShell->ISA(DrawViewShell) && !bOwnOutliner )
142 		{
143 			pSdOutliner->EndSpelling();
144 
145 			bOwnOutliner = sal_True;
146 			pSdOutliner = new ::sd::Outliner( mpDoc, OUTLINERMODE_TEXTOBJECT );
147 			pSdOutliner->PrepareSpelling();
148 		}
149 		else if ( pSdOutliner && pViewShell->ISA(OutlineViewShell) && bOwnOutliner )
150 		{
151 			pSdOutliner->EndSpelling();
152 			delete pSdOutliner;
153 
154 			bOwnOutliner = sal_False;
155 			pSdOutliner = mpDoc->GetOutliner();
156 			pSdOutliner->PrepareSpelling();
157 		}
158 
159 		if (pSdOutliner)
160 		{
161 			sal_Bool bEndSpelling = pSdOutliner->StartSearchAndReplace(pSearchItem);
162 
163 			if (bEndSpelling)
164 			{
165 				pSdOutliner->EndSpelling();
166 				pSdOutliner->PrepareSpelling();
167 			}
168 		}
169 	}
170 }
171 
172 
173 
174 } // end of namespace sd
175