|
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.Collections; |
|
40 using System.ComponentModel; |
|
41 using System.Drawing; |
|
42 using System.Data; |
|
43 using System.Windows.Forms; |
|
44 using HeapLib.Cells; |
|
45 using HeapLib.Reconstructor; |
|
46 using HeapCtrlLib.Renderers; |
|
47 using HeapCtrlLib.Types; |
|
48 using HeapLib; |
|
49 using HeapLib.Array; |
|
50 using SymbianUtils.RawItems; |
|
51 |
|
52 namespace HeapCtrlLib |
|
53 { |
|
54 public class HeapDataControl : System.Windows.Forms.UserControl |
|
55 { |
|
56 #region Delegates & events |
|
57 public delegate void OnCellSelected( HeapCell aCell ); |
|
58 public event OnCellSelected CellSelected; |
|
59 public delegate void OnCellDoubleClicked( HeapCell aCell ); |
|
60 public event OnCellDoubleClicked CellDoubleClicked; |
|
61 public delegate void CellRightClickedHandler( HeapCell aCell, RawItem aRawItem, Point aScreenPos ); |
|
62 public event CellRightClickedHandler CellRightClicked; |
|
63 #endregion |
|
64 |
|
65 #region Windows Form Designer code |
|
66 private System.ComponentModel.Container components = null; |
|
67 private HeapCtrlLib.Renderers.HeapDataRenderer iRenderer = null; |
|
68 private SymbianUtilsUi.Controls.ScrollBarWithoutKeyConsumption iSB_Vertical = null; |
|
69 #endregion |
|
70 |
|
71 #region Constructors & destructor |
|
72 public HeapDataControl() |
|
73 { |
|
74 InitializeComponent(); |
|
75 // |
|
76 // this.SetStyle(ControlStyles.DoubleBuffer, true); |
|
77 // this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); |
|
78 // this.SetStyle(ControlStyles.UserPaint, true); |
|
79 this.SetStyle(ControlStyles.ResizeRedraw, true); |
|
80 } |
|
81 |
|
82 protected override void Dispose( bool disposing ) |
|
83 { |
|
84 if( disposing ) |
|
85 { |
|
86 if(components != null) |
|
87 { |
|
88 components.Dispose(); |
|
89 } |
|
90 } |
|
91 base.Dispose( disposing ); |
|
92 } |
|
93 #endregion |
|
94 |
|
95 #region Component Designer generated code |
|
96 private void InitializeComponent() |
|
97 { |
|
98 this.iRenderer = new HeapDataRenderer(); |
|
99 this.iSB_Vertical = new SymbianUtilsUi.Controls.ScrollBarWithoutKeyConsumption(); |
|
100 this.SuspendLayout(); |
|
101 // |
|
102 // iSB_Vertical |
|
103 // |
|
104 this.iSB_Vertical.Dock = System.Windows.Forms.DockStyle.Right; |
|
105 this.iSB_Vertical.Location = new System.Drawing.Point( 598, 2 ); |
|
106 this.iSB_Vertical.Name = "iSB_Vertical"; |
|
107 this.iSB_Vertical.Size = new System.Drawing.Size( 16, 156 ); |
|
108 this.iSB_Vertical.TabIndex = 2; |
|
109 this.iSB_Vertical.Scroll += new System.Windows.Forms.ScrollEventHandler( this.iSB_Vertical_Scroll ); |
|
110 // |
|
111 // iRenderer |
|
112 // |
|
113 this.iRenderer.Address = ( (uint) ( 0u ) ); |
|
114 this.iRenderer.Anchor = ( (System.Windows.Forms.AnchorStyles) ( ( ( ( System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom ) |
|
115 | System.Windows.Forms.AnchorStyles.Left ) |
|
116 | System.Windows.Forms.AnchorStyles.Right ) ) ); |
|
117 this.iRenderer.FocusedCell = null; |
|
118 this.iRenderer.Location = new System.Drawing.Point( 3, 3 ); |
|
119 this.iRenderer.Name = "iRenderer"; |
|
120 this.iRenderer.Reconstructor = null; |
|
121 this.iRenderer.Size = new System.Drawing.Size( 596, 154 ); |
|
122 this.iRenderer.TabIndex = 1; |
|
123 this.iRenderer.Zoom = HeapCtrlLib.Types.THeapCtrlZoom.EHeapCtrlZoomMedium; |
|
124 this.iRenderer.Enter += new System.EventHandler( this.iRenderer_Enter ); |
|
125 this.iRenderer.AddressChanged += new HeapCtrlLib.Renderers.HeapDataRenderer.AddressChangeHandler( this.iRenderer_AddressChanged ); |
|
126 this.iRenderer.Leave += new System.EventHandler( this.iRenderer_Leave ); |
|
127 this.iRenderer.CellSelected += new HeapCtrlLib.Renderers.HeapDataRenderer.CellSelectionHandler( this.iRenderer_CellSelected ); |
|
128 this.iRenderer.CellRightClicked += new HeapDataRenderer.CellRightClickedHandler( iRenderer_CellRightClicked ); |
|
129 this.iRenderer.CellDoubleClicked += new HeapDataRenderer.CellDoubleClickHandler( iRenderer_CellDoubleClicked ); |
|
130 // |
|
131 // HeapDataControl |
|
132 // |
|
133 this.Controls.Add( this.iSB_Vertical ); |
|
134 this.Controls.Add( this.iRenderer ); |
|
135 this.Name = "HeapDataControl"; |
|
136 this.Padding = new System.Windows.Forms.Padding( 2 ); |
|
137 this.Size = new System.Drawing.Size( 616, 160 ); |
|
138 this.SizeChanged += new System.EventHandler( this.HeapDataControl_SizeChanged ); |
|
139 this.ResumeLayout( false ); |
|
140 } |
|
141 #endregion |
|
142 |
|
143 #region API |
|
144 public void SetupFilters() |
|
145 { |
|
146 iRenderer.SetupFilters(); |
|
147 } |
|
148 |
|
149 public void BreadcrumbsChanged() |
|
150 { |
|
151 iRenderer.Invalidate(); |
|
152 } |
|
153 #endregion |
|
154 |
|
155 #region Properties |
|
156 public THeapCtrlZoom Zoom |
|
157 { |
|
158 get { return iRenderer.Zoom; } |
|
159 set |
|
160 { |
|
161 iRenderer.Zoom = value; |
|
162 |
|
163 // Force repositioning to top of view. |
|
164 Reconstructor = Reconstructor; |
|
165 } |
|
166 } |
|
167 |
|
168 public THeapCtrlRenderingType Type |
|
169 { |
|
170 get { return iType; } |
|
171 set |
|
172 { |
|
173 if ( iType != value ) |
|
174 { |
|
175 iType = value; |
|
176 iRenderer.LoadTypeSet( iType ); |
|
177 iRenderer.Invalidate(); |
|
178 } |
|
179 } |
|
180 } |
|
181 |
|
182 [Browsable(false)] |
|
183 internal Size CellBoxSize |
|
184 { |
|
185 get { return iRenderer.CellBoxSize; } |
|
186 set { iRenderer.CellBoxSize = value; } |
|
187 } |
|
188 |
|
189 [Browsable(false)] |
|
190 internal Size CellPadding |
|
191 { |
|
192 get { return iRenderer.CellPadding; } |
|
193 set { iRenderer.CellPadding = value; } |
|
194 } |
|
195 |
|
196 [Browsable(false)] |
|
197 public HeapReconstructor Reconstructor |
|
198 { |
|
199 get |
|
200 { |
|
201 return iReconstructor; |
|
202 } |
|
203 set |
|
204 { |
|
205 iReconstructor = value; |
|
206 iRenderer.Reconstructor = value; |
|
207 SetupScrollBar(); |
|
208 // |
|
209 Invalidate(); |
|
210 } |
|
211 } |
|
212 |
|
213 [Browsable(false)] |
|
214 public HeapCell FocusedCell |
|
215 { |
|
216 get { return iRenderer.FocusedCell; } |
|
217 set { iRenderer.FocusedCell = value; } |
|
218 } |
|
219 |
|
220 [Browsable(false)] |
|
221 public bool SupportsFiltering |
|
222 { |
|
223 get { return iRenderer.SupportsFiltering; } |
|
224 } |
|
225 |
|
226 [Browsable( false )] |
|
227 public HeapCellArrayBase BreadcrumbCellsOutgoing |
|
228 { |
|
229 get { return iRenderer.BreadcrumbCellsOutgoing; } |
|
230 } |
|
231 |
|
232 [Browsable( false )] |
|
233 public HeapCellArrayBase BreadcrumbCellsIncoming |
|
234 { |
|
235 get { return iRenderer.BreadcrumbCellsIncoming; } |
|
236 } |
|
237 #endregion |
|
238 |
|
239 #region Drawing |
|
240 protected override void OnPaint( PaintEventArgs aArgs ) |
|
241 { |
|
242 aArgs.Graphics.Clear( Color.LightGray ); |
|
243 // |
|
244 float borderWidth = ( iRenderer.Focused ? 2.0f : 1.0f ); |
|
245 Color borderColor = ( iRenderer.Focused ? Color.Black : Color.Gray ); |
|
246 |
|
247 using( Pen borderPen = new Pen( borderColor, borderWidth ) ) |
|
248 { |
|
249 aArgs.Graphics.DrawRectangle( borderPen, 0, 0, ClientSize.Width-1, ClientSize.Height-1 ); |
|
250 } |
|
251 // |
|
252 base.OnPaint( aArgs ); |
|
253 } |
|
254 #endregion |
|
255 |
|
256 #region Event handlers |
|
257 private void HeapDataControl_SizeChanged(object sender, System.EventArgs e) |
|
258 { |
|
259 SetupScrollBar(); |
|
260 } |
|
261 |
|
262 private void iSB_Vertical_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e) |
|
263 { |
|
264 int rowIndex = e.NewValue; |
|
265 int bytesPerRow = iRenderer.RowsAndColumns.Width * 4; |
|
266 uint baseAddressOffset = (uint) ( bytesPerRow * rowIndex ); |
|
267 uint address = iReconstructor.Statistics.HeapAddressStart + baseAddressOffset; |
|
268 // |
|
269 iRenderer.Address = address ; |
|
270 } |
|
271 |
|
272 private void iRenderer_AddressChanged( uint aAddressOld, uint aAddressNew, HeapLib.Cells.HeapCell aFirstCell, int aFirstCellIndex ) |
|
273 { |
|
274 SetupScrollBar(); |
|
275 } |
|
276 |
|
277 private void iRenderer_Enter(object sender, System.EventArgs e) |
|
278 { |
|
279 Invalidate(); |
|
280 } |
|
281 |
|
282 private void iRenderer_Leave(object sender, System.EventArgs e) |
|
283 { |
|
284 Invalidate(); |
|
285 } |
|
286 |
|
287 private void iRenderer_CellSelected(HeapLib.Cells.HeapCell aCell) |
|
288 { |
|
289 if ( CellSelected != null ) |
|
290 { |
|
291 CellSelected( aCell ); |
|
292 } |
|
293 } |
|
294 |
|
295 private void iRenderer_CellDoubleClicked( HeapCell aCell ) |
|
296 { |
|
297 if ( CellDoubleClicked != null ) |
|
298 { |
|
299 CellDoubleClicked( aCell ); |
|
300 } |
|
301 } |
|
302 |
|
303 private void iRenderer_CellRightClicked( HeapCell aCell, RawItem aRawItem, Point aViewerPos ) |
|
304 { |
|
305 if ( CellRightClicked != null ) |
|
306 { |
|
307 Point screenPos = iRenderer.PointToScreen( aViewerPos ); |
|
308 CellRightClicked( aCell, aRawItem, screenPos ); |
|
309 } |
|
310 } |
|
311 |
|
312 /*protected override void WndProc(ref Message m) |
|
313 { |
|
314 SymbianUtilsUi.Utilities.WindowMessages.PrintMessage( "CTRL ", m.Msg ); |
|
315 base.WndProc (ref m); |
|
316 }*/ |
|
317 #endregion |
|
318 |
|
319 #region Internal methods |
|
320 private void SetupScrollBar() |
|
321 { |
|
322 Size rendererDimensions = iRenderer.RowsAndColumns; |
|
323 // |
|
324 if ( iReconstructor != null && rendererDimensions.Width > 0 && rendererDimensions.Height > 0 ) |
|
325 { |
|
326 uint extent = ( iReconstructor.Statistics.HeapAddressEnd - iReconstructor.Statistics.HeapAddressStart ); |
|
327 uint bytesPerRow = (uint) ( iRenderer.RowsAndColumns.Width * 4 ); |
|
328 uint numberOfRows = extent / bytesPerRow; |
|
329 uint rowNumber = ( iRenderer.Address - iReconstructor.Statistics.HeapAddressStart ) / bytesPerRow; |
|
330 if ( rowNumber > numberOfRows ) |
|
331 { |
|
332 rowNumber = numberOfRows; |
|
333 } |
|
334 // |
|
335 iSB_Vertical.Minimum = 0; |
|
336 iSB_Vertical.Maximum = (int) Math.Max( 0, numberOfRows ); |
|
337 iSB_Vertical.Value = (int) rowNumber; |
|
338 } |
|
339 } |
|
340 #endregion |
|
341 |
|
342 #region Data members |
|
343 private HeapReconstructor iReconstructor; |
|
344 private THeapCtrlRenderingType iType = THeapCtrlRenderingType.EHeapCtrlRenderingTypeByCell; |
|
345 #endregion |
|
346 } |
|
347 } |