/src/libreoffice/include/vcl/WindowPosSize.hxx
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #ifndef INCLUDED_VCL_FRAMEPOSSIZE_HXX |
21 | | #define INCLUDED_VCL_FRAMEPOSSIZE_HXX |
22 | | |
23 | | #include <vcl/dllapi.h> |
24 | | #include <sal/types.h> |
25 | | #include <tools/gen.hxx> |
26 | | |
27 | | namespace vcl |
28 | | { |
29 | | /** |
30 | | * There are multiple ways to store the two different areas of a vcl::Window. |
31 | | * But this representation is hopefully less error prone from the used types |
32 | | * and more clear in what values in- or exclude the non-drawable window frame. |
33 | | * |
34 | | * There are especially two things to remember: |
35 | | * * pos() is the top-left position of the window frame |
36 | | * * size() returns just the drawable client area |
37 | | * |
38 | | * So these values actually don't represent any "real" geometry of either the |
39 | | * outer frame or the inner client area of the window. That's my reason for |
40 | | * naming the rectangle function posSize() instead of geometry(). Also to not |
41 | | * be confused with Qt's geometry() function. YMMV. |
42 | | * |
43 | | * LO already is supposed to use this schema. FWIW, the Qt documentation claims |
44 | | * "The differentiation is done in a way that covers the most common usage |
45 | | * transparently." AFAIK this is common for most/all platforms / UI toolkits. |
46 | | * |
47 | | * The API is kept largely overload free, as we can now use list-initialization. |
48 | | */ |
49 | | class VCL_PLUGIN_PUBLIC WindowPosSize |
50 | | { |
51 | | // position of the window frames left-top corner |
52 | | sal_Int32 m_nX; |
53 | | sal_Int32 m_nY; |
54 | | // size of the client / drawable area, i.e. without decorations / borders |
55 | | sal_Int32 m_nWidth; |
56 | | sal_Int32 m_nHeight; |
57 | | |
58 | | protected: |
59 | | WindowPosSize() |
60 | 12.7k | : m_nX(0) |
61 | 12.7k | , m_nY(0) |
62 | 12.7k | , m_nWidth(1) |
63 | 12.7k | , m_nHeight(1) |
64 | 12.7k | { |
65 | 12.7k | } |
66 | | |
67 | | public: |
68 | 0 | constexpr sal_Int32 x() const { return m_nX; } |
69 | 0 | void setX(sal_Int32 nX) { m_nX = nX; } |
70 | 0 | constexpr sal_Int32 y() const { return m_nY; } |
71 | 0 | void setY(sal_Int32 nY) { m_nY = nY; } |
72 | | |
73 | 0 | constexpr Point pos() const { return { m_nX, m_nY }; } |
74 | | void setPos(const Point& aPos) |
75 | 0 | { |
76 | 0 | setX(aPos.getX()); |
77 | 0 | setY(aPos.getY()); |
78 | 0 | } |
79 | | void move(sal_Int32 nDX, sal_Int32 nDY) |
80 | 0 | { |
81 | 0 | m_nX += nDX; |
82 | 0 | m_nY += nDY; |
83 | 0 | } |
84 | | |
85 | 178k | constexpr sal_Int32 width() const { return m_nWidth; } |
86 | | void setWidth(sal_Int32 nWidth) |
87 | 12.7k | { |
88 | 12.7k | assert(nWidth >= 0); |
89 | 12.7k | if (nWidth >= 0) |
90 | 12.7k | m_nWidth = nWidth; |
91 | 0 | else |
92 | 0 | m_nWidth = 0; |
93 | 12.7k | } |
94 | | |
95 | 178k | constexpr sal_Int32 height() const { return m_nHeight; } |
96 | | void setHeight(sal_Int32 nHeight) |
97 | 12.7k | { |
98 | 12.7k | assert(nHeight >= 0); |
99 | 12.7k | if (nHeight >= 0) |
100 | 12.7k | m_nHeight = nHeight; |
101 | 0 | else |
102 | 0 | m_nHeight = 0; |
103 | 12.7k | } |
104 | | |
105 | | constexpr Size size() const |
106 | 0 | { |
107 | 0 | return { static_cast<tools::Long>(m_nWidth), static_cast<tools::Long>(m_nHeight) }; |
108 | 0 | } |
109 | | void setSize(const Size& rSize) |
110 | 0 | { |
111 | 0 | setWidth(rSize.Width()); |
112 | 0 | setHeight(rSize.Height()); |
113 | 0 | } |
114 | | |
115 | 0 | constexpr tools::Rectangle posSize() const { return { pos(), size() }; } |
116 | | void setPosSize(const tools::Rectangle& rRect) |
117 | 0 | { |
118 | 0 | setPos(rRect.GetPos()); |
119 | 0 | setSize(rRect.GetSize()); |
120 | 0 | } |
121 | | // because tools::Rectangle has the ambiguous (Point&, Point&) constructor, which we don't want here |
122 | 0 | void setPosSize(const Point& rPos, const Size& rSize) { setPosSize({ rPos, rSize }); } |
123 | | }; |
124 | | |
125 | | inline std::ostream& operator<<(std::ostream& s, const WindowPosSize& rPosSize) |
126 | 0 | { |
127 | 0 | s << rPosSize.width() << "x" << rPosSize.height() << "@(" << rPosSize.x() << "," << rPosSize.y() |
128 | 0 | << ")"; |
129 | 0 | return s; |
130 | 0 | } |
131 | | |
132 | | } // namespace vcl |
133 | | |
134 | | #endif // INCLUDED_VCL_FRAMEPOSSIZE_HXX |
135 | | |
136 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |