/*****************************************************************************
Open Source MIT License

Copyright (c) 2017 Matthew Ahmed

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*****************************************************************************/

// WinDlg.h: interface for the ZDlg class.
//
//////////////////////////////////////////////////////////////////////

#pragma once

#include "ZWin.h"


// WM_COMMAND handlers (with DLGPROC return TRUE - no further handling)
// All these assume OwnProc(HWND hDlg, UINT uMsg, WPARAM wP, LPARAM lP)
#define DTAKECMD(wP_LO, fn) case wP_LO : (fn)(); return TRUE
#define DTAKECMDPARMS(wP_LO, fn) case wP_LO : (fn)(wP, lP); return TRUE
// Other Window message handlers
#define DTAKEMSG(msg, fn) case msg : (fn)(); return TRUE
#define DTAKEMSGPARMS(msg, fn) case msg : (fn)(wP, lP); return TRUE

// Same WM_COMMAND handlers but DLGPROC break - then default handling)
#define DSEECMD(wP_LO, fn) case wP_LO : (fn)(); break
#define DSEECMDPARMS(wP_LO, fn) case wP_LO : (fn)(wP, lP); break
// Other Window message handlers
#define DSEEMSG(msg, fn) case msg : (fn)(); break
#define DSEEMSGPARMS(msg, fn) case msg : (fn)(wP, lP); break

// Same WM_COMMAND handlers but function determines return
#define DRETCMD(wP_LO, fn) case wP_LO : return (fn)()
#define DRETCMDPARMS(wP_LO, fn) case wP_LO : return (fn)(wP, lP)
// Other Window message handlers
#define DRETMSG(msg, fn) case msg : return (fn)()
#define DRETMSGPARMS(msg, fn) case msg : return (fn)(wP, lP)

// Less typing
#define SendItemMsg(nID, uMsg, wP, lP) \
	SendDlgItemMessage(m_hWnd, nID, uMsg, wP, lP)
#define GetItem(nID) GetDlgItem(m_hWnd, nID)
#define SetItemText(nID, s) SetDlgItemText(m_hWnd, nID, s)
#define GetItemText(nID, s, nMax) GetDlgItemText(m_hWnd, nID, s, nMax)
#define IsBnChecked(nID) IsDlgButtonChecked(m_hWnd, nID)
#define CheckBn(nID, bCheck) /* N.B.: CheckBn only for two state buttons  */ \
	CheckDlgButton(m_hWnd, nID, bCheck ? BST_CHECKED : BST_UNCHECKED)
#define CheckRB(n0, n9, nChk) CheckRadioButton(m_hWnd, n0, n9, nChk)
#define EnableItem(nID, bEnable) EnableWindow(GetDlgItem(m_hWnd, nID), bEnable)
#define ShowItem(nID, nShow) ShowWindow(GetDlgItem(m_hWnd, nID), nShow)

class ZDlg : public ZWin  
{
public:
	ZDlg(HINSTANCE hInst, LPCTSTR sCapt1, LPCTSTR sCapt2 = NULL,
       ZWin * pOwner = NULL, ZWinAppData * pzwd = NULL);

	INT Run();
	HWND RunModeless();
	BOOL OwnProc(HWND hDlg, UINT uMsg, WPARAM wP, LPARAM lP);

protected:
	BOOL (*m_pProc)(HWND, UINT, WPARAM, LPARAM);
	UINT m_uID;
	virtual void OnCancel();
	virtual void OnOk();
	virtual BOOL OnInitDialog();
  virtual void OnClose(); // Not called by OK
  virtual void OnDestroy();

  // Utility functions
  void GetControlRect(HWND hCtl, RECT * pRect);
};
