home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-06-17 | 6.0 KB | 169 lines | [TEXT/PJMM] |
- program Main;
-
- uses
- xWindow, applicationProcs;
-
- var
- appleMenu: MenuHandle;
-
- procedure AboutBox;
- var
- junk: integer;
- begin
- ParamText(ApplicationLongName, AuthorName, StringOf(AuthorAddress1, chr(13), AuthorAddress2, chr(13), AuthorAddress3), CommentLine);
- junk := Alert(128, nil);
- end;
-
- procedure DoAppleMenu (itemNum: integer);
- { Handles a command from the apple menu, either by displaying the about box for the }
- { application or loading a desk acessory; it is not necessary to change this procedure }
- var
- DAName: str255; { name of desk accessory to be loaded (from the apple menu) }
- junk: integer;
- begin
- if itemNum = 1 then
- AboutBox
- else begin
- GetItem(appleMenu, itemNum, DAName);
- junk := OpenDeskAcc(DAName);
- end;
- end;
-
-
- procedure HandleMenuEvent (selection: longint;
- var done: boolean);
- var
- MenuNum: integer; { The longint "selection" is decoded into the id of the menu, which }
- ItemNum: integer; { is just its menuID, and the item number, which is just the }
- { position of the item counting from the top of the menu. }
- begin
- MenuNum := HiWord(Selection);
- if MenuNum = 0 then { no menu item was actually chosen--no action }
- Exit(HandleMenuEvent);
- ItemNum := LoWord(Selection);
- if MenuNum = 1 then
- DoAppleMenu(itemNum)
- else if MenuNum = 2 then
- DoFileMenu(ItemNum, done)
- else if MenuNum = 3 then
- DoEditMenu(ItemNum)
- else
- doOtherMenu(menuNum, itemNum);
- HiliteMenu(0); { A menu title is highlighted until HiliteMenu(0) is called. }
- end;
-
-
-
- procedure InstallMenus;
- var
- MBar: Handle;
- begin
- MBar := GetNewMBar(128); { Get the menu resource. }
- SetMenuBar(MBar); { Specify that this is the menu to be used }
- appleMenu := GetMHandle(1); { Get a handle to the the apple menu. }
- SetItem(appleMenu, 1, StringOf('About ', ApplicationShortName, '...'));
- AddResMenu(appleMenu, 'DRVR'); { Install all the desk accessaries onto the }
- { apple menu. }
- editMenu := GetMHandle(3); { These provide GLOBAL variables for }
- fileMenu := GetMHandle(2); { referencing the edit and file menus; }
- DrawMenuBar; { This actually displays the Menu Bar and }
- { makes it active. }
- end;
-
-
- procedure SendEventToWindow (win: windowPtr;
- var theEvent: eventRecord);
- var
- X: XWindow;
- begin
- if Window2XWindow(win, x) then
- X.doEvent(theEvent);
- end;
-
-
- var { LOCAL VARIABLES FOR MAIN PROGRAM }
-
- done: boolean;
- theEvent: EventRecord; { contains the event read by main event loop }
- partNum: integer;
- selection: longint; { number encoding a menu selection }
- whichWin: WindowPtr; { the window that a mouseDown event occured in, or the }
- { window of concern in an activate or update event. }
- xWin: xWindow;
- savePort: GrafPtr;
- pt: point;
-
-
- begin
-
- InitXWindows;
- InstallMenus; { build the menu bar for this application }
- InitializeApplication;
-
- FlushEvents(keyDownMask + autoKeyMask + mDownMask, 0); { delete any events pending when}
- { program starts. }
-
- InitCursor; { changes cursor from watch to arrow; not needed inside THINK Pascal environment }
-
- done := false; { this global variable is set to TRUE when an event occurs that causes the }
- { program to end. (Program can also end via a Halt statement, as will }
- { happen if the procedure FatalError is called. }
-
- repeat { This is the main event loop, which gets events and processes }
- { them until the program ends. }
- if not WaitNextEvent(everyEvent, theEvent, maxSleepTime, nil) then begin{no event pending }
- ApplicationIdle
- end
- else begin { process the event }
- case theEvent.what of
- keyDown: begin
- if BitAnd(theEvent.modifiers, cmdKey) <> 0 then begin
- { a key was pressed with the command key held down -- it needs to }
- { be processed as a menu command. }
- UpdateMenus; { Enables/disables approporiate menu entries }
- SetCursor(arrow);
- Selection := MenuKey(chr(theEvent.message)); { which menu entry? }
- HandleMenuEvent(Selection, done)
- end
- else
- SendEventToWindow(FrontWindow, theEvent);
- end;
- autoKey: { note: don't allow autokey repeated command keys. }
- if (BitAnd(theEvent.modifiers, cmdKey) = 0) & (FrontWindow <> nil) then
- SendEventToWindow(FrontWindow, theEvent);
- mouseDown: begin
- partNum := FindWindow(theEvent.where, whichWin);
- if partNum = inSysWindow then begin { this event is for a desk accessary or something }
- SetCursor(arrow);
- SystemClick(theEvent, whichWin)
- end
- else if partNum = inMenuBar then begin
- UpdateMenus; { enable/disable appropriate menu entries }
- SetCursor(arrow);
- Selection := MenuSelect(theEvent.where); { which menu entry? }
- HandleMenuEvent(Selection, done);
- end
- else if partnum <> inDesk then { mouse event within a window }
- SendEventToWindow(whichWin, theEvent)
- end;
- updateEvt, activateEvt: begin
- whichWin := WindowPtr(theEvent.message);
- SendEventToWindow(whichWin, theEvent);
- end;
- otherwise
- { do nothing for keyUp, mouseUp, multifinder events }
- end;
- end;
- whichWin := FrontWindow;
- if (whichWin <> nil) & (window2xWindow(whichWin, xWin)) then begin
- GetPort(savePort);
- SetPort(whichWin);
- GetMouse(pt);
- SetPort(savePort);
- xWin.adjustCursor(pt);
- end;
- until done;
-
- CleanUpApplication;
-
- end.