/***************************************************************************
 *   Copyright (C) 2004-2007 by Georgy Yunaev, gyunaev@ulduzsoft.com       *
 *   Please do not use email address above for bug reports; see            *
 *   the README file                                                       *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/

#ifndef KCHMVIEWWINDOW_H
#define KCHMVIEWWINDOW_H

#include "forwarddeclarations.h"
#include "tde-tqt.h"

/**
@author Georgy Yunaev
*/
class KCHMViewWindow
{
public:
	KCHMViewWindow ( TQTabWidget * parent );
    virtual ~KCHMViewWindow();

	//! Open a page from current chm archive
	bool	openUrl (const TQString& url );
	
	TQString	getBaseUrl() const	{ return m_base_url; }
	TQString	getOpenedPage() const	{ return m_openedPage; }
	TQString	getNewTabLink() const	{ return m_newTabLinkKeeper; }
	TQString	makeURLabsolute ( const TQString &url, bool set_as_base = true );
	
public: 
	// virtual members, which should be implemented by viewers
	//! Invalidate current view, doing all the cleanups etc.
	virtual void	invalidate();

	//! Popups the print dialog, and prints the current page on the printer.
	virtual bool	printCurrentPage() = 0;

	//! Continues the find-in-page search forward or backward
	virtual void	searchWord( const TQString & word, bool forward = true, bool casesensitive = false ) = 0;

	//! Return current ZoomFactor.
	virtual int		getZoomFactor() const = 0;
	
	//! Sets ZoomFactor. The value returned by getZoomFactor(), given to this function, should give the same result.
	virtual void	setZoomFactor (int zoom) = 0;
	
	//! Relatively changes ZoomFactor. Most common values are -1 and 1.
	virtual void	addZoomFactor (int value) = 0;

	virtual TQObject *	getTQObject() = 0;
	virtual TQWidget *	getTQWidget() = 0;

	/*!
	 * Return current scrollbar position in view window. Saved on program exit. 
	 * There is no restriction on returned value, except that giving this value to 
	 * setScrollbarPosition() should move the scrollbar in the same position.
	 */
	virtual int		getScrollbarPosition() = 0;
	
	//! Sets the scrollbar position.
	virtual void	setScrollbarPosition(int pos) = 0;

	//! Select the content of the whole page
	virtual void	clipSelectAll() = 0;

	//! Copies the selected content to the clipboard
	virtual void	clipCopy() = 0;

	//! Returns the window title
	virtual TQString	getTitle() const;
	
	//! Navigation stuff
	virtual void	navigateBack();
	virtual void	navigateHome();
	virtual void	navigateForward();
	
	//! Navigation auxiliary stuff
	virtual void	setHistoryMaxSize (unsigned int size) { m_historyMaxSize = size; }
	virtual void	addNavigationHistory( const TQString & url, int scrollpos );
	virtual void 	updateNavigationToolbar();
	
	/*! 
	 * Used by contents window (and probably by other windows in future) to show
	 * context menu in listviews. Put here to futher reuse code in index and search windows.
	 */
	KTQPopupMenu *	createListItemContextMenu ( TQWidget * w );
	void			setTabKeeper ( const TQString& link );
	
		
protected: /* signals */
	/*!
	 * Emitted when the user clicked on the link, before the page changed.
	 * If linkClicked() return false, the current page should NOT change.
	 * Otherwise it should be changed to the new link value.
	 */
	virtual void	signalLinkClicked ( const TQString & newlink, bool& follow_link ) = 0;

protected:
	virtual bool	openPage ( const TQString& url ) = 0;
	virtual void	handleStartPageAsImage( TQString& link );
	
	KTQPopupMenu * 	getContextMenu( const TQString& link, TQWidget * parent );
	KTQPopupMenu * 	createStandardContextMenu( TQWidget * parent );
	
	//! History
	class KCHMUrlHistory
	{
		public:
			KCHMUrlHistory() { scrollbarpos = 0; }
			KCHMUrlHistory( const TQString& _url, int _scrollbarpos )
			: url(_url), scrollbarpos(_scrollbarpos) {};
		
			const TQString&  getUrl() const { return url; }
			int 			getScrollPosition() const { return scrollbarpos; }
			void			setScrollPosition( int pos ) { scrollbarpos = pos; }
			
		private:
			TQString  	url;
			int 		scrollbarpos;
	};

	unsigned int	m_historyMaxSize;
	unsigned int	m_historyCurrentPos;
	
	TQValueList<KCHMUrlHistory>		m_history;
	
	KTQPopupMenu *	m_contextMenu;
	KTQPopupMenu *	m_contextMenuLink;
	
	// This member keeps a "open new tab" link between getContextMenu() call and appropriate
	// slot call
	TQString			m_newTabLinkKeeper;

	TQString 		m_openedPage;
	TQString 		m_lastOpenedPage;
	TQString			m_base_url;

	TQTabWidget	*	m_parentTabWidget;
};

#endif
