uiservicetab/vimpstui/src/cvimpstuiblockviewcontrol.cpp
changeset 0 5e5d6b214f4f
child 10 78867dafe7eb
equal deleted inserted replaced
-1:000000000000 0:5e5d6b214f4f
       
     1 /*
       
     2 * Copyright (c) 2008 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 : Implementation for cvimpstuiblockviewcontrol.
       
    15  *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "cvimpstuiblockviewcontrol.h"
       
    20 #include "cvimpstuiblockview.h"
       
    21 #include "vimpstutils.h"
       
    22 #include "tvimpstconsts.h"
       
    23 #include "vimpstui.hrh"
       
    24 
       
    25 // system include
       
    26 #include	<aknlists.h>
       
    27 #include	<eikclbd.h> 
       
    28 #include <vimpstuires.rsg>
       
    29 
       
    30 #include <MPbk2KeyEventHandler.h>
       
    31 
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =======================
       
    34 
       
    35 
       
    36 // --------------------------------------------------------------------------
       
    37 // CVIMPSTUiBlockViewControl::CVIMPSTUiBlockViewControl
       
    38 // --------------------------------------------------------------------------
       
    39 //
       
    40 CVIMPSTUiBlockViewControl::CVIMPSTUiBlockViewControl( CVIMPSTUiBlockView& aBlockedView,MPbk2KeyEventHandler& aKeyEventHandler,
       
    41 													   	MVIMPSTEngine& aEngine,
       
    42 													   	RPointerArray<HBufC>* aBlockedList)
       
    43 	:iBlockedView(aBlockedView),
       
    44 	 iKeyEventHandler(aKeyEventHandler),
       
    45 	 iEngine( aEngine ),
       
    46 	 iBlockedList(aBlockedList)
       
    47     {
       
    48     
       
    49     }
       
    50 
       
    51 
       
    52 // --------------------------------------------------------------------------
       
    53 // CVIMPSTUiBlockViewControl::ConstructL
       
    54 // --------------------------------------------------------------------------
       
    55 //
       
    56 void CVIMPSTUiBlockViewControl::ConstructL()
       
    57     {
       
    58     CreateWindowL();
       
    59     iItemArray = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );   
       
    60     // Create listbox
       
    61     iListBox = new ( ELeave ) CAknSingleGraphicStyleListBox;
       
    62     iListBox->ConstructL( this, EAknListBoxSelectionList );
       
    63     
       
    64     iListBox->SetContainerWindowL(*this);
       
    65     iListBox->CreateScrollBarFrameL(ETrue);
       
    66     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL
       
    67         (CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
    68         
       
    69     // set marquee on
       
    70     iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
    71    	iListBox->Model()->SetItemTextArray( iItemArray );
       
    72 	iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
    73 	
       
    74 	iListBox->SetListBoxObserver( this );
       
    75 	
       
    76 	iCurrentItemIndex = 0;
       
    77 	UpdateBlockedListL();
       
    78 	ActivateL();
       
    79 
       
    80     }
       
    81 
       
    82 
       
    83 // --------------------------------------------------------------------------
       
    84 // CVIMPSTUiBlockViewControl::NewL
       
    85 // --------------------------------------------------------------------------
       
    86 //
       
    87 CVIMPSTUiBlockViewControl* CVIMPSTUiBlockViewControl::NewL( CVIMPSTUiBlockView& aBlockedView,
       
    88         								    MPbk2KeyEventHandler& aKeyEventHandler, 
       
    89         									MVIMPSTEngine& aEngine,
       
    90         									RPointerArray<HBufC>* aBlockedList )
       
    91     {
       
    92     CVIMPSTUiBlockViewControl* self = NewLC(aBlockedView,aKeyEventHandler,aEngine, aBlockedList );
       
    93     CleanupStack::Pop(self);
       
    94     return self;
       
    95     }
       
    96 
       
    97 
       
    98 // --------------------------------------------------------------------------
       
    99 // CVIMPSTUiBlockViewControl::NewLC
       
   100 // --------------------------------------------------------------------------
       
   101 //
       
   102 CVIMPSTUiBlockViewControl* CVIMPSTUiBlockViewControl::NewLC( CVIMPSTUiBlockView& aBlockedView,
       
   103 									          MPbk2KeyEventHandler& aKeyEventHandler,
       
   104 									          MVIMPSTEngine& aEngine,
       
   105 									          RPointerArray<HBufC>* aBlockedList )
       
   106     {
       
   107     CVIMPSTUiBlockViewControl* self =
       
   108         new (ELeave) CVIMPSTUiBlockViewControl(aBlockedView,aKeyEventHandler, aEngine, aBlockedList );
       
   109     CleanupStack::PushL(self);
       
   110     self->ConstructL();
       
   111     return self;
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CVIMPSTUiBlockViewControl::Destructor
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 CVIMPSTUiBlockViewControl::~CVIMPSTUiBlockViewControl()
       
   119     {
       
   120    
       
   121 	delete iItemArray;
       
   122 	iItemArray = NULL;
       
   123     delete iListBox;
       
   124     iListBox = NULL;
       
   125 	}
       
   126 
       
   127 // ---------------------------------------------------------
       
   128 // CVIMPSTUiBlockViewControl::HandleControlEventL
       
   129 // ---------------------------------------------------------
       
   130 //
       
   131 void CVIMPSTUiBlockViewControl::HandleControlEventL(CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
       
   132     {
       
   133     }
       
   134 
       
   135 
       
   136 // ---------------------------------------------------------
       
   137 // CVIMPSTUiBlockViewControl::HandleListBoxEventL
       
   138 // Handles list box events
       
   139 // (other items were commented in a header).
       
   140 // ---------------------------------------------------------
       
   141 //
       
   142 void CVIMPSTUiBlockViewControl::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
   143 												 TListBoxEvent aEventType )
       
   144 	{
       
   145 	iCurrentItemIndex = iListBox->CurrentItemIndex();
       
   146 	if(aEventType == EEventEnterKeyPressed)
       
   147 	    {
       
   148 	    iBlockedView.HandleCommandL(ECmdUnBlock);                          
       
   149 	    }
       
   150 	}
       
   151 
       
   152 
       
   153 // ---------------------------------------------------------
       
   154 // CVIMPSTUiBlockViewControl::SizeChanged()
       
   155 // Called by framework
       
   156 // (other items were commented in a header).
       
   157 // ---------------------------------------------------------
       
   158 //
       
   159 void CVIMPSTUiBlockViewControl::SizeChanged()
       
   160 	{
       
   161 	if ( iListBox )
       
   162         {
       
   163         iListBox->SetRect(Rect());
       
   164         }  
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------
       
   168 // CVIMPSTUiBlockViewControl::CountComponentControls()
       
   169 // Returns number of controls
       
   170 // (other items were commented in a header).
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 TInt CVIMPSTUiBlockViewControl::CountComponentControls() const
       
   174 	{
       
   175 	//Only one compound control so returning 1
       
   176 	return 1;
       
   177 	}
       
   178 
       
   179 // ---------------------------------------------------------
       
   180 // CVIMPSTUiBlockViewControl::ComponentControl( TInt aIndex )
       
   181 // Returns control for given index
       
   182 // (other items were commented in a header).
       
   183 // ---------------------------------------------------------
       
   184 //
       
   185 CCoeControl* CVIMPSTUiBlockViewControl::ComponentControl( TInt aIndex ) const
       
   186 	{
       
   187 	if( aIndex == 0 )
       
   188 		{
       
   189         return iListBox;
       
   190         }
       
   191     else
       
   192         {
       
   193         return NULL;
       
   194     	}
       
   195 	}
       
   196 
       
   197 
       
   198 // ---------------------------------------------------------
       
   199 // CVIMPSTUiBlockViewControl::UpdateBlockedListL()
       
   200 // ---------------------------------------------------------
       
   201 //
       
   202 void CVIMPSTUiBlockViewControl::UpdateBlockedListL()
       
   203     {
       
   204 	iItemArray->Reset();
       
   205 	
       
   206 	TInt granularity( iItemArray->Count() );
       
   207 	++granularity;
       
   208 	
       
   209    	CDesCArray* tempArray = new ( ELeave ) CDesCArrayFlat( granularity );
       
   210 	CleanupStack::PushL( tempArray );
       
   211     
       
   212     iListBox->Model()->SetItemTextArray( tempArray );
       
   213 	iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   214 	iListBox->HandleItemAdditionL();
       
   215 	for ( TInt i =0; i < iBlockedList->Count() ; ++ i)
       
   216 	    {
       
   217 	    TInt sizeOfItemText;
       
   218 	    // Calculating the size of the text that will be entered into listbox.
       
   219 	    // 3 * KTab().Length() calculates the length of the tabs that is 
       
   220 	    // appended to the actual text.
       
   221 	    sizeOfItemText = (*iBlockedList)[i]->Length() + 3 * KTab().Length();
       
   222 	    HBufC* itemText = HBufC::NewLC( sizeOfItemText ); // changing stuff..
       
   223 	    TPtr itemTextPtr( itemText->Des() );
       
   224 	    itemTextPtr.Append( KTab );
       
   225 	    itemTextPtr.Append( (*iBlockedList)[i]->Des());
       
   226 	    itemTextPtr.Append( KTab );
       
   227 	    itemTextPtr.Append( KTab );
       
   228 
       
   229 	    iItemArray->AppendL( itemTextPtr );
       
   230 	    CleanupStack::PopAndDestroy( itemText );
       
   231 	    }
       
   232 	CleanupStack::PopAndDestroy(tempArray );  // tempArray
       
   233 	
       
   234 	iItemArray->Sort();
       
   235 	iListBox->Model()->SetItemTextArray( iItemArray );
       
   236 	iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   237 
       
   238     iListBox->HandleItemAdditionL();
       
   239 
       
   240     if(0==iBlockedList->Count())
       
   241 	    {
       
   242 	    SetEmptyTextsToListboxL();	
       
   243 	    }
       
   244 	    
       
   245 	if ( iItemArray->MdcaCount() > 0 )
       
   246 		{
       
   247 		iListBox->SetCurrentItemIndexAndDraw( 0 );
       
   248 		}
       
   249     iListBox->UpdateScrollBarsL();
       
   250     SetCurrentIndex(iCurrentItemIndex);
       
   251     UpdateCbaL();
       
   252     }
       
   253     
       
   254     
       
   255 // ---------------------------------------------------------
       
   256 // CVIMPSTUiBlockViewControl::ListBox()
       
   257 // (other items were commented in a header).
       
   258 // ---------------------------------------------------------
       
   259 //
       
   260 CEikListBox* CVIMPSTUiBlockViewControl::ListBox() const
       
   261 	{
       
   262 	return iListBox;
       
   263 	}
       
   264 
       
   265 // ---------------------------------------------------------
       
   266 // CVIMPSTUiBlockViewControl::GetFocusedItemText
       
   267 // (other items were commented in a header).
       
   268 // ---------------------------------------------------------
       
   269 //
       
   270 HBufC* CVIMPSTUiBlockViewControl::GetFocusedContactLC() const
       
   271 	{
       
   272 	HBufC* retText = NULL;
       
   273 	TInt curIndex = iListBox->CurrentItemIndex();
       
   274 	if(KErrNotFound != curIndex)
       
   275 	    {
       
   276 	    TPtrC ptr= iItemArray->MdcaPoint(curIndex);
       
   277 	    ptr.Set(ptr.Mid(1));  // set pointer from next char :since first char is KTab
       
   278         TInt pos=ptr.FindC(KTab);
       
   279         if( pos !=KErrNotFound &&  (pos != ptr.Length()-1))
       
   280             {
       
   281             ptr.Set(ptr.Mid( 0, pos));
       
   282             retText = ptr.AllocLC();
       
   283             }
       
   284 	    }
       
   285     return retText;
       
   286 	}
       
   287 
       
   288 // ---------------------------------------------------------
       
   289 // CVIMPSTUiBlockViewControl::GetCurrentIndex
       
   290 // (other items were commented in a header).
       
   291 // ---------------------------------------------------------
       
   292 //
       
   293 TInt CVIMPSTUiBlockViewControl::GetCurrentIndex() const
       
   294 	{
       
   295 	return iCurrentItemIndex ;
       
   296 	}
       
   297 
       
   298 // ---------------------------------------------------------
       
   299 // CVIMPSTUiBlockViewControl::GetCurrentIndex
       
   300 // (other items were commented in a header).
       
   301 // ---------------------------------------------------------
       
   302 //
       
   303 void CVIMPSTUiBlockViewControl::SetCurrentIndex(TInt aIndex)
       
   304 	{
       
   305 	if(aIndex>0)
       
   306 		{
       
   307 	    TInt blockedCount = iListBox->Model()->NumberOfItems();
       
   308 		if(blockedCount > 0)
       
   309 			{
       
   310 			TInt itemIndex = aIndex % blockedCount;
       
   311 			iListBox->SetCurrentItemIndex(itemIndex);
       
   312 			}
       
   313 		}
       
   314 	}
       
   315 
       
   316 
       
   317 // ---------------------------------------------------------
       
   318 // CVIMPSTUiBlockViewControl::UpdateCbaL()
       
   319 // Updates Softkeys according to current focus.
       
   320 // ---------------------------------------------------------
       
   321 //
       
   322 void CVIMPSTUiBlockViewControl::UpdateCbaL()
       
   323     {
       
   324     TInt cbaRes = R_SERVTAB_SOFTKEYS_EMPTY_EMPTY__BACK;    
       
   325     if ( !iCba ) 
       
   326 	    {
       
   327 	    iCba = CEikButtonGroupContainer::Current();
       
   328 	    }
       
   329 
       
   330   	if( iCba )
       
   331         {
       
   332         iCba->SetCommandSetL( cbaRes );
       
   333      	iCba->DrawNow();
       
   334         }
       
   335     }
       
   336 
       
   337 // ---------------------------------------------------------
       
   338 // CVIMPSTUiBlockViewControl::OfferKeyEventL()
       
   339 // Handles user key inputs
       
   340 // (other items were commented in a header).
       
   341 // ---------------------------------------------------------
       
   342 //
       
   343 TKeyResponse CVIMPSTUiBlockViewControl::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   344 													TEventCode aType )
       
   345 	{
       
   346 	if ( !aKeyEvent.iCode ) 
       
   347 	        {
       
   348 	        //The character code generated 
       
   349 	        //for an EEventKey, or 0 for a down or up event.
       
   350 	        //For down or up key return key consumed.. handle only the events
       
   351 	        
       
   352 	        if((EEventKeyDown == aType) && (EStdKeyDevice3 == aKeyEvent.iScanCode))
       
   353 	            {
       
   354 	            //for setting the command to be executed for the "Selection key"
       
   355 	            //in case of selection key, container's OfferKeyEventL() is called only for EEventKeyDown and EEventKeyUp
       
   356 	            //and not for EEventKey
       
   357 	            UpdateCbaL();
       
   358 	            }
       
   359 	        return EKeyWasConsumed;         
       
   360 	        }
       
   361 	TKeyResponse result = EKeyWasNotConsumed;
       
   362 	iCurrentItemIndex = iListBox->CurrentItemIndex();
       
   363     // Offer key event first to the key event handler
       
   364     if ( (&iKeyEventHandler ) && iKeyEventHandler.Pbk2ProcessKeyEventL
       
   365             ( aKeyEvent, aType ) )
       
   366         {
       
   367         result = EKeyWasConsumed;
       
   368         }
       
   369     switch(aKeyEvent.iCode )
       
   370         {
       
   371       /*  case EKeyEnter:
       
   372            {
       
   373            iBlockedView.HandleCommandL(ECmdUnBlock);
       
   374            result = EKeyWasConsumed;
       
   375            break;
       
   376            } */
       
   377         default:
       
   378            {
       
   379            break;
       
   380            }
       
   381         }
       
   382     if( result == EKeyWasConsumed )
       
   383        {
       
   384        // user might has choosen back/end key/application key etc
       
   385        // application might switch to background 
       
   386        // return from here
       
   387        return result; 
       
   388        }
       
   389     // Not consumed by the key handler, offer to the control next
       
   390     if ( result == EKeyWasNotConsumed )
       
   391         {
       
   392         if ( iListBox )
       
   393             {
       
   394             result = iListBox->OfferKeyEventL(aKeyEvent, aType);
       
   395             }
       
   396         }
       
   397     UpdateCbaL();
       
   398     return result;
       
   399     
       
   400 	}
       
   401 
       
   402 // ---------------------------------------------------------------------------
       
   403 // CVIMPSTUiBlockViewControl::SetEmptyTextsToListboxL()
       
   404 // See header for details. 
       
   405 // ---------------------------------------------------------------------------
       
   406 //
       
   407 void CVIMPSTUiBlockViewControl::SetEmptyTextsToListboxL()
       
   408     {    
       
   409     HBufC* emptyFinal = VIMPSTUtils::LoadResourceL(R_SERVTAB_BLOCKLIST_BKGD);
       
   410     CleanupStack::PushL(emptyFinal);
       
   411     iListBox->View()->SetListEmptyTextL( *emptyFinal );
       
   412     CleanupStack::PopAndDestroy(emptyFinal);
       
   413     }
       
   414     
       
   415 // ---------------------------------------------------------------------------
       
   416 // CVIMPSTUiBlockViewControl::SetUpdatingTextsToListboxL()
       
   417 // See header for details. 
       
   418 // ---------------------------------------------------------------------------
       
   419 //
       
   420 void CVIMPSTUiBlockViewControl::SetUpdatingTextsToListboxL()
       
   421     {    
       
   422     HBufC* updating = VIMPSTUtils::LoadResourceL(R_SERVTAB_BLOCKLIST_BKGDTO);
       
   423     CleanupStack::PushL(updating);
       
   424     iListBox->View()->SetListEmptyTextL( *updating );
       
   425     CleanupStack::PopAndDestroy(updating);
       
   426     }
       
   427     
       
   428 
       
   429 //  End of File