diff --git a/Carbon/Classes/Application.cpp b/Carbon/Classes/Application.cpp index 012fb20..b1f6aa2 100644 --- a/Carbon/Classes/Application.cpp +++ b/Carbon/Classes/Application.cpp @@ -11,51 +11,51 @@ globals g; prefs p; /*** MAIN ***/ -int main( int argc, char* argv[] ) +int main(int argc, char* argv[]) { - #pragma unused( argc, argv ) + #pragma unused(argc, argv) // get system version - OSStatus error = Gestalt( gestaltSystemVersion, &g.systemVersion ); // this loads HIToolbox.framework on OS X - if( error ) return error; + OSStatus error = Gestalt(gestaltSystemVersion, &g.systemVersion); // this loads HIToolbox.framework on OS X + if(error) return error; // initalise application error = InitToolbox(); - if( error ) return error; + if(error) return error; error = InitMenubar(); - if( error ) return error; + if(error) return error; error = InitAppleEvents(); - if( error ) return error; + if(error) return error; error = InitCarbonEvents(); - if( error ) return error; + if(error) return error; error = InitGlobals(); - if( error ) return error; + if(error) return error; InitCursor(); // check system version is at least 7.1 - if( g.systemVersion < kMacOS71 ) + if(g.systemVersion < kMacOS71) { - DisplayError( kStringOSNotGoodEnough, kExplanationOSNotGoodEnough ); + DisplayError(kStringOSNotGoodEnough, kExplanationOSNotGoodEnough); QuitResKnife(); } #if TARGET_API_MAC_CARBON // check carbon version is at least 1.1 - error = Gestalt( gestaltCarbonVersion, &g.carbonVersion ); - if( g.carbonVersion < kCarbonLib11 || error ) + error = Gestalt(gestaltCarbonVersion, &g.carbonVersion); + if(g.carbonVersion < kCarbonLib11 || error) { - DisplayError( kStringMinimumCarbonLib, kExplanationMinimumCarbonLib ); + DisplayError(kStringMinimumCarbonLib, kExplanationMinimumCarbonLib); QuitResKnife(); } - else if( g.carbonVersion < kCarbonLib131 ) + else if(g.carbonVersion < kCarbonLib131) { - DisplayError( kStringRecommendedCarbonLib, kExplanationRecommendedCarbonLib ); + DisplayError(kStringRecommendedCarbonLib, kExplanationRecommendedCarbonLib); } #endif #if __profile__ - error = ProfilerInit( collectDetailed, bestTimeBase, 400, 40 ); - if( error ) DebugStr( "\pProfiler initalisation failed" ); // profiler failed + error = ProfilerInit(collectDetailed, bestTimeBase, 400, 40); + if(error) DebugStr("\pProfiler initalisation failed"); // profiler failed #endif #if TARGET_API_MAC_CARBON @@ -63,17 +63,17 @@ int main( int argc, char* argv[] ) RunApplicationEventLoop(); #else EventRecord theEvent; - while( !g.quitting ) + while(!g.quitting) { - WaitNextEvent( everyEvent, &theEvent, 20, null ); - if( IsDialogEvent( &theEvent ) ) - ParseDialogEvents( null, &theEvent, null ); - else ParseEvents( &theEvent ); + WaitNextEvent(everyEvent, &theEvent, 20, null); + if(IsDialogEvent(&theEvent)) + ParseDialogEvents(null, &theEvent, null); + else ParseEvents(&theEvent); } #endif #if __profile__ - ProfilerDump( "\pResKnife profile" ); + ProfilerDump("\pResKnife profile"); ProfilerTerm(); #endif @@ -85,22 +85,22 @@ int main( int argc, char* argv[] ) } /*** INIT TOOLBOX ***/ -OSStatus InitToolbox( void ) +OSStatus InitToolbox(void) { #if !TARGET_API_MAC_CARBON - InitGraf( &qd.thePort ); + InitGraf(&qd.thePort); InitFonts(); - FlushEvents( everyEvent, 0 ); + FlushEvents(everyEvent, 0); InitWindows(); InitMenus(); TEInit(); - InitDialogs( 0L ); + InitDialogs(0L); #endif return noErr; } /*** INITALIZE MENUBAR ***/ -OSStatus InitMenubar( void ) +OSStatus InitMenubar(void) { OSStatus error = noErr; @@ -108,53 +108,53 @@ OSStatus InitMenubar( void ) IBNibRef nibRef = null; // create a nib reference (only searches the application bundle) - error = CreateNibReference( CFSTR("ResKnife"), &nibRef ); - if( error != noErr ) + error = CreateNibReference(CFSTR("ResKnife"), &nibRef); + if(error != noErr) { - DisplayError( "\pThe nib file reference could not be obtained." ); + DisplayError("\pThe nib file reference could not be obtained."); return error; } // get menu bar - error = SetMenuBarFromNib( nibRef, CFSTR("Menubar") ); - if( error != noErr ) + error = SetMenuBarFromNib(nibRef, CFSTR("Menubar")); + if(error != noErr) { - DisplayError( "\pMenus could not be obtained from nib file." ); + DisplayError("\pMenus could not be obtained from nib file."); return error; } // dispose of nib ref - DisposeNibReference( nibRef ); + DisposeNibReference(nibRef); #else /* ! USE_NIBS */ - Handle menuList = GetNewMBar( kClassicMenuBar ); - SetMenuBar( menuList ); - ReleaseResource( menuList ); + Handle menuList = GetNewMBar(kClassicMenuBar); + SetMenuBar(menuList); + ReleaseResource(menuList); // delete quit and prefs on OS X long result; - error = Gestalt( gestaltMenuMgrAttr, &result ); - if( !error && (result & gestaltMenuMgrAquaLayoutMask) ) + error = Gestalt(gestaltMenuMgrAttr, &result); + if(!error && (result & gestaltMenuMgrAquaLayoutMask)) { - MenuRef fileMenu = GetMenuRef( kFileMenu ); - MenuRef editMenu = GetMenuRef( kEditMenu ); - DeleteMenuItem( fileMenu, kFileMenuQuitItem ); - DeleteMenuItem( fileMenu, kFileMenuQuitItem -1 ); - DeleteMenuItem( editMenu, kEditMenuPreferencesItem ); - DeleteMenuItem( editMenu, kEditMenuPreferencesItem -1 ); + MenuRef fileMenu = GetMenuRef(kFileMenu); + MenuRef editMenu = GetMenuRef(kEditMenu); + DeleteMenuItem(fileMenu, kFileMenuQuitItem); + DeleteMenuItem(fileMenu, kFileMenuQuitItem -1); + DeleteMenuItem(editMenu, kEditMenuPreferencesItem); + DeleteMenuItem(editMenu, kEditMenuPreferencesItem -1); } // set delete item character to the delete glyph - MenuRef editMenu = GetMenuRef( kEditMenu ); - SetMenuItemKeyGlyph( editMenu, kEditMenuClearItem, kMenuDeleteLeftGlyph ); + MenuRef editMenu = GetMenuRef(kEditMenu); + SetMenuItemKeyGlyph(editMenu, kEditMenuClearItem, kMenuDeleteLeftGlyph); #if TARGET_API_MAC_CARBON MenuRef windowMenu; - CreateStandardWindowMenu( 0, &windowMenu ); - InsertMenu( windowMenu, kWindowMenu ); + CreateStandardWindowMenu(0, &windowMenu); + InsertMenu(windowMenu, kWindowMenu); #else - AppendResMenu( GetMenuRef( kAppleMenu ), 'DRVR' ); + AppendResMenu(GetMenuRef(kAppleMenu), 'DRVR'); #endif /* TARGET_CARBON */ DrawMenuBar(); @@ -164,37 +164,37 @@ OSStatus InitMenubar( void ) } /*** INIT APPLE EVENTS ***/ -OSStatus InitAppleEvents( void ) +OSStatus InitAppleEvents(void) { - AEEventHandlerUPP appleEventParser = NewAEEventHandlerUPP( ParseAppleEvents ); - AEInstallEventHandler( kCoreEventClass, kAEOpenApplication, appleEventParser, 0, false ); - AEInstallEventHandler( kCoreEventClass, kAEReopenApplication, appleEventParser, 0, false ); - AEInstallEventHandler( kCoreEventClass, kAEOpenDocuments, appleEventParser, 0, false ); - AEInstallEventHandler( kCoreEventClass, kAEPrintDocuments, appleEventParser, 0, false ); - AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, appleEventParser, 0, false ); + AEEventHandlerUPP appleEventParser = NewAEEventHandlerUPP(ParseAppleEvents); + AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, appleEventParser, 0, false); + AEInstallEventHandler(kCoreEventClass, kAEReopenApplication, appleEventParser, 0, false); + AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, appleEventParser, 0, false); + AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, appleEventParser, 0, false); + AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, appleEventParser, 0, false); return noErr; } /*** INIT CARBON EVENTS ***/ -OSStatus InitCarbonEvents( void ) +OSStatus InitCarbonEvents(void) { #if TARGET_API_MAC_CARBON EventHandlerUPP handler = null; EventHandlerRef ref = null; - EventTypeSpec update = { kEventClassMenu, kEventMenuEnableItems }; - EventTypeSpec process = { kEventClassCommand, kEventCommandProcess }; + EventTypeSpec update = { kEventClassMenu, kEventMenuEnableItems }; + EventTypeSpec process = { kEventClassCommand, kEventCommandProcess }; // install menu adjust handler - handler = NewEventHandlerUPP( CarbonEventUpdateMenus ); - InstallApplicationEventHandler( handler, 1, &update, null, &ref ); + handler = NewEventHandlerUPP(CarbonEventUpdateMenus); + InstallApplicationEventHandler(handler, 1, &update, null, &ref); // install menu selection handler - handler = NewEventHandlerUPP( CarbonEventParseMenuSelection ); - InstallApplicationEventHandler( handler, 1, &process, null, &ref ); + handler = NewEventHandlerUPP(CarbonEventParseMenuSelection); + InstallApplicationEventHandler(handler, 1, &process, null, &ref); // install default idle timer Ñ 200 millisecond interval - bug: this should be in a seperate thread and the cursor blink time - EventLoopTimerUPP timerUPP = NewEventLoopTimerUPP( DefaultIdleTimer ); - OSStatus error = InstallEventLoopTimer( GetMainEventLoop(), kEventDurationNoWait, kEventDurationMillisecond * 200, timerUPP, null, &g.idleTimer ); + EventLoopTimerUPP timerUPP = NewEventLoopTimerUPP(DefaultIdleTimer); + OSStatus error = InstallEventLoopTimer(GetMainEventLoop(), kEventDurationNoWait, kEventDurationMillisecond * 200, timerUPP, null, &g.idleTimer); return error; #else return noErr; @@ -202,39 +202,39 @@ OSStatus InitCarbonEvents( void ) } /*** INITALIZE GLOBALS ***/ -OSStatus InitGlobals( void ) +OSStatus InitGlobals(void) { OSStatus error = noErr; // general app globals - g.quitting = false; - g.cancelQuit = false; - g.frontApp = true; - g.appResFile = CurResFile(); - g.asyncSound = !(Boolean) SHInitSoundHelper( &g.callSH, kSHDefChannels ); - g.emergencyMemory = NewHandleClear( kEmergencyMemory ); + g.quitting = false; + g.cancelQuit = false; + g.frontApp = true; + g.appResFile = CurResFile(); + g.asyncSound = !(Boolean) SHInitSoundHelper(&g.callSH, kSHDefChannels); + g.emergencyMemory = NewHandleClear(kEmergencyMemory); // files - g.tempCount = 0; + g.tempCount = 0; // debugging - g.debug = false; + g.debug = false; g.surpressErrors = false; g.useAppleEvents = true; - g.useSheets = (g.carbonVersion >= kCarbonLib11)? true:false; + g.useSheets = (g.carbonVersion >= kCarbonLib11)? true:false; // prefs dialog - g.prefsDialog = null; - p.warnOnDelete = true; + g.prefsDialog = null; + p.warnOnDelete = true; // colours - SetColour( &g.white, 0xFFFF, 0xFFFF, 0xFFFF ); - SetColour( &g.bgColour, 0xEEEE, 0xEEEE, 0xEEEE ); - SetColour( &g.sortColour, 0xDDDD, 0xDDDD, 0xDDDD ); - SetColour( &g.bevelColour, 0xAAAA, 0xAAAA, 0xAAAA ); - SetColour( &g.textColour, 0x7777, 0x7777, 0x7777 ); - SetColour( &g.frameColour, 0x5555, 0x5555, 0x5555 ); - SetColour( &g.black, 0x0000, 0x0000, 0x0000 ); + SetColour(&g.white, 0xFFFF, 0xFFFF, 0xFFFF); + SetColour(&g.bgColour, 0xEEEE, 0xEEEE, 0xEEEE); + SetColour(&g.sortColour, 0xDDDD, 0xDDDD, 0xDDDD); + SetColour(&g.bevelColour, 0xAAAA, 0xAAAA, 0xAAAA); + SetColour(&g.textColour, 0x7777, 0x7777, 0x7777); + SetColour(&g.frameColour, 0x5555, 0x5555, 0x5555); + SetColour(&g.black, 0x0000, 0x0000, 0x0000); #if TARGET_API_MAC_CARBON // window manager @@ -248,50 +248,53 @@ OSStatus InitGlobals( void ) // appearance manager g.appearanceAvailable = true; g.useAppearance = g.appearanceAvailable; // assume if user has Appearence, s/he wants to use it - if( g.useAppearance ) RegisterAppearanceClient(); // register such with the OS + if(g.useAppearance) RegisterAppearanceClient(); // register such with the OS // nav services g.navAvailable = true; g.useNavServices = g.navAvailable; // assume if user has NavServices, s/he wants to use them - if( g.navAvailable ) NavLoad(); // preload for efficiency - ignored on OS X (always loaded) + if(g.navAvailable) NavLoad(); // preload for efficiency - ignored on OS X (always loaded) #else // check for drag manager presence/attributes SInt32 result = null; - error = Gestalt( gestaltDragMgrAttr, &result ); - if( !error ) { + error = Gestalt(gestaltDragMgrAttr, &result); + if(!error) { g.dragAvailable = (Boolean) (result & (1 << gestaltDragMgrPresent)); - g.translucentDrag = (Boolean) (result & (1 << gestaltDragMgrHasImageSupport)); } - else { + g.translucentDrag = (Boolean) (result & (1 << gestaltDragMgrHasImageSupport)); + } else { g.dragAvailable = false; - g.translucentDrag = false; } + g.translucentDrag = false; + } // check appearance availablilty result = null; - error = Gestalt( gestaltAppearanceAttr, &result ); - if( !error ) { + error = Gestalt(gestaltAppearanceAttr, &result); + if(!error) { g.appearanceAvailable = (Boolean) (result & (1 << gestaltAppearanceExists)); - g.useAppearance = g.appearanceAvailable; } // assume if user has Appearence, s/he wants to use it - else { + g.useAppearance = g.appearanceAvailable; // assume if user has Appearence, s/he wants to use it + } else { g.appearanceAvailable = false; - g.useAppearance = false; } - if( g.useAppearance ) RegisterAppearanceClient(); // register such with the OS + g.useAppearance = false; + } + if(g.useAppearance) RegisterAppearanceClient(); // register such with the OS // check nav services availablilty g.navAvailable = (Boolean) NavServicesAvailable(); g.useNavServices = g.navAvailable; // assume if user has NavServices, s/he wants to use them - if( g.navAvailable ) NavLoad(); // preload for efficiency + if(g.navAvailable) NavLoad(); // preload for efficiency // check for MacOS 8.5's window manager (also in CarbonLib 1.0 - backported to 8.1) result = null; - error = Gestalt( gestaltWindowMgrAttr, &result ); - if( !error ) { + error = Gestalt(gestaltWindowMgrAttr, &result); + if(!error) { g.windowMgrAvailable = (Boolean) (result & (1 << gestaltWindowMgrPresentBit)); - g.extendedWindowAttr = (Boolean) (result & (1 << gestaltExtendedWindowAttributes)); } - else { + g.extendedWindowAttr = (Boolean) (result & (1 << gestaltExtendedWindowAttributes)); + } else { g.windowMgrAvailable = false; - g.extendedWindowAttr = false; } + g.extendedWindowAttr = false; + } - UpdateMenus( null ); + UpdateMenus(null); #endif return error; } @@ -299,73 +302,73 @@ OSStatus InitGlobals( void ) #if !TARGET_API_MAC_CARBON /*** PARSE EVENTS ***/ -OSStatus ParseEvents( EventRecord *event ) +OSStatus ParseEvents(EventRecord *event) { OSStatus error = eventNotHandledErr; - switch( event->what ) + switch(event->what) { case nullEvent: IdleEvent(); break; case mouseDown: - error = MouseDownEventOccoured( event ); + error = MouseDownEventOccoured(event); break; case mouseUp: - error = MouseUpEventOccoured( event ); + error = MouseUpEventOccoured(event); break; case keyDown: - error = KeyDownEventOccoured( event ); + error = KeyDownEventOccoured(event); break; case autoKey: - error = KeyRepeatEventOccoured( event ); + error = KeyRepeatEventOccoured(event); break; case keyUp: - error = KeyUpEventOccoured( event ); + error = KeyUpEventOccoured(event); break; case updateEvt: - error = UpdateEventOccoured( event ); + error = UpdateEventOccoured(event); break; case activateEvt: - error = ActivateEventOccoured( event ); + error = ActivateEventOccoured(event); break; case osEvt: - error = ParseOSEvents( event ); + error = ParseOSEvents(event); break; case kHighLevelEvent: - error = AEProcessAppleEvent( event ); + error = AEProcessAppleEvent(event); break; } return error; } /*** PARSE DIALOG EVENTS ***/ -pascal Boolean ParseDialogEvents( DialogPtr dialog, EventRecord *event, DialogItemIndex *itemHit ) +pascal Boolean ParseDialogEvents(DialogPtr dialog, EventRecord *event, DialogItemIndex *itemHit) { - #pragma unused( dialog, event, itemHit ) + #pragma unused(dialog, event, itemHit) /* OSStatus error = eventNotHandledErr; - if( dialog == null && itemHit == null ); + if(dialog == null && itemHit == null); */ return false; } /*** PARSE OS EVENTS ***/ -OSStatus ParseOSEvents( EventRecord *event ) +OSStatus ParseOSEvents(EventRecord *event) { - #pragma unused( event ) + #pragma unused(event) OSStatus error = eventNotHandledErr; SInt8 eventType = event->message >> 24; // high byte of message field - if( eventType & mouseMovedMessage ) + if(eventType & mouseMovedMessage) { // mouse moved event } - else if( eventType & suspendResumeMessage ) // suspend/resume event + else if(eventType & suspendResumeMessage) // suspend/resume event { - g.frontApp = ( event->message & resumeFlag ); // true on resume - if( FrontWindow() ) // only de/activate front window (if present) + g.frontApp = (event->message & resumeFlag); // true on resume + if(FrontWindow()) // only de/activate front window (if present) { - WindowObjectPtr winObj = (WindowObjectPtr) GetWindowRefCon( FrontWindow() ); - error = winObj->Activate( g.frontApp ); + WindowObjectPtr winObj = (WindowObjectPtr) GetWindowRefCon(FrontWindow()); + error = winObj->Activate(g.frontApp); } - if( event->message & convertClipboardFlag ) + if(event->message & convertClipboardFlag) { // convert clipboard to private scrap } @@ -377,55 +380,58 @@ OSStatus ParseOSEvents( EventRecord *event ) #endif /*** PARSE APPLE EVENTS ***/ -pascal OSErr ParseAppleEvents( const AppleEvent *event, AppleEvent *reply, SInt32 refCon ) +pascal OSErr ParseAppleEvents(const AppleEvent *event, AppleEvent *reply, SInt32 refCon) { - #pragma unused( reply, refCon ) + #pragma unused(reply, refCon) OSErr error; Size actualSize; DescType actualType; DescType eventClass, eventID; - error = AEGetAttributePtr( (AppleEvent *) event, keyEventClassAttr, typeType, &actualType, (Ptr) &eventClass, sizeof(eventClass), &actualSize ); - if( error ) return errAEEventNotHandled; + error = AEGetAttributePtr((AppleEvent *) event, keyEventClassAttr, typeType, &actualType, (Ptr) &eventClass, sizeof(eventClass), &actualSize); + if(error) return errAEEventNotHandled; - error = AEGetAttributePtr( (AppleEvent *) event, keyEventIDAttr, typeType, &actualType, (Ptr) &eventID, sizeof(eventID), &actualSize ); - if( error ) return errAEEventNotHandled; + error = AEGetAttributePtr((AppleEvent *) event, keyEventIDAttr, typeType, &actualType, (Ptr) &eventID, sizeof(eventID), &actualSize); + if(error) return errAEEventNotHandled; - switch( eventClass ) + switch(eventClass) { case kCoreEventClass: - switch( eventID ) + switch(eventID) { case kAEOpenApplication: // sent when app opened directly (ie not file opened) #if TARGET_API_MAC_CARBON - DisplayOpenDialog(); + DisplayOpenDialog(); #else - if( g.useNavServices ) DisplayOpenDialog(); - else DisplayStandardFileOpenDialog(); + if(g.useNavServices) + DisplayOpenDialog(); + else DisplayStandardFileOpenDialog(); #endif break; case kAEReopenApplication: // sent when app is double-clicked on, but is already open - if( FrontWindow() == null ) + if(FrontWindow() == null) { AEDescList list = {}; #if TARGET_API_MAC_CARBON - AppleEventSendSelf( kCoreEventClass, kAEOpenApplication, list ); + AppleEventSendSelf(kCoreEventClass, kAEOpenApplication, list); #else - if( g.useAppleEvents ) AppleEventSendSelf( kCoreEventClass, kAEOpenApplication, list ); - else if( g.useNavServices ) DisplayOpenDialog(); - else DisplayStandardFileOpenDialog(); + if(g.useAppleEvents) + AppleEventSendSelf(kCoreEventClass, kAEOpenApplication, list); + else if(g.useNavServices) + DisplayOpenDialog(); + else DisplayStandardFileOpenDialog(); #endif } break; case kAEOpenDocuments: // sent when file is double-clicked on in finder, - AppleEventOpen( event ); // or open is chosen in the file menu and g.useAppleEvents is true + AppleEventOpen(event); // or open is chosen in the file menu and g.useAppleEvents is true break; case kAEPrintDocuments: // sent when document is dragged onto printer - AppleEventPrint( event ); + AppleEventPrint(event); break; case kAEQuitApplication: // sent from many locations (eg after restart command) @@ -435,13 +441,13 @@ pascal OSErr ParseAppleEvents( const AppleEvent *event, AppleEvent *reply, SInt3 break; /* case kAECoreSuite: // i'm not even registering for these yet - switch( eventID ) + switch(eventID) { case kAECut: case kAECopy: case kAEPaste: case kAEDelete: - DisplayErrorDialog( "\pSorry, but cut, copy, paste and clear via Apple Events arn't yet supported." ); + DisplayErrorDialog("\pSorry, but cut, copy, paste and clear via Apple Events arn't yet supported."); error = errAEEventNotHandled; break; } @@ -457,65 +463,65 @@ pascal OSErr ParseAppleEvents( const AppleEvent *event, AppleEvent *reply, SInt3 #if !TARGET_API_MAC_CARBON /*** MOUSE DOWN EVENT OCCOURED ***/ -OSStatus MouseDownEventOccoured( EventRecord *event ) +OSStatus MouseDownEventOccoured(EventRecord *event) { // get the window OSStatus error = eventNotHandledErr; WindowRef window; - SInt16 windowPart = FindWindow( event->where, &window ); - WindowObjectPtr winObj = (WindowObjectPtr) GetWindowRefCon( window ); + SInt16 windowPart = FindWindow(event->where, &window); + WindowObjectPtr winObj = (WindowObjectPtr) GetWindowRefCon(window); // find out where the click occoured - if( !windowPart ) return error; - else switch( windowPart ) + if(!windowPart) return error; + else switch(windowPart) { case inMenuBar: - error = UpdateMenus( FrontWindow() ); // error ignored at the moment - UInt32 menuChoice = MenuSelect( event->where ); - UInt16 menu = HiWord( menuChoice ); - UInt16 item = LoWord( menuChoice ); - error = ParseMenuSelection( menu, item ); // error ignored at the moment - HiliteMenu( 0 ); + error = UpdateMenus(FrontWindow()); // error ignored at the moment + UInt32 menuChoice = MenuSelect(event->where); + UInt16 menu = HiWord(menuChoice); + UInt16 item = LoWord(menuChoice); + error = ParseMenuSelection(menu, item); // error ignored at the moment + HiliteMenu(0); break; case inSysWindow: - SystemClick( event, window ); + SystemClick(event, window); break; case inContent: - SelectWindow( window ); - winObj->Click( event->where, event->modifiers ); + SelectWindow(window); + winObj->Click(event->where, event->modifiers); break; case inDrag: - DragWindow( window, event->where, &qdb ); - winObj->BoundsChanged( null ); + DragWindow(window, event->where, &qdb); + winObj->BoundsChanged(null); break; case inGrow: Rect bounds; // minimum and maximum bounds of window - SetRect( &bounds, 128, 128, 1024, 1024 ); - SInt32 result = GrowWindow( window, event->where, &bounds ); - if( result ) + SetRect(&bounds, 128, 128, 1024, 1024); + SInt32 result = GrowWindow(window, event->where, &bounds); + if(result) { - SInt16 newWidth = LoWord( result ); - SInt16 newHeight = HiWord( result ); - SizeWindow( window, newWidth, newHeight, false ); - winObj->BoundsChanged( null ); + SInt16 newWidth = LoWord(result); + SInt16 newHeight = HiWord(result); + SizeWindow(window, newWidth, newHeight, false); + winObj->BoundsChanged(null); } break; case inGoAway: - if( TrackGoAway( window, event->where ) ) + if(TrackGoAway(window, event->where)) winObj->Close(); break; case inZoomIn: case inZoomOut: - if( TrackBox( window, event->where, windowPart ) ) + if(TrackBox(window, event->where, windowPart)) { - ZoomWindow( window, windowPart, window == FrontWindow() ); // I think the last param *might* need to be "g.frontApp" - winObj->BoundsChanged( null ); + ZoomWindow(window, windowPart, window == FrontWindow()); // I think the last param *might* need to be "g.frontApp" + winObj->BoundsChanged(null); } break; @@ -527,130 +533,130 @@ OSStatus MouseDownEventOccoured( EventRecord *event ) } /*** MOUSE UP EVENT OCCOURED ***/ -OSStatus MouseUpEventOccoured( EventRecord *event ) +OSStatus MouseUpEventOccoured(EventRecord *event) { - #pragma unused( event ) + #pragma unused(event) OSStatus error = eventNotHandledErr; return error; } /*** KEY DOWN EVENT OCCOURED ***/ -OSStatus KeyDownEventOccoured( EventRecord *event ) +OSStatus KeyDownEventOccoured(EventRecord *event) { OSStatus error = eventNotHandledErr; - char key = (char)( event->message & charCodeMask ); // get the key pressed - if( event->modifiers & cmdKey ) // was it a menu shortcut? + char key = (char)(event->message & charCodeMask); // get the key pressed + if(event->modifiers & cmdKey) // was it a menu shortcut? { - UpdateMenus( FrontWindow() ); - UInt32 menuChoice = MenuKey( key ); - UInt16 menu = HiWord( menuChoice ); - UInt16 item = LoWord( menuChoice ); - if( menu && item ) - error = ParseMenuSelection( menu, item ); + UpdateMenus(FrontWindow()); + UInt32 menuChoice = MenuKey(key); + UInt16 menu = HiWord(menuChoice); + UInt16 item = LoWord(menuChoice); + if(menu && item) + error = ParseMenuSelection(menu, item); } return error; } /*** KEY REPEAT EVENT OCCOURED ***/ -OSStatus KeyRepeatEventOccoured( EventRecord *event ) +OSStatus KeyRepeatEventOccoured(EventRecord *event) { - OSStatus error = KeyDownEventOccoured( event ); + OSStatus error = KeyDownEventOccoured(event); return error; } /*** KEY UP EVENT OCCOURED ***/ -OSStatus KeyUpEventOccoured( EventRecord *event ) +OSStatus KeyUpEventOccoured(EventRecord *event) { - #pragma unused( event ) + #pragma unused(event) OSStatus error = eventNotHandledErr; return error; } /*** UPDATE EVENT OCCOURED ***/ -OSStatus UpdateEventOccoured( EventRecord *event ) +OSStatus UpdateEventOccoured(EventRecord *event) { OSStatus error = eventNotHandledErr; GrafPtr oldPort; WindowRef window = (WindowRef) event->message; // send update events to window - GetPort( &oldPort ); - SetPortWindowPort( window ); - BeginUpdate( window ); // this sets up the visRgn + GetPort(&oldPort); + SetPortWindowPort(window); + BeginUpdate(window); // this sets up the visRgn { RgnHandle updateRgn = NewRgn(); - WindowObjectPtr winObj = (WindowObjectPtr) GetWindowRefCon( window ); - GetPortVisibleRegion( GetWindowPort( window ), updateRgn ); - if( winObj ) error = winObj->Update( updateRgn ); - DisposeRgn( updateRgn ); + WindowObjectPtr winObj = (WindowObjectPtr) GetWindowRefCon(window); + GetPortVisibleRegion(GetWindowPort(window), updateRgn); + if(winObj) error = winObj->Update(updateRgn); + DisposeRgn(updateRgn); } - EndUpdate( window ); - SetPort( oldPort ); + EndUpdate(window); + SetPort(oldPort); return error; } /*** ACTIVATE EVENT OCCOURED ***/ -OSStatus ActivateEventOccoured( EventRecord *event ) +OSStatus ActivateEventOccoured(EventRecord *event) { OSStatus error = eventNotHandledErr; - WindowObjectPtr winObj = (WindowObjectPtr) GetWindowRefCon( (WindowRef) event->message ); - if( winObj ) error = winObj->Activate( (Boolean) (event->modifiers & activeFlag) ); + WindowObjectPtr winObj = (WindowObjectPtr) GetWindowRefCon((WindowRef) event->message); + if(winObj) error = winObj->Activate((Boolean) (event->modifiers & activeFlag)); return error; } /*** IDLE EVENT ***/ -OSStatus IdleEvent( void ) +OSStatus IdleEvent(void) { // call sound idle routine - if( g.asyncSound ) SHIdle(); + if(g.asyncSound) SHIdle(); // compact all memory /* SInt32 total, contig; - PurgeMem( kEmergencyMemory ); - CompactMem( kEmergencyMemory ); - PurgeSpace( &total, &contig ); + PurgeMem(kEmergencyMemory); + CompactMem(kEmergencyMemory); + PurgeSpace(&total, &contig); // deal with emergency memory - if( total < kMinimumFreeMemory && g.emergencyMemory ) + if(total < kMinimumFreeMemory && g.emergencyMemory) { - DisposeHandle( g.emergencyMemory ); // release emergence memory - DisplayError( "\pMemory is running low, please close some windows." ); + DisposeHandle(g.emergencyMemory); // release emergence memory + DisplayError("\pMemory is running low, please close some windows."); } - else if( !g.emergencyMemory && contig > kEmergencyMemory ) // try to recover handle if possible - g.emergencyMemory = NewHandleClear( kEmergencyMemory ); + else if(!g.emergencyMemory && contig > kEmergencyMemory) // try to recover handle if possible + g.emergencyMemory = NewHandleClear(kEmergencyMemory); */ return noErr; } #endif /*** QUIT RES KNIFE ***/ -void QuitResKnife( void ) +void QuitResKnife(void) { // save all open files WindowRef window = FrontNonFloatingWindow(), nextWindow; - while( window ) + while(window) { - nextWindow = GetNextWindow( window ); - SInt32 kind = GetWindowKind( window ); - if( kind == kFileWindowKind ) + nextWindow = GetNextWindow(window); + SInt32 kind = GetWindowKind(window); + if(kind == kFileWindowKind) { #if TARGET_API_MAC_CARBON EventRef event; - CreateEvent( null, kEventClassWindow, kEventWindowClose, kEventDurationNoWait, kEventAttributeNone, &event ); - SendEventToWindow( event, window ); - ReleaseEvent( event ); + CreateEvent(null, kEventClassWindow, kEventWindowClose, kEventDurationNoWait, kEventAttributeNone, &event); + SendEventToWindow(event, window); + ReleaseEvent(event); #else // bug: this is totally the wrong thing to do here, but will have to do for now - DisposeWindow( window ); // bug: windows don't close when sent a WindowClose event! + DisposeWindow(window); // bug: windows don't close when sent a WindowClose event! #endif } window = nextWindow; } - if( !g.cancelQuit ) + if(!g.cancelQuit) { - if( g.asyncSound ) SHKillSoundHelper(); - if( g.navAvailable ) NavUnload(); + if(g.asyncSound) SHKillSoundHelper(); + if(g.navAvailable) NavUnload(); #if TARGET_API_MAC_CARBON QuitApplicationEventLoop(); #else @@ -666,77 +672,77 @@ void QuitResKnife( void ) #if TARGET_API_MAC_CARBON /*** CARBON EVENT UPDATE MENUS ***/ -pascal OSStatus CarbonEventUpdateMenus( EventHandlerCallRef callRef, EventRef event, void *userData ) +pascal OSStatus CarbonEventUpdateMenus(EventHandlerCallRef callRef, EventRef event, void *userData) { - #pragma unused( callRef, event, userData ) + #pragma unused(callRef, event, userData) OSStatus error = eventNotHandledErr; Boolean fileOpen = (Boolean) (FrontNonFloatingWindow() != NULL); // application menu (passing null causes all menus to be searched) - EnableCommand( null, kMenuCommandAbout, true ); - EnableCommand( null, kHICommandPreferences, true ); + EnableCommand(null, kMenuCommandAbout, true); + EnableCommand(null, kHICommandPreferences, true); // file menu - EnableCommand( null, kMenuCommandNewFile, true ); - EnableCommand( null, kMenuCommandOpenFile, true ); - EnableCommand( null, kMenuCommandCloseWindow, fileOpen ); - EnableCommand( null, kMenuCommandCloseFile, fileOpen ); - EnableCommand( null, kMenuCommandSaveFile, fileOpen ); // bug: shoud be disabled if file is unmodified - EnableCommand( null, kMenuCommandSaveFileAs, fileOpen ); - EnableCommand( null, kMenuCommandRevertFile, fileOpen ); - EnableCommand( null, kMenuCommandPageSetup, fileOpen ); - EnableCommand( null, kMenuCommandPrint, fileOpen ); - -/* if( fileOpen ) + EnableCommand(null, kMenuCommandNewFile, true); + EnableCommand(null, kMenuCommandOpenFile, true); + EnableCommand(null, kMenuCommandCloseWindow, fileOpen); + EnableCommand(null, kMenuCommandCloseFile, fileOpen); + EnableCommand(null, kMenuCommandSaveFile, fileOpen); // bug: shoud be disabled if file is unmodified + EnableCommand(null, kMenuCommandSaveFileAs, fileOpen); + EnableCommand(null, kMenuCommandRevertFile, fileOpen); + EnableCommand(null, kMenuCommandPageSetup, fileOpen); + EnableCommand(null, kMenuCommandPrint, fileOpen); + +/* if(fileOpen) { // edit window - EnableCommand( null, kHICommandUndo, false ); - EnableCommand( null, kHICommandRedo, false ); - EnableCommand( null, kHICommandCut, false ); - EnableCommand( null, kHICommandCopy, false ); - EnableCommand( null, kHICommandPaste, false ); - EnableCommand( null, kHICommandClear, false ); - EnableCommand( null, kHICommandSelectAll, false ); - EnableCommand( null, kMenuCommandFind, false ); - EnableCommand( null, kMenuCommandFindAgain, false ); + EnableCommand(null, kHICommandUndo, false); + EnableCommand(null, kHICommandRedo, false); + EnableCommand(null, kHICommandCut, false); + EnableCommand(null, kHICommandCopy, false); + EnableCommand(null, kHICommandPaste, false); + EnableCommand(null, kHICommandClear, false); + EnableCommand(null, kHICommandSelectAll, false); + EnableCommand(null, kMenuCommandFind, false); + EnableCommand(null, kMenuCommandFindAgain, false); // resource menu - EnableCommand( null, kMenuCommandNewResource, false ); - EnableCommand( null, kMenuCommandOpenHex, false ); - EnableCommand( null, kMenuCommandOpenDefault, false ); - EnableCommand( null, kMenuCommandOpenTemplate, false ); - EnableCommand( null, kMenuCommandOpenSpecific, false ); - EnableCommand( null, kMenuCommandRevertResource, false ); - EnableCommand( null, kMenuCommandPlaySound, false ); + EnableCommand(null, kMenuCommandNewResource, false); + EnableCommand(null, kMenuCommandOpenHex, false); + EnableCommand(null, kMenuCommandOpenDefault, false); + EnableCommand(null, kMenuCommandOpenTemplate, false); + EnableCommand(null, kMenuCommandOpenSpecific, false); + EnableCommand(null, kMenuCommandRevertResource, false); + EnableCommand(null, kMenuCommandPlaySound, false); } */ // debug menu - EnableCommand( null, kMenuCommandDebug, true ); - EnableCommand( null, kMenuCommandAppleEvents, false ); - EnableCommand( null, kMenuCommandAppearance, false ); - EnableCommand( null, kMenuCommandNavServices, false ); - EnableCommand( null, kMenuCommandSheets, g.carbonVersion >= kCarbonLib11 ); - SetMenuCommandMark( null, kMenuCommandDebug, g.debug? kMenuCheckmarkGlyph : kMenuNullGlyph ); - SetMenuCommandMark( null, kMenuCommandSurpressErrors, g.surpressErrors? kMenuCheckmarkGlyph : kMenuNullGlyph ); - SetMenuCommandMark( null, kMenuCommandAppleEvents, g.useAppleEvents? kMenuCheckmarkGlyph : kMenuNullGlyph ); // these three should always be true in Carbon - SetMenuCommandMark( null, kMenuCommandAppearance, g.useAppearance? kMenuCheckmarkGlyph : kMenuNullGlyph ); - SetMenuCommandMark( null, kMenuCommandNavServices, g.useNavServices? kMenuCheckmarkGlyph : kMenuNullGlyph ); - SetMenuCommandMark( null, kMenuCommandSheets, g.useSheets? kMenuCheckmarkGlyph : kMenuNullGlyph ); + EnableCommand(null, kMenuCommandDebug, true); + EnableCommand(null, kMenuCommandAppleEvents, false); + EnableCommand(null, kMenuCommandAppearance, false); + EnableCommand(null, kMenuCommandNavServices, false); + EnableCommand(null, kMenuCommandSheets, g.carbonVersion >= kCarbonLib11); + SetMenuCommandMark(null, kMenuCommandDebug, g.debug? kMenuCheckmarkGlyph : kMenuNullGlyph); + SetMenuCommandMark(null, kMenuCommandSurpressErrors, g.surpressErrors? kMenuCheckmarkGlyph : kMenuNullGlyph); + SetMenuCommandMark(null, kMenuCommandAppleEvents, g.useAppleEvents? kMenuCheckmarkGlyph : kMenuNullGlyph); // these three should always be true in Carbon + SetMenuCommandMark(null, kMenuCommandAppearance, g.useAppearance? kMenuCheckmarkGlyph : kMenuNullGlyph); + SetMenuCommandMark(null, kMenuCommandNavServices, g.useNavServices? kMenuCheckmarkGlyph : kMenuNullGlyph); + SetMenuCommandMark(null, kMenuCommandSheets, g.useSheets? kMenuCheckmarkGlyph : kMenuNullGlyph); return error; } /*** CARBON EVENT PARSE MENU SELECTION ***/ -pascal OSStatus CarbonEventParseMenuSelection( EventHandlerCallRef callRef, EventRef event, void *userData ) +pascal OSStatus CarbonEventParseMenuSelection(EventHandlerCallRef callRef, EventRef event, void *userData) { - #pragma unused( callRef, userData ) + #pragma unused(callRef, userData) // get menu command HICommand menuCommand; - OSStatus error = GetEventParameter( event, kEventParamDirectObject, typeHICommand, null, sizeof(HICommand), null, &menuCommand ); - if( error ) return eventNotHandledErr; + OSStatus error = GetEventParameter(event, kEventParamDirectObject, typeHICommand, null, sizeof(HICommand), null, &menuCommand); + if(error) return eventNotHandledErr; - switch( menuCommand.commandID ) + switch(menuCommand.commandID) { // application menu case kMenuCommandAbout: @@ -753,8 +759,9 @@ pascal OSStatus CarbonEventParseMenuSelection( EventHandlerCallRef callRef, Even break; case kMenuCommandOpenFile: - if( g.useSheets ) error = DisplayModelessGetFileDialog(); - else error = DisplayOpenDialog(); + if(g.useSheets) + error = DisplayModelessGetFileDialog(); + else error = DisplayOpenDialog(); break; // debug menu @@ -785,61 +792,61 @@ pascal OSStatus CarbonEventParseMenuSelection( EventHandlerCallRef callRef, Even } /*** DEFAULT IDLE TIMER ***/ -pascal void DefaultIdleTimer( EventLoopTimerRef timer, void *data ) +pascal void DefaultIdleTimer(EventLoopTimerRef timer, void *data) { - #pragma unused( timer, data ) + #pragma unused(timer, data) // idle controls (allow cursor blinking) - IdleControls( GetUserFocusWindow() ); // bug: apple should have the control install it's own timer + IdleControls(GetUserFocusWindow()); // bug: apple should have the control install it's own timer // call sound idle routine - if( g.asyncSound && g.callSH ) SHIdle(); + if(g.asyncSound && g.callSH) SHIdle(); } #else /*** UPDATE MENUS ***/ -OSStatus UpdateMenus( WindowRef window ) +OSStatus UpdateMenus(WindowRef window) { - #pragma unused( window ) + #pragma unused(window) OSStatus error = noErr; // disable/checkmark items in the debug menu - MenuRef debugMenu = GetMenuRef( kDebugMenu ); - MenuItemEnable( debugMenu, kDebugMenuAppearanceItem, g.appearanceAvailable ); - MenuItemEnable( debugMenu, kDebugMenuNavServicesItem, g.navAvailable ); - MenuItemEnable( debugMenu, kDebugMenuSheetsItem, false ); - CheckMenuItem( debugMenu, kDebugMenuDebugItem, g.debug ); - CheckMenuItem( debugMenu, kDebugMenuSurpressErrorsItem, g.surpressErrors ); - CheckMenuItem( debugMenu, kDebugMenuAppleEventsItem, g.useAppleEvents ); - CheckMenuItem( debugMenu, kDebugMenuAppearanceItem, g.useAppearance ); - CheckMenuItem( debugMenu, kDebugMenuNavServicesItem, g.useNavServices ); + MenuRef debugMenu = GetMenuRef(kDebugMenu); + MenuItemEnable(debugMenu, kDebugMenuAppearanceItem, g.appearanceAvailable); + MenuItemEnable(debugMenu, kDebugMenuNavServicesItem, g.navAvailable); + MenuItemEnable(debugMenu, kDebugMenuSheetsItem, false); + CheckMenuItem(debugMenu, kDebugMenuDebugItem, g.debug); + CheckMenuItem(debugMenu, kDebugMenuSurpressErrorsItem, g.surpressErrors); + CheckMenuItem(debugMenu, kDebugMenuAppleEventsItem, g.useAppleEvents); + CheckMenuItem(debugMenu, kDebugMenuAppearanceItem, g.useAppearance); + CheckMenuItem(debugMenu, kDebugMenuNavServicesItem, g.useNavServices); return error; } /*** PARSE MENU SELECTION ***/ -OSStatus ParseMenuSelection( UInt16 menu, UInt16 item ) +OSStatus ParseMenuSelection(UInt16 menu, UInt16 item) { // get the frontmost window, in all it's various forms OSStatus error = eventNotHandledErr; WindowRef window = FrontWindow(); WindowObjectPtr winObj = null; FileWindowPtr file = null; - if( window ) + if(window) { - winObj = (WindowObjectPtr) GetWindowRefCon( window ); - if( GetWindowKind( window ) == kFileWindowKind ) + winObj = (WindowObjectPtr) GetWindowRefCon(window); + if(GetWindowKind(window) == kFileWindowKind) file = (FileWindowPtr) winObj; } // do the menu function - if( menu && item ) + if(menu && item) { - switch( menu ) + switch(menu) { case kAppleMenu: - switch( item ) + switch(item) { case kAppleMenuAboutItem: ShowAboutBox(); @@ -847,39 +854,40 @@ OSStatus ParseMenuSelection( UInt16 menu, UInt16 item ) default: // something from "apple menu items" folder Str255 itemName; - MenuHandle appleMenu = GetMenuHandle( kAppleMenu ); - GetMenuItemText( appleMenu, item, itemName ); - OpenDeskAcc( itemName ); + MenuHandle appleMenu = GetMenuHandle(kAppleMenu); + GetMenuItemText(appleMenu, item, itemName); + OpenDeskAcc(itemName); break; } break; case kFileMenu: - switch( item ) + switch(item) { case kFileMenuNewFileItem: new FileWindow; break; case kFileMenuOpenFileItem: - if( g.useNavServices ) DisplayOpenDialog(); - else DisplayStandardFileOpenDialog(); + if(g.useNavServices) + DisplayOpenDialog(); + else DisplayStandardFileOpenDialog(); break; case kFileMenuCloseWindowItem: - if( winObj ) winObj->Close(); + if(winObj) winObj->Close(); break; case kFileMenuQuitItem: AEDescList list = {}; - error = AppleEventSendSelf( kCoreEventClass, kAEQuitApplication, list ); - if( error ) QuitResKnife(); + error = AppleEventSendSelf(kCoreEventClass, kAEQuitApplication, list); + if(error) QuitResKnife(); break; } break; case kEditMenu: -/* switch( item ) +/* switch(item) { case : break; @@ -887,16 +895,16 @@ OSStatus ParseMenuSelection( UInt16 menu, UInt16 item ) */ break; case kResourceMenu: - switch( item ) + switch(item) { case kResourceMenuNewResource: - if( file ) file->DisplayNewResourceDialog(); + if(file) file->DisplayNewResourceDialog(); break; } break; case kDebugMenu: - switch( item ) + switch(item) { case kDebugMenuDebugItem: g.debug = !g.debug; @@ -920,7 +928,7 @@ OSStatus ParseMenuSelection( UInt16 menu, UInt16 item ) } break; } - error = UpdateMenus( FrontWindow() ); + error = UpdateMenus(FrontWindow()); } return error; } @@ -932,82 +940,82 @@ OSStatus ParseMenuSelection( UInt16 menu, UInt16 item ) /****************/ /*** SEND MYSELF AN APPLE EVENT ***/ -OSStatus AppleEventSendSelf( DescType eventClass, DescType eventID, AEDescList list ) +OSStatus AppleEventSendSelf(DescType eventClass, DescType eventID, AEDescList list) { - OSStatus error; - AEAddressDesc myAddress; // all of these are really of type AEDesc - AppleEvent noReply; - AppleEvent event; - - myAddress.descriptorType = typeNull; - myAddress.dataHandle = null; - noReply.descriptorType = typeNull; - noReply.dataHandle = null; + OSStatus error; + AEAddressDesc myAddress; // all of these are really of type AEDesc + AppleEvent noReply; + AppleEvent event; + + myAddress.descriptorType = typeNull; + myAddress.dataHandle = null; + noReply.descriptorType = typeNull; + noReply.dataHandle = null; ProcessSerialNumber psn; - error = GetCurrentProcess( &psn ); - if( error ) return error; + error = GetCurrentProcess(&psn); + if(error) return error; - error = AECreateDesc( typeProcessSerialNumber, &psn, sizeof(ProcessSerialNumber), &myAddress ); - if( error ) return error; + error = AECreateDesc(typeProcessSerialNumber, &psn, sizeof(ProcessSerialNumber), &myAddress); + if(error) return error; - error = AECreateAppleEvent( eventClass, eventID, &myAddress, kAutoGenerateReturnID, kAnyTransactionID, &event ); - if( error ) return error; + error = AECreateAppleEvent(eventClass, eventID, &myAddress, kAutoGenerateReturnID, kAnyTransactionID, &event); + if(error) return error; - error = AEPutParamDesc( &event, keyDirectObject, &list ); - if( error ) return error; + error = AEPutParamDesc(&event, keyDirectObject, &list); + if(error) return error; - error = AESend( &event, &noReply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, null, null ); + error = AESend(&event, &noReply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, null, null); return error; } /*** GOT REQUIRED PARAMS ***/ -Boolean GotRequiredParams( const AppleEvent *event ) +Boolean GotRequiredParams(const AppleEvent *event) { - OSStatus error = noErr; - DescType actualType; - Size actualSize; + OSStatus error = noErr; + DescType actualType; + Size actualSize; // check if we have retrieved the required parameters - error = AEGetAttributePtr( event, keyMissedKeywordAttr, typeWildCard, &actualType, null, 0, &actualSize ); + error = AEGetAttributePtr(event, keyMissedKeywordAttr, typeWildCard, &actualType, null, 0, &actualSize); return error == errAEDescNotFound; } /*** OPEN ***/ -OSStatus AppleEventOpen( const AppleEvent *event ) +OSStatus AppleEventOpen(const AppleEvent *event) { OSStatus error = noErr; // get the list of objects to open - AEDescList list; - AEKeyword aeKeyword; + AEDescList list; + AEKeyword aeKeyword; aeKeyword = keyDirectObject; - error = AEGetParamDesc( event, aeKeyword, typeAEList, &list ); - if( !GotRequiredParams( event ) || error ) return errAEEventNotHandled; + error = AEGetParamDesc(event, aeKeyword, typeAEList, &list); + if(!GotRequiredParams(event) || error) return errAEEventNotHandled; // count how many we have SInt32 itemCount; - error = AECountItems( &list, &itemCount ); - if( error ) return errAEEventNotHandled; + error = AECountItems(&list, &itemCount); + if(error) return errAEEventNotHandled; // open each one - FSSpec fileSpec; - DescType actualType; - Size actualSize; - for( SInt32 n = 1; n <= itemCount; n++ ) + FSSpec fileSpec; + DescType actualType; + Size actualSize; + for(SInt32 n = 1; n <= itemCount; n++) { - error = AEGetNthPtr( &list, n, typeFSS, &aeKeyword, &actualType, (Ptr) &fileSpec, sizeof(FSSpec), &actualSize ); - if( actualType == typeFSS && !error ) new FileWindow( &fileSpec ); + error = AEGetNthPtr(&list, n, typeFSS, &aeKeyword, &actualType, (Ptr) &fileSpec, sizeof(FSSpec), &actualSize); + if(actualType == typeFSS && !error) new FileWindow(&fileSpec); } - AEDisposeDesc( &list ); + AEDisposeDesc(&list); return error; } /*** PRINT ***/ -OSStatus AppleEventPrint( const AppleEvent *event ) +OSStatus AppleEventPrint(const AppleEvent *event) { - #pragma unused( event ) + #pragma unused(event) return errAEEventNotHandled; } @@ -1016,123 +1024,122 @@ OSStatus AppleEventPrint( const AppleEvent *event ) /************************/ /*** SHOW ABOUT BOX ***/ -OSStatus ShowAboutBox( void ) +OSStatus ShowAboutBox(void) { #if TARGET_API_MAC_CARBON #if USE_NIBS // create a nib reference (only searches the application bundle) IBNibRef nibRef = null; - OSStatus error = CreateNibReference( CFSTR("ResKnife"), &nibRef ); - if( error != noErr || nibRef == null ) + OSStatus error = CreateNibReference(CFSTR("ResKnife"), &nibRef); + if(error != noErr || nibRef == null) { - DisplayError( "\pThe nib file reference could not be obtained." ); + DisplayError("\pThe nib file reference could not be obtained."); return error; } // create window WindowRef window; - error = CreateWindowFromNib( nibRef, CFSTR("About Box"), &window ); - if( error != noErr || window == null ) + error = CreateWindowFromNib(nibRef, CFSTR("About Box"), &window); + if(error != noErr || window == null) { - DisplayError( "\pThe about box could not be obtained from the nib file." ); + DisplayError("\pThe about box could not be obtained from the nib file."); return error; } // dispose of nib ref - DisposeNibReference( nibRef ); + DisposeNibReference(nibRef); // show window - ShowWindow( window ); + ShowWindow(window); #else Rect creationBounds; WindowRef window; - SetRect( &creationBounds, 0, 0, 300, 300 ); - OffsetRect( &creationBounds, 50, 50 ); - OSStatus error = CreateNewWindow( kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute | kWindowInWindowMenuAttribute, &creationBounds, &window ); - if( error ) return error; + SetRect(&creationBounds, 0, 0, 300, 300); + OffsetRect(&creationBounds, 50, 50); + OSStatus error = CreateNewWindow(kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute | kWindowInWindowMenuAttribute, &creationBounds, &window); + if(error) return error; ControlRef picControl; ControlButtonContentInfo content; /* content.contentType = kControlContentPictHandle; - content.u.picture = GetPicture( 128 ); - if( content.u.picture == null ) DebugStr("\ppicture == null"); + content.u.picture = GetPicture(128); + if(content.u.picture == null) DebugStr("\ppicture == null"); */ content.contentType = kControlContentPictRes; content.u.resID = 128; - CreatePictureControl( window, &creationBounds, &content, true, &picControl ); -// SetControlData( picControl, kControlPicturePart, kControlPictureHandleTag, sizeof(content.u.picture), content.u.picture ); + CreatePictureControl(window, &creationBounds, &content, true, &picControl); +// SetControlData(picControl, kControlPicturePart, kControlPictureHandleTag, sizeof(content.u.picture), content.u.picture); #endif #else WindowRef window = null; - if( g.useAppearance && g.systemVersion >= kMacOS8 ) - window = GetNewCWindow( kFileWindow8, null, kFirstWindowOfClass ); - else - window = GetNewCWindow( kFileWindow7, null, kFirstWindowOfClass ); - if( window == null ) return paramErr; - PicHandle picture = (PicHandle) GetPicture( 128 ); - SetWindowPic( window, picture ); + if(g.useAppearance && g.systemVersion >= kMacOS8) + window = GetNewCWindow(kFileWindow8, null, kFirstWindowOfClass); + else window = GetNewCWindow(kFileWindow7, null, kFirstWindowOfClass); + if(window == null) return paramErr; + PicHandle picture = (PicHandle) GetPicture(128); + SetWindowPic(window, picture); #endif - ShowWindow( window ); + ShowWindow(window); return noErr; } /*** SHOW PREFERENCES WINDOW ***/ -OSStatus ShowPrefsWindow( void ) +OSStatus ShowPrefsWindow(void) { #if USE_NIBS // create a nib reference (only searches the application bundle) IBNibRef nibRef = null; - OSStatus error = CreateNibReference( CFSTR("ResKnife"), &nibRef ); - if( error != noErr || nibRef == null ) + OSStatus error = CreateNibReference(CFSTR("ResKnife"), &nibRef); + if(error != noErr || nibRef == null) { - DisplayError( "\pThe nib file reference could not be obtained." ); + DisplayError("\pThe nib file reference could not be obtained."); return error; } // create window WindowRef window; - error = CreateWindowFromNib( nibRef, CFSTR("Preferences"), &window ); - if( error != noErr || window == null ) + error = CreateWindowFromNib(nibRef, CFSTR("Preferences"), &window); + if(error != noErr || window == null) { - DisplayError( "\pThe preferences window could not be obtained from the nib file." ); + DisplayError("\pThe preferences window could not be obtained from the nib file."); return error; } // dispose of nib ref - DisposeNibReference( nibRef ); + DisposeNibReference(nibRef); // install tabs handler ControlRef control; ControlID id = { 'tabs', 1 }; - GetControlByID( window, &id, &control ); + GetControlByID(window, &id, &control); EventTypeSpec event = { kEventClassControl, kEventControlHit }; - InstallEventHandler( GetControlEventTarget(control), NewEventHandlerUPP( PrefsTabEventHandler ), 1, &event, &control, null ); + InstallEventHandler(GetControlEventTarget(control), NewEventHandlerUPP(PrefsTabEventHandler), 1, &event, &control, null); // show window - ShowWindow( window ); + ShowWindow(window); #endif return noErr; } /*** PREFS TAB EVENT HANDLER ***/ -pascal OSStatus PrefsTabEventHandler( EventHandlerCallRef handlerRef, EventRef event, void* userData ) +pascal OSStatus PrefsTabEventHandler(EventHandlerCallRef handlerRef, EventRef event, void* userData) { - #pragma unused( handlerRef, event ) + #pragma unused(handlerRef, event) // get tabs control OSStatus error = noErr; ControlRef control = (ControlRef) userData; - SInt16 selectedTab = GetControlValue( control ); - WindowRef window = GetControlOwner( control ); + SInt16 selectedTab = GetControlValue(control); + WindowRef window = GetControlOwner(control); // select correct tab ControlRef currentTab; ControlID id = { 'pane', 1 }; - GetControlByID( window, &id, ¤tTab ); - SetControlVisibility( currentTab, selectedTab == id.id, true ); + GetControlByID(window, &id, ¤tTab); + SetControlVisibility(currentTab, selectedTab == id.id, true); id.id = 2; - GetControlByID( window, &id, ¤tTab ); - SetControlVisibility( currentTab, selectedTab == id.id, true ); + GetControlByID(window, &id, ¤tTab); + SetControlVisibility(currentTab, selectedTab == id.id, true); return error; } diff --git a/Carbon/Classes/Application.h b/Carbon/Classes/Application.h index 2b5fb50..36773e8 100644 --- a/Carbon/Classes/Application.h +++ b/Carbon/Classes/Application.h @@ -15,23 +15,23 @@ /*! @function InitToolbox */ -OSStatus InitToolbox( void ); +OSStatus InitToolbox(void); /*! @function InitMenubar */ -OSStatus InitMenubar( void ); +OSStatus InitMenubar(void); /*! @function InitAppleEvents */ -OSStatus InitAppleEvents( void ); +OSStatus InitAppleEvents(void); /*! @function InitCarbonEvents */ -OSStatus InitCarbonEvents( void ); +OSStatus InitCarbonEvents(void); /*! @function InitGlobals */ -OSStatus InitGlobals( void ); +OSStatus InitGlobals(void); /*****************/ /* EVENT PARSING */ @@ -42,22 +42,22 @@ OSStatus InitGlobals( void ); /*! @function ParseEvents */ -OSStatus ParseEvents( EventRecord *event ); +OSStatus ParseEvents(EventRecord *event); /*! @function ParseDialogEvents */ -pascal Boolean ParseDialogEvents( DialogPtr dialog, EventRecord *event, DialogItemIndex *itemHit ); +pascal Boolean ParseDialogEvents(DialogPtr dialog, EventRecord *event, DialogItemIndex *itemHit); /*! @function ParseOSEvents */ -OSStatus ParseOSEvents( EventRecord *event ); +OSStatus ParseOSEvents(EventRecord *event); #endif /*! @function ParseAppleEvents */ -pascal OSErr ParseAppleEvents( const AppleEvent *event, AppleEvent *reply, SInt32 refCon ); +pascal OSErr ParseAppleEvents(const AppleEvent *event, AppleEvent *reply, SInt32 refCon); /******************/ /* EVENT HANDLING */ @@ -68,42 +68,42 @@ pascal OSErr ParseAppleEvents( const AppleEvent *event, AppleEvent *reply, SInt /*! @function MouseDownEventOccoured */ -OSStatus MouseDownEventOccoured( EventRecord *event ); +OSStatus MouseDownEventOccoured(EventRecord *event); /*! @function MouseUpEventOccoured */ -OSStatus MouseUpEventOccoured( EventRecord *event ); +OSStatus MouseUpEventOccoured(EventRecord *event); /*! @function KeyDownEventOccoured */ -OSStatus KeyDownEventOccoured( EventRecord *event ); +OSStatus KeyDownEventOccoured(EventRecord *event); /*! @function KeyRepeatEventOccoured */ -OSStatus KeyRepeatEventOccoured( EventRecord *event ); +OSStatus KeyRepeatEventOccoured(EventRecord *event); /*! @function KeyUpEventOccoured */ -OSStatus KeyUpEventOccoured( EventRecord *event ); +OSStatus KeyUpEventOccoured(EventRecord *event); /*! @function UpdateEventOccoured */ -OSStatus UpdateEventOccoured( EventRecord *event ); +OSStatus UpdateEventOccoured(EventRecord *event); /*! @function ActivateEventOccoured */ -OSStatus ActivateEventOccoured( EventRecord *event ); +OSStatus ActivateEventOccoured(EventRecord *event); /*! @function IdleEvent */ -OSStatus IdleEvent( void ); +OSStatus IdleEvent(void); #endif /*! @function QuitResKnife */ -void QuitResKnife( void ); +void QuitResKnife(void); /*****************/ /* MENU HANDLING */ @@ -114,26 +114,26 @@ void QuitResKnife( void ); /*! @function CarbonEventUpdateMenus */ -pascal OSStatus CarbonEventUpdateMenus( EventHandlerCallRef callRef, EventRef event, void *userData ); +pascal OSStatus CarbonEventUpdateMenus(EventHandlerCallRef callRef, EventRef event, void *userData); /*! @function CarbonEventParseMenuSelection */ -pascal OSStatus CarbonEventParseMenuSelection( EventHandlerCallRef callRef, EventRef event, void *userData ); +pascal OSStatus CarbonEventParseMenuSelection(EventHandlerCallRef callRef, EventRef event, void *userData); /*! @function DefaultIdleTimer */ -pascal void DefaultIdleTimer( EventLoopTimerRef timer, void *data ); +pascal void DefaultIdleTimer(EventLoopTimerRef timer, void *data); #else /*! @function UpdateMenus */ -OSStatus UpdateMenus( WindowRef window ); +OSStatus UpdateMenus(WindowRef window); /*! @function ParseMenuSelection */ -OSStatus ParseMenuSelection( UInt16 menu, UInt16 item ); +OSStatus ParseMenuSelection(UInt16 menu, UInt16 item); #endif @@ -144,19 +144,19 @@ OSStatus ParseMenuSelection( UInt16 menu, UInt16 item ); /*! @function AppleEventSendSelf */ -OSStatus AppleEventSendSelf( DescType eventClass, DescType eventID, AEDescList list ); +OSStatus AppleEventSendSelf(DescType eventClass, DescType eventID, AEDescList list); /*! @function GotRequiredParams */ -Boolean GotRequiredParams( const AppleEvent *event ); +Boolean GotRequiredParams(const AppleEvent *event); /*! @function AppleEventOpen */ -OSStatus AppleEventOpen( const AppleEvent *event ); +OSStatus AppleEventOpen(const AppleEvent *event); /*! @function AppleEventPrint */ -OSStatus AppleEventPrint( const AppleEvent *event ); +OSStatus AppleEventPrint(const AppleEvent *event); /*********************/ /* NIBÑBASED WINDOWS */ @@ -165,14 +165,14 @@ OSStatus AppleEventPrint( const AppleEvent *event ); /*! @function ShowAboutBox */ -OSStatus ShowAboutBox( void ); +OSStatus ShowAboutBox(void); /*! @function ShowPrefsWindow */ -OSStatus ShowPrefsWindow( void ); +OSStatus ShowPrefsWindow(void); /*! @function PrefsTabEventHandler */ -pascal OSStatus PrefsTabEventHandler( EventHandlerCallRef handlerRef, EventRef event, void* userData ); +pascal OSStatus PrefsTabEventHandler(EventHandlerCallRef handlerRef, EventRef event, void* userData); #endif \ No newline at end of file diff --git a/Carbon/Classes/Asynchronous.cpp b/Carbon/Classes/Asynchronous.cpp index 597fd0b..cb5741a 100644 --- a/Carbon/Classes/Asynchronous.cpp +++ b/Carbon/Classes/Asynchronous.cpp @@ -15,22 +15,22 @@ static SICompletionUPP gsSHRecordCompletionUPP; // UPP for SIRecordCompletion (B //======================================================================================= // Static prototypes //======================================================================================= -static long SHNewRefNum( void ); -static OSErr SHNewOutRec( SHOutPtr *outRec ); -static pascal void SHPlayCompletion( SndChannelPtr channel, SndCommand *command ); -static pascal void SHRecordCompletion( SPBPtr inParams ); -static OSErr SHInitOutRec( SHOutPtr outRec, long refNum, Handle sound, char handleState ); -static void SHReleaseOutRec( SHOutPtr outRec ); -static OSErr SHQueueCallback( SndChannel *channel ); -static OSErr SHBeginPlayback( SHOutPtr outRec ); -static char SHGetState( Handle snd ); -static SHOutPtr SHOutRecFromRefNum( long refNum ); -static void SHPlayStopByRec( SHOutPtr outRec ); -static OSErr SHGetDeviceSettings( long inRefNum, short *numChannels, Fixed *sampleRate, short *sampleSize, OSType *compType ); +static long SHNewRefNum(void); +static OSErr SHNewOutRec(SHOutPtr *outRec); +static pascal void SHPlayCompletion(SndChannelPtr channel, SndCommand *command); +static pascal void SHRecordCompletion(SPBPtr inParams); +static OSErr SHInitOutRec(SHOutPtr outRec, long refNum, Handle sound, char handleState); +static void SHReleaseOutRec(SHOutPtr outRec); +static OSErr SHQueueCallback(SndChannel *channel); +static OSErr SHBeginPlayback(SHOutPtr outRec); +static char SHGetState(Handle snd); +static SHOutPtr SHOutRecFromRefNum(long refNum); +static void SHPlayStopByRec(SHOutPtr outRec); +static OSErr SHGetDeviceSettings(long inRefNum, short *numChannels, Fixed *sampleRate, short *sampleSize, OSType *compType); //======================================================================================= // -// pascal OSErr SHInitSoundHelper( Boolean *attnFlag, short numChannels ) +// pascal OSErr SHInitSoundHelper(Boolean *attnFlag, short numChannels) // // Summary: // This routine initializes the Asynchronous Sound Helper. @@ -62,12 +62,12 @@ static OSErr SHGetDeviceSettings( long inRefNum, short *numChannels, Fixed *samp // sets a flag that tells whether the Helper has been initialized. // //======================================================================================= -pascal OSErr SHInitSoundHelper( Boolean *attnFlag, short numChannels ) +pascal OSErr SHInitSoundHelper(Boolean *attnFlag, short numChannels) { OSErr error = noErr; // Use default number of channels if zero was specified - if( numChannels == 0 ) + if(numChannels == 0) numChannels = kSHDefChannels; // Remember the address of the application's "attention" flag @@ -75,23 +75,23 @@ pascal OSErr SHInitSoundHelper( Boolean *attnFlag, short numChannels ) // Allocate the channels gsSHOutVars.numOutRecs = numChannels; - gsSHOutVars.outArray = (SHOutPtr) NewPtrClear( numChannels * sizeof(SHOutRec) ); + gsSHOutVars.outArray = (SHOutPtr) NewPtrClear(numChannels * sizeof(SHOutRec)); // Set up UPPs for play completion and input completion - gsSHPlayCompletionUPP = NewSndCallBackUPP( SHPlayCompletion ); - gsSHRecordCompletionUPP = NewSICompletionUPP( SHRecordCompletion ); + gsSHPlayCompletionUPP = NewSndCallBackUPP(SHPlayCompletion); + gsSHRecordCompletionUPP = NewSICompletionUPP(SHRecordCompletion); // If successful, flag that we're initialized and exit - if( gsSHOutVars.outArray != nil ) + if(gsSHOutVars.outArray != nil) { gsSHInited = true; return error; } else { - // Return some kind of error (MemError if there is one, otherwise make one up ) + // Return some kind of error (MemError if there is one, otherwise make one up) error = MemError(); - if( error == noErr ) + if(error == noErr) error = memFullErr; return error; } @@ -99,7 +99,7 @@ pascal OSErr SHInitSoundHelper( Boolean *attnFlag, short numChannels ) //======================================================================================= // -// pascal void SHIdle( void ) +// pascal void SHIdle(void) // // Summary: // This routine performs various cleanup operations when sounds have finished @@ -131,7 +131,7 @@ pascal OSErr SHInitSoundHelper( Boolean *attnFlag, short numChannels ) // notified that recording is complete through his Boolean completion flag. // //======================================================================================= -pascal void SHIdle( void ) +pascal void SHIdle(void) { OSErr error = noErr; long realSize; @@ -140,23 +140,23 @@ pascal void SHIdle( void ) *gsSHNeedsTime = false; // Do playback cleanup - for( short i = 0; i < gsSHOutVars.numOutRecs; i++ ) - if( gsSHOutVars.outArray[i].inUse && - gsSHOutVars.outArray[i].channel.userInfo == kSHComplete ) + for(short i = 0; i < gsSHOutVars.numOutRecs; i++) + if(gsSHOutVars.outArray[i].inUse && + gsSHOutVars.outArray[i].channel.userInfo == kSHComplete) // We've found a channel that needs closing... - SHReleaseOutRec( &gsSHOutVars.outArray[i] ); + SHReleaseOutRec(&gsSHOutVars.outArray[i]); // Do recording cleaunp - if( gsSHInVars.recording && gsSHInVars.recordComplete ) + if(gsSHInVars.recording && gsSHInVars.recordComplete) { - HUnlock( gsSHInVars.inHandle ); + HUnlock(gsSHInVars.inHandle); - if( gsSHInVars.inPB.error && gsSHInVars.inPB.error != abortErr ) + if(gsSHInVars.inPB.error && gsSHInVars.inPB.error != abortErr) { // An error (other than a manual stop) occurred during recording. Kill the // handle and save the error code. gsSHInVars.recordErr = gsSHInVars.inPB.error; - DisposeHandle( gsSHInVars.inHandle ); + DisposeHandle(gsSHInVars.inHandle); gsSHInVars.inHandle = nil; } else @@ -168,26 +168,26 @@ pascal void SHIdle( void ) // size -- that's why we don't bother checking the error). gsSHInVars.recordErr = noErr; realSize = gsSHInVars.inPB.count + gsSHInVars.headerLength; - error = SetupSndHeader( (SndListHandle) gsSHInVars.inHandle, gsSHInVars.numChannels, + error = SetupSndHeader((SndListHandle) gsSHInVars.inHandle, gsSHInVars.numChannels, gsSHInVars.sampleRate, gsSHInVars.sampleSize, gsSHInVars.compType, - kSHBaseNote, realSize, &gsSHInVars.headerLength ); - SetHandleSize( gsSHInVars.inHandle, realSize ); // Shorten the handle + kSHBaseNote, realSize, &gsSHInVars.headerLength); + SetHandleSize(gsSHInVars.inHandle, realSize); // Shorten the handle } // Error or not, close the recording device, and notify the application that // recording is complete, through the recording-completed flag that the caller // originally passed into SHRecordStart. - SPBCloseDevice( gsSHInVars.inRefNum ); + SPBCloseDevice(gsSHInVars.inRefNum); gsSHInVars.recording = false; gsSHInVars.inRefNum = 0; - if( gsSHInVars.appComplete != nil ) + if(gsSHInVars.appComplete != nil) *gsSHInVars.appComplete = true; } } //======================================================================================= // -// pascal void SHKillSoundHelper( void ) +// pascal void SHKillSoundHelper(void) // // Summary: // This routine terminates the Asynchronous Sound Helper. @@ -210,12 +210,12 @@ pascal void SHIdle( void ) // output records. // //======================================================================================= -pascal void SHKillSoundHelper( void ) +pascal void SHKillSoundHelper(void) { unsigned long timeout; Boolean outputClean, inputClean; - if( !gsSHInited ) + if(!gsSHInited) return; SHPlayStopAll(); // Kill all playback @@ -224,29 +224,29 @@ pascal void SHKillSoundHelper( void ) // Now sync-wait for everything to clean itself up timeout = TickCount() + kSHSyncWaitTimeout; do { - if( *gsSHNeedsTime ) + if(*gsSHNeedsTime) SHIdle(); // Clean up when required // Check if all our output channels are cleaned up outputClean = true; - for( short i = 0; i < gsSHOutVars.numOutRecs && outputClean; i++ ) - if( gsSHOutVars.outArray[i].inUse ) + for(short i = 0; i < gsSHOutVars.numOutRecs && outputClean; i++) + if(gsSHOutVars.outArray[i].inUse) outputClean = false; // Check whether our recording is cleaned up inputClean = !gsSHInVars.recording; - if( inputClean && outputClean ) + if(inputClean && outputClean) break; - } while (TickCount() < timeout ); + } while (TickCount() < timeout); // Lose our preallocated sound channels - DisposePtr( (Ptr) gsSHOutVars.outArray ); + DisposePtr((Ptr) gsSHOutVars.outArray); } //======================================================================================= // -// long SHNewRefNum( void ) +// long SHNewRefNum(void) // // Summary: // This routine returns the next available output reference number. @@ -266,14 +266,14 @@ pascal void SHKillSoundHelper( void ) // erence numbers are unique throughout a session (modulo 2,147,483,647). // //======================================================================================= -long SHNewRefNum( void ) +long SHNewRefNum(void) { return gsSHOutVars.nextRef++; } //======================================================================================= // -// OSErr SHNewOutRec( SHOutPtr *outRec ) +// OSErr SHNewOutRec(SHOutPtr *outRec) // // Summary: // This routine attempts to return the first available output record. @@ -296,11 +296,11 @@ long SHNewRefNum( void ) // the record is stored via the VAR parameter, and noErr is returned. // //======================================================================================= -OSErr SHNewOutRec( SHOutPtr *outRec ) +OSErr SHNewOutRec(SHOutPtr *outRec) { // First look for a free channel among our preallocated output records - for( short i = 0; i < gsSHOutVars.numOutRecs; i++ ) - if( !gsSHOutVars.outArray[i].inUse ) + for(short i = 0; i < gsSHOutVars.numOutRecs; i++) + if(!gsSHOutVars.outArray[i].inUse) { *outRec = &gsSHOutVars.outArray[i]; return noErr; @@ -311,7 +311,7 @@ OSErr SHNewOutRec( SHOutPtr *outRec ) //======================================================================================= // -// pascal void SHPlayCompletion( SndChannelPtr channel, SndCommand *command ) +// pascal void SHPlayCompletion(SndChannelPtr channel, SndCommand *command) // // Summary: // This routine is the playback callback routine we provide to the Sound Manager. @@ -343,10 +343,10 @@ OSErr SHNewOutRec( SHOutPtr *outRec ) // freed. // //======================================================================================= -pascal void SHPlayCompletion( SndChannelPtr channel, SndCommand *command ) +pascal void SHPlayCompletion(SndChannelPtr channel, SndCommand *command) { // Look for our "callback signature" in the sound command. - if( command->param1 == kSHCompleteSig ) + if(command->param1 == kSHCompleteSig) { channel->userInfo = kSHComplete; *gsSHNeedsTime = true; // Tell the app to give us an SHIdle call @@ -355,7 +355,7 @@ pascal void SHPlayCompletion( SndChannelPtr channel, SndCommand *command ) //======================================================================================= // -// pascal void SHRecordCompletion( SPBPtr inParams ) +// pascal void SHRecordCompletion(SPBPtr inParams) // // Summary: // This routine is the recording callback routine we provide to the Sound Manager. @@ -376,19 +376,19 @@ pascal void SHPlayCompletion( SndChannelPtr channel, SndCommand *command ) // routine first grabs A5 from the SPB's userLong field and sets us up to use our // globals. Then, it sets the application's "Helper needs time" Boolean, and sets // our internal flag that recording has completed (so SHIdle will know to close the -// recording device, etc. ) +// recording device, etc.) // //======================================================================================= -pascal void SHRecordCompletion( SPBPtr inParams ) +pascal void SHRecordCompletion(SPBPtr inParams) { - #pragma unused( inParams ) + #pragma unused(inParams) *gsSHNeedsTime = true; // Notify the app to give us time gsSHInVars.recordComplete = true; // Make a note to ourselves, too } //======================================================================================= // -// OSErr SHInitOutRec( SHOutPtr outRec, long refNum, Handle sound, char handleState ) +// OSErr SHInitOutRec(SHOutPtr outRec, long refNum, Handle sound, char handleState) // // Summary: // This routine is used to fill out an SHOutRec and call SndNewChannel. @@ -420,19 +420,19 @@ pascal void SHRecordCompletion( SPBPtr inParams ) // SHPlayCompletion, to SndNewChannel. // //======================================================================================= -OSErr SHInitOutRec( SHOutPtr outRec, long refNum, Handle sound, char handleState ) +OSErr SHInitOutRec(SHOutPtr outRec, long refNum, Handle sound, char handleState) { OSErr error; SndChannelPtr channel; // Initialize the sound channel inside outRec. We'll clear the bytes to zero, // install the proper queue size, then call SndNewChannel. - for( unsigned short i = 0; i < sizeof(SndChannel); i++ ) + for(unsigned short i = 0; i < sizeof(SndChannel); i++) ((char *) &outRec->channel)[i] = 0; outRec->channel.qLength = stdQLength; channel = &outRec->channel; - error = SndNewChannel( &channel, kSHNoSynth, kSHNoInit, gsSHPlayCompletionUPP ); - if( error != noErr ) + error = SndNewChannel(&channel, kSHNoSynth, kSHNoInit, gsSHPlayCompletionUPP); + if(error != noErr) return error; // Initialize the rest of the record and return noErr. Note that we only set the @@ -448,7 +448,7 @@ OSErr SHInitOutRec( SHOutPtr outRec, long refNum, Handle sound, char handleState //======================================================================================= // -// void SHReleaseOutRec( SHOutPtr outRec ) +// void SHReleaseOutRec(SHOutPtr outRec) // // Summary: // This routine "releases," or frees up an output record. @@ -471,27 +471,27 @@ OSErr SHInitOutRec( SHOutPtr outRec, long refNum, Handle sound, char handleState // inUse flag, thereby allowing it to be reused. // //======================================================================================= -void SHReleaseOutRec( SHOutPtr outRec ) +void SHReleaseOutRec(SHOutPtr outRec) { Boolean found = false; // An SHOutRec's inUse flag only gets set if SndNewChannel has been called on the // record's sound channel. So if it is in use, we try a call to SndDisposeChannel, - // and ignore the error (what else can we do? ) - if( outRec->inUse ) - SndDisposeChannel( &outRec->channel, kSHQuietNow ); + // and ignore the error (what else can we do?) + if(outRec->inUse) + SndDisposeChannel(&outRec->channel, kSHQuietNow); // If this sound handle isn't being used by some other output record, kindly restore // the original handle state. - if( outRec->sound != nil ) + if(outRec->sound != nil) { - for( short i = 0; i < gsSHOutVars.numOutRecs && !found; i++ ) - if( &gsSHOutVars.outArray[i] != outRec && gsSHOutVars.outArray[i].inUse && - gsSHOutVars.outArray[i].sound == outRec->sound ) + for(short i = 0; i < gsSHOutVars.numOutRecs && !found; i++) + if(&gsSHOutVars.outArray[i] != outRec && gsSHOutVars.outArray[i].inUse && + gsSHOutVars.outArray[i].sound == outRec->sound) found = true; - if( !found ) - HSetState( outRec->sound,outRec->handleState ); + if(!found) + HSetState(outRec->sound,outRec->handleState); } outRec->inUse = false; @@ -499,7 +499,7 @@ void SHReleaseOutRec( SHOutPtr outRec ) //======================================================================================= // -// OSErr SHQueueCallback( SndChannel *channel ) +// OSErr SHQueueCallback(SndChannel *channel) // // Summary: // This routine queues up a verifyable callback in the given sound channel. @@ -522,7 +522,7 @@ void SHReleaseOutRec( SHOutPtr outRec ) // in param2. // //======================================================================================= -OSErr SHQueueCallback( SndChannel *channel ) +OSErr SHQueueCallback(SndChannel *channel) { SndCommand command; @@ -530,12 +530,12 @@ OSErr SHQueueCallback( SndChannel *channel ) command.param1 = kSHCompleteSig; // To make the callback verifyable. command.param2 = 0L; - return SndDoCommand( channel, &command, kSHWait ); + return SndDoCommand(channel, &command, kSHWait); } //======================================================================================= // -// OSErr SHBeginPlayback(SHOutPtr outRec ) +// OSErr SHBeginPlayback(SHOutPtr outRec) // // Summary: // This routine begins playback of the sound that's installed in the given SHOutRec. @@ -569,24 +569,24 @@ OSErr SHQueueCallback( SndChannel *channel ) // then call SHGetChannel to retrieve a pointer to the channel. // //======================================================================================= -OSErr SHBeginPlayback( SHOutPtr outRec ) +OSErr SHBeginPlayback(SHOutPtr outRec) { OSErr error = noErr; // First, initiate playback. If an error occurs, return it immediately. - error = SndPlay( &outRec->channel, (SndListHandle)outRec->sound, kSHAsync ); - if( error != noErr ) + error = SndPlay(&outRec->channel, (SndListHandle)outRec->sound, kSHAsync); + if(error != noErr) return error; // Playback started okay. Let's queue up a callback command so we'll know when // the sound is finished. - SHQueueCallback( &outRec->channel ); // ignore error (what can we do? ) + SHQueueCallback(&outRec->channel); // ignore error (what can we do?) return error; } //======================================================================================= // -// char SHGetState( Handle snd ) +// char SHGetState(Handle snd) // // Summary: // This routine is a local replacement for HGetState which tries to find snd in an @@ -617,12 +617,12 @@ OSErr SHBeginPlayback( SHOutPtr outRec ) // when the sound has completed. // //======================================================================================= -char SHGetState( Handle snd ) +char SHGetState(Handle snd) { // Look for an output record that has snd for a sound. If one is found, grab and // return its handleState instead of the handle's current flags. - for( short i = 0; i < gsSHOutVars.numOutRecs; i++ ) - if( gsSHOutVars.outArray[i].inUse && gsSHOutVars.outArray[i].sound == snd ) + for(short i = 0; i < gsSHOutVars.numOutRecs; i++) + if(gsSHOutVars.outArray[i].inUse && gsSHOutVars.outArray[i].sound == snd) return gsSHOutVars.outArray[i].handleState; return HGetState(snd); @@ -630,7 +630,7 @@ char SHGetState( Handle snd ) //======================================================================================= // -// pascal OSErr SHPlayByID( short resID, long *refNum ) +// pascal OSErr SHPlayByID(short resID, long *refNum) // // Summary: // This routine begins asynchronous playback of the 'snd ' resource with ID resID. @@ -671,7 +671,7 @@ char SHGetState( Handle snd ) // for SHPlayByHandle and SHBeginPlayback. // //======================================================================================= -pascal OSErr SHPlayByID( short resID, long *refNum ) +pascal OSErr SHPlayByID(short resID, long *refNum) { Handle sound; char oldhandleState; @@ -684,50 +684,50 @@ pascal OSErr SHPlayByID( short resID, long *refNum ) // is because some of the Sound Manager stuff below may cause memory allocation, // which could cause the sound to be purged. We don't want that, since we're // going to start playing it real soon. - sound = GetResource( soundListRsrc, resID ); - if( sound == nil ) + sound = GetResource(soundListRsrc, resID); + if(sound == nil) { error = ResError(); - if( error == noErr ) + if(error == noErr) error = resNotFound; return error; } - oldhandleState = SHGetState(sound ); - HNoPurge(sound ); + oldhandleState = SHGetState(sound); + HNoPurge(sound); // Now let's get a reference number and an output record. ref = SHNewRefNum(); - error = SHNewOutRec( &outRec ); - if( error != noErr ) + error = SHNewOutRec(&outRec); + if(error != noErr) { - HSetState( sound, oldhandleState ); + HSetState(sound, oldhandleState); return error; } // Now let's fill in the output record with all the pertinent information. This // routine also initializes the sound channel and flags outRec as "in use." - error = SHInitOutRec(outRec, ref, sound, oldhandleState ); - if( error != noErr ) + error = SHInitOutRec(outRec, ref, sound, oldhandleState); + if(error != noErr) { - HSetState( sound, oldhandleState ); - SHReleaseOutRec( outRec ); + HSetState(sound, oldhandleState); + SHReleaseOutRec(outRec); return error; } // At this point, we're in pretty good shape. We've got a reference number, an // initialized output record, and the sound handle. Let's party. - MoveHHi( sound ); - HLock( sound ); - error = SHBeginPlayback( outRec ); - if( error != noErr ) + MoveHHi(sound); + HLock(sound); + error = SHBeginPlayback(outRec); + if(error != noErr) { - HSetState( sound, oldhandleState ); - SHReleaseOutRec( outRec ); + HSetState(sound, oldhandleState); + SHReleaseOutRec(outRec); return error; } else { - if( refNum != nil ) // refNum is optional -- the caller may not want it + if(refNum != nil ) // refNum is optional -- the caller may not want it *refNum = ref; return error; } @@ -735,7 +735,7 @@ pascal OSErr SHPlayByID( short resID, long *refNum ) //======================================================================================= // -// pascal OSErr SHPlayByHandle( Handle sound, long *refNum ) +// pascal OSErr SHPlayByHandle(Handle sound, long *refNum) // // Summary: // This routine begins asynchronous playback of a sound provided in a handle. @@ -775,7 +775,7 @@ pascal OSErr SHPlayByID( short resID, long *refNum ) // See the comments for SHBeginPlayback. // //======================================================================================= -pascal OSErr SHPlayByHandle( Handle sound, long *refNum ) +pascal OSErr SHPlayByHandle(Handle sound, long *refNum) { char oldhandleState; short ref; @@ -788,56 +788,56 @@ pascal OSErr SHPlayByHandle( Handle sound, long *refNum ) // it real soon. If the caller gave us nil for a sound handle, that means he's // really just interested in having the sound channel. So, we go on our merrory way // without a sound handle. - if( sound != nil ) + if(sound != nil) { - oldhandleState = SHGetState( sound ); - HNoPurge(sound ); + oldhandleState = SHGetState(sound); + HNoPurge(sound); } else oldhandleState = 0; // Now, let's get a reference number and an output record. ref = SHNewRefNum(); - error = SHNewOutRec( &outRec ); - if( error != noErr ) + error = SHNewOutRec(&outRec); + if(error != noErr) { - if( sound != nil ) - HSetState( sound, oldhandleState ); + if(sound != nil) + HSetState(sound, oldhandleState); return error; } // Now let's fill in the output record with all the pertinent information. This // routine also initializes the sound channel and flags outRec as "in use." - error = SHInitOutRec( outRec, ref, sound, oldhandleState ); - if( error != noErr ) + error = SHInitOutRec(outRec, ref, sound, oldhandleState); + if(error != noErr) { - if( sound != nil ) - HSetState( sound, oldhandleState ); - SHReleaseOutRec( outRec ); + if(sound != nil) + HSetState(sound, oldhandleState); + SHReleaseOutRec(outRec); return error; } // At this point, we're in pretty good shape. We've got a reference number, an // initialized output record, and the sound handle. Let's get whacky. - if( sound != nil ) + if(sound != nil) { // if we've got a sound, lock and begin playback - MoveHHi( sound ); - HLock( sound ); - error = SHBeginPlayback( outRec ); - if( error != noErr ) + MoveHHi(sound); + HLock(sound); + error = SHBeginPlayback(outRec); + if(error != noErr) { - HSetState( sound, oldhandleState ); - SHReleaseOutRec( outRec ); + HSetState(sound, oldhandleState); + SHReleaseOutRec(outRec); return error; } else { - if( refNum != nil ) // refNum is optional - the caller may not want it + if(refNum != nil) // refNum is optional - the caller may not want it *refNum = ref; return error; } } else { // if there's no sound, go ahead and return noErr - if( refNum != nil ) // refNum is optional - the caller may not want it + if(refNum != nil) // refNum is optional - the caller may not want it *refNum = ref; return error; } @@ -845,7 +845,7 @@ pascal OSErr SHPlayByHandle( Handle sound, long *refNum ) //======================================================================================= // -// SHOutPtr SHOutRecFromRefNum( long refNum ) +// SHOutPtr SHOutRecFromRefNum(long refNum) // // Summary: // This routine finds that SHOutRec that is associated with a given refNum, if any. @@ -866,24 +866,24 @@ pascal OSErr SHPlayByHandle( Handle sound, long *refNum ) // returned. If not, then nil is returned. // //======================================================================================= -SHOutPtr SHOutRecFromRefNum( long refNum ) +SHOutPtr SHOutRecFromRefNum(long refNum) { short i; // Search for the specified refNum - for( i = 0; i < gsSHOutVars.numOutRecs; i++ ) - if( gsSHOutVars.outArray[i].inUse && gsSHOutVars.outArray[i].refNum == refNum ) + for(i = 0; i < gsSHOutVars.numOutRecs; i++) + if(gsSHOutVars.outArray[i].inUse && gsSHOutVars.outArray[i].refNum == refNum) break; // If we found it, return a pointer to that record, otherwise, nil. - if( i == gsSHOutVars.numOutRecs ) + if(i == gsSHOutVars.numOutRecs) return nil; else return &gsSHOutVars.outArray[i]; } //======================================================================================= // -// void SHPlayStopByRec( SHOutPtr outRec ) +// void SHPlayStopByRec(SHOutPtr outRec) // // Summary: // This routine stops sound playback on the channel associated with the given @@ -907,7 +907,7 @@ SHOutPtr SHOutRecFromRefNum( long refNum ) // commands are just eaten by the Sound Manager. // //======================================================================================= -void SHPlayStopByRec( SHOutPtr outRec ) +void SHPlayStopByRec(SHOutPtr outRec) { SndCommand cmd; @@ -915,22 +915,22 @@ void SHPlayStopByRec( SHOutPtr outRec ) cmd.cmd = flushCmd; cmd.param1 = 0; cmd.param2 = 0; - SndDoImmediate( &outRec->channel, &cmd ); + SndDoImmediate(&outRec->channel, &cmd); // Shut up this minute! Go to your room! No dessert tonight for you, little boy. cmd.cmd = quietCmd; cmd.param1 = 0; cmd.param2 = 0; - SndDoImmediate( &outRec->channel, &cmd ); + SndDoImmediate(&outRec->channel, &cmd); // It is now safe to just manually dump our channel (we'll just skip the whole // callback thing in this case). - SHReleaseOutRec( outRec ); + SHReleaseOutRec(outRec); } //======================================================================================= // -// pascal OSErr SHPlayStop( long refNum ) +// pascal OSErr SHPlayStop(long refNum) // // Summary: // This routine stops playback on the output record referrored to by refNum. @@ -946,7 +946,7 @@ void SHPlayStopByRec( SHOutPtr outRec ) // record. (Note that this is not necessarily bad. If they // try to stop a sound that has already stopped by its own // accord, this error will be returned. Usually you can call -// this routine and ignore the error. ) +// this routine and ignore the error.) // noErr Otherwise. // // Operation: @@ -955,17 +955,17 @@ void SHPlayStopByRec( SHOutPtr outRec ) // playback for that output record. // //======================================================================================= -pascal OSErr SHPlayStop( long refNum ) +pascal OSErr SHPlayStop(long refNum) { SHOutPtr outRec; // Look for the associated output record. - outRec = SHOutRecFromRefNum( refNum ); + outRec = SHOutRecFromRefNum(refNum); // If we found it, call SHPlayStopByRec to stop playback. - if( outRec != nil ) + if(outRec != nil) { - SHPlayStopByRec( outRec ); + SHPlayStopByRec(outRec); return noErr; } else return kSHErrBadRefNum; @@ -973,7 +973,7 @@ pascal OSErr SHPlayStop( long refNum ) //======================================================================================= // -// pascal OSErr SHPlayStopAll( void ) +// pascal OSErr SHPlayStopAll(void) // // Summary: // This routine stops all sound that the Helper initiated. @@ -993,20 +993,20 @@ pascal OSErr SHPlayStop( long refNum ) // by calling SHPlayStopByRec. Errors are ignored. // //======================================================================================= -pascal OSErr SHPlayStopAll( void ) +pascal OSErr SHPlayStopAll(void) { // Look for output records that are in use and stop their playback with // SHPlayStopByRec. - for( short i = 0; i < gsSHOutVars.numOutRecs; i++ ) - if( gsSHOutVars.outArray[i].inUse ) - SHPlayStopByRec( &gsSHOutVars.outArray[i] ); + for(short i = 0; i < gsSHOutVars.numOutRecs; i++) + if(gsSHOutVars.outArray[i].inUse) + SHPlayStopByRec(&gsSHOutVars.outArray[i]); return noErr; } //======================================================================================= // -// pascal OSErr SHPlayPause( long refNum ) +// pascal OSErr SHPlayPause(long refNum) // // Summary: // This routine pauses playback of sound associated with refNum. @@ -1047,39 +1047,39 @@ pascal OSErr SHPlayStopAll( void ) // If the sound was successfully paused, the output record's paused flag is set. // //======================================================================================= -pascal OSErr SHPlayPause( long refNum ) +pascal OSErr SHPlayPause(long refNum) { SHOutPtr outRec; SndCommand cmd; OSErr error; - outRec = SHOutRecFromRefNum(refNum ); - if( outRec != nil ) + outRec = SHOutRecFromRefNum(refNum); + if(outRec != nil) { // Don't bother with this if we're already paused. - if( outRec->paused ) + if(outRec->paused) return kSHErrAlreadyPaused; // Get the current playback rate for this sound. /* cmd.cmd = getRateCmd; cmd.param1 = 0; cmd.param2 = (long) &outRec->rate; - error = SndDoImmediate( &outRec->channel, &cmd ); - if( error != noErr ) + error = SndDoImmediate(&outRec->channel, &cmd); + if(error != noErr) return error; */ // Now pause with either a rateCmd or a pauseCmd, as appropriate cmd.param1 = 0; cmd.param2 = 0; -/* if( outRec->rate != 0 ) +/* if(outRec->rate != 0) { // If we get something non-zero, it's safe to assume that whatever // synthesizer we're talking to will be able to understand a rateCmd to // restore the rate (probably the sampled synthesizer). To pause the // sound, we'll set the rate to zero. cmd.cmd = rateCmd; - error = SndDoImmediate( &outRec->channel, &cmd ); - if( error != noErr ) + error = SndDoImmediate(&outRec->channel, &cmd); + if(error != noErr) return error; } else @@ -1088,8 +1088,8 @@ pascal OSErr SHPlayPause( long refNum ) // pause command queue processing with a pauseCmd. This is how command-type // sounds (e.g. Simple Beep) are paused. cmd.cmd = pauseCmd; - error = SndDoImmediate( &outRec->channel, &cmd ); - if( error != noErr ) + error = SndDoImmediate(&outRec->channel, &cmd); + if(error != noErr) return error; /* } */ @@ -1101,7 +1101,7 @@ pascal OSErr SHPlayPause( long refNum ) //======================================================================================= // -// pascal OSErr SHPlayContinue( long refNum ) +// pascal OSErr SHPlayContinue(long refNum) // // Summary: // This routine continues playback of a previously paused sound. @@ -1129,29 +1129,29 @@ pascal OSErr SHPlayPause( long refNum ) // we clear the output record's paused flag. // //======================================================================================= -pascal OSErr SHPlayContinue( long refNum ) +pascal OSErr SHPlayContinue(long refNum) { SHOutPtr outRec; SndCommand cmd; OSErr error; - outRec = SHOutRecFromRefNum(refNum ); - if( outRec != nil ) + outRec = SHOutRecFromRefNum(refNum); + if(outRec != nil) { // Don't even bother with this stuff if the channel isn't paused. - if( !outRec->paused ) + if(!outRec->paused) return kSHErrAlreadyContinued; // Now continue playback with a rateCmd or a resumeCmd, as appropriate. cmd.param1 = 0; -/* if( outRec->rate != 0 ) +/* if(outRec->rate != 0) { // Resume sampled sound playback by restoring the synthesizer's playback // rate with a rateCmd. cmd.cmd = rateCmd; cmd.param2 = outRec->rate; - error = SndDoImmediate( &outRec->channel, &cmd ); - if( error != noErr ) + error = SndDoImmediate(&outRec->channel, &cmd); + if(error != noErr) return error; } else @@ -1159,8 +1159,8 @@ pascal OSErr SHPlayContinue( long refNum ) */ // Resume sound queue processing with a resumeCmd. cmd.cmd = resumeCmd; cmd.param2 = 0; - error = SndDoImmediate( &outRec->channel, &cmd ); - if( error != noErr ) + error = SndDoImmediate(&outRec->channel, &cmd); + if(error != noErr) return error; /* } */ @@ -1172,7 +1172,7 @@ pascal OSErr SHPlayContinue( long refNum ) //======================================================================================= // -// pascal SHPlayStat SHPlayStatus( long refNum ) +// pascal SHPlayStat SHPlayStatus(long refNum) // // Summary: // This routine returns a status value for the sound associated with refNum. @@ -1199,17 +1199,17 @@ pascal OSErr SHPlayContinue( long refNum ) // shpPlaying based on the value of the output record's paused flag. // //======================================================================================= -pascal SHPlayStat SHPlayStatus( long refNum ) +pascal SHPlayStat SHPlayStatus(long refNum) { SHOutPtr outRec; - if( refNum >= gsSHOutVars.nextRef ) + if(refNum >= gsSHOutVars.nextRef) return shpError; else { - outRec = SHOutRecFromRefNum( refNum ); + outRec = SHOutRecFromRefNum(refNum); - if( outRec != nil ) + if(outRec != nil) { // We found an SHOutRec for the guy's ref num, (so it's in use). return outRec->paused? shpPaused:shpPlaying; @@ -1226,7 +1226,7 @@ pascal SHPlayStat SHPlayStatus( long refNum ) //======================================================================================= // -// pascal OSErr SHGetChannel( long refNum, SndChannelPtr *channel ) +// pascal OSErr SHGetChannel(long refNum, SndChannelPtr *channel) // // Summary: // This routine allows the caller to retrieve a pointer to the sound channel that @@ -1255,7 +1255,7 @@ pascal SHPlayStat SHPlayStatus( long refNum ) // the channel pointer by calling SHGetChannel, manually PlaySnd the background // music sound (which should contain a soundCmd to install the music as a voice), // then send a freqCmd to start the music playing. It'll keep looping until a -// quietCmd comes along. (SEE NOTE BELOW. ) +// quietCmd comes along. (SEE NOTE BELOW.) // // IMPORTANT: // If you use the above-described technique to provide looped background sound, it @@ -1266,15 +1266,15 @@ pascal SHPlayStat SHPlayStatus( long refNum ) // pre-7.0 Systems. // //======================================================================================= -pascal OSErr SHGetChannel( long refNum, SndChannelPtr *channel ) +pascal OSErr SHGetChannel(long refNum, SndChannelPtr *channel) { SHOutPtr outRec; // Look for the output record associated with refNum. - outRec = SHOutRecFromRefNum( refNum ); + outRec = SHOutRecFromRefNum(refNum); // If we found one, return a pointer to the sound channel. - if( outRec != nil ) + if(outRec != nil) { *channel = &outRec->channel; return noErr; @@ -1284,7 +1284,7 @@ pascal OSErr SHGetChannel( long refNum, SndChannelPtr *channel ) //======================================================================================= // -// OSErr SHGetDeviceSettings( long inRefNum, short *numChannels, Fixed *sampleRate, short *sampleSize, OSType *compType ) +// OSErr SHGetDeviceSettings(long inRefNum, short *numChannels, Fixed *sampleRate, short *sampleSize, OSType *compType) // // Summary: // This routine gets several parameters from an open sound input device. @@ -1310,24 +1310,24 @@ pascal OSErr SHGetChannel( long refNum, SndChannelPtr *channel ) // Volume 6. // //======================================================================================= -OSErr SHGetDeviceSettings( long inRefNum, short *numChannels, Fixed *sampleRate, short *sampleSize, OSType *compType ) +OSErr SHGetDeviceSettings(long inRefNum, short *numChannels, Fixed *sampleRate, short *sampleSize, OSType *compType) { OSErr error = noErr; // Hit on that sound input device. - error = SPBGetDeviceInfo( inRefNum, siNumberChannels, (Ptr) numChannels ); - if( error != noErr ) return error; - error = SPBGetDeviceInfo( inRefNum, siSampleRate, (Ptr) sampleRate ); - if( error != noErr ) return error; - error = SPBGetDeviceInfo(inRefNum, siSampleSize, (Ptr) sampleSize ); - if( error != noErr ) return error; - error = SPBGetDeviceInfo(inRefNum, siCompressionType, (Ptr) compType ); + error = SPBGetDeviceInfo(inRefNum, siNumberChannels, (Ptr) numChannels); + if(error != noErr) return error; + error = SPBGetDeviceInfo(inRefNum, siSampleRate, (Ptr) sampleRate); + if(error != noErr) return error; + error = SPBGetDeviceInfo(inRefNum, siSampleSize, (Ptr) sampleSize); + if(error != noErr) return error; + error = SPBGetDeviceInfo(inRefNum, siCompressionType, (Ptr) compType); return error; } //======================================================================================= // -// pascal OSErr SHRecordStart( short maxK, OSType quality, Boolean *doneFlag ) +// pascal OSErr SHRecordStart(short maxK, OSType quality, Boolean *doneFlag) // // Summary: // This routine initiates asynchronous sound recording. @@ -1387,7 +1387,7 @@ OSErr SHGetDeviceSettings( long inRefNum, short *numChannels, Fixed *sampleRate, // the sound input buffer may be deallocated. // //======================================================================================= -pascal OSErr SHRecordStart( short maxK, OSType quality, Boolean *doneFlag ) +pascal OSErr SHRecordStart(short maxK, OSType quality, Boolean *doneFlag) { Boolean deviceOpened = false; Boolean allocated = false; @@ -1398,61 +1398,61 @@ pascal OSErr SHRecordStart( short maxK, OSType quality, Boolean *doneFlag ) long allocSize; // 1. Try to open the current sound input device - error = SPBOpenDevice( nil, siWritePermission, &gsSHInVars.inRefNum ); - if( error == noErr ) + error = SPBOpenDevice(nil, siWritePermission, &gsSHInVars.inRefNum); + if(error == noErr) deviceOpened = true; // 2. Now let's see if this device can even handle asynchronous recording. - if( error == noErr ) + if(error == noErr) { - error = SPBGetDeviceInfo( gsSHInVars.inRefNum, siAsync, (Ptr) &canDoAsync ); - if( error == noErr && !canDoAsync ) + error = SPBGetDeviceInfo(gsSHInVars.inRefNum, siAsync, (Ptr) &canDoAsync); + if(error == noErr && !canDoAsync) error = kSHErrNonAsychDevice; } // 3. Try to allocate memory for the guy's sound. - if( error == noErr ) + if(error == noErr) { allocSize = (maxK * 1024) + kSHHeaderSlop; - gsSHInVars.inHandle = NewHandle(allocSize ); - if( gsSHInVars.inHandle == nil ) + gsSHInVars.inHandle = NewHandle(allocSize); + if(gsSHInVars.inHandle == nil) { error = MemError(); - if( error == noErr ) + if(error == noErr) error = memFullErr; } - if( error == noErr ) + if(error == noErr) allocated = true; } - // 4. Set up various recording parameters (metering and quality ) - if( error == noErr ) + // 4. Set up various recording parameters (metering and quality) + if(error == noErr) { metering = 1; - SPBSetDeviceInfo( gsSHInVars.inRefNum, siLevelMeterOnOff, (Ptr) &metering ); - error = SPBSetDeviceInfo( gsSHInVars.inRefNum, siRecordingQuality, (Ptr) &quality ); + SPBSetDeviceInfo(gsSHInVars.inRefNum, siLevelMeterOnOff, (Ptr) &metering); + error = SPBSetDeviceInfo(gsSHInVars.inRefNum, siRecordingQuality, (Ptr) &quality); } // 5. Call SHGetDeviceSettings to determine a bunch of information we'll need to // make a header for this sound. - if( error == noErr ) + if(error == noErr) { error = SHGetDeviceSettings(gsSHInVars.inRefNum, &gsSHInVars.numChannels, - &gsSHInVars.sampleRate, &gsSHInVars.sampleSize, &gsSHInVars.compType ); + &gsSHInVars.sampleRate, &gsSHInVars.sampleSize, &gsSHInVars.compType); } // 6. Create a header for this sound. - if( error == noErr ) + if(error == noErr) { error = SetupSndHeader((SndListHandle)gsSHInVars.inHandle, gsSHInVars.numChannels, gsSHInVars.sampleRate, gsSHInVars.sampleSize, - gsSHInVars.compType, kSHBaseNote, allocSize, &gsSHInVars.headerLength ); + gsSHInVars.compType, kSHBaseNote, allocSize, &gsSHInVars.headerLength); } // 7. Lock the input sound handle and set up the input parameter block. - if( error == noErr ) + if(error == noErr) { - MoveHHi( gsSHInVars.inHandle ); - HLock( gsSHInVars.inHandle ); + MoveHHi(gsSHInVars.inHandle); + HLock(gsSHInVars.inHandle); allocSize -= gsSHInVars.headerLength; gsSHInVars.inPB.inRefNum = gsSHInVars.inRefNum; @@ -1471,27 +1471,27 @@ pascal OSErr SHRecordStart( short maxK, OSType quality, Boolean *doneFlag ) // 8. Finally, if all went well, set our recording flag, make sure our record // completion flag is clear, and initiate asychronous recording. - if( error == noErr ) + if(error == noErr) { gsSHInVars.recording = true; gsSHInVars.recordComplete = false; gsSHInVars.appComplete = doneFlag; gsSHInVars.paused = false; - if( gsSHInVars.appComplete != nil ) + if(gsSHInVars.appComplete != nil) *gsSHInVars.appComplete = false; - error = SPBRecord(&gsSHInVars.inPB, kSHAsync ); + error = SPBRecord(&gsSHInVars.inPB, kSHAsync); } // Now clean up any errors that might have occurred. - if( error != noErr ) + if(error != noErr) { gsSHInVars.recording = false; - if( deviceOpened ) - SPBCloseDevice( gsSHInVars.inRefNum ); - if( allocated ) + if(deviceOpened) + SPBCloseDevice(gsSHInVars.inRefNum); + if(allocated) { - DisposeHandle( gsSHInVars.inHandle ); + DisposeHandle(gsSHInVars.inHandle); gsSHInVars.inHandle = nil; } } @@ -1501,7 +1501,7 @@ pascal OSErr SHRecordStart( short maxK, OSType quality, Boolean *doneFlag ) //======================================================================================= // -// pascal OSErr SHGetRecordedSound( Handle *theSound ) +// pascal OSErr SHGetRecordedSound(Handle *theSound) // // Summary: // This routine returns the sound handle from the last sound the Helper recorded. @@ -1526,11 +1526,11 @@ pascal OSErr SHRecordStart( short maxK, OSType quality, Boolean *doneFlag ) // complete. // //======================================================================================= -pascal OSErr SHGetRecordedSound( Handle *theSound ) +pascal OSErr SHGetRecordedSound(Handle *theSound) { - if( gsSHInVars.recordComplete ) + if(gsSHInVars.recordComplete) { - if( gsSHInVars.recordErr != noErr ) + if(gsSHInVars.recordErr != noErr) { *theSound = nil; return gsSHInVars.recordErr; @@ -1550,7 +1550,7 @@ pascal OSErr SHGetRecordedSound( Handle *theSound ) //======================================================================================= // -// pascal OSErr SHRecordStop( void ) +// pascal OSErr SHRecordStop(void) // // Summary: // This routine immediately stops sound recording. @@ -1570,16 +1570,16 @@ pascal OSErr SHGetRecordedSound( Handle *theSound ) // routine. Use this routine to implement a "stop" button. // //======================================================================================= -pascal OSErr SHRecordStop( void ) +pascal OSErr SHRecordStop(void) { - if( gsSHInVars.recording ) + if(gsSHInVars.recording) return SPBStopRecording(gsSHInVars.inRefNum); return noErr; } //======================================================================================= // -// pascal OSErr SHRecordPause( void ) +// pascal OSErr SHRecordPause(void) // // Summary: // This routine pauses sound recording. @@ -1600,14 +1600,14 @@ pascal OSErr SHRecordStop( void ) // paused. Use this routine to implement a "pause" button. // //======================================================================================= -pascal OSErr SHRecordPause( void ) +pascal OSErr SHRecordPause(void) { OSErr error = noErr; - if( gsSHInVars.recording ) + if(gsSHInVars.recording) { - if( !gsSHInVars.paused ) + if(!gsSHInVars.paused) { - error = SPBPauseRecording( gsSHInVars.inRefNum ); + error = SPBPauseRecording(gsSHInVars.inRefNum); gsSHInVars.paused = (error == noErr); return error; } @@ -1618,7 +1618,7 @@ pascal OSErr SHRecordPause( void ) //======================================================================================= // -// pascal OSErr SHRecordContinue( void ) +// pascal OSErr SHRecordContinue(void) // // Summary: // This routine resumes recording when recording has previously been paused. @@ -1639,15 +1639,15 @@ pascal OSErr SHRecordPause( void ) // previously paused. Use this routine to implement a "unpause" button. // //======================================================================================= -pascal OSErr SHRecordContinue( void ) +pascal OSErr SHRecordContinue(void) { OSErr error = noErr; - if( gsSHInVars.recording ) + if(gsSHInVars.recording) { - if( gsSHInVars.paused ) + if(gsSHInVars.paused) { - error = SPBResumeRecording( gsSHInVars.inRefNum ); + error = SPBResumeRecording(gsSHInVars.inRefNum); gsSHInVars.paused = !(error == noErr); return error; } @@ -1658,7 +1658,7 @@ pascal OSErr SHRecordContinue( void ) //======================================================================================= // -// pascal OSErr SHRecordStatus( SHRecordStatusRec *recordStatus ) +// pascal OSErr SHRecordStatus(SHRecordStatusRec *recordStatus) // // Summary: // This routine returns status information on sound that is being recorded. @@ -1683,23 +1683,23 @@ pascal OSErr SHRecordContinue( void ) // error occurs, we give a status of shrError. // //======================================================================================= -pascal OSErr SHRecordStatus( SHRecordStatusRec *recordStatus ) +pascal OSErr SHRecordStatus(SHRecordStatusRec *recordStatus) { short recStatus; OSErr error = noErr; unsigned long totalSamplesToRecord,numberOfSamplesRecorded; - if( gsSHInVars.recording ) + if(gsSHInVars.recording) { - error = SPBGetRecordingStatus( gsSHInVars.inRefNum, &recStatus, + error = SPBGetRecordingStatus(gsSHInVars.inRefNum, &recStatus, &recordStatus->meterLevel, &totalSamplesToRecord, &numberOfSamplesRecorded, - &recordStatus->totalRecordTime, &recordStatus->currentRecordTime ); - if( error == noErr ) - recordStatus->recordStatus = ( gsSHInVars.paused? shrPaused:shrRecording ); + &recordStatus->totalRecordTime, &recordStatus->currentRecordTime); + if(error == noErr) + recordStatus->recordStatus = (gsSHInVars.paused? shrPaused:shrRecording); else recordStatus->recordStatus = shrError; return error; } - else if( gsSHInVars.recordComplete ) + else if(gsSHInVars.recordComplete) { recordStatus->recordStatus = shrFinished; recordStatus->meterLevel = 0; diff --git a/Carbon/Classes/Asynchronous.h b/Carbon/Classes/Asynchronous.h index 74af642..341fbb0 100644 --- a/Carbon/Classes/Asynchronous.h +++ b/Carbon/Classes/Asynchronous.h @@ -94,28 +94,28 @@ typedef struct } SHInputVars; // Initialization, idle, and termination -pascal OSErr SHInitSoundHelper( Boolean *attnFlag, short numChannels ); -pascal void SHIdle( void ); -pascal void SHKillSoundHelper(void ); +pascal OSErr SHInitSoundHelper(Boolean *attnFlag, short numChannels); +pascal void SHIdle(void); +pascal void SHKillSoundHelper(void); // Easy sound output -pascal OSErr SHPlayByID( short resID, long *refNum ); -pascal OSErr SHPlayByHandle( Handle sound, long *refNum ); -pascal OSErr SHPlayStop( long refNum ); -pascal OSErr SHPlayStopAll( void ); +pascal OSErr SHPlayByID(short resID, long *refNum); +pascal OSErr SHPlayByHandle(Handle sound, long *refNum); +pascal OSErr SHPlayStop(long refNum); +pascal OSErr SHPlayStopAll(void); // Advanced sound output -pascal OSErr SHPlayPause( long refNum ); -pascal OSErr SHPlayContinue( long refNum ); -pascal SHPlayStat SHPlayStatus( long refNum ); -pascal OSErr SHGetChannel( long refNum, SndChannelPtr *channel ); +pascal OSErr SHPlayPause(long refNum); +pascal OSErr SHPlayContinue(long refNum); +pascal SHPlayStat SHPlayStatus(long refNum); +pascal OSErr SHGetChannel(long refNum, SndChannelPtr *channel); // Easy sound input -pascal OSErr SHRecordStart( short maxK, OSType quality, Boolean *doneFlag ); -pascal OSErr SHGetRecordedSound( Handle *theSound ); -pascal OSErr SHRecordStop( void ); +pascal OSErr SHRecordStart(short maxK, OSType quality, Boolean *doneFlag); +pascal OSErr SHGetRecordedSound(Handle *theSound); +pascal OSErr SHRecordStop(void); // Advanced sound input -pascal OSErr SHRecordPause( void ); -pascal OSErr SHRecordContinue( void ); -pascal OSErr SHRecordStatus( SHRecordStatusRec *recordStatus ); \ No newline at end of file +pascal OSErr SHRecordPause(void); +pascal OSErr SHRecordContinue(void); +pascal OSErr SHRecordStatus(SHRecordStatusRec *recordStatus); \ No newline at end of file diff --git a/Carbon/Classes/DataBrowser.cpp b/Carbon/Classes/DataBrowser.cpp index 7386113..ea0d9e0 100644 --- a/Carbon/Classes/DataBrowser.cpp +++ b/Carbon/Classes/DataBrowser.cpp @@ -9,73 +9,73 @@ extern globals g; #if TARGET_API_MAC_CARBON // CarbonLib 1.1+ or Public Beta only /*** INITALISE DATA BROWSER ***/ -OSStatus FileWindow::InitDataBrowser( void ) +OSStatus FileWindow::InitDataBrowser(void) { OSStatus error = noErr; // get the db control - compatable with both CarbonLib and nib based versions ControlID id = { kDataBrowserSignature, 0 }; - GetControlByID( window, &id, &dataBrowser ); + GetControlByID(window, &id, &dataBrowser); // set control ref to FileWindow - SetControlReference( dataBrowser, (long) this ); + SetControlReference(dataBrowser, (long) this); // turn off frame and focus Boolean frame = false; - SetControlData( dataBrowser, kControlNoPart, kControlDataBrowserIncludesFrameAndFocusTag, sizeof(Boolean), &frame ); + SetControlData(dataBrowser, kControlNoPart, kControlDataBrowserIncludesFrameAndFocusTag, sizeof(Boolean), &frame); #if !USE_NIBS // add empty columns - AddDataBrowserColumn( dataBrowser, kDBNameColumn, 0 ); // save column order into prefs file: Get/SetDataBrowserUserState() - AddDataBrowserColumn( dataBrowser, kDBTypeColumn, 1 ); - AddDataBrowserColumn( dataBrowser, kDBIDColumn, 2 ); - AddDataBrowserColumn( dataBrowser, kDBSizeColumn, 3 ); + AddDataBrowserColumn(dataBrowser, kDBNameColumn, 0); // save column order into prefs file: Get/SetDataBrowserUserState() + AddDataBrowserColumn(dataBrowser, kDBTypeColumn, 1); + AddDataBrowserColumn(dataBrowser, kDBIDColumn, 2); + AddDataBrowserColumn(dataBrowser, kDBSizeColumn, 3); #endif // add callbacks DataBrowserCallbacks theCallbacks; theCallbacks.version = kDataBrowserLatestCallbacks; - InitDataBrowserCallbacks( &theCallbacks ); - theCallbacks.u.v1.itemDataCallback = NewDataBrowserItemDataUPP( DataBrowserItemData ); - theCallbacks.u.v1.itemCompareCallback = NewDataBrowserItemCompareUPP( SortDataBrowser ); - theCallbacks.u.v1.itemNotificationCallback = NewDataBrowserItemNotificationUPP( DataBrowserMessage ); - theCallbacks.u.v1.addDragItemCallback = NewDataBrowserAddDragItemUPP( DataBrowserAddDragItem ); - theCallbacks.u.v1.acceptDragCallback = NewDataBrowserAcceptDragUPP( DataBrowserAcceptDrag ); - theCallbacks.u.v1.receiveDragCallback = NewDataBrowserReceiveDragUPP( DataBrowserReceiveDrag ); - theCallbacks.u.v1.postProcessDragCallback = NewDataBrowserPostProcessDragUPP( DataBrowserPostProcessDrag ); - SetDataBrowserCallbacks( dataBrowser, &theCallbacks ); + InitDataBrowserCallbacks(&theCallbacks); + theCallbacks.u.v1.itemDataCallback = NewDataBrowserItemDataUPP(DataBrowserItemData); + theCallbacks.u.v1.itemCompareCallback = NewDataBrowserItemCompareUPP(SortDataBrowser); + theCallbacks.u.v1.itemNotificationCallback = NewDataBrowserItemNotificationUPP(DataBrowserMessage); + theCallbacks.u.v1.addDragItemCallback = NewDataBrowserAddDragItemUPP(DataBrowserAddDragItem); + theCallbacks.u.v1.acceptDragCallback = NewDataBrowserAcceptDragUPP(DataBrowserAcceptDrag); + theCallbacks.u.v1.receiveDragCallback = NewDataBrowserReceiveDragUPP(DataBrowserReceiveDrag); + theCallbacks.u.v1.postProcessDragCallback = NewDataBrowserPostProcessDragUPP(DataBrowserPostProcessDrag); + SetDataBrowserCallbacks(dataBrowser, &theCallbacks); // setup rest of browser, inc. adding all resources DataBrowserItemID item; - for( UInt32 n = 1; n <= numResources; n++ ) + for(UInt32 n = 1; n <= numResources; n++) { item = n; - error = AddDataBrowserItems( dataBrowser, kDataBrowserNoItem, 1, &item, kDataBrowserItemNoProperty ); - if( error ) DebugError( "\pError occoured adding resource to data browser." ); + error = AddDataBrowserItems(dataBrowser, kDataBrowserNoItem, 1, &item, kDataBrowserItemNoProperty); + if(error) DebugError("\pError occoured adding resource to data browser."); } // add data fork if present - if( resourceMap->RepresentsDataFork() ) // requires data fork to be first in chain + if(resourceMap->RepresentsDataFork()) // requires data fork to be first in chain { item = kDataBrowserDataForkItem; // curently 0xFFFFFFFF - error = AddDataBrowserItems( dataBrowser, kDataBrowserNoItem, 1, &item, kDataBrowserItemNoProperty ); - if( error ) DebugError( "\pError occoured adding data fork to data browser." ); + error = AddDataBrowserItems(dataBrowser, kDataBrowserNoItem, 1, &item, kDataBrowserItemNoProperty); + if(error) DebugError("\pError occoured adding data fork to data browser."); } - SetDataBrowserSortProperty( dataBrowser, kDBTypeColumn ); - SetDataBrowserTableViewRowHeight( dataBrowser, 16 +2 ); - SetDataBrowserListViewDisclosureColumn( dataBrowser, kDBNameColumn, true ); + SetDataBrowserSortProperty(dataBrowser, kDBTypeColumn); + SetDataBrowserTableViewRowHeight(dataBrowser, 16 +2); + SetDataBrowserListViewDisclosureColumn(dataBrowser, kDBNameColumn, true); // set up drag tracking - SetControlDragTrackingEnabled( dataBrowser, true ); + SetControlDragTrackingEnabled(dataBrowser, true); return error; } /*** ADD DATA BROWSER COLUMN ***/ -void AddDataBrowserColumn( ControlRef browser, DataBrowserPropertyID column, UInt16 position ) +void AddDataBrowserColumn(ControlRef browser, DataBrowserPropertyID column, UInt16 position) { DataBrowserListViewColumnDesc columnDesc; - switch( column ) + switch(column) { case kDataBrowserNameColumn: columnDesc.propertyDesc.propertyID = kDataBrowserNameColumn; @@ -151,110 +151,110 @@ void AddDataBrowserColumn( ControlRef browser, DataBrowserPropertyID column, UIn } // create column and make respond to sorting - AddDataBrowserListViewColumn( browser, &columnDesc, position ); + AddDataBrowserListViewColumn(browser, &columnDesc, position); } /*** HANDLE ITEM DATA I/O ***/ -pascal OSStatus DataBrowserItemData( ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemDataRef itemData, Boolean setValue ) +pascal OSStatus DataBrowserItemData(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemDataRef itemData, Boolean setValue) { - #pragma unused( setValue ) + #pragma unused(setValue) OSStatus result = noErr; - if( setValue ) return result; - FileWindowPtr file = (FileWindowPtr) GetControlReference( browser ); - ResourceObjectPtr resource = file->GetResource( itemID ); + if(setValue) return result; + FileWindowPtr file = (FileWindowPtr) GetControlReference(browser); + ResourceObjectPtr resource = file->GetResource(itemID); - if( resource == null ) - DebugError( "\pNull resource returned within DataBrowserItemData()" ); + if(resource == null) + DebugError("\pNull resource returned within DataBrowserItemData()"); - switch( property ) + switch(property) { case kDataBrowserItemIsEditableProperty: - if( true ) // should item be editable? (i.e. is it a name, ID or type?) - SetDataBrowserItemDataBooleanValue( itemData, true ); + if(true) // should item be editable? (i.e. is it a name, ID or type?) + SetDataBrowserItemDataBooleanValue(itemData, true); break; case kDataBrowserItemIsContainerProperty: - if( resource->Type() == kIconFamilyType ) - SetDataBrowserItemDataBooleanValue( itemData, true ); + if(resource->Type() == kIconFamilyType) + SetDataBrowserItemDataBooleanValue(itemData, true); break; case kDBNameColumn: { // icon Ñ no resource for the icon! IconRef theIcon = null; #if !USE_NIBS - if( itemID != kDataBrowserDataForkItem ) + if(itemID != kDataBrowserDataForkItem) { Str255 iconString; - TypeToPString( resource->Type(), iconString ); - IconFamilyHandle iconFamily = (IconFamilyHandle) Get1NamedResource( kIconFamilyType, iconString ); - if( iconFamily ) + TypeToPString(resource->Type(), iconString); + IconFamilyHandle iconFamily = (IconFamilyHandle) Get1NamedResource(kIconFamilyType, iconString); + if(iconFamily) { - RegisterIconRefFromIconFamily( kResKnifeCreator, resource->Type(), iconFamily, &theIcon ); - ReleaseResource( (Handle) iconFamily ); // when dragging a rect this call caused other columns not to be displayed !?! + RegisterIconRefFromIconFamily(kResKnifeCreator, resource->Type(), iconFamily, &theIcon); + ReleaseResource((Handle) iconFamily); // when dragging a rect this call caused other columns not to be displayed !?! } } #endif - if( theIcon == null ) - GetIconRef( kOnSystemDisk, kResKnifeCreator, kResourceFileType, &theIcon ); - SetDataBrowserItemDataIcon( itemData, theIcon ); - ReleaseIconRef( theIcon ); + if(theIcon == null) + GetIconRef(kOnSystemDisk, kResKnifeCreator, kResourceFileType, &theIcon); + SetDataBrowserItemDataIcon(itemData, theIcon); + ReleaseIconRef(theIcon); // resource name CFStringRef nameCFStr; - if( itemID == kDataBrowserDataForkItem ) + if(itemID == kDataBrowserDataForkItem) { #if USE_NIBS // OS 9 version is not bundled at the present time - nameCFStr = CFBundleCopyLocalizedString( CFBundleGetMainBundle(), CFSTR("Data Fork"), null, null ); // bug: doesn't actually get localized string! + nameCFStr = CFBundleCopyLocalizedString(CFBundleGetMainBundle(), CFSTR("Data Fork"), null, null); // bug: doesn't actually get localized string! #else nameCFStr = CFSTR("Data Fork"); #endif - SetDataBrowserItemDataRGBColor( itemData, &g.textColour ); + SetDataBrowserItemDataRGBColor(itemData, &g.textColour); } - else if( *resource->Name() == 0x00 ) + else if(*resource->Name() == 0x00) { #if USE_NIBS // OS 9 version is not bundled at the present time - nameCFStr = CFBundleCopyLocalizedString( CFBundleGetMainBundle(), CFSTR("Untitled Resource"), null, null ); // bug: doesn't actually get localized string! + nameCFStr = CFBundleCopyLocalizedString(CFBundleGetMainBundle(), CFSTR("Untitled Resource"), null, null); // bug: doesn't actually get localized string! #else nameCFStr = CFSTR("Untitled Resource"); #endif - SetDataBrowserItemDataRGBColor( itemData, &g.textColour ); + SetDataBrowserItemDataRGBColor(itemData, &g.textColour); } - else nameCFStr = CFStringCreateWithPascalString( CFAllocatorGetDefault(), resource->Name(), kCFStringEncodingMacRoman ); - SetDataBrowserItemDataText( itemData, nameCFStr ); + else nameCFStr = CFStringCreateWithPascalString(CFAllocatorGetDefault(), resource->Name(), kCFStringEncodingMacRoman); + SetDataBrowserItemDataText(itemData, nameCFStr); #if USE_NIBS // OS 9 uses CFSTR() - CFRelease( nameCFStr ); + CFRelease(nameCFStr); #endif } break; case kDBTypeColumn: { // resource type - if( itemID == kDataBrowserDataForkItem ) + if(itemID == kDataBrowserDataForkItem) { - SetDataBrowserItemDataText( itemData, CFSTR("-") ); + SetDataBrowserItemDataText(itemData, CFSTR("-")); } else { CFStringRef typeString; - TypeToCFString( resource->Type(), &typeString ); - SetDataBrowserItemDataText( itemData, typeString ); - CFRelease( typeString ); + TypeToCFString(resource->Type(), &typeString); + SetDataBrowserItemDataText(itemData, typeString); + CFRelease(typeString); } } break; case kDBIDColumn: { // resource ID - if( itemID == kDataBrowserDataForkItem ) + if(itemID == kDataBrowserDataForkItem) { - SetDataBrowserItemDataText( itemData, CFSTR("-") ); + SetDataBrowserItemDataText(itemData, CFSTR("-")); } else { SInt16 id = resource->ID(); Str255 idPString; - NumToString( id, (StringPtr) &idPString ); - CFStringRef idString = CFStringCreateWithPascalString( CFAllocatorGetDefault(), idPString, kCFStringEncodingMacRoman ); - SetDataBrowserItemDataText( itemData, idString ); - CFRelease( idString ); + NumToString(id, (StringPtr) &idPString); + CFStringRef idString = CFStringCreateWithPascalString(CFAllocatorGetDefault(), idPString, kCFStringEncodingMacRoman); + SetDataBrowserItemDataText(itemData, idString); + CFRelease(idString); } } break; @@ -262,28 +262,28 @@ pascal OSStatus DataBrowserItemData( ControlRef browser, DataBrowserItemID itemI { SInt32 size = resource->Size(); UInt8 power = 0, remainder = 0; Str255 sizePString, frac; - while( size >= 1024 && power <= 30 ) + while(size >= 1024 && power <= 30) { power += 10; // 10 == KB, 20 == MB, 30 == GB remainder = (UInt8) ((size % 1024) / 102.4); // 102.4 gives one dp, 10.24 would give two dps, 1.024 would give three dps size /= 1024; } - NumToString( (long) size, (StringPtr) &sizePString ); - NumToString( remainder, (StringPtr) &frac ); - if( power ) // some division has occoured + NumToString((long) size, (StringPtr) &sizePString); + NumToString(remainder, (StringPtr) &frac); + if(power) // some division has occoured { - if( sizePString[0] < 3 && remainder > 0 ) + if(sizePString[0] < 3 && remainder > 0) { - AppendPString( (unsigned char *) &sizePString, "\p." ); // bug: should be a comma on european systems - AppendPString( (unsigned char *) &sizePString, (unsigned char *) &frac ); + AppendPString((unsigned char *) &sizePString, "\p."); // bug: should be a comma on european systems + AppendPString((unsigned char *) &sizePString, (unsigned char *) &frac); } - if( power == 10 ) AppendPString( (unsigned char *) &sizePString, "\p KB" ); - else if( power == 20 ) AppendPString( (unsigned char *) &sizePString, "\p MB" ); - else if( power == 30 ) AppendPString( (unsigned char *) &sizePString, "\p GB" ); // everything bigger will be given in GB + if(power == 10) AppendPString((unsigned char *) &sizePString, "\p KB"); + else if(power == 20) AppendPString((unsigned char *) &sizePString, "\p MB"); + else if(power == 30) AppendPString((unsigned char *) &sizePString, "\p GB"); // everything bigger will be given in GB } - CFStringRef sizeString = CFStringCreateWithPascalString( CFAllocatorGetDefault(), sizePString, kCFStringEncodingMacRoman ); - SetDataBrowserItemDataText( itemData, sizeString ); - CFRelease( sizeString ); + CFStringRef sizeString = CFStringCreateWithPascalString(CFAllocatorGetDefault(), sizePString, kCFStringEncodingMacRoman); + SetDataBrowserItemDataText(itemData, sizeString); + CFRelease(sizeString); } break; default: @@ -294,48 +294,48 @@ pascal OSStatus DataBrowserItemData( ControlRef browser, DataBrowserItemID itemI } /*** SORT DATA BROWSER ***/ -pascal Boolean SortDataBrowser( ControlRef browser, DataBrowserItemID itemOne, DataBrowserItemID itemTwo, DataBrowserPropertyID sortProperty ) +pascal Boolean SortDataBrowser(ControlRef browser, DataBrowserItemID itemOne, DataBrowserItemID itemTwo, DataBrowserPropertyID sortProperty) { short result; Str255 typeOne, typeTwo; StringPtr nameOne, nameTwo; - FileWindowPtr file = (FileWindowPtr) GetControlReference( browser ); + FileWindowPtr file = (FileWindowPtr) GetControlReference(browser); // send data fork to top regardless of property - if( itemOne == kDataBrowserDataForkItem ) return true; - if( itemTwo == kDataBrowserDataForkItem ) return false; + if(itemOne == kDataBrowserDataForkItem) return true; + if(itemTwo == kDataBrowserDataForkItem) return false; // validate data browser item IDs - if( itemOne <= kDataBrowserNoItem || itemOne > file->GetResourceCount() ) + if(itemOne <= kDataBrowserNoItem || itemOne > file->GetResourceCount()) { - DebugError( "\psort item one was invalid" ); + DebugError("\psort item one was invalid"); return false; } - if( itemTwo <= kDataBrowserNoItem || itemTwo > file->GetResourceCount() ) + if(itemTwo <= kDataBrowserNoItem || itemTwo > file->GetResourceCount()) { - DebugError( "\psort item two was invalid" ); + DebugError("\psort item two was invalid"); return false; } // get resource corrisponding to item ID - ResourceObjectPtr resourceOne = file->GetResource( itemOne ); - ResourceObjectPtr resourceTwo = file->GetResource( itemTwo ); - if( resourceOne == null || resourceTwo == null ) - DebugError( "\pNull resource returned within SortDataBrowser()" ); + ResourceObjectPtr resourceOne = file->GetResource(itemOne); + ResourceObjectPtr resourceTwo = file->GetResource(itemTwo); + if(resourceOne == null || resourceTwo == null) + DebugError("\pNull resource returned within SortDataBrowser()"); // sort resources according to property user has selected - switch( sortProperty ) + switch(sortProperty) { case kDBNameColumn: nameOne = resourceOne->Name(); nameTwo = resourceTwo->Name(); - result = CompareString( nameOne, nameTwo, null ); + result = CompareString(nameOne, nameTwo, null); return result < 0; case kDBTypeColumn: - TypeToPString( resourceOne->Type(), typeOne ); - TypeToPString( resourceTwo->Type(), typeTwo ); - result = CompareString( typeOne, typeTwo, null ); + TypeToPString(resourceOne->Type(), typeOne); + TypeToPString(resourceTwo->Type(), typeTwo); + result = CompareString(typeOne, typeTwo, null); return result < 0; case kDBIDColumn: @@ -345,42 +345,42 @@ pascal Boolean SortDataBrowser( ControlRef browser, DataBrowserItemID itemOne, D return resourceOne->Size() < resourceTwo->Size(); case kDataBrowserItemNoProperty: // this is valid when first constructing the data browser -// DebugError( "\pkDataBrowserItemNoProperty passed to sort function" ); +// DebugError("\pkDataBrowserItemNoProperty passed to sort function"); return false; default: - DebugError( "\pInvalid sort property given" ); + DebugError("\pInvalid sort property given"); return false; } return false; } /*** DATA BROWSER MESSAGE ***/ -pascal void DataBrowserMessage( ControlRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message/*, DataBrowserItemDataRef itemData*/ ) +pascal void DataBrowserMessage(ControlRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message/*, DataBrowserItemDataRef itemData*/) { - #pragma unused( itemID/*, itemData*/ ) - FileWindowPtr file = (FileWindowPtr) GetControlReference( browser ); - switch( message ) + #pragma unused(itemID/*, itemData*/) + FileWindowPtr file = (FileWindowPtr) GetControlReference(browser); + switch(message) { case kDataBrowserItemDoubleClicked: { KeyMap theKeys; Boolean shiftKeyDown = false, optionKeyDown = false, controlKeyDown = false; - GetKeys( theKeys ); - if( theKeys[1] & (shiftKey >> shiftKeyBit) ) shiftKeyDown = true; - if( theKeys[1] & (optionKey >> shiftKeyBit) ) optionKeyDown = true; - if( theKeys[1] & (controlKey >> shiftKeyBit) ) controlKeyDown = true; - if( optionKeyDown ) file->OpenResource( itemID, kMenuCommandOpenHex ); - else if( controlKeyDown ) file->OpenResource( itemID, kMenuCommandOpenTemplate ); - else file->OpenResource( itemID, kMenuCommandOpenDefault ); + GetKeys(theKeys); + if(theKeys[1] & (shiftKey >> shiftKeyBit)) shiftKeyDown = true; + if(theKeys[1] & (optionKey >> shiftKeyBit)) optionKeyDown = true; + if(theKeys[1] & (controlKey >> shiftKeyBit)) controlKeyDown = true; + if(optionKeyDown) file->OpenResource(itemID, kMenuCommandOpenHex); + else if(controlKeyDown) file->OpenResource(itemID, kMenuCommandOpenTemplate); + else file->OpenResource(itemID, kMenuCommandOpenDefault); } break; case kDataBrowserItemSelected: case kDataBrowserItemDeselected: case kDataBrowserSelectionSetChanged: // file->SetHeaderText(); - if( g.inspector ) + if(g.inspector) g.inspector->Update(); break; @@ -400,20 +400,20 @@ pascal void DataBrowserMessage( ControlRef browser, DataBrowserItemID itemID, Da } /*** ADD DRAG ITEM ***/ -pascal Boolean DataBrowserAddDragItem( ControlRef browser, DragRef drag, DataBrowserItemID item, DragItemRef *itemRef ) +pascal Boolean DataBrowserAddDragItem(ControlRef browser, DragRef drag, DataBrowserItemID item, DragItemRef *itemRef) { - #pragma unused( item ) + #pragma unused(item) // if drag already has phfs flavour, don't add another UInt16 numFlavours; - CountDragItemFlavors( drag, *itemRef, &numFlavours ); - if( numFlavours > 0 ) return true; + CountDragItemFlavors(drag, *itemRef, &numFlavours); + if(numFlavours > 0) return true; // add 'create file' callback - if( itemRef ) *itemRef = ItemReference( item ); + if(itemRef) *itemRef = ItemReference(item); FlavorFlags flags = flavorNotSaved; - DragSendDataUPP sendData = NewDragSendDataUPP( SendPromisedFile ); - SetDragSendProc( drag, sendData, browser ); + DragSendDataUPP sendData = NewDragSendDataUPP(SendPromisedFile); + SetDragSendProc(drag, sendData, browser); // setup imaginary file PromiseHFSFlavor promisedFile; @@ -423,7 +423,7 @@ pascal Boolean DataBrowserAddDragItem( ControlRef browser, DragRef drag, DataBro promisedFile.promisedFlavor = kResourceTransferType; // add phfs and TEXT flavours - AddDragItemFlavor( drag, *itemRef, flavorTypePromiseHFS, &promisedFile, sizeof(PromiseHFSFlavor), flags ); + AddDragItemFlavor(drag, *itemRef, flavorTypePromiseHFS, &promisedFile, sizeof(PromiseHFSFlavor), flags); return true; /* OSErr error = noErr; @@ -431,9 +431,9 @@ pascal Boolean DataBrowserAddDragItem( ControlRef browser, DragRef drag, DataBro ItemReference theItemRef = 1; // create the drag reference - NewDrag( &theDragRef ); - if( MemError() ) return; - SetDragSendProc( theDragRef, sendProc, this ); + NewDrag(&theDragRef); + if(MemError()) return; + SetDragSendProc(theDragRef, sendProc, this); RgnHandle dragRgn = NewRgn(), subtractRgn = NewRgn(); @@ -442,106 +442,106 @@ pascal Boolean DataBrowserAddDragItem( ControlRef browser, DragRef drag, DataBro Point dragOffset; GWorldPtr imageGWorld = nil; - resData = GetResourceData( ownerWindow ); - while( resData ) + resData = GetResourceData(ownerWindow); + while(resData) { - if( r.selected ) - UnionRgn( r.nameIconRgn, dragRgn, dragRgn ); // add new region to rest of drag region + if(r.selected) + UnionRgn(r.nameIconRgn, dragRgn, dragRgn); // add new region to rest of drag region resData = r.next; } - if( g.translucentDrag ) + if(g.translucentDrag) { short resCounter = 0; - SetPt( &dragOffset, 0, kFileHeaderHeight ); - resData = GetResourceData( ownerWindow ); + SetPt(&dragOffset, 0, kFileHeaderHeight); + resData = GetResourceData(ownerWindow); - while( !r.selected ) + while(!r.selected) { resCounter++; resData = r.next; } - error = CreateDragImage( resData, &imageGWorld ); - if( !error ) + error = CreateDragImage(resData, &imageGWorld); + if(!error) { // init mask region RgnHandle maskRgn = NewRgn(); - CopyRgn( r.nameIconRgn, maskRgn ); - OffsetRgn( maskRgn, 0, -kFileLineHeight * resCounter ); + CopyRgn(r.nameIconRgn, maskRgn); + OffsetRgn(maskRgn, 0, -kFileLineHeight * resCounter); // init rects Rect sourceRect, destRect; - SetRect( &sourceRect, 0, 0, g.nameColumnWidth, kFileLineHeight ); - SetRect( &destRect, 0, 0, g.nameColumnWidth, kFileLineHeight ); - OffsetRect( &destRect, 0, kFileHeaderHeight ); + SetRect(&sourceRect, 0, 0, g.nameColumnWidth, kFileLineHeight); + SetRect(&destRect, 0, 0, g.nameColumnWidth, kFileLineHeight); + OffsetRect(&destRect, 0, kFileHeaderHeight); // init GWorld - PixMapHandle imagePixMap = GetGWorldPixMap( imageGWorld ); + PixMapHandle imagePixMap = GetGWorldPixMap(imageGWorld); DragImageFlags imageFlags = kDragStandardTranslucency | kDragRegionAndImage; - error = SetDragImage( theDragRef, imagePixMap, maskRgn, dragOffset, imageFlags ); - CopyBits( &GrafPtr( imageGWorld )->portBits, &GrafPtr( ownerWindow )->portBits, &sourceRect, &destRect, srcCopy, maskRgn ); - if( error ) SysBeep(0); - DisposeGWorld( imageGWorld ); - DisposeRgn( maskRgn ); + error = SetDragImage(theDragRef, imagePixMap, maskRgn, dragOffset, imageFlags); + CopyBits(&GrafPtr(imageGWorld)->portBits, &GrafPtr(ownerWindow)->portBits, &sourceRect, &destRect, srcCopy, maskRgn); + if(error) SysBeep(0); + DisposeGWorld(imageGWorld); + DisposeRgn(maskRgn); } } // subtract middles from icons - MakeGlobal( ownerWindow, NewPoint(), &globalMouse ); - CopyRgn( dragRgn, subtractRgn ); // duplicate region - InsetRgn( subtractRgn, 2, 2 ); // inset it by 2 pixels - DiffRgn( dragRgn, subtractRgn, dragRgn ); // subtract subRgn from addRgn, save in nameIconRgn - OffsetRgn( dragRgn, globalMouse.h, globalMouse.v ); // change drag region to global coords + MakeGlobal(ownerWindow, NewPoint(), &globalMouse); + CopyRgn(dragRgn, subtractRgn); // duplicate region + InsetRgn(subtractRgn, 2, 2); // inset it by 2 pixels + DiffRgn(dragRgn, subtractRgn, dragRgn); // subtract subRgn from addRgn, save in nameIconRgn + OffsetRgn(dragRgn, globalMouse.h, globalMouse.v); // change drag region to global coords // add flavour data to drag - error = AddDragItemFlavor( theDragRef, theItemRef, flavorTypePromiseHFS, &theFile, sizeof(PromiseHFSFlavor), theFlags ); - error = AddDragItemFlavor( theDragRef, theItemRef, kResType, nil, 0, theFlags ); + error = AddDragItemFlavor(theDragRef, theItemRef, flavorTypePromiseHFS, &theFile, sizeof(PromiseHFSFlavor), theFlags); + error = AddDragItemFlavor(theDragRef, theItemRef, kResType, nil, 0, theFlags); // track the drag, then clean up - error = TrackDrag( theDragRef, theEvent, dragRgn ); - if( theDragRef ) DisposeDrag( theDragRef ); - if( subtractRgn ) DisposeRgn( subtractRgn ); - if( dragRgn ) DisposeRgn( dragRgn ); + error = TrackDrag(theDragRef, theEvent, dragRgn); + if(theDragRef) DisposeDrag(theDragRef); + if(subtractRgn) DisposeRgn(subtractRgn); + if(dragRgn) DisposeRgn(dragRgn); return error == noErr; */ } /*** ACCEPT DRAG ***/ -pascal Boolean DataBrowserAcceptDrag( ControlRef browser, DragRef drag, DataBrowserItemID item ) +pascal Boolean DataBrowserAcceptDrag(ControlRef browser, DragRef drag, DataBrowserItemID item) { - #pragma unused( browser, drag, item ) + #pragma unused(browser, drag, item) /* OSStatus error = noErr; Size size = null; DragItemRef dragItem = 1; UInt16 index, totalItems; - CountDragItems( theDrag, &totalItems ); - for( index = 1; index <= totalItems; index++ ) + CountDragItems(theDrag, &totalItems); + for(index = 1; index <= totalItems; index++) { - GetDragItemReferenceNumber( theDrag, index, &dragItem ); - error = GetFlavourDataSize( theDrag, dragItem, kDragFlavourTypeResource, &size ); -// if( error ) return false; - if( !error ) index = totalItems; // stop when valid item is reached + GetDragItemReferenceNumber(theDrag, index, &dragItem); + error = GetFlavourDataSize(theDrag, dragItem, kDragFlavourTypeResource, &size); +// if(error) return false; + if(!error) index = totalItems; // stop when valid item is reached } return size >= sizeof(ResTransferDesc); */ return true; } /*** RECEIVE DRAG ***/ -pascal Boolean DataBrowserReceiveDrag( ControlRef browser, DragRef drag, DataBrowserItemID item ) +pascal Boolean DataBrowserReceiveDrag(ControlRef browser, DragRef drag, DataBrowserItemID item) { - #pragma unused( browser, drag, item ) + #pragma unused(browser, drag, item) return true; } /*** POSTÐPROCESS DRAG ***/ -pascal void DataBrowserPostProcessDrag( ControlRef browser, DragRef drag, OSStatus trackDragResult ) +pascal void DataBrowserPostProcessDrag(ControlRef browser, DragRef drag, OSStatus trackDragResult) { - #pragma unused( browser, drag, trackDragResult ) + #pragma unused(browser, drag, trackDragResult) } /*** SEND PROMISED FILE ***/ -pascal OSErr SendPromisedFile( FlavorType type, void *dragSendRefCon, ItemReference item, DragReference drag ) +pascal OSErr SendPromisedFile(FlavorType type, void *dragSendRefCon, ItemReference item, DragReference drag) { OSErr error = noErr; ControlRef browser = (ControlRef) dragSendRefCon; @@ -550,67 +550,67 @@ pascal OSErr SendPromisedFile( FlavorType type, void *dragSendRefCon, ItemRefere short vRefNum; long dirID; - if( type != flavorTypePromiseHFS ) return badDragFlavorErr; + if(type != flavorTypePromiseHFS) return badDragFlavorErr; // create file - GetIndString( fileName, kFileNameStrings, kStringNewDragFileName ); - FindFolder( kOnSystemDisk, /*kTemporaryFolderType*/kDesktopFolderType, kCreateFolder, &vRefNum, &dirID ); - FSMakeFSSpec( vRefNum, dirID, fileName, &fileSpec ); - FSpCreateResFile( &fileSpec, kResKnifeCreator, kResourceFileType, smSystemScript ); + GetIndString(fileName, kFileNameStrings, kStringNewDragFileName); + FindFolder(kOnSystemDisk, /*kTemporaryFolderType*/kDesktopFolderType, kCreateFolder, &vRefNum, &dirID); + FSMakeFSSpec(vRefNum, dirID, fileName, &fileSpec); + FSpCreateResFile(&fileSpec, kResKnifeCreator, kResourceFileType, smSystemScript); // save resources into file DragData clientData; // waiting for jim to add a ControlRef to DataBrowserItemUPP; bug: jim no longer works at Apple clientData.browser = browser; clientData.fileSpec = &fileSpec; - DataBrowserItemUPP callback = NewDataBrowserItemUPP( AddResourceToDragFile ); + DataBrowserItemUPP callback = NewDataBrowserItemUPP(AddResourceToDragFile); /* control, container, recurse, state, callback, clientData */ - ForEachDataBrowserItem( browser, kDataBrowserNoItem, true, kDataBrowserItemIsSelected, callback, &clientData ); + ForEachDataBrowserItem(browser, kDataBrowserNoItem, true, kDataBrowserItemIsSelected, callback, &clientData); // save resources in file -/* ResourceObjectPtr resource = GetResourceData( file->window ); - short refNum = FSpOpenResFile( &fileSpec, fsRdWrPerm ); - UseResFile( refNum ); - while( resData ) +/* ResourceObjectPtr resource = GetResourceData(file->window); + short refNum = FSpOpenResFile(&fileSpec, fsRdWrPerm); + UseResFile(refNum); + while(resData) { - if( resource->Selected() ) - AddResource( resource->Data(), resource->Type(), resource->ID(), resource->Name() ); + if(resource->Selected()) + AddResource(resource->Data(), resource->Type(), resource->ID(), resource->Name()); resData = resource->Next(); } - CloseResFile( refNum ); - UseResFile( g.appResFile ); + CloseResFile(refNum); + UseResFile(g.appResFile); */ - error = SetDragItemFlavorData( drag, item, type, &fileSpec, sizeof(FSSpec), 0 ); + error = SetDragItemFlavorData(drag, item, type, &fileSpec, sizeof(FSSpec), 0); return error; } /*** ADD RESOURCE TO DRAG FILE ***/ -pascal void AddResourceToDragFile( DataBrowserItemID item, DataBrowserItemState state, void *clientData ) +pascal void AddResourceToDragFile(DataBrowserItemID item, DataBrowserItemState state, void *clientData) { - #pragma unused( state ) + #pragma unused(state) // FSSpecPtr fileSpec = (FSSpecPtr) clientData; - WindowRef window = GetControlOwner( ((DragDataPtr) clientData)->browser ); - FileWindowPtr file = (FileWindowPtr) GetWindowRefCon( window ); - ResourceObjectPtr resource = file->GetResource( item ); + WindowRef window = GetControlOwner(((DragDataPtr) clientData)->browser); + FileWindowPtr file = (FileWindowPtr) GetWindowRefCon(window); + ResourceObjectPtr resource = file->GetResource(item); // add resource to file short oldFile = CurResFile(); - short refNum = FSpOpenResFile( ((DragDataPtr) clientData)->fileSpec, fsRdWrPerm ); - UseResFile( refNum ); - AddResource( resource->Data(), resource->Type(), resource->ID(), resource->Name() ); - if( ResError() == addResFailed ) + short refNum = FSpOpenResFile(((DragDataPtr) clientData)->fileSpec, fsRdWrPerm); + UseResFile(refNum); + AddResource(resource->Data(), resource->Type(), resource->ID(), resource->Name()); + if(ResError() == addResFailed) { - DisplayError( "\pDrag Partially Failed", "\pCould not add a resource to file." ); + DisplayError("\pDrag Partially Failed", "\pCould not add a resource to file."); } else { - SetResAttrs( resource->Data(), resource->Attributes() ); - ChangedResource( resource->Data() ); + SetResAttrs(resource->Data(), resource->Attributes()); + ChangedResource(resource->Data()); // clean up & move on - DetachResource( resource->Data() ); + DetachResource(resource->Data()); } - CloseResFile( refNum ); - UseResFile( oldFile ); + CloseResFile(refNum); + UseResFile(oldFile); } #else @@ -620,12 +620,12 @@ pascal void AddResourceToDragFile( DataBrowserItemID item, DataBrowserItemState /*********************/ /*** CLEAR SELECTION ***/ -OSStatus FileWindow::ClearSelection( void ) +OSStatus FileWindow::ClearSelection(void) { ResourceObjectPtr resource = resourceMap; - while( resource ) + while(resource) { - resource->Select( false ); + resource->Select(false); resource = resource->Next(); } return noErr; diff --git a/Carbon/Classes/DataBrowser.h b/Carbon/Classes/DataBrowser.h index 70adba9..b2c6366 100644 --- a/Carbon/Classes/DataBrowser.h +++ b/Carbon/Classes/DataBrowser.h @@ -37,51 +37,51 @@ const DataBrowserItemID kDataBrowserDataForkItem = 0xFFFFFFFE; // bug in data br * @function AddDataBrowserColumn * @discussion Adds columns to the data browser one at a time. */ -void AddDataBrowserColumn( ControlRef browser, DataBrowserPropertyID column, UInt16 position ); +void AddDataBrowserColumn(ControlRef browser, DataBrowserPropertyID column, UInt16 position); /*! * @function DataBrowserItemData * @discussion DataBrowser callback. */ -pascal OSStatus DataBrowserItemData( ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemDataRef itemData, Boolean changeValue ); +pascal OSStatus DataBrowserItemData(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemDataRef itemData, Boolean changeValue); /*! * @function SortDataBrowser * @discussion DataBrowser callback. */ -pascal Boolean SortDataBrowser( ControlRef browser, DataBrowserItemID itemOne, DataBrowserItemID itemTwo, DataBrowserPropertyID sortProperty ); +pascal Boolean SortDataBrowser(ControlRef browser, DataBrowserItemID itemOne, DataBrowserItemID itemTwo, DataBrowserPropertyID sortProperty); /*! * @function DataBrowserMessage * @discussion DataBrowser callback. */ -pascal void DataBrowserMessage( ControlRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message/*, DataBrowserItemDataRef itemData*/ ); +pascal void DataBrowserMessage(ControlRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message/*, DataBrowserItemDataRef itemData*/); /*! * @function DataBrowserAddDragItem * @discussion DataBrowser callback. */ -pascal Boolean DataBrowserAddDragItem( ControlRef browser, DragRef drag, DataBrowserItemID item, DragItemRef *itemRef ); +pascal Boolean DataBrowserAddDragItem(ControlRef browser, DragRef drag, DataBrowserItemID item, DragItemRef *itemRef); /*! * @function DataBrowserAcceptDrag * @discussion DataBrowser callback. */ -pascal Boolean DataBrowserAcceptDrag( ControlRef browser, DragRef drag, DataBrowserItemID item ); +pascal Boolean DataBrowserAcceptDrag(ControlRef browser, DragRef drag, DataBrowserItemID item); /*! * @function DataBrowserReceiveDrag * @discussion DataBrowser callback. */ -pascal Boolean DataBrowserReceiveDrag( ControlRef browser, DragRef drag, DataBrowserItemID item ); +pascal Boolean DataBrowserReceiveDrag(ControlRef browser, DragRef drag, DataBrowserItemID item); /*! * @function DataBrowserPostProcessDrag * @discussion DataBrowser callback. */ -pascal void DataBrowserPostProcessDrag( ControlRef browser, DragRef drag, OSStatus trackDragResult ); +pascal void DataBrowserPostProcessDrag(ControlRef browser, DragRef drag, OSStatus trackDragResult); /*! * @function SendPromisedFile * @discussion Creates the promised file and sends the FSSpec for it back. */ -pascal OSErr SendPromisedFile( FlavorType theType, void *dragSendRefCon, ItemReference item, DragReference drag ); +pascal OSErr SendPromisedFile(FlavorType theType, void *dragSendRefCon, ItemReference item, DragReference drag); /*! * @function AddResourceToDragFile * @discussion Adds each resource to the file created by SendPromisedFile. Called once per resource. */ -pascal void AddResourceToDragFile( DataBrowserItemID item, DataBrowserItemState state, void *clientData ); +pascal void AddResourceToDragFile(DataBrowserItemID item, DataBrowserItemState state, void *clientData); #endif \ No newline at end of file diff --git a/Carbon/Classes/EditorWindow.cpp b/Carbon/Classes/EditorWindow.cpp index eab3e0f..70a6298 100644 --- a/Carbon/Classes/EditorWindow.cpp +++ b/Carbon/Classes/EditorWindow.cpp @@ -6,7 +6,7 @@ extern globals g; /*** CREATOR ***/ -EditorWindow::EditorWindow( FileWindowPtr ownerFile, ResourceObjectPtr targetResource, WindowRef inputWindow ) : PlugWindow( ownerFile ) +EditorWindow::EditorWindow(FileWindowPtr ownerFile, ResourceObjectPtr targetResource, WindowRef inputWindow) : PlugWindow(ownerFile) { // OSStatus error = noErr; @@ -17,33 +17,33 @@ EditorWindow::EditorWindow( FileWindowPtr ownerFile, ResourceObjectPtr targetRes // set up default window title Str255 windowTitle, resTypeStr, resIDStr; FSSpec spec = *ownerFile->GetFileSpec(); - CopyPString( spec.name, windowTitle ); - TypeToPString( resource->Type(), resTypeStr ); - NumToString( resource->ID(), resIDStr ); - AppendPString( windowTitle, "\p: " ); - AppendPString( windowTitle, resTypeStr ); - AppendPString( windowTitle, "\p " ); - AppendPString( windowTitle, resIDStr ); - if( *resource->Name() != 0x00 ) // resource has name + CopyPString(spec.name, windowTitle); + TypeToPString(resource->Type(), resTypeStr); + NumToString(resource->ID(), resIDStr); + AppendPString(windowTitle, "\p: "); + AppendPString(windowTitle, resTypeStr); + AppendPString(windowTitle, "\p "); + AppendPString(windowTitle, resIDStr); + if(*resource->Name() != 0x00) // resource has name { - AppendPString( windowTitle, "\p, Ò" ); - AppendPString( windowTitle, resource->Name() ); - AppendPString( windowTitle, "\pÓ" ); + AppendPString(windowTitle, "\p, Ò"); + AppendPString(windowTitle, resource->Name()); + AppendPString(windowTitle, "\pÓ"); } // save EditorWindow class in window's refcon - SetWindowRefCon( window, (UInt32) this ); - SetWindowKind( window, kEditorWindowKind ); - SetWindowTitle( window, windowTitle ); + SetWindowRefCon(window, (UInt32) this); + SetWindowKind(window, kEditorWindowKind); + SetWindowTitle(window, windowTitle); } #if !TARGET_API_MAC_CARBON /*** CLOSE ***/ -OSStatus EditorWindow::Close( void ) +OSStatus EditorWindow::Close(void) { // bug: need to tell plug it is about to die. - CloseWindow( window ); + CloseWindow(window); delete this; return noErr; } @@ -51,7 +51,7 @@ OSStatus EditorWindow::Close( void ) #endif /*** RESOURCE ACCESSOR ***/ -ResourceObjectPtr EditorWindow::Resource( void ) +ResourceObjectPtr EditorWindow::Resource(void) { return resource; } \ No newline at end of file diff --git a/Carbon/Classes/EditorWindow.h b/Carbon/Classes/EditorWindow.h index 0b5c79d..4edc189 100644 --- a/Carbon/Classes/EditorWindow.h +++ b/Carbon/Classes/EditorWindow.h @@ -25,13 +25,13 @@ public: * @function EditorWindow * @discussion Constructor function. */ - EditorWindow( FileWindowPtr ownerFile, ResourceObjectPtr targetResource, WindowRef inputWindow ); + EditorWindow(FileWindowPtr ownerFile, ResourceObjectPtr targetResource, WindowRef inputWindow); /*! * @function Close * @discussion Sends a close message to the plug, then closes the window. */ - OSStatus Close( void ); - ResourceObjectPtr Resource( void ); + OSStatus Close(void); + ResourceObjectPtr Resource(void); }; #endif \ No newline at end of file diff --git a/Carbon/Classes/Errors.cpp b/Carbon/Classes/Errors.cpp index 0630d69..822feb8 100644 --- a/Carbon/Classes/Errors.cpp +++ b/Carbon/Classes/Errors.cpp @@ -7,32 +7,32 @@ extern globals g; extern prefs p; /*** DISPLAY ANY ERROR ***/ -OSStatus DisplayError( CFStringRef errorStr ) +OSStatus DisplayError(CFStringRef errorStr) { - #pragma unused( errorStr ) + #pragma unused(errorStr) return noErr; } /*** DISPLAY SIMPLE ERROR ***/ -OSStatus DisplayError( ConstStr255Param errorStr ) +OSStatus DisplayError(ConstStr255Param errorStr) { - return DisplayError( errorStr, "\p" ); + return DisplayError(errorStr, "\p"); } /*** DISPLAY ERROR WITH EXPLANATION */ -OSStatus DisplayError( UInt16 error, UInt16 explanation ) +OSStatus DisplayError(UInt16 error, UInt16 explanation) { Str255 errorStr, explanationStr; - GetIndString( errorStr, kErrorStrings, error ); - GetIndString( explanationStr, kErrorStrings, explanation ); - return DisplayError( errorStr, explanationStr ); + GetIndString(errorStr, kErrorStrings, error); + GetIndString(explanationStr, kErrorStrings, explanation); + return DisplayError(errorStr, explanationStr); } /*** DISPLAY ERROR WITH EXPLANATION */ -OSStatus DisplayError( ConstStr255Param errorStr, ConstStr255Param explanationStr ) +OSStatus DisplayError(ConstStr255Param errorStr, ConstStr255Param explanationStr) { - if( g.surpressErrors ) return noErr; - if( g.useAppearance ) + if(g.surpressErrors) return noErr; + if(g.useAppearance) { SInt16 item; AlertStdAlertParamRec params = {}; @@ -41,49 +41,49 @@ OSStatus DisplayError( ConstStr255Param errorStr, ConstStr255Param explanationSt params.position = kWindowDefaultPosition; #if __profile__ - ProfilerSetStatus( false ); + ProfilerSetStatus(false); #endif SysBeep(0); - StandardAlert( kAlertStopAlert, errorStr, explanationStr, ¶ms, &item ); + StandardAlert(kAlertStopAlert, errorStr, explanationStr, ¶ms, &item); #if __profile__ - ProfilerSetStatus( true ); + ProfilerSetStatus(true); #endif return item == kAlertStdAlertOKButton? noErr:paramErr; } else { - ParamText( errorStr, explanationStr, "\p", "\p" ); - ModalFilterUPP filter = null; // NewModalFilterUPP( ParseDialogEvents ); + ParamText(errorStr, explanationStr, "\p", "\p"); + ModalFilterUPP filter = null; // NewModalFilterUPP(ParseDialogEvents); #if __profile__ - ProfilerSetStatus( false ); + ProfilerSetStatus(false); #endif SysBeep(0); - DialogItemIndex item = StopAlert( 128, filter ); + DialogItemIndex item = StopAlert(128, filter); #if __profile__ - ProfilerSetStatus( true ); + ProfilerSetStatus(true); #endif return item == kAlertStdAlertOKButton? noErr:paramErr; } } /*** DISPLAY ERROR WITH EXPLANATION */ -OSStatus DebugError( UInt16 error, OSStatus number ) +OSStatus DebugError(UInt16 error, OSStatus number) { Str255 errorStr; - GetIndString( errorStr, kDebugStrings, error ); - return DebugError( errorStr, number ); + GetIndString(errorStr, kDebugStrings, error); + return DebugError(errorStr, number); } /*** DISPLAY A DEBUGGING ERROR ***/ -OSStatus DebugError( ConstStr255Param errorStr, OSStatus number ) +OSStatus DebugError(ConstStr255Param errorStr, OSStatus number) { OSStatus error = noErr; - if( g.debug ) + if(g.debug) { Str255 message = "\pDebugging Error ID: ", numString = "\p"; - NumToString( number, numString ); - AppendPString( message, numString ); - error = DisplayError( message, errorStr ); + NumToString(number, numString); + AppendPString(message, numString); + error = DisplayError(message, errorStr); } return error; } \ No newline at end of file diff --git a/Carbon/Classes/Errors.h b/Carbon/Classes/Errors.h index fdfe4e5..70337f9 100644 --- a/Carbon/Classes/Errors.h +++ b/Carbon/Classes/Errors.h @@ -12,31 +12,31 @@ @function DisplayError @discussion Pass a CFStringRef and ResKnife will do noting at all. (yet :) */ -OSStatus DisplayError( CFStringRef error ); +OSStatus DisplayError(CFStringRef error); /*! @function DisplayError @discussion Pass one pascal string and ResKnife will display a simple error message. */ -OSStatus DisplayError( ConstStr255Param error ); +OSStatus DisplayError(ConstStr255Param error); /*! @function DisplayError @discussion Pass two string indecies within kErrorStrings, and they will be displayed as an error message. */ -OSStatus DisplayError( UInt16 error, UInt16 explanation ); +OSStatus DisplayError(UInt16 error, UInt16 explanation); /*! @function DisplayError @discussion Pass two pascal strings and ResKnife will display a more refined error message. */ -OSStatus DisplayError( ConstStr255Param error, ConstStr255Param explanation ); +OSStatus DisplayError(ConstStr255Param error, ConstStr255Param explanation); /*! @function DebugError @discussion Pass an index of a string with kDebugStrings and if debugging mode is on, ResKnife will display the message. */ -OSStatus DebugError( UInt16 error, OSStatus number = noErr ); +OSStatus DebugError(UInt16 error, OSStatus number = noErr); /*! @function DebugError @discussion Pass a pascal string and if debugging mode is on, ResKnife will display the message. */ -OSStatus DebugError( ConstStr255Param errorStr, OSStatus number = noErr ); +OSStatus DebugError(ConstStr255Param errorStr, OSStatus number = noErr); #endif \ No newline at end of file diff --git a/Carbon/Classes/FileWindow.cpp b/Carbon/Classes/FileWindow.cpp index 7c480a7..fb4b926 100644 --- a/Carbon/Classes/FileWindow.cpp +++ b/Carbon/Classes/FileWindow.cpp @@ -12,81 +12,81 @@ extern globals g; #pragma mark Constructor /*** FILE WINDOW CONSTRUCTOR ***/ -FileWindow::FileWindow( FSSpecPtr spec ) +FileWindow::FileWindow(FSSpecPtr spec) { OSStatus error = noErr; #if USE_NIBS // create a nib reference (only searches the application bundle) IBNibRef nibRef = null; - error = CreateNibReference( CFSTR("ResKnife"), &nibRef ); - if( error != noErr || nibRef == null ) + error = CreateNibReference(CFSTR("ResKnife"), &nibRef); + if(error != noErr || nibRef == null) { - DisplayError( "\pThe nib file reference could not be obtained." ); + DisplayError("\pThe nib file reference could not be obtained."); return; } // create window - error = CreateWindowFromNib( nibRef, CFSTR("File Window"), &window ); - if( error != noErr || window == null ) + error = CreateWindowFromNib(nibRef, CFSTR("File Window"), &window); + if(error != noErr || window == null) { - DisposeNibReference( nibRef ); - DisplayError( "\pA file window could not be obtained from the nib file." ); + DisposeNibReference(nibRef); + DisplayError("\pA file window could not be obtained from the nib file."); return; } // dispose of nib ref - DisposeNibReference( nibRef ); + DisposeNibReference(nibRef); #elif TARGET_API_MAC_CARBON // create window Rect creationBounds, sectRect; - SetRect( &creationBounds, 0, 0, kDefaultFileWindowWidth, kDefaultFileWindowHeight ); - GetAvailableWindowPositioningBounds( GetMainDevice(), §Rect ); - InsetRect( §Rect, 0, 10 ); - SectRect( §Rect, &creationBounds, &creationBounds ); - OffsetRect( &creationBounds, 10, 0 ); - WindowAttributes attributes = kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute | kWindowInWindowMenuAttribute; - if( g.systemVersion >= kMacOSX ) attributes |= kWindowLiveResizeAttribute; - error = CreateNewWindow( kDocumentWindowClass, attributes, &creationBounds, &window ); - if( error ) return; + SetRect(&creationBounds, 0, 0, kDefaultFileWindowWidth, kDefaultFileWindowHeight); + GetAvailableWindowPositioningBounds(GetMainDevice(), §Rect); + InsetRect(§Rect, 0, 10); + SectRect(§Rect, &creationBounds, &creationBounds); + OffsetRect(&creationBounds, 10, 0); + WindowAttributes attributes = kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute | kWindowInWindowMenuAttribute; + if(g.systemVersion >= kMacOSX) attributes |= kWindowLiveResizeAttribute; + error = CreateNewWindow(kDocumentWindowClass, attributes, &creationBounds, &window); + if(error) return; #else - if( g.useAppearance && g.systemVersion >= kMacOS8 ) + if(g.useAppearance && g.systemVersion >= kMacOS8) { - window = GetNewCWindow( kFileWindow8, null, kFirstWindowOfClass ); + window = GetNewCWindow(kFileWindow8, null, kFirstWindowOfClass); themeSavvy = true; } else { - window = GetNewCWindow( kFileWindow7, null, kFirstWindowOfClass ); + window = GetNewCWindow(kFileWindow7, null, kFirstWindowOfClass); themeSavvy = false; } #endif // save FileWindow class in window's refcon - SetWindowRefCon( window, (UInt32) this ); - SetWindowKind( window, kFileWindowKind ); - SetWindowTitle( window, spec->name ); + SetWindowRefCon(window, (UInt32) this); + SetWindowKind(window, kFileWindowKind); + SetWindowTitle(window, spec->name); #if TARGET_API_MAC_CARBON // set title used in window menu - SetWindowAlternateTitle( window, null ); // bug: should use path here + SetWindowAlternateTitle(window, null); // bug: should use path here #endif // set window's background to default for theme - if( g.useAppearance ) - SetThemeWindowBackground( window, kThemeBrushModelessDialogBackgroundActive, false ); + if(g.useAppearance) + SetThemeWindowBackground(window, kThemeBrushModelessDialogBackgroundActive, false); #if USE_NIBS // Carbon nib file on Public Beta doesn't let me set this WindowAttributes setThese = null, clearThese = null; setThese = kWindowInWindowMenuAttribute; - ChangeWindowAttributes( window, setThese, clearThese ); + ChangeWindowAttributes(window, setThese, clearThese); #endif // initalise file variables - fileSpec = (FSSpecPtr) NewPtrClear( sizeof(FSSpec) ); - tempSpec = (FSSpecPtr) NewPtrClear( sizeof(FSSpec) ); + fileSpec = (FSSpecPtr) NewPtrClear(sizeof(FSSpec)); + tempSpec = (FSSpecPtr) NewPtrClear(sizeof(FSSpec)); fileDirty = false; - SetFileSpec( spec ); + SetFileSpec(spec); #if TARGET_API_MAC_CARBON dataBrowser = null; #endif @@ -100,156 +100,156 @@ FileWindow::FileWindow( FSSpecPtr spec ) #if TARGET_API_MAC_CARBON // install window event handler EventHandlerRef ref = null; - EventHandlerUPP handler = NewEventHandlerUPP( FileWindowEventHandler ); + EventHandlerUPP handler = NewEventHandlerUPP(FileWindowEventHandler); EventTypeSpec events[] = { { kEventClassWindow, kEventWindowClose }, { kEventClassWindow, kEventWindowBoundsChanging }, { kEventClassWindow, kEventWindowBoundsChanged }, { kEventClassWindow, kEventWindowGetIdealSize }, { kEventClassWindow, kEventWindowZoomed } }; - InstallWindowEventHandler( window, handler, GetEventTypeCount(events), (EventTypeSpec *) &events, this, &ref ); + InstallWindowEventHandler(window, handler, GetEventTypeCount(events), (EventTypeSpec *) &events, this, &ref); EventTypeSpec update = { kEventClassMenu, kEventMenuEnableItems }; EventTypeSpec process = { kEventClassCommand, kEventCommandProcess }; // install menu update handler - handler = NewEventHandlerUPP( FileWindowUpdateMenus ); - InstallWindowEventHandler( window, handler, 1, &update, this, &ref ); + handler = NewEventHandlerUPP(FileWindowUpdateMenus); + InstallWindowEventHandler(window, handler, 1, &update, this, &ref); // install menu selection handler - handler = NewEventHandlerUPP( FileWindowParseMenuSelection ); - InstallWindowEventHandler( window, handler, 1, &process, this, &ref ); + handler = NewEventHandlerUPP(FileWindowParseMenuSelection); + InstallWindowEventHandler(window, handler, 1, &process, this, &ref); #endif #if USE_NIBS // set window property ControlRef dataBrowser; ControlID id = { kDataBrowserSignature, 0 }; - GetControlByID( window, &id, &dataBrowser ); - SetWindowProperty( window, kResKnifeCreator, kWindowPropertyDataBrowser, sizeof(ControlRef), &dataBrowser );; + GetControlByID(window, &id, &dataBrowser); + SetWindowProperty(window, kResKnifeCreator, kWindowPropertyDataBrowser, sizeof(ControlRef), &dataBrowser);; #elif TARGET_API_MAC_CARBON // CarbonLib 1.1+ only // create root control ControlRef root; - CreateRootControl( window, &root ); + CreateRootControl(window, &root); // create header control Rect windowBounds, rect; - GetWindowPortBounds( window, &windowBounds ); - SetRect( &rect, windowBounds.left, windowBounds.top, windowBounds.right, windowBounds.bottom ); - InsetRect( &rect, -1, -1 ); + GetWindowPortBounds(window, &windowBounds); + SetRect(&rect, windowBounds.left, windowBounds.top, windowBounds.right, windowBounds.bottom); + InsetRect(&rect, -1, -1); rect.bottom = rect.top + kDefaultHeaderHeight +1; - CreateWindowHeaderControl( window, &rect, true, &header ); + CreateWindowHeaderControl(window, &rect, true, &header); ControlID id = { kHeaderSignature, 0 }; - SetControlID( header, &id ); + SetControlID(header, &id); // create text controls ControlFontStyleRec fontStyle; fontStyle.flags = kControlUseFontMask + kControlUseJustMask; fontStyle.font = kControlFontSmallSystemFont; fontStyle.just = teJustLeft; - SetRect( &rect, windowBounds.left +4, windowBounds.top +4, (windowBounds.right - windowBounds.left) /5 *3, windowBounds.top + kDefaultHeaderHeight -4 ); - CreateStaticTextControl( window, &rect, CFSTR("left"), &fontStyle, &left ); + SetRect(&rect, windowBounds.left +4, windowBounds.top +4, (windowBounds.right - windowBounds.left) /5 *3, windowBounds.top + kDefaultHeaderHeight -4); + CreateStaticTextControl(window, &rect, CFSTR("left"), &fontStyle, &left); id.id = 0; id.signature = kLeftTextSignature; - SetControlID( left, &id ); + SetControlID(left, &id); fontStyle.just = teJustRight; - SetRect( &rect, (windowBounds.right - windowBounds.left) /5 *2, windowBounds.top +4, windowBounds.right -4, windowBounds.top + kDefaultHeaderHeight -4 ); - CreateStaticTextControl( window, &rect, CFSTR("right"), &fontStyle, &right ); + SetRect(&rect, (windowBounds.right - windowBounds.left) /5 *2, windowBounds.top +4, windowBounds.right -4, windowBounds.top + kDefaultHeaderHeight -4); + CreateStaticTextControl(window, &rect, CFSTR("right"), &fontStyle, &right); id.id = 0; id.signature = kRightTextSignature; - SetControlID( right, &id ); + SetControlID(right, &id); // embed text controls within header - EmbedControl( left, header ); - EmbedControl( right, header ); + EmbedControl(left, header); + EmbedControl(right, header); // create data browser - SetRect( &rect, windowBounds.left, windowBounds.top + kDefaultHeaderHeight +1, windowBounds.right, windowBounds.bottom ); - CreateDataBrowserControl( window, &rect, kDataBrowserListView, &dataBrowser ); + SetRect(&rect, windowBounds.left, windowBounds.top + kDefaultHeaderHeight +1, windowBounds.right, windowBounds.bottom); + CreateDataBrowserControl(window, &rect, kDataBrowserListView, &dataBrowser); id.id = 0; id.signature = kDataBrowserSignature; - SetControlID( dataBrowser, &id ); - SetControlReference( dataBrowser, (UInt32) this ); - SetWindowProperty( window, kResKnifeCreator, kWindowPropertyDataBrowser, sizeof(ControlRef), &dataBrowser ); - SetKeyboardFocus( window, dataBrowser, kControlDataBrowserPart ); + SetControlID(dataBrowser, &id); + SetControlReference(dataBrowser, (UInt32) this); + SetWindowProperty(window, kResKnifeCreator, kWindowPropertyDataBrowser, sizeof(ControlRef), &dataBrowser); + SetKeyboardFocus(window, dataBrowser, kControlDataBrowserPart); #elif !TARGET_API_MAC_CARBON // create controls - if( themeSavvy ) + if(themeSavvy) { // create basic window controls - header = GetNewControl( kFileHeaderControl, window ); - horizScroll = GetNewControl( kAppearanceScrollBarControl, window ); - vertScroll = GetNewControl( kAppearanceScrollBarControl, window ); + header = GetNewControl(kFileHeaderControl, window); + horizScroll = GetNewControl(kAppearanceScrollBarControl, window); + vertScroll = GetNewControl(kAppearanceScrollBarControl, window); // create sort buttons Rect bounds = {}; - sortName = NewControl( window, &bounds, "\pName", true, 0, kControlBehaviorSticky + kControlContentTextOnly, 0, kControlBevelButtonSmallBevelProc, 0 ); - sortType = NewControl( window, &bounds, "\pType", true, 0, kControlBehaviorSticky + kControlContentTextOnly, 0, kControlBevelButtonSmallBevelProc, 0 ); - sortID = NewControl( window, &bounds, "\pID", true, 0, kControlBehaviorSticky + kControlContentTextOnly, 0, kControlBevelButtonSmallBevelProc, 0 ); - sortSize = NewControl( window, &bounds, "\pSize", true, 0, kControlBehaviorSticky + kControlContentTextOnly, 0, kControlBevelButtonSmallBevelProc, 0 ); - sortAttrs = NewControl( window, &bounds, "\pAttributes", true, 0, kControlBehaviorSticky + kControlContentTextOnly, 0, kControlBevelButtonSmallBevelProc, 0 ); - sortDir = NewControl( window, &bounds, "\p", true, 0, kControlContentIconSuiteRes, kSortUpIcon, kControlBevelButtonSmallBevelProc, 0 ); + sortName = NewControl(window, &bounds, "\pName", true, 0, kControlBehaviorSticky + kControlContentTextOnly, 0, kControlBevelButtonSmallBevelProc, 0); + sortType = NewControl(window, &bounds, "\pType", true, 0, kControlBehaviorSticky + kControlContentTextOnly, 0, kControlBevelButtonSmallBevelProc, 0); + sortID = NewControl(window, &bounds, "\pID", true, 0, kControlBehaviorSticky + kControlContentTextOnly, 0, kControlBevelButtonSmallBevelProc, 0); + sortSize = NewControl(window, &bounds, "\pSize", true, 0, kControlBehaviorSticky + kControlContentTextOnly, 0, kControlBevelButtonSmallBevelProc, 0); + sortAttrs = NewControl(window, &bounds, "\pAttributes", true, 0, kControlBehaviorSticky + kControlContentTextOnly, 0, kControlBevelButtonSmallBevelProc, 0); + sortDir = NewControl(window, &bounds, "\p", true, 0, kControlContentIconSuiteRes, kSortUpIcon, kControlBevelButtonSmallBevelProc, 0); nameColumnWidth = kFileWindowDefaultNameColumnWidth; // put the text in the right place - SetBevelButtonTextAlignment( sortName, kControlBevelButtonAlignTextFlushLeft, kFileWindowNameColumnTextOffset -1 ); - SetBevelButtonTextAlignment( sortType, kControlBevelButtonAlignTextFlushRight, 5 ); - SetBevelButtonTextAlignment( sortSize, kControlBevelButtonAlignTextFlushRight, 5 ); - SetBevelButtonTextAlignment( sortID, kControlBevelButtonAlignTextFlushRight, 5 ); - SetBevelButtonTextAlignment( sortAttrs, kControlBevelButtonAlignTextCenter, 0 ); + SetBevelButtonTextAlignment(sortName, kControlBevelButtonAlignTextFlushLeft, kFileWindowNameColumnTextOffset -1); + SetBevelButtonTextAlignment(sortType, kControlBevelButtonAlignTextFlushRight, 5); + SetBevelButtonTextAlignment(sortSize, kControlBevelButtonAlignTextFlushRight, 5); + SetBevelButtonTextAlignment(sortID, kControlBevelButtonAlignTextFlushRight, 5); + SetBevelButtonTextAlignment(sortAttrs, kControlBevelButtonAlignTextCenter, 0); // set up font details - ControlFontStylePtr fontStyle = (ControlFontStylePtr) NewPtrClear( sizeof(ControlFontStyleRec) ); + ControlFontStylePtr fontStyle = (ControlFontStylePtr) NewPtrClear(sizeof(ControlFontStyleRec)); fontStyle->flags = kControlUseFontMask + kControlUseSizeMask; fontStyle->font = kControlFontSmallSystemFont; // apply font details to controls - SetControlFontStyle( sortName, fontStyle ); - SetControlFontStyle( sortType, fontStyle ); - SetControlFontStyle( sortSize, fontStyle ); - SetControlFontStyle( sortID, fontStyle ); - SetControlFontStyle( sortAttrs, fontStyle ); + SetControlFontStyle(sortName, fontStyle); + SetControlFontStyle(sortType, fontStyle); + SetControlFontStyle(sortSize, fontStyle); + SetControlFontStyle(sortID, fontStyle); + SetControlFontStyle(sortAttrs, fontStyle); // depress type control - SetControlValue( sortType, 1 ); + SetControlValue(sortType, 1); sortOrder = kSortType; // size the controls correctly - MoveControl( sortName, -1, kDefaultHeaderHeight +1 ); - SizeControl( sortName, nameColumnWidth, kBevelButtonHeight ); + MoveControl(sortName, -1, kDefaultHeaderHeight +1); + SizeControl(sortName, nameColumnWidth, kBevelButtonHeight); - MoveControl( sortType, nameColumnWidth -1, kDefaultHeaderHeight +1 ); - SizeControl( sortType, kFileWindowTypeColumnWidth, kBevelButtonHeight ); + MoveControl(sortType, nameColumnWidth -1, kDefaultHeaderHeight +1); + SizeControl(sortType, kFileWindowTypeColumnWidth, kBevelButtonHeight); - MoveControl( sortID, nameColumnWidth + kFileWindowTypeColumnWidth -1, kDefaultHeaderHeight +1 ); - SizeControl( sortID, kFileWindowIDColumnWidth, kBevelButtonHeight ); + MoveControl(sortID, nameColumnWidth + kFileWindowTypeColumnWidth -1, kDefaultHeaderHeight +1); + SizeControl(sortID, kFileWindowIDColumnWidth, kBevelButtonHeight); - MoveControl( sortSize, nameColumnWidth + kFileWindowTypeColumnWidth + kFileWindowIDColumnWidth -1, kDefaultHeaderHeight +1 ); - SizeControl( sortSize, kFileWindowSizeColumnWidth, kBevelButtonHeight ); + MoveControl(sortSize, nameColumnWidth + kFileWindowTypeColumnWidth + kFileWindowIDColumnWidth -1, kDefaultHeaderHeight +1); + SizeControl(sortSize, kFileWindowSizeColumnWidth, kBevelButtonHeight); - MoveControl( sortAttrs, nameColumnWidth + kFileWindowTypeColumnWidth + kFileWindowIDColumnWidth + kFileWindowSizeColumnWidth -1, kDefaultHeaderHeight +1 ); - SizeControl( sortAttrs, kFileWindowAttributesColumnWidth, kBevelButtonHeight ); + MoveControl(sortAttrs, nameColumnWidth + kFileWindowTypeColumnWidth + kFileWindowIDColumnWidth + kFileWindowSizeColumnWidth -1, kDefaultHeaderHeight +1); + SizeControl(sortAttrs, kFileWindowAttributesColumnWidth, kBevelButtonHeight); - MoveControl( sortDir, nameColumnWidth + kFileWindowTypeColumnWidth + kFileWindowIDColumnWidth + kFileWindowSizeColumnWidth + kFileWindowAttributesColumnWidth -1, kDefaultHeaderHeight +1 ); - SizeControl( sortDir, kFileWindowSortColumnWidth, kBevelButtonHeight ); + MoveControl(sortDir, nameColumnWidth + kFileWindowTypeColumnWidth + kFileWindowIDColumnWidth + kFileWindowSizeColumnWidth + kFileWindowAttributesColumnWidth -1, kDefaultHeaderHeight +1); + SizeControl(sortDir, kFileWindowSortColumnWidth, kBevelButtonHeight); } else { nameColumnWidth = kFileWindowDefaultNameColumnWidth; - horizScroll = GetNewControl( kSystem7ScrollBarControl, window ); - vertScroll = GetNewControl( kSystem7ScrollBarControl, window ); + horizScroll = GetNewControl(kSystem7ScrollBarControl, window); + vertScroll = GetNewControl(kSystem7ScrollBarControl, window); } // move & update scroll bars to where they should be :) - BoundsChanged( null ); + BoundsChanged(null); #endif // read forks into memory and error = ReadResourceFork(); - error = ReadDataFork( error ); - if( error ) + error = ReadDataFork(error); + if(error) { delete this; return; @@ -261,20 +261,20 @@ FileWindow::FileWindow( FSSpecPtr spec ) #endif // now finally we can show the window - ShowWindow( window ); + ShowWindow(window); new InspectorWindow; } /*** DESTRUCTOR ***/ -FileWindow::~FileWindow( void ) +FileWindow::~FileWindow(void) { - DisposeWindow( window ); - if( fileSpec ) DisposePtr( (Ptr) fileSpec ); - if( resourceMap ) DisposeResourceMap(); + DisposeWindow(window); + if(fileSpec) DisposePtr((Ptr) fileSpec); + if(resourceMap) DisposeResourceMap(); } /*** WINDOW ACCESSOR ***/ -WindowRef FileWindow::Window( void ) +WindowRef FileWindow::Window(void) { return window; } @@ -286,77 +286,77 @@ WindowRef FileWindow::Window( void ) #if TARGET_API_MAC_CARBON /*** FILE WINDOW EVENT HANDLER ***/ -pascal OSStatus FileWindowEventHandler( EventHandlerCallRef callRef, EventRef event, void *userData ) +pascal OSStatus FileWindowEventHandler(EventHandlerCallRef callRef, EventRef event, void *userData) { - #pragma unused( callRef ) + #pragma unused(callRef) OSStatus error = eventNotHandledErr; - unsigned long eventClass = GetEventClass( event ); - unsigned long eventKind = GetEventKind( event ); + unsigned long eventClass = GetEventClass(event); + unsigned long eventKind = GetEventKind(event); FileWindowPtr file = (FileWindowPtr) userData; - if( !file ) return eventNotHandledErr; + if(!file) return eventNotHandledErr; - switch( eventClass ) + switch(eventClass) { case kEventClassWindow: - switch( eventKind ) + switch(eventKind) { case kEventWindowClose: { WindowRef window = FrontNonFloatingWindow(), nextWindow; - while( window ) + while(window) { - nextWindow = GetNextWindow( window ); - SInt32 kind = GetWindowKind( window ); - if( kind == kPickerWindowKind || kind == kEditorWindowKind ) + nextWindow = GetNextWindow(window); + SInt32 kind = GetWindowKind(window); + if(kind == kPickerWindowKind || kind == kEditorWindowKind) { - FileWindowPtr owner = (FileWindowPtr) ((PlugWindowPtr) GetWindowRefCon( window ))->File(); - if( owner == file ) + FileWindowPtr owner = (FileWindowPtr) ((PlugWindowPtr) GetWindowRefCon(window))->File(); + if(owner == file) { -// DisposeWindow( window ); // bug: windows didn't used to close when sent a WindowClose event! (seems to work now though) +// DisposeWindow(window); // bug: windows didn't used to close when sent a WindowClose event! (seems to work now though) EventRef event; - CreateEvent( null, kEventClassWindow, kEventWindowClose, kEventDurationNoWait, kEventAttributeNone, &event ); - SendEventToWindow( event, window ); - ReleaseEvent( event ); + CreateEvent(null, kEventClassWindow, kEventWindowClose, kEventDurationNoWait, kEventAttributeNone, &event); + SendEventToWindow(event, window); + ReleaseEvent(event); } } window = nextWindow; } // feature to add: user chooses either resource-level or file-level (or both) save sheets - if( file->IsFileDirty() ) - if( g.useSheets ) error = file->DisplayModelessAskSaveChangesDialog(); + if(file->IsFileDirty()) + if(g.useSheets) error = file->DisplayModelessAskSaveChangesDialog(); else error = file->DisplaySaveDialog(); else error = noErr; - if( error != userCanceledErr ) + if(error != userCanceledErr) delete file; } break; case kEventWindowBoundsChanging: - error = file->BoundsChanging( event ); + error = file->BoundsChanging(event); break; case kEventWindowBoundsChanged: - error = file->BoundsChanged( event ); + error = file->BoundsChanged(event); break; case kEventWindowZoomed: - error = file->Zoomed( event ); + error = file->Zoomed(event); break; case kEventWindowGetIdealSize: - error = file->SetIdealSize( event ); + error = file->SetIdealSize(event); break; } break; case kEventClassCommand: HICommand command; - error = GetEventParameter( event, kEventParamDirectObject, typeHICommand, null, sizeof(HICommand), null, &command ); - if( error ) return eventNotHandledErr; + error = GetEventParameter(event, kEventParamDirectObject, typeHICommand, null, sizeof(HICommand), null, &command); + if(error) return eventNotHandledErr; else error = eventNotHandledErr; - switch( eventKind ) + switch(eventKind) { case kEventCommandProcess: -/* switch( command.commandID ) +/* switch(command.commandID) { } */ break; @@ -367,96 +367,96 @@ pascal OSStatus FileWindowEventHandler( EventHandlerCallRef callRef, EventRef ev } /*** FILE WINDOW UPDATE MENUS ***/ -pascal OSStatus FileWindowUpdateMenus( EventHandlerCallRef callRef, EventRef event, void *userData ) +pascal OSStatus FileWindowUpdateMenus(EventHandlerCallRef callRef, EventRef event, void *userData) { - #pragma unused( callRef, event ) + #pragma unused(callRef, event) // OSStatus error = eventNotHandledErr; // get file window FileWindowPtr file = (FileWindowPtr) userData; - if( !file ) return eventNotHandledErr; + if(!file) return eventNotHandledErr; // get number of resources selected UInt32 numSelected; - GetDataBrowserItemCount( file->GetDataBrowser(), kDataBrowserNoItem, true, kDataBrowserItemIsSelected, &numSelected ); + GetDataBrowserItemCount(file->GetDataBrowser(), kDataBrowserNoItem, true, kDataBrowserItemIsSelected, &numSelected); // determine if selected resource is of type 'snd ' Boolean canPlaySound = false; ResourceObjectPtr resource = null; DataBrowserItemID first, last, n; - GetDataBrowserSelectionAnchor( file->GetDataBrowser(), &first, &last ); - if( first != kDataBrowserNoItem && last != kDataBrowserNoItem ) + GetDataBrowserSelectionAnchor(file->GetDataBrowser(), &first, &last); + if(first != kDataBrowserNoItem && last != kDataBrowserNoItem) { - for( n = first; n <= last; n++ ) + for(n = first; n <= last; n++) { - resource = file->GetResource( n ); - if( resource->Type() == soundListRsrc ) + resource = file->GetResource(n); + if(resource->Type() == soundListRsrc) canPlaySound = true; } } // edit menu - EnableCommand( null, kHICommandUndo, false ); - EnableCommand( null, kHICommandRedo, false ); -/* EnableCommand( null, kHICommandCut, numSelected > 0 ); - EnableCommand( null, kHICommandCopy, numSelected > 0 ); - EnableCommand( null, kHICommandPaste, numSelected > 0 ); - EnableCommand( null, kHICommandClear, numSelected > 0 ); -*/ EnableCommand( null, kHICommandCut, false ); - EnableCommand( null, kHICommandCopy, false ); - EnableCommand( null, kHICommandPaste, false ); - EnableCommand( null, kHICommandClear, false ); - EnableCommand( null, kHICommandSelectAll, true ); - EnableCommand( null, kMenuCommandFind, false ); - EnableCommand( null, kMenuCommandFindAgain, false ); + EnableCommand(null, kHICommandUndo, false); + EnableCommand(null, kHICommandRedo, false); +/* EnableCommand(null, kHICommandCut, numSelected > 0); + EnableCommand(null, kHICommandCopy, numSelected > 0); + EnableCommand(null, kHICommandPaste, numSelected > 0); + EnableCommand(null, kHICommandClear, numSelected > 0); +*/ EnableCommand(null, kHICommandCut, false); + EnableCommand(null, kHICommandCopy, false); + EnableCommand(null, kHICommandPaste, false); + EnableCommand(null, kHICommandClear, false); + EnableCommand(null, kHICommandSelectAll, true); + EnableCommand(null, kMenuCommandFind, false); + EnableCommand(null, kMenuCommandFindAgain, false); // resource menu - EnableCommand( null, kMenuCommandNewResource, true ); - EnableCommand( null, kMenuCommandOpenHex, numSelected > 0 ); - EnableCommand( null, kMenuCommandOpenDefault, numSelected > 0 ); - EnableCommand( null, kMenuCommandOpenTemplate, numSelected > 0 ); - EnableCommand( null, kMenuCommandOpenSpecific, numSelected > 0 ); - EnableCommand( null, kMenuCommandRevertResource, numSelected > 0 ); - EnableCommand( null, kMenuCommandPlaySound, numSelected > 0 && canPlaySound ); + EnableCommand(null, kMenuCommandNewResource, true); + EnableCommand(null, kMenuCommandOpenHex, numSelected > 0); + EnableCommand(null, kMenuCommandOpenDefault, numSelected > 0); + EnableCommand(null, kMenuCommandOpenTemplate, numSelected > 0); + EnableCommand(null, kMenuCommandOpenSpecific, numSelected > 0); + EnableCommand(null, kMenuCommandRevertResource, numSelected > 0); + EnableCommand(null, kMenuCommandPlaySound, numSelected > 0 && canPlaySound); return eventNotHandledErr; } /*** FILE WINDOW PARSE MENU SELECTION ***/ -pascal OSStatus FileWindowParseMenuSelection( EventHandlerCallRef callRef, EventRef event, void *userData ) +pascal OSStatus FileWindowParseMenuSelection(EventHandlerCallRef callRef, EventRef event, void *userData) { - #pragma unused( callRef ) + #pragma unused(callRef) // get menu command HICommand menuCommand; - OSStatus error = GetEventParameter( event, kEventParamDirectObject, typeHICommand, null, sizeof(HICommand), null, &menuCommand ); - if( error ) return eventNotHandledErr; + OSStatus error = GetEventParameter(event, kEventParamDirectObject, typeHICommand, null, sizeof(HICommand), null, &menuCommand); + if(error) return eventNotHandledErr; // get file window FileWindowPtr file = (FileWindowPtr) userData; - if( !file ) return eventNotHandledErr; + if(!file) return eventNotHandledErr; - switch( menuCommand.commandID ) + switch(menuCommand.commandID) { // file menu case kMenuCommandCloseWindow: case kMenuCommandCloseFile: EventRef event; - CreateEvent( null, kEventClassWindow, kEventWindowClose, kEventDurationNoWait, kEventAttributeNone, &event ); - SendEventToWindow( event, file->Window() ); - ReleaseEvent( event ); + CreateEvent(null, kEventClassWindow, kEventWindowClose, kEventDurationNoWait, kEventAttributeNone, &event); + SendEventToWindow(event, file->Window()); + ReleaseEvent(event); break; case kMenuCommandSaveFile: - error = file->SaveFile( null ); + error = file->SaveFile(null); break; case kMenuCommandSaveFileAs: - if( g.useSheets ) error = file->DisplayModelessPutFileDialog(); + if(g.useSheets) error = file->DisplayModelessPutFileDialog(); else error = file->DisplaySaveAsDialog(); break; case kMenuCommandRevertFile: - if( g.useSheets ) error = file->DisplayModelessAskDiscardChangesDialog(); + if(g.useSheets) error = file->DisplayModelessAskDiscardChangesDialog(); else error = file->DisplayRevertFileDialog(); break; @@ -471,7 +471,7 @@ pascal OSStatus FileWindowParseMenuSelection( EventHandlerCallRef callRef, Event case kHICommandPaste: case kHICommandClear: */ case kHICommandSelectAll: - ForEachDataBrowserItem( file->GetDataBrowser(), kDataBrowserNoItem, true, kDataBrowserItemIsSelected, null, null ); + ForEachDataBrowserItem(file->GetDataBrowser(), kDataBrowserNoItem, true, kDataBrowserItemIsSelected, null, null); break; /* case kHICommandHide: case kHICommandPreferences: @@ -483,7 +483,7 @@ pascal OSStatus FileWindowParseMenuSelection( EventHandlerCallRef callRef, Event */ // resource menu case kMenuCommandNewResource: - if( g.useSheets ) error = file->DisplayNewResourceSheet(); + if(g.useSheets) error = file->DisplayNewResourceSheet(); else error = file->DisplayNewResourceDialog(); break; @@ -492,14 +492,14 @@ pascal OSStatus FileWindowParseMenuSelection( EventHandlerCallRef callRef, Event case kMenuCommandOpenSpecific: case kMenuCommandOpenHex: #if TARGET_API_MAC_CARBON - for( DataBrowserItemID item = 1; item <= file->GetResourceCount(); item++ ) + for(DataBrowserItemID item = 1; item <= file->GetResourceCount(); item++) { - if( IsDataBrowserItemSelected( file->GetDataBrowser(), item ) ) - error = file->OpenResource( item, menuCommand.commandID ); - if( error ) return eventNotHandledErr; + if(IsDataBrowserItemSelected(file->GetDataBrowser(), item)) + error = file->OpenResource(item, menuCommand.commandID); + if(error) return eventNotHandledErr; } #else - DisplayDialog( "\pAs I haven't wired up Classic Events, no Editors work in classic mode." ); + DisplayDialog("\pAs I haven't wired up Classic Events, no Editors work in classic mode."); #endif break; @@ -508,12 +508,12 @@ pascal OSStatus FileWindowParseMenuSelection( EventHandlerCallRef callRef, Event case kMenuCommandPlaySound: DataBrowserItemID first, last, n; - GetDataBrowserSelectionAnchor( file->GetDataBrowser(), &first, &last ); - for( n = first; n <= last; n++ ) + GetDataBrowserSelectionAnchor(file->GetDataBrowser(), &first, &last); + for(n = first; n <= last; n++) { - ResourceObjectPtr resource = file->GetResource( n ); - if( resource->Type() == soundListRsrc ) - file->PlaySound( n ); + ResourceObjectPtr resource = file->GetResource(n); + if(resource->Type() == soundListRsrc) + file->PlaySound(n); } break; @@ -526,126 +526,126 @@ pascal OSStatus FileWindowParseMenuSelection( EventHandlerCallRef callRef, Event #endif /*** WINDOW BOUNDS ARE CHANGING ***/ -OSStatus FileWindow::BoundsChanging( EventRef event ) +OSStatus FileWindow::BoundsChanging(EventRef event) { OSStatus error = noErr; #if TARGET_API_MAC_CARBON // check that window is not just being dragged UInt32 attributes; - error = GetEventParameter( event, kEventParamAttributes, typeUInt32, null, sizeof(UInt32), null, &attributes ); - if( error || attributes & kWindowBoundsChangeUserDrag ) return eventNotHandledErr; - if( g.systemVersion < kMacOSX ) return noErr; + error = GetEventParameter(event, kEventParamAttributes, typeUInt32, null, sizeof(UInt32), null, &attributes); + if(error || attributes & kWindowBoundsChangeUserDrag) return eventNotHandledErr; + if(g.systemVersion < kMacOSX) return noErr; // resize window's contents error = eventNotHandledErr; - if( g.systemVersion >= kMacOSX ) + if(g.systemVersion >= kMacOSX) { Rect windowBounds; - error = GetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, null, sizeof(Rect), null, &windowBounds ); - if( error ) return eventNotHandledErr; - SizeControl( dataBrowser, windowBounds.right - windowBounds.left, windowBounds.bottom - windowBounds.top - kDefaultHeaderHeight -1 ); + error = GetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, null, sizeof(Rect), null, &windowBounds); + if(error) return eventNotHandledErr; + SizeControl(dataBrowser, windowBounds.right - windowBounds.left, windowBounds.bottom - windowBounds.top - kDefaultHeaderHeight -1); } #else - #pragma unused( event ) + #pragma unused(event) #endif return error; } /*** WINDOW BOUNDS HAVE CHANGED ***/ -OSStatus FileWindow::BoundsChanged( EventRef event ) +OSStatus FileWindow::BoundsChanged(EventRef event) { #if TARGET_API_MAC_CARBON - if( event ) + if(event) { // check that window is not just being dragged UInt32 attributes; - OSStatus error = GetEventParameter( event, kEventParamAttributes, typeUInt32, null, sizeof(UInt32), null, &attributes ); - if( error || attributes & kWindowBoundsChangeUserDrag ) return eventNotHandledErr; + OSStatus error = GetEventParameter(event, kEventParamAttributes, typeUInt32, null, sizeof(UInt32), null, &attributes); + if(error || attributes & kWindowBoundsChangeUserDrag) return eventNotHandledErr; } #else - #pragma unused( event ) + #pragma unused(event) #endif GrafPtr oldPort; - GetPort( &oldPort ); - SetPortWindowPort( window ); + GetPort(&oldPort); + SetPortWindowPort(window); // move everything and invalidate the area Rect windowBounds; - if( g.windowMgrAvailable ) GetWindowBounds( window, kWindowContentRgn, &windowBounds ); - else GetPortBounds( (CGrafPtr) window, &windowBounds ); - OffsetRect( &windowBounds, -windowBounds.left, -windowBounds.top ); + if(g.windowMgrAvailable) GetWindowBounds(window, kWindowContentRgn, &windowBounds); + else GetPortBounds((CGrafPtr) window, &windowBounds); + OffsetRect(&windowBounds, -windowBounds.left, -windowBounds.top); #if TARGET_API_MAC_CARBON // resize header & data browser - SizeControl( header, (windowBounds.right - windowBounds.left) +2, kDefaultHeaderHeight +1 ); - SizeControl( left, (windowBounds.right - windowBounds.left) /2 -4, kDefaultHeaderHeight -4 ); - SizeControl( right, (windowBounds.right - windowBounds.left) /2 -4, kDefaultHeaderHeight -4 ); - MoveControl( right, (windowBounds.right - windowBounds.left) /2, 2 ); - SizeControl( dataBrowser, windowBounds.right - windowBounds.left, windowBounds.bottom - windowBounds.top - kDefaultHeaderHeight -1 ); + SizeControl(header, (windowBounds.right - windowBounds.left) +2, kDefaultHeaderHeight +1); + SizeControl(left, (windowBounds.right - windowBounds.left) /2 -4, kDefaultHeaderHeight -4); + SizeControl(right, (windowBounds.right - windowBounds.left) /2 -4, kDefaultHeaderHeight -4); + MoveControl(right, (windowBounds.right - windowBounds.left) /2, 2); + SizeControl(dataBrowser, windowBounds.right - windowBounds.left, windowBounds.bottom - windowBounds.top - kDefaultHeaderHeight -1); #else - if( themeSavvy ) + if(themeSavvy) { nameColumnWidth = windowBounds.right - kFileWindowAllOtherColumnWidths -6; - if( nameColumnWidth < kFileWindowMinimumNameColumnWidth ) nameColumnWidth = kFileWindowMinimumNameColumnWidth; - SizeControl( header, windowBounds.right +2 - windowBounds.left, kDefaultHeaderHeight +2 ); - SizeControl( sortName, nameColumnWidth, kBevelButtonHeight ); - MoveControl( sortType, (nameColumnWidth -1), kDefaultHeaderHeight +1 ); - MoveControl( sortID, (nameColumnWidth -1) + kFileWindowTypeColumnWidth, kDefaultHeaderHeight +1 ); - MoveControl( sortSize, (nameColumnWidth -1) + kFileWindowTypeColumnWidth + kFileWindowIDColumnWidth, kDefaultHeaderHeight +1 ); - MoveControl( sortAttrs, (nameColumnWidth -1) + kFileWindowTypeColumnWidth + kFileWindowIDColumnWidth + kFileWindowSizeColumnWidth, kDefaultHeaderHeight +1 ); - MoveControl( sortDir, (nameColumnWidth -1) + kFileWindowTypeColumnWidth + kFileWindowIDColumnWidth + kFileWindowSizeColumnWidth + kFileWindowAttributesColumnWidth, kDefaultHeaderHeight +1 ); + if(nameColumnWidth < kFileWindowMinimumNameColumnWidth) nameColumnWidth = kFileWindowMinimumNameColumnWidth; + SizeControl(header, windowBounds.right +2 - windowBounds.left, kDefaultHeaderHeight +2); + SizeControl(sortName, nameColumnWidth, kBevelButtonHeight); + MoveControl(sortType, (nameColumnWidth -1), kDefaultHeaderHeight +1); + MoveControl(sortID, (nameColumnWidth -1) + kFileWindowTypeColumnWidth, kDefaultHeaderHeight +1); + MoveControl(sortSize, (nameColumnWidth -1) + kFileWindowTypeColumnWidth + kFileWindowIDColumnWidth, kDefaultHeaderHeight +1); + MoveControl(sortAttrs, (nameColumnWidth -1) + kFileWindowTypeColumnWidth + kFileWindowIDColumnWidth + kFileWindowSizeColumnWidth, kDefaultHeaderHeight +1); + MoveControl(sortDir, (nameColumnWidth -1) + kFileWindowTypeColumnWidth + kFileWindowIDColumnWidth + kFileWindowSizeColumnWidth + kFileWindowAttributesColumnWidth, kDefaultHeaderHeight +1); } - MoveControl( horizScroll, -1, windowBounds.bottom - (kScrollBarWidth -1) ); - SizeControl( horizScroll, windowBounds.right - (kScrollBarWidth -3), kScrollBarWidth ); - MoveControl( vertScroll, windowBounds.right - (kScrollBarWidth -1), kFileWindowHeaderHeight ); - SizeControl( vertScroll, kScrollBarWidth, windowBounds.bottom - kFileWindowHeaderHeight - (kScrollBarWidth -2) ); - if( themeSavvy && g.systemVersion >= kMacOS85 ) + MoveControl(horizScroll, -1, windowBounds.bottom - (kScrollBarWidth -1)); + SizeControl(horizScroll, windowBounds.right - (kScrollBarWidth -3), kScrollBarWidth); + MoveControl(vertScroll, windowBounds.right - (kScrollBarWidth -1), kFileWindowHeaderHeight); + SizeControl(vertScroll, kScrollBarWidth, windowBounds.bottom - kFileWindowHeaderHeight - (kScrollBarWidth -2)); + if(themeSavvy && g.systemVersion >= kMacOS85) { - SetControlViewSize( horizScroll, nameColumnWidth + kFileWindowAllOtherColumnWidths ); - SetControlViewSize( vertScroll, windowBounds.bottom - (kScrollBarWidth -1) - kFileWindowHeaderHeight ); + SetControlViewSize(horizScroll, nameColumnWidth + kFileWindowAllOtherColumnWidths); + SetControlViewSize(vertScroll, windowBounds.bottom - (kScrollBarWidth -1) - kFileWindowHeaderHeight); } UpdateScrollBars(); #endif #if TARGET_API_MAC_CARBON - InvalidateWindowRect( window, &windowBounds ); + InvalidateWindowRect(window, &windowBounds); #else - if( g.windowMgrAvailable ) InvalidateWindowRect( window, &windowBounds ); - else InvalidateRect( &windowBounds ); + if(g.windowMgrAvailable) InvalidateWindowRect(window, &windowBounds); + else InvalidateRect(&windowBounds); #endif - SetPort( oldPort ); + SetPort(oldPort); return noErr; } #if TARGET_API_MAC_CARBON /*** WINDOW HAS BEEN ZOOMED ***/ -OSStatus FileWindow::Zoomed( EventRef event ) +OSStatus FileWindow::Zoomed(EventRef event) { // get new bounds WindowRef window; Rect windowBounds; - OSStatus error = GetEventParameter( event, kEventParamDirectObject, typeWindowRef, null, sizeof(WindowRef), null, &window ); - if( error ) return eventNotHandledErr; - GetWindowBounds( window, kWindowGlobalPortRgn, &windowBounds ); - OffsetRect( &windowBounds, -windowBounds.left, -windowBounds.top ); + OSStatus error = GetEventParameter(event, kEventParamDirectObject, typeWindowRef, null, sizeof(WindowRef), null, &window); + if(error) return eventNotHandledErr; + GetWindowBounds(window, kWindowGlobalPortRgn, &windowBounds); + OffsetRect(&windowBounds, -windowBounds.left, -windowBounds.top); // resize controls to the window size - SizeControl( header, windowBounds.right - windowBounds.left +2, kDefaultHeaderHeight +1 ); - SizeControl( left, (windowBounds.right - windowBounds.left) /5 *3 - windowBounds.left +4, kDefaultHeaderHeight - windowBounds.top -8 ); - MoveControl( right, (windowBounds.right - windowBounds.left) /5 *2, windowBounds.top +4 ); - SizeControl( right, windowBounds.right - ((windowBounds.right - windowBounds.left) /5 *2) -4, kDefaultHeaderHeight - windowBounds.top -8 ); - SizeControl( dataBrowser, windowBounds.right - windowBounds.left, windowBounds.bottom - windowBounds.top - kDefaultHeaderHeight -1 ); + SizeControl(header, windowBounds.right - windowBounds.left +2, kDefaultHeaderHeight +1); + SizeControl(left, (windowBounds.right - windowBounds.left) /5 *3 - windowBounds.left +4, kDefaultHeaderHeight - windowBounds.top -8); + MoveControl(right, (windowBounds.right - windowBounds.left) /5 *2, windowBounds.top +4); + SizeControl(right, windowBounds.right - ((windowBounds.right - windowBounds.left) /5 *2) -4, kDefaultHeaderHeight - windowBounds.top -8); + SizeControl(dataBrowser, windowBounds.right - windowBounds.left, windowBounds.bottom - windowBounds.top - kDefaultHeaderHeight -1); return error; } /*** SET IDEAL SIZE OF WINDOW ***/ -OSStatus FileWindow::SetIdealSize( EventRef event ) +OSStatus FileWindow::SetIdealSize(EventRef event) { Point idealSize; - SetPoint( &idealSize, 512, 512 ); - OSStatus error = SetEventParameter( event, kEventParamDimensions, typeQDPoint, sizeof(Point), &idealSize ); + SetPoint(&idealSize, 512, 512); + OSStatus error = SetEventParameter(event, kEventParamDimensions, typeQDPoint, sizeof(Point), &idealSize); return error? eventNotHandledErr:noErr; } @@ -653,136 +653,136 @@ OSStatus FileWindow::SetIdealSize( EventRef event ) #if !TARGET_API_MAC_CARBON /*** UPDATE WINDOW ***/ -OSStatus FileWindow::Update( RgnHandle update ) +OSStatus FileWindow::Update(RgnHandle update) { GrafPtr oldPort; - GetPort( &oldPort ); - SetPortWindowPort( window ); + GetPort(&oldPort); + SetPortWindowPort(window); // get rect into which I can draw Rect windowBounds, rect; - if( g.windowMgrAvailable ) GetWindowBounds( window, kWindowContentRgn, &windowBounds ); - else GetPortBounds( (CGrafPort *) window, &windowBounds ); - SetRect( &rect, 0, 0, windowBounds.right - windowBounds.left, windowBounds.bottom - windowBounds.top ); + if(g.windowMgrAvailable) GetWindowBounds(window, kWindowContentRgn, &windowBounds); + else GetPortBounds((CGrafPort *) window, &windowBounds); + SetRect(&rect, 0, 0, windowBounds.right - windowBounds.left, windowBounds.bottom - windowBounds.top); rect.top += kFileWindowHeaderHeight +1; rect.bottom -= (kScrollBarWidth -1); rect.right -= (kScrollBarWidth -1); // only draw resources if they are in the update region - if( !update || RectInRgn( &windowBounds, update ) ) + if(!update || RectInRgn(&windowBounds, update)) { RgnHandle clip = NewRgn(), oldClip = NewRgn(); - RectToRegion( clip, &rect ); - GetPortClipRegion( GetWindowPort( window ), oldClip ); - SetPortClipRegion( GetWindowPort( window ), clip ); + RectToRegion(clip, &rect); + GetPortClipRegion(GetWindowPort(window), oldClip); + SetPortClipRegion(GetWindowPort(window), clip); - SInt16 value = GetControlValue( vertScroll ); - if( themeSavvy ) + SInt16 value = GetControlValue(vertScroll); + if(themeSavvy) { // create light bg for all columns - RGBBackColor( &g.bgColour ); - EraseRect( &rect ); + RGBBackColor(&g.bgColour); + EraseRect(&rect); // add dark bg for sorted column Rect controlBounds; - switch( sortOrder ) + switch(sortOrder) { case kSortName: - GetControlBounds( sortName, &controlBounds ); + GetControlBounds(sortName, &controlBounds); rect.left = controlBounds.left; rect.right = controlBounds.right; break; case kSortType: - GetControlBounds( sortType, &controlBounds ); + GetControlBounds(sortType, &controlBounds); rect.left = controlBounds.left; rect.right = controlBounds.right; break; case kSortID: - GetControlBounds( sortID, &controlBounds ); + GetControlBounds(sortID, &controlBounds); rect.left = controlBounds.left; rect.right = controlBounds.right; break; case kSortSize: - GetControlBounds( sortSize, &controlBounds ); + GetControlBounds(sortSize, &controlBounds); rect.left = controlBounds.left; rect.right = controlBounds.right; break; case kSortAttrs: - GetControlBounds( sortAttrs, &controlBounds ); + GetControlBounds(sortAttrs, &controlBounds); rect.left = controlBounds.left; rect.right = controlBounds.right; break; default: - GetControlBounds( sortAttrs, &controlBounds ); + GetControlBounds(sortAttrs, &controlBounds); rect.left = controlBounds.right; rect.right = controlBounds.right +1; } - RGBBackColor( &g.sortColour ); - EraseRect( &rect ); + RGBBackColor(&g.sortColour); + EraseRect(&rect); } else { // erase background - RGBBackColor( &g.white ); - EraseRect( &rect ); + RGBBackColor(&g.white); + EraseRect(&rect); } // draw all resources ResourceObjectPtr current = resourceMap; - for( UInt16 line = 1; line <= numResources; line++ ) + for(UInt16 line = 1; line <= numResources; line++) { // draw resource icon - DrawResourceIcon( current, line ); + DrawResourceIcon(current, line); // reset text incase it was condensed or emboldened - RGBForeColor( &g.black ); - TextFace( normal ); + RGBForeColor(&g.black); + TextFace(normal); // resource type Str255 typeStr = "\p"; - TypeToPString( current->Type(), typeStr ); - MoveTo( nameColumnWidth + kFileWindowTypeColumnOffset + kFileWindowTypeColumnWidth - StringWidth(typeStr) -5, kFileWindowHeaderHeight + (kFileWindowRowHeight * line) - (kFileWindowRowHeight - kFileWindowTextHeight)/2 - 3 - value ); - DrawString( typeStr ); + TypeToPString(current->Type(), typeStr); + MoveTo(nameColumnWidth + kFileWindowTypeColumnOffset + kFileWindowTypeColumnWidth - StringWidth(typeStr) -5, kFileWindowHeaderHeight + (kFileWindowRowHeight * line) - (kFileWindowRowHeight - kFileWindowTextHeight)/2 - 3 - value); + DrawString(typeStr); // resource ID Str255 idStr; - NumToString( current->ID(), idStr ); - MoveTo( nameColumnWidth + kFileWindowIDColumnOffset + kFileWindowIDColumnWidth - StringWidth(idStr) -5, kFileWindowHeaderHeight + (kFileWindowRowHeight * line) - (kFileWindowRowHeight - kFileWindowTextHeight)/2 - 3 - value ); - DrawString( idStr ); + NumToString(current->ID(), idStr); + MoveTo(nameColumnWidth + kFileWindowIDColumnOffset + kFileWindowIDColumnWidth - StringWidth(idStr) -5, kFileWindowHeaderHeight + (kFileWindowRowHeight * line) - (kFileWindowRowHeight - kFileWindowTextHeight)/2 - 3 - value); + DrawString(idStr); // resource size Str255 sizeStr; - NumToString( current->Size(), sizeStr ); - MoveTo( nameColumnWidth + kFileWindowSizeColumnOffset + kFileWindowSizeColumnWidth - StringWidth(sizeStr) -5, kFileWindowHeaderHeight + (kFileWindowRowHeight * line) - (kFileWindowRowHeight - kFileWindowTextHeight)/2 - 3 - value ); - DrawString( sizeStr ); + NumToString(current->Size(), sizeStr); + MoveTo(nameColumnWidth + kFileWindowSizeColumnOffset + kFileWindowSizeColumnWidth - StringWidth(sizeStr) -5, kFileWindowHeaderHeight + (kFileWindowRowHeight * line) - (kFileWindowRowHeight - kFileWindowTextHeight)/2 - 3 - value); + DrawString(sizeStr); // resource attribute icons /* Rect iconRect; - SetRect( &iconRect, 0, 0, 16, 16 ); - OffsetRect( &iconRect, kFileWindowSizeColumnWidth + kAttrColumnOffset, (kFileLineHeight * line) +1 ); - if( current->Attributes() & resPreload) PlotIconID( &iconRect, kAlignNone, kTransformNone, kPreloadIcon ); - else PlotIconID( &iconRect, kAlignNone, kTransformDisabled, kPreloadIcon ); - OffsetRect( &iconRect, kAttrIconSep, 0 ); - if( current->Attributes() & resProtected) PlotIconID( &iconRect, kAlignNone, kTransformNone, kProtectedIcon ); - else PlotIconID( &iconRect, kAlignNone, kTransformDisabled, kProtectedIcon ); - OffsetRect( &iconRect, kAttrIconSep, 0 ); - if( current->Attributes() & resLocked) PlotIconID( &iconRect, kAlignNone, kTransformNone, kLockedIcon ); - else PlotIconID( &iconRect, kAlignNone, kTransformDisabled, kLockedIcon ); - OffsetRect( &iconRect, kAttrIconSep, 0 ); - if( current->Attributes() & resPurgeable) PlotIconID( &iconRect, kAlignNone, kTransformNone, kPurgableIcon ); - else PlotIconID( &iconRect, kAlignNone, kTransformDisabled, kPurgableIcon ); - OffsetRect( &iconRect, kAttrIconSep, 0 ); - if( current->Attributes() & resSysHeap) PlotIconID( &iconRect, kAlignNone, kTransformNone, kSysHeapIcon ); - else PlotIconID( &iconRect, kAlignNone, kTransformDisabled, kSysHeapIcon ); - OffsetRect( &iconRect, kAttrIconSep, 0 ); - if( current->Attributes() & null) PlotIconID( &iconRect, kAlignNone, kTransformNone, kCompressedIcon ); - else PlotIconID( &iconRect, kAlignNone, kTransformDisabled, kCompressedIcon ); + SetRect(&iconRect, 0, 0, 16, 16); + OffsetRect(&iconRect, kFileWindowSizeColumnWidth + kAttrColumnOffset, (kFileLineHeight * line) +1); + if(current->Attributes() & resPreload) PlotIconID(&iconRect, kAlignNone, kTransformNone, kPreloadIcon); + else PlotIconID(&iconRect, kAlignNone, kTransformDisabled, kPreloadIcon); + OffsetRect(&iconRect, kAttrIconSep, 0); + if(current->Attributes() & resProtected) PlotIconID(&iconRect, kAlignNone, kTransformNone, kProtectedIcon); + else PlotIconID(&iconRect, kAlignNone, kTransformDisabled, kProtectedIcon); + OffsetRect(&iconRect, kAttrIconSep, 0); + if(current->Attributes() & resLocked) PlotIconID(&iconRect, kAlignNone, kTransformNone, kLockedIcon); + else PlotIconID(&iconRect, kAlignNone, kTransformDisabled, kLockedIcon); + OffsetRect(&iconRect, kAttrIconSep, 0); + if(current->Attributes() & resPurgeable) PlotIconID(&iconRect, kAlignNone, kTransformNone, kPurgableIcon); + else PlotIconID(&iconRect, kAlignNone, kTransformDisabled, kPurgableIcon); + OffsetRect(&iconRect, kAttrIconSep, 0); + if(current->Attributes() & resSysHeap) PlotIconID(&iconRect, kAlignNone, kTransformNone, kSysHeapIcon); + else PlotIconID(&iconRect, kAlignNone, kTransformDisabled, kSysHeapIcon); + OffsetRect(&iconRect, kAttrIconSep, 0); + if(current->Attributes() & null) PlotIconID(&iconRect, kAlignNone, kTransformNone, kCompressedIcon); + else PlotIconID(&iconRect, kAlignNone, kTransformDisabled, kCompressedIcon); */ /* resSysHeap = 64, // System or application heap? resPurgeable = 32, // Purgeable resource? @@ -791,97 +791,97 @@ OSStatus FileWindow::Update( RgnHandle update ) resPreload = 4, // Load in on OpenResFile? resChanged = 2, // Resource changed? - not used by ResKnife */ - if( themeSavvy ) + if(themeSavvy) { // draw divider line - MoveTo( 0, kFileWindowHeaderHeight + (kFileWindowRowHeight * line) - value ); - RGBForeColor( &g.white ); - Line( windowBounds.right - windowBounds.left -1, 0 ); + MoveTo(0, kFileWindowHeaderHeight + (kFileWindowRowHeight * line) - value); + RGBForeColor(&g.white); + Line(windowBounds.right - windowBounds.left -1, 0); } // move on current = current->Next(); } - SetPortClipRegion( GetWindowPort( window ), oldClip ); - DisposeRgn( clip ); - DisposeRgn( oldClip ); + SetPortClipRegion(GetWindowPort(window), oldClip); + DisposeRgn(clip); + DisposeRgn(oldClip); } // update the controls - if( !themeSavvy ) DrawGrowIcon( window ); - UpdateControls( window, update ); - SetPort( oldPort ); + if(!themeSavvy) DrawGrowIcon(window); + UpdateControls(window, update); + SetPort(oldPort); return noErr; } /*** ACTIVATE WINDOW ***/ -OSStatus FileWindow::Activate( Boolean active ) +OSStatus FileWindow::Activate(Boolean active) { // invalidate the whole window GrafPtr oldPort; - GetPort( &oldPort ); - SetPortWindowPort( window ); + GetPort(&oldPort); + SetPortWindowPort(window); Rect windowBounds; - if( g.windowMgrAvailable ) GetWindowBounds( window, kWindowContentRgn, &windowBounds ); - else GetPortBounds( (CGrafPort *) window, &windowBounds ); - if( g.windowMgrAvailable ) InvalidateWindowRect( window, &windowBounds ); - else InvalidateRect( &windowBounds ); - SetPort( oldPort ); + if(g.windowMgrAvailable) GetWindowBounds(window, kWindowContentRgn, &windowBounds); + else GetPortBounds((CGrafPort *) window, &windowBounds); + if(g.windowMgrAvailable) InvalidateWindowRect(window, &windowBounds); + else InvalidateRect(&windowBounds); + SetPort(oldPort); // set the controls to display correctly ControlPartCode hiliteState = active? kControlNoPart:kControlInactivePart; - if( themeSavvy ) + if(themeSavvy) { - HiliteControl( header, hiliteState ); - HiliteControl( sortName, hiliteState ); - HiliteControl( sortType, hiliteState ); - HiliteControl( sortID, hiliteState ); - HiliteControl( sortSize, hiliteState ); - HiliteControl( sortAttrs, hiliteState ); - HiliteControl( sortDir, hiliteState ); + HiliteControl(header, hiliteState); + HiliteControl(sortName, hiliteState); + HiliteControl(sortType, hiliteState); + HiliteControl(sortID, hiliteState); + HiliteControl(sortSize, hiliteState); + HiliteControl(sortAttrs, hiliteState); + HiliteControl(sortDir, hiliteState); } - HiliteControl( horizScroll, hiliteState ); - HiliteControl( vertScroll, hiliteState ); + HiliteControl(horizScroll, hiliteState); + HiliteControl(vertScroll, hiliteState); return noErr; } /*** MOUSE CLICK ***/ -OSStatus FileWindow::Click( Point globalMouse, EventModifiers modifiers ) +OSStatus FileWindow::Click(Point globalMouse, EventModifiers modifiers) { // set the mouse location to local co-ords GrafPtr oldPort; - GetPort( &oldPort ); - SetPortWindowPort( window ); + GetPort(&oldPort); + SetPortWindowPort(window); Point localMouse = globalMouse, windowLoc = {0,0}; - GlobalToLocal( &localMouse ); - LocalToGlobal( &windowLoc ); - SetPort( oldPort ); + GlobalToLocal(&localMouse); + LocalToGlobal(&windowLoc); + SetPort(oldPort); // handle a click on a control first ControlHandle control; SInt16 controlPart; - if( themeSavvy ) control = FindControlUnderMouse( localMouse, window, &controlPart ); - else controlPart = FindControl( localMouse, window, &control ); - if( control && controlPart != kControlNoPart ) + if(themeSavvy) control = FindControlUnderMouse(localMouse, window, &controlPart); + else controlPart = FindControl(localMouse, window, &control); + if(control && controlPart != kControlNoPart) { // scroll the windoow - if( themeSavvy ) + if(themeSavvy) { - ControlActionUPP scrollAction = NewControlActionUPP( FileWindowScrollAction ); - controlPart = HandleControlClick( control, localMouse, modifiers, scrollAction ); - DisposeControlActionUPP( scrollAction ); + ControlActionUPP scrollAction = NewControlActionUPP(FileWindowScrollAction); + controlPart = HandleControlClick(control, localMouse, modifiers, scrollAction); + DisposeControlActionUPP(scrollAction); } - else if( controlPart != kControlIndicatorPart ) + else if(controlPart != kControlIndicatorPart) { - ControlActionUPP scrollAction = NewControlActionUPP( FileWindowScrollAction ); - TrackControl( control, localMouse, scrollAction ); - DisposeControlActionUPP( scrollAction ); + ControlActionUPP scrollAction = NewControlActionUPP(FileWindowScrollAction); + TrackControl(control, localMouse, scrollAction); + DisposeControlActionUPP(scrollAction); } else // clicks in the thumb cause crashes if given a ControlActionUPP { - controlPart = TrackControl( control, localMouse, nil ); + controlPart = TrackControl(control, localMouse, nil); Update(); } @@ -900,13 +900,13 @@ OSStatus FileWindow::Click( Point globalMouse, EventModifiers modifiers ) optionKeyDown = false; KeyMap theKeys; - GetKeys( theKeys ); - if( theKeys[1] & (shiftKey >> shiftKeyBit) ) shiftKeyDown = true; - if( theKeys[1] & (optionKey >> shiftKeyBit) ) optionKeyDown = true; + GetKeys(theKeys); + if(theKeys[1] & (shiftKey >> shiftKeyBit)) shiftKeyDown = true; + if(theKeys[1] & (optionKey >> shiftKeyBit)) optionKeyDown = true; // clicked on a part of the window where no resource is listed - SInt16 newSelection = ( localMouse.v + GetControlValue(vertScroll) - kFileWindowHeaderHeight ) / kFileWindowRowHeight +1; - if( newSelection > numResources ) + SInt16 newSelection = (localMouse.v + GetControlValue(vertScroll) - kFileWindowHeaderHeight) / kFileWindowRowHeight +1; + if(newSelection > numResources) { ClearSelection(); // should go to drag selection instead Update(); @@ -914,64 +914,64 @@ OSStatus FileWindow::Click( Point globalMouse, EventModifiers modifiers ) } // cycle to clicked resource - for( newSelection; newSelection > 1; newSelection-- ) + for(newSelection; newSelection > 1; newSelection--) resource = resource->Next(); // check for click on attributes -/* if( mouse.h >= g.nameColumnWidth + kAttrColumnOffset ) // clicked on attribute +/* if(mouse.h >= g.nameColumnWidth + kAttrColumnOffset) // clicked on attribute { short attrClicked = mouse.h; attrClicked -= g.nameColumnWidth + kAttrColumnOffset; attrClicked /= kAttrIconSep; attrClicked += resPreloadBit; - if( (r.attrs >> attrClicked) & 0x01 ) r.attrs -= 1 << attrClicked; + if((r.attrs >> attrClicked) & 0x01) r.attrs -= 1 << attrClicked; else r.attrs += 1 << attrClicked; // mark file & resource for saving dirty = true; r.dirty = true; - ChangedResource( r.resource ); + ChangedResource(r.resource); // update the window Update(); } // if in nameIconRgn, must be a click on a resource - else*/ if( PtInRgn( localMouse, resource->nameIconRgn ) ) + else*/ if(PtInRgn(localMouse, resource->nameIconRgn)) { - if( resource->Selected() == false ) + if(resource->Selected() == false) { - if( shiftKeyDown ) // shift click on unselected + if(shiftKeyDown) // shift click on unselected { - resource->Select( true ); + resource->Select(true); numSelected += 1; } else // click on unselected { clickTime = TickCount(); ClearSelection(); - resource->Select( true ); + resource->Select(true); numSelected = 1; } } else { - if( TickCount() <= clickTime + GetDblTime() ) // double click + if(TickCount() <= clickTime + GetDblTime()) // double click { ClearSelection(); - resource->Select( true ); + resource->Select(true); numSelected = 1; - OpenResource( resource->Number(), optionKeyDown? kMenuCommandOpenHex:kMenuCommandOpenDefault ); + OpenResource(resource->Number(), optionKeyDown? kMenuCommandOpenHex:kMenuCommandOpenDefault); } - else if( shiftKeyDown ) // shift click on selected + else if(shiftKeyDown) // shift click on selected { - resource->Select( false ); + resource->Select(false); numSelected -= 1; } else // click on selected { clickTime = TickCount(); - resource->Select( true ); + resource->Select(true); } } @@ -979,13 +979,13 @@ OSStatus FileWindow::Click( Point globalMouse, EventModifiers modifiers ) Update(); // check for resource drags - if( WaitMouseMoved( globalMouse ) ) // drag activated + if(WaitMouseMoved(globalMouse)) // drag activated { OSErr error = noErr; DragReference theDragRef; ItemReference theItemRef = 1; FlavorFlags theFlags = flavorNotSaved; - DragSendDataUPP sendProc = null; // bug: NewDragSendDataProc( SendFileDataProc ); + DragSendDataUPP sendProc = null; // bug: NewDragSendDataProc(SendFileDataProc); // setup imaginary file PromiseHFSFlavor theFile; @@ -995,10 +995,10 @@ OSStatus FileWindow::Click( Point globalMouse, EventModifiers modifiers ) theFile.promisedFlavor = kResourceTransferType; // create the drag reference - NewDrag( &theDragRef ); + NewDrag(&theDragRef); error = MemError(); - if( error ) return error; - SetDragSendProc( theDragRef, sendProc, this ); + if(error) return error; + SetDragSendProc(theDragRef, sendProc, this); RgnHandle dragRgn = NewRgn(), subtractRgn = NewRgn(); @@ -1007,60 +1007,60 @@ OSStatus FileWindow::Click( Point globalMouse, EventModifiers modifiers ) GWorldPtr imageGWorld = null; resource = resourceMap; - while( resource ) + while(resource) { - if( resource->Selected() ) - UnionRgn( resource->nameIconRgn, dragRgn, dragRgn ); // add new region to rest of drag region + if(resource->Selected()) + UnionRgn(resource->nameIconRgn, dragRgn, dragRgn); // add new region to rest of drag region resource = resource->Next(); } -/* if( g.translucentDrag ) +/* if(g.translucentDrag) { Point dragOffset; DataBrowserItemID resCounter = 0; - SetPt( &dragOffset, 0, kFileWindowHeaderHeight ); + SetPt(&dragOffset, 0, kFileWindowHeaderHeight); resource = resourceMap; - while( !resource->Selected() ) + while(!resource->Selected()) { resCounter++; resource = resource->Next(); } - error = CreateDragImage( resource, &imageGWorld ); - if( !error ) + error = CreateDragImage(resource, &imageGWorld); + if(!error) { // init mask region RgnHandle maskRgn = NewRgn(); - CopyRgn( resource->nameIconRgn, maskRgn ); - OffsetRgn( maskRgn, 0, -kFileWindowRowHeight * resCounter ); + CopyRgn(resource->nameIconRgn, maskRgn); + OffsetRgn(maskRgn, 0, -kFileWindowRowHeight * resCounter); // init rects Rect sourceRect, destRect; - SetRect( &sourceRect, 0, 0, nameColumnWidth, kFileWindowRowHeight ); - SetRect( &destRect, 0, 0, nameColumnWidth, kFileWindowRowHeight ); - OffsetRect( &destRect, 0, kFileWindowHeaderHeight ); + SetRect(&sourceRect, 0, 0, nameColumnWidth, kFileWindowRowHeight); + SetRect(&destRect, 0, 0, nameColumnWidth, kFileWindowRowHeight); + OffsetRect(&destRect, 0, kFileWindowHeaderHeight); // init GWorld - PixMapHandle imagePixMap = GetGWorldPixMap( imageGWorld ); + PixMapHandle imagePixMap = GetGWorldPixMap(imageGWorld); DragImageFlags imageFlags = kDragStandardTranslucency | kDragRegionAndImage; - error = SetDragImage( theDragRef, imagePixMap, maskRgn, dragOffset, imageFlags ); - CopyBits( &GrafPtr( imageGWorld )->portBits, &GrafPtr( window )->portBits, &sourceRect, &destRect, srcCopy, maskRgn ); - if( error ) SysBeep(0); - DisposeGWorld( imageGWorld ); - DisposeRgn( maskRgn ); + error = SetDragImage(theDragRef, imagePixMap, maskRgn, dragOffset, imageFlags); + CopyBits(&GrafPtr(imageGWorld)->portBits, &GrafPtr(window)->portBits, &sourceRect, &destRect, srcCopy, maskRgn); + if(error) SysBeep(0); + DisposeGWorld(imageGWorld); + DisposeRgn(maskRgn); } } */ // subtract middles from icons - CopyRgn( dragRgn, subtractRgn ); // duplicate region - InsetRgn( subtractRgn, 2, 2 ); // inset it by 2 pixels - DiffRgn( dragRgn, subtractRgn, dragRgn ); // subtract subRgn from addRgn, save in nameIconRgn - OffsetRgn( dragRgn, windowLoc.h, windowLoc.v ); // change drag region to global coords + CopyRgn(dragRgn, subtractRgn); // duplicate region + InsetRgn(subtractRgn, 2, 2); // inset it by 2 pixels + DiffRgn(dragRgn, subtractRgn, dragRgn); // subtract subRgn from addRgn, save in nameIconRgn + OffsetRgn(dragRgn, windowLoc.h, windowLoc.v); // change drag region to global coords // add flavour data to drag - error = AddDragItemFlavor( theDragRef, theItemRef, flavorTypePromiseHFS, &theFile, sizeof(PromiseHFSFlavor), theFlags ); - error = AddDragItemFlavor( theDragRef, theItemRef, kResourceTransferType, null, 0, theFlags ); + error = AddDragItemFlavor(theDragRef, theItemRef, flavorTypePromiseHFS, &theFile, sizeof(PromiseHFSFlavor), theFlags); + error = AddDragItemFlavor(theDragRef, theItemRef, kResourceTransferType, null, 0, theFlags); // track the drag, then clean up EventRecord event; @@ -1070,10 +1070,10 @@ OSStatus FileWindow::Click( Point globalMouse, EventModifiers modifiers ) event.where = globalMouse; event.modifiers = modifiers; - error = TrackDrag( theDragRef, &event, dragRgn ); - if( theDragRef ) DisposeDrag( theDragRef ); - if( subtractRgn ) DisposeRgn( subtractRgn ); - if( dragRgn ) DisposeRgn( dragRgn ); + error = TrackDrag(theDragRef, &event, dragRgn); + if(theDragRef) DisposeDrag(theDragRef); + if(subtractRgn) DisposeRgn(subtractRgn); + if(dragRgn) DisposeRgn(dragRgn); } } @@ -1081,72 +1081,72 @@ OSStatus FileWindow::Click( Point globalMouse, EventModifiers modifiers ) else { // clear current selections - if( shiftKeyDown == false ) + if(shiftKeyDown == false) { ClearSelection(); Update(); } // check for resource drags - if( WaitMouseMoved( globalMouse ) ) + if(WaitMouseMoved(globalMouse)) { // set pen PenState oldState, dragState; - GetPenState( &oldState ); - PenSize( 2, 2 ); - PenPat( &qd.gray ); - PenMode( srcXor ); - GetPenState( &dragState ); - SetPenState( &oldState ); + GetPenState(&oldState); + PenSize(2, 2); + PenPat(&qd.gray); + PenMode(srcXor); + GetPenState(&dragState); + SetPenState(&oldState); // do drag selection // RgnHandle oldClip = NewRgn(); -// GetClip( oldClip ); -// SetClip( bodyRgn ); +// GetClip(oldClip); +// SetClip(bodyRgn); Point mouse, savedMouse = globalMouse, oldMouse = globalMouse; Rect dragRect = {0,0,0,0}; - while( WaitMouseUp() ) + while(WaitMouseUp()) { - GetMouse( &mouse ); - SetPortWindowPort( window ); - if( mouse.h != oldMouse.h || mouse.v != oldMouse.v ) + GetMouse(&mouse); + SetPortWindowPort(window); + if(mouse.h != oldMouse.h || mouse.v != oldMouse.v) { - SetPenState( &dragState ); - FrameRect( &dragRect ); - SetRect( &dragRect, (savedMouse.h < mouse.h)? savedMouse.h : mouse.h, + SetPenState(&dragState); + FrameRect(&dragRect); + SetRect(&dragRect, (savedMouse.h < mouse.h)? savedMouse.h : mouse.h, (savedMouse.v < mouse.v)? savedMouse.v : mouse.v, (savedMouse.h > mouse.h)? savedMouse.h : mouse.h, - (savedMouse.v > mouse.v)? savedMouse.v : mouse.v ); - OffsetRect( &dragRect, -windowLoc.h, -windowLoc.v ); - FrameRect( &dragRect ); - SetPenState( &oldState ); + (savedMouse.v > mouse.v)? savedMouse.v : mouse.v); + OffsetRect(&dragRect, -windowLoc.h, -windowLoc.v); + FrameRect(&dragRect); + SetPenState(&oldState); // check to see if selection region coincides with resources short i; RgnHandle dragRgn = NewRgn(), resultRgn = NewRgn(); - RectRgn( dragRgn, &dragRect ); + RectRgn(dragRgn, &dragRect); ResourceObjectPtr resource = resourceMap; - for( i = 1; i <= GetControlValue(vertScroll); i++ ) + for(i = 1; i <= GetControlValue(vertScroll); i++) resource = resource->Next(); // move to first res in window - for( i = GetControlValue(vertScroll); i < numResources - GetControlValue(vertScroll); i++ ) + for(i = GetControlValue(vertScroll); i < numResources - GetControlValue(vertScroll); i++) { - SetEmptyRgn( resultRgn ); - SectRgn( dragRgn, resource->nameIconRgn, resultRgn ); - resource->Select( !EmptyRgn( resultRgn ) ); - DrawResourceIcon( resource, i+1 ); + SetEmptyRgn(resultRgn); + SectRgn(dragRgn, resource->nameIconRgn, resultRgn); + resource->Select(!EmptyRgn(resultRgn)); + DrawResourceIcon(resource, i+1); resource = resource->Next(); } - DisposeRgn( resultRgn ); - DisposeRgn( dragRgn ); + DisposeRgn(resultRgn); + DisposeRgn(dragRgn); } - SetPort( oldPort ); + SetPort(oldPort); oldMouse = mouse; } // restore clip region -// SetClip( oldClip ); +// SetClip(oldClip); } // update the window @@ -1157,20 +1157,20 @@ OSStatus FileWindow::Click( Point globalMouse, EventModifiers modifiers ) } /*** FILE WINDOW SCROLL ACTION ***/ -pascal void FileWindowScrollAction( ControlHandle control, SInt16 controlPart ) +pascal void FileWindowScrollAction(ControlHandle control, SInt16 controlPart) { // get owning window - if( !controlPart ) return; - SInt8 state = HGetState( (Handle) control ); - HLock( (Handle) control ); - WindowRef window = GetControlOwner( control ); - HSetState( (Handle) control, state ); - WindowObjectPtr winObj = (WindowObjectPtr) GetWindowRefCon( window ); + if(!controlPart) return; + SInt8 state = HGetState((Handle) control); + HLock((Handle) control); + WindowRef window = GetControlOwner(control); + HSetState((Handle) control, state); + WindowObjectPtr winObj = (WindowObjectPtr) GetWindowRefCon(window); // get window bounds Rect windowBounds; - if( g.windowMgrAvailable ) GetWindowBounds( window, kWindowContentRgn, &windowBounds ); - else GetPortBounds( (CGrafPort *) window, &windowBounds ); + if(g.windowMgrAvailable) GetWindowBounds(window, kWindowContentRgn, &windowBounds); + else GetPortBounds((CGrafPort *) window, &windowBounds); windowBounds.top += kFileWindowHeaderHeight +1; windowBounds.bottom -= (kScrollBarWidth -1); windowBounds.right -= (kScrollBarWidth -1); @@ -1178,7 +1178,7 @@ pascal void FileWindowScrollAction( ControlHandle control, SInt16 controlPart ) // decide how many pixels to scroll (and in which direction) SInt16 delta = 0; - switch( controlPart ) + switch(controlPart) { case kControlUpButtonPart: // up (20) delta = -kFileWindowRowHeight; @@ -1198,16 +1198,16 @@ pascal void FileWindowScrollAction( ControlHandle control, SInt16 controlPart ) } // calculate and correct control value - SInt16 max = GetControlMaximum( control ); - SInt16 startValue = GetControlValue( control ); + SInt16 max = GetControlMaximum(control); + SInt16 startValue = GetControlValue(control); SInt16 endValue = startValue + delta; - if( endValue < 0 ) endValue = 0; - if( endValue > max ) endValue = max; + if(endValue < 0) endValue = 0; + if(endValue > max) endValue = max; // only update window if anything changed - if( endValue != startValue || controlPart == kControlIndicatorPart ) + if(endValue != startValue || controlPart == kControlIndicatorPart) { - SetControlValue( control, endValue ); + SetControlValue(control, endValue); winObj->Update(); } } @@ -1215,45 +1215,45 @@ pascal void FileWindowScrollAction( ControlHandle control, SInt16 controlPart ) #endif /*** NEW RESOURCE SHEET WINDOW EVENT HANDLER ***/ -pascal OSStatus NewResourceEventHandler( EventHandlerCallRef callRef, EventRef event, void *userData ) +pascal OSStatus NewResourceEventHandler(EventHandlerCallRef callRef, EventRef event, void *userData) { - #pragma unused( callRef, userData ) + #pragma unused(callRef, userData) // get control that was hit UInt32 command; ControlRef control; - GetEventParameter( event, kEventParamDirectObject, typeControlRef, null, sizeof(ControlRef), null, &control ); - GetControlCommandID( control, &command ); + GetEventParameter(event, kEventParamDirectObject, typeControlRef, null, sizeof(ControlRef), null, &control); + GetControlCommandID(control, &command); // get parent window (so resource is added to correct file) WindowRef parent; - WindowRef sheet = GetControlOwner( control ); - GetSheetWindowParent( sheet, &parent ); - FileWindowPtr file = (FileWindowPtr) GetWindowRefCon( parent ); + WindowRef sheet = GetControlOwner(control); + GetSheetWindowParent(sheet, &parent); + FileWindowPtr file = (FileWindowPtr) GetWindowRefCon(parent); // do the button action - switch( command ) + switch(command) { case kHICommandOK: { // close the sheet - HideSheetWindow( sheet ); - DisposeWindow( sheet ); + HideSheetWindow(sheet); + DisposeWindow(sheet); // extract all the info about the resource we need Str255 name = "\pTest Resource Beta"; ResType type = 'test'; SInt16 resID = 129; SInt16 attribs = 0; - file->CreateNewResource( name, type, resID, attribs ); + file->CreateNewResource(name, type, resID, attribs); } break; case kHICommandCancel: // close the sheet - HideSheetWindow( sheet ); - DisposeWindow( sheet ); + HideSheetWindow(sheet); + DisposeWindow(sheet); break; default: - DebugError( "\pCommand assigned to that control was not dealt with." ); + DebugError("\pCommand assigned to that control was not dealt with."); } return noErr; } @@ -1265,150 +1265,150 @@ pascal OSStatus NewResourceEventHandler( EventHandlerCallRef callRef, EventRef e #if !TARGET_API_MAC_CARBON /*** UPDATE SCROLL BARS ***/ -OSStatus FileWindow::UpdateScrollBars( void ) +OSStatus FileWindow::UpdateScrollBars(void) { // get rect into which I can draw Rect windowBounds; - if( g.windowMgrAvailable ) GetWindowBounds( window, kWindowContentRgn, &windowBounds ); - else GetPortBounds( (CGrafPort *) window, &windowBounds ); + if(g.windowMgrAvailable) GetWindowBounds(window, kWindowContentRgn, &windowBounds); + else GetPortBounds((CGrafPort *) window, &windowBounds); windowBounds.top += kFileWindowHeaderHeight +1; windowBounds.bottom -= (kScrollBarWidth -1); windowBounds.right -= (kScrollBarWidth -1); UInt16 windowHeight = windowBounds.bottom - windowBounds.top; // horizontal scroll bar - if( nameColumnWidth + kFileWindowAllOtherColumnWidths - windowBounds.right <= 0 ) - SetControlMaximum( horizScroll, 0 ); - else SetControlMaximum( horizScroll, nameColumnWidth + kFileWindowAllOtherColumnWidths - windowBounds.right ); + if(nameColumnWidth + kFileWindowAllOtherColumnWidths - windowBounds.right <= 0) + SetControlMaximum(horizScroll, 0); + else SetControlMaximum(horizScroll, nameColumnWidth + kFileWindowAllOtherColumnWidths - windowBounds.right); // vertical scroll bar - SInt16 value = GetControlValue( vertScroll ); - if( windowHeight > numResources * kFileWindowRowHeight - value ) - SetControlMaximum( vertScroll, value ); - else SetControlMaximum( vertScroll, numResources * kFileWindowRowHeight - windowHeight ); + SInt16 value = GetControlValue(vertScroll); + if(windowHeight > numResources * kFileWindowRowHeight - value) + SetControlMaximum(vertScroll, value); + else SetControlMaximum(vertScroll, numResources * kFileWindowRowHeight - windowHeight); return noErr; } /*** DRAW RESOURCE ICON ***/ -OSStatus FileWindow::DrawResourceIcon( ResourceObjectPtr resource, UInt16 line ) +OSStatus FileWindow::DrawResourceIcon(ResourceObjectPtr resource, UInt16 line) { OSStatus error = noErr; Rect nameRect, iconRect; Str255 nameStr; IconAlignmentType alignment; IconTransformType transformation; - SInt16 value = GetControlValue( vertScroll ); + SInt16 value = GetControlValue(vertScroll); // resource icon alignment = kAlignNone; - if( resource->Selected() ) transformation = kTransformSelected; + if(resource->Selected()) transformation = kTransformSelected; else transformation = kTransformNone; - SetRect( &iconRect, 0, 0, 16, 16 ); - OffsetRect( &iconRect, kFileWindowNameColumnTextOffset -20, kFileWindowHeaderHeight + (kFileWindowRowHeight * line) - (kFileWindowRowHeight/2) - 8 - value ); + SetRect(&iconRect, 0, 0, 16, 16); + OffsetRect(&iconRect, kFileWindowNameColumnTextOffset -20, kFileWindowHeaderHeight + (kFileWindowRowHeight * line) - (kFileWindowRowHeight/2) - 8 - value); IconSuiteRef iconSuite; - GetIconSuite( &iconSuite, kDefaultResourceIcon, kSelectorAllSmallData ); - error = PlotIconSuite( &iconRect, alignment, transformation, iconSuite ); - if( error ) return error; + GetIconSuite(&iconSuite, kDefaultResourceIcon, kSelectorAllSmallData); + error = PlotIconSuite(&iconRect, alignment, transformation, iconSuite); + if(error) return error; /* IconSelectorValue whichIcons = kSelectorSmall32Bit | kSelectorSmall8BitMask; IconFamilyHandle iconFamily; IconSuiteRef iconSuite; - iconFamily = (IconFamilyHandle) Get1Resource( kIconFamilyType, kDefaultResourceIcon ); - IconFamilyToIconSuite( iconFamily, whichIcons, &iconSuite ); - PlotIconSuite( &iconRect, alignment, transformation, iconSuite ); - DisposeIconSuite( iconSuite, false ); - ReleaseResource( (Handle) iconFamily ); + iconFamily = (IconFamilyHandle) Get1Resource(kIconFamilyType, kDefaultResourceIcon); + IconFamilyToIconSuite(iconFamily, whichIcons, &iconSuite); + PlotIconSuite(&iconRect, alignment, transformation, iconSuite); + DisposeIconSuite(iconSuite, false); + ReleaseResource((Handle) iconFamily); */ // get name - if( *resource->Name() != 0x00 ) + if(*resource->Name() != 0x00) { - CopyPString( resource->name, nameStr ); + CopyPString(resource->name, nameStr); } else { Str255 unnamedStr; - if( resource->dataFork ) GetIndString( unnamedStr, kResourceNameStrings, kStringDataFork ); - else if( resource->ID() == -16455 && (resource->Type() == 'icns' || resource->Type() == 'icl8' || resource->Type() == 'icl4' || resource->Type() == 'ICN#' || resource->Type() == 'ics8' || resource->Type() == 'ics4' || resource->Type() == 'ics#') ) - GetIndString( unnamedStr, kResourceNameStrings, kStringCustomIcon ); - else GetIndString( unnamedStr, kResourceNameStrings, kStringUntitledResource ); - CopyPString( unnamedStr, nameStr ); + if(resource->dataFork) GetIndString(unnamedStr, kResourceNameStrings, kStringDataFork); + else if(resource->ID() == -16455 && (resource->Type() == 'icns' || resource->Type() == 'icl8' || resource->Type() == 'icl4' || resource->Type() == 'ICN#' || resource->Type() == 'ics8' || resource->Type() == 'ics4' || resource->Type() == 'ics#')) + GetIndString(unnamedStr, kResourceNameStrings, kStringCustomIcon); + else GetIndString(unnamedStr, kResourceNameStrings, kStringUntitledResource); + CopyPString(unnamedStr, nameStr); } // condense & italicise if necessary - if( StringWidth( nameStr ) > nameColumnWidth - 45 ) + if(StringWidth(nameStr) > nameColumnWidth - 45) { - if( resource->Dirty() ) TextFace( condense | bold ); - else TextFace( condense ); + if(resource->Dirty()) TextFace(condense | bold); + else TextFace(condense); } else { - if( resource->Dirty() ) TextFace( bold ); - else TextFace( normal ); + if(resource->Dirty()) TextFace(bold); + else TextFace(normal); } // add ellipsis if necessary - while( StringWidth( nameStr ) > nameColumnWidth - kFileWindowNameColumnTextOffset -3 ) + while(StringWidth(nameStr) > nameColumnWidth - kFileWindowNameColumnTextOffset -3) { nameStr[0] -= 1; // shorten string nameStr[ nameStr[0] ] = 0xC9; // replace new last char with 'É' } // set text/box colour - if( *resource->Name() == 0x00 ) - RGBForeColor( &g.frameColour ); - else RGBForeColor( &g.black ); + if(*resource->Name() == 0x00) + RGBForeColor(&g.frameColour); + else RGBForeColor(&g.black); // draw hilight box if selected - if( resource->Selected() ) + if(resource->Selected()) { - SetRect( &nameRect, 0, 0, StringWidth( nameStr ) +4, kFileWindowTextHeight ); - OffsetRect( &nameRect, kFileWindowNameColumnTextOffset -2, kFileWindowHeaderHeight + (kFileWindowRowHeight * line) - (kFileWindowRowHeight - kFileWindowTextHeight)/2 - kFileWindowTextHeight - value ); - PaintRect( &nameRect ); - RGBForeColor( &g.white ); // set text colour to white + SetRect(&nameRect, 0, 0, StringWidth(nameStr) +4, kFileWindowTextHeight); + OffsetRect(&nameRect, kFileWindowNameColumnTextOffset -2, kFileWindowHeaderHeight + (kFileWindowRowHeight * line) - (kFileWindowRowHeight - kFileWindowTextHeight)/2 - kFileWindowTextHeight - value); + PaintRect(&nameRect); + RGBForeColor(&g.white); // set text colour to white } // draw name in set colour SInt16 font; - GetFNum( "\pGeneva", &font ); - TextFont( font ); - TextSize( 10 ); -// TextFont( kControlFontSmallSystemFont ); // doesn't give right effect - MoveTo( kFileWindowNameColumnTextOffset, kFileWindowHeaderHeight + (kFileWindowRowHeight * line) - (kFileWindowRowHeight - kFileWindowTextHeight)/2 - 3 - value ); - DrawString( nameStr ); - RGBForeColor( &g.black ); + GetFNum("\pGeneva", &font); + TextFont(font); + TextSize(10); +// TextFont(kControlFontSmallSystemFont); // doesn't give right effect + MoveTo(kFileWindowNameColumnTextOffset, kFileWindowHeaderHeight + (kFileWindowRowHeight * line) - (kFileWindowRowHeight - kFileWindowTextHeight)/2 - 3 - value); + DrawString(nameStr); + RGBForeColor(&g.black); // create name & icon region for click detection and dragging RgnHandle addRgn = NewRgn(); - if( !addRgn ) + if(!addRgn) { - DisposeIconSuite( iconSuite, true ); + DisposeIconSuite(iconSuite, true); return memFullErr; } - if( resource->nameIconRgn ) - DisposeRgn( resource->nameIconRgn ); + if(resource->nameIconRgn) + DisposeRgn(resource->nameIconRgn); resource->nameIconRgn = NewRgn(); - if( !resource->nameIconRgn ) + if(!resource->nameIconRgn) { - DisposeRgn( addRgn ); - DisposeIconSuite( iconSuite, true ); + DisposeRgn(addRgn); + DisposeIconSuite(iconSuite, true); return memFullErr; } // resource icon - SetRect( &iconRect, 0, 0, 16, 16 ); - OffsetRect( &iconRect, 22, kFileWindowHeaderHeight + (kFileWindowRowHeight * (line-1)) +2 ); - IconSuiteToRgn( resource->nameIconRgn, &iconRect, kAlignNone, iconSuite ); + SetRect(&iconRect, 0, 0, 16, 16); + OffsetRect(&iconRect, 22, kFileWindowHeaderHeight + (kFileWindowRowHeight * (line-1)) +2); + IconSuiteToRgn(resource->nameIconRgn, &iconRect, kAlignNone, iconSuite); // resource name - SetRect( &nameRect, 0, 0, StringWidth( nameStr ) +4, kFileWindowTextHeight ); - OffsetRect( &nameRect, 40, kFileWindowHeaderHeight + (kFileWindowRowHeight * (line-1)) +3 ); - RectRgn( addRgn, &nameRect ); // convert textRect to region - UnionRgn( addRgn, resource->nameIconRgn, resource->nameIconRgn ); // add new region to icon region - DisposeRgn( addRgn ); - DisposeIconSuite( iconSuite, true ); + SetRect(&nameRect, 0, 0, StringWidth(nameStr) +4, kFileWindowTextHeight); + OffsetRect(&nameRect, 40, kFileWindowHeaderHeight + (kFileWindowRowHeight * (line-1)) +3); + RectRgn(addRgn, &nameRect); // convert textRect to region + UnionRgn(addRgn, resource->nameIconRgn, resource->nameIconRgn); // add new region to icon region + DisposeRgn(addRgn); + DisposeIconSuite(iconSuite, true); return error; } @@ -1419,37 +1419,37 @@ OSStatus FileWindow::DrawResourceIcon( ResourceObjectPtr resource, UInt16 line ) /*****************************/ /*** DISPLAY NEW RESOURCE SHEET ***/ -OSStatus FileWindow::DisplayNewResourceSheet( void ) +OSStatus FileWindow::DisplayNewResourceSheet(void) { #if TARGET_API_MAC_CARBON // create a nib reference (only searches the application bundle) IBNibRef nibRef = null; - OSStatus error = CreateNibReference( CFSTR("ResKnife"), &nibRef ); - if( error != noErr ) + OSStatus error = CreateNibReference(CFSTR("ResKnife"), &nibRef); + if(error != noErr) { - DisplayError( "\pThe nib file reference could not be obtained." ); + DisplayError("\pThe nib file reference could not be obtained."); return error; } // create save sheet WindowRef sheet; - error = CreateWindowFromNib( nibRef, CFSTR("New Resource"), &sheet ); - if( error != noErr ) + error = CreateWindowFromNib(nibRef, CFSTR("New Resource"), &sheet); + if(error != noErr) { - DisplayError( "\pA sheet window could not be obtained from the nib file." ); + DisplayError("\pA sheet window could not be obtained from the nib file."); return error; } // dispose of nib ref - DisposeNibReference( nibRef ); + DisposeNibReference(nibRef); // install window event handler EventTypeSpec events = { kEventClassControl, kEventControlHit }; - EventHandlerUPP eventHandler = NewEventHandlerUPP( NewResourceEventHandler ); - InstallWindowEventHandler( sheet, eventHandler, 1, &events, 0, null ); + EventHandlerUPP eventHandler = NewEventHandlerUPP(NewResourceEventHandler); + InstallWindowEventHandler(sheet, eventHandler, 1, &events, 0, null); // show sheet window - ShowSheetWindow( sheet, window ); + ShowSheetWindow(sheet, window); return error; #else return eventNotHandledErr; @@ -1457,16 +1457,16 @@ OSStatus FileWindow::DisplayNewResourceSheet( void ) } /*** DISPLAY NEW RESOURCE DIALOG ***/ -OSStatus FileWindow::DisplayNewResourceDialog( void ) +OSStatus FileWindow::DisplayNewResourceDialog(void) { // create and show dialog OSStatus error = noErr; GrafPtr oldPort; - DialogRef dialog = GetNewDialog( kNewResourceDialog, null, kFirstWindowOfClass ); - SetDialogDefaultItem( dialog, ok ); - GetPort( &oldPort ); - SetPortWindowPort( GetDialogWindow(dialog) ); - ShowWindow( GetDialogWindow(dialog) ); + DialogRef dialog = GetNewDialog(kNewResourceDialog, null, kFirstWindowOfClass); + SetDialogDefaultItem(dialog, ok); + GetPort(&oldPort); + SetPortWindowPort(GetDialogWindow(dialog)); + ShowWindow(GetDialogWindow(dialog)); // set up variables Str255 name = "\pTest Resource Alpha"; @@ -1481,24 +1481,24 @@ OSStatus FileWindow::DisplayNewResourceDialog( void ) DialogItemType itemType; do { - ModalDialog( null, &itemHit ); - GetDialogItem( dialog, itemHit, &itemType, &item, &box ); - switch( itemHit ) + ModalDialog(null, &itemHit); + GetDialogItem(dialog, itemHit, &itemType, &item, &box); + switch(itemHit) { case 5: { Str255 popupText; - MenuRef popupMenu = GetMenu( 140 ); - SInt16 popupItem = GetControlValue( (ControlRef) item ); - GetMenuItemText( popupMenu, popupItem, popupText ); - GetDialogItem( dialog, 4, &itemType, &item, &box ); - SetDialogItemText( item, popupText ); - if( popupItem == 1 ) SelectDialogItemText( dialog, 4, 0x0000, 0x0000 ); - else SelectDialogItemText( dialog, 4, 0x0000, 0xFFFF ); + MenuRef popupMenu = GetMenu(140); + SInt16 popupItem = GetControlValue((ControlRef) item); + GetMenuItemText(popupMenu, popupItem, popupText); + GetDialogItem(dialog, 4, &itemType, &item, &box); + SetDialogItemText(item, popupText); + if(popupItem == 1) SelectDialogItemText(dialog, 4, 0x0000, 0x0000); + else SelectDialogItemText(dialog, 4, 0x0000, 0xFFFF); RgnHandle updateRgn = NewRgn(); - RectRgn( updateRgn, &box ); - UpdateDialog( dialog, updateRgn ); - DisposeRgn( updateRgn ); - DisposeMenu( popupMenu ); + RectRgn(updateRgn, &box); + UpdateDialog(dialog, updateRgn); + DisposeRgn(updateRgn); + DisposeMenu(popupMenu); } break; case 7: @@ -1507,74 +1507,74 @@ OSStatus FileWindow::DisplayNewResourceDialog( void ) case 10: case 11: { attributes ^= 1 << (itemHit -5); - SetControlValue( (ControlRef) item, (short) (attributes & 1 << (itemHit -5)) ); + SetControlValue((ControlRef) item, (short) (attributes & 1 << (itemHit -5))); } break; } - } while( itemHit != ok && itemHit != cancel ); + } while(itemHit != ok && itemHit != cancel); - HideWindow( GetDialogWindow(dialog) ); - if( itemHit == cancel ) + HideWindow(GetDialogWindow(dialog)); + if(itemHit == cancel) { - DisposeDialog( dialog ); - SetPort( oldPort ); + DisposeDialog(dialog); + SetPort(oldPort); return userCanceledErr; } else { // get resource name - GetDialogItem( dialog, 3, &itemType, &item, &box ); - GetDialogItemText( item, name ); + GetDialogItem(dialog, 3, &itemType, &item, &box); + GetDialogItemText(item, name); // get resource type Str255 string; - GetDialogItem( dialog, 4, &itemType, &item, &box ); - GetDialogItemText( item, string ); - if( *string != sizeof(ResType) ) + GetDialogItem(dialog, 4, &itemType, &item, &box); + GetDialogItemText(item, string); + if(*string != sizeof(ResType)) { - DisplayError( "\pInvalid resource type given", "\pYou should either choose a type from the pop-up menu, or enter a four character resource type of your own." ); - SetPort( oldPort ); - DisposeDialog( dialog ); + DisplayError("\pInvalid resource type given", "\pYou should either choose a type from the pop-up menu, or enter a four character resource type of your own."); + SetPort(oldPort); + DisposeDialog(dialog); return paramErr; } - BlockMoveData( string +1, &type, sizeof(ResType) ); + BlockMoveData(string +1, &type, sizeof(ResType)); // get resource ID long number; - GetDialogItem( dialog, 6, &itemType, &item, &box ); - GetDialogItemText( item, string ); - StringToNum( string, &number ); - if( number < -32768 || number > 32767 ) + GetDialogItem(dialog, 6, &itemType, &item, &box); + GetDialogItemText(item, string); + StringToNum(string, &number); + if(number < -32768 || number > 32767) { - DisplayError( "\pInvalid resource ID chosen", "\pYou have to pick a number between -32768 and +32767. All ID numbers less than 128 are reserved by Apple." ); - SetPort( oldPort ); - DisposeDialog( dialog ); + DisplayError("\pInvalid resource ID chosen", "\pYou have to pick a number between -32768 and +32767. All ID numbers less than 128 are reserved by Apple."); + SetPort(oldPort); + DisposeDialog(dialog); return paramErr; } resID = (short) number; // create resource - error = CreateNewResource( name, type, resID, attributes ); + error = CreateNewResource(name, type, resID, attributes); } - SetPort( oldPort ); - DisposeDialog( dialog ); + SetPort(oldPort); + DisposeDialog(dialog); return error; } /*** CREATE NEW RESOURCE ***/ -OSStatus FileWindow::CreateNewResource( ConstStr255Param name, ResType type, SInt16 resID, SInt16 attributes ) +OSStatus FileWindow::CreateNewResource(ConstStr255Param name, ResType type, SInt16 resID, SInt16 attributes) { // cycle through ResourceObject chain OSStatus error = noErr; - ResourceObjectPtr last = resourceMap, addition = (ResourceObjectPtr) NewPtrClear( sizeof(ResourceObject) ); - while( last->next ) last = last->next; + ResourceObjectPtr last = resourceMap, addition = (ResourceObjectPtr) NewPtrClear(sizeof(ResourceObject)); + while(last->next) last = last->next; // append new resource to chain last->next = addition; addition->file = this; addition->number = last->number + 1; - addition->data = NewHandleClear( 0 ); - BlockMoveData( name, addition->name, sizeof(Str255) ); + addition->data = NewHandleClear(0); + BlockMoveData(name, addition->name, sizeof(Str255)); addition->size = 0; addition->type = type; addition->resID = resID; @@ -1582,53 +1582,53 @@ OSStatus FileWindow::CreateNewResource( ConstStr255Param name, ResType type, SIn // update the file's resource counts numResources += 1; - if( GetResourceCount(type) == 0 ) + if(GetResourceCount(type) == 0) numTypes += 1; #if TARGET_API_MAC_CARBON // add the resource to the databrowser - error = AddDataBrowserItems( dataBrowser, kDataBrowserNoItem, 1, &addition->number, kDataBrowserItemNoProperty ); + error = AddDataBrowserItems(dataBrowser, kDataBrowserNoItem, 1, &addition->number, kDataBrowserItemNoProperty); #endif // mark file as dirty fileDirty = true; - SetWindowModified( window, fileDirty ); + SetWindowModified(window, fileDirty); return error; } /*** OPEN RESOURCE ***/ -OSStatus FileWindow::OpenResource( DataBrowserItemID itemID, MenuCommand command ) +OSStatus FileWindow::OpenResource(DataBrowserItemID itemID, MenuCommand command) { - #pragma unused( command ) + #pragma unused(command) // get opened resource OSStatus error = noErr; // Boolean stop = false; - ResourceObjectPtr resource = GetResource( itemID ); + ResourceObjectPtr resource = GetResource(itemID); // check for null resource - if( resource == null ) + if(resource == null) { - DisplayError( "\pYou just double-clicked on a non-existant resource!" ); + DisplayError("\pYou just double-clicked on a non-existant resource!"); return paramErr; } // open correct editor - switch( command ) + switch(command) { case kMenuCommandOpenHex: - LoadEditor( resource, "\pHex Editor" ); + LoadEditor(resource, "\pHex Editor"); break; case kMenuCommandOpenDefault: Str255 typeStr; - TypeToPString( resource->Type(), typeStr ); - AppendPString( typeStr, "\p Editor" ); - LoadEditor( resource, typeStr ); + TypeToPString(resource->Type(), typeStr); + AppendPString(typeStr, "\p Editor"); + LoadEditor(resource, typeStr); break; case kMenuCommandOpenTemplate: - LoadEditor( resource, "\pTemplate Editor" ); + LoadEditor(resource, "\pTemplate Editor"); error = eventNotHandledErr; break; @@ -1638,7 +1638,7 @@ OSStatus FileWindow::OpenResource( DataBrowserItemID itemID, MenuCommand command break; default: - DebugError( "\pWrong command sent to FileWindow::OpenResource()" ); + DebugError("\pWrong command sent to FileWindow::OpenResource()"); error = eventNotHandledErr; break; } @@ -1648,21 +1648,21 @@ OSStatus FileWindow::OpenResource( DataBrowserItemID itemID, MenuCommand command /*** DISPOSE RESOURCE MAP ***/ OSStatus FileWindow::DisposeResourceMap() { - if( !resourceMap ) return noErr; // resource map already disposed + if(!resourceMap) return noErr; // resource map already disposed UInt32 numDeleted = 0; ResourceObjectPtr current = resourceMap, next; - while( current ) + while(current) { next = current->Next(); - if( current->nameIconRgn ) DisposeRgn( current->nameIconRgn ); - if( current->data ) DisposeHandle( current->data ); - DisposePtr( (Ptr) current ); + if(current->nameIconRgn) DisposeRgn(current->nameIconRgn); + if(current->data) DisposeHandle(current->data); + DisposePtr((Ptr) current); // delete current; numDeleted += 1; current = next; } - if( numResources != numDeleted ) return paramErr; // my lazy way of saying I don't know what happened + if(numResources != numDeleted) return paramErr; // my lazy way of saying I don't know what happened else return noErr; } @@ -1671,17 +1671,17 @@ OSStatus FileWindow::DisposeResourceMap() /******************/ /*** PLAY SOUND ***/ -OSStatus FileWindow::PlaySound( DataBrowserItemID itemID ) +OSStatus FileWindow::PlaySound(DataBrowserItemID itemID) { long refNum = 0; // unused - ResourceObjectPtr resource = GetResource( itemID ); - if( resource->Data() ) + ResourceObjectPtr resource = GetResource(itemID); + if(resource->Data()) { - SInt8 state = HGetState( resource->Data() ); - HLock( resource->Data() ); - if( g.asyncSound ) SHPlayByHandle( resource->Data(), &refNum ); - else SndPlay( nil, (SndListHandle) resource->Data(), false ); - HSetState( resource->Data(), state ); + SInt8 state = HGetState(resource->Data()); + HLock(resource->Data()); + if(g.asyncSound) SHPlayByHandle(resource->Data(), &refNum); + else SndPlay(nil, (SndListHandle) resource->Data(), false); + HSetState(resource->Data(), state); } return noErr; } @@ -1691,47 +1691,47 @@ OSStatus FileWindow::PlaySound( DataBrowserItemID itemID ) /*******************************/ /*** GET FILE SPEC ***/ -FSSpecPtr FileWindow::GetFileSpec( void ) +FSSpecPtr FileWindow::GetFileSpec(void) { return fileSpec; } /*** SET FILE SPEC ***/ -void FileWindow::SetFileSpec( FSSpecPtr spec ) +void FileWindow::SetFileSpec(FSSpecPtr spec) { fileExists = spec? true:false; - if( fileExists ) + if(fileExists) { - BlockMoveData( (Ptr) spec, (Ptr) fileSpec, sizeof(FSSpec) ); - SetWindowProxyFSSpec( window, fileSpec ); - SetWindowModified( window, fileDirty ); + BlockMoveData((Ptr) spec, (Ptr) fileSpec, sizeof(FSSpec)); + SetWindowProxyFSSpec(window, fileSpec); + SetWindowModified(window, fileDirty); } else { - DisposePtr( (Ptr) fileSpec ); - fileSpec = (FSSpecPtr) NewPtrClear( sizeof(FSSpec) ); - SetWindowProxyCreatorAndType( window, kResKnifeCreator, kResourceFileType, kOnSystemDisk ); - SetWindowModified( window, true ); + DisposePtr((Ptr) fileSpec); + fileSpec = (FSSpecPtr) NewPtrClear(sizeof(FSSpec)); + SetWindowProxyCreatorAndType(window, kResKnifeCreator, kResourceFileType, kOnSystemDisk); + SetWindowModified(window, true); } } /*** IS FILE DIRTY ***/ -Boolean FileWindow::IsFileDirty( void ) +Boolean FileWindow::IsFileDirty(void) { return fileDirty; } /*** SET FILE DIRTY ***/ -void FileWindow::SetFileDirty( Boolean dirty ) +void FileWindow::SetFileDirty(Boolean dirty) { fileDirty = dirty; // bug: used to crash my machine but mysteriously doesn't any more - SetWindowModified( window, dirty ); + SetWindowModified(window, dirty); } #if TARGET_API_MAC_CARBON /*** GET DATA BROWSER ***/ -ControlRef FileWindow::GetDataBrowser( void ) +ControlRef FileWindow::GetDataBrowser(void) { return dataBrowser; } @@ -1743,61 +1743,61 @@ ControlRef FileWindow::GetDataBrowser( void ) /**********************/ /*** GET RESOURCE COUNT ***/ -UInt32 FileWindow::GetResourceCount( ResType wanted ) +UInt32 FileWindow::GetResourceCount(ResType wanted) { - #pragma unused( wanted ) + #pragma unused(wanted) return numResources; } /*** GET RESOURCE ***/ -ResourceObjectPtr FileWindow::GetResource( DataBrowserItemID itemID ) +ResourceObjectPtr FileWindow::GetResource(DataBrowserItemID itemID) { ResourceObjectPtr res = resourceMap; - if( itemID == kDataBrowserNoItem ) return null; - while( itemID != res->Number() ) + if(itemID == kDataBrowserNoItem) return null; + while(itemID != res->Number()) { res = res->Next(); - if( res == null ) return null; + if(res == null) return null; } return res; } /*** GET RESOURCE NAME ***/ -UInt8* FileWindow::GetResourceName( DataBrowserItemID itemID ) +UInt8* FileWindow::GetResourceName(DataBrowserItemID itemID) { - ResourceObjectPtr resource = GetResource( itemID ); - if( resource == null ) return null; + ResourceObjectPtr resource = GetResource(itemID); + if(resource == null) return null; return resource->Name(); } /*** GET RESOURCE SIZE ***/ -UInt32 FileWindow::GetResourceSize( DataBrowserItemID itemID ) +UInt32 FileWindow::GetResourceSize(DataBrowserItemID itemID) { - ResourceObjectPtr resource = GetResource( itemID ); - if( resource == null ) return null; + ResourceObjectPtr resource = GetResource(itemID); + if(resource == null) return null; return resource->Size(); } /*** GET RESOURCE TYPE ***/ -ResType FileWindow::GetResourceType( DataBrowserItemID itemID ) +ResType FileWindow::GetResourceType(DataBrowserItemID itemID) { - ResourceObjectPtr resource = GetResource( itemID ); - if( resource == null ) return null; + ResourceObjectPtr resource = GetResource(itemID); + if(resource == null) return null; return resource->Type(); } /*** GET RESOURCE ID ***/ -SInt16 FileWindow::GetResourceID( DataBrowserItemID itemID ) +SInt16 FileWindow::GetResourceID(DataBrowserItemID itemID) { - ResourceObjectPtr resource = GetResource( itemID ); - if( resource == null ) return null; + ResourceObjectPtr resource = GetResource(itemID); + if(resource == null) return null; return resource->ID(); } /*** GET RESOURCE ATTRIBUTES ***/ -SInt16 FileWindow::GetResourceAttributes( DataBrowserItemID itemID ) +SInt16 FileWindow::GetResourceAttributes(DataBrowserItemID itemID) { - ResourceObjectPtr resource = GetResource( itemID ); - if( resource == null ) return null; + ResourceObjectPtr resource = GetResource(itemID); + if(resource == null) return null; return resource->Attributes(); } \ No newline at end of file diff --git a/Carbon/Classes/FileWindow.h b/Carbon/Classes/FileWindow.h index 31b92ac..41e6bc9 100644 --- a/Carbon/Classes/FileWindow.h +++ b/Carbon/Classes/FileWindow.h @@ -89,87 +89,87 @@ class FileWindow : WindowObject /* methods */ public: - FileWindow( FSSpecPtr spec = null ); - virtual ~FileWindow( void ); + FileWindow(FSSpecPtr spec = null); + virtual ~FileWindow(void); // overridden inherited functions /*! * @function Window * @discussion Accessor for the object’s WindowRef. */ - virtual WindowRef Window( void ); - virtual OSStatus BoundsChanging( EventRef event ); - virtual OSStatus BoundsChanged( EventRef event ); + virtual WindowRef Window(void); + virtual OSStatus BoundsChanging(EventRef event); + virtual OSStatus BoundsChanged(EventRef event); #if !TARGET_API_MAC_CARBON - virtual OSStatus Activate( Boolean active = true ); - virtual OSStatus Update( RgnHandle region = null ); - virtual OSStatus Click( Point mouse, EventModifiers modifiers ); + virtual OSStatus Activate(Boolean active = true); + virtual OSStatus Update(RgnHandle region = null); + virtual OSStatus Click(Point mouse, EventModifiers modifiers); // drawing private: - virtual OSStatus UpdateScrollBars( void ); - OSStatus DrawResourceIcon( ResourceObjectPtr resource, UInt16 line ); + virtual OSStatus UpdateScrollBars(void); + OSStatus DrawResourceIcon(ResourceObjectPtr resource, UInt16 line); // fake data brwser - OSStatus ClearSelection( void ); + OSStatus ClearSelection(void); #endif // file manipulation public: - OSStatus ReadResourceFork( void ); - OSStatus ReadDataFork( OSStatus rfError ); - OSStatus InitDataBrowser( void ); - OSStatus SaveFile( FSSpecPtr saveSpec = null ); + OSStatus ReadResourceFork(void); + OSStatus ReadDataFork(OSStatus rfError); + OSStatus InitDataBrowser(void); + OSStatus SaveFile(FSSpecPtr saveSpec = null); /*! @function ReadResourceMap @discussion Requires the fork containing resources to be at the top of the resource chain */ - OSStatus ReadResourceMap( void ); // fork-independent resource routines - OSStatus SaveResourceMap( void ); + OSStatus ReadResourceMap(void); // fork-independent resource routines + OSStatus SaveResourceMap(void); // carbon routines - OSStatus Zoomed( EventRef event ); - OSStatus SetIdealSize( EventRef event ); - OSStatus DisplaySaveDialog( void ); - OSStatus DisplayModelessAskSaveChangesDialog( void ); - OSStatus DisplaySaveAsDialog( void ); - OSStatus DisplayModelessPutFileDialog( void ); - OSStatus DisplayRevertFileDialog( void ); - OSStatus DisplayModelessAskDiscardChangesDialog( void ); - OSStatus DisplayNewResourceDialog( void ); - OSStatus DisplayNewResourceSheet( void ); + OSStatus Zoomed(EventRef event); + OSStatus SetIdealSize(EventRef event); + OSStatus DisplaySaveDialog(void); + OSStatus DisplayModelessAskSaveChangesDialog(void); + OSStatus DisplaySaveAsDialog(void); + OSStatus DisplayModelessPutFileDialog(void); + OSStatus DisplayRevertFileDialog(void); + OSStatus DisplayModelessAskDiscardChangesDialog(void); + OSStatus DisplayNewResourceDialog(void); + OSStatus DisplayNewResourceSheet(void); // resource map processing - OSStatus CreateNewResource( ConstStr255Param name, ResType type, SInt16 resID, SInt16 attribs ); - OSStatus OpenResource( DataBrowserItemID itemID, MenuCommand command ); - OSStatus DisposeResourceMap( void ); + OSStatus CreateNewResource(ConstStr255Param name, ResType type, SInt16 resID, SInt16 attribs); + OSStatus OpenResource(DataBrowserItemID itemID, MenuCommand command); + OSStatus DisposeResourceMap(void); // sound handlers - OSStatus PlaySound( DataBrowserItemID itemID ); + OSStatus PlaySound(DataBrowserItemID itemID); // file accessors - FSSpecPtr GetFileSpec( void ); - void SetFileSpec( FSSpecPtr spec ); - Boolean IsFileDirty( void ); - void SetFileDirty( Boolean dirty = true ); + FSSpecPtr GetFileSpec(void); + void SetFileSpec(FSSpecPtr spec); + Boolean IsFileDirty(void); + void SetFileDirty(Boolean dirty = true); #if TARGET_API_MAC_CARBON - ControlRef GetDataBrowser( void ); + ControlRef GetDataBrowser(void); #endif // resource accessors - UInt32 GetResourceCount( ResType wanted = 0x00000000 ); - ResourceObjectPtr GetResource( DataBrowserItemID itemID ); - UInt8* GetResourceName( DataBrowserItemID itemID ); - UInt32 GetResourceSize( DataBrowserItemID itemID ); - ResType GetResourceType( DataBrowserItemID itemID ); - SInt16 GetResourceID( DataBrowserItemID itemID ); - SInt16 GetResourceAttributes( DataBrowserItemID itemID ); + UInt32 GetResourceCount(ResType wanted = 0x00000000); + ResourceObjectPtr GetResource(DataBrowserItemID itemID); + UInt8* GetResourceName(DataBrowserItemID itemID); + UInt32 GetResourceSize(DataBrowserItemID itemID); + ResType GetResourceType(DataBrowserItemID itemID); + SInt16 GetResourceID(DataBrowserItemID itemID); + SInt16 GetResourceAttributes(DataBrowserItemID itemID); }; /* window event handler */ -pascal void FileWindowScrollAction( ControlHandle control, SInt16 controlPart ); -pascal OSStatus FileWindowEventHandler( EventHandlerCallRef callRef, EventRef event, void *userData ); -pascal OSStatus FileWindowUpdateMenus( EventHandlerCallRef callRef, EventRef event, void *userData ); -pascal OSStatus FileWindowParseMenuSelection( EventHandlerCallRef callRef, EventRef event, void *userData ); -pascal OSStatus NewResourceEventHandler( EventHandlerCallRef callRef, EventRef event, void *userData ); +pascal void FileWindowScrollAction(ControlHandle control, SInt16 controlPart); +pascal OSStatus FileWindowEventHandler(EventHandlerCallRef callRef, EventRef event, void *userData); +pascal OSStatus FileWindowUpdateMenus(EventHandlerCallRef callRef, EventRef event, void *userData); +pascal OSStatus FileWindowParseMenuSelection(EventHandlerCallRef callRef, EventRef event, void *userData); +pascal OSStatus NewResourceEventHandler(EventHandlerCallRef callRef, EventRef event, void *userData); -#endif \ No newline at end of file +#endif diff --git a/Carbon/Classes/Files.cpp b/Carbon/Classes/Files.cpp index 8dfb1c3..9405f7a 100644 --- a/Carbon/Classes/Files.cpp +++ b/Carbon/Classes/Files.cpp @@ -8,43 +8,43 @@ extern globals g; /* Convert an FSRef to an FSSpec: - FSGetCatalogInfo( &fsref, kFSCatInfoNone, null, null, &spec, null ); + FSGetCatalogInfo(&fsref, kFSCatInfoNone, null, null, &spec, null); Get your application's FSSpec FSSpec spec; String name; ProcessInfoRec info; ProcessSerialNumber psn; - GetCurrentProcess( &psn ); + GetCurrentProcess(&psn); info.processName = &name; info.processAppSpec = &spec; - GetProcessInformation( psn, &info ); + GetProcessInformation(psn, &info); */ /*** NAV OPEN FILE ***/ -/*OSStatus NavOpenFile( void ) +/*OSStatus NavOpenFile(void) { OSStatus error = noErr; NavReplyRecord reply; NavDialogOptions dialogOptions; - NavEventUPP eventProc = NewNavEventUPP( NavEventFilter ); - NavPreviewUPP previewProc = NewNavPreviewUPP( NavPreviewFilter ); - NavObjectFilterUPP filterProc = NewNavObjectFilterUPP( NavFileFilter ); + NavEventUPP eventProc = NewNavEventUPP(NavEventFilter); + NavPreviewUPP previewProc = NewNavPreviewUPP(NavPreviewFilter); + NavObjectFilterUPP filterProc = NewNavObjectFilterUPP(NavFileFilter); // Initialize dialog options structure and set default values - NavGetDefaultDialogOptions( &dialogOptions ); + NavGetDefaultDialogOptions(&dialogOptions); dialogOptions.dialogOptionFlags = kNavNoTypePopup | kNavDontAutoTranslate | kNavDontAddTranslateItems | kNavAllowMultipleFiles | kNavAllowInvisibleFiles; - BlockMoveData( g.appName, dialogOptions.clientName, sizeof(Str255) ); + BlockMoveData(g.appName, dialogOptions.clientName, sizeof(Str255)); // call the nav services routine - error = NavGetFile( null, &reply, &dialogOptions, eventProc, previewProc, filterProc, null, null ); - DisposeNavEventUPP( eventProc ); - DisposeNavPreviewUPP( previewProc ); - DisposeNavObjectFilterUPP( filterProc ); + error = NavGetFile(null, &reply, &dialogOptions, eventProc, previewProc, filterProc, null, null); + DisposeNavEventUPP(eventProc); + DisposeNavPreviewUPP(previewProc); + DisposeNavObjectFilterUPP(filterProc); - if( reply.validRecord && error == noErr ) + if(reply.validRecord && error == noErr) { - if( g.useAppleEvents ) - error = AppleEventSendSelf( kCoreEventClass, kAEOpenDocuments, reply.selection ); + if(g.useAppleEvents) + error = AppleEventSendSelf(kCoreEventClass, kAEOpenDocuments, reply.selection); #if !TARGET_API_MAC_CARBON else { @@ -54,30 +54,30 @@ extern globals g; FSSpec fileSpec; Size actualSize; - error = AEGetNthPtr( &(reply.selection), 1, typeFSS, &keyword, &descType, &fileSpec, sizeof(FSSpec), &actualSize ); - if( !error ) // if sucessful, open & read the file - new FileWindow( &fileSpec ); + error = AEGetNthPtr(&(reply.selection), 1, typeFSS, &keyword, &descType, &fileSpec, sizeof(FSSpec), &actualSize); + if(!error) // if sucessful, open & read the file + new FileWindow(&fileSpec); */ /* SInt32 count; FSSpec fileSpec; AEDesc resultDesc; - error = AECountItems( &(reply.selection), &count ); - if( !error ) - for( SInt32 n = 1; n <= count; n++ ) + error = AECountItems(&(reply.selection), &count); + if(!error) + for(SInt32 n = 1; n <= count; n++) { - error = AEGetNthDesc( &(reply.selection), n, typeFSS, null, &resultDesc ); - if( !error ) + error = AEGetNthDesc(&(reply.selection), n, typeFSS, null, &resultDesc); + if(!error) { - HLock( (Handle) resultDesc.dataHandle ); - BlockMoveData( (void *) *resultDesc.dataHandle, &fileSpec, sizeof(FSSpec) ); - new FileWindow( &fileSpec ); - AEDisposeDesc( &resultDesc ); + HLock((Handle) resultDesc.dataHandle); + BlockMoveData((void *) *resultDesc.dataHandle, &fileSpec, sizeof(FSSpec)); + new FileWindow(&fileSpec); + AEDisposeDesc(&resultDesc); } } */ /* } #endif // Always dispose of reply structure, resources, and descriptors - error = NavDisposeReply( &reply ); + error = NavDisposeReply(&reply); } return error; } @@ -86,98 +86,98 @@ extern globals g; #if !TARGET_API_MAC_CARBON /*** OPEN FILE ***/ -OSStatus OpenFile( short vRefNum, long dirID, ConstStr255Param fileName ) +OSStatus OpenFile(short vRefNum, long dirID, ConstStr255Param fileName) { FSSpec fileSpec; - FSMakeFSSpec( vRefNum, dirID, fileName, &fileSpec ); - new FileWindow( &fileSpec ); + FSMakeFSSpec(vRefNum, dirID, fileName, &fileSpec); + new FileWindow(&fileSpec); return noErr; } /*** DISPLAY STANDARD FILE OPEN DIALOG ***/ -OSStatus DisplayStandardFileOpenDialog( void ) +OSStatus DisplayStandardFileOpenDialog(void) { StandardFileReply theReply; SFTypeList typeList = { 0x0L }; - StandardGetFile( null, 0, typeList, &theReply ); - if( theReply.sfGood ) new FileWindow( &theReply.sfFile ); + StandardGetFile(null, 0, typeList, &theReply); + if(theReply.sfGood) new FileWindow(&theReply.sfFile); return theReply.sfGood? noErr:userCanceledErr; } #endif /*** OPEN A FILE DIALOG ***/ -OSStatus DisplayOpenDialog( void ) +OSStatus DisplayOpenDialog(void) { OSStatus error = noErr; NavReplyRecord reply; NavDialogOptions dialogOptions; - NavEventUPP eventProc = NewNavEventUPP( NavEventFilter ); - NavPreviewUPP previewProc = NewNavPreviewUPP( NavPreviewFilter ); - NavObjectFilterUPP filterProc = NewNavObjectFilterUPP( NavFileFilter ); + NavEventUPP eventProc = NewNavEventUPP(NavEventFilter); + NavPreviewUPP previewProc = NewNavPreviewUPP(NavPreviewFilter); + NavObjectFilterUPP filterProc = NewNavObjectFilterUPP(NavFileFilter); NavTypeListHandle typeList = null; - NavGetDefaultDialogOptions( &dialogOptions ); + NavGetDefaultDialogOptions(&dialogOptions); dialogOptions.dialogOptionFlags += kNavNoTypePopup; - GetIndString( dialogOptions.clientName, kFileNameStrings, kStringResKnifeName ); - error = NavGetFile( null, &reply, &dialogOptions, eventProc, previewProc, filterProc, typeList, null); - if( reply.validRecord || !error ) + GetIndString(dialogOptions.clientName, kFileNameStrings, kStringResKnifeName); + error = NavGetFile(null, &reply, &dialogOptions, eventProc, previewProc, filterProc, typeList, null); + if(reply.validRecord || !error) { AEKeyword keyword; DescType descType; FSSpec fileSpec; Size actualSize; - error = AEGetNthPtr( &(reply.selection), 1, typeFSS, &keyword, &descType, &fileSpec, sizeof(FSSpec), &actualSize ); - if( !error ) new FileWindow( &fileSpec ); // if sucessful, opens & reads the file - NavDisposeReply( &reply ); + error = AEGetNthPtr(&(reply.selection), 1, typeFSS, &keyword, &descType, &fileSpec, sizeof(FSSpec), &actualSize); + if(!error) new FileWindow(&fileSpec); // if sucessful, opens & reads the file + NavDisposeReply(&reply); } else error = userCanceledErr; - DisposeNavEventUPP( eventProc ); - DisposeNavPreviewUPP( previewProc ); - DisposeNavObjectFilterUPP( filterProc ); + DisposeNavEventUPP(eventProc); + DisposeNavPreviewUPP(previewProc); + DisposeNavObjectFilterUPP(filterProc); return error; } /*** DISPLAY MODELESS GET FILE DIALOG ***/ -OSStatus DisplayModelessGetFileDialog( void ) +OSStatus DisplayModelessGetFileDialog(void) { OSStatus error; - NavEventUPP eventProc = NewNavEventUPP( ModelessGetFileHandler ); + NavEventUPP eventProc = NewNavEventUPP(ModelessGetFileHandler); NavPreviewUPP previewProc = null; NavObjectFilterUPP filterProc = null; NavTypeListHandle typeList = null; NavDialogCreationOptions options; - error = NavGetDefaultDialogCreationOptions( &options ); - options.clientName = (CFStringRef) CFBundleGetValueForInfoDictionaryKey( CFBundleGetMainBundle(), kCFBundleNameKey ); + error = NavGetDefaultDialogCreationOptions(&options); + options.clientName = (CFStringRef) CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleNameKey); NavDialogRef dialog; - error = NavCreateGetFileDialog( &options, typeList, eventProc, previewProc, filterProc, null, &dialog ); - error = NavDialogRun( dialog ); - if( error ) NavDialogDispose( dialog ); + error = NavCreateGetFileDialog(&options, typeList, eventProc, previewProc, filterProc, null, &dialog); + error = NavDialogRun(dialog); + if(error) NavDialogDispose(dialog); return error; } /*** SAVE FILE DIALOG ***/ -OSStatus FileWindow::DisplaySaveDialog( void ) +OSStatus FileWindow::DisplaySaveDialog(void) { OSStatus error = noErr; NavDialogOptions options; - NavEventUPP eventProc = NewNavEventUPP( NavEventFilter ); + NavEventUPP eventProc = NewNavEventUPP(NavEventFilter); NavAskSaveChangesAction action = g.quitting? kNavSaveChangesQuittingApplication : kNavSaveChangesClosingDocument; NavAskSaveChangesResult result; - NavGetDefaultDialogOptions( &options ); - GetWindowTitle( window, options.savedFileName ); -// GetIndString( options.clientName, kFileNameStrings, kStringAppName ); - NavAskSaveChanges( &options, action, &result, eventProc, null ); + NavGetDefaultDialogOptions(&options); + GetWindowTitle(window, options.savedFileName); +// GetIndString(options.clientName, kFileNameStrings, kStringAppName); + NavAskSaveChanges(&options, action, &result, eventProc, null); - switch( result ) + switch(result) { case kNavAskSaveChangesSave: - if( fileExists ) error = SaveFile( null ); + if(fileExists) error = SaveFile(null); else error = DisplaySaveAsDialog(); break; @@ -191,45 +191,45 @@ OSStatus FileWindow::DisplaySaveDialog( void ) break; } - DisposeNavEventUPP( eventProc ); + DisposeNavEventUPP(eventProc); return error; } /*** DISPLAY MODELESS SAVE DIALOG ***/ -OSStatus FileWindow::DisplayModelessAskSaveChangesDialog( void ) +OSStatus FileWindow::DisplayModelessAskSaveChangesDialog(void) { OSStatus error; - NavEventUPP eventProc = NewNavEventUPP( ModelessAskSaveChangesHandler ); + NavEventUPP eventProc = NewNavEventUPP(ModelessAskSaveChangesHandler); /* NavPreviewUPP previewProc = null; NavObjectFilterUPP filterProc = null; NavTypeListHandle typeList = null; */ NavAskSaveChangesAction action = g.quitting? kNavSaveChangesQuittingApplication : kNavSaveChangesClosingDocument; NavDialogCreationOptions options; - error = NavGetDefaultDialogCreationOptions( &options ); + error = NavGetDefaultDialogCreationOptions(&options); options.parentWindow = window; options.modality = kWindowModalityWindowModal; - options.clientName = (CFStringRef) CFBundleGetValueForInfoDictionaryKey( CFBundleGetMainBundle(), kCFBundleNameKey ); // bug: are these two strings CFReleased? Should they be? - options.saveFileName = CFStringCreateWithPascalString( null, fileSpec->name, CFStringGetSystemEncoding()); // bug: see above + options.clientName = (CFStringRef) CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleNameKey); // bug: are these two strings CFReleased? Should they be? + options.saveFileName = CFStringCreateWithPascalString(null, fileSpec->name, CFStringGetSystemEncoding()); // bug: see above NavDialogRef dialog; - error = NavCreateAskSaveChangesDialog( &options, action, eventProc, this, &dialog ); - error = NavDialogRun( dialog ); + error = NavCreateAskSaveChangesDialog(&options, action, eventProc, this, &dialog); + error = NavDialogRun(dialog); return error; } /*** SAVE AS DIALOG ***/ -OSStatus FileWindow::DisplaySaveAsDialog( void ) +OSStatus FileWindow::DisplaySaveAsDialog(void) { OSStatus error = noErr; NavReplyRecord reply; NavDialogOptions dialogOptions; - NavEventUPP eventProc = NewNavEventUPP( NavEventFilter ); + NavEventUPP eventProc = NewNavEventUPP(NavEventFilter); - NavGetDefaultDialogOptions( &dialogOptions ); - GetWindowTitle( window, dialogOptions.savedFileName ); - GetIndString( dialogOptions.clientName, kFileNameStrings, kStringResKnifeName ); - error = NavPutFile( null, &reply, &dialogOptions, eventProc, kResourceFileType, kResKnifeCreator, null ); - if( reply.validRecord || !error ) + NavGetDefaultDialogOptions(&dialogOptions); + GetWindowTitle(window, dialogOptions.savedFileName); + GetIndString(dialogOptions.clientName, kFileNameStrings, kStringResKnifeName); + error = NavPutFile(null, &reply, &dialogOptions, eventProc, kResourceFileType, kResKnifeCreator, null); + if(reply.validRecord || !error) { AEKeyword keyword; DescType descType; @@ -237,67 +237,67 @@ OSStatus FileWindow::DisplaySaveAsDialog( void ) Size actualSize; // bug: does the next line only get the first selected file? - error = AEGetNthPtr( &(reply.selection), 1, typeFSS, &keyword, &descType, &savedSpec, sizeof(FSSpec), &actualSize ); - if( !error ) + error = AEGetNthPtr(&(reply.selection), 1, typeFSS, &keyword, &descType, &savedSpec, sizeof(FSSpec), &actualSize); + if(!error) { - if( reply.replacing ) error = FSpDelete( &savedSpec ); - if( !error ) + if(reply.replacing) error = FSpDelete(&savedSpec); + if(!error) { - error = SaveFile( &savedSpec ); - if ( !error ) - error = NavCompleteSave( &reply, kNavTranslateInPlace ); + error = SaveFile(&savedSpec); + if (!error) + error = NavCompleteSave(&reply, kNavTranslateInPlace); } - else if( error == fBsyErr ) + else if(error == fBsyErr) { - DisplayError( kStringUnknownError, kExplanationUnknownError ); // read error + DisplayError(kStringUnknownError, kExplanationUnknownError); // read error } } - NavDisposeReply( &reply ); + NavDisposeReply(&reply); } - else if( !error ) error = userCanceledErr; + else if(!error) error = userCanceledErr; - DisposeNavEventUPP( eventProc ); + DisposeNavEventUPP(eventProc); return error; } /*** DISPLAY MODELESS PUT FILE DIALOG ***/ -OSStatus FileWindow::DisplayModelessPutFileDialog( void ) +OSStatus FileWindow::DisplayModelessPutFileDialog(void) { OSStatus error; - NavEventUPP eventProc = NewNavEventUPP( ModelessPutFileHandler ); + NavEventUPP eventProc = NewNavEventUPP(ModelessPutFileHandler); NavDialogCreationOptions options; - error = NavGetDefaultDialogCreationOptions( &options ); + error = NavGetDefaultDialogCreationOptions(&options); options.parentWindow = window; options.modality = kWindowModalityWindowModal; - options.clientName = (CFStringRef) CFBundleGetValueForInfoDictionaryKey( CFBundleGetMainBundle(), kCFBundleNameKey ); - options.saveFileName = CFStringCreateWithPascalString( null, fileSpec->name, CFStringGetSystemEncoding()); + options.clientName = (CFStringRef) CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleNameKey); + options.saveFileName = CFStringCreateWithPascalString(null, fileSpec->name, CFStringGetSystemEncoding()); NavDialogRef dialog; - error = NavCreatePutFileDialog( &options, kResourceFileType, kResKnifeCreator, eventProc, this, &dialog ); - error = NavDialogRun( dialog ); + error = NavCreatePutFileDialog(&options, kResourceFileType, kResKnifeCreator, eventProc, this, &dialog); + error = NavDialogRun(dialog); return error; } /*** DISPLAY REVERT FILE DIALOG ***/ -OSStatus FileWindow::DisplayRevertFileDialog( void ) +OSStatus FileWindow::DisplayRevertFileDialog(void) { OSStatus error = noErr; NavDialogOptions dialogOptions; - NavEventUPP eventProc = NewNavEventUPP( NavEventFilter ); + NavEventUPP eventProc = NewNavEventUPP(NavEventFilter); NavAskDiscardChangesResult result; - NavGetDefaultDialogOptions( &dialogOptions ); - GetWindowTitle( window, dialogOptions.savedFileName ); - NavAskDiscardChanges( &dialogOptions, &result, eventProc, null ); + NavGetDefaultDialogOptions(&dialogOptions); + GetWindowTitle(window, dialogOptions.savedFileName); + NavAskDiscardChanges(&dialogOptions, &result, eventProc, null); - switch( result ) + switch(result) { case kNavAskDiscardChanges: /* error = CloseFile(); - if( error ) break; + if(error) break; error = OpenFile(); - if( error ) break; + if(error) break; error = ReadFile(); */ break; @@ -306,25 +306,25 @@ OSStatus FileWindow::DisplayRevertFileDialog( void ) break; } - DisposeNavEventUPP( eventProc ); + DisposeNavEventUPP(eventProc); return error; } /*** DISPLAY MODELESS ASK DISCARD CHANGES DIALOG ***/ -OSStatus FileWindow::DisplayModelessAskDiscardChangesDialog( void ) +OSStatus FileWindow::DisplayModelessAskDiscardChangesDialog(void) { OSStatus error; - NavEventUPP eventProc = NewNavEventUPP( ModelessAskDiscardChangesHandler ); + NavEventUPP eventProc = NewNavEventUPP(ModelessAskDiscardChangesHandler); NavDialogCreationOptions options; - error = NavGetDefaultDialogCreationOptions( &options ); + error = NavGetDefaultDialogCreationOptions(&options); options.parentWindow = window; options.modality = kWindowModalityWindowModal; - options.clientName = (CFStringRef) CFBundleGetValueForInfoDictionaryKey( CFBundleGetMainBundle(), kCFBundleNameKey ); - options.saveFileName = CFStringCreateWithPascalString( null, fileSpec->name, CFStringGetSystemEncoding()); + options.clientName = (CFStringRef) CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleNameKey); + options.saveFileName = CFStringCreateWithPascalString(null, fileSpec->name, CFStringGetSystemEncoding()); NavDialogRef dialog; - error = NavCreateAskDiscardChangesDialog( &options, eventProc, this, &dialog ); - error = NavDialogRun( dialog ); + error = NavCreateAskDiscardChangesDialog(&options, eventProc, this, &dialog); + error = NavDialogRun(dialog); return error; } @@ -335,13 +335,13 @@ OSStatus FileWindow::DisplayModelessAskDiscardChangesDialog( void ) #pragma mark - /*** NAV SERVICES EVENT FILTER ***/ -pascal void NavEventFilter( NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD ) +pascal void NavEventFilter(NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD) { - #pragma unused( callBackUD ) - switch( callBackSelector ) + #pragma unused(callBackUD) + switch(callBackSelector) { case kNavCBEvent: - switch( cbRecord->eventData.eventDataParms.event->what ) + switch(cbRecord->eventData.eventDataParms.event->what) { default: break; @@ -350,22 +350,22 @@ pascal void NavEventFilter( NavEventCallbackMessage callBackSelector, NavCBRecPt /* // Don't open file if it gets double-clicked (e.g. to add to an 'open' list instead) case kNavCBOpenSelection: - NavCustomControl( callBackParms->context, (long) kNavCtlSetActionState, (void *) kNavDontOpenState ); + NavCustomControl(callBackParms->context, (long) kNavCtlSetActionState, (void *) kNavDontOpenState); break; */ } } /*** NAV SERVICES PREVIEW FILTER ***/ -pascal Boolean NavPreviewFilter( NavCBRecPtr callBackParms, void *callBackUD ) +pascal Boolean NavPreviewFilter(NavCBRecPtr callBackParms, void *callBackUD) { - #pragma unused( callBackParms, callBackUD ) + #pragma unused(callBackParms, callBackUD) return false; } /*** NAV SERVICES FILE FILTER ***/ -pascal Boolean NavFileFilter( AEDescPtr theItem, void *info, void *callBackUD, NavFilterModes filterMode ) +pascal Boolean NavFileFilter(AEDescPtr theItem, void *info, void *callBackUD, NavFilterModes filterMode) { - #pragma unused( theItem, info, callBackUD, filterMode ) + #pragma unused(theItem, info, callBackUD, filterMode) /* do something useful here: count rsources & types give DF-based or RF-based info @@ -376,112 +376,112 @@ pascal Boolean NavFileFilter( AEDescPtr theItem, void *info, void *callBackUD, N #pragma mark - /*** MODELESS GET FILE HANDLER ***/ -pascal void ModelessGetFileHandler( const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD ) +pascal void ModelessGetFileHandler(const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD) { - #pragma unused( callBackUD ) + #pragma unused(callBackUD) OSStatus error = noErr; - switch( callBackSelector ) + switch(callBackSelector) { case kNavCBAccept: // case kNavCBUserAction: { // open first selected file NavReplyRecord reply; - error = NavDialogGetReply( cbRecord->context, &reply ); - if( reply.validRecord ) + error = NavDialogGetReply(cbRecord->context, &reply); + if(reply.validRecord) { AEKeyword keyword; DescType descType; FSSpec fileSpec; Size actualSize; - error = AEGetNthPtr( &(reply.selection), 1, typeFSS, &keyword, &descType, &fileSpec, sizeof(FSSpec), &actualSize ); - if( !error ) new FileWindow( &fileSpec ); // if sucessful, opens & reads the file + error = AEGetNthPtr(&(reply.selection), 1, typeFSS, &keyword, &descType, &fileSpec, sizeof(FSSpec), &actualSize); + if(!error) new FileWindow(&fileSpec); // if sucessful, opens & reads the file } else SysBeep(0); - NavDisposeReply( &reply ); + NavDisposeReply(&reply); } break; case kNavCBTerminate: { // dispose of the dialog - NavDialogDispose( cbRecord->context ); + NavDialogDispose(cbRecord->context); } break; } } /*** MODELESS ASK SAVE CHANGES HANDLER ***/ -pascal void ModelessAskSaveChangesHandler( const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD ) +pascal void ModelessAskSaveChangesHandler(const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD) { OSStatus error = noErr; FileWindowPtr file = (FileWindowPtr) callBackUD; - switch( callBackSelector ) + switch(callBackSelector) { case kNavCBUserAction: { // open first selected file NavReplyRecord reply; - error = NavDialogGetReply( cbRecord->context, &reply ); - if( reply.validRecord ) + error = NavDialogGetReply(cbRecord->context, &reply); + if(reply.validRecord) { - error = file->SaveFile( null ); + error = file->SaveFile(null); } else SysBeep(0); - NavDisposeReply( &reply ); + NavDisposeReply(&reply); } break; case kNavCBTerminate: { // dispose of the dialog - NavDialogDispose( cbRecord->context ); + NavDialogDispose(cbRecord->context); } break; } } /*** MODELESS PUT FILE HANDLER ***/ -pascal void ModelessPutFileHandler( const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD ) +pascal void ModelessPutFileHandler(const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD) { OSStatus error = noErr; // FileWindowPtr file = (FileWindowPtr) callBackUD; - switch( callBackSelector ) + switch(callBackSelector) { case kNavCBUserAction: { // open first selected file NavReplyRecord reply; - error = NavDialogGetReply( cbRecord->context, &reply ); - if( reply.validRecord ) + error = NavDialogGetReply(cbRecord->context, &reply); + if(reply.validRecord) { ; } else SysBeep(0); - NavDisposeReply( &reply ); + NavDisposeReply(&reply); } break; case kNavCBTerminate: { // dispose of the dialog - NavDialogDispose( cbRecord->context ); + NavDialogDispose(cbRecord->context); } break; } } /*** MODELESS ASK DISCARD CHANGES HANDLER ***/ -pascal void ModelessAskDiscardChangesHandler( const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD ) +pascal void ModelessAskDiscardChangesHandler(const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD) { OSStatus error = noErr; // FileWindowPtr file = (FileWindowPtr) callBackUD; - switch( callBackSelector ) + switch(callBackSelector) { case kNavCBUserAction: { // open first selected file NavReplyRecord reply; - error = NavDialogGetReply( cbRecord->context, &reply ); - if( reply.validRecord ) + error = NavDialogGetReply(cbRecord->context, &reply); + if(reply.validRecord) { ; } else SysBeep(0); - NavDisposeReply( &reply ); + NavDisposeReply(&reply); } break; case kNavCBTerminate: { // dispose of the dialog - NavDialogDispose( cbRecord->context ); + NavDialogDispose(cbRecord->context); } break; } } @@ -493,67 +493,67 @@ pascal void ModelessAskDiscardChangesHandler( const NavEventCallbackMessage call #pragma mark - /*** READ RESOURCE FORK ***/ -OSStatus FileWindow::ReadResourceFork( void ) +OSStatus FileWindow::ReadResourceFork(void) { // open file for reading OSStatus error = noErr; SInt16 oldResFile = CurResFile(); - SetResLoad( false ); // don't load "preload" resources - SInt16 refNum = FSpOpenResFile( fileSpec, fsRdPerm ); - SetResLoad( true ); - if( !refNum ) return resFNotFound; - UseResFile( refNum ); + SetResLoad(false); // don't load "preload" resources + SInt16 refNum = FSpOpenResFile(fileSpec, fsRdPerm); + SetResLoad(true); + if(!refNum) return resFNotFound; + UseResFile(refNum); error = ResError(); - if( error ) // no resource map in resource fork, try in data fork before alerting user - DebugError( "\pResource map not present in resource fork", error ); + if(error) // no resource map in resource fork, try in data fork before alerting user + DebugError("\pResource map not present in resource fork", error); // fork-independant resource reading routine else error = ReadResourceMap(); rfBased = error? false:true; // tidy up loose ends - UseResFile( oldResFile ); - FSClose( refNum ); + UseResFile(oldResFile); + FSClose(refNum); return error; } /*** READ DATA FORK ***/ -OSStatus FileWindow::ReadDataFork( OSStatus rfError ) +OSStatus FileWindow::ReadDataFork(OSStatus rfError) { OSStatus error = rfError; - if( error ) // error occoured reading resource map from resource fork, try reading map from data fork instead + if(error) // error occoured reading resource map from resource fork, try reading map from data fork instead { #if TARGET_API_MAC_CARBON FSRef fileRef; SInt16 refNum; SInt16 oldResFile = CurResFile(); - error = FSpMakeFSRef( fileSpec, &fileRef ); - if( error ) + error = FSpMakeFSRef(fileSpec, &fileRef); + if(error) { - DebugError( "\pFSpMakeFSRef error", error ); + DebugError("\pFSpMakeFSRef error", error); return error; } - if( FSOpenResourceFile == (void *) kUnresolvedCFragSymbolAddress ) + if(FSOpenResourceFile == (void *) kUnresolvedCFragSymbolAddress) { - DisplayError( "\pCarbonLib version too old", "\pThe version of CarbonLib you have installed won't let you view files whose resources are stored in the data fork. Please update to version 1.3 GM of CarbonLib, available from http://www.apple.com/" ); + DisplayError("\pCarbonLib version too old", "\pThe version of CarbonLib you have installed won't let you view files whose resources are stored in the data fork. Please update to version 1.3 GM of CarbonLib, available from http://www.apple.com/"); error = paramErr; return error; } - SetResLoad( false ); // don't load "preload" resources - error = FSOpenResourceFile( &fileRef, 0, null, fsRdPerm, &refNum ); - SetResLoad( true ); - if( error || !refNum ) + SetResLoad(false); // don't load "preload" resources + error = FSOpenResourceFile(&fileRef, 0, null, fsRdPerm, &refNum); + SetResLoad(true); + if(error || !refNum) { - DisplayError( "\pThis file is corrupt", "\pSorry, but you will not be able to open it. You should replace it with a backÑup. FSOpenResourceFile()" ); + DisplayError("\pThis file is corrupt", "\pSorry, but you will not be able to open it. You should replace it with a backÑup. FSOpenResourceFile()"); return error? error:resFNotFound; } - UseResFile( refNum ); + UseResFile(refNum); // fork-independant resource reading routine error = ReadResourceMap(); // tidy up loose ends - UseResFile( oldResFile ); - FSClose( refNum ); + UseResFile(oldResFile); + FSClose(refNum); #endif return error; } @@ -561,17 +561,17 @@ OSStatus FileWindow::ReadDataFork( OSStatus rfError ) { // open file for reading SInt16 refNum; - error = FSpOpenDF( fileSpec, fsRdPerm, &refNum ); - if( error ) + error = FSpOpenDF(fileSpec, fsRdPerm, &refNum); + if(error) { - DisplayError( "\pData fork could not be read", "\pThis file appears to be corrupted. Although the resources could be read in correctly, the data fork could not be found. Please run Disk First Aid to correct the problem." ); + DisplayError("\pData fork could not be read", "\pThis file appears to be corrupted. Although the resources could be read in correctly, the data fork could not be found. Please run Disk First Aid to correct the problem."); return error; } - ResourceObjectPtr current = (ResourceObjectPtr) NewPtrClear( sizeof(ResourceObject) ); - if( !current ) + ResourceObjectPtr current = (ResourceObjectPtr) NewPtrClear(sizeof(ResourceObject)); + if(!current) { - DisplayError( "\pNot enough memory to read data fork", "\pPlease quit other applications and try again." ); - FSClose( refNum ); + DisplayError("\pNot enough memory to read data fork", "\pPlease quit other applications and try again."); + FSClose(refNum); return error; } @@ -579,7 +579,7 @@ OSStatus FileWindow::ReadDataFork( OSStatus rfError ) *current->name = 0x00; current->type = 0x00000000; current->resID = 0; - GetEOF( refNum, ¤t->size ); + GetEOF(refNum, ¤t->size); current->attribs = 0; current->nameIconRgn = NewRgn(); current->file = this; @@ -587,84 +587,84 @@ OSStatus FileWindow::ReadDataFork( OSStatus rfError ) // get new handle current->retainCount = 1; - current->data = NewHandleClear( current->size ); - if( !current->data || MemError() ) + current->data = NewHandleClear(current->size); + if(!current->data || MemError()) { - DisplayError( "\pNot enough memory to read data fork", "\pPlease quit other applications and try again." ); - FSClose( refNum ); + DisplayError("\pNot enough memory to read data fork", "\pPlease quit other applications and try again."); + FSClose(refNum); return memFullErr; } // read data fork - HLock( current->data ); - error = FSRead( refNum, ¤t->size, *current->data ); - HUnlock( current->data ); - if( error ) + HLock(current->data); + error = FSRead(refNum, ¤t->size, *current->data); + HUnlock(current->data); + if(error) { - DisplayError( "\pFailed to read data fork.", "\pA mysterious error occured reading the data fork. The record saying how long the file is has probably been corrupted. You should run Disk First Aid to repair the dis." ); - FSClose( refNum ); + DisplayError("\pFailed to read data fork.", "\pA mysterious error occured reading the data fork. The record saying how long the file is has probably been corrupted. You should run Disk First Aid to repair the dis."); + FSClose(refNum); return error; } current->next = resourceMap; resourceMap = current; - FSClose( refNum ); + FSClose(refNum); return error; } } /*** READ RESOURCE MAP ***/ -OSStatus FileWindow::ReadResourceMap( void ) +OSStatus FileWindow::ReadResourceMap(void) { OSStatus error = noErr; // set up variables & first resource record numResources = 0; numTypes = Count1Types(); - resourceMap = (ResourceObjectPtr) NewPtrClear( sizeof(ResourceObject) ); -// resourceMap = new ResourceObject( this ); + resourceMap = (ResourceObjectPtr) NewPtrClear(sizeof(ResourceObject)); +// resourceMap = new ResourceObject(this); ResourceObjectPtr current = resourceMap; - for( unsigned short i = 1; i <= numTypes; i++ ) + for(unsigned short i = 1; i <= numTypes; i++) { // read in each data type ResType type; - Get1IndType( &type, i ); - UInt16 n = Count1Resources( type ); - for( UInt16 j = 1; j <= n; j++ ) + Get1IndType(&type, i); + UInt16 n = Count1Resources(type); + for(UInt16 j = 1; j <= n; j++) { // get resource info -// SetResLoad( false ); - current->data = Get1IndResource( type, j ); +// SetResLoad(false); + current->data = Get1IndResource(type, j); error = ResError(); -// SetResLoad( true ); - if( MemError() ) +// SetResLoad(true); + if(MemError()) { - DisplayError( "\pNot enough memory to read all resources", "\pPlease quit other applications and try again." ); - DisposePtr( (Ptr) current ); + DisplayError("\pNot enough memory to read all resources", "\pPlease quit other applications and try again."); + DisposePtr((Ptr) current); return memFullErr; } - if( !current->Data() || error != noErr ) + if(!current->Data() || error != noErr) { - DisplayError( "\pResources are damaged, proceed with extreme caution!" ); + DisplayError("\pResources are damaged, proceed with extreme caution!"); // bug: dialog should have "continue", "stop" and "quit" buttons, stop being default - DisposePtr( (Ptr) current ); + DisposePtr((Ptr) current); // delete current; return error; // bug: what should I be doing here? } current->number = numResources + j; // ID of resource in dataBrowser - GetResInfo( current->Data(), ¤t->resID, ¤t->type, current->name ); - current->size = GetResourceSizeOnDisk( current->Data() ); - current->attribs = GetResAttrs( current->Data() ); + GetResInfo(current->Data(), ¤t->resID, ¤t->type, current->name); + current->size = GetResourceSizeOnDisk(current->Data()); + current->attribs = GetResAttrs(current->Data()); current->file = this; current->dataFork = false; - DetachResource( current->Data() ); // bug: this needs to be here so calling AddResource() when saving will work, but if ResLoad() was off above, it will kill the only link between the Handle and the resource. + DetachResource(current->Data()); // bug: this needs to be here so calling AddResource() when saving will work, but if ResLoad() was off above, it will kill the only link between the Handle and the resource. - if( i != numTypes || j != n ) // if this isn't the last resourceÉ + if(i != numTypes || j != n) // if this isn't the last resourceÉ { // Émove on to the next one - current->next = (ResourceObjectPtr) NewPtrClear( sizeof(ResourceObject) ); -// current->next = new ResourceObject( this ); + current->next = (ResourceObjectPtr) NewPtrClear(sizeof(ResourceObject)); +// current->next = new ResourceObject(this); current = current->next; } } @@ -674,32 +674,32 @@ OSStatus FileWindow::ReadResourceMap( void ) } /*** SAVE FILE ***/ -OSStatus FileWindow::SaveFile( FSSpecPtr saveSpec ) +OSStatus FileWindow::SaveFile(FSSpecPtr saveSpec) { OSStatus error; - if( saveSpec == null ) // we're straight saving the file, use a temp file, then switch + if(saveSpec == null) // we're straight saving the file, use a temp file, then switch { // set up file name Str255 countStr; // bug: this is not initalised before being used Str255 tempFileName = "\pResKnife Temporary File "; - NumToString( ++g.tempCount, (StringPtr) countStr ); - AppendPString( tempFileName, countStr ); + NumToString(++g.tempCount, (StringPtr) countStr); + AppendPString(tempFileName, countStr); // create temporary file spec SInt32 dirID; SInt16 vRefNum; // Always create the temporary file on the same volume as the file we're saving, otherwise FSpExchangeFiles() won't work - OSStatus error = FindFolder( fileSpec->vRefNum, /*kTemporaryFolderType*/ kDesktopFolderType, kCreateFolder, &vRefNum, &dirID ); - if( error ) DebugError( "\pFindFolder returned error.", error ); - error = FSMakeFSSpec( vRefNum, dirID, tempFileName, tempSpec ); - if( error == noErr ) + OSStatus error = FindFolder(fileSpec->vRefNum, /*kTemporaryFolderType*/ kDesktopFolderType, kCreateFolder, &vRefNum, &dirID); + if(error) DebugError("\pFindFolder returned error.", error); + error = FSMakeFSSpec(vRefNum, dirID, tempFileName, tempSpec); + if(error == noErr) { - DisplayError( "\pFile already exists", "\pThe temporary file used by ResKnife to protect your data already exists, try saving again. If the problem persists, flush your temporary items folder with a utility such as Eradicator." ); + DisplayError("\pFile already exists", "\pThe temporary file used by ResKnife to protect your data already exists, try saving again. If the problem persists, flush your temporary items folder with a utility such as Eradicator."); return error; } - else if( error != fnfErr && error != dirNFErr ) + else if(error != fnfErr && error != dirNFErr) { - DebugError( "\pError calling FSMakeFSSpec from FileWindow::SaveFile.", error ); + DebugError("\pError calling FSMakeFSSpec from FileWindow::SaveFile.", error); return error; } } @@ -710,52 +710,52 @@ OSStatus FileWindow::SaveFile( FSSpecPtr saveSpec ) // save plain DF if present ResourceObjectPtr current = resourceMap; - if( rfBased && current->RepresentsDataFork() ) // requires data fork to be first item in list + if(rfBased && current->RepresentsDataFork()) // requires data fork to be first item in list { // create data fork - FSpCreate( tempSpec, kResKnifeCreator, kResourceFileType, smSystemScript ); + FSpCreate(tempSpec, kResKnifeCreator, kResourceFileType, smSystemScript); // open file for writing SInt16 refNum; - error = FSpOpenDF( tempSpec, fsWrPerm, &refNum ); - if( error ) + error = FSpOpenDF(tempSpec, fsWrPerm, &refNum); + if(error) { - DisplayError( "\pData fork could not be read", "\pThis file appears to be corrupted. Although the resources could be read in correctly, the data fork could not be found. Please run Disk First Aid to correct the problem." ); + DisplayError("\pData fork could not be read", "\pThis file appears to be corrupted. Although the resources could be read in correctly, the data fork could not be found. Please run Disk First Aid to correct the problem."); return error; } // save byte stream - SInt8 state = HGetState( resourceMap->Data() ); - HLock( current->Data() ); + SInt8 state = HGetState(resourceMap->Data()); + HLock(current->Data()); SInt32 size = current->Size(); - SetEOF( refNum, size ); - error = FSWrite( refNum, &size, (Ptr) *current->Data() ); - HSetState( current->Data(), state ); - FSClose( refNum ); + SetEOF(refNum, size); + error = FSWrite(refNum, &size, (Ptr) *current->Data()); + HSetState(current->Data(), state); + FSClose(refNum); } - else if( !rfBased && current->RepresentsDataFork() ) + else if(!rfBased && current->RepresentsDataFork()) { - DisplayError( "\pData fork present with DF-based resource file." ); + DisplayError("\pData fork present with DF-based resource file."); } - else if( rfBased ) + else if(rfBased) { - DisplayError( "\pTried to save resource fork based file, but no data fork could be found" ); + DisplayError("\pTried to save resource fork based file, but no data fork could be found"); } // save resource map in specified fork - if( rfBased ) + if(rfBased) { SInt16 oldResFile = CurResFile(); - FSpCreateResFile( tempSpec, kResKnifeCreator, kResourceFileType, smSystemScript ); - SInt16 tempRef = FSpOpenResFile( tempSpec, fsWrPerm ); - UseResFile( tempRef ); + FSpCreateResFile(tempSpec, kResKnifeCreator, kResourceFileType, smSystemScript); + SInt16 tempRef = FSpOpenResFile(tempSpec, fsWrPerm); + UseResFile(tempRef); error = SaveResourceMap(); - UseResFile( oldResFile ); - CloseResFile( tempRef ); + UseResFile(oldResFile); + CloseResFile(tempRef); error = ResError(); - if( error ) + if(error) { - DebugError( "\pError calling CloseResFile.", error ); + DebugError("\pError calling CloseResFile.", error); return error; } } @@ -764,19 +764,19 @@ OSStatus FileWindow::SaveFile( FSSpecPtr saveSpec ) FSRef fileRef; SInt16 refNum; SInt16 oldResFile = CurResFile(); - error = FSpMakeFSRef( tempSpec, &fileRef ); - if( error ) + error = FSpMakeFSRef(tempSpec, &fileRef); + if(error) { - DebugError( "\pFSpMakeFSRef error", error ); + DebugError("\pFSpMakeFSRef error", error); return error; } - if( FSOpenResourceFile == (void *) kUnresolvedCFragSymbolAddress ) + if(FSOpenResourceFile == (void *) kUnresolvedCFragSymbolAddress) { - DisplayError( "\pCarbonLib version too old", "\pThe version of CarbonLib you have installed won't let you save resources into the data fork. Please update to version 1.3.1 of CarbonLib, available from http://www.apple.com/" ); + DisplayError("\pCarbonLib version too old", "\pThe version of CarbonLib you have installed won't let you save resources into the data fork. Please update to version 1.3.1 of CarbonLib, available from http://www.apple.com/"); error = paramErr; return error; } -/* error = FSCreateResourceFile( &fileRef, ); +/* error = FSCreateResourceFile(&fileRef,); const FSRef * parentRef, UniCharCount nameLength, const UniChar * name, @@ -787,77 +787,77 @@ OSStatus FileWindow::SaveFile( FSSpecPtr saveSpec ) FSRef * newRef, // can be NULL FSSpec * newSpec); // can be NULL - if( error ) + if(error) { - DisplayError( "\pFile could not be created", "\pThe file to save your resources into could not be created. FSCreateResourceFile()" ); + DisplayError("\pFile could not be created", "\pThe file to save your resources into could not be created. FSCreateResourceFile()"); return error? error:resFNotFound; } -*/ error = FSOpenResourceFile( &fileRef, 0, null, fsRdPerm, &refNum ); - if( error || !refNum ) +*/ error = FSOpenResourceFile(&fileRef, 0, null, fsRdPerm, &refNum); + if(error || !refNum) { - DisplayError( "\pFile could not be created", "\pThe file to save your resources into could not be created. FSOpenResourceFile()" ); + DisplayError("\pFile could not be created", "\pThe file to save your resources into could not be created. FSOpenResourceFile()"); return error? error:resFNotFound; } - UseResFile( refNum ); + UseResFile(refNum); error = SaveResourceMap(); - UseResFile( oldResFile ); - CloseResFile( refNum ); + UseResFile(oldResFile); + CloseResFile(refNum); error = ResError(); - if( error ) + if(error) { - DebugError( "\pError calling CloseResFile.", error ); + DebugError("\pError calling CloseResFile.", error); return error; } } // switch file for temp if we did a regular save - if( saveSpec == null ) + if(saveSpec == null) { // swap the temporary file for the real one - error = FSpExchangeFiles( tempSpec, fileSpec ); // bug: this will fail on non HFS/HFS+ file systems - therefore file will not save - if( error ) + error = FSpExchangeFiles(tempSpec, fileSpec); // bug: this will fail on non HFS/HFS+ file systems - therefore file will not save + if(error) { - DebugError( "\pError calling FSpExchangeFiles.", error ); + DebugError("\pError calling FSpExchangeFiles.", error); return error; } - error = FSpDelete( tempSpec ); - if( error ) + error = FSpDelete(tempSpec); + if(error) { - DebugError( "\pError calling FSpDelete.", error ); + DebugError("\pError calling FSpDelete.", error); } // file is no longer dirty fileDirty = false; - SetWindowModified( window, fileDirty ); + SetWindowModified(window, fileDirty); } return error; } /*** SAVE RESOURCE MAP ***/ -OSStatus FileWindow::SaveResourceMap( void ) +OSStatus FileWindow::SaveResourceMap(void) { OSStatus error = noErr; // save resources from memory to the temp file ResourceObjectPtr current = resourceMap; - if( current->RepresentsDataFork() == true ) + if(current->RepresentsDataFork() == true) current = current->Next(); // skip data fork - while( current ) + while(current) { // save resource - AddResource( current->Data(), current->Type(), current->ID(), current->Name() ); - if( ResError() == addResFailed ) + AddResource(current->Data(), current->Type(), current->ID(), current->Name()); + if(ResError() == addResFailed) { - DisplayError( "\pSaving Failed", "\pCould not add resources to file." ); + DisplayError("\pSaving Failed", "\pCould not add resources to file."); current = null; error = addResFailed; } else { - SetResAttrs( current->Data(), current->Attributes() ); - ChangedResource( current->Data() ); + SetResAttrs(current->Data(), current->Attributes()); + ChangedResource(current->Data()); // clean up & move on - DetachResource( current->Data() ); + DetachResource(current->Data()); current = current->Next(); } } diff --git a/Carbon/Classes/Files.h b/Carbon/Classes/Files.h index 544e139..902fa09 100644 --- a/Carbon/Classes/Files.h +++ b/Carbon/Classes/Files.h @@ -12,51 +12,51 @@ @function DisplayOpenDialog @discussion Calls the appropriate Open() function for the system we are running on. */ -OSStatus DisplayOpenDialog( void ); +OSStatus DisplayOpenDialog(void); /*! @function DisplayModelessGetFileDialog @discussion Requires CarbonLib 1.1 or OS X */ -OSStatus DisplayModelessGetFileDialog( void ); +OSStatus DisplayModelessGetFileDialog(void); /*! @function OpenFile */ -OSStatus OpenFile( short vRefNum, long dirID, ConstStr255Param fileName ); +OSStatus OpenFile(short vRefNum, long dirID, ConstStr255Param fileName); /*! @function DisplayStandardFileOpenDialog */ -OSStatus DisplayStandardFileOpenDialog( void ); +OSStatus DisplayStandardFileOpenDialog(void); /*! @function ModelessGetFileHandler @discussion Requires CarbonLib 1.1 or OS X */ -pascal void ModelessGetFileHandler( const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD ); +pascal void ModelessGetFileHandler(const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD); /*! @function ModelessAskSaveChangesHandler @discussion Requires CarbonLib 1.1 or OS X */ -pascal void ModelessAskSaveChangesHandler( const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD ); +pascal void ModelessAskSaveChangesHandler(const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD); /*! @function ModelessPutFileHandler @discussion Requires CarbonLib 1.1 or OS X */ -pascal void ModelessPutFileHandler( const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD ); +pascal void ModelessPutFileHandler(const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD); /*! @function ModelessAskDiscardChangesHandler @discussion Requires CarbonLib 1.1 or OS X */ -pascal void ModelessAskDiscardChangesHandler( const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD ); +pascal void ModelessAskDiscardChangesHandler(const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD); /*! @function NavEventFilter */ -pascal void NavEventFilter( NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD ); +pascal void NavEventFilter(NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD); /*! @function NavPreviewFilter */ -pascal Boolean NavPreviewFilter( NavCBRecPtr callBackParms, void *callBackUD ); +pascal Boolean NavPreviewFilter(NavCBRecPtr callBackParms, void *callBackUD); /*! @function NavFileFilter */ -pascal Boolean NavFileFilter( AEDescPtr theItem, void *info, void *callBackUD, NavFilterModes filterMode ); +pascal Boolean NavFileFilter(AEDescPtr theItem, void *info, void *callBackUD, NavFilterModes filterMode); #endif \ No newline at end of file diff --git a/Carbon/Classes/HostCallbacks.cpp b/Carbon/Classes/HostCallbacks.cpp index 73ad867..113996d 100644 --- a/Carbon/Classes/HostCallbacks.cpp +++ b/Carbon/Classes/HostCallbacks.cpp @@ -9,20 +9,20 @@ extern globals g; /* window management */ -Plug_WindowRef Host_RegisterWindow( Plug_PlugInRef plug, Plug_ResourceRef resource, WindowRef window ) +Plug_WindowRef Host_RegisterWindow(Plug_PlugInRef plug, Plug_ResourceRef resource, WindowRef window) { - if( resource ) + if(resource) { - EditorWindowPtr plugWindow = new EditorWindow( ((ResourceObjectPtr) resource)->File(), (ResourceObjectPtr) resource, window ); - ((PlugObjectPtr) plug)->SetWindowObject( (WindowObjectPtr) plugWindow ); - ((PlugObjectPtr) plug)->SetResourceObject( (ResourceObjectPtr) resource ); + EditorWindowPtr plugWindow = new EditorWindow(((ResourceObjectPtr) resource)->File(), (ResourceObjectPtr) resource, window); + ((PlugObjectPtr) plug)->SetWindowObject((WindowObjectPtr) plugWindow); + ((PlugObjectPtr) plug)->SetResourceObject((ResourceObjectPtr) resource); return (Plug_WindowRef) plugWindow; } /* else { - PickerWindowPtr plugWindow = new PickerWindow( window ); - ((PlugObjectPtr) plug)->SetWindowObject( plugWindow ); - ((PlugObjectPtr) plug)->SetResourceObject( (ResourceObjectPtr) resource ); + PickerWindowPtr plugWindow = new PickerWindow(window); + ((PlugObjectPtr) plug)->SetWindowObject(plugWindow); + ((PlugObjectPtr) plug)->SetResourceObject((ResourceObjectPtr) resource); return (Plug_WindowRef) plugWindow; } */ else return null; @@ -30,172 +30,172 @@ Plug_WindowRef Host_RegisterWindow( Plug_PlugInRef plug, Plug_ResourceRef resour #if !TARGET_API_MAC_CARBON -void Host_InstallClassicWindowEventHandler( Plug_WindowRef plugWindow, RoutineDescriptor *handler ) +void Host_InstallClassicWindowEventHandler(Plug_WindowRef plugWindow, RoutineDescriptor *handler) { - ((PlugWindowPtr) plugWindow)->InstallClassicEventHandler( (ClassicEventHandlerProcPtr) handler ); + ((PlugWindowPtr) plugWindow)->InstallClassicEventHandler((ClassicEventHandlerProcPtr) handler); } #endif -WindowRef Host_GetWindowRefFromPlugWindow( Plug_WindowRef plugWindow ) +WindowRef Host_GetWindowRefFromPlugWindow(Plug_WindowRef plugWindow) { return ((WindowObjectPtr) plugWindow)->Window(); } -Plug_WindowRef Host_GetPlugWindowFromWindowRef( WindowRef window ) +Plug_WindowRef Host_GetPlugWindowFromWindowRef(WindowRef window) { return (Plug_WindowRef) GetWindowRefCon(window); } -Plug_PlugInRef Host_GetPlugRef( WindowRef window ) +Plug_PlugInRef Host_GetPlugRef(WindowRef window) { - #pragma unused( window ) + #pragma unused(window) return null; } -Plug_ResourceRef Host_GetResource( ResType type, SInt32 resID, Plug_ResourceRef sameFileAsResource ) +Plug_ResourceRef Host_GetResource(ResType type, SInt32 resID, Plug_ResourceRef sameFileAsResource) { // FileWindowPtr file; - if( sameFileAsResource != NULL ) + if(sameFileAsResource != NULL) { // file = ((ResourceObjectPtr) sameFileAsResource)->file; short oldResFile = CurResFile(); - UseResFile( HomeResFile( ((ResourceObjectPtr) sameFileAsResource)->Data() ) ); - Get1Resource( type, resID ); // bug: handle ignored at present - UseResFile( oldResFile ); + UseResFile(HomeResFile(((ResourceObjectPtr) sameFileAsResource)->Data())); + Get1Resource(type, resID); // bug: handle ignored at present + UseResFile(oldResFile); } - else GetResource( type, resID ); // bug: handle ignored at present + else GetResource(type, resID); // bug: handle ignored at present return nil; // bug: handle ignored at present } -Plug_ResourceRef Host_GetTargetResource( Plug_WindowRef plugWindow ) +Plug_ResourceRef Host_GetTargetResource(Plug_WindowRef plugWindow) { return (Plug_ResourceRef) ((EditorWindowPtr) plugWindow)->Resource(); } /* accessors */ -Handle Host_GetResourceData( Plug_ResourceRef resource ) +Handle Host_GetResourceData(Plug_ResourceRef resource) { ((ResourceObjectPtr) resource)->Retain(); return ((ResourceObjectPtr) resource)->Data(); } -Handle Host_GetPartialResourceData( Plug_ResourceRef resource, UInt32 offset, UInt32 length ) +Handle Host_GetPartialResourceData(Plug_ResourceRef resource, UInt32 offset, UInt32 length) { - #pragma unused( resource, offset, length ) + #pragma unused(resource, offset, length) return null; } -void Host_ReleaseResourceData( Plug_ResourceRef resource ) +void Host_ReleaseResourceData(Plug_ResourceRef resource) { - #pragma unused( resource ) + #pragma unused(resource) // ((ResourceObjectPtr) resource)->Release(); return; } -void Host_ReleasePartialResourceData( Plug_ResourceRef resource, Handle data ) +void Host_ReleasePartialResourceData(Plug_ResourceRef resource, Handle data) { - #pragma unused( resource, data ) + #pragma unused(resource, data) return; } -ResType Host_GetResourceType( Plug_ResourceRef resource ) +ResType Host_GetResourceType(Plug_ResourceRef resource) { return ((ResourceObjectPtr) resource)->Type(); } -SInt16 Host_GetResourceID( Plug_ResourceRef resource ) +SInt16 Host_GetResourceID(Plug_ResourceRef resource) { return ((ResourceObjectPtr) resource)->ID(); } -UInt32 Host_GetResourceSize( Plug_ResourceRef resource ) +UInt32 Host_GetResourceSize(Plug_ResourceRef resource) { return ((ResourceObjectPtr) resource)->Size(); } -void Host_GetResourceName( Plug_ResourceRef resource, Str255 name ) +void Host_GetResourceName(Plug_ResourceRef resource, Str255 name) { - #pragma unused( resource, name ) + #pragma unused(resource, name) return; } -UInt32 Host_GetWindowRefCon( Plug_WindowRef plugWindow ) +UInt32 Host_GetWindowRefCon(Plug_WindowRef plugWindow) { return ((PlugWindowPtr) plugWindow)->GetRefCon(); } -void Host_SetWindowRefCon( Plug_WindowRef plugWindow, UInt32 value ) +void Host_SetWindowRefCon(Plug_WindowRef plugWindow, UInt32 value) { ((PlugWindowPtr) plugWindow)->SetRefCon(value); } -UInt32 Host_GetGlobalRefCon( Plug_PlugInRef plug ) +UInt32 Host_GetGlobalRefCon(Plug_PlugInRef plug) { return ((PlugObjectPtr) plug)->GetRefCon(); } -void Host_SetGlobalRefCon( Plug_PlugInRef plug, UInt32 value ) +void Host_SetGlobalRefCon(Plug_PlugInRef plug, UInt32 value) { ((PlugObjectPtr) plug)->SetRefCon(value); } -Boolean Host_GetResourceDirty( Plug_ResourceRef resource ) +Boolean Host_GetResourceDirty(Plug_ResourceRef resource) { return ((ResourceObjectPtr) resource)->Dirty(); } -void Host_SetResourceDirty( Plug_ResourceRef resource, Boolean dirty ) +void Host_SetResourceDirty(Plug_ResourceRef resource, Boolean dirty) { - ((ResourceObjectPtr) resource)->SetDirty( dirty ); + ((ResourceObjectPtr) resource)->SetDirty(dirty); } /* utilities */ -Handle Host_GetDefaultTemplate( ResType type ) +Handle Host_GetDefaultTemplate(ResType type) { short savedResFile = CurResFile(); - UseResFile( g.appResFile ); + UseResFile(g.appResFile); Str255 name = "\pxxxx"; - BlockMoveData( &type, name +1, sizeof(ResType) ); - Handle tmpl = Get1NamedResource( 'TMPL', name ); + BlockMoveData(&type, name +1, sizeof(ResType)); + Handle tmpl = Get1NamedResource('TMPL', name); OSStatus error = ResError(); - UseResFile( savedResFile ); - if( error ) return null; + UseResFile(savedResFile); + if(error) return null; else return tmpl; } -void Host_AppendMenuToBar( Plug_PlugInRef plug, SInt16 resID ) +void Host_AppendMenuToBar(Plug_PlugInRef plug, SInt16 resID) { - #pragma unused( plug, resID ) + #pragma unused(plug, resID) return; } -void Host_RemoveMenuFromBar( Plug_PlugInRef plug, SInt16 resID ) +void Host_RemoveMenuFromBar(Plug_PlugInRef plug, SInt16 resID) { - #pragma unused( plug, resID ) + #pragma unused(plug, resID) return; } -void Host_UpdateMenus( Plug_ResourceRef resource ) +void Host_UpdateMenus(Plug_ResourceRef resource) { OSStatus error = noErr; #if TARGET_API_MAC_CARBON - error = CarbonEventUpdateMenus( null, null, null ); -// if( error ) DebugError( "\pHost_UpdateMenus hit an error when calling CarbonEventUpdateMenus()" ); - error = FileWindowUpdateMenus( null, null, ((ResourceObjectPtr) resource)->File() ); -// if( error ) DebugError( "\pHost_UpdateMenus hit an error when calling FileWindowUpdateMenus()" ); + error = CarbonEventUpdateMenus(null, null, null); +// if(error) DebugError("\pHost_UpdateMenus hit an error when calling CarbonEventUpdateMenus()"); + error = FileWindowUpdateMenus(null, null, ((ResourceObjectPtr) resource)->File()); +// if(error) DebugError("\pHost_UpdateMenus hit an error when calling FileWindowUpdateMenus()"); #else - UpdateMenus( ((ResourceObjectPtr) resource)->File()->Window() ); + UpdateMenus(((ResourceObjectPtr) resource)->File()->Window()); #endif } -void Host_DisplayError( ConstStr255Param errorStr, ConstStr255Param explanationStr, UInt8 severity ) +void Host_DisplayError(ConstStr255Param errorStr, ConstStr255Param explanationStr, UInt8 severity) { - #pragma unused( severity ) - DisplayError( errorStr, explanationStr ); + #pragma unused(severity) + DisplayError(errorStr, explanationStr); } -void Host_DebugError( ConstStr255Param errorStr, OSStatus number ) +void Host_DebugError(ConstStr255Param errorStr, OSStatus number) { - DebugError( errorStr, number ); + DebugError(errorStr, number); } \ No newline at end of file diff --git a/Carbon/Classes/HostCallbacks.h b/Carbon/Classes/HostCallbacks.h index 30ba244..f80ad8d 100644 --- a/Carbon/Classes/HostCallbacks.h +++ b/Carbon/Classes/HostCallbacks.h @@ -94,7 +94,7 @@ extern "C" // functions beginning "Host_" are in ResKnife/Resurrection * @discussion Plug-ins should call this function immediatly after creating a window to swap their Mac OS WindowRef * for a Plug_WindowRef, which allows the host to track the window, it's contents, and to send events there. */ - ResCall Plug_WindowRef Host_RegisterWindow( Plug_PlugInRef plug, Plug_ResourceRef resource, WindowRef window ); + ResCall Plug_WindowRef Host_RegisterWindow(Plug_PlugInRef plug, Plug_ResourceRef resource, WindowRef window); /*! * @function Host_InstallClassicWindowEventHandler * @abstract Without this, non-carbon plugs will not receive events @@ -103,136 +103,136 @@ extern "C" // functions beginning "Host_" are in ResKnife/Resurrection * * • kEventWindowClickContentRgn */ - ResCall void Host_InstallClassicWindowEventHandler( Plug_WindowRef plugWindow, RoutineDescriptor *handler ); + ResCall void Host_InstallClassicWindowEventHandler(Plug_WindowRef plugWindow, RoutineDescriptor *handler); /*! * @function Host_GetWindowRefFromPlugWindow * @abstract Allows plug-ins to obtain a Mac OS WindowRef from their Plug_WindowRef * @discussion This call must not be made before the window has been registered using Host_RegisterWindow() */ - ResCall WindowRef Host_GetWindowRefFromPlugWindow( Plug_WindowRef plugWindow ); + ResCall WindowRef Host_GetWindowRefFromPlugWindow(Plug_WindowRef plugWindow); /*! * @function Host_GetPlugWindowFromWindowRef * @abstract Allows plug-ins to obtain a Plug_WindowRef from their Mac OS WindowRef * @discussion This call must not be made before the window has been registered using Host_RegisterWindow() */ - ResCall Plug_WindowRef Host_GetPlugWindowFromWindowRef( WindowRef window ); + ResCall Plug_WindowRef Host_GetPlugWindowFromWindowRef(WindowRef window); /*! * @function Host_GetPlugRef * @discussion You will probably need to call this if the system calls one of your routines directly. */ - ResCall Plug_PlugInRef Host_GetPlugRef( WindowRef window ); + ResCall Plug_PlugInRef Host_GetPlugRef(WindowRef window); /*! * @function Host_GetResource * @discussion Returns a reference to any arbitrary resource. * @param limitToDoc If true, the function will only search the same document that contains the resource returned by Host_GetTargetResource. If false, it will return any resource in the current resource chain. */ - ResCall Plug_ResourceRef Host_GetResource( SInt32 type, SInt32 resID, Boolean limitToDoc ); + ResCall Plug_ResourceRef Host_GetResource(SInt32 type, SInt32 resID, Boolean limitToDoc); /*! * @function Host_GetTargetResource * @discussion Returns the reference to the resource you're actually editing. */ - ResCall Plug_ResourceRef Host_GetTargetResource( Plug_WindowRef plugWindow ); + ResCall Plug_ResourceRef Host_GetTargetResource(Plug_WindowRef plugWindow); /*! * @function Host_GetResourceData * @discussion Dispose of with Host_ReleaseResourceData() */ - ResCall Handle Host_GetResourceData( Plug_ResourceRef resource ); + ResCall Handle Host_GetResourceData(Plug_ResourceRef resource); /*! * @function Host_GetPartialResourceData * @discussion Dispose of with Host_ReleasePartialResourceData() */ - ResCall Handle Host_GetPartialResourceData( Plug_ResourceRef resource, UInt32 offset, UInt32 length ); + ResCall Handle Host_GetPartialResourceData(Plug_ResourceRef resource, UInt32 offset, UInt32 length); /*! * @function Host_ReleaseResourceData */ - ResCall void Host_ReleaseResourceData( Plug_ResourceRef resource ); + ResCall void Host_ReleaseResourceData(Plug_ResourceRef resource); /*! * @function Host_ReleasePartialResourceData */ - ResCall void Host_ReleasePartialResourceData( Plug_ResourceRef resource, Handle data ); + ResCall void Host_ReleasePartialResourceData(Plug_ResourceRef resource, Handle data); /*! * @function Host_GetResourceType */ - ResCall ResType Host_GetResourceType( Plug_ResourceRef resource ); + ResCall ResType Host_GetResourceType(Plug_ResourceRef resource); /*! * @function Host_GetResourceID */ - ResCall SInt16 Host_GetResourceID( Plug_ResourceRef resource ); + ResCall SInt16 Host_GetResourceID(Plug_ResourceRef resource); /*! * @function Host_GetResourceSize */ - ResCall UInt32 Host_GetResourceSize( Plug_ResourceRef resource ); + ResCall UInt32 Host_GetResourceSize(Plug_ResourceRef resource); /*! * @function Host_GetResourceName */ - ResCall void Host_GetResourceName( Plug_ResourceRef resource, Str255 name ); -/* ResCall void Host_SetResourceName( Plug_ResourceRef resource, ConstStr255Param name ); */ + ResCall void Host_GetResourceName(Plug_ResourceRef resource, Str255 name); +/* ResCall void Host_SetResourceName(Plug_ResourceRef resource, ConstStr255Param name); */ /*! * @function Host_GetResourceDirty */ - ResCall Boolean Host_GetResourceDirty( Plug_ResourceRef resource ); + ResCall Boolean Host_GetResourceDirty(Plug_ResourceRef resource); /*! * @function Host_SetResourceDirty */ - ResCall void Host_SetResourceDirty( Plug_ResourceRef resource, Boolean dirty ); -/* ResCall Boolean Host_GetResourceIsOnDisk( Plug_ResourceRef resource ); */ // name may change soon + ResCall void Host_SetResourceDirty(Plug_ResourceRef resource, Boolean dirty); +/* ResCall Boolean Host_GetResourceIsOnDisk(Plug_ResourceRef resource); */ // name may change soon /*! * @function Host_GetWindowRefCon */ - ResCall UInt32 Host_GetWindowRefCon( Plug_WindowRef plugWindow ); + ResCall UInt32 Host_GetWindowRefCon(Plug_WindowRef plugWindow); /*! * @function Host_SetWindowRefCon */ - ResCall void Host_SetWindowRefCon( Plug_WindowRef plugWindow, UInt32 value ); + ResCall void Host_SetWindowRefCon(Plug_WindowRef plugWindow, UInt32 value); /*! * @function Host_GetGlobalRefCon */ - ResCall UInt32 Host_GetGlobalRefCon( Plug_PlugInRef plugRef ); + ResCall UInt32 Host_GetGlobalRefCon(Plug_PlugInRef plugRef); /*! * @function Host_SetGlobalRefCon */ - ResCall void Host_SetGlobalRefCon( Plug_PlugInRef plugRef, UInt32 value ); -/* ResCall OSStatus Host_OpenEditor( Plug_ResourceRef resource, ResOpenMode mode ); - ResCall OSStatus Host_SaveResource( Plug_ResourceRef resource ); // VERY IMPORTANT CALL! - Make when closing window - ResCall void Host_SetCursor( Plug_PlugInRef plugRef, Cursor *cursor ); - ResCall void Host_SetCursorToID( Plug_PlugInRef plugRef, SInt16 resID ); + ResCall void Host_SetGlobalRefCon(Plug_PlugInRef plugRef, UInt32 value); +/* ResCall OSStatus Host_OpenEditor(Plug_ResourceRef resource, ResOpenMode mode); + ResCall OSStatus Host_SaveResource(Plug_ResourceRef resource); // VERY IMPORTANT CALL! - Make when closing window + ResCall void Host_SetCursor(Plug_PlugInRef plugRef, Cursor *cursor); + ResCall void Host_SetCursorToID(Plug_PlugInRef plugRef, SInt16 resID); */ /*! * @function Host_GetDefaultTemplate * @abstract Returns the default TMPL resource for the resource type passed in. * @discussion Handle is NULL if no template exists. You must dispose of the handle yourself. */ - ResCall Handle Host_GetDefaultTemplate( ResType type ); + ResCall Handle Host_GetDefaultTemplate(ResType type); /*! * @function Host_AppendMenuToBar * @discussion The host will track your window, and hide the menu when you are not fromtmost. */ - ResCall void Host_AppendMenuToBar( Plug_PlugInRef plug, SInt16 resID ); + ResCall void Host_AppendMenuToBar(Plug_PlugInRef plug, SInt16 resID); /*! * @function Host_RemoveMenuFromBar */ - ResCall void Host_RemoveMenuFromBar( Plug_PlugInRef plug, SInt16 resID ); + ResCall void Host_RemoveMenuFromBar(Plug_PlugInRef plug, SInt16 resID); /*! * @function Host_UpdateMenus */ - ResCall void Host_UpdateMenus( Plug_ResourceRef resource ); + ResCall void Host_UpdateMenus(Plug_ResourceRef resource); /*! * @function Host_DisplayError * @discussion Errors the user should see */ - ResCall void Host_DisplayError( ConstStr255Param error, ConstStr255Param explanation, UInt8 severity ); + ResCall void Host_DisplayError(ConstStr255Param error, ConstStr255Param explanation, UInt8 severity); /*! * @function Host_DebugError * @discussion Errors the user shouldn't see */ - ResCall void Host_DebugError( ConstStr255Param error, OSStatus number ); + ResCall void Host_DebugError(ConstStr255Param error, OSStatus number); } /*** EXPORTED FUNCTIONS ***/ extern "C" // functions beginning "Plug_" should be in your plug-in editor { /* required functions - plug-in won't be loaded if all these symbols cannot be found */ -/* ResCallBack OSStatus Plug_EditorType( Plug_PlugInRef plugRef, EditorType *type, ResType *kind, UInt8 *number ); // called to identify the number of different types of resources it can handle +/* ResCallBack OSStatus Plug_EditorType(Plug_PlugInRef plugRef, EditorType *type, ResType *kind, UInt8 *number); // called to identify the number of different types of resources it can handle */ /*! * @function Plug_InitInstance @@ -241,14 +241,14 @@ extern "C" // functions beginning "Plug_" should be in your plug-in editor * @param plug A reference which has been assigned to this plug-in. It will not necessarily remain constant, so do not save it beyond this call returning. * @param resource A reference to the resource whose editing session has been requested. */ - ResCallBack OSStatus Plug_InitInstance( Plug_PlugInRef plug, Plug_ResourceRef resource ); -/* ResCallBack OSStatus Plug_FlattenResource( Plug_PlugInRef plugRef, Plug_ResourceRef resource ); // update the handle provided by the host (see Host_GetResData) - ResCallBack OSStatus Plug_ResourceChanged( Plug_PlugInRef plugRef, Plug_ResourceRef resource ); // another editor has changed the resource your working on (normally responded to by calling Host_GetResData and a window update) + ResCallBack OSStatus Plug_InitInstance(Plug_PlugInRef plug, Plug_ResourceRef resource); +/* ResCallBack OSStatus Plug_FlattenResource(Plug_PlugInRef plugRef, Plug_ResourceRef resource); // update the handle provided by the host (see Host_GetResData) + ResCallBack OSStatus Plug_ResourceChanged(Plug_PlugInRef plugRef, Plug_ResourceRef resource); // another editor has changed the resource your working on (normally responded to by calling Host_GetResData and a window update) */ /* optional functions - only called if they are requested & found */ -/* ResCallBack OSStatus Plug_UpdateMenu( Plug_PlugInRef plugRef, Plug_WindowRef windowObject ); - ResCallBack OSStatus Plug_HandleMenuCommand( Plug_PlugInRef plugRef, Plug_MenuCommand menuCmd, Boolean *handled ); - ResCallBack OSStatus Plug_HandleMenuItem( Plug_PlugInRef plugRef, SInt16 menuID, SInt16 itemID, Boolean *handled ); // name change - ResCallBack OSStatus Plug_AboutBox( Plug_PlugInRef plugRef ); +/* ResCallBack OSStatus Plug_UpdateMenu(Plug_PlugInRef plugRef, Plug_WindowRef windowObject); + ResCallBack OSStatus Plug_HandleMenuCommand(Plug_PlugInRef plugRef, Plug_MenuCommand menuCmd, Boolean *handled); + ResCallBack OSStatus Plug_HandleMenuItem(Plug_PlugInRef plugRef, SInt16 menuID, SInt16 itemID, Boolean *handled); // name change + ResCallBack OSStatus Plug_AboutBox(Plug_PlugInRef plugRef); */} #endif \ No newline at end of file diff --git a/Carbon/Classes/InspectorWindow.cpp b/Carbon/Classes/InspectorWindow.cpp index 3815800..22c752e 100644 --- a/Carbon/Classes/InspectorWindow.cpp +++ b/Carbon/Classes/InspectorWindow.cpp @@ -9,12 +9,12 @@ extern globals g; /*******************/ /*** CONSTRUCTOR ***/ -InspectorWindow::InspectorWindow( void ) +InspectorWindow::InspectorWindow(void) { // if inspector already exists, return - if( g.inspector ) + if(g.inspector) { - SelectWindow( g.inspector->Window() ); + SelectWindow(g.inspector->Window()); return; } @@ -22,37 +22,37 @@ InspectorWindow::InspectorWindow( void ) // create window Str255 windowName; Rect creationBounds; - SetRect( &creationBounds, 0, 0, kInspectorWindowWidth, kInspectorWindowHeight ); - OffsetRect( &creationBounds, 520, 45 ); - OSStatus error = CreateNewWindow( kFloatingWindowClass, kWindowStandardFloatingAttributes | kWindowStandardHandlerAttribute, &creationBounds, &window ); - if( !error ) + SetRect(&creationBounds, 0, 0, kInspectorWindowWidth, kInspectorWindowHeight); + OffsetRect(&creationBounds, 520, 45); + OSStatus error = CreateNewWindow(kFloatingWindowClass, kWindowStandardFloatingAttributes | kWindowStandardHandlerAttribute, &creationBounds, &window); + if(!error) { - GetIndString( windowName, kWindowNameStrings, kStringInspectorWindowName ); - SetWindowTitle( window, windowName ); - SetWindowKind( window, kInspectorWindowKind ); - SetThemeWindowBackground( window, kThemeBrushUtilityWindowBackgroundActive, false ); + GetIndString(windowName, kWindowNameStrings, kStringInspectorWindowName); + SetWindowTitle(window, windowName); + SetWindowKind(window, kInspectorWindowKind); + SetThemeWindowBackground(window, kThemeBrushUtilityWindowBackgroundActive, false); // install window event handler EventHandlerRef ref = null; - EventHandlerUPP eventHandler = NewEventHandlerUPP( CloseInspectorWindow ); + EventHandlerUPP eventHandler = NewEventHandlerUPP(CloseInspectorWindow); EventTypeSpec events[] = { { kEventClassWindow, kEventWindowClose } }; - InstallWindowEventHandler( window, eventHandler, GetEventTypeCount(events), (EventTypeSpec *) &events, this, &ref ); + InstallWindowEventHandler(window, eventHandler, GetEventTypeCount(events), (EventTypeSpec *) &events, this, &ref); // create root control Rect bounds; - if( g.systemVersion < kMacOSX ) + if(g.systemVersion < kMacOSX) { ControlRef root; - CreateRootControl( window, &root ); + CreateRootControl(window, &root); } // create image well ControlRef imageWell; ControlButtonContentInfo content; content.contentType = kControlNoContent; - SetRect( &bounds, 0, 0, 44, 44 ); - OffsetRect( &bounds, 8, 8 ); - CreateImageWellControl( window, &bounds, &content, &imageWell ); + SetRect(&bounds, 0, 0, 44, 44); + OffsetRect(&bounds, 8, 8); + CreateImageWellControl(window, &bounds, &content, &imageWell); // create static text controls Rect windowRect; @@ -61,210 +61,210 @@ InspectorWindow::InspectorWindow( void ) fontStyle.flags = kControlUseFontMask + kControlUseJustMask; fontStyle.font = kControlFontSmallSystemFont; fontStyle.just = teJustLeft; - GetWindowPortBounds( window, &windowRect ); - SetRect( &bounds, windowRect.left +60, windowRect.top +8, windowRect.right - windowRect.left -8, windowRect.top +36 ); - CreateStaticTextControl( window, &bounds, CFSTR(""), &fontStyle, &name ); + GetWindowPortBounds(window, &windowRect); + SetRect(&bounds, windowRect.left +60, windowRect.top +8, windowRect.right - windowRect.left -8, windowRect.top +36); + CreateStaticTextControl(window, &bounds, CFSTR(""), &fontStyle, &name); fontStyle.font = kControlFontSmallBoldSystemFont; - SetRect( &bounds, windowRect.left +60, windowRect.top +38, windowRect.right - windowRect.left -70, windowRect.top +52 ); - CreateStaticTextControl( window, &bounds, CFSTR(""), &fontStyle, &type ); - SetRect( &bounds, windowRect.right - windowRect.left -70, windowRect.top +38, windowRect.right - windowRect.left -8, windowRect.top +52 ); - CreateStaticTextControl( window, &bounds, CFSTR(""), &fontStyle, &id ); + SetRect(&bounds, windowRect.left +60, windowRect.top +38, windowRect.right - windowRect.left -70, windowRect.top +52); + CreateStaticTextControl(window, &bounds, CFSTR(""), &fontStyle, &type); + SetRect(&bounds, windowRect.right - windowRect.left -70, windowRect.top +38, windowRect.right - windowRect.left -8, windowRect.top +52); + CreateStaticTextControl(window, &bounds, CFSTR(""), &fontStyle, &id); // create group control ControlRef group; - GetWindowPortBounds( window, &bounds ); - InsetRect( &bounds, 8, 8 ); + GetWindowPortBounds(window, &bounds); + InsetRect(&bounds, 8, 8); bounds.top += kInspectorHeaderHeight; - CreateGroupBoxControl( window, &bounds, CFSTR("Attributes"), true, &group ); + CreateGroupBoxControl(window, &bounds, CFSTR("Attributes"), true, &group); // create checkboxes ControlRef changedBox, preloadBox, protectedBox, lockedBox, purgeableBox, sysHeapBox; - InsetRect( &bounds, 4, 4 ); + InsetRect(&bounds, 4, 4); bounds.top = bounds.bottom - kControlCheckBoxHeight; - CreateCheckBoxControl( window, &bounds, CFSTR("System Heap"), kControlCheckBoxUncheckedValue, true, &sysHeapBox ); + CreateCheckBoxControl(window, &bounds, CFSTR("System Heap"), kControlCheckBoxUncheckedValue, true, &sysHeapBox); bounds.top -= kControlCheckBoxHeight; bounds.bottom -= kControlCheckBoxHeight; - CreateCheckBoxControl( window, &bounds, CFSTR("Purgeable"), kControlCheckBoxUncheckedValue, true, &purgeableBox ); + CreateCheckBoxControl(window, &bounds, CFSTR("Purgeable"), kControlCheckBoxUncheckedValue, true, &purgeableBox); bounds.top -= kControlCheckBoxHeight; bounds.bottom -= kControlCheckBoxHeight; - CreateCheckBoxControl( window, &bounds, CFSTR("Locked"), kControlCheckBoxUncheckedValue, true, &lockedBox ); + CreateCheckBoxControl(window, &bounds, CFSTR("Locked"), kControlCheckBoxUncheckedValue, true, &lockedBox); bounds.top -= kControlCheckBoxHeight; bounds.bottom -= kControlCheckBoxHeight; - CreateCheckBoxControl( window, &bounds, CFSTR("Protected"), kControlCheckBoxUncheckedValue, true, &protectedBox ); + CreateCheckBoxControl(window, &bounds, CFSTR("Protected"), kControlCheckBoxUncheckedValue, true, &protectedBox); bounds.top -= kControlCheckBoxHeight; bounds.bottom -= kControlCheckBoxHeight; - CreateCheckBoxControl( window, &bounds, CFSTR("Preload"), kControlCheckBoxUncheckedValue, true, &preloadBox ); + CreateCheckBoxControl(window, &bounds, CFSTR("Preload"), kControlCheckBoxUncheckedValue, true, &preloadBox); bounds.top -= kControlCheckBoxHeight; bounds.bottom -= kControlCheckBoxHeight; - CreateCheckBoxControl( window, &bounds, CFSTR("Changed"), kControlCheckBoxUncheckedValue, true, &changedBox ); + CreateCheckBoxControl(window, &bounds, CFSTR("Changed"), kControlCheckBoxUncheckedValue, true, &changedBox); // embed controls - EmbedControl( changedBox, group ); - EmbedControl( preloadBox, group ); - EmbedControl( protectedBox, group ); - EmbedControl( lockedBox, group ); - EmbedControl( purgeableBox, group ); - EmbedControl( sysHeapBox, group ); + EmbedControl(changedBox, group); + EmbedControl(preloadBox, group); + EmbedControl(protectedBox, group); + EmbedControl(lockedBox, group); + EmbedControl(purgeableBox, group); + EmbedControl(sysHeapBox, group); } else window = NULL; #else - if( g.useAppearance && g.systemVersion >= kMacOS8 ) - window = GetNewCWindow( kFileWindow8, null, kFirstWindowOfClass ); + if(g.useAppearance && g.systemVersion >= kMacOS8) + window = GetNewCWindow(kFileWindow8, null, kFirstWindowOfClass); else - window = GetNewCWindow( kFileWindow7, null, kFirstWindowOfClass ); + window = GetNewCWindow(kFileWindow7, null, kFirstWindowOfClass); #endif - if( window ) + if(window) { // update and show window Update(); - ShowWindow( window ); + ShowWindow(window); g.inspector = this; } else g.inspector = NULL; } /*** DESTRUCTOR ***/ -InspectorWindow::~InspectorWindow( void ) +InspectorWindow::~InspectorWindow(void) { g.inspector = null; } /*** CLOSW WINDOW EVENT HANDLER ***/ -pascal OSStatus CloseInspectorWindow( EventHandlerCallRef callRef, EventRef event, void *userData ) +pascal OSStatus CloseInspectorWindow(EventHandlerCallRef callRef, EventRef event, void *userData) { - #pragma unused( callRef, event, userData ) - if( g.inspector ) delete g.inspector; + #pragma unused(callRef, event, userData) + if(g.inspector) delete g.inspector; return eventNotHandledErr; } /*** UPDATE WINDOW ***/ -OSStatus InspectorWindow::Update( RgnHandle region ) +OSStatus InspectorWindow::Update(RgnHandle region) { - #pragma unused( region ) + #pragma unused(region) #if TARGET_API_MAC_CARBON // get target file FileWindowPtr file = null; - WindowRef fileWindow = GetFrontWindowOfClass( kDocumentWindowClass, true ); - if( !fileWindow ) return noErr; // no window is open - BUG: items in window are not cleared + WindowRef fileWindow = GetFrontWindowOfClass(kDocumentWindowClass, true); + if(!fileWindow) return noErr; // no window is open - BUG: items in window are not cleared OSStatus error = noErr; Boolean validWindow = false; - while( !validWindow || error ) + while(!validWindow || error) { - WindowKind kind = (WindowKind) GetWindowKind( fileWindow ); - if( kind != kFileWindowKind ) + WindowKind kind = (WindowKind) GetWindowKind(fileWindow); + if(kind != kFileWindowKind) { - fileWindow = GetNextWindowOfClass( fileWindow, kDocumentWindowClass, true ); - if( !window ) error = paramErr; + fileWindow = GetNextWindowOfClass(fileWindow, kDocumentWindowClass, true); + if(!window) error = paramErr; } else { - file = (FileWindowPtr) GetWindowRefCon( fileWindow ); - if( file ) validWindow = true; + file = (FileWindowPtr) GetWindowRefCon(fileWindow); + if(file) validWindow = true; else error = paramErr; } } - if( error ) return error; + if(error) return error; // get selection UInt32 itemCount; ControlRef browser = null; - GetWindowProperty( fileWindow, kResKnifeCreator, kDataBrowserSignature, sizeof(ControlRef), null, &browser ); - GetDataBrowserItemCount( browser, kDataBrowserNoItem, true, kDataBrowserItemIsSelected, &itemCount ); + GetWindowProperty(fileWindow, kResKnifeCreator, kDataBrowserSignature, sizeof(ControlRef), null, &browser); + GetDataBrowserItemCount(browser, kDataBrowserNoItem, true, kDataBrowserItemIsSelected, &itemCount); // get controls ControlRef root, well, name, type, id, group; ControlRef changedBox, preloadBox, protectedBox, lockedBox, purgeableBox, sysHeapBox; ControlButtonContentInfo content; - GetRootControl( window, &root ); - GetIndexedSubControl( root, 1, &well ); - GetIndexedSubControl( root, 2, &name ); - GetIndexedSubControl( root, 3, &type ); - GetIndexedSubControl( root, 4, &id ); - GetIndexedSubControl( root, 5, &group ); - GetIndexedSubControl( group, 1, &changedBox ); - GetIndexedSubControl( group, 2, &preloadBox ); - GetIndexedSubControl( group, 3, &protectedBox ); - GetIndexedSubControl( group, 4, &lockedBox ); - GetIndexedSubControl( group, 5, &purgeableBox ); - GetIndexedSubControl( group, 6, &sysHeapBox ); + GetRootControl(window, &root); + GetIndexedSubControl(root, 1, &well); + GetIndexedSubControl(root, 2, &name); + GetIndexedSubControl(root, 3, &type); + GetIndexedSubControl(root, 4, &id); + GetIndexedSubControl(root, 5, &group); + GetIndexedSubControl(group, 1, &changedBox); + GetIndexedSubControl(group, 2, &preloadBox); + GetIndexedSubControl(group, 3, &protectedBox); + GetIndexedSubControl(group, 4, &lockedBox); + GetIndexedSubControl(group, 5, &purgeableBox); + GetIndexedSubControl(group, 6, &sysHeapBox); - if( itemCount != 1 ) + if(itemCount != 1) { // set icon content.contentType = kControlNoContent; - SetImageWellContentInfo( well, &content ); - DrawOneControl( well ); // bug: work around for bug in ControlManager -// DisableControl( well ); + SetImageWellContentInfo(well, &content); + DrawOneControl(well); // bug: work around for bug in ControlManager +// DisableControl(well); // set name - StringPtr blank = (StringPtr) NewPtrClear( sizeof(Str255) ); - CopyPascalStringToC( "\p", (char *) blank ); - SetControlData( name, kControlLabelPart, kControlStaticTextTextTag, 1, blank ); - SetControlTitle( name, "\p" ); + StringPtr blank = (StringPtr) NewPtrClear(sizeof(Str255)); + CopyPascalStringToC("\p", (char *) blank); + SetControlData(name, kControlLabelPart, kControlStaticTextTextTag, 1, blank); + SetControlTitle(name, "\p"); // set type - SetControlData( type, kControlLabelPart, kControlStaticTextTextTag, 1, blank ); - SetControlTitle( type, "\p" ); + SetControlData(type, kControlLabelPart, kControlStaticTextTextTag, 1, blank); + SetControlTitle(type, "\p"); // set ID - SetControlData( id, kControlLabelPart, kControlStaticTextTextTag, 1, blank ); - SetControlTitle( id, "\p" ); + SetControlData(id, kControlLabelPart, kControlStaticTextTextTag, 1, blank); + SetControlTitle(id, "\p"); // set control values - SetControlValue( changedBox, kControlCheckBoxUncheckedValue ); - SetControlValue( preloadBox, kControlCheckBoxUncheckedValue ); - SetControlValue( protectedBox, kControlCheckBoxUncheckedValue ); - SetControlValue( lockedBox, kControlCheckBoxUncheckedValue ); - SetControlValue( purgeableBox, kControlCheckBoxUncheckedValue ); - SetControlValue( sysHeapBox, kControlCheckBoxUncheckedValue ); -// DisableControl( group ); + SetControlValue(changedBox, kControlCheckBoxUncheckedValue); + SetControlValue(preloadBox, kControlCheckBoxUncheckedValue); + SetControlValue(protectedBox, kControlCheckBoxUncheckedValue); + SetControlValue(lockedBox, kControlCheckBoxUncheckedValue); + SetControlValue(purgeableBox, kControlCheckBoxUncheckedValue); + SetControlValue(sysHeapBox, kControlCheckBoxUncheckedValue); +// DisableControl(group); } else { // get selected resource DataBrowserItemID first, last; - GetDataBrowserSelectionAnchor( browser, &first, &last ); // first must == last + GetDataBrowserSelectionAnchor(browser, &first, &last); // first must == last ResourceObjectPtr resource = file->GetResource(first); // set icon content.contentType = kControlContentIconSuiteRes; content.u.resID = kDefaultResourceIcon; - SetImageWellContentInfo( well, &content ); - DrawOneControl( well ); // bug: work around for bug in ControlManager -// EnableControl( well ); + SetImageWellContentInfo(well, &content); + DrawOneControl(well); // bug: work around for bug in ControlManager +// EnableControl(well); // set name - StringPtr label = (StringPtr) NewPtrClear( sizeof(Str255) ); - if( PStringLength( resource->Name()) == 0 ) GetIndString( label, kResourceNameStrings, kStringUntitledResource ); - else CopyPascalStringToC( resource->Name(), (char *) label ); - SetControlData( name, kControlLabelPart, kControlStaticTextTextTag, PStringLength(resource->Name()), label ); - SetControlTitle( name, resource->Name() ); + StringPtr label = (StringPtr) NewPtrClear(sizeof(Str255)); + if(PStringLength(resource->Name()) == 0) GetIndString(label, kResourceNameStrings, kStringUntitledResource); + else CopyPascalStringToC(resource->Name(), (char *) label); + SetControlData(name, kControlLabelPart, kControlStaticTextTextTag, PStringLength(resource->Name()), label); + SetControlTitle(name, resource->Name()); // set type Str255 string; - TypeToPString( resource->Type(), string ); - CopyPascalStringToC( string, (char *) label ); - SetControlData( type, kControlLabelPart, kControlStaticTextTextTag, string[0], label ); - SetControlTitle( type, string ); + TypeToPString(resource->Type(), string); + CopyPascalStringToC(string, (char *) label); + SetControlData(type, kControlLabelPart, kControlStaticTextTextTag, string[0], label); + SetControlTitle(type, string); // set ID - NumToString( resource->ID(), string ); - CopyPascalStringToC( string, (char *) label ); - SetControlData( id, kControlLabelPart, kControlStaticTextTextTag, string[0], label ); - SetControlTitle( id, string ); + NumToString(resource->ID(), string); + CopyPascalStringToC(string, (char *) label); + SetControlData(id, kControlLabelPart, kControlStaticTextTextTag, string[0], label); + SetControlTitle(id, string); // set control values - SetControlValue( changedBox, (resource->Attributes() & resChanged)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue ); - SetControlValue( preloadBox, (resource->Attributes() & resPreload)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue ); - SetControlValue( protectedBox, (resource->Attributes() & resProtected)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue ); - SetControlValue( lockedBox, (resource->Attributes() & resLocked)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue ); - SetControlValue( purgeableBox, (resource->Attributes() & resPurgeable)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue ); - SetControlValue( sysHeapBox, (resource->Attributes() & resSysHeap)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue ); - DeactivateControl( changedBox ); -// EnableControl( group ); + SetControlValue(changedBox, (resource->Attributes() & resChanged)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue); + SetControlValue(preloadBox, (resource->Attributes() & resPreload)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue); + SetControlValue(protectedBox, (resource->Attributes() & resProtected)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue); + SetControlValue(lockedBox, (resource->Attributes() & resLocked)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue); + SetControlValue(purgeableBox, (resource->Attributes() & resPurgeable)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue); + SetControlValue(sysHeapBox, (resource->Attributes() & resSysHeap)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue); + DeactivateControl(changedBox); +// EnableControl(group); } return error; #else diff --git a/Carbon/Classes/InspectorWindow.h b/Carbon/Classes/InspectorWindow.h index 798cab5..3b6bb88 100644 --- a/Carbon/Classes/InspectorWindow.h +++ b/Carbon/Classes/InspectorWindow.h @@ -10,12 +10,12 @@ class InspectorWindow : WindowObject { public: - InspectorWindow( void ); - ~InspectorWindow( void ); - virtual OSStatus Update( RgnHandle region = null ); // unused parameter + InspectorWindow(void); + ~InspectorWindow(void); + virtual OSStatus Update(RgnHandle region = null); // unused parameter }; -pascal OSStatus CloseInspectorWindow( EventHandlerCallRef callRef, EventRef event, void *userData ); +pascal OSStatus CloseInspectorWindow(EventHandlerCallRef callRef, EventRef event, void *userData); // inspector window dimentions const UInt16 kInspectorHeaderHeight = 48 + 4; // 48 for huge icon diff --git a/Carbon/Classes/PickerWindow.cpp b/Carbon/Classes/PickerWindow.cpp index 13fc1a7..c0bb5d4 100644 --- a/Carbon/Classes/PickerWindow.cpp +++ b/Carbon/Classes/PickerWindow.cpp @@ -6,45 +6,45 @@ extern globals g; /*** CREATOR ***/ -PickerWindow::PickerWindow( FileWindowPtr ownerFile, ResType resType ) : PlugWindow( ownerFile ) +PickerWindow::PickerWindow(FileWindowPtr ownerFile, ResType resType) : PlugWindow(ownerFile) { OSStatus error = noErr; #if USE_NIBS // create a nib reference (only searches the application bundle) IBNibRef nibRef = null; - error = CreateNibReference( CFSTR("ResKnife"), &nibRef ); - if( error != noErr || nibRef == null ) + error = CreateNibReference(CFSTR("ResKnife"), &nibRef); + if(error != noErr || nibRef == null) { - DisplayError( "\pThe nib file reference could not be obtained." ); + DisplayError("\pThe nib file reference could not be obtained."); return; } // create window - error = CreateWindowFromNib( nibRef, CFSTR("Picker Window"), &window ); - if( error != noErr || window == null ) + error = CreateWindowFromNib(nibRef, CFSTR("Picker Window"), &window); + if(error != noErr || window == null) { - DisplayError( "\pA picker window could not be obtained from the nib file." ); + DisplayError("\pA picker window could not be obtained from the nib file."); return; } // dispose of nib ref - DisposeNibReference( nibRef ); + DisposeNibReference(nibRef); #elif TARGET_API_MAC_CARBON // create window Rect creationBounds; - SetRect( &creationBounds, 9, 45, 256 +9, 256 +45 ); - error = CreateNewWindow( kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute, &creationBounds, &window ); + SetRect(&creationBounds, 9, 45, 256 +9, 256 +45); + error = CreateNewWindow(kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute, &creationBounds, &window); #else - if( g.useAppearance && g.systemVersion >= kMacOS8 ) + if(g.useAppearance && g.systemVersion >= kMacOS8) { - window = GetNewCWindow( kFileWindow8, null, kFirstWindowOfClass ); + window = GetNewCWindow(kFileWindow8, null, kFirstWindowOfClass); themeSavvy = true; } else { - window = GetNewCWindow( kFileWindow7, null, kFirstWindowOfClass ); + window = GetNewCWindow(kFileWindow7, null, kFirstWindowOfClass); themeSavvy = false; } #endif @@ -52,22 +52,22 @@ PickerWindow::PickerWindow( FileWindowPtr ownerFile, ResType resType ) : PlugWin // set up default window title Str255 windowTitle, resTypeStr; FSSpec spec = *ownerFile->GetFileSpec(); - CopyPString( spec.name, windowTitle ); - TypeToPString( resType, resTypeStr ); - AppendPString( windowTitle, "\p: " ); - AppendPString( windowTitle, resTypeStr ); - AppendPString( windowTitle, "\p resources" ); + CopyPString(spec.name, windowTitle); + TypeToPString(resType, resTypeStr); + AppendPString(windowTitle, "\p: "); + AppendPString(windowTitle, resTypeStr); + AppendPString(windowTitle, "\p resources"); // save PickerWindow class in window's refcon - SetWindowRefCon( window, (UInt32) this ); - SetWindowKind( window, kPickerWindowKind ); - SetWindowTitle( window, windowTitle ); + SetWindowRefCon(window, (UInt32) this); + SetWindowKind(window, kPickerWindowKind); + SetWindowTitle(window, windowTitle); // set window's background to default for theme #if TARGET_API_MAC_CARBON - SetThemeWindowBackground( window, kThemeBrushDocumentWindowBackground, true ); + SetThemeWindowBackground(window, kThemeBrushDocumentWindowBackground, true); #else - if( g.useAppearance ) - SetThemeWindowBackground( window, kThemeBrushDocumentWindowBackground, false ); + if(g.useAppearance) + SetThemeWindowBackground(window, kThemeBrushDocumentWindowBackground, false); #endif } \ No newline at end of file diff --git a/Carbon/Classes/PickerWindow.h b/Carbon/Classes/PickerWindow.h index 5ad89d4..d3b752e 100644 --- a/Carbon/Classes/PickerWindow.h +++ b/Carbon/Classes/PickerWindow.h @@ -17,7 +17,7 @@ class PickerWindow : PlugWindow { public: // methods - PickerWindow( FileWindowPtr ownerFile, ResType resType ); + PickerWindow(FileWindowPtr ownerFile, ResType resType); }; #endif \ No newline at end of file diff --git a/Carbon/Classes/PlugObject.cpp b/Carbon/Classes/PlugObject.cpp index cc6b3f9..c6c7820 100644 --- a/Carbon/Classes/PlugObject.cpp +++ b/Carbon/Classes/PlugObject.cpp @@ -3,80 +3,80 @@ extern globals g; /*** LOAD EDITOR ***/ -OSStatus LoadEditor( ResourceObjectPtr resource, ConstStr63Param libName ) +OSStatus LoadEditor(ResourceObjectPtr resource, ConstStr63Param libName) { // create editor window structure and save resource to be edited into it OSStatus error = noErr; - PlugObjectPtr plug = (PlugObjectPtr) NewPtrClear( sizeof(PlugObject) ); // bug: this function calls itself, so memory leak may exist here - if( !plug ) return memFullErr; // another bug: should check if plug already has associated PlugObject (ie it is loaded already) - globalRefCon won't work + PlugObjectPtr plug = (PlugObjectPtr) NewPtrClear(sizeof(PlugObject)); // bug: this function calls itself, so memory leak may exist here + if(!plug) return memFullErr; // another bug: should check if plug already has associated PlugObject (ie it is loaded already) - globalRefCon won't work // load editor's library into memory CFragConnectionID connID = null; Ptr mainAddr = null; Str255 errMessage; - error = GetSharedLibrary( libName, kPowerPCCFragArch, kLoadCFrag, &connID, &mainAddr, errMessage ); - DebugError( errMessage ); - if( error ) + error = GetSharedLibrary(libName, kPowerPCCFragArch, kLoadCFrag, &connID, &mainAddr, errMessage); + DebugError(errMessage); + if(error) { - if( EqualString( libName, "\pHex Editor", true, true ) ) + if(EqualString(libName, "\pHex Editor", true, true)) { - DisposePtr( (Ptr) plug ); // only dispose if was created just now - DisplayError( "\pNo editors are available for this resource!", "\pI suggest you reinstall the program." ); + DisposePtr((Ptr) plug); // only dispose if was created just now + DisplayError("\pNo editors are available for this resource!", "\pI suggest you reinstall the program."); return error; } - else if( EqualString( libName, "\pTemplate Editor", true, true ) ) + else if(EqualString(libName, "\pTemplate Editor", true, true)) { - error = LoadEditor( resource, "\pHex Editor" ); + error = LoadEditor(resource, "\pHex Editor"); return error; } else { - error = LoadEditor( resource, "\pTemplate Editor" ); - if( error ) - error = LoadEditor( resource, "\pHex Editor" ); + error = LoadEditor(resource, "\pTemplate Editor"); + if(error) + error = LoadEditor(resource, "\pHex Editor"); return error; } } - plug->SetConnectionID( connID ); + plug->SetConnectionID(connID); // find and call InitInstance symbol InitPlugProcPtr symAddr; CFragSymbolClass symClass; - error = FindSymbol( connID, "\pPlug_InitInstance", (Ptr *) &symAddr, &symClass ); - if( error ) + error = FindSymbol(connID, "\pPlug_InitInstance", (Ptr *) &symAddr, &symClass); + if(error) { - DisposePtr( (Ptr) plug ); // only dispose if was created just now - if( g.debug ) DebugError( "\pPlug_InitInstance() could not be found." ); - else DisplayError( "\pCannot load up requested editor.", "\pPlease obtain an update from the plug-in's author." ); + DisposePtr((Ptr) plug); // only dispose if was created just now + if(g.debug) DebugError("\pPlug_InitInstance() could not be found."); + else DisplayError("\pCannot load up requested editor.", "\pPlease obtain an update from the plug-in's author."); return error; } - error = (* symAddr)( plug, resource ); - if( error ) + error = (* symAddr)(plug, resource); + if(error) { - DisposePtr( (Ptr) plug ); // only dispose if was created just now - DebugError( "\pPlug_InitInstance() returned an error. This is quite normal for the Template Editor, thus if no XXXX Editor exists, and no template is found, you will see this dialog, then a hex editor appear." ); + DisposePtr((Ptr) plug); // only dispose if was created just now + DebugError("\pPlug_InitInstance() returned an error. This is quite normal for the Template Editor, thus if no XXXX Editor exists, and no template is found, you will see this dialog, then a hex editor appear."); } return error; } /*** UNLOAD EDITOR ***/ -OSStatus UnloadEditor( PlugObjectPtr plug ) +OSStatus UnloadEditor(PlugObjectPtr plug) { - #pragma unused( plug ) + #pragma unused(plug) OSStatus error = noErr; CFragConnectionID connID = plug->GetConnectionID(); // find and call DisposeEditor symbol /* DisposePlugProcPtr symAddr; CFragSymbolClass symClass; - error = FindSymbol( connID, "\pPlug_DisposeEditor", (Ptr *) &symAddr, &symClass ); - if( error ) return error; - (* symAddr)( plug ); + error = FindSymbol(connID, "\pPlug_DisposeEditor", (Ptr *) &symAddr, &symClass); + if(error) return error; + (* symAddr)(plug); */ // close connection to editor - error = CloseConnection( &connID ); - plug->SetConnectionID( null ); + error = CloseConnection(&connID); + plug->SetConnectionID(null); return error; } @@ -85,11 +85,11 @@ OSStatus UnloadEditor( PlugObjectPtr plug ) /**************************/ /*** ACCESSORS ***/ -void PlugObject::SetRefCon( UInt32 value ) { refcon = value; } -UInt32 PlugObject::GetRefCon( void ) { return refcon; } -CFragConnectionID PlugObject::GetConnectionID( void ) { return connID; } -void PlugObject::SetConnectionID( CFragConnectionID newID ) { connID = newID; } -WindowObjectPtr PlugObject::GetWindowObject( void ) { return windowObj; } -void PlugObject::SetWindowObject( WindowObjectPtr newWindowObj ) { windowObj = newWindowObj; } -ResourceObjectPtr PlugObject::GetResourceObject( void ) { return resourceObj; } -void PlugObject::SetResourceObject( ResourceObjectPtr newResourceObj ) { resourceObj = newResourceObj; } \ No newline at end of file +void PlugObject::SetRefCon(UInt32 value) { refcon = value; } +UInt32 PlugObject::GetRefCon(void) { return refcon; } +CFragConnectionID PlugObject::GetConnectionID(void) { return connID; } +void PlugObject::SetConnectionID(CFragConnectionID newID) { connID = newID; } +WindowObjectPtr PlugObject::GetWindowObject(void) { return windowObj; } +void PlugObject::SetWindowObject(WindowObjectPtr newWindowObj) { windowObj = newWindowObj; } +ResourceObjectPtr PlugObject::GetResourceObject(void) { return resourceObj; } +void PlugObject::SetResourceObject(ResourceObjectPtr newResourceObj) { resourceObj = newResourceObj; } \ No newline at end of file diff --git a/Carbon/Classes/PlugObject.h b/Carbon/Classes/PlugObject.h index fbb709e..580884d 100644 --- a/Carbon/Classes/PlugObject.h +++ b/Carbon/Classes/PlugObject.h @@ -36,42 +36,42 @@ public: @function GetConnectionID @discussion Accessor function. */ - CFragConnectionID GetConnectionID( void ); + CFragConnectionID GetConnectionID(void); /*! @function SetConnectionID @discussion Accessor function. */ - void SetConnectionID( CFragConnectionID newID ); + void SetConnectionID(CFragConnectionID newID); /*! @function GetWindowObject @discussion Accessor function. */ - WindowObjectPtr GetWindowObject( void ); + WindowObjectPtr GetWindowObject(void); /*! @function SetWindowObject @discussion Accessor function. */ - void SetWindowObject( WindowObjectPtr newWindowObj ); + void SetWindowObject(WindowObjectPtr newWindowObj); /*! @function GetResourceObject @discussion Accessor function. */ - ResourceObjectPtr GetResourceObject( void ); + ResourceObjectPtr GetResourceObject(void); /*! @function SetResourceObject @discussion Accessor function. */ - void SetResourceObject( ResourceObjectPtr newResourceObj ); + void SetResourceObject(ResourceObjectPtr newResourceObj); /*! @function SetRefCon @discussion Accessor function. */ - void SetRefCon( UInt32 value ); + void SetRefCon(UInt32 value); /*! @function GetRefCon @discussion Accessor function. */ - UInt32 GetRefCon( void ); + UInt32 GetRefCon(void); } PlugObject, *PlugObjectPtr; /*! @@ -80,18 +80,18 @@ public: @param resource The resource to be edited. @param libName A string containing the fragment name of the editor to be used, for example "icns Editor" or "PICT Picker". */ -OSStatus LoadEditor( ResourceObjectPtr resource, ConstStr63Param libName ); +OSStatus LoadEditor(ResourceObjectPtr resource, ConstStr63Param libName); /*! @function UnloadEditor @discussion Unloads the given plug. @param plug The plug-in to be killed. */ -OSStatus UnloadEditor( PlugObjectPtr plug ); +OSStatus UnloadEditor(PlugObjectPtr plug); /*! @typedef InitPlugProcPtr @discussion The pointer to Plug_InitInstance() that FindSymbol returns. */ -typedef OSStatus (* InitPlugProcPtr)( PlugObjectPtr plug, ResourceObjectPtr resource ); +typedef OSStatus (* InitPlugProcPtr)(PlugObjectPtr plug, ResourceObjectPtr resource); #endif \ No newline at end of file diff --git a/Carbon/Classes/PlugWindow.cpp b/Carbon/Classes/PlugWindow.cpp index 0fc4b55..f98a34c 100644 --- a/Carbon/Classes/PlugWindow.cpp +++ b/Carbon/Classes/PlugWindow.cpp @@ -8,14 +8,14 @@ extern globals g; /*********************/ /*** CREATOR ***/ -PlugWindow::PlugWindow( FileWindowPtr ownerFile ) +PlugWindow::PlugWindow(FileWindowPtr ownerFile) { - memset( this, 0, sizeof(PlugWindow) ); + memset(this, 0, sizeof(PlugWindow)); file = ownerFile; } /*** GET FILE WINDOW ***/ -FileWindowPtr PlugWindow::File( void ) +FileWindowPtr PlugWindow::File(void) { return file; } @@ -23,13 +23,13 @@ FileWindowPtr PlugWindow::File( void ) #if !TARGET_API_MAC_CARBON /*** INSTALL CLASSIC EVENT HANDLER ***/ -void PlugWindow::InstallClassicEventHandler( ClassicEventHandlerProcPtr newHandler ) +void PlugWindow::InstallClassicEventHandler(ClassicEventHandlerProcPtr newHandler) { handler = newHandler; } /*** UPDATE WINDOW ***/ -OSStatus PlugWindow::Update( RgnHandle region ) +OSStatus PlugWindow::Update(RgnHandle region) { EventRecord event; event.what = updateEvt; @@ -38,12 +38,12 @@ OSStatus PlugWindow::Update( RgnHandle region ) event.where = NewPoint(); event.modifiers = null; - OSStatus error = (* handler)( &event, kEventWindowUpdate, null ); + OSStatus error = (* handler)(&event, kEventWindowUpdate, null); return error; } /*** ACTIVATE WINDOW ***/ -OSStatus PlugWindow::Activate( Boolean active ) +OSStatus PlugWindow::Activate(Boolean active) { EventRecord event; event.what = activateEvt; @@ -52,12 +52,12 @@ OSStatus PlugWindow::Activate( Boolean active ) event.where = NewPoint(); event.modifiers = null; - OSStatus error = (* handler)( &event, active? kEventWindowActivated:kEventWindowDeactivated, null ); + OSStatus error = (* handler)(&event, active? kEventWindowActivated:kEventWindowDeactivated, null); return error; } /*** CLOSE WINDOW ***/ -OSStatus PlugWindow::Close( void ) +OSStatus PlugWindow::Close(void) { EventRecord event; event.what = mouseUp; @@ -66,12 +66,12 @@ OSStatus PlugWindow::Close( void ) event.where = NewPoint(); event.modifiers = null; - OSStatus error = (* handler)( &event, kEventWindowClose, null ); + OSStatus error = (* handler)(&event, kEventWindowClose, null); return error; } /*** HANDLE CLICK IN WINDOW ***/ -OSStatus PlugWindow::Click( Point mouse, EventModifiers modifiers ) +OSStatus PlugWindow::Click(Point mouse, EventModifiers modifiers) { EventRecord event; event.what = mouseDown; @@ -80,12 +80,12 @@ OSStatus PlugWindow::Click( Point mouse, EventModifiers modifiers ) event.where = mouse; event.modifiers = modifiers; - OSStatus error = (* handler)( &event, kEventWindowClickContentRgn, null ); + OSStatus error = (* handler)(&event, kEventWindowClickContentRgn, null); return error; } #endif /*** ACCESSORS ***/ -void PlugWindow::SetRefCon( UInt32 value ) { refcon = value; } -UInt32 PlugWindow::GetRefCon( void ) { return refcon; } +void PlugWindow::SetRefCon(UInt32 value) { refcon = value; } +UInt32 PlugWindow::GetRefCon(void) { return refcon; } diff --git a/Carbon/Classes/PlugWindow.h b/Carbon/Classes/PlugWindow.h index fb464df..d8567ce 100644 --- a/Carbon/Classes/PlugWindow.h +++ b/Carbon/Classes/PlugWindow.h @@ -44,35 +44,35 @@ public: /*! * @function PlugWindow */ - PlugWindow( FileWindowPtr ownerFile ); + PlugWindow(FileWindowPtr ownerFile); /*! * @function File */ - FileWindowPtr File( void ); + FileWindowPtr File(void); #if !TARGET_API_MAC_CARBON /*! * @function InstallClassicEventHandler */ - void InstallClassicEventHandler( ClassicEventHandlerProcPtr newHandler ); + void InstallClassicEventHandler(ClassicEventHandlerProcPtr newHandler); /*! * @function Close */ - virtual OSStatus Close( void ); + virtual OSStatus Close(void); /*! * @function Activate */ - virtual OSStatus Activate( Boolean active = true ); + virtual OSStatus Activate(Boolean active = true); /*! * @function Update */ - virtual OSStatus Update( RgnHandle region = null ); + virtual OSStatus Update(RgnHandle region = null); /*! * @function Click */ - virtual OSStatus Click( Point mouse, EventModifiers modifiers ); + virtual OSStatus Click(Point mouse, EventModifiers modifiers); #endif - void SetRefCon( UInt32 value ); - UInt32 GetRefCon( void ); + void SetRefCon(UInt32 value); + UInt32 GetRefCon(void); }; #endif diff --git a/Carbon/Classes/ResourceObject.cpp b/Carbon/Classes/ResourceObject.cpp index 29e381b..94fd515 100644 --- a/Carbon/Classes/ResourceObject.cpp +++ b/Carbon/Classes/ResourceObject.cpp @@ -3,57 +3,57 @@ #include "string.h" /*** CREATOR ***/ -ResourceObject::ResourceObject( FileWindowPtr owner ) +ResourceObject::ResourceObject(FileWindowPtr owner) { // set contents to zero - memset( this, 0, sizeof(ResourceObject) ); + memset(this, 0, sizeof(ResourceObject)); file = owner; nameIconRgn = NewRgn(); } /*** DESTRUCTOR ***/ -ResourceObject::~ResourceObject( void ) +ResourceObject::~ResourceObject(void) { - if( nameIconRgn ) DisposeRgn( nameIconRgn ); - if( data ) DisposeHandle( data ); + if(nameIconRgn) DisposeRgn(nameIconRgn); + if(data) DisposeHandle(data); } /*** RETAIN ***/ -OSStatus ResourceObject::Retain( void ) +OSStatus ResourceObject::Retain(void) { OSStatus error = noErr; -/* if( retainCount == 0 ) +/* if(retainCount == 0) { - if( dataFork ) + if(dataFork) { // open file for reading SInt16 refNum; - error = FSpOpenDF( file->GetFileSpec(), fsRdPerm, &refNum ); - if( error ) + error = FSpOpenDF(file->GetFileSpec(), fsRdPerm, &refNum); + if(error) { - DisplayError( "\pData fork could not be read", "\pThis file appears to be corrupted. Although the resources could be read in correctly, the data fork could not be found. Please run Disk First Aid to correct the problem." ); + DisplayError("\pData fork could not be read", "\pThis file appears to be corrupted. Although the resources could be read in correctly, the data fork could not be found. Please run Disk First Aid to correct the problem."); return error; } // get new handle - data = NewHandleClear( size ); - if( !data || MemError() ) + data = NewHandleClear(size); + if(!data || MemError()) { - DisplayError( "\pNot enough memory to read data fork", "\pPlease quit other applications and try again." ); - FSClose( refNum ); + DisplayError("\pNot enough memory to read data fork", "\pPlease quit other applications and try again."); + FSClose(refNum); return memFullErr; } // read data fork - HLock( data ); - error = FSRead( refNum, (long *) &size, *data ); - HUnlock( data ); - FSClose( refNum ); + HLock(data); + error = FSRead(refNum, (long *) &size, *data); + HUnlock(data); + FSClose(refNum); } else { - LoadResource( data ); + LoadResource(data); } } */ retainCount++; @@ -61,40 +61,40 @@ OSStatus ResourceObject::Retain( void ) } /*** RELEASE ***/ -void ResourceObject::Release( void ) +void ResourceObject::Release(void) { - if( retainCount > 0 ) + if(retainCount > 0) { -/* if( retainCount == 1 ) - DisposeHandle( data ); +/* if(retainCount == 1) + DisposeHandle(data); */ retainCount--; } } /*** SET RESOURCE DIRTY ***/ -void ResourceObject::SetDirty( Boolean value ) +void ResourceObject::SetDirty(Boolean value) { dirty = value; - file->SetFileDirty( value ); + file->SetFileDirty(value); // being here indicates the resource size parameter also needs updating - size = GetHandleSize( data ); + size = GetHandleSize(data); // bug: should now tell all open copies of this resource to update themselves } /*** RES INFO RECORD ACCESSORS ***/ -FileWindowPtr ResourceObject::File( void ) { return file; } -ResourceObjectPtr ResourceObject::Next( void ) { return next; } -Boolean ResourceObject::Dirty( void ) { return dirty; } -void ResourceObject::Select( Boolean select ) { selected = select; } -Boolean ResourceObject::Selected( void ) { return selected; } -DataBrowserItemID ResourceObject::Number( void ) { return number; } -Boolean ResourceObject::RepresentsDataFork( void ) { return dataFork; } +FileWindowPtr ResourceObject::File(void) { return file; } +ResourceObjectPtr ResourceObject::Next(void) { return next; } +Boolean ResourceObject::Dirty(void) { return dirty; } +void ResourceObject::Select(Boolean select) { selected = select; } +Boolean ResourceObject::Selected(void) { return selected; } +DataBrowserItemID ResourceObject::Number(void) { return number; } +Boolean ResourceObject::RepresentsDataFork(void) { return dataFork; } -Handle ResourceObject::Data( void ) { return data; } -UInt8* ResourceObject::Name( void ) { return name; } -UInt32 ResourceObject::Size( void ) { return size; } -ResType ResourceObject::Type( void ) { return type; } -SInt16 ResourceObject::ID( void ) { return resID; } -SInt16 ResourceObject::Attributes( void ) { return attribs; } \ No newline at end of file +Handle ResourceObject::Data(void) { return data; } +UInt8* ResourceObject::Name(void) { return name; } +UInt32 ResourceObject::Size(void) { return size; } +ResType ResourceObject::Type(void) { return type; } +SInt16 ResourceObject::ID(void) { return resID; } +SInt16 ResourceObject::Attributes(void) { return attribs; } \ No newline at end of file diff --git a/Carbon/Classes/ResourceObject.h b/Carbon/Classes/ResourceObject.h index 9dcea9f..04cdaac 100644 --- a/Carbon/Classes/ResourceObject.h +++ b/Carbon/Classes/ResourceObject.h @@ -57,103 +57,103 @@ public: @function ResourceObject @discussion Creator function. */ - ResourceObject( FileWindowPtr owner = null ); + ResourceObject(FileWindowPtr owner = null); /*! @function ~ResourceObject @discussion Destructor function. */ - ~ResourceObject( void ); + ~ResourceObject(void); /*! @function Retain @discussion Accessor function. */ - OSStatus Retain( void ); + OSStatus Retain(void); /*! @function Release @discussion Accessor function. */ - void Release( void ); + void Release(void); /*! @function File @discussion Accessor function. */ - FileWindowPtr File( void ); + FileWindowPtr File(void); /*! @function Next @discussion Accessor function. */ - ResourceObjectPtr Next( void ); + ResourceObjectPtr Next(void); /*! @function SetDirty @discussion Accessor function. */ - void SetDirty( Boolean value ); + void SetDirty(Boolean value); /*! @function Dirty @discussion Accessor function. */ - Boolean Dirty( void ); + Boolean Dirty(void); /*! @function Select @discussion Accessor function. @param select Pass true to select, false to deselect this resource in the file window. */ - void Select( Boolean select ); + void Select(Boolean select); /*! @function Selected @discussion Accessor function. */ - Boolean Selected( void ); + Boolean Selected(void); /*! @function Number @discussion Accessor function. */ - DataBrowserItemID Number( void ); + DataBrowserItemID Number(void); /*! @function RepresentsDataFork @discussion Accessor function. */ - Boolean RepresentsDataFork( void ); + Boolean RepresentsDataFork(void); /*! @function Data @discussion Accessor function. Warning: This functions returns the ACTUAL data handle - do not dispose of it. */ - Handle Data( void ); + Handle Data(void); /*! @function Name @discussion Accessor function. */ - UInt8* Name( void ); + UInt8* Name(void); /*! @function Size @discussion Accessor function. */ - UInt32 Size( void ); + UInt32 Size(void); /*! @function Type @discussion Accessor function. */ - ResType Type( void ); + ResType Type(void); /*! @function ID @discussion Accessor function. */ - SInt16 ID( void ); + SInt16 ID(void); /*! @function Attributes @discussion Accessor function. */ - SInt16 Attributes( void ); + SInt16 Attributes(void); - friend OSStatus FileWindow::ReadResourceMap( void ); - friend OSStatus FileWindow::ReadDataFork( OSStatus RFError ); - friend OSStatus FileWindow::InitDataBrowser( void ); + friend OSStatus FileWindow::ReadResourceMap(void); + friend OSStatus FileWindow::ReadDataFork(OSStatus RFError); + friend OSStatus FileWindow::InitDataBrowser(void); #if !TARGET_API_MAC_CARBON - friend OSStatus FileWindow::Click( Point mouse, EventModifiers modifiers ); - friend OSStatus FileWindow::DrawResourceIcon( ResourceObjectPtr resource, UInt16 line ); + friend OSStatus FileWindow::Click(Point mouse, EventModifiers modifiers); + friend OSStatus FileWindow::DrawResourceIcon(ResourceObjectPtr resource, UInt16 line); #endif - friend OSStatus FileWindow::CreateNewResource( ConstStr255Param name, ResType type, SInt16 resID, SInt16 attribs ); - friend OSStatus FileWindow::DisposeResourceMap( void ); + friend OSStatus FileWindow::CreateNewResource(ConstStr255Param name, ResType type, SInt16 resID, SInt16 attribs); + friend OSStatus FileWindow::DisposeResourceMap(void); }; #endif \ No newline at end of file diff --git a/Carbon/Classes/Utility.cpp b/Carbon/Classes/Utility.cpp index fdd168b..100a34c 100644 --- a/Carbon/Classes/Utility.cpp +++ b/Carbon/Classes/Utility.cpp @@ -1,18 +1,45 @@ #include "Utility.h" -extern globals g; /**********************/ /* QUICKDRAW ROUTINES */ /**********************/ /*** SET COLOUR ***/ -void SetColour( RGBColor *colour, UInt16 red, UInt16 green, UInt16 blue ) +void SetColour(RGBColor *colour, UInt16 red, UInt16 green, UInt16 blue) { colour->red = red; colour->green = green; colour->blue = blue; } +/*** MAKE LOCAL ***/ +void MakeLocal( WindowRef window, Point globalPoint, Point *localPoint ) +{ + GrafPtr oldPort; + GetPort( &oldPort ); + SetPortWindowPort( window ); + + localPoint->h = globalPoint.h; + localPoint->v = globalPoint.v; + GlobalToLocal( localPoint ); + + SetPort( oldPort ); +} + +/*** MAKE GLOBAL ***/ +void MakeGlobal( WindowRef window, Point localPoint, Point *globalPoint ) +{ + GrafPtr oldPort; + GetPort( &oldPort ); + SetPortWindowPort( window ); + + globalPoint->h = localPoint.h; + globalPoint->v = localPoint.v; + LocalToGlobal( globalPoint ); + + SetPort( oldPort ); +} + /* investigate the call ShieldCursor() - it hides the mouse when it enters a certain rect */ /*******************/ @@ -20,91 +47,91 @@ void SetColour( RGBColor *colour, UInt16 red, UInt16 green, UInt16 blue ) /*******************/ /*** C STRING LENGTH ***/ -unsigned long CStringLength( char *string ) +unsigned long CStringLength(char *string) { unsigned long length; Boolean end = false; - for( length = 0; end == false; length++ ) - if( *(string + length) == 0x00 ) end = true; + for(length = 0; end == false; length++) + if(*(string + length) == 0x00) end = true; return length; } /*** PASCAL STRING LENGTH ***/ -unsigned char PStringLength( unsigned char *string ) +unsigned char PStringLength(unsigned char *string) { return *string; } /*** TYPE TO C STRING ***/ -void TypeToCString( const OSType type, char *string ) +void TypeToCString(const OSType type, char *string) { - BlockMoveData( &type, &string[0], sizeof(OSType) ); + BlockMoveData(&type, &string[0], sizeof(OSType)); string[sizeof(OSType)] = 0x00; } /*** TYPE TO PASCAL STRING ***/ -void TypeToPString( const OSType type, Str255 string ) +void TypeToPString(const OSType type, Str255 string) { string[0] = sizeof(OSType); - BlockMoveData( &type, &string[1], sizeof(OSType) ); + BlockMoveData(&type, &string[1], sizeof(OSType)); } /*** TYPE TO CORE FOUNDATION STRING ***/ -void TypeToCFString( const OSType type, CFStringRef *string ) +void TypeToCFString(const OSType type, CFStringRef *string) { char cString[5]; - TypeToCString( type, (char *) &cString ); - *string = CFStringCreateWithCString( CFAllocatorGetDefault(), (char *) &cString, kCFStringEncodingMacRoman ); + TypeToCString(type, (char *) &cString); + *string = CFStringCreateWithCString(CFAllocatorGetDefault(), (char *) &cString, kCFStringEncodingMacRoman); } /*** COPY C STRING ***/ -void CopyCString( const UInt8 *source, UInt8 *dest ) +void CopyCString(const UInt8 *source, UInt8 *dest) { //#pragma warning off - while( *dest++ = *source++ ); + while(*dest++ = *source++); //#pragma warning reset } /*** COPY PASCAL STRING ***/ -void CopyPString( const UInt8 *source, UInt8 *dest ) +void CopyPString(const UInt8 *source, UInt8 *dest) { UInt8 length = *source, count; - for( count = 0; count <= length; count++ ) + for(count = 0; count <= length; count++) *dest++ = *source++; } /*** EQUAL C STRINGS ***/ -Boolean EqualCStrings( UInt8 *source, UInt8 *dest ) +Boolean EqualCStrings(UInt8 *source, UInt8 *dest) { - while( *source != 0x00 ) - if( *source++ != *dest++ ) return false; + while(*source != 0x00) + if(*source++ != *dest++) return false; return true; } /*** EQUAL PASCAL STRINGS ***/ -Boolean EqualPStrings( UInt8 *source, UInt8 *dest ) +Boolean EqualPStrings(UInt8 *source, UInt8 *dest) { UInt8 length = *source, count; - for( count = 0; count <= length; count++ ) - if( *source++ != *dest++ ) return false; + for(count = 0; count <= length; count++) + if(*source++ != *dest++) return false; return true; } /*** APPEND ONE PASCAL STRING ONTO ANOTHER ***/ -void AppendPString( Str255 original, ConstStr255Param added ) +void AppendPString(Str255 original, ConstStr255Param added) { short numberBytes = added[0]; // length of string to be added short totalLength = added[0] + original[0]; - if( totalLength > 255 ) // too long, adjust number of bytes to add + if(totalLength > 255) // too long, adjust number of bytes to add { totalLength = 255; numberBytes = totalLength - original[0]; } - BlockMoveData( &added[1], &original[totalLength-numberBytes + 1], numberBytes ); + BlockMoveData(&added[1], &original[totalLength-numberBytes + 1], numberBytes); original[0] = totalLength; // new length of original string - while( ++totalLength <= 255 ) + while(++totalLength <= 255) original[totalLength] = 0x00; // set rest of string to zero } @@ -113,29 +140,29 @@ void AppendPString( Str255 original, ConstStr255Param added ) /*****************/ /*** MENU ITEM ENABLE ***/ -void MenuItemEnable( MenuRef menu, MenuItemIndex item, Boolean enable ) +void MenuItemEnable(MenuRef menu, MenuItemIndex item, Boolean enable) { #if !TARGET_API_MAC_CARBON - if( g.systemVersion >= kMacOS85 ) + if(g.systemVersion >= kMacOS85) { #endif - if( enable ) EnableMenuItem( menu, item ); - else DisableMenuItem( menu, item ); + if(enable) EnableMenuItem(menu, item); + else DisableMenuItem(menu, item); #if !TARGET_API_MAC_CARBON } else { - if( enable ) EnableItem( menu, item ); - else DisableItem( menu, item ); + if(enable) EnableItem(menu, item); + else DisableItem(menu, item); } #endif } /*** ENABLE MENU COMMAND ***/ -void EnableCommand( MenuRef menu, MenuCommand command, Boolean enable ) +void EnableCommand(MenuRef menu, MenuCommand command, Boolean enable) { - if( enable ) EnableMenuCommand( menu, command ); - else DisableMenuCommand( menu, command ); + if(enable) EnableMenuCommand(menu, command); + else DisableMenuCommand(menu, command); } /******************/ @@ -151,53 +178,53 @@ OSErr MakeRelativeAliasFile(FSSpec *targetFile, FSSpec *aliasDest) { OSErr error; FInfo fndrInfo; - AliasHandle theAlias = null; + AliasHandle theAlias = NULL; Boolean fileCreated = false; SInt16 rsrc = -1; // set up our the alias' file information - error = FSpGetFInfo( targetFile, &fndrInfo ); - if( error != noErr ) goto bail; - if( fndrInfo.fdType == 'APPL') + error = FSpGetFInfo(targetFile, &fndrInfo); + if(error != noErr) goto bail; + if(fndrInfo.fdType == 'APPL') fndrInfo.fdType = kApplicationAliasType; fndrInfo.fdFlags = kIsAlias; // implicitly clear the inited bit // create the new file - FSpCreateResFile( aliasDest, 'TEMP', 'TEMP', smSystemScript ); - if( (error = ResError() ) != noErr) goto bail; + FSpCreateResFile(aliasDest, 'TEMP', 'TEMP', smSystemScript); + if((error = ResError()) != noErr) goto bail; fileCreated = true; // set the file information or the new file - error = FSpSetFInfo( aliasDest, &fndrInfo ); - if( error != noErr ) goto bail; + error = FSpSetFInfo(aliasDest, &fndrInfo); + if(error != noErr) goto bail; // create the alias record, relative to the new alias file - error = NewAlias( aliasDest, targetFile, &theAlias ); - if( error != noErr ) goto bail; + error = NewAlias(aliasDest, targetFile, &theAlias); + if(error != noErr) goto bail; // save the resource - rsrc = FSpOpenResFile( aliasDest, fsRdWrPerm ); - if( rsrc == -1) + rsrc = FSpOpenResFile(aliasDest, fsRdWrPerm); + if(rsrc == -1) { error = ResError(); goto bail; } - UseResFile( rsrc ); - AddResource( (Handle) theAlias, rAliasType, 0, aliasDest->name ); + UseResFile(rsrc); + AddResource((Handle) theAlias, rAliasType, 0, aliasDest->name); error = ResError(); - if( error != noErr) goto bail; - theAlias = null; - CloseResFile( rsrc ); + if(error != noErr) goto bail; + theAlias = NULL; + CloseResFile(rsrc); rsrc = -1; error = ResError(); - if( error != noErr) goto bail; + if(error != noErr) goto bail; // done return noErr; bail: - if( rsrc != -1 ) CloseResFile( rsrc ); - if( fileCreated ) FSpDelete( aliasDest ); - if( theAlias != null ) DisposeHandle( (Handle) theAlias ); + if(rsrc != -1) CloseResFile(rsrc); + if(fileCreated) FSpDelete(aliasDest); + if(theAlias != NULL) DisposeHandle((Handle) theAlias); return error; } @@ -206,15 +233,15 @@ bail: /**********************/ /*** LAUNCH WEB BROWSER ***/ -OSStatus LaunchURL( char *url ) +OSStatus LaunchURL(char *url) { OSStatus error = noErr; ICInstance instance; - error = ICStart( &instance, kResKnifeCreator ); - if( error != noErr ) return error; + error = ICStart(&instance, 'rsrc'); + if(error != noErr) return error; - SInt32 start = 0, length = CStringLength( url ); - error = ICLaunchURL( instance, null, url, length, &start, &length ); - ICStop( instance ); + SInt32 start = 0, length = CStringLength(url); + error = ICLaunchURL(instance, NULL, url, length, &start, &length); + ICStop(instance); return error; } \ No newline at end of file diff --git a/Carbon/Classes/Utility.h b/Carbon/Classes/Utility.h index 0bb8a00..beb3c37 100644 --- a/Carbon/Classes/Utility.h +++ b/Carbon/Classes/Utility.h @@ -1,4 +1,10 @@ -#include "ResKnife.h" +#if !TARGET_API_MAC_OS8 + #if defined(__APPLE_CC__) // compiling with gcc + #include + #else // compiling with CodeWarrior, __MWERKS__ + #include + #endif +#endif #ifndef _ResKnife_Utility_ #define _ResKnife_Utility_ @@ -11,55 +17,63 @@ /*! @function SetColour */ -void SetColour( RGBColor *colour, UInt16 red, UInt16 green, UInt16 blue ); +void SetColour(RGBColor *colour, UInt16 red, UInt16 green, UInt16 blue); +/*! + @function MakeLocal +*/ +void MakeLocal( WindowRef window, Point globalPoint, Point *localPoint ); +/*! + @function MakeGlobal +*/ +void MakeGlobal( WindowRef window, Point localPoint, Point *globalPoint ); /*! @function CStringLength */ -unsigned long CStringLength( char *string ); +unsigned long CStringLength(char *string); /*! @function PStringLength */ -unsigned char PStringLength( unsigned char *string ); +unsigned char PStringLength(unsigned char *string); /*! @function TypeToCString */ -void TypeToCString( const OSType type, char *string ); +void TypeToCString(const OSType type, char *string); /*! @function TypeToPString */ -void TypeToPString( const OSType type, Str255 string ); +void TypeToPString(const OSType type, Str255 string); /*! @function TypeToCFString */ -void TypeToCFString( const OSType type, CFStringRef *string ); +void TypeToCFString(const OSType type, CFStringRef *string); /*! @function CopyCString */ -void CopyCString( const UInt8 *source, UInt8 *dest ); +void CopyCString(const UInt8 *source, UInt8 *dest); /*! @function CopyPString */ -void CopyPString( const UInt8 *source, UInt8 *dest ); +void CopyPString(const UInt8 *source, UInt8 *dest); /*! @function EqualCStrings */ -Boolean EqualCStrings( UInt8 *source, UInt8 *dest ); +Boolean EqualCStrings(UInt8 *source, UInt8 *dest); /*! @function EqualPStrings */ -Boolean EqualPStrings( UInt8 *source, UInt8 *dest ); +Boolean EqualPStrings(UInt8 *source, UInt8 *dest); /*! @function AppendPString */ -void AppendPString( Str255 original, ConstStr255Param added ); +void AppendPString(Str255 original, ConstStr255Param added); /*! @function MenuItemEnable */ -void MenuItemEnable( MenuRef menu, MenuItemIndex item, Boolean enable ); +void MenuItemEnable(MenuRef menu, MenuItemIndex item, Boolean enable); /*! @function EnableCommand */ -void EnableCommand( MenuRef menu, MenuCommand command, Boolean enable ); +void EnableCommand(MenuRef menu, MenuCommand command, Boolean enable); /*! @function MakeRelativeAliasFile */ @@ -68,6 +82,6 @@ OSErr MakeRelativeAliasFile(FSSpec *targetFile, FSSpec *aliasDest); @function LaunchURL @param url A C string containing the address to which you want the user to go. You must include 'http://' if necessary, and all addresses to a directory should have a trailing slash. */ -OSStatus LaunchURL( char *url ); +OSStatus LaunchURL(char *url); #endif \ No newline at end of file diff --git a/Carbon/Classes/WindowObject.cpp b/Carbon/Classes/WindowObject.cpp index b5bb246..a5dd724 100644 --- a/Carbon/Classes/WindowObject.cpp +++ b/Carbon/Classes/WindowObject.cpp @@ -3,74 +3,74 @@ /*** CONSTRUCTOR ***/ -WindowObject::WindowObject( void ) +WindowObject::WindowObject(void) { - memset( this, 0, sizeof(WindowObject) ); + memset(this, 0, sizeof(WindowObject)); } /*** DESTRUCTOR ***/ -WindowObject::~WindowObject( void ) +WindowObject::~WindowObject(void) { - if( window ) + if(window) { - HideWindow( window ); - DisposeWindow( window ); + HideWindow(window); + DisposeWindow(window); } } /*** WINDOW ACCESSOR ***/ -WindowRef WindowObject::Window( void ) +WindowRef WindowObject::Window(void) { return window; } /*** WINDOW BOUNDS ARE CHANGING ***/ -OSStatus WindowObject::BoundsChanging( EventRef event ) +OSStatus WindowObject::BoundsChanging(EventRef event) { - #pragma unused( event ) + #pragma unused(event) return eventNotHandledErr; } /*** WINDOW BOUNDS HAVE CHANGED ***/ -OSStatus WindowObject::BoundsChanged( EventRef event ) +OSStatus WindowObject::BoundsChanged(EventRef event) { - #pragma unused( event ) + #pragma unused(event) return eventNotHandledErr; } #if !TARGET_API_MAC_CARBON /*** CLOSE ***/ -OSStatus WindowObject::Close( void ) +OSStatus WindowObject::Close(void) { delete this; return noErr; } /*** ACTIVATE ***/ -OSStatus WindowObject::Activate( Boolean active ) +OSStatus WindowObject::Activate(Boolean active) { - #pragma unused( active ) + #pragma unused(active) return eventNotHandledErr; } /*** UPDATE ***/ -OSStatus WindowObject::Update( RgnHandle region ) +OSStatus WindowObject::Update(RgnHandle region) { - #pragma unused( region ) + #pragma unused(region) return eventNotHandledErr; } /*** UPDATE SCROLL BARS ***/ -OSStatus WindowObject::UpdateScrollBars( void ) +OSStatus WindowObject::UpdateScrollBars(void) { return eventNotHandledErr; } /*** MOUSE CLICK ***/ -OSStatus WindowObject::Click( Point mouse, EventModifiers modifiers ) +OSStatus WindowObject::Click(Point mouse, EventModifiers modifiers) { - #pragma unused( mouse, modifiers ) + #pragma unused(mouse, modifiers) return eventNotHandledErr; } diff --git a/Carbon/Classes/WindowObject.h b/Carbon/Classes/WindowObject.h index 18d98d2..b42eeae 100644 --- a/Carbon/Classes/WindowObject.h +++ b/Carbon/Classes/WindowObject.h @@ -40,46 +40,46 @@ public: * @function WindowObject * @discussion Constructor function. */ - WindowObject( void ); + WindowObject(void); /*! * @function WindowObject * @discussion Desturctor function. */ - virtual ~WindowObject( void ); + virtual ~WindowObject(void); /*! * @function Window * @discussion Accessor for the object’s WindowRef. */ - virtual WindowRef Window( void ); + virtual WindowRef Window(void); /*! * @function BoundsChanging */ - virtual OSStatus BoundsChanging( EventRef event ); + virtual OSStatus BoundsChanging(EventRef event); /*! * @function BoundsChanged */ - virtual OSStatus BoundsChanged( EventRef event ); + virtual OSStatus BoundsChanged(EventRef event); #if !TARGET_API_MAC_CARBON /*! * @function Close */ - virtual OSStatus Close( void ); + virtual OSStatus Close(void); /*! * @function Activate */ - virtual OSStatus Activate( Boolean active = true ); + virtual OSStatus Activate(Boolean active = true); /*! * @function Update */ - virtual OSStatus Update( RgnHandle region = null ); + virtual OSStatus Update(RgnHandle region = null); /*! * @function UpdateScrollBars */ - virtual OSStatus UpdateScrollBars( void ); + virtual OSStatus UpdateScrollBars(void); /*! * @function Click */ - virtual OSStatus Click( Point mouse, EventModifiers modifiers ); + virtual OSStatus Click(Point mouse, EventModifiers modifiers); #endif }; diff --git a/Carbon/Generic.h b/Carbon/Generic.h index bc46fdc..229bdcc 100644 --- a/Carbon/Generic.h +++ b/Carbon/Generic.h @@ -1,27 +1,38 @@ // abbreviations -#define null NULL +#define null NULL #if TARGET_API_MAC_CARBON - #define qdb ScreenBounds() + #define qdb ScreenBounds() inline Rect ScreenBounds() { Rect rect; - GetAvailableWindowPositioningBounds( GetMainDevice(), &rect ); + GetAvailableWindowPositioningBounds(GetMainDevice(), &rect); return rect; } #else - #define qdb qd.screenBits.bounds + #define qdb qd.screenBits.bounds #endif +// Easier constants +#define RGBColour RGBColor + // Easier API call names -#define GetWindowRefCon( window ) (long) GetWRefCon( window ) -#define SetWindowRefCon( window, refcon ) SetWRefCon( window, refcon ) -#define GetWindowTitle( window, string ) GetWTitle( window, string ) -#define SetWindowTitle( window, name ) SetWTitle( window, name ) -#define InvalidateRect( bounds ) InvalRect( bounds ) -#define InvalidateWindowRect( window, bounds ) (OSStatus) InvalWindowRect( window, bounds ) -#define RectToRegion( region, rect ) RectRgn( region, rect ) -#define NewPoint() (Point) { 0, 0 } -#define SetPoint( point, x, y ) SetPt( point, x, y ) -#define HighlightColour( colour ) HiliteColor( colour ) -#define GetPortHighlightColour( window, colour ) GetPortHiliteColor( window, colour ) +#define GetWindowRefCon(window) (long) GetWRefCon(window) +#define SetWindowRefCon(window, refcon) SetWRefCon(window, refcon) +#define GetWindowTitle(window, string) GetWTitle(window, string) +#define SetWindowTitle(window, name) SetWTitle(window, name) +#define InvalidateRect(bounds) InvalRect(bounds) +#define InvalidateWindowRect(window, bounds) (OSStatus) InvalWindowRect(window, bounds) +#define RectToRegion(region, rect) RectRgn(region, rect) +#define NewPoint() (Point) { 0, 0 } +#define SetPoint(point, x, y) SetPt(point, x, y) +/* apperance.h */ +#define SetThemeTextColour(c, d, cd) (OSStatus) SetThemeTextColor(c, d, cd) +#define IsThemeInColour(d, cd) (Boolean) IsThemeInColor(d, cd) +#define GetThemeAccentColours(out) (OSStatus) GetThemeAccentColors(out) +#define SetThemeTextColourForWindow(w, a, d, cd) (OSStatus) SetThemeTextColorForWindow(w, a, d, cd) +#define GetThemeBrushAsColour(b, d, cd, out) (OSStatus) GetThemeBrushAsColor(b, d, cd, out) +#define GetThemeTextColour(c, d, cd, out) (OSStatus) GetThemeTextColor(c, d, cd, out) +/* quickdraw.h */ +#define HighlightColour(colour) HiliteColor(colour) +#define GetPortHighlightColour(window, colour) GetPortHiliteColor(window, colour)