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