2008-06-03 10:25:58 +00:00
|
|
|
#include <locale>
|
2003-11-27 23:41:00 +00:00
|
|
|
#include <Main/globals.hxx>
|
|
|
|
#include <Airports/simple.hxx>
|
|
|
|
|
|
|
|
#include "AirportList.hxx"
|
|
|
|
|
|
|
|
|
2008-06-03 10:25:58 +00:00
|
|
|
AirportList::AirportList(int x, int y, int width, int height) :
|
|
|
|
puaList(x, y, width, height),
|
|
|
|
GUI_ID(FGCLASS_AIRPORTLIST),
|
|
|
|
_airports(globals->get_airports()),
|
|
|
|
_content(0)
|
2003-11-27 23:41:00 +00:00
|
|
|
{
|
2006-03-31 10:17:43 +00:00
|
|
|
create_list();
|
|
|
|
}
|
|
|
|
|
2008-06-03 10:25:58 +00:00
|
|
|
|
|
|
|
AirportList::~AirportList()
|
2006-03-31 10:17:43 +00:00
|
|
|
{
|
|
|
|
destroy_list();
|
|
|
|
}
|
|
|
|
|
2008-06-03 10:25:58 +00:00
|
|
|
|
2006-03-31 10:17:43 +00:00
|
|
|
void
|
2008-06-03 10:25:58 +00:00
|
|
|
AirportList::create_list()
|
2006-03-31 10:17:43 +00:00
|
|
|
{
|
2008-06-03 10:25:58 +00:00
|
|
|
const std::ctype<char> &ct = std::use_facet<std::ctype<char> >(std::locale());
|
2006-03-31 10:17:43 +00:00
|
|
|
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);
|
2008-06-03 10:25:58 +00:00
|
|
|
std::string entry(' ' + apt->getName() + " (" + apt->getId() + ')');
|
|
|
|
|
|
|
|
if (!_filter.empty()) {
|
|
|
|
std::string upper(entry.data());
|
|
|
|
ct.toupper((char *)upper.data(), (char *)upper.data() + upper.size());
|
2003-11-28 20:25:50 +00:00
|
|
|
|
2008-06-03 10:25:58 +00:00
|
|
|
if (upper.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
|
|
|
}
|
|
|
|
|
2008-06-03 10:25:58 +00:00
|
|
|
|
2006-03-31 10:17:43 +00:00
|
|
|
void
|
2008-06-03 10:25:58 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-06-03 10:25:58 +00:00
|
|
|
|
2006-03-31 10:17:43 +00:00
|
|
|
void
|
2008-06-03 10:25:58 +00:00
|
|
|
AirportList::setValue(const char *s)
|
2006-03-31 10:17:43 +00:00
|
|
|
{
|
2008-06-03 10:25:58 +00:00
|
|
|
std::string filter(s);
|
|
|
|
const std::ctype<char> &ct = std::use_facet<std::ctype<char> >(std::locale());
|
|
|
|
ct.toupper((char *)filter.data(), (char *)filter.data() + filter.size());
|
|
|
|
|
2006-03-31 10:17:43 +00:00
|
|
|
if (filter != _filter) {
|
|
|
|
_filter = filter;
|
|
|
|
create_list();
|
|
|
|
}
|
2003-11-27 23:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|