--- np2/macosx/toolwin.cpp 2003/11/27 16:25:42 1.14 +++ np2/macosx/toolwin.cpp 2005/05/20 17:25:03 1.21 @@ -16,6 +16,7 @@ #include "pccore.h" #include "iocore.h" +extern void HandleMenuChoice(long wParam); enum { IDC_TOOLHDDACC = 0, @@ -117,9 +118,9 @@ static const ControlID imageid = {'back' static DragReceiveHandlerUPP dr; static DragTrackingHandlerUPP tr; -static bool isPUMA; +static bool isPUMA, isJaguar; -static void openpopup(HIPoint location); +static void openpopup(Point location); static void skinchange(bool remake); // ---- @@ -130,9 +131,15 @@ static void checkOSVersion(void) { Gestalt(gestaltSystemVersion, &res); if (res<0x1020) { isPUMA = true; + isJaguar = false; } + else if (res<0x1030) { + isPUMA = false; + isJaguar = true; + } else { isPUMA = false; + isJaguar = false; } } } @@ -192,14 +199,11 @@ static void setlist(ControlRef hwnd, con const char *q; const char *p; CFStringRef str; - SInt32 attr = kMenuItemAttrIconDisabled; Str255 pname; bool success = false; GetBevelButtonMenuHandle(hwnd, &menu); - while (MenuHasEnabledItems(menu)) { - DeleteMenuItem(menu, 1); - }; + DeleteMenuItems(menu, 1, fdd->cnt); #if 0 GetControlBounds(hwnd, &rc); width = rc.right - rc.left - 6; // border size? @@ -210,14 +214,17 @@ const char *p; } #endif for (i=0; icnt; i++) { + SInt32 attr = kMenuItemAttrIconDisabled; p = fdd->name[fdd->pos[i]]; success = getLongFileName(cfname, p); str = CFStringCreateWithCString(NULL, cfname, CFStringGetSystemEncoding()); - if ((str) && success) { - if (file_attr(p) != FILEATTR_ARCHIVE) { - attr |= kMenuItemAttrDisabled; - } - AppendMenuItemTextWithCFString(menu, str, attr, NULL, NULL); + if (str) { + if (success) { + if (file_attr(p) != FILEATTR_ARCHIVE) { + attr |= kMenuItemAttrDisabled; + } + AppendMenuItemTextWithCFString(menu, str, attr, 0, 0); + } CFRelease(str); } else { @@ -239,6 +246,9 @@ const char *p; if (file_attr(p)==FILEATTR_ARCHIVE) { EnableMenuItem(menu, i+1); } + else { + DisableMenuItem(menu, i+1); + } } p += sizeof(fdd->name[0]); } @@ -246,10 +256,16 @@ const char *p; CFStringRef title; SetBevelButtonMenuValue(hwnd, sel+1); CopyMenuItemTextAsCFString(menu, sel+1, &title); - SetControlTitleWithCFString(hwnd, title); + if (title) { + SetControlTitleWithCFString(hwnd, title); + CFRelease(title); + } } else { SetControlTitleWithCFString(hwnd, CFSTR(" ")); + for (i=0; icnt; i++) { + CheckMenuItem(menu, i+1, 0); + } } } @@ -348,9 +364,21 @@ static pascal OSStatus cfControlproc(Eve } else if (GetEventClass(event)==kEventClassControl && GetEventKind(event)==kEventControlContextualMenuClick) { HIPoint location; + Point point; + soundmng_stop(); GetEventParameter (event, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(HIPoint), NULL, &location); - openpopup(location); + point.h = (short)location.x; + point.v = (short)location.y; + if (!isJaguar && !isPUMA) { + GrafPtr port, dst; + bool portchanged; + dst = GetWindowPort(toolwin.hwnd); + portchanged = QDSwapPort(dst, &port); + LocalToGlobal(&point); + if (portchanged) QDSwapPort(port, NULL); + } + openpopup(point); soundmng_play(); } @@ -430,7 +458,7 @@ const char *cls; style = 1; CreateBevelButtonControl(hWnd, &bounds, CFSTRj(p->text), kControlBevelButtonSmallBevel, - 0 ,NULL, NULL, NULL, NULL, &sub); + 0 ,NULL, 0, 0, 0, &sub); SetControlCommandID(sub, subcommand[i]); SetControlFontStyle(sub, &fontstyle); break; @@ -502,7 +530,7 @@ static pascal OSStatus cfWinproc(EventHa switch (cmd.commandID) { case 'rset': - recieveCommand(IDM_RESET); + HandleMenuChoice(IDM_RESET); err=noErr; break; @@ -512,12 +540,12 @@ static pascal OSStatus cfWinproc(EventHa break; case 'opn1': - recieveCommand(IDM_FDD1OPEN); + HandleMenuChoice(IDM_FDD1OPEN); err=noErr; break; case 'ejt1': - recieveCommand(IDM_FDD1EJECT); + HandleMenuChoice(IDM_FDD1EJECT); err=noErr; break; @@ -527,17 +555,17 @@ static pascal OSStatus cfWinproc(EventHa break; case 'opn2': - recieveCommand(IDM_FDD2OPEN); + HandleMenuChoice(IDM_FDD2OPEN); err=noErr; break; case 'ejt2': - recieveCommand(IDM_FDD2EJECT); + HandleMenuChoice(IDM_FDD2EJECT); err=noErr; break; case 'exit': - recieveCommand(IDM_EXIT); + HandleMenuChoice(IDM_EXIT); err=noErr; break; @@ -548,6 +576,9 @@ static pascal OSStatus cfWinproc(EventHa else if (GetEventClass(event)==kEventClassWindow) { switch (GetEventKind(event)) { case kEventWindowClose: +#ifdef AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER + case kEventWindowDrawerClosed: +#endif toolwin_close(); err=noErr; break; @@ -563,22 +594,15 @@ static pascal OSStatus cfWinproc(EventHa err=noErr; break; - case kEventWindowFocusAcquired: - BringToFront(hWndMain); - err = noErr; - break; - - default: break; } } else if (GetEventClass(event)==kEventClassKeyboard) { - static UInt32 backup = 0; UInt32 whatHappened = GetEventKind(event); - UInt32 key; + UInt32 key; GetEventParameter (event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &key); - UInt32 modif; + UInt32 modif; GetEventParameter (event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modif); switch (whatHappened) { @@ -595,7 +619,7 @@ static pascal OSStatus cfWinproc(EventHa EventRecord eve; ConvertEventRefToEventRecord( event,&eve ); mousemng_disable(MOUSEPROC_MACUI); - recieveCommand(MenuEvent(&eve)); + HandleMenuChoice(MenuEvent(&eve)); mousemng_enable(MOUSEPROC_MACUI); } else { @@ -603,19 +627,6 @@ static pascal OSStatus cfWinproc(EventHa } err = noErr; break; - case kEventRawKeyModifiersChanged: - if (modif & shiftKey) keystat_senddata(0x70); - else keystat_senddata(0x70 | 0x80); - if (modif & optionKey) keystat_senddata(0x73); - else keystat_senddata(0x73 | 0x80); - if (modif & controlKey) keystat_senddata(0x74); - else keystat_senddata(0x74 | 0x80); - if ((modif & alphaLock) != (backup & alphaLock)) { - keystat_senddata(0x71); - backup = modif; - } - err = noErr; - break; default: break; } @@ -807,8 +818,12 @@ static WindowRef makeNibWindow (IBNibRef { kEventClassWindow, kEventWindowClose }, { kEventClassWindow, kEventWindowShown }, { kEventClassWindow, kEventWindowDrawContent }, - { kEventClassWindow, kEventWindowFocusAcquired }, + { kEventClassKeyboard, kEventRawKeyUp}, { kEventClassKeyboard, kEventRawKeyDown}, + { kEventClassKeyboard, kEventRawKeyRepeat}, +#ifdef AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER + { kEventClassWindow, kEventWindowDrawerClosed }, +#endif }; EventHandlerRef ref; InstallWindowEventHandler (win, NewEventHandlerUPP(cfWinproc), GetEventTypeCount(list), list, (void *)win, &ref); @@ -842,11 +857,11 @@ const char *base; UINT i; char longname[256]; - AppendMenuItemTextWithCFString(ret, CFCopyLocalizedString(CFSTR("Select Skin..."),"Slect Skin"), kMenuItemAttrIconDisabled, NULL,NULL); + AppendMenuItemTextWithCFString(ret, CFCopyLocalizedString(CFSTR("Select Skin..."),"Slect Skin"), kMenuItemAttrIconDisabled, 0, 0); AppendMenu(ret, "\p-"); base = np2tool.skin; - AppendMenuItemTextWithCFString(ret, CFCopyLocalizedString(CFSTR(""),"Base Skin"), kMenuItemAttrIconDisabled, NULL,NULL); + AppendMenuItemTextWithCFString(ret, CFCopyLocalizedString(CFSTR(""),"Base Skin"), kMenuItemAttrIconDisabled, 0, 0); if (base[0] == '\0') { CheckMenuItem(ret, BASENUMBER-1, true); } @@ -863,7 +878,7 @@ const char *base; if (!getLongFileName(longname, p)) { strcpy(longname, file_getname(p)); } - AppendMenuItemTextWithCFString(ret, CFStringCreateWithCString(NULL, longname, kCFStringEncodingUTF8), attr, NULL, NULL); + AppendMenuItemTextWithCFString(ret, CFStringCreateWithCString(NULL, longname, kCFStringEncodingUTF8), attr, 0, 0); } for (i=0; i