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