Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / vcl / WindowPosSize.hxx
blob6c5484c47b30da3d3f56049307daf1dd3c0edacc
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 #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>
29 namespace vcl
31 /**
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
54 sal_Int32 m_nX;
55 sal_Int32 m_nY;
56 // size of the client / drawable area, i.e. without decorations / borders
57 sal_Int32 m_nWidth;
58 sal_Int32 m_nHeight;
60 protected:
61 WindowPosSize()
62 : m_nX(0)
63 , m_nY(0)
64 , m_nWidth(1)
65 , m_nHeight(1)
69 public:
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)
78 setX(aPos.getX());
79 setY(aPos.getY());
81 void move(sal_Int32 nDX, sal_Int32 nDY)
83 m_nX += nDX;
84 m_nY += nDY;
87 constexpr sal_Int32 width() const { return m_nWidth; }
88 void setWidth(sal_Int32 nWidth)
90 assert(nWidth >= 0);
91 if (nWidth >= 0)
92 m_nWidth = nWidth;
93 else
94 m_nWidth = 0;
97 constexpr sal_Int32 height() const { return m_nHeight; }
98 void setHeight(sal_Int32 nHeight)
100 assert(nHeight >= 0);
101 if (nHeight >= 0)
102 m_nHeight = nHeight;
103 else
104 m_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()
130 << ")";
131 return s;
134 } // namespace vcl
136 #endif // INCLUDED_VCL_FRAMEPOSSIZE_HXX
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */