2003-11-28 15:48:05 +00:00
|
|
|
#include <string.h> // strncpy()
|
|
|
|
|
2003-11-27 23:41:00 +00:00
|
|
|
#include <Main/globals.hxx>
|
|
|
|
#include <Airports/simple.hxx>
|
|
|
|
|
|
|
|
#include "AirportList.hxx"
|
|
|
|
|
|
|
|
|
|
|
|
AirportList::AirportList (int x, int y, int width, int height)
|
|
|
|
: puList(x, y, width, height)
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
_airports = globals->get_airports();
|
|
|
|
_nAirports = _airports->size();
|
|
|
|
|
|
|
|
_content = new char *[_nAirports+1];
|
2005-10-01 09:56:53 +00:00
|
|
|
for (int i = 0; i < _nAirports; i++) {
|
2004-02-23 11:42:49 +00:00
|
|
|
const FGAirport *airport = _airports->getAirport(i);
|
2006-03-25 08:47:53 +00:00
|
|
|
snprintf(buf, 1023, "%s (%s)",
|
|
|
|
airport->getName().c_str(),
|
|
|
|
airport->getId().c_str());
|
2003-11-28 20:25:50 +00:00
|
|
|
|
|
|
|
unsigned int buf_len = (strlen(buf) > 1023) ? 1023 : strlen(buf);
|
2006-03-25 08:47:53 +00:00
|
|
|
|
2003-11-28 20:25:50 +00:00
|
|
|
_content[i] = new char[buf_len+1];
|
|
|
|
memcpy(_content[i], buf, buf_len);
|
2004-04-24 21:25:54 +00:00
|
|
|
_content[i][buf_len] = '\0';
|
2003-11-27 23:41:00 +00:00
|
|
|
}
|
|
|
|
_content[_nAirports] = 0;
|
|
|
|
newList(_content);
|
|
|
|
}
|
|
|
|
|
|
|
|
AirportList::~AirportList ()
|
|
|
|
{
|
2005-10-01 09:56:53 +00:00
|
|
|
for (int i = 0; i < _nAirports; i++) {
|
2003-11-27 23:41:00 +00:00
|
|
|
delete _content[i];
|
|
|
|
_content[i] = 0;
|
|
|
|
}
|
|
|
|
delete [] _content;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2005-01-31 10:36:59 +00:00
|
|
|
AirportList::getListStringValue ()
|
2003-11-27 23:41:00 +00:00
|
|
|
{
|
2006-03-25 08:47:53 +00:00
|
|
|
int i = getListIntegerValue();
|
|
|
|
if (i >= 0)
|
|
|
|
return (char *)_airports->getAirport(i)->getId().c_str();
|
|
|
|
else
|
|
|
|
return "";
|
2003-11-27 23:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// end of AirportList.cxx
|
|
|
|
|