| author | teknolog | 
| Sun, 28 Feb 2010 21:19:40 +0000 | |
| changeset 26 | 71493655568a | 
| parent 24 | ca50ea154990 | 
| child 27 | f21a29fc4769 | 
| 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: 
13diff
changeset | 76 | |
| 
cf4b850bbffb
Added macro SYMBIAN1_UI that toggles between single and double tap UI
 teknolog parents: 
13diff
changeset | 77 | //#ifndef SYMBIAN1_UI | 
| 
cf4b850bbffb
Added macro SYMBIAN1_UI that toggles between single and double tap UI
 teknolog parents: 
13diff
changeset | 78 | // TInt flags = iListbox->View()->ItemDrawer()->Flags(); | 
| 
cf4b850bbffb
Added macro SYMBIAN1_UI that toggles between single and double tap UI
 teknolog parents: 
13diff
changeset | 79 | // flags |= CListItemDrawer::EDisableHighlight; | 
| 
cf4b850bbffb
Added macro SYMBIAN1_UI that toggles between single and double tap UI
 teknolog parents: 
13diff
changeset | 80 | // iListbox->ItemDrawer()->SetFlags(flags); | 
| 
cf4b850bbffb
Added macro SYMBIAN1_UI that toggles between single and double tap UI
 teknolog parents: 
13diff
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; | |
| 106 | } | |
| 107 | ||
| 2 | 108 | void CPodcastListContainer::HandleResourceChange(TInt aType) | 
| 109 | {
 | |
| 110 | switch( aType ) | |
| 111 |     	{
 | |
| 112 | case KEikDynamicLayoutVariantSwitch: | |
| 113 | SetRect(iEikonEnv->EikAppUi()->ClientRect()); | |
| 114 | break; | |
| 115 | } | |
| 116 | } | |
| 117 | ||
| 118 | void CPodcastListContainer::ScrollToVisible() {
 | |
| 119 | 	if (iListbox != NULL) {
 | |
| 120 | iListbox->ScrollToMakeItemVisible(iListbox->CurrentItemIndex()); | |
| 121 | } | |
| 122 | } | |
| 123 | void CPodcastListContainer::SizeChanged() | |
| 124 | {
 | |
| 125 | 	DP2("CPodcastListContainer::SizeChanged(), width=%d, height=%d",Size().iWidth, Size().iHeight);
 | |
| 126 | if(iListbox != NULL) | |
| 127 | 	{
 | |
| 128 | iListbox->SetSize(Size()); | |
| 129 | } | |
| 130 | } | |
| 131 | ||
| 132 | CEikFormattedCellListBox* CPodcastListContainer::Listbox() | |
| 133 | {
 | |
| 134 | return iListbox; | |
| 135 | } | |
| 136 | ||
| 137 | ||
| 138 | CPodcastListContainer::~CPodcastListContainer() | |
| 139 | {
 | |
| 140 | delete iListbox; | |
| 141 | delete iBgContext; | |
| 142 | } | |
| 143 | ||
| 144 | ||
| 145 | void CPodcastListContainer::Draw(const TRect& aRect) const | |
| 146 | 	{
 | |
| 147 | CWindowGc& gc = SystemGc(); | |
| 148 | gc.SetBrushStyle(CGraphicsContext::ESolidBrush); | |
| 149 | MAknsControlContext* cc = AknsDrawUtils::ControlContext(this); | |
| 150 | MAknsSkinInstance* skin = AknsUtils::SkinInstance(); | |
| 151 | AknsDrawUtils::Background(skin, cc, (CCoeControl*) this, gc, aRect); | |
| 152 | } | |
| 153 | ||
| 154 | ||
| 155 | TTypeUid::Ptr CPodcastListContainer::MopSupplyObject( TTypeUid aId ) | |
| 156 |     {
 | |
| 157 | if (iBgContext ) | |
| 158 |     {
 | |
| 159 | return MAknsControlContext::SupplyMopObject( aId, iBgContext ); | |
| 160 | } | |
| 161 | return CCoeControl::MopSupplyObject(aId); | |
| 162 | } | |
| 163 | ||
| 164 | void CPodcastListContainer::HandlePointerEventL(const TPointerEvent& aPointerEvent) | |
| 165 | 	{
 | |
| 166 | if (iPointerListener) | |
| 167 | iPointerListener->PointerEventL(aPointerEvent); | |
| 168 | ||
| 26 | 169 | // Call base class HandlePointerEventL() if not a long tap | 
| 170 | if (!iLongTapDetected) | |
| 171 | 		{
 | |
| 172 | CCoeControl::HandlePointerEventL(aPointerEvent); | |
| 173 | } | |
| 2 | 174 | } | 
| 175 | ||
| 176 | ||
| 177 | void CPodcastListContainer::SetPointerListener(MPointerListener *aPointerListener) | |
| 178 | 	{
 | |
| 179 | iPointerListener = aPointerListener; | |
| 180 | } | |
| 181 | ||
| 182 | ||
| 183 | CPodcastListView::CPodcastListView() | |
| 184 | {
 | |
| 185 | } | |
| 186 | ||
| 187 | void CPodcastListView::ConstructL() | |
| 188 | {
 | |
| 189 | 	DP("CPodcastListView::ConstructL BEGIN");
 | |
| 190 | iListContainer = new (ELeave) CPodcastListContainer; | |
| 191 | iListContainer->ConstructL(ClientRect(), iListboxFlags); | |
| 192 | iListContainer->SetMopParent(this); | |
| 193 | iListContainer->ActivateL(); | |
| 194 | iItemArray = new (ELeave)CDesCArrayFlat(KDefaultGran); | |
| 195 | iListContainer->Listbox()->Model()->SetItemTextArray(iItemArray); | |
| 196 | iListContainer->Listbox()->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray); | |
| 197 | ||
| 198 | 	if (Toolbar()) {
 | |
| 199 | iToolbar = Toolbar(); | |
| 200 | iToolbar->SetToolbarObserver(this); | |
| 201 | } | |
| 202 | ||
| 203 | iLongTapDetector = CAknLongTapDetector::NewL(this); | |
| 204 | iListContainer->SetPointerListener(this); | |
| 205 | iListContainer->SetKeyEventListener(this); | |
| 23 
cf4b850bbffb
Added macro SYMBIAN1_UI that toggles between single and double tap UI
 teknolog parents: 
13diff
changeset | 206 | |
| 2 | 207 | 	DP("CPodcastListView::ConstructL END");
 | 
| 208 | } | |
| 209 | ||
| 210 | void CPodcastListView::HandleViewRectChange() | |
| 211 | {
 | |
| 212 | if ( iListContainer ) | |
| 213 | 	{
 | |
| 214 | iListContainer->SetRect( ClientRect() ); | |
| 215 | } | |
| 216 | } | |
| 217 | ||
| 218 | void CPodcastListView::HandleStatusPaneSizeChange() | |
| 219 | {
 | |
| 220 | 	DP2("CPodcastListView::HandleStatusPaneSizeChange(), width=%d, height=%d", ClientRect().Width(), ClientRect().Height());
 | |
| 221 | ||
| 222 | if ( iListContainer ) | |
| 223 | 	{
 | |
| 224 | iListContainer->SetRect( ClientRect() ); | |
| 225 | } | |
| 226 | ||
| 227 | } | |
| 228 | ||
| 229 | ||
| 230 | CPodcastListView::~CPodcastListView() | |
| 231 |     {
 | |
| 232 | if(iListContainer) | |
| 233 |     	{
 | |
| 234 | AppUi()->RemoveFromStack(iListContainer); | |
| 235 | delete iListContainer; | |
| 236 | } | |
| 237 | ||
| 238 | delete iItemArray; | |
| 239 | delete iLongTapDetector; | |
| 240 | iItemIdArray.Close(); | |
| 241 | } | |
| 242 | ||
| 243 | ||
| 244 | void CPodcastListView::DoActivateL(const TVwsViewId& /*aPrevViewId */, | |
| 245 | TUid /*aCustomMessageId */, | |
| 246 | const TDesC8& /* aCustomMessage */) | |
| 247 | {	
 | |
| 248 | 	DP("CPodcastListView::DoActivateL() BEGIN");
 | |
| 249 | ||
| 250 | if(iListContainer) | |
| 251 | 	{
 | |
| 252 | iListContainer->SetSize(ClientRect().Size()); | |
| 253 | iListContainer->SetMopParent(this); | |
| 254 | ||
| 255 | AppUi()->AddToStackL(*this, iListContainer); | |
| 256 | iListContainer->MakeVisible(ETrue); | |
| 257 | UpdateListboxItemsL(); | |
| 258 | iListContainer->DrawNow(); | |
| 259 | } | |
| 260 | 	DP("CPodcastListView::DoActivateL() END");
 | |
| 261 | ||
| 262 | } | |
| 263 | ||
| 264 | void CPodcastListView::DoDeactivate() | |
| 265 | {
 | |
| 266 | 	DP("CPodcastListView::DoDeactivate() BEGIN");
 | |
| 267 | if ( iListContainer ) | |
| 268 | 	{
 | |
| 269 | AppUi()->RemoveFromViewStack( *this, iListContainer); | |
| 270 | iListContainer->MakeVisible(EFalse); | |
| 271 | } | |
| 272 | 	DP("CPodcastListView::DoDeactivate() END");
 | |
| 273 | } | |
| 274 | ||
| 275 | /** | |
| 276 | * Command handling function intended for overriding by sub classes. | |
| 277 | * Default implementation is empty. | |
| 278 | * @param aCommand ID of the command to respond to. | |
| 279 | */ | |
| 280 | void CPodcastListView::HandleCommandL(TInt aCommand) | |
| 281 | {
 | |
| 282 | 	DP1("CPodcastListView::HandleCommandL=%d", aCommand);
 | |
| 283 | switch(aCommand) | |
| 284 | 	{
 | |
| 285 | case EAknSoftkeyExit: | |
| 286 | case EEikCmdExit: | |
| 287 | 		{
 | |
| 288 | AppUi()->Exit(); | |
| 289 | break; | |
| 290 | } | |
| 291 | case EAknSoftkeyBack: | |
| 292 | 		{
 | |
| 293 | AppUi()->ActivateViewL(iPreviousView); | |
| 294 | 		if (iPreviousView.iViewUid == KUidPodcastFeedViewID) {
 | |
| 295 | ((CPodcastAppUi*)AppUi())->SetActiveTab(KTabIdFeeds); | |
| 296 | } | |
| 297 | }break; | |
| 298 | case EPodcastSettings: | |
| 299 | AppUi()->ActivateLocalViewL(KUidPodcastSettingsViewID); | |
| 300 | break; | |
| 301 | case EPodcastAbout: | |
| 302 | RunAboutDialogL(); | |
| 303 | break; | |
| 304 | default: | |
| 305 | AppUi()->HandleCommandL(aCommand); | |
| 306 | } | |
| 307 | } | |
| 308 | ||
| 309 | ||
| 310 | void CPodcastListView::RunAboutDialogL() | |
| 311 | {
 | |
| 312 | CAknNoteDialog* dlg = new(ELeave) CAknNoteDialog(); | |
| 313 | dlg->ExecuteLD(R_DLG_ABOUT); | |
| 314 | } | |
| 315 | ||
| 316 | void CPodcastListView::SetEmptyTextL(TInt aResourceId) | |
| 317 | 	{
 | |
| 318 | HBufC* emptyText = iEikonEnv->AllocReadResourceLC(aResourceId); | |
| 319 | iListContainer->Listbox()->View()->SetListEmptyTextL(*emptyText); | |
| 320 | CleanupStack::PopAndDestroy(emptyText); | |
| 321 | } | |
| 322 | ||
| 323 | void CPodcastListView::ShowOkMessage(TDesC &aText) | |
| 324 | 	{
 | |
| 325 | CAknNoteDialog* dlg= new(ELeave) CAknNoteDialog(); | |
| 326 | CleanupStack::PushL(dlg); | |
| 327 | dlg->SetTextL(aText); | |
| 328 | CleanupStack::Pop(dlg); | |
| 329 | dlg->ExecuteLD(R_MESSAGEDLG_OK); | |
| 330 | } | |
| 331 | ||
| 332 | void CPodcastListView::ShowErrorMessage(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_ERRORDLG_OK); | |
| 339 | } | |
| 340 | ||
| 341 | TInt CPodcastListView::ShowQueryMessage(TDesC &aText) | |
| 342 | 	{
 | |
| 343 | CAknQueryDialog* dlg= new(ELeave) CAknQueryDialog(); | |
| 344 | ||
| 345 | CleanupStack::PushL(dlg); | |
| 346 | dlg->SetPromptL(aText); | |
| 347 | CleanupStack::Pop(dlg); | |
| 348 | return dlg->ExecuteLD(R_QUERYDLG); | |
| 349 | } | |
| 350 | ||
| 351 | void CPodcastListView::CloseToolbarExtension() | |
| 352 | {
 | |
| 353 | CAknToolbar* toolbar = Toolbar(); | |
| 354 | 	if (toolbar) {
 | |
| 355 | CAknToolbarExtension* toolbarExtension = toolbar->ToolbarExtension(); | |
| 356 | 		if (toolbarExtension) {
 | |
| 357 | toolbarExtension->SetShown( EFalse ); | |
| 358 | } | |
| 359 | } | |
| 360 | } | |
| 361 | ||
| 362 | void CPodcastListView::PointerEventL(const TPointerEvent& aPointerEvent) | |
| 363 | 	{
 | |
| 364 | 	//DP1("CPodcastListView::PointerEventL, iType=%d", aPointerEvent.iType);
 | |
| 365 | // Pass the pointer event to Long tap detector component | |
| 366 | iLongTapDetector->PointerEventL(aPointerEvent); | |
| 367 | } | |
| 368 | ||
| 369 | ||
| 370 | void CPodcastListView::HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& /* aPenEventScreenLocation */) | |
| 371 | {
 | |
| 372 | 	DP("CPodcastListView::HandleLongTapEventL BEGIN");
 | |
| 26 | 373 | 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: 
2diff
changeset | 374 | 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: 
2diff
changeset | 375 | 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: 
2diff
changeset | 376 | 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: 
2diff
changeset | 377 | |
| 
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: 
2diff
changeset | 378 | if(iStylusPopupMenu && aPenEventLocation.iY < lbHeight) | 
| 2 | 379 |     {
 | 
| 380 | iStylusPopupMenu->ShowMenu(); | |
| 381 | iStylusPopupMenu->SetPosition(aPenEventLocation); | |
| 382 | } | |
| 383 | 	DP("CPodcastListView::HandleLongTapEventL END");
 | |
| 384 | } | |
| 385 | ||
| 386 | ||
| 387 | void CPodcastListView::DynInitToolbarL (TInt /*aResourceId*/, CAknToolbar * /*aToolbar*/) | |
| 388 | 	{
 | |
| 389 | } | |
| 390 | ||
| 391 | ||
| 392 | void CPodcastListView::OfferToolbarEventL(TInt aCommand) | |
| 393 | 	{
 | |
| 394 | HandleCommandL(aCommand); | |
| 395 | } | |
| 396 | ||
| 397 | void CPodcastListView::ShowWaitDialogL(TDesC &aWaitText) | |
| 398 | 	{
 | |
| 399 | 	DP("CPodcastListView::ShowWaitDialogL BEGIN");
 | |
| 400 | ||
| 401 | 	if (iWaitDialog) {
 | |
| 402 | User::Leave(KErrInUse); | |
| 403 | } | |
| 404 | ||
| 405 | iWaitDialog=new(ELeave) CAknWaitDialog(reinterpret_cast<CEikDialog**>(&iWaitDialog), EFalse); | |
| 406 | iWaitDialog->SetCallback(this); | |
| 407 | iWaitDialog->ExecuteLD(R_WAITDLG); | |
| 408 | iWaitDialog->SetTextL(aWaitText); | |
| 409 | 	DP("CPodcastListView::ShowWaitDialogL END");
 | |
| 410 | } | |
| 411 | ||
| 412 | TKeyResponse CPodcastListView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) | |
| 413 | 	{
 | |
| 414 | if (aType==EEventKey) | |
| 415 | 		{
 | |
| 416 | switch (aKeyEvent.iCode) | |
| 417 | 			{
 | |
| 418 | case EKeyRightArrow: | |
| 419 | ((CPodcastAppUi*)AppUi())->TabRight(); | |
| 420 | return EKeyWasConsumed; | |
| 421 | case EKeyLeftArrow: | |
| 422 | ((CPodcastAppUi*)AppUi())->TabLeft(); | |
| 423 | return EKeyWasConsumed; | |
| 424 | } | |
| 425 | } | |
| 426 | return EKeyWasNotConsumed; | |
| 427 | } | |
| 428 |