//
//	Class:		CStaticST
//
//	Version:	See GetVersionC() or GetVersionI()
//
//	Created:	11/Nov/2002
//	Updated:	12/Jul/2007
//				29/Sep/2015
//				22/Dec/2017
//
//	Author:		Davide Calabro'		info@softechsoftware.it
//									http://www.softechsoftware.it
//
//	Disclaimer
//	----------
//	THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT
//	ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO REPONSIBILITIES FOR POSSIBLE
//	DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE
//	RISK OF USING THIS SOFTWARE.
//
//	Terms of use
//	------------
//	In the past years SoftechSoftware has produced many free controls and code snippets.
//	All of this products were released with the full source codes included and hundreds of developers
//	all around the world have taken benefits using these easy and ready to use controls into their applications.
//	In return, SoftechSoftware asked only for a small money donation from developers.
//	Unfortunately only a very limited number of donations has been received from the large number of users
//	that rely on SoftechSoftware products for their applications.
//	Producing and updating good software costs time. So it costs money. Also, maintaning a dedicated web site
//	costs time and money.
//
//	Starting from now on almost all SoftechSoftware products will be distributed into a single general use DLL.
//	This DLL will show an annoying dialog each time your application starts. Also, this demo DLL has resource
//	and memory leaks that make your target application unstable. You can use the demo DLL only for testing
//	the SoftechSoftware product you are interested in. Then if you decide to use this product into your
//	application you must buy the full DLL version directly from SoftechSoftware.
//
//	SoftechSoftware
//	Davide Calabro'
//	Italy
//
//	http://www.softechsoftware.it
//
#pragma once

// Uncomment following line if you are using this class outside the DLL
//#define _STATICST_NODLL_

#ifndef _STATICST_NODLL_
#ifndef	_SOFTECHSOFTWAREDLL_NOLIB_
	#ifdef _DEBUG
		#ifdef _UNICODE
			#ifdef	_WIN64
				#pragma comment(lib, "SoftechSoftwareUD64.lib")
			#else
				#pragma comment(lib, "SoftechSoftwareUD.lib")
			#endif
		#else
			#ifdef	_WIN64
				#pragma comment(lib, "SoftechSoftwareD64.lib")
			#else
				#pragma comment(lib, "SoftechSoftwareD.lib")
			#endif
		#endif
	#else
		#ifdef _UNICODE
			#ifdef	_WIN64
				#pragma comment(lib, "SoftechSoftwareU64.lib")
			#else
				#pragma comment(lib, "SoftechSoftwareU.lib")
			#endif
		#else
			#ifdef	_WIN64
				#pragma comment(lib, "SoftechSoftware64.lib")
			#else
				#pragma comment(lib, "SoftechSoftware.lib")
			#endif
		#endif
	#endif
#endif

	#ifdef	_SOFTECHSOFTWAREDLL_BUILDDLL_
		#define	STATICST_EXPORT	__declspec(dllexport)
	#else
		#define	STATICST_EXPORT	__declspec(dllimport)
	#endif

#else
		#define	STATICST_EXPORT
#endif

// Return values
#ifndef	STATICST_OK
#define	STATICST_OK						0
#endif
#ifndef	STATICST_INVALIDCLICKTYPE
#define	STATICST_INVALIDCLICKTYPE		1
#endif
#ifndef	STATICST_BADPARAM
#define	STATICST_BADPARAM				2
#endif
#ifndef	STATICST_INVALIDRESOURCE
#define	STATICST_INVALIDRESOURCE		3
#endif
#ifndef	STATICST_NOTSUPPORTED
#define	STATICST_NOTSUPPORTED			4
#endif

// MSDN KB Article: 134980
// PRB: C4251 & C4275 Compiler Warnings While Compiling an AFXDLL
#pragma warning(disable: 4275)
#pragma warning(disable: 4251)

class STATICST_EXPORT CStaticST : public CStatic
{
public:
	CStaticST();
	virtual ~CStaticST();

	enum	{	STATICST_CLICK	= 0,		// A single click on the control
				STATICST_DBLCLICK,			// A double click on the control

				STATICST_MAX_CLICKS
			};

	DWORD SetIcon(int nIcon, BOOL bRepaint = TRUE, HINSTANCE hInstance = NULL);
	DWORD SetIcon(HICON hIcon, BOOL bRepaint = TRUE);

	void SetTooltipText(int nId, BOOL bActivate = TRUE);
	void SetTooltipText(LPCTSTR lpszText, BOOL bActivate = TRUE);
	void ActivateTooltip(BOOL bActivate = TRUE);

	void SetColors(COLORREF crTextColor, COLORREF crBkColor, BOOL bRepaint = TRUE);
	void SetTextColor(COLORREF crTextColor, BOOL bRepaint = TRUE);
	void SetBkColor(COLORREF crBkColor, BOOL bRepaint = TRUE);

	DWORD SetMessageClick(BYTE byClickType, HWND hWnd, UINT nMsg);

	DWORD SetTextMargins(int nTextMargin, BOOL bRepaint = TRUE);

	DWORD DrawTransparent(BOOL bRepaint = FALSE);
	DWORD SetBk(CDC* pDC);

	void SetFont(CFont* pFont, BOOL bRedraw = TRUE);

	static short GetVersionI()		{return 13;}
	static LPCTSTR GetVersionC()	{return (LPCTSTR)_T("1.3");}


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CStaticST)
	public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	//}}AFX_VIRTUAL

protected:
	virtual DWORD OnDrawBackground(CDC* pDC, CRect* pRect);
	virtual DWORD OnDrawBorder(CDC* pDC, CRect* pRect);

	//{{AFX_MSG(CStaticST)
	afx_msg void OnPaint();
	afx_msg void OnNcPaint();
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	//}}AFX_MSG

	CFont			m_Font;

	BOOL			m_bCustomFont;		// Custom font assigned to the control ?
	BOOL			m_bDrawTransparent;	// Draw transparent?
	COLORREF		m_crTextColor;
	COLORREF		m_crBkColor;

	HICON			m_hIcon;
	BYTE			m_cyIcon;
	BYTE			m_cxIcon;

	int				m_nTextMargin;		// How many extra blank pixels around the text

private:
	void FreeResources(BOOL bCheckForNULL = TRUE);
	void PaintBk(CDC* pDC);
	void InitToolTip();
	void DrawItem(CDC* pDC);
	void DrawTheIcon(CDC* pDC, CRect* rpCtrl, BOOL bText);
	void DrawTheText(CDC* pDC, CRect* rpCtrl, CString& sText, DWORD dwStyle, DWORD dwExStyle);

	CToolTipCtrl	m_ToolTip;

	CDC				m_dcBk;
	CBitmap			m_bmpBk;
	CBitmap*		m_pbmpOldBk;

#pragma pack(1)
	typedef struct _STRUCT_CLICKS
	{
		HWND		hWnd;			// Window that will receive the message
		UINT		nMsg;			// Message to send
	} STRUCT_CLICKS;
#pragma pack()

	STRUCT_CLICKS	m_csClicks[STATICST_MAX_CLICKS];

	DECLARE_MESSAGE_MAP()
};

#pragma warning(default: 4275)
#pragma warning(default: 4251)

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
