home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Creator Changer 2.7 / Code & Resource / Creator Changer.menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-12  |  5.3 KB  |  175 lines  |  [TEXT/KAHL]

  1. /**********************************************************************
  2.  *    This file handles all of the pop-up menu options.  It updates the
  3.  *    menu when needed, and decides what parts were clicked on.
  4.  **********************************************************************/
  5.  
  6. #include    "Creator Changer.h"
  7. #include    "Creator Changer.menu.h"
  8.  
  9.  
  10. /**********************************************************************
  11.  *    Function Handle_pop_up_menu(), this function handles the events
  12.  *    given to the prefered types pop-up menu.
  13.  **********************************************************************/
  14.  
  15. void Handle_Pt_Pop_Up(DialogPtr the_dialog, short menu_id, short creator, short file, short description)
  16.     {
  17.     
  18.     Handle        creator_handle, file_handle, desc_handle, menu_handle;
  19.     short        item_type, the_choice, the_item;
  20.     Rect        creator_rect, file_rect, the_rect;
  21.     pref_types    rsrc_handle;
  22.     Str32        description_type;
  23.     Str4        creator_type, file_type;
  24.     
  25.     GetDItem(the_dialog, menu_id, &the_item, &menu_handle, &the_rect);
  26.     
  27.     the_choice=GetCtlValue((ControlHandle)menu_handle);
  28.     if(the_choice)
  29.         {
  30.         UseResFile(CreatorChangerPref);
  31.             rsrc_handle=**(pref_types **)GetResource(PREF_PT, The_pt_Type[the_choice]);
  32.             if(description) p_Str_Copy(rsrc_handle.Description, description_type);
  33.             p_Str_Copy(rsrc_handle.CreatorType, creator_type);
  34.             p_Str_Copy(rsrc_handle.FileType, file_type);
  35.             ReleaseResource((Handle)&rsrc_handle);
  36.         UseResFile(CreatorChangerApp);
  37.         
  38.         if(description)
  39.             {
  40.             GetDItem(the_dialog, description, &item_type, &desc_handle, &file_rect);
  41.             SetIText(desc_handle, description_type);
  42.             }
  43.         
  44.         GetDItem(the_dialog, creator, &item_type, &creator_handle, &creator_rect);
  45.         SetIText(creator_handle, creator_type);
  46.     
  47.         GetDItem(the_dialog, file, &item_type, &file_handle, &file_rect);
  48.         SetIText(file_handle, file_type);
  49.         }
  50.     (**(ControlHandle)menu_handle).contrlValue=0;
  51.     if(!description) Draw1Control((ControlHandle)menu_handle);
  52.     PT_Item_To_Edit=the_choice;
  53.         
  54.     }
  55.  
  56.  
  57.  
  58. /**********************************************************************
  59.  *    Function Make_Pop_Up_Menu(), this function makes the pop-up menu
  60.  *    for the prefered types menu.
  61.  **********************************************************************/
  62.  
  63. void Make_Pop_Up_Menu(short ID, OSType the_type, short num)
  64.     {
  65.     
  66.     short        item;
  67.     MenuHandle    menu_handle;
  68.     pref_types    rsrc_handle_pt;
  69.     auto_chng    rsrc_handle_ac;
  70.     
  71.     menu_handle=GetMenu(ID);
  72.     DisposeMenu(menu_handle);
  73.     
  74.     menu_handle=GetMenu(ID);
  75.     UseResFile(CreatorChangerPref);
  76.         for(item=0;item<num;item++)
  77.             {
  78.             if(the_type==PREF_PT)
  79.                 {
  80.                 The_pt_Type[item+1]=item+Strt_Rsrc;
  81.                 rsrc_handle_pt=**(pref_types **)GetResource(the_type, item+128);
  82.                 InsMenuItem(menu_handle, rsrc_handle_pt.Description, item);
  83.                 ReleaseResource((Handle)&rsrc_handle_pt);
  84.                 }
  85.             else if(the_type==PREF_AC)
  86.                 {
  87.                 The_ac_Type[item+1]=item+Strt_Rsrc;
  88.                 rsrc_handle_ac=**(auto_chng **)GetResource(PREF_AC, item+128);
  89.                 InsMenuItem(menu_handle, rsrc_handle_ac.Name, item);
  90.                 ReleaseResource((Handle)&rsrc_handle_ac);
  91.                 }
  92.             }
  93.     UseResFile(CreatorChangerApp);
  94.     
  95.     }
  96.  
  97.  
  98.  
  99. /**********************************************************************
  100.  *    Function Handle_Ac_Pop_Up(), this function handles the events
  101.  *    given to the auto change pop-up menu.
  102.  **********************************************************************/
  103.  
  104. void Handle_Ac_Pop_Up(DialogPtr the_dialog, short menu_id, short from_file_id, short to_creator_id, short to_file_id)
  105.     {
  106.     
  107.     Handle        the_handle, menu_handle;
  108.     short        the_type, the_choice, the_item;
  109.     Rect        the_rect;
  110.     auto_chng    rsrc_handle;
  111.     Str16        name;
  112.     Str4        from_file, to_creator, to_file;
  113.     
  114.     GetDItem(the_dialog, menu_id, &the_item, &menu_handle, &the_rect);
  115.     
  116.     the_choice=GetCtlValue((ControlHandle)menu_handle);
  117.     if(the_choice)
  118.         {
  119.         UseResFile(CreatorChangerPref);
  120.             rsrc_handle=**(auto_chng **)GetResource(PREF_AC, The_ac_Type[the_choice]);
  121.             p_Str_Copy(rsrc_handle.FromFile,  from_file);
  122.             p_Str_Copy(rsrc_handle.ToCreator, to_creator);
  123.             p_Str_Copy(rsrc_handle.ToFile,       to_file);
  124.             ReleaseResource((Handle)&rsrc_handle);
  125.         UseResFile(CreatorChangerApp);
  126.         
  127.         GetDItem(the_dialog, from_file_id, &the_type, &the_handle, &the_rect);
  128.         SetIText(the_handle, from_file);
  129.         
  130.         GetDItem(the_dialog, to_creator_id, &the_type, &the_handle, &the_rect);
  131.         SetIText(the_handle, to_creator);
  132.     
  133.         GetDItem(the_dialog, to_file_id, &the_type, &the_handle, &the_rect);
  134.         SetIText(the_handle, to_file);
  135.         }
  136.     (**(ControlHandle)menu_handle).contrlValue=0;
  137.     Draw1Control((ControlHandle)menu_handle);
  138.     AC_Item_To_Edit=the_choice;
  139.         
  140.     }
  141.  
  142.  
  143.  
  144. /**********************************************************************
  145.  *    Function Maintain_Menu_Items(), this function 
  146.  **********************************************************************/
  147.     
  148. void Maintain_Menu_Items(DialogPtr the_dialog)
  149.     {
  150.     
  151.     if(the_dialog!=NIL_PTR)
  152.         {
  153.         if(the_dialog==Chng.dialog || the_dialog==Edit.dialog || the_dialog== Auto.dialog || the_dialog==Pref.dialog)
  154.             {
  155.             EnableItem(Apple_Menu, ENTIRE_MENU);
  156.             DisableItem(File_Menu, ENTIRE_MENU);
  157.             EnableItem(Edit_Menu, ENTIRE_MENU);
  158.             }
  159.         else if(the_dialog==About.dialog)
  160.             {
  161.             DisableItem(Apple_Menu, ENTIRE_MENU);
  162.             DisableItem(Edit_Menu, ENTIRE_MENU);
  163.             DisableItem(File_Menu, ENTIRE_MENU);
  164.             }
  165.         }
  166.     else if(the_dialog==NIL_PTR)
  167.         {
  168.         EnableItem(Apple_Menu, ENTIRE_MENU);
  169.         EnableItem(File_Menu, ENTIRE_MENU);
  170.         DisableItem(Edit_Menu, ENTIRE_MENU);
  171.         }
  172.  
  173.     DrawMenuBar();
  174.     
  175.     }