/******************************************************************************
 GMTextLink.h

	Interface for the GMTextLink class

	Copyright © 1998 by John Lindal. All rights reserved.

 ******************************************************************************/

#ifndef _H_GMTextLink
#define _H_GMTextLink

#include <JXTextLink.h>
#include <JBroadcaster.h>
#include <JArray.h>

class JXTEBase;
class JRegex;
class JString;
class JLatentPG;

class GMTextLink : public JXTextLink , public JBroadcaster
{
public:

	GMTextLink(JXDisplay* display, JXTEBase* editor);

	virtual ~GMTextLink();

	enum LinkType
	{
		kFullURL = 1,
		kEMail,
		kWeb
	};

protected:

	virtual void		Receive(JBroadcaster* sender, const Message& message);

	virtual JSize		GetLinkCount() const;
	virtual JIndexRange	GetLinkRange(const JIndex index) const;
	virtual void		LinkClicked(const JIndex index);

private:


	struct LinkInfo
	{
		JIndexRange	range;
		JString*	url;
		LinkType	type;

		LinkInfo()
			:
			range(), url(NULL), type(kFullURL)
		{ };

		LinkInfo(const JIndexRange& r, JString* s, const LinkType t)
			:
			range(r), url(s), type(t)
		{ };
	};

private:

	JArray<LinkInfo>*	itsLinks;
	JXTEBase*			itsEditor;

private:

	void		RemoveLinks(const JIndex startIndex);

	JBoolean 	ParseForURLs(const JIndex index, JLatentPG* pg, 
						  const JSize length, JIndex* lastindex);

	// not allowed

	GMTextLink(const GMTextLink& source);
	const GMTextLink& operator=(const GMTextLink& source);
};

#endif
