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