X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FGUI%2FAirportList.cxx;h=bcbe06e09c90dea778a4430228f2d208d93f4313;hb=0f7f7fce6bd57bea6c93f5d40c89f1b741edff45;hp=6ded7f88b2c9bb7c5b9524f4f7a28fe50a718b41;hpb=222446df29724aa496da85ea334788f59276b922;p=flightgear.git diff --git a/src/GUI/AirportList.cxx b/src/GUI/AirportList.cxx index 6ded7f88b..bcbe06e09 100644 --- a/src/GUI/AirportList.cxx +++ b/src/GUI/AirportList.cxx @@ -1,50 +1,65 @@ -#include // strncpy() +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif #include
#include #include "AirportList.hxx" +AirportList::AirportList(int x, int y, int width, int height) : + puaList(x, y, width, height), + GUI_ID(FGCLASS_AIRPORTLIST), + _content(0) +{ + create_list(); +} -AirportList::AirportList (int x, int y, int width, int height) - : puList(x, y, width, height) + +AirportList::~AirportList() { - char buf[1024]; - - _airports = globals->get_airports(); - _nAirports = _airports->size(); - - _content = new char *[_nAirports+1]; - for (int i = 0; i < _nAirports; i++) { - const FGAirport *airport = _airports->getAirport(i); - snprintf(buf, 1023, "%s %s", - airport->_id.c_str(), - airport->_name.c_str()); - - unsigned int buf_len = (strlen(buf) > 1023) ? 1023 : strlen(buf); - - _content[i] = new char[buf_len+1]; - memcpy(_content[i], buf, buf_len); - _content[i][buf_len] = '\0'; - } - _content[_nAirports] = 0; - newList(_content); + destroy_list(); +} + + +void +AirportList::create_list() +{ + char **content = FGAirport::searchNamesAndIdents(_filter); + int n = (content[0] != NULL) ? 1 : 0; + + // work around plib 2006/04/18 bug: lists with no entries cause crash on arrow-up + newList(n > 0 ? content : 0); + + if (_content) + destroy_list(); + + _content = content; } -AirportList::~AirportList () + +void +AirportList::destroy_list() { - for (int i = 0; i < _nAirports; i++) { - delete _content[i]; - _content[i] = 0; + for (char **c = _content; *c; c++) { + delete *c; + *c = 0; } delete [] _content; } -char * -AirportList::getStringValue () + +void +AirportList::setValue(const char *s) { - return (char *)_airports->getAirport(getIntegerValue())->_id.c_str(); + std::string filter(s); + const std::ctype &ct = std::use_facet >(std::locale()); + ct.toupper((char *)filter.data(), (char *)filter.data() + filter.size()); + + if (filter != _filter) { + _filter = filter; + create_list(); + } } -// end of AirportList.cxx