]> git.mxchange.org Git - flightgear.git/blob - src/GUI/AirportList.cxx
Tidy new_gui header
[flightgear.git] / src / GUI / AirportList.cxx
1 #ifdef HAVE_CONFIG_H
2 #  include "config.h"
3 #endif
4
5 #include <Main/globals.hxx>
6 #include <Airports/simple.hxx>
7
8 #include "AirportList.hxx"
9
10 AirportList::AirportList(int x, int y, int width, int height) :
11     puaList(x, y, width, height),
12     GUI_ID(FGCLASS_AIRPORTLIST),
13     _content(0)
14 {
15     create_list();
16 }
17
18
19 AirportList::~AirportList()
20 {
21     destroy_list();
22 }
23
24
25 void
26 AirportList::create_list()
27 {
28    char **content = FGAirport::searchNamesAndIdents(_filter);
29    int n = (content[0] != NULL) ? 1 : 0;
30     
31     // work around plib 2006/04/18 bug: lists with no entries cause crash on arrow-up
32     newList(n > 0 ? content : 0);
33
34     if (_content)
35         destroy_list();
36
37     _content = content;
38 }
39
40
41 void
42 AirportList::destroy_list()
43 {
44     for (char **c = _content; *c; c++) {
45         delete *c;
46         *c = 0;
47     }
48     delete [] _content;
49 }
50
51
52 void
53 AirportList::setValue(const char *s)
54 {
55     std::string filter(s);
56     const std::ctype<char> &ct = std::use_facet<std::ctype<char> >(std::locale());
57     ct.toupper((char *)filter.data(), (char *)filter.data() + filter.size());
58
59     if (filter != _filter) {
60         _filter = filter;
61         create_list();
62     }
63 }
64
65