sysperfana/heapanalyser/Libraries/UI/HeapCtrlLib/Utilities/HeapRenderingNavigator.cs
changeset 8 15296fd0af4a
equal deleted inserted replaced
7:8e12a575a9b5 8:15296fd0af4a
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * Redistribution and use in source and binary forms, with or without
       
     6 * modification, are permitted provided that the following conditions are met:
       
     7 *
       
     8 * - Redistributions of source code must retain the above copyright notice,
       
     9 *   this list of conditions and the following disclaimer.
       
    10 * - Redistributions in binary form must reproduce the above copyright notice,
       
    11 *   this list of conditions and the following disclaimer in the documentation
       
    12 *   and/or other materials provided with the distribution.
       
    13 * - Neither the name of Nokia Corporation nor the names of its contributors
       
    14 *   may be used to endorse or promote products derived from this software
       
    15 *   without specific prior written permission.
       
    16 *
       
    17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
       
    18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
       
    19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
       
    20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
       
    21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
       
    22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
       
    23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
       
    24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
       
    25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
       
    26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
       
    27 * POSSIBILITY OF SUCH DAMAGE.
       
    28 * 
       
    29 * Initial Contributors:
       
    30 * Nokia Corporation - initial contribution.
       
    31 *
       
    32 * Contributors:
       
    33 *
       
    34 * Description: 
       
    35 *
       
    36 */
       
    37 
       
    38 using System;
       
    39 using System.Drawing;
       
    40 using HeapLib;
       
    41 using HeapLib.Cells;
       
    42 using HeapLib.Array;
       
    43 
       
    44 namespace HeapCtrlLib.Utilities
       
    45 {
       
    46 	public class HeapRenderingNavigator
       
    47 	{
       
    48         #region Delegates
       
    49         public delegate void NavBegin();
       
    50         public delegate void NavEnd();
       
    51         public delegate void NavHeapCellBegin( HeapCell aCell, uint aAddress, Point aPosition, Size aDimensions, Size aBoxSize, Size aPadding );
       
    52         public delegate void NavHeapCellEnd( HeapCell aCell, HeapCellMetaData aMetaData, uint aAddress, Point aPosition, Size aDimensions, Size aBoxSize, Size aPadding );
       
    53         public delegate void NavNewRowHeader( uint aAddress, Point aPosition, Size aDimensions, Size aBoxSize, Size aPadding );
       
    54         public delegate void NavNewRowBody( HeapCellMetaData aMetaData, uint aAddress, Point aPosition, Size aDimensions, Size aBoxSize, Size aPadding );
       
    55         public delegate void NavNewColumn( HeapCell aCell, HeapCellMetaData aMetaData, uint aAddress, Point aPixelPos, Point aBoxPos, Size aDimensions, Size aBoxSize, Size aPadding );
       
    56         #endregion
       
    57 
       
    58         #region Events
       
    59         public event NavBegin iNavBegin;
       
    60         public event NavEnd iNavEnd;
       
    61         public event NavHeapCellBegin iNavHeapCellBegin;
       
    62         public event NavHeapCellEnd iNavHeapCellEnd;
       
    63         public event NavNewRowHeader iNavNewRowHeader;
       
    64         public event NavNewRowBody iNavNewRowBody;
       
    65         public event NavNewColumn iNavNewColumn;
       
    66         #endregion
       
    67 
       
    68         #region Constructors & destructor
       
    69 		public HeapRenderingNavigator( HeapCellArray aCells )
       
    70 		{
       
    71             iCells = aCells;
       
    72             //
       
    73             iMetaData = new HeapCellMetaData( this );
       
    74 		}
       
    75         #endregion
       
    76 
       
    77         #region Properties
       
    78         public HeapCellArray Cells
       
    79         {
       
    80             get { return iCells; }
       
    81         }
       
    82         #endregion
       
    83 
       
    84         #region API
       
    85         public void Navigate( int aStartingCellIndex, uint aStartingAddress, int aHeaderTextWidth, Point aStartOffset, Size aDimensions, Size aBoxSize, Size aPadding )
       
    86         {
       
    87             // This is the size of the cell including padding
       
    88             Size cellSizeIncPadding = aBoxSize + aPadding;
       
    89             
       
    90             if  ( Cells.Count > 0 )
       
    91             {
       
    92                 // The co-ordinates at which we will render a box (or header).
       
    93                 Point pos = new Point( aStartOffset.X, aStartOffset.Y - cellSizeIncPadding.Height );
       
    94 
       
    95                 // The index of the current heap cell within the iCells data structure.
       
    96                 // We start one before the requested cell, since we immediately skip
       
    97                 // on to the next one during the initialisation phase.
       
    98                 int cellIndex = aStartingCellIndex - 1;
       
    99 
       
   100                 // The total number of cells we have to work with
       
   101                 int cellCount = Cells.Count;
       
   102 
       
   103                 // The cell we are rendering. This changes as we move through the capture data.
       
   104                 HeapCell cell = null;
       
   105 
       
   106                 // The address of the currently paining box
       
   107                 uint address = aStartingAddress;
       
   108 
       
   109                 // Notify that we are starting.
       
   110                 if  ( iNavBegin != null )
       
   111                 {
       
   112                     iNavBegin();
       
   113                 }
       
   114 
       
   115                 // Draw the cells
       
   116                 bool abort = false;
       
   117                 for( int row = 0; row < aDimensions.Height && !abort; row++ )
       
   118                 {
       
   119                     // Handle the header at the start of each row
       
   120                     pos.X = aStartOffset.X;
       
   121                     pos.Y += cellSizeIncPadding.Height;
       
   122                     if  ( iNavNewRowHeader != null )
       
   123                     {
       
   124                         iNavNewRowHeader( address, pos, aDimensions, aBoxSize, aPadding );
       
   125                     }
       
   126 
       
   127                     // Move forwards, past the header
       
   128                     pos.X += aHeaderTextWidth;
       
   129                     if  ( iNavNewRowBody != null )
       
   130                     {
       
   131                         iNavNewRowBody( iMetaData, address, pos, aDimensions, aBoxSize, aPadding );
       
   132                     }
       
   133 
       
   134                     // Prepare for columns in this row
       
   135                     //System.Diagnostics.Debug.WriteLine( "Nav[" /*+ col.ToString("d2")*/ + "00," + row.ToString("d2") + "], ");
       
   136                     //System.Diagnostics.Debug.Write( ".");
       
   137                     for( int col = 0; col < aDimensions.Width && !abort; col++ )
       
   138                     {
       
   139                         // Do we need to also move to the next cell?
       
   140                         if  ( cell == null || cell.RegionForAddress( address ) == HeapCell.TRegion.EAfterCell )
       
   141                         {
       
   142                             // Notify finishing a cell
       
   143                             if  ( cell != null && iNavHeapCellEnd != null )
       
   144                             {
       
   145                                 iNavHeapCellEnd( cell, iMetaData, address, pos, aDimensions, aBoxSize, aPadding );
       
   146                             }
       
   147 
       
   148                             if  ( cellIndex < cellCount - 1 )
       
   149                             {
       
   150                                 // Get next cell
       
   151                                 cell = Cells[ ++cellIndex ];
       
   152 
       
   153                                 // Notify starting a cell
       
   154                                 if  ( iNavHeapCellBegin != null )
       
   155                                 {
       
   156                                     iNavHeapCellBegin( cell, address, pos, aDimensions, aBoxSize, aPadding );
       
   157                                 }
       
   158                             }
       
   159                             else
       
   160                             {
       
   161                                 abort = true;
       
   162                                 break;
       
   163                             }
       
   164                         }
       
   165                         //
       
   166                         if ( !abort )
       
   167                         {
       
   168                             // Notify starting a new box
       
   169                             if  ( iNavNewColumn != null )
       
   170                             {
       
   171                                 iNavNewColumn( cell, iMetaData, address, pos, new Point( col, row ), aDimensions, aBoxSize, aPadding );
       
   172                             }
       
   173                           
       
   174                             // Move to next address & position
       
   175                             pos.X += cellSizeIncPadding.Width;
       
   176                             address += SymbianUtils.RawItems.RawItem.KSizeOfOneRawItemInBytes;
       
   177                         }
       
   178                     }
       
   179                 }
       
   180 
       
   181                 if  ( !abort )
       
   182                 {
       
   183                     if  ( cell != null && iNavHeapCellEnd != null )
       
   184                     {
       
   185                         iNavHeapCellEnd( cell, iMetaData, address, pos, aDimensions, aBoxSize, aPadding );
       
   186                     }
       
   187                 }
       
   188 
       
   189                 // Notify that we are ending
       
   190                 if  ( iNavEnd != null )
       
   191                 {
       
   192                     iNavEnd();
       
   193                 }
       
   194             }
       
   195         }
       
   196         #endregion
       
   197 
       
   198         #region Data members
       
   199         private readonly HeapCellArray iCells;
       
   200         private readonly HeapCellMetaData iMetaData;
       
   201         #endregion
       
   202     }
       
   203 }