|
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.Cells; |
|
41 |
|
42 namespace HeapCtrlLib.Utilities |
|
43 { |
|
44 public class HeapCellLargestRectangleCalculator |
|
45 { |
|
46 #region Constructors & destructor |
|
47 public HeapCellLargestRectangleCalculator( HeapRenderingNavigator aNavigator ) |
|
48 : this( aNavigator, 0 ) |
|
49 { |
|
50 } |
|
51 |
|
52 public HeapCellLargestRectangleCalculator( HeapRenderingNavigator aNavigator, int aStartingBoxNumber ) |
|
53 { |
|
54 aNavigator.iNavBegin += new HeapCtrlLib.Utilities.HeapRenderingNavigator.NavBegin( Navigator_NavBegin ); |
|
55 aNavigator.iNavEnd += new HeapCtrlLib.Utilities.HeapRenderingNavigator.NavEnd( Navigator_NavEnd ); |
|
56 aNavigator.iNavHeapCellBegin += new HeapCtrlLib.Utilities.HeapRenderingNavigator.NavHeapCellBegin( Navigator_NavHeapCellBegin ); |
|
57 aNavigator.iNavHeapCellEnd += new HeapCtrlLib.Utilities.HeapRenderingNavigator.NavHeapCellEnd( Navigator_NavHeapCellEnd ); |
|
58 aNavigator.iNavNewColumn += new HeapCtrlLib.Utilities.HeapRenderingNavigator.NavNewColumn( Navigator_NavNewColumn ); |
|
59 aNavigator.iNavNewRowBody += new HeapCtrlLib.Utilities.HeapRenderingNavigator.NavNewRowBody( Navigator_NavNewRowBody ); |
|
60 // |
|
61 iStartingBoxNumber = aStartingBoxNumber; |
|
62 } |
|
63 #endregion |
|
64 |
|
65 #region API |
|
66 #endregion |
|
67 |
|
68 #region Properties |
|
69 public Rectangle Rectangle |
|
70 { |
|
71 get { return new Rectangle( iPosition, iSize ); } |
|
72 } |
|
73 |
|
74 public int NumberOfContinuousBoxes |
|
75 { |
|
76 get { return iMaxRunLength; } |
|
77 } |
|
78 #endregion |
|
79 |
|
80 #region Navigator call backs |
|
81 public void Navigator_NavBegin() |
|
82 { |
|
83 } |
|
84 |
|
85 public void Navigator_NavEnd() |
|
86 { |
|
87 } |
|
88 |
|
89 public void Navigator_NavHeapCellBegin( HeapCell aCell, uint aAddress, Point aPosition, Size aDimensions, Size aBoxSize, Size aPadding ) |
|
90 { |
|
91 CaptureStart( aPosition, aBoxSize, aPadding ); |
|
92 } |
|
93 |
|
94 public void Navigator_NavHeapCellEnd( HeapCell aCell, HeapCellMetaData aMetaData, uint aAddress, Point aPosition, Size aDimensions, Size aBoxSize, Size aPadding ) |
|
95 { |
|
96 } |
|
97 |
|
98 public void Navigator_NavNewRowBody( HeapCellMetaData aMetaData, uint aAddress, Point aPosition, Size aDimensions, Size aBoxSize, Size aPadding ) |
|
99 { |
|
100 if ( aAddress == 0x700144 ) |
|
101 { int x = 0; x++; } |
|
102 |
|
103 if ( !iFoundMaximumSize ) |
|
104 { |
|
105 if ( aMetaData.CellRowIndex == 1 ) |
|
106 { |
|
107 // If the last row was just a few items and this second row has |
|
108 // more (or it is a complete row) then we start the tracing again |
|
109 // from the beginning. |
|
110 int remaining = aMetaData.RemainingBoxes; |
|
111 if ( remaining > iMaxRunLength ) |
|
112 { |
|
113 // Reset - this row is longer |
|
114 if ( iMaxRunLength < aDimensions.Width ) |
|
115 { |
|
116 iMaxRunLength = 0; |
|
117 iPosition = aPosition; |
|
118 iSize = new Size( 0, aBoxSize.Height + aPadding.Height ); // aBoxSize + aPadding; |
|
119 } |
|
120 else |
|
121 { |
|
122 iSize.Width = 0; |
|
123 iSize.Height += aBoxSize.Height + aPadding.Height; |
|
124 } |
|
125 } |
|
126 else |
|
127 { |
|
128 iFoundMaximumSize = true; |
|
129 } |
|
130 } |
|
131 else if ( aMetaData.RemainingBoxes > aDimensions.Width ) |
|
132 { |
|
133 iSize.Width = 0; |
|
134 iSize.Height += aBoxSize.Height + aPadding.Height; |
|
135 } |
|
136 else |
|
137 { |
|
138 iFoundMaximumSize = true; |
|
139 } |
|
140 } |
|
141 } |
|
142 |
|
143 public void Navigator_NavNewColumn( HeapCell aCell, HeapCellMetaData aMetaData, uint aAddress, Point aPixelPos, Point aBoxPos, Size aDimensions, Size aBoxSize, Size aPadding ) |
|
144 { |
|
145 if ( aCell.Address == 0x700144 ) |
|
146 { int x=0; x++; } |
|
147 |
|
148 if ( !iFoundMaximumSize ) |
|
149 { |
|
150 // If we must exclude the first box from our rectangle calculations, |
|
151 // then begin the capture process again. |
|
152 if ( aMetaData.CellBoxIndex == iStartingBoxNumber ) |
|
153 { |
|
154 CaptureStart( aPixelPos, aBoxSize, aPadding ); |
|
155 } |
|
156 // |
|
157 ++iMaxRunLength; |
|
158 iSize.Width += aBoxSize.Width + aPadding.Width; |
|
159 } |
|
160 } |
|
161 #endregion |
|
162 |
|
163 #region Internal methods |
|
164 private void CaptureStart( Point aPosition, Size aBoxSize, Size aPadding ) |
|
165 { |
|
166 iFoundMaximumSize = false; |
|
167 iPosition = aPosition; |
|
168 iMaxRunLength = 0; |
|
169 iSize = new Size( 0, aBoxSize.Height + aPadding.Height ); |
|
170 } |
|
171 #endregion |
|
172 |
|
173 #region Data members |
|
174 private readonly int iStartingBoxNumber; |
|
175 private bool iFoundMaximumSize = false; |
|
176 private int iMaxRunLength = 0; |
|
177 private Size iSize = new Size(); |
|
178 private Point iPosition = new Point(); |
|
179 #endregion |
|
180 } |
|
181 } |