summaryrefslogtreecommitdiffstats
path: root/include/vcl/windowstate.hxx
blob: 527e3661e9cea6acfc9dba36d7f88ba8fa2e3369 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_VCL_WINDOWSTATE_HXX
#define INCLUDED_VCL_WINDOWSTATE_HXX

#include <vcl/WindowPosSize.hxx>

namespace vcl
{
enum class WindowState
{
    NONE = 0x0000,
    Normal = 0x0001,
    Minimized = 0x0002,
    Maximized = 0x0004,
    // Rollup is no longer used, but the bit is retained because WindowData is serialized
    // from/to strings describing window state that are stored in a users config
    // Rollup = 0x0008,
    MaximizedHorz = 0x0010,
    MaximizedVert = 0x0020,
    FullScreen = 0x0040,
    SystemMask = 0xffff
};

enum class WindowDataMask
{
    NONE = 0x0000,
    X = 0x0001,
    Y = 0x0002,
    Width = 0x0004,
    Height = 0x0008,
    State = 0x0010,
    Minimized = 0x0020,
    MaximizedX = 0x0100,
    MaximizedY = 0x0200,
    MaximizedWidth = 0x0400,
    MaximizedHeight = 0x0800,
    Pos = X | Y,
    Size = Width | Height,
    PosSize = Pos | Size,
    PosSizeState = Pos | Size | State,
    All = X | Y | Width | Height | MaximizedX | MaximizedY | MaximizedWidth | MaximizedHeight
          | State | Minimized
};

class VCL_PLUGIN_PUBLIC WindowData final : public WindowPosSize
{
    WindowState m_nState;
    WindowDataMask m_nMask;

    int mnMaximizedX;
    int mnMaximizedY;
    unsigned int mnMaximizedWidth;
    unsigned int mnMaximizedHeight;

public:
    WindowData()
        : m_nState(WindowState::NONE)
        , m_nMask(WindowDataMask::NONE)
        , mnMaximizedX(0)
        , mnMaximizedY(0)
        , mnMaximizedWidth(0)
        , mnMaximizedHeight(0)
    {
    }
    WindowData(std::u16string_view rStr);

    // serialize values to a string (the original WindowState representation)
    OUString toStr() const;

    void setState(WindowState nState) { m_nState = nState; }
    WindowState state() const { return m_nState; }
    WindowState& rState() { return m_nState; }

    void setMask(WindowDataMask nMask) { m_nMask = nMask; }
    WindowDataMask mask() const { return m_nMask; }
    WindowDataMask& rMask() { return m_nMask; }

    void SetMaximizedX(int nRX) { mnMaximizedX = nRX; }
    int GetMaximizedX() const { return mnMaximizedX; }
    void SetMaximizedY(int nRY) { mnMaximizedY = nRY; }
    int GetMaximizedY() const { return mnMaximizedY; }
    void SetMaximizedWidth(unsigned int nRWidth) { mnMaximizedWidth = nRWidth; }
    unsigned int GetMaximizedWidth() const { return mnMaximizedWidth; }
    void SetMaximizedHeight(unsigned int nRHeight) { mnMaximizedHeight = nRHeight; }
    unsigned int GetMaximizedHeight() const { return mnMaximizedHeight; }
};

} // namespace vcl

namespace o3tl
{
template <> struct typed_flags<vcl::WindowState> : is_typed_flags<vcl::WindowState, 0xffff>
{
};
template <> struct typed_flags<vcl::WindowDataMask> : is_typed_flags<vcl::WindowDataMask, 0x0f3f>
{
};
}

namespace vcl
{
inline std::ostream& operator<<(std::ostream& s, const WindowData& rData)
{
    if (rData.mask() & WindowDataMask::Width)
        s << rData.width() << "x";
    else
        s << "?x";
    if (rData.mask() & WindowDataMask::Height)
        s << rData.height() << "@(";
    else
        s << "?@(";
    if (rData.mask() & WindowDataMask::X)
        s << rData.x() << ",";
    else
        s << "?,";
    if (rData.mask() & WindowDataMask::Y)
        s << rData.y() << ")^";
    else
        s << "?)^";
    if (rData.mask() & WindowDataMask::State)
        s << "0x" << std::hex << static_cast<unsigned>(rData.state()) << std::dec;
    else
        s << "?";
    return s;
}

} // namespace vcl

#endif // INCLUDED_VCL_WINDOWSTATE_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */