bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / dlg / SpellDialogChildWindow.cxx
blobc87919346322e819dbe857e2a93a98bf5e9477e9
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 (rHint.GetId() != SfxHintId::ThisIsAnSdrHint)
114 return;
115 const SdrHint* pSdrHint = static_cast<const SdrHint*>(&rHint);
116 if (SdrHintKind::ModelCleared == pSdrHint->GetKind())
118 EndSpellingAndClearOutliner();
122 void SpellDialogChildWindow::ProvideOutliner()
124 ViewShellBase* pViewShellBase = dynamic_cast<ViewShellBase*>( SfxViewShell::Current() );
126 if (pViewShellBase == nullptr)
127 return;
129 ViewShell* pViewShell = pViewShellBase->GetMainViewShell().get();
130 // If there already exists an outliner that has been created
131 // for another view shell then destroy it first.
132 if (mpSdOutliner != nullptr)
133 if(( dynamic_cast< const DrawViewShell *>( pViewShell ) != nullptr && ! mbOwnOutliner)
134 || (dynamic_cast< const OutlineViewShell *>( pViewShell ) != nullptr && mbOwnOutliner))
136 EndSpellingAndClearOutliner();
139 // Now create/get an outliner if none is present.
140 if (mpSdOutliner != nullptr)
141 return;
143 if( dynamic_cast< const DrawViewShell *>( pViewShell ) != nullptr)
145 // We need an outliner for the spell check so we have
146 // to create one.
147 mbOwnOutliner = true;
148 SdDrawDocument *pDoc = pViewShell->GetDoc();
149 mpSdOutliner = new SdOutliner(pDoc, OutlinerMode::TextObject);
150 StartListening(*pDoc);
152 else if( dynamic_cast< const OutlineViewShell *>( pViewShell ) != nullptr)
154 // An outline view is already visible. The SdOutliner
155 // will use it instead of creating its own.
156 mbOwnOutliner = false;
157 SdDrawDocument *pDoc = pViewShell->GetDoc();
158 mpSdOutliner = pDoc->GetOutliner();
159 StartListening(*pDoc);
162 // Initialize spelling.
163 if (mpSdOutliner != nullptr)
165 mpSdOutliner->PrepareSpelling();
166 mpSdOutliner->StartSpelling();
170 } // end of namespace ::sd
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */