LibreOffice Module sd (master) 1
SpellDialogChildWindow.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <SpellDialogChildWindow.hxx>
21#include <svx/svxids.hrc>
22
23#include <ViewShell.hxx>
24#include <ViewShellBase.hxx>
25#include <DrawViewShell.hxx>
26#include <OutlineViewShell.hxx>
27#include <Outliner.hxx>
28#include <drawdoc.hxx>
29
30namespace sd {
31
32SFX_IMPL_CHILDWINDOW_WITHID(SpellDialogChildWindow, SID_SPELL_DIALOG)
33
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)
42{
43 ProvideOutliner();
44}
45
46SpellDialogChildWindow::~SpellDialogChildWindow()
47{
48 EndSpellingAndClearOutliner();
49}
50
51SfxChildWinInfo SpellDialogChildWindow::GetInfo() const
52{
53 return svx::SpellDialogChildWindow::GetInfo();
54}
55
56void SpellDialogChildWindow::InvalidateSpellDialog()
57{
59}
60
61svx::SpellPortions SpellDialogChildWindow::GetNextWrongSentence( bool /*bRecheck*/ )
62{
63 svx::SpellPortions aResult;
64
65 if (mpSdOutliner != nullptr)
66 {
67 ProvideOutliner();
68 aResult = mpSdOutliner->GetNextSpellSentence();
69 }
70 return aResult;
71}
72
73void SpellDialogChildWindow::ApplyChangedSentence (
74 const svx::SpellPortions& rChanged, bool bRecheck )
75{
76 if (mpSdOutliner != nullptr)
77 {
78 OutlinerView* pOutlinerView = mpSdOutliner->GetView(0);
79 if (pOutlinerView != nullptr)
80 mpSdOutliner->ApplyChangedSentence (
81 pOutlinerView->GetEditView(),
82 rChanged, bRecheck);
83 }
84}
85
86void SpellDialogChildWindow::GetFocus()
87{
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.
93}
94
95void SpellDialogChildWindow::LoseFocus()
96{
97}
98
99void SpellDialogChildWindow::EndSpellingAndClearOutliner()
100{
101 if (!mpSdOutliner)
102 return;
103 EndListening(*mpSdOutliner->GetDoc());
104 mpSdOutliner->EndSpelling();
105 if (mbOwnOutliner)
106 delete mpSdOutliner;
107 mpSdOutliner = nullptr;
108 mbOwnOutliner = false;
109}
110
111void SpellDialogChildWindow::Notify(SfxBroadcaster&, const SfxHint& rHint)
112{
113 if (rHint.GetId() != SfxHintId::ThisIsAnSdrHint)
114 return;
115 const SdrHint* pSdrHint = static_cast<const SdrHint*>(&rHint);
116 if (SdrHintKind::ModelCleared == pSdrHint->GetKind())
117 {
118 EndSpellingAndClearOutliner();
119 }
120}
121
122void SpellDialogChildWindow::ProvideOutliner()
123{
124 ViewShellBase* pViewShellBase = dynamic_cast<ViewShellBase*>( SfxViewShell::Current() );
125
126 if (pViewShellBase == nullptr)
127 return;
128
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))
135 {
136 EndSpellingAndClearOutliner();
137 }
138
139 // Now create/get an outliner if none is present.
140 if (mpSdOutliner != nullptr)
141 return;
142
143 if( dynamic_cast< const DrawViewShell *>( pViewShell ) != nullptr)
144 {
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);
151 }
152 else if( dynamic_cast< const OutlineViewShell *>( pViewShell ) != nullptr)
153 {
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);
160 }
161
162 // Initialize spelling.
163 if (mpSdOutliner != nullptr)
164 {
165 mpSdOutliner->PrepareSpelling();
166 mpSdOutliner->StartSpelling();
167 }
168}
169
170} // end of namespace ::sd
171
172/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
EditView & GetEditView() const
SAL_DLLPRIVATE SdOutliner * GetOutliner(bool bCreateOutliner=true)
Definition: drawdoc.cxx:912
The main purpose of this class is searching and replacing as well as spelling of impress documents.
Definition: Outliner.hxx:123
SdrHintKind GetKind() const
SfxHintId GetId() const
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
Base class of the stacked shells that provide graphical views to Draw and Impress documents and editi...
Show a textual overview of the text contents of all slides.
SpellDialogChildWindow(vcl::Window *pParent, sal_uInt16 nId, SfxBindings *pBindings, SfxChildWinInfo *pInfo)
SfxViewShell descendant that the stacked Draw/Impress shells are based on.
std::shared_ptr< ViewShell > GetMainViewShell() const
Return the main view shell stacked on the called ViewShellBase object.
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
SdDrawDocument * GetDoc() const
Definition: viewshel.cxx:1412
SFX_IMPL_CHILDWINDOW_WITHID(SearchResultsDlgWrapper, SID_SEARCH_RESULTS_DIALOG)
std::vector< SpellPortion > SpellPortions
sal_Int16 nId