2 #include <Main/globals.hxx>
3 #include <Airports/simple.hxx>
5 #include "AirportList.hxx"
8 AirportList::AirportList(int x, int y, int width, int height) :
9 puaList(x, y, width, height),
10 GUI_ID(FGCLASS_AIRPORTLIST),
11 _airports(globals->get_airports()),
18 AirportList::~AirportList()
25 AirportList::create_list()
27 const std::ctype<char> &ct = std::use_facet<std::ctype<char> >(std::locale());
28 int num_apt = _airports->size();
29 char **content = new char *[num_apt + 1];
32 for (int i = 0; i < num_apt; i++) {
33 const FGAirport *apt = _airports->getAirport(i);
34 std::string entry(' ' + apt->getName() + " (" + apt->getId() + ')');
36 if (!_filter.empty()) {
37 std::string upper(entry.data());
38 ct.toupper((char *)upper.data(), (char *)upper.data() + upper.size());
40 if (upper.find(_filter) == std::string::npos)
44 content[n] = new char[entry.size() + 1];
45 strcpy(content[n], entry.c_str());
49 // work around plib 2006/04/18 bug: lists with no entries cause crash on arrow-up
50 newList(n > 0 ? content : 0);
60 AirportList::destroy_list()
62 for (char **c = _content; *c; c++) {
71 AirportList::setValue(const char *s)
73 std::string filter(s);
74 const std::ctype<char> &ct = std::use_facet<std::ctype<char> >(std::locale());
75 ct.toupper((char *)filter.data(), (char *)filter.data() + filter.size());
77 if (filter != _filter) {