Back to index

lightning-sunbird  0.9+nobinonly
nsSimplePageSequence.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #ifndef nsSimplePageSequence_h___
00038 #define nsSimplePageSequence_h___
00039 
00040 #include "nsIPageSequenceFrame.h"
00041 #include "nsContainerFrame.h"
00042 #include "nsIPrintSettings.h"
00043 #include "nsIPrintOptions.h"
00044 #include "nsIDateTimeFormat.h"
00045 
00046 //-----------------------------------------------
00047 // This class maintains all the data that 
00048 // is used by all the page frame
00049 // It lives while the nsSimplePageSequenceFrame lives
00050 class nsSharedPageData {
00051 public:
00052   nsSharedPageData();
00053   ~nsSharedPageData();
00054 
00055   PRUnichar * mDateTimeStr;
00056   nsFont *    mHeadFootFont;
00057   PRUnichar * mPageNumFormat;
00058   PRUnichar * mPageNumAndTotalsFormat;
00059   PRUnichar * mDocTitle;
00060   PRUnichar * mDocURL;
00061 
00062   nsRect      mReflowRect;
00063   nsMargin    mReflowMargin;
00064   nsSize      mShadowSize;       // shadow of page in PrintPreview
00065   nsMargin    mDeadSpaceMargin;  // Extra dead space around outside of Page in PrintPreview
00066   nsMargin    mExtraMargin;      // Extra Margin between the printable area and the edge of the page
00067   nsMargin    mEdgePaperMargin;  // In twips, gap between the Margin and edge of page
00068 
00069   nsCOMPtr<nsIPrintSettings> mPrintSettings;
00070   nsCOMPtr<nsIPrintOptions> mPrintOptions;
00071 
00072   nscoord      mPageContentXMost;      // xmost size from Reflow(width)
00073   nscoord      mPageContentSize;       // constrained size (width)
00074 };
00075 
00076 // Simple page sequence frame class. Used when we're in paginated mode
00077 class nsSimplePageSequenceFrame : public nsContainerFrame,
00078                                   public nsIPageSequenceFrame {
00079 public:
00080   friend nsresult NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsIFrame** aResult);
00081 
00082   // nsISupports
00083   NS_IMETHOD  QueryInterface(const nsIID& aIID, void** aInstancePtr);
00084 
00085   // nsIFrameReflow
00086   NS_IMETHOD  Reflow(nsPresContext*      aPresContext,
00087                      nsHTMLReflowMetrics& aDesiredSize,
00088                      const nsHTMLReflowState& aMaxSize,
00089                      nsReflowStatus&      aStatus);
00090 
00091   NS_IMETHOD  Paint(nsPresContext*      aPresContext,
00092                     nsIRenderingContext& aRenderingContext,
00093                     const nsRect&        aDirtyRect,
00094                     nsFramePaintLayer    aWhichLayer);
00095 
00096   // nsIPageSequenceFrame
00097   NS_IMETHOD SetOffsets(nscoord aStartOffset, nscoord aEndOffset);
00098   NS_IMETHOD SetPageNo(PRInt32 aPageNo) { return NS_OK;}
00099   NS_IMETHOD SetSelectionHeight(nscoord aYOffset, nscoord aHeight) { mYSelOffset = aYOffset; mSelectionHeight = aHeight; return NS_OK; }
00100   NS_IMETHOD SetTotalNumPages(PRInt32 aTotal) { mTotalPages = aTotal; return NS_OK; }
00101 
00102   // Gets the dead space (the gray area) around the Print Preview Page
00103   NS_IMETHOD GetDeadSpaceValue(nscoord* aValue) { *aValue = NS_INCHES_TO_TWIPS(0.25); return NS_OK; };
00104   
00105   // For Shrink To Fit
00106   NS_IMETHOD GetSTFPercent(float& aSTFPercent);
00107 
00108   // Async Printing
00109   NS_IMETHOD StartPrint(nsPresContext*  aPresContext,
00110                         nsIPrintSettings* aPrintSettings,
00111                         PRUnichar*        aDocTitle,
00112                         PRUnichar*        aDocURL);
00113   NS_IMETHOD PrintNextPage(nsPresContext*  aPresContext);
00114   NS_IMETHOD GetCurrentPageNum(PRInt32* aPageNum);
00115   NS_IMETHOD GetNumPages(PRInt32* aNumPages);
00116   NS_IMETHOD IsDoingPrintRange(PRBool* aDoing);
00117   NS_IMETHOD GetPrintRange(PRInt32* aFromPage, PRInt32* aToPage);
00118   NS_IMETHOD SkipPageBegin() { mSkipPageBegin = PR_TRUE; return NS_OK; }
00119   NS_IMETHOD SkipPageEnd() { mSkipPageEnd = PR_TRUE; return NS_OK; }
00120   NS_IMETHOD DoPageEnd(nsPresContext*  aPresContext);
00121   NS_IMETHOD GetPrintThisPage(PRBool*  aPrintThisPage) { *aPrintThisPage = mPrintThisPage; return NS_OK; }
00122   NS_IMETHOD SetOffset(nscoord aX, nscoord aY) { mOffsetX = aX; mOffsetY = aY; return NS_OK; }
00123   NS_IMETHOD SuppressHeadersAndFooters(PRBool aDoSup);
00124   NS_IMETHOD SetClipRect(nsPresContext* aPresContext, nsRect* aSize);
00125 
00131   virtual nsIAtom* GetType() const;
00132   
00133 #ifdef NS_DEBUG
00134   NS_IMETHOD  GetFrameName(nsAString& aResult) const;
00135 #endif
00136 
00137 
00138 protected:
00139   nsSimplePageSequenceFrame();
00140   virtual ~nsSimplePageSequenceFrame();
00141 
00142   nsresult CreateContinuingPageFrame(nsPresContext* aPresContext,
00143                                      nsIFrame*       aPageFrame,
00144                                      nsIFrame**      aContinuingFrame);
00145 
00146   void SetPageNumberFormat(const char* aPropName, const char* aDefPropVal, PRBool aPageNumOnly);
00147 
00148   // SharedPageData Helper methods
00149   void SetDateTimeStr(PRUnichar * aDateTimeStr);
00150   void SetPageNumberFormat(PRUnichar * aFormatStr, PRBool aForPageNumOnly);
00151   void SetPageSizes(const nsRect& aRect, const nsMargin& aMarginRect);
00152 
00153   void GetEdgePaperMarginCoord(char* aPrefName, nscoord& aCoord);
00154   void GetEdgePaperMargin(nsMargin& aMargin);
00155 
00156   NS_IMETHOD_(nsrefcnt) AddRef(void) {return nsContainerFrame::AddRef();}
00157   NS_IMETHOD_(nsrefcnt) Release(void) {return nsContainerFrame::Release();}
00158 
00159 
00160   nscoord  mStartOffset;
00161   nscoord  mEndOffset;
00162 
00163   nsMargin mMargin;
00164   PRBool   mIsPrintingSelection;
00165 
00166   // Asynch Printing
00167   PRInt32      mPageNum;
00168   PRInt32      mTotalPages;
00169   PRInt32      mPrintedPageNum;
00170   nsIFrame *   mCurrentPageFrame;
00171   PRPackedBool mDoingPageRange;
00172   PRInt32      mPrintRangeType;
00173   PRInt32      mFromPageNum;
00174   PRInt32      mToPageNum;
00175   PRPackedBool mSkipPageBegin;
00176   PRPackedBool mSkipPageEnd;
00177   PRPackedBool mPrintThisPage;
00178 
00179   PRPackedBool mSupressHF;
00180   nscoord      mOffsetX;
00181   nscoord      mOffsetY;
00182 
00183   nsSize       mSize;
00184   nsSharedPageData* mPageData; // data shared by all the nsPageFrames
00185 
00186   // Selection Printing Info
00187   nscoord      mSelectionHeight;
00188   nscoord      mYSelOffset;
00189 
00190   // I18N date formatter service which we'll want to cache locally.
00191   nsCOMPtr<nsIDateTimeFormat> mDateFormatter;
00192 
00193 private:
00194   void CacheBackground(nsPresContext* aPresContext);
00195 
00196 };
00197 
00198 #endif /* nsSimplePageSequence_h___ */
00199