/*****************************************************************************
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.
*****************************************************************************/

// MatchDlg.h: interface for the CMatchDlg class.
//
//////////////////////////////////////////////////////////////////////

#pragma once


//#include "ZWinDlg.h"
#include "resource.h"
#include "ZDialog.h"
#include "JpgFolders.h"

// ZDialog insert
//#define IsBnChecked(nID) ::IsDlgButtonChecked(m_hWnd, nID)
#define ROW_TYPE_RED    0
#define ROW_TYPE_NO_SRC 1
#define ROW_TYPE_NO_TGT 2



//class CJpgFolders;
class CPicture;

//BOOL MatchDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);

class CMatchDlg : public CZDialog  
{
public:
  //CMatchDlg(CJpgFolders * pJpf, LPCTSTR sSrcJpg, LPCTSTR sTgtJpg,
  //           HINSTANCE hInst, CSettings * pSet, LPCTSTR sCapt1,
		//						LPCTSTR sCapt2 = NULL, ZWin * pOwner = NULL);
  CMatchDlg(CJpgFolders * pJpf, LPCTSTR sSrcJpg, LPCTSTR sTgtJpg,
            HINSTANCE hInst, CSettings * pSet, LPCTSTR sCapt1, LPCTSTR sCapt2,
            CWnd * pOwner, ZWinAppDataClone * pzwd = NULL);

	~CMatchDlg();
	// ZDialog // BOOL OwnProc(HWND hDlg, UINT uMsg, WPARAM wP, LPARAM lP);

  enum { IDD = IDD_MATCH }; // ZDialog

  // Public so global callback can call
  BOOL SortListview(LPARAM lp1, LPARAM lp2);

  // Vars for CopyDlg to read after OK, on which files to copy
  INT m_nArrToCopy[MAX_ALBUMS]; // Indexes of CJpgFolders items
  INT m_nCountToCopy;


protected:
  // ZDialog insert:
  HINSTANCE m_hInst;
//  HWND m_hParent;
  LRESULT OnWmuUncheck(WPARAM wP, LPARAM);
  void OnLvColumnClick(NMHDR *pNMHDR, LRESULT *pResult);
  void OnLvItemChanging(NMHDR *pNMHDR, LRESULT *pResult);
  void OnClose();
  DECLARE_MESSAGE_MAP()

  // Variables & functions to use with CImage
//  virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
//  BOOL DrawPic(LPCTSTR sImgPath, CImage & img, CStatic & sttc,
//               HWND hWndImg, POINT pntImgTopLeft);
//  void SetImagesForListItem(INT nItem);
  void OnLvItemActivated(NMHDR *pNMHDR, LRESULT *pResult);

//  CStatic m_stSrc;
//  CImage m_imgSrc;
//  CStatic m_stTgt;
//  CImage m_imgTgt;

  HWND m_hImgSrc;
  HWND m_hImgTgt;
  POINT m_pntSrc;
  POINT m_pntTgt;
  POINT m_pntImgWidthHeight;
  POINT m_pntOffset;

  // Change from MFC CImage & CStatic to CPicture
  CPicture * m_pPicSrc;
  CPicture * m_pPicTgt;
  BOOL DrawPic(INT nID);
  void SetPicsForListItem(); // Use m_nLvSelected, not param
  CPoint m_cpZero;
  CSize m_cszHtWd;

  void OnPaint();
  //void OnLvHotTrack(NMHDR *pNMHDR, LRESULT *pResult);
  void OnTimer(UINT nIDEvent);
  //void OnLvGarbageNotify(NMHDR*, LRESULT *pResult);
  void OnLvKeyDown(NMHDR*, LRESULT *pResult);
  INT m_nLvSelected;
  BOOL GetImageDimensions(LPCTSTR sPath, CString & csPixels);
  BOOL m_bImgSrc;
  BOOL m_bImgTgt;


	CSettings * ini;
  HWND m_hList;
  BOOL m_bReviewChecks;
  TCHAR m_sSrcJpg[100];
  TCHAR m_sTgtJpg[100];

  BOOL InitListView(LPCTSTR sSource, LPCTSTR sTarget);
  BOOL InsertListItem(LPCTSTR sSource, LPCTSTR sTarget, INT nImg, INT nIxJpf);
  // ZDialog // BOOL OnNotifyListview(LPNMLISTVIEW pnmv);

  INT m_nLvSortCol;
  INT m_nLvSort2nd; // Only matters if level/color is primary sort
//  INT m_nLvSortDirection; // 1 or -1
  INT m_nLvSortDirectionText; // 1 or -1
  INT m_nLvSortDirectionColor; // 1 or -1

  INT SortListviewCol0(LPARAM lp1, LPARAM lp2);
  INT SortListviewTextCol(LPARAM lp1, LPARAM lp2, INT nColFirst);
  INT ListViewStringSort(LPCTSTR s1, LPCTSTR s2);

  void SetCheckStateAll(BOOL bCheck);
  void SetCheckStateByColor(INT nMaxMatchLevel);

  BOOL ShowOrHideRows(INT nCtlId, INT nMatchLevel);
  BOOL HideRows(INT nMatchLevelToHide);
  BOOL ShowRows(INT nMatchLevelToShow);

  // BOOL CopyFiles(); // Let CopyDlg & child do the actual copy
  BOOL ListFilesToCopy();

	BOOL OnInitDialog();

//	void OnOk();
	void OnOK(); // ZDialog
  void OnBnHelp();
  void OnBnCheckAll();
  void OnBnUnCheckAll();
//  void OnBnCheckColor();
  void OnBnCheckCol0();
  void OnBnCheckCol1();
  void OnBnCheckCol2();
  void OnBnCheckCol3();

  void OnCkHideRed();
  void OnCkHideNoSrc();
  void OnCkHideNoTgt();
  void OnCkHideNoImg();

  CJpgFolders * m_pJpf;
};

