merged tag LIBREOFFICE_3_2_99_3
[LibreOffice.git] / sd / source / ui / accessibility / AccessibleOutlineEditSource.cxx
blob9fd2430d64e68244794a6246fe39adeafe56e5d3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_sd.hxx"
31 #include <editeng/unoedhlp.hxx>
32 #include <svx/svdoutl.hxx>
34 #include <AccessibleOutlineEditSource.hxx>
35 #include "OutlineView.hxx"
36 #include <svx/sdrpaintwindow.hxx>
38 namespace accessibility
41 AccessibleOutlineEditSource::AccessibleOutlineEditSource(
42 SdrOutliner& rOutliner,
43 SdrView& rView,
44 OutlinerView& rOutlView,
45 const ::Window& rViewWindow )
46 : mrView( rView ),
47 mrWindow( rViewWindow ),
48 mpOutliner( &rOutliner ),
49 mpOutlinerView( &rOutlView ),
50 mTextForwarder( rOutliner, 0 ),
51 mViewForwarder( rOutlView )
53 // register as listener - need to broadcast state change messages
54 rOutliner.SetNotifyHdl( LINK(this, AccessibleOutlineEditSource, NotifyHdl) );
55 StartListening(rOutliner);
58 AccessibleOutlineEditSource::~AccessibleOutlineEditSource()
60 if( mpOutliner )
61 mpOutliner->SetNotifyHdl( Link() );
62 Broadcast( TextHint( SFX_HINT_DYING ) );
65 SvxEditSource* AccessibleOutlineEditSource::Clone() const
67 return NULL;
70 SvxTextForwarder* AccessibleOutlineEditSource::GetTextForwarder()
72 // TODO: maybe suboptimal
73 if( IsValid() )
74 return &mTextForwarder;
75 else
76 return NULL;
79 SvxViewForwarder* AccessibleOutlineEditSource::GetViewForwarder()
81 // TODO: maybe suboptimal
82 if( IsValid() )
83 return this;
84 else
85 return NULL;
88 SvxEditViewForwarder* AccessibleOutlineEditSource::GetEditViewForwarder( sal_Bool )
90 // TODO: maybe suboptimal
91 if( IsValid() )
93 // ignore parameter, we're always in edit mode here
94 return &mViewForwarder;
96 else
97 return NULL;
100 void AccessibleOutlineEditSource::UpdateData()
102 // NOOP, since we're always working on the 'real' outliner,
103 // i.e. changes are immediately reflected on the screen
106 SfxBroadcaster& AccessibleOutlineEditSource::GetBroadcaster() const
108 return *( const_cast< AccessibleOutlineEditSource* > (this) );
111 BOOL AccessibleOutlineEditSource::IsValid() const
113 if( mpOutliner && mpOutlinerView )
115 // Our view still on outliner?
116 ULONG nCurrView, nViews;
118 for( nCurrView=0, nViews=mpOutliner->GetViewCount(); nCurrView<nViews; ++nCurrView )
120 if( mpOutliner->GetView(nCurrView) == mpOutlinerView )
121 return sal_True;
125 return sal_False;
128 Rectangle AccessibleOutlineEditSource::GetVisArea() const
130 if( IsValid() )
132 SdrPaintWindow* pPaintWindow = mrView.FindPaintWindow(mrWindow);
133 Rectangle aVisArea;
135 if(pPaintWindow)
137 aVisArea = pPaintWindow->GetVisibleArea();
140 MapMode aMapMode(mrWindow.GetMapMode());
141 aMapMode.SetOrigin(Point());
142 return mrWindow.LogicToPixel( aVisArea, aMapMode );
145 return Rectangle();
148 Point AccessibleOutlineEditSource::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
150 if( IsValid() && mrView.GetModel() )
152 Point aPoint( OutputDevice::LogicToLogic( rPoint, rMapMode,
153 MapMode(mrView.GetModel()->GetScaleUnit()) ) );
154 MapMode aMapMode(mrWindow.GetMapMode());
155 aMapMode.SetOrigin(Point());
156 return mrWindow.LogicToPixel( aPoint, aMapMode );
159 return Point();
162 Point AccessibleOutlineEditSource::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
164 if( IsValid() && mrView.GetModel() )
166 MapMode aMapMode(mrWindow.GetMapMode());
167 aMapMode.SetOrigin(Point());
168 Point aPoint( mrWindow.PixelToLogic( rPoint, aMapMode ) );
169 return OutputDevice::LogicToLogic( aPoint,
170 MapMode(mrView.GetModel()->GetScaleUnit()),
171 rMapMode );
174 return Point();
177 void AccessibleOutlineEditSource::Notify( SfxBroadcaster& rBroadcaster, const SfxHint& rHint )
179 bool bDispose = false;
181 if( &rBroadcaster == mpOutliner )
183 const SfxSimpleHint* pHint = dynamic_cast< const SfxSimpleHint * >( &rHint );
184 if( pHint && (pHint->GetId() == SFX_HINT_DYING) )
186 bDispose = true;
187 mpOutliner = NULL;
190 else
192 const SdrHint* pSdrHint = dynamic_cast< const SdrHint* >( &rHint );
194 if( pSdrHint && ( pSdrHint->GetKind() == HINT_MODELCLEARED ) )
196 // model is dying under us, going defunc
197 bDispose = true;
201 if( bDispose )
203 if( mpOutliner )
204 mpOutliner->SetNotifyHdl( Link() );
205 mpOutliner = NULL;
206 mpOutlinerView = NULL;
207 Broadcast( TextHint( SFX_HINT_DYING ) );
211 IMPL_LINK(AccessibleOutlineEditSource, NotifyHdl, EENotify*, aNotify)
213 if( aNotify )
215 ::std::auto_ptr< SfxHint > aHint( SvxEditSourceHelper::EENotification2Hint( aNotify) );
217 if( aHint.get() )
218 Broadcast( *aHint.get() );
221 return 0;
224 } // end of namespace accessibility
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */