]> git.mxchange.org Git - flightgear.git/blob - src/GUI/AirportList.cxx
da25a861dcef80871649f23664e8ece6296b4344
[flightgear.git] / src / GUI / AirportList.cxx
1 #ifdef HAVE_CONFIG_H
2 #  include "config.h"
3 #endif
4
5 #include <Main/globals.hxx>
6 #include <Airports/simple.hxx>
7
8 #include "AirportList.hxx"
9
10 AirportList::AirportList(int x, int y, int width, int height) :
11     puaList(x, y, width, height),
12     GUI_ID(FGCLASS_AIRPORTLIST),
13     _content(0)
14 {
15     create_list();
16 }
17
18
19 AirportList::~AirportList()
20 {
21     destroy_list();
22 }
23
24
25 void
26 AirportList::create_list()
27 {
28    char **content = FGAirport::searchNamesAndIdents(_filter);
29    int n = (content[0] != NULL) ? 1 : 0;
30     
31     // work around plib 2006/04/18 bug: lists with no entries cause crash on arrow-up
32     newList(n > 0 ? content : 0);
33
34     if (_content)
35         destroy_list();
36
37     _content = content;
38 }
39
40
41 void
42 AirportList::destroy_list()
43 {
44     for (char **c = _content; *c; c++) {
45         free(*c);
46         *c = 0;
47     }
48   
49     free(_content);
50 }
51
52
53 void
54 AirportList::setValue(const char *s)
55 {
56     std::string filter(s);
57     const std::ctype<char> &ct = std::use_facet<std::ctype<char> >(std::locale());
58     ct.toupper((char *)filter.data(), (char *)filter.data() + filter.size());
59
60     if (filter != _filter) {
61         _filter = filter;
62         create_list();
63     }
64 }
65
66