6 #include <Main/globals.hxx>
7 #include <Airports/simple.hxx>
9 #include "AirportList.hxx"
12 AirportList::AirportList(int x, int y, int width, int height) :
13 puaList(x, y, width, height),
14 GUI_ID(FGCLASS_AIRPORTLIST),
15 _airports(globals->get_airports()),
22 AirportList::~AirportList()
29 AirportList::create_list()
31 const std::ctype<char> &ct = std::use_facet<std::ctype<char> >(std::locale());
32 int num_apt = _airports->size();
33 char **content = new char *[num_apt + 1];
36 for (int i = 0; i < num_apt; i++) {
37 const FGAirport *apt = _airports->getAirport(i);
38 std::string entry(' ' + apt->getName() + " (" + apt->getId() + ')');
40 if (!_filter.empty()) {
41 std::string upper(entry.data());
42 ct.toupper((char *)upper.data(), (char *)upper.data() + upper.size());
44 if (upper.find(_filter) == std::string::npos)
48 content[n] = new char[entry.size() + 1];
49 strcpy(content[n], entry.c_str());
53 // work around plib 2006/04/18 bug: lists with no entries cause crash on arrow-up
54 newList(n > 0 ? content : 0);
64 AirportList::destroy_list()
66 for (char **c = _content; *c; c++) {
75 AirportList::setValue(const char *s)
77 std::string filter(s);
78 const std::ctype<char> &ct = std::use_facet<std::ctype<char> >(std::locale());
79 ct.toupper((char *)filter.data(), (char *)filter.data() + filter.size());
81 if (filter != _filter) {