memspyui/ui/avkon/src/MemSpyViewBase.cpp
branchRCL_3
changeset 60 6646c35e558c
parent 50 9b2cffad4b5e
equal deleted inserted replaced
50:9b2cffad4b5e 60:6646c35e558c
     1 /*
       
     2 * Copyright (c) 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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "MemSpyViewBase.h"
       
    19 
       
    20 // System includes
       
    21 #include <eikrted.h>  // for example label control
       
    22 #include <txtrich.h>
       
    23 #include <apgtask.h>
       
    24 #include <akntitle.h>
       
    25 #include <akncontext.h>
       
    26 #include <aknnavi.h>
       
    27 #include <eiklbx.h>
       
    28 #include <eiklbm.h>
       
    29 #include <avkon.hrh>
       
    30 
       
    31 // Engine includes
       
    32 #include <memspy/engine/memspyengine.h>
       
    33 #include <memspy/engine/memspyengineutils.h>
       
    34 #include <memspy/engine/memspyengineoutputsink.h>
       
    35 
       
    36 // User includes
       
    37 #include "MemSpyAppUi.h"
       
    38 #include "MemSpyDocument.h"
       
    39 #include "MemSpyContainer.h"
       
    40 #include "MemSpyContainerObserver.h"
       
    41 
       
    42 
       
    43 
       
    44 /*
       
    45 CMemSpyViewBase::CMemSpyViewBase( CMemSpyEngine& aEngine, MMemSpyViewObserver& aObserver )
       
    46 :   iEngine( aEngine ), iObserver( aObserver )
       
    47     {
       
    48     }
       
    49 */
       
    50 CMemSpyViewBase::CMemSpyViewBase( RMemSpySession& aSession, MMemSpyViewObserver& aObserver )
       
    51 :   iMemSpySession( aSession ), iObserver( aObserver )
       
    52     {
       
    53     }
       
    54 
       
    55 
       
    56 CMemSpyViewBase::~CMemSpyViewBase()
       
    57     {
       
    58     delete iListBox;
       
    59     }
       
    60  
       
    61 
       
    62 void CMemSpyViewBase::ConstructL( const TRect& aRect, CCoeControl& aContainer, TAny* /*aSelectionRune*/ )
       
    63     {
       
    64     iSettings = &static_cast< CMemSpyAppUi* >( iEikonEnv->EikAppUi() )->MemSpyDocument().Settings();
       
    65     //
       
    66     User::LeaveIfError( SetParent( &aContainer ) );
       
    67     SetContainerWindowL( aContainer );
       
    68     
       
    69     SetComponentsToInheritVisibility( ETrue );
       
    70 
       
    71     iListBox = ConstructListBoxL();
       
    72     if  ( iListBox )
       
    73         {
       
    74         iListBox->SetFocus( ETrue );
       
    75         }
       
    76 
       
    77     SetRect( aRect );
       
    78     ActivateL();
       
    79     }
       
    80 
       
    81 
       
    82 void CMemSpyViewBase::SetTitleL( const TDesC& aText )
       
    83     {
       
    84     CEikStatusPane* statusPane = static_cast<CAknAppUi*> ( iEikonEnv->EikAppUi() )->StatusPane();
       
    85     CAknTitlePane* title = static_cast<CAknTitlePane*> ( statusPane->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
    86     title->SetTextL( aText );
       
    87     }
       
    88 
       
    89 
       
    90 TPtrC CMemSpyViewBase::TitleL() const
       
    91     {
       
    92     TPtrC ret( KNullDesC );
       
    93     //
       
    94     CEikStatusPane* statusPane = static_cast<CAknAppUi*> ( iEikonEnv->EikAppUi() )->StatusPane();
       
    95     CAknTitlePane* title = static_cast<CAknTitlePane*> ( statusPane->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
    96     if  ( title->Text() )
       
    97         {
       
    98         ret.Set( *title->Text() );
       
    99         }
       
   100     //
       
   101     return ret;
       
   102     }
       
   103 
       
   104 
       
   105 CMemSpyViewBase* CMemSpyViewBase::PrepareParentViewL()
       
   106     {
       
   107     return NULL;
       
   108     }
       
   109 
       
   110 
       
   111 CMemSpyViewBase* CMemSpyViewBase::PrepareChildViewL()
       
   112     {
       
   113     return NULL;
       
   114     }
       
   115     
       
   116     
       
   117 void CMemSpyViewBase::RefreshL()
       
   118     {
       
   119     if  ( iListBox )
       
   120         {
       
   121         iListBox->UpdateScrollBarsL();
       
   122         }
       
   123 
       
   124     DrawDeferred();
       
   125     }
       
   126 
       
   127 
       
   128 TBool CMemSpyViewBase::HandleCommandL( TInt aCommand )
       
   129     {
       
   130     TBool handled = ETrue;
       
   131     //
       
   132     switch( aCommand )
       
   133         {
       
   134 	case EMemSpyCmdViewOutputToSink:
       
   135         OnCmdViewOutputToSinkL();
       
   136         break;
       
   137     default:
       
   138         handled = EFalse;
       
   139         break;
       
   140         }
       
   141     //
       
   142     return handled;
       
   143     }
       
   144 
       
   145 
       
   146 void CMemSpyViewBase::DynInitMenuPaneL( TInt /*aResourceId*/, CEikMenuPane* /*aMenuPane*/ )
       
   147     {
       
   148     }
       
   149 
       
   150 
       
   151 TUint CMemSpyViewBase::MenuCascadeResourceId() const
       
   152     {
       
   153     return 0;
       
   154     }
       
   155 
       
   156 
       
   157 TInt CMemSpyViewBase::MenuCascadeCommandId() const
       
   158     {
       
   159     return 0;
       
   160     }
       
   161 
       
   162 
       
   163 void CMemSpyViewBase::OnCmdViewOutputToSinkL()
       
   164     {
       
   165 	//cigasto so solve - outputs content of the listbox into the sink
       
   166 	//to discuss format with Orbit
       
   167 	/*
       
   168     if  ( iListBox )
       
   169         {
       
   170         // Prepare sink
       
   171         CMemSpyEngineOutputSink& sink = iEngine.Sink();
       
   172         HBufC* name = MemSpyEngineUtils::CleanupTextLC( TitleL() );
       
   173         sink.OutputSectionHeadingL( *name, TChar('-') );
       
   174         CleanupStack::PopAndDestroy( name );
       
   175         sink.OutputPrefixSetLC( _L("  ") ); // Slight insertion
       
   176         
       
   177         // Get text from underlying listbox model...
       
   178         MTextListBoxModel* model = static_cast< MTextListBoxModel* >( iListBox->Model() );
       
   179         const TInt count = model->NumberOfItems();
       
   180 
       
   181         // First pass to get max lengths
       
   182         TInt maxLengthCaption = 0;
       
   183         TInt maxLengthValue = 0;
       
   184 
       
   185         for( TInt j=0; j<count; j++ )
       
   186             {
       
   187             const TPtrC pItem( model->ItemText( j ) );
       
   188             const TInt length = pItem.Length();
       
   189     
       
   190             // Check if its split or not?
       
   191             const TInt splitPos = pItem.FindF( _L("\t\t") );
       
   192             if  ( splitPos > 0 )
       
   193                 {
       
   194                 maxLengthCaption = Max( maxLengthCaption, splitPos );
       
   195                 maxLengthValue = Max( maxLengthValue, length - splitPos + 1 );
       
   196                 }
       
   197             else
       
   198                 {
       
   199                 maxLengthCaption = Max( maxLengthCaption, length );
       
   200                 }
       
   201             }
       
   202 
       
   203         // Second pass - real this time - to print the values
       
   204         HBufC* line = HBufC::NewLC( ( maxLengthCaption + maxLengthValue ) + 20 );
       
   205         TPtr pLine( line->Des() );
       
   206         //
       
   207         for( TInt i=0; i<count; i++ )
       
   208             {
       
   209             const TPtrC pItem( model->ItemText( i ) );
       
   210             const TInt length = pItem.Length();
       
   211             //
       
   212             TPtrC pCaption( KNullDesC );
       
   213             TPtrC pValue( KNullDesC );
       
   214             //
       
   215             const TInt splitPos = pItem.FindF( _L("\t\t") );
       
   216             if  ( splitPos > 0 )
       
   217                 {
       
   218                 pCaption.Set( pItem.Left( splitPos ) );
       
   219                 pValue.Set( pItem.Mid( splitPos + 1 ) );
       
   220                 }
       
   221             else
       
   222                 {
       
   223                 pCaption.Set( pItem );
       
   224                 }
       
   225 
       
   226             // Remove initial tabs in caption
       
   227             HBufC* caption = MemSpyEngineUtils::CleanupTextLC( pCaption );
       
   228         
       
   229             // Create value item & replace any further tabs
       
   230             HBufC* value = MemSpyEngineUtils::CleanupTextLC( pValue );
       
   231 
       
   232             // Now format the final line, with padding.
       
   233             pLine.Justify( *caption, maxLengthCaption + 3, ELeft, TChar(' ') );
       
   234             pLine.Append( *value );
       
   235             CleanupStack::PopAndDestroy( 2, caption );
       
   236 
       
   237             // Sink output
       
   238             sink.OutputLineL( pLine );
       
   239             }
       
   240 
       
   241         // Remove prefix & tidy up
       
   242         CleanupStack::PopAndDestroy( line );
       
   243         sink.OutputBlankLineL();
       
   244         CleanupStack::PopAndDestroy(); // clear prefix
       
   245 		}  
       
   246 	*/     
       
   247     }
       
   248 
       
   249 
       
   250 CEikListBox* CMemSpyViewBase::ConstructListBoxL()
       
   251     {
       
   252     delete iListBox;
       
   253     iListBox = NULL;
       
   254     CAknSettingStyleListBox* listbox = new(ELeave) CAknSettingStyleListBox();
       
   255     iListBox = listbox;
       
   256     //
       
   257     listbox->ConstructL( this, EAknListBoxSelectionList | EAknListBoxLoopScrolling );
       
   258     listbox->SetContainerWindowL( *this );
       
   259     listbox->CreateScrollBarFrameL( ETrue );
       
   260     SetListBoxModelL();
       
   261     listbox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   262     listbox->SetListBoxObserver( this );
       
   263     listbox->SetObserver( this );
       
   264     listbox->SetComponentsToInheritVisibility( ETrue );
       
   265     //
       
   266     return listbox;
       
   267     }
       
   268 
       
   269 
       
   270 void CMemSpyViewBase::HandleListBoxItemActionedL( TInt /*aIndex*/ )
       
   271     {
       
   272     ReportEventL( MMemSpyViewObserver::EEventItemActioned );
       
   273     }
       
   274 
       
   275 
       
   276 void CMemSpyViewBase::HandleListBoxItemSelectedL( TInt /*aIndex*/ )
       
   277     {
       
   278     ReportEventL( MMemSpyViewObserver::EEventItemSelected );
       
   279     }
       
   280 
       
   281 
       
   282 void CMemSpyViewBase::ReportEventL( MMemSpyViewObserver::TViewEventType aEvent, TAny* aContext )
       
   283     {
       
   284     iObserver.HandleMemSpyViewEventL( aEvent, ViewType(), *this, aContext );
       
   285     }
       
   286 
       
   287 
       
   288 void CMemSpyViewBase::SetListBoxCurrentItemIndexL( TInt aIndex )
       
   289     {
       
   290     if  ( iListBox )
       
   291         {
       
   292         iListBox->SetCurrentItemIndex( aIndex );
       
   293         HandleListBoxItemSelectedL( aIndex );
       
   294         }
       
   295     }
       
   296 
       
   297 
       
   298 CMemSpyContainer& CMemSpyViewBase::Container()
       
   299     {
       
   300     CMemSpyAppUi* appUi = static_cast< CMemSpyAppUi* >( iEikonEnv->EikAppUi() );
       
   301     return appUi->Container();
       
   302     }
       
   303 
       
   304 
       
   305 CMemSpySettings& CMemSpyViewBase::Settings()
       
   306     {
       
   307     return *iSettings;
       
   308     }
       
   309 
       
   310 
       
   311 const CMemSpySettings& CMemSpyViewBase::Settings() const
       
   312     {
       
   313     return *iSettings;
       
   314     }
       
   315 
       
   316     
       
   317 void CMemSpyViewBase::Draw( const TRect& aRect ) const
       
   318     {
       
   319     CWindowGc& gc = SystemGc();
       
   320     //
       
   321     gc.SetPenStyle( CGraphicsContext::ENullPen );
       
   322     gc.SetBrushColor( KRgbWhite );
       
   323     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   324     gc.DrawRect( aRect );
       
   325     }
       
   326 
       
   327 
       
   328 void CMemSpyViewBase::SizeChanged()
       
   329     {
       
   330     if  ( iListBox )
       
   331         {
       
   332         iListBox->SetRect( Rect() );
       
   333         }
       
   334     }
       
   335 
       
   336 
       
   337 void CMemSpyViewBase::FocusChanged(TDrawNow /*aDrawNow*/)
       
   338     {
       
   339     if  ( iListBox )
       
   340         {
       
   341         iListBox->SetFocus( IsFocused() );
       
   342         }
       
   343     }
       
   344 
       
   345 
       
   346 TInt CMemSpyViewBase::CountComponentControls() const
       
   347     {
       
   348     TInt count = 0;
       
   349     if  ( iListBox )
       
   350         {
       
   351         ++count;
       
   352         }
       
   353     //
       
   354     return count;
       
   355     }
       
   356 
       
   357 
       
   358 CCoeControl* CMemSpyViewBase::ComponentControl(TInt aIndex) const
       
   359     {
       
   360     switch ( aIndex )
       
   361         {
       
   362     case 0:
       
   363         return iListBox;
       
   364     default:
       
   365         return NULL;
       
   366         }
       
   367     }
       
   368 
       
   369 
       
   370 TKeyResponse CMemSpyViewBase::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   371 	{
       
   372     TKeyResponse resp = EKeyWasNotConsumed;
       
   373     if  ( iListBox )
       
   374         {
       
   375         resp = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   376         }
       
   377     //
       
   378     if ( resp == EKeyWasNotConsumed && aType == EEventKeyDown && aKeyEvent.iCode == EKeyBackspace )
       
   379         {
       
   380         // When backspace is pushed, go to the parent view
       
   381         CMemSpyAppUi* appUi = static_cast< CMemSpyAppUi* >( iEikonEnv->EikAppUi() );
       
   382         appUi->Container().NavigateToParentViewL();
       
   383         resp = EKeyWasConsumed;
       
   384         }
       
   385     //
       
   386 	return resp;
       
   387 	}
       
   388 
       
   389 
       
   390 void CMemSpyViewBase::HandleControlEventL( CCoeControl* aControl,TCoeEvent aEventType )
       
   391     {
       
   392     if  ( aControl == iListBox )
       
   393         {
       
   394         if  ( aEventType == MCoeControlObserver::EEventStateChanged )
       
   395             {
       
   396             const TInt index = iListBox->CurrentItemIndex();
       
   397             HandleListBoxItemSelectedL( index );
       
   398             }
       
   399         }
       
   400     }
       
   401 
       
   402 
       
   403 void CMemSpyViewBase::HandleListBoxEventL( CEikListBox* /*aListBox*/, TListBoxEvent aEventType )
       
   404     {
       
   405     const TInt index = iListBox->CurrentItemIndex();
       
   406     //
       
   407     switch (aEventType)
       
   408         {
       
   409     case EEventItemActioned:
       
   410     case EEventEnterKeyPressed:
       
   411     case EEventItemDoubleClicked:
       
   412         HandleListBoxItemActionedL( index );
       
   413         break;
       
   414 
       
   415     default:
       
   416         break;
       
   417         }
       
   418     }
       
   419 
       
   420 
       
   421 
       
   422