--- np2/macosx/dialog/midiopt.cpp 2004/03/02 23:23:06 1.2 +++ np2/macosx/dialog/midiopt.cpp 2004/03/22 17:56:35 1.4 @@ -13,6 +13,7 @@ #include "dialog.h" #include "dialogutils.h" #include "midiopt.h" +#include "dipswbmp.h" #define setControlValue(a,b,c) SetControl32BitValue(getControlRefByID(a,b,midiWin),c) #define getMenuValue (GetControl32BitValue(getControlRefByID(cmd.commandID,0,midiWin))-1) @@ -70,6 +71,11 @@ static void setMPUs(void) { setControlValue('usem', 0, mpucfg.def_en); setMIMPIFilename(); + + PicHandle pict; + ControlRef disp = getControlRefByID('BMP ', 0, midiWin); + setbmp(dipswbmp_getmpu(mpu), &pict); + SetControlData(disp, kControlNoPart, kControlPictureHandleTag, sizeof(PicHandle), &pict); } static pascal OSStatus cfWinproc(EventHandlerCallRef myHandler, EventRef event, void* userData) { @@ -89,35 +95,43 @@ static pascal OSStatus cfWinproc(EventHa strcpy(mpucfg.def, ""); mpucfg.def_en = 0; setMPUs(); + err=noErr; break; case 'MPio': setjmper(&mpu, getMenuValue << 4, 0xf0); + err=noErr; break; case 'MPin': setjmper(&mpu, getMenuValue, 0x03); + err=noErr; break; case 'mido': strcpy(mpucfg.mout, midiout_name[getMenuValue]); + err=noErr; break; case 'midi': strcpy(mpucfg.min, midiout_name[getMenuValue]); + err=noErr; break; case 'midm': strcpy(mpucfg.mdl, cmmidi_mdlname[getMenuValue]); + err=noErr; break; case 'usem': mpucfg.def_en = GetControl32BitValue(getControlRefByID(cmd.commandID, 0, midiWin)); + err=noErr; break; case 'opnm': dialog_fileselect(mpucfg.def, sizeof(mpucfg.def), NULL, OPEN_MIMPI); setMIMPIFilename(); + err=noErr; break; case kHICommandOK: @@ -155,6 +169,49 @@ static pascal OSStatus cfWinproc(EventHa return err; } +static pascal OSStatus ctrlproc(EventHandlerCallRef myHandler, EventRef event, void* userData) { + OSStatus err = eventNotHandledErr; + HIPoint p; + BYTE bit; + int move; + Rect ctrlbounds, winbounds; + PicHandle pict; + BOOL redraw = FALSE; + + if (GetEventClass(event)==kEventClassControl && GetEventKind(event)==kEventControlClick ) { + err = noErr; + GetEventParameter(event, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(HIPoint), NULL, &p); + GetControlBounds((ControlRef)userData, &ctrlbounds); + GetWindowBounds(midiWin, kWindowContentRgn, &winbounds); + p.x -= (ctrlbounds.left + winbounds.left); + p.x /= 9; + if ((p.x >= 2) && (p.x < 6)) { + move = (int)(p.x - 2); + bit = 0x80 >> move; + mpu ^= bit; + redraw = TRUE; + } + else if ((p.x >= 9) && (p.x < 13)) { + bit = (BYTE)(13 - p.x); + if ((mpu ^ bit) & 3) { + mpu &= ~0x3; + mpu |= bit; + redraw = TRUE; + } + } + if (redraw) { + setMPUs(); + setbmp(dipswbmp_getmpu(mpu), &pict); + SetControlData((ControlRef)userData, kControlNoPart, kControlPictureHandleTag, sizeof(PicHandle), &pict); + Draw1Control((ControlRef)userData); + } + } + + (void)myHandler; + (void)userData; + return err; +} + static void initMidiWindow(void) { mpu = np2cfg.mpuopt; mpucfg = np2oscfg.mpu; @@ -167,15 +224,22 @@ static void initMidiWindow(void) { } static void makeNibWindow (IBNibRef nibRef) { - OSStatus err; + OSStatus err; EventHandlerRef ref; + ControlRef cref; err = CreateWindowFromNib(nibRef, CFSTR("MidiDialog"), &midiWin); if (err == noErr) { initMidiWindow(); - EventTypeSpec list[]={ { kEventClassCommand, kEventCommandProcess },}; + EventTypeSpec list[]={ { kEventClassCommand, kEventCommandProcess }, + { kEventClassWindow, kEventWindowShowing} }; InstallWindowEventHandler (midiWin, NewEventHandlerUPP(cfWinproc), GetEventTypeCount(list), list, (void *)midiWin, &ref); + + EventTypeSpec ctrllist[]={ { kEventClassControl, kEventControlClick } }; + cref = getControlRefByID('BMP ', 0, midiWin); + InstallControlEventHandler(cref, NewEventHandlerUPP(ctrlproc), GetEventTypeCount(ctrllist), ctrllist, (void *)cref, NULL); + ShowSheetWindow(midiWin, hWndMain); err=RunAppModalLoopForWindow(midiWin);