]> git.mxchange.org Git - flightgear.git/blob - src/GUI/AirportList.cxx
the last patch fixed the AirportList ... and broke all other PUCLASS_LIST.;
[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       GUI_ID(FGCLASS_AIRPORTLIST),
11       _airports(globals->get_airports()),
12       _content(0)
13 {
14     create_list();
15 }
16
17 AirportList::~AirportList ()
18 {
19     destroy_list();
20 }
21
22 void
23 AirportList::create_list ()
24 {
25     int num_apt = _airports->size();
26     char **content = new char *[num_apt + 1];
27
28     int n = 0;
29     for (int i = 0; i < num_apt; i++) {
30         const FGAirport *apt = _airports->getAirport(i);
31         STD::string entry(apt->getName() + "   (" + apt->getId() + ')');
32
33         if (!_filter.empty() && entry.find(_filter) == STD::string::npos)
34             continue;
35
36         content[n] = new char[entry.size() + 1];
37         strcpy(content[n], entry.c_str());
38         n++;
39     }
40     content[n] = 0;
41     // work around plib 2006/04/18 bug: lists with no entries cause crash on arrow-up
42     newList(n > 0 ? content : 0);
43
44     if (_content)
45         destroy_list();
46
47     _content = content;
48 }
49
50 void
51 AirportList::destroy_list ()
52 {
53     for (char **c = _content; *c; c++) {
54         delete *c;
55         *c = 0;
56     }
57     delete [] _content;
58 }
59
60 char *
61 AirportList::getListStringValue ()
62 {
63     int i = getListIntegerValue();
64     return i < 0 ? 0 : _content[i];
65 }
66
67 void
68 AirportList::setValue (const char *s)
69 {
70     STD::string filter(s);
71     if (filter != _filter) {
72         _filter = filter;
73         create_list();
74     }
75 }
76
77 // end of AirportList.cxx
78