xref: /AOO41X/main/sd/source/ui/accessibility/AccessibleOutlineEditSource.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 #include <editeng/unoedhlp.hxx>
31 #include <svx/svdoutl.hxx>
32 
33 #ifndef SD_ACCESSIBILITY_ACCESSIBLE_OUTLINE_EDIT_SOURCE_HXX
34 #include <AccessibleOutlineEditSource.hxx>
35 #endif
36 #include "OutlineView.hxx"
37 #include <svx/sdrpaintwindow.hxx>
38 
39 namespace accessibility
40 {
41 
42     AccessibleOutlineEditSource::AccessibleOutlineEditSource(
43         SdrOutliner& 	rOutliner,
44         SdrView& 		rView,
45         OutlinerView& rOutlView,
46         const ::Window& rViewWindow )
47         : mrView( rView ),
48           mrWindow( rViewWindow ),
49           mpOutliner( &rOutliner ),
50           mpOutlinerView( &rOutlView ),
51           mTextForwarder( rOutliner, 0 ),
52           mViewForwarder( rOutlView )
53     {
54         // register as listener - need to broadcast state change messages
55         rOutliner.SetNotifyHdl( LINK(this, AccessibleOutlineEditSource, NotifyHdl) );
56         StartListening(rOutliner);
57     }
58 
59     AccessibleOutlineEditSource::~AccessibleOutlineEditSource()
60     {
61         if( mpOutliner )
62             mpOutliner->SetNotifyHdl( Link() );
63         Broadcast( TextHint( SFX_HINT_DYING ) );
64     }
65 
66     SvxEditSource* AccessibleOutlineEditSource::Clone() const
67     {
68         return NULL;
69     }
70 
71     SvxTextForwarder* AccessibleOutlineEditSource::GetTextForwarder()
72     {
73         // TODO: maybe suboptimal
74         if( IsValid() )
75             return &mTextForwarder;
76         else
77             return NULL;
78     }
79 
80     SvxViewForwarder* AccessibleOutlineEditSource::GetViewForwarder()
81     {
82         // TODO: maybe suboptimal
83         if( IsValid() )
84             return this;
85         else
86             return NULL;
87     }
88 
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 
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 
107     SfxBroadcaster& AccessibleOutlineEditSource::GetBroadcaster() const
108     {
109         return *( const_cast< AccessibleOutlineEditSource* > (this) );
110     }
111 
112 	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 
129     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 
149     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 
163     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 
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 
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