|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // THelpViewCtrls module |
|
15 // |
|
16 // |
|
17 |
|
18 #include "thelpviewctrls.h" |
|
19 |
|
20 // System includes |
|
21 #include <techview/eikcmbut.h> |
|
22 #include <techview/eikedwin.h> |
|
23 // |
|
24 #include "hlpmodel.h" |
|
25 |
|
26 // Constants |
|
27 const TInt KTimeOutPeriod = 10000000; // Ten seconds |
|
28 |
|
29 // Literal constants |
|
30 _LIT(KDoneCaption, "Done"); |
|
31 |
|
32 |
|
33 // |
|
34 // ----> CHlpSearchPrompt (header) |
|
35 // |
|
36 |
|
37 CHlpSearchPrompt::CHlpSearchPrompt() |
|
38 { |
|
39 } |
|
40 |
|
41 CHlpSearchPrompt::~CHlpSearchPrompt() |
|
42 { |
|
43 iHideTimer->Cancel(); |
|
44 delete iHideTimer; |
|
45 delete iEdwin; |
|
46 } |
|
47 |
|
48 void CHlpSearchPrompt::ConstructL(CCoeControl& aParent) |
|
49 { |
|
50 CreateWindowL(&aParent); |
|
51 |
|
52 iHideTimer = CPeriodic::NewL(CActive::EPriorityIdle); |
|
53 |
|
54 iEdwin = new(ELeave) CEikEdwin(); |
|
55 iEdwin->SetContainerWindowL(*this); |
|
56 iEdwin->ConstructL(0, 25, 140, 1); |
|
57 iEdwin->CreateTextViewL(); |
|
58 iEdwin->SetObserver(this); |
|
59 } |
|
60 |
|
61 // |
|
62 // |
|
63 // |
|
64 |
|
65 void CHlpSearchPrompt::ResetSearchL() |
|
66 { |
|
67 iEdwin->Text()->Reset(); |
|
68 iEdwin->NotifyNewDocumentL(); |
|
69 iEdwin->DrawNow(); |
|
70 } |
|
71 |
|
72 HBufC* CHlpSearchPrompt::SearchTextLC() |
|
73 { |
|
74 HBufC* buf = iEdwin->GetTextInHBufL(); |
|
75 CleanupStack::PushL(buf); |
|
76 return buf; |
|
77 } |
|
78 |
|
79 // |
|
80 // |
|
81 // |
|
82 |
|
83 void CHlpSearchPrompt::MakeVisible(TBool aVisible) |
|
84 { |
|
85 CCoeControl::MakeVisible(aVisible); |
|
86 if (!aVisible) |
|
87 { |
|
88 iHideTimer->Cancel(); |
|
89 ResetSearchL(); // Leaves if not visible |
|
90 } |
|
91 } |
|
92 |
|
93 void CHlpSearchPrompt::SizeChanged() |
|
94 { |
|
95 iEdwin->SetRect(Rect()); |
|
96 } |
|
97 |
|
98 TInt CHlpSearchPrompt::CountComponentControls() const |
|
99 { |
|
100 return 1; |
|
101 } |
|
102 |
|
103 CCoeControl* CHlpSearchPrompt::ComponentControl(TInt/* aIndex*/) const |
|
104 { |
|
105 return iEdwin; |
|
106 } |
|
107 |
|
108 TKeyResponse CHlpSearchPrompt::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) |
|
109 { |
|
110 if (aKeyEvent.iCode == EKeyEnter && aType == EEventKey) |
|
111 { |
|
112 ReportEventL(EEventStateChanged); |
|
113 return EKeyWasConsumed; |
|
114 } |
|
115 else if (aKeyEvent.iCode == EKeyEscape && aType == EEventKey) |
|
116 { |
|
117 MakeVisible(EFalse); |
|
118 return EKeyWasConsumed; |
|
119 } |
|
120 else |
|
121 { |
|
122 iHideTimer->Cancel(); |
|
123 iHideTimer->Start(KTimeOutPeriod, KTimeOutPeriod, TCallBack(HandleTimerExpiredL, this)); |
|
124 return iEdwin->OfferKeyEventL(aKeyEvent, aType); |
|
125 } |
|
126 } |
|
127 |
|
128 // |
|
129 // |
|
130 // |
|
131 |
|
132 void CHlpSearchPrompt::HandleControlEventL(CCoeControl* /*aControl*/, TCoeEvent /*aEventType*/) |
|
133 { |
|
134 } |
|
135 |
|
136 // |
|
137 // |
|
138 // |
|
139 |
|
140 TInt CHlpSearchPrompt::HandleTimerExpiredL(TAny* aSelf) |
|
141 { |
|
142 CHlpSearchPrompt* self = STATIC_CAST(CHlpSearchPrompt*, aSelf); |
|
143 self->MakeVisible(EFalse); |
|
144 return EFalse; // one shot |
|
145 } |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 // |
|
156 // ----> CHlpListBox (source) |
|
157 // |
|
158 |
|
159 CHlpListBox::CHlpListBox() |
|
160 { |
|
161 } |
|
162 |
|
163 CHlpListBox::~CHlpListBox() |
|
164 { |
|
165 delete iContent; |
|
166 delete iButton; |
|
167 delete iListBox; |
|
168 } |
|
169 |
|
170 void CHlpListBox::ConstructL(CCoeControl& aParent) |
|
171 { |
|
172 SetContainerWindowL(aParent); |
|
173 |
|
174 iButton = new(ELeave) CEikCommandButton(); |
|
175 iButton->SetContainerWindowL(*this); |
|
176 iButton->SetTextL(KDoneCaption); |
|
177 iButton->SetObserver(this); |
|
178 |
|
179 iListBox = new(ELeave) CEikTextListBox(); |
|
180 iListBox->ConstructL(this, CEikListBox::ENoExtendedSelection); |
|
181 iListBox->CreateScrollBarFrameL()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
182 iListBox->SetObserver(this); |
|
183 } |
|
184 |
|
185 // |
|
186 // FROM CCoeControl |
|
187 // |
|
188 |
|
189 void CHlpListBox::SizeChanged() |
|
190 { |
|
191 TRect rect(Rect()); |
|
192 TSize size(rect.Size()); |
|
193 const TInt KButtonHeight = iButton->MinimumSize().iHeight; |
|
194 iButton->SetExtent(rect.iTl, TSize(size.iWidth, KButtonHeight)); |
|
195 rect.iTl.iY += KButtonHeight; |
|
196 iListBox->SetRect(rect); |
|
197 } |
|
198 |
|
199 TInt CHlpListBox::CountComponentControls() const |
|
200 { |
|
201 return 2; |
|
202 } |
|
203 |
|
204 CCoeControl* CHlpListBox::ComponentControl(TInt aIndex) const |
|
205 { |
|
206 if (!aIndex) |
|
207 return iListBox; |
|
208 return iButton; |
|
209 } |
|
210 |
|
211 TKeyResponse CHlpListBox::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) |
|
212 { |
|
213 return iListBox->OfferKeyEventL(aKeyEvent, aType); |
|
214 } |
|
215 |
|
216 TSize CHlpListBox::MinimumSize() |
|
217 { |
|
218 return iButton->MinimumSize(); |
|
219 } |
|
220 |
|
221 // |
|
222 // NEW |
|
223 // |
|
224 |
|
225 const CHlpItem& CHlpListBox::HelpItemL() const |
|
226 { |
|
227 TInt index = iListBox->CurrentItemIndex(); |
|
228 if (!iContent || index >= iContent->MdcaCount()) |
|
229 User::Leave(KErrNotFound); |
|
230 |
|
231 // Return the topic id of the topic that the user is interested in |
|
232 return *iContent->Item(index); |
|
233 } |
|
234 |
|
235 void CHlpListBox::PopulateListBoxL(CHlpList* aContent) |
|
236 { |
|
237 SetContent(aContent); |
|
238 |
|
239 CDesCArray* itemArray = STATIC_CAST(CDesCArray*, iListBox->Model()->ItemTextArray()); |
|
240 itemArray->Reset(); |
|
241 |
|
242 const TInt count = iContent->MdcaCount(); |
|
243 for(TInt i=0; i<count; i++) |
|
244 { |
|
245 itemArray->AppendL(iContent->MdcaPoint(i)); |
|
246 } |
|
247 |
|
248 iListBox->HandleItemAdditionL(); |
|
249 iListBox->SetCurrentItemIndex(0); // first item |
|
250 } |
|
251 |
|
252 // |
|
253 // FROM MCoeControlObserver |
|
254 // |
|
255 |
|
256 void CHlpListBox::HandleControlEventL(CCoeControl* aControl, TCoeEvent aEventType) |
|
257 { |
|
258 if (aControl == iButton) |
|
259 ReportEventL(EEventRequestExit); |
|
260 else if (aControl == iListBox) |
|
261 ReportEventL(aEventType); |
|
262 } |
|
263 |
|
264 |
|
265 // |
|
266 // INTERNAL |
|
267 // |
|
268 |
|
269 void CHlpListBox::SetContent(CHlpList* aContent) |
|
270 { |
|
271 delete iContent; |
|
272 iContent = aContent; |
|
273 } |