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