|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "LauncherContainerOutput.h" |
|
21 #include "LauncherEngine.h" |
|
22 |
|
23 |
|
24 #include <AknBidiTextUtils.h> |
|
25 #include <aknutils.h> |
|
26 #include <aknnotewrappers.h> |
|
27 #include <eiksbfrm.h> |
|
28 #include <akndef.h> |
|
29 |
|
30 const TUint KLeftMargin = 2; |
|
31 const TUint KRightMargin = 2; |
|
32 |
|
33 |
|
34 // ================= MEMBER FUNCTIONS ======================= |
|
35 |
|
36 |
|
37 void CLauncherContainerOutput::ConstructL(const TRect& aRect, CLauncherEngine* aEngine) |
|
38 { |
|
39 iEngine = aEngine; |
|
40 |
|
41 CreateWindowL(); |
|
42 Window().SetShadowDisabled(EFalse); |
|
43 |
|
44 SetBlank(); |
|
45 |
|
46 iText = HBufC::NewL(200000); |
|
47 iCurrentLine = 0; |
|
48 iLineCount = 0; |
|
49 iNumberOfLinesFitsScreen = 0; |
|
50 iX_factor = 1; |
|
51 iY_factor = 1; |
|
52 iLeftDrawingPosition = KLeftMargin; |
|
53 |
|
54 iFont = AknLayoutUtils::FontFromId(EAknLogicalFontSecondaryFont); |
|
55 |
|
56 iWrappedArray = new(ELeave) CArrayFixFlat<TPtrC>(500); |
|
57 |
|
58 |
|
59 SetRect(aRect); |
|
60 //ActivateL(); |
|
61 |
|
62 |
|
63 PrintTextL(_L("Ready.\n\n")); |
|
64 |
|
65 } |
|
66 |
|
67 CLauncherContainerOutput::~CLauncherContainerOutput() |
|
68 { |
|
69 if (iWrappedArray) |
|
70 { |
|
71 iWrappedArray->Reset(); |
|
72 delete iWrappedArray; |
|
73 } |
|
74 |
|
75 if (iText) |
|
76 delete iText; |
|
77 |
|
78 if (iScrollBarFrame) |
|
79 delete iScrollBarFrame; |
|
80 |
|
81 if (iWrapperString) |
|
82 delete iWrapperString; |
|
83 } |
|
84 |
|
85 |
|
86 // --------------------------------------------------------- |
|
87 // CLauncherContainerOutput::UpdateVisualContentL() |
|
88 // --------------------------------------------------------- |
|
89 // |
|
90 void CLauncherContainerOutput::UpdateVisualContentL(TBool aScrollToBottom, TBool aScrollToTop) |
|
91 { |
|
92 TSize rectSize; |
|
93 AknLayoutUtils::LayoutMetricsSize(AknLayoutUtils::EMainPane, rectSize); |
|
94 TRect rect(rectSize); |
|
95 |
|
96 // init scroll bar if not yet done |
|
97 if (!iScrollBarFrame) |
|
98 { |
|
99 iScrollBarFrame = new(ELeave) CEikScrollBarFrame(this, this, ETrue); |
|
100 |
|
101 CAknAppUi* appUi = iAvkonAppUi; |
|
102 |
|
103 if (AknLayoutUtils::DefaultScrollBarType(appUi) == CEikScrollBarFrame::EDoubleSpan) |
|
104 { |
|
105 iScrollBarFrame->CreateDoubleSpanScrollBarsL(ETrue, EFalse); |
|
106 iScrollBarFrame->SetTypeOfVScrollBar(CEikScrollBarFrame::EDoubleSpan); |
|
107 } |
|
108 else |
|
109 { |
|
110 iScrollBarFrame->SetTypeOfVScrollBar(CEikScrollBarFrame::EArrowHead); |
|
111 } |
|
112 iScrollBarFrame->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
113 } |
|
114 |
|
115 // drawing positions, needed for scalable ui |
|
116 iX_factor = TReal(rect.Width()) / 176; |
|
117 iY_factor = TReal(rect.Height()) / 144; |
|
118 |
|
119 iWrappedArray->Reset(); |
|
120 |
|
121 if (iWrapperString) |
|
122 { |
|
123 delete iWrapperString; |
|
124 iWrapperString = NULL; |
|
125 } |
|
126 |
|
127 // define drawing width, some extra space needed if using double span scrolling bar |
|
128 TUint drawingWidth(0); |
|
129 if (iScrollBarFrame->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan) |
|
130 { |
|
131 if (AknLayoutUtils::LayoutMirrored()) // scroll bar on 'left' |
|
132 { |
|
133 iLeftDrawingPosition = KLeftMargin + 12; |
|
134 drawingWidth = TInt( rect.Width() - iLeftDrawingPosition*iX_factor - (KRightMargin*iX_factor)); |
|
135 } |
|
136 else // scroll bar on 'right' |
|
137 { |
|
138 iLeftDrawingPosition = KLeftMargin; |
|
139 drawingWidth = TInt( rect.Width() - iLeftDrawingPosition*iX_factor - (KRightMargin*iX_factor + 7*iX_factor)); |
|
140 } |
|
141 } |
|
142 else |
|
143 drawingWidth = TInt( rect.Width() - KLeftMargin*iX_factor - KRightMargin*iX_factor); |
|
144 |
|
145 // wrap the text |
|
146 iWrapperString = AknBidiTextUtils::ConvertToVisualAndWrapToArrayL( |
|
147 iText->Des(), |
|
148 drawingWidth, |
|
149 *iFont, |
|
150 *iWrappedArray |
|
151 ); |
|
152 |
|
153 iLineCount = iWrappedArray->Count(); |
|
154 |
|
155 // count amount of lines fits to screen |
|
156 iNumberOfLinesFitsScreen = TInt(rect.Height() / (iFont->HeightInPixels())); |
|
157 |
|
158 // check if needed to scroll to the bottom |
|
159 if (aScrollToBottom ) |
|
160 { |
|
161 if( iCurrentLine < iLineCount - iNumberOfLinesFitsScreen) |
|
162 { |
|
163 iCurrentLine = iLineCount-iNumberOfLinesFitsScreen; |
|
164 } |
|
165 } |
|
166 else if( aScrollToTop ) |
|
167 { |
|
168 iCurrentLine = 0; |
|
169 } |
|
170 |
|
171 // update the scroll bars |
|
172 TEikScrollBarModel horizontalBar; |
|
173 TEikScrollBarModel verticalBar; |
|
174 verticalBar.iThumbPosition = iCurrentLine; |
|
175 verticalBar.iScrollSpan = iLineCount - iNumberOfLinesFitsScreen + 1; |
|
176 verticalBar.iThumbSpan = 1; |
|
177 |
|
178 TEikScrollBarFrameLayout layout; |
|
179 layout.iTilingMode = TEikScrollBarFrameLayout::EInclusiveRectConstant; |
|
180 |
|
181 if (iScrollBarFrame->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan) |
|
182 { |
|
183 // do not let scrollbar values overflow |
|
184 if (verticalBar.iThumbPosition + verticalBar.iThumbSpan > verticalBar.iScrollSpan) |
|
185 verticalBar.iThumbPosition = verticalBar.iScrollSpan - verticalBar.iThumbSpan; |
|
186 |
|
187 TAknDoubleSpanScrollBarModel horizontalDSBar(horizontalBar); |
|
188 TAknDoubleSpanScrollBarModel verticalDSBar(verticalBar); |
|
189 |
|
190 iScrollBarFrame->TileL(&horizontalDSBar, &verticalDSBar, rect, rect, layout); |
|
191 iScrollBarFrame->SetVFocusPosToThumbPos(verticalDSBar.FocusPosition()); |
|
192 } |
|
193 else |
|
194 { |
|
195 iScrollBarFrame->TileL( &horizontalBar, &verticalBar, rect, rect, layout ); |
|
196 iScrollBarFrame->SetVFocusPosToThumbPos( verticalBar.iThumbPosition ); |
|
197 } |
|
198 |
|
199 |
|
200 // update the screen |
|
201 DrawNow(); |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------- |
|
205 // CLauncherContainerOutput::Draw(const TRect& aRect) const |
|
206 // --------------------------------------------------------- |
|
207 // |
|
208 void CLauncherContainerOutput::Draw(const TRect& aRect) const |
|
209 { |
|
210 CWindowGc& gc = SystemGc(); |
|
211 gc.Clear(aRect); |
|
212 gc.SetPenColor(KRgbBlack); |
|
213 gc.UseFont(iFont); |
|
214 |
|
215 // draw the text |
|
216 for (TInt i=0; i<iNumberOfLinesFitsScreen; i++) |
|
217 { |
|
218 // index out of bounds check and then draw text |
|
219 if (i+iCurrentLine < iWrappedArray->Count()) |
|
220 gc.DrawText(iWrappedArray->At(i+iCurrentLine), TPoint(TInt(iLeftDrawingPosition*iX_factor), TInt(iFont->HeightInPixels()*(i+1)))); |
|
221 } |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------- |
|
225 // CLauncherContainerOutput::HandleControlEventL( |
|
226 // CCoeControl* aControl,TCoeEvent aEventType) |
|
227 // --------------------------------------------------------- |
|
228 // |
|
229 void CLauncherContainerOutput::HandleControlEventL( |
|
230 CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/) |
|
231 { |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------- |
|
235 // CLauncherContainerOutput::PrintTextL(const TDesC& aDes) |
|
236 // Print text into output window. |
|
237 // --------------------------------------------------------- |
|
238 // |
|
239 void CLauncherContainerOutput::PrintTextL(const TDesC& aDes) |
|
240 { |
|
241 iText->Des().Append( aDes ); |
|
242 UpdateVisualContentL(ETrue); |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------- |
|
246 // CLauncherContainerOutput::OfferKeyEventL(const TKeyEvent& aKeyEvent, |
|
247 // TEventCode aType) |
|
248 // Handle key event. Only up and down key arrow events are |
|
249 // consumed in order to enable scrolling in output window. |
|
250 // --------------------------------------------------------- |
|
251 // |
|
252 TKeyResponse CLauncherContainerOutput::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
253 { |
|
254 if(aType != EEventKey) |
|
255 return EKeyWasNotConsumed; |
|
256 |
|
257 if(aKeyEvent.iCode == EKeyUpArrow) |
|
258 { |
|
259 if (iCurrentLine > 0) |
|
260 { |
|
261 iCurrentLine--; |
|
262 UpdateVisualContentL(EFalse); |
|
263 } |
|
264 |
|
265 return EKeyWasConsumed; |
|
266 } |
|
267 |
|
268 else if(aKeyEvent.iCode == EKeyDownArrow) |
|
269 { |
|
270 if (iCurrentLine < iLineCount - iNumberOfLinesFitsScreen) |
|
271 { |
|
272 iCurrentLine++; |
|
273 UpdateVisualContentL(EFalse); |
|
274 } |
|
275 |
|
276 return EKeyWasConsumed; |
|
277 } |
|
278 |
|
279 return EKeyWasNotConsumed; |
|
280 } |
|
281 |
|
282 |
|
283 // --------------------------------------------------------- |
|
284 // CLauncherContainerOutput::ClearOutputWindowL() |
|
285 // Clear the output window. |
|
286 // --------------------------------------------------------- |
|
287 // |
|
288 void CLauncherContainerOutput::ClearOutputWindowL() |
|
289 { |
|
290 iText->Des() = _L(""); |
|
291 UpdateVisualContentL(EFalse, ETrue); |
|
292 } |
|
293 |
|
294 // --------------------------------------------------------- |
|
295 // CLauncherContainerOutput::HandleResourceChange(TInt aType) |
|
296 // Handle layout change of the screen |
|
297 // --------------------------------------------------------- |
|
298 // |
|
299 |
|
300 void CLauncherContainerOutput::HandleResourceChange(TInt aType) |
|
301 { |
|
302 if ( aType == KEikDynamicLayoutVariantSwitch ) |
|
303 { |
|
304 TRect mainPaneRect; |
|
305 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect); |
|
306 SetRect(mainPaneRect); |
|
307 |
|
308 iCurrentLine = 0; // scroll to top |
|
309 |
|
310 // update font |
|
311 iFont = AknLayoutUtils::FontFromId(EAknLogicalFontSecondaryFont); |
|
312 |
|
313 // delete the scroll and update screen |
|
314 if (iScrollBarFrame) |
|
315 { |
|
316 delete iScrollBarFrame; |
|
317 iScrollBarFrame = NULL; |
|
318 } |
|
319 TRAP_IGNORE(UpdateVisualContentL(EFalse)); |
|
320 } |
|
321 else |
|
322 { |
|
323 CCoeControl::HandleResourceChange(aType); |
|
324 } |
|
325 } |
|
326 |
|
327 // --------------------------------------------------------- |
|
328 // CLauncherContainerOutput::HandleScrollEventL() |
|
329 // Capture touch events on the scroll bar |
|
330 // --------------------------------------------------------- |
|
331 // |
|
332 void CLauncherContainerOutput::HandleScrollEventL(CEikScrollBar* aScrollBar, TEikScrollEvent aEventType) |
|
333 { |
|
334 // only on page up/down,scroll up/down and drag events |
|
335 if ((aEventType == EEikScrollPageDown) || (aEventType == EEikScrollPageUp) || |
|
336 (aEventType == EEikScrollThumbDragVert) || (aEventType == EEikScrollUp) || |
|
337 (aEventType == EEikScrollDown)) |
|
338 { |
|
339 // get the current position from the scroll bar |
|
340 iCurrentLine = aScrollBar->ThumbPosition(); |
|
341 |
|
342 // refresh now |
|
343 UpdateVisualContentL(EFalse); |
|
344 } |
|
345 } |
|
346 |
|
347 |
|
348 // End of File |