| version 1.8, 2003/11/08 17:54:26 | version 1.19, 2004/03/15 05:06:01 | 
| Line 11 | Line 11 | 
 | #include        "dialog.h" | #include        "dialog.h" | 
 | #include        "soundmng.h" | #include        "soundmng.h" | 
 | #include        "fdefine.h" | #include        "fdefine.h" | 
 |  | #include        "mackbd.h" | 
 |  | #include        "mousemng.h" | 
 |  | #include        "pccore.h" | 
 |  | #include        "iocore.h" | 
 |  |  | 
 |  | extern void HandleMenuChoice(long wParam); | 
 |  |  | 
 | enum { | enum { | 
 | IDC_TOOLHDDACC                  = 0, | IDC_TOOLHDDACC                  = 0, | 
| Line 107  static const OSType subcommand[11] ={ '- | Line 112  static const OSType subcommand[11] ={ '- | 
 | 'exit', | 'exit', | 
 | }; | }; | 
 |  |  | 
 |  | #define BASENUMBER      4 | 
 | static const ControlID popup[2] = { {'pop1', 1}, {'pop2', 2} }; | static const ControlID popup[2] = { {'pop1', 1}, {'pop2', 2} }; | 
 |  | static const ControlID imageid = {'back', 0}; | 
 |  |  | 
 | static DragReceiveHandlerUPP    dr; | static DragReceiveHandlerUPP    dr; | 
| static bool     isPUMA; | static DragTrackingHandlerUPP   tr; | 
|  | static bool     isPUMA, isJaguar; | 
 |  |  | 
| static void openpopup(HIPoint location); | static void openpopup(Point location); | 
| static void skinchange(void); | static void skinchange(bool remake); | 
 |  |  | 
 | // ---- | // ---- | 
 |  |  | 
 | static void checkOSVersion(void) { | static void checkOSVersion(void) { | 
| long        res; | static      long    res = 0; | 
| Gestalt(gestaltSystemVersion, &res); | if (!res) { | 
| if (res<0x1020) { | Gestalt(gestaltSystemVersion, &res); | 
| isPUMA = true; | if (res<0x1020) { | 
| } | isPUMA = true; | 
| else { | isJaguar = false; | 
| isPUMA = false; | } | 
|  | else if (res<0x1030) { | 
|  | isPUMA = false; | 
|  | isJaguar = true; | 
|  | } | 
|  | else { | 
|  | isPUMA = false; | 
|  | isJaguar = false; | 
|  | } | 
 | } | } | 
 | } | } | 
 |  |  | 
| Line 165  static PicHandle skinload(const char *pa | Line 181  static PicHandle skinload(const char *pa | 
 | return(ret); | return(ret); | 
 | } | } | 
 | } | } | 
| return(getBMPfromResource("np2tool", bounds)); | return(getBMPfromResource("np2tool.bmp", bounds)); | 
 | } | } | 
 |  |  | 
 | // ---- | // ---- | 
| Line 174  static void setlist(ControlRef hwnd, con | Line 190  static void setlist(ControlRef hwnd, con | 
 | #if 0 | #if 0 | 
 | Rect    rc; | Rect    rc; | 
 | int             width; | int             width; | 
 | #endif |  | 
 | char    basedir[MAX_PATH]; |  | 
 | UINT    i; |  | 
 | const char      *p; |  | 
 | char    dir[MAX_PATH]; | char    dir[MAX_PATH]; | 
| const char      *q; | char            basedir[MAX_PATH]; | 
| char        cfname[512]; | #endif | 
 | MenuHandle  menu; | MenuHandle  menu; | 
 |  | UINT            i; | 
 |  | char                cfname[512]; | 
 |  | const char              *q; | 
 |  | const char              *p; | 
 |  | CFStringRef str; | 
 |  | Str255              pname; | 
 |  | bool                success = false; | 
 |  |  | 
 | GetBevelButtonMenuHandle(hwnd, &menu); | GetBevelButtonMenuHandle(hwnd, &menu); | 
| while (MenuHasEnabledItems(menu)) { | DeleteMenuItems(menu, 1, fdd->cnt); | 
| DeleteMenuItem(menu, 1); |  | 
| }; |  | 
 | #if 0 | #if 0 | 
 | GetControlBounds(hwnd, &rc); | GetControlBounds(hwnd, &rc); | 
 | width = rc.right - rc.left - 6;                 // border size? | width = rc.right - rc.left - 6;                 // border size? | 
 | #endif |  | 
 | basedir[0] = '\0'; | basedir[0] = '\0'; | 
 | if (sel < fdd->cnt) { | if (sel < fdd->cnt) { | 
 | milstr_ncpy(basedir, fdd->name[fdd->pos[sel]], sizeof(basedir)); | milstr_ncpy(basedir, fdd->name[fdd->pos[sel]], sizeof(basedir)); | 
 | file_cutname(basedir); | file_cutname(basedir); | 
 | } | } | 
 |  | #endif | 
 | for (i=0; i<fdd->cnt; i++) { | for (i=0; i<fdd->cnt; i++) { | 
 |  | SInt32          attr = kMenuItemAttrIconDisabled; | 
 | p = fdd->name[fdd->pos[i]]; | p = fdd->name[fdd->pos[i]]; | 
| if (getLongFileName(cfname, p)) { | success = getLongFileName(cfname, p); | 
| q = cfname; | 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 { | else { | 
 |  | #if 0 | 
 | milstr_ncpy(dir, p, sizeof(dir)); | milstr_ncpy(dir, p, sizeof(dir)); | 
 | file_cutname(dir); | file_cutname(dir); | 
 | #if 0 |  | 
 | if (!file_cmpname(basedir, dir)) { | if (!file_cmpname(basedir, dir)) { | 
 | q = file_getname((char *)p); | q = file_getname((char *)p); | 
 | } | } | 
| Line 213  const char *q; | Line 239  const char *q; | 
 | q = dir; | q = dir; | 
 | } | } | 
 | #else | #else | 
| q = file_getname((char *)p); | q = file_getname((char *)p); | 
 | #endif | #endif | 
| } | mkstr255(pname, q); | 
| AppendMenu(menu, "\pNot Available"); | AppendMenu(menu, pname); | 
| SetMenuItemTextWithCFString(menu, i+1, CFStringCreateWithCString(NULL,q,kCFStringEncodingUTF8)); | if (file_attr(p)==FILEATTR_ARCHIVE) { | 
| if (file_attr(p)==FILEATTR_ARCHIVE) { | EnableMenuItem(menu, i+1); | 
| EnableMenuItem(menu, i+1); | } | 
|  | else { | 
|  | DisableMenuItem(menu, i+1); | 
|  | } | 
 | } | } | 
 | p += sizeof(fdd->name[0]); | p += sizeof(fdd->name[0]); | 
 | } | } | 
| Line 227  const char *q; | Line 256  const char *q; | 
 | CFStringRef title; | CFStringRef title; | 
 | SetBevelButtonMenuValue(hwnd, sel+1); | SetBevelButtonMenuValue(hwnd, sel+1); | 
 | CopyMenuItemTextAsCFString(menu, sel+1, &title); | CopyMenuItemTextAsCFString(menu, sel+1, &title); | 
| SetControlTitleWithCFString(hwnd, title); | if (title) { | 
|  | SetControlTitleWithCFString(hwnd, title); | 
|  | CFRelease(title); | 
|  | } | 
 | } | } | 
 | else { | else { | 
 | SetControlTitleWithCFString(hwnd, CFSTR(" ")); | SetControlTitleWithCFString(hwnd, CFSTR(" ")); | 
 |  | for (i=0; i<fdd->cnt; i++) { | 
 |  | CheckMenuItem(menu, i+1, 0); | 
 |  | } | 
 | } | } | 
 | } | } | 
 |  |  | 
| Line 329  static pascal OSStatus cfControlproc(Eve | Line 364  static pascal OSStatus cfControlproc(Eve | 
 | } | } | 
 | else if (GetEventClass(event)==kEventClassControl && GetEventKind(event)==kEventControlContextualMenuClick) { | else if (GetEventClass(event)==kEventClassControl && GetEventKind(event)==kEventControlContextualMenuClick) { | 
 | HIPoint location; | HIPoint location; | 
 |  | Point   point; | 
 |  |  | 
 | soundmng_stop(); | soundmng_stop(); | 
 | GetEventParameter (event, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(HIPoint), NULL, &location); | 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(); | soundmng_play(); | 
 | } | } | 
 |  |  | 
| Line 340  static pascal OSStatus cfControlproc(Eve | Line 387  static pascal OSStatus cfControlproc(Eve | 
 | return err; | 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) { | static void toolwincreate(WindowRef hWnd) { | 
 |  |  | 
 | const SUBITEM   *p; | const SUBITEM   *p; | 
| Line 348  const SUBITEM *p; | Line 411  const SUBITEM *p; | 
 | const char              *cls; | const char              *cls; | 
 | UInt32          style; | UInt32          style; | 
 |  |  | 
 |  | setDragColor(GetWindowPort(hWnd)); | 
 |  |  | 
 | ControlButtonContentInfo    info; | ControlButtonContentInfo    info; | 
 | info.contentType = kControlContentPictHandle; | info.contentType = kControlContentPictHandle; | 
 | info.u.picture = NULL; | info.u.picture = NULL; | 
| Line 447  static void toolwindestroy(void) { | Line 512  static void toolwindestroy(void) { | 
 | DisposePixPat(toolwin.access[1]); | DisposePixPat(toolwin.access[1]); | 
 | KillPicture(toolwin.hbmp); | KillPicture(toolwin.hbmp); | 
 | toolwin.hbmp = NULL; | toolwin.hbmp = NULL; | 
 |  | DisposePixPat(portpat); | 
 | } | } | 
 | } | } | 
 |  |  | 
| Line 464  static pascal OSStatus cfWinproc(EventHa | Line 530  static pascal OSStatus cfWinproc(EventHa | 
 | switch (cmd.commandID) | switch (cmd.commandID) | 
 | { | { | 
 | case 'rset': | case 'rset': | 
| recieveCommand(IDM_RESET); | HandleMenuChoice(IDM_RESET); | 
 | err=noErr; | err=noErr; | 
 | break; | break; | 
 |  |  | 
| Line 474  static pascal OSStatus cfWinproc(EventHa | Line 540  static pascal OSStatus cfWinproc(EventHa | 
 | break; | break; | 
 |  |  | 
 | case 'opn1': | case 'opn1': | 
| recieveCommand(IDM_FDD1OPEN); | HandleMenuChoice(IDM_FDD1OPEN); | 
 | err=noErr; | err=noErr; | 
 | break; | break; | 
 |  |  | 
 | case 'ejt1': | case 'ejt1': | 
| recieveCommand(IDM_FDD1EJECT); | HandleMenuChoice(IDM_FDD1EJECT); | 
 | err=noErr; | err=noErr; | 
 | break; | break; | 
 |  |  | 
| Line 489  static pascal OSStatus cfWinproc(EventHa | Line 555  static pascal OSStatus cfWinproc(EventHa | 
 | break; | break; | 
 |  |  | 
 | case 'opn2': | case 'opn2': | 
| recieveCommand(IDM_FDD2OPEN); | HandleMenuChoice(IDM_FDD2OPEN); | 
 | err=noErr; | err=noErr; | 
 | break; | break; | 
 |  |  | 
 | case 'ejt2': | case 'ejt2': | 
| recieveCommand(IDM_FDD2EJECT); | HandleMenuChoice(IDM_FDD2EJECT); | 
 | err=noErr; | err=noErr; | 
 | break; | break; | 
 |  |  | 
 | case 'exit': | case 'exit': | 
| recieveCommand(IDM_EXIT); | HandleMenuChoice(IDM_EXIT); | 
 | err=noErr; | err=noErr; | 
 | break; | break; | 
 |  |  | 
| Line 510  static pascal OSStatus cfWinproc(EventHa | Line 576  static pascal OSStatus cfWinproc(EventHa | 
 | else if (GetEventClass(event)==kEventClassWindow) { | else if (GetEventClass(event)==kEventClassWindow) { | 
 | switch (GetEventKind(event)) { | switch (GetEventKind(event)) { | 
 | case kEventWindowClose: | case kEventWindowClose: | 
 |  | #ifdef AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER | 
 |  | case kEventWindowDrawerClosed: | 
 |  | #endif | 
 | toolwin_close(); | toolwin_close(); | 
 | err=noErr; | err=noErr; | 
 | break; | break; | 
| Line 522  static pascal OSStatus cfWinproc(EventHa | Line 591  static pascal OSStatus cfWinproc(EventHa | 
 | Draw1Control(sub); | Draw1Control(sub); | 
 | } | } | 
 | } | } | 
 |  | err=noErr; | 
 | break; | break; | 
 |  |  | 
 | case kEventWindowFocusAcquired: |  | 
 | SelectWindow(hWndMain); |  | 
 | break; |  | 
 |  |  | 
 |  |  | 
 | default: | default: | 
 | break; | 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; | (void)myHandler; | 
 | return err; | return err; | 
 | } | } | 
 |  |  | 
| OSErr setDropFile(FSSpec spec, int drv) { | static int getTypeFromFSSpec(char* fname, FSSpec* spec) { | 
| char                fname[MAX_PATH]; |  | 
 | int                 ftype; | int                 ftype; | 
 |  |  | 
| fsspec2path(&spec, fname, MAX_PATH); | fsspec2path(spec, fname, MAX_PATH); | 
 | ftype = file_getftype(fname); | 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_D88: | 
 | case FTYPE_BETA: | case FTYPE_BETA: | 
 | if (drv == -1) { | if (drv == -1) { | 
| Line 554  OSErr setDropFile(FSSpec spec, int drv) | Line 658  OSErr setDropFile(FSSpec spec, int drv) | 
 | toolwin_setfdd(drv, fname); | toolwin_setfdd(drv, fname); | 
 | break; | break; | 
 |  |  | 
| case FTYPE_TEXT: | case FTYPE_INI: | 
 | strcpy(np2tool.skin, fname); | strcpy(np2tool.skin, fname); | 
| skinchange(); | skinchange(true); | 
 | break; | break; | 
 |  |  | 
 | case FTYPE_THD: | case FTYPE_THD: | 
| Line 570  OSErr setDropFile(FSSpec spec, int drv) | Line 674  OSErr setDropFile(FSSpec spec, int drv) | 
 | return(noErr); | 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; | SInt16              drv = -1; | 
 | Point               pt; | Point               pt; | 
 |  | int                 i; | 
 | ControlRef  popupref[2]; | ControlRef  popupref[2]; | 
 | Rect                bounds[2]; | Rect                bounds[2]; | 
 | int                 i; |  | 
 |  |  | 
 | GetDragMouse(theDrag, &pt, NULL); | GetDragMouse(theDrag, &pt, NULL); | 
 | GlobalToLocal(&pt); | GlobalToLocal(&pt); | 
| Line 588  static pascal OSErr DragReceiver( Window | Line 710  static pascal OSErr DragReceiver( Window | 
 | break; | break; | 
 | } | } | 
 | } | } | 
 |  | return(drv); | 
 |  | } | 
 |  |  | 
| UInt16 numItems; | static OSErr DragTracker (DragTrackingMessage message, WindowRef theWindow, void * handlerRefCon, DragRef theDrag) { | 
| CountDragItems( theDrag, &numItems ); | SInt16              drv = -1; | 
| if ( numItems != 1 ) | HFSFlavor       aHFSFlavor; | 
| { | RgnHandle   rgn = NULL; | 
| return( -1 ); | 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; | portchanged = QDSwapPort(GetWindowPort(theWindow), &port); | 
| GetFlavorType( theDrag, ItemRef, 1, &Type ); | if (message == kDragTrackingLeaveWindow && hilite) { | 
| if ( Type != flavorTypeHFS ) | GetControlByID(theWindow, &imageid, &back); | 
| { | Draw1Control(back); | 
| return( -1 ); | 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; | HFSFlavor aHFSFlavor; | 
| Size dataSize = sizeof(aHFSFlavor); | ControlRef  back; | 
| GetFlavorData( theDrag, ItemRef, flavorTypeHFS, &aHFSFlavor, &dataSize, 0 ); |  | 
|  | GetControlByID(theWindow, &imageid, &back); | 
|  | Draw1Control(back); | 
|  |  | 
|  | if (getFSSpecFromDragItem(theDrag, &aHFSFlavor) != noErr) { | 
|  | return (-1); | 
|  | } | 
|  | drv = whichControl(theDrag, theWindow); | 
 | return( setDropFile(aHFSFlavor.fileSpec, drv) ); | return( setDropFile(aHFSFlavor.fileSpec, drv) ); | 
 | } | } | 
 |  |  | 
| Line 628  static WindowRef makeNibWindow (IBNibRef | Line 814  static WindowRef makeNibWindow (IBNibRef | 
 | if (err == noErr) { | if (err == noErr) { | 
 | InstallStandardEventHandler(GetWindowEventTarget(win)); | InstallStandardEventHandler(GetWindowEventTarget(win)); | 
 | EventTypeSpec   list[]={ | EventTypeSpec   list[]={ | 
| { kEventClassCommand, kEventCommandProcess }, | { kEventClassCommand,       kEventCommandProcess }, | 
| { kEventClassWindow, kEventWindowClose }, | { kEventClassWindow,        kEventWindowClose }, | 
| { kEventClassWindow, kEventWindowShown }, | { kEventClassWindow,        kEventWindowShown }, | 
| { kEventClassWindow, kEventWindowDrawContent }, | { 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; | EventHandlerRef ref; | 
 | InstallWindowEventHandler (win, NewEventHandlerUPP(cfWinproc), GetEventTypeCount(list), list, (void *)win, &ref); | InstallWindowEventHandler (win, NewEventHandlerUPP(cfWinproc), GetEventTypeCount(list), list, (void *)win, &ref); | 
 |  |  | 
 | dr = NewDragReceiveHandlerUPP((DragReceiveHandlerProcPtr)DragReceiver); | dr = NewDragReceiveHandlerUPP((DragReceiveHandlerProcPtr)DragReceiver); | 
 |  | tr = NewDragTrackingHandlerUPP((DragTrackingHandlerProcPtr)DragTracker); | 
 | InstallReceiveHandler( dr, win, NULL); | InstallReceiveHandler( dr, win, NULL); | 
 |  | InstallTrackingHandler( tr, win, NULL); | 
 | } | } | 
 | return(win); | return(win); | 
 | } | } | 
| Line 662  static void createskinmenu(MenuRef ret) | Line 855  static void createskinmenu(MenuRef ret) | 
 | const char      *base; | const char      *base; | 
 | char    *p; | char    *p; | 
 | UINT    i; | UINT    i; | 
 | UINT    j; |  | 
 | UINT    id[SKINMRU_MAX]; |  | 
 | const char      *file[SKINMRU_MAX]; |  | 
 | char        longname[256]; | char        longname[256]; | 
 |  |  | 
 | AppendMenuItemTextWithCFString(ret, CFCopyLocalizedString(CFSTR("Select Skin..."),"Slect Skin"), kMenuItemAttrIconDisabled, NULL,NULL); | AppendMenuItemTextWithCFString(ret, CFCopyLocalizedString(CFSTR("Select Skin..."),"Slect Skin"), kMenuItemAttrIconDisabled, NULL,NULL); | 
 | AppendMenu(ret, "\p-"); | AppendMenu(ret, "\p-"); | 
 |  |  | 
 | base = np2tool.skin; | base = np2tool.skin; | 
| AppendMenuItemTextWithCFString(ret, CFCopyLocalizedString(CFSTR("Base Skin"),"Base Skin"), kMenuItemAttrIconDisabled, NULL,NULL); | AppendMenuItemTextWithCFString(ret, CFCopyLocalizedString(CFSTR("<Base Skin>"),"Base Skin"), kMenuItemAttrIconDisabled, NULL,NULL); | 
 | if (base[0] == '\0') { | if (base[0] == '\0') { | 
| DisableMenuItem(ret, 3); | CheckMenuItem(ret, BASENUMBER-1, true); | 
 | } | } | 
 | for (cnt=0; cnt<SKINMRU_MAX; cnt++) { | for (cnt=0; cnt<SKINMRU_MAX; cnt++) { | 
 | p = np2tool.skinmru[cnt]; | p = np2tool.skinmru[cnt]; | 
 | if (p[0] == '\0') { | if (p[0] == '\0') { | 
 | break; | break; | 
 | } | } | 
| getLongFileName(longname, p); | UInt32  attr = kMenuItemAttrIconDisabled; | 
| p = longname; | if (file_attr(p) != FILEATTR_ARCHIVE) { | 
| for (i=0; i<cnt; i++) { | attr |= kMenuItemAttrDisabled; | 
| if (file_cmpname(p, file[id[i]]) < 0) { | } | 
| break; | ZeroMemory(longname, sizeof(longname)); | 
| } | if (!getLongFileName(longname, p)) { | 
| } | strcpy(longname, file_getname(p)); | 
| for (j=cnt; j>i; j--) { | } | 
| id[j] = id[j-1]; | AppendMenuItemTextWithCFString(ret, CFStringCreateWithCString(NULL, longname, kCFStringEncodingUTF8), attr, NULL, NULL); | 
| } |  | 
| id[i] = cnt; |  | 
| file[cnt] = p; |  | 
 | } | } | 
 | for (i=0; i<cnt; i++) { | for (i=0; i<cnt; i++) { | 
| j = id[i]; | if (!file_cmpname(base, np2tool.skinmru[i])) { | 
| if (file[j][0] != '\0') { | CheckMenuItem(ret, i+BASENUMBER, true); | 
| UInt32      attr = kMenuItemAttrIconDisabled; | break; | 
| if (!file_cmpname(base, np2tool.skinmru[j])) { |  | 
| attr |= kMenuItemAttrDisabled; |  | 
| } |  | 
| else if (file_attr(np2tool.skinmru[j]) == -1) { |  | 
| attr |= kMenuItemAttrDisabled; |  | 
| } |  | 
| AppendMenuItemTextWithCFString(ret, CFStringCreateWithCString(NULL, file[j], kCFStringEncodingUTF8), attr, NULL, NULL); |  | 
 | } | } | 
 | } | } | 
 | return; | return; | 
 | } | } | 
 |  |  | 
| static void skinchange(void) { | static void skinchange(bool remake) { | 
 |  |  | 
 | const char              *p; | const char              *p; | 
 | UINT            i; | UINT            i; | 
 |  |  | 
 | toolwin_close(); | toolwin_close(); | 
 | p = np2tool.skin; | p = np2tool.skin; | 
| if (p[0]) { | if (p[0] && remake) { | 
 | for (i=0; i<(SKINMRU_MAX - 1); i++) { | for (i=0; i<(SKINMRU_MAX - 1); i++) { | 
 | if (!file_cmpname(p, np2tool.skinmru[i])) { | if (!file_cmpname(p, np2tool.skinmru[i])) { | 
 | break; | break; | 
| Line 735  const char  *p; | Line 915  const char  *p; | 
 |  |  | 
 |  |  | 
 | // ---- | // ---- | 
| static void openpopup(HIPoint location) { | static void openpopup(Point location) { | 
 |  |  | 
 | MenuRef hMenu; | MenuRef hMenu; | 
 | short   sel; | short   sel; | 
| Line 747  static void openpopup(HIPoint location) | Line 927  static void openpopup(HIPoint location) | 
 | createskinmenu(hMenu); | createskinmenu(hMenu); | 
 | AppendMenu(hMenu, "\p-"); | AppendMenu(hMenu, "\p-"); | 
 | AppendMenuItemTextWithCFString(hMenu, CFCopyLocalizedString(CFSTR("Close"),"ToolWin Close"), kMenuItemAttrIconDisabled, NULL, NULL); | AppendMenuItemTextWithCFString(hMenu, CFCopyLocalizedString(CFSTR("Close"),"ToolWin Close"), kMenuItemAttrIconDisabled, NULL, NULL); | 
 |  |  | 
 | DeleteMenu(222); | DeleteMenu(222); | 
 | selectclose = CountMenuItems(hMenu); | selectclose = CountMenuItems(hMenu); | 
| sel = LoWord(PopUpMenuSelect(hMenu, (short)location.y, (short)location.x, 0)); | sel = LoWord(PopUpMenuSelect(hMenu, location.v, location.h, 0)); | 
 | DisposeMenu(hMenu); | DisposeMenu(hMenu); | 
 | if (sel == selectclose) { | if (sel == selectclose) { | 
 | toolwin_close(); | toolwin_close(); | 
| Line 758  static void openpopup(HIPoint location) | Line 937  static void openpopup(HIPoint location) | 
 | else { | else { | 
 | switch (sel) { | switch (sel) { | 
 | case 1: | case 1: | 
| if(dialog_fileselect(fname, sizeof(fname), hWndMain)) { | if(dialog_fileselect(fname, sizeof(fname), hWndMain, OPEN_INI)) { | 
| if (file_getftype(fname)==FTYPE_TEXT) { | if (file_getftype(fname)==FTYPE_INI) { | 
 | strcpy(np2tool.skin, fname); | strcpy(np2tool.skin, fname); | 
| skinchange(); | skinchange(true); | 
 | } | } | 
 | } | } | 
 | break; | break; | 
 | case 3: | case 3: | 
| np2tool.skin[0] = '\0'; | if (np2tool.skin[0]) { | 
| skinchange(); | np2tool.skin[0] = '\0'; | 
|  | skinchange(false); | 
|  | } | 
 | break; | break; | 
 | case 4: | case 4: | 
 | case 5: | case 5: | 
 | case 6: | case 6: | 
 | case 7: | case 7: | 
| file_cpyname(np2tool.skin, np2tool.skinmru[sel - 4], sizeof(np2tool.skin)); | if (file_cmpname(np2tool.skin, np2tool.skinmru[sel - BASENUMBER])) { | 
| skinchange(); | file_cpyname(np2tool.skin, np2tool.skinmru[sel - BASENUMBER], sizeof(np2tool.skin)); | 
|  | skinchange(false); | 
|  | } | 
 | break; | break; | 
 | default: | default: | 
 | break; | break; | 
| Line 783  static void openpopup(HIPoint location) | Line 966  static void openpopup(HIPoint location) | 
 |  |  | 
 | } | } | 
 |  |  | 
 |  | static void makeskinimage(WindowRef win,PicHandle bmp, Rect* rect) { | 
 |  | ControlButtonContentInfo    info; | 
 |  | ControlRef                                  image; | 
 |  | EventHandlerRef                             ref; | 
 |  | EventTypeSpec                               list[]={ | 
 |  | { kEventClassControl, kEventControlContextualMenuClick }, | 
 |  | }; | 
 |  |  | 
 |  | info.contentType = kControlContentPictHandle; | 
 |  | info.u.picture = bmp; | 
 |  | CreatePictureControl(win, rect, &info, true, &image); | 
 |  | SetControlID(image, &imageid); | 
 |  | InstallControlEventHandler (image, NewEventHandlerUPP(cfControlproc), GetEventTypeCount(list), list, (void *)win, &ref); | 
 |  | } | 
 |  |  | 
 |  | static void opentoolwin_puma(WindowRef win) { | 
 |  | if (np2tool.posy < 35) np2tool.posy = 35; | 
 |  | if (np2tool.posx < 5 ) np2tool.posx = 5; | 
 |  | MoveWindow(win, np2tool.posx, np2tool.posy, true); | 
 |  | ShowWindow(win); | 
 |  | } | 
 |  |  | 
 | void toolwin_open(void) { | void toolwin_open(void) { | 
 |  |  | 
 | PicHandle       hbmp; | PicHandle       hbmp; | 
 | WindowRef       hWnd = NULL; | WindowRef       hWnd = NULL; | 
 | Rect                bounds; | Rect                bounds; | 
 | ControlRef  image; |  | 
 | EventTypeSpec       list[]={ |  | 
 | { kEventClassControl, kEventControlContextualMenuClick }, |  | 
 | }; |  | 
 | EventHandlerRef     ref; |  | 
 |  |  | 
 | if (toolwin.hwnd) { | if (toolwin.hwnd) { | 
 | toolwin_close(); | toolwin_close(); | 
| Line 813  void toolwin_open(void) { | Line 1013  void toolwin_open(void) { | 
 | goto twope_err2; | goto twope_err2; | 
 | } | } | 
 |  |  | 
| if (isPUMA) { |  | 
|  | SetWindowBounds(hWnd, kWindowContentRgn, &bounds); | 
|  | if (isPUMA) { | 
 | toolwincreate(hWnd); | toolwincreate(hWnd); | 
 |  | makeskinimage(hWnd, hbmp, &bounds); | 
 | } | } | 
| SizeWindow(hWnd, bounds.right-bounds.left, bounds.bottom-bounds.top, true); | else { | 
| ControlButtonContentInfo    info; | makeskinimage(hWnd, hbmp, &bounds); | 
| info.contentType = kControlContentPictHandle; |  | 
| info.u.picture = hbmp; |  | 
| CreatePictureControl(hWnd, &bounds, &info, true, &image); |  | 
| InstallControlEventHandler (image, NewEventHandlerUPP(cfControlproc), GetEventTypeCount(list), list, (void *)hWnd, &ref); |  | 
| if (!isPUMA) { |  | 
 | toolwincreate(hWnd); | toolwincreate(hWnd); | 
 | } | } | 
 | #ifndef AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER | #ifndef AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER | 
| if (np2tool.posy < 35) np2tool.posy = 35; | opentoolwin_puma(hWnd); | 
| if (np2tool.posx < 5 ) np2tool.posx = 5; |  | 
| MoveWindow(hWnd, np2tool.posx, np2tool.posy, true); |  | 
| ShowWindow(hWnd); |  | 
 | #else | #else | 
 | if (isPUMA) { | if (isPUMA) { | 
| if (np2tool.posy < 35) np2tool.posy = 35; | opentoolwin_puma(hWnd); | 
| if (np2tool.posx < 5 ) np2tool.posx = 5; |  | 
| MoveWindow(hWnd, np2tool.posx, np2tool.posy, true); |  | 
| ShowWindow(hWnd); |  | 
 | } | } | 
 | else { | else { | 
 |  | Rect    mainbounds; | 
 |  | int             width; | 
 | SetDrawerParent(hWnd, hWndMain); | SetDrawerParent(hWnd, hWndMain); | 
| SetDrawerOffsets(hWnd, (640-(bounds.right-bounds.left))/2-11, (640-(bounds.right-bounds.left))/2-11); | GetWindowBounds(hWndMain, kWindowContentRgn, &mainbounds); | 
|  | width = (mainbounds.right-mainbounds.left)-(bounds.right-bounds.left); | 
|  | if (width/2-11<0) { | 
|  | toolwin_close(); | 
|  | return; | 
|  | } | 
|  | SetDrawerOffsets(hWnd, width/2-11, width/2-11); | 
 | SetDrawerPreferredEdge(hWnd, kWindowEdgeTop); | SetDrawerPreferredEdge(hWnd, kWindowEdgeTop); | 
 |  | const HISize  size = {bounds.right-bounds.left, bounds.bottom-bounds.top}; | 
 |  | SetWindowResizeLimits(hWnd, &size, &size); | 
 | OpenDrawer(hWnd, kWindowEdgeDefault, 1); | OpenDrawer(hWnd, kWindowEdgeDefault, 1); | 
 | } | } | 
 | #endif | #endif | 
 |  |  | 
 |  | np2oscfg.toolwin = 1; | 
 | return; | return; | 
 |  |  | 
 | twope_err2: | twope_err2: | 
| Line 869  void toolwin_close(void) { | Line 1072  void toolwin_close(void) { | 
 | } | } | 
 | #endif | #endif | 
 | RemoveReceiveHandler(dr, toolwin.hwnd); | RemoveReceiveHandler(dr, toolwin.hwnd); | 
 |  | RemoveTrackingHandler(tr, toolwin.hwnd); | 
 | toolwindestroy(); | toolwindestroy(); | 
 | DisposeWindow(toolwin.hwnd); | DisposeWindow(toolwin.hwnd); | 
 | toolwin.hwnd = NULL; | toolwin.hwnd = NULL; | 
 |  | np2oscfg.toolwin = 0; | 
 | } | } | 
 | } | } | 
 |  |  |