/*****************************************************************************
* Copyright (c) 1990-98 Digi International Inc., All Rights Reserved
* 
* This software contains proprietary and confidential information of Digi
* International Inc.  By accepting transfer of this copy, Recipient agrees
* to retain this software in confidence, to prevent disclosure to others,
* and to make no use of this software other than that for which it was
* delivered.  This is an unpublished copyrighted work of Digi International
* Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
* prohibited.
* 
* Restricted Rights Legend
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7031 or
* subparagraphs (c)(1) and (2) of the Commercial Computer Software -
* Restricted Rights at 48 CFR 52.227-19, as applicable.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
*
*****************************************************************************/


// PageModemCC.cpp: implementation of the CPageModemCC class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "PageModemCC.h"

#include "ModemCCDisplayNameMap.h"
#include "Resource.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CPageModemCC::CPageModemCC() : CPageComboBox()
{
}

CPageModemCC::CPageModemCC(int const eMode, CConfigObject const * const pOwner /* = NULL */, int const nState /* = -1 */) : CPageComboBox()
{
   Construct(eMode, pOwner, nState);
}

void CPageModemCC::Construct(int const eMode, CConfigObject const * const pOwner /* = NULL */, int const nState /* = -1 */)
{
   try
   {
      CString strTitle = TEXT("");
      CString strInstruction = TEXT("");
      UINT nIDCaption = 0;

      if (eMode == WIZARD)
      {
         AffirmThrow(strTitle.LoadString(IDS_Title_ModemCC));
         AffirmThrow(strInstruction.LoadString(IDS_Instruction_ModemCC));
      }
      else
      {
         nIDCaption = IDS_Title_ModemCC;
         AffirmThrow(strInstruction.LoadString(IDS_Instruction_PropPageModemCC));
      }

      CPageComboBox::Construct(eMode, nIDCaption, pOwner, nState, strTitle, strInstruction);

      SetHelpID(IDH_WizPageModemNationality);
   }
   catch (CAffirmException ae)
   {
   }
}

CPageModemCC::~CPageModemCC()
{
}

void CPageModemCC::Init(CDWordArray const & adwModemCCsAllowed)
{
   try
   {
      // copy list passed in
      m_adwModemCCsAllowed.Copy(adwModemCCsAllowed);

      // reset display names
      m_astrModemCCDisplayNames.RemoveAll();

      CModemCCDisplayNameMap mapModemCCDisplayNames;

      for (int i = 0; i < m_adwModemCCsAllowed.GetSize(); i++)
      {
         m_astrModemCCDisplayNames.Add(mapModemCCDisplayNames[m_adwModemCCsAllowed[i]]);
      }
   }
   catch (CAffirmException ae)
   {
   }
}

void CPageModemCC::SetModemCC(DWORD const dwModemCC)
{
   try
   {
      AffirmThrow(m_adwModemCCsAllowed.GetSize() > 0);
      AffirmThrow(m_astrModemCCDisplayNames.GetSize() > 0);
      AffirmThrow(m_adwModemCCsAllowed.GetSize() == m_astrModemCCDisplayNames.GetSize());

      AffirmThrow(SetValues(m_astrModemCCDisplayNames, GetModemCCIndex(dwModemCC)));
   }
   catch (CAffirmException ae)
   {
   }
}

DWORD CPageModemCC::GetModemCC(void)
{
   DWORD dwModemCC = 0;

   try
   {
      AffirmThrow(m_adwModemCCsAllowed.GetSize() > 0);
      AffirmThrow(m_astrModemCCDisplayNames.GetSize() > 0);
      AffirmThrow(m_adwModemCCsAllowed.GetSize() == m_astrModemCCDisplayNames.GetSize());

      int iChoice = GetChoice();
      AffirmThrow(iChoice >= 0);
      AffirmThrow(iChoice < m_adwModemCCsAllowed.GetSize());

      dwModemCC = m_adwModemCCsAllowed[iChoice];
   }
   catch (CAffirmException ae)
   {
   }

   return dwModemCC;
}

int CPageModemCC::GetModemCCIndex(DWORD const dwModemCC)
{
   int iModemCC = 0;

   try
   {
      AffirmThrow(m_adwModemCCsAllowed.GetSize() > 0);

      for (int i = 0; i < m_adwModemCCsAllowed.GetSize(); i++)
      {
         if (dwModemCC == m_adwModemCCsAllowed[i])
         {
            iModemCC = i;
            break;
         }
      }
   }
   catch (CAffirmException ae)
   {
   }

   return iModemCC;
}
