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


// OpenBoardDlg.cpp : implementation file
//

#include "stdafx.h"
#include "constellate.h"
#include "OpenBoardDlg.h"

#include "DxbMgt.h"
#include "mgmtshim.h"


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

/////////////////////////////////////////////////////////////////////////////
// COpenBoardDlg dialog


COpenBoardDlg::COpenBoardDlg(CWnd* pParent /*=NULL*/)
	: CDialog(COpenBoardDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(COpenBoardDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void COpenBoardDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COpenBoardDlg)
	DDX_Control(pDX, IDOK, m_ctrlOpenButton);
	DDX_Control(pDX, IDC_BOARDLIST, m_ctrlBoardList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(COpenBoardDlg, CDialog)
	//{{AFX_MSG_MAP(COpenBoardDlg)
	ON_BN_CLICKED(IDOK, OnOpen)
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_BOARDLIST, OnItemchangedBoardList)
	ON_NOTIFY(NM_DBLCLK, IDC_BOARDLIST, OnDblclkBoardList)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COpenBoardDlg message handlers

BOOL COpenBoardDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

   m_ImageList.Create(IDB_BoardList, 16, 0, RGB(255,255,255));
   m_ctrlBoardList.SetImageList(&m_ImageList, LVSIL_SMALL);

   get_mgmt_board_no_response_t mgmtBoardNoRsp;
#if 0
   if (MgmtCommand(0, GET_MGMT_BOARD_NO, NULL, 0, &mgmtBoardNoRsp, sizeof(mgmtBoardNoRsp)) == MGMT_OK)
#else
   mgmtBoardNoRsp.NumberOfBoards = 10;
#endif
   {
      TRACE("Number of boards == %d\n", mgmtBoardNoRsp.NumberOfBoards);
      for (DWORD i = 0; i < mgmtBoardNoRsp.NumberOfBoards; i++)
      {
         TCHAR szBoardName[32];
#if 0
         if (cfgGetNameFromBoardNo(i, szBoardName, sizeof(szBoardName)))
#else
         sprintf(szBoardName, "Board%d", i);
#endif
         {
            m_ctrlBoardList.InsertItem(i, szBoardName, 0);
         }
      }
   }

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void COpenBoardDlg::OnOpen() 
{
   
}

void COpenBoardDlg::OnItemchangedBoardList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;

   if ((pNMListView != NULL) && (pNMListView->uNewState & LVIS_SELECTED))
   {
      TRACE("Index of selected item == %d\n", pNMListView->iItem);
      TRACE("Selected item is %s\n", m_ctrlBoardList.GetItemText(pNMListView->iItem, 0));
   }
	
	*pResult = 0;
}

void COpenBoardDlg::OnDblclkBoardList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	
	*pResult = 0;
}
