///////////////////////////////////////////////////////////
//
//  DEFINITION
//
//  CONTEXT: Genesis3D lightweight framework
//  MODULE:	 abstract main window class
//  PREREQ:	 customized resource.h 
//  FILE:	 mainviewcontroller.h
//	AUTHOR:  Klaus Zerbe <klaus@zerbe.com>
//  ORIGIN:  http://klaus.zerbe.com
//  VERSION: 1.0
//  DATE:    3.2.1999
//  PURPOSE: Kapselung der Windows-Hauptfenster Verwaltung
//
///////////////////////////////////////////////////////////

#ifndef __MAINVIEWCONTROLLER__
#define __MAINVIEWCONTROLLER__

#define MAX_LOADSTRING 100 // max. string length for title and window class

// left and right mouse buttons
enum MouseButton { btnLeft, btnRight };

// abstract main window classs
// does all MS-Windows related main window management
// and implements main loop and message handling
// This is a singleton, since every app has just a mainwindow
//
class CMainViewController {
public:
	CMainViewController();
	virtual ~CMainViewController() {}
	// get instance
	static CMainViewController* GetCurrent();
	// register class and store WinMain arguments
	static BOOL Initialize(HINSTANCE hInst, LPSTR pCmdLine);
	// get Windows application handle
	static HINSTANCE GetInstance() { return m_hInst; }
	// create window sized width x height
	virtual bool Create(int width, int height);
	// main loop
	virtual int Run();
	// idle loop processing (eg. for render)
	virtual bool DoEvent();
	// get main window handle
	HWND GetHandle() { return m_hWnd; }
	// get main window title
	LPSTR GetCaption() { return m_szTitle; }
	// switch idle loop processing (rendering)  on/off
	void SetReady(bool bReady) { m_bReady= bReady; }
	// is app ready for rendering?
	bool IsReady() { return m_bReady; }
	// show "About" box
	void ShowInfo();
protected:
	// overridable callbacks (events)
	//
	
	// do idle processing until returning false
	virtual BOOL DoIdle() { return FALSE; }
	// process keyboard messages
	virtual bool OnKeyDown(DWORD dwKeyCode) { return false; }
	virtual bool OnKeyUp(DWORD dwKeyCode) { return false; }
	// process mouse messages
	virtual bool OnButtonDown(MouseButton butt, POINT pos) { return false; }
	virtual bool OnButtonUp(MouseButton butt, POINT pos) { return false; }
	// place main window cursor
	virtual bool OnSetCursor() { return false; }
	// handle menu selection
	virtual bool OnCommand(WORD wId, WORD wNotify) { return false; }
	// paint client area of main window
	virtual bool OnPaint(HWND hwnd) { return false; }
	// do on window get activated
	virtual bool OnActivateApp(BOOL activated) { return false; }
	// do on app shutdown
	virtual bool OnDestroy() { return false; }
	// do before main window get closed
	virtual bool OnClose() { return false; }
	// do before main window structure is created
	virtual bool OnCreate(HWND hwnd) { return false; }
private:
	// main window function
	friend long CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
	// about box function
	friend LRESULT CALLBACK About( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
	
	static HINSTANCE m_hInst; // application handle
	static LPSTR m_pCmdLine;  // command line arguments
	static TCHAR m_szWindowClass[MAX_LOADSTRING]; // main window class
	static CMainViewController* m_pCurrent; // singleton instance
	TCHAR m_szTitle[MAX_LOADSTRING]; // main window title
	HWND m_hWnd; // main window handle
	HACCEL m_hAccelTable; // hotkeys
	MSG m_msg; // current windows message
	bool m_bReady; // idle processing/rendering active
};

#endif
