Diff for /np2/macosx/toolwin.cpp between versions 1.10 and 1.15

version 1.10, 2003/11/12 19:06:33 version 1.15, 2004/01/05 01:53:34
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"
   
   
 enum {  enum {
Line 109  static const OSType subcommand[11] ={ '- Line 113  static const OSType subcommand[11] ={ '-
   
 #define BASENUMBER      4  #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 DragTrackingHandlerUPP   tr;
 static bool     isPUMA;  static bool     isPUMA;
   
 static void openpopup(HIPoint location);  static void openpopup(HIPoint location);
Line 168  static PicHandle skinload(const char *pa Line 174  static PicHandle skinload(const char *pa
                         return(ret);                          return(ret);
                 }                  }
         }          }
         return(getBMPfromResource("np2tool", bounds, CFSTR("bmp")));          return(getBMPfromResource("np2tool.bmp", bounds));
 }  }
   
 // ----  // ----
Line 177  static void setlist(ControlRef hwnd, con Line 183  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)) {      while (MenuHasEnabledItems(menu)) {
Line 193  const char *q; Line 202  const char *q;
 #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) && 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 216  const char *q; Line 232  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 343  static pascal OSStatus cfControlproc(Eve Line 362  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 351  const SUBITEM *p; Line 386  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 450  static void toolwindestroy(void) { Line 487  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 525  static pascal OSStatus cfWinproc(EventHa Line 563  static pascal OSStatus cfWinproc(EventHa
                         Draw1Control(sub);                          Draw1Control(sub);
                     }                      }
                 }                  }
                   err=noErr;
                 break;                  break;
                                   
             case kEventWindowFocusAcquired:              case kEventWindowFocusAcquired:
                 SelectWindow(hWndMain);                  BringToFront(hWndMain);
                   err = noErr;
                 break;                  break;
                                   
                                   
Line 536  static pascal OSStatus cfWinproc(EventHa Line 576  static pascal OSStatus cfWinproc(EventHa
                 break;                  break;
         }          }
     }      }
     else if (GetEventClass(event)==kEventClassKeyboard && GetEventKind(event)==kEventRawKeyDown) {      else if (GetEventClass(event)==kEventClassKeyboard) {
           static  UInt32  backup = 0;
           UInt32  whatHappened = GetEventKind(event);
           UInt32 key;
           GetEventParameter (event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &key);
         UInt32 modif;          UInt32 modif;
         GetEventParameter (event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modif);          GetEventParameter (event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modif);
         if (modif & cmdKey) {          switch (whatHappened)
             EventRecord eve;          {
             ConvertEventRefToEventRecord( event,&eve );              case kEventRawKeyUp:
             recieveCommand(MenuEvent(&eve));                  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);
                       recieveCommand(MenuEvent(&eve));
                       mousemng_enable(MOUSEPROC_MACUI);
                   }
                   else {
                       mackbd_keydown(key);
                   }
                   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;             
         }          }
     }      }
   
Line 550  static pascal OSStatus cfWinproc(EventHa Line 628  static pascal OSStatus cfWinproc(EventHa
     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 566  OSErr setDropFile(FSSpec spec, int drv)  Line 650  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(true);              skinchange(true);
             break;              break;
Line 582  OSErr setDropFile(FSSpec spec, int drv)  Line 666  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 600  static pascal OSErr DragReceiver( Window Line 702  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 651  static WindowRef makeNibWindow (IBNibRef Line 817  static WindowRef makeNibWindow (IBNibRef
         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 757  static void openpopup(HIPoint location)  Line 925  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_TEXT) {
                         strcpy(np2tool.skin, fname);                          strcpy(np2tool.skin, fname);
                         skinchange(true);                          skinchange(true);
Line 824  void toolwin_open(void) { Line 992  void toolwin_open(void) {
     info.contentType = kControlContentPictHandle;      info.contentType = kControlContentPictHandle;
     info.u.picture = hbmp;      info.u.picture = hbmp;
     CreatePictureControl(hWnd, &bounds, &info, true, &image);      CreatePictureControl(hWnd, &bounds, &info, true, &image);
       SetControlID(image, &imageid);
     InstallControlEventHandler (image, NewEventHandlerUPP(cfControlproc), GetEventTypeCount(list), list, (void *)hWnd, &ref);      InstallControlEventHandler (image, NewEventHandlerUPP(cfControlproc), GetEventTypeCount(list), list, (void *)hWnd, &ref);
     if (!isPUMA) {      if (!isPUMA) {
         toolwincreate(hWnd);          toolwincreate(hWnd);
Line 881  void toolwin_close(void) { Line 1050  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;

Removed from v.1.10  
changed lines
  Added in v.1.15


RetroPC.NET-CVS <cvs@retropc.net>