|
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: CCSXHLegacyTopicContainer class definition |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CSXHLegacyTOC2.h" |
|
20 #include "CSXHLegacyTopicContainer.h" |
|
21 #include "CSXHDocument.h" |
|
22 |
|
23 #include "CSXHAppUi.h" |
|
24 |
|
25 #include <eikrted.h> |
|
26 #include <txtrich.h> |
|
27 #include <aknkeys.h> |
|
28 #include <AknUtils.h> |
|
29 #include <barsread.h> |
|
30 #include <applayout.cdl.h> //Dynamic layout functions |
|
31 #include <AknsDrawUtils.h> |
|
32 #include <AknsBasicBackgroundControlContext.h> |
|
33 #include <aknlayoutscalable_apps.cdl.h> |
|
34 #include <aknappui.h> |
|
35 #include <txtfrmat.h> |
|
36 |
|
37 CCSXHLegacyTopicContainer* CCSXHLegacyTopicContainer::NewL(const TRect& |
|
38 aRect,CCSXHDocument &aDocument,CCSXHLegacyTOC2 *aTopic) |
|
39 { |
|
40 CCSXHLegacyTopicContainer* self = CCSXHLegacyTopicContainer::NewLC(aRect,aDocument,aTopic); |
|
41 CleanupStack::Pop(self); |
|
42 return self; |
|
43 } |
|
44 |
|
45 CCSXHLegacyTopicContainer* CCSXHLegacyTopicContainer::NewLC(const TRect& |
|
46 aRect,CCSXHDocument &aDocument,CCSXHLegacyTOC2 *aTopic) |
|
47 { |
|
48 CCSXHLegacyTopicContainer* self = new (ELeave) CCSXHLegacyTopicContainer(aDocument,aTopic); |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(aRect); |
|
51 return self; |
|
52 } |
|
53 |
|
54 CCSXHLegacyTopicContainer::CCSXHLegacyTopicContainer(CCSXHDocument |
|
55 &aDocument,CCSXHLegacyTOC2 *aTopic):iDocument(aDocument),iTopic(aTopic) |
|
56 { |
|
57 } |
|
58 |
|
59 void CCSXHLegacyTopicContainer::ConstructL(const TRect& aRect/*, CRichText* aText*/) |
|
60 { |
|
61 CreateWindowL(); |
|
62 TRect rect(0,0,0,0); |
|
63 // Temporary rect is passed. Correct rect is set in SizeChanged. |
|
64 iSkinContext = CAknsBasicBackgroundControlContext::NewL( |
|
65 KAknsIIDQsnBgAreaMain , rect, EFalse); |
|
66 |
|
67 iText = STATIC_CAST(CRichText*,iTopic->GetTopicContentL()); |
|
68 |
|
69 GetTextFormat(); |
|
70 |
|
71 iEdwin = new(ELeave) CEikEdwin(); |
|
72 const TInt flags(CEikEdwin::EKeepDocument | |
|
73 CEikEdwin::EUserSuppliedText | |
|
74 CEikEdwin::ENoAutoSelection | |
|
75 CEikEdwin::EAvkonDisableCursor | |
|
76 CEikEdwin::EReadOnly | |
|
77 CEikEdwin::EDisplayOnly); |
|
78 iEdwin->SetContainerWindowL(*this); |
|
79 |
|
80 iEdwin->ConstructL(flags); |
|
81 iEdwin->CreatePreAllocatedScrollBarFrameL()->SetScrollBarVisibilityL( |
|
82 CEikScrollBarFrame::EOff, |
|
83 CEikScrollBarFrame::EAuto); |
|
84 SetTextL(iText); |
|
85 FormatRichTextL(*iText); |
|
86 SetRect(aRect); |
|
87 ActivateL(); |
|
88 } |
|
89 |
|
90 CCSXHLegacyTopicContainer::~CCSXHLegacyTopicContainer() |
|
91 { |
|
92 delete iEdwin; |
|
93 delete iSkinContext; |
|
94 } |
|
95 |
|
96 void CCSXHLegacyTopicContainer::RefreshL(CCSXHLegacyTOC2 *aTopic) |
|
97 { |
|
98 iTopic = aTopic; |
|
99 iText = STATIC_CAST(CRichText*,iTopic->GetTopicContentL()); |
|
100 SetTextL(iText); |
|
101 FormatRichTextL(*iText); |
|
102 SizeChanged(); |
|
103 } |
|
104 |
|
105 void CCSXHLegacyTopicContainer::SetTextL(CRichText* aText) |
|
106 { |
|
107 iEdwin->SetDocumentContentL(*aText, CEikEdwin::EUseText); |
|
108 iEdwin->SetCursorPosL(0, EFalse); |
|
109 |
|
110 } |
|
111 |
|
112 void CCSXHLegacyTopicContainer::FocusChanged(TDrawNow aDrawNow) |
|
113 { |
|
114 if (iEdwin) |
|
115 { |
|
116 iEdwin->SetFocus(IsFocused(), aDrawNow); |
|
117 } |
|
118 } |
|
119 |
|
120 void CCSXHLegacyTopicContainer::GetTextFormat() |
|
121 { |
|
122 |
|
123 TAknMultiLineTextLayout layoutToUse; |
|
124 if( AknLayoutUtils::ScalableLayoutInterfaceAvailable() ) |
|
125 { |
|
126 |
|
127 TAknTextLineLayout layoutnew1 = AknLayoutScalable_Apps::help_list_pane_t1(0).LayoutLine(); |
|
128 |
|
129 |
|
130 TAknLayoutScalableParameterLimits limits1 = |
|
131 AknLayoutScalable_Apps::help_list_pane_t1_ParamLimits(); |
|
132 |
|
133 TInt numberoflines = limits1.LastRow() + 1; |
|
134 |
|
135 layoutnew1.iNumberOfLinesShown = numberoflines ; |
|
136 |
|
137 layoutToUse.iC = layoutnew1.iC; |
|
138 layoutToUse.il = layoutnew1.il; |
|
139 layoutToUse.ir = layoutnew1.ir; |
|
140 layoutToUse.iB = layoutnew1.iB; |
|
141 layoutToUse.iW = layoutnew1.iW; |
|
142 layoutToUse.iJ = layoutnew1.iJ; |
|
143 layoutToUse.iFont = layoutnew1.iFont; |
|
144 layoutToUse.iBaselineSkip = layoutnew1.iBaselineSkip; |
|
145 layoutToUse.iNumberOfLinesShown = layoutnew1.iNumberOfLinesShown; |
|
146 } |
|
147 else |
|
148 { |
|
149 layoutToUse = AppLayout::Multiline_Help_texts_Line_1(0); |
|
150 } |
|
151 |
|
152 const CFont* font = AknLayoutUtils::FontFromId(layoutToUse.FontId() /*iFont*/, NULL); |
|
153 iCharFormat.iFontSpec = font->FontSpecInTwips(); |
|
154 iCharFormatMask.SetAttrib(EAttFontTypeface); |
|
155 iCharFormatMask.SetAttrib(EAttFontHeight); |
|
156 |
|
157 TRgb color; |
|
158 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
159 TInt error = AknsUtils::GetCachedColor(skin, color, KAknsIIDQsnTextColors, |
|
160 EAknsCIQsnTextColorsCG6 ); |
|
161 if(error==KErrNone) |
|
162 iCharFormat.iFontPresentation.iTextColor = color; |
|
163 |
|
164 iCharFormatMask.SetAttrib(EAttColor); |
|
165 iCharFormatMask.SetAttrib(EAttFontPosture); |
|
166 } |
|
167 void CCSXHLegacyTopicContainer::FormatRichTextL( CRichText& aText ) |
|
168 { |
|
169 TInt length = aText.DocumentLength(); |
|
170 length++; |
|
171 // Apply the general formatting rules... |
|
172 aText.ApplyCharFormatL( iCharFormat, iCharFormatMask, 0, length ); |
|
173 |
|
174 TParaFormatMask paraFormatMask; |
|
175 paraFormatMask.SetAttrib( EAttBullet ); |
|
176 CParaFormat *paraFormat = new ( ELeave ) CParaFormat; |
|
177 CleanupStack::PushL(paraFormat); |
|
178 TInt paraCount = aText.ParagraphCount(); |
|
179 for(TInt i = 0; i < paraCount ; ++i) |
|
180 { |
|
181 TInt paraLength; |
|
182 TInt paraStart = aText.CharPosOfParagraph(paraLength,i); |
|
183 |
|
184 aText.GetParagraphFormatL(paraFormat,paraStart); |
|
185 if(paraFormat->iBullet) |
|
186 { |
|
187 TBullet* bullet = new ( ELeave ) TBullet; |
|
188 CleanupStack::PushL(bullet); |
|
189 bullet->iColor = iCharFormat.iFontPresentation.iTextColor; |
|
190 bullet->iHeightInTwips = iCharFormat.iFontSpec.iHeight; |
|
191 |
|
192 CParaFormat* paraFormatNew = new ( ELeave ) CParaFormat; |
|
193 paraFormatNew->iBullet = bullet; // ownership xfer |
|
194 |
|
195 CleanupStack::Pop(); |
|
196 CleanupStack::PushL(paraFormatNew); |
|
197 |
|
198 aText.ApplyParaFormatL( paraFormatNew, paraFormatMask, paraStart, paraLength - 1); |
|
199 CleanupStack::PopAndDestroy(paraFormatNew); |
|
200 } |
|
201 } |
|
202 CleanupStack::PopAndDestroy(paraFormat); |
|
203 } |
|
204 |
|
205 |
|
206 void CCSXHLegacyTopicContainer::SizeChanged() |
|
207 { |
|
208 if(iSkinContext) |
|
209 iSkinContext->SetRect(Rect()); |
|
210 if(iEdwin) |
|
211 { |
|
212 TRect clientrect = Rect(); |
|
213 if(AknLayoutUtils::LayoutMirrored()) |
|
214 { |
|
215 clientrect.iTl.iX = clientrect.iTl.iX + (iEdwin->ScrollBarFrame() |
|
216 ->ScrollBarBreadth(CEikScrollBar::EVertical))* 1.1; |
|
217 } |
|
218 else |
|
219 { |
|
220 TInt RectWidth = clientrect.Width() - (iEdwin->ScrollBarFrame() |
|
221 ->ScrollBarBreadth(CEikScrollBar::EVertical))* 1.1; |
|
222 |
|
223 clientrect.SetWidth(RectWidth); |
|
224 } |
|
225 |
|
226 iEdwin->SetRect(clientrect); |
|
227 TRAP_IGNORE(iEdwin->ForceScrollBarUpdateL()); |
|
228 } |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------- |
|
232 // CCsHelpTopicContainer::OfferKeyEventL(...) |
|
233 // Processing a key event |
|
234 // |
|
235 // (other items were commented in a header). |
|
236 // --------------------------------------------------------- |
|
237 TKeyResponse CCSXHLegacyTopicContainer::OfferKeyEventL( |
|
238 const TKeyEvent& aKeyEvent, |
|
239 TEventCode aType) |
|
240 { |
|
241 TKeyResponse result(EKeyWasConsumed); |
|
242 |
|
243 switch (aKeyEvent.iCode) |
|
244 { |
|
245 case EKeyUpArrow: |
|
246 iEdwin->MoveDisplayL(TCursorPosition::EFLineUp); |
|
247 iEdwin->UpdateScrollBarsL(); |
|
248 break; |
|
249 case EKeyDownArrow: |
|
250 iEdwin->MoveDisplayL(TCursorPosition::EFLineDown); |
|
251 iEdwin->UpdateScrollBarsL(); |
|
252 break; |
|
253 default: |
|
254 result = iEdwin->OfferKeyEventL(aKeyEvent, aType); |
|
255 } |
|
256 |
|
257 return result; |
|
258 } |
|
259 |
|
260 |
|
261 // --------------------------------------------------------- |
|
262 // CCsHelpTopicContainer::CountComponentControls() const |
|
263 // |
|
264 // |
|
265 // (other items were commented in a header). |
|
266 // --------------------------------------------------------- |
|
267 // |
|
268 TInt CCSXHLegacyTopicContainer::CountComponentControls() const |
|
269 { |
|
270 return 1; // return nbr of controls inside this container |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------- |
|
274 // CCsHelpTopicContainer::ComponentControl(TInt aIndex) const |
|
275 // |
|
276 // (other items were commented in a header). |
|
277 // --------------------------------------------------------- |
|
278 // |
|
279 CCoeControl* CCSXHLegacyTopicContainer::ComponentControl(TInt aIndex) const |
|
280 { |
|
281 switch ( aIndex ) |
|
282 { |
|
283 case 0: |
|
284 return iEdwin; |
|
285 default: |
|
286 return NULL; |
|
287 } |
|
288 } |
|
289 |
|
290 // --------------------------------------------------------- |
|
291 // CCsHelpTopicContainer::Draw(..) |
|
292 // |
|
293 // (other items were commented in a header). |
|
294 // --------------------------------------------------------- |
|
295 // |
|
296 void CCSXHLegacyTopicContainer::Draw(const TRect& aRect) const |
|
297 { |
|
298 CWindowGc& gc = SystemGc(); |
|
299 gc.Clear(aRect); |
|
300 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
301 if (iSkinContext) |
|
302 {//Draw the skin background |
|
303 AknsDrawUtils::Background( |
|
304 skin, iSkinContext, this, gc, aRect); |
|
305 } |
|
306 } |
|
307 void CCSXHLegacyTopicContainer::HandleResourceChange(TInt aType) |
|
308 { |
|
309 CCSXHAppUi::GetInstance()->PropagateResourceChange(aType); |
|
310 } |
|
311 |
|
312 void CCSXHLegacyTopicContainer::HandleResourceChangeImpl(TInt aType) |
|
313 { |
|
314 if(aType == KEikDynamicLayoutVariantSwitch) |
|
315 { |
|
316 iEdwin->HandleResourceChange(aType); |
|
317 TRect mainRect; |
|
318 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,mainRect); |
|
319 SetRect(mainRect); |
|
320 } |
|
321 else |
|
322 { |
|
323 CCoeControl::HandleResourceChange(aType); |
|
324 } |
|
325 |
|
326 } |
|
327 |
|
328 |
|
329 // --------------------------------------------------------- |
|
330 // CCsHelpTopicContainer::MopSupplyObject() |
|
331 // Pass skin information if need. |
|
332 // --------------------------------------------------------- |
|
333 |
|
334 TTypeUid::Ptr CCSXHLegacyTopicContainer::MopSupplyObject(TTypeUid aId) |
|
335 { |
|
336 if (aId.iUid == MAknsControlContext::ETypeId && iSkinContext) |
|
337 { |
|
338 return MAknsControlContext::SupplyMopObject(aId, iSkinContext); |
|
339 } |
|
340 |
|
341 return CCoeControl::MopSupplyObject(aId); |
|
342 } |
|
343 // End of File |