]> git.mxchange.org Git - flightgear.git/blob - src/GUI/AirportList.cxx
Use OSG polytope intersector to fill ground cache
[flightgear.git] / src / GUI / AirportList.cxx
1 #ifdef HAVE_CONFIG_H
2 #  include "config.h"
3 #endif
4
5 #include <locale>
6 #include <Main/globals.hxx>
7 #include <Airports/simple.hxx>
8
9 #include "AirportList.hxx"
10
11
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()),
16     _content(0)
17 {
18     create_list();
19 }
20
21
22 AirportList::~AirportList()
23 {
24     destroy_list();
25 }
26
27
28 void
29 AirportList::create_list()
30 {
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];
34
35     int n = 0;
36     for (int i = 0; i < num_apt; i++) {
37         const FGAirport *apt = _airports->getAirport(i);
38         std::string entry(' ' + apt->getName() + "   (" + apt->getId() + ')');
39
40         if (!_filter.empty()) {
41             std::string upper(entry.data());
42             ct.toupper((char *)upper.data(), (char *)upper.data() + upper.size());
43
44             if (upper.find(_filter) == std::string::npos)
45                 continue;
46         }
47
48         content[n] = new char[entry.size() + 1];
49         strcpy(content[n], entry.c_str());
50         n++;
51     }
52     content[n] = 0;
53     // work around plib 2006/04/18 bug: lists with no entries cause crash on arrow-up
54     newList(n > 0 ? content : 0);
55
56     if (_content)
57         destroy_list();
58
59     _content = content;
60 }
61
62
63 void
64 AirportList::destroy_list()
65 {
66     for (char **c = _content; *c; c++) {
67         delete *c;
68         *c = 0;
69     }
70     delete [] _content;
71 }
72
73
74 void
75 AirportList::setValue(const char *s)
76 {
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());
80
81     if (filter != _filter) {
82         _filter = filter;
83         create_list();
84     }
85 }
86
87