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 // Moved to ::GetTextForwarder() 52 //rOutliner.SetNotifyHdl( LINK(this, AccessibleOutlineEditSource, NotifyHdl) ); 53 StartListening(rOutliner); 54 } 55 56 AccessibleOutlineEditSource::~AccessibleOutlineEditSource() 57 { 58 if( mpOutliner ) 59 mpOutliner->SetNotifyHdl( Link() ); 60 Broadcast( TextHint( SFX_HINT_DYING ) ); 61 } 62 63 SvxEditSource* AccessibleOutlineEditSource::Clone() const 64 { 65 //IAccessibility2 Implementation 2009----- 66 /*return NULL;*/ 67 return new AccessibleOutlineEditSource(*mpOutliner, mrView, *mpOutlinerView, mrWindow); 68 //-----IAccessibility2 Implementation 2009 69 } 70 71 SvxTextForwarder* AccessibleOutlineEditSource::GetTextForwarder() 72 { 73 // TODO: maybe suboptimal 74 if( IsValid() ) 75 { 76 // Moved here to make sure that 77 // the NotifyHandler was set on the current object. 78 mpOutliner->SetNotifyHdl( LINK(this, AccessibleOutlineEditSource, NotifyHdl) ); 79 return &mTextForwarder; 80 } 81 else 82 return NULL; 83 } 84 85 SvxViewForwarder* AccessibleOutlineEditSource::GetViewForwarder() 86 { 87 // TODO: maybe suboptimal 88 if( IsValid() ) 89 return this; 90 else 91 return NULL; 92 } 93 94 SvxEditViewForwarder* AccessibleOutlineEditSource::GetEditViewForwarder( sal_Bool ) 95 { 96 // TODO: maybe suboptimal 97 if( IsValid() ) 98 { 99 // ignore parameter, we're always in edit mode here 100 return &mViewForwarder; 101 } 102 else 103 return NULL; 104 } 105 106 void AccessibleOutlineEditSource::UpdateData() 107 { 108 // NOOP, since we're always working on the 'real' outliner, 109 // i.e. changes are immediately reflected on the screen 110 } 111 112 SfxBroadcaster& AccessibleOutlineEditSource::GetBroadcaster() const 113 { 114 return *( const_cast< AccessibleOutlineEditSource* > (this) ); 115 } 116 117 sal_Bool AccessibleOutlineEditSource::IsValid() const 118 { 119 if( mpOutliner && mpOutlinerView ) 120 { 121 // Our view still on outliner? 122 sal_uLong nCurrView, nViews; 123 124 for( nCurrView=0, nViews=mpOutliner->GetViewCount(); nCurrView<nViews; ++nCurrView ) 125 { 126 if( mpOutliner->GetView(nCurrView) == mpOutlinerView ) 127 return sal_True; 128 } 129 } 130 131 return sal_False; 132 } 133 134 Rectangle AccessibleOutlineEditSource::GetVisArea() const 135 { 136 if( IsValid() ) 137 { 138 SdrPaintWindow* pPaintWindow = mrView.FindPaintWindow(mrWindow); 139 Rectangle aVisArea; 140 141 if(pPaintWindow) 142 { 143 aVisArea = pPaintWindow->GetVisibleArea(); 144 } 145 146 MapMode aMapMode(mrWindow.GetMapMode()); 147 aMapMode.SetOrigin(Point()); 148 return mrWindow.LogicToPixel( aVisArea, aMapMode ); 149 } 150 151 return Rectangle(); 152 } 153 154 Point AccessibleOutlineEditSource::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const 155 { 156 if( IsValid() && mrView.GetModel() ) 157 { 158 Point aPoint( OutputDevice::LogicToLogic( rPoint, rMapMode, 159 MapMode(mrView.GetModel()->GetScaleUnit()) ) ); 160 MapMode aMapMode(mrWindow.GetMapMode()); 161 aMapMode.SetOrigin(Point()); 162 return mrWindow.LogicToPixel( aPoint, aMapMode ); 163 } 164 165 return Point(); 166 } 167 168 Point AccessibleOutlineEditSource::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const 169 { 170 if( IsValid() && mrView.GetModel() ) 171 { 172 MapMode aMapMode(mrWindow.GetMapMode()); 173 aMapMode.SetOrigin(Point()); 174 Point aPoint( mrWindow.PixelToLogic( rPoint, aMapMode ) ); 175 return OutputDevice::LogicToLogic( aPoint, 176 MapMode(mrView.GetModel()->GetScaleUnit()), 177 rMapMode ); 178 } 179 180 return Point(); 181 } 182 183 void AccessibleOutlineEditSource::Notify( SfxBroadcaster& rBroadcaster, const SfxHint& rHint ) 184 { 185 bool bDispose = false; 186 187 if( &rBroadcaster == mpOutliner ) 188 { 189 const SfxSimpleHint* pHint = dynamic_cast< const SfxSimpleHint * >( &rHint ); 190 if( pHint && (pHint->GetId() == SFX_HINT_DYING) ) 191 { 192 bDispose = true; 193 mpOutliner = NULL; 194 } 195 } 196 else 197 { 198 const SdrHint* pSdrHint = dynamic_cast< const SdrHint* >( &rHint ); 199 200 if( pSdrHint && ( pSdrHint->GetKind() == HINT_MODELCLEARED ) ) 201 { 202 // model is dying under us, going defunc 203 bDispose = true; 204 } 205 } 206 207 if( bDispose ) 208 { 209 if( mpOutliner ) 210 mpOutliner->SetNotifyHdl( Link() ); 211 mpOutliner = NULL; 212 mpOutlinerView = NULL; 213 Broadcast( TextHint( SFX_HINT_DYING ) ); 214 } 215 } 216 217 IMPL_LINK(AccessibleOutlineEditSource, NotifyHdl, EENotify*, aNotify) 218 { 219 if( aNotify ) 220 { 221 ::std::auto_ptr< SfxHint > aHint( SvxEditSourceHelper::EENotification2Hint( aNotify) ); 222 223 if( aHint.get() ) 224 Broadcast( *aHint.get() ); 225 } 226 227 return 0; 228 } 229 230 } // end of namespace accessibility 231