|
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.Text; |
|
40 using System.Drawing; |
|
41 using System.Collections; |
|
42 using System.Collections.Generic; |
|
43 using SymbianUtils.Graphics; |
|
44 using SymbianStructuresLib.Debug.Symbols; |
|
45 using HeapLib; |
|
46 using HeapLib.Cells; |
|
47 using HeapLib.Array; |
|
48 using HeapLib.Reconstructor; |
|
49 using HeapLib.Statistics.Tracking.Base; |
|
50 using HeapCtrlLib.Dialogs; |
|
51 using HeapCtrlLib.Factories; |
|
52 using HeapCtrlLib.Interfaces; |
|
53 using HeapCtrlLib.Utilities; |
|
54 using HeapCtrlLib.Renderers; |
|
55 using HeapCtrlLib.Renderers.Utilities; |
|
56 using HeapCtrlLib.Renderers.Contents.Bases; |
|
57 |
|
58 namespace HeapCtrlLib.Renderers.Contents |
|
59 { |
|
60 internal class HeapCellRendererColourBySymbol : HeapCellRendererByColour, IHeapCellRendererContent |
|
61 { |
|
62 #region Constructors & destructor |
|
63 public HeapCellRendererColourBySymbol() |
|
64 { |
|
65 } |
|
66 #endregion |
|
67 |
|
68 #region API |
|
69 public static string MakeColourHash( Symbol aSymbol ) |
|
70 { |
|
71 System.Diagnostics.Debug.Assert( aSymbol != null ); |
|
72 // |
|
73 string ret = string.Format( "{0:x8} {1} [{2}]", aSymbol.Address, aSymbol.Name, aSymbol.Object ); |
|
74 return ret; |
|
75 } |
|
76 #endregion |
|
77 |
|
78 #region From IHeapCellRendererContent |
|
79 public void Initialise( HeapCellArray aCells, HeapReconstructor aReconstructor, HeapDataRenderer aRenderer ) |
|
80 { |
|
81 iRenderer = aRenderer; |
|
82 // |
|
83 iFactory = (FactoryBySymbol) aRenderer.Factory; |
|
84 iFactory.PrepareColourHashes( aReconstructor, StandardColours ); |
|
85 } |
|
86 |
|
87 public void PrepareToNavigate( HeapRenderingNavigator aNavigator ) |
|
88 { |
|
89 iLargestRectangleCalculator = new HeapCellLargestRectangleCalculator( aNavigator ); |
|
90 } |
|
91 |
|
92 public void HeapCellRenderingComplete( Graphics aGraphics, HeapCell aCell, HeapCellMetaData aMetaData ) |
|
93 { |
|
94 Color fillColour = ColorForCell( aCell ); |
|
95 // |
|
96 string text = aCell.SymbolStringWithoutDescriptorPrefix; |
|
97 PaintBoxedTextWithLuminanceHandling( text, aGraphics, fillColour ); |
|
98 } |
|
99 |
|
100 public void RenderingComplete( Graphics aGraphics ) |
|
101 { |
|
102 } |
|
103 |
|
104 public void PaintContent( Graphics aGraphics, HeapCellMetaData aMetaData, HeapCell aCell, uint aAddress, Point aPosition, Size aBoxSize, Size aPaddingSize ) |
|
105 { |
|
106 // Get the cell colour that is associated with the cell symbol object type |
|
107 aMetaData.CellBoxColor = RampedColourByBoxNumber( ColorForCell( aCell ), aMetaData.CellBoxCount, aCell.Address, aAddress ); |
|
108 |
|
109 // Draw actual cell |
|
110 SymRect boxRect = new SymRect( aPosition, aBoxSize ); |
|
111 boxRect.HalfOffset( aPaddingSize ); |
|
112 using ( Brush brush = new SolidBrush( aMetaData.CellBoxColor ) ) |
|
113 { |
|
114 aGraphics.FillRectangle( brush, boxRect.Rectangle ); |
|
115 } |
|
116 } |
|
117 |
|
118 public bool SupportsFiltering |
|
119 { |
|
120 get { return true; } |
|
121 } |
|
122 |
|
123 public void SetupFilters() |
|
124 { |
|
125 if ( iRenderer != null ) |
|
126 { |
|
127 HeapCellFilterTripletDictionary dictionary = new HeapCellFilterTripletDictionary( ColourHashes ); |
|
128 HeapRendererFilterConfigDialog dialog = new HeapRendererFilterConfigDialog( dictionary ); |
|
129 if ( dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK ) |
|
130 { |
|
131 ColourHashes = dialog.Dictionary; |
|
132 iRenderer.Invalidate(); |
|
133 } |
|
134 } |
|
135 } |
|
136 #endregion |
|
137 |
|
138 #region Internal methods |
|
139 private HeapCellFilterTripletDictionary ColourHashes |
|
140 { |
|
141 get { return iFactory.ColourHashes; } |
|
142 set { iFactory.ColourHashes = value; } |
|
143 } |
|
144 |
|
145 private Color ColorForCell( HeapCell aCell ) |
|
146 { |
|
147 Color fillColour = HeapCellRendererColour.ColourByCellType( aCell ); |
|
148 // |
|
149 if ( aCell.Type == HeapCell.TType.EAllocated && !aCell.IsUnknown ) |
|
150 { |
|
151 string hash = MakeColourHash( aCell.Symbol ); |
|
152 // |
|
153 HeapCellFilterTriplet val = ColourHashes[ hash ]; |
|
154 System.Diagnostics.Debug.Assert( val != null ); |
|
155 fillColour = val.Color; |
|
156 } |
|
157 // |
|
158 return fillColour; |
|
159 } |
|
160 #endregion |
|
161 |
|
162 #region Internal constants |
|
163 #endregion |
|
164 |
|
165 #region Data members |
|
166 private HeapDataRenderer iRenderer = null; |
|
167 private FactoryBySymbol iFactory = null; |
|
168 #endregion |
|
169 } |
|
170 } |