1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19efeef26fSAndrew Rist  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <SwSpellDialogChildWindow.hxx>
28cdf0e10cSrcweir #include <vcl/msgbox.hxx>
29cdf0e10cSrcweir #include <editeng/svxacorr.hxx>
30cdf0e10cSrcweir #include <editeng/acorrcfg.hxx>
31cdf0e10cSrcweir #include <svx/svxids.hrc>
32cdf0e10cSrcweir #include <sfx2/app.hxx>
33cdf0e10cSrcweir #include <sfx2/bindings.hxx>
34cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
35cdf0e10cSrcweir #include <editeng/unolingu.hxx>
36cdf0e10cSrcweir #include <editeng/editeng.hxx>
37cdf0e10cSrcweir #include <editeng/editview.hxx>
38cdf0e10cSrcweir #include <wrtsh.hxx>
39cdf0e10cSrcweir #include <sfx2/printer.hxx>
40cdf0e10cSrcweir #include <svx/svdoutl.hxx>
41cdf0e10cSrcweir #include <svx/svdview.hxx>
42cdf0e10cSrcweir #include <svx/svditer.hxx>
43cdf0e10cSrcweir #include <svx/svdogrp.hxx>
44cdf0e10cSrcweir #include <unotools/linguprops.hxx>
45cdf0e10cSrcweir #include <unotools/lingucfg.hxx>
46cdf0e10cSrcweir #include <doc.hxx>
47cdf0e10cSrcweir #include <docsh.hxx>
48cdf0e10cSrcweir #include <docary.hxx>
49cdf0e10cSrcweir #include <frmfmt.hxx>
50cdf0e10cSrcweir #include <dcontact.hxx>
51cdf0e10cSrcweir #include <edtwin.hxx>
52cdf0e10cSrcweir #include <pam.hxx>
53cdf0e10cSrcweir #include <drawbase.hxx>
54cdf0e10cSrcweir #include <unotextrange.hxx>
55cdf0e10cSrcweir #include <dialog.hrc>
56cdf0e10cSrcweir #include <cmdid.h>
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 
59cdf0e10cSrcweir using namespace ::com::sun::star;
60cdf0e10cSrcweir using namespace ::com::sun::star::uno;
61cdf0e10cSrcweir using namespace ::com::sun::star::text;
62cdf0e10cSrcweir using namespace ::com::sun::star::linguistic2;
63cdf0e10cSrcweir using namespace ::com::sun::star::beans;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir SFX_IMPL_CHILDWINDOW(SwSpellDialogChildWindow, FN_SPELL_GRAMMAR_DIALOG)
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 
68cdf0e10cSrcweir #define SPELL_START_BODY        0   // body text area
69cdf0e10cSrcweir #define SPELL_START_OTHER       1   // frame, footnote, header, footer
70cdf0e10cSrcweir #define SPELL_START_DRAWTEXT    2   // started in a draw text object
71cdf0e10cSrcweir 
72cdf0e10cSrcweir struct SpellState
73cdf0e10cSrcweir {
74cdf0e10cSrcweir     bool                m_bInitialCall;
75cdf0e10cSrcweir     bool                m_bLockFocus; //lock the focus notification while a modal dialog is active
76cdf0e10cSrcweir     bool                m_bLostFocus;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     //restart and progress information
79cdf0e10cSrcweir     sal_uInt16              m_SpellStartPosition;
80cdf0e10cSrcweir     bool                m_bBodySpelled;  //body already spelled
81cdf0e10cSrcweir     bool                m_bOtherSpelled; //frames, footnotes, headers and footers spelled
82cdf0e10cSrcweir     bool                m_bStartedInOther; //started the spelling insided of the _other_ area
83cdf0e10cSrcweir     bool                m_bStartedInSelection; // there was an initial text selection
84cdf0e10cSrcweir     SwPaM*              pOtherCursor; // position where the spelling inside the _other_ area started
85cdf0e10cSrcweir     bool                m_bDrawingsSpelled; //all drawings spelled
86cdf0e10cSrcweir     Reference<XTextRange> m_xStartRange; //text range that marks the start of spelling
87cdf0e10cSrcweir     const SdrObject*    m_pStartDrawing; //draw text object spelling started in
88cdf0e10cSrcweir     ESelection          m_aStartDrawingSelection; //draw text start selection
89cdf0e10cSrcweir     bool                m_bRestartDrawing; // the first selected drawing object is found again
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     //lose/get focus information to decide if spelling can be continued
92cdf0e10cSrcweir     ShellModes          m_eSelMode;
93cdf0e10cSrcweir     const SwNode*       m_pPointNode;
94cdf0e10cSrcweir     const SwNode*       m_pMarkNode;
95cdf0e10cSrcweir     xub_StrLen          m_nPointPos;
96cdf0e10cSrcweir     xub_StrLen          m_nMarkPos;
97cdf0e10cSrcweir     const SdrOutliner*  m_pOutliner;
98cdf0e10cSrcweir     ESelection          m_aESelection;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     //iterating over draw text objects
101cdf0e10cSrcweir     std::list<SdrTextObj*> m_aTextObjects;
102cdf0e10cSrcweir     bool                m_bTextObjectsCollected;
103cdf0e10cSrcweir 
SpellStateSpellState104cdf0e10cSrcweir     SpellState() :
105cdf0e10cSrcweir         m_bInitialCall(true),
106cdf0e10cSrcweir         m_bLockFocus(false),
107cdf0e10cSrcweir         m_bLostFocus(false),
108cdf0e10cSrcweir         m_SpellStartPosition(SPELL_START_BODY),
109cdf0e10cSrcweir         m_bBodySpelled(false),
110cdf0e10cSrcweir         m_bOtherSpelled(false),
111cdf0e10cSrcweir         m_bStartedInOther(false),
112cdf0e10cSrcweir         m_bStartedInSelection(false),
113cdf0e10cSrcweir         pOtherCursor(0),
114cdf0e10cSrcweir         m_bDrawingsSpelled(false),
115cdf0e10cSrcweir         m_pStartDrawing(0),
116cdf0e10cSrcweir         m_bRestartDrawing(false),
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         m_eSelMode(SHELL_MODE_OBJECT), //initially invalid
119cdf0e10cSrcweir         m_pPointNode(0),
120cdf0e10cSrcweir         m_pMarkNode(0),
121cdf0e10cSrcweir         m_nPointPos(0),
122cdf0e10cSrcweir         m_nMarkPos(0),
123cdf0e10cSrcweir         m_pOutliner(0),
124cdf0e10cSrcweir         m_bTextObjectsCollected(false)
125cdf0e10cSrcweir         {}
126cdf0e10cSrcweir 
~SpellStateSpellState127cdf0e10cSrcweir     ~SpellState() {delete pOtherCursor;}
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     // reset state in ::InvalidateSpellDialog
ResetSpellState130cdf0e10cSrcweir     void    Reset()
131cdf0e10cSrcweir             {   m_bInitialCall = true;
132cdf0e10cSrcweir                 m_bBodySpelled = m_bOtherSpelled = m_bDrawingsSpelled = false;
133cdf0e10cSrcweir                 m_xStartRange = 0;
134cdf0e10cSrcweir                 m_pStartDrawing = 0;
135cdf0e10cSrcweir                 m_bRestartDrawing = false;
136cdf0e10cSrcweir 				m_bTextObjectsCollected = false;
137cdf0e10cSrcweir                 m_aTextObjects.clear();
138cdf0e10cSrcweir                 m_bStartedInOther = false;
139cdf0e10cSrcweir                 delete pOtherCursor;
140cdf0e10cSrcweir                 pOtherCursor = 0;
141cdf0e10cSrcweir             }
142cdf0e10cSrcweir };
143cdf0e10cSrcweir /*-- 30.10.2003 14:33:26---------------------------------------------------
144cdf0e10cSrcweir 
145cdf0e10cSrcweir   -----------------------------------------------------------------------*/
lcl_LeaveDrawText(SwWrtShell & rSh)146cdf0e10cSrcweir void lcl_LeaveDrawText(SwWrtShell& rSh)
147cdf0e10cSrcweir {
148cdf0e10cSrcweir     if(rSh.GetDrawView())
149cdf0e10cSrcweir     {
150cdf0e10cSrcweir         rSh.GetDrawView()->SdrEndTextEdit( sal_True );
151cdf0e10cSrcweir         Point aPt(LONG_MIN, LONG_MIN);
152cdf0e10cSrcweir         //go out of the frame
153cdf0e10cSrcweir         rSh.SelectObj(aPt, SW_LEAVE_FRAME);
154cdf0e10cSrcweir         rSh.EnterStdMode();
155cdf0e10cSrcweir         rSh.GetView().AttrChangedNotify(&rSh);
156cdf0e10cSrcweir     }
157cdf0e10cSrcweir }
158cdf0e10cSrcweir /*-- 09.09.2003 10:39:22---------------------------------------------------
159cdf0e10cSrcweir 
160cdf0e10cSrcweir   -----------------------------------------------------------------------*/
SwSpellDialogChildWindow(Window * _pParent,sal_uInt16 nId,SfxBindings * pBindings,SfxChildWinInfo * pInfo)161cdf0e10cSrcweir SwSpellDialogChildWindow::SwSpellDialogChildWindow (
162cdf0e10cSrcweir             Window* _pParent,
163cdf0e10cSrcweir             sal_uInt16 nId,
164cdf0e10cSrcweir             SfxBindings* pBindings,
165cdf0e10cSrcweir             SfxChildWinInfo* pInfo) :
166cdf0e10cSrcweir                 svx::SpellDialogChildWindow (
167cdf0e10cSrcweir                     _pParent, nId, pBindings, pInfo),
168cdf0e10cSrcweir                     m_pSpellState(new SpellState)
169cdf0e10cSrcweir {
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     String aPropName( String::CreateFromAscii(UPN_IS_GRAMMAR_INTERACTIVE ) );
172cdf0e10cSrcweir     SvtLinguConfig().GetProperty( aPropName ) >>= m_bIsGrammarCheckingOn;
173cdf0e10cSrcweir }
174cdf0e10cSrcweir /*-- 09.09.2003 10:39:22---------------------------------------------------
175cdf0e10cSrcweir 
176cdf0e10cSrcweir   -----------------------------------------------------------------------*/
~SwSpellDialogChildWindow()177cdf0e10cSrcweir SwSpellDialogChildWindow::~SwSpellDialogChildWindow ()
178cdf0e10cSrcweir {
179cdf0e10cSrcweir     SwWrtShell* pWrtShell = GetWrtShell_Impl();
180cdf0e10cSrcweir     if(!m_pSpellState->m_bInitialCall && pWrtShell)
181cdf0e10cSrcweir         pWrtShell->SpellEnd();
182cdf0e10cSrcweir     delete m_pSpellState;
183cdf0e10cSrcweir }
184cdf0e10cSrcweir 
185cdf0e10cSrcweir /*-- 09.09.2003 12:40:07---------------------------------------------------
186cdf0e10cSrcweir 
187cdf0e10cSrcweir   -----------------------------------------------------------------------*/
GetInfo(void) const188cdf0e10cSrcweir SfxChildWinInfo SwSpellDialogChildWindow::GetInfo (void) const
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     SfxChildWinInfo aInfo = svx::SpellDialogChildWindow::GetInfo();
191cdf0e10cSrcweir     aInfo.bVisible = sal_False;
192cdf0e10cSrcweir     return aInfo;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir /*-- 09.09.2003 10:39:40---------------------------------------------------
196cdf0e10cSrcweir 
197cdf0e10cSrcweir 
198cdf0e10cSrcweir   -----------------------------------------------------------------------*/
GetNextWrongSentence(bool bRecheck)199cdf0e10cSrcweir svx::SpellPortions SwSpellDialogChildWindow::GetNextWrongSentence(bool bRecheck)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir     svx::SpellPortions aRet;
202cdf0e10cSrcweir     SwWrtShell* pWrtShell = GetWrtShell_Impl();
203cdf0e10cSrcweir     if(pWrtShell)
204cdf0e10cSrcweir     {
205cdf0e10cSrcweir         if (!bRecheck)
206cdf0e10cSrcweir         {
207cdf0e10cSrcweir             // first set continuation point for spell/grammar check to the
208cdf0e10cSrcweir             // end of the current sentence
209cdf0e10cSrcweir             pWrtShell->MoveContinuationPosToEndOfCheckedSentence();
210cdf0e10cSrcweir         }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir         ShellModes  eSelMode = pWrtShell->GetView().GetShellMode();
213cdf0e10cSrcweir         bool bDrawText = SHELL_MODE_DRAWTEXT == eSelMode;
214cdf0e10cSrcweir         bool bNormalText =
215cdf0e10cSrcweir             SHELL_MODE_TABLE_TEXT == eSelMode ||
216cdf0e10cSrcweir             SHELL_MODE_LIST_TEXT == eSelMode ||
217cdf0e10cSrcweir             SHELL_MODE_TABLE_LIST_TEXT == eSelMode ||
218cdf0e10cSrcweir             SHELL_MODE_TEXT == eSelMode;
219cdf0e10cSrcweir         //Writer text outside of the body
220cdf0e10cSrcweir         bool bOtherText = false;
221cdf0e10cSrcweir 
222cdf0e10cSrcweir         if( m_pSpellState->m_bInitialCall )
223cdf0e10cSrcweir         {
224cdf0e10cSrcweir             //if no text selection exists the cursor has to be set into the text
225cdf0e10cSrcweir             if(!bDrawText && !bNormalText)
226cdf0e10cSrcweir             {
227cdf0e10cSrcweir                 if(!MakeTextSelection_Impl(*pWrtShell, eSelMode))
228cdf0e10cSrcweir                     return aRet;
229cdf0e10cSrcweir                 else
230cdf0e10cSrcweir                 {
231cdf0e10cSrcweir                     // the selection type has to be checked again - both text types are possible
232cdf0e10cSrcweir                     if(0 != (pWrtShell->GetSelectionType()& nsSelectionType::SEL_DRW_TXT))
233cdf0e10cSrcweir                         bDrawText = true;
234cdf0e10cSrcweir                     bNormalText = !bDrawText;
235cdf0e10cSrcweir                 }
236cdf0e10cSrcweir             }
237cdf0e10cSrcweir             if(bNormalText)
238cdf0e10cSrcweir             {
239cdf0e10cSrcweir                 //set cursor to the start of the sentence
240cdf0e10cSrcweir                 if(!pWrtShell->HasSelection())
241cdf0e10cSrcweir                     pWrtShell->GoStartSentence();
242cdf0e10cSrcweir                 else
243cdf0e10cSrcweir                 {
244cdf0e10cSrcweir                     pWrtShell->ExpandToSentenceBorders();
245cdf0e10cSrcweir                     m_pSpellState->m_bStartedInSelection = true;
246cdf0e10cSrcweir                 }
247cdf0e10cSrcweir                 //determine if the selection is outside of the body text
248cdf0e10cSrcweir                 bOtherText = !(pWrtShell->GetFrmType(0,sal_True) & FRMTYPE_BODY);
249cdf0e10cSrcweir                 m_pSpellState->m_SpellStartPosition = bOtherText ? SPELL_START_OTHER : SPELL_START_BODY;
250cdf0e10cSrcweir                 if(bOtherText)
251cdf0e10cSrcweir                 {
252cdf0e10cSrcweir                     m_pSpellState->pOtherCursor = new SwPaM(*pWrtShell->GetCrsr()->GetPoint());
253cdf0e10cSrcweir                     m_pSpellState->m_bStartedInOther = true;
254*46d2a04eSHerbert Dürr                     pWrtShell->SpellStart( DOCPOS_OTHERSTART, DOCPOS_OTHEREND, DOCPOS_CURR, NULL );
255cdf0e10cSrcweir                 }
256cdf0e10cSrcweir                 else
257cdf0e10cSrcweir 				{
258cdf0e10cSrcweir 					SwPaM* pCrsr = pWrtShell->GetCrsr();
259cdf0e10cSrcweir 					//mark the start position only if not at start of doc
260cdf0e10cSrcweir 					if(!pWrtShell->IsStartOfDoc())
261cdf0e10cSrcweir 					{
262cdf0e10cSrcweir                         m_pSpellState->m_xStartRange =
263cdf0e10cSrcweir                             SwXTextRange::CreateXTextRange(
264cdf0e10cSrcweir                                 *pWrtShell->GetDoc(),
265cdf0e10cSrcweir                                 *pCrsr->Start(), pCrsr->End());
266cdf0e10cSrcweir 					}
267*46d2a04eSHerbert Dürr                     pWrtShell->SpellStart( DOCPOS_START, DOCPOS_END, DOCPOS_CURR, NULL );
268cdf0e10cSrcweir 				}
269cdf0e10cSrcweir             }
270cdf0e10cSrcweir             else
271cdf0e10cSrcweir             {
272cdf0e10cSrcweir                 SdrView* pSdrView = pWrtShell->GetDrawView();
273cdf0e10cSrcweir                 m_pSpellState->m_SpellStartPosition = SPELL_START_DRAWTEXT;
274cdf0e10cSrcweir                 m_pSpellState->m_pStartDrawing = pSdrView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
275cdf0e10cSrcweir                 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
276cdf0e10cSrcweir                 // start checking at the top of the drawing object
277cdf0e10cSrcweir                 pOLV->SetSelection( ESelection() );
278cdf0e10cSrcweir                 m_pSpellState->m_aStartDrawingSelection = ESelection();
279cdf0e10cSrcweir /*
280cdf0e10cSrcweir Note: spelling in a selection only, or starting in a mid of a drawing object requires
281cdf0e10cSrcweir further changes elsewhere. (Especially if it should work in sc and sd as well.)
282cdf0e10cSrcweir The code below would only be part of the solution.
283cdf0e10cSrcweir (Keeping it a as a comment for the time being)
284cdf0e10cSrcweir                 ESelection aCurSel( pOLV->GetSelection() );
285cdf0e10cSrcweir                 ESelection aSentenceSel( pOLV->GetEditView().GetEditEngine()->SelectSentence( aCurSel ) );
286cdf0e10cSrcweir                 if (!aCurSel.HasRange())
287cdf0e10cSrcweir                 {
288cdf0e10cSrcweir                     aSentenceSel.nEndPara = aSentenceSel.nStartPara;
289cdf0e10cSrcweir                     aSentenceSel.nEndPos  = aSentenceSel.nStartPos;
290cdf0e10cSrcweir                 }
291cdf0e10cSrcweir                 pOLV->SetSelection( aSentenceSel );
292cdf0e10cSrcweir                 m_pSpellState->m_aStartDrawingSelection = aSentenceSel;
293cdf0e10cSrcweir */
294cdf0e10cSrcweir             }
295cdf0e10cSrcweir 
296cdf0e10cSrcweir             m_pSpellState->m_bInitialCall = false;
297cdf0e10cSrcweir         }
298cdf0e10cSrcweir         if( bDrawText )
299cdf0e10cSrcweir         {
300cdf0e10cSrcweir             // spell inside of the current draw text
301cdf0e10cSrcweir             if(!SpellDrawText_Impl(*pWrtShell, aRet))
302cdf0e10cSrcweir             {
303cdf0e10cSrcweir                 if(!FindNextDrawTextError_Impl(*pWrtShell) || !SpellDrawText_Impl(*pWrtShell, aRet))
304cdf0e10cSrcweir                 {
305cdf0e10cSrcweir                     lcl_LeaveDrawText(*pWrtShell);
306cdf0e10cSrcweir                     //now the drawings have been spelled
307cdf0e10cSrcweir                     m_pSpellState->m_bDrawingsSpelled = true;
308cdf0e10cSrcweir                     //the spelling continues at the other content
309cdf0e10cSrcweir                     //if there's any that has not been spelled yet
310cdf0e10cSrcweir                     if(!m_pSpellState->m_bOtherSpelled && pWrtShell->HasOtherCnt())
311cdf0e10cSrcweir                     {
312*46d2a04eSHerbert Dürr                         pWrtShell->SpellStart(DOCPOS_OTHERSTART, DOCPOS_OTHEREND, DOCPOS_OTHERSTART, NULL );
313cdf0e10cSrcweir                         if(!pWrtShell->SpellSentence(aRet, m_bIsGrammarCheckingOn))
314cdf0e10cSrcweir 						{
315cdf0e10cSrcweir                             pWrtShell->SpellEnd();
316cdf0e10cSrcweir 							m_pSpellState->m_bOtherSpelled = true;
317cdf0e10cSrcweir 						}
318cdf0e10cSrcweir                     }
319cdf0e10cSrcweir                     else
320cdf0e10cSrcweir                         m_pSpellState->m_bOtherSpelled = true;
321cdf0e10cSrcweir                     //if no result has been found try at the body text - completely
322cdf0e10cSrcweir                     if(!m_pSpellState->m_bBodySpelled && !aRet.size())
323cdf0e10cSrcweir                     {
324*46d2a04eSHerbert Dürr                         pWrtShell->SpellStart(DOCPOS_START, DOCPOS_END, DOCPOS_START, NULL );
325cdf0e10cSrcweir                         if(!pWrtShell->SpellSentence(aRet, m_bIsGrammarCheckingOn))
326cdf0e10cSrcweir                         {
327cdf0e10cSrcweir                             m_pSpellState->m_bBodySpelled = true;
328cdf0e10cSrcweir                             pWrtShell->SpellEnd();
329cdf0e10cSrcweir                         }
330cdf0e10cSrcweir                     }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir                 }
333cdf0e10cSrcweir             }
334cdf0e10cSrcweir         }
335cdf0e10cSrcweir         else
336cdf0e10cSrcweir         {
337cdf0e10cSrcweir             //spell inside of the Writer text
338cdf0e10cSrcweir             if(!pWrtShell->SpellSentence(aRet, m_bIsGrammarCheckingOn))
339cdf0e10cSrcweir             {
340cdf0e10cSrcweir                 // if there is a selection (within body or header/footer text)
341cdf0e10cSrcweir                 // then spell/grammar checking should not move outside of it.
342cdf0e10cSrcweir                 if (!m_pSpellState->m_bStartedInSelection)
343cdf0e10cSrcweir                 {
344cdf0e10cSrcweir                     //find out which text has been spelled body or other
345cdf0e10cSrcweir                     bOtherText = !(pWrtShell->GetFrmType(0,sal_True) & FRMTYPE_BODY);
346cdf0e10cSrcweir                     if(bOtherText && m_pSpellState->m_bStartedInOther && m_pSpellState->pOtherCursor)
347cdf0e10cSrcweir                     {
348cdf0e10cSrcweir                         m_pSpellState->m_bStartedInOther = false;
349cdf0e10cSrcweir                         pWrtShell->SetSelection(*m_pSpellState->pOtherCursor);
350cdf0e10cSrcweir                         pWrtShell->SpellEnd();
351cdf0e10cSrcweir                         delete m_pSpellState->pOtherCursor;
352cdf0e10cSrcweir                         m_pSpellState->pOtherCursor = 0;
353*46d2a04eSHerbert Dürr                         pWrtShell->SpellStart(DOCPOS_OTHERSTART, DOCPOS_CURR, DOCPOS_OTHERSTART, NULL );
354cdf0e10cSrcweir                         pWrtShell->SpellSentence(aRet, m_bIsGrammarCheckingOn);
355cdf0e10cSrcweir                     }
356cdf0e10cSrcweir                     if(!aRet.size())
357cdf0e10cSrcweir                     {
358cdf0e10cSrcweir                         //end spelling
359cdf0e10cSrcweir                         pWrtShell->SpellEnd();
360cdf0e10cSrcweir                         if(bOtherText)
361cdf0e10cSrcweir                         {
362cdf0e10cSrcweir                             m_pSpellState->m_bOtherSpelled = true;
363cdf0e10cSrcweir                             //has the body been spelled?
364cdf0e10cSrcweir                             if(!m_pSpellState->m_bBodySpelled)
365cdf0e10cSrcweir                             {
366*46d2a04eSHerbert Dürr                                 pWrtShell->SpellStart(DOCPOS_START, DOCPOS_END, DOCPOS_START, NULL );
367cdf0e10cSrcweir                                 if(!pWrtShell->SpellSentence(aRet, m_bIsGrammarCheckingOn))
368cdf0e10cSrcweir                                 {
369cdf0e10cSrcweir                                     m_pSpellState->m_bBodySpelled = true;
370cdf0e10cSrcweir                                     pWrtShell->SpellEnd();
371cdf0e10cSrcweir                                 }
372cdf0e10cSrcweir                             }
373cdf0e10cSrcweir                         }
374cdf0e10cSrcweir                         else
375cdf0e10cSrcweir                         {
376cdf0e10cSrcweir                              m_pSpellState->m_bBodySpelled = true;
377cdf0e10cSrcweir                              if(!m_pSpellState->m_bOtherSpelled && pWrtShell->HasOtherCnt())
378cdf0e10cSrcweir                              {
379*46d2a04eSHerbert Dürr                                 pWrtShell->SpellStart(DOCPOS_OTHERSTART, DOCPOS_OTHEREND, DOCPOS_OTHERSTART, NULL );
380cdf0e10cSrcweir                                 if(!pWrtShell->SpellSentence(aRet, m_bIsGrammarCheckingOn))
381cdf0e10cSrcweir                                 {
382cdf0e10cSrcweir                                     pWrtShell->SpellEnd();
383cdf0e10cSrcweir                                     m_pSpellState->m_bOtherSpelled = true;
384cdf0e10cSrcweir                                 }
385cdf0e10cSrcweir                              }
386cdf0e10cSrcweir                              else
387cdf0e10cSrcweir                                  m_pSpellState->m_bOtherSpelled = true;
388cdf0e10cSrcweir                         }
389cdf0e10cSrcweir                     }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir                     //search for a draw text object that contains error and spell it
392cdf0e10cSrcweir                     if(!aRet.size() &&
393cdf0e10cSrcweir                             (m_pSpellState->m_bDrawingsSpelled ||
394cdf0e10cSrcweir                             !FindNextDrawTextError_Impl(*pWrtShell) || !SpellDrawText_Impl(*pWrtShell, aRet)))
395cdf0e10cSrcweir                     {
396cdf0e10cSrcweir                         lcl_LeaveDrawText(*pWrtShell);
397cdf0e10cSrcweir                         m_pSpellState->m_bDrawingsSpelled = true;
398cdf0e10cSrcweir                     }
399cdf0e10cSrcweir                 }
400cdf0e10cSrcweir             }
401cdf0e10cSrcweir         }
402cdf0e10cSrcweir         // now only the rest of the body text can be spelled -
403cdf0e10cSrcweir         // if the spelling started inside of the body
404cdf0e10cSrcweir         //
405cdf0e10cSrcweir         bool bCloseMessage = true;
406cdf0e10cSrcweir         if(!aRet.size() && !m_pSpellState->m_bStartedInSelection)
407cdf0e10cSrcweir         {
408cdf0e10cSrcweir             DBG_ASSERT(m_pSpellState->m_bDrawingsSpelled &&
409cdf0e10cSrcweir                         m_pSpellState->m_bOtherSpelled && m_pSpellState->m_bBodySpelled,
410cdf0e10cSrcweir                         "not all parts of the document are already spelled");
411cdf0e10cSrcweir             if(m_pSpellState->m_xStartRange.is())
412cdf0e10cSrcweir             {
413cdf0e10cSrcweir                 LockFocusNotification( true );
414cdf0e10cSrcweir                 sal_uInt16 nRet = QueryBox( GetWindow(),  SW_RES(RID_QB_SPELL_CONTINUE)).Execute();
415cdf0e10cSrcweir                 if(RET_YES == nRet)
416cdf0e10cSrcweir                 {
417cdf0e10cSrcweir                     SwUnoInternalPaM aPam(*pWrtShell->GetDoc());
418cdf0e10cSrcweir                     if (::sw::XTextRangeToSwPaM(aPam,
419cdf0e10cSrcweir                                 m_pSpellState->m_xStartRange))
420cdf0e10cSrcweir                     {
421cdf0e10cSrcweir                         pWrtShell->SetSelection(aPam);
422cdf0e10cSrcweir                         pWrtShell->SpellStart(DOCPOS_START, DOCPOS_CURR, DOCPOS_START);
423cdf0e10cSrcweir                         if(!pWrtShell->SpellSentence(aRet, m_bIsGrammarCheckingOn))
424cdf0e10cSrcweir                             pWrtShell->SpellEnd();
425cdf0e10cSrcweir                     }
426cdf0e10cSrcweir                     m_pSpellState->m_xStartRange = 0;
427cdf0e10cSrcweir                     LockFocusNotification( false );
428cdf0e10cSrcweir                     //take care that the now valid selection is stored
429cdf0e10cSrcweir                     LoseFocus();
430cdf0e10cSrcweir                 }
431cdf0e10cSrcweir                 else
432cdf0e10cSrcweir                     bCloseMessage = false; //no closing message if a wrap around has been denied
433cdf0e10cSrcweir             }
434cdf0e10cSrcweir         }
435cdf0e10cSrcweir         if(!aRet.size())
436cdf0e10cSrcweir         {
437cdf0e10cSrcweir             if(bCloseMessage)
438cdf0e10cSrcweir 			{
439cdf0e10cSrcweir 				LockFocusNotification( true );
440cdf0e10cSrcweir                 String sInfo(SW_RES(STR_SPELLING_COMPLETED));
441cdf0e10cSrcweir                 //#i84610#
442cdf0e10cSrcweir                 Window* pTemp = GetWindow();    // temporary needed for g++ 3.3.5
443cdf0e10cSrcweir                 InfoBox(pTemp, sInfo ).Execute();
444cdf0e10cSrcweir                 LockFocusNotification( false );
445cdf0e10cSrcweir                 //take care that the now valid selection is stored
446cdf0e10cSrcweir                 LoseFocus();
447cdf0e10cSrcweir 			}
448cdf0e10cSrcweir 
449cdf0e10cSrcweir             //close the spelling dialog
450cdf0e10cSrcweir             GetBindings().GetDispatcher()->Execute(FN_SPELL_GRAMMAR_DIALOG, SFX_CALLMODE_ASYNCHRON);
451cdf0e10cSrcweir         }
452cdf0e10cSrcweir     }
453cdf0e10cSrcweir     return aRet;
454cdf0e10cSrcweir 
455cdf0e10cSrcweir }
456cdf0e10cSrcweir /*-- 09.09.2003 10:39:40---------------------------------------------------
457cdf0e10cSrcweir 
458cdf0e10cSrcweir   -----------------------------------------------------------------------*/
ApplyChangedSentence(const svx::SpellPortions & rChanged,bool bRecheck)459cdf0e10cSrcweir void SwSpellDialogChildWindow::ApplyChangedSentence(const svx::SpellPortions& rChanged, bool bRecheck)
460cdf0e10cSrcweir {
461cdf0e10cSrcweir     SwWrtShell* pWrtShell = GetWrtShell_Impl();
462cdf0e10cSrcweir     DBG_ASSERT(!m_pSpellState->m_bInitialCall, "ApplyChangedSentence in initial call or after resume");
463cdf0e10cSrcweir     if(pWrtShell && !m_pSpellState->m_bInitialCall)
464cdf0e10cSrcweir     {
465cdf0e10cSrcweir 		ShellModes  eSelMode = pWrtShell->GetView().GetShellMode();
466cdf0e10cSrcweir 		bool bDrawText = SHELL_MODE_DRAWTEXT == eSelMode;
467cdf0e10cSrcweir 		bool bNormalText =
468cdf0e10cSrcweir 			SHELL_MODE_TABLE_TEXT == eSelMode ||
469cdf0e10cSrcweir 			SHELL_MODE_LIST_TEXT == eSelMode ||
470cdf0e10cSrcweir 			SHELL_MODE_TABLE_LIST_TEXT == eSelMode ||
471cdf0e10cSrcweir 			SHELL_MODE_TEXT == eSelMode;
472cdf0e10cSrcweir 
473cdf0e10cSrcweir         // evaluate if the same sentence should be rechecked or not.
474cdf0e10cSrcweir         // Sentences that got grammar checked should always be rechecked in order
475cdf0e10cSrcweir         // to detect possible errors that get introduced with the changes
476cdf0e10cSrcweir         bRecheck |= pWrtShell->HasLastSentenceGotGrammarChecked();
477cdf0e10cSrcweir 
478cdf0e10cSrcweir 		if(bNormalText)
479cdf0e10cSrcweir 			pWrtShell->ApplyChangedSentence(rChanged, bRecheck);
480cdf0e10cSrcweir         else if(bDrawText )
481cdf0e10cSrcweir         {
482cdf0e10cSrcweir             SdrView* pDrView = pWrtShell->GetDrawView();
483cdf0e10cSrcweir             SdrOutliner *pOutliner = pDrView->GetTextEditOutliner();
484cdf0e10cSrcweir             pOutliner->ApplyChangedSentence(pDrView->GetTextEditOutlinerView()->GetEditView(), rChanged, bRecheck);
485cdf0e10cSrcweir         }
486cdf0e10cSrcweir 	}
487cdf0e10cSrcweir }
488cdf0e10cSrcweir /*-- 21.10.2003 09:33:57---------------------------------------------------
489cdf0e10cSrcweir 
490cdf0e10cSrcweir   -----------------------------------------------------------------------*/
AddAutoCorrection(const String & rOld,const String & rNew,LanguageType eLanguage)491cdf0e10cSrcweir void SwSpellDialogChildWindow::AddAutoCorrection(
492cdf0e10cSrcweir         const String& rOld, const String& rNew, LanguageType eLanguage)
493cdf0e10cSrcweir {
494cdf0e10cSrcweir     SvxAutoCorrect* pACorr = SvxAutoCorrCfg::Get()->GetAutoCorrect();
495cdf0e10cSrcweir     pACorr->PutText( rOld, rNew, eLanguage );
496cdf0e10cSrcweir }
497cdf0e10cSrcweir /*-- 21.10.2003 09:33:59---------------------------------------------------
498cdf0e10cSrcweir 
499cdf0e10cSrcweir   -----------------------------------------------------------------------*/
HasAutoCorrection()500cdf0e10cSrcweir bool SwSpellDialogChildWindow::HasAutoCorrection()
501cdf0e10cSrcweir {
502cdf0e10cSrcweir     return true;
503cdf0e10cSrcweir }
504cdf0e10cSrcweir /*-- 16.06.2008 11:59:17---------------------------------------------------
505cdf0e10cSrcweir 
506cdf0e10cSrcweir   -----------------------------------------------------------------------*/
HasGrammarChecking()507cdf0e10cSrcweir bool SwSpellDialogChildWindow::HasGrammarChecking()
508cdf0e10cSrcweir {
509cdf0e10cSrcweir     return SvtLinguConfig().HasGrammarChecker();
510cdf0e10cSrcweir }
511cdf0e10cSrcweir /*-- 18.06.2008 12:27:11---------------------------------------------------
512cdf0e10cSrcweir 
513cdf0e10cSrcweir   -----------------------------------------------------------------------*/
IsGrammarChecking()514cdf0e10cSrcweir bool SwSpellDialogChildWindow::IsGrammarChecking()
515cdf0e10cSrcweir {
516cdf0e10cSrcweir     return m_bIsGrammarCheckingOn;
517cdf0e10cSrcweir }
518cdf0e10cSrcweir /*-- 18.06.2008 12:27:11---------------------------------------------------
519cdf0e10cSrcweir 
520cdf0e10cSrcweir   -----------------------------------------------------------------------*/
SetGrammarChecking(bool bOn)521cdf0e10cSrcweir void SwSpellDialogChildWindow::SetGrammarChecking(bool bOn)
522cdf0e10cSrcweir {
523cdf0e10cSrcweir     uno::Any aVal;
524cdf0e10cSrcweir     aVal <<= bOn;
525cdf0e10cSrcweir     m_bIsGrammarCheckingOn = bOn;
526cdf0e10cSrcweir     String aPropName( C2S(UPN_IS_GRAMMAR_INTERACTIVE ) );
527cdf0e10cSrcweir     SvtLinguConfig().SetProperty( aPropName, aVal );
528cdf0e10cSrcweir     // set current spell position to the start of the current sentence to
529cdf0e10cSrcweir     // continue with this sentence after grammar checking state has been changed
530cdf0e10cSrcweir     SwWrtShell* pWrtShell = GetWrtShell_Impl();
531cdf0e10cSrcweir     if(pWrtShell)
532cdf0e10cSrcweir     {
533cdf0e10cSrcweir         ShellModes  eSelMode = pWrtShell->GetView().GetShellMode();
534cdf0e10cSrcweir         bool bDrawText = SHELL_MODE_DRAWTEXT == eSelMode;
535cdf0e10cSrcweir         bool bNormalText =
536cdf0e10cSrcweir             SHELL_MODE_TABLE_TEXT == eSelMode ||
537cdf0e10cSrcweir             SHELL_MODE_LIST_TEXT == eSelMode ||
538cdf0e10cSrcweir             SHELL_MODE_TABLE_LIST_TEXT == eSelMode ||
539cdf0e10cSrcweir             SHELL_MODE_TEXT == eSelMode;
540cdf0e10cSrcweir         if( bNormalText )
541cdf0e10cSrcweir             pWrtShell->PutSpellingToSentenceStart();
542cdf0e10cSrcweir         else if( bDrawText )
543cdf0e10cSrcweir         {
544cdf0e10cSrcweir             SdrView*     pSdrView = pWrtShell->GetDrawView();
545cdf0e10cSrcweir             SdrOutliner* pOutliner = pSdrView ? pSdrView->GetTextEditOutliner() : 0;
546cdf0e10cSrcweir             DBG_ASSERT(pOutliner, "No Outliner in SwSpellDialogChildWindow::SetGrammarChecking");
547cdf0e10cSrcweir             if(pOutliner)
548cdf0e10cSrcweir             {
549cdf0e10cSrcweir                 pOutliner->PutSpellingToSentenceStart( pSdrView->GetTextEditOutlinerView()->GetEditView() );
550cdf0e10cSrcweir             }
551cdf0e10cSrcweir         }
552cdf0e10cSrcweir     }
553cdf0e10cSrcweir }
554cdf0e10cSrcweir /*-- 28.10.2003 08:41:09---------------------------------------------------
555cdf0e10cSrcweir 
556cdf0e10cSrcweir   -----------------------------------------------------------------------*/
GetFocus()557cdf0e10cSrcweir void SwSpellDialogChildWindow::GetFocus()
558cdf0e10cSrcweir {
559cdf0e10cSrcweir     if(m_pSpellState->m_bLockFocus)
560cdf0e10cSrcweir         return;
561cdf0e10cSrcweir     bool bInvalidate = false;
562cdf0e10cSrcweir     SwWrtShell* pWrtShell = GetWrtShell_Impl();
563cdf0e10cSrcweir     if(pWrtShell && !m_pSpellState->m_bInitialCall)
564cdf0e10cSrcweir     {
565cdf0e10cSrcweir         ShellModes  eSelMode = pWrtShell->GetView().GetShellMode();
566cdf0e10cSrcweir         if(eSelMode != m_pSpellState->m_eSelMode)
567cdf0e10cSrcweir         {
568cdf0e10cSrcweir             //prevent initial invalidation
569cdf0e10cSrcweir             if(m_pSpellState->m_bLostFocus)
570cdf0e10cSrcweir                 bInvalidate = true;
571cdf0e10cSrcweir         }
572cdf0e10cSrcweir         else
573cdf0e10cSrcweir         {
574cdf0e10cSrcweir             switch(m_pSpellState->m_eSelMode)
575cdf0e10cSrcweir             {
576cdf0e10cSrcweir                 case SHELL_MODE_TEXT:
577cdf0e10cSrcweir                 case SHELL_MODE_LIST_TEXT:
578cdf0e10cSrcweir                 case SHELL_MODE_TABLE_TEXT:
579cdf0e10cSrcweir                 case SHELL_MODE_TABLE_LIST_TEXT:
580cdf0e10cSrcweir                 {
581cdf0e10cSrcweir                     SwPaM* pCursor = pWrtShell->GetCrsr();
582cdf0e10cSrcweir                     if(m_pSpellState->m_pPointNode != pCursor->GetNode(sal_True) ||
583cdf0e10cSrcweir                         m_pSpellState->m_pMarkNode != pCursor->GetNode(sal_False)||
584cdf0e10cSrcweir                         m_pSpellState->m_nPointPos != pCursor->GetPoint()->nContent.GetIndex()||
585cdf0e10cSrcweir                         m_pSpellState->m_nMarkPos != pCursor->GetMark()->nContent.GetIndex())
586cdf0e10cSrcweir                             bInvalidate = true;
587cdf0e10cSrcweir                 }
588cdf0e10cSrcweir                 break;
589cdf0e10cSrcweir                 case SHELL_MODE_DRAWTEXT:
590cdf0e10cSrcweir                 {
591cdf0e10cSrcweir                     SdrView*     pSdrView = pWrtShell->GetDrawView();
592cdf0e10cSrcweir                     SdrOutliner* pOutliner = pSdrView ? pSdrView->GetTextEditOutliner() : 0;
593cdf0e10cSrcweir                     if(!pOutliner || m_pSpellState->m_pOutliner != pOutliner)
594cdf0e10cSrcweir                         bInvalidate = true;
595cdf0e10cSrcweir                     else
596cdf0e10cSrcweir                     {
597cdf0e10cSrcweir                         OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
598cdf0e10cSrcweir                         DBG_ASSERT(pOLV, "no OutlinerView in SwSpellDialogChildWindow::GetFocus()");
599cdf0e10cSrcweir                         if(!pOLV || !m_pSpellState->m_aESelection.IsEqual(pOLV->GetSelection()))
600cdf0e10cSrcweir                             bInvalidate = true;
601cdf0e10cSrcweir                     }
602cdf0e10cSrcweir                 }
603cdf0e10cSrcweir                 break;
604cdf0e10cSrcweir                 default: bInvalidate = true;
605cdf0e10cSrcweir             }
606cdf0e10cSrcweir         }
607cdf0e10cSrcweir     }
608cdf0e10cSrcweir     else
609cdf0e10cSrcweir     {
610cdf0e10cSrcweir         bInvalidate = true;
611cdf0e10cSrcweir     }
612cdf0e10cSrcweir     if(bInvalidate)
613cdf0e10cSrcweir         InvalidateSpellDialog();
614cdf0e10cSrcweir }
615cdf0e10cSrcweir /*-- 28.10.2003 08:41:09---------------------------------------------------
616cdf0e10cSrcweir 
617cdf0e10cSrcweir   -----------------------------------------------------------------------*/
LoseFocus()618cdf0e10cSrcweir void SwSpellDialogChildWindow::LoseFocus()
619cdf0e10cSrcweir {
620cdf0e10cSrcweir     //prevent initial invalidation
621cdf0e10cSrcweir     m_pSpellState->m_bLostFocus = true;
622cdf0e10cSrcweir     if(m_pSpellState->m_bLockFocus)
623cdf0e10cSrcweir         return;
624cdf0e10cSrcweir     SwWrtShell* pWrtShell = GetWrtShell_Impl();
625cdf0e10cSrcweir     if(pWrtShell)
626cdf0e10cSrcweir     {
627cdf0e10cSrcweir         m_pSpellState->m_eSelMode = pWrtShell->GetView().GetShellMode();
628cdf0e10cSrcweir         m_pSpellState->m_pPointNode = m_pSpellState->m_pMarkNode = 0;
629cdf0e10cSrcweir         m_pSpellState->m_nPointPos = m_pSpellState->m_nMarkPos = 0;
630cdf0e10cSrcweir         m_pSpellState->m_pOutliner = 0;
631cdf0e10cSrcweir 
632cdf0e10cSrcweir         switch(m_pSpellState->m_eSelMode)
633cdf0e10cSrcweir         {
634cdf0e10cSrcweir             case SHELL_MODE_TEXT:
635cdf0e10cSrcweir             case SHELL_MODE_LIST_TEXT:
636cdf0e10cSrcweir             case SHELL_MODE_TABLE_TEXT:
637cdf0e10cSrcweir             case SHELL_MODE_TABLE_LIST_TEXT:
638cdf0e10cSrcweir             {
639cdf0e10cSrcweir                 //store a node pointer and a pam-position to be able to check on next GetFocus();
640cdf0e10cSrcweir                 SwPaM* pCursor = pWrtShell->GetCrsr();
641cdf0e10cSrcweir                 m_pSpellState->m_pPointNode = pCursor->GetNode(sal_True);
642cdf0e10cSrcweir                 m_pSpellState->m_pMarkNode = pCursor->GetNode(sal_False);
643cdf0e10cSrcweir                 m_pSpellState->m_nPointPos = pCursor->GetPoint()->nContent.GetIndex();
644cdf0e10cSrcweir                 m_pSpellState->m_nMarkPos = pCursor->GetMark()->nContent.GetIndex();
645cdf0e10cSrcweir 
646cdf0e10cSrcweir             }
647cdf0e10cSrcweir             break;
648cdf0e10cSrcweir             case SHELL_MODE_DRAWTEXT:
649cdf0e10cSrcweir             {
650cdf0e10cSrcweir                 SdrView*     pSdrView = pWrtShell->GetDrawView();
651cdf0e10cSrcweir                 SdrOutliner* pOutliner = pSdrView->GetTextEditOutliner();
652cdf0e10cSrcweir                 m_pSpellState->m_pOutliner = pOutliner;
653cdf0e10cSrcweir                 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
654cdf0e10cSrcweir                 DBG_ASSERT(pOutliner && pOLV, "no Outliner/OutlinerView in SwSpellDialogChildWindow::LoseFocus()");
655cdf0e10cSrcweir                 if(pOLV)
656cdf0e10cSrcweir                 {
657cdf0e10cSrcweir                     m_pSpellState->m_aESelection = pOLV->GetSelection();
658cdf0e10cSrcweir                 }
659cdf0e10cSrcweir             }
660cdf0e10cSrcweir             break;
661cdf0e10cSrcweir             default:;//prevent warning
662cdf0e10cSrcweir         }
663cdf0e10cSrcweir     }
664cdf0e10cSrcweir     else
665cdf0e10cSrcweir         m_pSpellState->m_eSelMode = SHELL_MODE_OBJECT;
666cdf0e10cSrcweir }
667cdf0e10cSrcweir /*-- 18.09.2003 12:50:18---------------------------------------------------
668cdf0e10cSrcweir 
669cdf0e10cSrcweir   -----------------------------------------------------------------------*/
InvalidateSpellDialog()670cdf0e10cSrcweir void SwSpellDialogChildWindow::InvalidateSpellDialog()
671cdf0e10cSrcweir {
672cdf0e10cSrcweir     SwWrtShell* pWrtShell = GetWrtShell_Impl();
673cdf0e10cSrcweir     if(!m_pSpellState->m_bInitialCall && pWrtShell)
674cdf0e10cSrcweir         pWrtShell->SpellEnd(0, false);
675cdf0e10cSrcweir     m_pSpellState->Reset();
676cdf0e10cSrcweir     svx::SpellDialogChildWindow::InvalidateSpellDialog();
677cdf0e10cSrcweir }
678cdf0e10cSrcweir 
679cdf0e10cSrcweir /*-- 18.09.2003 12:54:59---------------------------------------------------
680cdf0e10cSrcweir 
681cdf0e10cSrcweir   -----------------------------------------------------------------------*/
GetWrtShell_Impl()682cdf0e10cSrcweir SwWrtShell* SwSpellDialogChildWindow::GetWrtShell_Impl()
683cdf0e10cSrcweir {
684cdf0e10cSrcweir     SfxDispatcher* pDispatch = GetBindings().GetDispatcher();
685cdf0e10cSrcweir     SwView* pView = 0;
686cdf0e10cSrcweir     if(pDispatch)
687cdf0e10cSrcweir     {
688cdf0e10cSrcweir         sal_uInt16 nShellIdx = 0;
689cdf0e10cSrcweir         SfxShell* pShell;
690cdf0e10cSrcweir         while(0 != (pShell = pDispatch->GetShell(nShellIdx++)))
691cdf0e10cSrcweir             if(pShell->ISA(SwView))
692cdf0e10cSrcweir             {
693cdf0e10cSrcweir                 pView = static_cast<SwView* >(pShell);
694cdf0e10cSrcweir                 break;
695cdf0e10cSrcweir             }
696cdf0e10cSrcweir     }
697cdf0e10cSrcweir     return pView ? pView->GetWrtShellPtr(): 0;
698cdf0e10cSrcweir }
699cdf0e10cSrcweir 
700cdf0e10cSrcweir /*-- 13.10.2003 15:19:04---------------------------------------------------
701cdf0e10cSrcweir     set the cursor into the body text - necessary if any object is selected
702cdf0e10cSrcweir     on start of the spelling dialog
703cdf0e10cSrcweir   -----------------------------------------------------------------------*/
MakeTextSelection_Impl(SwWrtShell & rShell,ShellModes eSelMode)704cdf0e10cSrcweir bool SwSpellDialogChildWindow::MakeTextSelection_Impl(SwWrtShell& rShell, ShellModes  eSelMode)
705cdf0e10cSrcweir {
706cdf0e10cSrcweir     SwView& rView = rShell.GetView();
707cdf0e10cSrcweir     switch(eSelMode)
708cdf0e10cSrcweir     {
709cdf0e10cSrcweir         case SHELL_MODE_TEXT:
710cdf0e10cSrcweir         case SHELL_MODE_LIST_TEXT:
711cdf0e10cSrcweir         case SHELL_MODE_TABLE_TEXT:
712cdf0e10cSrcweir         case SHELL_MODE_TABLE_LIST_TEXT:
713cdf0e10cSrcweir         case SHELL_MODE_DRAWTEXT:
714cdf0e10cSrcweir             DBG_ERROR("text already active in SwSpellDialogChildWindow::MakeTextSelection_Impl()");
715cdf0e10cSrcweir         break;
716cdf0e10cSrcweir 
717cdf0e10cSrcweir         case SHELL_MODE_FRAME:
718cdf0e10cSrcweir         {
719cdf0e10cSrcweir             rShell.UnSelectFrm();
720cdf0e10cSrcweir             rShell.LeaveSelFrmMode();
721cdf0e10cSrcweir             rView.AttrChangedNotify(&rShell);
722cdf0e10cSrcweir         }
723cdf0e10cSrcweir         break;
724cdf0e10cSrcweir 
725cdf0e10cSrcweir         case SHELL_MODE_DRAW:
726cdf0e10cSrcweir         case SHELL_MODE_DRAW_CTRL:
727cdf0e10cSrcweir         case SHELL_MODE_DRAW_FORM:
728cdf0e10cSrcweir         case SHELL_MODE_BEZIER:
729cdf0e10cSrcweir             if(FindNextDrawTextError_Impl(rShell))
730cdf0e10cSrcweir 			{
731cdf0e10cSrcweir                 rView.AttrChangedNotify(&rShell);
732cdf0e10cSrcweir                 break;
733cdf0e10cSrcweir 			}
734cdf0e10cSrcweir         //otherwise no break to deselect the object
735cdf0e10cSrcweir         case SHELL_MODE_GRAPHIC:
736cdf0e10cSrcweir         case SHELL_MODE_OBJECT:
737cdf0e10cSrcweir         {
738cdf0e10cSrcweir             if ( rShell.IsDrawCreate() )
739cdf0e10cSrcweir             {
740cdf0e10cSrcweir                 rView.GetDrawFuncPtr()->BreakCreate();
741cdf0e10cSrcweir                 rView.AttrChangedNotify(&rShell);
742cdf0e10cSrcweir             }
743cdf0e10cSrcweir             else if ( rShell.HasSelection() || rView.IsDrawMode() )
744cdf0e10cSrcweir             {
745cdf0e10cSrcweir                 SdrView *pSdrView = rShell.GetDrawView();
746cdf0e10cSrcweir                 if(pSdrView && pSdrView->AreObjectsMarked() &&
747cdf0e10cSrcweir                     pSdrView->GetHdlList().GetFocusHdl())
748cdf0e10cSrcweir                 {
749cdf0e10cSrcweir                     ((SdrHdlList&)pSdrView->GetHdlList()).ResetFocusHdl();
750cdf0e10cSrcweir                 }
751cdf0e10cSrcweir                 else
752cdf0e10cSrcweir                 {
753cdf0e10cSrcweir                     rView.LeaveDrawCreate();
754cdf0e10cSrcweir                     Point aPt(LONG_MIN, LONG_MIN);
755cdf0e10cSrcweir                     //go out of the frame
756cdf0e10cSrcweir                     rShell.SelectObj(aPt, SW_LEAVE_FRAME);
757cdf0e10cSrcweir                     SfxBindings& rBind = rView.GetViewFrame()->GetBindings();
758cdf0e10cSrcweir                     rBind.Invalidate( SID_ATTR_SIZE );
759cdf0e10cSrcweir                     rShell.EnterStdMode();
760cdf0e10cSrcweir                     rView.AttrChangedNotify(&rShell);
761cdf0e10cSrcweir                 }
762cdf0e10cSrcweir             }
763cdf0e10cSrcweir         }
764cdf0e10cSrcweir         break;
765cdf0e10cSrcweir         default:; //prevent warning
766cdf0e10cSrcweir     }
767cdf0e10cSrcweir     return true;
768cdf0e10cSrcweir }
769cdf0e10cSrcweir /*-- 13.10.2003 15:20:09---------------------------------------------------
770cdf0e10cSrcweir     select the next draw text object that has a spelling error
771cdf0e10cSrcweir   -----------------------------------------------------------------------*/
FindNextDrawTextError_Impl(SwWrtShell & rSh)772cdf0e10cSrcweir bool SwSpellDialogChildWindow::FindNextDrawTextError_Impl(SwWrtShell& rSh)
773cdf0e10cSrcweir {
774cdf0e10cSrcweir     bool bNextDoc = false;
775cdf0e10cSrcweir     SdrView* pDrView = rSh.GetDrawView();
776cdf0e10cSrcweir     if(!pDrView)
777cdf0e10cSrcweir         return bNextDoc;
778cdf0e10cSrcweir     SwView& rView = rSh.GetView();
779cdf0e10cSrcweir     SwDoc* pDoc = rView.GetDocShell()->GetDoc();
780cdf0e10cSrcweir     const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
781cdf0e10cSrcweir     //start at the current draw object - if there is any selected
782cdf0e10cSrcweir     SdrTextObj* pCurrentTextObj = 0;
783cdf0e10cSrcweir     if ( rMarkList.GetMarkCount() == 1 )
784cdf0e10cSrcweir     {
785cdf0e10cSrcweir         SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
786cdf0e10cSrcweir         if( pObj && pObj->ISA(SdrTextObj) )
787cdf0e10cSrcweir             pCurrentTextObj = static_cast<SdrTextObj*>(pObj);
788cdf0e10cSrcweir     }
789cdf0e10cSrcweir     //at first fill the list of drawing objects
790cdf0e10cSrcweir     if(!m_pSpellState->m_bTextObjectsCollected )
791cdf0e10cSrcweir     {
792cdf0e10cSrcweir         m_pSpellState->m_bTextObjectsCollected = true;
793cdf0e10cSrcweir         std::list<SdrTextObj*> aTextObjs;
794cdf0e10cSrcweir         SwDrawContact::GetTextObjectsFromFmt( aTextObjs, pDoc );
795cdf0e10cSrcweir         if(pCurrentTextObj)
796cdf0e10cSrcweir         {
797cdf0e10cSrcweir             m_pSpellState->m_aTextObjects.remove(pCurrentTextObj);
798cdf0e10cSrcweir             m_pSpellState->m_aTextObjects.push_back(pCurrentTextObj);
799cdf0e10cSrcweir                                 }
800cdf0e10cSrcweir                             }
801cdf0e10cSrcweir     if(m_pSpellState->m_aTextObjects.size())
802cdf0e10cSrcweir     {
803cdf0e10cSrcweir         Reference< XSpellChecker1 >  xSpell( GetSpellChecker() );
804cdf0e10cSrcweir         while(!bNextDoc && m_pSpellState->m_aTextObjects.size())
805cdf0e10cSrcweir         {
806cdf0e10cSrcweir             std::list<SdrTextObj*>::iterator aStart = m_pSpellState->m_aTextObjects.begin();
807cdf0e10cSrcweir             SdrTextObj* pTextObj = *aStart;
808cdf0e10cSrcweir             if(m_pSpellState->m_pStartDrawing == pTextObj)
809cdf0e10cSrcweir                 m_pSpellState->m_bRestartDrawing = true;
810cdf0e10cSrcweir             m_pSpellState->m_aTextObjects.erase(aStart);
811cdf0e10cSrcweir             OutlinerParaObject* pParaObj = pTextObj->GetOutlinerParaObject();
812cdf0e10cSrcweir             if ( pParaObj )
813cdf0e10cSrcweir             {
814cdf0e10cSrcweir                 bool bHasSpellError = false;
815cdf0e10cSrcweir                 {
816cdf0e10cSrcweir                     SdrOutliner aTmpOutliner(pDoc->GetDrawModel()->
817cdf0e10cSrcweir                                              GetDrawOutliner().GetEmptyItemSet().GetPool(),
818cdf0e10cSrcweir                                                 OUTLINERMODE_TEXTOBJECT );
819cdf0e10cSrcweir                     aTmpOutliner.SetRefDevice( pDoc->getPrinter( false ) );
820cdf0e10cSrcweir                     MapMode aMapMode (MAP_TWIP);
821cdf0e10cSrcweir                     aTmpOutliner.SetRefMapMode(aMapMode);
822cdf0e10cSrcweir                     aTmpOutliner.SetPaperSize( pTextObj->GetLogicRect().GetSize() );
823cdf0e10cSrcweir                     aTmpOutliner.SetSpeller( xSpell );
824cdf0e10cSrcweir 
825cdf0e10cSrcweir                     OutlinerView* pOutlView = new OutlinerView( &aTmpOutliner, &(rView.GetEditWin()) );
826cdf0e10cSrcweir                     pOutlView->GetOutliner()->SetRefDevice( rSh.getIDocumentDeviceAccess()->getPrinter( false ) );
827cdf0e10cSrcweir                     aTmpOutliner.InsertView( pOutlView );
828cdf0e10cSrcweir                     Point aPt;
829cdf0e10cSrcweir                     Size aSize(1,1);
830cdf0e10cSrcweir                     Rectangle aRect( aPt, aSize );
831cdf0e10cSrcweir                     pOutlView->SetOutputArea( aRect );
832cdf0e10cSrcweir                     aTmpOutliner.SetText( *pParaObj );
833cdf0e10cSrcweir                     aTmpOutliner.ClearModifyFlag();
834cdf0e10cSrcweir                     bHasSpellError = EE_SPELL_OK != aTmpOutliner.HasSpellErrors();
835cdf0e10cSrcweir                     aTmpOutliner.RemoveView( pOutlView );
836cdf0e10cSrcweir                     delete pOutlView;
837cdf0e10cSrcweir                 }
838cdf0e10cSrcweir                 if(bHasSpellError)
839cdf0e10cSrcweir                 {
840cdf0e10cSrcweir                     //now the current one has to be deselected
841cdf0e10cSrcweir                     if(pCurrentTextObj)
842cdf0e10cSrcweir                         pDrView->SdrEndTextEdit( sal_True );
843cdf0e10cSrcweir                     //and the found one should be activated
844cdf0e10cSrcweir                     rSh.MakeVisible(pTextObj->GetLogicRect());
845cdf0e10cSrcweir                     Point aTmp( 0,0 );
846cdf0e10cSrcweir                     rSh.SelectObj( aTmp, 0, pTextObj );
847cdf0e10cSrcweir                     SdrPageView* pPV = pDrView->GetSdrPageView();
848cdf0e10cSrcweir                     rView.BeginTextEdit( pTextObj, pPV, &rView.GetEditWin(), sal_False, sal_True );
849cdf0e10cSrcweir                     rView.AttrChangedNotify(&rSh);
850cdf0e10cSrcweir                     bNextDoc = true;
851cdf0e10cSrcweir                 }
852cdf0e10cSrcweir             }
853cdf0e10cSrcweir         }
854cdf0e10cSrcweir     }
855cdf0e10cSrcweir     return bNextDoc;
856cdf0e10cSrcweir }
857cdf0e10cSrcweir 
858cdf0e10cSrcweir /*-- 13.10.2003 15:24:27---------------------------------------------------
859cdf0e10cSrcweir 
860cdf0e10cSrcweir   -----------------------------------------------------------------------*/
SpellDrawText_Impl(SwWrtShell & rSh,::svx::SpellPortions & rPortions)861cdf0e10cSrcweir bool SwSpellDialogChildWindow::SpellDrawText_Impl(SwWrtShell& rSh, ::svx::SpellPortions& rPortions)
862cdf0e10cSrcweir {
863cdf0e10cSrcweir     bool bRet = false;
864cdf0e10cSrcweir     SdrView*     pSdrView = rSh.GetDrawView();
865cdf0e10cSrcweir     SdrOutliner* pOutliner = pSdrView ? pSdrView->GetTextEditOutliner() : 0;
866cdf0e10cSrcweir     DBG_ASSERT(pOutliner, "No Outliner in SwSpellDialogChildWindow::SpellDrawText_Impl");
867cdf0e10cSrcweir     if(pOutliner)
868cdf0e10cSrcweir     {
869cdf0e10cSrcweir         bRet = pOutliner->SpellSentence(pSdrView->GetTextEditOutlinerView()->GetEditView(), rPortions, m_bIsGrammarCheckingOn);
870cdf0e10cSrcweir         //find out if the current selection is in the first spelled drawing object
871cdf0e10cSrcweir         //and behind the initial selection
872cdf0e10cSrcweir         if(bRet && m_pSpellState->m_bRestartDrawing)
873cdf0e10cSrcweir         {
874cdf0e10cSrcweir             OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
875cdf0e10cSrcweir             ESelection aCurrentSelection = pOLV->GetSelection();
876cdf0e10cSrcweir             if(m_pSpellState->m_aStartDrawingSelection.nEndPara < aCurrentSelection.nEndPara ||
877cdf0e10cSrcweir                (m_pSpellState->m_aStartDrawingSelection.nEndPara ==  aCurrentSelection.nEndPara &&
878cdf0e10cSrcweir                     m_pSpellState->m_aStartDrawingSelection.nEndPos <  aCurrentSelection.nEndPos))
879cdf0e10cSrcweir 			{
880cdf0e10cSrcweir                 bRet = false;
881cdf0e10cSrcweir 				rPortions.clear();
882cdf0e10cSrcweir 			}
883cdf0e10cSrcweir         }
884cdf0e10cSrcweir     }
885cdf0e10cSrcweir     return bRet;
886cdf0e10cSrcweir }
887cdf0e10cSrcweir /*-- 30.10.2003 14:54:59---------------------------------------------------
888cdf0e10cSrcweir 
889cdf0e10cSrcweir   -----------------------------------------------------------------------*/
LockFocusNotification(bool bLock)890cdf0e10cSrcweir void SwSpellDialogChildWindow::LockFocusNotification(bool bLock)
891cdf0e10cSrcweir {
892cdf0e10cSrcweir     DBG_ASSERT(m_pSpellState->m_bLockFocus != bLock, "invalid locking - no change of state");
893cdf0e10cSrcweir     m_pSpellState->m_bLockFocus = bLock;
894cdf0e10cSrcweir }
895cdf0e10cSrcweir 
896cdf0e10cSrcweir 
897