|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "GRDPRINT.H" |
|
17 |
|
18 EXPORT_C CGridPrinter::~CGridPrinter() |
|
19 /** Destructor. |
|
20 |
|
21 Frees resources before destruction of the object. */ |
|
22 { |
|
23 delete iGridLay; |
|
24 delete iGridImg; |
|
25 delete iPrintLabelImg; |
|
26 delete iPrintCellImg; |
|
27 delete iZoomFactor; |
|
28 } |
|
29 |
|
30 CGridPrinter::CGridPrinter(CGridLabelImg* aPrintLabelImg,CGridCellImg* aPrintCellImg,TZoomFactor* aZoomFactor) |
|
31 : iPrintLabelImg(aPrintLabelImg), |
|
32 iPrintCellImg(aPrintCellImg), |
|
33 iZoomFactor(aZoomFactor), |
|
34 iGraphicsDeviceMap(iZoomFactor->GraphicsDeviceMap()) |
|
35 { |
|
36 } |
|
37 |
|
38 EXPORT_C CGridPrinter* CGridPrinter::NewL(CGridLay* aGridLay,CGridLabelImg* aPrintLabelImg, |
|
39 CGridCellImg* aPrintCellImg,TZoomFactor* aZoomFactor) |
|
40 /** Creates a new grid printer object. |
|
41 |
|
42 @param aGridLay A pointer to an object that controls the layout of rows and |
|
43 columns. |
|
44 @param aPrintLabelImg A pointer to an object that draws a grid cell's label. |
|
45 @param aPrintCellImg A pointer to an object that draws the contents of a single |
|
46 cell. |
|
47 @param aZoomFactor A pointer to the zoom factor object. |
|
48 @see CGridLay::ConstructL() */ |
|
49 { |
|
50 CGridPrinter* self=new(ELeave) CGridPrinter(aPrintLabelImg,aPrintCellImg,aZoomFactor); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(aGridLay); |
|
53 CleanupStack::Pop(); |
|
54 return self; |
|
55 } |
|
56 |
|
57 void CGridPrinter::ConstructL(CGridLay* aGridLay) |
|
58 { |
|
59 iGridLay=new(ELeave) CGridLay(iZoomFactor); |
|
60 iGridImg=CGridImg::NewL(iPrintCellImg,iGridLay); |
|
61 iGridImg->SetGridLabelImg(iPrintLabelImg); |
|
62 iGridLay->ConstructL(aGridLay,iGridImg); |
|
63 } |
|
64 |
|
65 LOCAL_C void CleanupGridLabelImg(TAny* aObject) |
|
66 { |
|
67 ((CGridLabelImg*)aObject)->ReleaseFont(); |
|
68 ((CGridLabelImg*)aObject)->SetGraphicsDeviceMap(NULL); |
|
69 } |
|
70 |
|
71 EXPORT_C void CGridPrinter::PrintBandL(CGraphicsDevice* aDevice,TInt aPageNo,const TBandAttributes& aBandInPixels) |
|
72 /** Prints a band. |
|
73 |
|
74 The function implements MPageRegionPrinter::PrintBandL(). |
|
75 |
|
76 @param aDevice Pointer to the graphics device representing the printer |
|
77 @param aPageNo The number of the page containing the band to be printed. |
|
78 @param aBandInPixels Attributes of the band to be printed. */ |
|
79 { |
|
80 if (aBandInPixels.iFirstBandOnPage) |
|
81 { |
|
82 TSize pageSize=iGridLay->PageSizeInTwips(); |
|
83 iPrintablePage.SetRect(iTlMarginInTwips,pageSize); |
|
84 iZoomFactor->SetGraphicsDeviceMap(iGraphicsDeviceMap); // the real printing device |
|
85 iPrintLabelImg->SetGraphicsDeviceMap(iZoomFactor); |
|
86 iPrintLabelImg->NotifyGraphicsDeviceMapChangeL(); |
|
87 TRect printGridRect=iZoomFactor->TwipsToPixels(iPrintablePage); |
|
88 printGridRect.iTl+=TPoint(1,1); //For border |
|
89 iGridImg->SetPrintGridRect(printGridRect); |
|
90 iPrintLabelImg->ReleaseFont(); |
|
91 TRangeRef pageRange=iGridLay->PageToRange(aPageNo,CGridLay::ERightThenDown/*!!For Now*/); |
|
92 iGridLay->SetPrintRange(pageRange); |
|
93 } |
|
94 iZoomFactor->SetGraphicsDeviceMap(aDevice); |
|
95 iPrintLabelImg->SetGraphicsDeviceMap(iZoomFactor); |
|
96 iPrintLabelImg->NotifyGraphicsDeviceMapChangeL(); |
|
97 TRect printablePageInPixels=iZoomFactor->TwipsToPixels(iPrintablePage); |
|
98 iScaleFactor=(iGridImg->GridRect().Height()*CGridImg::EScaleOneToOne-1)/printablePageInPixels.Height()+1;//Round up |
|
99 |
|
100 TRect printRect=aBandInPixels.iRect; |
|
101 if (!printRect.Intersects(printablePageInPixels)) |
|
102 return; |
|
103 printRect.Intersection(printablePageInPixels); |
|
104 |
|
105 TRangeRef printRange=iGridLay->VisibleRange(); |
|
106 printRange.iFrom.iRow=Max(printRange.iFrom.iRow,iGridLay->YValToRow(printRect.iTl.iY*iScaleFactor/CGridImg::EScaleOneToOne)); |
|
107 printRange.iTo.iRow=Min(printRange.iTo.iRow,iGridLay->YValToRow(printRect.iBr.iY*iScaleFactor/CGridImg::EScaleOneToOne)); |
|
108 CleanupStack::PushL(TCleanupItem(CleanupGridLabelImg,iPrintLabelImg)); |
|
109 CGraphicsContext* printerGc; |
|
110 User::LeaveIfError(aDevice->CreateContext(printerGc)); |
|
111 CleanupStack::PushL(printerGc); |
|
112 iGridImg->PrintGridLinesAndCellsInRangeL(printerGc,printRange,iScaleFactor); |
|
113 CleanupStack::PopAndDestroy(2); // printerGc + CleanupGridLabelImg |
|
114 } |
|
115 |
|
116 EXPORT_C void CGridPrinter::SetTopLeftMargin(const TPoint& aTlMarginInTwips) |
|
117 /** Sets the top left margin. |
|
118 |
|
119 @param aTlMarginInTwips The top left margin, in twips. */ |
|
120 { |
|
121 iTlMarginInTwips=aTlMarginInTwips; |
|
122 } |
|
123 |
|
124 EXPORT_C void CGridPrinter::SetPageSizeInTwipsL(const TSize& aSizeInTwips) |
|
125 /** Sets the size of the page. |
|
126 |
|
127 @param aSizeInTwips The size of the page, in twips. */ |
|
128 { |
|
129 if (!iGridLay->IsAutoPagination()) |
|
130 { |
|
131 iGridLay->SetPageSizeInTwipsL(aSizeInTwips); // won't leave |
|
132 return; |
|
133 } |
|
134 SetGdMapAndPushLabelImgLC(); |
|
135 iGridLay->SetPageSizeInTwipsL(aSizeInTwips); |
|
136 CleanupStack::PopAndDestroy(); // CleanupGridLabelImg |
|
137 } |
|
138 |
|
139 EXPORT_C void CGridPrinter::PaginateL() |
|
140 /** Paginates the grid. */ |
|
141 { |
|
142 if (iGridLay->IsPaginated()) |
|
143 return; |
|
144 SetGdMapAndPushLabelImgLC(); |
|
145 iGridLay->PaginateL(); |
|
146 CleanupStack::PopAndDestroy(); // CleanupGridLabelImg |
|
147 } |
|
148 |
|
149 void CGridPrinter::SetGdMapAndPushLabelImgLC() |
|
150 { |
|
151 iZoomFactor->SetGraphicsDeviceMap(iGraphicsDeviceMap); // re-paginate with the real printing device |
|
152 iPrintLabelImg->SetGraphicsDeviceMap(iZoomFactor); |
|
153 iPrintLabelImg->NotifyGraphicsDeviceMapChangeL(); |
|
154 iGridLay->SetGraphicsDeviceMap(iZoomFactor); // Pointer value is same but internal rep. may be different |
|
155 CleanupStack::PushL(TCleanupItem(CleanupGridLabelImg,iPrintLabelImg)); |
|
156 } |