usbuis/usbui/USBClassChangeUIPlugin/src/USBClassChangeUIPluginContainer.cpp
branchRCL_3
changeset 24 e02eb84a14d2
equal deleted inserted replaced
23:25fce757be94 24:e02eb84a14d2
       
     1 /*
       
     2 * Copyright (c) 2005-2009 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:  Container that contains the USB mode listbox
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <barsread.h>	// Resource reader
       
    21 
       
    22 #include <usbpersonalityids.h>
       
    23 #include <USBClassChangeUIPlugin.rsg> // Resources
       
    24 #include <csxhelp/usb.hlp.hrh>   // Help id
       
    25 #include <StringLoader.h>
       
    26 #include <AknIconArray.h>
       
    27 #include <eikmenub.h>
       
    28 #include <eikmobs.h>
       
    29 
       
    30 #include "USBClassChangeUIPlugin.h"
       
    31 #include "USBClassChangeUIPluginContainer.h"
       
    32 #include "USBClassChangeUIPluginModel.h"
       
    33 #include "USBClassChangeUIPluginView.h"
       
    34 #include "USBClassChangeUIPluginDebug.h"
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CUSBClassChangeUIPluginContainer::NewL
       
    38 // Two-phased constructor.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CUSBClassChangeUIPluginContainer*
       
    42 CUSBClassChangeUIPluginContainer::NewL(
       
    43     CUSBClassChangeUIPluginView* aView,
       
    44     CUSBClassChangeUIPluginModel* aModel)
       
    45     {
       
    46     FLOG(_L("[USBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer:NewL"));
       
    47     CUSBClassChangeUIPluginContainer* self 
       
    48         = new (ELeave) CUSBClassChangeUIPluginContainer(aView, aModel);
       
    49     CleanupStack::PushL(self);
       
    50     self->ConstructL();
       
    51     CleanupStack::Pop(self); 
       
    52     return self;
       
    53     }
       
    54 
       
    55 // ----------------------------------------------------------------------------
       
    56 // CUSBClassChangeUIPluginContainer::ConstructL(const TRect& aRect)
       
    57 // Symbian 2nd phase constructor can leave.
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 void CUSBClassChangeUIPluginContainer::ConstructL()
       
    61     { 
       
    62     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::ConstructL()"));
       
    63     
       
    64     CreateWindowL();
       
    65     iPopupController = CAknInfoPopupNoteController::NewL();
       
    66    
       
    67     iUSBAllItemsArray = new ( ELeave ) CDesCArrayFlat( 
       
    68         KUSBClassChangeUISupportedModesGranularity );
       
    69     iUSBAllItemsArrayDefault = new ( ELeave ) CDesCArrayFlat( 
       
    70             KUSBClassChangeUISupportedModesGranularity );
       
    71     iUSBAllItemsArrayActive = new ( ELeave ) CDesCArrayFlat( 
       
    72             KUSBClassChangeUISupportedModesGranularity );
       
    73     iPopUpItems = new ( ELeave ) CDesCArrayFlat( 
       
    74             KUSBClassChangeUISupportedModesGranularity );
       
    75     CArrayPtrFlat<CGulIcon>* iconArray = new(ELeave) CArrayPtrFlat<CGulIcon>(KUSBClassChangeUIIconGranularity);  
       
    76     CleanupStack::PushL( iconArray );
       
    77        
       
    78     // prepare the listbox items and the tooltip strings for the USB UI view
       
    79     iModelRef->SupportedUSBModeArraysL( *iUSBAllItemsArray, *iUSBAllItemsArrayDefault, *iUSBAllItemsArrayActive, *iPopUpItems, *iconArray);
       
    80 
       
    81     // Create DoubleLargeStyleListBox for USB UI view
       
    82     //
       
    83     iUSBMainListBox = new ( ELeave ) CAknDoubleLargeStyleListBox;
       
    84     iUSBMainListBox->SetContainerWindowL( *this );
       
    85     iUSBMainListBox->ConstructL( this, EAknListBoxMarkableList );
       
    86 
       
    87     // Set up scroll bar for the Listbox
       
    88     iUSBMainListBox->CreateScrollBarFrameL( ETrue );
       
    89     iUSBMainListBox->ScrollBarFrame()->SetScrollBarVisibilityL( 
       
    90         CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto );
       
    91     
       
    92     // As soon as the list is created the tooltip info of the first item in the list is shown
       
    93     
       
    94    
       
    95     //creating a handle to the icon array and passing its ownership to data object
       
    96     //no need to handle its deletion
       
    97     iUSBMainListBox->ItemDrawer()->FormattedCellData()->SetIconArray(iconArray);
       
    98     CleanupStack::Pop(iconArray);
       
    99     
       
   100     iUSBMainListBox->Model()->SetItemTextArray( this );
       
   101     iUSBMainListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   102 
       
   103     iUSBMainListBox->SetListBoxObserver( this );
       
   104 
       
   105     SetRect( iViewRef->ClientRect() );
       
   106    
       
   107     const RArray<TInt> usbIds = iModelRef->GetUsbIds();
       
   108     TInt currentMode = usbIds.Find(iViewRef->USBMode());
       
   109     ShowPopUpsL(currentMode);
       
   110     ActivateL();
       
   111     
       
   112     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::ConstructL complete"));
       
   113     }
       
   114 
       
   115 // ----------------------------------------------------------------------------
       
   116 // C++ default constructor can NOT contain any code, that
       
   117 // might leave.
       
   118 // ----------------------------------------------------------------------------
       
   119 //
       
   120 CUSBClassChangeUIPluginContainer::CUSBClassChangeUIPluginContainer( 
       
   121     CUSBClassChangeUIPluginView* aView,
       
   122     CUSBClassChangeUIPluginModel* aModel) :
       
   123     iViewRef(aView), iModelRef(aModel)
       
   124     {
       
   125     }
       
   126 
       
   127 // ----------------------------------------------------------------------------
       
   128 // Destructor
       
   129 // ----------------------------------------------------------------------------
       
   130 //
       
   131 CUSBClassChangeUIPluginContainer::~CUSBClassChangeUIPluginContainer()
       
   132     {
       
   133     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::Destructor"));
       
   134 
       
   135 	delete iUSBMainListBox;
       
   136 	
       
   137 	delete iUSBAllItemsArray;
       
   138 	delete iUSBAllItemsArrayDefault;
       
   139 	delete iUSBAllItemsArrayActive;
       
   140 	delete iPopUpItems;
       
   141 	
       
   142     delete iPopupController;
       
   143 	FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::Destructor complete"));
       
   144     }
       
   145 
       
   146 // ----------------------------------------------------------------------------
       
   147 // CUSBClassChangeUIPluginContainer::SizeChanged()
       
   148 // Called by framework when the view size is changed
       
   149 // ----------------------------------------------------------------------------
       
   150 //
       
   151 void CUSBClassChangeUIPluginContainer::SizeChanged()
       
   152     {
       
   153     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::SizeChangedL()"));
       
   154     
       
   155     iUSBMainListBox->SetRect( Rect() ); 
       
   156     iUSBMainListBox->SetFocus( ETrue );
       
   157     
       
   158     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::SizeChangedL complete"));
       
   159     }
       
   160 
       
   161 // ----------------------------------------------------------------------------
       
   162 // CUSBClassChangeUIPluginContainer::FocusChanged()
       
   163 // Called by framework when the focus is changed
       
   164 // ----------------------------------------------------------------------------
       
   165 //    
       
   166 void CUSBClassChangeUIPluginContainer::FocusChanged( TDrawNow /*aDranow*/ )
       
   167     {
       
   168     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::FocusChanged()"));
       
   169     if( iUSBMainListBox)
       
   170         {
       
   171         iUSBMainListBox->SetFocus( IsFocused() );
       
   172         }
       
   173     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::FocusChanged() complete"));    
       
   174     }
       
   175     
       
   176 // ----------------------------------------------------------------------------
       
   177 // CUSBClassChangeUIPluginContainer::CountComponentControls() const
       
   178 // Returns the number of controls inside this container
       
   179 // ----------------------------------------------------------------------------
       
   180 //
       
   181 TInt CUSBClassChangeUIPluginContainer::CountComponentControls() const
       
   182     {
       
   183     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::CountComponentControls()"));
       
   184     
       
   185     return KUSBClassChangeUIComponentCount; 
       
   186     }
       
   187 
       
   188 // ----------------------------------------------------------------------------
       
   189 // CUSBClassChangeUIPluginContainer::ComponentControl(TInt aIndex) const
       
   190 // Returns the control inside this container. Note that this function is
       
   191 // inherited from CCoeControl and thus must be const even it returns a pointer,
       
   192 // which can be used for modifying the class. 
       
   193 // ----------------------------------------------------------------------------
       
   194 //
       
   195 CCoeControl* CUSBClassChangeUIPluginContainer::ComponentControl( 
       
   196     TInt aIndex ) const
       
   197     {
       
   198     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::ComponentControl()"));
       
   199     
       
   200     switch ( aIndex )
       
   201         {
       
   202         case 0:
       
   203             {
       
   204             return iUSBMainListBox;
       
   205             }
       
   206         default:
       
   207             {
       
   208             return NULL;
       
   209             }            
       
   210         }
       
   211     }
       
   212 
       
   213 
       
   214 // ----------------------------------------------------------------------------
       
   215 // CUSBClassChangeUIPluginContainer::OfferKeyEventL
       
   216 // Redirects keypresses to the listbox
       
   217 // ----------------------------------------------------------------------------
       
   218 //
       
   219 TKeyResponse CUSBClassChangeUIPluginContainer::OfferKeyEventL(
       
   220     const TKeyEvent& aKeyEvent,TEventCode aType )
       
   221     {
       
   222     TInt maxItemcount = iModelRef->PersonalityCount();
       
   223     TInt maxIndex = maxItemcount-1;
       
   224     
       
   225     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::OfferKeyEventL()"));
       
   226     TBool isfocus =  iViewRef->MenuBar()->ItemSpecificCommandsEnabled();   
       
   227     if ( isfocus && aType == EEventKey && 
       
   228             (aKeyEvent.iCode == EKeyDownArrow || aKeyEvent.iCode == EKeyUpArrow) )
       
   229             {
       
   230             iCurrentItemIndex = iUSBMainListBox->CurrentItemIndex();
       
   231             if( aKeyEvent.iCode == EKeyDownArrow )
       
   232                 {
       
   233                 if( iCurrentItemIndex >= maxIndex )
       
   234                     {
       
   235                     iCurrentItemIndex = 0;
       
   236                     }
       
   237                 else
       
   238                     {
       
   239                     iCurrentItemIndex++;
       
   240                     }
       
   241                 }
       
   242             else // ( aKeyEvent.iCode == EKeyUpArrow )    
       
   243                 {
       
   244                 if( iCurrentItemIndex <= 0 )
       
   245                     {
       
   246                     iCurrentItemIndex = maxIndex;
       
   247                     }
       
   248                 else
       
   249                     {
       
   250                     iCurrentItemIndex--;
       
   251                     }
       
   252                 }
       
   253             ShowPopUpsL( iCurrentItemIndex );
       
   254             iCurrentItemIndex = iUSBMainListBox->CurrentItemIndex();
       
   255             }
       
   256 
       
   257    
       
   258           TKeyResponse res = iUSBMainListBox->OfferKeyEventL( aKeyEvent, aType );
       
   259            FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::OfferKeyEventL complete"));
       
   260 
       
   261           return res;
       
   262     }
       
   263 
       
   264 //------------------------------------------------------------------------------
       
   265 // CUSBClassChangeUIPluginContainer::showpopupsFinal(TInt &aValue)
       
   266 // Display the popups
       
   267 //------------------------------------------------------------------------------
       
   268 //
       
   269 void CUSBClassChangeUIPluginContainer::ShowPopUpsL(TInt aIndex)
       
   270     {
       
   271     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::ShowPopUpsL "));
       
   272     if ( aIndex >= 0 && aIndex < iPopUpItems->Count() )
       
   273         {
       
   274         iPopupController->SetTimePopupInView( KMaxVisibleTime);
       
   275         TPtrC chosen = iPopUpItems->MdcaPoint(aIndex);
       
   276         iPopupController->SetTextL( chosen );
       
   277         iPopupController->SetPositionByHighlight( TRect( 
       
   278                    iUSBMainListBox->View()->ItemPos( aIndex + 1 ), 
       
   279                    iUSBMainListBox->View()->ItemSize() ) );
       
   280         iPopupController->SetTimeDelayBeforeShow( KMsToWaitBeforePopup );
       
   281         iPopupController->ShowInfoPopupNote();
       
   282         }
       
   283     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::ShowPopUpsL complete"));
       
   284   
       
   285 }
       
   286 
       
   287 // ----------------------------------------------------------------------------
       
   288 // CUSBClassChangeUIPluginContainer::HandleListBoxEventL(
       
   289 //     CEikListBox* aListBox,TListBoxEvent aEventType)
       
   290 // Handle events from the ListBox
       
   291 // ----------------------------------------------------------------------------
       
   292 //    
       
   293 void CUSBClassChangeUIPluginContainer::HandleListBoxEventL(
       
   294     CEikListBox* /*aListBox*/,TListBoxEvent aEventType )
       
   295    {
       
   296    FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::HandleListBoxEventL()"));
       
   297    
       
   298     __ASSERT_DEBUG( iViewRef!=0, PANIC( EUSBUIPanicIllegalValue ) );
       
   299     
       
   300     //Selection key pressed, when MSK is not enabled. Or touch stylus 
       
   301     //double clicked.
       
   302     //
       
   303     if( AknLayoutUtils::PenEnabled() )
       
   304            {
       
   305            switch ( aEventType )
       
   306                {
       
   307                case EEventItemSingleClicked:
       
   308                    {
       
   309                    FLOG(_L("[CUSBClassChangeUIPlugin]\t HandleListBoxEventL()EEventItemSingleClicked"));
       
   310                    iViewRef->HandleCommandL( EUSBUICmdSelect );
       
   311                    break;
       
   312                    }
       
   313                case EEventPenDownOnItem:
       
   314             	   {
       
   315             	   ShowPopUpsL (CurrentItemIndex());
       
   316             	   break;
       
   317             	   }
       
   318                case EEventPanningStarted:
       
   319                case EEventPanningStopped:
       
   320                case EEventFlickStarted:
       
   321                case EEventFlickStopped:
       
   322                case EEventItemDraggingActioned:
       
   323             	   break;
       
   324               default:
       
   325                      break;
       
   326                      }
       
   327                 }
       
   328     if( (aEventType == EEventEnterKeyPressed) || 
       
   329         (aEventType == EEventItemDoubleClicked) ) //for touch support
       
   330             {
       
   331             iViewRef->HandleCommandL( EUSBUICmdSelect );
       
   332             }
       
   333         
       
   334     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::HandleListBoxEventL complete"));
       
   335 	}
       
   336 
       
   337 // ----------------------------------------------------------------------------
       
   338 // CUSBClassChangeUIPluginContainer::MdcaCount()
       
   339 // ----------------------------------------------------------------------------
       
   340 //
       
   341 TInt CUSBClassChangeUIPluginContainer::MdcaCount() const
       
   342     {
       
   343     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::MdcaCount()"));
       
   344     TInt numberOfMainViewItems =iModelRef->PersonalityCount();
       
   345     FTRACE(FPrint(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::MdcaCount()= %d"), numberOfMainViewItems));
       
   346     return numberOfMainViewItems;
       
   347     }
       
   348     
       
   349 // ----------------------------------------------------------------------------
       
   350 // CUSBClassChangeUIPluginContainer::MdcaPoint()
       
   351 // Main view listbox item formatter:
       
   352 // Returns the current format string depending value
       
   353 // of the item concerned.
       
   354 // ----------------------------------------------------------------------------
       
   355 //
       
   356 TPtrC CUSBClassChangeUIPluginContainer::MdcaPoint( TInt aIndex ) const
       
   357     {
       
   358     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::MdcaPoint()"));
       
   359     
       
   360     TPtrC chosen;
       
   361     const RArray<TInt> usbIds = iModelRef->GetUsbIds();
       
   362     TInt currentIndex = usbIds.Find(iViewRef->USBMode());
       
   363     if (aIndex == currentIndex)
       
   364         {
       
   365         if(iViewRef->IsUSBDeviceConnected())
       
   366             {
       
   367             FLOG(_L("[CUSBClassChangeUIPlugin]\t MdcaPoint()The selected mode and usbconnected"));
       
   368             chosen.Set(iUSBAllItemsArrayActive->MdcaPoint(aIndex));
       
   369             }
       
   370         else
       
   371             {
       
   372             FLOG(_L("[CUSBClassChangeUIPlugin]\t MdcaPoint()The selected mode and usb not connected"));
       
   373             chosen.Set(iUSBAllItemsArrayDefault->MdcaPoint(aIndex));
       
   374             }
       
   375         }
       
   376     else
       
   377         {
       
   378         FLOG(_L("[CUSBClassChangeUIPlugin]\t MdcaPoint()not selected mode"));
       
   379         chosen.Set(iUSBAllItemsArray->MdcaPoint(aIndex));
       
   380         }
       
   381      
       
   382     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::MdcaPoint complete"));
       
   383     
       
   384     return chosen;
       
   385     }
       
   386     
       
   387 // ----------------------------------------------------------------------------
       
   388 // CUSBClassChangeUIPluginContainer::SettingChanged
       
   389 // ----------------------------------------------------------------------------
       
   390 //
       
   391 void CUSBClassChangeUIPluginContainer::SettingChanged()
       
   392     {
       
   393     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::SettingChangedL()"));
       
   394     
       
   395 	iUSBMainListBox->DrawDeferred();
       
   396     
       
   397     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::SettingChangedL complete"));
       
   398     }
       
   399     
       
   400 // ----------------------------------------------------------------------------
       
   401 // CUSBClassChangeUIPluginContainer::GetHelpContext
       
   402 // ----------------------------------------------------------------------------
       
   403 //
       
   404 void CUSBClassChangeUIPluginContainer::GetHelpContext(TCoeHelpContext& aContext) const
       
   405     {
       
   406     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::GetHelpContext()"));
       
   407     
       
   408     aContext.iMajor = KUidUSBClassChangeUI;
       
   409     aContext.iContext = KUSB_HLP_MAIN;
       
   410     
       
   411     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::GetHelpContext complete"));
       
   412     }
       
   413 
       
   414 // ----------------------------------------------------------------------------
       
   415 // CUSBClassChangeUIPluginContainer::HandleResourceChange
       
   416 // ----------------------------------------------------------------------------
       
   417 //
       
   418 void CUSBClassChangeUIPluginContainer::HandleResourceChange( TInt aType )
       
   419     {
       
   420     CCoeControl::HandleResourceChange( aType ); 
       
   421     if( aType == KEikDynamicLayoutVariantSwitch )
       
   422         {
       
   423         SetRect( iViewRef->ClientRect() );
       
   424         DrawNow(); 
       
   425         }
       
   426     else 
       
   427         {
       
   428         if ( aType == KAknsMessageSkinChange )
       
   429             {
       
   430             iUSBMainListBox->HandleResourceChange( aType ); 
       
   431             }
       
   432         }
       
   433     }
       
   434 
       
   435 // ----------------------------------------------------------------------------
       
   436 // CUSBClassChangeUIPluginContainer::CurrentItemIndex
       
   437 // ----------------------------------------------------------------------------
       
   438 //
       
   439 TInt CUSBClassChangeUIPluginContainer::CurrentItemIndex()
       
   440     {
       
   441     FLOG(_L("[CUSBClassChangeUIPlugin]\t CUSBClassChangeUIPluginContainer::CurrentItemIndex()"));
       
   442 
       
   443     return iUSBMainListBox->CurrentItemIndex();
       
   444     }
       
   445 
       
   446 // End of File