1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sd.hxx" 30 31 #include "SpellDialogChildWindow.hxx" 32 #include <svx/svxids.hrc> 33 #include <sfx2/app.hxx> 34 #include <sfx2/bindings.hxx> 35 #include <sfx2/dispatch.hxx> 36 37 namespace sd{ 38 39 SFX_IMPL_CHILDWINDOW(SpellDialogChildWindow, SID_SPELL_DIALOG) 40 } 41 42 #include "ViewShell.hxx" 43 #include "ViewShellBase.hxx" 44 #include "DrawViewShell.hxx" 45 #include "OutlineViewShell.hxx" 46 #include <Outliner.hxx> 47 #include "drawdoc.hxx" 48 49 50 namespace sd { 51 52 SpellDialogChildWindow::SpellDialogChildWindow ( 53 ::Window* _pParent, 54 sal_uInt16 nId, 55 SfxBindings* pBindings, 56 SfxChildWinInfo* pInfo) 57 : ::svx::SpellDialogChildWindow (_pParent, nId, pBindings, pInfo), 58 mpSdOutliner (NULL), 59 mbOwnOutliner (false) 60 { 61 ProvideOutliner(); 62 } 63 64 65 66 67 SpellDialogChildWindow::~SpellDialogChildWindow (void) 68 { 69 if (mpSdOutliner != NULL) 70 mpSdOutliner->EndSpelling(); 71 72 if (mbOwnOutliner) 73 delete mpSdOutliner; 74 } 75 76 77 78 79 80 81 82 83 SfxChildWinInfo SpellDialogChildWindow::GetInfo (void) const 84 { 85 return ::svx::SpellDialogChildWindow::GetInfo(); 86 } 87 88 89 90 91 void SpellDialogChildWindow::InvalidateSpellDialog (void) 92 { 93 ::svx::SpellDialogChildWindow::InvalidateSpellDialog(); 94 } 95 96 97 98 99 ::svx::SpellPortions SpellDialogChildWindow::GetNextWrongSentence( bool /*bRecheck*/ ) 100 { 101 ::svx::SpellPortions aResult; 102 103 if (mpSdOutliner != NULL) 104 { 105 ProvideOutliner(); 106 aResult = mpSdOutliner->GetNextSpellSentence(); 107 } 108 109 // Close the spell check dialog when there are no more sentences to 110 // check. 111 if (aResult.empty()) 112 { 113 SfxBoolItem aItem (SID_SPELL_DIALOG, sal_False); 114 GetBindings().GetDispatcher()->Execute( 115 SID_SPELL_DIALOG, 116 SFX_CALLMODE_ASYNCHRON, 117 &aItem, 118 0L); 119 } 120 121 return aResult; 122 } 123 124 125 126 127 void SpellDialogChildWindow::ApplyChangedSentence ( 128 const ::svx::SpellPortions& rChanged, bool bRecheck ) 129 { 130 if (mpSdOutliner != NULL) 131 { 132 OutlinerView* pOutlinerView = mpSdOutliner->GetView(0); 133 if (pOutlinerView != NULL) 134 mpSdOutliner->ApplyChangedSentence ( 135 pOutlinerView->GetEditView(), 136 rChanged, bRecheck); 137 } 138 } 139 140 141 142 143 void SpellDialogChildWindow::GetFocus (void) 144 { 145 // In order to detect a cursor movement we could compare the 146 // currently selected text shape with the one that was selected 147 // when LoseFocus() was called the last time. 148 // For the time being we instead rely on the DetectChange() method 149 // in the SdOutliner class. 150 } 151 152 153 154 155 void SpellDialogChildWindow::LoseFocus() 156 { 157 } 158 159 160 161 162 void SpellDialogChildWindow::ProvideOutliner (void) 163 { 164 ViewShellBase* pViewShellBase = PTR_CAST (ViewShellBase, SfxViewShell::Current()); 165 166 if (pViewShellBase != NULL) 167 { 168 ViewShell* pViewShell = pViewShellBase->GetMainViewShell().get(); 169 // If there already exists an outliner that has been created 170 // for another view shell then destroy it first. 171 if (mpSdOutliner != NULL) 172 if ((pViewShell->ISA(DrawViewShell) && ! mbOwnOutliner) 173 || (pViewShell->ISA(OutlineViewShell) && mbOwnOutliner)) 174 { 175 mpSdOutliner->EndSpelling(); 176 if (mbOwnOutliner) 177 delete mpSdOutliner; 178 mpSdOutliner = NULL; 179 } 180 181 // Now create/get an outliner if none is present. 182 if (mpSdOutliner == NULL) 183 { 184 if (pViewShell->ISA(DrawViewShell)) 185 { 186 // We need an outliner for the spell check so we have 187 // to create one. 188 mbOwnOutliner = true; 189 mpSdOutliner = new Outliner ( 190 pViewShell->GetDoc(), 191 OUTLINERMODE_TEXTOBJECT); 192 } 193 else if (pViewShell->ISA(OutlineViewShell)) 194 { 195 // An outline view is already visible. The SdOutliner 196 // will use it instead of creating its own. 197 mbOwnOutliner = false; 198 mpSdOutliner = pViewShell->GetDoc()->GetOutliner(); 199 } 200 201 // Initialize spelling. 202 if (mpSdOutliner != NULL) 203 { 204 mpSdOutliner->PrepareSpelling(); 205 mpSdOutliner->StartSpelling(); 206 } 207 } 208 } 209 } 210 211 212 213 } // end of namespace ::sd 214