|
1 /* |
|
2 * Copyright (c) 2010 Kanrikogaku Kenkyusho, Ltd. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Kanrikogaku Kenkyusho, Ltd. - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <coemain.h> |
|
20 #include <barsread.h> |
|
21 #include <DirectPrintApp.rsg> |
|
22 #include <prninf.h> |
|
23 #include <prnsetup.h> |
|
24 #include <gdi.h> |
|
25 #include <prnprev.h> |
|
26 #include <eikenv.h> |
|
27 #include <gulbordr.h> // TGulBorder |
|
28 #include <e32cmn.h> |
|
29 |
|
30 #include "directprintapp.pan" |
|
31 #include "directprintapp.hrh" |
|
32 #include "directprintpreviewcontrol.h" |
|
33 |
|
34 const TInt KFirstPage=0; |
|
35 |
|
36 const TInt KDraggingAccepted = 10; |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CDirectPrintPreviewControl::NewL() |
|
40 // Two-phased constructor. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CDirectPrintPreviewControl* CDirectPrintPreviewControl::NewL(const CCoeControl* aParent) |
|
44 { |
|
45 CDirectPrintPreviewControl* self = CDirectPrintPreviewControl::NewLC(aParent); |
|
46 CleanupStack::Pop(self); |
|
47 return self; |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CDirectPrintPreviewControl::NewLC() |
|
52 // Two-phased constructor. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CDirectPrintPreviewControl* CDirectPrintPreviewControl::NewLC(const CCoeControl* aParent) |
|
56 { |
|
57 CDirectPrintPreviewControl* self = new(ELeave) CDirectPrintPreviewControl(); |
|
58 CleanupStack::PushL(self); |
|
59 self->ConstructL(aParent); |
|
60 return self; |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CDirectPrintPreviewControl::CDirectPrintPreviewControl() |
|
65 // C++ default constructor can NOT contain any code, that might leave. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CDirectPrintPreviewControl::CDirectPrintPreviewControl() |
|
69 { |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CDirectPrintPreviewControl::~CDirectPrintPreviewControl() |
|
74 // C++ default constructor can NOT contain any code, that might leave. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CDirectPrintPreviewControl::~CDirectPrintPreviewControl() |
|
78 { |
|
79 Window().SetPointerGrab(EFalse); |
|
80 delete iPreview; |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CDirectPrintPreviewControl::ConstructL() |
|
85 // Symbian 2nd phase constructor can leave. |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 void CDirectPrintPreviewControl::ConstructL(const CCoeControl* aParent) |
|
89 { |
|
90 // Create a window for this application view |
|
91 if (aParent) |
|
92 { |
|
93 CreateBackedUpWindowL(*aParent->DrawableWindow(), EGray4); |
|
94 } |
|
95 else |
|
96 { |
|
97 CreateBackedUpWindowL((RWindowTreeNode&)iCoeEnv->RootWin(), EGray4); |
|
98 } |
|
99 |
|
100 EnableDragEvents(); |
|
101 Window().SetPointerGrab(ETrue); |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CDirectPrintPreviewControl::SetPreviewImageObserver() |
|
106 // |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 void CDirectPrintPreviewControl::SetPreviewImageObserver(MPrintProcessObserver* aObserver) |
|
110 { |
|
111 __ASSERT_DEBUG(iPreview,Panic(EDirectPrintNullPointer)); |
|
112 iPreview->SetObserver(*aObserver); |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CDirectPrintPreviewControl::CountComponentControls() |
|
117 // Called by framework |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 TInt CDirectPrintPreviewControl::CountComponentControls() const |
|
121 { |
|
122 // return(2); |
|
123 return(0); |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CDirectPrintPreviewControl::ComponentControl() |
|
128 // Called by framework |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 CCoeControl* CDirectPrintPreviewControl::ComponentControl( TInt aIndex ) const |
|
132 { |
|
133 CCoeControl* control=NULL; |
|
134 switch (aIndex) |
|
135 { |
|
136 case 0: |
|
137 // control=iButton[0]; |
|
138 break; |
|
139 case 1: |
|
140 // control=iButton[1]; |
|
141 break; |
|
142 } |
|
143 return(control); |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CDirectPrintPreviewControl::WriteInternalStateL() |
|
148 // |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 #ifndef _DEBUG |
|
152 void CDirectPrintPreviewControl::WriteInternalStateL(RWriteStream& /*aWriteStream*/) const |
|
153 { |
|
154 } |
|
155 #else |
|
156 void CDirectPrintPreviewControl::WriteInternalStateL(RWriteStream& aWriteStream) const |
|
157 { |
|
158 CEikBorderedControl::WriteInternalStateL(aWriteStream); |
|
159 } |
|
160 #endif |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CDirectPrintAppAppView::HandlePointerEventL() |
|
164 // Called by framework to handle pointer touch events. |
|
165 // Note: although this method is compatible with earlier SDKs, |
|
166 // it will not be called in SDKs without Touch support. |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 void CDirectPrintPreviewControl::HandlePointerEventL( |
|
170 const TPointerEvent& aPointerEvent) |
|
171 { |
|
172 const TRect rect=Rect(); |
|
173 if( !rect.Contains(aPointerEvent.iPosition) ) |
|
174 { |
|
175 return; |
|
176 } |
|
177 |
|
178 switch ( aPointerEvent.iType ) |
|
179 { |
|
180 case TPointerEvent::EButton1Down: |
|
181 { |
|
182 iPointerDownPos = aPointerEvent.iPosition; |
|
183 } |
|
184 break; |
|
185 case TPointerEvent::EButton1Up: |
|
186 case TPointerEvent::EDrag: |
|
187 { |
|
188 TInt x = aPointerEvent.iPosition.iX - iPointerDownPos.iX; |
|
189 TInt y = aPointerEvent.iPosition.iY - iPointerDownPos.iY; |
|
190 if (Abs(x) > KDraggingAccepted || Abs(y) > KDraggingAccepted) |
|
191 { |
|
192 TPoint newPos; |
|
193 TInt maxWidth = iDisplayRect.Width() - rect.Width(); |
|
194 TInt maxHeight = iDisplayRect.Height() - rect.Height(); |
|
195 newPos.iX = Min(iDisplayPoint.iX + x, maxWidth); |
|
196 if (newPos.iX <= (maxWidth*-1)) |
|
197 newPos.iX = (maxWidth*-1); |
|
198 newPos.iY = Min(iDisplayPoint.iY + y, maxHeight); |
|
199 if (newPos.iY <= (maxHeight*-1)) |
|
200 newPos.iY = (maxHeight*-1); |
|
201 iDisplayPoint = newPos; |
|
202 iPointerDownPos = aPointerEvent.iPosition; |
|
203 DrawNow(); |
|
204 } |
|
205 } |
|
206 break; |
|
207 default: |
|
208 break; |
|
209 } |
|
210 } |
|
211 |
|
212 void CDirectPrintPreviewControl::ActivateL() |
|
213 { |
|
214 DrawButtons(); |
|
215 CCoeControl::ActivateL(); |
|
216 } |
|
217 |
|
218 TCoeInputCapabilities CDirectPrintPreviewControl::InputCapabilities() const |
|
219 { |
|
220 return TCoeInputCapabilities(TCoeInputCapabilities::ENavigation); |
|
221 } |
|
222 |
|
223 void CDirectPrintPreviewControl::InitializeFormat( |
|
224 CPrintSetup& aPrintSetup, |
|
225 MPageRegionPrinter& aBodyPrinter, |
|
226 TPrintPreviewFormat& aFormat, |
|
227 TInt& aNumPagesInDoc, |
|
228 TInt& aFirstPageToDisplay, |
|
229 TInt aNumPagesToView, |
|
230 CPrintPreviewImage::TMarginState& aMarginState) |
|
231 { |
|
232 iPrintSetup=&aPrintSetup; |
|
233 iBodyPrinter=&aBodyPrinter; |
|
234 iPrintPreviewFormat=&aFormat; |
|
235 iFirstPageToDisplay=&aFirstPageToDisplay; |
|
236 iNumPagesInDoc=aNumPagesInDoc; |
|
237 iNumPagesToView=aNumPagesToView; |
|
238 iMarginState=aMarginState; |
|
239 } |
|
240 |
|
241 void CDirectPrintPreviewControl::SetNumBands(TInt aNumBands) |
|
242 { |
|
243 iNumBands=aNumBands; |
|
244 if (iPreview) |
|
245 { |
|
246 iPreview->SetNumBands(aNumBands); |
|
247 } |
|
248 } |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // CDirectPrintPreviewControl::SizeChanged() |
|
252 // Called by framework when the view size is changed. |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 void CDirectPrintPreviewControl::SizeChanged() |
|
256 // can't recover if CPrintPreviewImage::NewL() fails !! |
|
257 { |
|
258 iPreviewDraw=ETrue; |
|
259 |
|
260 // set zoom level |
|
261 SetZoomLevelAndDispalyRect(EPreviewZoomLevel1); |
|
262 |
|
263 // create CPrintPreviewImage object |
|
264 TRAP_IGNORE(CreatePreviewImageL()); |
|
265 } |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // CDirectPrintPreviewControl::Draw() |
|
269 // Draws the display. |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 void CDirectPrintPreviewControl::Draw(const TRect& aRect) const |
|
273 { |
|
274 if (!iPreviewDraw) |
|
275 return; |
|
276 // DrawButtons(); |
|
277 CWindowGc& gc=SystemGc(); |
|
278 iBorder.Draw(gc,Rect()); |
|
279 gc.Clear(); |
|
280 gc.SetPenStyle(CGraphicsContext::ENullPen); |
|
281 gc.SetBrushColor(KRgbWhite); |
|
282 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
283 // TRect rectAboveButton(TPoint(iDisplayRect.iTl.iX-KScrollButtonWidth,iDisplayRect.iTl.iY),TSize(KScrollButtonWidth,iDisplayRect.Height()-(iButton[0]->IsVisible()? KScrollButtonWidth : 0))); |
|
284 // gc.DrawRect(rectAboveButton); |
|
285 // rectAboveButton=(TPoint(iDisplayRect.iTl.iX-KScrollButtonWidth,iDisplayRect.iTl.iY),TSize(KScrollButtonWidth,iDisplayRect.Height()-(iButton[1]->IsVisible()? KScrollButtonWidth : 0))); |
|
286 // rectAboveButton.Move(iDisplayRect.Width()+KScrollButtonWidth+1,1); // why are the 1s needed??? |
|
287 // gc.DrawRect(rectAboveButton); |
|
288 gc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
289 CONST_CAST(CDirectPrintPreviewControl*,this)->DrawPreview(aRect); // cast away constness |
|
290 } |
|
291 |
|
292 void CDirectPrintPreviewControl::SetDrawFlag(TBool aDraw) |
|
293 { |
|
294 iPreviewDraw=aDraw; |
|
295 } |
|
296 |
|
297 TBool CDirectPrintPreviewControl::DrawFlag() |
|
298 { |
|
299 return iPreviewDraw; |
|
300 } |
|
301 |
|
302 void CDirectPrintPreviewControl::SetFormatAndDrawL(TInt& aFirstPageToDisplay,TInt& aNumPagesToView) |
|
303 { |
|
304 iPreview->FormatL(iNumPagesInDoc,aFirstPageToDisplay,aNumPagesToView); |
|
305 *iFirstPageToDisplay=aFirstPageToDisplay; |
|
306 iNumPagesToView=aNumPagesToView; |
|
307 DrawButtons(); |
|
308 DrawNow(); |
|
309 } |
|
310 |
|
311 void CDirectPrintPreviewControl::SetMarginAndDrawL(CPrintPreviewImage::TMarginState aMarginState) |
|
312 { |
|
313 iPreview->SetMargins(aMarginState); |
|
314 iMarginState=aMarginState; |
|
315 DrawNow(); |
|
316 } |
|
317 |
|
318 void CDirectPrintPreviewControl::SetNumPagesInDoc(TInt aNumPagesInDoc,TInt aFirstPageToDisplay,TInt aNumPagesToView) |
|
319 { |
|
320 iNumPagesInDoc=aNumPagesInDoc; |
|
321 *iFirstPageToDisplay=aFirstPageToDisplay; |
|
322 iNumPagesToView=aNumPagesToView; |
|
323 } |
|
324 |
|
325 void CDirectPrintPreviewControl::DrawPreview(const TRect& aRect) |
|
326 { |
|
327 TRAPD(err,iPreview->DrawL(iDisplayPoint,aRect)); |
|
328 if (err) |
|
329 { |
|
330 SystemGc().Clear(iDisplayRect); |
|
331 CEikonEnv::Static()->NotifyIdleErrorWhileRedrawing(err); |
|
332 } |
|
333 } |
|
334 |
|
335 TKeyResponse CDirectPrintPreviewControl::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode /*aType*/) |
|
336 { |
|
337 TInt newFirstPageToDisplay=*iFirstPageToDisplay; |
|
338 switch (aKeyEvent.iCode) |
|
339 { |
|
340 case EKeyLeftArrow: |
|
341 case EKeyPageUp: |
|
342 newFirstPageToDisplay--; |
|
343 break; |
|
344 case EKeyRightArrow: |
|
345 case EKeyPageDown: |
|
346 newFirstPageToDisplay++; |
|
347 break; |
|
348 case EKeyHome: |
|
349 newFirstPageToDisplay=KFirstPage; |
|
350 break; |
|
351 case EKeyEnd: |
|
352 newFirstPageToDisplay=iNumPagesInDoc-iNumPagesToView; |
|
353 break; |
|
354 default: |
|
355 return(EKeyWasNotConsumed); |
|
356 |
|
357 } |
|
358 SwitchFirstPageToDisplayL(newFirstPageToDisplay); |
|
359 return(EKeyWasConsumed); |
|
360 } |
|
361 |
|
362 void CDirectPrintPreviewControl::SwitchFirstPageToDisplayL(TInt& aNewFirstPageToDisplay) |
|
363 { |
|
364 if (aNewFirstPageToDisplay<KFirstPage) |
|
365 aNewFirstPageToDisplay=KFirstPage; |
|
366 if (aNewFirstPageToDisplay>iNumPagesInDoc-iNumPagesToView) |
|
367 aNewFirstPageToDisplay=iNumPagesInDoc-iNumPagesToView; |
|
368 if (aNewFirstPageToDisplay!=*iFirstPageToDisplay) |
|
369 SetFormatAndDrawL(aNewFirstPageToDisplay,iNumPagesToView); |
|
370 } |
|
371 |
|
372 void CDirectPrintPreviewControl::HandleControlEventL(CCoeControl* /*aControl*/,TCoeEvent aEventType) |
|
373 { |
|
374 if (aEventType!=EEventStateChanged) |
|
375 return; |
|
376 TInt newFirstPageToDisplay=*iFirstPageToDisplay; |
|
377 // if (aControl==iButton[0]) |
|
378 // newFirstPageToDisplay--; |
|
379 // else if (aControl==iButton[1]) |
|
380 // newFirstPageToDisplay++; |
|
381 SwitchFirstPageToDisplayL(newFirstPageToDisplay); |
|
382 } |
|
383 |
|
384 void CDirectPrintPreviewControl::DrawButtons() const |
|
385 { |
|
386 if (iNumPagesToView==iNumPagesInDoc) |
|
387 { |
|
388 // iButton[1]->MakeVisible(EFalse); |
|
389 // iButton[0]->MakeVisible(EFalse); |
|
390 return; |
|
391 } |
|
392 // TBool leftvisible=ETrue; |
|
393 // TBool rightvisible=ETrue; |
|
394 // if (*iFirstPageToDisplay==KFirstPage) |
|
395 // leftvisible=EFalse; |
|
396 // else |
|
397 // { |
|
398 // if (*iFirstPageToDisplay>=iNumPagesInDoc-iNumPagesToView) |
|
399 // rightvisible=EFalse; |
|
400 // } |
|
401 // iButton[0]->MakeVisible(leftvisible); |
|
402 // iButton[1]->MakeVisible(rightvisible); |
|
403 //// iButton[0]->DrawNow(); |
|
404 //// iButton[1]->DrawNow(); |
|
405 } |
|
406 |
|
407 |
|
408 // for zoom |
|
409 void CDirectPrintPreviewControl::SetZoomLevel(TInt /*aZoomLevel*/) |
|
410 { |
|
411 SetZoomLevelAndDispalyRect(iZoomLevel); |
|
412 } |
|
413 |
|
414 TInt CDirectPrintPreviewControl::GetZoomLebel() |
|
415 { |
|
416 return (TInt)iZoomLevel; |
|
417 } |
|
418 |
|
419 void CDirectPrintPreviewControl::IncrementZoomLevel() |
|
420 { |
|
421 TInt zoom = iZoomLevel + 1; |
|
422 if (zoom >= EPreviewZoomLevel1 |
|
423 && zoom < EPreviewZoomLevelMax) |
|
424 { |
|
425 SetZoomLevelAndDispalyRect(zoom); |
|
426 TRAPD(err, CreatePreviewImageL()); |
|
427 if (err == KErrNone) |
|
428 { |
|
429 DrawNow(); |
|
430 } |
|
431 } |
|
432 } |
|
433 |
|
434 void CDirectPrintPreviewControl::DecrementZoomLevel() |
|
435 { |
|
436 TInt zoom = iZoomLevel - 1; |
|
437 if (zoom >= EPreviewZoomLevel1) |
|
438 { |
|
439 SetZoomLevelAndDispalyRect(zoom); |
|
440 TRAPD(err, CreatePreviewImageL()); |
|
441 if (err == KErrNone) |
|
442 { |
|
443 DrawNow(); |
|
444 } |
|
445 } |
|
446 } |
|
447 |
|
448 // set zoom level |
|
449 void CDirectPrintPreviewControl::SetZoomLevelAndDispalyRect(TInt aZoomLevel) |
|
450 { |
|
451 static const TInt KZoomPercent[EPreviewZoomLevelMax] = {100, 120, 140, 160, 180}; |
|
452 TInt oldZoomLevel = iZoomLevel; |
|
453 if (aZoomLevel == EPreviewZoomLevel1) |
|
454 { |
|
455 iDisplayRect = iBorder.InnerRect(Rect()); |
|
456 iDisplayPoint = iDisplayRect.iTl; |
|
457 } |
|
458 else |
|
459 { |
|
460 TRect rect(iBorder.InnerRect(Rect())); |
|
461 TSize newSize; |
|
462 newSize.iWidth = (rect.Size().iWidth * KZoomPercent[aZoomLevel] + 5) / KZoomPercent[EPreviewZoomLevel1]; |
|
463 newSize.iHeight = (rect.Size().iHeight * KZoomPercent[aZoomLevel] + 5) / KZoomPercent[EPreviewZoomLevel1]; |
|
464 iDisplayRect.SetSize(newSize); |
|
465 if (oldZoomLevel != EPreviewZoomLevel1) |
|
466 { |
|
467 TPoint newPos; |
|
468 newPos.iX = Max(0, ((iDisplayPoint.iX * KZoomPercent[aZoomLevel] + 5) / KZoomPercent[EPreviewZoomLevel1])); |
|
469 newPos.iY = Max(0, ((iDisplayPoint.iY * KZoomPercent[aZoomLevel] + 5) / KZoomPercent[EPreviewZoomLevel1])); |
|
470 iDisplayPoint = newPos; |
|
471 } |
|
472 } |
|
473 iZoomLevel = aZoomLevel; |
|
474 } |
|
475 |
|
476 void CDirectPrintPreviewControl::CreatePreviewImageL() |
|
477 { |
|
478 if (iPreview) |
|
479 { |
|
480 delete iPreview; |
|
481 iPreview=NULL; |
|
482 } |
|
483 |
|
484 iPreview = CPrintPreviewImage::NewL(*iPrintSetup, |
|
485 *iBodyPrinter, |
|
486 CEikonEnv::Static()->WsSession(), |
|
487 Window(), |
|
488 iDisplayRect.Size(), |
|
489 *iPrintPreviewFormat); |
|
490 iPreview->SetNumBands(iNumBands); |
|
491 iPreview->FormatL(iNumPagesInDoc,*iFirstPageToDisplay,iNumPagesToView); |
|
492 iPreview->SetMargins(iMarginState); |
|
493 // TRect buttonRect(TPoint(iDisplayRect.iTl.iX-KScrollButtonWidth,iDisplayRect.iBr.iY-KScrollButtonWidth), |
|
494 // TSize(KScrollButtonWidth,KScrollButtonWidth)); |
|
495 // iButton[0]->SetRect(buttonRect); |
|
496 // buttonRect.Move(iDisplayRect.Width()+KScrollButtonWidth,0); |
|
497 // iButton[1]->SetRect(buttonRect); |
|
498 } |
|
499 |
|
500 // End of file |