diff --git a/client/mac/mac_about.cpp b/client/mac/mac_about.cpp new file mode 100644 index 0000000000..2273653ee3 --- /dev/null +++ b/client/mac/mac_about.cpp @@ -0,0 +1,96 @@ +// The contents of this file are subject to the Mozilla Public License +// Version 1.0 (the "License"); you may not use this file except in +// compliance with the License. You may obtain a copy of the License at +// http://www.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is the Berkeley Open Infrastructure for Network Computing. +// +// The Initial Developer of the Original Code is the SETI@home project. +// Portions created by the SETI@home project are Copyright (C) 2002 +// University of California at Berkeley. All Rights Reserved. +// +// Contributor(s): +// + +#include "mac_about.h" + +// Create, show and run our about box +// +OSStatus CreateAboutWindow() +{ + IBNibRef nibRef; + EventTypeSpec dialogSpec = {kEventClassCommand, kEventCommandProcess }; + WindowRef aboutWindow; + EventHandlerUPP aboutBoxUPP; + OSStatus err = noErr; + + // Find the dialog nib + err = CreateNibReference(CFSTR("AboutBox"), &nibRef); + require_noerr( err, CantFindDialogNib ); + + // Load the window inside it + err = CreateWindowFromNib(nibRef, CFSTR("About Box"), &aboutWindow); + require_noerr( err, CantCreateDialogWindow ); + + // We don't need the nib reference anymore. + DisposeNibReference(nibRef); + + // Install our event handler + /*dialogUPP = NewEventHandlerUPP (JoinDialogEventHandler); + err = InstallWindowEventHandler (aboutWindow, aboutBoxUPP, 1, &dialogSpec, (void *) dialogWindow, NULL); + require_noerr( err, CantInstallDialogHandler );*/ + + // Show the window + ShowWindow( aboutWindow ); + + /*HideWindow(aboutWindow); + DisposeWindow(aboutWindow); + DisposeEventHandlerUPP(aboutBoxUPP);*/ + +CantFindDialogNib: +CantCreateDialogWindow: +CantInstallDialogHandler: + + return err; +} + + +// Dialog event handler +// +/*pascal OSStatus AboutBoxEventHandler (EventHandlerCallRef myHandler, EventRef event, void *userData) { + OSStatus result = eventNotHandledErr; + HICommand command; + bool stopModalLoop = FALSE; + + // Get the HI Command + GetEventParameter (event, kEventParamDirectObject, typeHICommand, NULL, + sizeof (HICommand), NULL, &command); + // Look for our Yes Join and No Join commands + switch (command.commandID) { + case 'ysjn': + //HandleResponse(TRUE); + stopModalLoop = TRUE; + result = noErr; + break; + case 'nojn': + //HandleResponse(FALSE); + stopModalLoop = TRUE; + result = noErr; + break; + } + + // Stop the modal loop. + if (stopModalLoop) { + QuitAppModalLoopForWindow((WindowRef)userData); + } + + //Return how we handled the event. + return result; +} + +*/ \ No newline at end of file diff --git a/client/mac/mac_about.h b/client/mac/mac_about.h new file mode 100644 index 0000000000..c6e0d67061 --- /dev/null +++ b/client/mac/mac_about.h @@ -0,0 +1,22 @@ +// The contents of this file are subject to the Mozilla Public License +// Version 1.0 (the "License"); you may not use this file except in +// compliance with the License. You may obtain a copy of the License at +// http://www.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is the Berkeley Open Infrastructure for Network Computing. +// +// The Initial Developer of the Original Code is the SETI@home project. +// Portions created by the SETI@home project are Copyright (C) 2002 +// University of California at Berkeley. All Rights Reserved. +// +// Contributor(s): +// + +#include + +OSStatus CreateAboutWindow(); diff --git a/client/mac/mac_join.c b/client/mac/mac_join.cpp similarity index 97% rename from client/mac/mac_join.c rename to client/mac/mac_join.cpp index 93ee36eb4d..d0d103ec16 100644 --- a/client/mac/mac_join.c +++ b/client/mac/mac_join.cpp @@ -74,12 +74,12 @@ pascal OSStatus JoinDialogEventHandler (EventHandlerCallRef myHandler, EventRef sizeof (HICommand), NULL, &command); // Look for our Yes Join and No Join commands switch (command.commandID) { - case 'ysjn': + case kHICommandOK: // 'ok ' //HandleResponse(TRUE); stopModalLoop = TRUE; result = noErr; break; - case 'nojn': + case kHICommandCancel: // 'not!' //HandleResponse(FALSE); stopModalLoop = TRUE; result = noErr; diff --git a/client/mac/mac_main.c b/client/mac/mac_main.c deleted file mode 100755 index c1ad7da337..0000000000 --- a/client/mac/mac_main.c +++ /dev/null @@ -1,239 +0,0 @@ -// The contents of this file are subject to the Mozilla Public License -// Version 1.0 (the "License"); you may not use this file except in -// compliance with the License. You may obtain a copy of the License at -// http://www.mozilla.org/MPL/ -// -// Software distributed under the License is distributed on an "AS IS" -// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -// License for the specific language governing rights and limitations -// under the License. -// -// The Original Code is the Berkeley Open Infrastructure for Network Computing. -// -// The Initial Developer of the Original Code is the SETI@home project. -// Portions created by the SETI@home project are Copyright (C) 2002 -// University of California at Berkeley. All Rights Reserved. -// -// Contributor(s): -// - -#include -#include -#include - -// project includes --------------------------------------------------------- - -#include "mac_main.h" -#include "mac_join.h" - -// statics/globals (internal only) ------------------------------------------ - -static const EventTypeSpec appEventList[] = -{ -{kEventClassCommand, kEventCommandProcess}, - {kEventClassMouse, kEventMouseDown}, -{kEventClassMouse, kEventMouseUp}, -{kEventClassMouse, kEventMouseMoved}, -{kEventClassMouse, kEventMouseDragged}, -{kEventClassMouse, kEventMouseWheelMoved} -}; - -WindowRef boincWindow; -ControlRef boincStatusControl; -EventLoopTimerRef boincTimer; -EventLoopTimerUPP boincTimerUPP; -EventHandlerUPP appCommandProcessor; -WindowPtr boincAboutWindow; - -bool user_requested_exit = false; - -#define kStatusControl 'cntl' -#define kStatusControlID 128 - -enum -{ - kBOINCCommandJoin = 'join', - kBOINCCommandSuspend = 'susp' -}; - -// -------------------------------------------------------------------------- - -void InitToolbox(void) -{ - OSStatus err; - Handle boincMenuBar; - ControlID ctrlID; - IBNibRef boincNibRef; - - InitCursor(); - - // Search for the "boinc" .nib file - err = CreateNibReference(CFSTR("boinc"), &boincNibRef); - if ( err != noErr ) { - fprintf(stderr, "Can't load boinc.nib. Err: %d\n", (int)err); - ExitToShell(); - } - - // Init Menus - err = CreateMenuBarFromNib(boincNibRef, CFSTR("MainMenu"), &boincMenuBar); - if ( err != noErr ) { - fprintf(stderr, "Can't load MenuBar. Err: %d\n", (int)err); - ExitToShell(); - } - - err = CreateWindowFromNib(boincNibRef, CFSTR("Client Window"), &boincWindow); - if (err != noErr) { - fprintf(stderr, "Can't load Window. Err: %d\n", (int)err); - ExitToShell(); - } - - ctrlID.id = kStatusControl; - ctrlID.signature = kStatusControlID; - GetControlByID(boincWindow, &ctrlID, &boincStatusControl); - - // Enable the preferences item - EnableMenuCommand(NULL, kHICommandPreferences); - - // Application-level event handler installer - appCommandProcessor = NewEventHandlerUPP(MainAppEventHandler); - err = InstallApplicationEventHandler(appCommandProcessor, GetEventTypeCount(appEventList), - appEventList, 0, NULL); - // BOINC Timed event handler installer - boincTimerUPP = NewEventLoopTimerUPP(BOINCPollLoopProcessor); - err = InstallEventLoopTimer(GetCurrentEventLoop(), 0, - kEventDurationMillisecond*1000, // Every 1 second - boincTimerUPP, NULL, &boincTimer); - - SetMenuBar(boincMenuBar); - ShowWindow(boincWindow); - - DisposeNibReference(boincNibRef); -} - -////////////////////////////////////////////////////////////////////////////////// -// BOINCPollLoopProcessor // -////////////////////////////////////////////////////////////////////////////////// -pascal void BOINCPollLoopProcessor(EventLoopTimerRef inTimer, void* timeData) -{ -#pragma unused(inTimer, timeData) - fprintf( stderr, "Fired timer.\n" ); - // Call do_something here - -} - -////////////////////////////////////////////////////////////////////////////////// -// MainAppEventHandler // -////////////////////////////////////////////////////////////////////////////////// -pascal OSStatus MainAppEventHandler(EventHandlerCallRef appHandler, EventRef theEvent, void* appData) -{ -#pragma unused (appHandler, appData) - - HICommand aCommand; - OSStatus result; - Point mDelta; - - switch(GetEventClass(theEvent)) - { - case kEventClassMouse: // 'mous' - GetEventParameter(theEvent, // the event itself - kEventParamMouseDelta, // symbolic parameter name - typeQDPoint, // expected type - NULL, // actual type (NULL is valid) - sizeof(mDelta), // buffer size - NULL, // actual buffer size (Can be NULL) - &mDelta); // variable to hold data - switch(GetEventKind(theEvent)) - { - case kEventMouseDown: - break; - case kEventMouseUp: - break; - case kEventMouseMoved: - break; - case kEventMouseDragged: - break; - case kEventMouseWheelMoved: - break; - default: - result = eventNotHandledErr; - break; - } - break; - case kEventClassCommand: - result = GetEventParameter(theEvent, kEventParamDirectObject, - typeHICommand, NULL, sizeof(HICommand), - NULL, &aCommand); - switch (aCommand.commandID) - { - case kHICommandOK: // 'ok ' - case kHICommandCancel: // 'not!' - result = eventNotHandledErr; - break; - case kHICommandQuit: - QuitApplicationEventLoop(); - result = noErr; - break; - case kHICommandUndo: // 'undo' - case kHICommandRedo: // 'redo' - case kHICommandCut: // 'cut ' - case kHICommandCopy: // 'copy' - case kHICommandPaste: // 'past' - case kHICommandClear: // 'clea' - case kHICommandSelectAll: // 'sall' - case kHICommandHide: // 'hide' - case kHICommandZoomWindow: // 'zoom' - case kHICommandMinimizeWindow: // 'mini' - case kHICommandArrangeInFront: // 'frnt' - break; - case kHICommandPreferences: // 'pref' - // Open prefs dialog - result = noErr; - break; - case kBOINCCommandJoin: // 'join' - // Open join dialog - CreateJoinDialog(); - result = noErr; - break; - case kBOINCCommandSuspend: // 'susp' - // Suspend processing - result = noErr; - break; - case kHICommandAbout: // 'abou' - // Put in check to see if window is already open - /*err = CreateWindowFromNib(boincNibRef, CFSTR("About Box"), &boincAboutWindow); - if (err != noErr) { - fprintf(stderr, "Can't load Window. Err: %d\n", (int)err); - ExitToShell(); - } - ShowWindow(boincAboutWindow);*/ - result = noErr; - break; - default: - result = eventNotHandledErr; - break; - } - break; - default: - result = eventNotHandledErr; - break; - } - return result; -} - -// -------------------------------------------------------------------------- - -int mac_setup (void) -{ - InitToolbox (); - RunApplicationEventLoop(); - return true; -} - -// -------------------------------------------------------------------------- - -void mac_cleanup (void) -{ - RemoveEventLoopTimer(boincTimer); - DisposeEventLoopTimerUPP(boincTimerUPP); - DisposeEventHandlerUPP(appCommandProcessor); -} diff --git a/client/mac/mac_prefs.cpp b/client/mac/mac_prefs.cpp new file mode 100644 index 0000000000..d761d037ff --- /dev/null +++ b/client/mac/mac_prefs.cpp @@ -0,0 +1,98 @@ +// The contents of this file are subject to the Mozilla Public License +// Version 1.0 (the "License"); you may not use this file except in +// compliance with the License. You may obtain a copy of the License at +// http://www.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is the Berkeley Open Infrastructure for Network Computing. +// +// The Initial Developer of the Original Code is the SETI@home project. +// Portions created by the SETI@home project are Copyright (C) 2002 +// University of California at Berkeley. All Rights Reserved. +// +// Contributor(s): +// + +#include "mac_prefs.h" + +// Create, show and run our prefs dialog +// +OSStatus CreatePrefsDialog() +{ + IBNibRef nibRef; + EventTypeSpec dialogSpec = {kEventClassCommand, kEventCommandProcess }; + WindowRef prefsDialog; + EventHandlerUPP prefsDialogUPP; + OSStatus err = noErr; + + // Find the dialog nib + err = CreateNibReference(CFSTR("PrefsDialog"), &nibRef); + require_noerr( err, CantFindDialogNib ); + + // Load the window inside it + err = CreateWindowFromNib(nibRef, CFSTR("Prefs Dialog"), &prefsDialog); + require_noerr( err, CantCreateDialogWindow ); + + // We don't need the nib reference anymore. + DisposeNibReference(nibRef); + + // Install our event handler + prefsDialogUPP = NewEventHandlerUPP (PrefsDialogEventHandler); + err = InstallWindowEventHandler (prefsDialog, prefsDialogUPP, 1, &dialogSpec, (void *) prefsDialog, NULL); + require_noerr( err, CantInstallDialogHandler ); + + // Show the window + ShowWindow( prefsDialog ); + + // Run modally + RunAppModalLoopForWindow(prefsDialog); + + HideWindow(prefsDialog); + DisposeWindow(prefsDialog); + DisposeEventHandlerUPP(prefsDialogUPP); + +CantFindDialogNib: +CantCreateDialogWindow: +CantInstallDialogHandler: + + return err; +} + + +// Dialog event handler +// +pascal OSStatus PrefsDialogEventHandler (EventHandlerCallRef myHandler, EventRef event, void *userData) { +OSStatus result = eventNotHandledErr; +HICommand command; +bool stopModalLoop = FALSE; + +// Get the HI Command +GetEventParameter (event, kEventParamDirectObject, typeHICommand, NULL, + sizeof (HICommand), NULL, &command); +// Look for OK and Cancel commands +switch (command.commandID) { + case kHICommandOK: // 'ok ' + //HandleResponse(TRUE); + stopModalLoop = TRUE; + result = noErr; + break; + case kHICommandCancel: // 'not!' + //HandleResponse(FALSE); + stopModalLoop = TRUE; + result = noErr; + break; +} + +// Stop the modal loop. +if (stopModalLoop) { + QuitAppModalLoopForWindow((WindowRef)userData); +} + +//Return how we handled the event. +return result; +} + diff --git a/client/mac/mac_prefs.h b/client/mac/mac_prefs.h new file mode 100644 index 0000000000..f114ac2976 --- /dev/null +++ b/client/mac/mac_prefs.h @@ -0,0 +1,13 @@ +/* + * mac_prefs.h + * boinc + * + * Created by Eric Heien on Mon Aug 12 2002. + * Copyright (c) 2002 __MyCompanyName__. All rights reserved. + * + */ + +#include + +OSStatus CreatePrefsDialog(); +pascal OSStatus PrefsDialogEventHandler (EventHandlerCallRef myHandler, EventRef event, void *userData); diff --git a/mac_build.sit b/mac_build.sit index 2c11078aa1..92a50d27c3 100644 Binary files a/mac_build.sit and b/mac_build.sit differ