1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwSpellDialogChildWindow.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include <SwSpellDialogChildWindow.hxx>
34 #include <vcl/msgbox.hxx>
35 #include <svx/svxacorr.hxx>
36 #include <svx/acorrcfg.hxx>
37 #ifndef _SVX_SVXIDS_HRC
38 #include <svx/svxids.hrc>
40 #include <sfx2/app.hxx>
41 #include <sfx2/bindings.hxx>
42 #include <sfx2/dispatch.hxx>
43 #include <svx/unolingu.hxx>
45 #include <sfx2/printer.hxx>
46 #include <svx/svdoutl.hxx>
47 #include <svx/svdview.hxx>
48 #include <svx/svditer.hxx>
49 #include <svx/svdogrp.hxx>
50 #include <svtools/linguprops.hxx>
51 #include <svtools/lingucfg.hxx>
58 #include <dcontact.hxx>
61 #include <drawbase.hxx>
68 using namespace ::com::sun::star
;
69 using namespace ::com::sun::star::uno
;
70 using namespace ::com::sun::star::text
;
71 using namespace ::com::sun::star::linguistic2
;
72 using namespace ::com::sun::star::beans
;
74 SFX_IMPL_CHILDWINDOW(SwSpellDialogChildWindow
, FN_SPELL_GRAMMAR_DIALOG
)
77 #define SPELL_START_BODY 0 // body text area
78 #define SPELL_START_OTHER 1 // frame, footnote, header, footer
79 #define SPELL_START_DRAWTEXT 2 // started in a draw text object
84 bool m_bLockFocus
; //lock the focus notification while a modal dialog is active
87 //restart and progress information
88 USHORT m_SpellStartPosition
;
89 bool m_bBodySpelled
; //body already spelled
90 bool m_bOtherSpelled
; //frames, footnotes, headers and footers spelled
91 bool m_bStartedInOther
; //started the spelling insided of the _other_ area
92 bool m_bStartedInSelection
; // there was an initial text selection
93 SwPaM
* pOtherCursor
; // position where the spelling inside the _other_ area started
94 bool m_bDrawingsSpelled
; //all drawings spelled
95 Reference
<XTextRange
> m_xStartRange
; //text range that marks the start of spelling
96 const SdrObject
* m_pStartDrawing
; //draw text object spelling started in
97 ESelection m_aStartDrawingSelection
; //draw text start selection
98 bool m_bRestartDrawing
; // the first selected drawing object is found again
100 //lose/get focus information to decide if spelling can be continued
101 ShellModes m_eSelMode
;
102 const SwNode
* m_pPointNode
;
103 const SwNode
* m_pMarkNode
;
104 xub_StrLen m_nPointPos
;
105 xub_StrLen m_nMarkPos
;
106 const SdrOutliner
* m_pOutliner
;
107 ESelection m_aESelection
;
109 //iterating over draw text objects
110 std::vector
<SdrTextObj
*> m_aTextObjects
;
111 bool m_bTextObjectsCollected
;
114 m_bInitialCall(true),
117 m_SpellStartPosition(SPELL_START_BODY
),
118 m_bBodySpelled(false),
119 m_bOtherSpelled(false),
120 m_bStartedInOther(false),
121 m_bStartedInSelection(false),
123 m_bDrawingsSpelled(false),
125 m_bRestartDrawing(false),
127 m_eSelMode(SHELL_MODE_OBJECT
), //initially invalid
133 m_bTextObjectsCollected(false)
136 ~SpellState() {delete pOtherCursor
;}
138 // reset state in ::InvalidateSpellDialog
140 { m_bInitialCall
= true;
141 m_bBodySpelled
= m_bOtherSpelled
= m_bDrawingsSpelled
= false;
144 m_bRestartDrawing
= false;
145 m_bTextObjectsCollected
= false;
146 m_aTextObjects
.clear();
147 m_bStartedInOther
= false;
152 /*-- 30.10.2003 14:33:26---------------------------------------------------
154 -----------------------------------------------------------------------*/
155 void lcl_LeaveDrawText(SwWrtShell
& rSh
)
157 if(rSh
.GetDrawView())
159 rSh
.GetDrawView()->SdrEndTextEdit( TRUE
);
160 Point
aPt(LONG_MIN
, LONG_MIN
);
161 //go out of the frame
162 rSh
.SelectObj(aPt
, SW_LEAVE_FRAME
);
164 rSh
.GetView().AttrChangedNotify(&rSh
);
167 /*-- 09.09.2003 10:39:22---------------------------------------------------
169 -----------------------------------------------------------------------*/
170 SwSpellDialogChildWindow::SwSpellDialogChildWindow (
173 SfxBindings
* pBindings
,
174 SfxChildWinInfo
* pInfo
) :
175 svx::SpellDialogChildWindow (
176 _pParent
, nId
, pBindings
, pInfo
),
177 m_pSpellState(new SpellState
)
180 String
aPropName( String::CreateFromAscii(UPN_IS_GRAMMAR_INTERACTIVE
) );
181 SvtLinguConfig().GetProperty( aPropName
) >>= m_bIsGrammarCheckingOn
;
183 /*-- 09.09.2003 10:39:22---------------------------------------------------
185 -----------------------------------------------------------------------*/
186 SwSpellDialogChildWindow::~SwSpellDialogChildWindow ()
188 SwWrtShell
* pWrtShell
= GetWrtShell_Impl();
189 if(!m_pSpellState
->m_bInitialCall
&& pWrtShell
)
190 pWrtShell
->SpellEnd();
191 delete m_pSpellState
;
194 /*-- 09.09.2003 12:40:07---------------------------------------------------
196 -----------------------------------------------------------------------*/
197 SfxChildWinInfo
SwSpellDialogChildWindow::GetInfo (void) const
199 SfxChildWinInfo aInfo
= svx::SpellDialogChildWindow::GetInfo();
200 aInfo
.bVisible
= FALSE
;
204 /*-- 09.09.2003 10:39:40---------------------------------------------------
207 -----------------------------------------------------------------------*/
208 svx::SpellPortions
SwSpellDialogChildWindow::GetNextWrongSentence (void)
210 svx::SpellPortions aRet
;
211 SwWrtShell
* pWrtShell
= GetWrtShell_Impl();
214 ShellModes eSelMode
= pWrtShell
->GetView().GetShellMode();
215 bool bDrawText
= SHELL_MODE_DRAWTEXT
== eSelMode
;
217 SHELL_MODE_TABLE_TEXT
== eSelMode
||
218 SHELL_MODE_LIST_TEXT
== eSelMode
||
219 SHELL_MODE_TABLE_LIST_TEXT
== eSelMode
||
220 SHELL_MODE_TEXT
== eSelMode
;
221 //Writer text outside of the body
222 bool bOtherText
= false;
224 if( m_pSpellState
->m_bInitialCall
)
226 //if no text selection exists the cursor has to be set into the text
227 if(!bDrawText
&& !bNormalText
)
229 if(!MakeTextSelection_Impl(*pWrtShell
, eSelMode
))
233 // the selection type has to be checked again - both text types are possible
234 if(0 != (pWrtShell
->GetSelectionType()& nsSelectionType::SEL_DRW_TXT
))
236 bNormalText
= !bDrawText
;
241 //set cursor to the start of the sentence
242 if(!pWrtShell
->HasSelection())
243 pWrtShell
->GoStartSentence();
245 m_pSpellState
->m_bStartedInSelection
= true;
246 //determine if the selection is outside of the body text
247 bOtherText
= !(pWrtShell
->GetFrmType(0,sal_True
) & FRMTYPE_BODY
);
248 m_pSpellState
->m_SpellStartPosition
= bOtherText
? SPELL_START_OTHER
: SPELL_START_BODY
;
251 m_pSpellState
->pOtherCursor
= new SwPaM(*pWrtShell
->GetCrsr()->GetPoint());
252 m_pSpellState
->m_bStartedInOther
= true;
253 pWrtShell
->SpellStart( DOCPOS_OTHERSTART
, DOCPOS_OTHEREND
, DOCPOS_CURR
, FALSE
);
257 SwPaM
* pCrsr
= pWrtShell
->GetCrsr();
258 //mark the start position only if not at start of doc
259 if(!pWrtShell
->IsStartOfDoc())
261 m_pSpellState
->m_xStartRange
= SwXTextRange::CreateTextRangeFromPosition(
262 pWrtShell
->GetDoc(), *pCrsr
->Start(), pCrsr
->End());
264 pWrtShell
->SpellStart( DOCPOS_START
, DOCPOS_END
, DOCPOS_CURR
, FALSE
);
269 SdrView
* pSdrView
= pWrtShell
->GetDrawView();
270 m_pSpellState
->m_SpellStartPosition
= SPELL_START_DRAWTEXT
;
271 m_pSpellState
->m_pStartDrawing
= pSdrView
->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
272 OutlinerView
* pOLV
= pSdrView
->GetTextEditOutlinerView();
273 m_pSpellState
->m_aStartDrawingSelection
= pOLV
->GetSelection();
276 m_pSpellState
->m_bInitialCall
= false;
280 // spell inside of the current draw text
281 if(!SpellDrawText_Impl(*pWrtShell
, aRet
))
283 if(!FindNextDrawTextError_Impl(*pWrtShell
) || !SpellDrawText_Impl(*pWrtShell
, aRet
))
285 lcl_LeaveDrawText(*pWrtShell
);
286 //now the drawings have been spelled
287 m_pSpellState
->m_bDrawingsSpelled
= true;
288 //the spelling continues at the other content
289 //if there's any that has not been spelled yet
290 if(!m_pSpellState
->m_bOtherSpelled
&& pWrtShell
->HasOtherCnt())
292 pWrtShell
->SpellStart(DOCPOS_OTHERSTART
, DOCPOS_OTHEREND
, DOCPOS_OTHERSTART
, FALSE
);
293 if(!pWrtShell
->SpellSentence(aRet
, m_bIsGrammarCheckingOn
))
295 pWrtShell
->SpellEnd();
296 m_pSpellState
->m_bOtherSpelled
= true;
300 m_pSpellState
->m_bOtherSpelled
= true;
301 //if no result has been found try at the body text - completely
302 if(!m_pSpellState
->m_bBodySpelled
&& !aRet
.size())
304 pWrtShell
->SpellStart(DOCPOS_START
, DOCPOS_END
, DOCPOS_START
, FALSE
);
305 if(!pWrtShell
->SpellSentence(aRet
, m_bIsGrammarCheckingOn
))
307 m_pSpellState
->m_bBodySpelled
= true;
308 pWrtShell
->SpellEnd();
317 //spell inside of the Writer text
318 if(!pWrtShell
->SpellSentence(aRet
, m_bIsGrammarCheckingOn
))
320 //find out which text has been spelled body or other
321 bOtherText
= !(pWrtShell
->GetFrmType(0,sal_True
) & FRMTYPE_BODY
);
322 if(bOtherText
&& m_pSpellState
->m_bStartedInOther
&& m_pSpellState
->pOtherCursor
)
324 m_pSpellState
->m_bStartedInOther
= false;
325 pWrtShell
->SetSelection(*m_pSpellState
->pOtherCursor
);
326 pWrtShell
->SpellEnd();
327 delete m_pSpellState
->pOtherCursor
;
328 m_pSpellState
->pOtherCursor
= 0;
329 pWrtShell
->SpellStart(DOCPOS_OTHERSTART
, DOCPOS_CURR
, DOCPOS_OTHERSTART
, FALSE
);
330 pWrtShell
->SpellSentence(aRet
, m_bIsGrammarCheckingOn
);
335 pWrtShell
->SpellEnd();
338 m_pSpellState
->m_bOtherSpelled
= true;
339 //has the body been spelled?
340 if(!m_pSpellState
->m_bBodySpelled
)
342 pWrtShell
->SpellStart(DOCPOS_START
, DOCPOS_END
, DOCPOS_START
, FALSE
);
343 if(!pWrtShell
->SpellSentence(aRet
, m_bIsGrammarCheckingOn
))
345 m_pSpellState
->m_bBodySpelled
= true;
346 pWrtShell
->SpellEnd();
352 m_pSpellState
->m_bBodySpelled
= true;
353 if(!m_pSpellState
->m_bOtherSpelled
&& pWrtShell
->HasOtherCnt())
355 pWrtShell
->SpellStart(DOCPOS_OTHERSTART
, DOCPOS_OTHEREND
, DOCPOS_OTHERSTART
, FALSE
);
356 if(!pWrtShell
->SpellSentence(aRet
, m_bIsGrammarCheckingOn
))
358 pWrtShell
->SpellEnd();
359 m_pSpellState
->m_bOtherSpelled
= true;
363 m_pSpellState
->m_bOtherSpelled
= true;
367 //search for a draw text object that contains error and spell it
369 (m_pSpellState
->m_bDrawingsSpelled
||
370 !FindNextDrawTextError_Impl(*pWrtShell
) || !SpellDrawText_Impl(*pWrtShell
, aRet
)))
372 lcl_LeaveDrawText(*pWrtShell
);
373 m_pSpellState
->m_bDrawingsSpelled
= true;
377 // now only the rest of the body text can be spelled -
378 // if the spelling started inside of the body
380 bool bCloseMessage
= true;
381 if(!aRet
.size() && !m_pSpellState
->m_bStartedInSelection
)
383 DBG_ASSERT(m_pSpellState
->m_bDrawingsSpelled
&&
384 m_pSpellState
->m_bOtherSpelled
&& m_pSpellState
->m_bBodySpelled
,
385 "not all parts of the document are already spelled");
386 if(m_pSpellState
->m_xStartRange
.is())
388 LockFocusNotification( true );
389 USHORT nRet
= QueryBox( GetWindow(), SW_RES(RID_QB_SPELL_CONTINUE
)).Execute();
392 SwUnoInternalPaM
aPam(*pWrtShell
->GetDoc());
393 if(SwXTextRange::XTextRangeToSwPaM(aPam
, m_pSpellState
->m_xStartRange
))
395 pWrtShell
->SetSelection(aPam
);
396 pWrtShell
->SpellStart(DOCPOS_START
, DOCPOS_CURR
, DOCPOS_START
);
397 if(!pWrtShell
->SpellSentence(aRet
, m_bIsGrammarCheckingOn
))
398 pWrtShell
->SpellEnd();
400 m_pSpellState
->m_xStartRange
= 0;
401 LockFocusNotification( false );
402 //take care that the now valid selection is stored
406 bCloseMessage
= false; //no closing message if a wrap around has been denied
413 LockFocusNotification( true );
414 String
sInfo(SW_RES(STR_SPELLING_COMPLETED
));
416 Window
* pTemp
= GetWindow(); // temporary needed for g++ 3.3.5
417 InfoBox(pTemp
, sInfo
).Execute();
418 LockFocusNotification( false );
419 //take care that the now valid selection is stored
423 //close the spelling dialog
424 GetBindings().GetDispatcher()->Execute(FN_SPELL_GRAMMAR_DIALOG
, SFX_CALLMODE_ASYNCHRON
);
430 /*-- 09.09.2003 10:39:40---------------------------------------------------
432 -----------------------------------------------------------------------*/
433 void SwSpellDialogChildWindow::ApplyChangedSentence(const svx::SpellPortions
& rChanged
)
435 SwWrtShell
* pWrtShell
= GetWrtShell_Impl();
436 DBG_ASSERT(!m_pSpellState
->m_bInitialCall
, "ApplyChangedSentence in initial call or after resume");
437 if(pWrtShell
&& !m_pSpellState
->m_bInitialCall
)
439 ShellModes eSelMode
= pWrtShell
->GetView().GetShellMode();
440 bool bDrawText
= SHELL_MODE_DRAWTEXT
== eSelMode
;
442 SHELL_MODE_TABLE_TEXT
== eSelMode
||
443 SHELL_MODE_LIST_TEXT
== eSelMode
||
444 SHELL_MODE_TABLE_LIST_TEXT
== eSelMode
||
445 SHELL_MODE_TEXT
== eSelMode
;
447 pWrtShell
->ApplyChangedSentence(rChanged
, m_bIsGrammarCheckingOn
);
450 SdrView
* pDrView
= pWrtShell
->GetDrawView();
451 SdrOutliner
*pOutliner
= pDrView
->GetTextEditOutliner();
452 pOutliner
->ApplyChangedSentence(pDrView
->GetTextEditOutlinerView()->GetEditView(), rChanged
, m_bIsGrammarCheckingOn
);
456 /*-- 21.10.2003 09:33:57---------------------------------------------------
458 -----------------------------------------------------------------------*/
459 void SwSpellDialogChildWindow::AddAutoCorrection(
460 const String
& rOld
, const String
& rNew
, LanguageType eLanguage
)
462 SvxAutoCorrect
* pACorr
= SvxAutoCorrCfg::Get()->GetAutoCorrect();
463 pACorr
->PutText( rOld
, rNew
, eLanguage
);
465 /*-- 21.10.2003 09:33:59---------------------------------------------------
467 -----------------------------------------------------------------------*/
468 bool SwSpellDialogChildWindow::HasAutoCorrection()
472 /*-- 16.06.2008 11:59:17---------------------------------------------------
474 -----------------------------------------------------------------------*/
475 bool SwSpellDialogChildWindow::HasGrammarChecking()
477 return SvtLinguConfig().HasGrammarChecker();
479 /*-- 18.06.2008 12:27:11---------------------------------------------------
481 -----------------------------------------------------------------------*/
482 bool SwSpellDialogChildWindow::IsGrammarChecking()
484 return m_bIsGrammarCheckingOn
;
486 /*-- 18.06.2008 12:27:11---------------------------------------------------
488 -----------------------------------------------------------------------*/
489 void SwSpellDialogChildWindow::SetGrammarChecking(bool bOn
)
493 m_bIsGrammarCheckingOn
= bOn
;
494 String
aPropName( C2S(UPN_IS_GRAMMAR_INTERACTIVE
) );
495 SvtLinguConfig().SetProperty( aPropName
, aVal
);
496 // set current spell position to the start of the current sentence to
497 // continue with this sentence after grammar checking state has been changed
498 SwWrtShell
* pWrtShell
= GetWrtShell_Impl();
501 ShellModes eSelMode
= pWrtShell
->GetView().GetShellMode();
502 bool bDrawText
= SHELL_MODE_DRAWTEXT
== eSelMode
;
504 SHELL_MODE_TABLE_TEXT
== eSelMode
||
505 SHELL_MODE_LIST_TEXT
== eSelMode
||
506 SHELL_MODE_TABLE_LIST_TEXT
== eSelMode
||
507 SHELL_MODE_TEXT
== eSelMode
;
509 pWrtShell
->PutSpellingToSentenceStart();
512 SdrView
* pSdrView
= pWrtShell
->GetDrawView();
513 SdrOutliner
* pOutliner
= pSdrView
? pSdrView
->GetTextEditOutliner() : 0;
514 DBG_ASSERT(pOutliner
, "No Outliner in SwSpellDialogChildWindow::SetGrammarChecking");
517 pOutliner
->PutSpellingToSentenceStart( pSdrView
->GetTextEditOutlinerView()->GetEditView() );
522 /*-- 28.10.2003 08:41:09---------------------------------------------------
524 -----------------------------------------------------------------------*/
525 void SwSpellDialogChildWindow::GetFocus()
527 if(m_pSpellState
->m_bLockFocus
)
529 bool bInvalidate
= false;
530 SwWrtShell
* pWrtShell
= GetWrtShell_Impl();
531 if(pWrtShell
&& !m_pSpellState
->m_bInitialCall
)
533 ShellModes eSelMode
= pWrtShell
->GetView().GetShellMode();
534 if(eSelMode
!= m_pSpellState
->m_eSelMode
)
536 //prevent initial invalidation
537 if(m_pSpellState
->m_bLostFocus
)
542 switch(m_pSpellState
->m_eSelMode
)
544 case SHELL_MODE_TEXT
:
545 case SHELL_MODE_LIST_TEXT
:
546 case SHELL_MODE_TABLE_TEXT
:
547 case SHELL_MODE_TABLE_LIST_TEXT
:
549 SwPaM
* pCursor
= pWrtShell
->GetCrsr();
550 if(m_pSpellState
->m_pPointNode
!= pCursor
->GetNode(TRUE
) ||
551 m_pSpellState
->m_pMarkNode
!= pCursor
->GetNode(FALSE
)||
552 m_pSpellState
->m_nPointPos
!= pCursor
->GetPoint()->nContent
.GetIndex()||
553 m_pSpellState
->m_nMarkPos
!= pCursor
->GetMark()->nContent
.GetIndex())
557 case SHELL_MODE_DRAWTEXT
:
559 SdrView
* pSdrView
= pWrtShell
->GetDrawView();
560 SdrOutliner
* pOutliner
= pSdrView
? pSdrView
->GetTextEditOutliner() : 0;
561 if(!pOutliner
|| m_pSpellState
->m_pOutliner
!= pOutliner
)
565 OutlinerView
* pOLV
= pSdrView
->GetTextEditOutlinerView();
566 DBG_ASSERT(pOLV
, "no OutlinerView in SwSpellDialogChildWindow::GetFocus()");
567 if(!pOLV
|| !m_pSpellState
->m_aESelection
.IsEqual(pOLV
->GetSelection()))
572 default: bInvalidate
= true;
581 InvalidateSpellDialog();
583 /*-- 28.10.2003 08:41:09---------------------------------------------------
585 -----------------------------------------------------------------------*/
586 void SwSpellDialogChildWindow::LoseFocus()
588 //prevent initial invalidation
589 m_pSpellState
->m_bLostFocus
= true;
590 if(m_pSpellState
->m_bLockFocus
)
592 SwWrtShell
* pWrtShell
= GetWrtShell_Impl();
595 m_pSpellState
->m_eSelMode
= pWrtShell
->GetView().GetShellMode();
596 m_pSpellState
->m_pPointNode
= m_pSpellState
->m_pMarkNode
= 0;
597 m_pSpellState
->m_nPointPos
= m_pSpellState
->m_nMarkPos
= 0;
598 m_pSpellState
->m_pOutliner
= 0;
600 switch(m_pSpellState
->m_eSelMode
)
602 case SHELL_MODE_TEXT
:
603 case SHELL_MODE_LIST_TEXT
:
604 case SHELL_MODE_TABLE_TEXT
:
605 case SHELL_MODE_TABLE_LIST_TEXT
:
607 //store a node pointer and a pam-position to be able to check on next GetFocus();
608 SwPaM
* pCursor
= pWrtShell
->GetCrsr();
609 m_pSpellState
->m_pPointNode
= pCursor
->GetNode(TRUE
);
610 m_pSpellState
->m_pMarkNode
= pCursor
->GetNode(FALSE
);
611 m_pSpellState
->m_nPointPos
= pCursor
->GetPoint()->nContent
.GetIndex();
612 m_pSpellState
->m_nMarkPos
= pCursor
->GetMark()->nContent
.GetIndex();
616 case SHELL_MODE_DRAWTEXT
:
618 SdrView
* pSdrView
= pWrtShell
->GetDrawView();
619 SdrOutliner
* pOutliner
= pSdrView
->GetTextEditOutliner();
620 m_pSpellState
->m_pOutliner
= pOutliner
;
621 OutlinerView
* pOLV
= pSdrView
->GetTextEditOutlinerView();
622 DBG_ASSERT(pOutliner
&& pOLV
, "no Outliner/OutlinerView in SwSpellDialogChildWindow::LoseFocus()");
625 m_pSpellState
->m_aESelection
= pOLV
->GetSelection();
629 default:;//prevent warning
633 m_pSpellState
->m_eSelMode
= SHELL_MODE_OBJECT
;
635 /*-- 18.09.2003 12:50:18---------------------------------------------------
637 -----------------------------------------------------------------------*/
638 void SwSpellDialogChildWindow::InvalidateSpellDialog()
640 SwWrtShell
* pWrtShell
= GetWrtShell_Impl();
641 if(!m_pSpellState
->m_bInitialCall
&& pWrtShell
)
642 pWrtShell
->SpellEnd(0, false);
643 m_pSpellState
->Reset();
644 svx::SpellDialogChildWindow::InvalidateSpellDialog();
647 /*-- 18.09.2003 12:54:59---------------------------------------------------
649 -----------------------------------------------------------------------*/
650 SwWrtShell
* SwSpellDialogChildWindow::GetWrtShell_Impl()
652 SfxDispatcher
* pDispatch
= GetBindings().GetDispatcher();
656 USHORT nShellIdx
= 0;
658 while(0 != (pShell
= pDispatch
->GetShell(nShellIdx
++)))
659 if(pShell
->ISA(SwView
))
661 pView
= static_cast<SwView
* >(pShell
);
665 return pView
? pView
->GetWrtShellPtr(): 0;
668 /*-- 13.10.2003 15:19:04---------------------------------------------------
669 set the cursor into the body text - necessary if any object is selected
670 on start of the spelling dialog
671 -----------------------------------------------------------------------*/
672 bool SwSpellDialogChildWindow::MakeTextSelection_Impl(SwWrtShell
& rShell
, ShellModes eSelMode
)
674 SwView
& rView
= rShell
.GetView();
677 case SHELL_MODE_TEXT
:
678 case SHELL_MODE_LIST_TEXT
:
679 case SHELL_MODE_TABLE_TEXT
:
680 case SHELL_MODE_TABLE_LIST_TEXT
:
681 case SHELL_MODE_DRAWTEXT
:
682 DBG_ERROR("text already active in SwSpellDialogChildWindow::MakeTextSelection_Impl()");
685 case SHELL_MODE_FRAME
:
687 rShell
.UnSelectFrm();
688 rShell
.LeaveSelFrmMode();
689 rView
.AttrChangedNotify(&rShell
);
693 case SHELL_MODE_DRAW
:
694 case SHELL_MODE_DRAW_CTRL
:
695 case SHELL_MODE_DRAW_FORM
:
696 case SHELL_MODE_BEZIER
:
697 if(FindNextDrawTextError_Impl(rShell
))
699 rView
.AttrChangedNotify(&rShell
);
702 //otherwise no break to deselect the object
703 case SHELL_MODE_GRAPHIC
:
704 case SHELL_MODE_OBJECT
:
706 if ( rShell
.IsDrawCreate() )
708 rView
.GetDrawFuncPtr()->BreakCreate();
709 rView
.AttrChangedNotify(&rShell
);
711 else if ( rShell
.HasSelection() || rView
.IsDrawMode() )
713 SdrView
*pSdrView
= rShell
.GetDrawView();
714 if(pSdrView
&& pSdrView
->AreObjectsMarked() &&
715 pSdrView
->GetHdlList().GetFocusHdl())
717 ((SdrHdlList
&)pSdrView
->GetHdlList()).ResetFocusHdl();
721 rView
.LeaveDrawCreate();
722 Point
aPt(LONG_MIN
, LONG_MIN
);
723 //go out of the frame
724 rShell
.SelectObj(aPt
, SW_LEAVE_FRAME
);
725 SfxBindings
& rBind
= rView
.GetViewFrame()->GetBindings();
726 rBind
.Invalidate( SID_ATTR_SIZE
);
727 rShell
.EnterStdMode();
728 rView
.AttrChangedNotify(&rShell
);
733 default:; //prevent warning
737 /*-- 13.10.2003 15:20:09---------------------------------------------------
738 select the next draw text object that has a spelling error
739 -----------------------------------------------------------------------*/
740 bool SwSpellDialogChildWindow::FindNextDrawTextError_Impl(SwWrtShell
& rSh
)
742 bool bNextDoc
= false;
743 SdrView
* pDrView
= rSh
.GetDrawView();
746 SwView
& rView
= rSh
.GetView();
747 SwDoc
* pDoc
= rView
.GetDocShell()->GetDoc();
748 const SdrMarkList
& rMarkList
= pDrView
->GetMarkedObjectList();
749 //start at the current draw object - if there is any selected
750 SdrTextObj
* pCurrentTextObj
= 0;
751 if ( rMarkList
.GetMarkCount() == 1 )
753 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
754 if( pObj
&& pObj
->ISA(SdrTextObj
) )
755 pCurrentTextObj
= static_cast<SdrTextObj
*>(pObj
);
757 //at first fill the vector of drawing objects
758 if(!m_pSpellState
->m_bTextObjectsCollected
)
760 m_pSpellState
->m_bTextObjectsCollected
= true;
762 //iterate in the 'normal' array of objects
763 while( n
< pDoc
->GetSpzFrmFmts()->Count() )
765 SwFrmFmt
* pFly
= (*pDoc
->GetSpzFrmFmts())[ n
];
766 if( pFly
->IsA( TYPE(SwDrawFrmFmt
) ) )
768 SwClientIter
aIter( (SwFmt
&) *pFly
);
769 if( aIter
.First( TYPE(SwDrawContact
) ) )
771 SdrObject
* pSdrO
= ((SwDrawContact
*)aIter())->GetMaster();
774 if ( pSdrO
->IsA( TYPE(SdrObjGroup
) ) )
776 SdrObjListIter
aListIter( *pSdrO
, IM_DEEPNOGROUPS
);
777 //iterate inside of a grouped object
778 while( aListIter
.IsMore() )
780 SdrObject
* pSdrOElement
= aListIter
.Next();
781 if( pSdrOElement
&& pSdrOElement
->IsA( TYPE(SdrTextObj
) ) &&
782 static_cast<SdrTextObj
*>( pSdrOElement
)->HasText() &&
783 pCurrentTextObj
!= pSdrOElement
)
785 m_pSpellState
->m_aTextObjects
.push_back((SdrTextObj
*) pSdrOElement
);
789 else if( pSdrO
->IsA( TYPE(SdrTextObj
) ) &&
790 static_cast<SdrTextObj
*>( pSdrO
)->HasText() &&
791 pCurrentTextObj
!= pSdrO
)
793 m_pSpellState
->m_aTextObjects
.push_back((SdrTextObj
*) pSdrO
);
801 m_pSpellState
->m_aTextObjects
.push_back(pCurrentTextObj
);
803 if(m_pSpellState
->m_aTextObjects
.size())
805 Reference
< XSpellChecker1
> xSpell( GetSpellChecker() );
806 while(!bNextDoc
&& m_pSpellState
->m_aTextObjects
.size())
808 std::vector
<SdrTextObj
*>::iterator aStart
= m_pSpellState
->m_aTextObjects
.begin();
809 SdrTextObj
* pTextObj
= *aStart
;
810 if(m_pSpellState
->m_pStartDrawing
== pTextObj
)
811 m_pSpellState
->m_bRestartDrawing
= true;
812 m_pSpellState
->m_aTextObjects
.erase(aStart
);
813 OutlinerParaObject
* pParaObj
= pTextObj
->GetOutlinerParaObject();
816 bool bHasSpellError
= false;
818 SdrOutliner
aTmpOutliner(pDoc
->GetDrawModel()->
819 GetDrawOutliner().GetEmptyItemSet().GetPool(),
820 OUTLINERMODE_TEXTOBJECT
);
821 aTmpOutliner
.SetRefDevice( pDoc
->getPrinter( false ) );
822 MapMode
aMapMode (MAP_TWIP
);
823 aTmpOutliner
.SetRefMapMode(aMapMode
);
824 aTmpOutliner
.SetPaperSize( pTextObj
->GetLogicRect().GetSize() );
825 aTmpOutliner
.SetSpeller( xSpell
);
827 OutlinerView
* pOutlView
= new OutlinerView( &aTmpOutliner
, &(rView
.GetEditWin()) );
828 pOutlView
->GetOutliner()->SetRefDevice( rSh
.getIDocumentDeviceAccess()->getPrinter( false ) );
829 aTmpOutliner
.InsertView( pOutlView
);
832 Rectangle
aRect( aPt
, aSize
);
833 pOutlView
->SetOutputArea( aRect
);
834 aTmpOutliner
.SetText( *pParaObj
);
835 aTmpOutliner
.ClearModifyFlag();
836 bHasSpellError
= EE_SPELL_OK
!= aTmpOutliner
.HasSpellErrors();
837 aTmpOutliner
.RemoveView( pOutlView
);
842 //now the current one has to be deselected
844 pDrView
->SdrEndTextEdit( TRUE
);
845 //and the found one should be activated
846 rSh
.MakeVisible(pTextObj
->GetLogicRect());
848 rSh
.SelectObj( aTmp
, 0, pTextObj
);
849 SdrPageView
* pPV
= pDrView
->GetSdrPageView();
850 rView
.BeginTextEdit( pTextObj
, pPV
, &rView
.GetEditWin(), FALSE
);
851 rView
.AttrChangedNotify(&rSh
);
860 /*-- 13.10.2003 15:24:27---------------------------------------------------
862 -----------------------------------------------------------------------*/
863 bool SwSpellDialogChildWindow::SpellDrawText_Impl(SwWrtShell
& rSh
, ::svx::SpellPortions
& rPortions
)
866 SdrView
* pSdrView
= rSh
.GetDrawView();
867 SdrOutliner
* pOutliner
= pSdrView
? pSdrView
->GetTextEditOutliner() : 0;
868 DBG_ASSERT(pOutliner
, "No Outliner in SwSpellDialogChildWindow::SpellDrawText_Impl");
871 bRet
= pOutliner
->SpellSentence(pSdrView
->GetTextEditOutlinerView()->GetEditView(), rPortions
, m_bIsGrammarCheckingOn
);
872 //find out if the current selection is in the first spelled drawing object
873 //and behind the initial selection
874 if(bRet
&& m_pSpellState
->m_bRestartDrawing
)
876 OutlinerView
* pOLV
= pSdrView
->GetTextEditOutlinerView();
877 ESelection aCurrentSelection
= pOLV
->GetSelection();
878 if(m_pSpellState
->m_aStartDrawingSelection
.nEndPara
< aCurrentSelection
.nEndPara
||
879 (m_pSpellState
->m_aStartDrawingSelection
.nEndPara
== aCurrentSelection
.nEndPara
&&
880 m_pSpellState
->m_aStartDrawingSelection
.nEndPos
< aCurrentSelection
.nEndPos
))
889 /*-- 30.10.2003 14:54:59---------------------------------------------------
891 -----------------------------------------------------------------------*/
892 void SwSpellDialogChildWindow::LockFocusNotification(bool bLock
)
894 DBG_ASSERT(m_pSpellState
->m_bLockFocus
!= bLock
, "invalid locking - no change of state");
895 m_pSpellState
->m_bLockFocus
= bLock
;