/*
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
// SiteSelectDlg.cpp : implementation file
//
#include "stdafx.h"
#include "d3launch.h"
#include "SiteSelectDlg.h"
#include "LaunchNames.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// Column header info
#define SITE_NAME_COLUMN 0
#define SITE_ADDRESS_COLUMN 1
#define SITE_LOCATION_COLUMN 2
#define SITE_NAME_COLUMN_WIDTH 0.3
#define SITE_ADDRESS_COLUMN_WIDTH 0.4
#define SITE_LOCATION_COLUMN_WIDTH 0.3
/////////////////////////////////////////////////////////////////////////////
// CSiteSelectDlg dialog
CSiteSelectDlg::CSiteSelectDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSiteSelectDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSiteSelectDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CSiteSelectDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSiteSelectDlg)
DDX_Control(pDX, IDC_SITE_LIST, m_SiteList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSiteSelectDlg, CDialog)
//{{AFX_MSG_MAP(CSiteSelectDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSiteSelectDlg message handlers
void CSiteSelectDlg::OnOK()
{
// TODO: Add extra validation here
int num_items, j, flags;
// If no item is selected, return (user MUST select an item)
if(m_SiteList.GetSelectedCount()==0) {
LocalizedMessageBox(IDS_SITESELECTDLG_MUST_SELECT, IDS_SITESELECTDLG_SELECT_TITLE, MB_OK|MB_ICONEXCLAMATION);
return;
}
// How many items in the control list?
num_items=m_SiteList.GetItemCount();
// scan the item list for the selected item
chosen_site=NO_SITE_CHOSEN;
j=0;
while(j0 && filebuffer[strlen(filebuffer) - 1] == '\n')
filebuffer[strlen(filebuffer) - 1] = '\0';
// if line is a comment, or empty, discard it
if(strlen(filebuffer)==0 || filebuffer[0]==SITE_FILE_COMMENT_CHAR)
continue;
switch(field) {
case 0:
strcpy(site_entry.name,filebuffer);
break;
case 1:
strcpy(site_entry.location,filebuffer);
break;
case 2:
strcpy(site_entry.url,filebuffer);
break;
case 3:
strcpy(site_entry.path,filebuffer);
break;
}
field++;
if(field==4) {
AddSiteEntry(&site_entry);
field=0;
}
}
fclose(f);
return TRUE;
}
// Adds an entry struct to the list array and the list control
BOOL CSiteSelectDlg::AddSiteEntry(SITE_ENTRY *entry)
{
int index;
// Check if too many sites have been read in
if(num_sites>=MAX_SITES) return FALSE;
// Add the entry to the list control
index=m_SiteList.GetItemCount();
if((index=m_SiteList.InsertItem(index,entry->name))==-1)
OutputDebugString("Didn't work!");
m_SiteList.SetItem(index,SITE_ADDRESS_COLUMN,LVIF_TEXT,entry->url,0,0,0,0);
m_SiteList.SetItem(index,SITE_LOCATION_COLUMN,LVIF_TEXT,entry->location,0,0,0,0);
// Add the entry to the list array
strcpy(site_entries[num_sites].name,entry->name);
strcpy(site_entries[num_sites].location,entry->location);
strcpy(site_entries[num_sites].url,entry->url);
strcpy(site_entries[num_sites].path,entry->path);
num_sites++;
return TRUE;
}
void CSiteSelectDlg::LocalizedMessageBox(UINT msgID, UINT titleID, UINT type /*=MB_OK*/)
{
CString msg, title;
msg.LoadString(msgID);
title.LoadString(titleID);
MessageBox(msg,title,type);
}