1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
32 SFX_IMPL_CHILDWINDOW_WITHID(SpellDialogChildWindow
, SID_SPELL_DIALOG
)
34 SpellDialogChildWindow::SpellDialogChildWindow (
35 vcl::Window
* _pParent
,
37 SfxBindings
* pBindings
,
38 SAL_UNUSED_PARAMETER SfxChildWinInfo
* /*pInfo*/)
39 : svx::SpellDialogChildWindow (_pParent
, nId
, pBindings
),
40 mpSdOutliner (nullptr),
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)
68 aResult
= mpSdOutliner
->GetNextSpellSentence();
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(),
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()
103 EndListening(*mpSdOutliner
->GetDoc());
104 mpSdOutliner
->EndSpelling();
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
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: */