home *** CD-ROM | disk | FTP | other *** search
- #define DEBUG_MODE
-
- /************************************************************/
- /* Program Fix Desktop: clean up the desktop file. */
- /* Removes extraneous information from the desktop. */
- /* */
- /* Version 1.0 [ 7/ 9/87]: Original implementation. */
- /* 1.1 [ 7/16/87]: Support for MFS volumes added. */
- /* 2.0 [ 8/22/88]: Converted to Lightspeed C. */
- /* */
- /************************************************************/
-
- #include <MacTypes.h>
- #include <QuickDraw.h>
- #include <MenuMgr.h>
- #include <WindowMgr.h>
- #include <DialogMgr.h>
- #include <EventMgr.h>
- #include <FileMgr.h>
- #include <HFS.h>
-
- #define FIX_MAIN
- #include "fix.h"
-
- static MenuHandle menulist[4];
-
- void main(void);
- void check_hfs(void);
- void initialize_toolbox(void);
- void initialize_menus(void);
- void handle_events(void);
- int menu_command(long menu_choice, int was_key);
- void apple_command(int what);
- int file_command(int what);
-
- /* Main program. */
-
- void main()
- {
- check_hfs();
-
- MaxApplZone();
- initialize_toolbox();
- initialize_menus();
-
- handle_events();
-
- InitWindows();
- set_watch_cursor();
- }
-
- /* Check that the Hierarchical File System is available. */
-
- static void check_hfs()
- {
- if (FSFCBLen < 0) { /* Not HFS */
- StopAlert(ALERT_ROM,NIL);
- ExitToShell();
- }
- }
-
- /* Initialize all ToolBox routines used by the program. */
-
- #ifdef DEBUG_MODE
- void goodbye(void);
-
- static void goodbye()
- {
- ExitToShell();
- }
- #endif
-
- static void initialize_toolbox()
- {
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
-
- #ifdef DEBUG_MODE
- InitDialogs(goodbye);
- #else
- InitDialogs(NIL);
- #endif
-
- FlushEvents(everyEvent, 0);
- InitCursor();
- }
-
- /* Load our menus and draw the menu bar. */
-
- static void initialize_menus()
- {
- register Handle my_menus; /* Menu bar... */
-
- my_menus = GetNewMBar(MBAR_RESOURCE);
- SetMenuBar(my_menus);
- DisposHandle(my_menus);
-
- menulist[APPLE_MENU] = GetMHandle(APPLE_MENU);
- menulist[FILE_MENU] = GetMHandle(FILE_MENU);
- menulist[EDIT_MENU] = GetMHandle(EDIT_MENU);
-
- AddResMenu(menulist[APPLE_MENU], 'DRVR');
-
- DisableItem(menulist[FILE_MENU], FILE_CLOSE); /* Disable */
- DisableItem(menulist[EDIT_MENU], 0); /* some commands... */
-
- DrawMenuBar();
- }
-
- /* Main event loop. */
-
- static void handle_events()
- {
- EventRecord myevent;
- register int quit_flag, desk_status, new_desk_status;
-
- quit_flag = 0;
- desk_status = 0; /* No desk accessory is initially open. */
- while (!quit_flag) {
- new_desk_status = (FrontWindow() != NIL);
- if (new_desk_status != desk_status) { /* Update menus. */
- desk_status = new_desk_status;
- if (desk_status) {
- EnableItem(menulist[FILE_MENU], FILE_CLOSE);
- EnableItem(menulist[EDIT_MENU], 0);
- DrawMenuBar();
- }
- else {
- DisableItem(menulist[FILE_MENU], FILE_CLOSE);
- DisableItem(menulist[EDIT_MENU], 0);
- DrawMenuBar();
- }
- }
- SystemTask();
- GetNextEvent(everyEvent, &myevent);
- switch(myevent.what) {
- case mouseDown:
- {
- WindowPtr which_window;
-
- switch(FindWindow(myevent.where, &which_window)) {
- case inSysWindow:
- SystemClick(&myevent, which_window);
- break;
- case inMenuBar:
- quit_flag = menu_command(MenuSelect(myevent.where), 0); /* not keypress */
- break;
- }
- }
- break;
- case keyDown:
- case autoKey:
- if (myevent.modifiers & cmdKey)
- quit_flag = menu_command(MenuKey((char)myevent.message), 1); /* was keypress */
- break;
- }
- }
- }
-
- /* Dispatch a menu selection. Called from the event loop. */
-
- static int menu_command(menu_choice, was_key)
- long menu_choice;
- int was_key;
- {
- register int which_menu, which_item;
-
- which_menu = (int)(menu_choice>>16);
- which_item = (int)menu_choice;
-
- HiliteMenu(which_menu);
- switch(which_menu) {
- case APPLE_MENU:
- apple_command(which_item);
- break;
- case FILE_MENU:
- if (file_command(which_item)) {
- HiliteMenu(0);
- return(1);
- }
- break;
- case EDIT_MENU:
- if (!was_key)
- SystemEdit(which_item-1);
- break;
- }
- HiliteMenu(0);
- return(0); /* Not ready to quit yet... */
- }
-
- /* Handle an Apple menu selection. */
-
- static void apple_command(what)
- int what;
- {
- register DialogPtr about_dialog;
- int temp;
-
- if (what == APPLE_ABOUT) {
- about_dialog = GetNewDialog(DIALOG_ABOUT, NIL, MINUS_ONE);
- ModalDialog(NIL, &temp);
- DisposDialog(about_dialog);
- }
- else {
- GetItem(menulist[APPLE_MENU], what, string);
- OpenDeskAcc(string);
- }
- }
-
- /* Handle a file menu selection. */
-
- static int file_command(what)
- int what;
- {
- switch(what) {
- case FILE_OPTIONS:
- do_options();
- break;
- case FILE_PROCESS:
- one_pass();
- break;
- case FILE_CLOSE:
- {
- register int refnum;
-
- if ((refnum = ((WindowPeek) FrontWindow())->windowKind) < 0)
- CloseDeskAcc(refnum);
- }
- break;
- case FILE_QUIT:
- return(1); /* We're quitting! */
- break;
- }
- return(0); /* Not a quit... */
- }
-