bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / accessibility / AccessibleViewForwarder.cxx
blobf110a6b676afd93292d0338aae7559dafbafedf8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "AccessibleViewForwarder.hxx"
21 #include <svx/svdpntv.hxx>
22 #include <vcl/outdev.hxx>
23 #include <svx/sdrpaintwindow.hxx>
25 namespace accessibility {
27 /** For the time being, the implementation of this class will not use the
28 member mrDevice. Instead the device is retrieved from the view
29 every time it is used. This is necessary because the device has to stay
30 up-to-date with the current view and the class has to stay compatible.
31 May change in the future.
34 AccessibleViewForwarder::AccessibleViewForwarder (SdrPaintView* pView, OutputDevice& rDevice)
35 : mpView (pView),
36 mnWindowId (0),
37 mrDevice (rDevice)
39 // Search the output device to determine its id.
40 for(sal_uInt32 a(0L); a < mpView->PaintWindowCount(); a++)
42 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow(a);
43 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
45 if(&rOutDev == &rDevice)
47 mnWindowId = (sal_uInt16)a;
48 break;
53 AccessibleViewForwarder::~AccessibleViewForwarder()
55 // empty
58 bool AccessibleViewForwarder::IsValid() const
60 return true;
63 Rectangle AccessibleViewForwarder::GetVisibleArea() const
65 Rectangle aVisibleArea;
67 if((sal_uInt32)mnWindowId < mpView->PaintWindowCount())
69 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId);
70 aVisibleArea = pPaintWindow->GetVisibleArea();
73 return aVisibleArea;
76 /** Tansform the given point into pixel coordiantes. After the pixel
77 coordiantes of the window origin are added to make the point coordinates
78 absolute.
80 Point AccessibleViewForwarder::LogicToPixel (const Point& rPoint) const
82 OSL_ASSERT (mpView != NULL);
83 if((sal_uInt32)mnWindowId < mpView->PaintWindowCount())
85 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId);
86 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
87 Rectangle aBBox(static_cast<vcl::Window&>(rOutDev).GetWindowExtentsRelative(0L));
88 return rOutDev.LogicToPixel (rPoint) + aBBox.TopLeft();
90 else
91 return Point();
94 Size AccessibleViewForwarder::LogicToPixel (const Size& rSize) const
96 OSL_ASSERT (mpView != NULL);
97 if((sal_uInt32)mnWindowId < mpView->PaintWindowCount())
99 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId);
100 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
101 return rOutDev.LogicToPixel (rSize);
103 else
104 return Size();
107 /** First subtract the window origin to make the point coordinates relative
108 to the window and then transform them into internal coordinates.
110 Point AccessibleViewForwarder::PixelToLogic (const Point& rPoint) const
112 OSL_ASSERT (mpView != NULL);
113 if((sal_uInt32)mnWindowId < mpView->PaintWindowCount())
115 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId);
116 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
117 Rectangle aBBox (static_cast<vcl::Window&>(rOutDev).GetWindowExtentsRelative(0L));
118 return rOutDev.PixelToLogic (rPoint - aBBox.TopLeft());
120 else
121 return Point();
124 Size AccessibleViewForwarder::PixelToLogic (const Size& rSize) const
126 OSL_ASSERT (mpView != NULL);
127 if((sal_uInt32)mnWindowId < mpView->PaintWindowCount())
129 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow((sal_uInt32)mnWindowId);
130 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
131 return rOutDev.PixelToLogic (rSize);
133 else
134 return Size();
137 } // end of namespace accessibility
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */