Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / dlg / SpellDialogChildWindow.cxx
blob15c89cc01fbe1306a4c8f2c0dbba40d4f2c86236
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <SpellDialogChildWindow.hxx>
21 #include <svx/svxids.hrc>
23 #include <ViewShell.hxx>
24 #include <ViewShellBase.hxx>
25 #include <DrawViewShell.hxx>
26 #include <OutlineViewShell.hxx>
27 #include <Outliner.hxx>
28 #include <drawdoc.hxx>
30 namespace sd {
32 SFX_IMPL_CHILDWINDOW_WITHID(SpellDialogChildWindow, SID_SPELL_DIALOG)
34 SpellDialogChildWindow::SpellDialogChildWindow (
35 vcl::Window* _pParent,
36 sal_uInt16 nId,
37 SfxBindings* pBindings,
38 SAL_UNUSED_PARAMETER SfxChildWinInfo* /*pInfo*/)
39 : svx::SpellDialogChildWindow (_pParent, nId, pBindings),
40 mpSdOutliner (nullptr),
41 mbOwnOutliner (false)
43 ProvideOutliner();
46 SpellDialogChildWindow::~SpellDialogChildWindow()
48 EndSpellingAndClearOutliner();
51 SfxChildWinInfo SpellDialogChildWindow::GetInfo() const
53 return svx::SpellDialogChildWindow::GetInfo();
56 void SpellDialogChildWindow::InvalidateSpellDialog()
58 svx::SpellDialogChildWindow::InvalidateSpellDialog();
61 svx::SpellPortions SpellDialogChildWindow::GetNextWrongSentence( bool /*bRecheck*/ )
63 svx::SpellPortions aResult;
65 if (mpSdOutliner != nullptr)
67 ProvideOutliner();
68 aResult = mpSdOutliner->GetNextSpellSentence();
70 return aResult;
73 void SpellDialogChildWindow::ApplyChangedSentence (
74 const svx::SpellPortions& rChanged, bool bRecheck )
76 if (mpSdOutliner != nullptr)
78 OutlinerView* pOutlinerView = mpSdOutliner->GetView(0);
79 if (pOutlinerView != nullptr)
80 mpSdOutliner->ApplyChangedSentence (
81 pOutlinerView->GetEditView(),
82 rChanged, bRecheck);
86 void SpellDialogChildWindow::GetFocus()
88 // In order to detect a cursor movement we could compare the
89 // currently selected text shape with the one that was selected
90 // when LoseFocus() was called the last time.
91 // For the time being we instead rely on the DetectChange() method
92 // in the SdOutliner class.
95 void SpellDialogChildWindow::LoseFocus()
99 void SpellDialogChildWindow::EndSpellingAndClearOutliner()
101 if (!mpSdOutliner)
102 return;
103 EndListening(*mpSdOutliner->GetDoc());
104 mpSdOutliner->EndSpelling();
105 if (mbOwnOutliner)
106 delete mpSdOutliner;
107 mpSdOutliner = nullptr;
108 mbOwnOutliner = false;
111 void SpellDialogChildWindow::Notify(SfxBroadcaster&, const SfxHint& rHint)
113 if (const SdrHint* pSdrHint = dynamic_cast<const SdrHint*>(&rHint))
115 if (SdrHintKind::ModelCleared == pSdrHint->GetKind())
117 EndSpellingAndClearOutliner();
122 void SpellDialogChildWindow::ProvideOutliner()
124 ViewShellBase* pViewShellBase = dynamic_cast<ViewShellBase*>( SfxViewShell::Current() );
126 if (pViewShellBase != nullptr)
128 ViewShell* pViewShell = pViewShellBase->GetMainViewShell().get();
129 // If there already exists an outliner that has been created
130 // for another view shell then destroy it first.
131 if (mpSdOutliner != nullptr)
132 if(( dynamic_cast< const DrawViewShell *>( pViewShell ) != nullptr && ! mbOwnOutliner)
133 || (dynamic_cast< const OutlineViewShell *>( pViewShell ) != nullptr && mbOwnOutliner))
135 EndSpellingAndClearOutliner();
138 // Now create/get an outliner if none is present.
139 if (mpSdOutliner == nullptr)
141 if( dynamic_cast< const DrawViewShell *>( pViewShell ) != nullptr)
143 // We need an outliner for the spell check so we have
144 // to create one.
145 mbOwnOutliner = true;
146 SdDrawDocument *pDoc = pViewShell->GetDoc();
147 mpSdOutliner = new SdOutliner(pDoc, OutlinerMode::TextObject);
148 StartListening(*pDoc);
150 else if( dynamic_cast< const OutlineViewShell *>( pViewShell ) != nullptr)
152 // An outline view is already visible. The SdOutliner
153 // will use it instead of creating its own.
154 mbOwnOutliner = false;
155 SdDrawDocument *pDoc = pViewShell->GetDoc();
156 mpSdOutliner = pDoc->GetOutliner();
157 StartListening(*pDoc);
160 // Initialize spelling.
161 if (mpSdOutliner != nullptr)
163 mpSdOutliner->PrepareSpelling();
164 mpSdOutliner->StartSpelling();
170 } // end of namespace ::sd
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */