Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / source / uibase / sidebar / PageMarginUtils.hxx
blob7e29cef6d6b439457de63fbead46aad6656c9989
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 .
19 #include <cmath>
20 #define SWPAGE_NO_MARGIN 0
21 #define SWPAGE_NARROW_VALUE 720
22 #define SWPAGE_MODERATE_LR 1080
23 #define SWPAGE_NORMAL_VALUE 1136
24 #define SWPAGE_WIDE_VALUE1 1440
25 #define SWPAGE_WIDE_VALUE2 2880
26 #define SWPAGE_WIDE_VALUE3 1800
27 #define SWPAGE_UNIT_THRESHOLD 5
29 namespace sw { namespace sidebar{
31 bool IsNone( const long nPageLeftMargin, const long nPageRightMargin,
32 const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
34 return( std::abs(nPageLeftMargin - SWPAGE_NO_MARGIN) <= SWPAGE_UNIT_THRESHOLD &&
35 std::abs(nPageRightMargin - SWPAGE_NO_MARGIN ) <= SWPAGE_UNIT_THRESHOLD &&
36 std::abs(nPageTopMargin - SWPAGE_NO_MARGIN) <= SWPAGE_UNIT_THRESHOLD &&
37 std::abs(nPageBottomMargin - SWPAGE_NO_MARGIN) <= SWPAGE_UNIT_THRESHOLD &&
38 !bMirrored );
41 void SetNone( long& nPageLeftMargin, long& nPageRightMargin,
42 long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored)
44 nPageLeftMargin = SWPAGE_NO_MARGIN;
45 nPageRightMargin = SWPAGE_NO_MARGIN;
46 nPageTopMargin = SWPAGE_NO_MARGIN;
47 nPageBottomMargin = SWPAGE_NO_MARGIN;
48 bMirrored = false;
51 bool IsNarrow( const long nPageLeftMargin, const long nPageRightMargin,
52 const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
54 return( std::abs(nPageLeftMargin - SWPAGE_NARROW_VALUE) <= SWPAGE_UNIT_THRESHOLD &&
55 std::abs(nPageRightMargin - SWPAGE_NARROW_VALUE) <= SWPAGE_UNIT_THRESHOLD &&
56 std::abs(nPageTopMargin - SWPAGE_NARROW_VALUE) <= SWPAGE_UNIT_THRESHOLD &&
57 std::abs(nPageBottomMargin - SWPAGE_NARROW_VALUE) <= SWPAGE_UNIT_THRESHOLD &&
58 !bMirrored );
61 void SetNarrow( long& nPageLeftMargin, long& nPageRightMargin,
62 long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored)
64 nPageLeftMargin = SWPAGE_NARROW_VALUE;
65 nPageRightMargin = SWPAGE_NARROW_VALUE;
66 nPageTopMargin = SWPAGE_NARROW_VALUE;
67 nPageBottomMargin = SWPAGE_NARROW_VALUE;
68 bMirrored = false;
71 bool IsModerate( const long nPageLeftMargin, const long nPageRightMargin,
72 const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
74 return( std::abs(nPageLeftMargin - SWPAGE_MODERATE_LR) <= SWPAGE_UNIT_THRESHOLD &&
75 std::abs(nPageRightMargin - SWPAGE_MODERATE_LR) <= SWPAGE_UNIT_THRESHOLD &&
76 std::abs(nPageTopMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
77 std::abs(nPageBottomMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
78 !bMirrored );
81 void SetModerate( long& nPageLeftMargin, long& nPageRightMargin,
82 long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored)
84 nPageLeftMargin = SWPAGE_MODERATE_LR;
85 nPageRightMargin = SWPAGE_MODERATE_LR;
86 nPageTopMargin = SWPAGE_WIDE_VALUE1;
87 nPageBottomMargin = SWPAGE_WIDE_VALUE1;
88 bMirrored = false;
91 bool IsNormal075( const long nPageLeftMargin, const long nPageRightMargin,
92 const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
94 return( std::abs(nPageLeftMargin - SWPAGE_NORMAL_VALUE) <= SWPAGE_UNIT_THRESHOLD &&
95 std::abs(nPageRightMargin - SWPAGE_NORMAL_VALUE) <= SWPAGE_UNIT_THRESHOLD &&
96 std::abs(nPageTopMargin - SWPAGE_NORMAL_VALUE) <= SWPAGE_UNIT_THRESHOLD &&
97 std::abs(nPageBottomMargin - SWPAGE_NORMAL_VALUE) <= SWPAGE_UNIT_THRESHOLD &&
98 !bMirrored );
101 void SetNormal075( long& nPageLeftMargin, long& nPageRightMargin,
102 long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored)
104 nPageLeftMargin = SWPAGE_NORMAL_VALUE;
105 nPageRightMargin = SWPAGE_NORMAL_VALUE;
106 nPageTopMargin = SWPAGE_NORMAL_VALUE;
107 nPageBottomMargin = SWPAGE_NORMAL_VALUE;
108 bMirrored = false;
111 bool IsNormal100( const long nPageLeftMargin, const long nPageRightMargin,
112 const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
114 return( std::abs(nPageLeftMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
115 std::abs(nPageRightMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
116 std::abs(nPageTopMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
117 std::abs(nPageBottomMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
118 !bMirrored );
121 void SetNormal100( long& nPageLeftMargin, long& nPageRightMargin,
122 long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored)
124 nPageLeftMargin = SWPAGE_WIDE_VALUE1;
125 nPageRightMargin = SWPAGE_WIDE_VALUE1;
126 nPageTopMargin = SWPAGE_WIDE_VALUE1;
127 nPageBottomMargin = SWPAGE_WIDE_VALUE1;
128 bMirrored = false;
131 bool IsNormal125( const long nPageLeftMargin, const long nPageRightMargin,
132 const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
134 return( std::abs(nPageLeftMargin - SWPAGE_WIDE_VALUE3) <= SWPAGE_UNIT_THRESHOLD &&
135 std::abs(nPageRightMargin - SWPAGE_WIDE_VALUE3) <= SWPAGE_UNIT_THRESHOLD &&
136 std::abs(nPageTopMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
137 std::abs(nPageBottomMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
138 !bMirrored );
141 void SetNormal125( long& nPageLeftMargin, long& nPageRightMargin,
142 long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored)
144 nPageLeftMargin = SWPAGE_WIDE_VALUE3;
145 nPageRightMargin = SWPAGE_WIDE_VALUE3;
146 nPageTopMargin = SWPAGE_WIDE_VALUE1;
147 nPageBottomMargin = SWPAGE_WIDE_VALUE1;
148 bMirrored = false;
151 bool IsWide( const long nPageLeftMargin, const long nPageRightMargin,
152 const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
154 return( std::abs(nPageLeftMargin - SWPAGE_WIDE_VALUE2) <= SWPAGE_UNIT_THRESHOLD &&
155 std::abs(nPageRightMargin - SWPAGE_WIDE_VALUE2) <= SWPAGE_UNIT_THRESHOLD &&
156 std::abs(nPageTopMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
157 std::abs(nPageBottomMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
158 !bMirrored );
161 void SetWide( long& nPageLeftMargin, long& nPageRightMargin,
162 long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored)
164 nPageLeftMargin = SWPAGE_WIDE_VALUE2;
165 nPageRightMargin = SWPAGE_WIDE_VALUE2;
166 nPageTopMargin = SWPAGE_WIDE_VALUE1;
167 nPageBottomMargin = SWPAGE_WIDE_VALUE1;
168 bMirrored = false;
171 bool IsMirrored( const long nPageLeftMargin, const long nPageRightMargin,
172 const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
174 return( std::abs(nPageLeftMargin - SWPAGE_WIDE_VALUE3) <= SWPAGE_UNIT_THRESHOLD &&
175 std::abs(nPageRightMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
176 std::abs(nPageTopMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
177 std::abs(nPageBottomMargin - SWPAGE_WIDE_VALUE1) <= SWPAGE_UNIT_THRESHOLD &&
178 bMirrored );
181 void SetMirrored( long& nPageLeftMargin, long& nPageRightMargin,
182 long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored)
184 nPageLeftMargin = SWPAGE_WIDE_VALUE3;
185 nPageRightMargin = SWPAGE_WIDE_VALUE1;
186 nPageTopMargin = SWPAGE_WIDE_VALUE1;
187 nPageBottomMargin = SWPAGE_WIDE_VALUE1;
188 bMirrored = true;
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */