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