2003-11-28 15:48:05 +00:00
|
|
|
|
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)
|
2006-03-31 10:17:43 +00:00
|
|
|
: puList(x, y, width, height),
|
|
|
|
_airports(globals->get_airports()),
|
|
|
|
_content(0)
|
2003-11-27 23:41:00 +00:00
|
|
|
{
|
2006-03-31 10:17:43 +00:00
|
|
|
create_list();
|
|
|
|
}
|
|
|
|
|
|
|
|
AirportList::~AirportList ()
|
|
|
|
{
|
|
|
|
destroy_list();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AirportList::create_list ()
|
|
|
|
{
|
|
|
|
if (_content)
|
|
|
|
destroy_list();
|
2003-11-27 23:41:00 +00:00
|
|
|
|
2006-03-31 10:17:43 +00:00
|
|
|
int num_apt = _airports->size();
|
|
|
|
_content = new char *[num_apt + 1];
|
2003-11-27 23:41:00 +00:00
|
|
|
|
2006-03-31 10:17:43 +00:00
|
|
|
int n = 0;
|
|
|
|
for (int i = 0; i < num_apt; i++) {
|
|
|
|
const FGAirport *apt = _airports->getAirport(i);
|
|
|
|
STD::string entry(apt->getName() + " (" + apt->getId() + ')');
|
2003-11-28 20:25:50 +00:00
|
|
|
|
2006-03-31 10:17:43 +00:00
|
|
|
if (!_filter.empty() && entry.find(_filter) == STD::string::npos)
|
|
|
|
continue;
|
2006-03-25 08:47:53 +00:00
|
|
|
|
2006-03-31 10:17:43 +00:00
|
|
|
_content[n] = new char[entry.size() + 1];
|
|
|
|
strcpy(_content[n], entry.c_str());
|
|
|
|
n++;
|
2003-11-27 23:41:00 +00:00
|
|
|
}
|
2006-03-31 10:17:43 +00:00
|
|
|
_content[n] = 0;
|
2003-11-27 23:41:00 +00:00
|
|
|
newList(_content);
|
|
|
|
}
|
|
|
|
|
2006-03-31 10:17:43 +00:00
|
|
|
void
|
|
|
|
AirportList::destroy_list ()
|
2003-11-27 23:41:00 +00:00
|
|
|
{
|
2006-03-31 10:17:43 +00:00
|
|
|
for (char **c = _content; *c; c++) {
|
|
|
|
delete *c;
|
|
|
|
*c = 0;
|
2003-11-27 23:41:00 +00:00
|
|
|
}
|
|
|
|
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();
|
2006-03-31 10:17:43 +00:00
|
|
|
return i < 0 ? 0 : _content[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AirportList::setValue (const char *s)
|
|
|
|
{
|
|
|
|
STD::string filter(s);
|
|
|
|
if (filter != _filter) {
|
|
|
|
_filter = filter;
|
|
|
|
create_list();
|
|
|
|
}
|
2003-11-27 23:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// end of AirportList.cxx
|
|
|
|
|