/*
 * Copyright (c) 2001, 2002, 2003 Gary R. Van Sickle.
 * Copyright (c) 2005-2006 Tom N Harris.
 *
 *     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.
 *
 *     A copy of the GNU General Public License can be found at
 *     http://www.gnu.org/
 *
 * Written by Gary R. Van Sickle <g.r.vansickle@worldnet.att.net>
 * Written by Tom N Harris <telliamed@whoopdedo.org>
 *
 */

#ifndef SETUP_PROPPAGE_H
#define SETUP_PROPPAGE_H

// This is the header for the PropertyPage class.  It works closely with the
// PropSheet class to implement a single page of the property sheet.


#include "win32.h"
#include <prsht.h>
#undef PropertySheet
#ifdef UNICODE
#define DoPropertySheet PropertySheetW
#else
#define DoPropertySheet PropertySheetA
#endif

#include "Window.h"
#include "ControlAdjuster.h"

namespace Setup
{

class PropertySheet;

class PropertyPage : public Window
{
	static bool DoOnceForSheet;
	PROPSHEETPAGE m_psp;
	DLGPROC m_proc;
	BOOL (*m_cmdproc)(HWND h, int id, HWND hwndctl, UINT code);

	// The sheet that owns this page.
	PropertySheet* m_ourSheet;

	// For setting the back/finish buttons properly.
	bool m_isFirst, m_isLast;
  
	static BOOL CALLBACK FirstDialogProcReflector(HWND hwnd, UINT message,
						      WPARAM wParam,
						      LPARAM lParam);
	static BOOL CALLBACK DialogProcReflector(HWND hwnd, UINT message,
						 WPARAM wParam, LPARAM lParam);
	void setTitleFont();

protected:
	SizeProcessor m_sizeProcessor;
  
	virtual BOOL CALLBACK dialogProc(UINT message, WPARAM wParam, LPARAM lParam);

public:
	PropertyPage();
	virtual ~PropertyPage();

	PROPSHEETPAGE* getPROPSHEETPAGEPtr()
	{
		return &m_psp;
	};

private:
	void youAreBeingAddedToASheet(PropertySheet * ps)
	{
		m_ourSheet = ps;
		m_isFirst = false;
		m_isLast = false;
	};
	void youAreFirst()
	{
		m_isFirst = true;
	};
	void youAreLast()
	{
		m_isLast = true;
	};
	void youAreMiddle()
	{
		m_isFirst = false;
		m_isLast = false;
	};

	friend class PropertySheet;

public:
	virtual bool create(int TemplateID);
	virtual bool create(DLGPROC dlgproc, int TemplateID);
	virtual bool create(DLGPROC dlgproc,
			    BOOL (*cmdproc)(HWND h, int id, HWND hwndctl, UINT code),
			    int TemplateID);

	virtual void onInit()
	{
	};
	virtual void onActivate()
	{
	};
	virtual bool wantsActivation() const
	{
		return true;
	};
	virtual void onDeactivate()
	{
	};
	// Return true to abort the cancellation.
	virtual bool onCancel()
	{
		return false;
	};

	// Overload these to perform special processing when the user hits
	// "Next" or "Back". Return:
	// 0 == Go to next/previous page in sequence.
	// -1 == Prevent wizard from changing page.
	// Resource ID == go to a specific page specified by the resource ID.
	enum SequenceID
	{
		NextPage = 0,
		PreviousPage = 0,
		AbortPageChange = -1,
	};

	virtual long onNext()
	{
		return NextPage;
	};
	virtual long onBack()
	{
		return PreviousPage;
	};

	virtual bool onFinish()
	{
		return true;
	};

	enum UnattendedModeID
	{
		SkipPage = 0,
		DisplayPage = -1,
		InterruptAndDisplay = -2,
	};

	virtual long onUnattended()
	{
		return InterruptAndDisplay;
	};

	PropertySheet* getOwner() const
	{
		return m_ourSheet;
	};

	void enableNext(bool enable);
};

};

#endif /* SETUP_PROPPAGE_H */
