home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Carousel
/
CAROUSEL.cdr
/
mactosh
/
code
/
c_bmug3.sit
< prev
next >
Wrap
Text File
|
1988-06-20
|
5KB
|
227 lines
18-Jun-88 14:24:14-MDT,5281;000000000000
Return-Path: <u-lchoqu%sunset@cs.utah.edu>
Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:24:06 MDT
Received: by cs.utah.edu (5.54/utah-2.0-cs)
id AA22086; Sat, 18 Jun 88 14:24:09 MDT
Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
id AA24488; Sat, 18 Jun 88 14:24:06 MDT
Date: Sat, 18 Jun 88 14:24:06 MDT
From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
Message-Id: <8806182024.AA24488@sunset.utah.edu>
To: rthum@simtel20.arpa
Subject: BMUG3.c
/* Window - Event Manager Example Lesson 3 */
/* Note that DJB has enforced K&R's standard for indentation */
#include "Events.h"
#include "Window.h"
#include "Menu.h"
#define TRUE 1
#define FALSE 0
#define NIL 0
#define KEYMASK 0xFF
/* Menu Stuff */
#define Desk_ID 100
#define File_ID 101
#define Our_ID 102
#define BMUG_ID 103
MenuHandle DeskMenu;
MenuHandle FileMenu;
MenuHandle OurMenu;
MenuHandle BMUGMenu;
EventRecord theEvent;
WindowRecord theWindowRec; /* Don't Fragment the Heap */
WindowPtr theWindow,whichWindow;
Rect windowR,legalR,limitR;
short windowcode,still_InGoAway;
char c;
long newSize;
extern struct P_Str *CtoPstr();
int strlen(str)char *str;
{int i=0;while (str[i++]);return i-1;}
SetUpMenus()
{
/* Desk Accessory Menu */
DeskMenu = NewMenu (Desk_ID,CtoPstr("\24"));
AddResMenu (DeskMenu, 'DRVR');
InsertMenu (DeskMenu, 0);
/* File Menu */
FileMenu = NewMenu (File_ID, CtoPstr("File"));
AppendMenu (FileMenu, CtoPstr("Open Window/M;Close Window/X;Quit/Q"));
InsertMenu (FileMenu,0);
DisableItem (FileMenu, 2);
/* Our Menu */
OurMenu = NewMenu (Our_ID, CtoPstr("Our Menu"));
AppendMenu (OurMenu, CtoPstr("Hide Window/H;Show Window/S;New Window Title;(-;Show BMUG;Hide BMUG"));
InsertMenu (OurMenu, 0);
DisableItem (OurMenu, 6);
SetItemIcon (OurMenu, 5,1);
/* BMUG Menu */
BMUGMenu = NewMenu (BMUG_ID, CtoPstr("BMUG"));
AppendMenu (BMUGMenu, CtoPstr("<O<SDevelopers' Group"));
DrawMenuBar();
}
main() /* main() */
{
InitWindows();
InitCursor();
InitFonts();
FlushEvents(everyEvent);
InitMenus();
SetUpMenus();
theWindow = NIL;
SetRect(&windowR,50,50,300,150);
SetRect(&legalR,5,5,505,335);
SetRect(&limitR, 50,10,500,330);
while (TRUE) {
if (GetNextEvent(everyEvent,&theEvent)) {
switch (theEvent.what) {
case keyDown:
c = theEvent.message & cmdKey;
DoWhatTheMenuSays( MenuKey (c) );
HiliteMenu(0);
break;
case mouseDown:
windowcode=FindWindow(&theEvent.where,&whichWindow);
switch (windowcode) {
case inDesk:
if((whichWindow = FrontWindow()) != 0)
HiliteWindow(whichWindow, FALSE);
break;
case inMenuBar:
DoWhatTheMenuSays(MenuSelect(&theEvent.where));
break;
case inSysWindow:
SysBeep(1);
break;
case inContent:
HiliteWindow(whichWindow, TRUE);
break;
case inDrag:
DragWindow(whichWindow,&theEvent.where,&legalR);
break;
case inGrow:
newSize = GrowWindow(whichWindow,&theEvent.where,&limitR);
SizeWindow(whichWindow,LoWord(newSize),HiWord(newSize),FALSE);
/* newSize is split into short ints for width and height */
break;
case inGoAway:
still_InGoAway = TrackGoAway(whichWindow,&theEvent.where);
if(still_InGoAway) {
CloseWindow(whichWindow);
theWindow = NIL;
EnableItem(FileMenu,1);
DisableItem(FileMenu, 2);
}
break;
} /* end of switch(windowcode) */
break;
default:
break;
} /* end of switch(theEvent.what) */
} /* end of if(GetNext...) */
} /* end of while(True) */
} /* end of procedure main() */
DoWhatTheMenuSays(menuResult,)
long menuResult;
{
short menuID, itemNumber;
menuID = HiWord (menuResult);
itemNumber = LoWord (menuResult);
switch (menuID)
{
case File_ID:
switch (itemNumber)
{
case 1:
theWindow = NewWindow (&theWindowRec,&windowR,"13/BMUG Rules!",TRUE,documentProc, (WindowPtr) - 1,TRUE,0);
DisableItem (FileMenu, 1);
EnableItem (FileMenu, 2);
break;
case 2:
CloseWindow (theWindow);
theWindow = NIL;
DisableItem (FileMenu, 2);
EnableItem (FileMenu, 1);
break;
case 3:
ExitToShell();
break;
} /* end of case FileMenu */
break; /* case File_ID */
case Our_ID:
switch (itemNumber) {
case 1:
HideWindow (theWindow);
break;
case 2:
ShowWindow (theWindow);
break;
case 3:
SetWTitle (theWindow,CtoPstr("A New Title"));
break;
case 5:
InsertMenu (BMUGMenu, 0);
EnableItem (OurMenu, 6);
DisableItem (OurMenu, 5);
DrawMenuBar();
break;
case 6:
DeleteMenu (BMUG_ID);
EnableItem (OurMenu, 5);
DisableItem (OurMenu, 6);
DrawMenuBar();
break;
} /* end of menu OurMenu */
break;
case Desk_ID:
break;
} /* end of switch (menuID) */
HiliteMenu(0);
} /* end of procedure DoWhatTheMenuSays() */