|
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 System.Text; |
|
45 using SymbianStructuresLib.Debug.Symbols; |
|
46 using HeapLib; |
|
47 using HeapLib.Cells; |
|
48 using HeapLib.Array; |
|
49 |
|
50 namespace HeapUiLib.Controls |
|
51 { |
|
52 public class HeapCellListingControl : System.Windows.Forms.UserControl |
|
53 { |
|
54 #region Component Designer generated code |
|
55 private XPTable.Models.Table iTable; |
|
56 private XPTable.Models.TableModel iTableModel; |
|
57 private XPTable.Models.ColumnModel iColumnModel; |
|
58 private XPTable.Models.TextColumn iCol_Type; |
|
59 private XPTable.Models.TextColumn iCol_Address; |
|
60 private XPTable.Models.TextColumn iCol_Length; |
|
61 private XPTable.Models.TextColumn iCol_Symbol; |
|
62 private XPTable.Models.TextColumn iCol_Index; |
|
63 private XPTable.Models.TextColumn iCol_DescriptorLength; |
|
64 private System.ComponentModel.Container components = null; |
|
65 #endregion |
|
66 |
|
67 #region Constructors & destructor |
|
68 public HeapCellListingControl() |
|
69 { |
|
70 InitializeComponent(); |
|
71 } |
|
72 |
|
73 protected override void Dispose( bool disposing ) |
|
74 { |
|
75 if( disposing ) |
|
76 { |
|
77 if(components != null) |
|
78 { |
|
79 components.Dispose(); |
|
80 } |
|
81 } |
|
82 base.Dispose( disposing ); |
|
83 } |
|
84 #endregion |
|
85 |
|
86 #region Component Designer generated code |
|
87 private void InitializeComponent() |
|
88 { |
|
89 XPTable.Models.DataSourceColumnBinder dataSourceColumnBinder1 = new XPTable.Models.DataSourceColumnBinder(); |
|
90 this.iTable = new XPTable.Models.Table(); |
|
91 this.iColumnModel = new XPTable.Models.ColumnModel(); |
|
92 this.iCol_Index = new XPTable.Models.TextColumn(); |
|
93 this.iCol_Type = new XPTable.Models.TextColumn(); |
|
94 this.iCol_Address = new XPTable.Models.TextColumn(); |
|
95 this.iCol_Length = new XPTable.Models.TextColumn(); |
|
96 this.iCol_DescriptorLength = new XPTable.Models.TextColumn(); |
|
97 this.iCol_Symbol = new XPTable.Models.TextColumn(); |
|
98 this.iTableModel = new XPTable.Models.TableModel(); |
|
99 ( (System.ComponentModel.ISupportInitialize) ( this.iTable ) ).BeginInit(); |
|
100 this.SuspendLayout(); |
|
101 // |
|
102 // iTable |
|
103 // |
|
104 this.iTable.AlternatingRowColor = System.Drawing.Color.Gainsboro; |
|
105 this.iTable.BorderColor = System.Drawing.Color.Black; |
|
106 this.iTable.ColumnModel = this.iColumnModel; |
|
107 this.iTable.DataMember = null; |
|
108 this.iTable.DataSourceColumnBinder = dataSourceColumnBinder1; |
|
109 this.iTable.Dock = System.Windows.Forms.DockStyle.Fill; |
|
110 this.iTable.EditStartAction = XPTable.Editors.EditStartAction.CustomKey; |
|
111 this.iTable.EnableToolTips = true; |
|
112 this.iTable.Font = new System.Drawing.Font( "Lucida Console", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ( (byte) ( 0 ) ) ); |
|
113 this.iTable.FullRowSelect = true; |
|
114 this.iTable.HeaderFont = new System.Drawing.Font( "Tahoma", 6.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ( (byte) ( 0 ) ) ); |
|
115 this.iTable.Location = new System.Drawing.Point( 0, 0 ); |
|
116 this.iTable.MultiSelect = true; |
|
117 this.iTable.Name = "iTable"; |
|
118 this.iTable.NoItemsText = "No Data"; |
|
119 this.iTable.NoItemsTextColor = System.Drawing.SystemColors.ControlText; |
|
120 this.iTable.NoItemsTextFont = new System.Drawing.Font( "Tahoma", 8.25F ); |
|
121 this.iTable.Size = new System.Drawing.Size( 791, 336 ); |
|
122 this.iTable.TabIndex = 0; |
|
123 this.iTable.TableModel = this.iTableModel; |
|
124 this.iTable.UnfocusedBorderColor = System.Drawing.Color.Black; |
|
125 this.iTable.PrepareForSort += new XPTable.Events.SortEventHandler( this.iTable_PrepareForSort ); |
|
126 this.iTable.KeyDown += new System.Windows.Forms.KeyEventHandler( this.iTable_KeyDown ); |
|
127 this.iTable.DoubleClick += new System.EventHandler( this.iTable_DoubleClick ); |
|
128 // |
|
129 // iColumnModel |
|
130 // |
|
131 this.iColumnModel.Columns.AddRange( new XPTable.Models.Column[] { |
|
132 this.iCol_Index, |
|
133 this.iCol_Type, |
|
134 this.iCol_Address, |
|
135 this.iCol_Length, |
|
136 this.iCol_DescriptorLength, |
|
137 this.iCol_Symbol} ); |
|
138 // |
|
139 // iCol_Index |
|
140 // |
|
141 this.iCol_Index.Alignment = XPTable.Models.ColumnAlignment.Center; |
|
142 this.iCol_Index.ContentWidth = 0; |
|
143 // |
|
144 // iCol_Type |
|
145 // |
|
146 this.iCol_Type.ContentWidth = 29; |
|
147 this.iCol_Type.Text = "Type"; |
|
148 this.iCol_Type.Width = 85; |
|
149 // |
|
150 // iCol_Address |
|
151 // |
|
152 this.iCol_Address.Alignment = XPTable.Models.ColumnAlignment.Center; |
|
153 this.iCol_Address.ContentWidth = 46; |
|
154 this.iCol_Address.Text = "Address"; |
|
155 this.iCol_Address.Width = 85; |
|
156 // |
|
157 // iCol_Length |
|
158 // |
|
159 this.iCol_Length.Alignment = XPTable.Models.ColumnAlignment.Right; |
|
160 this.iCol_Length.ContentWidth = 39; |
|
161 this.iCol_Length.Text = "Length"; |
|
162 this.iCol_Length.Width = 85; |
|
163 // |
|
164 // iCol_DescriptorLength |
|
165 // |
|
166 this.iCol_DescriptorLength.Alignment = XPTable.Models.ColumnAlignment.Right; |
|
167 this.iCol_DescriptorLength.ContentWidth = 53; |
|
168 this.iCol_DescriptorLength.Text = "Des. Len."; |
|
169 this.iCol_DescriptorLength.Width = 85; |
|
170 // |
|
171 // iCol_Symbol |
|
172 // |
|
173 this.iCol_Symbol.ContentWidth = 70; |
|
174 this.iCol_Symbol.Text = "Object Name"; |
|
175 this.iCol_Symbol.Width = 350; |
|
176 // |
|
177 // HeapCellListingControl |
|
178 // |
|
179 this.Controls.Add( this.iTable ); |
|
180 this.Font = new System.Drawing.Font( "Tahoma", 8.25F ); |
|
181 this.Name = "HeapCellListingControl"; |
|
182 this.Size = new System.Drawing.Size( 791, 336 ); |
|
183 ( (System.ComponentModel.ISupportInitialize) ( this.iTable ) ).EndInit(); |
|
184 this.ResumeLayout( false ); |
|
185 |
|
186 } |
|
187 #endregion |
|
188 |
|
189 #region API |
|
190 public void SetFilter( TFilterType aType ) |
|
191 { |
|
192 SetFilter( aType, null ); |
|
193 } |
|
194 |
|
195 public void SetFilter( TFilterType aType, Symbol aSymbol ) |
|
196 { |
|
197 iFilterType = aType; |
|
198 iFilterSymbol = aSymbol; |
|
199 // |
|
200 iCol_DescriptorLength.Visible = ( aType == TFilterType.EFilterShowCellsAllocatedDescriptor ); |
|
201 // |
|
202 UpdateListView(); |
|
203 } |
|
204 |
|
205 public void CopySelectedDataToClipboard() |
|
206 { |
|
207 StringBuilder clipboardText = new StringBuilder(); |
|
208 |
|
209 // Get columns |
|
210 foreach( XPTable.Models.Column column in iTable.ColumnModel.Columns ) |
|
211 { |
|
212 clipboardText.Append( column.Text + "\t" ); |
|
213 } |
|
214 clipboardText.Append( System.Environment.NewLine ); |
|
215 |
|
216 // Do underline (there must be a better way!) |
|
217 int len = clipboardText.Length; |
|
218 for( int i=0; i<len; i++ ) |
|
219 { |
|
220 clipboardText.Append( "=" ); |
|
221 } |
|
222 clipboardText.Append( System.Environment.NewLine ); |
|
223 |
|
224 // Get cell values |
|
225 foreach( XPTable.Models.Row row in iTable.SelectedItems ) |
|
226 { |
|
227 foreach( XPTable.Models.Cell cell in row.Cells ) |
|
228 { |
|
229 string text = cell.Text; |
|
230 clipboardText.Append( text + "\t" ); |
|
231 } |
|
232 // |
|
233 clipboardText.Append( System.Environment.NewLine ); |
|
234 } |
|
235 // |
|
236 Clipboard.SetDataObject( clipboardText.ToString(), true ); |
|
237 } |
|
238 #endregion |
|
239 |
|
240 #region Properties |
|
241 [Browsable( false )] |
|
242 public HeapCell SelectedCell |
|
243 { |
|
244 get |
|
245 { |
|
246 HeapCell cell = null; |
|
247 // |
|
248 if ( iTable.SelectedItems.Length > 0 ) |
|
249 { |
|
250 int index = iTable.SelectedIndicies[ 0 ]; |
|
251 cell = iTable.TableModel.Rows[ index ].Tag as HeapCell; |
|
252 } |
|
253 // |
|
254 return cell; |
|
255 } |
|
256 set |
|
257 { |
|
258 foreach ( XPTable.Models.Row row in iTable.TableModel.Rows ) |
|
259 { |
|
260 HeapCell cell = (HeapCell) row.Tag; |
|
261 // |
|
262 if ( cell.Address == value.Address ) |
|
263 { |
|
264 iTable.EnsureVisible( row.Index, 0 ); |
|
265 iTable.TableModel.Selections.Clear(); |
|
266 iTable.TableModel.Selections.AddCell( row.Index, 0 ); |
|
267 break; |
|
268 } |
|
269 } |
|
270 } |
|
271 } |
|
272 |
|
273 [Browsable( false )] |
|
274 public HeapCellArray Cells |
|
275 { |
|
276 get { return iCells; } |
|
277 set |
|
278 { |
|
279 iCells = value; |
|
280 UpdateListView(); |
|
281 } |
|
282 } |
|
283 #endregion |
|
284 |
|
285 #region Event handlers |
|
286 private void iTable_DoubleClick( object sender, System.EventArgs e ) |
|
287 { |
|
288 OnDoubleClick( e ); |
|
289 } |
|
290 |
|
291 private void iTable_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e ) |
|
292 { |
|
293 OnKeyDown( e ); |
|
294 } |
|
295 |
|
296 private void iTable_PrepareForSort( object sender, XPTable.Events.SortEventArgs e ) |
|
297 { |
|
298 if ( e.Column == iCol_Length ) |
|
299 { |
|
300 e.Comparer = new XPTable.Sorting.NumberComparer( iTable.TableModel, e.Index, e.Column.SortOrder ); |
|
301 } |
|
302 else if ( e.Column == iCol_DescriptorLength ) |
|
303 { |
|
304 e.Comparer = new XPTable.Sorting.NumberComparer( iTable.TableModel, e.Index, e.Column.SortOrder ); |
|
305 } |
|
306 else |
|
307 { |
|
308 e.Comparer = new XPTable.Sorting.TextComparer( iTable.TableModel, e.Index, e.Column.SortOrder ); |
|
309 } |
|
310 } |
|
311 #endregion |
|
312 |
|
313 #region Internal methods |
|
314 private void UpdateListView() |
|
315 { |
|
316 iTable.BeginUpdate(); |
|
317 iTable.TableModel.Rows.Clear(); |
|
318 // |
|
319 int index = 0; |
|
320 foreach( HeapCell cell in Cells ) |
|
321 { |
|
322 // Check whether the filter permits this item to be included. |
|
323 if ( CheckAgainstFilter( cell ) ) |
|
324 { |
|
325 XPTable.Models.Row row = new XPTable.Models.Row(); |
|
326 row.Tag = cell; |
|
327 // |
|
328 row.Cells.Add( new XPTable.Models.Cell( index.ToString( "d6" ) ) ); |
|
329 XPTable.Models.Cell cellType = new XPTable.Models.Cell( " " + cell.TypeString ); |
|
330 if ( cell.Type == HeapCell.TType.EAllocated ) |
|
331 { |
|
332 if ( cell.IsDescriptor ) |
|
333 { |
|
334 cellType.ForeColor = Color.DarkGoldenrod; |
|
335 cellType.ToolTipText = "Descriptor"; |
|
336 } |
|
337 else |
|
338 { |
|
339 cellType.ForeColor = Color.Red; |
|
340 } |
|
341 } |
|
342 else if ( cell.Type == HeapCell.TType.EFree ) |
|
343 { |
|
344 cellType.ForeColor = Color.Blue; |
|
345 } |
|
346 row.Cells.Add( cellType ); |
|
347 row.Cells.Add( new XPTable.Models.Cell( "0x" + cell.Address.ToString( "x8" ) ) ); |
|
348 |
|
349 // Must initialise "data" in order for sorting to work (XPTable's numeric sorter relies upon it). |
|
350 XPTable.Models.Cell cellLength = new XPTable.Models.Cell( cell.Length.ToString() ); |
|
351 cellLength.Data = cell.Length; |
|
352 row.Cells.Add( cellLength ); |
|
353 |
|
354 // If we are filtering to show only descriptor entries, then we also include an extra |
|
355 // column containing the descriptor length. |
|
356 if ( iFilterType == TFilterType.EFilterShowCellsAllocatedDescriptor ) |
|
357 { |
|
358 if ( cell.IsDescriptor ) |
|
359 { |
|
360 // Must initialise "data" in order for sorting to work (XPTable's numeric sorter relies upon it). |
|
361 XPTable.Models.Cell cellDescriptorLength = new XPTable.Models.Cell( cell.DescriptorLength.ToString() ); |
|
362 cellDescriptorLength.Data = cell.DescriptorLength; |
|
363 row.Cells.Add( cellDescriptorLength ); |
|
364 } |
|
365 else |
|
366 { |
|
367 row.Cells.Add( new XPTable.Models.Cell( string.Empty ) ); |
|
368 } |
|
369 } |
|
370 else |
|
371 { |
|
372 row.Cells.Add( new XPTable.Models.Cell( string.Empty ) ); |
|
373 } |
|
374 |
|
375 // Payload column |
|
376 if ( cell.IsDescriptor ) |
|
377 { |
|
378 row.Cells.Add( new XPTable.Models.Cell( cell.DescriptorText ) ); |
|
379 } |
|
380 else if ( cell.Symbol != null ) |
|
381 { |
|
382 row.Cells.Add( new XPTable.Models.Cell( cell.SymbolString ) ); |
|
383 } |
|
384 else |
|
385 { |
|
386 row.Cells.Add( new XPTable.Models.Cell( cell.RawItems.FirstLine ) ); |
|
387 } |
|
388 // |
|
389 iTable.TableModel.Rows.Add( row ); |
|
390 |
|
391 ++index; |
|
392 } |
|
393 } |
|
394 |
|
395 // Must sort if the user had previously selected a sort column |
|
396 if ( iTable.IsValidColumn( iTable.SortingColumn ) ) |
|
397 { |
|
398 iTable.Sort(); |
|
399 } |
|
400 |
|
401 // Done - end transaction & redraw |
|
402 iTable.EndUpdate(); |
|
403 } |
|
404 |
|
405 private bool CheckAgainstFilter( HeapCell aCell ) |
|
406 { |
|
407 bool ret = false; |
|
408 // |
|
409 if ( iFilterType == TFilterType.EFilterShowAll ) |
|
410 { |
|
411 ret = true; |
|
412 } |
|
413 else if ( iFilterType == TFilterType.EFilterShowCellsFree && aCell.Type == HeapCell.TType.EFree ) |
|
414 { |
|
415 ret = true; |
|
416 } |
|
417 else if ( iFilterType == TFilterType.EFilterShowCellsAllocated && aCell.Type == HeapCell.TType.EAllocated ) |
|
418 { |
|
419 ret = true; |
|
420 } |
|
421 else if ( iFilterType == TFilterType.EFilterShowCellsAllocatedDescriptor && aCell.Type == HeapCell.TType.EAllocated && aCell.IsDescriptor ) |
|
422 { |
|
423 ret = true; |
|
424 } |
|
425 else if ( iFilterType == TFilterType.EFilterShowCellsAllocatedByType && aCell.Type == HeapCell.TType.EAllocated ) |
|
426 { |
|
427 bool noSymbol = ( iFilterSymbol == null || iFilterSymbol.Address == 0 ); |
|
428 bool descriptor = aCell.IsDescriptor; |
|
429 // |
|
430 if ( !descriptor ) |
|
431 { |
|
432 if ( noSymbol && aCell.Symbol == null ) |
|
433 { |
|
434 ret = true; |
|
435 } |
|
436 else if ( iFilterSymbol != null && aCell.Symbol != null ) |
|
437 { |
|
438 ret = ( aCell.Symbol.Address == iFilterSymbol.Address ); |
|
439 } |
|
440 } |
|
441 } |
|
442 // |
|
443 return ret; |
|
444 } |
|
445 #endregion |
|
446 |
|
447 #region Data members |
|
448 private TFilterType iFilterType = TFilterType.EFilterShowAll; |
|
449 private Symbol iFilterSymbol = null; |
|
450 private HeapCellArray iCells = new HeapCellArray(); |
|
451 #endregion |
|
452 } |
|
453 } |