|
1 /* |
|
2 * Copyright (c) 2006-2009 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: The container class for ConnTest |
|
15 * Shows status line and notification text editor |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <eikenv.h> |
|
21 #include <eikrted.h> |
|
22 #include <txtrich.h> |
|
23 #include <eiklabel.h> |
|
24 #include "ConnTestContainer.h" |
|
25 #include "ConnTest.pan" |
|
26 |
|
27 |
|
28 // ================= MEMBER FUNCTIONS ======================= |
|
29 |
|
30 // --------------------------------------------------------- |
|
31 // CConnTestContainer::ConstructL(const TRect& aRect) |
|
32 // EPOC two phased constructor |
|
33 // --------------------------------------------------------- |
|
34 // |
|
35 void CConnTestContainer::ConstructL(const TRect& aRect) |
|
36 { |
|
37 CreateWindowL(); |
|
38 Window().SetShadowDisabled(EFalse); |
|
39 |
|
40 SetBlank(); |
|
41 |
|
42 // Get an alternative font for output window. |
|
43 // Note! Only NormalFont works in output window with current |
|
44 // build version, alternative font doesn't. |
|
45 _LIT(KMyFontName,"Arial"); |
|
46 CFont* myFont; |
|
47 TFontSpec myFontSpec(KMyFontName,1); // to get smallest Swiss font |
|
48 CGraphicsDevice* screenDevice=iCoeEnv->ScreenDevice(); |
|
49 screenDevice->GetNearestFontInTwips(myFont,myFontSpec); |
|
50 //TFontSpec testFont = myFont->FontSpecInTwips(); |
|
51 screenDevice->ReleaseFont(myFont); |
|
52 |
|
53 // construct main text display window |
|
54 const CFont* font = CEikonEnv::Static()->NormalFont(); |
|
55 |
|
56 TFontSpec fontspec = font->FontSpecInTwips(); |
|
57 |
|
58 TCharFormat defaultCharFormat( fontspec.iTypeface.iName, fontspec.iHeight ); |
|
59 // TCharFormat defaultCharFormat( testFont.iTypeface.iName, testFont.iHeight ); |
|
60 TCharFormatMask defaultCharFormatMask; |
|
61 |
|
62 defaultCharFormatMask.SetAttrib(EAttFontTypeface); |
|
63 defaultCharFormatMask.SetAttrib(EAttFontHeight); |
|
64 |
|
65 iParaFormat = CParaFormatLayer::NewL(); |
|
66 iCharFormat = CCharFormatLayer::NewL(defaultCharFormat,defaultCharFormatMask); |
|
67 |
|
68 iRichText = CRichText::NewL(iParaFormat, iCharFormat); |
|
69 |
|
70 //Create bordered edit windows. |
|
71 iOutputWindow = new (ELeave) CEikRichTextEditor(TGulBorder(TGulBorder::EShallowRaised)); |
|
72 iOutputWindow->ConstructL(this,0,0,EEikEdwinOwnsWindow|EEikEdwinInclusiveSizeFixed| |
|
73 EEikEdwinKeepDocument|EEikEdwinUserSuppliedText| |
|
74 EEikEdwinLineCursor|EEikEdwinAlwaysShowSelection| |
|
75 EEikEdwinReadOnly); |
|
76 |
|
77 iOutputWindow->SetContainerWindowL(*this); |
|
78 |
|
79 // Create the single line 'status' display |
|
80 iStatusWindow = new (ELeave) CEikLabel; |
|
81 iStatusWindow->SetContainerWindowL(*this); |
|
82 iStatusWindow->SetNonFocusing(); |
|
83 iStatusWindow->SetTextL(_L("Uninitialised")); |
|
84 |
|
85 TRect outputRect(Rect()); |
|
86 TRect statusRect(Rect()); |
|
87 |
|
88 // Set status display to be a single line at bottom of screen |
|
89 statusRect.iTl.iY = statusRect.iBr.iY - iStatusWindow->MinimumSize().iHeight; |
|
90 |
|
91 // Set main output window to occupy rest of screen |
|
92 outputRect.iBr.iY = statusRect.iTl.iY - 1; |
|
93 |
|
94 // Create scrollbar show tabs |
|
95 iOutputWindow->SetAknEditorFlags(EAknEditorFlagEnableScrollBars|EAknEditorFlagNoEditIndicators); |
|
96 |
|
97 iOutputWindow->CreateScrollBarFrameL(); |
|
98 iOutputWindow->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
99 CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto); |
|
100 |
|
101 iOutputWindow->SetDocumentContentL(*iRichText,CEikEdwin::EUseText); |
|
102 iOutputWindow->SetRect(outputRect); |
|
103 iOutputWindow->ActivateL(); |
|
104 iOutputWindow->SetFocus(ETrue); |
|
105 iStatusWindow->SetRect(statusRect); |
|
106 |
|
107 SetRect(aRect); |
|
108 ActivateL(); |
|
109 iOutputWindow->UpdateScrollBarsL(); |
|
110 iOutputWindow->DrawNow(); |
|
111 SizeChanged(); |
|
112 } |
|
113 |
|
114 // ---------------------------------------------------- |
|
115 // CConnTestContainer::~CConnTestContainer() |
|
116 // Destructor |
|
117 // Frees reserved resources |
|
118 // ---------------------------------------------------- |
|
119 // |
|
120 CConnTestContainer::~CConnTestContainer() |
|
121 { |
|
122 delete iParaFormat; |
|
123 iParaFormat = NULL; |
|
124 |
|
125 delete iCharFormat; |
|
126 iCharFormat = NULL; |
|
127 |
|
128 delete iOutputWindow; |
|
129 iOutputWindow = NULL; |
|
130 |
|
131 delete iRichText; |
|
132 iRichText = NULL; |
|
133 |
|
134 delete iStatusWindow; |
|
135 iStatusWindow = NULL; |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------- |
|
139 // CConnTestContainer::SizeChanged() |
|
140 // Called by framework when the view size is changed |
|
141 // --------------------------------------------------------- |
|
142 // |
|
143 void CConnTestContainer::SizeChanged() |
|
144 { |
|
145 TRect outputRect(Rect()); |
|
146 TRect statusRect(Rect()); |
|
147 |
|
148 // Set status display to be a single line at bottom of screen |
|
149 statusRect.iTl.iY = statusRect.iBr.iY - iStatusWindow->MinimumSize().iHeight; |
|
150 |
|
151 // Find the scrollbar rectangle. |
|
152 TRect ScrollBarRect = iOutputWindow->ScrollBarFrame()->VerticalScrollBar()->Rect(); |
|
153 |
|
154 |
|
155 // Set main output window to occupy rest of screen |
|
156 outputRect.iBr.iY = statusRect.iTl.iY - 1; |
|
157 outputRect.iBr.iX -= ScrollBarRect.Width(); |
|
158 |
|
159 iOutputWindow->SetRect(outputRect); |
|
160 iOutputWindow->SetFocus(ETrue); |
|
161 iStatusWindow->SetRect(statusRect); |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------- |
|
165 // CConnTestContainer::CountComponentControls() const |
|
166 // Note! Output window is ignored. |
|
167 // --------------------------------------------------------- |
|
168 // |
|
169 TInt CConnTestContainer::CountComponentControls() const |
|
170 { |
|
171 // Return nbr of controls inside this container |
|
172 // return 2; // Returning control for rich text editor makes it override navipanel. |
|
173 return 2; |
|
174 } |
|
175 |
|
176 |
|
177 // --------------------------------------------------------- |
|
178 // CConnTestContainer::ComponentControl(TInt aIndex) const |
|
179 // Note! Output window is ignored. |
|
180 // --------------------------------------------------------- |
|
181 // |
|
182 CCoeControl* CConnTestContainer::ComponentControl(TInt aIndex) const |
|
183 { |
|
184 switch ( aIndex ) |
|
185 { |
|
186 case 0: |
|
187 return iStatusWindow; |
|
188 case 1: |
|
189 return iOutputWindow; |
|
190 default: |
|
191 return NULL; |
|
192 } |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------- |
|
196 // CConnTestContainer::Draw(const TRect& aRect) const |
|
197 // --------------------------------------------------------- |
|
198 // |
|
199 void CConnTestContainer::Draw(const TRect& aRect) const |
|
200 { |
|
201 //CWindowGc& gc = SystemGc(); |
|
202 //gc.Clear(Rect()); |
|
203 CWindowGc& gc = SystemGc(); |
|
204 gc.SetPenStyle(CGraphicsContext::ENullPen); |
|
205 gc.SetBrushColor(KRgbWhite); |
|
206 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
207 gc.DrawRect(aRect); |
|
208 } |
|
209 |
|
210 |
|
211 // --------------------------------------------------------- |
|
212 // CConnTestContainer::HandleControlEventL( |
|
213 // CCoeControl* aControl,TCoeEvent aEventType) |
|
214 // --------------------------------------------------------- |
|
215 // |
|
216 void CConnTestContainer::HandleControlEventL( CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/ ) |
|
217 { |
|
218 // no implementation required. |
|
219 } |
|
220 |
|
221 |
|
222 // --------------------------------------------------------- |
|
223 // CConnTestContainer::SetFontStyle(TUint aFontStyle) |
|
224 // Set font style for output window. |
|
225 // --------------------------------------------------------- |
|
226 // |
|
227 void CConnTestContainer::SetFontStyle(TUint aFontStyle) |
|
228 { |
|
229 // Set current main window style to match that requested |
|
230 UpdateFontAttribute(aFontStyle, CEikGlobalTextEditor::EBold); |
|
231 UpdateFontAttribute(aFontStyle, CEikGlobalTextEditor::EItalic); |
|
232 UpdateFontAttribute(aFontStyle, CEikGlobalTextEditor::EUnderline); |
|
233 } |
|
234 |
|
235 |
|
236 // --------------------------------------------------------- |
|
237 // CConnTestContainer::UpdateFontAttribute(TUint aFontStyle, |
|
238 // TInt aAttribute) |
|
239 // Do the real work of setting the font style. |
|
240 // --------------------------------------------------------- |
|
241 // |
|
242 void CConnTestContainer::UpdateFontAttribute(TUint aFontStyle, |
|
243 TInt aAttribute) |
|
244 { |
|
245 TInt error; |
|
246 |
|
247 // Ensure an individual attribute is on or off as requested |
|
248 if ((aFontStyle & aAttribute) != (iFontStyle & aAttribute)) |
|
249 { |
|
250 TRAP(error, iOutputWindow->BoldItalicUnderlineEventL(aAttribute)); |
|
251 if(error != KErrNone) |
|
252 { |
|
253 User::Panic (KPanicConnTest, EConnTestContainer); |
|
254 } |
|
255 iFontStyle ^= aAttribute; |
|
256 } |
|
257 } |
|
258 |
|
259 |
|
260 // --------------------------------------------------------- |
|
261 // CConnTestContainer::PrintNotify(const TDesC& aDes, TUint aFontStyle) |
|
262 // Print text into output window. |
|
263 // --------------------------------------------------------- |
|
264 // |
|
265 void CConnTestContainer::PrintNotify(const TDesC& aDes, TUint aFontStyle) |
|
266 { |
|
267 SetFontStyle(aFontStyle); |
|
268 TChar ch; |
|
269 TInt error; |
|
270 |
|
271 RDebug::Print(_L("ConnTest: %S"),&aDes); |
|
272 |
|
273 for (TInt i = 0; i < aDes.Length(); i++) |
|
274 { |
|
275 // Add linebreak if character is '\n', otherwise |
|
276 // add character as it is. |
|
277 ch = aDes[i] != 10 ? (TChar)aDes[i] : (TChar)CEditableText::ELineBreak; |
|
278 TRAP(error, iRichText->InsertL(iOutputWindow->TextLength(), ch)); |
|
279 if(error != KErrNone) |
|
280 { |
|
281 User::Panic (KPanicConnTest, EConnTestContainer); |
|
282 } |
|
283 } |
|
284 |
|
285 TRAP(error, iOutputWindow->NotifyNewDocumentL()); |
|
286 if(error != KErrNone) |
|
287 { |
|
288 User::Panic (KPanicConnTest, EConnTestContainer); |
|
289 } |
|
290 |
|
291 TRAP(error, iOutputWindow->SetCursorPosL(iOutputWindow->TextLength(), EFalse)); |
|
292 if(error != KErrNone) |
|
293 { |
|
294 User::Panic (KPanicConnTest, EConnTestContainer); |
|
295 } |
|
296 } |
|
297 |
|
298 |
|
299 // --------------------------------------------------------- |
|
300 // CConnTestContainer::PrintNotify(const TDesC8& aDes, TUint aFontStyle) |
|
301 // Print text into output window. |
|
302 // --------------------------------------------------------- |
|
303 // |
|
304 void CConnTestContainer::PrintNotify(const TDesC8& aDes, TUint aFontStyle) |
|
305 { |
|
306 SetFontStyle(aFontStyle); |
|
307 TChar ch; |
|
308 TInt error; |
|
309 |
|
310 TBuf<128> des; |
|
311 des.Copy( aDes ); |
|
312 |
|
313 RDebug::Print(_L("ConnTest: %S"),&des); |
|
314 |
|
315 TRAP(error, iRichText->InsertL(iOutputWindow->TextLength(), des)); |
|
316 if(error != KErrNone) |
|
317 { |
|
318 User::Panic (KPanicConnTest, EConnTestContainer); |
|
319 } |
|
320 |
|
321 TRAP(error, iOutputWindow->NotifyNewDocumentL()); |
|
322 if(error != KErrNone) |
|
323 { |
|
324 User::Panic (KPanicConnTest, EConnTestContainer); |
|
325 } |
|
326 |
|
327 TRAP(error, iOutputWindow->SetCursorPosL(iOutputWindow->TextLength(), EFalse)); |
|
328 if(error != KErrNone) |
|
329 { |
|
330 User::Panic (KPanicConnTest, EConnTestContainer); |
|
331 } |
|
332 } |
|
333 |
|
334 |
|
335 // --------------------------------------------------------- |
|
336 // CConnTestContainer::PrintNotify(TInt aIn) |
|
337 // Print integer into output window. |
|
338 // --------------------------------------------------------- |
|
339 // |
|
340 void CConnTestContainer::PrintNotify(TInt aInt) |
|
341 { |
|
342 // Display number in ascii decimal |
|
343 TBuf<50> buf; |
|
344 buf.Num(aInt); |
|
345 PrintNotify(buf); |
|
346 } |
|
347 |
|
348 |
|
349 // --------------------------------------------------------- |
|
350 // CConnTestContainer::ErrorNotify(const TDesC& aErrMessage, TInt aErrCode) |
|
351 // Display error message in an information window. |
|
352 // --------------------------------------------------------- |
|
353 // |
|
354 void CConnTestContainer::ErrorNotify(const TDesC& aErrMessage, TInt aErrCode) |
|
355 { |
|
356 TInt error; |
|
357 |
|
358 // Error up call: inform user and quit |
|
359 _LIT(KErrorTitle,"Error code "); |
|
360 TBuf<25> errorTitleCode(KErrorTitle); |
|
361 errorTitleCode.AppendNum(aErrCode); |
|
362 RDebug::Print(_L("ConnTest: ErrorNotify: %S %d"), &aErrMessage, aErrCode); |
|
363 TRAP(error, CEikonEnv::Static()->InfoWinL(errorTitleCode,aErrMessage)); |
|
364 if(error != KErrNone) |
|
365 { |
|
366 User::Panic (KPanicConnTest, EConnTestContainer); |
|
367 } |
|
368 } |
|
369 |
|
370 // --------------------------------------------------------- |
|
371 // CConnTestContainer::PopupNotify(const TDesC& msg) |
|
372 // Display message in an information window. |
|
373 // --------------------------------------------------------- |
|
374 // |
|
375 void CConnTestContainer::PopupNotify(const TDesC& aMessage) |
|
376 { |
|
377 // Error up call: inform user and quit |
|
378 /* _LIT(KMsgTitle,"NOTE"); |
|
379 TBuf<25> titleCode(KMsgTitle); |
|
380 TRAPD(error, CEikonEnv::Static()->InfoWinL(titleCode,aMessage)); |
|
381 if(error != KErrNone) |
|
382 { |
|
383 User::Panic (KPanicConnTest, EConnTestContainer); |
|
384 } |
|
385 */ |
|
386 RDebug::Print(_L("ConnTest: PopupNotify: %S"), &aMessage); |
|
387 CEikonEnv::Static()->InfoMsgWithDuration(aMessage, 1500000); |
|
388 } |
|
389 |
|
390 // --------------------------------------------------------- |
|
391 // CConnTestContainer::SetStatus(const TDesC& aStatus) |
|
392 // Update the status line text. |
|
393 // --------------------------------------------------------- |
|
394 // |
|
395 void CConnTestContainer::SetStatus(const TDesC& aStatus) |
|
396 { |
|
397 TInt error; |
|
398 |
|
399 // Update contents of status window |
|
400 TRAP(error, iStatusWindow->SetTextL(aStatus)); |
|
401 if(error != KErrNone) |
|
402 { |
|
403 User::Panic (KPanicConnTest, EConnTestContainer); |
|
404 } |
|
405 |
|
406 iStatusWindow->DrawDeferred(); |
|
407 } |
|
408 |
|
409 |
|
410 // --------------------------------------------------------- |
|
411 // CConnTestContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, |
|
412 // TEventCode aType) |
|
413 // Handle key event. Only up and down key arrow events are |
|
414 // consumed in order to enable scrolling in output window. |
|
415 // --------------------------------------------------------- |
|
416 // |
|
417 TKeyResponse CConnTestContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
418 { |
|
419 if(aType != EEventKey) |
|
420 return EKeyWasNotConsumed; |
|
421 |
|
422 if(aKeyEvent.iCode == EKeyUpArrow) |
|
423 { |
|
424 iOutputWindow->MoveCursorL(TCursorPosition::EFLineUp,EFalse); |
|
425 return EKeyWasConsumed; |
|
426 } |
|
427 |
|
428 if(aKeyEvent.iCode == EKeyDownArrow) |
|
429 { |
|
430 iOutputWindow->MoveCursorL(TCursorPosition::EFLineDown,EFalse); |
|
431 return EKeyWasConsumed; |
|
432 } |
|
433 |
|
434 return EKeyWasNotConsumed; |
|
435 } |
|
436 |
|
437 // --------------------------------------------------------- |
|
438 // CConnTestContainer::ClearOutputWindow() |
|
439 // Clear the output window. |
|
440 // --------------------------------------------------------- |
|
441 // |
|
442 void CConnTestContainer::ClearOutputWindow() |
|
443 { |
|
444 TInt error; |
|
445 |
|
446 iRichText->Reset(); |
|
447 TRAP(error, iOutputWindow->NotifyNewDocumentL()); |
|
448 if(error != KErrNone) |
|
449 { |
|
450 User::Panic (KPanicConnTest, EConnTestContainer); |
|
451 } |
|
452 } |
|
453 |
|
454 |
|
455 // End of File |