/src/libreoffice/sd/source/ui/accessibility/AccessibleOutlineEditSource.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 <memory> |
21 | | #include <editeng/unoedhlp.hxx> |
22 | | #include <svx/svdoutl.hxx> |
23 | | #include <svx/svdview.hxx> |
24 | | #include <vcl/window.hxx> |
25 | | #include <AccessibleOutlineEditSource.hxx> |
26 | | |
27 | | namespace accessibility |
28 | | { |
29 | | |
30 | | AccessibleOutlineEditSource::AccessibleOutlineEditSource( |
31 | | SdrOutliner& rOutliner, |
32 | | SdrView& rView, |
33 | | OutlinerView& rOutlView, |
34 | | const vcl::Window& rViewWindow ) |
35 | 0 | : mrView( rView ), |
36 | 0 | mrWindow( rViewWindow ), |
37 | 0 | mpOutliner( &rOutliner ), |
38 | 0 | mpOutlinerView( &rOutlView ), |
39 | 0 | mTextForwarder( rOutliner, false ), |
40 | 0 | mViewForwarder( rOutlView ) |
41 | 0 | { |
42 | | // register as listener - need to broadcast state change messages |
43 | | // Moved to ::GetTextForwarder() |
44 | | //rOutliner.SetNotifyHdl( LINK(this, AccessibleOutlineEditSource, NotifyHdl) ); |
45 | 0 | StartListening(rOutliner); |
46 | 0 | } |
47 | | |
48 | | AccessibleOutlineEditSource::~AccessibleOutlineEditSource() |
49 | 0 | { |
50 | 0 | if( mpOutliner ) |
51 | 0 | mpOutliner->SetNotifyHdl( Link<EENotify&,void>() ); |
52 | 0 | Broadcast( TextHint( SfxHintId::Dying ) ); |
53 | 0 | } |
54 | | |
55 | | std::unique_ptr<SvxEditSource> AccessibleOutlineEditSource::Clone() const |
56 | 0 | { |
57 | 0 | return std::unique_ptr<SvxEditSource>(new AccessibleOutlineEditSource(*mpOutliner, mrView, *mpOutlinerView, mrWindow)); |
58 | 0 | } |
59 | | |
60 | | SvxTextForwarder* AccessibleOutlineEditSource::GetTextForwarder() |
61 | 0 | { |
62 | | // TODO: maybe suboptimal |
63 | 0 | if( IsValid() ) |
64 | 0 | { |
65 | | // Moved here to make sure that |
66 | | // the NotifyHandler was set on the current object. |
67 | 0 | mpOutliner->SetNotifyHdl( LINK(this, AccessibleOutlineEditSource, NotifyHdl) ); |
68 | 0 | return &mTextForwarder; |
69 | 0 | } |
70 | 0 | else |
71 | 0 | return nullptr; |
72 | 0 | } |
73 | | |
74 | | SvxViewForwarder* AccessibleOutlineEditSource::GetViewForwarder() |
75 | 0 | { |
76 | | // TODO: maybe suboptimal |
77 | 0 | if( IsValid() ) |
78 | 0 | return this; |
79 | 0 | else |
80 | 0 | return nullptr; |
81 | 0 | } |
82 | | |
83 | | SvxEditViewForwarder* AccessibleOutlineEditSource::GetEditViewForwarder( bool ) |
84 | 0 | { |
85 | | // TODO: maybe suboptimal |
86 | 0 | if( IsValid() ) |
87 | 0 | { |
88 | | // ignore parameter, we're always in edit mode here |
89 | 0 | return &mViewForwarder; |
90 | 0 | } |
91 | 0 | else |
92 | 0 | return nullptr; |
93 | 0 | } |
94 | | |
95 | | void AccessibleOutlineEditSource::UpdateData() |
96 | 0 | { |
97 | | // NOOP, since we're always working on the 'real' outliner, |
98 | | // i.e. changes are immediately reflected on the screen |
99 | 0 | } |
100 | | |
101 | | SfxBroadcaster& AccessibleOutlineEditSource::GetBroadcaster() const |
102 | 0 | { |
103 | 0 | return * const_cast< AccessibleOutlineEditSource* > (this); |
104 | 0 | } |
105 | | |
106 | | bool AccessibleOutlineEditSource::IsValid() const |
107 | 0 | { |
108 | 0 | if( mpOutliner && mpOutlinerView ) |
109 | 0 | { |
110 | | // Our view still on outliner? |
111 | 0 | sal_uLong nCurrView, nViews; |
112 | |
|
113 | 0 | for( nCurrView=0, nViews=mpOutliner->GetViewCount(); nCurrView<nViews; ++nCurrView ) |
114 | 0 | { |
115 | 0 | if( mpOutliner->GetView(nCurrView) == mpOutlinerView ) |
116 | 0 | return true; |
117 | 0 | } |
118 | 0 | } |
119 | | |
120 | 0 | return false; |
121 | 0 | } |
122 | | |
123 | | Point AccessibleOutlineEditSource::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const |
124 | 0 | { |
125 | 0 | if (IsValid()) |
126 | 0 | { |
127 | 0 | Point aPoint( OutputDevice::LogicToLogic( rPoint, rMapMode, |
128 | 0 | MapMode(mrView.GetModel().GetScaleUnit()) ) ); |
129 | 0 | MapMode aMapMode(mrWindow.GetMapMode()); |
130 | 0 | aMapMode.SetOrigin(Point()); |
131 | 0 | return mrWindow.LogicToPixel( aPoint, aMapMode ); |
132 | 0 | } |
133 | | |
134 | 0 | return Point(); |
135 | 0 | } |
136 | | |
137 | | Point AccessibleOutlineEditSource::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const |
138 | 0 | { |
139 | 0 | if (IsValid()) |
140 | 0 | { |
141 | 0 | MapMode aMapMode(mrWindow.GetMapMode()); |
142 | 0 | aMapMode.SetOrigin(Point()); |
143 | 0 | Point aPoint( mrWindow.PixelToLogic( rPoint, aMapMode ) ); |
144 | 0 | return OutputDevice::LogicToLogic( aPoint, |
145 | 0 | MapMode(mrView.GetModel().GetScaleUnit()), |
146 | 0 | rMapMode ); |
147 | 0 | } |
148 | | |
149 | 0 | return Point(); |
150 | 0 | } |
151 | | |
152 | | void AccessibleOutlineEditSource::Notify( SfxBroadcaster& rBroadcaster, const SfxHint& rHint ) |
153 | 0 | { |
154 | 0 | bool bDispose = false; |
155 | |
|
156 | 0 | if( &rBroadcaster == mpOutliner ) |
157 | 0 | { |
158 | 0 | if( rHint.GetId() == SfxHintId::Dying ) |
159 | 0 | { |
160 | 0 | bDispose = true; |
161 | 0 | mpOutliner = nullptr; |
162 | 0 | } |
163 | 0 | } |
164 | 0 | else |
165 | 0 | { |
166 | 0 | if (rHint.GetId() == SfxHintId::ThisIsAnSdrHint) |
167 | 0 | { |
168 | 0 | const SdrHint* pSdrHint = static_cast< const SdrHint* >( &rHint ); |
169 | 0 | if( pSdrHint->GetKind() == SdrHintKind::ModelCleared ) |
170 | 0 | { |
171 | | // model is dying under us, going defunc |
172 | 0 | bDispose = true; |
173 | 0 | } |
174 | 0 | } |
175 | 0 | } |
176 | |
|
177 | 0 | if( bDispose ) |
178 | 0 | { |
179 | 0 | if( mpOutliner ) |
180 | 0 | mpOutliner->SetNotifyHdl( Link<EENotify&,void>() ); |
181 | 0 | mpOutliner = nullptr; |
182 | 0 | mpOutlinerView = nullptr; |
183 | 0 | Broadcast( TextHint( SfxHintId::Dying ) ); |
184 | 0 | } |
185 | 0 | } |
186 | | |
187 | | IMPL_LINK(AccessibleOutlineEditSource, NotifyHdl, EENotify&, rNotify, void) |
188 | 0 | { |
189 | 0 | ::std::unique_ptr< SfxHint > aHint( SvxEditSourceHelper::EENotification2Hint( &rNotify) ); |
190 | |
|
191 | 0 | if (aHint) |
192 | 0 | { |
193 | 0 | Broadcast(*aHint); |
194 | 0 | } |
195 | 0 | } |
196 | | |
197 | | } // end of namespace accessibility |
198 | | |
199 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |