From: daveluff Date: Tue, 21 Oct 2003 11:44:43 +0000 (+0000) Subject: Fixed up the freqency search dialogs properly - this should eliminate crashing and... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3d104940e98c84f7b652468e0f0142a5dacf27ed;p=flightgear.git Fixed up the freqency search dialogs properly - this should eliminate crashing and memory leakage --- diff --git a/src/ATC/ATCDialog.cxx b/src/ATC/ATCDialog.cxx index 0bb9ce5b2..baa01d3b4 100644 --- a/src/ATC/ATCDialog.cxx +++ b/src/ATC/ATCDialog.cxx @@ -36,6 +36,12 @@ SG_USING_STD(ostringstream); +static void atcUppercase(string &s) { + for(unsigned int i=0; igetStringValue(); + FG_POP_PUI_DIALOG(atcFreqDialog); + current_atcdialog->FreqDisplay(tmp); +} + +static void FreqDisplayOK(puObject*) { + FG_POP_PUI_DIALOG(atcFreqDisplay); +} + +////////////// end freq search statics /////////////// + // ------------------------ AK ------------------------------------------ static puDialogBox *ATCMenuBox = 0; static puFrame *ATCMenuFrame = 0; @@ -256,9 +299,70 @@ void ATCDoDialog(atc_type type) { } } +FGATCDialog::FGATCDialog() { +} + +FGATCDialog::~FGATCDialog() { + if(atcFreqDialog) delete atcFreqDialog; + if(atcFreqDisplay) delete atcFreqDisplay; +} + void FGATCDialog::Init() { // Add ATC-freq-search to the command list globals->get_commands()->addCommand("ATC-freq-search", do_ATC_freq_search); + + // Init the freq-search dialog + char *s; + int hsize = 150; + atcFreqDialog = new puDialogBox (150, 50); + { + atcFreqDialogFrame = new puFrame (0, 0, 300, hsize); + atcFreqDialogMessage = new puText (40, (hsize - 30)); + atcFreqDialogMessage->setDefaultValue ("Enter airport identifier:"); + atcFreqDialogMessage->getDefaultValue (&s); + atcFreqDialogMessage->setLabel(s); + + atcFreqDialogInput = new puInput (50, (hsize - 75), 150, (hsize - 45)); + + atcFreqDialogOkButton = new puOneShot (50, 10, 110, 50); + atcFreqDialogOkButton -> setLegend (gui_msg_OK); + atcFreqDialogOkButton -> makeReturnDefault (TRUE); + atcFreqDialogOkButton -> setCallback (FreqDialogOK); + + atcFreqDialogCancelButton = new puOneShot (140, 10, 210, 50); + atcFreqDialogCancelButton -> setLegend (gui_msg_CANCEL); + atcFreqDialogCancelButton -> setCallback (FreqDialogCancel); + + atcFreqDialogInput->acceptInput(); + } + + FG_FINALIZE_PUI_DIALOG(atcFreqDialog); + + // Init the freq-display dialog + hsize = 100; + atcFreqDisplay = new puDialogBox (250, 50); + { + atcFreqDisplayFrame = new puFrame (0, 0, 400, hsize); + + atcFreqDisplayMessage = new puText (40, (hsize - 30)); + atcFreqDisplayMessage -> setDefaultValue ("No freqencies found"); + atcFreqDisplayMessage -> getDefaultValue (&s); + atcFreqDisplayMessage -> setLabel (s); + + for(int i=0; isetDefaultValue(""); + atcFreqDisplayText[i]-> getDefaultValue (&s); + atcFreqDisplayText[i]-> setLabel (s); + atcFreqDisplayText[i]->hide(); + } + + atcFreqDisplayOkButton = new puOneShot (50, 10, 110, 50); + atcFreqDisplayOkButton -> setLegend (gui_msg_OK); + atcFreqDisplayOkButton -> makeReturnDefault (TRUE); + atcFreqDisplayOkButton -> setCallback (FreqDisplayOK); + } + FG_FINALIZE_PUI_DIALOG(atcFreqDisplay); } // AK @@ -407,43 +511,7 @@ void FGATCDialog::DoDialog() { } } -////////////////////////////////////////////////////// -// -// STUFF FOR THE FREQUENCY SEARCH DIALOG -// -////////////////////////////////////////////////////// - -static puDialogBox* atcFreqDialog; -static puFrame* atcFreqDialogFrame; -static puText* atcFreqDialogMessage; -static puInput* atcFreqDialogInput; -static puOneShot* atcFreqDialogOkButton; -static puOneShot* atcFreqDialogCancelButton; - -static puDialogBox* atcFreqDisplay; -static puFrame* atcFreqDisplayFrame; -static puText* atcFreqDisplayMessage; -static puOneShot* atcFreqDisplayOkButton; -static puOneShot* atcFreqDisplayCancelButton; -static puText* atcFreqDisplayText[20]; - -static void FreqDialogCancel(puObject*) { - FG_POP_PUI_DIALOG(atcFreqDialog); -} - -static void FreqDialogOK(puObject*) { - string tmp = atcFreqDialogInput->getStringValue(); - FG_POP_PUI_DIALOG(atcFreqDialog); - current_atcdialog->FreqDisplay(tmp); -} - -static void FreqDisplayOK(puObject*) { - FG_POP_PUI_DIALOG(atcFreqDisplay); -} -static void FreqDisplayCancel(puObject*) { - FG_POP_PUI_DIALOG(atcFreqDisplay); -} void FGATCDialog::FreqDialog() { @@ -464,57 +532,23 @@ void FGATCDialog::FreqDialog() { } */ - //char defaultATCLabel[] = "Enter desired option to communicate with ATC:"; - char *s; - - int hsize = 150; - atcFreqDialog = new puDialogBox (150, 50); - { - atcFreqDialogFrame = new puFrame (0, 0, 300, hsize); - - atcFreqDialogMessage = new puText (40, (hsize - 30)); - atcFreqDialogMessage -> setDefaultValue ("Enter airport identifier:"); - atcFreqDialogMessage -> getDefaultValue (&s); - atcFreqDialogMessage -> setLabel (s); - - atcFreqDialogInput = new puInput (50, (hsize - 75), 150, (hsize - 45)); - atcFreqDialogInput->acceptInput(); - - atcFreqDialogOkButton = new puOneShot (50, 10, 110, 50); - atcFreqDialogOkButton -> setLegend (gui_msg_OK); - atcFreqDialogOkButton -> makeReturnDefault (TRUE); - atcFreqDialogOkButton -> setCallback (FreqDialogOK); - - atcFreqDialogCancelButton = new puOneShot (140, 10, 210, 50); - atcFreqDialogCancelButton -> setLegend (gui_msg_CANCEL); - atcFreqDialogCancelButton -> setCallback (FreqDialogCancel); - - } - FG_FINALIZE_PUI_DIALOG(atcFreqDialog); + // TODO - it would be nice to display a drop-down list of airports within the general vicinity of the user + // in addition to the general input box (started above). + atcFreqDialogInput->setValue(""); + atcFreqDialogInput->acceptInput(); FG_PUSH_PUI_DIALOG(atcFreqDialog); - -} - -static void atcUppercase(string &s) -{ - for(unsigned int i=0; isetSize(400, hsize); + + atcFreqDisplayMessage -> setPosition (40, (hsize - 30)); + atcFreqDisplayMessage -> setValue (label.c_str()); + atcFreqDisplayMessage -> getValue (&s); + atcFreqDisplayMessage -> setLabel (s); + + for(int i=0; i setPosition(40, hsize - 65 - (30 * i)); + atcFreqDisplayText[i] -> setValue(freqs[i].c_str()); + atcFreqDisplayText[i] -> getValue (&s); + atcFreqDisplayText[i] -> setLabel (s); + atcFreqDisplayText[i] -> reveal(); } - - int hsize = (n < 0 ? 100 : 105 + (n * 30)); - atcFreqDisplay = new puDialogBox (250, 50); - { - atcFreqDisplayFrame = new puFrame (0, 0, 400, hsize); - - atcFreqDisplayMessage = new puText (40, (hsize - 30)); - atcFreqDisplayMessage -> setDefaultValue (label.c_str()); - atcFreqDisplayMessage -> getDefaultValue (&s); - atcFreqDisplayMessage -> setLabel (s); - - for(int i=0; isetDefaultValue(freqs[i].c_str()); - atcFreqDisplayText[i]-> getDefaultValue (&s); - atcFreqDisplayText[i]-> setLabel (s); - } - - atcFreqDisplayOkButton = new puOneShot (50, 10, 110, 50); - atcFreqDisplayOkButton -> setLegend (gui_msg_OK); - atcFreqDisplayOkButton -> makeReturnDefault (TRUE); - atcFreqDisplayOkButton -> setCallback (FreqDisplayOK); - - atcFreqDisplayCancelButton = new puOneShot (140, 10, 210, 50); - atcFreqDisplayCancelButton -> setLegend (gui_msg_CANCEL); - atcFreqDisplayCancelButton -> setCallback (FreqDisplayCancel); - + for(int j=n; j hide(); } - FG_FINALIZE_PUI_DIALOG(atcFreqDisplay); FG_PUSH_PUI_DIALOG(atcFreqDisplay); diff --git a/src/ATC/ATCDialog.hxx b/src/ATC/ATCDialog.hxx index 812d08dda..9bbf1064a 100644 --- a/src/ATC/ATCDialog.hxx +++ b/src/ATC/ATCDialog.hxx @@ -55,6 +55,9 @@ class FGATCDialog { public: + FGATCDialog(); + ~FGATCDialog(); + void Init(); void DoDialog();