Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
Source/WRay_Menu.c
/* |
* WRay_Menu.c |
* |
* QuickDraw 3D 1.6 Sample |
* Robert Dierkes |
* |
* 07/28/98 RDD Created. |
*/ |
/*------------------*/ |
/* Include Files */ |
/*------------------*/ |
#include "QD3D.h" |
#if defined(OS_MACINTOSH) && OS_MACINTOSH |
#include <Devices.h> |
#include <Menus.h> |
#include <Dialogs.h> |
#include <Resources.h> |
#include <ToolUtils.h> |
#endif |
#include "WRay_Error.h" |
#include "WRay_Document.h" |
#include "WRay_Main.h" |
#include "WRay_Menu.h" |
#include "WRay_Pick.h" |
#include "WRay_Scene.h" |
#include "WRay_System.h" |
/*------------------*/ |
/* Constants */ |
/*------------------*/ |
#define kMenuBarRsrcID 128 |
#define kAboutDialogRsrcID 128 |
/*----------------------*/ |
/* Extern Declarations */ |
/*----------------------*/ |
extern TQ3Boolean gTimeToQuit; |
/*----------------------*/ |
/* Global Declarations */ |
/*----------------------*/ |
Handle ghMenuBar = NULL; |
/*----------------------*/ |
/* Local Prototypes */ |
/*----------------------*/ |
static |
TQ3Boolean Menu_Apple( |
short menuID, |
short itemNumber); |
static |
TQ3Boolean Menu_File( |
short itemNumber, |
TDocumentPtr pDoc); |
static |
TQ3Boolean Menu_Edit( |
short itemNumber, |
TDocumentPtr pDoc); |
static |
TQ3Boolean Menu_WorldRay( |
short menuID, |
short itemNumber, |
TDocumentPtr pDoc); |
static |
TQ3Boolean Menu_AboutBox ( |
void); |
/* |
* Menu_Initialize |
*/ |
TQ3Boolean Menu_Initialize( |
void) |
{ |
TQ3Boolean goodMenus; |
goodMenus = kQ3True; |
/* Initialize MenuBar */ |
ghMenuBar = GetNewMBar (kMenuBarRsrcID); |
if (ghMenuBar != NULL) { |
SetMenuBar(ghMenuBar); |
AppendResMenu(GetMenuHandle (mApple), (ResType) 'DRVR'); |
DrawMenuBar(); |
} |
else { |
ERROR_DEBUG_STR ("Menu_Initialize: Menu_Initialize: Couldn't find menu bar."); |
ghMenuBar = NULL; |
goodMenus = kQ3False; |
} |
return (goodMenus); |
} |
/* |
* Menu_InitializeItems |
* |
* Globals: |
* None |
* |
* Menu_InitializeItems sets menu items based on these pDoc fields: |
*/ |
TQ3Boolean Menu_InitializeItems( |
TDocumentPtr pDoc) |
{ |
MenuHandle hMenu; |
#pragma unused(pDoc) |
DEBUG_ASSERT(pDoc != NULL, Menu_InitializeItems); |
/* |
* mRay Menu |
*/ |
hMenu = GetMenuHandle(mRay); |
DEBUG_ASSERT(hMenu != NULL, Menu_InitializeItems); |
if (hMenu == NULL) { |
return kQ3False; |
} |
DisableItem(hMenu, iRayEnd); |
CheckItem(hMenu, iRayRotate, Scene_IsRotating()); |
CheckItem(hMenu, iRaySound, System_GetSound()); |
return kQ3True; |
} |
/* |
* Menu_Command |
*/ |
TQ3Boolean Menu_Command ( |
long menuResult, |
TDocumentPtr pDoc) |
{ |
TQ3Boolean isOK = kQ3True; |
short menuID, |
itemNumber; |
if (menuResult == 0) { |
return kQ3False; |
} |
menuID = HiWord (menuResult); |
itemNumber = LoWord (menuResult); |
switch (menuID) { |
case mApple: |
isOK = Menu_Apple(menuID, itemNumber); |
break; |
case mFile: |
isOK = Menu_File(itemNumber, pDoc); |
break; |
case mEdit: |
isOK = Menu_Edit(itemNumber, pDoc); |
break; |
case mRay: |
isOK = Menu_WorldRay(menuID, itemNumber, pDoc); |
break; |
default: |
isOK = kQ3False; |
break; |
} /* switch (menuID) */ |
HiliteMenu (0); |
return isOK; |
} |
#pragma mark - |
/* |
* Menu_Apple |
*/ |
static |
TQ3Boolean Menu_Apple( |
short menuID, |
short itemNumber) |
{ |
TQ3Boolean isOK = kQ3True; |
switch (itemNumber) |
{ |
case iAbout: |
isOK = Menu_AboutBox(); |
break; |
default: |
{ |
MenuHandle hMenu; |
Str255 deskAccName; |
GrafPtr oldPort; |
hMenu = GetMenuHandle (menuID); |
if (hMenu != NULL) { |
GetPort (&oldPort); |
GetMenuItemText (hMenu, itemNumber, deskAccName); |
(void) OpenDeskAcc (deskAccName); |
SetPort (oldPort); |
} |
else { |
isOK = kQ3False; |
} |
} |
break; |
} |
return isOK; |
} |
/* |
* Menu_File |
*/ |
static |
TQ3Boolean Menu_File( |
short itemNumber, |
TDocumentPtr pDoc) |
{ |
TQ3Boolean isOK = kQ3True; |
#pragma unused(pDoc) |
switch (itemNumber) { |
case iNew: |
case iOpen: |
case iClose: |
case iSave: |
case iSaveAs: |
isOK = kQ3False;/**/ |
break; |
case iQuit: |
gTimeToQuit = kQ3True; |
break; |
default: |
System_Beep(); |
isOK = kQ3False; |
break; |
} |
return isOK; |
} |
/* |
* Menu_Edit |
*/ |
static |
TQ3Boolean Menu_Edit( |
short itemNumber, |
TDocumentPtr pDoc) |
{ |
TQ3Boolean isOK = kQ3True; |
#pragma unused (pDoc) |
if (! SystemEdit (itemNumber - 1)) { |
switch (itemNumber) { |
case iUndo: break; |
case iCut: break; |
case iCopy: break; |
case iPaste: break; |
case iClear: break; |
} |
} |
return isOK; |
} |
/* |
* Menu_WorldRay |
*/ |
static |
TQ3Boolean Menu_WorldRay( |
short menuID, |
short itemNumber, |
TDocumentPtr pDoc) |
{ |
TQ3Boolean isOK = kQ3False; |
MenuHandle hMenu; |
DEBUG_ASSERT(pDoc != NULL, Menu_WorldRay); |
hMenu = GetMenuHandle(menuID); |
DEBUG_ASSERT(hMenu != NULL, Menu_WorldRay); |
if (hMenu == NULL) { |
return kQ3False; |
} |
switch (itemNumber) { |
case iRayBegin: |
{ |
if (Pick_BeginAnimation(pDoc) == kQ3Success) { |
DisableItem(hMenu, iRayBegin); |
EnableItem(hMenu, iRayEnd); |
isOK = kQ3True; |
} else { |
isOK = kQ3False; |
} |
} |
break; |
case iRayEnd: |
{ |
if (Pick_EndAnimation(pDoc) == kQ3Success) { |
EnableItem(hMenu, iRayBegin); |
DisableItem(hMenu, iRayEnd); |
isOK = kQ3True; |
} else { |
isOK = kQ3False; |
} |
} |
break; |
case iRayRotate: |
{ |
CheckItem(hMenu, itemNumber, ! Scene_IsRotating()); |
Scene_SetIsRotating((Scene_IsRotating() == kQ3True) ? kQ3False : kQ3True); |
isOK = kQ3True; |
} |
break; |
case iRaySound: |
{ |
TQ3Boolean itemState; |
itemState = System_GetSound() ? kQ3False : kQ3True; |
CheckItem(hMenu, itemNumber, itemState); |
System_SetSound(itemState); |
isOK = kQ3True; |
} |
break; |
default: |
{ |
System_Beep(); |
isOK = kQ3False; |
} |
break; |
} |
return isOK; |
} |
#pragma mark - |
/* |
* Menu_AboutBox |
*/ |
static |
TQ3Boolean Menu_AboutBox (void) |
{ |
TQ3Boolean isOK = kQ3True; |
DialogPtr theDialog; |
short itemHit; |
theDialog = GetNewDialog(kAboutDialogRsrcID, NULL, kWindowOnTop); |
if (theDialog == NULL) |
return kQ3False; |
do { |
ModalDialog (NULL, &itemHit); |
} |
while (itemHit != ok); |
DisposeDialog (theDialog); |
return isOK; |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14