|
1 /* |
|
2 * Copyright (c) 2006 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: Text viewer component |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CCATextViewControl.h" |
|
22 #include "CCACustomDraw.h" |
|
23 #include "ChatDebugPrint.h" |
|
24 #include "chatdebugassert.h" |
|
25 #include "catouchutils.h" |
|
26 |
|
27 #include <frmtlay.h> // CTextLayout |
|
28 #include <frmtview.h> // CTextView |
|
29 #include <coemain.h> // CCoeEnv |
|
30 |
|
31 #include <AknUtils.h> |
|
32 #include <aknsettingcache.h> |
|
33 #include <aknenv.h> |
|
34 #include <aknconsts.h> |
|
35 #include <avkon.mbg> |
|
36 #include <AknAppUi.h> |
|
37 |
|
38 #include <eikrted.h> |
|
39 #include <AknLayoutScalable_Apps.cdl.h> |
|
40 #include <AknsBasicBackgroundControlContext.h> |
|
41 #include <AknsDrawUtils.h> |
|
42 #include <AknsUtils.h> |
|
43 |
|
44 #include "impsbuilddefinitions.h" |
|
45 |
|
46 // ============================ MEMBER FUNCTIONS =============================== |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CCATextViewControl::CCATextViewControl |
|
50 // C++ default constructor can NOT contain any code, that |
|
51 // might leave. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CCATextViewControl::CCATextViewControl() : |
|
55 iPenType( EPenForwardToChild ) |
|
56 { |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CCATextViewControl::ConstructL |
|
61 // Symbian 2nd phase constructor can leave. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 void CCATextViewControl::ConstructL( const TRect& aRect, |
|
65 const CCoeControl& aParent, |
|
66 MLayDoc* aTextLayout ) |
|
67 { |
|
68 CreateWindowL( &aParent ); |
|
69 |
|
70 // get the drawing device |
|
71 CWindowGc& gc = SystemGc(); |
|
72 CBitmapDevice* device = static_cast<CBitmapDevice*>( gc.Device() ); |
|
73 |
|
74 // create text layout and text view |
|
75 |
|
76 iViewRect = aRect; |
|
77 iClipping = new ( ELeave ) RRegion( aRect ); |
|
78 |
|
79 iLayout = CTextLayout::NewL( aTextLayout, iViewRect.Width() ); |
|
80 iTextView = CTextView::NewL( iLayout, iViewRect, |
|
81 device, device, &Window(), NULL, &iCoeEnv->WsSession() ); |
|
82 |
|
83 iTextView->EnableFlickerFreeRedraw(); |
|
84 iTextView->SetOpaque( ETrue ); |
|
85 |
|
86 // create our background drawer |
|
87 iCustomDraw = new( ELeave )CCACustomDraw( iViewRect ); |
|
88 iLayout->SetCustomDraw( iCustomDraw ); |
|
89 |
|
90 // and scrollbar |
|
91 if ( CATouchUtils::PenEnabled() ) |
|
92 { |
|
93 // Observer |
|
94 iScrollBar = new( ELeave )CEikScrollBarFrame( this, this ); |
|
95 } |
|
96 else |
|
97 { |
|
98 // No observer |
|
99 iScrollBar = new( ELeave )CEikScrollBarFrame( this, NULL ); |
|
100 } |
|
101 |
|
102 CAknAppUi* appUi = iAvkonAppUi; |
|
103 if ( AknLayoutUtils::DefaultScrollBarType( appUi ) == CEikScrollBarFrame::EDoubleSpan ) |
|
104 { |
|
105 // For EDoubleSpan type scrollbar |
|
106 // If pen is supported, SB needs to own a window |
|
107 iScrollBar->CreateDoubleSpanScrollBarsL( CATouchUtils::PenEnabled(), |
|
108 EFalse, ETrue, EFalse ); |
|
109 iScrollBar->SetTypeOfVScrollBar( CEikScrollBarFrame::EDoubleSpan ); |
|
110 } |
|
111 else |
|
112 { |
|
113 // For EArrowHead type scrollbar |
|
114 iScrollBar->SetTypeOfVScrollBar( CEikScrollBarFrame::EArrowHead ); |
|
115 } |
|
116 iScrollBar->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, |
|
117 CEikScrollBarFrame::EOn ); |
|
118 TEikScrollBarModel vSbarModel; |
|
119 vSbarModel.iThumbPosition = 0; // current position |
|
120 vSbarModel.iScrollSpan = 0; // how many items |
|
121 vSbarModel.iThumbSpan = 0; // ignored |
|
122 |
|
123 iScrollBar->Tile( &vSbarModel ); |
|
124 iScrollBar->SetVFocusPosToThumbPos( vSbarModel.iThumbPosition ); |
|
125 |
|
126 iBgContext = CAknsBasicBackgroundControlContext::NewL( |
|
127 KAknsIIDQsnBgAreaMain, Rect(), ETrue ); |
|
128 iCustomDraw->SetBackgroundContext( iBgContext, this ); |
|
129 |
|
130 // Set extensions |
|
131 //SetRect is not necessary, because it will be called again in SizeChanged of CCAChatViewContainer and CCAConversationsContainer |
|
132 //SetRect( aRect ); |
|
133 ActivateL(); |
|
134 |
|
135 // we're ready |
|
136 static_cast<CCoeAppUi*>( iEikonEnv->AppUi() )->AddToStackL( this ); |
|
137 iAddedToStack = ETrue; |
|
138 |
|
139 // Enable draging |
|
140 if ( DrawableWindow() && CATouchUtils::PenEnabled() ) |
|
141 { |
|
142 EnableDragEvents(); |
|
143 Window().SetPointerGrab( ETrue ); |
|
144 } |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CCATextViewControl::NewL |
|
149 // Two-phased constructor. |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 CCATextViewControl* CCATextViewControl::NewL( const TRect& aRect, |
|
153 const CCoeControl& aParent, |
|
154 MLayDoc* aTextLayout ) |
|
155 { |
|
156 CCATextViewControl* self = new( ELeave ) CCATextViewControl; |
|
157 CleanupStack::PushL( self ); |
|
158 self->ConstructL( aRect, aParent, aTextLayout ); |
|
159 CleanupStack::Pop( self ); |
|
160 return self; |
|
161 } |
|
162 |
|
163 // Destructor |
|
164 CCATextViewControl::~CCATextViewControl() |
|
165 { |
|
166 if ( iAddedToStack ) |
|
167 { |
|
168 static_cast<CCoeAppUi*>( iEikonEnv->AppUi() )->RemoveFromStack( this ); |
|
169 } |
|
170 |
|
171 delete iScrollBar; |
|
172 delete iCustomDraw; |
|
173 delete iTextView; |
|
174 delete iLayout; |
|
175 |
|
176 delete iBgContext; |
|
177 if ( iClipping ) |
|
178 { |
|
179 iClipping->Destroy(); |
|
180 } |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CCATextViewControl::UpdateScrollBarsL |
|
185 // (other items were commented in a header). |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 void CCATextViewControl::UpdateScrollBarsL( TBool aScrollDraw /* = ETrue */ ) |
|
189 { |
|
190 TInt height = iLayout->FormattedHeightInPixels(); |
|
191 TInt span = iViewRect.Height(); |
|
192 TInt pos = iLayout->PixelsAboveBand(); |
|
193 |
|
194 if ( span < 0 ) |
|
195 { |
|
196 span = 0; |
|
197 } |
|
198 |
|
199 if ( pos < 0 ) |
|
200 { |
|
201 pos = 0; |
|
202 } |
|
203 |
|
204 TEikScrollBarModel vSbarModel; |
|
205 vSbarModel.iThumbPosition = pos; // current position |
|
206 vSbarModel.iScrollSpan = height; // total length |
|
207 vSbarModel.iThumbSpan = span; // bar length |
|
208 |
|
209 CHAT_DP( D_CHAT_LIT( "CCATextViewControl::UpdateScrollBarsL [%d...%d/%d]" ), |
|
210 pos, pos + span, height ); |
|
211 |
|
212 // Double span |
|
213 if ( iScrollBar && |
|
214 iScrollBar->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan ) |
|
215 { |
|
216 TAknDoubleSpanScrollBarModel vDsModel( vSbarModel ); |
|
217 iScrollBar->Tile( &vDsModel ); |
|
218 iScrollBar->SetVFocusPosToThumbPos( vDsModel.FocusPosition() ); |
|
219 |
|
220 } |
|
221 // ArrowHead |
|
222 else |
|
223 { |
|
224 iScrollBar->Tile( &vSbarModel ); |
|
225 iScrollBar->SetVFocusPosToThumbPos( vSbarModel.iThumbPosition ); |
|
226 } |
|
227 if ( aScrollDraw ) |
|
228 { |
|
229 iScrollBar->DrawScrollBarsNow(); |
|
230 } |
|
231 |
|
232 } |
|
233 |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // CCATextViewControl::UpdateViewL |
|
237 // (other items were commented in a header). |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 void CCATextViewControl::UpdateViewL() |
|
241 { |
|
242 iTextView->FormatTextL(); |
|
243 iTextView->SetSelectionVisibilityL( EFalse ); |
|
244 TCursorSelection sel; |
|
245 // Don't scroll if some item is highlighted |
|
246 if ( !iIsHighlighted ) |
|
247 { |
|
248 sel = TCursorSelection( iLayout->DocumentLength(), 0 ); |
|
249 ScrollVisibleL( sel, ETrue ); |
|
250 } |
|
251 else |
|
252 { |
|
253 sel = iTextView->Selection(); |
|
254 ScrollVisibleL( sel, ETrue ); |
|
255 } |
|
256 |
|
257 DrawDeferred(); |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CCATextViewControl::SetHighlighted |
|
262 // (other items were commented in a header). |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 void CCATextViewControl::SetHighlighted( TBool aIsHighlighted ) |
|
266 { |
|
267 iIsHighlighted = aIsHighlighted; |
|
268 } |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CCATextViewControl::ScrollBarFrame |
|
272 // (other items were commented in a header). |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 const CEikScrollBarFrame* CCATextViewControl::ScrollBarFrame() |
|
276 { |
|
277 return iScrollBar; |
|
278 } |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // CCATextViewControl::ScrollBarFrame |
|
282 // (other items were commented in a header). |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 TInt CCATextViewControl::FindDocPos( TPoint aPoint ) |
|
286 { |
|
287 TTmPosInfo2 posInfo; |
|
288 TBool found = EFalse; |
|
289 |
|
290 TRAPD( err, found = iTextView->FindXyPosL( aPoint, posInfo ) ); |
|
291 if ( err ) |
|
292 { |
|
293 CActiveScheduler::Current()->Error( err ); |
|
294 // Return not found |
|
295 return KErrNotFound; |
|
296 } |
|
297 |
|
298 if ( found ) |
|
299 { |
|
300 CHAT_DP( D_PLAIN_LIT( "CCATextViewControl::FindDocPos:\ |
|
301 Pos fount at %d" ), posInfo.iDocPos.iPos ); |
|
302 |
|
303 return posInfo.iDocPos.iPos; |
|
304 } |
|
305 // not found |
|
306 return KErrNotFound; |
|
307 } |
|
308 |
|
309 // --------------------------------------------------------- |
|
310 // CCATextViewControl::MopSupplyObject |
|
311 // |
|
312 // --------------------------------------------------------- |
|
313 // |
|
314 TTypeUid::Ptr CCATextViewControl::MopSupplyObject( TTypeUid aId ) |
|
315 { |
|
316 if ( aId.iUid == MAknsControlContext::ETypeId ) |
|
317 { |
|
318 return MAknsControlContext::SupplyMopObject( aId, iBgContext ); |
|
319 } |
|
320 |
|
321 return CCoeControl::MopSupplyObject( aId ); |
|
322 } |
|
323 |
|
324 // --------------------------------------------------------- |
|
325 // CCATextViewControl::HandleScrollEventL |
|
326 // |
|
327 // --------------------------------------------------------- |
|
328 // |
|
329 void CCATextViewControl::HandleScrollEventL( CEikScrollBar* /*aScrollBar*/, |
|
330 TEikScrollEvent aEventType ) |
|
331 { |
|
332 switch ( aEventType ) |
|
333 { |
|
334 case EEikScrollUp: |
|
335 { |
|
336 ScrollLinesL( 1 ); |
|
337 break; |
|
338 } |
|
339 case EEikScrollDown: |
|
340 { |
|
341 ScrollLinesL( -1 ); |
|
342 break; |
|
343 } |
|
344 case EEikScrollPageUp: |
|
345 { |
|
346 iTextView->ScrollDisplayL( TCursorPosition::EFPageUp ); |
|
347 UpdateScrollBarsL(); |
|
348 DrawDeferred(); |
|
349 break; |
|
350 } |
|
351 case EEikScrollPageDown: |
|
352 { |
|
353 iTextView->ScrollDisplayL( TCursorPosition::EFPageDown ); |
|
354 UpdateScrollBarsL(); |
|
355 DrawDeferred(); |
|
356 break; |
|
357 } |
|
358 case EEikScrollThumbDragVert: |
|
359 { |
|
360 // Get position values from scrollbar |
|
361 const TEikScrollBarModel* model = |
|
362 iScrollBar->VerticalScrollBar()->Model(); |
|
363 TInt thumb = model->iThumbPosition; |
|
364 if ( CEikScrollBarFrame::EDoubleSpan == |
|
365 iScrollBar->TypeOfVScrollBar() ) |
|
366 { |
|
367 const TAknDoubleSpanScrollBarModel* dsModel = |
|
368 static_cast <const TAknDoubleSpanScrollBarModel*>( model ); |
|
369 thumb = dsModel->FocusPosition(); |
|
370 } |
|
371 |
|
372 // Scroll the textview according to scrollbar |
|
373 TViewYPosQualifier yPosQua; |
|
374 yPosQua.SetHotSpot( TViewYPosQualifier::EFViewTopOfLine ); |
|
375 TInt topPos = -thumb; |
|
376 iTextView->SetViewL( 0, topPos, yPosQua ); |
|
377 break; |
|
378 } |
|
379 case EEikScrollThumbReleaseVert: |
|
380 { |
|
381 // Nothing to do here because EEikScrollThumbDragVert gets |
|
382 // the scrollbar in correct state |
|
383 break; |
|
384 } |
|
385 default: |
|
386 { |
|
387 break; |
|
388 } |
|
389 } |
|
390 } |
|
391 |
|
392 // ----------------------------------------------------------------------------- |
|
393 // CCATextViewControl::OfferKeyEventL |
|
394 // (other items were commented in a header). |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 TKeyResponse CCATextViewControl::OfferKeyEventL( const TKeyEvent& aKeyEvent, |
|
398 TEventCode aType ) |
|
399 { |
|
400 // Commented because it generates so much log |
|
401 // CHAT_DP( D_CHAT_LIT("CCATextViewControl::OfferKeyEventL %d, type %d"), |
|
402 // aKeyEvent, aType ) |
|
403 |
|
404 if ( aType != EEventKey ) |
|
405 { |
|
406 return EKeyWasNotConsumed; |
|
407 } |
|
408 |
|
409 switch ( aKeyEvent.iCode ) |
|
410 { |
|
411 case EKeyDownArrow: |
|
412 { |
|
413 //scroll lines one line down |
|
414 ScrollLinesL( -1 ); |
|
415 return EKeyWasConsumed; |
|
416 |
|
417 } |
|
418 case EKeyUpArrow: |
|
419 { |
|
420 //scroll lines one line up |
|
421 ScrollLinesL( 1 ); |
|
422 return EKeyWasConsumed; |
|
423 |
|
424 } |
|
425 default: |
|
426 { |
|
427 // No handling for other events |
|
428 break; |
|
429 } |
|
430 } |
|
431 |
|
432 return EKeyWasNotConsumed; |
|
433 } |
|
434 |
|
435 // ----------------------------------------------------------------------------- |
|
436 // CCATextViewControl::HandlePointerEventL |
|
437 // (other items were commented in a header). |
|
438 // ----------------------------------------------------------------------------- |
|
439 // |
|
440 void CCATextViewControl::HandlePointerEventL( |
|
441 const TPointerEvent& aPointerEvent ) |
|
442 { |
|
443 if ( !CATouchUtils::PenEnabled() ) |
|
444 { |
|
445 return; |
|
446 } |
|
447 |
|
448 switch ( iPenType ) |
|
449 { |
|
450 case EPenForwardToChild: |
|
451 { |
|
452 // normal (CCoeControl) behaviour |
|
453 CCoeControl::HandlePointerEventL( aPointerEvent ); |
|
454 break; |
|
455 } |
|
456 case EPenForwardToParent: |
|
457 { |
|
458 // forward all to parent |
|
459 if ( Parent() ) |
|
460 { |
|
461 Parent()->HandlePointerEventL( aPointerEvent ); |
|
462 } |
|
463 break; |
|
464 } |
|
465 // Process event ourself |
|
466 case EPenProcessEvent: |
|
467 { |
|
468 ProcessStylusEventL( aPointerEvent ); |
|
469 break; |
|
470 } |
|
471 case EPenIgnoreEvent: |
|
472 { |
|
473 // Ignore all |
|
474 break; |
|
475 } |
|
476 default: |
|
477 { |
|
478 // Can't be |
|
479 __CHAT_ASSERT_DEBUG( EFalse ); |
|
480 break; |
|
481 } |
|
482 } |
|
483 } |
|
484 |
|
485 // ----------------------------------------------------------------------------- |
|
486 // CCATextViewControl::Draw |
|
487 // (other items were commented in a header). |
|
488 // ----------------------------------------------------------------------------- |
|
489 // |
|
490 void CCATextViewControl::Draw( const TRect& aRect ) const |
|
491 { |
|
492 CWindowGc& gc = SystemGc(); |
|
493 |
|
494 // Clip text control and scrollbar to prevent flickering |
|
495 gc.SetClippingRegion( *iClipping ); |
|
496 |
|
497 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
498 if ( iBgContext ) |
|
499 { |
|
500 // Draw the skin background |
|
501 AknsDrawUtils::Background( |
|
502 skin, iBgContext, this, gc, aRect ); |
|
503 } |
|
504 else |
|
505 { |
|
506 // clear the area |
|
507 gc.SetBrushColor( iEikonEnv->ControlColor( EColorWindowBackground, *this ) ); |
|
508 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
509 gc.Clear( aRect ); |
|
510 } |
|
511 |
|
512 TRAP_IGNORE( iTextView->DrawL( aRect ) ); |
|
513 |
|
514 // Cancel clipping |
|
515 gc.CancelClippingRegion(); |
|
516 } |
|
517 |
|
518 // ----------------------------------------------------------------------------- |
|
519 // CCATextViewControl::SizeChanged |
|
520 // (other items were commented in a header). |
|
521 // ----------------------------------------------------------------------------- |
|
522 // |
|
523 void CCATextViewControl::SizeChanged() |
|
524 { |
|
525 TAknWindowLineLayout rpLayout( AknLayoutScalable_Apps::list_im_pane( 3 ) ); |
|
526 TAknLayoutRect rpLayoutRect; |
|
527 rpLayoutRect.LayoutRect( Rect(), rpLayout ); |
|
528 |
|
529 // update rects |
|
530 iViewRect = rpLayoutRect.Rect(); |
|
531 |
|
532 iCustomDraw->SetRect( iViewRect ); |
|
533 iTextView->SetViewRect( iViewRect ); |
|
534 iLayout->SetWrapWidth( iViewRect.Width() ); |
|
535 |
|
536 CAknAppUi* appUi = iAvkonAppUi; |
|
537 if ( AknLayoutUtils::DefaultScrollBarType( appUi ) == CEikScrollBarFrame::EDoubleSpan ) |
|
538 { |
|
539 // For EDoubleSpan type scrollbar |
|
540 TAknWindowLineLayout sbLayout( AknLayoutScalable_Apps::scroll_pane_cp07( 3 ) ); |
|
541 AknLayoutUtils::LayoutVerticalScrollBar( iScrollBar, Rect(), sbLayout ); |
|
542 TAknLayoutRect sbLayoutRect; |
|
543 sbLayoutRect.LayoutRect( Rect(), sbLayout ); |
|
544 } |
|
545 |
|
546 if ( iBgContext ) |
|
547 { |
|
548 iBgContext->SetRect( Parent()->Rect() ); |
|
549 iBgContext->SetParentPos( Parent()->PositionRelativeToScreen() ); |
|
550 } |
|
551 |
|
552 // Setup clipping region |
|
553 iClipping->Clear(); |
|
554 iClipping->AddRect( Rect() ); |
|
555 |
|
556 // clip text control |
|
557 iClipping->SubRect( iTextView->ViewRect() ); |
|
558 |
|
559 // clip scrollbar |
|
560 if ( iScrollBar->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan ) |
|
561 { |
|
562 TAknWindowLineLayout sbLayout( AknLayoutScalable_Apps::scroll_pane_cp07( 3 ) ); |
|
563 AknLayoutUtils::LayoutVerticalScrollBar( iScrollBar, Rect(), sbLayout ); |
|
564 TAknLayoutRect sbLayoutRect; |
|
565 sbLayoutRect.LayoutRect( Rect(), sbLayout ); |
|
566 iClipping->SubRect( sbLayoutRect.Rect() ); |
|
567 } |
|
568 |
|
569 // and update view |
|
570 TRAPD( err, ScrollLinesL( 0 ); |
|
571 UpdateViewL() ); |
|
572 if ( err != KErrNone ) |
|
573 { |
|
574 CActiveScheduler::Current()->Error( err ); |
|
575 } |
|
576 |
|
577 } |
|
578 |
|
579 // ----------------------------------------------------------------------------- |
|
580 // CCATextViewControl::HandleFormatChangedL |
|
581 // (other items were commented in a header). |
|
582 // ----------------------------------------------------------------------------- |
|
583 // |
|
584 void CCATextViewControl::HandleFormatChangedL( TCursorSelection& aChanged, |
|
585 TBool aPreserveFocus /* = EFalse */ ) |
|
586 { |
|
587 // rich text has changed, inform viewer |
|
588 iTextView->SetSelectionVisibilityL( EFalse ); |
|
589 |
|
590 if ( aPreserveFocus ) |
|
591 { |
|
592 // Preserve focus |
|
593 TCursorSelection sel = iTextView->Selection(); |
|
594 // This seems to be the only method which doesn't change focus. |
|
595 // --> so it's possible to preserve focus without flicker |
|
596 iTextView->HandleGlobalChangeNoRedrawL(); |
|
597 ScrollVisibleL( sel, EFalse ); |
|
598 } |
|
599 else |
|
600 { |
|
601 // Move focus along with changes |
|
602 iTextView->HandleRangeFormatChangeL( aChanged ); |
|
603 } |
|
604 } |
|
605 |
|
606 // ----------------------------------------------------------------------------- |
|
607 // CCATextViewControl::HandleInsertDeleteL |
|
608 // (other items were commented in a header). |
|
609 // ----------------------------------------------------------------------------- |
|
610 // |
|
611 void CCATextViewControl::HandleInsertDeleteL( TCursorSelection& aChanged, |
|
612 TInt aDeletedChars ) |
|
613 { |
|
614 // inform about insertion or deletion |
|
615 iTextView->SetSelectionVisibilityL( EFalse ); |
|
616 iTextView->HandleInsertDeleteL( aChanged, aDeletedChars ); |
|
617 } |
|
618 |
|
619 // ----------------------------------------------------------------------------- |
|
620 // CCATextViewControl::HandleAdditionL |
|
621 // (other items were commented in a header). |
|
622 // ----------------------------------------------------------------------------- |
|
623 // |
|
624 void CCATextViewControl::HandleAdditionL( TBool aFirst, |
|
625 TCursorSelection& aSelection, |
|
626 TBool aTop ) |
|
627 { |
|
628 // inform about addition |
|
629 if ( aFirst ) |
|
630 { |
|
631 iTextView->FormatTextL(); |
|
632 } |
|
633 else |
|
634 { |
|
635 iTextView->HandleAdditionalCharactersAtEndL(); |
|
636 } |
|
637 |
|
638 ScrollVisibleL( aSelection, aTop ); |
|
639 DrawDeferred(); |
|
640 } |
|
641 |
|
642 // ----------------------------------------------------------------------------- |
|
643 // CCATextViewControl::ScrollVisibleL |
|
644 // (other items were commented in a header). |
|
645 // ----------------------------------------------------------------------------- |
|
646 // |
|
647 void CCATextViewControl::ScrollVisibleL( TCursorSelection& aSelection, TBool aTop ) |
|
648 { |
|
649 TCursorSelection sel( aSelection ); |
|
650 if ( !ParagraphFits( sel.LowerPos() ) ) |
|
651 { |
|
652 // selection doesn't fit to screen |
|
653 TInt pos( aTop ? aSelection.LowerPos() : aSelection.HigherPos() ); |
|
654 sel.SetSelection( pos, pos ); |
|
655 } |
|
656 |
|
657 // scroll selection to screen |
|
658 iTextView->SetSelectionVisibilityL( EFalse ); |
|
659 iTextView->SetSelectionL( sel ); |
|
660 |
|
661 // and update scroll bars |
|
662 UpdateScrollBarsL(); |
|
663 } |
|
664 |
|
665 // ----------------------------------------------------------------------------- |
|
666 // CCATextViewControl::ScrollSelectionL |
|
667 // (other items were commented in a header). |
|
668 // ----------------------------------------------------------------------------- |
|
669 // |
|
670 TCursorSelection CCATextViewControl::ScrollSelection() |
|
671 { |
|
672 return iTextView->Selection(); |
|
673 } |
|
674 |
|
675 |
|
676 // ----------------------------------------------------------------------------- |
|
677 // CCATextViewControl::ScrollLinesL |
|
678 // (other items were commented in a header). |
|
679 // ----------------------------------------------------------------------------- |
|
680 // |
|
681 void CCATextViewControl::ScrollLinesL( TInt aAmount ) |
|
682 { |
|
683 iLayout->ScrollLinesL( aAmount ); |
|
684 UpdateScrollBarsL(); |
|
685 DrawDeferred(); |
|
686 } |
|
687 |
|
688 // ----------------------------------------------------------------------------- |
|
689 // CCATextViewControl::IsVisible |
|
690 // (other items were commented in a header). |
|
691 // ----------------------------------------------------------------------------- |
|
692 // |
|
693 TBool CCATextViewControl::IsVisible( TInt aPos ) |
|
694 { |
|
695 TTmDocPos pos( aPos, ETrue ); |
|
696 TTmLineInfo lineInfo; |
|
697 |
|
698 if ( !iLayout->PosInBand( pos, &lineInfo ) ) |
|
699 { |
|
700 // current position outside |
|
701 return EFalse; |
|
702 } |
|
703 |
|
704 if ( !ParagraphFits( aPos ) ) |
|
705 { |
|
706 // paragraph doesn't fit to screen |
|
707 // extend scrolling one line up and down |
|
708 |
|
709 // iLineNumber starts from 0 and FirstCharOnLine assumes first line to be 1 |
|
710 TInt lineNo( lineInfo.iLineNumber + 1 ); |
|
711 |
|
712 // check previous line (if it exists) |
|
713 if ( lineNo > 1 ) |
|
714 { |
|
715 pos.iPos = iLayout->FirstCharOnLine( lineNo - 1 ); |
|
716 |
|
717 if ( !iLayout->PosInBand( pos ) ) |
|
718 { |
|
719 // previous line outside |
|
720 return EFalse; |
|
721 } |
|
722 } |
|
723 |
|
724 // check next line |
|
725 pos.iPos = iLayout->FirstCharOnLine( lineNo + 1 ); |
|
726 |
|
727 return iLayout->PosInBand( pos ); |
|
728 } |
|
729 |
|
730 return ETrue; |
|
731 } |
|
732 |
|
733 // ----------------------------------------------------------------------------- |
|
734 // CCATextViewControl::ParagraphFits |
|
735 // (other items were commented in a header). |
|
736 // ----------------------------------------------------------------------------- |
|
737 // |
|
738 TBool CCATextViewControl::ParagraphFits( TInt aPos ) |
|
739 { |
|
740 return iLayout->ParagraphHeight( aPos ) <= iViewRect.Height(); |
|
741 } |
|
742 |
|
743 // ----------------------------------------------------------------------------- |
|
744 // CCATextViewControl::RedrawL |
|
745 // (other items were commented in a header). |
|
746 // ----------------------------------------------------------------------------- |
|
747 // |
|
748 void CCATextViewControl::Redraw() |
|
749 { |
|
750 DrawDeferred(); |
|
751 } |
|
752 |
|
753 // ----------------------------------------------------------------------------- |
|
754 // CCATextViewControl::SetPenBehaviour |
|
755 // (other items were commented in a header). |
|
756 // ----------------------------------------------------------------------------- |
|
757 // |
|
758 void CCATextViewControl::SetPenBehaviour( TPenBehaviour aPen ) |
|
759 { |
|
760 iPenType = aPen; |
|
761 } |
|
762 |
|
763 // ----------------------------------------------------------------------------- |
|
764 // CCATextViewControl::PenBehaviour |
|
765 // (other items were commented in a header). |
|
766 // ----------------------------------------------------------------------------- |
|
767 // |
|
768 MCATextView::TPenBehaviour CCATextViewControl::PenBehaviour() |
|
769 { |
|
770 return iPenType; |
|
771 } |
|
772 |
|
773 // ----------------------------------------------------------------------------- |
|
774 // CCATextViewControl::ProcessStylusEventL |
|
775 // (other items were commented in a header). |
|
776 // ----------------------------------------------------------------------------- |
|
777 // |
|
778 void CCATextViewControl::ProcessStylusEventL( |
|
779 const TPointerEvent& /*aPointerEvent*/ ) |
|
780 { |
|
781 // nothing to do. Let derived classes to handle text selection. |
|
782 } |
|
783 |
|
784 // ----------------------------------------------------------------------------- |
|
785 // CCATextViewControl::HandleGlobalChangeNoRedrawL |
|
786 // (other items were commented in a header). |
|
787 // ----------------------------------------------------------------------------- |
|
788 // |
|
789 void CCATextViewControl::HandleGlobalChangeNoRedrawL( |
|
790 TViewYPosQualifier aYPosQualifier /*= TViewYPosQualifier()*/ ) |
|
791 { |
|
792 iTextView->HandleGlobalChangeNoRedrawL( aYPosQualifier ); |
|
793 } |
|
794 |
|
795 // ----------------------------------------------------------------------------- |
|
796 // CCATextViewControl::CountComponentControls |
|
797 // ----------------------------------------------------------------------------- |
|
798 // |
|
799 TInt CCATextViewControl::CountComponentControls() const |
|
800 { |
|
801 if ( iScrollBar && iScrollBar->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan ) |
|
802 { |
|
803 return 1; |
|
804 } |
|
805 else |
|
806 { |
|
807 return 0; |
|
808 } |
|
809 } |
|
810 |
|
811 // ----------------------------------------------------------------------------- |
|
812 // CCATextViewControl::ComponentControl |
|
813 // ----------------------------------------------------------------------------- |
|
814 // |
|
815 CCoeControl* CCATextViewControl::ComponentControl( TInt aIndex ) const |
|
816 { |
|
817 if ( aIndex == 0 && iScrollBar && iScrollBar->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan ) |
|
818 { |
|
819 return iScrollBar->VerticalScrollBar(); |
|
820 } |
|
821 else |
|
822 { |
|
823 return NULL; |
|
824 } |
|
825 } |
|
826 |
|
827 // End of File |