
///////////////////////////////////////////////////////////////////////////////
// Copyright 1995 by Potomac Software, Inc. Use of this material is subject to
// the terms and conditions of the software license agreement.

#ifndef __HTMLPARS_H__
#define __HTMLPARS_H__

#include <windows.h>

#ifdef __cplusplus 
extern "C" {
#endif 

///////////////////////////////////////////////////////////////////////////////
// Numeric identifiers for each HTML tag (tool developer note: these must remain
// in sync with internal lists stored in the DLL).

#define HTML_INVALID				0
#define HTML_COMMENT				0x1000

// Text style bits, returned by GetTextAttr
#define HTML_BOLD					0x0000001L		// <B>				(HTML 2.0)
#define HTML_ITALIC					0x0000002L		// <I>
#define HTML_UNDERLINE				0x0000004L		// <U>
#define HTML_EMPHASIS				0x0000008L		// <EM>
#define HTML_STRONG 				0x0000010L		// <STRONG>
#define HTML_CITE					0x0000020L		// <CITE>
#define HTML_CODE					0x0000040L		// <CODE>
#define HTML_KEYBOARD				0x0000080L		// <KBD>
#define HTML_SAMPLE					0x0000100L		// <SAMP>
#define HTML_STRIKE					0x0000200L		// <STRIKE>
#define HTML_VARIABLE         		0x0000400L		// <VAR>
#define HTML_TYPEWRITER     		0x0000800L		// <TT>
#define HTML_LISTING                0x0001000L      // <LISTING>
#define HTML_EXAMPLE                0x0002000L     	// <XMP>
#define HTML_PLAINTEXT              0x0004000L     	// <PLAINTEXT>
#define HTML_ARGUMENT				0x0008000L		// <ARG>			(HTML+)
#define HTML_DEFINE					0x0010000L		// <DFN>
#define HTML_ABBREV					0x0020000L		// <ABBREV>
#define HTML_COMMAND               	0x0040000L     	// <CMD>
#define HTML_ACRONYM				0x0080000L		// <ACRONYM>
#define HTML_PERSON					0x0100000L		// <PERSON>
#define HTML_QUOTATION				0x0200000L		// <Q>
#define HTML_STRIKETHRU             0x0400000L     	// <S>
#define HTML_SUBSCRIPT              0x0800000L     	// <SUB>
#define HTML_SUPERSCRIPT            0x1000000L     	// <SUP>
#define HTML_BLINK					0x2000000L		// <BLINK>			(Netscape)

// Empty tags, returned by GetTagType
#define HTML_BASE					1				// <BASE>			(HTML 2.0)
#define HTML_ISINDEX                2				// <ISINDEX>
#define HTML_LINK                   3				// <LINK>
#define HTML_NEXTID 				4				// <NEXTID>
#define HTML_META 					5				// <META>
#define HTML_BR              		6              	// <BR>
#define HTML_DD               		7				// <DD>
#define HTML_DT               		8				// <DT>
#define HTML_HR              		9				// <HR>
#define HTML_IMG                  	10				// <IMG>
#define HTML_LI              		11				// <LI>
#define HTML_P              		12				// <P>
#define HTML_SELECT					13				// <SELECT>	
#define HTML_INPUT					14				// <INPUT>
#define HTML_TEXTAREA				15				// <TEXTAREA>
#define HTML_OPTION					16				// <OPTION>
#define HTML_TD						17				// <TD> 			(HTML+)
#define HTML_TH						18				// <TH>
#define HTML_TR						19				// <TR>
#define HTML_RENDER            		20             	// <RENDER>
#define HTML_NOBR					21				// <NOBR>			(Netscape)
#define HTML_WBR                    22           	// <WBR>
#define HTML_BASEFONT               23          	// <BASEFONT> 

// Must add 256 to container tags to differentiate between empty tags
#define HTML_CONTAINER				(0x100)
#define GETCONTAINER(x)				((x) & (HTML_CONTAINER - 1))
#define MAKECONTAINER(x)			((x) | HTML_CONTAINER)

// Container Tags, returned by GetTagType
#define HTML_HTML					MAKECONTAINER(1)	// <HTML>			(HTML 2.0)
#define HTML_HEAD                   MAKECONTAINER(2) 	// <HEAD>
#define HTML_TITLE                  MAKECONTAINER(3)   	// <TITLE>
#define HTML_A                		MAKECONTAINER(4)	// <A>
#define HTML_ADDRESS                MAKECONTAINER(5)   	// <ADDRESS>
#define HTML_BLOCKQUOTE             MAKECONTAINER(6)	// <BLOCKQUOTE>
#define HTML_BODY                   MAKECONTAINER(7)	// <BODY>
#define HTML_DIR                    MAKECONTAINER(8)	// <DIR>
#define HTML_DL                		MAKECONTAINER(9)	// <DL>
#define HTML_H1               		MAKECONTAINER(10)	// <H1>
#define HTML_H2               		MAKECONTAINER(11)   // <H2>
#define HTML_H3               		MAKECONTAINER(12)   // <H3>
#define HTML_H4               		MAKECONTAINER(13)   // <H4>
#define HTML_H5               		MAKECONTAINER(14)   // <H5>
#define HTML_H6               		MAKECONTAINER(15)   // <H6>
#define HTML_MENU                   MAKECONTAINER(16)   // <MENU>
#define HTML_OL              		MAKECONTAINER(17)   // <OL>
#define HTML_PRE              		MAKECONTAINER(18)   // <PRE>
#define HTML_UL            			MAKECONTAINER(19)   // <UL>
#define HTML_FORM                   MAKECONTAINER(20)   // <FORM>
#define HTML_TABLE                  MAKECONTAINER(21)   // <TABLE>			(HTML+)
#define HTML_CAPTION                MAKECONTAINER(22)   // <CAPTION>
#define HTML_ABSTRACT               MAKECONTAINER(23)   // <ABSTRACT>
#define HTML_FIG                 	MAKECONTAINER(24)   // <FIG>
#define HTML_FOOTNOTE               MAKECONTAINER(25)   // <FOOTNOTE>
#define HTML_LIT                	MAKECONTAINER(26)   // <LIT>
#define HTML_MARGIN                 MAKECONTAINER(27)   // <MARGIN>
#define HTML_MATH                   MAKECONTAINER(28)   // <MATH>
#define HTML_ONLINE                 MAKECONTAINER(29)   // <ONLINE>
#define HTML_PRINTED                MAKECONTAINER(30)   // <PRINTED>
#define HTML_NOTE					MAKECONTAINER(31)	// <NOTE>
#define HTML_FONT                   MAKECONTAINER(32)   // <FONT>			(Netscape)
#define HTML_CENTER                 MAKECONTAINER(33)   // <CENTER>                

///////////////////////////////////////////////////////////////////////////////
// Flags that may be passed to API functions

// Flags for ParseFile and ParseBuf
#define WL_KEEPATTRIBUTETAG			0x1
#define WL_KEEPCLOSINGTAG         	0x2

// Flags for GetSibling
#define WL_FIRSTELEM				0x1
#define WL_NEXTELEM					0x2
#define WL_PREVELEM					0x3
#define WL_LASTELEM					0x4

// Flag for GetChild, Find and FindEnum to obtain root of parse tree
#define WL_ROOTELEMENT				(NULL)

// Flags for GetElementType
#define WL_ROOT						0x0	
#define WL_TAG        				0x1
#define WL_SPECIALCHAR            	0x2
#define WL_COMMENT                	0x3
#define WL_TEXT                   	0x4

// Flags for GetTagAttrInfo
#define WL_WORD						0x1 									
#define WL_QUOTEDSTRING            	0x2
#define WL_NUMBER                  	0x3
#define WL_STANDALONE               0x4

// Flags for EnumFindText, EnumFindSpecial, EnumFindComment and EnumFindTagName
#define WL_ENUMERATEALL				NULL

// Pre-defined enumeration notification messages included for convenience
#ifndef WEBLIB_NO_PREDEFINEDMESSAGES

#define WM_WEBLIB_ENUMPARSETREE		(WM_USER + 1001)
#define WM_WEBLIB_ENUMFINDTEXT		(WM_USER + 1002)
#define WM_WEBLIB_ENUMFINDSPEC		(WM_USER + 1003)
#define WM_WEBLIB_ENUMFINDCOMM		(WM_USER + 1004)
#define WM_WEBLIB_ENUMFINDTAGTYPE	(WM_USER + 1005)
#define WM_WEBLIB_ENUMFINDTAGNAME	(WM_USER + 1006)
#define WM_WEBLIB_ENUMFINDTAGATTR	(WM_USER + 1007)

#endif

///////////////////////////////////////////////////////////////////////////////
// Typedefs for handles used by API.

typedef HLOCAL HPARSE;
typedef DWORD  HELEMENT;
typedef DWORD  HTAGATTR;

///////////////////////////////////////////////////////////////////////////////
// HTML API

HPARSE WINAPI WLHtmlParseFile(LPCSTR lpszFilename,WORD wOptions);
HPARSE WINAPI WLHtmlParseBuf(LPCSTR lpszBuf,DWORD cbBuf,WORD wOptions);
BOOL WINAPI WLHtmlEndParse(HPARSE hParse); 

BOOL WINAPI WLHtmlEnumParseTree(HPARSE hParse,HWND hwndNotify,UINT nMsg);

HELEMENT WINAPI WLHtmlGetChild(HPARSE hParse,HELEMENT hElement);
HELEMENT WINAPI WLHtmlGetParent(HPARSE hParse,HELEMENT hElement);
HELEMENT WINAPI WLHtmlGetSibling(HPARSE hParse,HELEMENT hElement,WORD wRel);

UINT WINAPI WLHtmlGetElementType(HPARSE hParse,HELEMENT hElement);
LPCSTR WINAPI WLHtmlGetElementText(HPARSE hParse,HELEMENT hElement);

DWORD WINAPI WLHtmlGetTextAttr(HPARSE hParse,HELEMENT hElement);

LPCSTR WINAPI WLHtmlGetTagName(HPARSE hParse,HELEMENT hElement);
UINT WINAPI WLHtmlGetTagType(HPARSE hParse,HELEMENT hElement);

HTAGATTR WINAPI WLHtmlGetTagAttr(HPARSE hParse,HELEMENT hElement,HTAGATTR hTagAttr,
	WORD *pwType,LPSTR lpszAttr,UINT cbAttr,LPSTR lpszValue,UINT cbValue); 
LPCSTR WINAPI WLHtmlExtractTagAttr(HPARSE hParse,HELEMENT hElement,LPSTR lpszAttr);	
	
HELEMENT WINAPI WLHtmlFindText(HPARSE hParse,HELEMENT hElement,LPCSTR lpszText);
HELEMENT WINAPI WLHtmlFindSpecial(HPARSE hParse,HELEMENT hElement,LPCSTR lpszSpecial);
HELEMENT WINAPI WLHtmlFindComment(HPARSE hParse,HELEMENT hElement,LPCSTR lpszCommentText);

HELEMENT WINAPI WLHtmlFindTagType(HPARSE hParse,HELEMENT hElement,UINT nType);
HELEMENT WINAPI WLHtmlFindTagName(HPARSE hParse,HELEMENT hElement,LPCSTR lpszTag);
HELEMENT WINAPI WLHtmlFindTagAttr(HPARSE hParse,HELEMENT hElement,UINT nType,
	LPCSTR lpszAttr,LPCSTR lpszValue);

BOOL WINAPI WLHtmlEnumFindText(HPARSE hParse,HELEMENT hElement,LPCSTR lpszText,
	HWND hwndNotify,UINT nMsg);
BOOL WINAPI WLHtmlEnumFindSpecial(HPARSE hParse,HELEMENT hElement,LPCSTR lpszSpecial,
	HWND hwndNotify,UINT nMsg);
BOOL WINAPI WLHtmlEnumFindComment(HPARSE hParse,HELEMENT hElement,LPCSTR lpszCommentText,
	HWND hwndNotify,UINT nMsg);

BOOL WINAPI WLHtmlEnumFindTagType(HPARSE hParse,HELEMENT hElement,UINT nType,
	HWND hwndNotify,UINT nMsg);
BOOL WINAPI WLHtmlEnumFindTagName(HPARSE hParse,HELEMENT hElement,LPCSTR lpszTag,
	HWND hwndNotify,UINT nMsg);
BOOL WINAPI WLHtmlEnumFindTagAttr(HPARSE hParse,HELEMENT hElement,UINT nType,
	LPCSTR lpszAttr,LPCSTR lpszValueText,HWND hwndNotify,UINT nMsg);
	
///////////////////////////////////////////////////////////////////////////////
// Utility function to parse URL.

BOOL WINAPI WLParseAbsoluteURL(LPCSTR lpszURL,LPSTR lpszProtocol,UINT cbProtocol,
	LPSTR lpszHost,UINT cbHost,UINT *pnPort,LPSTR lpszPath,UINT cbPath);

#ifdef __cplusplus 
}
#endif

#endif
