Update ooo320-m1
[ooovba.git] / sd / source / ui / accessibility / AccessibleViewForwarder.cxx
blob6db539801c1e130ff10cee9db09f61c635f01428
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleViewForwarder.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #ifndef _SVX_ACCESSIBILITY_ACCESSIBLE_VIEW_FORWARDER_HXX
35 #include "AccessibleViewForwarder.hxx"
36 #endif
37 #include <svx/svdpntv.hxx>
38 #include <vcl/outdev.hxx>
39 #include <svx/sdrpaintwindow.hxx>
41 namespace accessibility {
43 /** For the time beeing, the implementation of this class will not use the
44 member mrDevice. Instead the device is retrieved from the view
45 everytime it is used. This is necessary because the device has to stay
46 up-to-date with the current view and the class has to stay compatible.
47 May change in the future.
50 AccessibleViewForwarder::AccessibleViewForwarder (SdrPaintView* pView, USHORT nWindowId)
51 : mpView (pView),
52 mnWindowId (nWindowId),
53 mrDevice (pView->GetPaintWindow((sal_uInt32)nWindowId)->GetOutputDevice())
55 OSL_ASSERT (mpView != NULL);
56 // empty
62 AccessibleViewForwarder::AccessibleViewForwarder (SdrPaintView* pView, OutputDevice& rDevice)
63 : mpView (pView),
64 mnWindowId (0),
65 mrDevice (rDevice)
67 // Search the output device to determine its id.
68 for(sal_uInt32 a(0L); a < mpView->PaintWindowCount(); a++)
70 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow(a);
71 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
73 if(&rOutDev == &rDevice)
75 mnWindowId = (sal_uInt16)a;
76 break;
84 AccessibleViewForwarder::~AccessibleViewForwarder (void)
86 // empty
92 void AccessibleViewForwarder::SetView (SdrPaintView* pView)
94 mpView = pView;
95 OSL_ASSERT (mpView != NULL);
101 sal_Bool AccessibleViewForwarder::IsValid (void) const
103 return sal_True;
109 Rectangle AccessibleViewForwarder::GetVisibleArea (void) const
111 Rectangle aVisibleArea;
113 if((sal_uInt32)mnWindowId < mpView->PaintWindowCount())
115 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId);
116 aVisibleArea = pPaintWindow->GetVisibleArea();
119 return aVisibleArea;
125 /** Tansform the given point into pixel coordiantes. After the the pixel
126 coordiantes of the window origin are added to make the point coordinates
127 absolute.
129 Point AccessibleViewForwarder::LogicToPixel (const Point& rPoint) const
131 OSL_ASSERT (mpView != NULL);
132 if((sal_uInt32)mnWindowId < mpView->PaintWindowCount())
134 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId);
135 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
136 Rectangle aBBox(static_cast<Window&>(rOutDev).GetWindowExtentsRelative(0L));
137 return rOutDev.LogicToPixel (rPoint) + aBBox.TopLeft();
139 else
140 return Point();
146 Size AccessibleViewForwarder::LogicToPixel (const Size& rSize) const
148 OSL_ASSERT (mpView != NULL);
149 if((sal_uInt32)mnWindowId < mpView->PaintWindowCount())
151 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId);
152 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
153 return rOutDev.LogicToPixel (rSize);
155 else
156 return Size();
162 /** First subtract the window origin to make the point coordinates relative
163 to the window and then transform them into internal coordinates.
165 Point AccessibleViewForwarder::PixelToLogic (const Point& rPoint) const
167 OSL_ASSERT (mpView != NULL);
168 if((sal_uInt32)mnWindowId < mpView->PaintWindowCount())
170 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId);
171 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
172 Rectangle aBBox (static_cast<Window&>(rOutDev).GetWindowExtentsRelative(0L));
173 return rOutDev.PixelToLogic (rPoint - aBBox.TopLeft());
175 else
176 return Point();
182 Size AccessibleViewForwarder::PixelToLogic (const Size& rSize) const
184 OSL_ASSERT (mpView != NULL);
185 if((sal_uInt32)mnWindowId < mpView->PaintWindowCount())
187 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId);
188 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
189 return rOutDev.PixelToLogic (rSize);
191 else
192 return Size();
196 } // end of namespace accessibility