#pragma once
//#include "KsCPP_Exports.h"
#include <map>
#include "properties.h"

class CWizard;

class CWizardPage : public CBCGPDialog
{
	READONLY_PROPERTY(CString, _title, L"", title) // setTitle另定
	READONLY_PROPERTY(CString, _desc, L"", desc)	// setDesc另定
	READONLY_POINTER_PROPERTY(CWizard, _wizard, nullptr, wizard)

	void setTitle(const wchar_t* t);
	void setTitle(const CString& t);
	void setDesc(const wchar_t* t);
	void setDesc(const CString& t);

public:
	CWizardPage(UINT nIDTemplate, CWizard* pParentWnd = NULL);

	/// @brief 构造函数已经指定IDD和父窗口时可以用这个简化的Create()
	void Create() {
		ASSERT(m_pParentWnd != nullptr);
		ASSERT(m_lpszTemplateName !=nullptr);
		Create(m_lpszTemplateName, m_pParentWnd);
	}

	using CBCGPDialog::Create;


	enum TriState { Tri_Unknown = -1, Tri_False, Tri_True };

	void setFinalPage(bool finalPage);
	bool isFinalPage() const;
	void setCommitPage(bool commitPage);
	bool isCommitPage() const;

	/*!
	This virtual function is called by QWizard::initializePage() to
	prepare the page just before it is shown either as a result of QWizard::restart()
	being called, or as a result of the user clicking \uicontrol Next.
	(However, if the \l QWizard::IndependentPages option is set, this function is only
	called the first time the page is shown.)

	By reimplementing this function, you can ensure that the page's
	fields are properly initialized based on fields from previous
	pages. For example:

	\snippet dialogs/classwizard/classwizard.cpp 17

	The default implementation does nothing.

	\sa QWizard::initializePage(), cleanupPage(), QWizard::IndependentPages
*/
	virtual void initializePage(){}

	virtual void cleanupPage();
	/*!
	This virtual function is called by QWizard::validateCurrentPage()
	when the user clicks \uicontrol Next or \uicontrol Finish to perform some
	last-minute validation. If it returns \c true, the next page is shown
	(or the wizard finishes); otherwise, the current page stays up.

	The default implementation returns \c true.

	When possible, it is usually better style to disable the \uicontrol
	Next or \uicontrol Finish button (by specifying \l{mandatory fields} or
	reimplementing isComplete()) than to reimplement validatePage().

	\sa QWizard::validateCurrentPage(), isComplete()
*/
	virtual bool validatePage() {return true;}
	virtual bool isComplete() const;
	virtual int nextId() const;

	void setButtonText(int which, const CString& text);

	// 很多Radio、CheckBox的点击事件只需要更新数据，不需要其它，所以这里提供一个简化的UpdateData
	afx_msg void CallUpdateData() {
		UpdateData();
	}

protected:
	mutable TriState completeState = Tri_Unknown;
	bool explicitlyFinal = false;
	bool commit = false;
	bool initialized = false;
	std::map<int, CString> buttonCustomTexts;

	friend class CWizard;

	
};

