/src/libreoffice/sd/source/ui/dlg/SpellDialogChildWindow.cxx
Line | Count | Source (jump to first uncovered line) |
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 ( |
35 | | vcl::Window* _pParent, |
36 | | sal_uInt16 nId, |
37 | | SfxBindings* pBindings, |
38 | | SAL_UNUSED_PARAMETER SfxChildWinInfo* /*pInfo*/) |
39 | 0 | : svx::SpellDialogChildWindow (_pParent, nId, pBindings), |
40 | 0 | mpSdOutliner (nullptr), |
41 | 0 | mbOwnOutliner (false) |
42 | 0 | { |
43 | 0 | ProvideOutliner(); |
44 | 0 | } |
45 | | |
46 | | SpellDialogChildWindow::~SpellDialogChildWindow() |
47 | 0 | { |
48 | 0 | EndSpellingAndClearOutliner(); |
49 | 0 | } |
50 | | |
51 | | SfxChildWinInfo SpellDialogChildWindow::GetInfo() const |
52 | 0 | { |
53 | 0 | return svx::SpellDialogChildWindow::GetInfo(); |
54 | 0 | } |
55 | | |
56 | | void SpellDialogChildWindow::InvalidateSpellDialog() |
57 | 0 | { |
58 | 0 | svx::SpellDialogChildWindow::InvalidateSpellDialog(); |
59 | 0 | } |
60 | | |
61 | | svx::SpellPortions SpellDialogChildWindow::GetNextWrongSentence( bool /*bRecheck*/ ) |
62 | 0 | { |
63 | 0 | svx::SpellPortions aResult; |
64 | |
|
65 | 0 | if (mpSdOutliner != nullptr) |
66 | 0 | { |
67 | 0 | ProvideOutliner(); |
68 | 0 | aResult = mpSdOutliner->GetNextSpellSentence(); |
69 | 0 | } |
70 | 0 | return aResult; |
71 | 0 | } |
72 | | |
73 | | void SpellDialogChildWindow::ApplyChangedSentence ( |
74 | | const svx::SpellPortions& rChanged, bool bRecheck ) |
75 | 0 | { |
76 | 0 | if (mpSdOutliner != nullptr) |
77 | 0 | { |
78 | 0 | OutlinerView* pOutlinerView = mpSdOutliner->GetView(0); |
79 | 0 | if (pOutlinerView != nullptr) |
80 | 0 | mpSdOutliner->ApplyChangedSentence ( |
81 | 0 | pOutlinerView->GetEditView(), |
82 | 0 | rChanged, bRecheck); |
83 | 0 | } |
84 | 0 | } |
85 | | |
86 | | void SpellDialogChildWindow::GetFocus() |
87 | 0 | { |
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 | 0 | } |
94 | | |
95 | | void SpellDialogChildWindow::LoseFocus() |
96 | 0 | { |
97 | 0 | } |
98 | | |
99 | | void SpellDialogChildWindow::EndSpellingAndClearOutliner() |
100 | 0 | { |
101 | 0 | if (!mpSdOutliner) |
102 | 0 | return; |
103 | 0 | EndListening(mpSdOutliner->GetDoc()); |
104 | 0 | mpSdOutliner->EndSpelling(); |
105 | 0 | if (mbOwnOutliner) |
106 | 0 | delete mpSdOutliner; |
107 | 0 | mpSdOutliner = nullptr; |
108 | 0 | mbOwnOutliner = false; |
109 | 0 | } |
110 | | |
111 | | void SpellDialogChildWindow::Notify(SfxBroadcaster&, const SfxHint& rHint) |
112 | 0 | { |
113 | 0 | if (rHint.GetId() != SfxHintId::ThisIsAnSdrHint) |
114 | 0 | return; |
115 | 0 | const SdrHint* pSdrHint = static_cast<const SdrHint*>(&rHint); |
116 | 0 | if (SdrHintKind::ModelCleared == pSdrHint->GetKind()) |
117 | 0 | { |
118 | 0 | EndSpellingAndClearOutliner(); |
119 | 0 | } |
120 | 0 | } |
121 | | |
122 | | void SpellDialogChildWindow::ProvideOutliner() |
123 | 0 | { |
124 | 0 | ViewShellBase* pViewShellBase = dynamic_cast<ViewShellBase*>( SfxViewShell::Current() ); |
125 | |
|
126 | 0 | if (pViewShellBase == nullptr) |
127 | 0 | return; |
128 | | |
129 | 0 | 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 | 0 | if (mpSdOutliner != nullptr) |
133 | 0 | if(( dynamic_cast< const DrawViewShell *>( pViewShell ) != nullptr && ! mbOwnOutliner) |
134 | 0 | || (dynamic_cast< const OutlineViewShell *>( pViewShell ) != nullptr && mbOwnOutliner)) |
135 | 0 | { |
136 | 0 | EndSpellingAndClearOutliner(); |
137 | 0 | } |
138 | | |
139 | | // Now create/get an outliner if none is present. |
140 | 0 | if (mpSdOutliner != nullptr) |
141 | 0 | return; |
142 | | |
143 | 0 | if( dynamic_cast< const DrawViewShell *>( pViewShell ) != nullptr) |
144 | 0 | { |
145 | | // We need an outliner for the spell check so we have |
146 | | // to create one. |
147 | 0 | mbOwnOutliner = true; |
148 | 0 | SdDrawDocument *pDoc = pViewShell->GetDoc(); |
149 | 0 | mpSdOutliner = new SdOutliner(*pDoc, OutlinerMode::TextObject); |
150 | 0 | StartListening(*pDoc); |
151 | 0 | } |
152 | 0 | else if( dynamic_cast< const OutlineViewShell *>( pViewShell ) != nullptr) |
153 | 0 | { |
154 | | // An outline view is already visible. The SdOutliner |
155 | | // will use it instead of creating its own. |
156 | 0 | mbOwnOutliner = false; |
157 | 0 | SdDrawDocument *pDoc = pViewShell->GetDoc(); |
158 | 0 | mpSdOutliner = pDoc->GetOutliner(); |
159 | 0 | StartListening(*pDoc); |
160 | 0 | } |
161 | | |
162 | | // Initialize spelling. |
163 | 0 | if (mpSdOutliner != nullptr) |
164 | 0 | { |
165 | 0 | mpSdOutliner->PrepareSpelling(); |
166 | 0 | mpSdOutliner->StartSpelling(); |
167 | 0 | } |
168 | 0 | } |
169 | | |
170 | | } // end of namespace ::sd |
171 | | |
172 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |