Annotation of hatari/src/gui-sdl/dlgDevice.c, revision 1.1.1.12

1.1       root        1: /*
                      2:   Hatari - dlgDevice.c
                      3: 
1.1.1.9   root        4:   This file is distributed under the GNU General Public License, version 2
                      5:   or at your option any later version. Read the file gpl.txt for details.
1.1       root        6: 
                      7:   Device (Printer etc.) setup dialog
                      8: */
1.1.1.7   root        9: const char DlgDevice_fileid[] = "Hatari dlgDevice.c : " __DATE__ " " __TIME__;
1.1       root       10: 
1.1.1.12! root       11: #include <assert.h>
1.1       root       12: #include "main.h"
                     13: #include "configuration.h"
                     14: #include "dialog.h"
                     15: #include "sdlgui.h"
                     16: #include "file.h"
                     17: #include "screen.h"
                     18: 
                     19: 
                     20: #define DEVDLG_PRNENABLE       3
1.1.1.3   root       21: #define DEVDLG_PRNBROWSE       5
1.1       root       22: #define DEVDLG_PRNFILENAME     6
                     23: #define DEVDLG_RS232ENABLE     8
                     24: #define DEVDLG_RS232OUTBROWSE  10
                     25: #define DEVDLG_RS232OUTNAME    11
                     26: #define DEVDLG_RS232INBROWSE   13
                     27: #define DEVDLG_RS232INNAME     14
                     28: #define DEVDLG_MIDIENABLE      16
1.1.1.12! root       29: #ifndef HAVE_PORTMIDI
1.1.1.6   root       30: #define DEVDLG_MIDIINBROWSE    18
                     31: #define DEVDLG_MIDIINNAME      19
                     32: #define DEVDLG_MIDIOUTBROWSE   21
                     33: #define DEVDLG_MIDIOUTNAME     22
                     34: #define DEVDLG_EXIT            23
1.1.1.12! root       35: #else
        !            36: #define DEVDLG_PREVIN          18
        !            37: #define DEVDLG_NEXTIN          19
        !            38: #define DEVDLG_MIDIINNAME      21
        !            39: #define DEVDLG_PREVOUT         23
        !            40: #define DEVDLG_NEXTOUT         24
        !            41: #define DEVDLG_MIDIOUTNAME     26
        !            42: #define DEVDLG_EXIT            27
        !            43: #endif
1.1       root       44: 
                     45: 
1.1.1.4   root       46: #define MAX_DLG_FILENAME 46+1
                     47: static char dlgPrinterName[MAX_DLG_FILENAME];
                     48: static char dlgRs232OutName[MAX_DLG_FILENAME];
                     49: static char dlgRs232InName[MAX_DLG_FILENAME];
1.1.1.6   root       50: static char dlgMidiInName[MAX_DLG_FILENAME];
1.1.1.4   root       51: static char dlgMidiOutName[MAX_DLG_FILENAME];
1.1       root       52: 
                     53: /* The devices dialog: */
                     54: static SGOBJ devicedlg[] =
                     55: {
1.1.1.6   root       56:        { SGBOX, 0, 0, 0,0, 52,24, NULL },
1.1       root       57:        { SGTEXT, 0, 0, 20,1, 13,1, "Devices setup" },
                     58: 
                     59:        { SGBOX, 0, 0, 1,3, 50,4, NULL },
1.1.1.10  root       60:        { SGCHECKBOX, 0, 0,  2,3, 26,1, "Enable _printer emulation" },
1.1       root       61:        { SGTEXT, 0, 0, 2,5, 10,1, "Print to file:" },
1.1.1.10  root       62:        { SGBUTTON,   0, 0, 42,5,  8,1, "_Browse" },
1.1       root       63:        { SGTEXT, 0, 0, 3,6, 46,1, dlgPrinterName },
                     64: 
                     65:        { SGBOX, 0, 0, 1,8, 50,6, NULL },
1.1.1.10  root       66:        { SGCHECKBOX, 0, 0,  2,8, 24,1, "Enable _RS232 emulation" },
1.1       root       67:        { SGTEXT, 0, 0, 2,10, 10,1, "Write RS232 output to file:" },
1.1.1.10  root       68:        { SGBUTTON,   0, 0, 42,10, 8,1, "Br_owse" },
1.1       root       69:        { SGTEXT, 0, 0, 3,11, 46,1, dlgRs232OutName },
                     70:        { SGTEXT, 0, 0, 2,12, 10,1, "Read RS232 input from file:" },
1.1.1.10  root       71:        { SGBUTTON,   0, 0, 42,12, 8,1, "Bro_wse" },
1.1       root       72:        { SGTEXT, 0, 0, 3,13, 46,1, dlgRs232InName },
                     73: 
1.1.1.6   root       74:        { SGBOX, 0, 0, 1,15, 50,6, NULL },
1.1.1.10  root       75:        { SGCHECKBOX, 0, 0, 2,15, 23,1, "Enable _MIDI emulation" },
1.1.1.12! root       76: #ifndef HAVE_PORTMIDI
1.1.1.6   root       77:        { SGTEXT, 0, 0, 2,17, 26,1, "Read MIDI input from file:" },
1.1.1.10  root       78:        { SGBUTTON,   0, 0, 42,17, 8,1, "Brow_se" },
1.1.1.6   root       79:        { SGTEXT, 0, 0, 3,18, 46,1, dlgMidiInName },
                     80:        { SGTEXT, 0, 0, 2,19, 26,1, "Write MIDI output to file:" },
1.1.1.10  root       81:        { SGBUTTON,   0, 0, 42,19, 8,1, "Brows_e" },
1.1.1.6   root       82:        { SGTEXT, 0, 0, 3,20, 46,1, dlgMidiOutName },
1.1.1.12! root       83: #else
        !            84:        { SGTEXT, 0, 0, 5,17, 7,1, "input:" },
        !            85:        { SGBUTTON, 0, 0,  12,17, 3,1, "\x04", SG_SHORTCUT_LEFT },
        !            86:        { SGBUTTON, 0, 0, 15,17, 3,1, "\x03", SG_SHORTCUT_RIGHT },
        !            87:        { SGBOX, 0, 0, 18,17, 32,1, NULL },
        !            88:        { SGTEXT, 0, 0, 19,17, 30,1, dlgMidiInName },
        !            89:        { SGTEXT, 0, 0, 4,19, 7,1, "output:" },
        !            90:        { SGBUTTON, 0, 0,  12,19, 3,1, "\x04", SG_SHORTCUT_LEFT },
        !            91:        { SGBUTTON, 0, 0, 15,19, 3,1, "\x03", SG_SHORTCUT_RIGHT },
        !            92:        { SGBOX, 0, 0, 18,19, 32,1, NULL },
        !            93:        { SGTEXT, 0, 0, 19,19, 30,1, dlgMidiOutName },
        !            94: #endif
1.1.1.6   root       95:        { SGBUTTON, SG_DEFAULT, 0, 16,22, 20,1, "Back to main menu" },
1.1.1.11  root       96:        { SGSTOP, 0, 0, 0,0, 0,0, NULL }
1.1       root       97: };
                     98: 
                     99: 
1.1.1.12! root      100: #ifdef HAVE_PORTMIDI
        !           101: #include "midi.h"
        !           102: static int midiInput  = -1;
        !           103: static int midiOutput = -1;
        !           104: 
        !           105: static void setupMidiControls(void)
        !           106: {
        !           107:        const char *inportName,*outportName;
        !           108:        midiInput  = Midi_Host_GetPortIndex(ConfigureParams.Midi.sMidiInPortName,  true);
        !           109:        midiOutput = Midi_Host_GetPortIndex(ConfigureParams.Midi.sMidiOutPortName, false);
        !           110:        inportName  = (midiInput  < 0) ? "Off" : ConfigureParams.Midi.sMidiInPortName;
        !           111:        outportName = (midiOutput < 0) ? "Off" : ConfigureParams.Midi.sMidiOutPortName;
        !           112:        File_ShrinkName(dlgMidiInName,  inportName,  devicedlg[DEVDLG_MIDIINNAME].w);
        !           113:        File_ShrinkName(dlgMidiOutName, outportName, devicedlg[DEVDLG_MIDIOUTNAME].w);
        !           114: }
        !           115: #endif
        !           116: 
        !           117: 
1.1       root      118: /*-----------------------------------------------------------------------*/
1.1.1.8   root      119: /**
                    120:  * Show and process the "Device" dialog.
                    121:  */
1.1       root      122: void Dialog_DeviceDlg(void)
                    123: {
                    124:        int but;
1.1.1.12! root      125: #ifdef HAVE_PORTMIDI
        !           126:        const char* portName;
        !           127: #endif
1.1       root      128: 
                    129:        SDLGui_CenterDlg(devicedlg);
                    130: 
                    131:        /* Set up dialog from actual values: */
                    132: 
1.1.1.5   root      133:        if (ConfigureParams.Printer.bEnablePrinting)
1.1       root      134:                devicedlg[DEVDLG_PRNENABLE].state |= SG_SELECTED;
                    135:        else
                    136:                devicedlg[DEVDLG_PRNENABLE].state &= ~SG_SELECTED;
1.1.1.5   root      137:        File_ShrinkName(dlgPrinterName, ConfigureParams.Printer.szPrintToFileName, devicedlg[DEVDLG_PRNFILENAME].w);
1.1       root      138: 
1.1.1.5   root      139:        if (ConfigureParams.RS232.bEnableRS232)
1.1       root      140:                devicedlg[DEVDLG_RS232ENABLE].state |= SG_SELECTED;
                    141:        else
                    142:                devicedlg[DEVDLG_RS232ENABLE].state &= ~SG_SELECTED;
1.1.1.5   root      143:        File_ShrinkName(dlgRs232OutName, ConfigureParams.RS232.szOutFileName, devicedlg[DEVDLG_RS232OUTNAME].w);
                    144:        File_ShrinkName(dlgRs232InName, ConfigureParams.RS232.szInFileName, devicedlg[DEVDLG_RS232INNAME].w);
1.1       root      145: 
1.1.1.5   root      146:        if (ConfigureParams.Midi.bEnableMidi)
1.1       root      147:                devicedlg[DEVDLG_MIDIENABLE].state |= SG_SELECTED;
                    148:        else
                    149:                devicedlg[DEVDLG_MIDIENABLE].state &= ~SG_SELECTED;
1.1.1.12! root      150: #ifndef HAVE_PORTMIDI
1.1.1.6   root      151:        File_ShrinkName(dlgMidiInName, ConfigureParams.Midi.sMidiInFileName, devicedlg[DEVDLG_MIDIINNAME].w);
                    152:        File_ShrinkName(dlgMidiOutName, ConfigureParams.Midi.sMidiOutFileName, devicedlg[DEVDLG_MIDIOUTNAME].w);
1.1.1.12! root      153: #else
        !           154:        setupMidiControls();
        !           155: #endif
1.1       root      156: 
                    157:        /* The devices dialog main loop */
                    158:        do
                    159:        {
1.1.1.10  root      160:                but = SDLGui_DoDialog(devicedlg, NULL, false);
1.1       root      161: 
                    162:                switch(but)
                    163:                {
                    164:                 case DEVDLG_PRNBROWSE:                 /* Choose a new printer file */
1.1.1.10  root      165:                        SDLGui_FileConfSelect("Printer output:", dlgPrinterName,
1.1.1.5   root      166:                                               ConfigureParams.Printer.szPrintToFileName,
1.1.1.4   root      167:                                               devicedlg[DEVDLG_PRNFILENAME].w,
1.1.1.7   root      168:                                               true);
1.1       root      169:                        break;
                    170:                 case DEVDLG_RS232OUTBROWSE:            /* Choose a new RS232 output file */
1.1.1.10  root      171:                        SDLGui_FileConfSelect("RS232 output:", dlgRs232OutName,
1.1.1.5   root      172:                                               ConfigureParams.RS232.szOutFileName,
1.1.1.4   root      173:                                               devicedlg[DEVDLG_RS232OUTNAME].w,
1.1.1.7   root      174:                                               true);
1.1       root      175:                        break;
                    176:                 case DEVDLG_RS232INBROWSE:             /* Choose a new RS232 input file */
1.1.1.10  root      177:                        SDLGui_FileConfSelect("RS232 input:", dlgRs232InName,
1.1.1.5   root      178:                                               ConfigureParams.RS232.szInFileName,
1.1.1.4   root      179:                                               devicedlg[DEVDLG_RS232INNAME].w,
1.1.1.7   root      180:                                               true);
1.1       root      181:                        break;
1.1.1.12! root      182: #ifndef HAVE_PORTMIDI
1.1.1.6   root      183:                 case DEVDLG_MIDIINBROWSE:              /* Choose a new MIDI file */
1.1.1.10  root      184:                        SDLGui_FileConfSelect("MIDI input:", dlgMidiInName,
1.1.1.6   root      185:                                               ConfigureParams.Midi.sMidiInFileName,
                    186:                                               devicedlg[DEVDLG_MIDIINNAME].w,
1.1.1.7   root      187:                                               true);
1.1.1.6   root      188:                        break;
                    189:                 case DEVDLG_MIDIOUTBROWSE:             /* Choose a new MIDI file */
1.1.1.10  root      190:                        SDLGui_FileConfSelect("MIDI output:", dlgMidiOutName,
1.1.1.6   root      191:                                               ConfigureParams.Midi.sMidiOutFileName,
1.1.1.4   root      192:                                               devicedlg[DEVDLG_MIDIOUTNAME].w,
1.1.1.7   root      193:                                               true);
1.1       root      194:                        break;
1.1.1.12! root      195: #else
        !           196:                case DEVDLG_PREVIN:
        !           197:                        if (midiInput >= 0)
        !           198:                        {
        !           199:                                midiInput--;
        !           200:                                portName = (midiInput == -1) ? "Off" : Midi_Host_GetPortName(midiInput, true);
        !           201:                                if (portName)
        !           202:                                        File_ShrinkName(dlgMidiInName, portName, devicedlg[DEVDLG_MIDIINNAME].w);
        !           203:                        }
        !           204:                        break;
        !           205:                case DEVDLG_NEXTIN:
        !           206:                        portName = Midi_Host_GetPortName(midiInput + 1, true);
        !           207:                        if (portName)
        !           208:                        {
        !           209:                                midiInput++;
        !           210:                                File_ShrinkName(dlgMidiInName, portName, devicedlg[DEVDLG_MIDIINNAME].w);
        !           211:                        }
        !           212:                        break;
        !           213:                case DEVDLG_PREVOUT:
        !           214:                        if (midiOutput >= 0)
        !           215:                        {
        !           216:                                midiOutput--;
        !           217:                                portName = (midiOutput == -1) ? "Off" : Midi_Host_GetPortName(midiOutput, false);
        !           218:                                if (portName)
        !           219:                                        File_ShrinkName(dlgMidiOutName, portName, devicedlg[DEVDLG_MIDIOUTNAME].w);
        !           220:                        }
        !           221:                        break;
        !           222:                case DEVDLG_NEXTOUT:
        !           223:                        portName = Midi_Host_GetPortName(midiOutput + 1, false);
        !           224:                        if (portName)
        !           225:                        {
        !           226:                                midiOutput++;
        !           227:                                File_ShrinkName(dlgMidiOutName, portName, devicedlg[DEVDLG_MIDIOUTNAME].w);
        !           228:                        }
        !           229:                        break;
        !           230: #endif
1.1       root      231:                }
                    232:        }
1.1.1.4   root      233:        while (but != DEVDLG_EXIT && but != SDLGUI_QUIT
                    234:               && but != SDLGUI_ERROR && !bQuitProgram);
1.1       root      235: 
                    236:        /* Read values from dialog */
1.1.1.5   root      237:        ConfigureParams.Printer.bEnablePrinting = (devicedlg[DEVDLG_PRNENABLE].state & SG_SELECTED);
                    238:        ConfigureParams.RS232.bEnableRS232 = (devicedlg[DEVDLG_RS232ENABLE].state & SG_SELECTED);
                    239:        ConfigureParams.Midi.bEnableMidi = (devicedlg[DEVDLG_MIDIENABLE].state & SG_SELECTED);
1.1.1.12! root      240: #ifdef HAVE_PORTMIDI
        !           241:        assert(sizeof(dlgMidiInName) <= sizeof(ConfigureParams.Midi.sMidiInPortName));
        !           242:        strcpy(ConfigureParams.Midi.sMidiInPortName, dlgMidiInName);
        !           243:        assert(sizeof(dlgMidiOutName) <= sizeof(ConfigureParams.Midi.sMidiOutPortName));
        !           244:        strcpy(ConfigureParams.Midi.sMidiOutPortName, dlgMidiOutName);
        !           245: #endif
1.1       root      246: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.