📄 pphtmldrawer.h
字号:
//
// Class: CPPHtmlDrawer
//
// Compiler: Visual C++
// Tested on: Visual C++ 6.0
// Visual C++ .NET 2003
//
// Version: See GetVersionC() or GetVersionI()
//
// Created: xx/xxxx/2004
// Updated: 21/November/2004
//
// Author: Eugene Pustovoyt pustovoyt@mail.ru
//
// Disclaimer
// ----------
// THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT
// ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO REPONSIBILITIES FOR POSSIBLE
// DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE
// RISK OF USING THIS SOFTWARE.
//
// Terms of use
// ------------
// THIS SOFTWARE IS FREE FOR PERSONAL USE OR FREEWARE APPLICATIONS.
// IF YOU WISH TO THANK MY WORK, YOU MAY DONATE ANY SUM OF MONEY TO ME
// FOR SUPPORT OF DEVELOPMENT OF THIS CLASS.
// IF YOU USE THIS SOFTWARE IN COMMERCIAL OR SHAREWARE APPLICATIONS YOU
// ARE GENTLY ASKED TO DONATE ANY SUM OF MONEY TO THE AUTHOR:
//
//--- History ------------------------------
// 2004/03/01 *** Releases version 1.0 ***
//------------------------------------------
// 2004/04/13 [ADD] Added a "speed" parameter to a <ilst> tag for animation
// 2004/04/20 [ADD] For non-MFC program added STL class CStdString
// 2004/05/05 [ADD] Added an EnableOutput method
// [FIX] Fixed an error in SetImageList method (thanks to topus)
//------------------------------------------
// 2004/05/05 *** Releases version 1.1 ***
//------------------------------------------
// 2004/06/06 [FIX] Fixed an error on select a reference to the handle of the font
// instead select a handle of the font
// 2004/06/24 [ADD] Added SetMaxWidth and GetMaxWidth methods for supporting a text wrapping
// [ADD] Added EnableTextWrap and IsTextWrapEnabled methods to sets a text wrap
// mode or to retrieves a mode status.
// [ADD] Added common character entities.
// 2004/06/25 [ADD] Added SetTabSize method.
// [ADD] Implemented a support to output a justified text.
// [ADD] Added new <justify> tag to output a justified text.
// 2004/07/18 [ADD] Support a disabled draw in the tables
// 2004/09/07 [FIX] Fixed minor errors of drawing table's cells
// 2004/10/13 [FIX] The last line of the paragraph alignment on fields now is not applied
// 2004/10/20 [FIX] Fixed error in GetLengthUnit method. Thanks to Reinhard Steiner
// 2004/10/26 [FIX] Corrected work of the justify for the multifont text in one line
// [ADD] Support a word wrapping for the text with the images
// 2004/10/28 [ADD] Now cx and cy parameters of the <ilst> tag is an optional information
//------------------------------------------
// 2004/10/30 *** Releases version 1.2 ***
//------------------------------------------
// 2004/11/30 [FIX] Fixed an error in the drawing nested tables
// 2004/12/05 [CHN] Replaces CImageList to HIMAGELIST
// [CHN] Replaces MFC classes (CSize, CPoint, CRect) to API structures
// 2004/12/14 [FIX] Fixed an error in determinates of the hyperlink area
// [FIX] Fixed an error in drawing of the horizontal line (<hr> tag)
// 2005/01/15 [ADD] Not fixed columns will resize to the width of the client area
// 2005/03/01 [FIX] Fixed an error of the imagelist drawing
/////////////////////////////////////////////////////////////////////
//
// "GotoURL" function by Stuart Patterson
// As seen in the August, 1997 Windows Developer's Journal.
// Copyright 1997 by Miller Freeman, Inc. All rights reserved.
// Modified by Chris Maunder to use TCHARs instead of chars.
//
// "Default hand cursor" from Paul DiLascia's Jan 1998 MSJ article.
// Modified by Zorglab to use standard hand cursor on WinMe,2k,XP
//
/////////////////////////////////////////////////////////////////////
#ifndef _PPHTMLDRAWER_H_
#define _PPHTMLDRAWER_H_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// disable warning C4786: symbol greater than 255 character, okay to ignore
#pragma warning(disable : 4786)
#include "PPDrawManager.h"
#include <vector>
#include <map>
#ifdef _MFC_VER
#define CPPString CString //MFC program
#else
#include "StdString.h"
#ifdef _UNICODE
#define CPPString CStdStringW //non-MFC program UNICODE
#else
#define CPPString CStdStringA //non-MFC program ANSI
#endif
#endif
/////////////////////////////////////////////////////////////////////////////
// CPPHtmlDrawer window
class CPPHtmlDrawer
{
// Construction
public:
CPPHtmlDrawer();
// Attributes
public:
// Operations
public:
//Drawing methods
void Draw(HDC hDC, LPCTSTR lpszHtml, LPPOINT lpPoint);
void PrepareOutput(HDC hDC, LPCTSTR lpszHtml, LPSIZE lpSize); //Prepares to draw the HTML string
void DrawPreparedOutput(HDC hDC, LPCRECT lpRect);
void EnableEscapeSequences(BOOL bEnable = TRUE);
void EnableOutput(BOOL bEnable = TRUE);
void SetDisabledColor(COLORREF color);
//Shadow of the image
void SetImageShadow(int nOffsetX, int nOffsetY, BYTE nDarkenPercent = 50, BOOL bGradient = TRUE, int nDepthX = 7, int nDepthY = 7);
CPPString GetResCommandPrompt(UINT nID, UINT nNumParam = 0);
//Functions for the styles
void SetTextStyle(LPCTSTR lpszStyleName, LPCTSTR lpszStyleValue);
void SetCssStyles(LPCTSTR lpszCssString = NULL); //Sets the CSS styles
void SetCssStyles(DWORD dwIdCssString, LPCTSTR lpszPathDll = NULL); //Sets the CSS styles
LPCTSTR GetCssStyles(); //Returns the current CSS styles
void OnLButtonDown(LPPOINT lpClient);
BOOL OnSetCursor(LPPOINT lpClient);
BOOL OnTimer(); //New timer count
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.
HCURSOR GetHyperlinkCursor() const; //Returns the current link cursor.
void SetCallbackHyperlink(HWND hWnd, UINT nMessage, LPARAM lParam = 0); //Sets the callback message: "Mouse over the link".
void SetCallbackRepaint(HWND hWnd, UINT nMessage, LPARAM lParam = 0); //Sets the callback message: "Please repaint me".
//Functions for images
void SetImageList(UINT nIdBitmap, int cx, int cy, int nCount, COLORREF crMask = RGB(255, 0, 255));
void SetImageList(HBITMAP hBitmap, int cx, int cy, int nCount, COLORREF crMask = RGB(255, 0, 255));
void LoadResourceDll(LPCTSTR lpszPathDll, DWORD dwFlags = 0); //Sets the path to the resource's DLL
void SetResourceDll(HINSTANCE hInstDll = NULL); //Sets the handle of the loaded resource's DLL
void SetMaxWidth(int nWidth = 0) {m_nMaxWidth = nWidth;}; //Sets the maximum width of the output window.
int GetMaxWidth() {return m_nMaxWidth;}; //Gets the maximum width of the output window.
// void EnableTextWrap(BOOL bEnable = TRUE){
// m_bIsTextWrapEnabled = bEnable;};
// BOOL IsTextWrapEnabled() {return m_bIsTextWrapEnabled;};
void SetTabSize(int nSize) {m_nTabSize = nSize;};
CPPDrawManager * GetDrawManager();
static short GetVersionI() {return 0x13;}
static LPCTSTR GetVersionC() {return (LPCTSTR)_T("1.3 beta");}
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CPPHtmlDrawer)
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CPPHtmlDrawer();
protected:
enum{ ALIGN_LEFT = 0,
ALIGN_CENTER,
ALIGN_RIGHT,
ALIGN_JUSTIFY
};
enum{ ALIGN_TOP = 0,
ALIGN_VCENTER,
ALIGN_BOTTOM,
ALIGN_BASELINE
};
enum{ LINK_NONE = 0,
LINK_HREF,
LINK_MESSAGE
};
enum{ TEXT_TRANSFORM_NONE = 0,
TEXT_TRANSFORM_UPPERCASE,
TEXT_TRANSFORM_LOWERCASE,
TEXT_TRANSFORM_CAPITALIZE
};
enum{ BORDER_STYLE_NONE = 0,
BORDER_STYLE_SOLID,
BORDER_STYLE_DOTTED,
BORDER_STYLE_DASHED,
BORDER_STYLE_DOUBLE,
};
enum { TAG_NONE = 0,
TAG_BOLD,
TAG_ITALIC,
TAG_UNDERLINE,
TAG_STRIKEOUT,
TAG_FONT,
TAG_HLINE,
TAG_NEWLINE,
TAG_TABULATION,
TAG_LEFT,
TAG_CENTER,
TAG_RIGHT,
TAG_JUSTIFY,
TAG_BASELINE,
TAG_TOP,
TAG_VCENTER,
TAG_BOTTOM,
TAG_BITMAP,
TAG_ICON,
TAG_IMAGELIST,
TAG_STRING,
TAG_NEWSTYLE,
TAG_SPAN,
TAG_HYPERLINK
};
#pragma pack(1)
typedef struct _STRUCT_TAGPROP
{
DWORD dwTagIndex; // The hot rect of the hyperlink
CPPString strTagName; // The type of the hyperlink
} STRUCT_TAGPROP;
#pragma pack()
#pragma pack(1)
typedef struct _STRUCT_ANIMATION
{
int nIndex; //The current index of the image
int nMaxImages; //The max images in the bitmap
int nTimerCount;//The current time position
int nSpeed; //The speed of animation
} STRUCT_ANIMATION;
#pragma pack()
#pragma pack(1)
typedef struct _STRUCT_HYPERLINK
{
RECT rcArea; // The hot rect of the hyperlink
int nTypeLink; // The type of the hyperlink
int nIndexLink; // The index of the hyperlink
CPPString sHyperlink; // The hyperlink
} STRUCT_HYPERLINK;
#pragma pack()
#pragma pack(1)
typedef struct _STRUCT_CHANGESTYLE
{
CPPString strTag; //The name of the last opened tag
//Font
int nSizeFont; //The height of the logic font
int nWeightFont; //The weight of the logic font
BOOL bItalicFont; //Is italic logic font?
BOOL bUnderlineFont;//Is underline logic font?
BOOL bStrikeOutFont;//Is strikeout logic font?
BOOL bOverlineFont; //Is overline logic font?
CPPString sFaceFont; //The face name of the logic font
//Color
COLORREF crText; //The foreground color
COLORREF crBkgnd; //The background color (also begin for the gradient)
COLORREF crBorderLight; //The border color
COLORREF crBorderDark; //The border color
COLORREF crMidBkgnd;//The middle background color
COLORREF crEndBkgnd;//The end background color
//Fill
int nBkMode; //The background mode for the text (TRANSPARENT, OPAQUE)
int nFillBkgnd; //The fill effect of the background
CPPString strNameResBk;
//Align
int nHorzAlign; //The horizontal align
int nVertAlign; //The vertical align
//Border
int nBorderStyle; //The border style
int nBorderWidth; //The width of the border
//Cell Sizes
int nCellWidth; //The width of the cell
int nCellHeight; //The height of the cell
BOOL bCellWidthPercent; //The width value in the percent
BOOL bCellHeightPercent; //The height value in the percent
//Text
int nTextTransform;//Transformation of the text (NONE, UPPERCASE, LOWERCASE, CAPITALIZE)
int nMargin; //Margins
int nPadding; //Padding
//Hyperlink
int nTypeLink; //The type of the link (NONE, HREF, MESSAGE)
CPPString sHyperlink; //The additional parameter for the link
} STRUCT_CHANGESTYLE;
#pragma pack()
#pragma pack(1)
typedef struct _STRUCT_IMAGE
{
int nIndexImageList;//image's index of the image list
int nIdRes; //ID resource from app
int nIdDll; //ID resource from dll
int nHandle; //handle of the resource
int cx; //horizontal size of image
int cy; //vertical size of image
int nWidth; //width of image
int nHeight; //height of image
int nSpeed; //speed for animation
UINT nStyles; //styles of image
UINT nHotStyles; //hot styles of image
BOOL bUseMask; //
BOOL bPercentWidth;
BOOL bPercentHeight;
COLORREF crMask; //color of mask
CPPString strSrcFile; //path on the source file
CPPString strPathDll; //path on the resource dll
} STRUCT_IMAGE;
#pragma pack()
#pragma pack(1)
typedef struct _STRUCT_CALLBACK
{
HWND hWnd; /* 腻耜痂矧铕 铌磬, 镳桧桁帼
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -