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 31 #ifndef _SVX_ACCESSIBILITY_ACCESSIBLE_VIEW_FORWARDER_HXX 32 #include "AccessibleViewForwarder.hxx" 33 #endif 34 #include <svx/svdpntv.hxx> 35 #include <vcl/outdev.hxx> 36 #include <svx/sdrpaintwindow.hxx> 37 38 namespace accessibility { 39 40 /** For the time beeing, the implementation of this class will not use the 41 member mrDevice. Instead the device is retrieved from the view 42 everytime it is used. This is necessary because the device has to stay 43 up-to-date with the current view and the class has to stay compatible. 44 May change in the future. 45 */ 46 47 AccessibleViewForwarder::AccessibleViewForwarder (SdrPaintView* pView, OutputDevice& rDevice) 48 : mpView (pView), 49 mnWindowId (0), 50 mrDevice (rDevice) 51 { 52 // Search the output device to determine its id. 53 for(sal_uInt32 a(0L); a < mpView->PaintWindowCount(); a++) 54 { 55 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow(a); 56 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice(); 57 58 if(&rOutDev == &rDevice) 59 { 60 mnWindowId = (sal_uInt16)a; 61 break; 62 } 63 } 64 } 65 66 67 68 69 AccessibleViewForwarder::~AccessibleViewForwarder (void) 70 { 71 // empty 72 } 73 74 75 76 77 sal_Bool AccessibleViewForwarder::IsValid (void) const 78 { 79 return sal_True; 80 } 81 82 83 84 85 Rectangle AccessibleViewForwarder::GetVisibleArea (void) const 86 { 87 Rectangle aVisibleArea; 88 89 if((sal_uInt32)mnWindowId < mpView->PaintWindowCount()) 90 { 91 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId); 92 aVisibleArea = pPaintWindow->GetVisibleArea(); 93 } 94 95 return aVisibleArea; 96 } 97 98 99 100 101 /** Tansform the given point into pixel coordiantes. After the the pixel 102 coordiantes of the window origin are added to make the point coordinates 103 absolute. 104 */ 105 Point AccessibleViewForwarder::LogicToPixel (const Point& rPoint) const 106 { 107 OSL_ASSERT (mpView != NULL); 108 if((sal_uInt32)mnWindowId < mpView->PaintWindowCount()) 109 { 110 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId); 111 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice(); 112 Rectangle aBBox(static_cast<Window&>(rOutDev).GetWindowExtentsRelative(0L)); 113 return rOutDev.LogicToPixel (rPoint) + aBBox.TopLeft(); 114 } 115 else 116 return Point(); 117 } 118 119 120 121 122 Size AccessibleViewForwarder::LogicToPixel (const Size& rSize) const 123 { 124 OSL_ASSERT (mpView != NULL); 125 if((sal_uInt32)mnWindowId < mpView->PaintWindowCount()) 126 { 127 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId); 128 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice(); 129 return rOutDev.LogicToPixel (rSize); 130 } 131 else 132 return Size(); 133 } 134 135 136 137 138 /** First subtract the window origin to make the point coordinates relative 139 to the window and then transform them into internal coordinates. 140 */ 141 Point AccessibleViewForwarder::PixelToLogic (const Point& rPoint) const 142 { 143 OSL_ASSERT (mpView != NULL); 144 if((sal_uInt32)mnWindowId < mpView->PaintWindowCount()) 145 { 146 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId); 147 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice(); 148 Rectangle aBBox (static_cast<Window&>(rOutDev).GetWindowExtentsRelative(0L)); 149 return rOutDev.PixelToLogic (rPoint - aBBox.TopLeft()); 150 } 151 else 152 return Point(); 153 } 154 155 156 157 158 Size AccessibleViewForwarder::PixelToLogic (const Size& rSize) const 159 { 160 OSL_ASSERT (mpView != NULL); 161 if((sal_uInt32)mnWindowId < mpView->PaintWindowCount()) 162 { 163 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId); 164 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice(); 165 return rOutDev.PixelToLogic (rSize); 166 } 167 else 168 return Size(); 169 } 170 171 172 } // end of namespace accessibility 173