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

#ifndef __WEBLIB_H__
#define __WEBLIB_H__

#include <windows.h>

#ifdef __cplusplus 
extern "C" {
#endif 

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

// Flags for ConnectBrowser
#define WL_STARTBROWSER			0x1                  	// start browser if not running
#define WL_SENDMESSAGE      	0x2                   	// notify caller via SendMessage
#define WL_POSTMESSAGE      	0x4						// notify caller via PostMessage

// Flags for ListWindows
#define WL_FIRSTWINDOW			TRUE					// get first window
#define WL_NEXTWINDOW			FALSE					// get next window (if any)

// Flags for GetWindowInfo, ActivateWindow and OpenURL
#define WL_ACTIVEWINDOW			0xFFFFFFFF				// operate on active window
#define WL_LASTACTIVEWINDOW 	0xFFFFFFFF 				// activate last active window
#define WL_NEWWINDOW			0x0						// create new window for URL

// Flags for SetWindowPos
#define WL_NOCHANGE				0xFFFFFFFF				// do not change x, y, width, height

// Flags for ShowWindow
#define WL_MINIMIZE				0x1						// minimize window
#define WL_MAXIMIZE         	0x2                    	// maximize window
#define WL_NORMAL           	0x3                   	// restore window to normal size

// Flags for OpenURL, values must conform to DDE API
#define WL_NODOCUMENTCACHE		0x01					// ignore browser's doc cache
#define WL_NOIMAGECACHE			0x02					// ignore browser's image cache
#define WL_BACKGROUNDMODE		0x04					// operate in background mode 

// Flags that may be passed instead of notification window handle
#define WL_DEFAULTNOTIFY		((HWND) -1)				// use default from SetDefaultNotify
#define WL_NONOTIFY	       		((HWND) NULL)         	// do not send notification message

// Flags for UnRegisterURLEcho and others
#define WL_UNREGISTERALL		((HWND) NULL)			// unregister all windows

// Flags for RegisterViewer, values must conform to DDE API
#define WL_SHELLEXECUTE			0x01					// launch viewer using ShellExecute
#define WL_QUERYVIEWER			0x02					// send event to query filename
#define WL_VIEWDOCFILE			0x04					// send event to view filename

// Flags for AddToolbarButton
#define WL_BITMAPHANDLES		((HINSTANCE) NULL)		// passing bitmaps, not resource IDs

// Flags for SetToolbarText
#define WL_TOOLBARTEXT			((UINT) (-1))			// set toolbar text, not button text

// Flags for SetToolbarFont
#define WL_TOOLBARFONT			0x1						// set font for toolbar text
#define WL_BUTTONFONT			0x2						// set font for button text

// Flags for SetToolbarTextColor
#define WL_TOOLBARTEXTCOLOR		0x1						// set color for toolbar text
#define WL_BUTTONTEXTCOLOR		0x2						// set color for button text

///////////////////////////////////////////////////////////////////////////////
// Notification events generated by API

#define WLN_BEGINPROGRESS		0x1
#define WLN_SETPROGRESSRANGE 	0x2
#define WLN_MAKINGPROGRESS		0x3
#define WLN_ENDPROGRESS			0x4
#define WLN_FINISHED			0x5
#define WLN_CANCELED			0x6
#define WLN_URLECHO				0x7
#define WLN_OPENURL				0x8
#define WLN_CANCELTRX			0x9
#define WLN_WINDOWCHANGE		0xa
#define WLN_QUERYVIEWER			0xb
#define WLN_VIEWDOCFILE			0xc 
#define WLN_BUTTONCLICKED		0xd
#define WLN_BROWSERSTART		0xe
#define WLN_BROWSEREXIT			0xf

///////////////////////////////////////////////////////////////////////////////
// Flags for WindowChange notification event

#define WLF_MOVESIZE			0x00001
#define WLF_MAXIMIZED			0x00002
#define WLF_NORMALIZED			0x00004
#define WLF_MINIMIZED			0x00008
#define WLF_CLOSED				0x00010
#define WLF_EXITING				0x10000

///////////////////////////////////////////////////////////////////////////////
// Macros for extracting parameters from notification events  

#define WLNTXN					0
#define WLNPROGSTR				1
#define WLNPROGVAL				2
#define WLNPROGMAX				3
#define WLNWINDOW				4
#define WLNURL					5
#define WLNMIME					6
#define WLNREF					7
#define WLNFLAGS				8
#define WLNSAVE					9
#define WLNFORM					10 
#define WLNX					11
#define WLNY					12
#define WLNWIDTH				13
#define WLNHEIGHT				14
#define WLNFILE					15

#ifndef WEBLIB_NO_INLINE

#define WLNGetTransaction(lp)			((DWORD) WLGetNotifyParm(lp,WLNTXN))
#define WLNGetProgressString(lp)		((LPSTR) WLGetNotifyParm(lp,WLNPROGSTR))
#define WLNGetProgressValue(lp)			((DWORD) WLGetNotifyParm(lp,WLNPROGVAL))
#define WLNGetProgressMaximum(lp)		((DWORD) WLGetNotifyParm(lp,WLNPROGMAX))
#define WLNGetWindow(lp)				((DWORD) WLGetNotifyParm(lp,WLNWINDOW))
#define WLNGetURL(lp)					((LPSTR) WLGetNotifyParm(lp,WLNURL))
#define WLNGetMIMEType(lp)				((LPSTR) WLGetNotifyParm(lp,WLNMIME))
#define WLNGetReferrer(lp)				((LPSTR) WLGetNotifyParm(lp,WLNREF))
#define WLNGetFlags(lp)					((DWORD) WLGetNotifyParm(lp,WLNFLAGS))
#define WLNGetSaveFile(lp)				((LPSTR) WLGetNotifyParm(lp,WLNSAVE))
#define WLNGetFormData(lp)				((LPSTR) WLGetNotifyParm(lp,WLNFORM))
#define WLNGetX(lp)						((DWORD) WLGetNotifyParm(lp,WLNX))
#define WLNGetY(lp)						((DWORD) WLGetNotifyParm(lp,WLNY))
#define WLNGetWidth(lp)					((DWORD) WLGetNotifyParm(lp,WLNWIDTH))
#define WLNGetHeight(lp)				((DWORD) WLGetNotifyParm(lp,WLNHEIGHT))
#define WLNGetFileName(lp)				((LPSTR) WLGetNotifyParm(lp,WLNFILE))
#define WLNGetButtonID(lp)				((UINT) lParam)

#endif

///////////////////////////////////////////////////////////////////////////////
// Pre-defined notification message, included for convenience
#ifndef WEBLIB_NO_PREDEFINEDMESSAGES

#define WM_WEBLIB_NOTIFY		(WM_USER + 1000)		

#endif

/////////////////////////////////////////////////////////////////////////
// Typedefs for API 

// Handles returned by ConnectBrowser, CreateToolbar and AppendFormData
typedef HLOCAL 	HBROWSER;
typedef HLOCAL 	HTOOLBAR; 
typedef HGLOBAL HFORMDATA; 

///////////////////////////////////////////////////////////////////////////////
// Housekeeping functions 

BOOL WINAPI WLStartup();
BOOL WINAPI WLCleanup();
BOOL WINAPI WLSetDefaultNotify(HWND hwndNotify,UINT nMsg);

///////////////////////////////////////////////////////////////////////////////
// Browser API functions 

HBROWSER WINAPI WLConnectBrowser(WORD wOptions);
BOOL WINAPI WLDisconnectBrowser(HBROWSER hBrowser,BOOL bExit);

BOOL WINAPI WLGetWindowInfo(HBROWSER hBrowser,
	DWORD dwWindow,LPSTR lpszURL,int cbURL,LPSTR lpszTitle,int cbTitle);
DWORD WINAPI WLListWindows(HBROWSER hBrowser,BOOL bFirst);

DWORD WINAPI WLActivateWindow(HBROWSER hBrowser,DWORD dwWindow);	
BOOL WINAPI WLCloseWindow(HBROWSER hBrowser,DWORD dwWindow);

BOOL WINAPI WLSetWindowPos(HBROWSER hBrowser,
	DWORD dwWindow,DWORD dwX,DWORD dwY,DWORD dwWidth,DWORD dwHeight);
BOOL WINAPI WLShowWindow(HBROWSER hBrowser,DWORD dwWindow,UINT nShow);

DWORD WINAPI WLShowFile(HBROWSER hBrowser,
	LPCSTR lpszFile,LPCSTR lpszMIMEType,DWORD dwWindow,LPCSTR lpszURL,HWND hwndNotify,UINT nMsg);
	
DWORD WINAPI WLOpenURL(HBROWSER hBrowser,
	LPCSTR lpszURL,DWORD dwWindow,WORD wOptions,HWND hwndNotify,UINT nMsg);
DWORD WINAPI WLSaveURL(HBROWSER hBrowser,
	LPCSTR lpszURL,LPCSTR lpszFile,DWORD dwWindow,WORD wOptions,HWND hwndNotify,UINT nMsg);

DWORD WINAPI WLPostFormData(HBROWSER hBrowser,
	LPCSTR lpszURL,DWORD dwWindow,LPCSTR lpszFormData,LPCSTR lpszMIMEType,
		HWND hwndNotify,UINT nMsg);
DWORD WINAPI WLSaveFormData(HBROWSER hBrowser,LPCSTR lpszURL,
	LPCSTR lpszFile,DWORD dwWindow,LPCSTR lpszFormData,LPCSTR lpszMIMEType,
		HWND hwndNotify,UINT nMsg);
		
BOOL WINAPI WLCancel(HBROWSER hBrowser,DWORD dwTransaction);
	
BOOL WINAPI WLRegisterProtocol(HBROWSER hBrowser,LPCSTR lpszProtocol,HWND hwndNotify,UINT nMsg);
BOOL WINAPI WLUnregisterProtocol(HBROWSER hBrowser,LPCSTR lpszProtocol,HWND hwndNotify);

BOOL WINAPI WLRegisterURLEcho(HBROWSER hBrowser,HWND hwndNotify,UINT nMsg);
BOOL WINAPI WLUnregisterURLEcho(HBROWSER hBrowser,HWND hwndNotify);

BOOL WINAPI WLRegisterViewer(HBROWSER hBrowser,LPCSTR lpszMIMEType,WORD wOptions,
	HWND hwndNotify,UINT nMsg);
BOOL WINAPI WLUnregisterViewer(HBROWSER hBrowser,LPCSTR lpszMIMEType,HWND hwndNotify);

BOOL WINAPI WLRegisterWindowChange(HBROWSER hBrowser,DWORD dwWindow,HWND hwndNotify,UINT nMsg);
BOOL WINAPI WLUnregisterWindowChange(HBROWSER hBrowser,DWORD dwWindow,HWND hwndNotify);

LPCSTR WINAPI WLParseAnchor(HBROWSER hBrowser,LPCSTR lpszAbsoluteURL,LPCSTR lpszRelativeURL);
DWORD WINAPI WLGetVersion(HBROWSER hBrowser,WORD wMajor,WORD wMinor);

LPCSTR WINAPI WLQueryURLFile(HBROWSER hBrowser,LPCSTR lpszFile);		// Netscape only!

BOOL WINAPI WLSetNotifyMethod(HBROWSER hBrowser,WORD wMethod);	
DWORD WINAPI WLGetTransactionWindow(HBROWSER hBrowser,DWORD dwTransaction);

LRESULT WINAPI WLGetNotifyParm(LPARAM lParam,int nType);
void WINAPI WLNSetFileName(LPARAM lParam,LPCSTR lpszFileName);

///////////////////////////////////////////////////////////////////////////////
// Toolbar functions

HTOOLBAR WINAPI WLCreateToolbar(LPCSTR lpszMenu,HWND hwndNotify,UINT nMsg);
BOOL WINAPI WLDeleteToolbar(HTOOLBAR hToolbar);

BOOL WINAPI WLIsToolbarActive(HTOOLBAR hToolbar);
BOOL WINAPI WLSetActiveToolbar(HTOOLBAR hToolbar);

BOOL WINAPI WLAddToolbarButton(HTOOLBAR hToolbar,UINT nID,int nIdx,LPCSTR lpszText,
	HINSTANCE hInstance,LPCSTR lpszBitmap,LPCSTR lpszBitmapSel,LPCSTR lpszBitmapFocus,
		LPCSTR lpszBitmapDisabled);
BOOL WINAPI WLRemoveToolbarButton(HTOOLBAR hToolbar,UINT nID);             

BOOL WINAPI WLIsToolbarButtonVisible(HTOOLBAR hToolbar,UINT nID);
BOOL WINAPI WLShowToolbarButton(HTOOLBAR hToolbar,UINT nID,BOOL bShow);

BOOL WINAPI WLEnableToolbarButton(HTOOLBAR hToolbar,UINT nID,BOOL bEnable);
BOOL WINAPI WLIsToolbarButtonEnabled(HTOOLBAR hToolbar,UINT nID);

LPCSTR WINAPI WLGetToolbarText(HTOOLBAR hToolbar,UINT nID);
BOOL WINAPI WLSetToolbarText(HTOOLBAR hToolbar,UINT nID,LPCSTR lpszText);

HFONT WINAPI WLGetToolbarFont(HTOOLBAR hToolbar,WORD wType);
BOOL WINAPI WLSetToolbarFont(HTOOLBAR hToolbar,WORD wType,HFONT hFont);

COLORREF WINAPI WLGetToolbarBkgnd(HTOOLBAR hToolbar);
BOOL WINAPI WLSetToolbarBkgnd(HTOOLBAR hToolbar,COLORREF crBackground);

COLORREF WINAPI WLGetToolbarTextColor(HTOOLBAR hToolbar,WORD wType);
BOOL WINAPI WLSetToolbarTextColor(HTOOLBAR hToolbar,WORD wType,COLORREF crText);

///////////////////////////////////////////////////////////////////////////////
// Utility functions for building form data buffer for posting to URL.

HFORMDATA WINAPI WLAppendFormData(HFORMDATA hFormData,LPCSTR lpszName,LPCSTR lpszData,
	UINT cbData);
UINT WINAPI WLGetFormDataLength(HFORMDATA hFormData);
BOOL WINAPI WLAccessFormData(HFORMDATA hFormData,LPSTR lpszRetBuf,UINT cbRetBuf);

#ifdef __cplusplus 
}
#endif

#endif
