--- hatari/src/gui-sdl/dlgDevice.c 2019/04/01 07:11:38 1.1 +++ hatari/src/gui-sdl/dlgDevice.c 2019/04/01 07:15:00 1.1.1.5 @@ -6,19 +6,18 @@ Device (Printer etc.) setup dialog */ -char DlgDevice_rcsid[] = "Hatari $Id: dlgDevice.c,v 1.1 2019/04/01 07:11:38 root Exp $"; +const char DlgDevice_rcsid[] = "Hatari $Id: dlgDevice.c,v 1.1.1.5 2019/04/01 07:15:00 root Exp $"; #include "main.h" #include "configuration.h" #include "dialog.h" #include "sdlgui.h" -#include "memAlloc.h" #include "file.h" #include "screen.h" #define DEVDLG_PRNENABLE 3 -#define DEVDLG_PRNBROWSE 4 +#define DEVDLG_PRNBROWSE 5 #define DEVDLG_PRNFILENAME 6 #define DEVDLG_RS232ENABLE 8 #define DEVDLG_RS232OUTBROWSE 10 @@ -31,11 +30,11 @@ char DlgDevice_rcsid[] = "Hatari $Id: dl #define DEVDLG_EXIT 20 -static char dlgPrinterName[46+1]; -static char dlgRs232OutName[46+1]; -static char dlgRs232InName[46+1]; -static char dlgMidiOutName[46+1]; - +#define MAX_DLG_FILENAME 46+1 +static char dlgPrinterName[MAX_DLG_FILENAME]; +static char dlgRs232OutName[MAX_DLG_FILENAME]; +static char dlgRs232InName[MAX_DLG_FILENAME]; +static char dlgMidiOutName[MAX_DLG_FILENAME]; /* The devices dialog: */ static SGOBJ devicedlg[] = @@ -64,7 +63,7 @@ static SGOBJ devicedlg[] = { SGBUTTON, 0, 0, 42,17, 8,1, "Browse" }, { SGTEXT, 0, 0, 3,18, 46,1, dlgMidiOutName }, - { SGBUTTON, 0, 0, 16,20, 20,1, "Back to main menu" }, + { SGBUTTON, SG_DEFAULT, 0, 16,20, 20,1, "Back to main menu" }, { -1, 0, 0, 0,0, 0,0, NULL } }; @@ -76,93 +75,68 @@ static SGOBJ devicedlg[] = void Dialog_DeviceDlg(void) { int but; - char *tmpname; - - /* Allocate memory for tmpname: */ - tmpname = Memory_Alloc(FILENAME_MAX); SDLGui_CenterDlg(devicedlg); /* Set up dialog from actual values: */ - if (DialogParams.Printer.bEnablePrinting) + if (ConfigureParams.Printer.bEnablePrinting) devicedlg[DEVDLG_PRNENABLE].state |= SG_SELECTED; else devicedlg[DEVDLG_PRNENABLE].state &= ~SG_SELECTED; - File_ShrinkName(dlgPrinterName, DialogParams.Printer.szPrintToFileName, devicedlg[DEVDLG_PRNFILENAME].w); + File_ShrinkName(dlgPrinterName, ConfigureParams.Printer.szPrintToFileName, devicedlg[DEVDLG_PRNFILENAME].w); - if (DialogParams.RS232.bEnableRS232) + if (ConfigureParams.RS232.bEnableRS232) devicedlg[DEVDLG_RS232ENABLE].state |= SG_SELECTED; else devicedlg[DEVDLG_RS232ENABLE].state &= ~SG_SELECTED; - File_ShrinkName(dlgRs232OutName, DialogParams.RS232.szOutFileName, devicedlg[DEVDLG_RS232OUTNAME].w); - File_ShrinkName(dlgRs232InName, DialogParams.RS232.szInFileName, devicedlg[DEVDLG_RS232INNAME].w); + File_ShrinkName(dlgRs232OutName, ConfigureParams.RS232.szOutFileName, devicedlg[DEVDLG_RS232OUTNAME].w); + File_ShrinkName(dlgRs232InName, ConfigureParams.RS232.szInFileName, devicedlg[DEVDLG_RS232INNAME].w); - if (DialogParams.Midi.bEnableMidi) + if (ConfigureParams.Midi.bEnableMidi) devicedlg[DEVDLG_MIDIENABLE].state |= SG_SELECTED; else devicedlg[DEVDLG_MIDIENABLE].state &= ~SG_SELECTED; - File_ShrinkName(dlgMidiOutName, DialogParams.Midi.szMidiOutFileName, devicedlg[DEVDLG_MIDIOUTNAME].w); + File_ShrinkName(dlgMidiOutName, ConfigureParams.Midi.szMidiOutFileName, devicedlg[DEVDLG_MIDIOUTNAME].w); /* The devices dialog main loop */ do { - but = SDLGui_DoDialog(devicedlg); + but = SDLGui_DoDialog(devicedlg, NULL); switch(but) { case DEVDLG_PRNBROWSE: /* Choose a new printer file */ - strcpy(tmpname, DialogParams.Printer.szPrintToFileName); - if (SDLGui_FileSelect(tmpname, NULL, TRUE)) - { - if (!File_DoesFileNameEndWithSlash(tmpname)) - { - strcpy(DialogParams.Printer.szPrintToFileName, tmpname); - File_ShrinkName(dlgPrinterName, tmpname, devicedlg[DEVDLG_PRNFILENAME].w); - } - } + SDLGui_FileConfSelect(dlgPrinterName, + ConfigureParams.Printer.szPrintToFileName, + devicedlg[DEVDLG_PRNFILENAME].w, + TRUE); break; case DEVDLG_RS232OUTBROWSE: /* Choose a new RS232 output file */ - strcpy(tmpname, DialogParams.RS232.szOutFileName); - if (SDLGui_FileSelect(tmpname, NULL, TRUE)) - { - if (!File_DoesFileNameEndWithSlash(tmpname)) - { - strcpy(DialogParams.RS232.szOutFileName, tmpname); - File_ShrinkName(dlgRs232OutName, tmpname, devicedlg[DEVDLG_RS232OUTNAME].w); - } - } + SDLGui_FileConfSelect(dlgRs232OutName, + ConfigureParams.RS232.szOutFileName, + devicedlg[DEVDLG_RS232OUTNAME].w, + TRUE); break; case DEVDLG_RS232INBROWSE: /* Choose a new RS232 input file */ - strcpy(tmpname, DialogParams.RS232.szInFileName); - if (SDLGui_FileSelect(tmpname, NULL, TRUE)) - { - if (!File_DoesFileNameEndWithSlash(tmpname)) - { - strcpy(DialogParams.RS232.szInFileName, tmpname); - File_ShrinkName(dlgRs232InName, tmpname, devicedlg[DEVDLG_RS232INNAME].w); - } - } + SDLGui_FileConfSelect(dlgRs232InName, + ConfigureParams.RS232.szInFileName, + devicedlg[DEVDLG_RS232INNAME].w, + TRUE); break; case DEVDLG_MIDIBROWSE: /* Choose a new MIDI file */ - strcpy(tmpname, DialogParams.Midi.szMidiOutFileName); - if (SDLGui_FileSelect(tmpname, NULL, TRUE)) - { - if (!File_DoesFileNameEndWithSlash(tmpname)) - { - strcpy(DialogParams.Midi.szMidiOutFileName, tmpname); - File_ShrinkName(dlgMidiOutName, tmpname, devicedlg[DEVDLG_MIDIOUTNAME].w); - } - } + SDLGui_FileConfSelect(dlgMidiOutName, + ConfigureParams.Midi.szMidiOutFileName, + devicedlg[DEVDLG_MIDIOUTNAME].w, + TRUE); break; } } - while (but != DEVDLG_EXIT && !bQuitProgram); + while (but != DEVDLG_EXIT && but != SDLGUI_QUIT + && but != SDLGUI_ERROR && !bQuitProgram); /* Read values from dialog */ - DialogParams.Printer.bEnablePrinting = (devicedlg[DEVDLG_PRNENABLE].state & SG_SELECTED); - DialogParams.RS232.bEnableRS232 = (devicedlg[DEVDLG_RS232ENABLE].state & SG_SELECTED); - DialogParams.Midi.bEnableMidi = (devicedlg[DEVDLG_MIDIENABLE].state & SG_SELECTED); - - Memory_Free(tmpname); + ConfigureParams.Printer.bEnablePrinting = (devicedlg[DEVDLG_PRNENABLE].state & SG_SELECTED); + ConfigureParams.RS232.bEnableRS232 = (devicedlg[DEVDLG_RS232ENABLE].state & SG_SELECTED); + ConfigureParams.Midi.bEnableMidi = (devicedlg[DEVDLG_MIDIENABLE].state & SG_SELECTED); }