//this file is part of eMule
//Copyright (C)2002 Merkur ( merkur-@users.sourceforge.net / http://www.emule-project.net )
//
//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., 675 Mass Ave, Cambridge, MA 02139, USA.


#pragma once
#include "searchlistctrl.h"
#include "afxcmn.h"
#include "packets.h"
#include "types.h"
#include "afxwin.h"
#include "iconstatic.h"
#include "closabletabctrl.h"

class CCustomAutoComplete;

// CSearchDlg dialog
class CSearchDlg : public CResizableDialog
{
	DECLARE_DYNAMIC(CSearchDlg)

public:
	CSearchDlg(CWnd* pParent = NULL);   // standard constructor
	virtual ~CSearchDlg();
	
	afx_msg void OnBnClickedStarts();
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnBnClickedCancels();
	afx_msg void OnBnClickedSdownload();
	afx_msg void OnBnClickedClearall();
	afx_msg void OnBnClickedSearchReset();
	afx_msg void OnEnKillfocusElink();
	afx_msg void OnSearchKeyDown();

	enum { IDD = IDD_SEARCH };

	void	Localize();
	void	DownloadSelected();
	void	LocalSearchEnd(uint16 count);
	void	AddUDPResult(uint16 count);
	void	DeleteSearch(uint32 nSearchID);
	void	DeleteAllSearchs();
	bool	CreateNewTab(CString searchString,uint32 nSearchID);
	void	UpdateCatTabs();
	void	SearchClipBoard();
	void	AddEd2kLinksToDownload(CString strlink,uint8 cat);
	void	AddEd2kLinksToDownload(CString strlink)	{AddEd2kLinksToDownload(strlink,m_cattabs.GetCurSel());}
	CSearchListCtrl searchlistctrl;
	CClosableTabCtrl searchselect;
	void	IgnoreClipBoardLinks(CString strlink)		{m_lastclpbrd = strlink; }
	void	DoNewSearch(CString searchString, CString typeText,unsigned long min, unsigned long max, 
			int avaibility,CString extension,bool doGlobal );
	void	ShowSearchSelector(bool visible);
	BOOL	SaveSearchStrings();

protected:
	void StartNewSearch();
	LRESULT OnCloseTab(WPARAM wparam, LPARAM lparam);
	CString	CreateWebQuery();

	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	virtual BOOL OnInitDialog();
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	afx_msg void OnNMDblclkSearchlist(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnTcnSelchangeTab1(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnEnChangeSearchname();

	DECLARE_MESSAGE_MAP()

private:
	Packet*		searchpacket;		
	UINT_PTR	global_search_timer;
	CProgressCtrl searchprogress;
	bool		canceld;
	uint16		servercount;
	bool		globsearch;
	uint32		m_nSearchID;
	CComboBox	methodBox;
	CComboBox	Stypebox;
	CImageList	m_ImageList;
	CTabCtrl	m_cattabs;
	CString		m_lastclpbrd;
	bool		m_guardCBPrompt;
	CCustomAutoComplete* m_pacSearchString;
	CString	ToQueryString(CString str);

	HICON icon_search;
	CIconStatic m_ctrlSearchFrm;
	CIconStatic m_ctrlDirectDlFrm;
};
