sysperfana/heapanalyser/Libraries/Engine/HeapLib/Output_HTML/HeapToHTMLPageJavaScriptManager.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.IO;
       
    40 using System.Text;
       
    41 using System.Collections;
       
    42 using SymbianUtils;
       
    43 using HeapLib.Array;
       
    44 using HeapLib.Reconstructor;
       
    45 
       
    46 namespace HeapLib
       
    47 {
       
    48 	public class HeapToHTMLPageJavaScriptManager : AsyncTextWriterBase
       
    49 	{
       
    50 		#region Constructors & destructor
       
    51 		public HeapToHTMLPageJavaScriptManager( HeapReconstructor aReconstructor, string aBasePath )
       
    52 		{
       
    53 			iReconstructor = aReconstructor;
       
    54 			iEntries = iReconstructor.Data;
       
    55 			iBasePath = aBasePath;
       
    56 		}
       
    57 		#endregion
       
    58 		
       
    59 		#region API
       
    60 		public static string JavaScriptHelperFileName
       
    61 		{
       
    62 			get { return "HeapDataJavaScriptLib.js"; }
       
    63 		}
       
    64 
       
    65 		public static string MakeToolTipLink( string aToolTipTitle, string aToolTipBody, string aUrl, string aWindowTarget, string aLinkText )
       
    66 		{
       
    67 			string javaScript = JavaScript( aToolTipTitle, aToolTipBody );
       
    68 			
       
    69 			StringBuilder ret = new StringBuilder();
       
    70 			//
       
    71 			ret.Append( "<a href=\"" + aUrl + "\" " );
       
    72 			if	( aWindowTarget != string.Empty )
       
    73 			{
       
    74 				ret.Append( "target=\"" + aWindowTarget + "\" " );
       
    75 			}
       
    76 			ret.Append( javaScript );
       
    77 			ret.Append( ">" );
       
    78 			ret.Append( aLinkText );
       
    79 			ret.Append( "</a>" );
       
    80 			//
       
    81 			return ret.ToString();
       
    82 		}
       
    83 
       
    84 		public static string MakeToolTipDiv( string aToolTipTitle, string aToolTipBody, string aDivText )
       
    85 		{
       
    86 			return MakeToolTipDiv( aToolTipTitle, aToolTipBody, aDivText, -1 );
       
    87 		}
       
    88 
       
    89 		public static string MakeToolTipDiv( string aToolTipTitle, string aToolTipBody, string aDivText, int aWidth )
       
    90 		{
       
    91 			string javaScript = JavaScript( aToolTipTitle, aToolTipBody, aWidth);
       
    92 			
       
    93 			StringBuilder ret = new StringBuilder();
       
    94 			//
       
    95 			ret.Append( "<div " + javaScript + ">" );
       
    96 			ret.Append( aDivText );
       
    97 			ret.Append( "</div>" );
       
    98 			//
       
    99 			return ret.ToString();
       
   100 		}
       
   101 		#endregion
       
   102 
       
   103 		#region Internal methods
       
   104 		private static string JavaScript( string aTooltipTitle, string aToolTipBody )
       
   105 		{
       
   106 			return JavaScript( aTooltipTitle, aToolTipBody, -1 );
       
   107 		}
       
   108 
       
   109 		private static string JavaScript( string aTooltipTitle, string aToolTipBody, int aWidth )
       
   110 		{
       
   111 			string onMouseOver = " onmouseover=\"showInfo(\'" + aTooltipTitle + "\', \'" + aToolTipBody + "\'";
       
   112 			if	( aWidth > 0 )
       
   113 			{
       
   114 				onMouseOver += ", \'" + aWidth.ToString() + "\'";
       
   115 			}
       
   116 			onMouseOver += ")\"";
       
   117 			//
       
   118 			string onMouseOut = " onmouseout=\"hideInfo()\"";
       
   119 			string onFocus = " onfocus=\"this.blur()\"";
       
   120 			string javaScript = onMouseOver + onMouseOut + onFocus;
       
   121 			//
       
   122 			return javaScript;
       
   123 		}
       
   124 		#endregion
       
   125 
       
   126 		#region From AsyncTextWriterBase
       
   127         public override long Size
       
   128 		{
       
   129 			get
       
   130 			{
       
   131 				return 2;
       
   132 			}
       
   133 		}
       
   134 
       
   135         public override long Position
       
   136 		{
       
   137 			get
       
   138 			{
       
   139 				return iPosition;
       
   140 			}
       
   141 		}
       
   142 
       
   143         public override void ExportData()
       
   144 		{
       
   145 			string javaScriptLibSourceFileName = Path.Combine( System.Windows.Forms.Application.StartupPath, JavaScriptHelperFileName );
       
   146 			if	( File.Exists( javaScriptLibSourceFileName ) == false )
       
   147 			{
       
   148 				throw new FileNotFoundException( "Cannot locate Heap Data java script library", javaScriptLibSourceFileName );
       
   149 			}
       
   150 
       
   151 			string javaScriptLibFileNameHeapData = Path.Combine( HeapToHTMLConverter.PageDirectoryNameEnsuringPathExists( iBasePath, "HeapData" ), JavaScriptHelperFileName );
       
   152 			File.Copy( javaScriptLibSourceFileName, javaScriptLibFileNameHeapData, true );
       
   153 			iPosition++;
       
   154 
       
   155 			string javaScriptLibFileNameHeapLinkInfo = Path.Combine( HeapToHTMLConverter.PageDirectoryNameEnsuringPathExists( iBasePath, "HeapLinkInfo" ), JavaScriptHelperFileName );
       
   156 			File.Copy( javaScriptLibSourceFileName, javaScriptLibFileNameHeapLinkInfo, true );
       
   157 			iPosition++;
       
   158 		}
       
   159 		#endregion
       
   160 
       
   161 		#region Data members
       
   162 		private readonly HeapReconstructor iReconstructor;
       
   163 		private readonly HeapCellArray iEntries;
       
   164 		private readonly string iBasePath;
       
   165 		private long iPosition = 0;
       
   166 		#endregion
       
   167 	}
       
   168 }