--- np2/macosx/toolwin.cpp 2003/11/21 16:01:41 1.12 +++ np2/macosx/toolwin.cpp 2003/11/24 20:44:14 1.13 @@ -115,6 +115,7 @@ static const OSType subcommand[11] ={ '- static const ControlID popup[2] = { {'pop1', 1}, {'pop2', 2} }; static DragReceiveHandlerUPP dr; +static DragTrackingHandlerUPP tr; static bool isPUMA; static void openpopup(HIPoint location); @@ -181,14 +182,18 @@ static void setlist(ControlRef hwnd, con #if 0 Rect rc; int width; -#endif - char basedir[MAX_PATH]; - UINT i; -const char *p; char dir[MAX_PATH]; -const char *q; - char cfname[512]; + char basedir[MAX_PATH]; +#endif MenuHandle menu; + UINT i; + char cfname[512]; +const char *q; +const char *p; + CFStringRef str; + SInt32 attr = kMenuItemAttrIconDisabled; + Str255 pname; + bool success = false; GetBevelButtonMenuHandle(hwnd, &menu); while (MenuHasEnabledItems(menu)) { @@ -197,21 +202,27 @@ const char *q; #if 0 GetControlBounds(hwnd, &rc); width = rc.right - rc.left - 6; // border size? -#endif basedir[0] = '\0'; if (sel < fdd->cnt) { milstr_ncpy(basedir, fdd->name[fdd->pos[sel]], sizeof(basedir)); file_cutname(basedir); } +#endif for (i=0; icnt; i++) { p = fdd->name[fdd->pos[i]]; - if (getLongFileName(cfname, p)) { - q = cfname; + 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); + CFRelease(str); } else { +#if 0 milstr_ncpy(dir, p, sizeof(dir)); file_cutname(dir); -#if 0 if (!file_cmpname(basedir, dir)) { q = file_getname((char *)p); } @@ -220,13 +231,13 @@ const char *q; q = dir; } #else - q = file_getname((char *)p); + q = file_getname((char *)p); #endif - } - AppendMenu(menu, "\pNot Available"); - SetMenuItemTextWithCFString(menu, i+1, CFStringCreateWithCString(NULL,q,kCFStringEncodingUTF8)); - if (file_attr(p)==FILEATTR_ARCHIVE) { - EnableMenuItem(menu, i+1); + mkstr255(pname, q); + AppendMenu(menu, pname); + if (file_attr(p)==FILEATTR_ARCHIVE) { + EnableMenuItem(menu, i+1); + } } p += sizeof(fdd->name[0]); } @@ -594,13 +605,19 @@ static pascal OSStatus cfWinproc(EventHa return err; } -OSErr setDropFile(FSSpec spec, int drv) { - char fname[MAX_PATH]; +static int getTypeFromFSSpec(char* fname, FSSpec* spec) { int ftype; - fsspec2path(&spec, fname, MAX_PATH); + fsspec2path(spec, fname, MAX_PATH); ftype = file_getftype(fname); - switch (ftype) { + + return (ftype); +} + +OSErr setDropFile(FSSpec spec, int drv) { + char fname[MAX_PATH]; + + switch (getTypeFromFSSpec(fname, &spec)) { case FTYPE_D88: case FTYPE_BETA: if (drv == -1) { @@ -610,7 +627,7 @@ OSErr setDropFile(FSSpec spec, int drv) toolwin_setfdd(drv, fname); break; - case FTYPE_TEXT: + case FTYPE_INI: strcpy(np2tool.skin, fname); skinchange(true); break; @@ -626,13 +643,31 @@ OSErr setDropFile(FSSpec spec, int drv) return(noErr); } -static pascal OSErr DragReceiver( WindowRef theWindow, void *handlerRefCon, DragRef theDrag ) -{ +static OSErr getFSSpecFromDragItem(DragRef theDrag, HFSFlavor* aHFSFlavor) { + UInt16 numItems; + DragItemRef ItemRef; + FlavorType Type; + + CountDragItems( theDrag, &numItems ); + if ( numItems != 1 ) { + return( -1 ); + } + GetDragItemReferenceNumber( theDrag, 1, &ItemRef ); + GetFlavorType( theDrag, ItemRef, 1, &Type ); + if ( Type != flavorTypeHFS ) { + return( -1 ); + } + Size dataSize = sizeof(HFSFlavor); + GetFlavorData( theDrag, ItemRef, flavorTypeHFS, aHFSFlavor, &dataSize, 0 ); + return(noErr); +} + +static SInt16 whichControl(DragRef theDrag, WindowRef theWindow) { SInt16 drv = -1; Point pt; + int i; ControlRef popupref[2]; Rect bounds[2]; - int i; GetDragMouse(theDrag, &pt, NULL); GlobalToLocal(&pt); @@ -644,28 +679,91 @@ static pascal OSErr DragReceiver( Window break; } } + return(drv); +} - UInt16 numItems; - CountDragItems( theDrag, &numItems ); - if ( numItems != 1 ) - { - return( -1 ); +static OSErr DragTracker (DragTrackingMessage message, WindowRef theWindow, void * handlerRefCon, DragRef theDrag) { + SInt16 drv = -1; + HFSFlavor aHFSFlavor; + RgnHandle rgn = NULL; + char fname[MAX_PATH]; + ControlRef targetControl; + GrafPtr port; + bool portchanged = false; + static bool hilite = false; + Rect bounds; + Boolean inframe = TRUE; + + if (message == kDragTrackingEnterHandler || message == kDragTrackingLeaveHandler) { + hilite = false; + return (noErr); + } + if (getFSSpecFromDragItem(theDrag, &aHFSFlavor) != noErr) { + if (hilite) { + if (HideDragHilite(theDrag) == noErr) { + hilite = false; + } + } + return (-1); + } + if (message != kDragTrackingLeaveWindow) { + switch (getTypeFromFSSpec(fname, &aHFSFlavor.fileSpec)) { + case FTYPE_D88: + case FTYPE_BETA: + drv = whichControl(theDrag, theWindow); + if (drv == -1) { + 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: + return(noErr); + } } - - DragItemRef ItemRef; - GetDragItemReferenceNumber( theDrag, 1, &ItemRef ); - FlavorType Type; - GetFlavorType( theDrag, ItemRef, 1, &Type ); - if ( Type != flavorTypeHFS ) - { - return( -1 ); + portchanged = QDSwapPort(GetWindowPort(theWindow), &port); + if (message == kDragTrackingLeaveWindow && hilite) { + if (HideDragHilite(theDrag) == noErr) { + hilite = false; + } } + else { + if (ShowDragHilite(theDrag, rgn, inframe) == noErr) { + hilite = true; + } + } + if (portchanged) QDSwapPort(port, NULL); + if (rgn) DisposeRgn(rgn); + return(noErr); +} + +static pascal OSErr DragReceiver( WindowRef theWindow, void *handlerRefCon, DragRef theDrag ) +{ + SInt16 drv = -1; HFSFlavor aHFSFlavor; - Size dataSize = sizeof(aHFSFlavor); - GetFlavorData( theDrag, ItemRef, flavorTypeHFS, &aHFSFlavor, &dataSize, 0 ); - + + if (getFSSpecFromDragItem(theDrag, &aHFSFlavor) != noErr) { + return (-1); + } + drv = whichControl(theDrag, theWindow); return( setDropFile(aHFSFlavor.fileSpec, drv) ); } @@ -695,7 +793,9 @@ static WindowRef makeNibWindow (IBNibRef InstallWindowEventHandler (win, NewEventHandlerUPP(cfWinproc), GetEventTypeCount(list), list, (void *)win, &ref); dr = NewDragReceiveHandlerUPP((DragReceiveHandlerProcPtr)DragReceiver); + tr = NewDragTrackingHandlerUPP((DragTrackingHandlerProcPtr)DragTracker); InstallReceiveHandler( dr, win, NULL); + InstallTrackingHandler( tr, win, NULL); } return(win); } @@ -925,6 +1025,7 @@ void toolwin_close(void) { } #endif RemoveReceiveHandler(dr, toolwin.hwnd); + RemoveTrackingHandler(tr, toolwin.hwnd); toolwindestroy(); DisposeWindow(toolwin.hwnd); toolwin.hwnd = NULL;