--- np2/macosx/toolwin.cpp 2003/11/05 17:58:01 1.7 +++ np2/macosx/toolwin.cpp 2004/03/02 23:23:06 1.18 @@ -11,7 +11,12 @@ #include "dialog.h" #include "soundmng.h" #include "fdefine.h" +#include "mackbd.h" +#include "mousemng.h" +#include "pccore.h" +#include "iocore.h" +extern void HandleMenuChoice(long wParam); enum { IDC_TOOLHDDACC = 0, @@ -107,24 +112,35 @@ static const OSType subcommand[11] ={ '- 'exit', }; +#define BASENUMBER 4 static const ControlID popup[2] = { {'pop1', 1}, {'pop2', 2} }; +static const ControlID imageid = {'back', 0}; -static void openpopup(HIPoint location); -static void skinchange(void); static DragReceiveHandlerUPP dr; +static DragTrackingHandlerUPP tr; +static bool isPUMA, isJaguar; -static bool isPUMA; +static void openpopup(Point location); +static void skinchange(bool remake); // ---- static void checkOSVersion(void) { - long res; - Gestalt(gestaltSystemVersion, &res); - if (res<0x1020) { - isPUMA = true; - } - else { - isPUMA = false; + static long res = 0; + if (!res) { + Gestalt(gestaltSystemVersion, &res); + if (res<0x1020) { + isPUMA = true; + isJaguar = false; + } + else if (res<0x1030) { + isPUMA = false; + isJaguar = true; + } + else { + isPUMA = false; + isJaguar = false; + } } } @@ -165,7 +181,7 @@ static PicHandle skinload(const char *pa return(ret); } } - return(getBMPfromResource("np2tool", bounds)); + return(getBMPfromResource("np2tool.bmp", bounds)); } // ---- @@ -174,14 +190,17 @@ 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; + Str255 pname; + bool success = false; GetBevelButtonMenuHandle(hwnd, &menu); while (MenuHasEnabledItems(menu)) { @@ -190,21 +209,30 @@ 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++) { + SInt32 attr = kMenuItemAttrIconDisabled; p = fdd->name[fdd->pos[i]]; - if (getLongFileName(cfname, p)) { - q = cfname; + success = getLongFileName(cfname, p); + str = CFStringCreateWithCString(NULL, cfname, CFStringGetSystemEncoding()); + if (str) { + if (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); } @@ -213,13 +241,16 @@ 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); + } + else { + DisableMenuItem(menu, i+1); + } } p += sizeof(fdd->name[0]); } @@ -227,7 +258,10 @@ const char *q; 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(" ")); @@ -329,9 +363,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(); } @@ -340,6 +386,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; @@ -348,6 +410,8 @@ const SUBITEM *p; const char *cls; UInt32 style; + setDragColor(GetWindowPort(hWnd)); + ControlButtonContentInfo info; info.contentType = kControlContentPictHandle; info.u.picture = NULL; @@ -447,6 +511,7 @@ static void toolwindestroy(void) { DisposePixPat(toolwin.access[1]); KillPicture(toolwin.hbmp); toolwin.hbmp = NULL; + DisposePixPat(portpat); } } @@ -464,7 +529,7 @@ static pascal OSStatus cfWinproc(EventHa switch (cmd.commandID) { case 'rset': - recieveCommand(IDM_RESET); + HandleMenuChoice(IDM_RESET); err=noErr; break; @@ -474,12 +539,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; @@ -489,17 +554,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; @@ -510,6 +575,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; @@ -522,25 +590,64 @@ static pascal OSStatus cfWinproc(EventHa Draw1Control(sub); } } + err=noErr; break; - default: break; } } + else if (GetEventClass(event)==kEventClassKeyboard) { + UInt32 whatHappened = GetEventKind(event); + UInt32 key; + GetEventParameter (event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &key); + UInt32 modif; + GetEventParameter (event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modif); + switch (whatHappened) + { + case kEventRawKeyUp: + mackbd_keyup(key); + err = noErr; + break; + case kEventRawKeyRepeat: + mackbd_keydown(key); + err = noErr; + break; + case kEventRawKeyDown: + if (modif & cmdKey) { + EventRecord eve; + ConvertEventRefToEventRecord( event,&eve ); + mousemng_disable(MOUSEPROC_MACUI); + HandleMenuChoice(MenuEvent(&eve)); + mousemng_enable(MOUSEPROC_MACUI); + } + else { + mackbd_keydown(key); + } + err = noErr; + break; + default: + break; + } + } (void)myHandler; 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) { @@ -550,9 +657,9 @@ OSErr setDropFile(FSSpec spec, int drv) toolwin_setfdd(drv, fname); break; - case FTYPE_TEXT: + case FTYPE_INI: strcpy(np2tool.skin, fname); - skinchange(); + skinchange(true); break; case FTYPE_THD: @@ -566,13 +673,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); @@ -584,28 +709,92 @@ 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; + ControlRef back; + + if (message == kDragTrackingEnterHandler || message == kDragTrackingLeaveHandler) { + hilite = false; + return (noErr); + } + if (getFSSpecFromDragItem(theDrag, &aHFSFlavor) != noErr) { + if (hilite) { + GetControlByID(theWindow, &imageid, &back); + Draw1Control(back); + 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 { + GetControlByID(theWindow, &popup[drv], &targetControl); + GetControlBounds(targetControl, &bounds); + } + break; + + case FTYPE_INI: + case FTYPE_THD: + case FTYPE_HDI: + GetWindowBounds(theWindow, kWindowContentRgn, &bounds); + OffsetRect(&bounds, -bounds.left, -bounds.top); + 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) { + GetControlByID(theWindow, &imageid, &back); + Draw1Control(back); + hilite = false; + } + else { + rgn = NewRgn(); + if (rgn) { + RectRgn(rgn, &bounds); + FrameRgn(rgn); + DisposeRgn(rgn); + } + hilite = true; } + if (portchanged) QDSwapPort(port, NULL); + 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 ); - + ControlRef back; + + GetControlByID(theWindow, &imageid, &back); + Draw1Control(back); + + if (getFSSpecFromDragItem(theDrag, &aHFSFlavor) != noErr) { + return (-1); + } + drv = whichControl(theDrag, theWindow); return( setDropFile(aHFSFlavor.fileSpec, drv) ); } @@ -624,16 +813,24 @@ static WindowRef makeNibWindow (IBNibRef if (err == noErr) { InstallStandardEventHandler(GetWindowEventTarget(win)); EventTypeSpec list[]={ - { kEventClassCommand, kEventCommandProcess }, - { kEventClassWindow, kEventWindowClose }, - { kEventClassWindow, kEventWindowShown }, - { kEventClassWindow, kEventWindowDrawContent }, + { kEventClassCommand, kEventCommandProcess }, + { kEventClassWindow, kEventWindowClose }, + { kEventClassWindow, kEventWindowShown }, + { kEventClassWindow, kEventWindowDrawContent }, + { 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); dr = NewDragReceiveHandlerUPP((DragReceiveHandlerProcPtr)DragReceiver); + tr = NewDragTrackingHandlerUPP((DragTrackingHandlerProcPtr)DragTracker); InstallReceiveHandler( dr, win, NULL); + InstallTrackingHandler( tr, win, NULL); } return(win); } @@ -657,63 +854,48 @@ static void createskinmenu(MenuRef ret) const char *base; char *p; UINT i; - UINT j; - UINT id[SKINMRU_MAX]; -const char *file[SKINMRU_MAX]; - Str255 seltext, deftext; + char longname[256]; - mkstr255(seltext, str_skinsel); - AppendMenu(ret, seltext); + AppendMenuItemTextWithCFString(ret, CFCopyLocalizedString(CFSTR("Select Skin..."),"Slect Skin"), kMenuItemAttrIconDisabled, NULL,NULL); AppendMenu(ret, "\p-"); base = np2tool.skin; - mkstr255(deftext, str_skindef); - AppendMenu(ret, deftext); - if (base[0] != '\0') { - EnableMenuItem(ret, 3); + AppendMenuItemTextWithCFString(ret, CFCopyLocalizedString(CFSTR(""),"Base Skin"), kMenuItemAttrIconDisabled, NULL,NULL); + if (base[0] == '\0') { + CheckMenuItem(ret, BASENUMBER-1, true); } for (cnt=0; cnti; j--) { - id[j] = id[j-1]; - } - id[i] = cnt; - file[cnt] = p; - } - for (i=0; i