Diff for /np2/macosx/dialog/macnewdisk.cpp between versions 1.1 and 1.7

version 1.1, 2003/10/31 16:55:06 version 1.7, 2004/02/25 17:16:31
Line 4 Line 4
 #include        "np2.h"  #include        "np2.h"
 #include        "newdisk.h"  #include        "newdisk.h"
 #include        "dialog.h"  #include        "dialog.h"
   #include        "dialogutils.h"
 #include        "macnewdisk.h"  #include        "macnewdisk.h"
   
 Boolean saveFile(OSType type, char *title, FSSpec *fsc);  static  WindowRef       diskWin;
   static  SInt32  targetDisk, media, hdsize, hddtype;
 #if 0  static  char    disklabel[256];
 static BYTE hdddiskboot[] = {  enum {kTabMasterSig = 'ScrT',kTabMasterID = 1000,kTabPaneSig= 'ScTb'};
                         0xb8,0x00,0x10,0xbb,0x00,0x80,0x8e,0xd0,0x8b,0xe3,0x8c,0xc8,  #define kMaxNumTabs 4
                         0x8e,0xd8,0xb8,0x00,0xa0,0x8e,0xc0,0xb9,0x00,0x10,0xb8,0x20,  static UInt16           lastPaneSelected = 1;
                         0x00,0x33,0xff,0xfc,0xf3,0xab,0xb0,0xe1,0xb9,0xe0,0x1f,0xaa,  #define getControlValue(a,b)            GetControl32BitValue(getControlRefByID(a,b,diskWin))
                         0x47,0xe2,0xfc,0xbe,0x44,0x00,0x33,0xff,0xe8,0x08,0x00,0xbf,  
                         0xa0,0x00,0xe8,0x02,0x00,0xeb,0xfe,0x2e,0xad,0x85,0xc0,0x74,  const int defaultsize[5] = {20, 41, 65, 80, 128};
                         0x06,0xab,0x83,0xc7,0x02,0xeb,0xf4,0xc3,0x04,0x33,0x04,0x4e,  const EventTypeSpec     tabControlEvents[] ={ { kEventClassControl, kEventControlHit }};
                         0x05,0x4f,0x01,0x3c,0x05,0x49,0x05,0x47,0x05,0x23,0x05,0x39,  const EventTypeSpec     hicommandEvents[]={ { kEventClassCommand, kEventCommandProcess },};
                         0x05,0x2f,0x05,0x24,0x05,0x61,0x01,0x3c,0x05,0x38,0x04,0x4f,  
                         0x05,0x55,0x05,0x29,0x01,0x3c,0x05,0x5e,0x05,0x43,0x05,0x48,  
                         0x04,0x35,0x04,0x6c,0x04,0x46,0x04,0x24,0x04,0x5e,0x04,0x3b,  static pascal OSStatus cfWinproc(EventHandlerCallRef myHandler, EventRef event, void* userData) {
                         0x04,0x73,0x01,0x25,0x00,0x00,0x05,0x47,0x05,0x23,0x05,0x39,      OSStatus    err = eventNotHandledErr;
                         0x05,0x2f,0x05,0x24,0x05,0x61,0x01,0x3c,0x05,0x38,0x04,0x72,      HICommand   cmd;
                         0x21,0x5e,0x26,0x7e,0x18,0x65,0x01,0x24,0x05,0x6a,0x05,0x3b,          SINT32          data;
                         0x05,0x43,0x05,0x48,0x04,0x37,0x04,0x46,0x12,0x3c,0x04,0x35,      char                outstr[16];
                         0x04,0x24,0x01,0x25,0x00,0x00};  
 #endif      if (GetEventClass(event)==kEventClassCommand && GetEventKind(event)==kEventCommandProcess ) {
           GetEventParameter(event, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &cmd);
 static Handle GetDlgItem(DialogPtr hWnd, short pos) {          switch (cmd.commandID)
           {
         Handle  ret;              case 'hds2':
         Rect    rct;                  data = getControlValue('hdsz', 3)-1;
         short   s;                  sprintf(outstr, "%d", defaultsize[data]);
                   SetControlData(getControlRefByID('hdsz',2,diskWin),kControlNoPart,kControlStaticTextTextTag,strlen(outstr),outstr);
         GetDialogItem(hWnd, pos, &s, &ret, &rct);                  Draw1Control(getControlRefByID('hdsz',2,diskWin));
         return(ret);                  break;
 }                                 
               case 'hds4':
 static void macos_setradiobtn(ControlHandle *hRadio, int items, int pos) {                  data = getControlValue('hdsz', 5)-1;
                   sprintf(outstr, "%d", defaultsize[data]);
         int             i;                  SetControlData(getControlRefByID('hdsz',4,diskWin),kControlNoPart,kControlStaticTextTextTag,strlen(outstr),outstr);
                   Draw1Control(getControlRefByID('hdsz',4,diskWin));
                   break;
   
               case kHICommandOK:
                   targetDisk = getControlValue(kTabMasterSig, kTabMasterID);
                   getFieldText(getControlRefByID('fdlb', 0, diskWin), disklabel);
                   media = getControlValue('fdty', 0);
                                   if (targetDisk==2 || targetDisk==4) {
                                           data = getFieldValue(getControlRefByID('hdsz', targetDisk, diskWin));
                                           if (data < 0) {
                                                   data = 0;
                                           }
                                           else if (data > 512) {
                                                   data = 512;
                                           }
                                           hdsize = data;
                                   }
                                   else if (targetDisk==3) {
                                           hdsize = getControlValue('hdsz', 20)-1;
                                   }
                   QuitAppModalLoopForWindow(diskWin);
                   err=noErr;
                   break;
                  
               case kHICommandCancel:
                   QuitAppModalLoopForWindow(diskWin);
                   err=noErr;
                   break;
                  
               default:
                   break;
           }
       }
   
         for (i=0; i<items; i++) {          (void)myHandler;
                 SetControlValue(hRadio[i], ((i==pos)?1:0));          (void)userData;
         }      return err;
 }  }
   
   static pascal OSStatus PrefsTabEventHandlerProc( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData )
 // とりあえずモーダルで  {
 void newdisk(void) {      WindowRef   theWindow = (WindowRef)inUserData;  // get the windowRef, passed around as userData    
       short               ret;
         DialogPtr                       hDlg;      ControlRef  focus = NULL;
         int                                     done;  
         short                           item;      ret = changeTab(theWindow, lastPaneSelected);
         Str255                          disklabel;      if (ret) {
         ControlHandle           hmedia[2];          if (ret == 1) {
         int                                     media;              focus = getControlRefByID('fdlb', 0, theWindow);
   
     OSType      type='.D88';  
     FSSpec      fss;  
     char        fileName[] = "Newdisk.d88";  
      
         char    fname[MAX_PATH];  
     char        label[255];  
   
         hDlg = GetNewDialog(IDD_NEWDISK, NULL, (WindowPtr)-1);  
         if (!hDlg) {  
                 return;  
         }  
   
         // テキスト〜  
         SelectDialogItemText(hDlg, IDC_DISKLABEL, 0x0000, 0x7fff);  
   
         // チェックボックスのハンドル  
         hmedia[0] = (ControlHandle)GetDlgItem(hDlg, IDC_MAKE2DD);  
         hmedia[1] = (ControlHandle)GetDlgItem(hDlg, IDC_MAKE2HD);  
         media = 1;  
         macos_setradiobtn(hmedia, 2, 1);  
         SetDialogDefaultItem(hDlg, IDOK);  
         SetDialogCancelItem(hDlg, IDCANCEL);  
   
         done = 0;  
         while(!done) {  
                 ModalDialog(NULL, &item);  
                 switch(item) {  
                         case IDOK:  
                                 done = 1;  
                                 break;  
                         case IDCANCEL:  
                                 done = -1;  
                                 break;  
                         case IDC_DISKLABEL:  
                                 break;  
                         case IDC_MAKE2DD:  
                                 media = 0;  
                                 macos_setradiobtn(hmedia, 2, 0);  
                                 break;  
                         case IDC_MAKE2HD:  
                                 media = 1;  
                                 macos_setradiobtn(hmedia, 2, 1);  
                                 break;  
                 }  
         }  
         if (done > 0) {  
                 GetDialogItemText(GetDlgItem(hDlg, IDC_DISKLABEL), disklabel);  
         }  
         DisposeDialog(hDlg);  
   
         if (done > 0) {                                                         // making  
   
         if (saveFile(type, fileName, &fss)) {  
             fsspec2path(&fss, fname, sizeof(fname));  
             mkcstr(label, sizeof(label), disklabel);  
             newdisk_fdd(fname, media, label);  
         }          }
         }          else if (ret == 2 || ret == 4) {
               focus = getControlRefByID('hdsz', ret, theWindow);
           }
           SetKeyboardFocus(theWindow, focus, kControlFocusNextPart);
           lastPaneSelected = ret;
       }
       return( eventNotHandledErr );
 }  }
   
 #if 0  static void makeNibWindow (IBNibRef nibRef) {
 static BOOL gethddsize(Str255 str, int *size) {      OSStatus    err;
       EventHandlerRef     ref;
         int             hddsize;     
         BYTE    *p;      err = CreateWindowFromNib(nibRef, CFSTR("NewDiskDialog"), &diskWin);
         BYTE    c;      if (err == noErr) {
         UInt32  remain;          SetInitialTabState(diskWin, lastPaneSelected, kMaxNumTabs);
          
         p = (BYTE *)str;          InstallControlEventHandler( getControlRefByID(kTabMasterSig,kTabMasterID,diskWin),  PrefsTabEventHandlerProc , GetEventTypeCount(tabControlEvents), tabControlEvents, diskWin, NULL );
         remain = *p++;          InstallWindowEventHandler (diskWin, NewEventHandlerUPP(cfWinproc), GetEventTypeCount(hicommandEvents), hicommandEvents, (void *)diskWin, &ref);
         while((remain) && (*p == ' ')) {  
                 remain--;          ShowWindow(diskWin);
                 p++;          RunAppModalLoopForWindow(diskWin);
         }      }
         hddsize = 0;      return;
         while(remain--) {  }
                 c = *p++;  
                 if ((c < '0') || (c > '9')) {  static SInt32 initNewDisk( void ) {
                         break;      OSStatus    err;
                 }      IBNibRef    nibRef;
                 hddsize *= 10;  
                 hddsize += (c - '0');      err = CreateNibReference(CFSTR("np2"), &nibRef);
         }      if (err ==noErr ) {
         if (hddsize < 5) {          makeNibWindow (nibRef);
                 *size = 5;          DisposeNibReference ( nibRef);
                 return(FAILURE);      }
         }      return(err);
         else if (hddsize > 256) {  
                 *size = 256;  
                 return(FAILURE);  
         }  
         *size = hddsize;  
         return(SUCCESS);  
 }  }
   
   
 // とりあえずモーダルで  // とりあえずモーダルで
 void newhdddisk(void) {  void newdisk(void) {
   
         DialogPtr                       hDlg;  
         int                                     done;  
         short                           item;  
         Str255                          sizestr;  
         int                                     size;  
   
     OSType      type='.THD';  
     FSSpec      fss;      FSSpec      fss;
     char        fileName[] = "Newdisk.thd";  
     char        fname[MAX_PATH];      char        fname[MAX_PATH];
   
         hDlg = GetNewDialog(IDD_NEWHDDDISK, NULL, (WindowPtr)-1);      initNewDisk();
         if (!hDlg) {     
                 return;          if (targetDisk == 1) {
         }          if (dialog_filewriteselect('.D88', "Newdisk.d88", &fss, diskWin)) {
         SelectDialogItemText(hDlg, IDC_HDDSIZE, 0x0000, 0x7fff);  
   
         SetDialogDefaultItem(hDlg, IDOK);  
         SetDialogCancelItem(hDlg, IDCANCEL);  
   
         done = 0;  
         size = 41;  
         while(!done) {  
                 ModalDialog(NULL, &item);  
                 switch(item) {  
                         case IDOK:  
                                 GetDialogItemText(GetDlgItem(hDlg, IDC_HDDSIZE), sizestr);  
                                 if (gethddsize(sizestr, &size)) {  
                                         ZeroMemory(sizestr, sizeof(sizestr));  
                                         sprintf(((char *)sizestr) + 1, "%d", size);  
                                         sizestr[0] = (BYTE)strlen(((char *)sizestr) + 1);  
                                         SetDialogItemText(GetDlgItem(hDlg, IDC_HDDSIZE), sizestr);  
                                         break;  
                                 }  
                                 done = 1;  
                                 break;  
                         case IDCANCEL:  
                                 done = -1;  
                                 break;  
                 }  
         }  
         DisposeDialog(hDlg);  
         if (done > 0) {                                                         // making  
   
         if (saveFile(type, fileName, &fss)) {  
             fsspec2path(&fss, fname, sizeof(fname));              fsspec2path(&fss, fname, sizeof(fname));
             newdisk_hdd(fname, size);              newdisk_fdd(fname, media << 4, disklabel);
         }          }
         }          }
 }      else if (targetDisk == 2) {
 #endif          if (dialog_filewriteselect('.THD', "Newdisk.thd", &fss, diskWin)) {
               fsspec2path(&fss, fname, sizeof(fname));
 static pascal void navEventProc( NavEventCallbackMessage sel,NavCBRecPtr parm,NavCallBackUserData ud )              newdisk_thd(fname, hdsize);
 {          }
         switch( sel )      }
         {      else if (targetDisk == 3) {
                 case kNavCBEvent:          if (dialog_filewriteselect('.HDI', "Newdisk.hdi", &fss, diskWin)) {
                 {              fsspec2path(&fss, fname, sizeof(fname));
                         switch( parm->eventData.eventDataParms.event->what )              newdisk_hdi(fname, hddtype);
                         {          }
                         }      }
                         break;      else if (targetDisk == 4) {
                 }          if (dialog_filewriteselect('.HDD', "Newdisk.hdd", &fss, diskWin)) {
         }              fsspec2path(&fss, fname, sizeof(fname));
 }              newdisk_vhd(fname, hdsize);
   
 Boolean saveFile(OSType type, char *title, FSSpec *fsc)  
 {        
         OSType                          sign='SMil';  
         NavEventUPP                     eventUPP;  
         NavReplyRecord          reply;  
         DescType                        rtype;  
         short                           ret;  
         AEKeyword                       key;  
         Size                            len;  
         NavDialogOptions        opt;  
                  
         InitCursor();  
         NavGetDefaultDialogOptions( &opt );  
     mkstr255(opt.savedFileName, title);  
         opt.dialogOptionFlags+=kNavNoTypePopup;  
          
         eventUPP=NewNavEventUPP( navEventProc );  
         ret=NavPutFile( NULL,&reply,&opt,eventUPP,type,sign,NULL );  
         DisposeNavEventUPP( eventUPP );  
   
         if( reply.validRecord && ret==0 )  
         {  
                 ret=AEGetNthPtr( &(reply.selection),1,typeFSS,&key,&rtype,(Ptr)fsc,(long)sizeof(FSSpec),&len );  
                 NavDisposeReply( &reply );  
         }  
         if (ret == noErr) {  
             return true;  
         }          }
         return( false );      }
       HideWindow(diskWin);
       DisposeWindow(diskWin);
 }  }

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


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