michael@0: /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* ex: set tabstop=8 softtabstop=4 shiftwidth=4 expandtab: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: #ifndef _PAPERPS_H_ michael@0: #define _PAPERPS_H_ michael@0: michael@0: #include "nsDebug.h" michael@0: michael@0: struct nsPaperSizePS_ { michael@0: const char *name; michael@0: float width_mm; michael@0: float height_mm; michael@0: bool isMetric; // Present to the user in metric, if possible michael@0: }; michael@0: michael@0: class nsPaperSizePS { michael@0: public: michael@0: /** --------------------------------------------------- michael@0: * Constructor michael@0: */ michael@0: nsPaperSizePS() { mCurrent = 0; } michael@0: michael@0: /** --------------------------------------------------- michael@0: * @return true if the cursor points past the last item. michael@0: */ michael@0: bool AtEnd() { return mCurrent >= mCount; } michael@0: michael@0: /** --------------------------------------------------- michael@0: * Position the cursor at the beginning of the paper size list. michael@0: * @return VOID michael@0: */ michael@0: void First() { mCurrent = 0; } michael@0: michael@0: /** --------------------------------------------------- michael@0: * Advance the cursor to the next item. michael@0: * @return VOID michael@0: */ michael@0: void Next() { michael@0: NS_ASSERTION(!AtEnd(), "Invalid current item"); michael@0: mCurrent++; michael@0: } michael@0: michael@0: /** --------------------------------------------------- michael@0: * Point the cursor to the entry with the given paper name. michael@0: * @return true if pointing to a valid entry. michael@0: */ michael@0: bool Find(const char *aName); michael@0: michael@0: /** --------------------------------------------------- michael@0: * @return a pointer to the name of the current paper size michael@0: */ michael@0: const char *Name() { michael@0: NS_PRECONDITION(!AtEnd(), "Invalid current item"); michael@0: return mList[mCurrent].name; michael@0: } michael@0: michael@0: /** --------------------------------------------------- michael@0: * @return the width of the page in millimeters michael@0: */ michael@0: float Width_mm() { michael@0: NS_PRECONDITION(!AtEnd(), "Invalid current item"); michael@0: return mList[mCurrent].width_mm; michael@0: } michael@0: michael@0: /** --------------------------------------------------- michael@0: * @return the height of the page in millimeters michael@0: */ michael@0: float Height_mm() { michael@0: NS_PRECONDITION(!AtEnd(), "Invalid current item"); michael@0: return mList[mCurrent].height_mm; michael@0: } michael@0: michael@0: /** --------------------------------------------------- michael@0: * @return true if the paper should be presented to michael@0: * the user in metric units. michael@0: */ michael@0: bool IsMetric() { michael@0: NS_PRECONDITION(!AtEnd(), "Invalid current item"); michael@0: return mList[mCurrent].isMetric; michael@0: } michael@0: michael@0: private: michael@0: unsigned int mCurrent; michael@0: static const nsPaperSizePS_ mList[]; michael@0: static const unsigned int mCount; michael@0: }; michael@0: michael@0: #endif michael@0: