/*******************************************************************

Copyright (c) 2004 Open Mobile Alliance, Ltd.  All Rights Reserved.

This software is made available under the usage and distribution terms 
covered by the Common Public License 1.0 and by using this software you
are bound by the terms and conditions of the same.

EXCEPT AS EXPRESSLY SET FORTH IN THE COMMON PUBLIC LICENSE,
THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, 
ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
   
Each recipient is solely responsible for determining the 
appropriateness of using and distributing this program and assumes 
all risks associated with its exercise of rights under the Common 
Public License, including but not limited to the risks and 
costs of program errors, compliance with applicable laws, 
damage to or loss of data, programs or equipment, and 
unavailability or interruption of operations.

********************************************************************/
// UIAInput.cpp : implementation file
//

#include "stdafx.h"
#include "scts3devman.h"
#include "UIAInput.h"

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

/////////////////////////////////////////////////////////////////////////////
// CUIAInput dialog


CUIAInput::CUIAInput(SctsSemaphore& _lock,char *_deviceID,char *_display,CString &_input,char _et,char _it,int _maxLen,CWnd* pParent /*=NULL*/)
	: CDialog(CUIAInput::IDD, pParent),lock(_lock),deviceID(_deviceID),display(_display),input(_input),et(_et),it(_it),maxLen(_maxLen),isModal(false)
{
	//{{AFX_DATA_INIT(CUIAInput)
	m_edit = _T("");
	//}}AFX_DATA_INIT
}


void CUIAInput::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUIAInput)
	DDX_Text(pDX, IDC_EDIT, m_edit);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CUIAInput, CDialog)
	//{{AFX_MSG_MAP(CUIAInput)
	ON_WM_DESTROY()
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUIAInput message handlers

BOOL CUIAInput::OnInitDialog() 
{
	CDialog::OnInitDialog();
	GetDlgItem(IDC_DISPLAY)->SetWindowText(display);
	SetWindowText(deviceID);
	m_edit=input;
	UpdateData(FALSE);
	if (maxLen) ((CEdit *)GetDlgItem(IDC_EDIT))->SetLimitText(maxLen);
	if (et=='P') ((CEdit *)GetDlgItem(IDC_EDIT))->SetPasswordChar('*');
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CUIAInput::OnDestroy() 
{
	CDialog::OnDestroy();
	input=m_edit;
	lock.Unlock();
	delete this;
}

void CUIAInput::OnClose() 
{
	UpdateData(TRUE);
	input=m_edit;
	CDialog::OnClose();
	lock.Unlock();
	delete this;
}

void CUIAInput::OnOK()
{
    if (isModal)
    {
        UpdateData(TRUE);
        EndDialog(IDOK);
    }
    else
    {
	    OnClose();
    }
}

void CUIAInput::OnCancel()
{
    if (isModal)
    {
        EndDialog(IDCANCEL);
    }
    else
    {
	    OnDestroy();
    }
}

int CUIAInput::DoModal()
{
	isModal = true;
    return CDialog::DoModal();
}
