1998-04-14 00:24:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:40:37 +03: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-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03: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-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-04-14 00:24:54 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:40:37 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-04-14 00:24:54 +04:00
|
|
|
*/
|
|
|
|
#include "nsPageFrame.h"
|
1998-12-18 08:44:26 +03:00
|
|
|
#include "nsHTMLParts.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIStyleContext.h"
|
1998-06-09 08:51:44 +04:00
|
|
|
#include "nsIReflowCommand.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIRenderingContext.h"
|
1998-06-25 18:53:45 +04:00
|
|
|
#include "nsHTMLAtoms.h"
|
1998-10-01 08:46:11 +04:00
|
|
|
#include "nsHTMLIIDs.h"
|
1999-02-14 06:47:33 +03:00
|
|
|
#include "nsLayoutAtoms.h"
|
1999-02-24 07:03:50 +03:00
|
|
|
#include "nsIStyleSet.h"
|
|
|
|
#include "nsIPresShell.h"
|
2001-01-27 17:09:34 +03:00
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
|
|
|
|
// for page number localization formatting
|
|
|
|
#include "nsTextFormatter.h"
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
// Temporary
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
|
|
|
|
// tstaic data members
|
|
|
|
PRUnichar * nsPageFrame::mPageNumFormat = nsnull;
|
1998-04-14 00:24:54 +04: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
|
|
|
|
|
1999-05-12 02:03:29 +04:00
|
|
|
nsresult
|
1999-12-05 02:49:50 +03:00
|
|
|
NS_NewPageFrame(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
|
|
|
nsPageFrame* it = new (aPresShell) nsPageFrame;
|
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
|
|
|
nsPageFrame::nsPageFrame() :
|
2001-04-12 17:04:29 +04:00
|
|
|
mHeadFootFont(nsnull),
|
|
|
|
mSupressHF(PR_FALSE),
|
|
|
|
mClipRect(-1, -1, -1, -1)
|
|
|
|
|
1999-02-19 01:23:36 +03:00
|
|
|
{
|
2001-04-12 17:04:29 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
mDebugFD = stdout;
|
|
|
|
#endif
|
1999-02-19 01:23:36 +03:00
|
|
|
}
|
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
nsPageFrame::~nsPageFrame()
|
|
|
|
{
|
|
|
|
if (mHeadFootFont)
|
|
|
|
delete mHeadFootFont;
|
|
|
|
|
|
|
|
if (mPageNumFormat) {
|
|
|
|
nsMemory::Free(mPageNumFormat);
|
|
|
|
mPageNumFormat = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_METHOD nsPageFrame::Reflow(nsIPresContext* aPresContext,
|
1998-10-02 08:10:00 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2000-04-21 18:59:47 +04:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsPageFrame", aReflowState.reason);
|
1998-05-12 08:17:56 +04:00
|
|
|
aStatus = NS_FRAME_COMPLETE; // initialize out parameter
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-25 21:31:49 +04:00
|
|
|
if (eReflowReason_Incremental == aReflowState.reason) {
|
|
|
|
// We don't expect the target of the reflow command to be page frame
|
1998-06-09 08:51:44 +04:00
|
|
|
#ifdef NS_DEUG
|
1998-05-25 21:31:49 +04:00
|
|
|
NS_ASSERTION(nsnull != aReflowState.reflowCommand, "null reflow command");
|
1998-06-09 08:51:44 +04:00
|
|
|
|
|
|
|
nsIFrame* target;
|
|
|
|
aReflowState.reflowCommand->GetTarget(target);
|
|
|
|
NS_ASSERTION(target != this, "page frame is reflow command target");
|
|
|
|
#endif
|
1998-05-25 21:31:49 +04:00
|
|
|
|
|
|
|
// Verify the next reflow command frame is our one and only child frame
|
1998-06-09 08:51:44 +04:00
|
|
|
nsIFrame* next;
|
|
|
|
aReflowState.reflowCommand->GetNext(next);
|
1999-01-16 01:53:39 +03:00
|
|
|
NS_ASSERTION(next == mFrames.FirstChild(), "bad reflow frame");
|
1998-05-25 21:31:49 +04:00
|
|
|
|
1999-03-09 08:01:59 +03:00
|
|
|
// Dispatch the reflow command to our frame
|
|
|
|
nsSize maxSize(aReflowState.availableWidth, aReflowState.availableHeight);
|
1999-03-05 07:28:07 +03:00
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState,
|
|
|
|
mFrames.FirstChild(), maxSize);
|
1998-05-25 21:31:49 +04:00
|
|
|
|
1998-12-12 20:58:18 +03:00
|
|
|
kidReflowState.isTopOfPage = PR_TRUE;
|
1999-01-16 01:53:39 +03:00
|
|
|
ReflowChild(mFrames.FirstChild(), aPresContext, aDesiredSize,
|
1999-11-19 18:33:29 +03:00
|
|
|
kidReflowState, 0, 0, 0, aStatus);
|
1998-05-25 21:31:49 +04:00
|
|
|
|
|
|
|
// Place and size the child. Make sure the child is at least as
|
|
|
|
// tall as our max size (the containing window)
|
1999-01-06 02:31:18 +03:00
|
|
|
if (aDesiredSize.height < aReflowState.availableHeight) {
|
|
|
|
aDesiredSize.height = aReflowState.availableHeight;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-11-19 18:33:29 +03:00
|
|
|
FinishReflowChild(mFrames.FirstChild(), aPresContext, aDesiredSize,
|
|
|
|
0, 0, 0);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-25 21:31:49 +04:00
|
|
|
} else {
|
|
|
|
// Do we have any children?
|
1998-11-05 09:12:57 +03:00
|
|
|
// XXX We should use the overflow list instead...
|
1999-01-16 01:53:39 +03:00
|
|
|
if (mFrames.IsEmpty() && (nsnull != mPrevInFlow)) {
|
1998-11-05 09:12:57 +03:00
|
|
|
nsPageFrame* prevPage = (nsPageFrame*)mPrevInFlow;
|
|
|
|
|
1999-01-16 01:53:39 +03:00
|
|
|
nsIFrame* prevLastChild = prevPage->mFrames.LastChild();
|
1998-11-05 09:12:57 +03:00
|
|
|
|
|
|
|
// Create a continuing child of the previous page's last child
|
1999-02-24 07:03:50 +03:00
|
|
|
nsIPresShell* presShell;
|
|
|
|
nsIStyleSet* styleSet;
|
|
|
|
nsIFrame* newFrame;
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetShell(&presShell);
|
1999-02-24 07:03:50 +03:00
|
|
|
presShell->GetStyleSet(&styleSet);
|
|
|
|
NS_RELEASE(presShell);
|
1999-11-24 09:03:41 +03:00
|
|
|
styleSet->CreateContinuingFrame(aPresContext, prevLastChild, this, &newFrame);
|
1999-02-24 07:03:50 +03:00
|
|
|
NS_RELEASE(styleSet);
|
1999-01-16 01:53:39 +03:00
|
|
|
mFrames.SetFrames(newFrame);
|
1998-05-25 21:31:49 +04:00
|
|
|
}
|
1998-11-05 09:12:57 +03:00
|
|
|
|
1998-05-25 21:31:49 +04:00
|
|
|
// Resize our frame allowing it only to be as big as we are
|
|
|
|
// XXX Pay attention to the page's border and padding...
|
1999-01-16 01:53:39 +03:00
|
|
|
if (mFrames.NotEmpty()) {
|
|
|
|
nsIFrame* frame = mFrames.FirstChild();
|
1999-01-06 02:31:18 +03:00
|
|
|
nsSize maxSize(aReflowState.availableWidth, aReflowState.availableHeight);
|
1999-03-05 07:28:07 +03:00
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, frame,
|
1999-01-06 02:31:18 +03:00
|
|
|
maxSize);
|
1998-12-12 20:58:18 +03:00
|
|
|
kidReflowState.isTopOfPage = PR_TRUE;
|
1998-05-30 00:36:05 +04:00
|
|
|
|
1999-10-30 06:52:11 +04:00
|
|
|
// Get the child's desired size
|
1999-11-19 18:33:29 +03:00
|
|
|
ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, 0, 0, 0, aStatus);
|
1999-10-30 06:52:11 +04:00
|
|
|
|
|
|
|
// Make sure the child is at least as tall as our max size (the containing window)
|
|
|
|
if (aDesiredSize.height < aReflowState.availableHeight) {
|
|
|
|
aDesiredSize.height = aReflowState.availableHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Place and size the child
|
1999-11-19 18:33:29 +03:00
|
|
|
FinishReflowChild(frame, aPresContext, aDesiredSize, 0, 0, 0);
|
1999-10-30 06:52:11 +04:00
|
|
|
|
|
|
|
// Is the frame complete?
|
|
|
|
if (NS_FRAME_IS_COMPLETE(aStatus)) {
|
|
|
|
nsIFrame* childNextInFlow;
|
|
|
|
|
|
|
|
frame->GetNextInFlow(&childNextInFlow);
|
|
|
|
NS_ASSERTION(nsnull == childNextInFlow, "bad child flow list");
|
1998-05-25 21:31:49 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
PRINT_DEBUG_MSG2("PageFrame::Reflow %p ", this);
|
|
|
|
PRINT_DEBUG_MSG5("[%d,%d][%d,%d]\n", aDesiredSize.width, aDesiredSize.height, aReflowState.availableWidth, aReflowState.availableHeight);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-25 21:31:49 +04:00
|
|
|
// Return our desired size
|
1999-01-06 02:31:18 +03:00
|
|
|
aDesiredSize.width = aReflowState.availableWidth;
|
|
|
|
aDesiredSize.height = aReflowState.availableHeight;
|
1998-05-25 21:31:49 +04:00
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
PRINT_DEBUG_MSG2("PageFrame::Reflow %p ", this);
|
|
|
|
PRINT_DEBUG_MSG3("[%d,%d]\n", aReflowState.availableWidth, aReflowState.availableHeight);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-02-14 06:47:33 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPageFrame::GetFrameType(nsIAtom** aType) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer");
|
|
|
|
*aType = nsLayoutAtoms::pageFrame;
|
|
|
|
NS_ADDREF(*aType);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef DEBUG
|
1998-11-19 20:22:29 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPageFrame::GetFrameName(nsString& aResult) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-11-19 20:22:29 +03:00
|
|
|
return MakeFrameName("Page", aResult);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-03-05 07:28:07 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPageFrame::IsPercentageBase(PRBool& aBase) const
|
|
|
|
{
|
|
|
|
aBase = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-01-27 17:09:34 +03:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
nscoord nsPageFrame::GetXPosition(nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aRect,
|
|
|
|
PRInt32 aJust,
|
|
|
|
const nsString& aStr)
|
|
|
|
{
|
|
|
|
PRInt32 width;
|
|
|
|
aRenderingContext.GetWidth(aStr, width);
|
|
|
|
|
|
|
|
nscoord x = aRect.x;
|
|
|
|
switch (aJust) {
|
2001-02-02 11:42:53 +03:00
|
|
|
case nsIPrintOptions::kJustLeft:
|
2001-01-27 17:09:34 +03:00
|
|
|
// do nothing, already set
|
|
|
|
break;
|
|
|
|
|
2001-02-02 11:42:53 +03:00
|
|
|
case nsIPrintOptions::kJustCenter:
|
2001-01-27 17:09:34 +03:00
|
|
|
x += (aRect.width - width) / 2;
|
|
|
|
break;
|
|
|
|
|
2001-02-02 11:42:53 +03:00
|
|
|
case nsIPrintOptions::kJustRight:
|
2001-01-27 17:09:34 +03:00
|
|
|
x += aRect.width - width;
|
|
|
|
break;
|
|
|
|
} // switch
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Draw a Header or footer text lrft,right or center justified
|
|
|
|
// @parm aRenderingContext - rendering content ot draw into
|
|
|
|
// @parm aHeaderFooter - indicates whether it is a header or footer
|
|
|
|
// @parm aJust - indicates the justification of the text
|
|
|
|
// @parm aStr - The string to be drawn
|
|
|
|
// @parm aRect - the rect of the page
|
|
|
|
// @parm aHeight - the height of the text
|
|
|
|
// @parm aUseHalfThePage - indicates whether the text should limited to the width
|
|
|
|
// of the entire page or just half the page
|
|
|
|
void
|
|
|
|
nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame * aFrame,
|
|
|
|
nsHeaderFooterEnum aHeaderFooter,
|
|
|
|
PRInt32 aJust,
|
|
|
|
const nsString& aStr,
|
|
|
|
const nsRect& aRect,
|
|
|
|
nscoord aHeight,
|
|
|
|
PRBool aUseHalfThePage)
|
|
|
|
{
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
// first make sure we have a vaild string and that the height of the
|
|
|
|
// text will fit in the margin
|
|
|
|
if (aStr.Length() > 0 &&
|
|
|
|
((aHeaderFooter == eHeader && aHeight < mMargin.top) ||
|
|
|
|
(aHeaderFooter == eFooter && aHeight < mMargin.bottom))) {
|
|
|
|
// measure the width of the text
|
|
|
|
nsString str = aStr;
|
|
|
|
PRInt32 width;
|
|
|
|
aRenderingContext.GetWidth(str, width);
|
|
|
|
PRBool addEllipse = PR_FALSE;
|
|
|
|
nscoord halfWidth = aRect.width;
|
|
|
|
if (aUseHalfThePage) {
|
|
|
|
halfWidth /= 2;
|
|
|
|
}
|
|
|
|
// trim the text and add the elipses if it won't fit
|
|
|
|
while (width >= halfWidth && str.Length() > 1) {
|
|
|
|
str.SetLength(str.Length()-1);
|
|
|
|
aRenderingContext.GetWidth(str, width);
|
|
|
|
addEllipse = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (addEllipse && str.Length() > 3) {
|
|
|
|
str.SetLength(str.Length()-3);
|
|
|
|
str.AppendWithConversion("...");
|
|
|
|
aRenderingContext.GetWidth(str, width);
|
|
|
|
}
|
|
|
|
|
|
|
|
// cacl the x and y positions of the text
|
|
|
|
nsRect rect(aRect);
|
2001-07-24 17:53:52 +04:00
|
|
|
nscoord quarterInch = NS_INCHES_TO_TWIPS(0.25);
|
|
|
|
rect.Deflate(quarterInch,0);
|
2001-01-27 17:09:34 +03:00
|
|
|
nscoord x = GetXPosition(aRenderingContext, rect, aJust, str);
|
|
|
|
nscoord y;
|
|
|
|
if (aHeaderFooter == eHeader) {
|
|
|
|
nscoord offset = ((mMargin.top - aHeight) / 2);
|
|
|
|
y = rect.y - offset - aHeight;
|
|
|
|
rect.Inflate(0, offset + aHeight);
|
|
|
|
} else {
|
|
|
|
nscoord offset = ((mMargin.bottom - aHeight) / 2);
|
|
|
|
y = rect.y + rect.height + offset;
|
|
|
|
rect.height += offset + aHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up new clip and draw the text
|
|
|
|
PRBool clipEmpty;
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetClipRect(rect, nsClipCombine_kReplace, clipEmpty);
|
|
|
|
aRenderingContext.DrawString(str, x, y);
|
|
|
|
aRenderingContext.PopState(clipEmpty);
|
2001-04-12 17:04:29 +04:00
|
|
|
#ifdef DEBUG_PRINTING
|
|
|
|
PRINT_DEBUG_MSG2("Page: %p", this);
|
|
|
|
char * s = str.ToNewCString();
|
|
|
|
if (s) {
|
|
|
|
PRINT_DEBUG_MSG2(" [%s]", s);
|
|
|
|
nsMemory::Free(s);
|
|
|
|
}
|
|
|
|
char justStr[64];
|
|
|
|
switch (aJust) {
|
|
|
|
case nsIPrintOptions::kJustLeft:strcpy(justStr, "Left");break;
|
|
|
|
case nsIPrintOptions::kJustCenter:strcpy(justStr, "Center");break;
|
|
|
|
case nsIPrintOptions::kJustRight:strcpy(justStr, "Right");break;
|
|
|
|
} // switch
|
|
|
|
PRINT_DEBUG_MSG2(" HF: %s ", aHeaderFooter==eHeader?"Header":"Footer");
|
|
|
|
PRINT_DEBUG_MSG2(" JST: %s ", justStr);
|
|
|
|
PRINT_DEBUG_MSG3(" x,y: %d,%d", x, y);
|
|
|
|
PRINT_DEBUG_MSG2(" Hgt: %d ", aHeight);
|
|
|
|
PRINT_DEBUG_MSG2(" Half: %s\n", aUseHalfThePage?"Yes":"No");
|
|
|
|
#endif
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPageFrame::Paint(nsIPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
|
|
|
{
|
2001-04-12 17:04:29 +04:00
|
|
|
aRenderingContext.PushState();
|
|
|
|
PRBool clipEmpty;
|
|
|
|
if (mClipRect.width != -1 || mClipRect.height != -1) {
|
|
|
|
#ifdef DEBUG_PRINTING
|
|
|
|
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
|
|
|
|
printf("*** ClipRect: %5d,%5d,%5d,%5d\n", mClipRect.x, mClipRect.y, mClipRect.width, mClipRect.height);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
mClipRect.x = 0;
|
|
|
|
mClipRect.y = 0;
|
|
|
|
aRenderingContext.SetClipRect(mClipRect, nsClipCombine_kReplace, clipEmpty);
|
|
|
|
}
|
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
nsresult rv = nsContainerFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
|
2001-01-27 17:09:34 +03:00
|
|
|
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
|
2001-04-12 17:04:29 +04:00
|
|
|
nsRect r;
|
|
|
|
fprintf(mDebugFD, "PF::Paint -> %p SupHF: %s Rect: [%5d,%5d,%5d,%5d]\n", this,
|
|
|
|
mSupressHF?"Yes":"No", mRect.x, mRect.y, mRect.width, mRect.height);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer && !mSupressHF) {
|
2001-01-27 17:09:34 +03:00
|
|
|
// get the current margin
|
2001-02-02 11:42:53 +03:00
|
|
|
mPrintOptions->GetMarginInTwips(mMargin);
|
2001-01-27 17:09:34 +03:00
|
|
|
|
|
|
|
nsRect rect(0,0,mRect.width, mRect.height);
|
|
|
|
|
|
|
|
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
|
|
|
|
// XXX Paint a one-pixel border around the page so it's easy to see where
|
|
|
|
// each page begins and ends when we're
|
|
|
|
float p2t;
|
|
|
|
aPresContext->GetPixelsToTwips(&p2t);
|
|
|
|
rect.Deflate(NSToCoordRound(p2t), NSToCoordRound(p2t));
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0, 0, 0));
|
2001-04-12 17:04:29 +04:00
|
|
|
aRenderingContext.DrawRect(rect);
|
2001-01-27 17:09:34 +03:00
|
|
|
rect.Inflate(NSToCoordRound(p2t), NSToCoordRound(p2t));
|
2001-04-12 17:04:29 +04:00
|
|
|
fprintf(mDebugFD, "PageFr::PaintChild -> Painting Frame %p Page No: %d\n", this, mPageNum);
|
2001-01-27 17:09:34 +03:00
|
|
|
#endif
|
|
|
|
// use the whole page
|
|
|
|
rect.width += mMargin.left + mMargin.right;
|
|
|
|
rect.x -= mMargin.left;
|
|
|
|
|
|
|
|
aRenderingContext.SetFont(*mHeadFootFont);
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
|
|
|
|
|
|
|
// Get the FontMetrics to determine width.height of strings
|
|
|
|
nsCOMPtr<nsIDeviceContext> deviceContext;
|
|
|
|
aPresContext->GetDeviceContext(getter_AddRefs(deviceContext));
|
|
|
|
NS_ASSERTION(deviceContext, "Couldn't get the device context");
|
|
|
|
nsCOMPtr<nsIFontMetrics> fontMet;
|
|
|
|
deviceContext->GetMetricsFor(*mHeadFootFont, *getter_AddRefs(fontMet));
|
|
|
|
nscoord visibleHeight = 0;
|
|
|
|
if (fontMet) {
|
|
|
|
fontMet->GetHeight(visibleHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the print options bits so we can figure out all the
|
|
|
|
// the extra pieces of text that need to be drawn
|
|
|
|
PRInt32 printOptBits;
|
|
|
|
mPrintOptions->GetPrintOptionsBits(&printOptBits);
|
|
|
|
|
|
|
|
// print page numbers
|
2001-02-02 11:42:53 +03:00
|
|
|
if (printOptBits & nsIPrintOptions::kOptPrintPageNums && mPageNumFormat != nsnull) {
|
|
|
|
PRInt16 justify = nsIPrintOptions::kJustLeft;
|
2001-01-27 17:09:34 +03:00
|
|
|
mPrintOptions->GetPageNumJust(&justify);
|
|
|
|
|
|
|
|
PRUnichar * valStr;
|
|
|
|
// print page number totals "x of x"
|
2001-02-02 11:42:53 +03:00
|
|
|
if (printOptBits & nsIPrintOptions::kOptPrintPageTotal) {
|
2001-01-27 17:09:34 +03:00
|
|
|
valStr = nsTextFormatter::smprintf(mPageNumFormat, mPageNum, mTotNumPages);
|
|
|
|
} else {
|
|
|
|
valStr = nsTextFormatter::smprintf(mPageNumFormat, mPageNum);
|
|
|
|
}
|
|
|
|
nsAutoString pageNoStr(valStr);
|
|
|
|
nsMemory::Free(valStr);
|
|
|
|
DrawHeaderFooter(aRenderingContext, this, eFooter, justify, pageNoStr, rect, visibleHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
// print localized date
|
2001-02-02 11:42:53 +03:00
|
|
|
if (printOptBits & nsIPrintOptions::kOptPrintDatePrinted) {
|
2001-01-27 17:09:34 +03:00
|
|
|
// Get Locale for Formating DateTime
|
|
|
|
nsCOMPtr<nsILocale> locale;
|
2001-07-25 11:54:28 +04:00
|
|
|
nsCOMPtr<nsILocaleService> localeSvc =
|
|
|
|
do_GetService(kLocaleServiceCID, &rv);
|
2001-01-27 17:09:34 +03:00
|
|
|
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 );
|
2001-06-14 00:20:43 +04:00
|
|
|
rv = dateTime->FormatTime(locale, kDateFormatShort, kTimeFormatNoSeconds, ltime, dateString);
|
2001-01-27 17:09:34 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2001-02-02 11:42:53 +03:00
|
|
|
DrawHeaderFooter(aRenderingContext, this, eFooter, nsIPrintOptions::kJustRight, dateString, rect, visibleHeight);
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-02 11:42:53 +03:00
|
|
|
PRBool usingHalfThePage = (printOptBits & nsIPrintOptions::kOptPrintDocTitle) &&
|
|
|
|
(printOptBits & nsIPrintOptions::kOptPrintDocLoc);
|
2001-01-27 17:09:34 +03:00
|
|
|
|
|
|
|
// print document title
|
|
|
|
PRUnichar * title;
|
|
|
|
mPrintOptions->GetTitle(&title); // creates memory
|
2001-02-02 11:42:53 +03:00
|
|
|
if (title != nsnull && (printOptBits & nsIPrintOptions::kOptPrintDocTitle)) {
|
|
|
|
DrawHeaderFooter(aRenderingContext, this, eHeader, nsIPrintOptions::kJustLeft, nsAutoString(title), rect, visibleHeight, usingHalfThePage);
|
2001-01-27 17:09:34 +03:00
|
|
|
nsMemory::Free(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
// print document URL
|
|
|
|
PRUnichar * url;
|
2001-02-02 11:42:53 +03:00
|
|
|
mPrintOptions->GetDocURL(&url);
|
2001-05-18 00:54:05 +04:00
|
|
|
if ((nsnull != url) && (printOptBits & nsIPrintOptions::kOptPrintDocLoc)) {
|
2001-02-02 11:42:53 +03:00
|
|
|
DrawHeaderFooter(aRenderingContext, this, eHeader, nsIPrintOptions::kJustRight, nsAutoString(url), rect, visibleHeight, usingHalfThePage);
|
2001-01-27 17:09:34 +03:00
|
|
|
nsMemory::Free(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
aRenderingContext.PopState(clipEmpty);
|
2001-01-27 17:09:34 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsPageFrame::SetPrintOptions(nsIPrintOptions * aPrintOptions)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aPrintOptions != nsnull, "Print Options can not be null!");
|
|
|
|
|
|
|
|
mPrintOptions = aPrintOptions;
|
|
|
|
// create a default font
|
|
|
|
mHeadFootFont = new nsFont("serif", NS_FONT_STYLE_NORMAL,NS_FONT_VARIANT_NORMAL,
|
|
|
|
NS_FONT_WEIGHT_NORMAL,0,NSIntPointsToTwips(10));
|
|
|
|
// now get the default font form the print options
|
|
|
|
mPrintOptions->GetDefaultFont(*mHeadFootFont);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsPageFrame::SetPageNumInfo(PRInt32 aPageNumber, PRInt32 aTotalPages)
|
|
|
|
{
|
|
|
|
mPageNum = aPageNumber;
|
2001-04-12 17:04:29 +04:00
|
|
|
mTotNumPages = aTotalPages;
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsPageFrame::SetPageNumberFormat(PRUnichar * aFormatStr)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFormatStr != nsnull, "Format string cannot be null!");
|
|
|
|
|
|
|
|
if (mPageNumFormat != nsnull) {
|
|
|
|
nsMemory::Free(mPageNumFormat);
|
|
|
|
}
|
|
|
|
mPageNumFormat = aFormatStr;
|
|
|
|
}
|