|
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* ex: set tabstop=8 softtabstop=4 shiftwidth=4 expandtab: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 |
|
8 #ifndef _PAPERPS_H_ |
|
9 #define _PAPERPS_H_ |
|
10 |
|
11 #include "nsDebug.h" |
|
12 |
|
13 struct nsPaperSizePS_ { |
|
14 const char *name; |
|
15 float width_mm; |
|
16 float height_mm; |
|
17 bool isMetric; // Present to the user in metric, if possible |
|
18 }; |
|
19 |
|
20 class nsPaperSizePS { |
|
21 public: |
|
22 /** --------------------------------------------------- |
|
23 * Constructor |
|
24 */ |
|
25 nsPaperSizePS() { mCurrent = 0; } |
|
26 |
|
27 /** --------------------------------------------------- |
|
28 * @return true if the cursor points past the last item. |
|
29 */ |
|
30 bool AtEnd() { return mCurrent >= mCount; } |
|
31 |
|
32 /** --------------------------------------------------- |
|
33 * Position the cursor at the beginning of the paper size list. |
|
34 * @return VOID |
|
35 */ |
|
36 void First() { mCurrent = 0; } |
|
37 |
|
38 /** --------------------------------------------------- |
|
39 * Advance the cursor to the next item. |
|
40 * @return VOID |
|
41 */ |
|
42 void Next() { |
|
43 NS_ASSERTION(!AtEnd(), "Invalid current item"); |
|
44 mCurrent++; |
|
45 } |
|
46 |
|
47 /** --------------------------------------------------- |
|
48 * Point the cursor to the entry with the given paper name. |
|
49 * @return true if pointing to a valid entry. |
|
50 */ |
|
51 bool Find(const char *aName); |
|
52 |
|
53 /** --------------------------------------------------- |
|
54 * @return a pointer to the name of the current paper size |
|
55 */ |
|
56 const char *Name() { |
|
57 NS_PRECONDITION(!AtEnd(), "Invalid current item"); |
|
58 return mList[mCurrent].name; |
|
59 } |
|
60 |
|
61 /** --------------------------------------------------- |
|
62 * @return the width of the page in millimeters |
|
63 */ |
|
64 float Width_mm() { |
|
65 NS_PRECONDITION(!AtEnd(), "Invalid current item"); |
|
66 return mList[mCurrent].width_mm; |
|
67 } |
|
68 |
|
69 /** --------------------------------------------------- |
|
70 * @return the height of the page in millimeters |
|
71 */ |
|
72 float Height_mm() { |
|
73 NS_PRECONDITION(!AtEnd(), "Invalid current item"); |
|
74 return mList[mCurrent].height_mm; |
|
75 } |
|
76 |
|
77 /** --------------------------------------------------- |
|
78 * @return true if the paper should be presented to |
|
79 * the user in metric units. |
|
80 */ |
|
81 bool IsMetric() { |
|
82 NS_PRECONDITION(!AtEnd(), "Invalid current item"); |
|
83 return mList[mCurrent].isMetric; |
|
84 } |
|
85 |
|
86 private: |
|
87 unsigned int mCurrent; |
|
88 static const nsPaperSizePS_ mList[]; |
|
89 static const unsigned int mCount; |
|
90 }; |
|
91 |
|
92 #endif |
|
93 |