Update ooo320-m1
[ooovba.git] / sd / source / ui / accessibility / AccessibleOutlineEditSource.cxx
blobd24d687774bc8ad74f2f91dad84ce49ead40dc16
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleOutlineEditSource.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
33 #include <svx/unoedhlp.hxx>
34 #include <svx/svdoutl.hxx>
36 #ifndef SD_ACCESSIBILITY_ACCESSIBLE_OUTLINE_EDIT_SOURCE_HXX
37 #include <AccessibleOutlineEditSource.hxx>
38 #endif
39 #include "OutlineView.hxx"
40 #include <svx/sdrpaintwindow.hxx>
42 namespace accessibility
45 AccessibleOutlineEditSource::AccessibleOutlineEditSource(
46 SdrOutliner& rOutliner,
47 SdrView& rView,
48 OutlinerView& rOutlView,
49 const ::Window& rViewWindow )
50 : mrView( rView ),
51 mrWindow( rViewWindow ),
52 mpOutliner( &rOutliner ),
53 mpOutlinerView( &rOutlView ),
54 mTextForwarder( rOutliner, NULL ),
55 mViewForwarder( rOutlView )
57 // register as listener - need to broadcast state change messages
58 rOutliner.SetNotifyHdl( LINK(this, AccessibleOutlineEditSource, NotifyHdl) );
59 StartListening(rOutliner);
62 AccessibleOutlineEditSource::~AccessibleOutlineEditSource()
64 if( mpOutliner )
65 mpOutliner->SetNotifyHdl( Link() );
66 Broadcast( TextHint( SFX_HINT_DYING ) );
69 SvxEditSource* AccessibleOutlineEditSource::Clone() const
71 return NULL;
74 SvxTextForwarder* AccessibleOutlineEditSource::GetTextForwarder()
76 // TODO: maybe suboptimal
77 if( IsValid() )
78 return &mTextForwarder;
79 else
80 return NULL;
83 SvxViewForwarder* AccessibleOutlineEditSource::GetViewForwarder()
85 // TODO: maybe suboptimal
86 if( IsValid() )
87 return this;
88 else
89 return NULL;
92 SvxEditViewForwarder* AccessibleOutlineEditSource::GetEditViewForwarder( sal_Bool )
94 // TODO: maybe suboptimal
95 if( IsValid() )
97 // ignore parameter, we're always in edit mode here
98 return &mViewForwarder;
100 else
101 return NULL;
104 void AccessibleOutlineEditSource::UpdateData()
106 // NOOP, since we're always working on the 'real' outliner,
107 // i.e. changes are immediately reflected on the screen
110 SfxBroadcaster& AccessibleOutlineEditSource::GetBroadcaster() const
112 return *( const_cast< AccessibleOutlineEditSource* > (this) );
115 BOOL AccessibleOutlineEditSource::IsValid() const
117 if( mpOutliner && mpOutlinerView )
119 // Our view still on outliner?
120 ULONG nCurrView, nViews;
122 for( nCurrView=0, nViews=mpOutliner->GetViewCount(); nCurrView<nViews; ++nCurrView )
124 if( mpOutliner->GetView(nCurrView) == mpOutlinerView )
125 return sal_True;
129 return sal_False;
132 Rectangle AccessibleOutlineEditSource::GetVisArea() const
134 if( IsValid() )
136 SdrPaintWindow* pPaintWindow = mrView.FindPaintWindow(mrWindow);
137 Rectangle aVisArea;
139 if(pPaintWindow)
141 aVisArea = pPaintWindow->GetVisibleArea();
144 MapMode aMapMode(mrWindow.GetMapMode());
145 aMapMode.SetOrigin(Point());
146 return mrWindow.LogicToPixel( aVisArea, aMapMode );
149 return Rectangle();
152 Point AccessibleOutlineEditSource::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
154 if( IsValid() && mrView.GetModel() )
156 Point aPoint( OutputDevice::LogicToLogic( rPoint, rMapMode,
157 MapMode(mrView.GetModel()->GetScaleUnit()) ) );
158 MapMode aMapMode(mrWindow.GetMapMode());
159 aMapMode.SetOrigin(Point());
160 return mrWindow.LogicToPixel( aPoint, aMapMode );
163 return Point();
166 Point AccessibleOutlineEditSource::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
168 if( IsValid() && mrView.GetModel() )
170 MapMode aMapMode(mrWindow.GetMapMode());
171 aMapMode.SetOrigin(Point());
172 Point aPoint( mrWindow.PixelToLogic( rPoint, aMapMode ) );
173 return OutputDevice::LogicToLogic( aPoint,
174 MapMode(mrView.GetModel()->GetScaleUnit()),
175 rMapMode );
178 return Point();
181 void AccessibleOutlineEditSource::Notify( SfxBroadcaster& rBroadcaster, const SfxHint& rHint )
183 bool bDispose = false;
185 if( &rBroadcaster == mpOutliner )
187 const SfxSimpleHint* pHint = dynamic_cast< const SfxSimpleHint * >( &rHint );
188 if( pHint && (pHint->GetId() == SFX_HINT_DYING) )
190 bDispose = true;
191 mpOutliner = NULL;
194 else
196 const SdrHint* pSdrHint = dynamic_cast< const SdrHint* >( &rHint );
198 if( pSdrHint && ( pSdrHint->GetKind() == HINT_MODELCLEARED ) )
200 // model is dying under us, going defunc
201 bDispose = true;
205 if( bDispose )
207 if( mpOutliner )
208 mpOutliner->SetNotifyHdl( Link() );
209 mpOutliner = NULL;
210 mpOutlinerView = NULL;
211 Broadcast( TextHint( SFX_HINT_DYING ) );
215 IMPL_LINK(AccessibleOutlineEditSource, NotifyHdl, EENotify*, aNotify)
217 if( aNotify )
219 ::std::auto_ptr< SfxHint > aHint( SvxEditSourceHelper::EENotification2Hint( aNotify) );
221 if( aHint.get() )
222 Broadcast( *aHint.get() );
225 return 0;
228 } // end of namespace accessibility