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 ()
|
|
|
|
{
|
|
|
|
int num_apt = _airports->size();
|
2006-04-18 15:21:19 +00:00
|
|
|
char **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-04-18 15:21:19 +00:00
|
|
|
content[n] = new char[entry.size() + 1];
|
|
|
|
strcpy(content[n], entry.c_str());
|
2006-03-31 10:17:43 +00:00
|
|
|
n++;
|
2003-11-27 23:41:00 +00:00
|
|
|
}
|
2006-04-18 15:21:19 +00:00
|
|
|
content[n] = 0;
|
|
|
|
// work around plib 2006/04/18 bug: lists with no entries cause crash on arrow-up
|
|
|
|
newList(n > 0 ? content : 0);
|
|
|
|
|
|
|
|
if (_content)
|
|
|
|
destroy_list();
|
|
|
|
|
|
|
|
_content = content;
|
2003-11-27 23:41:00 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|