|
1 // Copyright (c) 2005-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 // Part of the MVS Application for TechView |
|
15 // |
|
16 |
|
17 #include <w32std.h> |
|
18 |
|
19 #include "MVSApp.h" |
|
20 #include "MVSAppUI.h" |
|
21 #include "mvsvideocontrol.h" |
|
22 |
|
23 CMVSAppView* CMVSAppView::NewL(const TRect& aRect, CMVSVideoPlayAgent& aVideoPlayAgent) |
|
24 { |
|
25 CMVSAppView * self = new(ELeave) CMVSAppView; |
|
26 CleanupStack::PushL(self); |
|
27 self->ConstructL(aRect, aVideoPlayAgent); |
|
28 CleanupStack::Pop(); |
|
29 return self; |
|
30 } |
|
31 |
|
32 |
|
33 CMVSAppView::CMVSAppView() |
|
34 { |
|
35 } |
|
36 |
|
37 |
|
38 CMVSAppView::~CMVSAppView() |
|
39 { |
|
40 //Remove our controls |
|
41 delete iMainWindowControl; |
|
42 delete iStatusWindowFNameControl; |
|
43 delete iStatusWindowStateControl; |
|
44 delete iStatusWindowTimeControl; |
|
45 delete iInfoWindowControl; |
|
46 delete iProgress; |
|
47 |
|
48 CloseWindow(); |
|
49 } |
|
50 |
|
51 |
|
52 void CMVSAppView::ConstructL(const TRect& aRect, CMVSVideoPlayAgent& aVideoPlayAgent) |
|
53 { |
|
54 //we need a window in which to place controls, so take ownership of one |
|
55 CreateWindowL(); |
|
56 |
|
57 //Set the extent of the control. |
|
58 SetRect(aRect); |
|
59 TRect fullRectWindow = Rect(); |
|
60 //vertical point co-ordinate |
|
61 TInt statusPaneHeight = 4*(fullRectWindow.iTl.iY + fullRectWindow.iBr.iY)/5; |
|
62 TInt halfLength = (fullRectWindow.iTl.iX + fullRectWindow.iBr.iX)/2; |
|
63 TInt threeQuarterLength= 3*(fullRectWindow.iTl.iX + fullRectWindow.iBr.iX)/4; |
|
64 |
|
65 //set the dimensions of our main window |
|
66 TRect mainWindow(Rect()); |
|
67 mainWindow.iTl.iX = halfLength-115; |
|
68 mainWindow.iBr.iY = statusPaneHeight; |
|
69 |
|
70 iMainWindowControl = CMVSVideoControl::NewL(aVideoPlayAgent, 0, Window()); |
|
71 iMainWindowControl->SetExtent(mainWindow.iTl, mainWindow.Size()); |
|
72 |
|
73 //set the dimensions of our status window |
|
74 TRect statusWindowFName = fullRectWindow; |
|
75 statusWindowFName.iTl.iY = statusPaneHeight; |
|
76 statusWindowFName.iBr.iX = halfLength; |
|
77 |
|
78 //now construct our status window filename control |
|
79 iStatusWindowFNameControl = CMVSFileControl::NewL(*this, statusWindowFName, |
|
80 KNullDesC); |
|
81 //set the dimensions of our state window |
|
82 TRect statusWindowState = fullRectWindow; |
|
83 statusWindowState.iTl.iX = halfLength; |
|
84 statusWindowState.iTl.iY = statusPaneHeight; |
|
85 statusWindowState.iBr.iX = threeQuarterLength; |
|
86 |
|
87 //now construct our status window state control |
|
88 iStatusWindowStateControl = CMVSStateControl::NewL(*this, statusWindowState, |
|
89 KNullDesC); |
|
90 |
|
91 //set the dimensions of our timer window |
|
92 TRect statusWindowTime = fullRectWindow; |
|
93 statusWindowTime.iTl.iX = threeQuarterLength; |
|
94 statusWindowTime.iTl.iY = statusPaneHeight; |
|
95 |
|
96 //now construct our status window timer control |
|
97 iStatusWindowTimeControl = CMVSTimeControl::NewL(*this, statusWindowTime, |
|
98 KNullDesC); |
|
99 TRect infoWindow = fullRectWindow; |
|
100 infoWindow.iTl.iX=0; |
|
101 infoWindow.iBr.iX= halfLength-115; |
|
102 infoWindow.iBr.iY =statusPaneHeight-15; |
|
103 iInfoWindowControl = CMVSInfoControl::NewL(*this,infoWindow,KNullDesC); |
|
104 iInfoWindowControl->SetParent(this); |
|
105 //now activate the control. |
|
106 |
|
107 // construct and draw the progress bar |
|
108 iProgress = new (ELeave) CEikProgressInfo(); |
|
109 |
|
110 TResourceReader reader; |
|
111 iEikonEnv->CreateResourceReaderLC(reader, R_CLIP_PROGRESSINFO); |
|
112 iProgress->ConstructFromResourceL(reader); |
|
113 iProgress->SetContainerWindowL(*this); |
|
114 iProgress->SetExtent(TPoint(fullRectWindow.iTl.iX+ (fullRectWindow.iBr.iX/20),statusPaneHeight-10),TSize((fullRectWindow.iBr.iX - fullRectWindow.iTl.iX - (fullRectWindow.iBr.iX/10) ),10)); |
|
115 iProgress->SetAndDraw(0); |
|
116 CleanupStack::PopAndDestroy(); |
|
117 |
|
118 ActivateL(); |
|
119 } |
|
120 |
|
121 void CMVSAppView::SetClipLength(TInt& aClipLen) |
|
122 { |
|
123 iClipLength = aClipLen; |
|
124 } |
|
125 |
|
126 // |
|
127 //CountComponentControls() |
|
128 // |
|
129 // Implemented by a view with more than one control so that a call to |
|
130 // DrawNow successfully draws all four component controls. |
|
131 // |
|
132 TInt CMVSAppView::CountComponentControls() const |
|
133 { |
|
134 return 6; //we have six controls |
|
135 } |
|
136 |
|
137 // |
|
138 // To handle the Pointer events on the Progress Bar |
|
139 // |
|
140 void CMVSAppView::HandlePointerEventL(const TPointerEvent &aPointerEvent) |
|
141 { |
|
142 TInt clipPos; |
|
143 TRect rect = iProgress->Rect(); |
|
144 if( (aPointerEvent.iPosition.iX>=rect.iTl.iX && aPointerEvent.iPosition.iX<=rect.iBr.iX) && |
|
145 (aPointerEvent.iPosition.iY>=rect.iTl.iY && aPointerEvent.iPosition.iY<=rect.iBr.iY) ) |
|
146 { |
|
147 TInt pos = aPointerEvent.iPosition.iX - rect.iTl.iX; |
|
148 switch(aPointerEvent.iType) |
|
149 { |
|
150 case TPointerEvent::EButton1Down: |
|
151 break; |
|
152 case TPointerEvent::EDrag: |
|
153 { |
|
154 iProgress->SetAndDraw(pos); |
|
155 break; |
|
156 } |
|
157 case TPointerEvent::EButton1Up: |
|
158 { |
|
159 TInt progToDraw = pos* (static_cast<double>(200)/(rect.iBr.iX -rect.iTl.iX)); |
|
160 iProgress->SetAndDraw(progToDraw+1); |
|
161 clipPos = (progToDraw+1) *(static_cast<double>(iClipLength)/200); |
|
162 TTimeIntervalMicroSeconds clipTime(clipPos); |
|
163 static_cast<CMVSAppUi*>(CEikonEnv::Static()->EikAppUi())->SetPosition(clipTime); |
|
164 break; |
|
165 } |
|
166 |
|
167 default: |
|
168 break; |
|
169 } |
|
170 } |
|
171 CCoeControl::HandlePointerEventL(aPointerEvent); |
|
172 |
|
173 } |
|
174 |
|
175 |
|
176 // |
|
177 // Updates the Audion play progress |
|
178 // |
|
179 void CMVSAppView::UpdatePlayProgress(TTimeIntervalMicroSeconds& aPos) |
|
180 { |
|
181 TInt curPos = I64INT(aPos.Int64()); |
|
182 TInt percent = curPos*(static_cast<double>(100)/iClipLength); |
|
183 TInt progressPos = percent*2; |
|
184 iProgress->SetAndDraw(progressPos+1); |
|
185 } |
|
186 |
|
187 // |
|
188 // Reset the Progress to ) and redraw |
|
189 // |
|
190 void CMVSAppView::ResetProgressBar() |
|
191 { |
|
192 iProgress->SetAndDraw(0); |
|
193 } |
|
194 // |
|
195 //ComponentControl(...) |
|
196 // |
|
197 // Returns the control by index. The counting sequence goes left to right, top |
|
198 // to bottom. |
|
199 // |
|
200 CCoeControl* CMVSAppView::ComponentControl(TInt aIndex) const |
|
201 { |
|
202 switch (aIndex) |
|
203 { |
|
204 case 0: return iMainWindowControl; |
|
205 case 1: return iStatusWindowFNameControl; |
|
206 case 2: return iStatusWindowStateControl; |
|
207 case 3: return iStatusWindowTimeControl; |
|
208 case 4: return iInfoWindowControl; |
|
209 case 5: return iProgress; |
|
210 default: return 0; |
|
211 } |
|
212 } |
|
213 |
|
214 |
|
215 |
|
216 // |
|
217 // |
|
218 // class CMVSFileControl |
|
219 // |
|
220 // |
|
221 |
|
222 |
|
223 |
|
224 // |
|
225 //NewL(...) *** This method can LEAVE *** |
|
226 // |
|
227 // Factory contructor, initialises a control based on the rectangle provided. |
|
228 // |
|
229 CMVSFileControl* CMVSFileControl::NewL(const CCoeControl& aContainer, |
|
230 const TRect& aRect, |
|
231 const TDesC& aText) |
|
232 { |
|
233 CMVSFileControl* self=new(ELeave) CMVSFileControl; |
|
234 CleanupStack::PushL(self); |
|
235 self->ConstructL(aContainer, aRect, aText); |
|
236 CleanupStack::Pop(); |
|
237 return self; |
|
238 } |
|
239 |
|
240 |
|
241 // |
|
242 //ContructL(...) *** This method can LEAVE *** |
|
243 // |
|
244 // |
|
245 void CMVSFileControl::ConstructL(const CCoeControl& aContainer, |
|
246 const TRect& aRect, const TDesC& aText) |
|
247 { |
|
248 SetContainerWindowL(aContainer); |
|
249 SetRect(aRect); |
|
250 iWindow = aRect; |
|
251 SetTextL(aText); |
|
252 //Activate the control |
|
253 ActivateL(); |
|
254 } |
|
255 |
|
256 |
|
257 // |
|
258 //CMVSControl() |
|
259 // |
|
260 // Constructor, does nothing. Private to prevent it being called. |
|
261 // |
|
262 CMVSFileControl::CMVSFileControl() |
|
263 { |
|
264 } |
|
265 |
|
266 |
|
267 // |
|
268 //~CMVSControl() |
|
269 // |
|
270 // Destructor. |
|
271 // |
|
272 CMVSFileControl::~CMVSFileControl() |
|
273 { |
|
274 delete iText; |
|
275 } |
|
276 |
|
277 |
|
278 //Draw the FileName Display Window |
|
279 void CMVSFileControl::Draw(const TRect& /*aRect*/) const |
|
280 { |
|
281 //Establish a Graphics Context |
|
282 CWindowGc& gc=SystemGc(); |
|
283 |
|
284 //Establish a drawing rectangle |
|
285 TRect rect=Rect(); |
|
286 |
|
287 //Move in 2 pixels each side to give a white border |
|
288 rect.Shrink(2,2); |
|
289 |
|
290 //Set-up a pen |
|
291 gc.SetPenStyle(CGraphicsContext::ENullPen); |
|
292 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
293 gc.SetBrushColor(KRgbDarkGray); |
|
294 |
|
295 //Draw a blank rectangle |
|
296 gc.DrawRect(rect); |
|
297 |
|
298 //Fill in the border-regions |
|
299 DrawUtils::DrawBetweenRects(gc, Rect(), rect); |
|
300 |
|
301 //Change the pen colour to black |
|
302 gc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
303 gc.SetPenColor(KRgbWhite); |
|
304 |
|
305 //Set the fill colour to 'no fill' |
|
306 gc.SetBrushStyle(CGraphicsContext::ENullBrush); |
|
307 |
|
308 //Draw a rectangle (transparent with a black border) |
|
309 gc.DrawRect(rect); |
|
310 rect.Shrink(1,1); |
|
311 |
|
312 const CFont* appFont = iEikonEnv->AnnotationFont(); |
|
313 DrawOtherWindows(gc,rect,appFont); |
|
314 return; |
|
315 } |
|
316 |
|
317 |
|
318 |
|
319 // |
|
320 //DrawOtherWindows(...) |
|
321 // |
|
322 // Draw the text in a central position in the window. |
|
323 // |
|
324 void CMVSFileControl::DrawOtherWindows(CGraphicsContext& aGc, |
|
325 const TRect& aDeviceRect, |
|
326 const CFont* aFont) const |
|
327 { |
|
328 //Set up the pen and brush colours |
|
329 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
330 aGc.SetBrushColor(KRgbGray); |
|
331 |
|
332 aGc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
333 aGc.SetPenColor(KRgbWhite); |
|
334 |
|
335 //Set-up a font |
|
336 aGc.UseFont(aFont); |
|
337 |
|
338 //Set the baseline to be half the height of the rectangle + half |
|
339 //the height of the font |
|
340 TInt baseline=aDeviceRect.Height()/2 + aFont->AscentInPixels()/2; |
|
341 |
|
342 //Draw the text |
|
343 //__ASSERT_ALWAYS(iText != NULL, User::Panic(KNullPtr, KNAPanicNullPointer)); |
|
344 aGc.DrawText(*iText, aDeviceRect, baseline, CGraphicsContext::ECenter); |
|
345 |
|
346 //Done with the font |
|
347 aGc.DiscardFont(); |
|
348 } |
|
349 |
|
350 void CMVSFileControl::SetTextL(const TDesC& aText) |
|
351 { |
|
352 HBufC* text=aText.AllocL(); |
|
353 delete iText; |
|
354 iText=text; |
|
355 } |
|
356 |
|
357 // |
|
358 //Window() |
|
359 // |
|
360 // Returns the window defined by this object. |
|
361 TRect& CMVSFileControl::Window() |
|
362 { |
|
363 return iWindow; |
|
364 } |
|
365 |
|
366 |
|
367 |
|
368 // |
|
369 // |
|
370 // class CMVSStateControl |
|
371 // |
|
372 // |
|
373 |
|
374 |
|
375 |
|
376 // |
|
377 //NewL(...) *** This method can LEAVE *** |
|
378 // |
|
379 // Factory contructor, initialises a control based on the rectangle provided. |
|
380 // |
|
381 CMVSStateControl* CMVSStateControl::NewL(const CCoeControl& aContainer, |
|
382 const TRect& aRect, |
|
383 const TDesC& aText) |
|
384 { |
|
385 CMVSStateControl* self=new(ELeave) CMVSStateControl; |
|
386 CleanupStack::PushL(self); |
|
387 self->ConstructL(aContainer, aRect, aText); |
|
388 CleanupStack::Pop(); |
|
389 return self; |
|
390 } |
|
391 |
|
392 |
|
393 |
|
394 // |
|
395 //ContructL(...) *** This method can LEAVE *** |
|
396 // |
|
397 // |
|
398 void CMVSStateControl::ConstructL(const CCoeControl& aContainer, |
|
399 const TRect& aRect, const TDesC& aText) |
|
400 { |
|
401 SetContainerWindowL(aContainer); |
|
402 SetRect(aRect); |
|
403 iWindow = aRect; |
|
404 SetTextL(aText); |
|
405 |
|
406 //Activate the control |
|
407 ActivateL(); |
|
408 } |
|
409 |
|
410 |
|
411 |
|
412 // |
|
413 //CMVSControl() |
|
414 // |
|
415 // Constructor, does nothing. Private to prevent it being called. |
|
416 // |
|
417 CMVSStateControl::CMVSStateControl() |
|
418 { |
|
419 } |
|
420 |
|
421 |
|
422 // |
|
423 //~CMVSControl() |
|
424 // |
|
425 // Destructor. |
|
426 // |
|
427 CMVSStateControl::~CMVSStateControl() |
|
428 { |
|
429 delete iText; |
|
430 } |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 //For Displaying the state |
|
436 void CMVSStateControl::Draw(const TRect& /*aRect*/) const |
|
437 { |
|
438 //Establish a Graphics Context |
|
439 CWindowGc& gc=SystemGc(); |
|
440 |
|
441 //Establish a drawing rectangle |
|
442 TRect rect=Rect(); |
|
443 |
|
444 //Move in 2 pixels each side to give a white border |
|
445 rect.Shrink(2,2); |
|
446 |
|
447 //Set-up a pen |
|
448 gc.SetPenStyle(CGraphicsContext::ENullPen); |
|
449 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
450 gc.SetBrushColor(KRgbDarkGray); |
|
451 |
|
452 //Draw a blank rectangle |
|
453 gc.DrawRect(rect); |
|
454 |
|
455 //Fill in the border-regions |
|
456 DrawUtils::DrawBetweenRects(gc, Rect(), rect); |
|
457 |
|
458 //Change the pen colour to black |
|
459 gc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
460 gc.SetPenColor(KRgbWhite); |
|
461 |
|
462 //Set the fill colour to 'no fill' |
|
463 gc.SetBrushStyle(CGraphicsContext::ENullBrush); |
|
464 |
|
465 //Draw a rectangle (transparent with a black border) |
|
466 gc.DrawRect(rect); |
|
467 rect.Shrink(1,1); |
|
468 |
|
469 const CFont* appFont = iEikonEnv->AnnotationFont(); |
|
470 DrawOtherWindows(gc,rect,appFont); |
|
471 return; |
|
472 } |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 // |
|
478 //DrawOtherWindows(...) |
|
479 // |
|
480 // Draw the text in a central position in the window. |
|
481 // |
|
482 void CMVSStateControl::DrawOtherWindows(CGraphicsContext& aGc, |
|
483 const TRect& aDeviceRect, |
|
484 const CFont* aFont) const |
|
485 { |
|
486 //Set up the pen and brush colours |
|
487 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
488 aGc.SetBrushColor(KRgbGray); |
|
489 |
|
490 aGc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
491 aGc.SetPenColor(KRgbWhite); |
|
492 |
|
493 //Set-up a font |
|
494 aGc.UseFont(aFont); |
|
495 |
|
496 //Set the baseline to be half the height of the rectangle + half |
|
497 //the height of the font |
|
498 TInt baseline=aDeviceRect.Height()/2 + aFont->AscentInPixels()/2; |
|
499 |
|
500 //Draw the text |
|
501 //__ASSERT_ALWAYS(iText != NULL, User::Panic(KNullPtr, KNAPanicNullPointer)); |
|
502 aGc.DrawText(*iText, aDeviceRect, baseline, CGraphicsContext::ECenter); |
|
503 |
|
504 //Done with the font |
|
505 aGc.DiscardFont(); |
|
506 } |
|
507 |
|
508 void CMVSStateControl::SetTextL(const TDesC& aText) |
|
509 { |
|
510 HBufC* text=aText.AllocL(); |
|
511 delete iText; |
|
512 iText=NULL; |
|
513 iText=text; |
|
514 } |
|
515 |
|
516 // |
|
517 //Window() |
|
518 // |
|
519 // Returns the window defined by this object. |
|
520 TRect& CMVSStateControl::Window() |
|
521 { |
|
522 return iWindow; |
|
523 } |
|
524 |
|
525 |
|
526 |
|
527 // |
|
528 // |
|
529 // class CMVSTimeControl |
|
530 // |
|
531 // |
|
532 |
|
533 |
|
534 |
|
535 // |
|
536 //NewL(...) *** This method can LEAVE *** |
|
537 // |
|
538 // Factory contructor, initialises a control based on the rectangle provided. |
|
539 // |
|
540 CMVSTimeControl* CMVSTimeControl::NewL(const CCoeControl& aContainer, |
|
541 const TRect& aRect, |
|
542 const TDesC& aText) |
|
543 { |
|
544 CMVSTimeControl* self=new(ELeave) CMVSTimeControl; |
|
545 CleanupStack::PushL(self); |
|
546 self->ConstructL(aContainer, aRect, aText); |
|
547 CleanupStack::Pop(); |
|
548 return self; |
|
549 } |
|
550 |
|
551 |
|
552 |
|
553 // |
|
554 //ContructL(...) *** This method can LEAVE *** |
|
555 // |
|
556 // |
|
557 void CMVSTimeControl::ConstructL(const CCoeControl& aContainer, |
|
558 const TRect& aRect, const TDesC& aText) |
|
559 { |
|
560 SetContainerWindowL(aContainer); |
|
561 SetRect(aRect); |
|
562 iWindow = aRect; |
|
563 SetTextL(aText); |
|
564 iText2 = NULL; |
|
565 //Activate the control |
|
566 ActivateL(); |
|
567 } |
|
568 |
|
569 |
|
570 |
|
571 // |
|
572 //CMVSControl() |
|
573 // |
|
574 // Constructor, does nothing. Private to prevent it being called. |
|
575 // |
|
576 CMVSTimeControl::CMVSTimeControl() |
|
577 { |
|
578 } |
|
579 |
|
580 |
|
581 // |
|
582 //~CMVSControl() |
|
583 // |
|
584 // Destructor. |
|
585 // |
|
586 CMVSTimeControl::~CMVSTimeControl() |
|
587 { |
|
588 delete iText; |
|
589 if(iText2) |
|
590 { |
|
591 delete iText2; |
|
592 } |
|
593 } |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 //For TimeDisplay |
|
599 void CMVSTimeControl::Draw(const TRect& /*aRect*/) const |
|
600 { |
|
601 //Establish a Graphics Context |
|
602 CWindowGc& gc=SystemGc(); |
|
603 |
|
604 //Establish a drawing rectangle |
|
605 TRect rect=Rect(); |
|
606 |
|
607 //Move in 2 pixels each side to give a white border |
|
608 rect.Shrink(2,2); |
|
609 |
|
610 //Set-up a pen |
|
611 gc.SetPenStyle(CGraphicsContext::ENullPen); |
|
612 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
613 gc.SetBrushColor(KRgbDarkGray); |
|
614 |
|
615 //Draw a blank rectangle |
|
616 gc.DrawRect(rect); |
|
617 |
|
618 //Fill in the border-regions |
|
619 DrawUtils::DrawBetweenRects(gc, Rect(), rect); |
|
620 |
|
621 //Change the pen colour to black |
|
622 gc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
623 gc.SetPenColor(KRgbWhite); |
|
624 |
|
625 //Set the fill colour to 'no fill' |
|
626 gc.SetBrushStyle(CGraphicsContext::ENullBrush); |
|
627 |
|
628 //Draw a rectangle (transparent with a black border) |
|
629 gc.DrawRect(rect); |
|
630 rect.Shrink(1,1); |
|
631 |
|
632 const CFont* appFont = iEikonEnv->AnnotationFont(); |
|
633 DrawOtherWindows(gc,rect,appFont); |
|
634 return; |
|
635 } |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 // |
|
641 //DrawOtherWindows(...) |
|
642 // |
|
643 // Draw the text in a central position in the window. |
|
644 // |
|
645 void CMVSTimeControl::DrawOtherWindows(CGraphicsContext& aGc, |
|
646 const TRect& aDeviceRect, |
|
647 const CFont* aFont) const |
|
648 { |
|
649 //Set up the pen and brush colours |
|
650 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
651 aGc.SetBrushColor(KRgbGray); |
|
652 |
|
653 aGc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
654 aGc.SetPenColor(KRgbWhite); |
|
655 |
|
656 //Set-up a font |
|
657 aGc.UseFont(aFont); |
|
658 |
|
659 |
|
660 if(iText2) |
|
661 { |
|
662 TInt rWidth = aDeviceRect.iBr.iX - aDeviceRect.iTl.iX; |
|
663 TInt rHeight = aDeviceRect.iBr.iY - aDeviceRect.iTl.iY; |
|
664 |
|
665 TRect rect1(aDeviceRect.iTl,TSize(rWidth, rHeight/2)); |
|
666 TRect rect2(TPoint(aDeviceRect.iTl.iX, aDeviceRect.iTl.iY + rHeight/2),TSize(rWidth, rHeight/2)); |
|
667 |
|
668 TInt baseline = rect1.Height(); |
|
669 //Draw the text 1 |
|
670 aGc.DrawText(*iText, rect1, baseline - 2, CGraphicsContext::ECenter); |
|
671 //Draw the text 2 |
|
672 aGc.DrawText(*iText2, rect2, baseline - 3 , CGraphicsContext::ECenter); |
|
673 } |
|
674 else |
|
675 { |
|
676 //Set the baseline to be half the height of the rectangle + half |
|
677 //the height of the font |
|
678 TInt baseline=aDeviceRect.Height()/2 + aFont->AscentInPixels()/2; |
|
679 |
|
680 //Draw the text |
|
681 aGc.DrawText(*iText, aDeviceRect, baseline, CGraphicsContext::ECenter); |
|
682 } |
|
683 |
|
684 //Done with the font |
|
685 aGc.DiscardFont(); |
|
686 } |
|
687 |
|
688 void CMVSTimeControl::SetTextL(const TDesC& aText) |
|
689 { |
|
690 HBufC* text=aText.AllocL(); |
|
691 delete iText; |
|
692 iText=NULL; |
|
693 iText=text; |
|
694 } |
|
695 |
|
696 void CMVSTimeControl::SetText2L(const TDesC& aText) |
|
697 { |
|
698 HBufC* text=aText.AllocL(); |
|
699 delete iText2; |
|
700 iText2=NULL; |
|
701 iText2=text; |
|
702 } |
|
703 |
|
704 void CMVSTimeControl::ResetText2L() |
|
705 { |
|
706 delete iText2; |
|
707 iText2=NULL; |
|
708 } |
|
709 // |
|
710 //Window() |
|
711 // |
|
712 // Returns the window defined by this object. |
|
713 TRect& CMVSTimeControl::Window() |
|
714 { |
|
715 return iWindow; |
|
716 } |
|
717 |
|
718 |
|
719 // |
|
720 // |
|
721 // class CMVSInfoControl |
|
722 // |
|
723 // |
|
724 |
|
725 |
|
726 |
|
727 // |
|
728 //NewL(...) *** This method can LEAVE *** |
|
729 // |
|
730 // Factory contructor, initialises a control based on the rectangle provided. |
|
731 // |
|
732 CMVSInfoControl* CMVSInfoControl::NewL(const CCoeControl& aContainer, |
|
733 const TRect& aRect, |
|
734 const TDesC& aText) |
|
735 { |
|
736 CMVSInfoControl* self=new(ELeave) CMVSInfoControl; |
|
737 CleanupStack::PushL(self); |
|
738 self->ConstructL(aContainer, aRect, aText); |
|
739 CleanupStack::Pop(); |
|
740 return self; |
|
741 } |
|
742 |
|
743 |
|
744 |
|
745 // |
|
746 //ContructL(...) *** This method can LEAVE *** |
|
747 // |
|
748 // |
|
749 void CMVSInfoControl::ConstructL(const CCoeControl& aContainer, |
|
750 const TRect& aRect, const TDesC& aText) |
|
751 { |
|
752 SetContainerWindowL(aContainer); |
|
753 SetRect(aRect); |
|
754 iWindow = aRect; |
|
755 SetTextL(aText); |
|
756 //Activate the control |
|
757 ActivateL(); |
|
758 } |
|
759 |
|
760 |
|
761 |
|
762 // |
|
763 //CMVSControl() |
|
764 // |
|
765 // Constructor, does nothing. Private to prevent it being called. |
|
766 // |
|
767 CMVSInfoControl::CMVSInfoControl() |
|
768 { |
|
769 } |
|
770 |
|
771 |
|
772 // |
|
773 //~CMVSControl() |
|
774 // |
|
775 // Destructor. |
|
776 // |
|
777 CMVSInfoControl::~CMVSInfoControl() |
|
778 { |
|
779 delete iText; |
|
780 } |
|
781 |
|
782 |
|
783 |
|
784 // |
|
785 //Draw(...) |
|
786 // |
|
787 void CMVSInfoControl::Draw(const TRect& /*aRect*/) const |
|
788 { |
|
789 //Establish a Graphics Context |
|
790 CWindowGc& gc=SystemGc(); |
|
791 |
|
792 //Establish a drawing rectangle |
|
793 TRect rect=Rect(); |
|
794 |
|
795 //Move in 2 pixels each side to give a white border |
|
796 rect.Shrink(2,2); |
|
797 |
|
798 //Set-up a pen |
|
799 gc.SetPenStyle(CGraphicsContext::ENullPen); |
|
800 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
801 gc.SetBrushColor(KRgbDarkGray); |
|
802 |
|
803 //Draw a blank rectangle |
|
804 //gc.DrawRect(rect); |
|
805 |
|
806 //To cover Progress Bar area |
|
807 TRect ProgRect = rect; |
|
808 TInt statusPaneHeight = 4*(Parent()->Rect().iTl.iY + Parent()->Rect().iBr.iY)/5; |
|
809 ProgRect.iBr.iY = statusPaneHeight; |
|
810 ProgRect.Grow(2,0); |
|
811 gc.DrawRect(ProgRect); |
|
812 |
|
813 //Fill in the border-regions |
|
814 DrawUtils::DrawBetweenRects(gc, Rect(), rect); |
|
815 |
|
816 //Change the pen colour to black |
|
817 gc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
818 gc.SetPenColor(KRgbWhite); |
|
819 |
|
820 //Set the fill colour to 'no fill' |
|
821 gc.SetBrushStyle(CGraphicsContext::ENullBrush); |
|
822 |
|
823 //Draw a rectangle (transparent with a black border) |
|
824 gc.DrawRect(rect); |
|
825 rect.Shrink(1,1); |
|
826 |
|
827 const CFont* appFont = iEikonEnv->AnnotationFont(); |
|
828 DrawMainWindow(gc,rect,appFont); |
|
829 return; |
|
830 } |
|
831 |
|
832 |
|
833 |
|
834 void CMVSInfoControl::DrawMainWindow(CGraphicsContext& aGc, |
|
835 const TRect& /*aDeviceRect*/, |
|
836 const CFont* aFont) const |
|
837 { |
|
838 //Set up a brush and pen |
|
839 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
840 aGc.SetBrushColor(KRgbDarkGray); |
|
841 |
|
842 aGc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
843 aGc.SetPenColor(KRgbWhite); |
|
844 |
|
845 //Get a font |
|
846 aGc.UseFont(aFont); |
|
847 |
|
848 //The 'step' by which we move down to get to a fresh line in |
|
849 //the window |
|
850 TInt distToNextBaseline = (aFont->AscentInPixels()/2)*3; |
|
851 |
|
852 //The main window text |
|
853 TPtrC mainWindowText; |
|
854 mainWindowText.Set(iText->Des()); |
|
855 |
|
856 //The escape sequence |
|
857 _LIT(KDollarDollar, "$$"); |
|
858 |
|
859 TRect rect; |
|
860 TInt x = 10; //The left hand side of the rectangle |
|
861 TInt y = 10; //The top of the rectangle. |
|
862 |
|
863 //Whilst we can find a '$$' in the string |
|
864 while(mainWindowText.Find(KDollarDollar) != KErrNotFound) |
|
865 { |
|
866 //do text up to $$ |
|
867 TInt pos = mainWindowText.Find(KDollarDollar); |
|
868 TPtrC text(mainWindowText.Mid(0,pos)); |
|
869 |
|
870 //define the rectangle for this text |
|
871 TInt height = aFont->HeightInPixels(); |
|
872 TInt width = aFont->TextWidthInPixels( text ); |
|
873 rect.SetRect( x, y, x + width, y + height ); |
|
874 |
|
875 //Draw the text |
|
876 aGc.DrawText(text, rect, height - aFont->DescentInPixels(), |
|
877 CGraphicsContext::ELeft); |
|
878 |
|
879 //delete text upto and including '$$' |
|
880 text.Set(mainWindowText.Right(mainWindowText.Length() - (pos+2))); |
|
881 mainWindowText.Set(text); |
|
882 |
|
883 //adjust the baseline offset |
|
884 y+=distToNextBaseline; |
|
885 } |
|
886 |
|
887 //Done with our font |
|
888 aGc.DiscardFont(); |
|
889 } |
|
890 |
|
891 |
|
892 void CMVSInfoControl::SetTextL(const TDesC& aText) |
|
893 { |
|
894 HBufC* text=aText.AllocL(); |
|
895 delete iText; |
|
896 iText=NULL; |
|
897 iText=text; |
|
898 } |
|
899 |
|
900 // |
|
901 //Window() |
|
902 // |
|
903 // Returns the window defined by this object. |
|
904 TRect& CMVSInfoControl::Window() |
|
905 { |
|
906 return iWindow; |
|
907 } |