PPHtmlDrawer.h
上传用户:dengkfang
上传日期:2008-12-30
资源大小:5233k
文件大小:22k
源码类别:

CA认证

开发平台:

Visual C++

  1. //
  2. // Class: CPPHtmlDrawer
  3. //
  4. // Compiler: Visual C++
  5. // Tested on: Visual C++ 6.0
  6. // Visual C++ .NET 2003
  7. //
  8. // Version: See GetVersionC() or GetVersionI()
  9. //
  10. // Created: xx/xxxx/2004
  11. // Updated: 21/November/2004
  12. //
  13. // Author: Eugene Pustovoyt pustovoyt@mail.ru
  14. //
  15. // Disclaimer
  16. // ----------
  17. // THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT
  18. // ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO REPONSIBILITIES FOR POSSIBLE
  19. // DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE
  20. // RISK OF USING THIS SOFTWARE.
  21. //
  22. // Terms of use
  23. // ------------
  24. // THIS SOFTWARE IS FREE FOR PERSONAL USE OR FREEWARE APPLICATIONS.
  25. // IF YOU WISH TO THANK MY WORK, YOU MAY DONATE ANY SUM OF MONEY TO ME 
  26. //  FOR SUPPORT OF DEVELOPMENT OF THIS CLASS.
  27. // IF YOU USE THIS SOFTWARE IN COMMERCIAL OR SHAREWARE APPLICATIONS YOU
  28. // ARE GENTLY ASKED TO DONATE ANY SUM OF MONEY TO THE AUTHOR:
  29. //
  30. //--- History ------------------------------ 
  31. // 2004/03/01  *** Releases version 1.0 ***
  32. //------------------------------------------
  33. // 2004/04/13 [ADD] Added a "speed" parameter to a <ilst> tag for animation
  34. // 2004/04/20 [ADD] For non-MFC program added STL class CStdString
  35. // 2004/05/05 [ADD] Added an EnableOutput method
  36. // [FIX] Fixed an error in SetImageList method (thanks to topus)
  37. //------------------------------------------
  38. // 2004/05/05  *** Releases version 1.1 ***
  39. //------------------------------------------
  40. // 2004/06/06 [FIX] Fixed an error on select a reference to the handle of the font
  41. // instead select a handle of the font
  42. // 2004/06/24 [ADD] Added SetMaxWidth and GetMaxWidth methods for supporting a text wrapping
  43. // [ADD] Added EnableTextWrap and IsTextWrapEnabled methods to sets a text wrap
  44. // mode or to retrieves a mode status.
  45. // [ADD] Added common character entities.
  46. // 2004/06/25 [ADD] Added SetTabSize method.
  47. // [ADD] Implemented a support to output a justified text.
  48. // [ADD] Added new <justify> tag to output a justified text.
  49. // 2004/07/18 [ADD] Support a disabled draw in the tables
  50. // 2004/09/07 [FIX] Fixed minor errors of drawing table's cells 
  51. // 2004/10/13 [FIX] The last line of the paragraph alignment on fields now is not applied
  52. // 2004/10/20 [FIX] Fixed error in GetLengthUnit method. Thanks to Reinhard Steiner
  53. // 2004/10/26 [FIX] Corrected work of the justify for the multifont text in one line
  54. //   [ADD] Support a word wrapping for the text with the images
  55. // 2004/10/28 [ADD] Now cx and cy parameters of the <ilst> tag is an optional information
  56. //------------------------------------------
  57. // 2004/10/30  *** Releases version 1.2 ***
  58. //------------------------------------------
  59. // 2004/11/30 [FIX] Fixed an error in the drawing nested tables
  60. // 2004/12/05 [CHN] Replaces CImageList to HIMAGELIST
  61. // [CHN] Replaces MFC classes (CSize, CPoint, CRect) to API structures
  62. // 2004/12/14 [FIX] Fixed an error in determinates of the hyperlink area
  63. // [FIX] Fixed an error in drawing of the horizontal line (<hr> tag)
  64. // 2005/01/15 [ADD] Not fixed columns will resize to the width of the client area
  65. // 2005/03/01 [FIX] Fixed an error of the imagelist drawing
  66. /////////////////////////////////////////////////////////////////////
  67. //
  68. // "GotoURL" function by Stuart Patterson
  69. // As seen in the August, 1997 Windows Developer's Journal.
  70. // Copyright 1997 by Miller Freeman, Inc. All rights reserved.
  71. // Modified by Chris Maunder to use TCHARs instead of chars.
  72. //
  73. // "Default hand cursor" from Paul DiLascia's Jan 1998 MSJ article.
  74. // Modified by Zorglab to use standard hand cursor on WinMe,2k,XP
  75. //
  76. /////////////////////////////////////////////////////////////////////
  77. #ifndef _PPHTMLDRAWER_H_
  78. #define _PPHTMLDRAWER_H_
  79. #if _MSC_VER > 1000
  80. #pragma once
  81. #endif // _MSC_VER > 1000
  82. // disable warning C4786: symbol greater than 255 character, okay to ignore
  83. #pragma warning(disable : 4786)
  84. #include "PPDrawManager.h"
  85. #include <vector>
  86. #include <map>
  87. #ifdef _MFC_VER
  88. #define CPPString CString //MFC program
  89. #else
  90. #include "StdString.h"
  91. #ifdef _UNICODE
  92. #define CPPString CStdStringW //non-MFC program UNICODE
  93. #else
  94. #define CPPString CStdStringA //non-MFC program ANSI
  95. #endif
  96. #endif
  97. /////////////////////////////////////////////////////////////////////////////
  98. // CPPHtmlDrawer window
  99. class CPPHtmlDrawer
  100. {
  101. // Construction
  102. public:
  103. CPPHtmlDrawer();
  104. // Attributes
  105. public:
  106. // Operations
  107. public:
  108. //Drawing methods
  109. void  Draw(HDC hDC, LPCTSTR lpszHtml, LPPOINT lpPoint);
  110. void  PrepareOutput(HDC hDC, LPCTSTR lpszHtml, LPSIZE lpSize); //Prepares to draw the HTML string
  111. void  DrawPreparedOutput(HDC hDC, LPCRECT lpRect);
  112. void  EnableEscapeSequences(BOOL bEnable = TRUE);
  113. void  EnableOutput(BOOL bEnable = TRUE);
  114. void  SetDisabledColor(COLORREF color);
  115. //Shadow of the image
  116. void SetImageShadow(int nOffsetX, int nOffsetY, BYTE nDarkenPercent = 50, BOOL bGradient = TRUE, int nDepthX = 7, int nDepthY = 7);
  117. CPPString GetResCommandPrompt(UINT nID, UINT nNumParam = 0);
  118. //Functions for the styles
  119. void SetTextStyle(LPCTSTR lpszStyleName, LPCTSTR lpszStyleValue);
  120. void SetCssStyles(LPCTSTR lpszCssString = NULL); //Sets the CSS styles
  121. void SetCssStyles(DWORD dwIdCssString, LPCTSTR lpszPathDll = NULL); //Sets the CSS styles
  122. LPCTSTR GetCssStyles(); //Returns the current CSS styles
  123. void OnLButtonDown(LPPOINT lpClient);
  124. BOOL OnSetCursor(LPPOINT lpClient);
  125. BOOL OnTimer(); //New timer count
  126. void SetHyperlinkCursor(HCURSOR hCursor = NULL); //Sets the cursor to be displayed when moving the mouse over a link. Specifying NULL will cause the control to display its default 'hand' cursor.
  127. HCURSOR GetHyperlinkCursor() const; //Returns the current link cursor.
  128. void SetCallbackHyperlink(HWND hWnd, UINT nMessage, LPARAM lParam = 0); //Sets the callback message: "Mouse over the link".
  129. void SetCallbackRepaint(HWND hWnd, UINT nMessage, LPARAM lParam = 0); //Sets the callback message: "Please repaint me".
  130. //Functions for images
  131. void SetImageList(UINT nIdBitmap, int cx, int cy, int nCount, COLORREF crMask = RGB(255, 0, 255));
  132. void SetImageList(HBITMAP hBitmap, int cx, int cy, int nCount, COLORREF crMask = RGB(255, 0, 255));
  133. void LoadResourceDll(LPCTSTR lpszPathDll, DWORD dwFlags = 0); //Sets the path to the resource's DLL
  134. void SetResourceDll(HINSTANCE hInstDll = NULL); //Sets the handle of the loaded resource's DLL
  135. void SetMaxWidth(int nWidth = 0) {m_nMaxWidth = nWidth;}; //Sets the maximum width of the output window.
  136. int  GetMaxWidth() {return m_nMaxWidth;}; //Gets the maximum width of the output window.
  137. // void EnableTextWrap(BOOL bEnable = TRUE){
  138. // m_bIsTextWrapEnabled = bEnable;};
  139. // BOOL IsTextWrapEnabled() {return m_bIsTextWrapEnabled;};
  140. void SetTabSize(int nSize) {m_nTabSize = nSize;};
  141. CPPDrawManager * GetDrawManager();
  142. static short GetVersionI() {return 0x13;}
  143. static LPCTSTR GetVersionC() {return (LPCTSTR)_T("1.3 beta");}
  144. // Overrides
  145. // ClassWizard generated virtual function overrides
  146. //{{AFX_VIRTUAL(CPPHtmlDrawer)
  147. //}}AFX_VIRTUAL
  148. // Implementation
  149. public:
  150. virtual ~CPPHtmlDrawer();
  151. protected:
  152. enum{ ALIGN_LEFT = 0,
  153. ALIGN_CENTER,
  154. ALIGN_RIGHT,
  155. ALIGN_JUSTIFY
  156. };
  157. enum{ ALIGN_TOP = 0,
  158. ALIGN_VCENTER,
  159. ALIGN_BOTTOM,
  160. ALIGN_BASELINE
  161. };
  162. enum{ LINK_NONE = 0,
  163. LINK_HREF,
  164. LINK_MESSAGE
  165. };
  166. enum{ TEXT_TRANSFORM_NONE = 0,
  167. TEXT_TRANSFORM_UPPERCASE,
  168. TEXT_TRANSFORM_LOWERCASE,
  169. TEXT_TRANSFORM_CAPITALIZE
  170. };
  171. enum{ BORDER_STYLE_NONE = 0,
  172. BORDER_STYLE_SOLID,
  173. BORDER_STYLE_DOTTED,
  174. BORDER_STYLE_DASHED,
  175. BORDER_STYLE_DOUBLE,
  176. };
  177. enum { TAG_NONE = 0,
  178. TAG_BOLD,
  179. TAG_ITALIC,
  180. TAG_UNDERLINE,
  181. TAG_STRIKEOUT,
  182. TAG_FONT,
  183. TAG_HLINE,
  184. TAG_NEWLINE,
  185. TAG_TABULATION,
  186. TAG_LEFT,
  187. TAG_CENTER,
  188. TAG_RIGHT,
  189. TAG_JUSTIFY,
  190. TAG_BASELINE,
  191. TAG_TOP,
  192. TAG_VCENTER,
  193. TAG_BOTTOM,
  194. TAG_BITMAP,
  195. TAG_ICON,
  196. TAG_IMAGELIST,
  197. TAG_STRING,
  198. TAG_NEWSTYLE,
  199. TAG_SPAN,
  200. TAG_HYPERLINK
  201. };
  202. #pragma pack(1)
  203. typedef struct _STRUCT_TAGPROP
  204. {
  205. DWORD dwTagIndex; // The hot rect of the hyperlink
  206. CPPString strTagName; // The type of the hyperlink
  207. } STRUCT_TAGPROP;
  208. #pragma pack()
  209. #pragma pack(1)
  210. typedef struct _STRUCT_ANIMATION
  211. {
  212. int nIndex; //The current index of the image
  213. int nMaxImages; //The max images in the bitmap
  214. int nTimerCount;//The current time position
  215. int nSpeed; //The speed of animation
  216. } STRUCT_ANIMATION;
  217. #pragma pack()
  218. #pragma pack(1)
  219. typedef struct _STRUCT_HYPERLINK
  220. {
  221. RECT rcArea; // The hot rect of the hyperlink
  222. int nTypeLink; // The type of the hyperlink
  223. int nIndexLink; // The index of the hyperlink
  224. CPPString sHyperlink; // The hyperlink
  225. } STRUCT_HYPERLINK;
  226. #pragma pack()
  227. #pragma pack(1)
  228. typedef struct _STRUCT_CHANGESTYLE 
  229. {
  230. CPPString strTag; //The name of the last opened tag
  231. //Font
  232. int  nSizeFont; //The height of the logic font
  233. int  nWeightFont; //The weight of the logic font
  234. BOOL bItalicFont; //Is italic logic font?
  235. BOOL bUnderlineFont;//Is underline logic font?
  236. BOOL bStrikeOutFont;//Is strikeout logic font?
  237. BOOL bOverlineFont; //Is overline logic font?
  238. CPPString sFaceFont;  //The face name of the logic font
  239. //Color
  240. COLORREF crText; //The foreground color 
  241. COLORREF crBkgnd; //The background color (also begin for the gradient)
  242. COLORREF crBorderLight; //The border color
  243. COLORREF crBorderDark; //The border color
  244. COLORREF crMidBkgnd;//The middle background color
  245. COLORREF crEndBkgnd;//The end background color
  246. //Fill
  247. int  nBkMode; //The background mode for the text (TRANSPARENT, OPAQUE)
  248. int  nFillBkgnd; //The fill effect of the background
  249. CPPString strNameResBk;
  250. //Align
  251. int  nHorzAlign; //The horizontal align
  252. int  nVertAlign; //The vertical align
  253. //Border
  254. int  nBorderStyle; //The border style
  255. int  nBorderWidth; //The width of the border
  256. //Cell Sizes
  257. int nCellWidth; //The width of the cell
  258. int nCellHeight; //The height of the cell
  259. BOOL bCellWidthPercent; //The width value in the percent
  260. BOOL bCellHeightPercent; //The height value in the percent
  261. //Text
  262. int  nTextTransform;//Transformation of the text (NONE, UPPERCASE, LOWERCASE, CAPITALIZE)
  263. int nMargin; //Margins
  264. int nPadding; //Padding
  265. //Hyperlink
  266. int  nTypeLink; //The type of the link (NONE, HREF, MESSAGE)
  267. CPPString sHyperlink; //The additional parameter for the link
  268. } STRUCT_CHANGESTYLE; 
  269. #pragma pack()
  270. #pragma pack(1)
  271. typedef struct _STRUCT_IMAGE
  272. {
  273. int nIndexImageList;//image's index of the image list
  274. int nIdRes; //ID resource from app
  275. int nIdDll; //ID resource from dll
  276. int nHandle; //handle of the resource
  277. int cx; //horizontal size of image
  278. int cy; //vertical size of image
  279. int nWidth; //width of image
  280. int nHeight; //height of image
  281. int         nSpeed; //speed for animation
  282. UINT nStyles; //styles of image
  283. UINT nHotStyles; //hot styles of image
  284. BOOL        bUseMask; //
  285. BOOL bPercentWidth;
  286. BOOL bPercentHeight;
  287. COLORREF crMask; //color of mask
  288. CPPString strSrcFile; //path on the source file
  289. CPPString   strPathDll; //path on the resource dll
  290. } STRUCT_IMAGE;
  291. #pragma pack()
  292. #pragma pack(1)
  293. typedef struct _STRUCT_CALLBACK
  294. {
  295. HWND hWnd; /* 腻耜痂矧铕 铌磬, 镳桧桁帼