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 
00044 class MWAWHeaderFooter
00045 {
00046 public:
00048   enum Type { HEADER, FOOTER, UNDEF };
00050   enum Occurrence { ODD, EVEN, ALL, NEVER };
00052   enum PageNumberPosition { None = 0, TopLeft, TopCenter, TopRight, BottomLeft, BottomCenter, BottomRight };
00053 
00055   MWAWHeaderFooter(Type const type=UNDEF, Occurrence const occurrence=NEVER);
00057   ~MWAWHeaderFooter();
00059   bool isDefined() const
00060   {
00061     return m_type != UNDEF;
00062   }
00064   void send(MWAWListener *listener) const;
00066   bool operator==(MWAWHeaderFooter const &headerFooter) const;
00068   bool operator!=(MWAWHeaderFooter const &headerFooter) const
00069   {
00070     return !operator==(headerFooter);
00071   }
00073   void insertPageNumberParagraph(MWAWListener *listener) const;
00074 
00075 public:
00077   Type m_type;
00079   Occurrence m_occurrence;
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 public:
00099   enum FormOrientation { PORTRAIT, LANDSCAPE };
00101   enum PageNumberPosition { None = 0, TopLeft, TopCenter, TopRight,
00102                             BottomLeft, BottomCenter, BottomRight
00103                           };
00104 public:
00106   MWAWPageSpan();
00108   virtual ~MWAWPageSpan();
00109 
00111   double getFormLength() const
00112   {
00113     return m_formLength;
00114   }
00116   double getFormWidth() const
00117   {
00118     return m_formWidth;
00119   }
00121   FormOrientation getFormOrientation() const
00122   {
00123     return m_formOrientation;
00124   }
00126   double getMarginLeft() const
00127   {
00128     return m_margins[libmwaw::Left];
00129   }
00131   double getMarginRight() const
00132   {
00133     return m_margins[libmwaw::Right];
00134   }
00136   double getMarginTop() const
00137   {
00138     return m_margins[libmwaw::Top];
00139   }
00141   double getMarginBottom() const
00142   {
00143     return m_margins[libmwaw::Bottom];
00144   }
00146   double getPageLength() const
00147   {
00148     return m_formLength-m_margins[libmwaw::Top]-m_margins[libmwaw::Bottom];
00149   }
00151   double getPageWidth() const
00152   {
00153     return m_formWidth-m_margins[libmwaw::Left]-m_margins[libmwaw::Right];
00154   }
00156   MWAWColor backgroundColor() const
00157   {
00158     return m_backgroundColor;
00159   }
00160   int getPageNumber() const
00161   {
00162     return m_pageNumber;
00163   }
00164   int getPageSpan() const
00165   {
00166     return m_pageSpan;
00167   }
00168 
00170   void setHeaderFooter(MWAWHeaderFooter const &headerFooter);
00172   void setFormLength(const double formLength)
00173   {
00174     m_formLength = formLength;
00175   }
00177   void setFormWidth(const double formWidth)
00178   {
00179     m_formWidth = formWidth;
00180   }
00182   void setFormOrientation(const FormOrientation formOrientation)
00183   {
00184     m_formOrientation = formOrientation;
00185   }
00187   void setMarginLeft(const double marginLeft)
00188   {
00189     m_margins[libmwaw::Left] = (marginLeft >= 0) ? marginLeft : 0.01;
00190   }
00192   void setMarginRight(const double marginRight)
00193   {
00194     m_margins[libmwaw::Right] = (marginRight >= 0) ? marginRight : 0.01;
00195   }
00197   void setMarginTop(const double marginTop)
00198   {
00199     m_margins[libmwaw::Top] =(marginTop >= 0) ? marginTop : 0.01;
00200   }
00202   void setMarginBottom(const double marginBottom)
00203   {
00204     m_margins[libmwaw::Bottom] = (marginBottom >= 0) ? marginBottom : 0.01;
00205   }
00207   void setMargins(double margin, int wh=libmwaw::LeftBit|libmwaw::RightBit|libmwaw::TopBit|libmwaw::BottomBit)
00208   {
00209     if (margin < 0.0) margin = 0.01;
00210     if (wh&libmwaw::LeftBit)
00211       m_margins[libmwaw::Left]=margin;
00212     if (wh&libmwaw::RightBit)
00213       m_margins[libmwaw::Right]=margin;
00214     if (wh&libmwaw::TopBit)
00215       m_margins[libmwaw::Top]=margin;
00216     if (wh&libmwaw::BottomBit)
00217       m_margins[libmwaw::Bottom]=margin;
00218   }
00220   void checkMargins();
00222   void setPageName(librevenge::RVNGString const &name)
00223   {
00224     m_name=name;
00225   }
00227   bool hasPageName() const
00228   {
00229     return !m_name.empty();
00230   }
00232   librevenge::RVNGString const &getPageName() const
00233   {
00234     return m_name;
00235   }
00237   void setMasterPageName(librevenge::RVNGString const &name)
00238   {
00239     m_masterName=name;
00240   }
00242   bool hasMasterPageName() const
00243   {
00244     return !m_masterName.empty();
00245   }
00247   librevenge::RVNGString const &getMasterPageName() const
00248   {
00249     return m_masterName;
00250   }
00252   void setBackgroundColor(MWAWColor color=MWAWColor::white())
00253   {
00254     m_backgroundColor=color;
00255   }
00257   void setPageNumber(const int pageNumber)
00258   {
00259     m_pageNumber = pageNumber;
00260   }
00262   void setPageSpan(const int pageSpan)
00263   {
00264     m_pageSpan = pageSpan;
00265   }
00267   bool operator==(shared_ptr<MWAWPageSpan> const &pageSpan) const;
00269   bool operator!=(shared_ptr<MWAWPageSpan> const &pageSpan) const
00270   {
00271     return !operator==(pageSpan);
00272   }
00273 
00274   // interface with MWAWListener
00276   void getPageProperty(librevenge::RVNGPropertyList &pList) const;
00278   void sendHeaderFooters(MWAWListener *listener) const;
00280   void sendHeaderFooters(MWAWListener *listener, MWAWHeaderFooter::Occurrence occurrence) const;
00281 
00282 protected:
00284   int getHeaderFooterPosition(MWAWHeaderFooter::Type type, MWAWHeaderFooter::Occurrence occurrence);
00286   void removeHeaderFooter(MWAWHeaderFooter::Type type, MWAWHeaderFooter::Occurrence occurrence);
00288   bool containsHeaderFooter(MWAWHeaderFooter::Type type, MWAWHeaderFooter::Occurrence occurrence);
00289 private:
00290   double m_formLength, m_formWidth ;
00292   FormOrientation m_formOrientation;
00294   double m_margins[4];
00296   librevenge::RVNGString m_name;
00298   librevenge::RVNGString m_masterName;
00300   MWAWColor m_backgroundColor;
00302   int m_pageNumber;
00304   std::vector<MWAWHeaderFooter> m_headerFooterList;
00306   int m_pageSpan;
00307 };
00308 
00309 #endif
00310 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: