xref: /AOO41X/main/sd/source/ui/accessibility/AccessibleViewForwarder.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sd.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifndef _SVX_ACCESSIBILITY_ACCESSIBLE_VIEW_FORWARDER_HXX
32*cdf0e10cSrcweir #include "AccessibleViewForwarder.hxx"
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir #include <svx/svdpntv.hxx>
35*cdf0e10cSrcweir #include <vcl/outdev.hxx>
36*cdf0e10cSrcweir #include <svx/sdrpaintwindow.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir namespace accessibility {
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir /** For the time beeing, the implementation of this class will not use the
41*cdf0e10cSrcweir     member mrDevice.  Instead the device is retrieved from the view
42*cdf0e10cSrcweir     everytime it is used.  This is necessary because the device has to stay
43*cdf0e10cSrcweir     up-to-date with the current view and the class has to stay compatible.
44*cdf0e10cSrcweir     May change in the future.
45*cdf0e10cSrcweir */
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir AccessibleViewForwarder::AccessibleViewForwarder (SdrPaintView* pView, OutputDevice& rDevice)
48*cdf0e10cSrcweir     : mpView (pView),
49*cdf0e10cSrcweir       mnWindowId (0),
50*cdf0e10cSrcweir       mrDevice (rDevice)
51*cdf0e10cSrcweir {
52*cdf0e10cSrcweir     // Search the output device to determine its id.
53*cdf0e10cSrcweir 	for(sal_uInt32 a(0L); a < mpView->PaintWindowCount(); a++)
54*cdf0e10cSrcweir 	{
55*cdf0e10cSrcweir 		SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow(a);
56*cdf0e10cSrcweir 		OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir 		if(&rOutDev == &rDevice)
59*cdf0e10cSrcweir 		{
60*cdf0e10cSrcweir             mnWindowId = (sal_uInt16)a;
61*cdf0e10cSrcweir             break;
62*cdf0e10cSrcweir 		}
63*cdf0e10cSrcweir 	}
64*cdf0e10cSrcweir }
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir AccessibleViewForwarder::~AccessibleViewForwarder (void)
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir     // empty
72*cdf0e10cSrcweir }
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir sal_Bool AccessibleViewForwarder::IsValid (void) const
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir     return sal_True;
80*cdf0e10cSrcweir }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir Rectangle AccessibleViewForwarder::GetVisibleArea (void) const
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir 	Rectangle aVisibleArea;
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 	if((sal_uInt32)mnWindowId < mpView->PaintWindowCount())
90*cdf0e10cSrcweir 	{
91*cdf0e10cSrcweir 		SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId);
92*cdf0e10cSrcweir 		aVisibleArea = pPaintWindow->GetVisibleArea();
93*cdf0e10cSrcweir 	}
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 	return aVisibleArea;
96*cdf0e10cSrcweir }
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir /** Tansform the given point into pixel coordiantes.  After the the pixel
102*cdf0e10cSrcweir     coordiantes of the window origin are added to make the point coordinates
103*cdf0e10cSrcweir     absolute.
104*cdf0e10cSrcweir */
105*cdf0e10cSrcweir Point AccessibleViewForwarder::LogicToPixel (const Point& rPoint) const
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir     OSL_ASSERT (mpView != NULL);
108*cdf0e10cSrcweir 	if((sal_uInt32)mnWindowId < mpView->PaintWindowCount())
109*cdf0e10cSrcweir 	{
110*cdf0e10cSrcweir 		SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId);
111*cdf0e10cSrcweir 		OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
112*cdf0e10cSrcweir         Rectangle aBBox(static_cast<Window&>(rOutDev).GetWindowExtentsRelative(0L));
113*cdf0e10cSrcweir         return rOutDev.LogicToPixel (rPoint) + aBBox.TopLeft();
114*cdf0e10cSrcweir 	}
115*cdf0e10cSrcweir     else
116*cdf0e10cSrcweir         return Point();
117*cdf0e10cSrcweir }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir Size AccessibleViewForwarder::LogicToPixel (const Size& rSize) const
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir     OSL_ASSERT (mpView != NULL);
125*cdf0e10cSrcweir 	if((sal_uInt32)mnWindowId < mpView->PaintWindowCount())
126*cdf0e10cSrcweir 	{
127*cdf0e10cSrcweir 		SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId);
128*cdf0e10cSrcweir 		OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
129*cdf0e10cSrcweir         return rOutDev.LogicToPixel (rSize);
130*cdf0e10cSrcweir 	}
131*cdf0e10cSrcweir     else
132*cdf0e10cSrcweir         return Size();
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir /** First subtract the window origin to make the point coordinates relative
139*cdf0e10cSrcweir     to the window and then transform them into internal coordinates.
140*cdf0e10cSrcweir */
141*cdf0e10cSrcweir Point AccessibleViewForwarder::PixelToLogic (const Point& rPoint) const
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir     OSL_ASSERT (mpView != NULL);
144*cdf0e10cSrcweir 	if((sal_uInt32)mnWindowId < mpView->PaintWindowCount())
145*cdf0e10cSrcweir 	{
146*cdf0e10cSrcweir 		SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId);
147*cdf0e10cSrcweir 		OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
148*cdf0e10cSrcweir         Rectangle aBBox (static_cast<Window&>(rOutDev).GetWindowExtentsRelative(0L));
149*cdf0e10cSrcweir         return rOutDev.PixelToLogic (rPoint - aBBox.TopLeft());
150*cdf0e10cSrcweir     }
151*cdf0e10cSrcweir     else
152*cdf0e10cSrcweir         return Point();
153*cdf0e10cSrcweir }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir Size AccessibleViewForwarder::PixelToLogic (const Size& rSize) const
159*cdf0e10cSrcweir {
160*cdf0e10cSrcweir     OSL_ASSERT (mpView != NULL);
161*cdf0e10cSrcweir 	if((sal_uInt32)mnWindowId < mpView->PaintWindowCount())
162*cdf0e10cSrcweir 	{
163*cdf0e10cSrcweir 		SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId);
164*cdf0e10cSrcweir 		OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
165*cdf0e10cSrcweir         return rOutDev.PixelToLogic (rSize);
166*cdf0e10cSrcweir 	}
167*cdf0e10cSrcweir 	else
168*cdf0e10cSrcweir         return Size();
169*cdf0e10cSrcweir }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir } // end of namespace accessibility
173