2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-11-05 02:21:50 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
1998-11-05 02:21:50 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-11-05 02:21:50 +03:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-02-12 20:45:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
1998-11-05 02:21:50 +03:00
|
|
|
#include "nsSimplePageSequence.h"
|
|
|
|
#include "nsIPresContext.h"
|
1998-11-05 09:13:55 +03:00
|
|
|
#include "nsIRenderingContext.h"
|
1998-11-05 02:21:50 +03:00
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
1998-12-07 06:43:02 +03:00
|
|
|
#include "nsHTMLIIDs.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsIPresShell.h"
|
1999-02-24 07:03:50 +03:00
|
|
|
#include "nsIStyleSet.h"
|
2001-01-27 17:09:34 +03:00
|
|
|
#include "nsIFontMetrics.h"
|
2002-01-01 15:58:53 +03:00
|
|
|
#include "nsIPrintSettings.h"
|
2001-01-27 17:09:34 +03:00
|
|
|
#include "nsPageFrame.h"
|
2001-11-03 17:59:39 +03:00
|
|
|
#include "nsIPrintPreviewContext.h"
|
2002-01-19 01:45:06 +03:00
|
|
|
#include "nsIPrintContext.h"
|
2001-12-05 01:46:41 +03:00
|
|
|
#include "nsStyleConsts.h"
|
2001-12-01 17:31:45 +03:00
|
|
|
#include "nsIRegion.h"
|
2002-03-04 15:55:20 +03:00
|
|
|
#include "nsLayoutAtoms.h"
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2001-11-28 18:19:47 +03:00
|
|
|
#include "nsIPref.h" // for header/footer gap & ExtraMargin for Print Preview
|
|
|
|
|
2001-09-26 18:01:26 +04:00
|
|
|
// DateTime Includes
|
|
|
|
#include "nsDateTimeFormatCID.h"
|
|
|
|
#include "nsIDateTimeFormat.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsILocale.h"
|
|
|
|
#include "nsLocaleCID.h"
|
|
|
|
#include "nsILocaleService.h"
|
|
|
|
static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID);
|
|
|
|
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
|
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
#define OFFSET_NOT_SET -1
|
|
|
|
|
|
|
|
// This is for localization of the "x of n" pages string
|
|
|
|
// this class contains a helper method we need to get
|
|
|
|
// a string from a string bundle
|
|
|
|
#include "nsFormControlHelper.h"
|
2002-04-19 02:43:02 +04:00
|
|
|
#define PRINTING_PROPERTIES "chrome://global/locale/printing.properties"
|
2001-01-27 17:09:34 +03:00
|
|
|
|
|
|
|
// Print Options
|
2002-01-01 15:58:53 +03:00
|
|
|
#include "nsIPrintSettings.h"
|
2001-01-27 17:09:34 +03:00
|
|
|
#include "nsIPrintOptions.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
|
|
|
|
//
|
2001-12-01 17:31:45 +03:00
|
|
|
static NS_DEFINE_CID(kRegionCID, NS_REGION_CID);
|
1998-12-07 06:43:02 +03:00
|
|
|
|
2001-12-05 01:46:41 +03:00
|
|
|
|
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
|
|
|
|
#define DEBUG_PRINTING
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG_PRINTING
|
|
|
|
#define PRINT_DEBUG_MSG1(_msg1) fprintf(mDebugFD, (_msg1))
|
|
|
|
#define PRINT_DEBUG_MSG2(_msg1, _msg2) fprintf(mDebugFD, (_msg1), (_msg2))
|
|
|
|
#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3) fprintf(mDebugFD, (_msg1), (_msg2), (_msg3))
|
|
|
|
#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4) fprintf(mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4))
|
|
|
|
#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5) fprintf(mDebugFD, (_msg1), (_msg2), (_msg3), (_msg4), (_msg5))
|
|
|
|
#else //--------------
|
|
|
|
#define PRINT_DEBUG_MSG1(_msg)
|
|
|
|
#define PRINT_DEBUG_MSG2(_msg1, _msg2)
|
|
|
|
#define PRINT_DEBUG_MSG3(_msg1, _msg2, _msg3)
|
|
|
|
#define PRINT_DEBUG_MSG4(_msg1, _msg2, _msg3, _msg4)
|
|
|
|
#define PRINT_DEBUG_MSG5(_msg1, _msg2, _msg3, _msg4, _msg5)
|
|
|
|
#endif
|
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
// This object a shared by all the nsPageFrames
|
|
|
|
// parented to a SimplePageSequenceFrame
|
|
|
|
nsSharedPageData::nsSharedPageData() :
|
|
|
|
mDateTimeStr(nsnull),
|
|
|
|
mHeadFootFont(nsnull),
|
|
|
|
mPageNumFormat(nsnull),
|
|
|
|
mPageNumAndTotalsFormat(nsnull),
|
2002-05-07 16:03:37 +04:00
|
|
|
mDocTitle(nsnull),
|
|
|
|
mDocURL(nsnull),
|
2001-11-03 17:59:39 +03:00
|
|
|
mReflowRect(0,0,0,0),
|
|
|
|
mReflowMargin(0,0,0,0),
|
|
|
|
mShadowSize(0,0),
|
2001-11-28 18:19:47 +03:00
|
|
|
mDeadSpaceMargin(0,0,0,0),
|
2001-11-29 13:26:51 +03:00
|
|
|
mExtraMargin(0,0,0,0),
|
2002-02-01 18:31:15 +03:00
|
|
|
mEdgePaperMargin(0,0,0,0)
|
2001-11-03 17:59:39 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSharedPageData::~nsSharedPageData()
|
|
|
|
{
|
|
|
|
nsMemory::Free(mDateTimeStr);
|
|
|
|
if (mHeadFootFont) delete mHeadFootFont;
|
|
|
|
nsMemory::Free(mPageNumFormat);
|
|
|
|
nsMemory::Free(mPageNumAndTotalsFormat);
|
2002-05-07 16:03:37 +04:00
|
|
|
if (mDocTitle) nsMemory::Free(mDocTitle);
|
|
|
|
if (mDocURL) nsMemory::Free(mDocURL);
|
2001-11-03 17:59:39 +03:00
|
|
|
}
|
|
|
|
|
1999-05-12 02:03:29 +04:00
|
|
|
nsresult
|
1999-12-05 02:49:50 +03:00
|
|
|
NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
1999-05-12 02:03:29 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-12-05 02:49:50 +03:00
|
|
|
nsSimplePageSequenceFrame* it = new (aPresShell) nsSimplePageSequenceFrame;
|
1999-05-12 02:03:29 +04:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
nsSimplePageSequenceFrame::nsSimplePageSequenceFrame() :
|
2001-11-03 17:59:39 +03:00
|
|
|
mIsPrintingSelection(PR_FALSE),
|
2002-02-12 16:33:39 +03:00
|
|
|
mTotalPages(-1),
|
2001-11-03 17:59:39 +03:00
|
|
|
mSelectionHeight(-1),
|
|
|
|
mYSelOffset(0)
|
2001-01-27 17:09:34 +03:00
|
|
|
{
|
|
|
|
mStartOffset = OFFSET_NOT_SET;
|
|
|
|
mEndOffset = OFFSET_NOT_SET;
|
|
|
|
|
|
|
|
nscoord halfInch = NS_INCHES_TO_TWIPS(0.5);
|
|
|
|
mMargin.SizeTo(halfInch, halfInch, halfInch, halfInch);
|
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
mPageData = new nsSharedPageData();
|
|
|
|
NS_ASSERTION(mPageData != nsnull, "Can't be null!");
|
|
|
|
if (mPageData->mHeadFootFont == nsnull) {
|
|
|
|
mPageData->mHeadFootFont = new nsFont("serif", NS_FONT_STYLE_NORMAL,NS_FONT_VARIANT_NORMAL,
|
|
|
|
NS_FONT_WEIGHT_NORMAL,0,NSIntPointsToTwips(10));
|
|
|
|
}
|
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
// XXX this code and the object data member "mIsPrintingSelection" is only needed
|
|
|
|
// for the hack for printing selection where we make the page the max size
|
|
|
|
nsresult rv;
|
2002-01-01 15:58:53 +03:00
|
|
|
mPageData->mPrintOptions = do_GetService(kPrintOptionsCID, &rv);
|
2001-11-03 17:59:39 +03:00
|
|
|
if (NS_SUCCEEDED(rv) && mPageData->mPrintOptions) {
|
|
|
|
// now get the default font form the print options
|
|
|
|
mPageData->mPrintOptions->GetDefaultFont(*mPageData->mHeadFootFont);
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
mSkipPageBegin = PR_FALSE;
|
|
|
|
mSkipPageEnd = PR_FALSE;
|
|
|
|
mPrintThisPage = PR_FALSE;
|
|
|
|
mOffsetX = 0;
|
|
|
|
mOffsetY = 0;
|
2001-11-03 17:59:39 +03:00
|
|
|
|
|
|
|
// Doing this here so we only have to go get these formats once
|
|
|
|
SetPageNumberFormat("pagenumber", "%1$d", PR_TRUE);
|
|
|
|
SetPageNumberFormat("pageofpages", "%1$d of %2$d", PR_FALSE);
|
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
mDebugFD = stdout;
|
|
|
|
#endif
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSimplePageSequenceFrame::~nsSimplePageSequenceFrame()
|
1999-05-12 02:03:29 +04:00
|
|
|
{
|
2001-11-03 17:59:39 +03:00
|
|
|
if (mPageData) delete mPageData;
|
1999-05-12 02:03:29 +04:00
|
|
|
}
|
|
|
|
|
1998-12-07 06:43:02 +03:00
|
|
|
nsresult
|
|
|
|
nsSimplePageSequenceFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(0 != aInstancePtr, "null ptr");
|
|
|
|
if (NULL == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIPageSequenceFrameIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIPageSequenceFrame*)this;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return nsContainerFrame::QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
1998-11-05 02:21:50 +03:00
|
|
|
|
1999-07-03 06:22:10 +04:00
|
|
|
// Creates a continuing page frame
|
|
|
|
nsresult
|
1999-11-24 09:03:41 +03:00
|
|
|
nsSimplePageSequenceFrame::CreateContinuingPageFrame(nsIPresContext* aPresContext,
|
1999-07-03 06:22:10 +04:00
|
|
|
nsIFrame* aPageFrame,
|
|
|
|
nsIFrame** aContinuingPage)
|
|
|
|
{
|
|
|
|
nsIPresShell* presShell;
|
|
|
|
nsIStyleSet* styleSet;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Create the continuing frame
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetShell(&presShell);
|
1999-07-03 06:22:10 +04:00
|
|
|
presShell->GetStyleSet(&styleSet);
|
|
|
|
NS_RELEASE(presShell);
|
1999-11-24 09:03:41 +03:00
|
|
|
rv = styleSet->CreateContinuingFrame(aPresContext, aPageFrame, this, aContinuingPage);
|
1999-07-03 06:22:10 +04:00
|
|
|
NS_RELEASE(styleSet);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-02-01 18:31:15 +03:00
|
|
|
static void GetEdgePaperMarginCoord(nsIPref* aPref, char* aPrefName, nscoord& aCoord)
|
|
|
|
{
|
|
|
|
if (NS_SUCCEEDED(aPref->GetIntPref(aPrefName, &aCoord))) {
|
|
|
|
nscoord inchInTwips = NS_INCHES_TO_TWIPS(1.0);
|
|
|
|
aCoord = PR_MAX(NS_INCHES_TO_TWIPS(float(aCoord)/100.0f), 0);
|
|
|
|
aCoord = PR_MIN(aCoord, inchInTwips); // an inch is still probably excessive
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void GetEdgePaperMargin(nsIPref* aPref, nsMargin& aMargin)
|
|
|
|
{
|
|
|
|
aMargin.SizeTo(0,0,0,0);
|
|
|
|
GetEdgePaperMarginCoord(aPref, "print.print_edge_top", aMargin.top);
|
|
|
|
GetEdgePaperMarginCoord(aPref, "print.print_edge_left", aMargin.left);
|
|
|
|
GetEdgePaperMarginCoord(aPref, "print.print_edge_bottom", aMargin.bottom);
|
|
|
|
GetEdgePaperMarginCoord(aPref, "print.print_edge_right", aMargin.right);
|
|
|
|
}
|
|
|
|
|
1998-11-05 02:21:50 +03:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
|
1998-11-05 02:21:50 +03:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2000-04-21 18:59:47 +04:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsSimplePageSequenceFrame", aReflowState.reason);
|
2001-11-14 16:40:03 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
1998-11-05 02:21:50 +03:00
|
|
|
NS_FRAME_TRACE_REFLOW_IN("nsSimplePageSequenceFrame::Reflow");
|
|
|
|
|
1999-03-10 01:34:51 +03:00
|
|
|
aStatus = NS_FRAME_COMPLETE; // we're always complete
|
1998-11-05 02:21:50 +03:00
|
|
|
|
2002-02-01 18:31:15 +03:00
|
|
|
// absolutely ignore all other types of reflows
|
|
|
|
// we only want to have done the Initial Reflow
|
|
|
|
if (eReflowReason_Resize == aReflowState.reason ||
|
|
|
|
eReflowReason_Incremental == aReflowState.reason ||
|
|
|
|
eReflowReason_StyleChange == aReflowState.reason ||
|
|
|
|
eReflowReason_Dirty == aReflowState.reason) {
|
|
|
|
// Return our desired size
|
|
|
|
aDesiredSize.height = mSize.height;
|
|
|
|
aDesiredSize.width = mSize.width;
|
|
|
|
aDesiredSize.ascent = aDesiredSize.height;
|
|
|
|
aDesiredSize.descent = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-04-23 16:05:43 +04:00
|
|
|
// Turn on the scaling of twips so any of the scrollbars
|
|
|
|
// in the UI no longer get scaled
|
|
|
|
nsCOMPtr<nsIPrintPreviewContext> printPreviewContext(do_QueryInterface(aPresContext));
|
|
|
|
if (printPreviewContext) {
|
|
|
|
printPreviewContext->SetScalingOfTwips(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
nsCOMPtr<nsIPrintPreviewContext> ppContext = do_QueryInterface(aPresContext);
|
|
|
|
|
2002-01-19 01:45:06 +03:00
|
|
|
// See if we can get a Print Settings from the Context
|
|
|
|
if (!mPageData->mPrintSettings) {
|
|
|
|
if (ppContext) {
|
|
|
|
ppContext->GetPrintSettings(getter_AddRefs(mPageData->mPrintSettings));
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIPrintContext> prtContext = do_QueryInterface(aPresContext);
|
|
|
|
if (prtContext) {
|
|
|
|
prtContext->GetPrintSettings(getter_AddRefs(mPageData->mPrintSettings));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now get out margins
|
|
|
|
if (mPageData->mPrintSettings) {
|
|
|
|
mPageData->mPrintSettings->GetMarginInTwips(mMargin);
|
2002-04-11 04:34:59 +04:00
|
|
|
PRInt16 printType;
|
|
|
|
mPageData->mPrintSettings->GetPrintRange(&printType);
|
|
|
|
mPrintRangeType = printType;
|
|
|
|
mIsPrintingSelection = nsIPrintSettings::kRangeSelection == printType;
|
2002-01-19 01:45:06 +03:00
|
|
|
}
|
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
// *** Special Override ***
|
|
|
|
// If this is a sub-sdoc (meaning it doesn't take the whole page)
|
|
|
|
// and if this Document is in the upper left hand corner
|
|
|
|
// we need to suppress the top margin or it will reflow too small
|
|
|
|
// Start by getting the actual printer page dimensions to see if we are not a whole page
|
|
|
|
nsCOMPtr<nsIDeviceContext> dc;
|
|
|
|
aPresContext->GetDeviceContext(getter_AddRefs(dc));
|
|
|
|
NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!");
|
|
|
|
nscoord width, height;
|
|
|
|
dc->GetDeviceSurfaceDimensions(width, height);
|
|
|
|
|
1998-11-05 02:21:50 +03:00
|
|
|
// Compute the size of each page and the x coordinate that each page will
|
|
|
|
// be placed at
|
2001-04-12 17:04:29 +04:00
|
|
|
nsRect pageSize;
|
|
|
|
nsRect adjSize;
|
|
|
|
aPresContext->GetPageDim(&pageSize, &adjSize);
|
|
|
|
|
2001-11-28 18:19:47 +03:00
|
|
|
nscoord extraGap = 0;
|
|
|
|
nsCOMPtr<nsIPref> pref = do_GetService(NS_PREF_CONTRACTID);
|
|
|
|
if (pref) {
|
2002-02-01 18:31:15 +03:00
|
|
|
GetEdgePaperMargin(pref, mPageData->mEdgePaperMargin);
|
2001-11-28 18:19:47 +03:00
|
|
|
nscoord inchInTwips = NS_INCHES_TO_TWIPS(1.0);
|
|
|
|
PRInt32 gapInTwips;
|
|
|
|
if (NS_SUCCEEDED(pref->GetIntPref("print.print_extra_margin", &gapInTwips))) {
|
|
|
|
gapInTwips = PR_MAX(gapInTwips, 0);
|
|
|
|
gapInTwips = PR_MIN(gapInTwips, inchInTwips); // an inch is still probably excessive
|
2002-02-01 18:31:15 +03:00
|
|
|
extraGap = nscoord(gapInTwips);
|
2001-11-28 18:19:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-15 02:18:09 +03:00
|
|
|
nscoord deadSpaceGap;
|
|
|
|
GetDeadSpaceValue(&deadSpaceGap);
|
|
|
|
|
2001-11-28 18:19:47 +03:00
|
|
|
nsMargin deadSpaceMargin(0,0,0,0);
|
2001-11-03 17:59:39 +03:00
|
|
|
nsMargin extraMargin(0,0,0,0);
|
2001-11-28 18:19:47 +03:00
|
|
|
nsSize shadowSize(0,0);
|
2001-11-03 17:59:39 +03:00
|
|
|
if (ppContext) {
|
|
|
|
if (adjSize.width == width && adjSize.height == height) {
|
2002-02-15 02:18:09 +03:00
|
|
|
deadSpaceMargin.SizeTo(deadSpaceGap, deadSpaceGap, deadSpaceGap, deadSpaceGap);
|
2001-11-28 18:19:47 +03:00
|
|
|
extraMargin.SizeTo(extraGap, extraGap, extraGap, extraGap);
|
2001-11-03 17:59:39 +03:00
|
|
|
float p2t;
|
|
|
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
|
|
|
nscoord fourPixels = NSIntPixelsToTwips(4, p2t);
|
|
|
|
shadowSize.SizeTo(fourPixels, fourPixels);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-28 18:19:47 +03:00
|
|
|
mPageData->mShadowSize = shadowSize;
|
|
|
|
mPageData->mExtraMargin = extraMargin;
|
|
|
|
mPageData->mDeadSpaceMargin = deadSpaceMargin;
|
2001-11-06 17:34:00 +03:00
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
PRBool suppressLeftMargin = PR_FALSE;
|
|
|
|
PRBool suppressRightMargin = PR_FALSE;
|
|
|
|
PRBool suppressTopMargin = PR_FALSE;
|
|
|
|
PRBool suppressBottomMargin = PR_FALSE;
|
|
|
|
|
|
|
|
if (pageSize != adjSize &&
|
|
|
|
(adjSize.x != 0 || adjSize.y != 0 || adjSize.width != 0 || adjSize.height != 0)) {
|
2002-03-20 15:34:18 +03:00
|
|
|
suppressLeftMargin = pageSize.x != adjSize.x || (pageSize.x == adjSize.x && !adjSize.x);
|
|
|
|
suppressTopMargin = pageSize.y != adjSize.y || (pageSize.y == adjSize.y && !adjSize.y);
|
2001-04-12 17:04:29 +04:00
|
|
|
if (pageSize.width != adjSize.width) {
|
|
|
|
suppressRightMargin = PR_TRUE;
|
|
|
|
pageSize.width = adjSize.width;
|
|
|
|
}
|
|
|
|
if (pageSize.height != adjSize.height) {
|
|
|
|
suppressBottomMargin = PR_TRUE;
|
|
|
|
pageSize.height = adjSize.height;
|
|
|
|
}
|
|
|
|
}
|
1998-11-05 02:21:50 +03:00
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
// XXX - Hack Alert
|
|
|
|
// OK, so ther eis a selection, we will print the entire selection
|
|
|
|
// on one page and then crop the page.
|
|
|
|
// This means you can never print any selection that is longer than one page
|
|
|
|
// put it keeps it from page breaking in the middle of your print of the selection
|
|
|
|
// (see also nsDocumentViewer.cpp)
|
|
|
|
if (mIsPrintingSelection) {
|
2001-09-24 18:48:38 +04:00
|
|
|
pageSize.height = NS_UNCONSTRAINEDSIZE;
|
2001-11-03 17:59:39 +03:00
|
|
|
suppressLeftMargin = PR_FALSE;
|
|
|
|
suppressTopMargin = PR_FALSE;
|
|
|
|
suppressRightMargin = PR_FALSE;
|
|
|
|
suppressBottomMargin = PR_FALSE;
|
1998-11-05 02:21:50 +03:00
|
|
|
}
|
|
|
|
|
2001-09-25 17:00:04 +04:00
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
// only use this local margin for sizing,
|
|
|
|
// not for positioning
|
|
|
|
nsMargin margin(suppressLeftMargin?0:mMargin.left,
|
|
|
|
suppressTopMargin?0:mMargin.top,
|
|
|
|
suppressRightMargin?0:mMargin.right,
|
|
|
|
suppressBottomMargin?0:mMargin.bottom);
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2001-11-28 18:19:47 +03:00
|
|
|
nscoord x = deadSpaceMargin.left;
|
|
|
|
nscoord y = deadSpaceMargin.top;// Running y-offset for each page
|
1998-11-05 02:21:50 +03:00
|
|
|
|
2002-01-16 06:24:09 +03:00
|
|
|
nsSize reflowPageSize(0,0);
|
|
|
|
|
1999-07-03 06:22:10 +04:00
|
|
|
// See if it's an incremental reflow command
|
1998-11-05 02:21:50 +03:00
|
|
|
if (eReflowReason_Incremental == aReflowState.reason) {
|
2001-03-27 15:56:03 +04:00
|
|
|
// XXX Skip Incremental reflow,
|
|
|
|
// in fact, all we want is the initial reflow
|
2001-11-03 17:59:39 +03:00
|
|
|
y = mRect.height;
|
1998-11-05 02:21:50 +03:00
|
|
|
} else {
|
2002-03-10 18:40:51 +03:00
|
|
|
// XXX Part of Temporary fix for Bug 127263
|
|
|
|
nsPageFrame::SetCreateWidget(PR_TRUE);
|
|
|
|
|
1998-11-05 02:21:50 +03:00
|
|
|
nsReflowReason reflowReason = aReflowState.reason;
|
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
SetPageSizes(pageSize, margin);
|
|
|
|
|
1998-11-05 02:21:50 +03:00
|
|
|
// Tile the pages vertically
|
|
|
|
nsHTMLReflowMetrics kidSize(nsnull);
|
1999-01-16 01:53:39 +03:00
|
|
|
for (nsIFrame* kidFrame = mFrames.FirstChild(); nsnull != kidFrame; ) {
|
1998-11-05 02:21:50 +03:00
|
|
|
// Reflow the page
|
2002-02-12 16:33:39 +03:00
|
|
|
// The availableHeight always comes in NS_UNCONSTRAINEDSIZE, so we need to check
|
|
|
|
// the "adjusted rect" to see if that is being reflowed NS_UNCONSTRAINEDSIZE or not
|
|
|
|
// When it is NS_UNCONSTRAINEDSIZE it means we are reflowing a single page
|
|
|
|
// to print selection. So this means we want to use NS_UNCONSTRAINEDSIZE without altering it
|
|
|
|
nsRect actualRect;
|
|
|
|
nsRect adjRect;
|
|
|
|
aPresContext->GetPageDim(&actualRect, &adjRect);
|
|
|
|
nscoord avHeight;
|
|
|
|
if (adjRect.height == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
avHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
} else {
|
|
|
|
avHeight = pageSize.height+deadSpaceMargin.top+deadSpaceMargin.bottom+shadowSize.height+extraMargin.top+extraMargin.bottom;
|
|
|
|
}
|
2001-11-28 18:19:47 +03:00
|
|
|
nsSize availSize(pageSize.width+deadSpaceMargin.right+deadSpaceMargin.left+shadowSize.width+extraMargin.right+extraMargin.left,
|
2002-02-12 16:33:39 +03:00
|
|
|
avHeight);
|
1999-03-05 07:29:11 +03:00
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, kidFrame,
|
2001-04-12 17:04:29 +04:00
|
|
|
availSize, reflowReason);
|
1998-11-05 02:21:50 +03:00
|
|
|
nsReflowStatus status;
|
2001-09-24 18:48:38 +04:00
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
kidReflowState.mComputedWidth = kidReflowState.availableWidth;
|
|
|
|
//kidReflowState.mComputedHeight = kidReflowState.availableHeight;
|
2001-09-26 18:01:26 +04:00
|
|
|
PRINT_DEBUG_MSG3("AV W: %d H: %d\n", kidReflowState.availableWidth, kidReflowState.availableHeight);
|
1998-11-05 02:21:50 +03:00
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
// Set the shared data into the page frame before reflow
|
|
|
|
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, kidFrame);
|
|
|
|
pf->SetSharedPageData(mPageData);
|
|
|
|
|
1998-11-05 02:21:50 +03:00
|
|
|
// Place and size the page. If the page is narrower than our
|
|
|
|
// max width then center it horizontally
|
1999-11-19 18:33:29 +03:00
|
|
|
ReflowChild(kidFrame, aPresContext, kidSize, kidReflowState, x, y, 0, status);
|
|
|
|
|
2002-01-16 06:24:09 +03:00
|
|
|
reflowPageSize.SizeTo(kidSize.width, kidSize.height);
|
|
|
|
|
2001-12-07 17:51:12 +03:00
|
|
|
FinishReflowChild(kidFrame, aPresContext, nsnull, kidSize, x, y, 0);
|
1998-11-05 02:21:50 +03:00
|
|
|
y += kidSize.height;
|
|
|
|
|
2002-03-10 18:40:51 +03:00
|
|
|
// XXX Temporary fix for Bug 127263
|
|
|
|
// This tells the nsPageFrame class to stop creating clipping widgets
|
|
|
|
// once we reach the 32k boundary for positioning
|
|
|
|
if (nsPageFrame::GetCreateWidget()) {
|
|
|
|
float t2p;
|
|
|
|
aPresContext->GetTwipsToPixels(&t2p);
|
|
|
|
nscoord xp = NSTwipsToIntPixels(x, t2p);
|
|
|
|
nscoord yp = NSTwipsToIntPixels(y, t2p);
|
|
|
|
nsPageFrame::SetCreateWidget(xp < 0x8000 && yp < 0x8000);
|
|
|
|
}
|
|
|
|
|
1998-11-05 02:21:50 +03:00
|
|
|
// Leave a slight gap between the pages
|
2002-02-15 02:18:09 +03:00
|
|
|
y += deadSpaceGap;
|
1998-11-05 02:21:50 +03:00
|
|
|
|
|
|
|
// Is the page complete?
|
|
|
|
nsIFrame* kidNextInFlow;
|
1999-02-24 07:48:08 +03:00
|
|
|
kidFrame->GetNextInFlow(&kidNextInFlow);
|
1999-03-10 01:34:51 +03:00
|
|
|
|
1998-11-05 02:21:50 +03:00
|
|
|
if (NS_FRAME_IS_COMPLETE(status)) {
|
|
|
|
NS_ASSERTION(nsnull == kidNextInFlow, "bad child flow list");
|
|
|
|
} else if (nsnull == kidNextInFlow) {
|
1999-07-03 06:22:10 +04:00
|
|
|
// The page isn't complete and it doesn't have a next-in-flow, so
|
1998-11-05 02:21:50 +03:00
|
|
|
// create a continuing page
|
1999-02-24 07:03:50 +03:00
|
|
|
nsIFrame* continuingPage;
|
1999-07-03 06:22:10 +04:00
|
|
|
CreateContinuingPageFrame(aPresContext, kidFrame, &continuingPage);
|
1998-11-05 02:21:50 +03:00
|
|
|
|
|
|
|
// Add it to our child list
|
|
|
|
kidFrame->SetNextSibling(continuingPage);
|
1999-07-03 06:22:10 +04:00
|
|
|
reflowReason = eReflowReason_Initial;
|
1998-11-05 02:21:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the next page
|
1999-02-10 09:13:38 +03:00
|
|
|
kidFrame->GetNextSibling(&kidFrame);
|
1998-11-05 02:21:50 +03:00
|
|
|
}
|
2001-09-26 18:01:26 +04:00
|
|
|
|
|
|
|
// Get Total Page Count
|
|
|
|
nsIFrame* page;
|
|
|
|
PRInt32 pageTot = 0;
|
|
|
|
for (page = mFrames.FirstChild(); nsnull != page; page->GetNextSibling(&page)) {
|
|
|
|
pageTot++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set Page Number Info
|
|
|
|
PRInt32 pageNum = 1;
|
|
|
|
for (page = mFrames.FirstChild(); nsnull != page; page->GetNextSibling(&page)) {
|
|
|
|
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, page);
|
|
|
|
if (pf != nsnull) {
|
|
|
|
pf->SetPageNumInfo(pageNum, pageTot);
|
|
|
|
}
|
|
|
|
pageNum++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create current Date/Time String
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsILocale> locale;
|
|
|
|
nsCOMPtr<nsILocaleService> localeSvc = do_GetService(kLocaleServiceCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = localeSvc->GetApplicationLocale(getter_AddRefs(locale));
|
|
|
|
if (NS_SUCCEEDED(rv) && locale) {
|
|
|
|
nsCOMPtr<nsIDateTimeFormat> dateTime;
|
|
|
|
rv = nsComponentManager::CreateInstance(kDateTimeFormatCID,
|
|
|
|
NULL,
|
|
|
|
NS_GET_IID(nsIDateTimeFormat),
|
|
|
|
(void**) getter_AddRefs(dateTime));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsAutoString dateString;
|
|
|
|
time_t ltime;
|
|
|
|
time( <ime );
|
|
|
|
if (NS_SUCCEEDED(dateTime->FormatTime(locale, kDateFormatShort, kTimeFormatNoSeconds, ltime, dateString))) {
|
2001-09-29 12:28:41 +04:00
|
|
|
PRUnichar * uStr = ToNewUnicode(dateString);
|
2001-11-03 17:59:39 +03:00
|
|
|
SetDateTimeStr(uStr); // memory will be freed
|
2001-09-26 18:01:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-05 02:21:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return our desired size
|
2001-01-27 17:09:34 +03:00
|
|
|
aDesiredSize.height = y;
|
2002-01-16 06:24:09 +03:00
|
|
|
aDesiredSize.width = reflowPageSize.width+deadSpaceMargin.right+shadowSize.width+extraMargin.right+extraMargin.left;
|
2001-01-27 17:09:34 +03:00
|
|
|
aDesiredSize.ascent = aDesiredSize.height;
|
1998-11-05 02:21:50 +03:00
|
|
|
aDesiredSize.descent = 0;
|
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
// cache the size so we can set the desired size
|
|
|
|
// for the other reflows that happen
|
|
|
|
mSize.width = aDesiredSize.width;
|
|
|
|
mSize.height = aDesiredSize.height;
|
|
|
|
|
2002-04-23 16:05:43 +04:00
|
|
|
// Turn off the scaling of twips so any of the scrollbars
|
|
|
|
// in the document get scaled
|
|
|
|
if (printPreviewContext) {
|
|
|
|
printPreviewContext->SetScalingOfTwips(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
1998-11-05 02:21:50 +03:00
|
|
|
NS_FRAME_TRACE_REFLOW_OUT("nsSimplePageSequeceFrame::Reflow", aStatus);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-07 06:43:02 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef DEBUG
|
1998-11-05 02:21:50 +03:00
|
|
|
NS_IMETHODIMP
|
2001-11-14 04:33:42 +03:00
|
|
|
nsSimplePageSequenceFrame::GetFrameName(nsAString& aResult) const
|
1998-11-05 02:21:50 +03:00
|
|
|
{
|
2001-11-14 04:33:42 +03:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SimplePageSequence"), aResult);
|
1998-11-05 02:21:50 +03:00
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
1998-11-05 02:21:50 +03:00
|
|
|
|
1998-12-07 06:43:02 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Helper function that sends the progress notification. Returns PR_TRUE
|
|
|
|
// if printing should continue and PR_FALSE otherwise
|
|
|
|
static PRBool
|
|
|
|
SendStatusNotification(nsIPrintStatusCallback* aStatusCallback,
|
|
|
|
PRInt32 aPageNumber,
|
|
|
|
PRInt32 aTotalPages,
|
|
|
|
nsPrintStatus aStatus)
|
|
|
|
{
|
|
|
|
PRBool ret = PR_TRUE;
|
|
|
|
|
|
|
|
if (nsnull != aStatusCallback) {
|
|
|
|
aStatusCallback->OnProgress(aPageNumber, aTotalPages, aStatus,ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::SetOffsets(nscoord aStartOffset, nscoord aEndOffset)
|
|
|
|
{
|
|
|
|
mStartOffset = aStartOffset;
|
|
|
|
mEndOffset = aEndOffset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-27 15:56:03 +04:00
|
|
|
//====================================================================
|
|
|
|
//== Asynch Printing
|
|
|
|
//====================================================================
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::GetCurrentPageNum(PRInt32* aPageNum)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPageNum);
|
|
|
|
|
|
|
|
*aPageNum = mPageNum;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::GetNumPages(PRInt32* aNumPages)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNumPages);
|
|
|
|
|
|
|
|
*aNumPages = mTotalPages;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::IsDoingPrintRange(PRBool* aDoing)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDoing);
|
|
|
|
|
|
|
|
*aDoing = mDoingPageRange;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::GetPrintRange(PRInt32* aFromPage, PRInt32* aToPage)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aFromPage);
|
|
|
|
NS_ENSURE_ARG_POINTER(aToPage);
|
|
|
|
|
|
|
|
*aFromPage = mFromPageNum;
|
|
|
|
*aToPage = mToPageNum;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-09-26 18:01:26 +04:00
|
|
|
// Helper Function
|
|
|
|
void
|
|
|
|
nsSimplePageSequenceFrame::SetPageNumberFormat(const char* aPropName, const char* aDefPropVal, PRBool aPageNumOnly)
|
|
|
|
{
|
|
|
|
// Doing this here so we only have to go get these formats once
|
|
|
|
nsAutoString pageNumberFormat;
|
|
|
|
// Now go get the Localized Page Formating String
|
2002-01-07 16:31:18 +03:00
|
|
|
nsresult rv = nsFormControlHelper::GetLocalizedString(PRINTING_PROPERTIES, NS_ConvertUTF8toUCS2(aPropName).get(), pageNumberFormat);
|
|
|
|
if (NS_FAILED(rv)) { // back stop formatting
|
|
|
|
pageNumberFormat.AssignWithConversion(aDefPropVal);
|
2001-09-26 18:01:26 +04:00
|
|
|
}
|
2002-01-07 16:31:18 +03:00
|
|
|
|
2001-09-26 18:01:26 +04:00
|
|
|
// Sets the format into a static data memeber which will own the memory and free it
|
2001-09-29 12:28:41 +04:00
|
|
|
PRUnichar* uStr = ToNewUnicode(pageNumberFormat);
|
2001-09-26 18:01:26 +04:00
|
|
|
if (uStr != nsnull) {
|
2001-11-03 17:59:39 +03:00
|
|
|
SetPageNumberFormat(uStr, aPageNumOnly); // nsPageFrame will own the memory
|
2001-09-26 18:01:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-02-12 16:33:39 +03:00
|
|
|
nsIRegion* nsSimplePageSequenceFrame::CreateRegion()
|
2001-12-01 17:31:45 +03:00
|
|
|
{
|
|
|
|
nsIRegion* region;
|
|
|
|
nsresult rv = nsComponentManager::CreateInstance(kRegionCID, nsnull, NS_GET_IID(nsIRegion), (void**)®ion);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (NS_SUCCEEDED(region->Init())) {
|
|
|
|
return region;
|
|
|
|
} else {
|
|
|
|
NS_RELEASE(region);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2001-03-27 15:56:03 +04:00
|
|
|
NS_IMETHODIMP
|
2002-05-07 16:03:37 +04:00
|
|
|
nsSimplePageSequenceFrame::StartPrint(nsIPresContext* aPresContext,
|
|
|
|
nsIPrintSettings* aPrintSettings,
|
|
|
|
PRUnichar* aDocTitle,
|
|
|
|
PRUnichar* aDocURL)
|
2001-03-27 15:56:03 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPresContext);
|
2002-01-01 15:58:53 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aPrintSettings);
|
|
|
|
|
|
|
|
if (!mPageData->mPrintSettings) {
|
|
|
|
mPageData->mPrintSettings = aPrintSettings;
|
|
|
|
}
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-05-07 16:03:37 +04:00
|
|
|
// Only set them if they are not null
|
|
|
|
if (aDocTitle) mPageData->mDocTitle = aDocTitle;
|
|
|
|
if (aDocURL) mPageData->mDocURL = aDocURL;
|
|
|
|
|
2002-01-01 15:58:53 +03:00
|
|
|
aPrintSettings->GetMarginInTwips(mMargin);
|
|
|
|
|
|
|
|
aPrintSettings->GetStartPageRange(&mFromPageNum);
|
|
|
|
aPrintSettings->GetEndPageRange(&mToPageNum);
|
|
|
|
aPrintSettings->GetMarginInTwips(mMargin);
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2002-01-01 15:58:53 +03:00
|
|
|
mDoingPageRange = nsIPrintSettings::kRangeSpecifiedPageRange == mPrintRangeType ||
|
|
|
|
nsIPrintSettings::kRangeSelection == mPrintRangeType;
|
2001-03-27 15:56:03 +04:00
|
|
|
|
|
|
|
// If printing a range of pages make sure at least the starting page
|
|
|
|
// number is valid
|
|
|
|
PRInt32 totalPages = mFrames.GetLength();
|
|
|
|
|
|
|
|
if (mDoingPageRange) {
|
|
|
|
if (mFromPageNum > totalPages) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Begin printing of the document
|
|
|
|
nsCOMPtr<nsIDeviceContext> dc;
|
|
|
|
aPresContext->GetDeviceContext(getter_AddRefs(dc));
|
|
|
|
NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
NS_ASSERTION(presShell, "nsIPresShell can't be NULL!");
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
|
|
|
|
{
|
|
|
|
nsIView * seqView;
|
|
|
|
GetView(aPresContext, &seqView);
|
|
|
|
nsRect rect;
|
|
|
|
GetRect(rect);
|
2001-04-12 17:04:29 +04:00
|
|
|
fprintf(mDebugFD, "Seq Frame: %p - [%5d,%5d,%5d,%5d] ", this, rect.x, rect.y, rect.width, rect.height);
|
|
|
|
fprintf(mDebugFD, "view: %p ", seqView);
|
2001-03-27 15:56:03 +04:00
|
|
|
nsRect viewRect;
|
|
|
|
if (seqView) {
|
|
|
|
seqView->GetBounds(viewRect);
|
2001-04-12 17:04:29 +04:00
|
|
|
fprintf(mDebugFD, " [%5d,%5d,%5d,%5d]", viewRect.x, viewRect.y, viewRect.width, viewRect.height);
|
2001-03-27 15:56:03 +04:00
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
fprintf(mDebugFD, "\n");
|
2001-03-27 15:56:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
PRInt32 pageNum = 1;
|
|
|
|
for (nsIFrame* page = mFrames.FirstChild(); nsnull != page; page->GetNextSibling(&page)) {
|
|
|
|
nsIView* view;
|
|
|
|
page->GetView(aPresContext, &view);
|
|
|
|
NS_ASSERTION(nsnull != view, "no page view");
|
|
|
|
nsRect rect;
|
|
|
|
page->GetRect(rect);
|
|
|
|
nsRect viewRect;
|
|
|
|
view->GetBounds(viewRect);
|
2001-04-12 17:04:29 +04:00
|
|
|
fprintf(mDebugFD, " Page: %p No: %d - [%5d,%5d,%5d,%5d] ", page, pageNum, rect.x, rect.y, rect.width, rect.height);
|
|
|
|
fprintf(mDebugFD, " [%5d,%5d,%5d,%5d]\n", viewRect.x, viewRect.y, viewRect.width, viewRect.height);
|
2001-03-27 15:56:03 +04:00
|
|
|
pageNum++;
|
|
|
|
}
|
|
|
|
}
|
2002-01-01 15:58:53 +03:00
|
|
|
//printf("***** Setting aPresContext %p is painting selection %d\n", aPresContext, nsIPrintSettings::kRangeSelection == mPrintRangeType);
|
2001-03-27 15:56:03 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Determine if we are rendering only the selection
|
2002-01-01 15:58:53 +03:00
|
|
|
aPresContext->SetIsRenderingOnlySelection(nsIPrintSettings::kRangeSelection == mPrintRangeType);
|
2001-03-27 15:56:03 +04:00
|
|
|
|
|
|
|
|
|
|
|
if (mDoingPageRange) {
|
|
|
|
// XXX because of the hack for making the selection all print on one page
|
|
|
|
// we must make sure that the page is sized correctly before printing.
|
|
|
|
PRInt32 width,height;
|
|
|
|
dc->GetDeviceSurfaceDimensions(width,height);
|
|
|
|
|
|
|
|
PRInt32 pageNum = 1;
|
2001-11-03 17:59:39 +03:00
|
|
|
nscoord y = 0;//mMargin.top;
|
2001-12-01 17:31:45 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRegion> emptyRegion = getter_AddRefs(CreateRegion());
|
2001-03-27 15:56:03 +04:00
|
|
|
for (nsIFrame* page = mFrames.FirstChild(); nsnull != page; page->GetNextSibling(&page)) {
|
2001-12-01 17:31:45 +03:00
|
|
|
nsIView* view = nsnull;
|
2001-03-27 15:56:03 +04:00
|
|
|
page->GetView(aPresContext, &view);
|
|
|
|
NS_ASSERTION(nsnull != view, "no page view");
|
2001-12-01 17:31:45 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
view->GetViewManager(*getter_AddRefs(vm));
|
|
|
|
NS_ASSERTION(nsnull != vm, "no view manager");
|
|
|
|
|
2001-03-27 15:56:03 +04:00
|
|
|
if (pageNum < mFromPageNum || pageNum > mToPageNum) {
|
2001-05-31 01:19:46 +04:00
|
|
|
// Hide the pages that won't be printed to the Viewmanager
|
|
|
|
// doesn't put them in the display list. Also, makde
|
|
|
|
// sure the child views don't get asked to print
|
|
|
|
// but my guess is that there won't be any
|
2001-12-01 17:31:45 +03:00
|
|
|
vm->SetViewVisibility(view, nsViewVisibility_kHide);
|
|
|
|
vm->SetViewChildClipRegion(view, emptyRegion);
|
2001-03-27 15:56:03 +04:00
|
|
|
} else {
|
|
|
|
nsRect rect;
|
|
|
|
page->GetRect(rect);
|
|
|
|
rect.y = y;
|
|
|
|
rect.height = height;
|
|
|
|
page->SetRect(aPresContext, rect);
|
2001-12-01 17:31:45 +03:00
|
|
|
|
2001-03-27 15:56:03 +04:00
|
|
|
nsRect viewRect;
|
|
|
|
view->GetBounds(viewRect);
|
|
|
|
viewRect.y = y;
|
|
|
|
viewRect.height = height;
|
2001-12-01 17:31:45 +03:00
|
|
|
vm->MoveViewTo(view, viewRect.x, viewRect.y);
|
|
|
|
viewRect.x = 0;
|
|
|
|
viewRect.y = 0;
|
|
|
|
vm->ResizeView(view, viewRect);
|
2001-03-27 15:56:03 +04:00
|
|
|
y += rect.height + mMargin.top + mMargin.bottom;
|
|
|
|
}
|
|
|
|
pageNum++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// adjust total number of pages
|
2002-02-12 16:33:39 +03:00
|
|
|
if (nsIPrintSettings::kRangeSelection != mPrintRangeType) {
|
2001-03-27 15:56:03 +04:00
|
|
|
totalPages = pageNum - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX - This wouldn't have to be done each time
|
|
|
|
// but it isn't that expensive and this the best place
|
|
|
|
// to have access to a localized file properties file
|
|
|
|
//
|
|
|
|
// Note: because this is done here it makes a little bit harder
|
|
|
|
// to have UI for setting the header/footer font name and size
|
|
|
|
//
|
|
|
|
// Get default font name and size to be used for the headers and footers
|
|
|
|
nsAutoString fontName;
|
2001-09-26 05:10:14 +04:00
|
|
|
rv = nsFormControlHelper::GetLocalizedString(PRINTING_PROPERTIES, NS_LITERAL_STRING("fontname").get(), fontName);
|
2001-03-27 15:56:03 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2001-12-16 14:58:03 +03:00
|
|
|
fontName.Assign(NS_LITERAL_STRING("serif"));
|
2001-03-27 15:56:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString fontSizeStr;
|
|
|
|
nscoord pointSize = 10;;
|
2001-09-26 05:10:14 +04:00
|
|
|
rv = nsFormControlHelper::GetLocalizedString(PRINTING_PROPERTIES, NS_LITERAL_STRING("fontsize").get(), fontSizeStr);
|
2001-03-27 15:56:03 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
PRInt32 errCode;
|
|
|
|
pointSize = fontSizeStr.ToInteger(&errCode);
|
|
|
|
if (NS_FAILED(errCode)) {
|
|
|
|
pointSize = 10;
|
|
|
|
}
|
|
|
|
}
|
2002-01-01 15:58:53 +03:00
|
|
|
mPageData->mPrintOptions->SetFontNamePointSize(fontName, pointSize);
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2001-09-26 18:01:26 +04:00
|
|
|
// Doing this here so we only have to go get these formats once
|
|
|
|
SetPageNumberFormat("pagenumber", "%1$d", PR_TRUE);
|
|
|
|
SetPageNumberFormat("pageofpages", "%1$d of %2$d", PR_FALSE);
|
2001-03-27 15:56:03 +04:00
|
|
|
|
|
|
|
mPageNum = 1;
|
|
|
|
mPrintedPageNum = 1;
|
|
|
|
mCurrentPageFrame = mFrames.FirstChild();
|
|
|
|
|
2002-02-12 16:33:39 +03:00
|
|
|
if (mTotalPages == -1) {
|
|
|
|
mTotalPages = totalPages;
|
|
|
|
}
|
|
|
|
|
2001-03-27 15:56:03 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-01-01 15:58:53 +03:00
|
|
|
nsSimplePageSequenceFrame::PrintNextPage(nsIPresContext* aPresContext)
|
2001-03-27 15:56:03 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPresContext);
|
|
|
|
|
|
|
|
// Print each specified page
|
|
|
|
// pageNum keeps track of the current page and what pages are printing
|
|
|
|
//
|
|
|
|
// printedPageNum keeps track of the current page number to be printed
|
|
|
|
// Note: When print al the pages or a page range the printed page shows the
|
|
|
|
// actual page number, when printing selection it prints the page number starting
|
|
|
|
// with the first page of the selection. For example if the user has a
|
|
|
|
// selection that starts on page 2 and ends on page 3, the page numbers when
|
|
|
|
// print are 1 and then two (which is different than printing a page range, where
|
|
|
|
// the page numbers would have been 2 and then 3)
|
|
|
|
|
|
|
|
if (mCurrentPageFrame == nsnull) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool printEvenPages, printOddPages;
|
2002-01-01 15:58:53 +03:00
|
|
|
mPageData->mPrintSettings->GetPrintOptions(nsIPrintSettings::kPrintEvenPages, &printEvenPages);
|
|
|
|
mPageData->mPrintSettings->GetPrintOptions(nsIPrintSettings::kPrintOddPages, &printOddPages);
|
2001-03-27 15:56:03 +04:00
|
|
|
|
|
|
|
// Begin printing of the document
|
|
|
|
nsCOMPtr<nsIDeviceContext> dc;
|
|
|
|
aPresContext->GetDeviceContext(getter_AddRefs(dc));
|
|
|
|
NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
NS_ASSERTION(presShell, "nsIPresShell can't be NULL!");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
presShell->GetViewManager(getter_AddRefs(vm));
|
|
|
|
NS_ASSERTION(vm, "nsIViewManager can't be NULL!");
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// See whether we should print this page
|
2001-04-12 17:04:29 +04:00
|
|
|
mPrintThisPage = PR_TRUE;
|
2001-03-27 15:56:03 +04:00
|
|
|
|
|
|
|
// If printing a range of pages check whether the page number is in the
|
|
|
|
// range of pages to print
|
|
|
|
if (mDoingPageRange) {
|
|
|
|
if (mPageNum < mFromPageNum) {
|
2001-04-12 17:04:29 +04:00
|
|
|
mPrintThisPage = PR_FALSE;
|
2001-03-27 15:56:03 +04:00
|
|
|
} else if (mPageNum > mToPageNum) {
|
|
|
|
mPageNum++;
|
|
|
|
mCurrentPageFrame = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for printing of odd and even pages
|
|
|
|
if (mPageNum & 0x1) {
|
|
|
|
if (!printOddPages) {
|
2001-04-12 17:04:29 +04:00
|
|
|
mPrintThisPage = PR_FALSE; // don't print odd numbered page
|
2001-03-27 15:56:03 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!printEvenPages) {
|
2001-04-12 17:04:29 +04:00
|
|
|
mPrintThisPage = PR_FALSE; // don't print even numbered page
|
2001-03-27 15:56:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
if (mPrintThisPage) {
|
2001-11-03 17:59:39 +03:00
|
|
|
// XXX This is temporary fix for printing more than one page of a selection
|
|
|
|
// This does a poor man's "dump" pagination (see Bug 89353)
|
|
|
|
// It has laid out as one long page and now we are just moving or view up/down
|
|
|
|
// one page at a time and printing the contents of what is exposed by the rect.
|
|
|
|
// currently this does not work for IFrames
|
|
|
|
// I will soon improve this to work with IFrames
|
|
|
|
PRBool continuePrinting = PR_TRUE;
|
|
|
|
nscoord selectionHeight = mSelectionHeight;
|
|
|
|
PRInt32 width, height;
|
|
|
|
dc->GetDeviceSurfaceDimensions(width, height);
|
|
|
|
nsRect clipRect(0, 0, width, height);
|
2002-02-12 16:33:39 +03:00
|
|
|
nsRect slidingRect(-1, -1, -1, -1);
|
2001-11-03 17:59:39 +03:00
|
|
|
height -= mMargin.top + mMargin.bottom;
|
|
|
|
width -= mMargin.left + mMargin.right;
|
|
|
|
nscoord selectionY = height;
|
|
|
|
nsIView* containerView = nsnull;
|
|
|
|
nsRect containerRect;
|
|
|
|
if (mSelectionHeight > -1) {
|
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
|
|
|
nsIFrame* conFrame;
|
|
|
|
childFrame->FirstChild(aPresContext, nsnull, &conFrame);
|
|
|
|
conFrame->GetView(aPresContext, &containerView);
|
2002-01-01 15:58:53 +03:00
|
|
|
NS_ASSERTION(containerView != nsnull, "Container view can't be null!");
|
2001-11-03 17:59:39 +03:00
|
|
|
containerView->GetBounds(containerRect);
|
|
|
|
containerRect.y -= mYSelOffset;
|
2002-02-12 16:33:39 +03:00
|
|
|
slidingRect.SetRect(0,mYSelOffset,width,height);
|
2001-12-01 17:31:45 +03:00
|
|
|
|
|
|
|
vm->MoveViewTo(containerView, containerRect.x, containerRect.y);
|
|
|
|
nsRect r(0, 0, containerRect.width, containerRect.height);
|
|
|
|
vm->ResizeView(containerView, r, PR_FALSE);
|
2001-11-03 17:59:39 +03:00
|
|
|
clipRect.SetRect(mMargin.left, mMargin.right, width, height);
|
2001-03-27 15:56:03 +04:00
|
|
|
}
|
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
while (continuePrinting) {
|
2002-02-12 16:33:39 +03:00
|
|
|
if (!mSkipPageBegin) {
|
|
|
|
PRINT_DEBUG_MSG1("\n***************** BeginPage *****************\n");
|
|
|
|
rv = dc->BeginPage();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
// cast the frame to be a page frame
|
|
|
|
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, mCurrentPageFrame);
|
|
|
|
if (pf != nsnull) {
|
|
|
|
pf->SetPageNumInfo(mPrintedPageNum, mTotalPages);
|
|
|
|
pf->SetSharedPageData(mPageData);
|
2002-02-12 16:33:39 +03:00
|
|
|
if (mSelectionHeight > -1) {
|
|
|
|
pf->SetClipRect(&slidingRect);
|
|
|
|
}
|
2001-11-03 17:59:39 +03:00
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
// Print the page
|
|
|
|
nsIView* view;
|
|
|
|
mCurrentPageFrame->GetView(aPresContext, &view);
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
NS_ASSERTION(nsnull != view, "no page view");
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
PRINT_DEBUG_MSG4("SeqFr::Paint -> %p PageNo: %d View: %p", pf, mPageNum, view);
|
|
|
|
PRINT_DEBUG_MSG3(" At: %d,%d\n", mMargin.left+mOffsetX, mMargin.top+mOffsetY);
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2001-12-01 17:31:45 +03:00
|
|
|
vm->SetViewContentTransparency(view, PR_FALSE);
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
vm->Display(view, mOffsetX, mOffsetY, clipRect);
|
|
|
|
|
|
|
|
// this view was printed and since display set the origin
|
|
|
|
// 0,0 there is a danger that this view can be printed again
|
|
|
|
// If it is a sibling to another page/view. Setting the visibility
|
|
|
|
// to hide will keep this page from printing again - dwc
|
|
|
|
//
|
|
|
|
// XXX Doesn't seem like we need to do this anymore
|
|
|
|
//view->SetVisibility(nsViewVisibility_kHide);
|
|
|
|
|
|
|
|
if (!mSkipPageEnd) {
|
|
|
|
PRINT_DEBUG_MSG1("***************** End Page (PrintNextPage) *****************\n");
|
|
|
|
rv = dc->EndPage();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSelectionHeight > -1 && selectionY < mSelectionHeight) {
|
|
|
|
selectionY += height;
|
|
|
|
|
|
|
|
mPrintedPageNum++;
|
|
|
|
pf->SetPageNumInfo(mPrintedPageNum, mTotalPages);
|
|
|
|
containerRect.y -= height;
|
|
|
|
containerRect.height += height;
|
2001-12-01 17:31:45 +03:00
|
|
|
vm->MoveViewTo(containerView, containerRect.x, containerRect.y);
|
|
|
|
nsRect r(0, 0, containerRect.width, containerRect.height);
|
|
|
|
vm->ResizeView(containerView, r, PR_FALSE);
|
2002-02-12 16:33:39 +03:00
|
|
|
if (pf != nsnull) {
|
|
|
|
slidingRect.y += height;
|
|
|
|
}
|
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
} else {
|
|
|
|
continuePrinting = PR_FALSE;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mSkipPageEnd) {
|
2002-01-01 15:58:53 +03:00
|
|
|
if (nsIPrintSettings::kRangeSelection != mPrintRangeType ||
|
|
|
|
(nsIPrintSettings::kRangeSelection == mPrintRangeType && mPrintThisPage)) {
|
2001-04-12 17:04:29 +04:00
|
|
|
mPrintedPageNum++;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPageNum++;
|
|
|
|
rv = mCurrentPageFrame->GetNextSibling(&mCurrentPageFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::DoPageEnd(nsIPresContext* aPresContext)
|
|
|
|
{
|
2001-04-25 18:26:28 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
if (mPrintThisPage) {
|
|
|
|
nsCOMPtr<nsIDeviceContext> dc;
|
|
|
|
aPresContext->GetDeviceContext(getter_AddRefs(dc));
|
|
|
|
NS_ASSERTION(dc, "nsIDeviceContext can't be NULL!");
|
|
|
|
|
2001-04-25 18:26:28 +04:00
|
|
|
if(mSkipPageEnd){
|
|
|
|
PRINT_DEBUG_MSG1("***************** End Page (DoPageEnd) *****************\n");
|
|
|
|
nsresult rv = dc->EndPage();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-03-27 15:56:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-01 15:58:53 +03:00
|
|
|
if (nsIPrintSettings::kRangeSelection != mPrintRangeType ||
|
|
|
|
(nsIPrintSettings::kRangeSelection == mPrintRangeType && mPrintThisPage)) {
|
2001-03-27 15:56:03 +04:00
|
|
|
mPrintedPageNum++;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPageNum++;
|
2001-04-25 18:26:28 +04:00
|
|
|
|
|
|
|
if( nsnull != mCurrentPageFrame){
|
|
|
|
rv = mCurrentPageFrame->GetNextSibling(&mCurrentPageFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
2001-03-27 15:56:03 +04:00
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::SuppressHeadersAndFooters(PRBool aDoSup)
|
|
|
|
{
|
|
|
|
for (nsIFrame* f = mFrames.FirstChild(); f != nsnull; f->GetNextSibling(&f)) {
|
|
|
|
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, f);
|
|
|
|
if (pf != nsnull) {
|
|
|
|
pf->SuppressHeadersAndFooters(aDoSup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2001-03-27 15:56:03 +04:00
|
|
|
}
|
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::SetClipRect(nsIPresContext* aPresContext, nsRect* aRect)
|
|
|
|
{
|
|
|
|
for (nsIFrame* f = mFrames.FirstChild(); f != nsnull; f->GetNextSibling(&f)) {
|
|
|
|
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, f);
|
|
|
|
if (pf != nsnull) {
|
|
|
|
pf->SetClipRect(aRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::SetDebugFD(FILE* aFD)
|
|
|
|
{
|
|
|
|
mDebugFD = aFD;
|
|
|
|
for (nsIFrame* f = mFrames.FirstChild(); f != nsnull; f->GetNextSibling(&f)) {
|
|
|
|
nsPageFrame * pf = NS_STATIC_CAST(nsPageFrame*, f);
|
|
|
|
if (pf != nsnull) {
|
|
|
|
pf->SetDebugFD(aFD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
2001-09-26 18:01:26 +04:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::Paint(nsIPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
|
|
|
{
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetColor(NS_RGB(255,255,255));
|
|
|
|
|
|
|
|
|
|
|
|
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
|
|
|
|
nsRect rect = mRect;
|
|
|
|
aRenderingContext.SetColor(NS_RGB(255,255,255));
|
|
|
|
rect.x = 0;
|
|
|
|
rect.y = 0;
|
|
|
|
aRenderingContext.FillRect(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = nsContainerFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
|
|
|
|
|
|
|
PRBool clipEmpty;
|
|
|
|
aRenderingContext.PopState(clipEmpty);
|
|
|
|
return rv;
|
|
|
|
}
|
2001-11-03 17:59:39 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsSimplePageSequenceFrame::SizeTo(nsIPresContext* aPresContext, nscoord aWidth, nscoord aHeight)
|
|
|
|
{
|
|
|
|
return nsFrame::SizeTo(aPresContext, aWidth, aHeight);
|
|
|
|
}
|
|
|
|
|
2002-03-04 15:55:20 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimplePageSequenceFrame::GetFrameType(nsIAtom** aType) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer");
|
|
|
|
*aType = nsLayoutAtoms::sequenceFrame;
|
|
|
|
NS_ADDREF(*aType);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-11-03 17:59:39 +03:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsSimplePageSequenceFrame::SetPageNumberFormat(PRUnichar * aFormatStr, PRBool aForPageNumOnly)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFormatStr != nsnull, "Format string cannot be null!");
|
|
|
|
NS_ASSERTION(mPageData != nsnull, "mPageData string cannot be null!");
|
|
|
|
|
|
|
|
if (aForPageNumOnly) {
|
|
|
|
if (mPageData->mPageNumFormat != nsnull) {
|
|
|
|
nsMemory::Free(mPageData->mPageNumFormat);
|
|
|
|
}
|
|
|
|
mPageData->mPageNumFormat = aFormatStr;
|
|
|
|
} else {
|
|
|
|
if (mPageData->mPageNumAndTotalsFormat != nsnull) {
|
|
|
|
nsMemory::Free(mPageData->mPageNumAndTotalsFormat);
|
|
|
|
}
|
|
|
|
mPageData->mPageNumAndTotalsFormat = aFormatStr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsSimplePageSequenceFrame::SetDateTimeStr(PRUnichar * aDateTimeStr)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aDateTimeStr != nsnull, "DateTime string cannot be null!");
|
|
|
|
NS_ASSERTION(mPageData != nsnull, "mPageData string cannot be null!");
|
|
|
|
|
|
|
|
if (mPageData->mDateTimeStr != nsnull) {
|
|
|
|
nsMemory::Free(mPageData->mDateTimeStr);
|
|
|
|
}
|
|
|
|
mPageData->mDateTimeStr = aDateTimeStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsSimplePageSequenceFrame::SetPageSizes(const nsRect& aRect, const nsMargin& aMarginRect)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mPageData != nsnull, "mPageData string cannot be null!");
|
|
|
|
|
|
|
|
mPageData->mReflowRect = aRect;
|
|
|
|
mPageData->mReflowMargin = aMarginRect;
|
|
|
|
}
|
2002-03-04 15:55:20 +03:00
|
|
|
|