// SSCopyDocsDlg.cpp : implementation file
//

#include "stdafx.h"
#include "resource.h"
#include "SSCopyDocsDlg.h"
#include "apl_gui.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSSCopyDocsDlg dialog
BOOL CSSCopyDocsDlg::s_recursive = FALSE;
BOOL CSSCopyDocsDlg::s_rec_docs = TRUE;
BOOL CSSCopyDocsDlg::s_bcheck = TRUE;


CSSCopyDocsDlg::CSSCopyDocsDlg(CWnd* pParent /*=NULL*/)
	: CaplTranslateDialog(CSSCopyDocsDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSSCopyDocsDlg)
	m_sFolder = _T("");
/*	m_recursive = FALSE;
	m_rec_docs = TRUE;
	m_bcheck = TRUE;*/
	//}}AFX_DATA_INIT
	m_add_or_copy = true;
	m_show_check = false;
	m_check_title =  APL_T("Устанавливать файлам атрибут \"Только для чтения\"");
}


void CSSCopyDocsDlg::DoDataExchange(CDataExchange* pDX)
{
	CaplTranslateDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSSCopyDocsDlg)
	DDX_Control(pDX, IDC_SS_FOLDER_BROSE, m_folder_browse);
	DDX_Control(pDX, IDC_CHECK, m_check);
	DDX_Control(pDX, IDC_RECURSIVE_DOCS, m_rec_doc_btn);
	DDX_Control(pDX, IDCANCEL, m_cancel_btn);
	DDX_Control(pDX, IDOK, m_ok_btn);
	DDX_Text(pDX, IDC_SS_FOLDER_BASE, m_sFolder);
	DDX_Check(pDX, IDC_SS_FOLDER_RECURSIVE, m_recursive);
	DDX_Check(pDX, IDC_RECURSIVE_DOCS, m_rec_docs);
	DDX_Check(pDX, IDC_CHECK, m_bcheck);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSSCopyDocsDlg, CaplTranslateDialog)
	//{{AFX_MSG_MAP(CSSCopyDocsDlg)
	ON_BN_CLICKED(IDC_SS_FOLDER_BROSE, OnSsFolderBrose)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSSCopyDocsDlg message handlers

void CSSCopyDocsDlg::OnSsFolderBrose() 
{
	UpdateData();
	// TODO: Add your control notification handler code here
/*    LPTSTR szPath = new char;
	szPath[0] = 0;
    bool result = false;
    
    LPMALLOC pMalloc;
    if (::SHGetMalloc(&pMalloc) == NOERROR) {
        BROWSEINFO bi;
        ::ZeroMemory(&bi,sizeof bi);
        bi.ulFlags = BIF_RETURNONLYFSDIRS;
        LPITEMIDLIST pidl = ::SHBrowseForFolder(&bi);
        if (pidl != NULL) {
            if (::SHGetPathFromIDList(pidl,szPath))
                result = true;
            pMalloc->Free(pidl);
        }
        pMalloc->Release();
		if(szPath) m_sFolder=szPath;
    }*/
	CaplSelectFolderDialog dlg(FALSE, m_sFolder);
	if(dlg.DoModal())
	{
		m_sFolder = dlg.GetSelectedPath();
		UpdateData(false);
	}
}

void CSSCopyDocsDlg::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData();
	s_bcheck = m_bcheck;
	s_rec_docs  = m_rec_docs;
	s_recursive  = m_recursive;
	
	CaplTranslateDialog::OnOK();
}

BOOL CSSCopyDocsDlg::OnInitDialog() 
{
	CaplTranslateDialog::OnInitDialog();

	if(!m_show_check)
		m_check.ShowWindow(SW_HIDE);
	else if(m_check_title>_T(""))
		m_check.SetWindowText(m_check_title);
	if(m_title== APL_T("Завершить редактирование"))
		m_folder_browse.EnableWindow(FALSE);


	m_cancel_btn.SetIcon(GetAplStdIco16(APLSTDICO_CANCEL));
	m_cancel_btn.SetFlat(FALSE);
	m_ok_btn.SetIcon(GetAplStdIco16(APLSTDICO_OK));
	m_ok_btn.SetFlat(FALSE);

	if(m_title>_T(""))
		SetWindowText(m_title);
	m_rec_doc_btn.EnableWindow(m_add_or_copy);
	m_bcheck = s_bcheck;
	m_rec_docs  = s_rec_docs;
	m_recursive  = s_recursive;
	UpdateData(FALSE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

