Diff for /np2/macosx/toolwin.cpp between versions 1.1 and 1.9

version 1.1, 2003/11/03 10:19:43 version 1.9, 2003/11/11 16:33:50
Line 5 Line 5
 #include        "dosio.h"  #include        "dosio.h"
 #include        "ini.h"  #include        "ini.h"
 #include        "resource.h"  #include        "resource.h"
 #include        "toolmac.h"  #include        "toolwin.h"
 #include        "np2opening.h"  #include        "np2opening.h"
 #include        "dialogutils.h"  #include        "dialogutils.h"
 #include        "dialog.h"  #include        "dialog.h"
 #include        "soundmng.h"  #include        "soundmng.h"
 #include        "fdefine.h"  #include        "fdefine.h"
   
   
 enum {  enum {
         IDC_TOOLHDDACC                  = 0,          IDC_TOOLHDDACC                  = 0,
         IDC_TOOLFDD1ACC,          IDC_TOOLFDD1ACC,
Line 108  static const OSType subcommand[11] ={ '- Line 109  static const OSType subcommand[11] ={ '-
   
 static const ControlID popup[2] = { {'pop1', 1}, {'pop2', 2} };  static const ControlID popup[2] = { {'pop1', 1}, {'pop2', 2} };
   
   static DragReceiveHandlerUPP    dr;
   static bool     isPUMA;
   
 static void openpopup(HIPoint location);  static void openpopup(HIPoint location);
 static void skinchange(void);  static void skinchange(void);
 static DragReceiveHandlerUPP    dr;  
   
 // ----  // ----
   
   static void checkOSVersion(void) {
       long        res;
       Gestalt(gestaltSystemVersion, &res);
       if (res<0x1020) {
           isPUMA = true;
       }
       else {
           isPUMA = false;
       }
   }
   
   
 static PicHandle skinload(const char *path, Rect* bounds) {  static PicHandle skinload(const char *path, Rect* bounds) {
   
         char            fname[MAX_PATH];          char            fname[MAX_PATH];
Line 150  static PicHandle skinload(const char *pa Line 165  static PicHandle skinload(const char *pa
                         return(ret);                          return(ret);
                 }                  }
         }          }
         return(getBMPfromResource("np2tool", bounds));          return(getBMPfromResource("np2tool", bounds, CFSTR("bmp")));
 }  }
   
 // ----  // ----
Line 441  static void toolwindestroy(void) { Line 456  static void toolwindestroy(void) {
 static pascal OSStatus cfWinproc(EventHandlerCallRef myHandler, EventRef event, void* userData) {  static pascal OSStatus cfWinproc(EventHandlerCallRef myHandler, EventRef event, void* userData) {
     OSStatus    err = eventNotHandledErr;      OSStatus    err = eventNotHandledErr;
     HICommand   cmd;      HICommand   cmd;
       ControlRef  sub;
       int                 i;
   
     if (GetEventClass(event)==kEventClassCommand && GetEventKind(event)==kEventCommandProcess ) {      if (GetEventClass(event)==kEventClassCommand && GetEventKind(event)==kEventCommandProcess ) {
         GetEventParameter(event, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &cmd);          GetEventParameter(event, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &cmd);
Line 497  static pascal OSStatus cfWinproc(EventHa Line 514  static pascal OSStatus cfWinproc(EventHa
                 err=noErr;                  err=noErr;
                 break;                  break;
                                   
               case kEventWindowDrawContent:
               case kEventWindowShown:
                   for (i=0; i<IDC_MAXITEMS; i++) {
                       sub = toolwin.sub[i];
                       if (sub) {
                           Draw1Control(sub);
                       }
                   }
                   break;
                   
               case kEventWindowFocusAcquired:
                   SelectWindow(hWndMain);
                   break;
                   
                   
             default:              default:
                 break;                  break;
         }          }
     }      }
       else if (GetEventClass(event)==kEventClassKeyboard && GetEventKind(event)==kEventRawKeyDown) {
           UInt32 modif;
           GetEventParameter (event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modif);
           if (modif & cmdKey) {
               EventRecord eve;
               ConvertEventRefToEventRecord( event,&eve );
               recieveCommand(MenuEvent(&eve));
           }
       }
   
         (void)myHandler;          (void)myHandler;
     return err;      return err;
Line 557  static pascal OSErr DragReceiver( Window Line 598  static pascal OSErr DragReceiver( Window
         }          }
     }      }
   
         // アイテムは1つだけか?  
         UInt16 numItems;          UInt16 numItems;
     CountDragItems( theDrag, &numItems );      CountDragItems( theDrag, &numItems );
         if ( numItems != 1 )          if ( numItems != 1 )
         {                                                       // 複数ある          {
                 return( -1 );                   // 取り扱わない                  return( -1 );
         }      }
   
         // アイテムリファレンスを取り出す  
         DragItemRef ItemRef;          DragItemRef ItemRef;
         GetDragItemReferenceNumber( theDrag, 1, &ItemRef );          GetDragItemReferenceNumber( theDrag, 1, &ItemRef );
           
         // フレーバタイプを調べる  
         FlavorType Type;          FlavorType Type;
         GetFlavorType( theDrag, ItemRef, 1, &Type );          GetFlavorType( theDrag, ItemRef, 1, &Type );
         // ファイルか?  
         if ( Type != flavorTypeHFS )          if ( Type != flavorTypeHFS )
         {                                                       // ファイルではない          {
                 return( -1 );                   // 取り扱わない          return( -1 );
         }      }
   
         // FSSpecを得る  
         HFSFlavor aHFSFlavor;          HFSFlavor aHFSFlavor;
         Size dataSize = sizeof(aHFSFlavor);          Size dataSize = sizeof(aHFSFlavor);
         GetFlavorData( theDrag, ItemRef, flavorTypeHFS, &aHFSFlavor, &dataSize, 0 );          GetFlavorData( theDrag, ItemRef, flavorTypeHFS, &aHFSFlavor, &dataSize, 0 );
Line 589  static pascal OSErr DragReceiver( Window Line 625  static pascal OSErr DragReceiver( Window
 static WindowRef makeNibWindow (IBNibRef nibRef) {  static WindowRef makeNibWindow (IBNibRef nibRef) {
     OSStatus    err;      OSStatus    err;
     WindowRef   win = NULL;      WindowRef   win = NULL;
 #if 0  
     Rect        bounds;      if (isPUMA) {
     SetRect(&bounds, 0, 0, 100, 100);          Rect    bounds;
     err = CreateNewWindow(kOverlayWindowClass, kWindowStandardHandlerAttribute, &bounds, &win);          SetRect(&bounds, 0, 0, 100, 100);
 #else          err = CreateNewWindow(kFloatingWindowClass, kWindowStandardHandlerAttribute, &bounds, &win);
     err = CreateWindowFromNib(nibRef, CFSTR("ToolWindow"), &win);      }
 #endif      else {
           err = CreateWindowFromNib(nibRef, CFSTR("ToolWindow"), &win);
       }
     if (err == noErr) {      if (err == noErr) {
           InstallStandardEventHandler(GetWindowEventTarget(win));
         EventTypeSpec   list[]={           EventTypeSpec   list[]={ 
             { kEventClassCommand, kEventCommandProcess },              { kEventClassCommand,       kEventCommandProcess },
             { kEventClassWindow, kEventWindowClose },               { kEventClassWindow,        kEventWindowClose }, 
               { kEventClassWindow,        kEventWindowShown }, 
               { kEventClassWindow,        kEventWindowDrawContent }, 
               { kEventClassWindow,        kEventWindowFocusAcquired }, 
               { kEventClassKeyboard,      kEventRawKeyDown},
         };          };
         EventHandlerRef ref;          EventHandlerRef ref;
         InstallWindowEventHandler (win, NewEventHandlerUPP(cfWinproc), GetEventTypeCount(list), list, (void *)win, &ref);          InstallWindowEventHandler (win, NewEventHandlerUPP(cfWinproc), GetEventTypeCount(list), list, (void *)win, &ref);
Line 632  const char *base; Line 675  const char *base;
         UINT    j;          UINT    j;
         UINT    id[SKINMRU_MAX];          UINT    id[SKINMRU_MAX];
 const char      *file[SKINMRU_MAX];  const char      *file[SKINMRU_MAX];
     Str255      seltext, deftext;      char        longname[256];
   
     mkstr255(seltext, str_skinsel);          AppendMenuItemTextWithCFString(ret, CFCopyLocalizedString(CFSTR("Select Skin..."),"Slect Skin"), kMenuItemAttrIconDisabled, NULL,NULL);
         AppendMenu(ret, seltext);  
         AppendMenu(ret, "\p-");          AppendMenu(ret, "\p-");
   
         base = np2tool.skin;          base = np2tool.skin;
     mkstr255(deftext, str_skindef);          AppendMenuItemTextWithCFString(ret, CFCopyLocalizedString(CFSTR("<Base Skin>"),"Base Skin"), kMenuItemAttrIconDisabled, NULL,NULL);
         AppendMenu(ret, deftext);          if (base[0] == '\0') {
         if (base[0] != '\0') {          DisableMenuItem(ret, 3);
         EnableMenuItem(ret, 3);  
     }      }
         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;
                 }                  }
                 p = file_getname(p);                  getLongFileName(longname, p);
           p = longname;
                 for (i=0; i<cnt; i++) {                  for (i=0; i<cnt; i++) {
                         if (file_cmpname(p, file[id[i]]) < 0) {                          if (file_cmpname(p, file[id[i]]) < 0) {
                                 break;                                  break;
Line 663  const char *file[SKINMRU_MAX]; Line 705  const char *file[SKINMRU_MAX];
         }          }
         for (i=0; i<cnt; i++) {          for (i=0; i<cnt; i++) {
                 j = id[i];                  j = id[i];
         if (file[j][0] == '\0') {          if (file[j][0] != '\0') {
             AppendMenu(ret, "\pN/A");              UInt32      attr = kMenuItemAttrIconDisabled;
         }              if (!file_cmpname(base, np2tool.skinmru[j])) {
         else {                  attr |= kMenuItemAttrDisabled;
             Str255      initext;              }
             mkstr255(initext, file[j]);              else if (file_attr(np2tool.skinmru[j]) == -1) {
             AppendMenu(ret, initext);                  attr |= kMenuItemAttrDisabled;
         }              }
         if (!file_cmpname(base, np2tool.skinmru[j])) {              AppendMenuItemTextWithCFString(ret, CFStringCreateWithCString(NULL, file[j], kCFStringEncodingUTF8), attr, NULL, NULL);
             EnableMenuItem(ret, 4+i);  
         }          }
         }          }
         return;          return;
Line 708  static void openpopup(HIPoint location)  Line 749  static void openpopup(HIPoint location) 
   
         MenuRef hMenu;          MenuRef hMenu;
         short   sel;          short   sel;
     Str255      closetext;  
     UInt16      selectclose;      UInt16      selectclose;
     char        fname[MAX_PATH];      char        fname[MAX_PATH];
   
     hMenu = NewMenu(222, "\pskin");      hMenu = NewMenu(222, "\pSkin");
     InsertMenu(hMenu, -1);      InsertMenu(hMenu, -1);
         createskinmenu(hMenu);          createskinmenu(hMenu);
         AppendMenu(hMenu, "\p-");          AppendMenu(hMenu, "\p-");
     mkstr255(closetext, str_toolclose);      AppendMenuItemTextWithCFString(hMenu, CFCopyLocalizedString(CFSTR("Close"),"ToolWin Close"), kMenuItemAttrIconDisabled, NULL, NULL);
         AppendMenu(hMenu, closetext);  
   
     DeleteMenu(222);      DeleteMenu(222);
     selectclose = CountMenuItems(hMenu);      selectclose = CountMenuItems(hMenu);
Line 769  void toolwin_open(void) { Line 808  void toolwin_open(void) {
         toolwin_close();          toolwin_close();
                 return;                  return;
         }          }
       
       checkOSVersion();
         ZeroMemory(&toolwin, sizeof(toolwin));          ZeroMemory(&toolwin, sizeof(toolwin));
   
         hbmp = skinload(np2tool.skin, &bounds);          hbmp = skinload(np2tool.skin, &bounds);
Line 782  void toolwin_open(void) { Line 823  void toolwin_open(void) {
                 goto twope_err2;                  goto twope_err2;
         }          }
           
       if (isPUMA) {
           toolwincreate(hWnd);
       }
     SizeWindow(hWnd, bounds.right-bounds.left, bounds.bottom-bounds.top, true);      SizeWindow(hWnd, bounds.right-bounds.left, bounds.bottom-bounds.top, true);
     ControlButtonContentInfo    info;      ControlButtonContentInfo    info;
     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);
     InstallControlEventHandler (image, NewEventHandlerUPP(cfControlproc), GetEventTypeCount(list), list, (void *)hWnd, &ref);      InstallControlEventHandler (image, NewEventHandlerUPP(cfControlproc), GetEventTypeCount(list), list, (void *)hWnd, &ref);
       if (!isPUMA) {
     toolwincreate(hWnd);          toolwincreate(hWnd);
       }
 #if 0  #ifndef AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER
     if (np2tool.posy < 30) np2tool.posy = 30;      if (np2tool.posy < 35) np2tool.posy = 35;
     if (np2tool.posx < 5 ) np2tool.posx = 5;      if (np2tool.posx < 5 ) np2tool.posx = 5;
     MoveWindow(hWnd, np2tool.posx, np2tool.posy, true);      MoveWindow(hWnd, np2tool.posx, np2tool.posy, true);
     ShowWindow(hWnd);      ShowWindow(hWnd);
 #else  #else
     SetDrawerParent(hWnd, hWndMain);      if (isPUMA) {
     SetDrawerOffsets(hWnd, (640-(bounds.right-bounds.left))/2-11, (640-(bounds.right-bounds.left))/2-11);          if (np2tool.posy < 35) np2tool.posy = 35;
     SetDrawerPreferredEdge(hWnd, kWindowEdgeTop);          if (np2tool.posx < 5 ) np2tool.posx = 5;
     OpenDrawer(hWnd, kWindowEdgeDefault, 1);          MoveWindow(hWnd, np2tool.posx, np2tool.posy, true);
           ShowWindow(hWnd);
       }
       else {
           SetDrawerParent(hWnd, hWndMain);
           SetDrawerOffsets(hWnd, (640-(bounds.right-bounds.left))/2-11, (640-(bounds.right-bounds.left))/2-11);
           SetDrawerPreferredEdge(hWnd, kWindowEdgeTop);
           OpenDrawer(hWnd, kWindowEdgeDefault, 1);
       }
 #endif  #endif
   
       np2oscfg.toolwin = 1;
         return;          return;
   
 twope_err2:  twope_err2:
Line 816  twope_err1: Line 869  twope_err1:
 void toolwin_close(void) {  void toolwin_close(void) {
   
     if (toolwin.hwnd) {      if (toolwin.hwnd) {
         CloseDrawer(toolwin.hwnd, 0);  #ifndef AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER
           HideWindow(toolwin.hwnd);
   #else
           if (isPUMA) {
               HideWindow(toolwin.hwnd);
           }
           else {
               CloseDrawer(toolwin.hwnd, 0);
           }
   #endif
         RemoveReceiveHandler(dr, toolwin.hwnd);          RemoveReceiveHandler(dr, toolwin.hwnd);
         toolwindestroy();          toolwindestroy();
         DisposeWindow(toolwin.hwnd);          DisposeWindow(toolwin.hwnd);
         toolwin.hwnd = NULL;          toolwin.hwnd = NULL;
           np2oscfg.toolwin = 0;
     }      }
 }  }
   
Line 937  const DISKACC *accterm; Line 1000  const DISKACC *accterm;
 // ----  // ----
   
 static const char ini_title[] = "NP2 tool";  static const char ini_title[] = "NP2 tool";
   static const char inifile[] = "np2.cfg";                        // same file name..
   
 static const INITBL iniitem[] = {  static const INITBL iniitem[] = {
         {"WindposX", INITYPE_SINT32,    &np2tool.posx,                  0},          {"WindposX", INITYPE_SINT32,    &np2tool.posx,                  0},
Line 964  static const INITBL iniitem[] = { Line 1028  static const INITBL iniitem[] = {
         {"FD2NAME7", INITYPE_STR,               np2tool.fdd[1].name[7], MAX_PATH}};          {"FD2NAME7", INITYPE_STR,               np2tool.fdd[1].name[7], MAX_PATH}};
   
   
 void initgetfile(char *path, UINT size) {  
   
         file_cpyname(path, file_getcd("np2"), size);  
     file_catname(path, ".ini", size);  
 }  
   
 void toolwin_readini(void) {  void toolwin_readini(void) {
   
         char    path[MAX_PATH];          char    path[MAX_PATH];
Line 977  void toolwin_readini(void) { Line 1035  void toolwin_readini(void) {
         ZeroMemory(&np2tool, sizeof(np2tool));          ZeroMemory(&np2tool, sizeof(np2tool));
         np2tool.posx = 0;          np2tool.posx = 0;
         np2tool.posy = 0;          np2tool.posy = 0;
         initgetfile(path, sizeof(path));          file_cpyname(path, file_getcd(inifile), sizeof(path));
         ini_read(path, ini_title, iniitem, sizeof(iniitem)/sizeof(INITBL));          ini_read(path, ini_title, iniitem, sizeof(iniitem)/sizeof(INITBL));
 }  }
   
Line 985  void toolwin_writeini(void) { Line 1043  void toolwin_writeini(void) {
   
         char    path[MAX_PATH];          char    path[MAX_PATH];
   
         initgetfile(path, sizeof(path));          file_cpyname(path, file_getcd(inifile), sizeof(path));
         ini_write(path, ini_title, iniitem, sizeof(iniitem)/sizeof(INITBL));          ini_write(path, ini_title, iniitem, sizeof(iniitem)/sizeof(INITBL), FALSE);
 }  }
   

Removed from v.1.1  
changed lines
  Added in v.1.9


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