1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sd.hxx" 26 #include <editeng/unoedhlp.hxx> 27 #include <svx/svdoutl.hxx> 28 29 #ifndef SD_ACCESSIBILITY_ACCESSIBLE_OUTLINE_EDIT_SOURCE_HXX 30 #include <AccessibleOutlineEditSource.hxx> 31 #endif 32 #include "OutlineView.hxx" 33 #include <svx/sdrpaintwindow.hxx> 34 35 namespace accessibility 36 { 37 38 AccessibleOutlineEditSource::AccessibleOutlineEditSource( 39 SdrOutliner& rOutliner, 40 SdrView& rView, 41 OutlinerView& rOutlView, 42 const ::Window& rViewWindow ) 43 : mrView( rView ), 44 mrWindow( rViewWindow ), 45 mpOutliner( &rOutliner ), 46 mpOutlinerView( &rOutlView ), 47 mTextForwarder( rOutliner, 0 ), 48 mViewForwarder( rOutlView ) 49 { 50 // register as listener - need to broadcast state change messages 51 rOutliner.SetNotifyHdl( LINK(this, AccessibleOutlineEditSource, NotifyHdl) ); 52 StartListening(rOutliner); 53 } 54 55 AccessibleOutlineEditSource::~AccessibleOutlineEditSource() 56 { 57 if( mpOutliner ) 58 mpOutliner->SetNotifyHdl( Link() ); 59 Broadcast( TextHint( SFX_HINT_DYING ) ); 60 } 61 62 SvxEditSource* AccessibleOutlineEditSource::Clone() const 63 { 64 return NULL; 65 } 66 67 SvxTextForwarder* AccessibleOutlineEditSource::GetTextForwarder() 68 { 69 // TODO: maybe suboptimal 70 if( IsValid() ) 71 return &mTextForwarder; 72 else 73 return NULL; 74 } 75 76 SvxViewForwarder* AccessibleOutlineEditSource::GetViewForwarder() 77 { 78 // TODO: maybe suboptimal 79 if( IsValid() ) 80 return this; 81 else 82 return NULL; 83 } 84 85 SvxEditViewForwarder* AccessibleOutlineEditSource::GetEditViewForwarder( sal_Bool ) 86 { 87 // TODO: maybe suboptimal 88 if( IsValid() ) 89 { 90 // ignore parameter, we're always in edit mode here 91 return &mViewForwarder; 92 } 93 else 94 return NULL; 95 } 96 97 void AccessibleOutlineEditSource::UpdateData() 98 { 99 // NOOP, since we're always working on the 'real' outliner, 100 // i.e. changes are immediately reflected on the screen 101 } 102 103 SfxBroadcaster& AccessibleOutlineEditSource::GetBroadcaster() const 104 { 105 return *( const_cast< AccessibleOutlineEditSource* > (this) ); 106 } 107 108 sal_Bool AccessibleOutlineEditSource::IsValid() const 109 { 110 if( mpOutliner && mpOutlinerView ) 111 { 112 // Our view still on outliner? 113 sal_uLong nCurrView, nViews; 114 115 for( nCurrView=0, nViews=mpOutliner->GetViewCount(); nCurrView<nViews; ++nCurrView ) 116 { 117 if( mpOutliner->GetView(nCurrView) == mpOutlinerView ) 118 return sal_True; 119 } 120 } 121 122 return sal_False; 123 } 124 125 Rectangle AccessibleOutlineEditSource::GetVisArea() const 126 { 127 if( IsValid() ) 128 { 129 SdrPaintWindow* pPaintWindow = mrView.FindPaintWindow(mrWindow); 130 Rectangle aVisArea; 131 132 if(pPaintWindow) 133 { 134 aVisArea = pPaintWindow->GetVisibleArea(); 135 } 136 137 MapMode aMapMode(mrWindow.GetMapMode()); 138 aMapMode.SetOrigin(Point()); 139 return mrWindow.LogicToPixel( aVisArea, aMapMode ); 140 } 141 142 return Rectangle(); 143 } 144 145 Point AccessibleOutlineEditSource::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const 146 { 147 if( IsValid() && mrView.GetModel() ) 148 { 149 Point aPoint( OutputDevice::LogicToLogic( rPoint, rMapMode, 150 MapMode(mrView.GetModel()->GetScaleUnit()) ) ); 151 MapMode aMapMode(mrWindow.GetMapMode()); 152 aMapMode.SetOrigin(Point()); 153 return mrWindow.LogicToPixel( aPoint, aMapMode ); 154 } 155 156 return Point(); 157 } 158 159 Point AccessibleOutlineEditSource::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const 160 { 161 if( IsValid() && mrView.GetModel() ) 162 { 163 MapMode aMapMode(mrWindow.GetMapMode()); 164 aMapMode.SetOrigin(Point()); 165 Point aPoint( mrWindow.PixelToLogic( rPoint, aMapMode ) ); 166 return OutputDevice::LogicToLogic( aPoint, 167 MapMode(mrView.GetModel()->GetScaleUnit()), 168 rMapMode ); 169 } 170 171 return Point(); 172 } 173 174 void AccessibleOutlineEditSource::Notify( SfxBroadcaster& rBroadcaster, const SfxHint& rHint ) 175 { 176 bool bDispose = false; 177 178 if( &rBroadcaster == mpOutliner ) 179 { 180 const SfxSimpleHint* pHint = dynamic_cast< const SfxSimpleHint * >( &rHint ); 181 if( pHint && (pHint->GetId() == SFX_HINT_DYING) ) 182 { 183 bDispose = true; 184 mpOutliner = NULL; 185 } 186 } 187 else 188 { 189 const SdrHint* pSdrHint = dynamic_cast< const SdrHint* >( &rHint ); 190 191 if( pSdrHint && ( pSdrHint->GetKind() == HINT_MODELCLEARED ) ) 192 { 193 // model is dying under us, going defunc 194 bDispose = true; 195 } 196 } 197 198 if( bDispose ) 199 { 200 if( mpOutliner ) 201 mpOutliner->SetNotifyHdl( Link() ); 202 mpOutliner = NULL; 203 mpOutlinerView = NULL; 204 Broadcast( TextHint( SFX_HINT_DYING ) ); 205 } 206 } 207 208 IMPL_LINK(AccessibleOutlineEditSource, NotifyHdl, EENotify*, aNotify) 209 { 210 if( aNotify ) 211 { 212 ::std::auto_ptr< SfxHint > aHint( SvxEditSourceHelper::EENotification2Hint( aNotify) ); 213 214 if( aHint.get() ) 215 Broadcast( *aHint.get() ); 216 } 217 218 return 0; 219 } 220 221 } // end of namespace accessibility 222