author | teknolog |
Thu, 11 Mar 2010 21:45:01 +0000 | |
changeset 48 | f8fd68d71cfd |
parent 33 | 64ed1227e68d |
child 49 | 43e204e6ae2e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB |
|
3 |
* |
|
4 |
* All rights reserved. |
|
5 |
* This component and the accompanying materials are made available |
|
6 |
* under the terms of the License "Eclipse Public License v1.0" |
|
7 |
* which accompanies this distribution, and is available |
|
8 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 |
* |
|
10 |
* Initial Contributors: |
|
11 |
* EmbedDev AB - initial contribution. |
|
12 |
* |
|
13 |
* Contributors: |
|
14 |
* |
|
15 |
* Description: |
|
16 |
* |
|
17 |
*/ |
|
18 |
||
19 |
#include "PodcastListView.h" |
|
20 |
#include "Podcast.hrh" |
|
21 |
#include "PodcastAppUi.h" |
|
22 |
#include "constants.h" |
|
23 |
#include <podcast.rsg> |
|
24 |
#include <aknlists.h> |
|
25 |
#include <aknviewappui.h> |
|
26 |
#include <aknnotedialog.h> |
|
27 |
#include <aknsbasicbackgroundcontrolcontext.h> |
|
28 |
#include <akntabgrp.h> |
|
29 |
#include <akntoolbarextension.h> |
|
30 |
#include <aknquerydialog.h> |
|
31 |
#include <barsread.h> |
|
32 |
||
33 |
const TInt KDefaultGran = 5; |
|
34 |
||
35 |
CPodcastListContainer::CPodcastListContainer() |
|
36 |
{ |
|
37 |
} |
|
38 |
||
39 |
void CPodcastListContainer::SetKeyEventListener(MKeyEventListener *aKeyEventListener) |
|
40 |
{ |
|
41 |
iKeyEventListener = aKeyEventListener; |
|
42 |
} |
|
43 |
||
44 |
TKeyResponse CPodcastListContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
45 |
{ |
|
46 |
TKeyResponse response = iListbox->OfferKeyEventL(aKeyEvent, aType); |
|
47 |
if (iKeyEventListener) |
|
48 |
iKeyEventListener->OfferKeyEventL(aKeyEvent, aType); |
|
49 |
||
50 |
return response; |
|
51 |
} |
|
52 |
||
53 |
void CPodcastListContainer::ConstructL( const TRect& aRect, TInt aListboxFlags ) |
|
54 |
{ |
|
55 |
CreateWindowL(); |
|
56 |
||
57 |
iBgContext = |
|
58 |
CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain, |
|
59 |
aRect, |
|
60 |
ETrue ); |
|
61 |
||
62 |
// Set the windows size |
|
63 |
SetRect( aRect ); |
|
64 |
iListbox =static_cast<CEikFormattedCellListBox*>( new (ELeave) CAknDoubleLargeStyleListBox); |
|
65 |
iListbox->ConstructL(this, aListboxFlags); |
|
66 |
iListbox->SetMopParent( this ); |
|
67 |
iListbox->SetContainerWindowL(*this); |
|
68 |
iListbox->CreateScrollBarFrameL(ETrue); |
|
69 |
iListbox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto ); |
|
70 |
||
71 |
iListbox->ItemDrawer()->FormattedCellData()->EnableMarqueeL( ETrue ); |
|
72 |
||
73 |
iListbox->SetSize(aRect.Size()); |
|
74 |
iListbox->MakeVisible(ETrue); |
|
75 |
MakeVisible(EFalse); |
|
23
cf4b850bbffb
Added macro SYMBIAN1_UI that toggles between single and double tap UI
teknolog
parents:
13
diff
changeset
|
76 |
|
cf4b850bbffb
Added macro SYMBIAN1_UI that toggles between single and double tap UI
teknolog
parents:
13
diff
changeset
|
77 |
//#ifndef SYMBIAN1_UI |
cf4b850bbffb
Added macro SYMBIAN1_UI that toggles between single and double tap UI
teknolog
parents:
13
diff
changeset
|
78 |
// TInt flags = iListbox->View()->ItemDrawer()->Flags(); |
cf4b850bbffb
Added macro SYMBIAN1_UI that toggles between single and double tap UI
teknolog
parents:
13
diff
changeset
|
79 |
// flags |= CListItemDrawer::EDisableHighlight; |
cf4b850bbffb
Added macro SYMBIAN1_UI that toggles between single and double tap UI
teknolog
parents:
13
diff
changeset
|
80 |
// iListbox->ItemDrawer()->SetFlags(flags); |
cf4b850bbffb
Added macro SYMBIAN1_UI that toggles between single and double tap UI
teknolog
parents:
13
diff
changeset
|
81 |
//#endif |
2 | 82 |
|
83 |
// Activate the window, which makes it ready to be drawn |
|
84 |
ActivateL(); |
|
85 |
} |
|
86 |
||
87 |
TInt CPodcastListContainer::CountComponentControls() const |
|
88 |
{ |
|
89 |
return 1; // return number of controls inside this container |
|
90 |
} |
|
91 |
||
92 |
CCoeControl* CPodcastListContainer::ComponentControl(TInt aIndex) const |
|
93 |
{ |
|
94 |
switch ( aIndex ) |
|
95 |
{ |
|
96 |
case 0: |
|
97 |
return iListbox; |
|
98 |
default: |
|
99 |
return NULL; |
|
100 |
} |
|
101 |
} |
|
102 |
||
26 | 103 |
void CPodcastListContainer::SetLongTapDetected(TBool aLongTapDetected) |
104 |
{ |
|
105 |
iLongTapDetected = aLongTapDetected; |
|
27 | 106 |
|
107 |
if (aLongTapDetected == EFalse) |
|
108 |
{ |
|
109 |
TPointerEvent event; |
|
110 |
event.iType = TPointerEvent::EButton1Up; |
|
111 |
CCoeControl::HandlePointerEventL(event); |
|
112 |
} |
|
26 | 113 |
} |
114 |
||
2 | 115 |
void CPodcastListContainer::HandleResourceChange(TInt aType) |
116 |
{ |
|
117 |
switch( aType ) |
|
118 |
{ |
|
119 |
case KEikDynamicLayoutVariantSwitch: |
|
120 |
SetRect(iEikonEnv->EikAppUi()->ClientRect()); |
|
121 |
break; |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
void CPodcastListContainer::ScrollToVisible() { |
|
126 |
if (iListbox != NULL) { |
|
127 |
iListbox->ScrollToMakeItemVisible(iListbox->CurrentItemIndex()); |
|
128 |
} |
|
129 |
} |
|
130 |
void CPodcastListContainer::SizeChanged() |
|
131 |
{ |
|
132 |
DP2("CPodcastListContainer::SizeChanged(), width=%d, height=%d",Size().iWidth, Size().iHeight); |
|
133 |
if(iListbox != NULL) |
|
134 |
{ |
|
135 |
iListbox->SetSize(Size()); |
|
136 |
} |
|
137 |
} |
|
138 |
||
139 |
CEikFormattedCellListBox* CPodcastListContainer::Listbox() |
|
140 |
{ |
|
141 |
return iListbox; |
|
142 |
} |
|
143 |
||
144 |
||
145 |
CPodcastListContainer::~CPodcastListContainer() |
|
146 |
{ |
|
147 |
delete iListbox; |
|
148 |
delete iBgContext; |
|
149 |
} |
|
150 |
||
151 |
||
152 |
void CPodcastListContainer::Draw(const TRect& aRect) const |
|
153 |
{ |
|
154 |
CWindowGc& gc = SystemGc(); |
|
155 |
gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
156 |
MAknsControlContext* cc = AknsDrawUtils::ControlContext(this); |
|
157 |
MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
158 |
AknsDrawUtils::Background(skin, cc, (CCoeControl*) this, gc, aRect); |
|
159 |
} |
|
160 |
||
161 |
||
162 |
TTypeUid::Ptr CPodcastListContainer::MopSupplyObject( TTypeUid aId ) |
|
163 |
{ |
|
164 |
if (iBgContext ) |
|
165 |
{ |
|
166 |
return MAknsControlContext::SupplyMopObject( aId, iBgContext ); |
|
167 |
} |
|
168 |
return CCoeControl::MopSupplyObject(aId); |
|
169 |
} |
|
170 |
||
171 |
void CPodcastListContainer::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
172 |
{ |
|
173 |
if (iPointerListener) |
|
174 |
iPointerListener->PointerEventL(aPointerEvent); |
|
175 |
||
26 | 176 |
// Call base class HandlePointerEventL() if not a long tap |
177 |
if (!iLongTapDetected) |
|
178 |
{ |
|
179 |
CCoeControl::HandlePointerEventL(aPointerEvent); |
|
180 |
} |
|
2 | 181 |
} |
182 |
||
183 |
||
184 |
void CPodcastListContainer::SetPointerListener(MPointerListener *aPointerListener) |
|
185 |
{ |
|
186 |
iPointerListener = aPointerListener; |
|
187 |
} |
|
188 |
||
189 |
||
190 |
CPodcastListView::CPodcastListView() |
|
191 |
{ |
|
192 |
} |
|
193 |
||
194 |
void CPodcastListView::ConstructL() |
|
195 |
{ |
|
196 |
DP("CPodcastListView::ConstructL BEGIN"); |
|
197 |
iListContainer = new (ELeave) CPodcastListContainer; |
|
198 |
iListContainer->ConstructL(ClientRect(), iListboxFlags); |
|
199 |
iListContainer->SetMopParent(this); |
|
200 |
iListContainer->ActivateL(); |
|
201 |
iItemArray = new (ELeave)CDesCArrayFlat(KDefaultGran); |
|
202 |
iListContainer->Listbox()->Model()->SetItemTextArray(iItemArray); |
|
203 |
iListContainer->Listbox()->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray); |
|
204 |
||
205 |
if (Toolbar()) { |
|
206 |
iToolbar = Toolbar(); |
|
207 |
iToolbar->SetToolbarObserver(this); |
|
208 |
} |
|
209 |
||
210 |
iLongTapDetector = CAknLongTapDetector::NewL(this); |
|
211 |
iListContainer->SetPointerListener(this); |
|
212 |
iListContainer->SetKeyEventListener(this); |
|
23
cf4b850bbffb
Added macro SYMBIAN1_UI that toggles between single and double tap UI
teknolog
parents:
13
diff
changeset
|
213 |
|
2 | 214 |
DP("CPodcastListView::ConstructL END"); |
215 |
} |
|
216 |
||
217 |
void CPodcastListView::HandleViewRectChange() |
|
218 |
{ |
|
219 |
if ( iListContainer ) |
|
220 |
{ |
|
221 |
iListContainer->SetRect( ClientRect() ); |
|
222 |
} |
|
223 |
} |
|
224 |
||
225 |
void CPodcastListView::HandleStatusPaneSizeChange() |
|
226 |
{ |
|
227 |
DP2("CPodcastListView::HandleStatusPaneSizeChange(), width=%d, height=%d", ClientRect().Width(), ClientRect().Height()); |
|
228 |
||
229 |
if ( iListContainer ) |
|
230 |
{ |
|
231 |
iListContainer->SetRect( ClientRect() ); |
|
232 |
} |
|
233 |
||
234 |
} |
|
235 |
||
236 |
||
237 |
CPodcastListView::~CPodcastListView() |
|
238 |
{ |
|
239 |
if(iListContainer) |
|
240 |
{ |
|
241 |
AppUi()->RemoveFromStack(iListContainer); |
|
242 |
delete iListContainer; |
|
243 |
} |
|
244 |
||
245 |
delete iItemArray; |
|
246 |
delete iLongTapDetector; |
|
247 |
iItemIdArray.Close(); |
|
248 |
} |
|
249 |
||
250 |
||
251 |
void CPodcastListView::DoActivateL(const TVwsViewId& /*aPrevViewId */, |
|
252 |
TUid /*aCustomMessageId */, |
|
253 |
const TDesC8& /* aCustomMessage */) |
|
254 |
{ |
|
255 |
DP("CPodcastListView::DoActivateL() BEGIN"); |
|
256 |
||
257 |
if(iListContainer) |
|
258 |
{ |
|
259 |
iListContainer->SetSize(ClientRect().Size()); |
|
260 |
iListContainer->SetMopParent(this); |
|
261 |
||
262 |
AppUi()->AddToStackL(*this, iListContainer); |
|
263 |
iListContainer->MakeVisible(ETrue); |
|
264 |
} |
|
265 |
DP("CPodcastListView::DoActivateL() END"); |
|
266 |
||
267 |
} |
|
268 |
||
269 |
void CPodcastListView::DoDeactivate() |
|
270 |
{ |
|
271 |
DP("CPodcastListView::DoDeactivate() BEGIN"); |
|
272 |
if ( iListContainer ) |
|
273 |
{ |
|
274 |
AppUi()->RemoveFromViewStack( *this, iListContainer); |
|
275 |
iListContainer->MakeVisible(EFalse); |
|
276 |
} |
|
277 |
DP("CPodcastListView::DoDeactivate() END"); |
|
278 |
} |
|
279 |
||
280 |
/** |
|
281 |
* Command handling function intended for overriding by sub classes. |
|
282 |
* Default implementation is empty. |
|
283 |
* @param aCommand ID of the command to respond to. |
|
284 |
*/ |
|
285 |
void CPodcastListView::HandleCommandL(TInt aCommand) |
|
286 |
{ |
|
287 |
DP1("CPodcastListView::HandleCommandL=%d", aCommand); |
|
288 |
switch(aCommand) |
|
289 |
{ |
|
290 |
case EAknSoftkeyExit: |
|
291 |
case EEikCmdExit: |
|
292 |
{ |
|
293 |
AppUi()->Exit(); |
|
294 |
break; |
|
295 |
} |
|
296 |
case EAknSoftkeyBack: |
|
297 |
{ |
|
298 |
AppUi()->ActivateViewL(iPreviousView); |
|
299 |
if (iPreviousView.iViewUid == KUidPodcastFeedViewID) { |
|
300 |
((CPodcastAppUi*)AppUi())->SetActiveTab(KTabIdFeeds); |
|
301 |
} |
|
302 |
}break; |
|
303 |
case EPodcastSettings: |
|
304 |
AppUi()->ActivateLocalViewL(KUidPodcastSettingsViewID); |
|
305 |
break; |
|
306 |
case EPodcastAbout: |
|
307 |
RunAboutDialogL(); |
|
308 |
break; |
|
309 |
default: |
|
310 |
AppUi()->HandleCommandL(aCommand); |
|
311 |
} |
|
312 |
} |
|
313 |
||
48 | 314 |
TBool CPodcastListView::IsVisible() |
315 |
{ |
|
316 |
return iListContainer->IsVisible(); |
|
317 |
} |
|
2 | 318 |
|
319 |
void CPodcastListView::RunAboutDialogL() |
|
320 |
{ |
|
321 |
CAknNoteDialog* dlg = new(ELeave) CAknNoteDialog(); |
|
322 |
dlg->ExecuteLD(R_DLG_ABOUT); |
|
323 |
} |
|
324 |
||
325 |
void CPodcastListView::SetEmptyTextL(TInt aResourceId) |
|
326 |
{ |
|
327 |
HBufC* emptyText = iEikonEnv->AllocReadResourceLC(aResourceId); |
|
328 |
iListContainer->Listbox()->View()->SetListEmptyTextL(*emptyText); |
|
329 |
CleanupStack::PopAndDestroy(emptyText); |
|
330 |
} |
|
331 |
||
332 |
void CPodcastListView::ShowOkMessage(TDesC &aText) |
|
333 |
{ |
|
334 |
CAknNoteDialog* dlg= new(ELeave) CAknNoteDialog(); |
|
335 |
CleanupStack::PushL(dlg); |
|
336 |
dlg->SetTextL(aText); |
|
337 |
CleanupStack::Pop(dlg); |
|
338 |
dlg->ExecuteLD(R_MESSAGEDLG_OK); |
|
339 |
} |
|
340 |
||
341 |
void CPodcastListView::ShowErrorMessage(TDesC &aText) |
|
342 |
{ |
|
343 |
CAknNoteDialog* dlg= new(ELeave) CAknNoteDialog(); |
|
344 |
CleanupStack::PushL(dlg); |
|
345 |
dlg->SetTextL(aText); |
|
346 |
CleanupStack::Pop(dlg); |
|
347 |
dlg->ExecuteLD(R_ERRORDLG_OK); |
|
348 |
} |
|
349 |
||
350 |
TInt CPodcastListView::ShowQueryMessage(TDesC &aText) |
|
351 |
{ |
|
352 |
CAknQueryDialog* dlg= new(ELeave) CAknQueryDialog(); |
|
353 |
||
354 |
CleanupStack::PushL(dlg); |
|
355 |
dlg->SetPromptL(aText); |
|
356 |
CleanupStack::Pop(dlg); |
|
357 |
return dlg->ExecuteLD(R_QUERYDLG); |
|
358 |
} |
|
359 |
||
360 |
void CPodcastListView::CloseToolbarExtension() |
|
361 |
{ |
|
362 |
CAknToolbar* toolbar = Toolbar(); |
|
363 |
if (toolbar) { |
|
364 |
CAknToolbarExtension* toolbarExtension = toolbar->ToolbarExtension(); |
|
365 |
if (toolbarExtension) { |
|
366 |
toolbarExtension->SetShown( EFalse ); |
|
367 |
} |
|
368 |
} |
|
369 |
} |
|
370 |
||
371 |
void CPodcastListView::PointerEventL(const TPointerEvent& aPointerEvent) |
|
372 |
{ |
|
373 |
//DP1("CPodcastListView::PointerEventL, iType=%d", aPointerEvent.iType); |
|
374 |
// Pass the pointer event to Long tap detector component |
|
375 |
iLongTapDetector->PointerEventL(aPointerEvent); |
|
376 |
} |
|
377 |
||
378 |
||
379 |
void CPodcastListView::HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& /* aPenEventScreenLocation */) |
|
380 |
{ |
|
381 |
DP("CPodcastListView::HandleLongTapEventL BEGIN"); |
|
26 | 382 |
iListContainer->SetLongTapDetected(ETrue); |
4
be243543a361
Added primitive detection if long tap is on a listbox item or not. Could use a better version of this going forward.
teknolog
parents:
2
diff
changeset
|
383 |
const TInt KListboxDefaultHeight = 19; // for some reason it returns 19 for an empty listbox in S^1 |
be243543a361
Added primitive detection if long tap is on a listbox item or not. Could use a better version of this going forward.
teknolog
parents:
2
diff
changeset
|
384 |
TInt lbHeight = iListContainer->Listbox()->CalcHeightBasedOnNumOfItems( |
be243543a361
Added primitive detection if long tap is on a listbox item or not. Could use a better version of this going forward.
teknolog
parents:
2
diff
changeset
|
385 |
iListContainer->Listbox()->Model()->NumberOfItems()) - KListboxDefaultHeight; |
be243543a361
Added primitive detection if long tap is on a listbox item or not. Could use a better version of this going forward.
teknolog
parents:
2
diff
changeset
|
386 |
|
be243543a361
Added primitive detection if long tap is on a listbox item or not. Could use a better version of this going forward.
teknolog
parents:
2
diff
changeset
|
387 |
if(iStylusPopupMenu && aPenEventLocation.iY < lbHeight) |
2 | 388 |
{ |
389 |
iStylusPopupMenu->ShowMenu(); |
|
390 |
iStylusPopupMenu->SetPosition(aPenEventLocation); |
|
391 |
} |
|
392 |
DP("CPodcastListView::HandleLongTapEventL END"); |
|
393 |
} |
|
394 |
||
395 |
||
396 |
void CPodcastListView::DynInitToolbarL (TInt /*aResourceId*/, CAknToolbar * /*aToolbar*/) |
|
397 |
{ |
|
398 |
} |
|
399 |
||
400 |
||
401 |
void CPodcastListView::OfferToolbarEventL(TInt aCommand) |
|
402 |
{ |
|
403 |
HandleCommandL(aCommand); |
|
404 |
} |
|
405 |
||
406 |
void CPodcastListView::ShowWaitDialogL(TDesC &aWaitText) |
|
407 |
{ |
|
408 |
DP("CPodcastListView::ShowWaitDialogL BEGIN"); |
|
409 |
||
410 |
if (iWaitDialog) { |
|
411 |
User::Leave(KErrInUse); |
|
412 |
} |
|
413 |
||
414 |
iWaitDialog=new(ELeave) CAknWaitDialog(reinterpret_cast<CEikDialog**>(&iWaitDialog), EFalse); |
|
415 |
iWaitDialog->SetCallback(this); |
|
416 |
iWaitDialog->ExecuteLD(R_WAITDLG); |
|
417 |
iWaitDialog->SetTextL(aWaitText); |
|
418 |
DP("CPodcastListView::ShowWaitDialogL END"); |
|
419 |
} |
|
420 |
||
421 |
TKeyResponse CPodcastListView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
422 |
{ |
|
423 |
if (aType==EEventKey) |
|
424 |
{ |
|
425 |
switch (aKeyEvent.iCode) |
|
426 |
{ |
|
427 |
case EKeyRightArrow: |
|
428 |
((CPodcastAppUi*)AppUi())->TabRight(); |
|
429 |
return EKeyWasConsumed; |
|
430 |
case EKeyLeftArrow: |
|
431 |
((CPodcastAppUi*)AppUi())->TabLeft(); |
|
432 |
return EKeyWasConsumed; |
|
433 |
} |
|
434 |
} |
|
435 |
return EKeyWasNotConsumed; |
|
436 |
} |
|
437 |