MWAWPageSpan.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
00002 
00003 /* libmwaw
00004 * Version: MPL 2.0 / LGPLv2+
00005 *
00006 * The contents of this file are subject to the Mozilla Public License Version
00007 * 2.0 (the "License"); you may not use this file except in compliance with
00008 * the License or as specified alternatively below. You may obtain a copy of
00009 * the License at http://www.mozilla.org/MPL/
00010 *
00011 * Software distributed under the License is distributed on an "AS IS" basis,
00012 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 * for the specific language governing rights and limitations under the
00014 * License.
00015 *
00016 * Major Contributor(s):
00017 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00018 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
00019 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00020 * Copyright (C) 2006, 2007 Andrew Ziem
00021 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
00022 *
00023 *
00024 * All Rights Reserved.
00025 *
00026 * For minor contributions see the git repository.
00027 *
00028 * Alternatively, the contents of this file may be used under the terms of
00029 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00030 * in which case the provisions of the LGPLv2+ are applicable
00031 * instead of those above.
00032 */
00033 
00034 #ifndef MWAWPAGESPAN_H
00035 #define MWAWPAGESPAN_H
00036 
00037 #include <vector>
00038 
00039 #include "libmwaw_internal.hxx"
00040 
00041 #include "MWAWFont.hxx"
00042 
00043 class WPXPropertyList;
00044 
00046 class MWAWHeaderFooter
00047 {
00048 public:
00050   enum Type { HEADER, FOOTER, UNDEF };
00052   enum Occurence { ODD, EVEN, ALL, NEVER };
00054   enum PageNumberPosition { None = 0, TopLeft, TopCenter, TopRight, BottomLeft, BottomCenter, BottomRight };
00055 
00057   MWAWHeaderFooter(Type const type=UNDEF, Occurence const occurence=NEVER);
00059   ~MWAWHeaderFooter();
00061   bool isDefined() const {
00062     return m_type != UNDEF;
00063   }
00065   void send(MWAWContentListener *listener) const;
00067   bool operator==(MWAWHeaderFooter const &headerFooter) const;
00069   bool operator!=(MWAWHeaderFooter const &headerFooter) const {
00070     return !operator==(headerFooter);
00071   }
00073   void insertPageNumberParagraph(MWAWContentListener *listener) const;
00074 
00075 public:
00077   Type m_type;
00079   Occurence m_occurence;
00081   double m_height;
00083   PageNumberPosition m_pageNumberPosition;
00085   libmwaw::NumberingType m_pageNumberType;
00087   MWAWFont m_pageNumberFont;
00089   MWAWSubDocumentPtr m_subDocument;
00090 };
00091 
00092 typedef shared_ptr<MWAWHeaderFooter> MWAWHeaderFooterPtr;
00093 
00095 class MWAWPageSpan
00096 {
00097   friend class MWAWContentListener;
00098 public:
00100   enum FormOrientation { PORTRAIT, LANDSCAPE };
00102   enum PageNumberPosition { None = 0, TopLeft, TopCenter, TopRight,
00103                             BottomLeft, BottomCenter, BottomRight
00104                           };
00105 public:
00107   MWAWPageSpan();
00109   virtual ~MWAWPageSpan();
00110 
00112   double getFormLength() const {
00113     return m_formLength;
00114   }
00116   double getFormWidth() const {
00117     return m_formWidth;
00118   }
00120   FormOrientation getFormOrientation() const {
00121     return m_formOrientation;
00122   }
00124   double getMarginLeft() const {
00125     return m_margins[libmwaw::Left];
00126   }
00128   double getMarginRight() const {
00129     return m_margins[libmwaw::Right];
00130   }
00132   double getMarginTop() const {
00133     return m_margins[libmwaw::Top];
00134   }
00136   double getMarginBottom() const {
00137     return m_margins[libmwaw::Bottom];
00138   }
00140   double getPageLength() const {
00141     return m_formLength-m_margins[libmwaw::Top]-m_margins[libmwaw::Bottom];
00142   }
00144   double getPageWidth() const {
00145     return m_formWidth-m_margins[libmwaw::Left]-m_margins[libmwaw::Right];
00146   }
00148   MWAWColor backgroundColor() const {
00149     return m_backgroundColor;
00150   }
00151   int getPageNumber() const {
00152     return m_pageNumber;
00153   }
00154   int getPageSpan() const {
00155     return m_pageSpan;
00156   }
00157 
00159   void setHeaderFooter(MWAWHeaderFooter const &headerFooter);
00161   void setFormLength(const double formLength) {
00162     m_formLength = formLength;
00163   }
00165   void setFormWidth(const double formWidth) {
00166     m_formWidth = formWidth;
00167   }
00169   void setFormOrientation(const FormOrientation formOrientation) {
00170     m_formOrientation = formOrientation;
00171   }
00173   void setMarginLeft(const double marginLeft) {
00174     m_margins[libmwaw::Left] = (marginLeft > 0) ? marginLeft : 0.01;
00175   }
00177   void setMarginRight(const double marginRight) {
00178     m_margins[libmwaw::Right] = (marginRight > 0) ? marginRight : 0.01;
00179   }
00181   void setMarginTop(const double marginTop) {
00182     m_margins[libmwaw::Top] =(marginTop > 0) ? marginTop : 0.01;
00183   }
00185   void setMarginBottom(const double marginBottom) {
00186     m_margins[libmwaw::Bottom] = (marginBottom > 0) ? marginBottom : 0.01;
00187   }
00189   void setMargins(double margin, int wh=libmwaw::LeftBit|libmwaw::RightBit|libmwaw::TopBit|libmwaw::BottomBit) {
00190     if (margin <= 0.0) margin = 0.01;
00191     if (wh&libmwaw::LeftBit)
00192       m_margins[libmwaw::Left]=margin;
00193     if (wh&libmwaw::RightBit)
00194       m_margins[libmwaw::Right]=margin;
00195     if (wh&libmwaw::TopBit)
00196       m_margins[libmwaw::Top]=margin;
00197     if (wh&libmwaw::BottomBit)
00198       m_margins[libmwaw::Bottom]=margin;
00199   }
00201   void checkMargins();
00203   void setBackgroundColor(MWAWColor color=MWAWColor::white()) {
00204     m_backgroundColor=color;
00205   }
00207   void setPageNumber(const int pageNumber) {
00208     m_pageNumber = pageNumber;
00209   }
00211   void setPageSpan(const int pageSpan) {
00212     m_pageSpan = pageSpan;
00213   }
00215   bool operator==(shared_ptr<MWAWPageSpan> const &pageSpan) const;
00217   bool operator!=(shared_ptr<MWAWPageSpan> const &pageSpan) const {
00218     return !operator==(pageSpan);
00219   }
00220 protected:
00221   // interface with MWAWContentListener
00223   void getPageProperty(WPXPropertyList &pList) const;
00225   void sendHeaderFooters(MWAWContentListener *listener) const;
00226 
00227 protected:
00229   int getHeaderFooterPosition(MWAWHeaderFooter::Type type, MWAWHeaderFooter::Occurence occurence);
00231   void removeHeaderFooter(MWAWHeaderFooter::Type type, MWAWHeaderFooter::Occurence occurence);
00233   bool containsHeaderFooter(MWAWHeaderFooter::Type type, MWAWHeaderFooter::Occurence occurence);
00234 private:
00235   double m_formLength, m_formWidth ;
00237   FormOrientation m_formOrientation;
00239   double m_margins[4];
00241   MWAWColor m_backgroundColor;
00243   int m_pageNumber;
00245   std::vector<MWAWHeaderFooter> m_headerFooterList;
00247   int m_pageSpan;
00248 };
00249 
00250 #endif
00251 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: