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