/*	HandleItemHit(theDialog, itemID, dsp)
	
	Called when the item identified by itemID is hit.
	Carries out any actions necessitated by the hit.
*/
static void
HandleItemHit(XOP_DIALOG_REF theDialog, int itemID, DialogStorage* dsp)
{
	int selItem;
	double d1;
	
	if (ItemIsPopMenu(theDialog, itemID))
		GetPopMenu(theDialog, itemID, &selItem, NULL);
	
	switch(itemID) {
		case SCALING_OFFSET_TEXT:
			dsp->offsetNoGood = GetDDouble(theDialog, SCALING_OFFSET_TEXT, &d1);
			break;
		
		case SCALING_MULTIPLIER_TEXT:
			dsp->multiplierNoGood = GetDDouble(theDialog, SCALING_MULTIPLIER_TEXT, &d1);
			break;
		
		case OK_BUTTON:
			ProcessOK(theDialog, dsp);
			break;
	}

	UpdateDialogItems(theDialog, dsp);
}
LRESULT DCLSTGenDlg::onInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	if (_Dir == NULL || _usr == NULL)
		return TRUE;
		
		
	SetWindowText(CTSTRING(DCLSTGEN_TITLE));
	CenterWindow(GetParent());
	
	// fill in dialog bits
	SetDlgItemText(IDC_DCLSTGEN_INFOBORDER, CTSTRING(DCLSTGEN_INFOBORDER));
	SetDlgItemText(IDC_DCLSTGEN_INFO_SIZESTATIC, CTSTRING(DCLSTGEN_INFO_SIZESTATIC));
	SetDlgItemText(IDC_DCLSTGEN_INFO_FOLDERSSTATIC, CTSTRING(DCLSTGEN_INFO_FOLDERSSTATIC));
	SetDlgItemText(IDC_DCLSTGEN_INFO_FILESSTATIC, CTSTRING(DCLSTGEN_INFO_FILESSTATIC));
	SetDlgItemText(IDC_DCLSTGEN_NAMEBORDER, CTSTRING(DCLSTGEN_NAMEBORDER));
	SetDlgItemText(IDC_DCLSTGEN_NAMESTATIC, CTSTRING(MAGNET_DLG_FILE));
	SetDlgItemText(IDC_DCLSTGEN_SAVEAS, CTSTRING(DCLSTGEN_RENAMEAS));
	SetDlgItemText(IDC_DCLSTGEN_SHARE, CTSTRING(DCLSTGEN_SHARE));
	SetDlgItemText(IDC_DCLSTGEN_COPYMAGNET, CTSTRING(COPY_MAGNET));
	SetDlgItemText(IDCANCEL, CTSTRING(CANCEL));
	
	GetDlgItem(IDC_DCLSTGEN_SAVEAS).EnableWindow(FALSE);
	GetDlgItem(IDC_DCLSTGEN_SHARE).EnableWindow(FALSE);
	GetDlgItem(IDC_DCLSTGEN_COPYMAGNET).EnableWindow(FALSE);
	
	// for Custom Themes Bitmap
	_img_f.LoadFromResource(IDR_FLYLINK_PNG, _T("PNG"));
	GetDlgItem(IDC_STATIC).SendMessage(STM_SETIMAGE, IMAGE_BITMAP, LPARAM((HBITMAP)_img_f));
	// IDC_DCLSTGEN_PICT
	_img.LoadFromResource(IDR_DCLST, _T("PNG"));
	GetDlgItem(IDC_DCLSTGEN_PICT).SendMessage(STM_SETIMAGE, IMAGE_BITMAP, LPARAM((HBITMAP)_img));
	
	// _totalSizeDir = _Dir->getTotalSize();
	
	_filesCount = _Dir->getTotalFileCount();
	
	//::SendMessage(GetDlgItem(IDC_DCLSTGEN_PROGRESS), PBM_SETRANGE32, 0, 100);
	//::SendMessage(GetDlgItem(IDC_DCLSTGEN_PROGRESS), PBM_SETPOS, 5, 0L);
	_pBar.Attach(GetDlgItem(IDC_DCLSTGEN_PROGRESS));
	_pBar.SetRange32(0, 100);
	// _pBar.SetPos(5);
	_pBar.Detach();
	
	std::string fileName = _Dir->getName();
	if (fileName.empty())
		fileName = _usr->getLastNick();
	_mNameDCLST = getDCLSTName(fileName);
	SetDlgItemText(IDC_DCLSTGEN_NAME, Text::toT(_mNameDCLST).c_str());
	
	UpdateDialogItems();
	
	_isInProcess = true;
	start(0);
	
	
	return 0;
}
LRESULT DCLSTGenDlg::OnFinishedDCLSTWindow(UINT uMsg, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
{
	UpdateDialogItems();
	
	SetDlgItemText(IDC_DCLSTGEN_MAGNET,  Text::toT(_strMagnet).c_str());
	
	GetDlgItem(IDC_DCLSTGEN_SAVEAS).EnableWindow(TRUE);
	GetDlgItem(IDC_DCLSTGEN_SHARE).EnableWindow(TRUE);
	GetDlgItem(IDC_DCLSTGEN_COPYMAGNET).EnableWindow(TRUE);
	return 0;
}
/*	InitDialogSettings(theDialog, dsp)

	Called when the dialog is first displayed to initialize all items.
*/
static int
InitDialogSettings(XOP_DIALOG_REF theDialog, DialogStorage* dsp)
{
	int err;
	
	err = 0;
	
	InitPopMenus(theDialog);
	
	do {
		SetDDouble(theDialog, SCALING_OFFSET_TEXT, dsp->offsetPtr);
		SetDDouble(theDialog, SCALING_MULTIPLIER_TEXT, dsp->multiplierPtr);
		SelEditItem(theDialog, SCALING_OFFSET_TEXT);
		
		UpdateDialogItems(theDialog, dsp);
	} while(0);
	
	if (err != 0)
		KillPopMenus(theDialog);

	return err;
}
LRESULT DCLSTGenDlg::OnUpdateDCLSTWindow(UINT uMsg, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
{
	UpdateDialogItems();
	return 0;
}