1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include "AccessibleViewForwarder.hxx"
22 #include <svx/svdpntv.hxx>
23 #include <vcl/outdev.hxx>
24 #include <svx/sdrpaintwindow.hxx>
26 namespace accessibility
{
28 /** For the time beeing, the implementation of this class will not use the
29 member mrDevice. Instead the device is retrieved from the view
30 everytime it is used. This is necessary because the device has to stay
31 up-to-date with the current view and the class has to stay compatible.
32 May change in the future.
35 AccessibleViewForwarder::AccessibleViewForwarder (SdrPaintView
* pView
, OutputDevice
& rDevice
)
40 // Search the output device to determine its id.
41 for(sal_uInt32
a(0L); a
< mpView
->PaintWindowCount(); a
++)
43 SdrPaintWindow
* pPaintWindow
= mpView
->GetPaintWindow(a
);
44 OutputDevice
& rOutDev
= pPaintWindow
->GetOutputDevice();
46 if(&rOutDev
== &rDevice
)
48 mnWindowId
= (sal_uInt16
)a
;
57 AccessibleViewForwarder::~AccessibleViewForwarder (void)
65 sal_Bool
AccessibleViewForwarder::IsValid (void) const
73 Rectangle
AccessibleViewForwarder::GetVisibleArea (void) const
75 Rectangle aVisibleArea
;
77 if((sal_uInt32
)mnWindowId
< mpView
->PaintWindowCount())
79 SdrPaintWindow
* pPaintWindow
= mpView
->GetPaintWindow((sal_uInt32
)mnWindowId
);
80 aVisibleArea
= pPaintWindow
->GetVisibleArea();
89 /** Tansform the given point into pixel coordiantes. After the pixel
90 coordiantes of the window origin are added to make the point coordinates
93 Point
AccessibleViewForwarder::LogicToPixel (const Point
& rPoint
) const
95 OSL_ASSERT (mpView
!= NULL
);
96 if((sal_uInt32
)mnWindowId
< mpView
->PaintWindowCount())
98 SdrPaintWindow
* pPaintWindow
= mpView
->GetPaintWindow((sal_uInt32
)mnWindowId
);
99 OutputDevice
& rOutDev
= pPaintWindow
->GetOutputDevice();
100 Rectangle
aBBox(static_cast<Window
&>(rOutDev
).GetWindowExtentsRelative(0L));
101 return rOutDev
.LogicToPixel (rPoint
) + aBBox
.TopLeft();
110 Size
AccessibleViewForwarder::LogicToPixel (const Size
& rSize
) 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 return rOutDev
.LogicToPixel (rSize
);
126 /** First subtract the window origin to make the point coordinates relative
127 to the window and then transform them into internal coordinates.
129 Point
AccessibleViewForwarder::PixelToLogic (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
.PixelToLogic (rPoint
- aBBox
.TopLeft());
143 Size
AccessibleViewForwarder::PixelToLogic (const Size
& rSize
) const
145 OSL_ASSERT (mpView
!= NULL
);
146 if((sal_uInt32
)mnWindowId
< mpView
->PaintWindowCount())
148 SdrPaintWindow
* pPaintWindow
= mpView
->GetPaintWindow((sal_uInt32
)mnWindowId
);
149 OutputDevice
& rOutDev
= pPaintWindow
->GetOutputDevice();
150 return rOutDev
.PixelToLogic (rSize
);
157 } // end of namespace accessibility
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */