#ifndef __CHIPMONK_TYPES__
#define __CHIPMONK_TYPES__

#ifdef WIN32
#ifndef USING_MFC
#include <windows.h>
#include <atltypes.h>
#endif
#else
#define FALSE 	0
#define TRUE 	1

typedef int BOOL;
typedef unsigned int UINT;
typedef UINT size_t;
typedef unsigned char UCHAR; 
typedef UCHAR * PUCHAR; 
typedef unsigned short USHORT;
typedef USHORT WCHAR;
typedef short* PSHORT;
typedef UCHAR BYTE;
typedef TInt64 LONGLONG;
typedef int* LPINT;
typedef const char * LPCTSTR;
typedef short SHORT;
typedef WCHAR* PWCHAR;
typedef USHORT WORD;
typedef UINT DWORD;
typedef long LONG;
typedef unsigned long ULONG;

#define MAX_PATH 512

typedef struct {int left, top, right, bottom;} RECT;
typedef struct {int x, y;} POINT;
typedef RECT* PRECT;

class CPoint
{
	public:
	CPoint ();
	CPoint (int _x, int _y);
	CPoint operator - (const CPoint& r) const;
	const CPoint& operator += (const CPoint& r);
	CPoint operator + (const CPoint& r) const;
	BOOL operator == (const CPoint& r) const;
	BOOL operator != (const CPoint& r) const;
	CPoint operator -() const;
	void Offset(const CPoint & shift);

	int x;
	int y;
};

class CSize {
	int cx, cy;
};

class CRect 
{
	public:
	CRect ();
	CRect (const CRect& r);
	CRect(int _left, int _top, int _right, int _bottom);
	CRect(const RECT &r);
	CRect(const CPoint &topLeft, const CPoint &rightBottom);
	BOOL IntersectRect(const CRect& r1, const CRect& r2);
	void SetRect (int _left, int _top, int _right, int _bottom);
	void SetRectEmpty ();
	BOOL UnionRect (const CRect& r1, const CRect& r2);
	CPoint BottomRight () const;
	CPoint TopLeft () const;
	CPoint CenterPoint() const;
	void CopyRect (const CRect& r);
	void OffsetRect (const CPoint& p);
	void OffsetRect (int x, int y);
	BOOL IsRectNull () const;
	BOOL IsRectEmpty() const;
	void InflateRect (int x, int y);

	
	CRect& operator |= (const CRect& r);
	CRect operator & (const CRect& r) const;
	CRect operator | (const CRect& r) const;
	BOOL operator == (const CRect& r) const;
	BOOL operator != (const CRect& r) const;
	
	int Width() const;
	int Height() const;
	int left;
	int right;
	int top;
	int bottom;
};

typedef CRect* LPRECT;
typedef const CRect* LPCRECT;

template <class T>
inline T max (const T& a, const T& b) {
	return (a>b)?a:b;
}
template <class T>
inline T min (const T& a, const T& b) {
	return (a>b)?b:a;
}


#endif

#define CHIPMONK_INSTALL_DIRECTORY "c:\\Data\\Chipmonk"
#define EndOfWord(c) ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n'|| (c) == '\0')

class CEventBase {
protected:
	int m_nId;
public:	
	CEventBase(int nId) : m_nId(nId) {
	}
	virtual ~CEventBase(){}
	inline int GetId()const {return m_nId;}
};

class CCoordinatorBase {
public:
	virtual void SetEvent(CEventBase *pEvent) = 0;
};

#define EVENT_ZONNING_DONE 		0
#define EVENT_OCR_CHUNK_DONE 	1
#define EVENT_OCR_DONE 			2
#define EVENT_SPEAKING_DONE		3
#define EVENT_PROCESS_CANCELED	4
#define EVENT_SPEAKING_NEW		5
#define EVENT_START_PREVIEW		6
#define EVENT_PAGE_INFO_READY	7

#endif //__CHIPMONK_TYPES__

