sl@0: /*
sl@0: * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: * All rights reserved.
sl@0: * This component and the accompanying materials are made available
sl@0: * under the terms of "Eclipse Public License v1.0"
sl@0: * which accompanies this distribution, and is available
sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: *
sl@0: * Initial Contributors:
sl@0: * Nokia Corporation - initial contribution.
sl@0: *
sl@0: * Contributors:
sl@0: *
sl@0: * Description: 
sl@0: *
sl@0: */
sl@0: 
sl@0: 
sl@0: #ifndef __FRMPAGE_H__
sl@0: #define __FRMPAGE_H__
sl@0: 
sl@0: #include <e32std.h>
sl@0: #include <e32base.h>
sl@0: #include <gdi.h>
sl@0: 
sl@0: class MLayDoc;
sl@0: class CTextLayout;
sl@0: class CParaFormat;
sl@0: 
sl@0: //
sl@0: // The following two classes are for internal use only
sl@0: //
sl@0: 
sl@0: /**
sl@0: @internalComponent
sl@0: */
sl@0: struct TPageLine
sl@0: 	{
sl@0: 	TInt iDocPos;
sl@0: 	TInt iLineHeight;
sl@0: 	TBool iKeepWithNext;
sl@0: 	TBool iStartNewPage;
sl@0: 	};
sl@0: 
sl@0: /**
sl@0: @internalComponent
sl@0: */
sl@0: class TLinePaginator
sl@0: 	{
sl@0: public:
sl@0: 	TLinePaginator();
sl@0: 	TBool AppendLineL(TPageLine aLine);
sl@0:  	void FlushL(TInt aEndDocPos);
sl@0: 	void SetPageHeight(TInt aPageHeight);
sl@0: 	void SetArray(CArrayFix<TInt>* aCharsPerPage);
sl@0: 	void Reset();
sl@0: private:
sl@0: 	void ResetArray();
sl@0:  	void InsertPageBreakL();
sl@0: 	void SetPotentialBreakPoint(TInt aDocPos);
sl@0: 	void CheckTallLineL(TPageLine& aLine);
sl@0: private:
sl@0: 	CArrayFix<TInt>* iPageList;	 // This is created and destroyed by the application running the paginator.
sl@0: 	TInt iDocPos;
sl@0: 	TBool iKeepWithPrev;
sl@0: 	TInt iPageHeight;
sl@0: 	TInt iHeightRem;
sl@0: 	TBool iBreakOnPage;
sl@0: 	TInt iPrevPageBreak;
sl@0: 	TInt iHeightLines;
sl@0: 	TBool iFirstLine;  // Used to prevent page break being inserted at top of document.
sl@0: 	};
sl@0: 
sl@0: /** 
sl@0: An abstract class which must be mixed with application calling the active object.
sl@0: It specifies the protocol for a pagination observer. A
sl@0: pagination observer may be used when paginating a document in the background
sl@0: (using CTextPaginator::PaginateCompleteDocumentL()). It notifies the client
sl@0: on page completion, document completion, and on errors.
sl@0: 
sl@0: The observer is set up using the function CTextPaginator::SetObserver().
sl@0: @publishedAll
sl@0: @released
sl@0: */
sl@0: class MPaginateObserver
sl@0: 	{
sl@0: public:
sl@0: 
sl@0: 	/** Notifies the client on completion of document pagination. */
sl@0: 	virtual void NotifyCompletion()=0;
sl@0: 
sl@0: 	/** Notifies the client when a leave is trapped or when the pagination is cancelled.
sl@0: 	Implements error handling.
sl@0: 	@param anErrorCode Error code - indicates the type of error. */
sl@0: 	virtual void NotifyError(TInt anErrorCode)=0;
sl@0: 
sl@0: 	/** Called by the paginator when each page has been completed.
sl@0: 	@param aCurrentPageNum The number of the page. */
sl@0: 	virtual void NotifyPageCompletion(TInt aCurrentPageNum)=0;
sl@0: 	};
sl@0: 
sl@0: 
sl@0: 
sl@0: /** 
sl@0: Paginates a document.
sl@0: 
sl@0: Sets the page dimensions, the printer device and the source document to paginate. 
sl@0: Uses a page list, which is an array of characters-per-page values.
sl@0: 
sl@0: There are two ways of paginating a document; either in the background using 
sl@0: an active object or by incrementally adding text to the document and repeatedly 
sl@0: notifying the CTextPaginator object to paginate the added text. If an active 
sl@0: object is used, the client may be notified on completion of pages, on trapped 
sl@0: leaves and on completion of the pagination by an optional pagination observer. 
sl@0: @publishedAll
sl@0: @released
sl@0: */
sl@0: class CTextPaginator : public CActive
sl@0: 	{
sl@0: public:
sl@0: // 2 phase ctor: automatically adds self to active scheduler 
sl@0: 	IMPORT_C static CTextPaginator* NewL(CPrinterDevice* aPrinterDevice,CArrayFix<TInt>* aCharsPerPage,TInt aPriority);	
sl@0: 	IMPORT_C ~CTextPaginator();
sl@0: 	IMPORT_C void SetDocumentL(MLayDoc* aLayDoc); // Must call before anything else
sl@0: 	IMPORT_C void SetPrinterDevice(CPrinterDevice* aPrinterDevice);
sl@0: 	IMPORT_C void SetPageSpecInTwips(const TPageSpec& aPageSpec);  // Physical size of page.
sl@0: 	IMPORT_C void SetPageMarginsInTwips(const TMargins& aPageMargins); // Default are all zero.
sl@0: 	IMPORT_C void SetTextMarginWidthsInTwips(TInt aLabelMarginWidth,TInt aGutterMarginWidth); // label margins (if any)
sl@0: // Called to initiate paginating a document using active object
sl@0: 	IMPORT_C void SetObserver(MPaginateObserver* aObserver);
sl@0: 	IMPORT_C void PaginateCompleteDocumentL();
sl@0: // Called to paginate incrementally, without active object
sl@0: 	IMPORT_C TInt AppendTextL(TInt& aCumulativeDocPos);	// returns number of page breaks so far
sl@0: 	IMPORT_C TInt PaginationCompletedL();	// called at end of incremental pagination	- returns total number of page breaks
sl@0: private:
sl@0: 	enum TPaginateMode
sl@0: 		{
sl@0: 		EFPaginateCompleteDocument,
sl@0: 		EFPaginateIncrementally
sl@0: 		};
sl@0: 	enum 
sl@0: 		{
sl@0: 		EPageLineArrayGranularity=10,
sl@0: 		EPageListArrayGranularity=5
sl@0: 		};
sl@0: 	enum
sl@0: 		{
sl@0: 		EFMaximumNumberLinesInBlock=20
sl@0: 		};
sl@0: private:
sl@0: 	CTextPaginator(TInt aPriority);
sl@0: 	void RunL(); // Active scheduler is friend - can access 
sl@0: 	void DoCancel();  // Called by CActive::Cancel()
sl@0: 	void ConstructL(CPrinterDevice* aPrinterDevice,CArrayFix<TInt>* aCharsPerPage);
sl@0: 	void SetLayoutDimensions();
sl@0: 	void SetOrReplaceDocumentL(MLayDoc* aLayDoc);
sl@0: 	TRect TextRectInTwips() const;
sl@0: 	TSize TextSizeInPixels() const;
sl@0: 	void TrapPaginateParagraphL();
sl@0: 	void PaginateParagraphL();
sl@0: 	void PageCompleted();
sl@0: 	void Reque();
sl@0: 	void ResetPaginator();
sl@0: 	void CopyTempPageListL();  // Copies temporary page list to real one.
sl@0: 	void LeaveL(TInt aErr);
sl@0: private:
sl@0: 	MLayDoc* iLayDoc;
sl@0: 	MPaginateObserver* iObserver;
sl@0: 	CPrinterDevice* iPrinterDevice;
sl@0: 	TLinePaginator iPaginator;
sl@0: 	CTextLayout* iLayout;
sl@0: 	CArrayFix<TInt>* iPageList;
sl@0: 	CArrayFixFlat<TInt>* iTempPageList;
sl@0: 	CArrayFixFlat<TPageLine>* iPageLineArray;
sl@0: 	TSize iPageSizeInTwips;
sl@0: 	TMargins iPageMarginsInTwips;
sl@0: 	TInt iGutterMarginWidthInTwips;   // Gap between labels and text proper - in twips
sl@0: 	TInt iLabelMarginWidthInTwips;
sl@0: 	TInt iDocPos;				// Within the laydoc
sl@0: 	TBool iPageBreakChar;
sl@0: 	TPaginateMode iMode;
sl@0: 	};
sl@0: 
sl@0: #endif
sl@0: