merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / dlg / SpellDialogChildWindow.cxx
bloba179275a28b5a203c6f4054123b3a85330a6beea
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SpellDialogChildWindow.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "SpellDialogChildWindow.hxx"
35 #include <svx/svxids.hrc>
36 #include <sfx2/app.hxx>
37 #include <sfx2/bindings.hxx>
38 #include <sfx2/dispatch.hxx>
40 namespace sd{
42 SFX_IMPL_CHILDWINDOW(SpellDialogChildWindow, SID_SPELL_DIALOG)
45 #include "ViewShell.hxx"
46 #include "ViewShellBase.hxx"
47 #include "DrawViewShell.hxx"
48 #include "OutlineViewShell.hxx"
49 #include <Outliner.hxx>
50 #include "drawdoc.hxx"
53 namespace sd {
55 SpellDialogChildWindow::SpellDialogChildWindow (
56 ::Window* _pParent,
57 USHORT nId,
58 SfxBindings* pBindings,
59 SfxChildWinInfo* pInfo)
60 : ::svx::SpellDialogChildWindow (_pParent, nId, pBindings, pInfo),
61 mpSdOutliner (NULL),
62 mbOwnOutliner (false)
64 ProvideOutliner();
70 SpellDialogChildWindow::~SpellDialogChildWindow (void)
72 if (mpSdOutliner != NULL)
73 mpSdOutliner->EndSpelling();
75 if (mbOwnOutliner)
76 delete mpSdOutliner;
86 SfxChildWinInfo SpellDialogChildWindow::GetInfo (void) const
88 return ::svx::SpellDialogChildWindow::GetInfo();
94 void SpellDialogChildWindow::InvalidateSpellDialog (void)
96 ::svx::SpellDialogChildWindow::InvalidateSpellDialog();
102 ::svx::SpellPortions SpellDialogChildWindow::GetNextWrongSentence (void)
104 ::svx::SpellPortions aResult;
106 if (mpSdOutliner != NULL)
108 ProvideOutliner();
109 aResult = mpSdOutliner->GetNextSpellSentence ();
112 // Close the spell check dialog when there are no more sentences to
113 // check.
114 if (aResult.size() == 0)
116 SfxBoolItem aItem (SID_SPELL_DIALOG, FALSE);
117 GetBindings().GetDispatcher()->Execute(
118 SID_SPELL_DIALOG,
119 SFX_CALLMODE_ASYNCHRON,
120 &aItem,
121 0L);
124 return aResult;
130 void SpellDialogChildWindow::ApplyChangedSentence (
131 const ::svx::SpellPortions& rChanged)
133 if (mpSdOutliner != NULL)
135 OutlinerView* pOutlinerView = mpSdOutliner->GetView(0);
136 if (pOutlinerView != NULL)
137 mpSdOutliner->ApplyChangedSentence (
138 pOutlinerView->GetEditView(),
139 rChanged, false);
146 void SpellDialogChildWindow::GetFocus (void)
148 // In order to detect a cursor movement we could compare the
149 // currently selected text shape with the one that was selected
150 // when LoseFocus() was called the last time.
151 // For the time being we instead rely on the DetectChange() method
152 // in the SdOutliner class.
158 void SpellDialogChildWindow::LoseFocus()
165 void SpellDialogChildWindow::ProvideOutliner (void)
167 ViewShellBase* pViewShellBase = PTR_CAST (ViewShellBase, SfxViewShell::Current());
169 if (pViewShellBase != NULL)
171 ViewShell* pViewShell = pViewShellBase->GetMainViewShell().get();
172 // If there already exists an outliner that has been created
173 // for another view shell then destroy it first.
174 if (mpSdOutliner != NULL)
175 if ((pViewShell->ISA(DrawViewShell) && ! mbOwnOutliner)
176 || (pViewShell->ISA(OutlineViewShell) && mbOwnOutliner))
178 mpSdOutliner->EndSpelling();
179 if (mbOwnOutliner)
180 delete mpSdOutliner;
181 mpSdOutliner = NULL;
184 // Now create/get an outliner if none is present.
185 if (mpSdOutliner == NULL)
187 if (pViewShell->ISA(DrawViewShell))
189 // We need an outliner for the spell check so we have
190 // to create one.
191 mbOwnOutliner = true;
192 mpSdOutliner = new Outliner (
193 pViewShell->GetDoc(),
194 OUTLINERMODE_TEXTOBJECT);
196 else if (pViewShell->ISA(OutlineViewShell))
198 // An outline view is already visible. The SdOutliner
199 // will use it instead of creating its own.
200 mbOwnOutliner = false;
201 mpSdOutliner = pViewShell->GetDoc()->GetOutliner();
204 // Initialize spelling.
205 if (mpSdOutliner != NULL)
207 mpSdOutliner->PrepareSpelling();
208 mpSdOutliner->StartSpelling();
216 } // end of namespace ::sd