bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / accessibility / AccessibleOutlineEditSource.cxx
blob7528ccb19b68377fd427005494895a340e583014
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 <editeng/unoedhlp.hxx>
21 #include <svx/svdoutl.hxx>
23 #include <AccessibleOutlineEditSource.hxx>
24 #include "OutlineView.hxx"
25 #include <svx/sdrpaintwindow.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<>() );
52 Broadcast( TextHint( SFX_HINT_DYING ) );
55 SvxEditSource* AccessibleOutlineEditSource::Clone() const
57 return 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 NULL;
74 SvxViewForwarder* AccessibleOutlineEditSource::GetViewForwarder()
76 // TODO: maybe suboptimal
77 if( IsValid() )
78 return this;
79 else
80 return NULL;
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 NULL;
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 Rectangle AccessibleOutlineEditSource::GetVisArea() const
125 if( IsValid() )
127 SdrPaintWindow* pPaintWindow = mrView.FindPaintWindow(mrWindow);
128 Rectangle aVisArea;
130 if(pPaintWindow)
132 aVisArea = pPaintWindow->GetVisibleArea();
135 MapMode aMapMode(mrWindow.GetMapMode());
136 aMapMode.SetOrigin(Point());
137 return mrWindow.LogicToPixel( aVisArea, aMapMode );
140 return Rectangle();
143 Point AccessibleOutlineEditSource::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
145 if( IsValid() && mrView.GetModel() )
147 Point aPoint( OutputDevice::LogicToLogic( rPoint, rMapMode,
148 MapMode(mrView.GetModel()->GetScaleUnit()) ) );
149 MapMode aMapMode(mrWindow.GetMapMode());
150 aMapMode.SetOrigin(Point());
151 return mrWindow.LogicToPixel( aPoint, aMapMode );
154 return Point();
157 Point AccessibleOutlineEditSource::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
159 if( IsValid() && mrView.GetModel() )
161 MapMode aMapMode(mrWindow.GetMapMode());
162 aMapMode.SetOrigin(Point());
163 Point aPoint( mrWindow.PixelToLogic( rPoint, aMapMode ) );
164 return OutputDevice::LogicToLogic( aPoint,
165 MapMode(mrView.GetModel()->GetScaleUnit()),
166 rMapMode );
169 return Point();
172 void AccessibleOutlineEditSource::Notify( SfxBroadcaster& rBroadcaster, const SfxHint& rHint )
174 bool bDispose = false;
176 if( &rBroadcaster == mpOutliner )
178 const SfxSimpleHint* pHint = dynamic_cast< const SfxSimpleHint * >( &rHint );
179 if( pHint && (pHint->GetId() == SFX_HINT_DYING) )
181 bDispose = true;
182 mpOutliner = NULL;
185 else
187 const SdrHint* pSdrHint = dynamic_cast< const SdrHint* >( &rHint );
189 if( pSdrHint && ( pSdrHint->GetKind() == HINT_MODELCLEARED ) )
191 // model is dying under us, going defunc
192 bDispose = true;
196 if( bDispose )
198 if( mpOutliner )
199 mpOutliner->SetNotifyHdl( Link<>() );
200 mpOutliner = NULL;
201 mpOutlinerView = NULL;
202 Broadcast( TextHint( SFX_HINT_DYING ) );
206 IMPL_LINK(AccessibleOutlineEditSource, NotifyHdl, EENotify*, aNotify)
208 if( aNotify )
210 ::std::unique_ptr< SfxHint > aHint( SvxEditSourceHelper::EENotification2Hint( aNotify) );
212 if( aHint.get() )
213 Broadcast( *aHint.get() );
216 return 0;
219 } // end of namespace accessibility
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */