/src/libreoffice/sd/source/ui/dlg/SpellDialogChildWindow.cxx
Line | Count | Source |
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 | | |
30 | | namespace sd { |
31 | | |
32 | | SFX_IMPL_CHILDWINDOW_WITHID(SpellDialogChildWindow, SID_SPELL_DIALOG) |
33 | | |
34 | | SpellDialogChildWindow::SpellDialogChildWindow(vcl::Window* _pParent, sal_uInt16 nId, |
35 | | SfxBindings& rBindings, |
36 | | SAL_UNUSED_PARAMETER SfxChildWinInfo& /*rInfo*/) |
37 | 0 | : svx::SpellDialogChildWindow(_pParent, nId, &rBindings) |
38 | 0 | , mpSdOutliner(nullptr) |
39 | 0 | , mbOwnOutliner(false) |
40 | 0 | { |
41 | 0 | ProvideOutliner(); |
42 | 0 | } |
43 | | |
44 | | SpellDialogChildWindow::~SpellDialogChildWindow() |
45 | 0 | { |
46 | 0 | EndSpellingAndClearOutliner(); |
47 | 0 | } |
48 | | |
49 | | SfxChildWinInfo SpellDialogChildWindow::GetInfo() const |
50 | 0 | { |
51 | | // tdf#117020: visible gets written to UserData |
52 | | // and a value of true means it automatically opens on startup |
53 | 0 | SfxChildWinInfo aInfo = svx::SpellDialogChildWindow::GetInfo(); |
54 | 0 | aInfo.bVisible = false; |
55 | 0 | return aInfo; |
56 | 0 | } |
57 | | |
58 | | void SpellDialogChildWindow::InvalidateSpellDialog() |
59 | 0 | { |
60 | 0 | svx::SpellDialogChildWindow::InvalidateSpellDialog(); |
61 | 0 | } |
62 | | |
63 | | svx::SpellPortions SpellDialogChildWindow::GetNextWrongSentence( bool /*bRecheck*/ ) |
64 | 0 | { |
65 | 0 | svx::SpellPortions aResult; |
66 | |
|
67 | 0 | if (mpSdOutliner != nullptr) |
68 | 0 | { |
69 | 0 | ProvideOutliner(); |
70 | 0 | aResult = mpSdOutliner->GetNextSpellSentence(); |
71 | 0 | } |
72 | 0 | return aResult; |
73 | 0 | } |
74 | | |
75 | | void SpellDialogChildWindow::ApplyChangedSentence ( |
76 | | const svx::SpellPortions& rChanged, bool bRecheck ) |
77 | 0 | { |
78 | 0 | if (mpSdOutliner != nullptr) |
79 | 0 | { |
80 | 0 | OutlinerView* pOutlinerView = mpSdOutliner->GetView(0); |
81 | 0 | if (pOutlinerView != nullptr) |
82 | 0 | mpSdOutliner->ApplyChangedSentence ( |
83 | 0 | pOutlinerView->GetEditView(), |
84 | 0 | rChanged, bRecheck); |
85 | 0 | } |
86 | 0 | } |
87 | | |
88 | | void SpellDialogChildWindow::GetFocus(bool bForceResume) |
89 | 0 | { |
90 | 0 | if (bForceResume) |
91 | 0 | InvalidateSpellDialog(); |
92 | | |
93 | | // In order to detect a cursor movement we could compare the |
94 | | // currently selected text shape with the one that was selected |
95 | | // when LoseFocus() was called the last time. |
96 | | // For the time being we instead rely on the DetectChange() method |
97 | | // in the SdOutliner class. |
98 | 0 | } |
99 | | |
100 | | void SpellDialogChildWindow::LoseFocus() |
101 | 0 | { |
102 | 0 | } |
103 | | |
104 | | void SpellDialogChildWindow::EndSpellingAndClearOutliner() |
105 | 0 | { |
106 | 0 | if (!mpSdOutliner) |
107 | 0 | return; |
108 | 0 | EndListening(mpSdOutliner->GetDoc()); |
109 | 0 | mpSdOutliner->EndSpelling(); |
110 | 0 | if (mbOwnOutliner) |
111 | 0 | delete mpSdOutliner; |
112 | 0 | mpSdOutliner = nullptr; |
113 | 0 | mbOwnOutliner = false; |
114 | 0 | } |
115 | | |
116 | | void SpellDialogChildWindow::Notify(SfxBroadcaster&, const SfxHint& rHint) |
117 | 0 | { |
118 | 0 | if (rHint.GetId() != SfxHintId::ThisIsAnSdrHint) |
119 | 0 | return; |
120 | 0 | const SdrHint* pSdrHint = static_cast<const SdrHint*>(&rHint); |
121 | 0 | if (SdrHintKind::ModelCleared == pSdrHint->GetKind()) |
122 | 0 | { |
123 | 0 | EndSpellingAndClearOutliner(); |
124 | 0 | } |
125 | 0 | } |
126 | | |
127 | | void SpellDialogChildWindow::ProvideOutliner() |
128 | 0 | { |
129 | 0 | ViewShellBase* pViewShellBase = dynamic_cast<ViewShellBase*>( SfxViewShell::Current() ); |
130 | |
|
131 | 0 | if (pViewShellBase == nullptr) |
132 | 0 | return; |
133 | | |
134 | 0 | ViewShell* pViewShell = pViewShellBase->GetMainViewShell().get(); |
135 | | // If there already exists an outliner that has been created |
136 | | // for another view shell then destroy it first. |
137 | 0 | if (mpSdOutliner != nullptr) |
138 | 0 | if(( dynamic_cast< const DrawViewShell *>( pViewShell ) != nullptr && ! mbOwnOutliner) |
139 | 0 | || (dynamic_cast< const OutlineViewShell *>( pViewShell ) != nullptr && mbOwnOutliner)) |
140 | 0 | { |
141 | 0 | EndSpellingAndClearOutliner(); |
142 | 0 | } |
143 | | |
144 | | // Now create/get an outliner if none is present. |
145 | 0 | if (mpSdOutliner != nullptr) |
146 | 0 | return; |
147 | | |
148 | 0 | if( dynamic_cast< const DrawViewShell *>( pViewShell ) != nullptr) |
149 | 0 | { |
150 | | // We need an outliner for the spell check so we have |
151 | | // to create one. |
152 | 0 | mbOwnOutliner = true; |
153 | 0 | SdDrawDocument *pDoc = pViewShell->GetDoc(); |
154 | 0 | mpSdOutliner = new SdOutliner(*pDoc, OutlinerMode::TextObject); |
155 | 0 | StartListening(*pDoc); |
156 | 0 | } |
157 | 0 | else if( dynamic_cast< const OutlineViewShell *>( pViewShell ) != nullptr) |
158 | 0 | { |
159 | | // An outline view is already visible. The SdOutliner |
160 | | // will use it instead of creating its own. |
161 | 0 | mbOwnOutliner = false; |
162 | 0 | SdDrawDocument *pDoc = pViewShell->GetDoc(); |
163 | 0 | mpSdOutliner = pDoc->GetOutliner(); |
164 | 0 | StartListening(*pDoc); |
165 | 0 | } |
166 | | |
167 | | // Initialize spelling. |
168 | 0 | if (mpSdOutliner != nullptr) |
169 | 0 | { |
170 | 0 | mpSdOutliner->PrepareSpelling(); |
171 | 0 | mpSdOutliner->StartSpelling(); |
172 | 0 | } |
173 | 0 | } |
174 | | |
175 | | } // end of namespace ::sd |
176 | | |
177 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |