|
1 /* |
|
2 * Copyright (c) 2007 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 the License "Symbian Foundation License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: AppView class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <coemain.h> |
|
20 #include <eikenv.h> |
|
21 #include <eikrted.h> |
|
22 #include <txtrich.h> |
|
23 #include <hapticstest.rsg> |
|
24 |
|
25 #include "hapticstestappview.h" |
|
26 |
|
27 const TInt KTestSmallerFontTwips = 65; |
|
28 |
|
29 // --------------------------------------------------------- |
|
30 // Standard construction sequence |
|
31 // --------------------------------------------------------- |
|
32 // |
|
33 CHapticsTestAppView* CHapticsTestAppView::NewL(const TRect& aRect) |
|
34 { |
|
35 CHapticsTestAppView* self = CHapticsTestAppView::NewLC(aRect); |
|
36 CleanupStack::Pop(self); |
|
37 return self; |
|
38 } |
|
39 |
|
40 // --------------------------------------------------------- |
|
41 // Static constructor. Leaves the created instance onto the |
|
42 // cleanup stack. |
|
43 // --------------------------------------------------------- |
|
44 // |
|
45 CHapticsTestAppView* CHapticsTestAppView::NewLC(const TRect& aRect) |
|
46 { |
|
47 CHapticsTestAppView* self = new (ELeave) CHapticsTestAppView; |
|
48 CleanupStack::PushL(self); |
|
49 self->ConstructL(aRect); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------- |
|
54 // Constructor. |
|
55 // --------------------------------------------------------- |
|
56 // |
|
57 CHapticsTestAppView::CHapticsTestAppView() |
|
58 { |
|
59 // no implementation required |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------- |
|
63 // Destructor. |
|
64 // --------------------------------------------------------- |
|
65 // |
|
66 CHapticsTestAppView::~CHapticsTestAppView() |
|
67 { |
|
68 delete iParaFormat; |
|
69 iParaFormat = NULL; |
|
70 |
|
71 delete iCharFormat; |
|
72 iCharFormat = NULL; |
|
73 |
|
74 delete iOutputWindow; |
|
75 iOutputWindow = NULL; |
|
76 |
|
77 delete iRichText; |
|
78 iRichText = NULL; |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------- |
|
82 // Construct the view using a rich text editor. |
|
83 // --------------------------------------------------------- |
|
84 // |
|
85 void CHapticsTestAppView::ConstructL(const TRect& aRect) |
|
86 { |
|
87 // Create a window for this application view |
|
88 CreateWindowL(); |
|
89 |
|
90 // get normal font |
|
91 const CFont* font = CEikonEnv::Static()->NormalFont(); |
|
92 TFontSpec fontspec = font->FontSpecInTwips(); |
|
93 |
|
94 TCharFormat defaultCharFormat( fontspec.iTypeface.iName, |
|
95 fontspec.iHeight - KTestSmallerFontTwips ); |
|
96 TCharFormatMask defaultCharFormatMask; |
|
97 defaultCharFormatMask.SetAttrib( EAttFontTypeface ); |
|
98 defaultCharFormatMask.SetAttrib( EAttFontHeight ); |
|
99 |
|
100 // paragraph and char format layers |
|
101 iParaFormat = CParaFormatLayer::NewL(); |
|
102 iCharFormat = CCharFormatLayer::NewL( defaultCharFormat, |
|
103 defaultCharFormatMask ); |
|
104 |
|
105 iRichText = CRichText::NewL( iParaFormat, iCharFormat ); |
|
106 |
|
107 //Create bordered edit windows. |
|
108 iOutputWindow = new (ELeave) CEikRichTextEditor( TGulBorder( TGulBorder::EShallowRaised ) ); |
|
109 iOutputWindow->SetContainerWindowL( *this ); |
|
110 |
|
111 // Create scrollbar |
|
112 iOutputWindow->CreateScrollBarFrameL(); |
|
113 iOutputWindow->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
114 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
115 |
|
116 iOutputWindow->ConstructL( this, 0, 0, |
|
117 EEikEdwinOwnsWindow|EEikEdwinInclusiveSizeFixed| |
|
118 EEikEdwinKeepDocument|EEikEdwinUserSuppliedText| |
|
119 EEikEdwinLineCursor|EEikEdwinAlwaysShowSelection ); |
|
120 |
|
121 TRect outputRect( Rect() ); |
|
122 TInt outputWidthOffset = iOutputWindow->ScrollBarFrame()->ScrollBarBreadth( CEikScrollBar::EVertical ); |
|
123 outputRect.iBr.iX -= outputWidthOffset; |
|
124 |
|
125 iOutputWindow->SetDocumentContentL( *iRichText, CEikEdwin::EUseText ); |
|
126 iOutputWindow->SetRect( outputRect ); |
|
127 iOutputWindow->ActivateL(); |
|
128 iOutputWindow->SetFocus( ETrue ); |
|
129 |
|
130 // Set the windows size |
|
131 SetRect( aRect ); |
|
132 |
|
133 // Activate the window, which makes it ready to be drawn |
|
134 ActivateL(); |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------- |
|
138 // Insert the given text to the end of the outputted text. |
|
139 // Adds line break to the end of the text. |
|
140 // --------------------------------------------------------- |
|
141 // |
|
142 void CHapticsTestAppView::InsertOutput( const TDesC& aOutputLine, |
|
143 TBool aLineBreak ) const |
|
144 { |
|
145 TRAPD( err, iRichText->InsertL( iOutputWindow->TextLength(), |
|
146 aOutputLine ) ); |
|
147 |
|
148 // insert line break if requested |
|
149 if ( aLineBreak ) |
|
150 { |
|
151 TRAP( err, iRichText->InsertL( iOutputWindow->TextLength(), |
|
152 (TChar)CEditableText::ELineBreak ) ); |
|
153 } |
|
154 |
|
155 TRAP( err, iOutputWindow->ForceScrollBarUpdateL() ); |
|
156 TRAP( err, iOutputWindow->SetCursorPosL( iOutputWindow->TextLength(), |
|
157 EFalse) ); |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------- |
|
161 // Clears the output view. |
|
162 // --------------------------------------------------------- |
|
163 // |
|
164 void CHapticsTestAppView::ClearOutput() const |
|
165 { |
|
166 iRichText->Reset(); |
|
167 TRAPD( err, iOutputWindow->HandleTextChangedL()); |
|
168 err = err; // just to escape warning message for ARM |
|
169 iOutputWindow->SetCursorPosL( 0, EFalse ); |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------- |
|
173 // Draw this application's view to the screen |
|
174 // --------------------------------------------------------- |
|
175 // |
|
176 void CHapticsTestAppView::Draw( const TRect& /*aRect*/ ) const |
|
177 { |
|
178 // Get the standard graphics context |
|
179 CWindowGc& gc = SystemGc(); |
|
180 |
|
181 // Gets the control's extent |
|
182 TRect rect = Rect(); |
|
183 |
|
184 // Clears the screen |
|
185 gc.Clear( rect ); |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------- |
|
189 // Called by framework when the view size is changed |
|
190 // --------------------------------------------------------- |
|
191 // |
|
192 void CHapticsTestAppView::SizeChanged() |
|
193 { |
|
194 // decrease the width of the scrollbar from the width of the editor rect |
|
195 TInt outputWidthOffset = iOutputWindow->ScrollBarFrame()->ScrollBarBreadth( CEikScrollBar::EVertical ); |
|
196 TRect outputRect( Rect() ); |
|
197 outputRect.iBr.iX -= outputWidthOffset; |
|
198 iOutputWindow->SetRect( outputRect ); |
|
199 iOutputWindow->SetFocus( ETrue ); |
|
200 } |
|
201 |
|
202 |