home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************
- * This file contains the functions which start off the program. The
- * main event loop and Macintosh toolbox definitions are in this
- * file.
- **********************************************************************/
-
- #include "Creator Changer.h"
- #include "Creator Changer.start.h"
-
-
- /**********************************************************************
- * Function main(), this is the main function of the program. The
- * major parts of the program are called in this function.
- **********************************************************************/
-
- void main(void)
- {
-
- Init_Toolbox();
-
- Check_Sys_Type();
- Check_Drag_Manager();
- Install_AE_Handlers();
-
- Get_Strings();
- Open_Preferences();
- Set_Up_Menu_Bar();
-
- while(!All_Done) Handle_One_Event();
-
- }
-
-
- /**********************************************************************
- * Function Handle_One_Event(), this function handles one event.
- * Depending on what the event is, it gets directed to the
- * appropriate place.
- **********************************************************************/
-
- void Handle_One_Event(void)
- {
-
- EventRecord the_event;
-
- if(WaitNextEvent(everyEvent, &the_event, Sleep_Ticks, MOUSE_REGION))
- {
- if(IsDialogEvent(&the_event)) Handle_Dialog_Event(&the_event);
- switch(the_event.what)
- {
- case mouseDown:
- Handle_Mouse_Down(&the_event);
- break;
- case keyDown:
- case autoKey:
- {
- static char command_key;
-
- Maintain_Menu_Items(FrontWindow());
- command_key=the_event.message & charCodeMask;
- if(the_event.modifiers & cmdKey) (void)Handle_Menu_Choice(MenuKey(command_key));
- }
- case kHighLevelEvent:
- Option_Key_Down=Is_Pressed(58);
- AEProcessAppleEvent(&the_event);
- break;
- }
- }
- else Do_Dialog_Null_Event(&the_event);
-
-
- }
-
-
-
- /**********************************************************************
- * Function Handle_Dialog_Event(), this function sends events to the dialog event
- * loop, then if the event loop did not handle the event it then checks to see what was
- * was selected.
- **********************************************************************/
-
- void Handle_Dialog_Event(EventRecord *the_event)
- {
-
- if(Dialog_Event_Loop(the_event))
- {
- DialogRef the_dialog;
- short the_item;
-
- if(DialogSelect(the_event, &the_dialog, &the_item))
- {
- if(the_dialog==Chng.dialog) Switch_Chng_Dialog(&Chng, the_item);
- else if(the_dialog==About.dialog) Switch_Abot_Dialog(&About, the_item);
- else if(the_dialog==Pref.dialog) Switch_Pref_Dialog(&Pref, the_item);
- }
- }
-
- }
-
-
-
- /**********************************************************************
- * Function Handle_Mouse_Down(), this function handles any mouse down
- * event, such as a window select, in the menu bar etc.
- **********************************************************************/
-
- void Handle_Mouse_Down(EventRecord *the_event)
- {
-
- short the_part;
- long menu_choice, the_volume;
- Rect drag_rect;
- RgnHandle the_gray_rgn;
- WindowRef which_window;
- DialogRef the_dialog=FrontWindow();
-
- GetSysBeepVolume(&the_volume);
- SetSysBeepVolume(the_volume);
- the_part=FindWindow(the_event->where, &which_window);
- the_gray_rgn=GetGrayRgn();
-
- switch(the_part)
- {
- case inMenuBar:
- Maintain_Menu_Items(the_dialog);
- menu_choice=MenuSelect(the_event->where);
- (void)Handle_Menu_Choice(menu_choice);
- break;
- case inSysWindow:
- SystemClick(the_event, which_window);
- break;
- case inDesk:
- case inContent:
- if(the_dialog==About.dialog && which_window!=the_dialog) SysBeep(the_volume);
- break;
- case inDrag:
- if(which_window==the_dialog) DragWindow(which_window, the_event->where, &((**the_gray_rgn).rgnBBox));
- else SysBeep(the_volume);
- default:
- break;
- }
-
- }
-
-
-
- /**********************************************************************
- * Function Handle_Menu_Choice(), this function handles the menu
- * choice made, then it directs it to the appropriate place.
- **********************************************************************/
-
- Boolean Handle_Menu_Choice(long menu_choice)
- {
-
- short the_menu=HiWord(menu_choice);
- short the_item=LoWord(menu_choice);
-
- if(menu_choice!=0)
- {
- switch(the_menu)
- {
- case APPLE_MENU_ID:
- Handle_Apple_Choice(the_item);
- HiliteMenu(0);
- return(TRUE);
- break;
- case FILE_MENU_ID:
- Handle_File_Choice(the_item);
- HiliteMenu(0);
- return(TRUE);
- break;
- case EDIT_MENU_ID:
- Handle_Edit_Choice(the_item);
- HiliteMenu(0);
- return(TRUE);
- default:
- return(FALSE);
- break;
- }
- }
-
- }
-
-
-
- /**********************************************************************
- * Function Is_Pressed(), this function determine what key is pressed.
- **********************************************************************/
-
- Boolean Is_Pressed(unsigned short key)
- {
-
- unsigned char key_mask[16];
-
- GetKeys((unsigned long *)key_mask);
- return((key_mask[key>>3]>>(key&7))&1);
-
- }
-
-
-
- /**********************************************************************
- * Function Do_Dialog_Null_Event(), this function keeps the text edit cursor blinking
- * and makes sure that the arrow changes to an I beam when ove the edit boxes.
- **********************************************************************/
-
- void Do_Dialog_Null_Event(EventRecord *the_event)
- {
-
- DialogRef the_dialog=FrontWindow();
- GrafPtr old_port;
-
- GetPort(&old_port);
- SetPort(the_dialog);
-
- if(the_dialog!=NIL_PTR)
- {
- if(!In_Background)
- {
- short the_item;
-
- if(Check_Edit_Box(the_dialog))
- {
- CursHandle the_cursor;
-
- the_cursor=GetCursor(iBeamCursor);
- HLock((Handle)the_cursor);
- SetCursor(*the_cursor);
- HUnlock((Handle)the_cursor);
- }
- else SetCursor(&qd.arrow);
-
- DialogSelect(the_event, &the_dialog, &the_item);
- }
- }
- SetPort(old_port);
-
- }
-
-
-
- /**********************************************************************
- * Function Dialog_Event_Loop(), this function is the switch for
- * any of the dialog events.
- **********************************************************************/
-
- Boolean Dialog_Event_Loop(EventRecord *the_event)
- {
-
- switch(the_event->what)
- {
- case keyDown:
- Maintain_Menu_Items(FrontWindow());
- Handle_Key_Down(the_event);
- return(FALSE);
- break;
- default:
- return(TRUE);
- break;
- }
-
- }
-
-
-
- /**********************************************************************
- * Function Check_Edit_Box(), this function checks to see if the cursor
- * is in any of the text-edit boxes in any of the dialogs.
- **********************************************************************/
-
- Boolean Check_Edit_Box(DialogRef the_dialog)
- {
-
- Point the_point;
- short os=Pref.num_items;
-
- GetMouse(&the_point);
-
- if(the_dialog==Chng.dialog)
- {
- if(Get_Dialog_Item_In_Rect(the_dialog, CHNG_CREATOR, the_point)) return(YES);
- if(Get_Dialog_Item_In_Rect(the_dialog, CHNG_FILE, the_point)) return(YES);
- }
- else if(the_dialog==Pref.dialog)
- {
- if(Pref.menu_id==P_EPTYPE_ITEM)
- {
- if(Get_Dialog_Item_In_Rect(the_dialog, os+P_PT_CT, the_point)) return(YES);
- if(Get_Dialog_Item_In_Rect(the_dialog, os+P_PT_FT, the_point)) return(YES);
- if(Get_Dialog_Item_In_Rect(the_dialog, os+P_PT_DS, the_point)) return(YES);
- }
- else if(Pref.menu_id==P_EATYPE_ITEM)
- {
- if(Get_Dialog_Item_In_Rect(the_dialog, os+P_AC_CHFT, the_point)) return(YES);
- if(Get_Dialog_Item_In_Rect(the_dialog, os+P_AC_CTCT, the_point)) return(YES);
- if(Get_Dialog_Item_In_Rect(the_dialog, os+P_AC_CTFT, the_point)) return(YES);
- }
- }
- return(NO);
-
- }
-
-
-
- /**********************************************************************
- * Function Handle_Key_Down(), this function handles any key down event
- * when any of the dialog boxes are open.
- **********************************************************************/
-
- void Handle_Key_Down(EventRecord *the_event)
- {
-
- static char key_pressed;
- short os=Pref.num_items;
- DialogRef the_dialog=FrontWindow();
-
- key_pressed=the_event->message & charCodeMask;
- if(!(the_event->modifiers & cmdKey))
- {
- if(the_dialog==Chng.dialog) switch(key_pressed)
- {
- case Escape_Key:
- Handle_Key_Pressed(Chng.dialog, CHNG_CANCEL);
- Switch_Chng_Dialog(&Chng, CHNG_CANCEL);
- break;
- case Return_Key:
- case Enter_Key:
- Handle_Key_Pressed(Chng.dialog, CHNG_OK);
- Switch_Chng_Dialog(&Chng, CHNG_OK);
- break;
- default:
- {
- short the_item;
-
- DialogSelect(the_event, &the_dialog, &the_item);
- }
- break;
- }
- else if(the_dialog==About.dialog || the_dialog==Pref.dialog) switch(key_pressed)
- {
- case Escape_Key:
- case Return_Key:
- case Enter_Key:
- if(the_dialog==About.dialog)
- {
- Handle_Key_Pressed(About.dialog, ABOUT_OK);
- Switch_Abot_Dialog(&About, ABOUT_OK);
- }
- else if(the_dialog==Pref.dialog)
- {
- Handle_Key_Pressed(Pref.dialog, PREF_DONE);
- Switch_Pref_Dialog(&Pref, PREF_DONE);
- }
- break;
- default:
- {
- short the_item;
-
- DialogSelect(the_event, &the_dialog, &the_item);
- }
- break;
- }
- PT_Item_To_Edit=AC_Item_To_Edit=0;
- }
- else if(the_event->modifiers & cmdKey)
- if(!Handle_Menu_Choice(MenuKey(key_pressed))) Do_DLOG_Cmd_Key(the_dialog, key_pressed);
-
- }
-
-
-
- /**********************************************************************
- * Function Do_DLOG_Cmd_Key(), this function handles a command key
- * event for any of the open dialogs.
- **********************************************************************/
-
- void Do_DLOG_Cmd_Key(DialogRef the_dialog, char key_pressed)
- {
-
- short os=Pref.num_items;
-
- if(the_dialog==Chng.dialog) switch(key_pressed)
- {
- case 'M':
- case 'm':
- Handle_Key_Pressed(Chng.dialog, CHNG_MKLK);
- Switch_Chng_Dialog(&Chng, CHNG_MKLK);
- break;
- case '.':
- Handle_Key_Pressed(Chng.dialog, CHNG_CANCEL);
- Switch_Chng_Dialog(&Chng, CHNG_CANCEL);
- break;
- }
- else if(the_dialog==Pref.dialog)
- {
- if(Pref.menu_id==P_EPTYPE_ITEM) switch(key_pressed)
- {
- case 'D':
- case 'd':
- Handle_Key_Pressed(Pref.dialog, os+P_PT_DEL);
- Switch_Pt_Dialog(&Pref, os+P_PT_DEL);
- break;
- case 'A':
- case 'a':
- Handle_Key_Pressed(Pref.dialog, os+P_PT_ADD);
- Switch_Pt_Dialog(&Pref, os+P_PT_ADD);
- break;
- case 'G':
- case 'g':
- Handle_Key_Pressed(Pref.dialog, os+P_PT_GFL);
- Switch_Pt_Dialog(&Pref, os+P_PT_GFL);
- break;
- }
- else if(Pref.menu_id==P_EATYPE_ITEM) switch(key_pressed)
- {
- case 'D':
- case 'd':
- Handle_Key_Pressed(Pref.dialog, os+P_AC_DEL);
- Switch_Ac_Dialog(&Pref, os+P_AC_DEL);
- break;
- case 'A':
- case 'a':
- Handle_Key_Pressed(Pref.dialog, os+P_AC_ADD);
- Switch_Ac_Dialog(&Pref, os+P_AC_ADD);
- break;
- case 'G':
- case 'g':
- Handle_Key_Pressed(Pref.dialog, os+P_AC_GFL);
- Switch_Ac_Dialog(&Pref, os+P_AC_GFL);
- break;
- }
- else if(Pref.menu_id==P_GENERL_ITEM) switch(key_pressed)
- {
- case 'E':
- case 'e':
- Handle_Key_Pressed(Pref.dialog, Pref.num_items+P_GN_OKAC);
- Switch_Gnrl_Dialog(&Pref, Pref.num_items+P_GN_OKAC);
- break;
- case 'Q':
- case 'q':
- Handle_Key_Pressed(Pref.dialog, Pref.num_items+P_GN_QADD);
- Switch_Gnrl_Dialog(&Pref, Pref.num_items+P_GN_QADD);
- break;
- }
- }
- PT_Item_To_Edit=AC_Item_To_Edit=0;
-
- }
-
-
-
- /**********************************************************************
- * Function Handle_Apple_Choice(), this function decides what item
- * to execute under the apple menu.
- **********************************************************************/
-
- void Handle_Apple_Choice(short the_item)
- {
-
- short desk_acc_number;
- Str32 desk_acc_name;
-
- switch(the_item)
- {
- case A_ABOUT_ITEM:
- Open_DLOG(&About);
- break;
- default:
- GetMenuItemText(Apple_Menu, the_item, desk_acc_name);
- desk_acc_number=OpenDeskAcc(desk_acc_name);
- break;
- }
-
- }
-
-
-
- /**********************************************************************
- * Function Handle_File_Choice(), this function decides what item
- * to execute under the options menu.
- **********************************************************************/
-
- void Handle_File_Choice(short the_item)
- {
-
- switch(the_item)
- {
- case F_OPEN_ITEM:
- if(Pick_File(&The_File_Spec, &File_Info, TRUE))
- {
- Multiple_Files=NO;
- Chng.num_files=1;
- Open_DLOG(&Chng);
- }
- Maintain_Menu_Items(FrontWindow());
- break;
- case F_PREF_ITEM:
- Open_DLOG(&Pref);
- break;
- case F_QUIT_ITEM:
- All_Done=TRUE;
- break;
- default:
- break;
- }
-
- }
-
-
-
- /**********************************************************************
- * Function Handle_Edit_Choice(), this function decides what item
- * to execute under the edit menu.
- **********************************************************************/
-
- void Handle_Edit_Choice(short the_item)
- {
-
- DialogRef the_dialog=FrontWindow();
-
- switch(the_item)
- {
- case E_CUT_ITEM:
- HiliteMenu(EDIT_MENU_ID);
- ZeroScrap();
- DialogCopy(the_dialog);
- DialogCut(the_dialog);
- TEToScrap();
- break;
- case E_COPY_ITEM:
- HiliteMenu(EDIT_MENU_ID);
- ZeroScrap();
- DialogCopy(the_dialog);
- TEToScrap();
- break;
- case E_PASTE_ITEM:
- TEFromScrap();
- HiliteMenu(EDIT_MENU_ID);
- DialogPaste(the_dialog);
- break;
- case E_CLEAR_ITEM:
- HiliteMenu(EDIT_MENU_ID);
- DialogDelete(the_dialog);
- break;
- }
- PT_Item_To_Edit=AC_Item_To_Edit=0;
-
- }
-
-
-
- /**********************************************************************
- * Function Handle_Key_Pressed(), this function handels what happens
- * if a key is pressed.
- **********************************************************************/
-
- static void Handle_Key_Pressed(DialogRef the_dialog, short the_item)
- {
-
- Handle item_handle;
- short item_type;
- long delay;
- Rect item_rect;
-
- Get_Dialog_Item_Hndl(the_dialog, the_item, &item_handle);
- HiliteControl((ControlHandle)item_handle, YES);
- Delay(DELAY, &delay);
- HiliteControl((ControlHandle)item_handle, NO);
-
- }
-