home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HyperLib 1997 Winter - Disc 1
/
HYPERLIB-1997-Winter-CD1.ISO.7z
/
HYPERLIB-1997-Winter-CD1.ISO
/
オンラインウェア
/
PRG
/
AESample.sit
/
AESample
/
sources
/
sample.menu.c
< prev
next >
Wrap
Text File
|
1996-06-22
|
5KB
|
178 lines
/*
*--------------------------------------------------------------
* sample.menu.c
*--------------------------------------------------------------
*/
#include "sample.h"
#include "sample.menu.h"
#include "sample.subs.h"
#include "sample.send.h"
#include "sample.dlog.h"
/*
*--------------------------------------------------------------
* static functuions only used in this source
*--------------------------------------------------------------
*/
static Boolean EnabeMyMItem(MenuRef, short, Boolean);
/*
*--------------------------------------------------------------
* macro
*--------------------------------------------------------------
*/
extern Boolean isEnabled(MenuRef, const short);
#define isEnabled(mH, item) ((**(mH)).enableFlags & (1 << (item)))
/*
*--------------------------------------------------------------
* SetUpMyMenus
*--------------------------------------------------------------
* setup menus
*--------------------------------------------------------------
*/
Boolean SetUpMyMenus(void)
{
Handle menuBar = GetNewMBar(rMenuBarID);
if (menuBar == nil) return (false);
SetMenuBar(menuBar);
DisposeHandle(menuBar);
AppendResMenu(GetMenuHandle(mAppleID), 'DRVR');
DrawMenuBar();
return (true);
}
/*
*--------------------------------------------------------------
* DoMenus
*--------------------------------------------------------------
* Handle the menu selection. mSelect is what MenuSelect() and
* MenuKey() return: the high word is the menu ID, the low word
* is the menu item
*--------------------------------------------------------------
*/
void DoMenus(long mSelect)
{
short menuID = HiWord(mSelect);
short menuItm = LoWord(mSelect);
switch (menuID) {
case mAppleID: DoAppleMenu(menuItm); break;
case mFileID: DoFileMenu(menuItm); break;
case mEditID: if (!SystemEdit(menuItm -1)) DoEditMenu(menuItm); break;
case mSendID: DoSendMenu(menuItm); break;
}
HiliteMenu(0);
}
/*
*--------------------------------------------------------------
* DoAppleMenu
*--------------------------------------------------------------
*/
void DoAppleMenu(const short theItem)
{
if (theItem == of_About) {
DoAboutMe();
} else {
/* Desk Accessories */
GrafPtr savePort;
Str63 itsDAname;
GetPort(&savePort);
GetMenuItemText(GetMenuHandle(mAppleID), theItem, itsDAname);
OpenDeskAcc(itsDAname);
SetPort(savePort);
}
}
/*
*--------------------------------------------------------------
* DoFileMenu
*--------------------------------------------------------------
*/
void DoFileMenu(const short theItem)
{
WindowRef aWindow = FrontWindow();
switch (theItem) {
case of_Open: DoOpenFile(); break;
case of_Close:
if (aWindow == gMainWindow) {
gForever = false;
}
else
if (aWindow == gViewDialog) {
CloseWindow(gViewDialog);
}
break;
case of_Print: DoPrintFile(); break;
case of_Quit: gForever = false; break;
}
}
/*
*--------------------------------------------------------------
* DoEditMenu
*--------------------------------------------------------------
*/
void DoEditMenu(const short theItem)
{
switch (theItem) {
case of_Undo: break;
case of_Cut: break;
case of_Copy: break;
case of_Paste: break;
case of_Clear: break;
case of_SelAll: break;
}
}
/*
*--------------------------------------------------------------
* DoSendMenu
*--------------------------------------------------------------
*/
void DoSendMenu(const short theItem)
{
switch (theItem) {
case of_Hold: DoHoldFile(); break;
case of_Send: DoSendFile(); break;
}
}
/*
*--------------------------------------------------------------
* AdjustMyMenus
*--------------------------------------------------------------
* change menu status according to current conditions
*--------------------------------------------------------------
*/
void AdjustMyMenus(void)
{
MenuRef aMenu = GetMenuHandle(mEditID);
Boolean redraw = false;
redraw |= EnabeMyMItem(aMenu, of_Title, GetWindowKind(FrontWindow()) < 0);
aMenu = GetMenuHandle(mSendID);
redraw |= EnabeMyMItem(aMenu, of_Send, gDocSpec.name[0] > 0);
if (redraw) DrawMenuBar();
}
/*
*--------------------------------------------------------------
* EnabeMyMItem
*--------------------------------------------------------------
* enable or disable menu item according to the conditon
*--------------------------------------------------------------
*/
static Boolean EnabeMyMItem(MenuRef myMenu, short item, Boolean activate)
{
Boolean redraw;
if (activate) {
redraw = (isEnabled(myMenu, item)) ? false : true;
EnableItem(myMenu, item);
} else {
redraw = (isEnabled(myMenu, item)) ? true : false;
DisableItem(myMenu, item);
}
return (redraw);
}