|
1 /* |
|
2 * Copyright (c) 1997-1999 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <gdi.h> |
|
21 #include <coecntrl.h> |
|
22 #include <coemain.h> |
|
23 #include <eikconso.h> // #include's eiksbfrm.h |
|
24 #include <eikenv.h> |
|
25 #include <barsread.h> |
|
26 #include <aknpriv.rsg> |
|
27 |
|
28 |
|
29 void cutmax(TInt &x,TInt max); |
|
30 |
|
31 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 // UpdateScrollBarsL() |
|
33 // =================== |
|
34 // Updates the thumb positions etc. on the scrollbars. |
|
35 // Should be called whenever the datasize, visiblesize or position on the scrollbars have changed. |
|
36 // RETURNS ETrue IF ANY SCROLLBARS (DIS)APPEARED |
|
37 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
38 |
|
39 EXPORT_C TBool CEikConsoleControl::UpdateScrollbarsL(const TSize &aDataSize,const TSize& aVisibleSize,TPoint aPos) |
|
40 { |
|
41 // complete available area in characters |
|
42 TSize viewInChars( iSize.iWidth / iCharSize.iWidth, iSize.iHeight / iCharSize.iHeight ); |
|
43 |
|
44 // remember for next time |
|
45 iLastThumbPos = aPos; |
|
46 TEikScrollBarModel vModel; |
|
47 TEikScrollBarModel hModel; |
|
48 if (iVBarVisibility!=CEikScrollBarFrame::EOff) |
|
49 { |
|
50 // Vertical |
|
51 vModel.iScrollSpan=aDataSize.iHeight; |
|
52 if ( viewInChars.iHeight > aVisibleSize.iHeight ) |
|
53 vModel.iThumbSpan=aVisibleSize.iHeight; |
|
54 else |
|
55 vModel.iThumbSpan=viewInChars.iHeight; |
|
56 vModel.iThumbPosition=aPos.iY; |
|
57 } |
|
58 if (iHBarVisibility!=CEikScrollBarFrame::EOff) |
|
59 { |
|
60 // Horizontal |
|
61 hModel.iScrollSpan=aDataSize.iWidth; |
|
62 if ( viewInChars.iWidth > aVisibleSize.iWidth ) |
|
63 hModel.iThumbSpan=aVisibleSize.iWidth; |
|
64 else |
|
65 hModel.iThumbSpan=viewInChars.iWidth; |
|
66 hModel.iThumbPosition=aPos.iX; |
|
67 } |
|
68 TRect fullRect(iSize); |
|
69 TRect clientRect(iViewInPixels); |
|
70 TEikScrollBarFrameLayout layout; |
|
71 CreateScrollBarFrameLayout(layout); |
|
72 if (iSBFrame->TileL(&hModel,&vModel,clientRect,fullRect,layout)) |
|
73 { |
|
74 // something happened, so redetermine the available pixels... |
|
75 iViewInPixels=clientRect.Size(); |
|
76 // the visible characters... |
|
77 // zoe |
|
78 iViewInChars = TSize( iViewInPixels.iWidth / iCharSize.iWidth, iViewInPixels.iHeight / iCharSize.iHeight ); |
|
79 if (iConsole) |
|
80 { |
|
81 cutmax(iViewInChars.iWidth,iConsole->ScreenSize().iWidth); |
|
82 cutmax(iViewInChars.iHeight,iConsole->ScreenSize().iHeight); |
|
83 } |
|
84 // and clear what's outside the new scope... |
|
85 TPoint br(iViewInChars.iWidth*iCharSize.iWidth, iViewInChars.iHeight*iCharSize.iHeight); |
|
86 const TRgb background=iEikonEnv->ControlColor(EColorControlBackground,*this); |
|
87 ClearPixels(TRect(br.iX,0,iViewInPixels.iWidth,br.iY),background); |
|
88 ClearPixels(TRect(0,br.iY,iViewInPixels.iWidth,iViewInPixels.iHeight),background); |
|
89 // and inform caller that the area has changed... |
|
90 return ETrue; |
|
91 } |
|
92 return EFalse; |
|
93 } |
|
94 |
|
95 void CEikConsoleControl::CreateScrollBarFrameLayout(TEikScrollBarFrameLayout& aLayout) const |
|
96 { |
|
97 // all margins default to 0 |
|
98 aLayout.iTilingMode=TEikScrollBarFrameLayout::EInclusiveRectConstant; |
|
99 aLayout.iClientAreaGranularity=iCharSize; |
|
100 } |
|
101 |
|
102 |
|
103 EXPORT_C void CEikConsoleControl::UpdateArea() |
|
104 { |
|
105 // determine how many characters will fit and how many pixels we thus ACTUALLY need |
|
106 //zoe |
|
107 iViewInChars = TSize( iViewInPixels.iWidth / iCharSize.iWidth, iViewInPixels.iHeight / iCharSize.iHeight ); |
|
108 if (iConsole) |
|
109 { |
|
110 cutmax(iViewInChars.iWidth,iConsole->ScreenSize().iWidth); |
|
111 cutmax(iViewInChars.iHeight,iConsole->ScreenSize().iHeight); |
|
112 } |
|
113 // clear the area and redraw |
|
114 const TRgb background=iEikonEnv->ControlColor(EColorControlBackground,*this); |
|
115 ClearPixels(iViewInPixels,background); |
|
116 if (iConsole) |
|
117 iConsole->Redraw(PixelsToChars(TRect(iViewInPixels))); |
|
118 } |
|
119 |
|
120 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
121 // HandleScrollEventL() |
|
122 // ==================== |
|
123 // Called when someone "touches the scrollbar". |
|
124 // Note that it calls back the owner (a CEikConsoleScreen) to do any real action |
|
125 // (specifically, it calls MoveTopLeft(), passing it the required move as a vector) |
|
126 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
127 EXPORT_C void CEikConsoleControl::HandleScrollEventL(CEikScrollBar* aScrollBar,TEikScrollEvent aEventType) |
|
128 { |
|
129 TInt newThumbPos = aScrollBar->ThumbPosition(); |
|
130 TInt pageSize = aScrollBar->Model()->iThumbSpan; |
|
131 const TInt horizontalNudgeFactor = 1; |
|
132 switch (aEventType & KEikScrollEventBarMask) |
|
133 { |
|
134 case KEikScrollEventFromHBar: |
|
135 switch (aEventType) |
|
136 { |
|
137 default: |
|
138 break; |
|
139 case EEikScrollLeft: |
|
140 newThumbPos -= horizontalNudgeFactor; |
|
141 break; |
|
142 case EEikScrollRight: |
|
143 newThumbPos += horizontalNudgeFactor; |
|
144 break; |
|
145 case EEikScrollPageLeft: |
|
146 newThumbPos -= pageSize; |
|
147 break; |
|
148 case EEikScrollPageRight: |
|
149 newThumbPos += pageSize; |
|
150 break; |
|
151 case EEikScrollThumbDragVert: |
|
152 case EEikScrollThumbReleaseVert: |
|
153 // in the case of drag events, the scrollbar automatically updates its thumb pos... |
|
154 break; |
|
155 } |
|
156 iConsole->MoveTopLeft(TPoint(newThumbPos - iLastThumbPos.iX,0)); |
|
157 if (aEventType != EEikScrollThumbDragHoriz) |
|
158 aScrollBar->SetModelThumbPosition(newThumbPos); |
|
159 break; |
|
160 case KEikScrollEventFromVBar: |
|
161 switch (aEventType) |
|
162 { |
|
163 default: |
|
164 break; |
|
165 case EEikScrollUp: |
|
166 --newThumbPos; |
|
167 break; |
|
168 case EEikScrollDown: |
|
169 ++newThumbPos; |
|
170 break; |
|
171 case EEikScrollPageUp: |
|
172 newThumbPos -= ((pageSize < 2)? 1 : pageSize - 1); |
|
173 break; |
|
174 case EEikScrollPageDown: |
|
175 newThumbPos += ((pageSize < 2)? 1 : pageSize - 1); |
|
176 break; |
|
177 case EEikScrollThumbDragVert: |
|
178 case EEikScrollThumbReleaseVert: |
|
179 // in the case of drag events, the scrollbar automatically updates its thumb pos... |
|
180 break; |
|
181 } |
|
182 iConsole->MoveTopLeft(TPoint(0,newThumbPos - iLastThumbPos.iY)); |
|
183 if (aEventType != EEikScrollThumbDragVert) |
|
184 aScrollBar->SetModelThumbPosition(newThumbPos); |
|
185 break; |
|
186 } |
|
187 } |
|
188 |
|
189 |
|
190 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
191 // SetScrollBarVisibility |
|
192 // ====================== |
|
193 // Changes which scroll bars are visible. Returns EFalse if nothing changed. |
|
194 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
195 EXPORT_C TInt CEikConsoleControl::SetScrollBarVisibilityL(CEikScrollBarFrame::TScrollBarVisibility aHBarVisibility, CEikScrollBarFrame::TScrollBarVisibility aVBarVisibility) |
|
196 { |
|
197 if ((aHBarVisibility==iHBarVisibility)&&(aVBarVisibility==iVBarVisibility)) |
|
198 return EFalse; |
|
199 iHBarVisibility=aHBarVisibility; |
|
200 iVBarVisibility=aVBarVisibility; |
|
201 iSBFrame->SetScrollBarVisibilityL(iHBarVisibility, iVBarVisibility); |
|
202 return ETrue; |
|
203 } |
|
204 |
|
205 |
|
206 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
207 // SizeChanged |
|
208 // ========== |
|
209 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
210 EXPORT_C void CEikConsoleControl::SizeChanged() |
|
211 { |
|
212 iViewInPixels=Size(); // new area |
|
213 if (iConsole && iSBFrame) |
|
214 { |
|
215 iConsole->UpdateScrollBars(); |
|
216 UpdateArea(); |
|
217 } |
|
218 } |
|
219 |
|
220 EXPORT_C void CEikConsoleControl::FocusChanged(TDrawNow aDrawNow) |
|
221 { |
|
222 if (aDrawNow==ENoDrawNow) |
|
223 return; |
|
224 if (IsFocused()) |
|
225 iConsole->DrawCursor(); |
|
226 else |
|
227 iConsole->HideCursor(); |
|
228 } |
|
229 |
|
230 EXPORT_C TInt CEikConsoleControl::CountComponentControls() const |
|
231 { |
|
232 return (iSBFrame) ? iSBFrame->CountComponentControls() : NULL; |
|
233 } |
|
234 |
|
235 EXPORT_C CCoeControl* CEikConsoleControl::ComponentControl(TInt aIndex) const |
|
236 { |
|
237 return iSBFrame->ComponentControl(aIndex); |
|
238 } |
|
239 |
|
240 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
241 // VisibleSize() |
|
242 // ============= |
|
243 // Simply returns the visible size in characters |
|
244 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
245 EXPORT_C TSize CEikConsoleControl::VisibleSize() const |
|
246 { |
|
247 return iViewInChars; |
|
248 } |
|
249 |
|
250 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
251 // ConstructL |
|
252 // ========== |
|
253 // Construct and activate a CEikConsoleControl (claiming the specified part of the physical screen) |
|
254 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
255 EXPORT_C void CEikConsoleControl::ConstructL(TInt aFlags) |
|
256 { |
|
257 // Init screen. Use RBackedUpWindow instead of RWindow if aFlags & CEikConsoleScreen::EUseBackedUpWindow |
|
258 if (aFlags&CEikConsoleScreen::EUseBackedUpWindow) |
|
259 CreateBackedUpWindowL((RWindowTreeNode&)iCoeEnv->RootWin(), EGray4); |
|
260 else |
|
261 { |
|
262 CreateWindowL(); |
|
263 Window().SetBackgroundColor(iEikonEnv->ControlColor(EColorControlBackground,*this)); |
|
264 } |
|
265 SetExtentToWholeScreen(); |
|
266 |
|
267 // Create scrollbars |
|
268 iSBFrame=new(ELeave) CEikScrollBarFrame(this, this); |
|
269 iSBFrame->SetScrollBarVisibilityL(iHBarVisibility,iVBarVisibility); |
|
270 |
|
271 InitFontSpecL(); |
|
272 SetFontL(iFontSpec,NULL); |
|
273 |
|
274 // activate |
|
275 ActivateL(); |
|
276 } |
|
277 |
|
278 EXPORT_C void CEikConsoleControl::ConstructL(TPoint aTopLeft,const TSize &aSize,TInt aFlags,TEikConsWinUnits aUnit) |
|
279 { |
|
280 // Init screen. Use RBackedUpWindow instead of RWindow if aFlags & CEikConsoleScreen::EUseBackedUpWindow |
|
281 if (aFlags&CEikConsoleScreen::EUseBackedUpWindow) |
|
282 CreateBackedUpWindowL((RWindowTreeNode&)iCoeEnv->RootWin(), EGray4); |
|
283 else |
|
284 { |
|
285 CreateWindowL(); |
|
286 Window().SetBackgroundColor(iEikonEnv->ControlColor(EColorControlBackground,*this)); |
|
287 } |
|
288 |
|
289 // Create scrollbars |
|
290 iSBFrame=new(ELeave) CEikScrollBarFrame(this, this); |
|
291 iSBFrame->SetScrollBarVisibilityL(iHBarVisibility,iVBarVisibility); |
|
292 |
|
293 InitFontSpecL(); |
|
294 |
|
295 if (aUnit==EEikConsWinInChars) |
|
296 { |
|
297 CFont *font; |
|
298 iEikonEnv->ScreenDevice()->GetNearestFontInTwips(font,iFontSpec); |
|
299 CFbsFont* fbsFont = (CFbsFont*)font; |
|
300 iCurrentFont=fbsFont; |
|
301 iCharSize.iWidth=fbsFont->MaxNormalCharWidthInPixels(); |
|
302 iCharSize.iWidth=fbsFont->CharWidthInPixels('i'); |
|
303 iCharSize.iWidth=fbsFont->CharWidthInPixels('M'); |
|
304 iCharSize.iHeight=fbsFont->HeightInPixels(); |
|
305 |
|
306 SetExtent(TPoint(aTopLeft.iX*iCharSize.iWidth,aTopLeft.iY*iCharSize.iHeight), |
|
307 TSize(aSize.iWidth*iCharSize.iWidth,aSize.iHeight*iCharSize.iHeight)); |
|
308 SetFontL(iFontSpec,fbsFont); |
|
309 } |
|
310 else |
|
311 { |
|
312 SetExtent(aTopLeft,aSize); |
|
313 SetFontL(iFontSpec,NULL); |
|
314 } |
|
315 // activate |
|
316 ActivateL(); |
|
317 } |
|
318 |
|
319 void CEikConsoleControl::InitFontSpecL() |
|
320 { |
|
321 HBufC16* typeface = iCoeEnv->AllocReadResourceAsDes16LC(R_AKNPRIV_DEFAULT_CONSOLE_FONTSPEC_TYPEFACE); |
|
322 iFontSpec.iTypeface.iName= *typeface; |
|
323 CleanupStack::PopAndDestroy(typeface); |
|
324 |
|
325 TResourceReader reader; |
|
326 iCoeEnv->CreateResourceReaderLC(reader,R_AKNPRIV_DEFAULT_CONSOLE_FONTSPEC_HEIGHT); |
|
327 iFontSpec.iHeight=reader.ReadInt16(); |
|
328 CleanupStack::PopAndDestroy(); // reader |
|
329 |
|
330 #if defined(_UNICODE) |
|
331 iFontSpec.iTypeface.SetIsProportional(EFalse); |
|
332 #endif |
|
333 iFontUnderline=EUnderlineOff; |
|
334 iFontSpec.iFontStyle.SetPosture(EPostureUpright); |
|
335 iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal); |
|
336 } |
|
337 |
|
338 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
339 // SetRedrawer |
|
340 // =========== |
|
341 // Define aConsoleScreen as the object responsible for redrawing |
|
342 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
343 EXPORT_C void CEikConsoleControl::SetRedrawer(CEikConsoleScreen *aConsoleScreen) |
|
344 { |
|
345 iConsole=aConsoleScreen; |
|
346 } |
|
347 |
|
348 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
349 // Constructor and Destructor |
|
350 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
351 EXPORT_C CEikConsoleControl::CEikConsoleControl() |
|
352 { |
|
353 // *** init color |
|
354 iBackGray16=iEikonEnv->Color(EColorControlBackground); |
|
355 iPenGray16=iEikonEnv->Color(EColorControlText); |
|
356 |
|
357 // *** init scrollbar settings and font (however, 0-values are free in construction) |
|
358 // iHBarPresent=FALSE; |
|
359 // iVBarPresent=FALSE; |
|
360 // iLastThumbPos = TPoint(0,0); |
|
361 // iCurrentFont=NULL; |
|
362 |
|
363 // *** init cursor |
|
364 iCursorHeightPercentage=20; |
|
365 iTextCursor.iType = TTextCursor::ETypeRectangle; |
|
366 iTextCursor.iFlags = 0; |
|
367 iTextCursor.iColor=iEikonEnv->Color(EColorControlBackground); |
|
368 iLastAtt=iLastFontFlags=(ATT_MAXVALUE+1); |
|
369 } |
|
370 |
|
371 EXPORT_C CEikConsoleControl::~CEikConsoleControl() |
|
372 { |
|
373 iEikonEnv->ReleaseScreenFont(CONST_CAST(CFont*,iCurrentFont)); |
|
374 delete(iSBFrame); |
|
375 } |
|
376 |
|
377 |
|
378 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
379 // NextFontL |
|
380 // ========= |
|
381 // Utility function: unload current font (if any) and load new font (specified elsewhere in iFontSpec) |
|
382 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
383 void CEikConsoleControl::NextFontL() |
|
384 { |
|
385 CFont* font; |
|
386 User::LeaveIfError(iEikonEnv->ScreenDevice()->GetNearestFontInTwips(font, iFontSpec)); |
|
387 CFbsFont* fbsFont = (CFbsFont*)font; |
|
388 iEikonEnv->ReleaseScreenFont(CONST_CAST(CFont*,iCurrentFont)); // note that this only happens if the previous line succeeds! |
|
389 iCurrentFont=fbsFont; |
|
390 } |
|
391 |
|
392 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
393 // SetFontL |
|
394 // ======== |
|
395 // Change the font |
|
396 /////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
397 EXPORT_C void CEikConsoleControl::SetFontL(const TFontSpec& aFontSpec,const CFbsFont *aFont) |
|
398 { |
|
399 iFontSpec=aFontSpec; |
|
400 iFontHeight=(TUint16)iFontSpec.iHeight; |
|
401 if (aFont==NULL) |
|
402 NextFontL(); |
|
403 |
|
404 iCharSize = TSize( iCurrentFont->CharWidthInPixels('M'),iCurrentFont->FontMaxHeight() ); |
|
405 |
|
406 SetCursorHeight(iCursorHeightPercentage); |
|
407 |
|
408 // Determine font flags for new font |
|
409 iFontIsProportional=iCurrentFont->FontSpecInTwips().iTypeface.IsProportional(); |
|
410 iLastFontFlags = 0; |
|
411 if (iFontUnderline!=EUnderlineOff) |
|
412 iLastFontFlags|=ATT_UNDERLINE; |
|
413 if (iFontSpec.iFontStyle.Posture()!=EPostureUpright) |
|
414 iLastFontFlags|=ATT_ITALIC; |
|
415 if (iFontSpec.iFontStyle.StrokeWeight()!=EStrokeWeightNormal) |
|
416 iLastFontFlags|=ATT_BOLD; |
|
417 |
|
418 UpdateArea(); |
|
419 } |
|
420 |
|
421 //////////////////////////////////////////////////////////////////////////////////////// |
|
422 // |
|
423 // Utility functions: convert between character coordinates to pixel coordinates |
|
424 // |
|
425 //////////////////////////////////////////////////////////////////////////////////////// |
|
426 |
|
427 TPoint CEikConsoleControl::CharsToPixels(TPoint aPos) |
|
428 { |
|
429 return TPoint( iCharSize.iWidth * aPos.iX, iCharSize.iHeight * aPos.iY ); |
|
430 } |
|
431 |
|
432 TRect CEikConsoleControl::CharsToPixels(const TRect &aRect) |
|
433 { |
|
434 return TRect(CharsToPixels(aRect.iTl),CharsToPixels(aRect.iBr)); |
|
435 } |
|
436 |
|
437 TRect CEikConsoleControl::PixelsToChars(const TRect &aRect) |
|
438 { |
|
439 TRect r = aRect; |
|
440 r.Normalize(); |
|
441 r.iTl.iX /= iCharSize.iWidth; |
|
442 r.iBr.iX /= iCharSize.iWidth; |
|
443 r.iBr.iX ++; |
|
444 r.iTl.iY /= iCharSize.iHeight; |
|
445 r.iBr.iY /= iCharSize.iHeight; |
|
446 r.iBr.iY ++; |
|
447 return r; |
|
448 } |
|
449 |
|
450 //////////////////////////////////////////////////////////////////////////////////////// |
|
451 // |
|
452 // Cursor stuff |
|
453 // |
|
454 //////////////////////////////////////////////////////////////////////////////////////// |
|
455 |
|
456 EXPORT_C void CEikConsoleControl::DrawCursor(TPoint aPosition) |
|
457 // Show cursor at character position |
|
458 { |
|
459 //iEikonEnv->RootWin().SetTextCursor(*DrawableWindow(),CharsToPixels(aPosition),iTextCursor); |
|
460 iEikonEnv->DrawCursor(this, CharsToPixels(aPosition), iTextCursor.iWidth, iTextCursor.iAscent, iTextCursor.iHeight); |
|
461 } |
|
462 |
|
463 EXPORT_C void CEikConsoleControl::HideCursor() |
|
464 // Hide cursor |
|
465 { |
|
466 //iEikonEnv->RootWin().CancelTextCursor(); |
|
467 iEikonEnv->HideCursor(this); |
|
468 } |
|
469 |
|
470 |
|
471 EXPORT_C void CEikConsoleControl::SetCursorHeight(TUint aPercentage) |
|
472 // Set new cursor height (specified as percentage of font height) |
|
473 // Should also be called whenever iCharSize changes! |
|
474 // Change will not take effect until the next call to DrawCursor! |
|
475 { |
|
476 iCursorHeightPercentage = aPercentage % 101; |
|
477 iTextCursor.iHeight = ( 99 + (iCharSize.iHeight * iCursorHeightPercentage) ) / 100; |
|
478 iTextCursor.iAscent = iTextCursor.iHeight-iCharSize.iHeight; |
|
479 iTextCursor.iWidth = iCharSize.iWidth; |
|
480 } |
|
481 |
|
482 //////////////////////////////////////////////////////////////////////////////////////// |
|
483 // |
|
484 // Draw - defers the real work to the owner (a CEikConsoleScreen) |
|
485 // |
|
486 //////////////////////////////////////////////////////////////////////////////////////// |
|
487 |
|
488 EXPORT_C void CEikConsoleControl::Draw(const TRect& aRect) const |
|
489 { |
|
490 if (iConsole) // if there's no owner, we do nothing |
|
491 { |
|
492 M().iRedrawing=1; |
|
493 TPoint br(iViewInChars.iWidth*iCharSize.iWidth,iViewInChars.iHeight*iCharSize.iHeight); |
|
494 const TRgb background=iEikonEnv->ControlColor(EColorControlBackground,*this); |
|
495 ClearPixels(TRect(br.iX,0,iViewInPixels.iWidth,br.iY),background); |
|
496 ClearPixels(TRect(0,br.iY,iViewInPixels.iWidth,iViewInPixels.iHeight),background); |
|
497 iConsole->Redraw(M().PixelsToChars(aRect)); // Redraw all chars in the rectangle |
|
498 M().iRedrawing=0; |
|
499 } |
|
500 } |
|
501 |
|
502 //////////////////////////////////////////////////////////////////////////////////////// |
|
503 // |
|
504 // Set up GC based for given attribute |
|
505 // |
|
506 //////////////////////////////////////////////////////////////////////////////////////// |
|
507 |
|
508 void CEikConsoleControl::InterpretColorBits(TUint aCharacterAttributes) |
|
509 // Set iPenGrey16 and iBackGrey16 based on character attribute aCharacterAttributes |
|
510 { |
|
511 if (aCharacterAttributes & ATT_COLORMASK) // is color |
|
512 { |
|
513 const TInt pen16=(aCharacterAttributes&0x0F); |
|
514 iPenGray16=TRgb::Color16(pen16); |
|
515 TInt back16=((aCharacterAttributes&0x70)>>4)*2+1; |
|
516 if (back16==1) |
|
517 back16=0; |
|
518 iBackGray16=TRgb::Color16(back16); |
|
519 } |
|
520 else if ( aCharacterAttributes & ATT_INVERSE ) |
|
521 { |
|
522 iBackGray16=iEikonEnv->ControlColor(EColorControlHighlightBackground,*this); |
|
523 iPenGray16=iEikonEnv->ControlColor(EColorControlHighlightText,*this); |
|
524 } |
|
525 else |
|
526 { |
|
527 iBackGray16=iEikonEnv->ControlColor(EColorControlBackground,*this); |
|
528 iPenGray16=iEikonEnv->ControlColor(EColorControlText,*this); |
|
529 } |
|
530 } |
|
531 |
|
532 void CEikConsoleControl::InterpretAttribute(TUint aCharacterAttributes) |
|
533 { |
|
534 if (iLastAtt!=aCharacterAttributes) |
|
535 { |
|
536 _LIT(KMonospace,"Monospaced"); |
|
537 _LIT(KMonodouble,"MONODOUBLE"); |
|
538 iLastAtt=aCharacterAttributes; |
|
539 InterpretColorBits(aCharacterAttributes); |
|
540 TUint fontFlags = (aCharacterAttributes & ATT_COLORMASK) ? (0) : (aCharacterAttributes & ATT_IGNORE_INVERSE & ATT_IGNORE_RIGHTLEFT); |
|
541 if (iLastFontFlags!=fontFlags) |
|
542 { |
|
543 iLastFontFlags=fontFlags; |
|
544 iFontUnderline=((fontFlags & ATT_UNDERLINE)? EUnderlineOn: EUnderlineOff); |
|
545 iFontSpec.iFontStyle.SetPosture(((fontFlags & ATT_ITALIC)? EPostureItalic: EPostureUpright)); |
|
546 iFontSpec.iFontStyle.SetStrokeWeight(((fontFlags & ATT_BOLD)? EStrokeWeightBold: EStrokeWeightNormal)); |
|
547 if (fontFlags & ATT_DOUBLEMASK) |
|
548 { // double aVisiblePixels |
|
549 if ( (fontFlags & ATT_DOUBLEMASK) == ATT_DOUBLEWIDTH ) |
|
550 { // double width |
|
551 iFontSpec.iHeight = iFontHeight; |
|
552 if (iFontSpec.iTypeface.iName.Compare(KMonospace)==0 ) |
|
553 iFontSpec.iTypeface.iName=KMonodouble; //@@@ |
|
554 } |
|
555 else |
|
556 { // double height |
|
557 iFontSpec.iHeight = (TUint16)(iFontHeight*2); |
|
558 if ( iFontSpec.iTypeface.iName.Compare(KMonodouble)==0 ) |
|
559 iFontSpec.iTypeface.iName=KMonospace; //@@@ |
|
560 } |
|
561 } |
|
562 else |
|
563 { // normal aVisiblePixels |
|
564 iFontSpec.iHeight = iFontHeight; |
|
565 if ( iFontSpec.iTypeface.iName.Compare(KMonodouble)==0 ) |
|
566 iFontSpec.iTypeface.iName=KMonospace; //@@@ |
|
567 } |
|
568 TRAP_IGNORE(NextFontL()); // ignore errors. If there is a problem, we'll use the one that was loaded |
|
569 } |
|
570 } |
|
571 } |
|
572 |
|
573 //////////////////////////////////////////////////////////////////////////////////////// |
|
574 // |
|
575 // Basic Graphic services |
|
576 // ====================== |
|
577 // NOTE: if iRedrawing, then a redraw is going on, |
|
578 // i.e. no need to (de)activate gc's or (in)validate rectangles |
|
579 // |
|
580 //////////////////////////////////////////////////////////////////////////////////////// |
|
581 |
|
582 EXPORT_C void CEikConsoleControl::InvertChars(const TRect &anArea) |
|
583 // invert a rectangle of characters |
|
584 { |
|
585 if (!iRedrawing) |
|
586 ActivateGc(); |
|
587 CWindowGc& gc=SystemGc(); |
|
588 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
589 const TRgb highlightBackground=iEikonEnv->ControlColor(EColorControlBackground,*this); |
|
590 gc.SetBrushColor(highlightBackground); |
|
591 gc.SetDrawMode(CGraphicsContext::EDrawModeXOR); |
|
592 gc.SetPenStyle(CGraphicsContext::ENullPen); |
|
593 if (!iRedrawing && !IsBackedUp()) |
|
594 { |
|
595 Window().Invalidate(anArea); |
|
596 Window().BeginRedraw(anArea); |
|
597 } |
|
598 |
|
599 gc.DrawRect(CharsToPixels(anArea)); |
|
600 if (!iRedrawing && !IsBackedUp()) |
|
601 { |
|
602 Window().EndRedraw(); |
|
603 } |
|
604 |
|
605 gc.SetDrawMode(CGraphicsContext::EDrawModePEN); |
|
606 gc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
607 gc.SetBrushStyle(CGraphicsContext::ENullBrush); |
|
608 if (!iRedrawing) |
|
609 DeactivateGc(); |
|
610 } |
|
611 |
|
612 EXPORT_C void CEikConsoleControl::ScrollChars(const TRect &anArea,const TPoint &aVector) |
|
613 // scroll a rectangle of characters by a given vector (character coordinates) |
|
614 { |
|
615 const TRect areaInPixels=CharsToPixels(anArea); |
|
616 Window().Scroll(areaInPixels,CharsToPixels(aVector),areaInPixels); |
|
617 } |
|
618 |
|
619 void CEikConsoleControl::ClearPixels(const TRect &anArea,TRgb aColor) const |
|
620 { |
|
621 if (!iRedrawing) |
|
622 ActivateGc(); |
|
623 CWindowGc& gc=SystemGc(); |
|
624 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
625 gc.SetBrushColor(aColor); |
|
626 gc.SetPenStyle(CGraphicsContext::ENullPen); |
|
627 if (!iRedrawing && !IsBackedUp()) |
|
628 { |
|
629 Window().Invalidate(anArea); |
|
630 Window().BeginRedraw(anArea); |
|
631 } |
|
632 |
|
633 gc.DrawRect(anArea); |
|
634 if (!iRedrawing && !IsBackedUp()) |
|
635 { |
|
636 Window().EndRedraw(); |
|
637 } |
|
638 gc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
639 gc.SetBrushStyle(CGraphicsContext::ENullBrush); |
|
640 if (!iRedrawing) |
|
641 DeactivateGc(); |
|
642 } |
|
643 |
|
644 EXPORT_C void CEikConsoleControl::ClearChars(const TRect &anArea,TUint aCharacterAttributes) |
|
645 // Clears a rectangle of characters to the current background color |
|
646 { |
|
647 TRect theArea=CharsToPixels(anArea); |
|
648 InterpretColorBits(aCharacterAttributes); |
|
649 ClearPixels(theArea,iBackGray16); |
|
650 } |
|
651 |
|
652 EXPORT_C void CEikConsoleControl::DrawChars(const TDesC &aString,const TPoint &aPosition,TUint aCharacterAttributes) |
|
653 // Draw characters at given position using given attribute |
|
654 { |
|
655 InterpretAttribute(aCharacterAttributes); |
|
656 TPoint pos = CharsToPixels(aPosition); |
|
657 TInt topMargin = iCurrentFont->AscentInPixels(); |
|
658 if ( iCurrentFont->TypeUid() == KCFbsFontUid) |
|
659 { |
|
660 const CFbsFont* fbsFont = (CFbsFont*)iCurrentFont; |
|
661 topMargin = fbsFont->FontMaxAscent(); |
|
662 } |
|
663 |
|
664 TInt isDouble = ( !(aCharacterAttributes & ATT_COLORMASK) && (aCharacterAttributes & ATT_DOUBLEMASK) ); |
|
665 TRect charArea = TRect(pos,iCharSize); |
|
666 |
|
667 if (!iRedrawing) |
|
668 ActivateGc(); |
|
669 |
|
670 CWindowGc& gc=SystemGc(); |
|
671 gc.UseFont(iCurrentFont); |
|
672 gc.SetPenColor(iPenGray16); |
|
673 gc.SetBrushColor(iBackGray16); |
|
674 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
675 gc.SetUnderlineStyle(iFontUnderline); |
|
676 |
|
677 TInt currentFont_width = iCurrentFont->MaxNormalCharWidthInPixels(); |
|
678 if (isDouble || iFontIsProportional || currentFont_width!=iCharSize.iWidth ) |
|
679 { |
|
680 TInt leftMargin = 0; |
|
681 |
|
682 if (isDouble) |
|
683 { |
|
684 if (aCharacterAttributes & ATT_RIGHTMASK) |
|
685 leftMargin -= iCharSize.iWidth; |
|
686 if ((aCharacterAttributes & ATT_DOUBLEMASK) == ATT_DOUBLEBOTTOM) |
|
687 topMargin -= iCharSize.iHeight; |
|
688 } |
|
689 |
|
690 if (!iRedrawing && !IsBackedUp()) |
|
691 { |
|
692 TSize stringSize(iCharSize); |
|
693 stringSize.iWidth *= aString.Length(); // calculate on-screen width of line |
|
694 TRect wholestring(pos,stringSize); |
|
695 Window().Invalidate(wholestring); |
|
696 Window().BeginRedraw(wholestring); // begin draw transaction for whole line |
|
697 } |
|
698 for ( TInt i=0;i<aString.Length();i++ ) |
|
699 { |
|
700 gc.DrawText(aString.Mid(i,1),charArea,topMargin,CGraphicsContext::ELeft,leftMargin); |
|
701 |
|
702 charArea.Move(iCharSize.iWidth,0); |
|
703 if (isDouble) |
|
704 leftMargin = - iCharSize.iWidth - leftMargin; |
|
705 } |
|
706 if (!iRedrawing && !IsBackedUp()) |
|
707 { |
|
708 Window().EndRedraw(); |
|
709 } |
|
710 } |
|
711 else |
|
712 { |
|
713 charArea.iBr.iX += (iCharSize.iWidth*(aString.Length()-1)); |
|
714 if (!iRedrawing && !IsBackedUp()) |
|
715 { |
|
716 Window().Invalidate(charArea); |
|
717 Window().BeginRedraw(charArea); |
|
718 } |
|
719 gc.DrawText(aString,charArea,topMargin); |
|
720 if (!iRedrawing && !IsBackedUp()) |
|
721 { |
|
722 Window().EndRedraw(); |
|
723 } |
|
724 } |
|
725 |
|
726 gc.DiscardFont(); |
|
727 if (!iRedrawing) |
|
728 DeactivateGc(); |
|
729 } |
|
730 |
|
731 /** |
|
732 * Gets the list of logical colors employed in the drawing of the control, |
|
733 * paired with an explanation of how they are used. Appends the list to aColorUseList. |
|
734 * |
|
735 * @since ER5U |
|
736 */ |
|
737 EXPORT_C void CEikConsoleControl::GetColorUseListL(CArrayFix<TCoeColorUse>& /*aColorUseList*/) const |
|
738 { |
|
739 } |
|
740 |
|
741 /** |
|
742 * Handles a change to the control's resources of type aType |
|
743 * which are shared across the environment, e.g. colors or fonts. |
|
744 * |
|
745 * @since ER5U |
|
746 */ |
|
747 EXPORT_C void CEikConsoleControl::HandleResourceChange(TInt aType) |
|
748 { |
|
749 CCoeControl::HandleResourceChange(aType); |
|
750 if (aType==KEikMessageColorSchemeChange) |
|
751 { |
|
752 if (!IsBackedUp()) |
|
753 { |
|
754 Window().SetBackgroundColor(iEikonEnv->ControlColor(EColorControlBackground,*this)); |
|
755 } |
|
756 } |
|
757 } |
|
758 |
|
759 // Reserved from CCoeControl |
|
760 |
|
761 EXPORT_C void CEikConsoleControl::WriteInternalStateL(RWriteStream& /*aWriteStream*/) const |
|
762 { |
|
763 } |
|
764 |
|
765 EXPORT_C void CEikConsoleControl::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
766 { |
|
767 CAknControl::HandlePointerEventL(aPointerEvent); |
|
768 } |
|
769 |
|
770 EXPORT_C void* CEikConsoleControl::ExtensionInterface( TUid /*aInterface*/ ) |
|
771 { |
|
772 return NULL; |
|
773 } |
|
774 |
|
775 EXPORT_C void CEikConsoleControl::Reserved_2() |
|
776 { |
|
777 } |
|
778 |