memspyui/source/MemSpyContainer.cpp
branchRCL_3
changeset 21 b3cee849fa46
parent 20 48060abbbeaf
child 22 fad26422216a
equal deleted inserted replaced
20:48060abbbeaf 21:b3cee849fa46
     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 "MemSpyContainer.h"
       
    19 
       
    20 // System includes
       
    21 #include <eikrted.h>  // for example label control
       
    22 #include <txtrich.h>
       
    23 #include <apgtask.h>
       
    24 
       
    25 // Engine includes
       
    26 #include <memspy/engine/memspyengine.h>
       
    27 #include <memspy/engine/memspyengineobjectprocess.h>
       
    28 #include <memspy/engine/memspyengineobjectthread.h>
       
    29 #include <memspy/engine/memspyengineobjectcontainer.h>
       
    30 #include <memspy/engine/memspyengineobjectthreadinfoobjects.h>
       
    31 #include <memspy/engine/memspyengineobjectthreadinfocontainer.h>
       
    32 
       
    33 // User includes
       
    34 #include "MemSpyViewMainMenu.h"
       
    35 #include "MemSpyContainerObserver.h"
       
    36 
       
    37 
       
    38 
       
    39 
       
    40 CMemSpyContainer::CMemSpyContainer( CMemSpyEngine& aEngine, MMemSpyContainerObserver& aObserver  )
       
    41 :   iEngine( aEngine ), iObserver( aObserver )
       
    42     {
       
    43     }
       
    44 
       
    45 
       
    46 CMemSpyContainer::~CMemSpyContainer()
       
    47     {
       
    48     delete iPreviousView;
       
    49     delete iActiveView;
       
    50     }
       
    51 
       
    52 
       
    53 void CMemSpyContainer::ConstructL(const TRect& aRect)
       
    54     {
       
    55     CreateWindowL();
       
    56     SetRect(aRect);
       
    57     PrepareTopLevelViewL();
       
    58     ActivateL();
       
    59     }
       
    60 
       
    61 
       
    62 void CMemSpyContainer::NavigateToParentViewL()
       
    63     {
       
    64     CMemSpyViewBase* parentView = iActiveView->PrepareParentViewL();
       
    65     //
       
    66     if  ( parentView == NULL )
       
    67         {
       
    68         // Parent can be null, in which case, revert to top-level view
       
    69         PrepareTopLevelViewL();
       
    70         }
       
    71     else
       
    72         {
       
    73         SetNewActiveViewL( parentView );
       
    74         }
       
    75     }
       
    76 
       
    77 
       
    78 void CMemSpyContainer::NavigateToChildViewL()
       
    79     {
       
    80     CMemSpyViewBase* childView = iActiveView->PrepareChildViewL();
       
    81     //
       
    82     if  ( childView != NULL )
       
    83         {
       
    84         SetNewActiveViewL( childView );
       
    85         }
       
    86     }
       
    87 
       
    88 
       
    89 void CMemSpyContainer::HandleCommandL( TInt aCommand )
       
    90     {
       
    91     switch( aCommand )
       
    92         {
       
    93 	case EMemSpyCmdViewRefresh:
       
    94         OnCmdViewRefreshL();
       
    95         break;
       
    96     default:
       
    97         if  ( iActiveView )
       
    98             {
       
    99             iActiveView->HandleCommandL( aCommand );
       
   100             }
       
   101         break;
       
   102         }
       
   103     }
       
   104 
       
   105 
       
   106 void CMemSpyContainer::OnCmdViewRefreshL()
       
   107     {
       
   108     if  ( iActiveView )
       
   109         {
       
   110         TRAPD(err, iActiveView->RefreshL());
       
   111         if  ( err != KErrNone )
       
   112             {
       
   113             // Error during view refreshing (perhaps the thread doesn't exist anymore).
       
   114             // Try to replace the active view with its parent...
       
   115             NavigateToParentViewL();
       
   116             }
       
   117         }
       
   118     }
       
   119 
       
   120 
       
   121 void CMemSpyContainer::SizeChanged()
       
   122     {
       
   123     if  ( iActiveView )
       
   124         {
       
   125         iActiveView->SetRect( Rect() );
       
   126         }
       
   127     }
       
   128 
       
   129 
       
   130 TInt CMemSpyContainer::CountComponentControls() const
       
   131     {
       
   132     return 1;
       
   133     }
       
   134 
       
   135 
       
   136 CCoeControl* CMemSpyContainer::ComponentControl(TInt /*aIndex*/) const
       
   137     {
       
   138     return iActiveView;
       
   139     }
       
   140 
       
   141 
       
   142 void CMemSpyContainer::Draw(const TRect& aRect) const
       
   143     {
       
   144     CWindowGc& gc = SystemGc();
       
   145     //
       
   146     gc.SetPenStyle(CGraphicsContext::ENullPen);
       
   147     gc.SetBrushColor(KRgbGray);
       
   148     gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   149     gc.DrawRect(aRect);
       
   150     }
       
   151 
       
   152 
       
   153 TKeyResponse CMemSpyContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   154     {
       
   155     TKeyResponse response = EKeyWasNotConsumed;
       
   156     //
       
   157     if  ( iActiveView )
       
   158         {
       
   159         response = iActiveView->OfferKeyEventL( aKeyEvent, aType );
       
   160         }
       
   161     //
       
   162     return response;
       
   163     }
       
   164 
       
   165 
       
   166 void CMemSpyContainer::HandleMemSpyViewEventL( TViewEventType aEvent, TMemSpyViewType /*aViewType*/, CMemSpyViewBase& aReportingView, TAny* /*aContext*/ )
       
   167     {
       
   168     if  ( aEvent == EEventItemActioned )
       
   169         {
       
   170         // Get the view to generate a child
       
   171         CMemSpyViewBase* child = aReportingView.PrepareChildViewL();
       
   172         if  ( child == NULL )
       
   173             {
       
   174             // View doesn't have a child - treat it as item activation and
       
   175             // report event to observer.
       
   176 
       
   177             }
       
   178         else
       
   179             {
       
   180             // Child view becomes the active one
       
   181             SetNewActiveViewL( child );
       
   182             }
       
   183         }
       
   184     }
       
   185 
       
   186 
       
   187 CMemSpyViewBase* CMemSpyContainer::PrepareTopLevelViewL()
       
   188     {
       
   189     CMemSpyViewMainMenu* view = new(ELeave) CMemSpyViewMainMenu( iEngine, *this );
       
   190     CleanupStack::PushL( view );
       
   191     view->ConstructL( Rect(), *this );
       
   192     SetNewActiveViewL( view );
       
   193     CleanupStack::Pop( view );
       
   194     return view;
       
   195     }
       
   196 
       
   197 
       
   198 void CMemSpyContainer::SetNewActiveViewL( CMemSpyViewBase* aNewView )
       
   199     {
       
   200     delete iPreviousView;
       
   201     //
       
   202     iPreviousView = iActiveView;
       
   203     if  ( iPreviousView )
       
   204         {
       
   205         iPreviousView->MakeVisible( EFalse );
       
   206         iPreviousView->SetFocus( EFalse );
       
   207         }
       
   208     //
       
   209     iActiveView = aNewView;
       
   210     iActiveView->RefreshL();
       
   211     iActiveView->SetFocus( ETrue );
       
   212     //
       
   213     ReportEventL( MCoeControlObserver::EEventStateChanged );
       
   214     }
       
   215 
       
   216 
       
   217 
       
   218 
       
   219 
       
   220 
       
   221 
       
   222