tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sd / source / ui / accessibility / AccessibleOutlineEditSource.cxx
blob90c3776ac689609621e8ace84dd1b42d1b3c6071
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <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>
27 namespace accessibility
30 AccessibleOutlineEditSource::AccessibleOutlineEditSource(
31 SdrOutliner& rOutliner,
32 SdrView& rView,
33 OutlinerView& rOutlView,
34 const vcl::Window& rViewWindow )
35 : mrView( rView ),
36 mrWindow( rViewWindow ),
37 mpOutliner( &rOutliner ),
38 mpOutlinerView( &rOutlView ),
39 mTextForwarder( rOutliner, false ),
40 mViewForwarder( rOutlView )
42 // register as listener - need to broadcast state change messages
43 // Moved to ::GetTextForwarder()
44 //rOutliner.SetNotifyHdl( LINK(this, AccessibleOutlineEditSource, NotifyHdl) );
45 StartListening(rOutliner);
48 AccessibleOutlineEditSource::~AccessibleOutlineEditSource()
50 if( mpOutliner )
51 mpOutliner->SetNotifyHdl( Link<EENotify&,void>() );
52 Broadcast( TextHint( SfxHintId::Dying ) );
55 std::unique_ptr<SvxEditSource> AccessibleOutlineEditSource::Clone() const
57 return std::unique_ptr<SvxEditSource>(new AccessibleOutlineEditSource(*mpOutliner, mrView, *mpOutlinerView, mrWindow));
60 SvxTextForwarder* AccessibleOutlineEditSource::GetTextForwarder()
62 // TODO: maybe suboptimal
63 if( IsValid() )
65 // Moved here to make sure that
66 // the NotifyHandler was set on the current object.
67 mpOutliner->SetNotifyHdl( LINK(this, AccessibleOutlineEditSource, NotifyHdl) );
68 return &mTextForwarder;
70 else
71 return nullptr;
74 SvxViewForwarder* AccessibleOutlineEditSource::GetViewForwarder()
76 // TODO: maybe suboptimal
77 if( IsValid() )
78 return this;
79 else
80 return nullptr;
83 SvxEditViewForwarder* AccessibleOutlineEditSource::GetEditViewForwarder( bool )
85 // TODO: maybe suboptimal
86 if( IsValid() )
88 // ignore parameter, we're always in edit mode here
89 return &mViewForwarder;
91 else
92 return nullptr;
95 void AccessibleOutlineEditSource::UpdateData()
97 // NOOP, since we're always working on the 'real' outliner,
98 // i.e. changes are immediately reflected on the screen
101 SfxBroadcaster& AccessibleOutlineEditSource::GetBroadcaster() const
103 return * const_cast< AccessibleOutlineEditSource* > (this);
106 bool AccessibleOutlineEditSource::IsValid() const
108 if( mpOutliner && mpOutlinerView )
110 // Our view still on outliner?
111 sal_uLong nCurrView, nViews;
113 for( nCurrView=0, nViews=mpOutliner->GetViewCount(); nCurrView<nViews; ++nCurrView )
115 if( mpOutliner->GetView(nCurrView) == mpOutlinerView )
116 return true;
120 return false;
123 Point AccessibleOutlineEditSource::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
125 if (IsValid())
127 Point aPoint( OutputDevice::LogicToLogic( rPoint, rMapMode,
128 MapMode(mrView.GetModel().GetScaleUnit()) ) );
129 MapMode aMapMode(mrWindow.GetMapMode());
130 aMapMode.SetOrigin(Point());
131 return mrWindow.LogicToPixel( aPoint, aMapMode );
134 return Point();
137 Point AccessibleOutlineEditSource::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
139 if (IsValid())
141 MapMode aMapMode(mrWindow.GetMapMode());
142 aMapMode.SetOrigin(Point());
143 Point aPoint( mrWindow.PixelToLogic( rPoint, aMapMode ) );
144 return OutputDevice::LogicToLogic( aPoint,
145 MapMode(mrView.GetModel().GetScaleUnit()),
146 rMapMode );
149 return Point();
152 void AccessibleOutlineEditSource::Notify( SfxBroadcaster& rBroadcaster, const SfxHint& rHint )
154 bool bDispose = false;
156 if( &rBroadcaster == mpOutliner )
158 if( rHint.GetId() == SfxHintId::Dying )
160 bDispose = true;
161 mpOutliner = nullptr;
164 else
166 if (rHint.GetId() == SfxHintId::ThisIsAnSdrHint)
168 const SdrHint* pSdrHint = static_cast< const SdrHint* >( &rHint );
169 if( pSdrHint->GetKind() == SdrHintKind::ModelCleared )
171 // model is dying under us, going defunc
172 bDispose = true;
177 if( bDispose )
179 if( mpOutliner )
180 mpOutliner->SetNotifyHdl( Link<EENotify&,void>() );
181 mpOutliner = nullptr;
182 mpOutlinerView = nullptr;
183 Broadcast( TextHint( SfxHintId::Dying ) );
187 IMPL_LINK(AccessibleOutlineEditSource, NotifyHdl, EENotify&, rNotify, void)
189 ::std::unique_ptr< SfxHint > aHint( SvxEditSourceHelper::EENotification2Hint( &rNotify) );
191 if (aHint)
193 Broadcast(*aHint);
197 } // end of namespace accessibility
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */