| version 1.2, 2003/11/06 18:27:59 | version 1.5, 2004/01/23 17:37:39 | 
| Line 7 | Line 7 | 
 | #include        "dialogutils.h" | #include        "dialogutils.h" | 
 | #include        "macnewdisk.h" | #include        "macnewdisk.h" | 
 |  |  | 
 | const int defaultsize[5] = {20, 41, 65, 80, 128}; |  | 
 | static  WindowRef       diskWin; | static  WindowRef       diskWin; | 
| static  SInt32  targetDisk, media, hdsize; | static  SInt32  targetDisk, media, hdsize, hddtype; | 
 | static  char    disklabel[256]; | static  char    disklabel[256]; | 
 | enum {kTabMasterSig = 'ScrT',kTabMasterID = 1000,kTabPaneSig= 'ScTb'}; | enum {kTabMasterSig = 'ScrT',kTabMasterID = 1000,kTabPaneSig= 'ScTb'}; | 
| #define kMaxNumTabs 2 | #define kMaxNumTabs 4 | 
 | static UInt16           lastPaneSelected = 1; | static UInt16           lastPaneSelected = 1; | 
 | #define getControlValue(a,b)            GetControl32BitValue(getControlRefByID(a,b,diskWin)) | #define getControlValue(a,b)            GetControl32BitValue(getControlRefByID(a,b,diskWin)) | 
 |  |  | 
 |  | const int defaultsize[5] = {20, 41, 65, 80, 128}; | 
 |  | const EventTypeSpec     tabControlEvents[] ={ { kEventClassControl, kEventControlHit }}; | 
 |  | const EventTypeSpec     hicommandEvents[]={ { kEventClassCommand, kEventCommandProcess },}; | 
 |  |  | 
 |  |  | 
 | 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; | 
| Line 26  static pascal OSStatus cfWinproc(EventHa | Line 30  static pascal OSStatus cfWinproc(EventHa | 
 | GetEventParameter(event, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &cmd); | GetEventParameter(event, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &cmd); | 
 | switch (cmd.commandID) | switch (cmd.commandID) | 
 | { | { | 
| case 'hdsz': | case 'hds2': | 
| data = getControlValue(cmd.commandID,1)-1; | data = getControlValue('hdsz', 3)-1; | 
 | sprintf(outstr, "%d", defaultsize[data]); | sprintf(outstr, "%d", defaultsize[data]); | 
| SetControlData(getControlRefByID(cmd.commandID,0,diskWin),kControlNoPart,kControlStaticTextTextTag,strlen(outstr),outstr); | SetControlData(getControlRefByID('hdsz',2,diskWin),kControlNoPart,kControlStaticTextTextTag,strlen(outstr),outstr); | 
| Draw1Control(getControlRefByID(cmd.commandID,0,diskWin)); | Draw1Control(getControlRefByID('hdsz',2,diskWin)); | 
|  | break; | 
|  |  | 
|  | case 'hds4': | 
|  | data = getControlValue('hdsz', 5)-1; | 
|  | sprintf(outstr, "%d", defaultsize[data]); | 
|  | SetControlData(getControlRefByID('hdsz',4,diskWin),kControlNoPart,kControlStaticTextTextTag,strlen(outstr),outstr); | 
|  | Draw1Control(getControlRefByID('hdsz',4,diskWin)); | 
 | break; | break; | 
 |  |  | 
 | case kHICommandOK: | case kHICommandOK: | 
 | targetDisk = getControlValue(kTabMasterSig, kTabMasterID); | targetDisk = getControlValue(kTabMasterSig, kTabMasterID); | 
 | getFieldText(getControlRefByID('fdlb', 0, diskWin), disklabel); | getFieldText(getControlRefByID('fdlb', 0, diskWin), disklabel); | 
 | media = getControlValue('fdty', 0); | media = getControlValue('fdty', 0); | 
| data = getFieldValue(getControlRefByID('hdsz', 0, diskWin)); | if (targetDisk==2 || targetDisk==4) { | 
| if (data < 0) { | data = getFieldValue(getControlRefByID('hdsz', targetDisk, diskWin)); | 
| data = 0; | if (data < 0) { | 
| } | data = 0; | 
| else if (data > 512) { | } | 
| data = 512; | else if (data > 512) { | 
| } | data = 512; | 
| hdsize = data; | } | 
|  | hdsize = data; | 
|  | } | 
|  | else if (targetDisk==3) { | 
|  | hdsize = getControlValue('hdsz', 20)-1; | 
|  | } | 
 | QuitAppModalLoopForWindow(diskWin); | QuitAppModalLoopForWindow(diskWin); | 
 | err=noErr; | err=noErr; | 
 | break; | break; | 
| Line 66  static pascal OSStatus cfWinproc(EventHa | Line 82  static pascal OSStatus cfWinproc(EventHa | 
 |  |  | 
 | static pascal OSStatus PrefsTabEventHandlerProc( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData ) | static pascal OSStatus PrefsTabEventHandlerProc( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData ) | 
 | { | { | 
| WindowRef theWindow = (WindowRef)inUserData;  // get the windowRef, passed around as userData | WindowRef   theWindow = (WindowRef)inUserData;  // get the windowRef, passed around as userData | 
| short ret; | short               ret; | 
|  | ControlRef  focus; | 
|  |  | 
 | ret = changeTab(theWindow, lastPaneSelected); | ret = changeTab(theWindow, lastPaneSelected); | 
 | if (ret) { | if (ret) { | 
 |  | if (ret == 1) { | 
 |  | focus = getControlRefByID('fdlb', 0, theWindow); | 
 |  | } | 
 |  | else if (ret == 2 || ret == 4) { | 
 |  | focus = getControlRefByID('hdsz', ret, theWindow); | 
 |  | } | 
 |  | SetKeyboardFocus(theWindow, focus, kControlFocusNextPart); | 
 | lastPaneSelected = ret; | lastPaneSelected = ret; | 
 | } | } | 
 | return( eventNotHandledErr ); | return( eventNotHandledErr ); | 
| Line 81  static void makeNibWindow (IBNibRef nibR | Line 106  static void makeNibWindow (IBNibRef nibR | 
 |  |  | 
 | err = CreateWindowFromNib(nibRef, CFSTR("NewDiskDialog"), &diskWin); | err = CreateWindowFromNib(nibRef, CFSTR("NewDiskDialog"), &diskWin); | 
 | if (err == noErr) { | if (err == noErr) { | 
 |  |  | 
 | SetInitialTabState(diskWin, lastPaneSelected, kMaxNumTabs); | SetInitialTabState(diskWin, lastPaneSelected, kMaxNumTabs); | 
| EventTypeSpec   tabControlEvents[] ={ { kEventClassControl, kEventControlHit }}; |  | 
 | InstallControlEventHandler( getControlRefByID(kTabMasterSig,kTabMasterID,diskWin),  PrefsTabEventHandlerProc , GetEventTypeCount(tabControlEvents), tabControlEvents, diskWin, NULL ); | InstallControlEventHandler( getControlRefByID(kTabMasterSig,kTabMasterID,diskWin),  PrefsTabEventHandlerProc , GetEventTypeCount(tabControlEvents), tabControlEvents, diskWin, NULL ); | 
| EventTypeSpec   list[]={ { kEventClassCommand, kEventCommandProcess },}; | InstallWindowEventHandler (diskWin, NewEventHandlerUPP(cfWinproc), GetEventTypeCount(hicommandEvents), hicommandEvents, (void *)diskWin, &ref); | 
| InstallWindowEventHandler (diskWin, NewEventHandlerUPP(cfWinproc), GetEventTypeCount(list), list, (void *)diskWin, &ref); |  | 
 | ShowWindow(diskWin); | ShowWindow(diskWin); | 
 | RunAppModalLoopForWindow(diskWin); | RunAppModalLoopForWindow(diskWin); | 
 |  |  | 
 | } | } | 
 | return; | return; | 
 | } | } | 
| Line 115  void newdisk(void) { | Line 138  void newdisk(void) { | 
 | initNewDisk(); | initNewDisk(); | 
 |  |  | 
 | if (targetDisk == 1) { | if (targetDisk == 1) { | 
| if (saveFile('.D88', "Newdisk.d88", &fss)) { | if (dialog_filewriteselect('.D88', "Newdisk.d88", &fss, diskWin)) { | 
 | fsspec2path(&fss, fname, sizeof(fname)); | fsspec2path(&fss, fname, sizeof(fname)); | 
 | newdisk_fdd(fname, media, disklabel); | newdisk_fdd(fname, media, disklabel); | 
 | } | } | 
 | } | } | 
 | else if (targetDisk == 2) { | else if (targetDisk == 2) { | 
| if (saveFile('.THD', "Newdisk.thd", &fss)) { | if (dialog_filewriteselect('.THD', "Newdisk.thd", &fss, diskWin)) { | 
|  | fsspec2path(&fss, fname, sizeof(fname)); | 
|  | newdisk_thd(fname, hdsize); | 
|  | } | 
|  | } | 
|  | else if (targetDisk == 3) { | 
|  | if (dialog_filewriteselect('.HDI', "Newdisk.hdi", &fss, diskWin)) { | 
 | fsspec2path(&fss, fname, sizeof(fname)); | fsspec2path(&fss, fname, sizeof(fname)); | 
| newdisk_hdd(fname, hdsize); | newdisk_hdi(fname, hddtype); | 
|  | } | 
|  | } | 
|  | else if (targetDisk == 4) { | 
|  | if (dialog_filewriteselect('.HDD', "Newdisk.hdd", &fss, diskWin)) { | 
|  | fsspec2path(&fss, fname, sizeof(fname)); | 
|  | newdisk_vhd(fname, hdsize); | 
 | } | } | 
 | } | } | 
 | HideWindow(diskWin); | HideWindow(diskWin); | 
 | DisposeWindow(diskWin); | DisposeWindow(diskWin); | 
 | } | } | 
 |  |  | 
 | static pascal void navEventProc( NavEventCallbackMessage sel,NavCBRecPtr parm,NavCallBackUserData ud ) |  | 
 | { |  | 
 | switch( sel ) |  | 
 | { |  | 
 | case kNavCBEvent: |  | 
 | { |  | 
 | switch( parm->eventData.eventDataParms.event->what ) |  | 
 | { |  | 
 | } |  | 
 | break; |  | 
 | } |  | 
 | } |  | 
 | } |  | 
 |  |  | 
 | 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 ); |  | 
 | } |  |