--- np2/macosx/toolwin.cpp 2003/11/24 20:44:14 1.13 +++ 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, @@ -113,12 +114,13 @@ static const OSType subcommand[11] ={ '- #define BASENUMBER 4 static const ControlID popup[2] = { {'pop1', 1}, {'pop2', 2} }; +static const ControlID imageid = {'back', 0}; 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); // ---- @@ -129,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; } } } @@ -191,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? @@ -209,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 { @@ -238,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]); } @@ -245,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); + } } } @@ -347,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(); } @@ -358,6 +387,22 @@ static pascal OSStatus cfControlproc(Eve return err; } +static PixPatHandle portpat; + +static void setDragColor(GrafPtr window) { + GrafPtr port; + RGBColor color; + bool portchanged; + + portchanged = QDSwapPort(window, &port); + GetThemeBrushAsColor(kThemeBrushDragHilite, 32, true, &color); + portpat = NewPixPat(); + MakeRGBPat(portpat, &color); + PenPixPat(portpat); + PenSize(3, 3); + if (portchanged) QDSwapPort(port, NULL); +} + static void toolwincreate(WindowRef hWnd) { const SUBITEM *p; @@ -366,6 +411,8 @@ const SUBITEM *p; const char *cls; UInt32 style; + setDragColor(GetWindowPort(hWnd)); + ControlButtonContentInfo info; info.contentType = kControlContentPictHandle; info.u.picture = NULL; @@ -411,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; @@ -465,6 +512,7 @@ static void toolwindestroy(void) { DisposePixPat(toolwin.access[1]); KillPicture(toolwin.hbmp); toolwin.hbmp = NULL; + DisposePixPat(portpat); } } @@ -482,7 +530,7 @@ static pascal OSStatus cfWinproc(EventHa switch (cmd.commandID) { case 'rset': - recieveCommand(IDM_RESET); + HandleMenuChoice(IDM_RESET); err=noErr; break; @@ -492,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; @@ -507,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; @@ -528,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; @@ -543,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) { @@ -575,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 { @@ -583,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; } @@ -692,7 +723,7 @@ static OSErr DragTracker (DragTrackingMe bool portchanged = false; static bool hilite = false; Rect bounds; - Boolean inframe = TRUE; + ControlRef back; if (message == kDragTrackingEnterHandler || message == kDragTrackingLeaveHandler) { hilite = false; @@ -700,9 +731,9 @@ static OSErr DragTracker (DragTrackingMe } if (getFSSpecFromDragItem(theDrag, &aHFSFlavor) != noErr) { if (hilite) { - if (HideDragHilite(theDrag) == noErr) { - hilite = false; - } + GetControlByID(theWindow, &imageid, &back); + Draw1Control(back); + hilite = false; } return (-1); } @@ -715,22 +746,16 @@ static OSErr DragTracker (DragTrackingMe message = kDragTrackingLeaveWindow; } else { - rgn = NewRgn(); GetControlByID(theWindow, &popup[drv], &targetControl); GetControlBounds(targetControl, &bounds); - RectRgn(rgn, &bounds); - inframe = FALSE; } break; case FTYPE_INI: case FTYPE_THD: case FTYPE_HDI: - rgn = NewRgn(); GetWindowBounds(theWindow, kWindowContentRgn, &bounds); OffsetRect(&bounds, -bounds.left, -bounds.top); - RectRgn(rgn, &bounds); - inframe = TRUE; break; default: @@ -740,17 +765,20 @@ static OSErr DragTracker (DragTrackingMe portchanged = QDSwapPort(GetWindowPort(theWindow), &port); if (message == kDragTrackingLeaveWindow && hilite) { - if (HideDragHilite(theDrag) == noErr) { - hilite = false; - } + GetControlByID(theWindow, &imageid, &back); + Draw1Control(back); + hilite = false; } else { - if (ShowDragHilite(theDrag, rgn, inframe) == noErr) { - hilite = true; + rgn = NewRgn(); + if (rgn) { + RectRgn(rgn, &bounds); + FrameRgn(rgn); + DisposeRgn(rgn); } + hilite = true; } if (portchanged) QDSwapPort(port, NULL); - if (rgn) DisposeRgn(rgn); return(noErr); } @@ -759,6 +787,10 @@ static pascal OSErr DragReceiver( Window { SInt16 drv = -1; HFSFlavor aHFSFlavor; + ControlRef back; + + GetControlByID(theWindow, &imageid, &back); + Draw1Control(back); if (getFSSpecFromDragItem(theDrag, &aHFSFlavor) != noErr) { return (-1); @@ -786,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); @@ -821,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); } @@ -842,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