xref: /aoo42x/main/sd/source/ui/func/fusearch.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sd.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include "fusearch.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <svx/svxids.hrc>
37*cdf0e10cSrcweir #include <svl/srchitem.hxx>
38*cdf0e10cSrcweir #include <svx/srchdlg.hxx>
39*cdf0e10cSrcweir #include <sfx2/bindings.hxx>
40*cdf0e10cSrcweir #include "fupoor.hxx"
41*cdf0e10cSrcweir #ifndef SD_WINDOW_SHELL_HXX
42*cdf0e10cSrcweir #include "Window.hxx"
43*cdf0e10cSrcweir #endif
44*cdf0e10cSrcweir #include "drawdoc.hxx"
45*cdf0e10cSrcweir #include "app.hrc"
46*cdf0e10cSrcweir #include "app.hxx"
47*cdf0e10cSrcweir #include "View.hxx"
48*cdf0e10cSrcweir #include "Outliner.hxx"
49*cdf0e10cSrcweir #include "DrawViewShell.hxx"
50*cdf0e10cSrcweir #include "OutlineViewShell.hxx"
51*cdf0e10cSrcweir #include "ViewShellBase.hxx"
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir class SfxRequest;
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir namespace sd {
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir static sal_uInt16 SidArraySpell[] = {
58*cdf0e10cSrcweir 			SID_DRAWINGMODE,
59*cdf0e10cSrcweir 			SID_OUTLINEMODE,
60*cdf0e10cSrcweir 			SID_DIAMODE,
61*cdf0e10cSrcweir 			SID_NOTESMODE,
62*cdf0e10cSrcweir 			SID_HANDOUTMODE,
63*cdf0e10cSrcweir 			0 };
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir TYPEINIT1( FuSearch, FuPoor );
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir /*************************************************************************
68*cdf0e10cSrcweir |*
69*cdf0e10cSrcweir |* Konstruktor
70*cdf0e10cSrcweir |*
71*cdf0e10cSrcweir \************************************************************************/
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir FuSearch::FuSearch (
74*cdf0e10cSrcweir     ViewShell* pViewSh,
75*cdf0e10cSrcweir     ::sd::Window* pWin,
76*cdf0e10cSrcweir     ::sd::View* pView,
77*cdf0e10cSrcweir     SdDrawDocument* pDoc,
78*cdf0e10cSrcweir     SfxRequest& rReq )
79*cdf0e10cSrcweir     : FuPoor(pViewSh, pWin, pView, pDoc, rReq),
80*cdf0e10cSrcweir       pSdOutliner(NULL),
81*cdf0e10cSrcweir       bOwnOutliner(sal_False)
82*cdf0e10cSrcweir {
83*cdf0e10cSrcweir }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir FunctionReference FuSearch::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir 	FunctionReference xFunc( new FuSearch( pViewSh, pWin, pView, pDoc, rReq ) );
88*cdf0e10cSrcweir 	xFunc->DoExecute(rReq);
89*cdf0e10cSrcweir 	return xFunc;
90*cdf0e10cSrcweir }
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir void FuSearch::DoExecute( SfxRequest& )
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir 	mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArraySpell );
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir 	if ( mpViewShell->ISA(DrawViewShell) )
97*cdf0e10cSrcweir 	{
98*cdf0e10cSrcweir 		bOwnOutliner = sal_True;
99*cdf0e10cSrcweir 		pSdOutliner = new ::sd::Outliner( mpDoc, OUTLINERMODE_TEXTOBJECT );
100*cdf0e10cSrcweir 	}
101*cdf0e10cSrcweir 	else if ( mpViewShell->ISA(OutlineViewShell) )
102*cdf0e10cSrcweir 	{
103*cdf0e10cSrcweir 		bOwnOutliner = sal_False;
104*cdf0e10cSrcweir 		pSdOutliner = mpDoc->GetOutliner();
105*cdf0e10cSrcweir 	}
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 	if (pSdOutliner)
108*cdf0e10cSrcweir 	   pSdOutliner->PrepareSpelling();
109*cdf0e10cSrcweir }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir /*************************************************************************
112*cdf0e10cSrcweir |*
113*cdf0e10cSrcweir |* Destruktor
114*cdf0e10cSrcweir |*
115*cdf0e10cSrcweir \************************************************************************/
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir FuSearch::~FuSearch()
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir     if ( ! mpDocSh->IsInDestruction() && mpDocSh->GetViewShell()!=NULL)
120*cdf0e10cSrcweir         mpDocSh->GetViewShell()->GetViewFrame()->GetBindings().Invalidate( SidArraySpell );
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 	if (pSdOutliner)
123*cdf0e10cSrcweir 		pSdOutliner->EndSpelling();
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir 	if (bOwnOutliner)
126*cdf0e10cSrcweir 		delete pSdOutliner;
127*cdf0e10cSrcweir }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir /*************************************************************************
131*cdf0e10cSrcweir |*
132*cdf0e10cSrcweir |* Suchen&Ersetzen
133*cdf0e10cSrcweir |*
134*cdf0e10cSrcweir \************************************************************************/
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir void FuSearch::SearchAndReplace( const SvxSearchItem* pSearchItem )
137*cdf0e10cSrcweir {
138*cdf0e10cSrcweir 	ViewShellBase* pBase = PTR_CAST(ViewShellBase, SfxViewShell::Current());
139*cdf0e10cSrcweir     ViewShell* pViewShell = NULL;
140*cdf0e10cSrcweir     if (pBase != NULL)
141*cdf0e10cSrcweir         pViewShell = pBase->GetMainViewShell().get();
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 	if (pViewShell != NULL)
144*cdf0e10cSrcweir 	{
145*cdf0e10cSrcweir 		if ( pSdOutliner && pViewShell->ISA(DrawViewShell) && !bOwnOutliner )
146*cdf0e10cSrcweir 		{
147*cdf0e10cSrcweir 			pSdOutliner->EndSpelling();
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 			bOwnOutliner = sal_True;
150*cdf0e10cSrcweir 			pSdOutliner = new ::sd::Outliner( mpDoc, OUTLINERMODE_TEXTOBJECT );
151*cdf0e10cSrcweir 			pSdOutliner->PrepareSpelling();
152*cdf0e10cSrcweir 		}
153*cdf0e10cSrcweir 		else if ( pSdOutliner && pViewShell->ISA(OutlineViewShell) && bOwnOutliner )
154*cdf0e10cSrcweir 		{
155*cdf0e10cSrcweir 			pSdOutliner->EndSpelling();
156*cdf0e10cSrcweir 			delete pSdOutliner;
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 			bOwnOutliner = sal_False;
159*cdf0e10cSrcweir 			pSdOutliner = mpDoc->GetOutliner();
160*cdf0e10cSrcweir 			pSdOutliner->PrepareSpelling();
161*cdf0e10cSrcweir 		}
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 		if (pSdOutliner)
164*cdf0e10cSrcweir 		{
165*cdf0e10cSrcweir 			sal_Bool bEndSpelling = pSdOutliner->StartSearchAndReplace(pSearchItem);
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 			if (bEndSpelling)
168*cdf0e10cSrcweir 			{
169*cdf0e10cSrcweir 				pSdOutliner->EndSpelling();
170*cdf0e10cSrcweir 				pSdOutliner->PrepareSpelling();
171*cdf0e10cSrcweir 			}
172*cdf0e10cSrcweir 		}
173*cdf0e10cSrcweir 	}
174*cdf0e10cSrcweir }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir } // end of namespace sd
179