1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5b190011SAndrew Rist  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19*5b190011SAndrew Rist  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "SpellDialogChildWindow.hxx"
28cdf0e10cSrcweir #include <svx/svxids.hrc>
29cdf0e10cSrcweir #include <sfx2/app.hxx>
30cdf0e10cSrcweir #include <sfx2/bindings.hxx>
31cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir namespace sd{
34cdf0e10cSrcweir 
35cdf0e10cSrcweir SFX_IMPL_CHILDWINDOW(SpellDialogChildWindow, SID_SPELL_DIALOG)
36cdf0e10cSrcweir }
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include "ViewShell.hxx"
39cdf0e10cSrcweir #include "ViewShellBase.hxx"
40cdf0e10cSrcweir #include "DrawViewShell.hxx"
41cdf0e10cSrcweir #include "OutlineViewShell.hxx"
42cdf0e10cSrcweir #include <Outliner.hxx>
43cdf0e10cSrcweir #include "drawdoc.hxx"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 
46cdf0e10cSrcweir namespace sd {
47cdf0e10cSrcweir 
48cdf0e10cSrcweir SpellDialogChildWindow::SpellDialogChildWindow (
49cdf0e10cSrcweir     ::Window* _pParent,
50cdf0e10cSrcweir     sal_uInt16 nId,
51cdf0e10cSrcweir     SfxBindings* pBindings,
52cdf0e10cSrcweir     SfxChildWinInfo* pInfo)
53cdf0e10cSrcweir     : ::svx::SpellDialogChildWindow (_pParent, nId, pBindings, pInfo),
54cdf0e10cSrcweir       mpSdOutliner (NULL),
55cdf0e10cSrcweir       mbOwnOutliner (false)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     ProvideOutliner();
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 
63cdf0e10cSrcweir SpellDialogChildWindow::~SpellDialogChildWindow (void)
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 	if (mpSdOutliner != NULL)
66cdf0e10cSrcweir 		mpSdOutliner->EndSpelling();
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	if (mbOwnOutliner)
69cdf0e10cSrcweir 		delete mpSdOutliner;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 
79cdf0e10cSrcweir SfxChildWinInfo SpellDialogChildWindow::GetInfo (void) const
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	return ::svx::SpellDialogChildWindow::GetInfo();
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 
87cdf0e10cSrcweir void SpellDialogChildWindow::InvalidateSpellDialog (void)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir     ::svx::SpellDialogChildWindow::InvalidateSpellDialog();
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 
95cdf0e10cSrcweir ::svx::SpellPortions SpellDialogChildWindow::GetNextWrongSentence( bool /*bRecheck*/ )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir     ::svx::SpellPortions aResult;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     if (mpSdOutliner != NULL)
100cdf0e10cSrcweir 	{
101cdf0e10cSrcweir 		ProvideOutliner();
102cdf0e10cSrcweir 	    aResult = mpSdOutliner->GetNextSpellSentence();
103cdf0e10cSrcweir 	}
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     // Close the spell check dialog when there are no more sentences to
106cdf0e10cSrcweir     // check.
107cdf0e10cSrcweir     if (aResult.empty())
108cdf0e10cSrcweir     {
109cdf0e10cSrcweir         SfxBoolItem aItem (SID_SPELL_DIALOG, sal_False);
110cdf0e10cSrcweir         GetBindings().GetDispatcher()->Execute(
111cdf0e10cSrcweir             SID_SPELL_DIALOG,
112cdf0e10cSrcweir             SFX_CALLMODE_ASYNCHRON,
113cdf0e10cSrcweir             &aItem,
114cdf0e10cSrcweir             0L);
115cdf0e10cSrcweir     }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     return aResult;
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 
123cdf0e10cSrcweir void SpellDialogChildWindow::ApplyChangedSentence (
124cdf0e10cSrcweir     const ::svx::SpellPortions& rChanged, bool bRecheck )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir     if (mpSdOutliner != NULL)
127cdf0e10cSrcweir     {
128cdf0e10cSrcweir         OutlinerView* pOutlinerView = mpSdOutliner->GetView(0);
129cdf0e10cSrcweir         if (pOutlinerView != NULL)
130cdf0e10cSrcweir             mpSdOutliner->ApplyChangedSentence (
131cdf0e10cSrcweir                 pOutlinerView->GetEditView(),
132cdf0e10cSrcweir                 rChanged, bRecheck);
133cdf0e10cSrcweir     }
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 
139cdf0e10cSrcweir void SpellDialogChildWindow::GetFocus (void)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     // In order to detect a cursor movement we could compare the
142cdf0e10cSrcweir     // currently selected text shape with the one that was selected
143cdf0e10cSrcweir     // when LoseFocus() was called the last time.
144cdf0e10cSrcweir     // For the time being we instead rely on the DetectChange() method
145cdf0e10cSrcweir     // in the SdOutliner class.
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 
151cdf0e10cSrcweir void SpellDialogChildWindow::LoseFocus()
152cdf0e10cSrcweir {
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 
158cdf0e10cSrcweir void SpellDialogChildWindow::ProvideOutliner (void)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir     ViewShellBase* pViewShellBase = PTR_CAST (ViewShellBase, SfxViewShell::Current());
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	if (pViewShellBase != NULL)
163cdf0e10cSrcweir 	{
164cdf0e10cSrcweir         ViewShell* pViewShell = pViewShellBase->GetMainViewShell().get();
165cdf0e10cSrcweir         // If there already exists an outliner that has been created
166cdf0e10cSrcweir         // for another view shell then destroy it first.
167cdf0e10cSrcweir 		if (mpSdOutliner != NULL)
168cdf0e10cSrcweir             if ((pViewShell->ISA(DrawViewShell) && ! mbOwnOutliner)
169cdf0e10cSrcweir                 || (pViewShell->ISA(OutlineViewShell) && mbOwnOutliner))
170cdf0e10cSrcweir             {
171cdf0e10cSrcweir                 mpSdOutliner->EndSpelling();
172cdf0e10cSrcweir                 if (mbOwnOutliner)
173cdf0e10cSrcweir                     delete mpSdOutliner;
174cdf0e10cSrcweir                 mpSdOutliner = NULL;
175cdf0e10cSrcweir             }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir         // Now create/get an outliner if none is present.
178cdf0e10cSrcweir         if (mpSdOutliner == NULL)
179cdf0e10cSrcweir         {
180cdf0e10cSrcweir             if (pViewShell->ISA(DrawViewShell))
181cdf0e10cSrcweir             {
182cdf0e10cSrcweir                 // We need an outliner for the spell check so we have
183cdf0e10cSrcweir                 // to create one.
184cdf0e10cSrcweir                 mbOwnOutliner = true;
185cdf0e10cSrcweir                 mpSdOutliner = new Outliner (
186cdf0e10cSrcweir                     pViewShell->GetDoc(),
187cdf0e10cSrcweir                     OUTLINERMODE_TEXTOBJECT);
188cdf0e10cSrcweir             }
189cdf0e10cSrcweir             else if (pViewShell->ISA(OutlineViewShell))
190cdf0e10cSrcweir             {
191cdf0e10cSrcweir                 // An outline view is already visible. The SdOutliner
192cdf0e10cSrcweir                 // will use it instead of creating its own.
193cdf0e10cSrcweir                 mbOwnOutliner = false;
194cdf0e10cSrcweir                 mpSdOutliner = pViewShell->GetDoc()->GetOutliner();
195cdf0e10cSrcweir             }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir             // Initialize spelling.
198cdf0e10cSrcweir             if (mpSdOutliner != NULL)
199cdf0e10cSrcweir             {
200cdf0e10cSrcweir                 mpSdOutliner->PrepareSpelling();
201cdf0e10cSrcweir                 mpSdOutliner->StartSpelling();
202cdf0e10cSrcweir             }
203cdf0e10cSrcweir         }
204cdf0e10cSrcweir     }
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 
209cdf0e10cSrcweir } // end of namespace ::sd
210