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