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 #include "SpellDialogChildWindow.hxx"
28 #include <svx/svxids.hrc>
29 #include <sfx2/app.hxx>
30 #include <sfx2/bindings.hxx>
31 #include <sfx2/dispatch.hxx>
32
33 namespace sd{
34
35 SFX_IMPL_CHILDWINDOW(SpellDialogChildWindow, SID_SPELL_DIALOG)
36 }
37
38 #include "ViewShell.hxx"
39 #include "ViewShellBase.hxx"
40 #include "DrawViewShell.hxx"
41 #include "OutlineViewShell.hxx"
42 #include <Outliner.hxx>
43 #include "drawdoc.hxx"
44
45
46 namespace sd {
47
SpellDialogChildWindow(::Window * _pParent,sal_uInt16 nId,SfxBindings * pBindings,SfxChildWinInfo * pInfo)48 SpellDialogChildWindow::SpellDialogChildWindow (
49 ::Window* _pParent,
50 sal_uInt16 nId,
51 SfxBindings* pBindings,
52 SfxChildWinInfo* pInfo)
53 : ::svx::SpellDialogChildWindow (_pParent, nId, pBindings, pInfo),
54 mpSdOutliner (NULL),
55 mbOwnOutliner (false)
56 {
57 ProvideOutliner();
58 }
59
60
61
62
~SpellDialogChildWindow(void)63 SpellDialogChildWindow::~SpellDialogChildWindow (void)
64 {
65 if (mpSdOutliner != NULL)
66 mpSdOutliner->EndSpelling();
67
68 if (mbOwnOutliner)
69 delete mpSdOutliner;
70 }
71
72
73
74
75
76
77
78
GetInfo(void) const79 SfxChildWinInfo SpellDialogChildWindow::GetInfo (void) const
80 {
81 return ::svx::SpellDialogChildWindow::GetInfo();
82 }
83
84
85
86
InvalidateSpellDialog(void)87 void SpellDialogChildWindow::InvalidateSpellDialog (void)
88 {
89 ::svx::SpellDialogChildWindow::InvalidateSpellDialog();
90 }
91
92
93
94
GetNextWrongSentence(bool)95 ::svx::SpellPortions SpellDialogChildWindow::GetNextWrongSentence( bool /*bRecheck*/ )
96 {
97 ::svx::SpellPortions aResult;
98
99 if (mpSdOutliner != NULL)
100 {
101 ProvideOutliner();
102 aResult = mpSdOutliner->GetNextSpellSentence();
103 }
104
105 // Close the spell check dialog when there are no more sentences to
106 // check.
107 if (aResult.empty())
108 {
109 SfxBoolItem aItem (SID_SPELL_DIALOG, sal_False);
110 GetBindings().GetDispatcher()->Execute(
111 SID_SPELL_DIALOG,
112 SFX_CALLMODE_ASYNCHRON,
113 &aItem,
114 0L);
115 }
116
117 return aResult;
118 }
119
120
121
122
ApplyChangedSentence(const::svx::SpellPortions & rChanged,bool bRecheck)123 void SpellDialogChildWindow::ApplyChangedSentence (
124 const ::svx::SpellPortions& rChanged, bool bRecheck )
125 {
126 if (mpSdOutliner != NULL)
127 {
128 OutlinerView* pOutlinerView = mpSdOutliner->GetView(0);
129 if (pOutlinerView != NULL)
130 mpSdOutliner->ApplyChangedSentence (
131 pOutlinerView->GetEditView(),
132 rChanged, bRecheck);
133 }
134 }
135
136
137
138
GetFocus(void)139 void SpellDialogChildWindow::GetFocus (void)
140 {
141 // In order to detect a cursor movement we could compare the
142 // currently selected text shape with the one that was selected
143 // when LoseFocus() was called the last time.
144 // For the time being we instead rely on the DetectChange() method
145 // in the SdOutliner class.
146 }
147
148
149
150
LoseFocus()151 void SpellDialogChildWindow::LoseFocus()
152 {
153 }
154
155
156
157
ProvideOutliner(void)158 void SpellDialogChildWindow::ProvideOutliner (void)
159 {
160 ViewShellBase* pViewShellBase = PTR_CAST (ViewShellBase, SfxViewShell::Current());
161
162 if (pViewShellBase != NULL)
163 {
164 ViewShell* pViewShell = pViewShellBase->GetMainViewShell().get();
165 // If there already exists an outliner that has been created
166 // for another view shell then destroy it first.
167 if (mpSdOutliner != NULL)
168 if ((pViewShell->ISA(DrawViewShell) && ! mbOwnOutliner)
169 || (pViewShell->ISA(OutlineViewShell) && mbOwnOutliner))
170 {
171 mpSdOutliner->EndSpelling();
172 if (mbOwnOutliner)
173 delete mpSdOutliner;
174 mpSdOutliner = NULL;
175 }
176
177 // Now create/get an outliner if none is present.
178 if (mpSdOutliner == NULL)
179 {
180 if (pViewShell->ISA(DrawViewShell))
181 {
182 // We need an outliner for the spell check so we have
183 // to create one.
184 mbOwnOutliner = true;
185 mpSdOutliner = new Outliner (
186 pViewShell->GetDoc(),
187 OUTLINERMODE_TEXTOBJECT);
188 }
189 else if (pViewShell->ISA(OutlineViewShell))
190 {
191 // An outline view is already visible. The SdOutliner
192 // will use it instead of creating its own.
193 mbOwnOutliner = false;
194 mpSdOutliner = pViewShell->GetDoc()->GetOutliner();
195 }
196
197 // Initialize spelling.
198 if (mpSdOutliner != NULL)
199 {
200 mpSdOutliner->PrepareSpelling();
201 mpSdOutliner->StartSpelling();
202 }
203 }
204 }
205 }
206
207
208
209 } // end of namespace ::sd
210