1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
,
33 OutlinerView
& rOutlView
,
34 const vcl::Window
& rViewWindow
)
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()
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
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
;
74 SvxViewForwarder
* AccessibleOutlineEditSource::GetViewForwarder()
76 // TODO: maybe suboptimal
83 SvxEditViewForwarder
* AccessibleOutlineEditSource::GetEditViewForwarder( bool )
85 // TODO: maybe suboptimal
88 // ignore parameter, we're always in edit mode here
89 return &mViewForwarder
;
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
)
123 Rectangle
AccessibleOutlineEditSource::GetVisArea() const
127 SdrPaintWindow
* pPaintWindow
= mrView
.FindPaintWindow(mrWindow
);
132 aVisArea
= pPaintWindow
->GetVisibleArea();
135 MapMode
aMapMode(mrWindow
.GetMapMode());
136 aMapMode
.SetOrigin(Point());
137 return mrWindow
.LogicToPixel( aVisArea
, aMapMode
);
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
);
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()),
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
) )
187 const SdrHint
* pSdrHint
= dynamic_cast< const SdrHint
* >( &rHint
);
189 if( pSdrHint
&& ( pSdrHint
->GetKind() == HINT_MODELCLEARED
) )
191 // model is dying under us, going defunc
199 mpOutliner
->SetNotifyHdl( Link
<>() );
201 mpOutlinerView
= NULL
;
202 Broadcast( TextHint( SFX_HINT_DYING
) );
206 IMPL_LINK(AccessibleOutlineEditSource
, NotifyHdl
, EENotify
*, aNotify
)
210 ::std::unique_ptr
< SfxHint
> aHint( SvxEditSourceHelper::EENotification2Hint( aNotify
) );
213 Broadcast( *aHint
.get() );
219 } // end of namespace accessibility
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */