LibreOffice Module sw (master)  1
PageMarginUtils.hxx
Go to the documentation of this file.
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 #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
28 
29 namespace sw { namespace sidebar{
30 
31 bool IsNone( const long nPageLeftMargin, const long nPageRightMargin,
32  const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
33 {
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 );
39 }
40 
41 void SetNone( long& nPageLeftMargin, long& nPageRightMargin,
42  long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored)
43 {
44  nPageLeftMargin = SWPAGE_NO_MARGIN;
45  nPageRightMargin = SWPAGE_NO_MARGIN;
46  nPageTopMargin = SWPAGE_NO_MARGIN;
47  nPageBottomMargin = SWPAGE_NO_MARGIN;
48  bMirrored = false;
49 }
50 
51 bool IsNarrow( const long nPageLeftMargin, const long nPageRightMargin,
52  const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
53 {
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 );
59 }
60 
61 void SetNarrow( long& nPageLeftMargin, long& nPageRightMargin,
62  long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored)
63 {
64  nPageLeftMargin = SWPAGE_NARROW_VALUE;
65  nPageRightMargin = SWPAGE_NARROW_VALUE;
66  nPageTopMargin = SWPAGE_NARROW_VALUE;
67  nPageBottomMargin = SWPAGE_NARROW_VALUE;
68  bMirrored = false;
69 }
70 
71 bool IsModerate( const long nPageLeftMargin, const long nPageRightMargin,
72  const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
73 {
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 );
79 }
80 
81 void SetModerate( long& nPageLeftMargin, long& nPageRightMargin,
82  long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored)
83 {
84  nPageLeftMargin = SWPAGE_MODERATE_LR;
85  nPageRightMargin = SWPAGE_MODERATE_LR;
86  nPageTopMargin = SWPAGE_WIDE_VALUE1;
87  nPageBottomMargin = SWPAGE_WIDE_VALUE1;
88  bMirrored = false;
89 }
90 
91 bool IsNormal075( const long nPageLeftMargin, const long nPageRightMargin,
92  const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
93 {
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 );
99 }
100 
101 void SetNormal075( long& nPageLeftMargin, long& nPageRightMargin,
102  long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored)
103 {
104  nPageLeftMargin = SWPAGE_NORMAL_VALUE;
105  nPageRightMargin = SWPAGE_NORMAL_VALUE;
106  nPageTopMargin = SWPAGE_NORMAL_VALUE;
107  nPageBottomMargin = SWPAGE_NORMAL_VALUE;
108  bMirrored = false;
109 }
110 
111 bool IsNormal100( const long nPageLeftMargin, const long nPageRightMargin,
112  const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
113 {
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 );
119 }
120 
121 void SetNormal100( long& nPageLeftMargin, long& nPageRightMargin,
122  long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored)
123 {
124  nPageLeftMargin = SWPAGE_WIDE_VALUE1;
125  nPageRightMargin = SWPAGE_WIDE_VALUE1;
126  nPageTopMargin = SWPAGE_WIDE_VALUE1;
127  nPageBottomMargin = SWPAGE_WIDE_VALUE1;
128  bMirrored = false;
129 }
130 
131 bool IsNormal125( const long nPageLeftMargin, const long nPageRightMargin,
132  const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
133 {
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 );
139 }
140 
141 void SetNormal125( long& nPageLeftMargin, long& nPageRightMargin,
142  long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored)
143 {
144  nPageLeftMargin = SWPAGE_WIDE_VALUE3;
145  nPageRightMargin = SWPAGE_WIDE_VALUE3;
146  nPageTopMargin = SWPAGE_WIDE_VALUE1;
147  nPageBottomMargin = SWPAGE_WIDE_VALUE1;
148  bMirrored = false;
149 }
150 
151 bool IsWide( const long nPageLeftMargin, const long nPageRightMargin,
152  const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
153 {
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 );
159 }
160 
161 void SetWide( long& nPageLeftMargin, long& nPageRightMargin,
162  long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored)
163 {
164  nPageLeftMargin = SWPAGE_WIDE_VALUE2;
165  nPageRightMargin = SWPAGE_WIDE_VALUE2;
166  nPageTopMargin = SWPAGE_WIDE_VALUE1;
167  nPageBottomMargin = SWPAGE_WIDE_VALUE1;
168  bMirrored = false;
169 }
170 
171 bool IsMirrored( const long nPageLeftMargin, const long nPageRightMargin,
172  const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
173 {
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 );
179 }
180 
181 void SetMirrored( long& nPageLeftMargin, long& nPageRightMargin,
182  long& nPageTopMargin, long& nPageBottomMargin, bool& bMirrored)
183 {
184  nPageLeftMargin = SWPAGE_WIDE_VALUE3;
185  nPageRightMargin = SWPAGE_WIDE_VALUE1;
186  nPageTopMargin = SWPAGE_WIDE_VALUE1;
187  nPageBottomMargin = SWPAGE_WIDE_VALUE1;
188  bMirrored = true;
189 }
190 } }
191 
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetNormal100(long &nPageLeftMargin, long &nPageRightMargin, long &nPageTopMargin, long &nPageBottomMargin, bool &bMirrored)
bool IsNarrow(const long nPageLeftMargin, const long nPageRightMargin, const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
Dialog to specify the properties of date form field.
Definition: accfrmobj.cxx:40
bool IsNormal075(const long nPageLeftMargin, const long nPageRightMargin, const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
void SetNarrow(long &nPageLeftMargin, long &nPageRightMargin, long &nPageTopMargin, long &nPageBottomMargin, bool &bMirrored)
bool IsMirrored(const long nPageLeftMargin, const long nPageRightMargin, const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
#define SWPAGE_WIDE_VALUE1
#define SWPAGE_NO_MARGIN
#define SWPAGE_WIDE_VALUE3
void SetWide(long &nPageLeftMargin, long &nPageRightMargin, long &nPageTopMargin, long &nPageBottomMargin, bool &bMirrored)
bool IsWide(const long nPageLeftMargin, const long nPageRightMargin, const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
#define SWPAGE_WIDE_VALUE2
#define SWPAGE_NORMAL_VALUE
void SetNone(long &nPageLeftMargin, long &nPageRightMargin, long &nPageTopMargin, long &nPageBottomMargin, bool &bMirrored)
void SetModerate(long &nPageLeftMargin, long &nPageRightMargin, long &nPageTopMargin, long &nPageBottomMargin, bool &bMirrored)
#define SWPAGE_UNIT_THRESHOLD
void SetNormal125(long &nPageLeftMargin, long &nPageRightMargin, long &nPageTopMargin, long &nPageBottomMargin, bool &bMirrored)
void SetMirrored(long &nPageLeftMargin, long &nPageRightMargin, long &nPageTopMargin, long &nPageBottomMargin, bool &bMirrored)
#define SWPAGE_NARROW_VALUE
bool IsNormal100(const long nPageLeftMargin, const long nPageRightMargin, const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
#define SWPAGE_MODERATE_LR
bool IsNormal125(const long nPageLeftMargin, const long nPageRightMargin, const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
bool IsNone(const long nPageLeftMargin, const long nPageRightMargin, const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
void SetNormal075(long &nPageLeftMargin, long &nPageRightMargin, long &nPageTopMargin, long &nPageBottomMargin, bool &bMirrored)
bool IsModerate(const long nPageLeftMargin, const long nPageRightMargin, const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)