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 .
20 #ifndef INCLUDED_VCL_FRAMEPOSSIZE_HXX
21 #define INCLUDED_VCL_FRAMEPOSSIZE_HXX
23 #include <vcl/dllapi.h>
24 #include <o3tl/typed_flags_set.hxx>
25 #include <rtl/string.hxx>
26 #include <sal/types.h>
27 #include <tools/gen.hxx>
32 * There are multiple ways to store the two different areas of a vcl::Window.
33 * But this representation is hopefully less error prone from the used types
34 * and more clear in what values in- or exclude the non-drawable window frame.
36 * There are especially two things to remember:
37 * * pos() is the top-left position of the window frame
38 * * size() returns just the drawable client area
40 * So these values actually don't represent any "real" geometry of either the
41 * outer frame or the inner client area of the window. That's my reason for
42 * naming the rectangle function posSize() instead of geometry(). Also to not
43 * be confused with Qt's geometry() function. YMMV.
45 * LO already is supposed to use this schema. FWIW, the Qt documentation claims
46 * "The differentiation is done in a way that covers the most common usage
47 * transparently." AFAIK this is common for most/all platforms / UI toolkits.
49 * The API is kept largely overload free, as we can now use list-initialization.
51 class VCL_PLUGIN_PUBLIC WindowPosSize
53 // position of the window frames left-top corner
56 // size of the client / drawable area, i.e. without decorations / borders
70 constexpr sal_Int32
x() const { return m_nX
; }
71 void setX(sal_Int32 nX
) { m_nX
= nX
; }
72 constexpr sal_Int32
y() const { return m_nY
; }
73 void setY(sal_Int32 nY
) { m_nY
= nY
; }
75 constexpr Point
pos() const { return { m_nX
, m_nY
}; }
76 void setPos(const Point
& aPos
)
81 void move(sal_Int32 nDX
, sal_Int32 nDY
)
87 constexpr sal_Int32
width() const { return m_nWidth
; }
88 void setWidth(sal_Int32 nWidth
)
97 constexpr sal_Int32
height() const { return m_nHeight
; }
98 void setHeight(sal_Int32 nHeight
)
100 assert(nHeight
>= 0);
107 constexpr Size
size() const
109 return { static_cast<tools::Long
>(m_nWidth
), static_cast<tools::Long
>(m_nHeight
) };
111 void setSize(const Size
& rSize
)
113 setWidth(rSize
.Width());
114 setHeight(rSize
.Height());
117 constexpr tools::Rectangle
posSize() const { return { pos(), size() }; }
118 void setPosSize(const tools::Rectangle
& rRect
)
120 setPos(rRect
.GetPos());
121 setSize(rRect
.GetSize());
123 // because tools::Rectangle has the ambiguous (Point&, Point&) constructor, which we don't want here
124 void setPosSize(const Point
& rPos
, const Size
& rSize
) { setPosSize({ rPos
, rSize
}); }
127 inline std::ostream
& operator<<(std::ostream
& s
, const WindowPosSize
& rPosSize
)
129 s
<< rPosSize
.width() << "x" << rPosSize
.height() << "@(" << rPosSize
.x() << "," << rPosSize
.y()
136 #endif // INCLUDED_VCL_FRAMEPOSSIZE_HXX
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */