]> git.mxchange.org Git - flightgear.git/blob - src/GUI/AirportList.cxx
3f97342dee4707a1b554b425d8770b8b0af161dc
[flightgear.git] / src / GUI / AirportList.cxx
1 #include <Main/globals.hxx>
2 #include <Airports/simple.hxx>
3
4 #include "AirportList.hxx"
5
6
7 AirportList::AirportList (int x, int y, int width, int height)
8     : puList(x, y, width, height)
9 {
10     char buf[1024];
11
12     _airports = globals->get_airports();
13     _nAirports = _airports->size();
14
15     _content = new char *[_nAirports+1];
16     for (int i = 0; i < _nAirports; i++) {
17         const FGAirport * airport = _airports->getAirport(i);
18         snprintf(buf, 1023, "%s  %s\n",
19                  airport->id.c_str(),
20                  airport->name.c_str());
21         int str_len = strlen(buf);
22         _content[i] = new char[(str_len > 1023) ? 1024 : str_len];
23         strncpy(_content[i], buf, 1023);
24     }
25     _content[_nAirports] = 0;
26     newList(_content);
27 }
28
29 AirportList::~AirportList ()
30 {
31     for (int i = 0; i < _nAirports; i++) {
32         delete _content[i];
33         _content[i] = 0;
34     }
35     delete [] _content;
36 }
37
38 char *
39 AirportList::getStringValue ()
40 {
41     return (char *)_airports->getAirport(getIntegerValue())->id.c_str();
42 }
43
44 // end of AirportList.cxx
45