]> git.mxchange.org Git - flightgear.git/blob - src/GUI/AirportList.cxx
make headers include headers they depend on, don't rely on the c(xx)
[flightgear.git] / src / GUI / AirportList.cxx
1
2 #include <Main/globals.hxx>
3 #include <Airports/simple.hxx>
4
5 #include "AirportList.hxx"
6
7
8 AirportList::AirportList (int x, int y, int width, int height)
9     : puList(x, y, width, height),
10       _airports(globals->get_airports()),
11       _content(0)
12 {
13     create_list();
14 }
15
16 AirportList::~AirportList ()
17 {
18     destroy_list();
19 }
20
21 void
22 AirportList::create_list ()
23 {
24     if (_content)
25         destroy_list();
26
27     int num_apt = _airports->size();
28     _content = new char *[num_apt + 1];
29
30     int n = 0;
31     for (int i = 0; i < num_apt; i++) {
32         const FGAirport *apt = _airports->getAirport(i);
33         STD::string entry(apt->getName() + "   (" + apt->getId() + ')');
34
35         if (!_filter.empty() && entry.find(_filter) == STD::string::npos)
36             continue;
37
38         _content[n] = new char[entry.size() + 1];
39         strcpy(_content[n], entry.c_str());
40         n++;
41     }
42     _content[n] = 0;
43     newList(_content);
44 }
45
46 void
47 AirportList::destroy_list ()
48 {
49     for (char **c = _content; *c; c++) {
50         delete *c;
51         *c = 0;
52     }
53     delete [] _content;
54 }
55
56 char *
57 AirportList::getListStringValue ()
58 {
59     int i = getListIntegerValue();
60     return i < 0 ? 0 : _content[i];
61 }
62
63 void
64 AirportList::setValue (const char *s)
65 {
66     STD::string filter(s);
67     if (filter != _filter) {
68         _filter = filter;
69         create_list();
70     }
71 }
72
73 // end of AirportList.cxx
74