Updated GUI (added preferences, about box)

svn path=/trunk/boinc/; revision=307
This commit is contained in:
Eric Heien 2002-08-12 23:22:17 +00:00
parent 030d0e213d
commit 33bfa9e96a
7 changed files with 231 additions and 241 deletions

96
client/mac/mac_about.cpp Normal file
View File

@ -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;
}
*/

22
client/mac/mac_about.h Normal file
View File

@ -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 <Carbon/Carbon.h>
OSStatus CreateAboutWindow();

View File

@ -74,12 +74,12 @@ pascal OSStatus JoinDialogEventHandler (EventHandlerCallRef myHandler, EventRef
sizeof (HICommand), NULL, &command); sizeof (HICommand), NULL, &command);
// Look for our Yes Join and No Join commands // Look for our Yes Join and No Join commands
switch (command.commandID) { switch (command.commandID) {
case 'ysjn': case kHICommandOK: // 'ok '
//HandleResponse(TRUE); //HandleResponse(TRUE);
stopModalLoop = TRUE; stopModalLoop = TRUE;
result = noErr; result = noErr;
break; break;
case 'nojn': case kHICommandCancel: // 'not!'
//HandleResponse(FALSE); //HandleResponse(FALSE);
stopModalLoop = TRUE; stopModalLoop = TRUE;
result = noErr; result = noErr;

View File

@ -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 <math.h>
#include <stdio.h>
#include <string.h>
// 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);
}

98
client/mac/mac_prefs.cpp Normal file
View File

@ -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;
}

13
client/mac/mac_prefs.h Normal file
View File

@ -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 <Carbon/Carbon.h>
OSStatus CreatePrefsDialog();
pascal OSStatus PrefsDialogEventHandler (EventHandlerCallRef myHandler, EventRef event, void *userData);

Binary file not shown.