home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / DCLAP 4j / vibrant / vibmenus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-17  |  123.7 KB  |  5,203 lines  |  [TEXT/R*ch]

  1. /*   vibmenus.c
  2. * ===========================================================================
  3. *
  4. *                            PUBLIC DOMAIN NOTICE
  5. *            National Center for Biotechnology Information (NCBI)
  6. *
  7. *  This software/database is a "United States Government Work" under the
  8. *  terms of the United States Copyright Act.  It was written as part of
  9. *  the author's official duties as a United States Government employee and
  10. *  thus cannot be copyrighted.  This software/database is freely available
  11. *  to the public for use. The National Library of Medicine and the U.S.
  12. *  Government do not place any restriction on its use or reproduction.
  13. *  We would, however, appreciate having the NCBI and the author cited in
  14. *  any work or product based on this material
  15. *
  16. *  Although all reasonable efforts have been taken to ensure the accuracy
  17. *  and reliability of the software and data, the NLM and the U.S.
  18. *  Government do not and cannot warrant the performance or results that
  19. *  may be obtained by using this software or data. The NLM and the U.S.
  20. *  Government disclaim all warranties, express or implied, including
  21. *  warranties of performance, merchantability or fitness for any particular
  22. *  purpose.
  23. *
  24. * ===========================================================================
  25. *
  26. * File Name:  vibmenus.c
  27. *
  28. * Author:  Jonathan Kans
  29. *
  30. * Version Creation Date:   7/1/91
  31. *
  32. * $Revision: 2.17 $
  33. *
  34. * File Description: 
  35. *       Vibrant menu functions
  36. *
  37. * Modifications:  
  38. * --------------------------------------------------------------------------
  39. * Date     Name        Description of modification
  40. * -------  ----------  -----------------------------------------------------
  41. *
  42. *
  43. * ==========================================================================
  44. */
  45.  
  46. #include <vibtypes.h>
  47. #include <vibprocs.h>
  48. #include <vibincld.h>
  49.  
  50. #ifdef WIN_MAC
  51. #define Nlm_MenuTool   MenuHandle
  52. #define Nlm_PopupTool  Nlm_Handle
  53. #define Nlm_ItemTool   Nlm_Handle
  54. #endif
  55.  
  56. #ifdef WIN_MSWIN
  57. #define Nlm_MenuTool   HMENU
  58. #define Nlm_PopupTool  HWND
  59. #define Nlm_ItemTool   Nlm_Handle
  60. #endif
  61.  
  62. #ifdef WIN_MOTIF
  63. #define Nlm_MenuTool   Widget
  64. #define Nlm_PopupTool  Widget
  65. #define Nlm_ItemTool   Widget
  66. #endif
  67.  
  68. typedef  struct  Nlm_menudata {
  69.   Nlm_MenuTool   handle;
  70.   Nlm_PrompT     prompt;
  71.   Nlm_Int2       menuTag;
  72.   Nlm_PopupTool  popup;
  73. } Nlm_MenuData;
  74.  
  75. typedef  struct  Nlm_menurec {
  76.   Nlm_GraphicRec  graphicR;
  77.   Nlm_MenuData    menu;
  78. } Nlm_MenuRec, PNTR Nlm_MenPtr;
  79.  
  80. typedef  struct  Nlm_itemdata {
  81.   Nlm_MenU      subMenu;
  82.   Nlm_Int2      firstItem;
  83.   Nlm_ItemTool  handle;
  84. } Nlm_ItemData;
  85.  
  86. typedef  struct  Nlm_itemrec {
  87.   Nlm_GraphicRec  graphicR;
  88.   Nlm_ItemData    item;
  89. } Nlm_ItemRec, PNTR Nlm_ItmPtr;
  90.  
  91. typedef  struct  Nlm_choicedata {
  92.   Nlm_Int2     numItems;
  93.   Nlm_Boolean  isAPopupList;
  94.   Nlm_Int2     popupValue;
  95.   Nlm_ItemTool PNTR handles;
  96. } Nlm_ChoiceData;
  97.  
  98. typedef  struct  Nlm_choicerec {
  99.   Nlm_ItemRec     itemR;
  100.   Nlm_ChoiceData  choice;
  101. } Nlm_ChoiceRec, PNTR Nlm_ChsPtr;
  102.  
  103. typedef  struct  Nlm_menubardata {
  104.   Nlm_MenuTool  handle;
  105. } Nlm_MenuBarData;
  106.  
  107. typedef  struct  Nlm_menubarrec {
  108.   Nlm_BoxRec       boxR;
  109.   Nlm_MenuBarData  menubar;
  110. } Nlm_MenuBarRec, PNTR Nlm_MbrPtr;
  111.  
  112. static Nlm_GphPrcsPtr   gphprcsptr = NULL;
  113.  
  114. #ifdef WIN_MAC
  115. static Nlm_GphPrcsPtr   desktopMenuBarProcs;
  116. static Nlm_GphPrcsPtr   desktopPulldownProcs;
  117. #endif
  118. static Nlm_GphPrcsPtr   windowMenuBarProcs;
  119. static Nlm_GphPrcsPtr   windowPulldownProcs;
  120. static Nlm_GphPrcsPtr   popupProcs;
  121. static Nlm_GphPrcsPtr   subMenuProcs;
  122. static Nlm_GphPrcsPtr   subItemProcs;
  123. static Nlm_GphPrcsPtr   commandItemProcs;
  124. static Nlm_GphPrcsPtr   statusItemProcs;
  125. static Nlm_GphPrcsPtr   choiceGroupProcs;
  126. static Nlm_GphPrcsPtr   choiceItemProcs;
  127. static Nlm_GphPrcsPtr   macPopListProcs;
  128. static Nlm_GphPrcsPtr   msPopListProcs;
  129. static Nlm_GphPrcsPtr   popUpChoiceProcs;
  130. static Nlm_GphPrcsPtr   daProcs;
  131.  
  132. static Nlm_MenU         recentMenu = NULL;
  133. static Nlm_MenuData     recentMenuData;
  134.  
  135. static Nlm_IteM         recentItem = NULL;
  136. static Nlm_ItemData     recentItemData;
  137.  
  138. static Nlm_ChoicE       recentChoice = NULL;
  139. static Nlm_ChoiceData   recentChoiceData;
  140.  
  141. static Nlm_MenuBaR      recentMenuBar = NULL;
  142. static Nlm_MenuBarData  recentMenuBarData;
  143.  
  144. static Nlm_Int2         nextMenuNum = 1;
  145.  
  146. #ifdef WIN_MAC
  147. static Nlm_Int2         currentItemNum = 0;
  148. static Nlm_Int2         currentMenuNum = 0;
  149. static Nlm_Int2         currentMenuTag = 0;
  150. #endif
  151.  
  152. #ifdef WIN_MSWIN
  153. static Nlm_Int2         currentItemID = 0;
  154. static WNDPROC          lpfnNewPopupProc = NULL;
  155. static WNDPROC          lpfnOldPopupProc = NULL;
  156. static Nlm_Boolean      handlechar;
  157. #endif
  158.  
  159. #ifdef WIN_MOTIF
  160. static Widget           choiceWidget = NULL;
  161. #endif
  162.  
  163. static void Nlm_LoadMenuData (Nlm_MenU m, Nlm_MenuTool hdl,
  164.                               Nlm_PrompT ppt, Nlm_Int2 tag,
  165.                               Nlm_PopupTool pup)
  166.  
  167. {
  168.   Nlm_MenuData  PNTR mdptr;
  169.   Nlm_MenPtr    mp;
  170.  
  171.   if (m != NULL) {
  172.     mp = (Nlm_MenPtr) Nlm_HandLock (m);
  173.     mdptr = &(mp->menu);
  174.     mdptr->handle = hdl;
  175.     mdptr->prompt = ppt;
  176.     mdptr->menuTag = tag;
  177.     mdptr->popup = pup;
  178.     Nlm_HandUnlock (m);
  179.     recentMenu = NULL;
  180.   }
  181. }
  182.  
  183. static void Nlm_SetMenuData (Nlm_MenU m, Nlm_MenuData * mdata)
  184.  
  185. {
  186.   Nlm_MenPtr  mp;
  187.  
  188.   if (m != NULL && mdata != NULL) {
  189.     mp = (Nlm_MenPtr) Nlm_HandLock (m);
  190.     mp->menu = *mdata;
  191.     Nlm_HandUnlock (m);
  192.     recentMenu = m;
  193.     recentMenuData = *mdata;
  194.   }
  195. }
  196.  
  197. static void Nlm_GetMenuData (Nlm_MenU m, Nlm_MenuData * mdata)
  198.  
  199. {
  200.   Nlm_MenPtr  mp;
  201.  
  202.   if (m != NULL && mdata != NULL) {
  203.     if (m == recentMenu && NLM_RISKY) {
  204.       *mdata = recentMenuData;
  205.     } else {
  206.       mp = (Nlm_MenPtr) Nlm_HandLock (m);
  207.       *mdata = mp->menu;
  208.       Nlm_HandUnlock (m);
  209.       recentMenu = m;
  210.       recentMenuData = *mdata;
  211.     }
  212.   }
  213. }
  214.  
  215. static void Nlm_LoadItemData (Nlm_IteM i, Nlm_MenU sub,
  216.                               Nlm_Int2 frst, Nlm_ItemTool hdl)
  217.  
  218. {
  219.   Nlm_ItemData  PNTR idptr;
  220.   Nlm_ItmPtr   ip;
  221.  
  222.   if (i != NULL) {
  223.     ip = (Nlm_ItmPtr) Nlm_HandLock (i);
  224.     idptr = &(ip->item);
  225.     idptr->subMenu = sub;
  226.     idptr->firstItem = frst;
  227.     idptr->handle = hdl;
  228.     Nlm_HandUnlock (i);
  229.     recentItem = NULL;
  230.   }
  231. }
  232.  
  233. static void Nlm_SetItemData (Nlm_IteM i, Nlm_ItemData * idata)
  234.  
  235. {
  236.   Nlm_ItmPtr  ip;
  237.  
  238.   if (i != NULL && idata != NULL) {
  239.     ip = (Nlm_ItmPtr) Nlm_HandLock (i);
  240.     ip->item = *idata;
  241.     Nlm_HandUnlock (i);
  242.     recentItem = i;
  243.     recentItemData = *idata;
  244.   }
  245. }
  246.  
  247. static void Nlm_GetItemData (Nlm_IteM i, Nlm_ItemData * idata)
  248.  
  249. {
  250.   Nlm_ItmPtr  ip;
  251.  
  252.   if (i != NULL && idata != NULL) {
  253.     if (i == recentItem && NLM_RISKY) {
  254.       *idata = recentItemData;
  255.     } else {
  256.       ip = (Nlm_ItmPtr) Nlm_HandLock (i);
  257.       *idata = ip->item;
  258.       Nlm_HandUnlock (i);
  259.       recentItem = i;
  260.       recentItemData = *idata;
  261.     }
  262.   }
  263. }
  264.  
  265. static void Nlm_LoadChoiceData (Nlm_ChoicE c, Nlm_Int2 num,
  266.                                 Nlm_Boolean plist, Nlm_Int2 pval,
  267.                                 Nlm_ItemTool PNTR hdls)
  268.  
  269. {
  270.   Nlm_ChoiceData  PNTR cdptr;
  271.   Nlm_ChsPtr      cp;
  272.  
  273.   if (c != NULL) {
  274.     cp = (Nlm_ChsPtr) Nlm_HandLock (c);
  275.     cdptr = &(cp->choice);
  276.     cdptr->numItems = num;
  277.     cdptr->isAPopupList = plist;
  278.     cdptr->popupValue = pval;
  279.     cdptr->handles = hdls;
  280.     Nlm_HandUnlock (c);
  281.     recentChoice = NULL;
  282.   }
  283. }
  284.  
  285. static void Nlm_SetChoiceData (Nlm_ChoicE c, Nlm_ChoiceData * cdata)
  286.  
  287. {
  288.   Nlm_ChsPtr  cp;
  289.  
  290.   if (c != NULL && cdata != NULL) {
  291.     cp = (Nlm_ChsPtr) Nlm_HandLock (c);
  292.     cp->choice = *cdata;
  293.     Nlm_HandUnlock (c);
  294.     recentChoice = c;
  295.     recentChoiceData = *cdata;
  296.   }
  297. }
  298.  
  299. static void Nlm_GetChoiceData (Nlm_ChoicE c, Nlm_ChoiceData * cdata)
  300.  
  301. {
  302.   Nlm_ChsPtr  cp;
  303.  
  304.   if (c != NULL && cdata != NULL) {
  305.     if (c == recentChoice && NLM_RISKY) {
  306.       *cdata = recentChoiceData;
  307.     } else {
  308.       cp = (Nlm_ChsPtr) Nlm_HandLock (c);
  309.       *cdata = cp->choice;
  310.       Nlm_HandUnlock (c);
  311.       recentChoice = c;
  312.       recentChoiceData = *cdata;
  313.     }
  314.   }
  315. }
  316.  
  317. static void Nlm_LoadMenuBarData (Nlm_MenuBaR mb, Nlm_MenuTool hdl)
  318.  
  319. {
  320.   Nlm_MenuBarData  PNTR mbptr;
  321.   Nlm_MbrPtr       mbp;
  322.  
  323.   if (mb != NULL) {
  324.     mbp = (Nlm_MbrPtr) Nlm_HandLock (mb);
  325.     mbptr = &(mbp->menubar);
  326.     mbptr->handle = hdl;
  327.     Nlm_HandUnlock (mb);
  328.     recentMenuBar = NULL;
  329.   }
  330. }
  331.  
  332. static void Nlm_SetMenuBarData (Nlm_MenuBaR mb, Nlm_MenuBarData * mbdata)
  333.  
  334. {
  335.   Nlm_MbrPtr  mbp;
  336.  
  337.   if (mb != NULL && mbdata != NULL) {
  338.     mbp = (Nlm_MbrPtr) Nlm_HandLock (mb);
  339.     mbp->menubar = *mbdata;
  340.     Nlm_HandUnlock (mb);
  341.     recentMenuBar = mb;
  342.     recentMenuBarData = *mbdata;
  343.   }
  344. }
  345.  
  346. static void Nlm_GetMenuBarData (Nlm_MenuBaR mb, Nlm_MenuBarData * mbdata)
  347.  
  348. {
  349.   Nlm_MbrPtr  mbp;
  350.  
  351.   if (mb != NULL && mbdata != NULL) {
  352.     if (mb == recentMenuBar && NLM_RISKY) {
  353.       *mbdata = recentMenuBarData;
  354.     } else {
  355.       mbp = (Nlm_MbrPtr) Nlm_HandLock (mb);
  356.       *mbdata = mbp->menubar;
  357.       Nlm_HandUnlock (mb);
  358.       recentMenuBar = mb;
  359.       recentMenuBarData = *mbdata;
  360.     }
  361.   }
  362. }
  363.  
  364. static Nlm_MenuTool Nlm_GetMenuHandle (Nlm_MenU m)
  365.  
  366. {
  367.   Nlm_MenuData  mdata;
  368.  
  369.   Nlm_GetMenuData (m, &mdata);
  370.   return mdata.handle;
  371. }
  372.  
  373. static Nlm_PrompT Nlm_GetMenuPrompt (Nlm_MenU m)
  374.  
  375. {
  376.   Nlm_MenuData  mdata;
  377.  
  378.   Nlm_GetMenuData (m, &mdata);
  379.   return mdata.prompt;
  380. }
  381.  
  382. static Nlm_Int2 Nlm_GetMenuTag (Nlm_MenU m)
  383.  
  384. {
  385.   Nlm_MenuData  mdata;
  386.  
  387.   Nlm_GetMenuData (m, &mdata);
  388.   return mdata.menuTag;
  389. }
  390.  
  391. static void Nlm_SetMenuPopup (Nlm_MenU m, Nlm_PopupTool pop)
  392.  
  393. {
  394.   Nlm_MenuData  mdata;
  395.  
  396.   Nlm_GetMenuData (m, &mdata);
  397.   mdata.popup = pop;
  398.   Nlm_SetMenuData (m, &mdata);
  399. }
  400.  
  401. static Nlm_PopupTool Nlm_GetMenuPopup (Nlm_MenU m)
  402.  
  403. {
  404.   Nlm_MenuData  mdata;
  405.  
  406.   Nlm_GetMenuData (m, &mdata);
  407.   return mdata.popup;
  408. }
  409.  
  410. static void Nlm_SetSubMenu (Nlm_IteM i, Nlm_MenU sub)
  411.  
  412. {
  413.   Nlm_ItemData  idata;
  414.  
  415.   Nlm_GetItemData (i, &idata);
  416.   idata.subMenu = sub;
  417.   Nlm_SetItemData (i, &idata);
  418. }
  419.  
  420. static Nlm_MenU Nlm_GetSubMenu (Nlm_IteM i)
  421.  
  422. {
  423.   Nlm_ItemData  idata;
  424.  
  425.   Nlm_GetItemData (i, &idata);
  426.   return idata.subMenu;
  427. }
  428.  
  429. static Nlm_Int2 Nlm_GetFirstItem (Nlm_IteM i)
  430.  
  431. {
  432.   Nlm_ItemData  idata;
  433.  
  434.   Nlm_GetItemData (i, &idata);
  435.   return idata.firstItem;
  436. }
  437.  
  438. static Nlm_ItemTool Nlm_GetItemHandle (Nlm_IteM i)
  439.  
  440. {
  441.   Nlm_ItemData  idata;
  442.  
  443.   Nlm_GetItemData (i, &idata);
  444.   return idata.handle;
  445. }
  446.  
  447. static void Nlm_SetNumItems (Nlm_ChoicE c, Nlm_Int2 num)
  448.  
  449. {
  450.   Nlm_ChoiceData  cdata;
  451.  
  452.   Nlm_GetChoiceData (c, &cdata);
  453.   cdata.numItems = num;
  454.   Nlm_SetChoiceData (c, &cdata);
  455. }
  456.  
  457. static Nlm_Int2 Nlm_GetNumItems (Nlm_ChoicE c)
  458.  
  459. {
  460.   Nlm_ChoiceData  cdata;
  461.  
  462.   Nlm_GetChoiceData (c, &cdata);
  463.   return cdata.numItems;
  464. }
  465.  
  466. static Nlm_Boolean Nlm_IsItAPopupList (Nlm_ChoicE c)
  467.  
  468. {
  469.   Nlm_ChoiceData  cdata;
  470.  
  471.   Nlm_GetChoiceData (c, &cdata);
  472.   return cdata.isAPopupList;
  473. }
  474.  
  475. static void Nlm_SetPopupValue (Nlm_ChoicE c, Nlm_Int2 pval)
  476.  
  477. {
  478.   Nlm_ChoiceData  cdata;
  479.  
  480.   Nlm_GetChoiceData (c, &cdata);
  481.   cdata.popupValue = pval;
  482.   Nlm_SetChoiceData (c, &cdata);
  483. }
  484.  
  485. static Nlm_Int2 Nlm_GetPopupValue (Nlm_ChoicE c)
  486.  
  487. {
  488.   Nlm_ChoiceData  cdata;
  489.  
  490.   Nlm_GetChoiceData (c, &cdata);
  491.   return cdata.popupValue;
  492. }
  493.  
  494. static void Nlm_SetChoiceHandles (Nlm_ChoicE c, Nlm_ItemTool PNTR hdls)
  495.  
  496. {
  497.   Nlm_ChoiceData  cdata;
  498.  
  499.   Nlm_GetChoiceData (c, &cdata);
  500.   cdata.handles = hdls;
  501.   Nlm_SetChoiceData (c, &cdata);
  502. }
  503.  
  504. static Nlm_ItemTool PNTR Nlm_GetChoiceHandles (Nlm_ChoicE c)
  505.  
  506. {
  507.   Nlm_ChoiceData  cdata;
  508.  
  509.   Nlm_GetChoiceData (c, &cdata);
  510.   return cdata.handles;
  511. }
  512.  
  513. static Nlm_MenuTool Nlm_GetMenuBarHandle (Nlm_MenuBaR mb)
  514.  
  515. {
  516.   Nlm_MenuBarData  mbdata;
  517.  
  518.   Nlm_GetMenuBarData (mb, &mbdata);
  519.   return mbdata.handle;
  520. }
  521.  
  522. static Nlm_Int2 Nlm_ItemToID (Nlm_MenU m, Nlm_Int2 index)
  523.  
  524. {
  525.   Nlm_MenuTool  h;
  526.   Nlm_Int2      rsult;
  527.  
  528.   rsult = 0;
  529. #ifdef WIN_MSWIN
  530.   if (m != NULL && index > 0) {
  531.     h = Nlm_GetMenuHandle (m);
  532.     rsult = GetMenuItemID (h, index - 1);
  533.   }
  534. #endif
  535.   return rsult;
  536. }
  537.  
  538. static Nlm_Boolean Nlm_IsMenuItemChecked (Nlm_MenU m, Nlm_ItemTool itool, Nlm_Int2 item)
  539.  
  540. {
  541.   Nlm_MenuTool  h;
  542.   Nlm_Int2      id;
  543. #ifdef WIN_MAC
  544.   Nlm_Char      mark;
  545.   Nlm_Int2      temp;
  546. #endif
  547.  
  548.   h = Nlm_GetMenuHandle (m);
  549. #ifdef WIN_MAC
  550.   GetItemMark (h, item, &temp);
  551.   mark = (Nlm_Char) temp;
  552.   return (mark != '\0');
  553. #endif
  554. #ifdef WIN_MSWIN
  555.   id = GetMenuItemID (h, item - 1);
  556.   return (Nlm_Boolean) ((LOBYTE (GetMenuState (h, id, MF_BYCOMMAND)) & MF_CHECKED) != 0);
  557. #endif
  558. #ifdef WIN_MOTIF
  559.   return (Nlm_Boolean) (XmToggleButtonGetState (itool) != FALSE);
  560. #endif
  561. }
  562.  
  563. static void Nlm_CheckMenuItem (Nlm_MenU m, Nlm_ItemTool itool,
  564.                                Nlm_Int2 item, Nlm_Boolean check)
  565.  
  566. {
  567.   Nlm_MenuTool  h;
  568.   Nlm_Int2      id;
  569. #ifdef WIN_MAC
  570.   Nlm_Char      ch;
  571. #endif
  572.  
  573.   h = Nlm_GetMenuHandle (m);
  574. #ifdef WIN_MAC
  575.   if (check) {
  576.     ch = '\22';
  577.   }
  578.   else {
  579.     ch = '\0';
  580.   }
  581.   SetItemMark (h, item, ch);
  582. #endif
  583. #ifdef WIN_MSWIN
  584.   id = GetMenuItemID (h, item - 1);
  585.   if (check) {
  586.     CheckMenuItem (h, id, MF_CHECKED);
  587.   } else {
  588.     CheckMenuItem (h, id, MF_UNCHECKED);
  589.   }
  590. #endif
  591. #ifdef WIN_MOTIF
  592.   XmToggleButtonSetState (itool, (Boolean) check, FALSE);
  593. #endif
  594. }
  595.  
  596. #ifdef WIN_MAC
  597. static void Nlm_DeskAccProc (Nlm_ChoicE c)
  598.  
  599. {
  600.   Nlm_MenuTool  h;
  601.   Nlm_MenU      m;
  602.   Nlm_Char      temp [256];
  603.  
  604.   m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
  605.   h = Nlm_GetMenuHandle (m);
  606.   GetItem (h, currentItemNum, (StringPtr) temp);
  607.   OpenDeskAcc ((StringPtr) temp);
  608. }
  609. #endif
  610.  
  611. static void Nlm_ActivateInnerMenus (Nlm_MenU m)
  612.  
  613. {
  614.   Nlm_IteM      i;
  615.   Nlm_MenU      s;
  616. #ifdef WIN_MAC
  617.   Nlm_MenuTool  h;
  618. #endif
  619.  
  620.   i = (Nlm_IteM) Nlm_GetChild ((Nlm_GraphiC) m);
  621.   while (i != NULL) {
  622.     s = Nlm_GetSubMenu (i);
  623.     if (s != NULL) {
  624.       if (Nlm_GetEnabled ((Nlm_GraphiC) s)) {
  625.         Nlm_DoEnable ((Nlm_GraphiC) i, FALSE, FALSE);
  626. #ifdef WIN_MAC
  627.         h = Nlm_GetMenuHandle (s);
  628.         InsertMenu (h, -1);
  629. #endif
  630.         Nlm_ActivateInnerMenus (s);
  631.       }
  632.     }
  633.     i = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
  634.   }
  635. }
  636.  
  637. static void Nlm_DeactivateInnerMenus (Nlm_MenU m)
  638.  
  639. {
  640.   Nlm_IteM  i;
  641.   Nlm_MenU  s;
  642. #ifdef WIN_MAC
  643.   Nlm_Int2  tag;
  644. #endif
  645.  
  646.   i = (Nlm_IteM) Nlm_GetChild ((Nlm_GraphiC) m);
  647.   while (i != NULL) {
  648.     s = Nlm_GetSubMenu (i);
  649.     if (s != NULL) {
  650.       Nlm_DoDisable ((Nlm_GraphiC) i, FALSE, FALSE);
  651. #ifdef WIN_MAC
  652.       tag = Nlm_GetMenuTag (s);
  653.       DeleteMenu (tag);
  654. #endif
  655.       Nlm_DeactivateInnerMenus (s);
  656.     }
  657.     i = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
  658.   }
  659. }
  660.  
  661. #ifdef WIN_MAC
  662. static Nlm_Boolean Nlm_DesktopMenuBarClick (Nlm_GraphiC mb, Nlm_PoinT pt)
  663.  
  664. {
  665.   Nlm_Int4        choice;
  666.   Nlm_PoinT       global;
  667.   Nlm_MenU        m;
  668.   Nlm_MenU        n;
  669.   Nlm_Boolean     notInGraphic;
  670.   Nlm_PointTool   ptool;
  671.   Nlm_Boolean     rsult;
  672.   Nlm_Int2        windowLoc;
  673.   Nlm_WindowTool  wptr;
  674.  
  675.   rsult = FALSE;
  676.   currentMenuNum = 0;
  677.   currentItemNum = 0;
  678.   global = pt;
  679.   Nlm_LocalToGlobal (&global);
  680.   Nlm_PoinTToPointTool (global, &ptool);
  681.   windowLoc = FindWindow (ptool, &wptr);
  682.   if (windowLoc == inMenuBar) {
  683.     choice = MenuSelect (ptool);
  684.     currentMenuNum = HiWord (choice);
  685.     currentItemNum = LoWord (choice);
  686.     m = (Nlm_MenU) Nlm_GetChild (mb);
  687.     notInGraphic = TRUE;
  688.     while (m != NULL && notInGraphic) {
  689.       n = (Nlm_MenU) Nlm_GetNext ((Nlm_GraphiC) m);
  690.       currentMenuTag = Nlm_GetMenuTag (m);
  691.       if (Nlm_GetEnabled ((Nlm_GraphiC) m) && Nlm_GetVisible ((Nlm_GraphiC) m) &&
  692.           Nlm_DoClick ((Nlm_GraphiC) m, pt)) {
  693.         notInGraphic = FALSE;
  694.       }
  695.       m = n;
  696.     }
  697.     rsult = TRUE;
  698.   }
  699.   return rsult;
  700. }
  701.  
  702. static Nlm_Boolean Nlm_WindowMenuBarClick (Nlm_GraphiC mb, Nlm_PoinT pt)
  703.  
  704. {
  705.   Nlm_MenU     m;
  706.   Nlm_MenU     n;
  707.   Nlm_Boolean  notInside;
  708.  
  709.   m = (Nlm_MenU) Nlm_GetChild (mb);
  710.   notInside = TRUE;
  711.   while (m != NULL && notInside) {
  712.     n = (Nlm_MenU) Nlm_GetNext ((Nlm_GraphiC) m);
  713.     currentMenuTag = Nlm_GetMenuTag (m);
  714.     if (Nlm_GetVisible ((Nlm_GraphiC) m) && Nlm_DoClick ((Nlm_GraphiC) m, pt)) {
  715.       notInside = FALSE;
  716.     }
  717.     m = n;
  718.   }
  719.   return (! notInside);
  720. }
  721.  
  722. static Nlm_Boolean Nlm_DesktopMenuClick (Nlm_GraphiC m, Nlm_PoinT pt)
  723.  
  724. {
  725.   Nlm_IteM     i;
  726.   Nlm_Boolean  notInMenu;
  727.   Nlm_IteM     n;
  728.   Nlm_Boolean  rsult;
  729.   Nlm_Int2     tag;
  730.  
  731.   rsult = FALSE;
  732.   tag = Nlm_GetMenuTag ((Nlm_MenU) m);
  733.   if (currentMenuNum > 0 && currentMenuNum == tag) {
  734.     i = (Nlm_IteM) Nlm_GetChild (m);
  735.     notInMenu = TRUE;
  736.     while (i != NULL && notInMenu) {
  737.       n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
  738.       if (Nlm_GetEnabled ((Nlm_GraphiC) i) && Nlm_GetVisible ((Nlm_GraphiC) i) &&
  739.           Nlm_DoClick ((Nlm_GraphiC) i, pt)) {
  740.         notInMenu = FALSE;
  741.       }
  742.       i = n;
  743.     }
  744.     HiliteMenu (0);
  745.     currentMenuNum = 0;
  746.     rsult = TRUE;
  747.   }
  748.   return rsult;
  749. }
  750.  
  751. static void Nlm_PopupAPopupList (Nlm_GraphiC m, Nlm_PoinT pt,
  752.                                  Nlm_RectPtr r, Nlm_PoinT pop,
  753.                                  Nlm_Int2 item)
  754.  
  755. {
  756.   Nlm_Int4      choice;
  757.   Nlm_MenuTool  h;
  758.   Nlm_IteM      i;
  759.   Nlm_IteM      n;
  760.   Nlm_WindoW    newwindow;
  761.   Nlm_Boolean   notInMenu;
  762.   Nlm_WindoW    oldwindow;
  763.  
  764.   oldwindow = Nlm_CurrentWindow ();
  765.   newwindow = Nlm_GetParentWindow (m);
  766.   Nlm_InvertRect (r);
  767.   h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  768.   choice = PopUpMenuSelect (h, pop.y, pop.x, item);
  769.   currentMenuNum = HiWord (choice);
  770.   currentItemNum = LoWord (choice);
  771.   currentMenuTag = Nlm_GetMenuTag ((Nlm_MenU) m);
  772.   i = (Nlm_IteM) Nlm_GetChild (m);
  773.   notInMenu = TRUE;
  774.   while (i != NULL && notInMenu) {
  775.     n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
  776.     if (Nlm_GetEnabled ((Nlm_GraphiC) i) && Nlm_GetVisible ((Nlm_GraphiC) i) &&
  777.         Nlm_DoClick ((Nlm_GraphiC) i, pt)) {
  778.       notInMenu = FALSE;
  779.     }
  780.     i = n;
  781.   }
  782.   currentMenuNum = 0;
  783.   Nlm_UseWindow (newwindow);
  784.   Nlm_EraseRect (r);
  785.   Nlm_InvalRect (r);
  786.   Nlm_Update ();
  787.   Nlm_UseWindow (oldwindow);
  788. }
  789.  
  790. static Nlm_Boolean Nlm_PopupClick (Nlm_GraphiC m, Nlm_PoinT pt)
  791.  
  792. {
  793.   Nlm_MenuTool  h;
  794.   Nlm_PrompT    p;
  795.   Nlm_PoinT     pop;
  796.   Nlm_RecT      r;
  797.   Nlm_Boolean   rsult;
  798.   Nlm_Int2      tag;
  799.  
  800.   rsult = FALSE;
  801.   p = Nlm_GetMenuPrompt ((Nlm_MenU) m);
  802.   Nlm_GetRect ((Nlm_GraphiC) p, &r);
  803.   if (Nlm_PtInRect (pt, &r)) {
  804.     h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  805.     InsertMenu (h, -1);
  806.     currentMenuNum = 0;
  807.     currentItemNum = 0;
  808.     pop.x = r.left;
  809.     pop.y = r.bottom + 1;
  810.     Nlm_LocalToGlobal (&pop);
  811.     Nlm_PopupAPopupList (m, pt, &r, pop, 0);
  812.     tag = Nlm_GetMenuTag ((Nlm_MenU) m);
  813.     DeleteMenu (tag);
  814.     rsult = TRUE;
  815.   }
  816.   return rsult;
  817. }
  818.  
  819. static Nlm_Boolean Nlm_PulldownClick (Nlm_GraphiC m, Nlm_PoinT pt)
  820.  
  821. {
  822.   Nlm_MenuTool  h;
  823.   Nlm_PoinT     pop;
  824.   Nlm_RecT      r;
  825.   Nlm_Boolean   rsult;
  826.   Nlm_Int2      tag;
  827.  
  828.   rsult = FALSE;
  829.   Nlm_GetRect (m, &r);
  830.   Nlm_InsetRect (&r, 0, 2);
  831.   if (Nlm_PtInRect (pt, &r)) {
  832.     h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  833.     InsertMenu (h, -1);
  834.     currentMenuNum = 0;
  835.     currentItemNum = 0;
  836.     Nlm_GetRect (m, &r);
  837.     Nlm_InsetRect (&r, -6, 0);
  838.     r.top++;
  839.     pop.x = r.left + 1;
  840.     pop.y = r.bottom;
  841.     Nlm_LocalToGlobal (&pop);
  842.     Nlm_PopupAPopupList (m, pt, &r, pop, 0);
  843.     tag = Nlm_GetMenuTag ((Nlm_MenU) m);
  844.     DeleteMenu (tag);
  845.     rsult = TRUE;
  846.   }
  847.   return rsult;
  848. }
  849.  
  850. static Nlm_Boolean Nlm_MacPopListClick (Nlm_GraphiC m, Nlm_PoinT pt)
  851.  
  852. {
  853.   Nlm_ChoicE    c;
  854.   Nlm_MenuTool  h;
  855.   Nlm_Int2      item;
  856.   Nlm_PoinT     pop;
  857.   Nlm_RecT      r;
  858.   Nlm_Boolean   rsult;
  859.   Nlm_Int2      tag;
  860.  
  861.   rsult = FALSE;
  862.   Nlm_GetRect (m, &r);
  863.   Nlm_InsetRect (&r, 2, 3);
  864.   if (Nlm_PtInRect (pt, &r)) {
  865.     h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  866.     InsertMenu (h, -1);
  867.     currentMenuNum = 0;
  868.     currentItemNum = 0;
  869.     item = 0;
  870.     c = (Nlm_ChoicE) Nlm_GetChild (m);
  871.     if (c != NULL) {
  872.       item = Nlm_DoGetValue ((Nlm_GraphiC) c);
  873.     }
  874.     Nlm_GetRect (m, &r);
  875.     pop.x = r.left + 1;
  876.     pop.y = r.top + 1;
  877.     Nlm_UpsetRect (&r, 1, 1, 2, 2);
  878.     Nlm_LocalToGlobal (&pop);
  879.     Nlm_PopupAPopupList (m, pt, &r, pop, item);
  880.     tag = Nlm_GetMenuTag ((Nlm_MenU) m);
  881.     DeleteMenu (tag);
  882.     rsult = TRUE;
  883.   }
  884.   return rsult;
  885. }
  886.  
  887. static Nlm_Boolean Nlm_MSPopListClick (Nlm_GraphiC m, Nlm_PoinT pt)
  888.  
  889. {
  890.   Nlm_MenuTool  h;
  891.   Nlm_PoinT     pop;
  892.   Nlm_RecT      r;
  893.   Nlm_Boolean   rsult;
  894.   Nlm_Int2      tag;
  895.  
  896.   rsult = FALSE;
  897.   Nlm_GetRect (m, &r);
  898.   Nlm_InsetRect (&r, 2, 2);
  899.   if (Nlm_PtInRect (pt, &r)) {
  900.     h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  901.     InsertMenu (h, -1);
  902.     currentMenuNum = 0;
  903.     currentItemNum = 0;
  904.     Nlm_GetRect (m, &r);
  905.     pop.x = r.left + 1;
  906.     pop.y = r.bottom - 1;
  907.     Nlm_UpsetRect (&r, 1, 1, 2, 2);
  908.     Nlm_LocalToGlobal (&pop);
  909.     Nlm_PopupAPopupList (m, pt, &r, pop, 0);
  910.     tag = Nlm_GetMenuTag ((Nlm_MenU) m);
  911.     DeleteMenu (tag);
  912.     rsult = TRUE;
  913.   }
  914.   return rsult;
  915. }
  916.  
  917. static Nlm_Boolean Nlm_SubItemClick (Nlm_GraphiC i, Nlm_PoinT pt)
  918.  
  919. {
  920.   Nlm_IteM     c;
  921.   Nlm_IteM     n;
  922.   Nlm_Boolean  notInMenu;
  923.   Nlm_Int2     oldMenuTag;
  924.   Nlm_Boolean  rsult;
  925.   Nlm_MenU     s;
  926.  
  927.   rsult = FALSE;
  928.   s = Nlm_GetSubMenu ((Nlm_IteM) i);
  929.   if (s != NULL) {
  930.     oldMenuTag = currentMenuTag;
  931.     currentMenuTag = Nlm_GetMenuTag (s);
  932.     c = (Nlm_IteM) Nlm_GetChild ((Nlm_GraphiC) s);
  933.     notInMenu = TRUE;
  934.     while (c != NULL && notInMenu) {
  935.       n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) c);
  936.       if (Nlm_GetEnabled ((Nlm_GraphiC) c) && Nlm_GetVisible ((Nlm_GraphiC) c) &&
  937.           Nlm_DoClick ((Nlm_GraphiC) c, pt)) {
  938.         notInMenu = FALSE;
  939.       }
  940.       c = n;
  941.     }
  942.     currentMenuTag = oldMenuTag;
  943.     rsult = (! notInMenu); 
  944.   }
  945.   return rsult;
  946. }
  947.  
  948. static Nlm_Boolean Nlm_CommItemClick (Nlm_GraphiC i, Nlm_PoinT pt)
  949.  
  950. {
  951.   Nlm_Int2     index;
  952.   Nlm_Boolean  rsult;
  953.  
  954.   rsult = FALSE;
  955.   index = Nlm_GetFirstItem ((Nlm_IteM) i);
  956.   if (currentItemNum == index && currentMenuTag == currentMenuNum) {
  957.     Nlm_DoAction (i);
  958.     rsult = TRUE;
  959.   }
  960.   return rsult;
  961. }
  962.  
  963. static Nlm_Boolean Nlm_StatItemClick (Nlm_GraphiC i, Nlm_PoinT pt)
  964.  
  965. {
  966.   Nlm_Int2     index;
  967.   Nlm_Boolean  rsult;
  968.   Nlm_Boolean  val;
  969.  
  970.   rsult = FALSE;
  971.   index = Nlm_GetFirstItem ((Nlm_IteM) i);
  972.   if (currentItemNum == index && currentMenuTag == currentMenuNum) {
  973.     val = Nlm_DoGetStatus (i, 0);
  974.     Nlm_DoSetStatus (i, 0, (! val), FALSE);
  975.     Nlm_DoAction (i);
  976.     rsult = TRUE;
  977.   }
  978.   return rsult;
  979. }
  980.  
  981. static Nlm_Boolean Nlm_ChoiceGroupClick (Nlm_GraphiC c, Nlm_PoinT pt)
  982.  
  983. {
  984.   Nlm_Int2     first;
  985.   Nlm_Int2     num;
  986.   Nlm_Boolean  rsult;
  987.   Nlm_Int2     val;
  988.  
  989.   rsult = FALSE;
  990.   first = Nlm_GetFirstItem ((Nlm_IteM) c);
  991.   num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  992.   val = Nlm_DoGetValue (c);
  993.   if (currentItemNum >= first && currentItemNum < first + num &&
  994.       currentMenuTag == currentMenuNum) {
  995.     if (val != currentItemNum - first + 1) {
  996.       Nlm_DoSetValue (c, currentItemNum - first + 1, FALSE);
  997.       Nlm_DoAction (c);
  998.     }
  999.     rsult = TRUE;
  1000.   }
  1001.   return rsult;
  1002. }
  1003.  
  1004. static Nlm_Boolean Nlm_PopupChoiceGroupClick (Nlm_GraphiC c, Nlm_PoinT pt)
  1005.  
  1006. {
  1007.   return Nlm_ChoiceGroupClick (c, pt);
  1008. }
  1009.  
  1010. static Nlm_Boolean Nlm_DAClick (Nlm_GraphiC c, Nlm_PoinT pt)
  1011.  
  1012. {
  1013.   Nlm_Int2     first;
  1014.   Nlm_Int2     num;
  1015.   Nlm_Boolean  rsult;
  1016.  
  1017.   rsult = FALSE;
  1018.   first = Nlm_GetFirstItem ((Nlm_IteM) c);
  1019.   num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  1020.   if (currentItemNum >= first && currentItemNum < first + num &&
  1021.       currentMenuTag == currentMenuNum) {
  1022.     Nlm_DeskAccProc ((Nlm_ChoicE) c);
  1023.     rsult = TRUE;
  1024.   }
  1025.   return rsult;
  1026. }
  1027. #endif
  1028.  
  1029. #ifdef WIN_MSWIN
  1030. static Nlm_Boolean Nlm_WindowMenuBarCommand (Nlm_GraphiC mb)
  1031.  
  1032. {
  1033.   Nlm_MenU     m;
  1034.   Nlm_MenU     n;
  1035.   Nlm_Boolean  notInside;
  1036.  
  1037.   notInside = TRUE;
  1038.   currentItemID = Nlm_currentId;
  1039.   m = (Nlm_MenU) Nlm_GetChild (mb);
  1040.   while (m != NULL && notInside) {
  1041.     n = (Nlm_MenU) Nlm_GetNext ((Nlm_GraphiC) m);
  1042.     if (Nlm_GetVisible ((Nlm_GraphiC) m) && Nlm_DoCommand ((Nlm_GraphiC) m)) {
  1043.       notInside = FALSE;
  1044.     }
  1045.     m = n;
  1046.   }
  1047.   return (Nlm_Boolean) (! notInside);
  1048. }
  1049.  
  1050. static Nlm_Boolean Nlm_PulldownCommand (Nlm_GraphiC m)
  1051.  
  1052. {
  1053.   Nlm_IteM     i;
  1054.   Nlm_IteM     n;
  1055.   Nlm_Boolean  notInside;
  1056.  
  1057.  
  1058.   notInside = TRUE;
  1059.   i = (Nlm_IteM) Nlm_GetChild (m);
  1060.   while (i != NULL && notInside) {
  1061.     n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
  1062.     if (Nlm_GetEnabled ((Nlm_GraphiC) i) && Nlm_GetVisible ((Nlm_GraphiC) i) &&
  1063.         Nlm_DoCommand ((Nlm_GraphiC) i)) {
  1064.       notInside = FALSE;
  1065.     }
  1066.     i = n;
  1067.   }
  1068.   return (Nlm_Boolean) (! notInside);
  1069. }
  1070.  
  1071. static Nlm_Boolean Nlm_MSPopListCommand (Nlm_GraphiC m)
  1072.  
  1073. {
  1074.   Nlm_ChoicE   c;
  1075.   Nlm_Boolean  rsult;
  1076.  
  1077.   if (Nlm_currentCode == CBN_SELCHANGE) {
  1078.     c = (Nlm_ChoicE) Nlm_GetChild (m);
  1079.     Nlm_DoAction ((Nlm_GraphiC) c);
  1080.   }
  1081.   rsult = TRUE;
  1082.   return rsult;
  1083. }
  1084.  
  1085. static Nlm_Boolean Nlm_MacPopListCommand (Nlm_GraphiC m)
  1086.  
  1087. {
  1088.   Nlm_Boolean  rsult;
  1089.  
  1090.   rsult = Nlm_MSPopListCommand (m);
  1091.   return rsult;
  1092. }
  1093.  
  1094. static Nlm_Boolean Nlm_SubItemCommand (Nlm_GraphiC prnt)
  1095.  
  1096. {
  1097.   Nlm_IteM     i;
  1098.   Nlm_MenU     m;
  1099.   Nlm_IteM     n;
  1100.   Nlm_Boolean  notInside;
  1101.  
  1102.  
  1103.   notInside = TRUE;
  1104.   m = Nlm_GetSubMenu ((Nlm_IteM) prnt);
  1105.   i = (Nlm_IteM) Nlm_GetChild ((Nlm_GraphiC) m);
  1106.   while (i != NULL && notInside) {
  1107.     n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
  1108.     if (Nlm_GetEnabled ((Nlm_GraphiC) i) && Nlm_GetVisible ((Nlm_GraphiC) i) &&
  1109.         Nlm_DoCommand ((Nlm_GraphiC) i)) {
  1110.       notInside = FALSE;
  1111.     }
  1112.     i = n;
  1113.   }
  1114.   return (Nlm_Boolean) (! notInside);
  1115. }
  1116.  
  1117. static Nlm_Boolean Nlm_CommItemCommand (Nlm_GraphiC i)
  1118.  
  1119. {
  1120.   Nlm_Int2     id;
  1121.   Nlm_Int2     index;
  1122.   Nlm_MenU     m;
  1123.   Nlm_Boolean  rsult;
  1124.  
  1125.   rsult = FALSE;
  1126.   index = Nlm_GetFirstItem ((Nlm_IteM) i);
  1127.   m = (Nlm_MenU) Nlm_GetParent (i);
  1128.   id = Nlm_ItemToID (m, index);
  1129.   if (currentItemID == id) {
  1130.     Nlm_DoAction (i);
  1131.     rsult = TRUE;
  1132.   }
  1133.   return rsult;
  1134. }
  1135.  
  1136. static Nlm_Boolean Nlm_StatItemCommand (Nlm_GraphiC i)
  1137.  
  1138. {
  1139.   Nlm_Int2     id;
  1140.   Nlm_Int2     index;
  1141.   Nlm_MenU     m;
  1142.   Nlm_Boolean  rsult;
  1143.  
  1144.   rsult = FALSE;
  1145.   index = Nlm_GetFirstItem ((Nlm_IteM) i);
  1146.   m = (Nlm_MenU) Nlm_GetParent (i);
  1147.   id = Nlm_ItemToID (m, index);
  1148.   if (currentItemID == id) {
  1149.     if (Nlm_DoGetStatus (i, 0)) {
  1150.       Nlm_DoSetStatus (i, 0, FALSE, FALSE);
  1151.     } else {
  1152.       Nlm_DoSetStatus (i, 0, TRUE, FALSE);
  1153.     }
  1154.     Nlm_DoAction (i);
  1155.     rsult = TRUE;
  1156.   }
  1157.   return rsult;
  1158. }
  1159.  
  1160. static Nlm_Boolean Nlm_ChoiceGroupCommand (Nlm_GraphiC c)
  1161.  
  1162. {
  1163.   Nlm_Int2     first;
  1164.   Nlm_Int2     id;
  1165.   Nlm_Int2     index;
  1166.   Nlm_MenU     m;
  1167.   Nlm_Int2     num;
  1168.   Nlm_Boolean  rsult;
  1169.   Nlm_Int2     val;
  1170.  
  1171.   rsult = FALSE;
  1172.   first = Nlm_GetFirstItem ((Nlm_IteM) c);
  1173.   num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  1174.   val = Nlm_DoGetValue (c);
  1175.   index = first;
  1176.   m = (Nlm_MenU) Nlm_GetParent (c);
  1177.   while (num > 0) {
  1178.     id = Nlm_ItemToID (m, index);
  1179.     if (currentItemID == id) {
  1180.       if (val != index - first + 1) {
  1181.         Nlm_DoSetValue (c, index - first + 1, FALSE);
  1182.         Nlm_DoAction (c);
  1183.       }
  1184.       num = 0;
  1185.       rsult = TRUE;
  1186.     } else {
  1187.       index++;
  1188.       num--;
  1189.     }
  1190.   }
  1191.   return rsult;
  1192. }
  1193. #endif
  1194.  
  1195. #ifdef WIN_MOTIF
  1196. static void Nlm_CommItemCallback (Nlm_GraphiC i)
  1197.  
  1198. {
  1199.   Nlm_DoAction (i);
  1200. }
  1201.  
  1202. static void Nlm_StatItemCallback (Nlm_GraphiC i)
  1203.  
  1204. {
  1205.   Nlm_DoAction (i);
  1206. }
  1207.  
  1208. static void Nlm_ChoiceGroupCallback (Nlm_GraphiC c)
  1209.  
  1210. {
  1211.   Nlm_ItemTool  PNTR hdls;
  1212.   Nlm_Int2      i;
  1213.   Nlm_Int2      j;
  1214.   Nlm_Int2      num;
  1215.  
  1216.   hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
  1217.   num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  1218.   if (hdls != NULL && num > 0) {
  1219.     i = 0;
  1220.     while (i < num && hdls [i] != (Nlm_ItemTool) choiceWidget) {
  1221.       i++;
  1222.     }
  1223.     if (i < num) {
  1224.       if (XmToggleButtonGetState (hdls [i]) == FALSE) {
  1225.         XmToggleButtonSetState (hdls [i], TRUE, FALSE);
  1226.       } else {
  1227.         for (j = 0; j < num; j++) {
  1228.           if (j != i) {
  1229.             XmToggleButtonSetState (hdls [j], FALSE, FALSE);
  1230.           }
  1231.         }
  1232.         Nlm_DoAction (c);
  1233.       }
  1234.     }
  1235.   }
  1236. }
  1237.  
  1238. static void Nlm_PopupChoiceCallback (Nlm_GraphiC c)
  1239.  
  1240. {
  1241.   Nlm_ItemTool  PNTR hdls;
  1242.   Nlm_Int2      i;
  1243.   Nlm_Int2      j;
  1244.   Nlm_Int2      num;
  1245.   Nlm_Int2      val;
  1246.  
  1247.   hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
  1248.   num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  1249.   if (hdls != NULL && num > 0) {
  1250.     i = 0;
  1251.     while (i < num && hdls [i] != (Nlm_ItemTool) choiceWidget) {
  1252.       i++;
  1253.     }
  1254.     if (i < num) {
  1255.       i++;
  1256.       val = Nlm_GetPopupValue ((Nlm_ChoicE) c);
  1257.       if (i != val) {
  1258.         Nlm_SetPopupValue ((Nlm_ChoicE) c, i);
  1259.         XtUnmanageChild (hdls [63]);
  1260.         Nlm_DoAction (c);
  1261.       }
  1262.     }
  1263.   }
  1264. }
  1265. #endif
  1266.  
  1267. #ifdef WIN_MAC
  1268. static Nlm_Boolean Nlm_DesktopMenuBarKey (Nlm_GraphiC mb, Nlm_Char ch)
  1269.  
  1270. {
  1271.   Nlm_Int4     choice;
  1272.   Nlm_MenU     m;
  1273.   Nlm_MenU     n;
  1274.   Nlm_Boolean  notInside;
  1275.   Nlm_Boolean  rsult;
  1276.  
  1277.   rsult = FALSE;
  1278.   currentMenuNum = 0;
  1279.   currentItemNum = 0;
  1280.   if (Nlm_cmmdKey) {
  1281.     choice = MenuKey (ch);
  1282.     currentMenuNum = HiWord (choice);
  1283.     currentItemNum = LoWord (choice);
  1284.     m = (Nlm_MenU) Nlm_GetChild (mb);
  1285.     notInside = TRUE;
  1286.     while (m != NULL && notInside) {
  1287.       n = (Nlm_MenU) Nlm_GetNext ((Nlm_GraphiC) m);
  1288.       currentMenuTag = Nlm_GetMenuTag (m);
  1289.       if (Nlm_GetEnabled ((Nlm_GraphiC) m) && Nlm_GetVisible ((Nlm_GraphiC) m) &&
  1290.           Nlm_DoKey ((Nlm_GraphiC) m, ch)) {
  1291.         notInside = FALSE;
  1292.       }
  1293.       m = n;
  1294.     }
  1295.     rsult = TRUE;
  1296.   }
  1297.   return rsult;
  1298. }
  1299.  
  1300. static Nlm_Boolean Nlm_WindowMenuBarKey (Nlm_GraphiC mb, Nlm_Char ch)
  1301.  
  1302. {
  1303.   Nlm_MenU     m;
  1304.   Nlm_MenU     n;
  1305.   Nlm_Boolean  notInside;
  1306.   Nlm_Boolean  rsult;
  1307.  
  1308.   rsult = FALSE;
  1309.   if (Nlm_cmmdKey) {
  1310.     m = (Nlm_MenU) Nlm_GetChild (mb);
  1311.     notInside = TRUE;
  1312.     while (m != NULL && notInside) {
  1313.       n = (Nlm_MenU) Nlm_GetNext ((Nlm_GraphiC) m);
  1314.       currentMenuTag = Nlm_GetMenuTag (m);
  1315.       if (Nlm_GetEnabled ((Nlm_GraphiC) m) && Nlm_GetVisible ((Nlm_GraphiC) m) &&
  1316.           Nlm_DoKey ((Nlm_GraphiC) m, ch)) {
  1317.         notInside = FALSE;
  1318.       }
  1319.       m = n;
  1320.     }
  1321.     rsult = (! notInside);
  1322.   }
  1323.   return rsult;
  1324. }
  1325.  
  1326. static Nlm_Boolean Nlm_DesktopMenuKey (Nlm_GraphiC m, Nlm_Char ch)
  1327.  
  1328. {
  1329.   Nlm_IteM     i;
  1330.   Nlm_IteM     n;
  1331.   Nlm_Boolean  notInMenu;
  1332.   Nlm_Boolean  rsult;
  1333.   Nlm_Int2     tag;
  1334.  
  1335.   rsult = FALSE;
  1336.   tag = Nlm_GetMenuTag ((Nlm_MenU) m);
  1337.   if (currentMenuNum > 0 && currentMenuNum == tag) {
  1338.     i = (Nlm_IteM) Nlm_GetChild (m);
  1339.     notInMenu = TRUE;
  1340.     while (i != NULL && notInMenu) {
  1341.       n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
  1342.       if (Nlm_GetEnabled ((Nlm_GraphiC) i) && Nlm_GetVisible ((Nlm_GraphiC) i) &&
  1343.           Nlm_DoKey ((Nlm_GraphiC) i, ch)) {
  1344.         notInMenu = FALSE;
  1345.       }
  1346.       i = n;
  1347.     }
  1348.     HiliteMenu (0);
  1349.     currentMenuNum = 0;
  1350.     rsult = TRUE;
  1351.   }
  1352.   return rsult;
  1353. }
  1354.  
  1355. static Nlm_Boolean Nlm_SubMenuKey (Nlm_GraphiC m, Nlm_Char ch)
  1356.  
  1357. {
  1358.   Nlm_IteM     i;
  1359.   Nlm_Boolean  rsult;
  1360.  
  1361.   rsult = FALSE;
  1362.   i = (Nlm_IteM) Nlm_GetParent (m);
  1363.   if (i != NULL) {
  1364.     rsult = Nlm_DesktopMenuKey (m, ch);
  1365.   }
  1366.   return rsult;
  1367. }
  1368.  
  1369. static Nlm_Boolean Nlm_PopupKey (Nlm_GraphiC m, Nlm_Char ch)
  1370.  
  1371. {
  1372.   Nlm_Int4      choice;
  1373.   Nlm_MenuTool  h;
  1374.   Nlm_IteM      i;
  1375.   Nlm_IteM      n;
  1376.   Nlm_Boolean   notInMenu;
  1377.   Nlm_RecT      r;
  1378.   Nlm_Boolean   rsult;
  1379.   Nlm_Int2      tag;
  1380.  
  1381.   rsult = FALSE;
  1382.   if (Nlm_cmmdKey) {
  1383.     tag = Nlm_GetMenuTag ((Nlm_MenU) m);
  1384.     h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  1385.     InsertMenu (h, -1);
  1386.     currentMenuNum = 0;
  1387.     currentItemNum = 0;
  1388.     choice = MenuKey (ch);
  1389.     currentMenuNum = HiWord (choice);
  1390.     currentItemNum = LoWord (choice);
  1391.     if (currentMenuNum > 0 && currentMenuNum == tag) {
  1392.       Nlm_GetRect (m, &r);
  1393.       Nlm_InvertRect (&r);
  1394.       i = (Nlm_IteM) Nlm_GetChild (m);
  1395.       notInMenu = TRUE;
  1396.       while (i != NULL && notInMenu) {
  1397.         n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
  1398.       if (Nlm_GetEnabled ((Nlm_GraphiC) i) && Nlm_GetVisible ((Nlm_GraphiC) i) &&
  1399.           Nlm_DoKey ((Nlm_GraphiC) i, ch)) {
  1400.           notInMenu = FALSE;
  1401.         }
  1402.         i = n;
  1403.       }
  1404.       currentMenuNum = 0;
  1405.       DeleteMenu (tag);
  1406.       Nlm_DoDraw (m);
  1407.       rsult = TRUE;
  1408.     } else {
  1409.       currentMenuNum = 0;
  1410.       DeleteMenu (tag);
  1411.     }
  1412.   }
  1413.   return rsult;
  1414. }
  1415.  
  1416. static Nlm_Boolean Nlm_PopListKey (Nlm_GraphiC m, Nlm_Char ch)
  1417.  
  1418. {
  1419.   return (Nlm_PopupKey (m, ch));
  1420. }
  1421.  
  1422. static Nlm_Boolean Nlm_CommItemKey (Nlm_GraphiC i, Nlm_Char ch)
  1423.  
  1424. {
  1425.   Nlm_Int2     index;
  1426.   Nlm_Boolean  rsult;
  1427.  
  1428.   rsult = FALSE;
  1429.   index = Nlm_GetFirstItem ((Nlm_IteM) i);
  1430.   if (currentItemNum == index) {
  1431.     Nlm_DoAction (i);
  1432.     rsult = TRUE;
  1433.   }
  1434.   return rsult;
  1435. }
  1436.  
  1437. static Nlm_Boolean Nlm_StatItemKey (Nlm_GraphiC i, Nlm_Char ch)
  1438.  
  1439. {
  1440.   Nlm_MenuTool  h;
  1441.   Nlm_Int2      index;
  1442.   Nlm_MenU      m;
  1443.   Nlm_Char      mark;
  1444.   Nlm_Boolean   rsult;
  1445.   Nlm_Int2      temp;
  1446.  
  1447.   rsult = FALSE;
  1448.   index = Nlm_GetFirstItem ((Nlm_IteM) i);
  1449.   if (currentItemNum == index) {
  1450.     m = (Nlm_MenU) Nlm_GetParent (i);
  1451.     h = Nlm_GetMenuHandle (m);
  1452.     GetItemMark (h, currentItemNum, &temp);
  1453.     mark = (Nlm_Char) temp;
  1454.     Nlm_CheckMenuItem (m, NULL, currentItemNum, (mark == '\0'));
  1455.     Nlm_DoAction (i);
  1456.     rsult = TRUE;
  1457.   }
  1458.   return rsult;
  1459. }
  1460.  
  1461. static Nlm_Boolean Nlm_ChoiceGroupKey (Nlm_GraphiC c, Nlm_Char ch)
  1462.  
  1463. {
  1464.   Nlm_Int2     first;
  1465.   Nlm_Int2     num;
  1466.   Nlm_Boolean  rsult;
  1467.   Nlm_Int2     val;
  1468.  
  1469.   rsult = FALSE;
  1470.   first = Nlm_GetFirstItem ((Nlm_IteM) c);
  1471.   num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  1472.   val = Nlm_DoGetValue (c);
  1473.   if (currentItemNum >= first && currentItemNum < first + num) {
  1474.     if (val != currentItemNum - first + 1) {
  1475.       Nlm_DoSetValue (c, currentItemNum - first + 1, FALSE);
  1476.       Nlm_DoAction (c);
  1477.       rsult = TRUE;
  1478.     }
  1479.   }
  1480.   return rsult;
  1481. }
  1482.  
  1483. static Nlm_Boolean Nlm_DAKey (Nlm_GraphiC c, Nlm_Char ch)
  1484.  
  1485. {
  1486.   Nlm_Int2     first;
  1487.   Nlm_Int2     num;
  1488.   Nlm_Boolean  rsult;
  1489.  
  1490.   rsult = FALSE;
  1491.   first = Nlm_GetFirstItem ((Nlm_IteM) c);
  1492.   num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  1493.   if (currentItemNum >= first && currentItemNum < first + num) {
  1494.     Nlm_DeskAccProc ((Nlm_ChoicE) c);
  1495.     rsult = TRUE;
  1496.   }
  1497.   return rsult;
  1498. }
  1499. #endif
  1500.  
  1501. #ifdef WIN_MAC
  1502. static void Nlm_DrawWindowMenuBar (Nlm_GraphiC mb)
  1503.  
  1504. {
  1505.   Nlm_MenU        m;
  1506.   Nlm_RecT        r;
  1507.   Nlm_WindowTool  wptr;
  1508.  
  1509.   wptr = Nlm_ParentWindowPtr (mb);
  1510.   Nlm_RectToolToRecT (&(wptr->portRect), &r);
  1511.   r.top = 19;
  1512.   r.bottom = 21;
  1513.   if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
  1514.     MoveTo (0, 20);
  1515.     LineTo (r.right, 20);
  1516.   }
  1517.   m = (Nlm_MenU) Nlm_GetChild (mb);
  1518.   while (m != NULL) {
  1519.     Nlm_DoDraw ((Nlm_GraphiC) m);
  1520.     m = (Nlm_MenU) Nlm_GetNext ((Nlm_GraphiC) m);
  1521.   }
  1522. }
  1523.  
  1524. static void Nlm_DrawDesktopMenu (Nlm_GraphiC m)
  1525.  
  1526. {
  1527.   DrawMenuBar ();
  1528. }
  1529.  
  1530. static void Nlm_DrawWindowMenu (Nlm_GraphiC m)
  1531.  
  1532. {
  1533.   Nlm_PrompT  p;
  1534.   Nlm_RecT    r;
  1535.  
  1536.   if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
  1537.     Nlm_GetRect (m, &r);
  1538.     if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
  1539.       p = Nlm_GetMenuPrompt ((Nlm_MenU) m);
  1540.       if (p != NULL) {
  1541.         Nlm_DoDraw ((Nlm_GraphiC) p);
  1542.         Nlm_SelectFont (Nlm_systemFont);
  1543.       }
  1544.     }
  1545.   }
  1546. }
  1547.  
  1548. static void Nlm_DrawPopup (Nlm_GraphiC m)
  1549.  
  1550. {
  1551.   Nlm_PrompT  p;
  1552.   Nlm_RecT    r;
  1553.  
  1554.   if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
  1555.     Nlm_GetRect (m, &r);
  1556.     if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
  1557.       p = Nlm_GetMenuPrompt ((Nlm_MenU) m);
  1558.       if (p != NULL) {
  1559.         Nlm_GetRect ((Nlm_GraphiC) p, &r);
  1560.         Nlm_InsetRect (&r, -1, -1);
  1561.         Nlm_FrameRect (&r);
  1562.         Nlm_OffsetRect (&r, 1, 1);
  1563.         Nlm_FrameRect (&r);
  1564.         Nlm_DoDraw ((Nlm_GraphiC) p);
  1565.         Nlm_SelectFont (Nlm_systemFont);
  1566.       }
  1567.     }
  1568.   }
  1569. }
  1570.  
  1571. static void Nlm_DrawPopList (Nlm_GraphiC m)
  1572.  
  1573. {
  1574.   Nlm_ChoicE  c;
  1575.   Nlm_RecT    pr;
  1576.   Nlm_RecT    r;
  1577.   Nlm_Char    temp [256];
  1578.   Nlm_Int2    value;
  1579.  
  1580.   if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
  1581.     Nlm_GetRect (m, &r);
  1582.     if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
  1583.       Nlm_SelectFont (Nlm_systemFont);
  1584.       Nlm_UpsetRect (&r, 1, 1, 2, 2);
  1585.       pr = r;
  1586.       Nlm_InsetRect (&r, -1, -1);
  1587.       Nlm_FrameRect (&r);
  1588.       Nlm_OffsetRect (&r, 1, 1);
  1589.       Nlm_FrameRect (&r);
  1590.       Nlm_EraseRect (&pr);
  1591.       c = (Nlm_ChoicE) Nlm_GetChild (m);
  1592.       if (c != NULL) {
  1593.         value = Nlm_DoGetValue ((Nlm_GraphiC) c);
  1594.         if (value > 0) {
  1595.           Nlm_DoGetTitle ((Nlm_GraphiC) c, value, temp, sizeof (temp));
  1596.           pr.left += 13;
  1597.           Nlm_DrawString (&pr, temp, 'l', FALSE);
  1598.         }
  1599.       }
  1600.     }
  1601.   }
  1602. }
  1603. #endif
  1604.  
  1605. static void Nlm_ShowWindowMenuBar (Nlm_GraphiC mb, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1606.  
  1607. {
  1608.   Nlm_WindoW      tempPort;
  1609.   Nlm_WindowTool  wptr;
  1610. #ifdef WIN_MOTIF
  1611.   Nlm_MenuTool    h;
  1612. #endif
  1613.  
  1614.   tempPort = Nlm_SavePortIfNeeded (mb, savePort);
  1615.   Nlm_SetVisible (mb, TRUE);
  1616. #ifdef WIN_MAC
  1617.   Nlm_DoDraw (mb);
  1618. #endif
  1619. #ifdef WIN_MSWIN
  1620.   wptr = Nlm_ParentWindowPtr (mb);
  1621.   DrawMenuBar (wptr);
  1622. #endif
  1623. #ifdef WIN_MOTIF
  1624.   h = Nlm_GetMenuBarHandle ((Nlm_MenuBaR) mb);
  1625.   XtManageChild (h);
  1626.   if (NLM_QUIET) {
  1627.     if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (mb))) {
  1628.       XtRealizeWidget (h);
  1629.     }
  1630.   } else {
  1631.     XtRealizeWidget (h);
  1632.   }
  1633. #endif
  1634.   Nlm_RestorePort (tempPort);
  1635. }
  1636.  
  1637. #ifdef WIN_MAC
  1638. static void Nlm_ShowDesktopMenu (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1639.  
  1640. {
  1641.   Nlm_MenuTool  h;
  1642.   Nlm_WindoW    tempPort;
  1643.  
  1644.   tempPort = Nlm_SavePortIfNeeded (m, savePort);
  1645.   Nlm_SetVisible (m, TRUE);
  1646.   h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  1647.   InsertMenu (h, 0);
  1648.   Nlm_ActivateInnerMenus ((Nlm_MenU) m);
  1649.   Nlm_DoDraw (m);
  1650.   Nlm_RestorePort (tempPort);
  1651. }
  1652. #endif
  1653.  
  1654. static void Nlm_ShowPopup (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1655.  
  1656. {
  1657.   Nlm_PrompT      p;
  1658.   Nlm_WindoW      tempPort;
  1659.   Nlm_WindowTool  wptr;
  1660.  
  1661.   if (setFlag) {
  1662.     Nlm_SetVisible (m, TRUE);
  1663.   }
  1664.   if (Nlm_GetVisible (m) && Nlm_AllParentsButWindowVisible (m)) {
  1665.     tempPort = Nlm_SavePortIfNeeded (m, savePort);
  1666.     p = Nlm_GetMenuPrompt ((Nlm_MenU) m);
  1667.     if (p != NULL) {
  1668.       Nlm_DoShow ((Nlm_GraphiC) p, TRUE, FALSE);
  1669.     }
  1670. #ifdef WIN_MAC
  1671.     Nlm_DoDraw (m);
  1672. #endif
  1673. #ifdef WIN_MSWIN
  1674.     wptr = Nlm_ParentWindowPtr (m);
  1675.     DrawMenuBar (wptr);
  1676. #endif
  1677. #ifdef WIN_MOTIF
  1678. #endif
  1679.     Nlm_RestorePort (tempPort);
  1680.   }
  1681. }
  1682.  
  1683. static void Nlm_ShowPopListMenu (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1684.  
  1685. {
  1686.   Nlm_WindoW     tempPort;
  1687.   Nlm_PopupTool  u;
  1688.  
  1689.   if (setFlag) {
  1690.     Nlm_SetVisible (m, TRUE);
  1691.   }
  1692.   if (Nlm_GetVisible (m) && Nlm_AllParentsButWindowVisible (m)) {
  1693.     tempPort = Nlm_SavePortIfNeeded (m, savePort);
  1694. #ifdef WIN_MAC
  1695.     Nlm_DoDraw (m);
  1696. #endif
  1697. #ifdef WIN_MSWIN
  1698.     u = Nlm_GetMenuPopup ((Nlm_MenU) m);
  1699.     if (u != NULL) {
  1700.       ShowWindow (u, SW_SHOW);
  1701.       UpdateWindow (u);
  1702.     }
  1703. #endif
  1704. #ifdef WIN_MOTIF
  1705.     u = Nlm_GetMenuPopup ((Nlm_MenU) m);
  1706.     XtManageChild (u);
  1707. #endif
  1708.     Nlm_RestorePort (tempPort);
  1709.   }
  1710. }
  1711.  
  1712. static void Nlm_ShowPopListChoice (Nlm_GraphiC c, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1713.  
  1714. {
  1715.   Nlm_MenU  m;
  1716.  
  1717.   m = (Nlm_MenU) Nlm_GetParent (c);
  1718.   Nlm_DoShow ((Nlm_GraphiC) m, setFlag, savePort);
  1719. }
  1720.  
  1721. #ifdef WIN_MAC
  1722. static void Nlm_HideDesktopMenu (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1723.  
  1724. {
  1725.   Nlm_Int2    tag;
  1726.   Nlm_WindoW  tempPort;
  1727.  
  1728.   tempPort = Nlm_SavePortIfNeeded (m, savePort);
  1729.   Nlm_SetVisible (m, FALSE);
  1730.   tag = Nlm_GetMenuTag ((Nlm_MenU) m);
  1731.   DeleteMenu (tag);
  1732.   Nlm_DeactivateInnerMenus ((Nlm_MenU) m);
  1733.   Nlm_DoDraw (m);
  1734.   Nlm_RestorePort (tempPort);
  1735. }
  1736. #endif
  1737.  
  1738. static void Nlm_HidePulldown (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1739.  
  1740. {
  1741. #ifdef WIN_MAC
  1742.   Nlm_RecT    r;
  1743.   Nlm_WindoW  tempPort;
  1744.  
  1745.   tempPort = Nlm_SavePortIfNeeded (m, savePort);
  1746.   Nlm_SetVisible (m, FALSE);
  1747.   Nlm_GetRect (m, &r);
  1748.   Nlm_EraseRect (&r);
  1749.   Nlm_ValidRect (&r);
  1750.   Nlm_RestorePort (tempPort);
  1751. #endif
  1752. }
  1753.  
  1754. static void Nlm_HidePopup (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1755.  
  1756. {
  1757. #ifdef WIN_MAC
  1758.   Nlm_RecT    r;
  1759.   Nlm_WindoW  tempPort;
  1760.  
  1761.   if (setFlag) {
  1762.     Nlm_SetVisible (m, FALSE);
  1763.   }
  1764.   if (Nlm_GetAllParentsVisible (m)) {
  1765.     tempPort = Nlm_SavePortIfNeeded (m, savePort);
  1766.     Nlm_GetRect (m, &r);
  1767.     /*
  1768.     Nlm_InsetRect (&r, -2, -2);
  1769.     Nlm_OffsetRect (&r, 1, 1);
  1770.     */
  1771.     Nlm_InsetRect (&r, -1, -1);
  1772.     Nlm_EraseRect (&r);
  1773.     Nlm_ValidRect (&r);
  1774.     Nlm_RestorePort (tempPort);
  1775.   }
  1776. #endif
  1777. }
  1778.  
  1779. static void Nlm_HidePopListMenu (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1780.  
  1781. {
  1782.   Nlm_WindoW     tempPort;
  1783.   Nlm_PopupTool  u;
  1784. #ifdef WIN_MAC
  1785.   Nlm_RecT       r;
  1786. #endif
  1787.  
  1788.   if (setFlag) {
  1789.     Nlm_SetVisible (m, FALSE);
  1790.   }
  1791.   tempPort = Nlm_SavePortIfNeeded (m, savePort);
  1792. #ifdef WIN_MAC
  1793.   if (Nlm_GetAllParentsVisible (m)) {
  1794.     Nlm_GetRect (m, &r);
  1795.     /*
  1796.     Nlm_InsetRect (&r, -2, -2);
  1797.     Nlm_OffsetRect (&r, 1, 1);
  1798.     */
  1799.     Nlm_InsetRect (&r, -1, -1);
  1800.     Nlm_EraseRect (&r);
  1801.     Nlm_ValidRect (&r);
  1802.   }
  1803. #endif
  1804. #ifdef WIN_MSWIN
  1805.   u = Nlm_GetMenuPopup ((Nlm_MenU) m);
  1806.   if (u != NULL) {
  1807.     ShowWindow (u, SW_HIDE);
  1808.     UpdateWindow (u);
  1809.   }
  1810. #endif
  1811. #ifdef WIN_MOTIF
  1812.     u = Nlm_GetMenuPopup ((Nlm_MenU) m);
  1813.     XtUnmanageChild (u);
  1814. #endif
  1815.   Nlm_RestorePort (tempPort);
  1816. }
  1817.  
  1818. static void Nlm_HidePopListChoice (Nlm_GraphiC c, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1819.  
  1820. {
  1821.   Nlm_MenU  m;
  1822.  
  1823.   m = (Nlm_MenU) Nlm_GetParent (c);
  1824.   Nlm_DoHide ((Nlm_GraphiC) m, setFlag, savePort);
  1825. }
  1826.  
  1827. #ifdef WIN_MAC
  1828. static void Nlm_EnableDesktopMenu (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1829.  
  1830. {
  1831.   Nlm_MenuTool  h;
  1832.   Nlm_WindoW    tempPort;
  1833.  
  1834.   tempPort = Nlm_SavePortIfNeeded (m, savePort);
  1835.   Nlm_SetEnabled (m, TRUE);
  1836.   h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  1837.   EnableItem (h, 0);
  1838.   if (Nlm_GetVisible (m)) {
  1839.     DrawMenuBar ();
  1840.   }
  1841.   Nlm_RestorePort (tempPort);
  1842. }
  1843. #endif
  1844.  
  1845. static void Nlm_EnablePopup (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1846.  
  1847. {
  1848. #ifdef WIN_MAC
  1849.   Nlm_MenuTool  h;
  1850.   Nlm_WindoW    tempPort;
  1851.  
  1852.   if (setFlag) {
  1853.     Nlm_SetEnabled (m, TRUE);
  1854.   }
  1855.   if (Nlm_GetEnabled (m) && Nlm_GetAllParentsEnabled (m)) {
  1856.     if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
  1857.       tempPort = Nlm_SavePortIfNeeded (m, savePort);
  1858.       h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  1859.       EnableItem (h, 0);
  1860.       Nlm_DoDraw (m);
  1861.       Nlm_RestorePort (tempPort);
  1862.     }
  1863.   }
  1864. #endif
  1865. }
  1866.  
  1867. static void Nlm_EnablePopList (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1868.  
  1869. {
  1870.   Nlm_WindoW     tempPort;
  1871.   Nlm_PopupTool  u;
  1872. #ifdef WIN_MAC
  1873.   Nlm_MenuTool   h;
  1874. #endif
  1875.  
  1876.   if (setFlag) {
  1877.     Nlm_SetEnabled (m, TRUE);
  1878.   }
  1879.   if (Nlm_GetEnabled (m) && Nlm_GetAllParentsEnabled (m)) {
  1880.     tempPort = Nlm_SavePortIfNeeded (m, savePort);
  1881. #ifdef WIN_MAC
  1882.     h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  1883.     EnableItem (h, 0);
  1884.     if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
  1885.       Nlm_DoDraw (m);
  1886.     }
  1887. #endif
  1888. #ifdef WIN_MSWIN
  1889.     u = Nlm_GetMenuPopup ((Nlm_MenU) m);
  1890.     if (u != NULL) {
  1891.       EnableWindow (u, TRUE);
  1892.     }
  1893. #endif
  1894. #ifdef WIN_MOTIF
  1895. #endif
  1896.     Nlm_RestorePort (tempPort);
  1897.   }
  1898. }
  1899.  
  1900. static void Nlm_EnableMenuItem (Nlm_GraphiC i, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1901.  
  1902. {
  1903.   Nlm_MenuTool  h;
  1904.   Nlm_Int2      id;
  1905.   Nlm_Int2      itm;
  1906.   Nlm_MenU      m;
  1907.   Nlm_WindoW    tempPort;
  1908. #ifdef WIN_MOTIF
  1909.   Nlm_ItemTool  itool;
  1910. #endif
  1911.  
  1912.   tempPort = Nlm_SavePortIfNeeded (i, savePort);
  1913.   Nlm_SetEnabled (i, TRUE);
  1914.   m = (Nlm_MenU) Nlm_GetParent (i);
  1915.   h = Nlm_GetMenuHandle (m);
  1916.   itm = Nlm_GetFirstItem ((Nlm_IteM) i);
  1917. #ifdef WIN_MAC
  1918.   EnableItem (h, itm);
  1919. #endif
  1920. #ifdef WIN_MSWIN
  1921.   id = Nlm_ItemToID (m, itm);
  1922.   EnableMenuItem (h, id, MF_ENABLED);
  1923. #endif
  1924. #ifdef WIN_MOTIF
  1925.   itool = Nlm_GetItemHandle ((Nlm_IteM) i);
  1926.   XtVaSetValues (itool, XmNsensitive, TRUE, NULL);
  1927. #endif
  1928.   Nlm_RestorePort (tempPort);
  1929. }
  1930.  
  1931. static void Nlm_EnableSubMenu (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1932.  
  1933. {
  1934.   Nlm_MenuTool   h;
  1935.   Nlm_IteM       i;
  1936.   Nlm_Int2       id;
  1937.   Nlm_Int2       index;
  1938.   Nlm_MenU       prnt;
  1939.   Nlm_WindoW     tempPort;
  1940. #ifdef WIN_MOTIF
  1941.   Nlm_PopupTool  pop;
  1942. #endif
  1943.  
  1944.   tempPort = Nlm_SavePortIfNeeded (m, savePort);
  1945.   Nlm_SetEnabled (m, TRUE);
  1946.   i = (Nlm_IteM) Nlm_GetParent (m);
  1947.   if (i != NULL) {
  1948.     Nlm_EnableMenuItem ((Nlm_GraphiC) i, FALSE, FALSE);
  1949. #ifdef WIN_MAC
  1950.     h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  1951.     InsertMenu (h, -1);
  1952. #endif
  1953. #ifdef WIN_MSWIN
  1954.     prnt = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) i);
  1955.     index = Nlm_GetFirstItem (i);
  1956.     h = Nlm_GetMenuHandle (prnt);
  1957.     id = Nlm_ItemToID (prnt, index);
  1958.     EnableMenuItem (h, id, MF_ENABLED);
  1959. #endif
  1960. #ifdef WIN_MOTIF
  1961.     pop = Nlm_GetMenuPopup ((Nlm_MenU) m);
  1962.     XtVaSetValues (pop, XmNsensitive, TRUE, NULL);
  1963. #endif
  1964.     Nlm_ActivateInnerMenus ((Nlm_MenU) m);
  1965.   }
  1966.   Nlm_RestorePort (tempPort);
  1967. }
  1968.  
  1969. static void Nlm_EnableChoice (Nlm_GraphiC c, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1970.  
  1971. {
  1972.   Nlm_MenuTool  h;
  1973.   Nlm_Int2      id;
  1974.   Nlm_Int2      itm;
  1975.   Nlm_MenU      m;
  1976.   Nlm_Int2      num;
  1977.   Nlm_WindoW    tempPort;
  1978. #ifdef WIN_MOTIF
  1979.   Nlm_ItemTool  PNTR hdls;
  1980. #endif
  1981.  
  1982.   tempPort = Nlm_SavePortIfNeeded (c, savePort);
  1983.   Nlm_SetEnabled (c, TRUE);
  1984.   m = (Nlm_MenU) Nlm_GetParent (c);
  1985.   itm = Nlm_GetFirstItem ((Nlm_IteM) c);
  1986.   num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  1987.   h = Nlm_GetMenuHandle (m);
  1988.   while (num > 0) {
  1989. #ifdef WIN_MAC
  1990.     EnableItem (h, itm);
  1991. #endif
  1992. #ifdef WIN_MSWIN
  1993.     if (! Nlm_IsItAPopupList ((Nlm_ChoicE) c)) {
  1994.       id = Nlm_ItemToID (m, itm);
  1995.       EnableMenuItem (h, id, MF_ENABLED);
  1996.     }
  1997. #endif
  1998. #ifdef WIN_MOTIF
  1999.     hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
  2000.     XtVaSetValues (hdls [num - 1], XmNsensitive, TRUE, NULL);
  2001. #endif
  2002.     itm++;
  2003.     num--;
  2004.   }
  2005.   Nlm_RestorePort (tempPort);
  2006. }
  2007.  
  2008. static void Nlm_EnableChoiceGroup (Nlm_GraphiC c, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  2009.  
  2010. {
  2011.   Nlm_MenuTool  h;
  2012.   Nlm_Int2      id;
  2013.   Nlm_Int2      itm;
  2014.   Nlm_MenU      m;
  2015.   Nlm_Int2      num;
  2016.   Nlm_WindoW    tempPort;
  2017. #ifdef WIN_MOTIF
  2018.   Nlm_ItemTool  PNTR hdls;
  2019. #endif
  2020.  
  2021.   tempPort = Nlm_SavePortIfNeeded (c, savePort);
  2022.   Nlm_SetEnabled (c, TRUE);
  2023.   m = (Nlm_MenU) Nlm_GetParent (c);
  2024.   itm = Nlm_GetFirstItem ((Nlm_IteM) c);
  2025.   num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  2026.   h = Nlm_GetMenuHandle (m);
  2027.   while (num > 0) {
  2028. #ifdef WIN_MAC
  2029.     EnableItem (h, itm);
  2030. #endif
  2031. #ifdef WIN_MSWIN
  2032.     if (! Nlm_IsItAPopupList ((Nlm_ChoicE) c)) {
  2033.       id = Nlm_ItemToID (m, itm);
  2034.       EnableMenuItem (h, id, MF_ENABLED);
  2035.     }
  2036. #endif
  2037. #ifdef WIN_MOTIF
  2038.     hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
  2039.     XtVaSetValues (hdls [num - 1], XmNsensitive, TRUE, NULL);
  2040. #endif
  2041.     itm++;
  2042.     num--;
  2043.   }
  2044.   Nlm_RestorePort (tempPort);
  2045. }
  2046.  
  2047. #ifdef DCLAP
  2048. extern
  2049. #else
  2050. static
  2051. #endif 
  2052. void Nlm_EnableChoiceItem (Nlm_GraphiC i, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  2053.  
  2054. {
  2055.   Nlm_ChoicE    c;
  2056.   Nlm_MenuTool  h;
  2057.   Nlm_Int2      id;
  2058.   Nlm_Int2      index;
  2059.   Nlm_Int2      itm;
  2060.   Nlm_MenU      m;
  2061.   Nlm_WindoW    tempPort;
  2062. #ifdef WIN_MOTIF
  2063.   Nlm_ItemTool  PNTR hdls;
  2064. #endif
  2065.  
  2066.   tempPort = Nlm_SavePortIfNeeded (i, savePort);
  2067.   Nlm_SetEnabled (i, TRUE);
  2068.   c = (Nlm_ChoicE) Nlm_GetParent (i);
  2069.   index = Nlm_GetFirstItem ((Nlm_IteM) i);
  2070.   if (index > 0 && index <= Nlm_GetNumItems ((Nlm_ChoicE) c)) {
  2071.     m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
  2072.     h = Nlm_GetMenuHandle (m);
  2073.     itm = Nlm_GetFirstItem ((Nlm_IteM) c) + index - 1;
  2074. #ifdef WIN_MAC
  2075.     EnableItem (h, itm);
  2076. #endif
  2077. #ifdef WIN_MSWIN
  2078.     if (! Nlm_IsItAPopupList ((Nlm_ChoicE) c)) {
  2079.       id = Nlm_ItemToID (m, itm);
  2080.       EnableMenuItem (h, id, MF_ENABLED);
  2081.     }
  2082. #endif
  2083. #ifdef WIN_MOTIF
  2084.     hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
  2085.     XtVaSetValues (hdls [index - 1], XmNsensitive, TRUE, NULL);
  2086. #endif
  2087.   }
  2088.   Nlm_RestorePort (tempPort);
  2089. }
  2090.  
  2091. #ifdef WIN_MAC
  2092. static void Nlm_DisableDesktopMenu (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  2093.  
  2094. {
  2095.   Nlm_MenuTool  h;
  2096.   Nlm_WindoW    tempPort;
  2097.  
  2098.   tempPort = Nlm_SavePortIfNeeded (m, savePort);
  2099.   Nlm_SetEnabled (m, FALSE);
  2100.   h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  2101.   DisableItem (h, 0);
  2102.   if (Nlm_GetVisible (m)) {
  2103.     DrawMenuBar ();
  2104.   }
  2105.   Nlm_RestorePort (tempPort);
  2106. }
  2107. #endif
  2108.  
  2109. static void Nlm_DisablePopup (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  2110.  
  2111. {
  2112. #ifdef WIN_MAC
  2113.   Nlm_MenuTool  h;
  2114.   Nlm_WindoW    tempPort;
  2115.  
  2116.   if (setFlag) {
  2117.     Nlm_SetEnabled (m, FALSE);
  2118.   }
  2119.   if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
  2120.     tempPort = Nlm_SavePortIfNeeded (m, savePort);
  2121.     h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  2122.     DisableItem (h, 0);
  2123.     Nlm_DoDraw (m);
  2124.     Nlm_RestorePort (tempPort);
  2125.   }
  2126. #endif
  2127. }
  2128.  
  2129. static void Nlm_DisablePopList (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  2130.  
  2131. {
  2132.   Nlm_WindoW     tempPort;
  2133.   Nlm_PopupTool  u;
  2134. #ifdef WIN_MAC
  2135.   Nlm_MenuTool   h;
  2136. #endif
  2137.  
  2138.   if (setFlag) {
  2139.     Nlm_SetEnabled (m, FALSE);
  2140.   }
  2141.   tempPort = Nlm_SavePortIfNeeded (m, savePort);
  2142. #ifdef WIN_MAC
  2143.   if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
  2144.     h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  2145.     DisableItem (h, 0);
  2146.     Nlm_DoDraw (m);
  2147.   }
  2148. #endif
  2149. #ifdef WIN_MSWIN
  2150.   u = Nlm_GetMenuPopup ((Nlm_MenU) m);
  2151.   if (u != NULL) {
  2152.     EnableWindow (u, FALSE);
  2153.   }
  2154. #endif
  2155. #ifdef WIN_MOTIF
  2156. #endif
  2157.   Nlm_RestorePort (tempPort);
  2158. }
  2159.  
  2160. static void Nlm_DisableMenuItem (Nlm_GraphiC i, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  2161.  
  2162. {
  2163.   Nlm_MenuTool  h;
  2164.   Nlm_Int2      id;
  2165.   Nlm_Int2      itm;
  2166.   Nlm_MenU      m;
  2167.   Nlm_WindoW    tempPort;
  2168. #ifdef WIN_MOTIF
  2169.   Nlm_ItemTool  itool;
  2170. #endif
  2171.  
  2172.   tempPort = Nlm_SavePortIfNeeded (i, savePort);
  2173.   Nlm_SetEnabled (i, FALSE);
  2174.   m = (Nlm_MenU) Nlm_GetParent (i);
  2175.   h = Nlm_GetMenuHandle (m);
  2176.   itm = Nlm_GetFirstItem ((Nlm_IteM) i);
  2177. #ifdef WIN_MAC
  2178.   DisableItem (h, itm);
  2179. #endif
  2180. #ifdef WIN_MSWIN
  2181.   id = Nlm_ItemToID (m, itm);
  2182.   EnableMenuItem (h, id, MF_GRAYED);
  2183. #endif
  2184. #ifdef WIN_MOTIF
  2185.   itool = Nlm_GetItemHandle ((Nlm_IteM) i);
  2186.   XtVaSetValues (itool, XmNsensitive, FALSE, NULL);
  2187. #endif
  2188.   Nlm_RestorePort (tempPort);
  2189. }
  2190.  
  2191. static void Nlm_DisableSubMenu (Nlm_GraphiC m, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  2192.  
  2193. {
  2194.   Nlm_MenuTool   h;
  2195.   Nlm_IteM       i;
  2196.   Nlm_Int2       id;
  2197.   Nlm_Int2       index;
  2198.   Nlm_MenU       prnt;
  2199.   Nlm_WindoW     tempPort;
  2200. #ifdef WIN_MAC
  2201.   Nlm_Int2       tag;
  2202. #endif
  2203. #ifdef WIN_MOTIF
  2204.   Nlm_PopupTool  pop;
  2205. #endif
  2206.  
  2207.   tempPort = Nlm_SavePortIfNeeded (m, savePort);
  2208.   Nlm_SetEnabled (m, FALSE);
  2209.   i = (Nlm_IteM) Nlm_GetParent (m);
  2210.   if (i != NULL) {
  2211.     Nlm_DisableMenuItem ((Nlm_GraphiC) i, FALSE, FALSE);
  2212. #ifdef WIN_MAC
  2213.     tag = Nlm_GetMenuTag ((Nlm_MenU) m);
  2214.     DeleteMenu (tag);
  2215. #endif
  2216. #ifdef WIN_MSWIN
  2217.     prnt = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) i);
  2218.     index = Nlm_GetFirstItem (i);
  2219.     h = Nlm_GetMenuHandle (prnt);
  2220.     id = Nlm_ItemToID (prnt, index);
  2221.     EnableMenuItem (h, id, MF_GRAYED);
  2222. #endif
  2223. #ifdef WIN_MOTIF
  2224.     pop = Nlm_GetMenuPopup ((Nlm_MenU) m);
  2225.     XtVaSetValues (pop, XmNsensitive, FALSE, NULL);
  2226. #endif
  2227.     Nlm_DeactivateInnerMenus ((Nlm_MenU) m);
  2228.   }
  2229.   Nlm_RestorePort (tempPort);
  2230. }
  2231.  
  2232. static void Nlm_DisableChoice (Nlm_GraphiC c, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  2233.  
  2234. {
  2235.   Nlm_MenuTool  h;
  2236.   Nlm_Int2      id;
  2237.   Nlm_Int2      itm;
  2238.   Nlm_MenU      m;
  2239.   Nlm_Int2      num;
  2240.   Nlm_WindoW    tempPort;
  2241. #ifdef WIN_MOTIF
  2242.   Nlm_ItemTool  PNTR hdls;
  2243. #endif
  2244.  
  2245.   tempPort = Nlm_SavePortIfNeeded (c, savePort);
  2246.   Nlm_SetEnabled (c, FALSE);
  2247.   m = (Nlm_MenU) Nlm_GetParent (c);
  2248.   itm = Nlm_GetFirstItem ((Nlm_IteM) c);
  2249.   num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  2250.   h = Nlm_GetMenuHandle (m);
  2251.   while (num > 0) {
  2252. #ifdef WIN_MAC
  2253.     DisableItem (h, itm);
  2254. #endif
  2255. #ifdef WIN_MSWIN
  2256.     if (! Nlm_IsItAPopupList ((Nlm_ChoicE) c)) {
  2257.       id = Nlm_ItemToID (m, itm);
  2258.       EnableMenuItem (h, id, MF_GRAYED);
  2259.     }
  2260. #endif
  2261. #ifdef WIN_MOTIF
  2262.     hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
  2263.     XtVaSetValues (hdls [num - 1], XmNsensitive, FALSE, NULL);
  2264. #endif
  2265.     itm++;
  2266.     num--;
  2267.   }
  2268.   Nlm_RestorePort (tempPort);
  2269. }
  2270.  
  2271. static void Nlm_DisableChoiceGroup (Nlm_GraphiC c, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  2272.  
  2273. {
  2274.   Nlm_MenuTool  h;
  2275.   Nlm_Int2      id;
  2276.   Nlm_Int2      itm;
  2277.   Nlm_MenU      m;
  2278.   Nlm_Int2      num;
  2279.   Nlm_WindoW    tempPort;
  2280. #ifdef WIN_MOTIF
  2281.   Nlm_ItemTool  PNTR hdls;
  2282. #endif
  2283.  
  2284.   tempPort = Nlm_SavePortIfNeeded (c, savePort);
  2285.   Nlm_SetEnabled (c, FALSE);
  2286.   m = (Nlm_MenU) Nlm_GetParent (c);
  2287.   itm = Nlm_GetFirstItem ((Nlm_IteM) c);
  2288.   num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  2289.   h = Nlm_GetMenuHandle (m);
  2290.   while (num > 0) {
  2291. #ifdef WIN_MAC
  2292.     DisableItem (h, itm);
  2293. #endif
  2294. #ifdef WIN_MSWIN
  2295.     if (! Nlm_IsItAPopupList ((Nlm_ChoicE) c)) {
  2296.       id = Nlm_ItemToID (m, itm);
  2297.       EnableMenuItem (h, id, MF_GRAYED);
  2298.     }
  2299. #endif
  2300. #ifdef WIN_MOTIF
  2301.     hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
  2302.     XtVaSetValues (hdls [num - 1], XmNsensitive, FALSE, NULL);
  2303. #endif
  2304.     itm++;
  2305.     num--;
  2306.   }
  2307.   Nlm_RestorePort (tempPort);
  2308. }
  2309.  
  2310. #ifdef DCLAP
  2311. extern
  2312. #else
  2313. static
  2314. #endif 
  2315. void Nlm_DisableChoiceItem (Nlm_GraphiC i, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  2316.  
  2317. {
  2318.   Nlm_ChoicE    c;
  2319.   Nlm_MenuTool  h;
  2320.   Nlm_Int2      id;
  2321.   Nlm_Int2      index;
  2322.   Nlm_Int2      itm;
  2323.   Nlm_MenU      m;
  2324.   Nlm_WindoW    tempPort;
  2325. #ifdef WIN_MOTIF
  2326.   Nlm_ItemTool  PNTR hdls;
  2327. #endif
  2328.  
  2329.   tempPort = Nlm_SavePortIfNeeded (i, savePort);
  2330.   Nlm_SetEnabled (i, FALSE);
  2331.   c = (Nlm_ChoicE) Nlm_GetParent (i);
  2332.   index = Nlm_GetFirstItem ((Nlm_IteM) i);
  2333.   if (index > 0 && index <= Nlm_GetNumItems ((Nlm_ChoicE) c)) {
  2334.     m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
  2335.     h = Nlm_GetMenuHandle (m);
  2336.     itm = Nlm_GetFirstItem ((Nlm_IteM) c) + index - 1;
  2337. #ifdef WIN_MAC
  2338.     DisableItem (h, itm);
  2339. #endif
  2340. #ifdef WIN_MSWIN
  2341.     if (! Nlm_IsItAPopupList ((Nlm_ChoicE) c)) {
  2342.       id = Nlm_ItemToID (m, itm);
  2343.       EnableMenuItem (h, id, MF_GRAYED);
  2344.     }
  2345. #endif
  2346. #ifdef WIN_MOTIF
  2347.     hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
  2348.     XtVaSetValues (hdls [index - 1], XmNsensitive, FALSE, NULL);
  2349. #endif
  2350.   }
  2351.   Nlm_RestorePort (tempPort);
  2352. }
  2353.  
  2354. #ifdef WIN_MAC
  2355. static void Nlm_RemoveDesktopMenuBar (Nlm_GraphiC mb, Nlm_Boolean savePort)
  2356.  
  2357. /*
  2358. *  A submenu is linked into the desktop menu bar immediately after the menu
  2359. *  that contains it is created.  Thus, removal of desktop menus cannot safely
  2360. *  get the next child in the list of menus right before removing a link, since
  2361. *  that next child, if a submenu, will immediately become a dangling pointer.
  2362. *  Removal of desktop menus must instead repeatedly remove the first child of
  2363. *  the desktop menu bar.
  2364. */
  2365.  
  2366. {
  2367.   Nlm_MenuTool  h;
  2368.   Nlm_MenU      m;
  2369.   Nlm_WindoW    tempPort;
  2370.  
  2371.   tempPort = Nlm_SavePortIfNeeded (mb, savePort);
  2372.   m = (Nlm_MenU) Nlm_GetChild (mb);
  2373.   while (m != NULL) {
  2374.     Nlm_DeactivateInnerMenus (m);
  2375.     Nlm_DoRemove ((Nlm_GraphiC) m, FALSE);
  2376.     m = (Nlm_MenU) Nlm_GetChild (mb);
  2377.   }
  2378.   Nlm_HandFree (mb);
  2379.   recentMenuBar = NULL;
  2380.   Nlm_RestorePort (tempPort);
  2381. }
  2382. #endif
  2383.  
  2384. static void Nlm_RemoveWindowMenuBar (Nlm_GraphiC mb, Nlm_Boolean savePort)
  2385.  
  2386. {
  2387.   Nlm_MenuTool  h;
  2388.   Nlm_MenU      m;
  2389.   Nlm_MenU      n;
  2390.   Nlm_WindoW    tempPort;
  2391.   Nlm_WindoW    w;
  2392.  
  2393.   tempPort = Nlm_SavePortIfNeeded (mb, savePort);
  2394.   m = (Nlm_MenU) Nlm_GetChild (mb);
  2395.   while (m != NULL) {
  2396.     n = (Nlm_MenU) Nlm_GetNext ((Nlm_GraphiC) m);
  2397.     Nlm_DeactivateInnerMenus (m);
  2398.     m = n;
  2399.   }
  2400.   m = (Nlm_MenU) Nlm_GetChild (mb);
  2401.   while (m != NULL) {
  2402.     n = (Nlm_MenU) Nlm_GetNext ((Nlm_GraphiC) m);
  2403.     Nlm_DoRemove ((Nlm_GraphiC) m, FALSE);
  2404.     m = n;
  2405.   }
  2406.   w = Nlm_GetParentWindow ((Nlm_GraphiC) mb);
  2407.   Nlm_SetWindowMenuBar (w, NULL);
  2408. #ifdef WIN_MSWIN
  2409.   h = Nlm_GetMenuBarHandle ((Nlm_MenuBaR) mb);
  2410.   DestroyMenu (h);
  2411. #endif
  2412. #ifdef WIN_MOTIF
  2413.   h = Nlm_GetMenuBarHandle ((Nlm_MenuBaR) mb);
  2414.   XtDestroyWidget (h);
  2415. #endif
  2416.   Nlm_HandFree (mb);
  2417.   recentMenuBar = NULL;
  2418.   Nlm_RestorePort (tempPort);
  2419. }
  2420.  
  2421. #ifdef WIN_MAC
  2422. static void Nlm_RemoveDesktopMenu (Nlm_GraphiC m, Nlm_Boolean savePort)
  2423.  
  2424. {
  2425.   Nlm_IteM      i;
  2426.   Nlm_MenuTool  h;
  2427.   Nlm_IteM      n;
  2428.   Nlm_WindoW    tempPort;
  2429.  
  2430.   tempPort = Nlm_SavePortIfNeeded (m, savePort);
  2431.   i = (Nlm_IteM) Nlm_GetChild (m);
  2432.   while (i != NULL) {
  2433.     n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
  2434.     Nlm_DoRemove ((Nlm_GraphiC) i, FALSE);
  2435.     i = n;
  2436.   }
  2437.   h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  2438.   DisposeMenu (h);
  2439.   DrawMenuBar ();
  2440.   Nlm_RemoveLink (m);
  2441.   recentMenu = NULL;
  2442.   Nlm_RestorePort (tempPort);
  2443. }
  2444. #endif
  2445.  
  2446. static void Nlm_RemoveSubMenu (Nlm_GraphiC m, Nlm_Boolean savePort)
  2447.  
  2448. {
  2449.   Nlm_IteM      i;
  2450.   Nlm_MenuTool  h;
  2451.   Nlm_IteM      n;
  2452.   Nlm_WindoW    tempPort;
  2453. #ifdef WIN_MAC
  2454.   Nlm_MenuBaR   mb;
  2455. #endif
  2456.  
  2457.   tempPort = Nlm_SavePortIfNeeded (m, savePort);
  2458.   Nlm_DoDisable (m, TRUE, FALSE);
  2459.   i = (Nlm_IteM) Nlm_GetChild (m);
  2460.   while (i != NULL) {
  2461.     n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
  2462.     Nlm_DoRemove ((Nlm_GraphiC) i, FALSE);
  2463.     i = n;
  2464.   }
  2465.   h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  2466. #ifdef WIN_MAC
  2467.   DisposeMenu (h);
  2468. #endif
  2469. #ifdef WIN_MSWIN
  2470.   DestroyMenu (h);
  2471. #endif
  2472. #ifdef WIN_MOTIF
  2473. #endif
  2474. #ifdef WIN_MAC
  2475.   i = (Nlm_IteM) Nlm_GetParent (m);
  2476.   Nlm_SetSubMenu (i, NULL);
  2477.   mb = Nlm_GetWindowMenuBar (Nlm_desktopWindow);
  2478.   Nlm_SetParent (m, (Nlm_GraphiC) mb);
  2479.   Nlm_RemoveLink (m);
  2480. #else
  2481.   Nlm_HandFree (m);
  2482. #endif
  2483.   recentMenu = NULL;
  2484.   Nlm_RestorePort (tempPort);
  2485. }
  2486.  
  2487. static void Nlm_RemovePopupMenu (Nlm_GraphiC m, Nlm_Boolean savePort)
  2488.  
  2489. {
  2490.   Nlm_IteM       i;
  2491.   Nlm_IteM       n;
  2492.   Nlm_PrompT     p;
  2493.   Nlm_WindoW     tempPort;
  2494.   Nlm_PopupTool  u;
  2495. #ifdef WIN_MAC
  2496.   Nlm_MenuTool   h;
  2497. #endif
  2498. #ifdef WIN_MOTIF
  2499.   Nlm_MenuTool   h;
  2500.   Nlm_PopupTool  pop;
  2501. #endif
  2502.  
  2503.   tempPort = Nlm_SavePortIfNeeded (m, savePort);
  2504.   i = (Nlm_IteM) Nlm_GetChild (m);
  2505.   while (i != NULL) {
  2506.     n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
  2507.     Nlm_DoRemove ((Nlm_GraphiC) i, FALSE);
  2508.     i = n;
  2509.   }
  2510. #ifdef WIN_MAC
  2511.   h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  2512.   DisposeMenu (h);
  2513. #endif
  2514. #ifdef WIN_MSWIN
  2515.   u = Nlm_GetMenuPopup ((Nlm_MenU) m);
  2516.   if (u != NULL) {
  2517.     RemoveProp (u, (LPSTR) "Nlm_VibrantProp");
  2518.     DestroyWindow (u);
  2519.   }
  2520. #endif
  2521. #ifdef WIN_MOTIF
  2522.   h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  2523.   if (h != NULL) {
  2524.     /*
  2525.       This code will, for some unknown reason, crash on the next
  2526.       update if you run a program from outside the window manager.
  2527.     */
  2528.     /*
  2529.     XtDestroyWidget (h);
  2530.     */
  2531.   }
  2532.   pop = Nlm_GetMenuPopup ((Nlm_MenU) m);
  2533.   if (pop != NULL) {
  2534.     XtDestroyWidget (pop);
  2535.   }
  2536. #endif
  2537.   p = Nlm_GetMenuPrompt ((Nlm_MenU) m);
  2538.   if (p != NULL) {
  2539.     Nlm_DoRemove ((Nlm_GraphiC) p, FALSE);
  2540.   }
  2541.   Nlm_RemoveLink (m);
  2542.   recentMenu = NULL;
  2543.   Nlm_RestorePort (tempPort);
  2544. }
  2545.  
  2546. static void Nlm_RemovePopListMenu (Nlm_GraphiC m, Nlm_Boolean savePort)
  2547.  
  2548. {
  2549.   Nlm_IteM       i;
  2550.   Nlm_IteM       n;
  2551.   Nlm_PrompT     p;
  2552.   Nlm_WindoW     tempPort;
  2553.   Nlm_PopupTool  u;
  2554. #ifdef WIN_MAC
  2555.   Nlm_MenuTool   h;
  2556. #endif
  2557.  
  2558.   tempPort = Nlm_SavePortIfNeeded (m, savePort);
  2559.   i = (Nlm_IteM) Nlm_GetChild (m);
  2560.   while (i != NULL) {
  2561.     n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
  2562.     Nlm_DoRemove ((Nlm_GraphiC) i, FALSE);
  2563.     i = n;
  2564.   }
  2565. #ifdef WIN_MAC
  2566.   h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  2567.   DisposeMenu (h);
  2568. #endif
  2569. #ifdef WIN_MSWIN
  2570.   u = Nlm_GetMenuPopup ((Nlm_MenU) m);
  2571.   if (u != NULL) {
  2572.     RemoveProp (u, (LPSTR) "Nlm_VibrantProp");
  2573.     DestroyWindow (u);
  2574.   }
  2575. #endif
  2576. #ifdef WIN_MOTIF
  2577. #endif
  2578.   p = Nlm_GetMenuPrompt ((Nlm_MenU) m);
  2579.   if (p != NULL) {
  2580.     Nlm_DoRemove ((Nlm_GraphiC) p, FALSE);
  2581.   }
  2582.   Nlm_RemoveLink (m);
  2583.   recentMenu = NULL;
  2584.   Nlm_RestorePort (tempPort);
  2585. }
  2586.  
  2587. static void Nlm_RemovePopupList (Nlm_GraphiC c, Nlm_Boolean savePort)
  2588.  
  2589. /*
  2590. *  If the user calls Remove (c) to remove the popup list, then
  2591. *  savePort will be TRUE, and the implicitly created parent menu
  2592. *  is also removed.  If the user calls Remove (w) to remove the
  2593. *  parent window, then RemovePopupList will be called by the
  2594. *  implicitly created parent menu just prior to its removal, and
  2595. *  an additional attempt to remove the menu is both unnecessary
  2596. *  and possibly dangerous.
  2597. */
  2598.  
  2599. {
  2600.   Nlm_MenU      m;
  2601.   Nlm_WindoW    tempPort;
  2602. #ifdef WIN_MOTIF
  2603.   Nlm_ItemTool   PNTR hdls;
  2604. #endif
  2605.  
  2606.   tempPort = Nlm_SavePortIfNeeded (c, savePort);
  2607. #ifdef WIN_MOTIF
  2608.   hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
  2609.   if (hdls != NULL) {
  2610.     Nlm_MemFree (hdls);
  2611.   }
  2612. #endif
  2613.   m = (Nlm_MenU) Nlm_GetParent (c);
  2614.   Nlm_RemoveLink (c);
  2615.   recentItem = NULL;
  2616.   recentChoice = NULL;
  2617.   if (savePort) {
  2618.     Nlm_DoRemove ((Nlm_GraphiC) m, FALSE);
  2619.   }
  2620.   Nlm_RestorePort (tempPort);
  2621. }
  2622.  
  2623. static void Nlm_RemoveMenuItem (Nlm_GraphiC i, Nlm_Boolean savePort)
  2624.  
  2625. {
  2626.   Nlm_MenU    sub;
  2627.   Nlm_WindoW  tempPort;
  2628.  
  2629.   tempPort = Nlm_SavePortIfNeeded (i, savePort);
  2630.   sub = Nlm_GetSubMenu ((Nlm_IteM) i);
  2631.   if (sub != NULL) {
  2632.     Nlm_DoRemove ((Nlm_GraphiC) sub, FALSE);
  2633.   }
  2634.   Nlm_RemoveLink (i);
  2635.   recentItem = NULL;
  2636.   recentChoice = NULL;
  2637.   Nlm_RestorePort (tempPort);
  2638. }
  2639.  
  2640. static void Nlm_RemoveChoiceGroup (Nlm_GraphiC c, Nlm_Boolean savePort)
  2641.  
  2642. {
  2643.   Nlm_IteM    i;
  2644.   Nlm_IteM    n;
  2645.   Nlm_MenU    sub;
  2646.   Nlm_WindoW  tempPort;
  2647. #ifdef WIN_MOTIF
  2648.   Nlm_ItemTool  PNTR hdls;
  2649. #endif
  2650.  
  2651.   tempPort = Nlm_SavePortIfNeeded (c, savePort);
  2652.   sub = Nlm_GetSubMenu ((Nlm_IteM) c);
  2653.   if (sub != NULL) {
  2654.     Nlm_DoRemove ((Nlm_GraphiC) sub, FALSE);
  2655.   }
  2656. #ifdef WIN_MOTIF
  2657.   hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
  2658.   if (hdls != NULL) {
  2659.     Nlm_MemFree (hdls);
  2660.   }
  2661. #endif
  2662.   i = (Nlm_IteM) Nlm_GetChild (c);
  2663.   while (i != NULL) {
  2664.     n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
  2665.     Nlm_DoRemove ((Nlm_GraphiC) i, FALSE);
  2666.     i = n;
  2667.   }
  2668.   Nlm_RemoveLink (c);
  2669.   recentItem = NULL;
  2670.   recentChoice = NULL;
  2671.   Nlm_RestorePort (tempPort);
  2672. }
  2673.  
  2674. static void Nlm_RemoveChoiceItem (Nlm_GraphiC i, Nlm_Boolean savePort)
  2675.  
  2676. {
  2677.   Nlm_WindoW  tempPort;
  2678.  
  2679.   tempPort = Nlm_SavePortIfNeeded (i, savePort);
  2680.   Nlm_RemoveLink (i);
  2681.   recentItem = NULL;
  2682.   recentChoice = NULL;
  2683.   Nlm_RestorePort (tempPort);
  2684. }
  2685.  
  2686. static void Nlm_ResetMenu (Nlm_GraphiC m, Nlm_Boolean savePort)
  2687.  
  2688. {
  2689. #ifdef WIN_MAC
  2690.   Nlm_Int2      cnt;
  2691.   Nlm_IteM      i;
  2692.   Nlm_MenuTool  h;
  2693.   Nlm_IteM      n;
  2694.   Nlm_WindoW    tempPort;
  2695.  
  2696.   tempPort = Nlm_SavePortIfNeeded (m, savePort);
  2697.   i = (Nlm_IteM) Nlm_GetChild (m);
  2698.   while (i != NULL) {
  2699.     n = (Nlm_IteM) Nlm_GetNext ((Nlm_GraphiC) i);
  2700.     Nlm_DoRemove ((Nlm_GraphiC) i, FALSE);
  2701.     i = n;
  2702.   }
  2703.   h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  2704.   cnt = CountMItems (h);
  2705.   while (cnt > 0) {
  2706.     DelMenuItem (h, cnt);
  2707.     cnt--;
  2708.   }
  2709.   Nlm_RestorePort (tempPort);
  2710. #endif
  2711. }
  2712.  
  2713. #ifndef WIN_MOTIF
  2714. static void Nlm_ResetPopList (Nlm_GraphiC c, Nlm_Boolean savePort)
  2715.  
  2716. {
  2717.   Nlm_Int2        hbounds;
  2718.   Nlm_MenU        m;
  2719.   Nlm_RecT        r;
  2720.   Nlm_WindoW      tempPort;
  2721.   Nlm_PopupTool   u;
  2722.   Nlm_Int2        vbounds;
  2723. #ifdef WIN_MAC
  2724.   Nlm_Int2        cnt;
  2725.   Nlm_MenuTool    h;
  2726. #endif
  2727.  
  2728.   tempPort = Nlm_SavePortIfNeeded (c, savePort);
  2729.   m = (Nlm_MenU) Nlm_GetParent (c);
  2730. #ifdef WIN_MAC
  2731.   h = Nlm_GetMenuHandle (m);
  2732.   cnt = CountMItems (h);
  2733.   while (cnt > 0) {
  2734.     DelMenuItem (h, cnt);
  2735.     cnt--;
  2736.   }
  2737. #endif
  2738. #ifdef WIN_MSWIN
  2739.   u = Nlm_GetMenuPopup (m);
  2740.   if (u != NULL) {
  2741.     ComboBox_ResetContent (u);
  2742.   }
  2743. #endif
  2744.   Nlm_LoadItemData ((Nlm_IteM) c, NULL, 1, NULL);
  2745.   Nlm_LoadChoiceData ((Nlm_ChoicE) c, 0, TRUE, 0, NULL);
  2746. #ifdef WIN_MAC
  2747.   hbounds = 13;
  2748.   vbounds = 2;
  2749. #endif
  2750. #ifdef WIN_MSWIN
  2751.   hbounds = 13;
  2752.   vbounds = 4;
  2753. #endif
  2754.   Nlm_GetRect ((Nlm_GraphiC) m, &r);
  2755.   r.right = r.left + hbounds * 2;
  2756.   r.bottom = r.top + Nlm_stdLineHeight + vbounds * 2;
  2757.   Nlm_DoSetPosition ((Nlm_GraphiC) c, &r, FALSE);
  2758.   Nlm_RestorePort (tempPort);
  2759. }
  2760. #endif
  2761.  
  2762. #ifdef WIN_MOTIF
  2763. static void Nlm_NewPopupList (Nlm_MenU m, Nlm_ChoicE c, Nlm_PupActnProc actn);
  2764.  
  2765. static void Nlm_ResetPopList (Nlm_GraphiC c, Nlm_Boolean savePort)
  2766.  
  2767. {
  2768.   Nlm_PupActnProc  actn;
  2769.   Nlm_ChoiceData   cdata;
  2770.   Nlm_GraphicData  gdata;
  2771.   Nlm_MenuTool     h;
  2772.   Nlm_ItemTool     *hdls;
  2773.   Nlm_Int2         i;
  2774.   Nlm_ItemData     idata;
  2775.   Nlm_ItemTool     itool;
  2776.   Nlm_PopupTool    pop;
  2777.   Nlm_MenU         m;
  2778.   Nlm_WindoW       tempPort;
  2779.  
  2780.   tempPort = Nlm_SavePortIfNeeded (c, savePort);
  2781.   m = (Nlm_MenU) Nlm_GetParent (c);
  2782.   Nlm_DoSetValue (c, 0, FALSE);
  2783.   Nlm_GetGraphicData (c, &gdata);
  2784.   actn = (Nlm_PupActnProc) gdata.action;
  2785.   hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
  2786.   if (hdls != NULL) {
  2787.     for (i = 0; i < 64; i++) {
  2788.       itool = hdls [i];
  2789.       if (itool != NULL) {
  2790.         XtUnmanageChild (itool);
  2791.         XtDestroyWidget (itool);
  2792.         hdls [i] = NULL;
  2793.       }
  2794.     }
  2795.     Nlm_MemFree (hdls);
  2796.   }
  2797.   pop = Nlm_GetMenuPopup (m);
  2798.   if (pop != NULL) {
  2799.     XtDestroyWidget (pop);
  2800.   }
  2801.   h = Nlm_GetMenuHandle (m);
  2802.   if (h != NULL) {
  2803.     XtDestroyWidget (h);
  2804.   }
  2805.   Nlm_NewPopupList (m, (Nlm_ChoicE) c, actn);
  2806.   Nlm_RestorePort (tempPort);
  2807. }
  2808. #endif
  2809.  
  2810. static Nlm_Int2 Nlm_CountMenuItems (Nlm_GraphiC m)
  2811.  
  2812. {
  2813.   Nlm_MenuTool  h;
  2814.   Nlm_Int2      rsult;
  2815.  
  2816.   rsult = 0;
  2817.   h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  2818. #ifdef WIN_MAC
  2819.   rsult = CountMItems (h);
  2820. #endif
  2821. #ifdef WIN_MSWIN
  2822.   rsult = GetMenuItemCount (h);
  2823. #endif
  2824. #ifdef WIN_MOTIF
  2825. #endif
  2826.   return rsult;
  2827. }
  2828.  
  2829. static Nlm_Int2 Nlm_CountChoiceItems (Nlm_GraphiC c)
  2830.  
  2831. {
  2832.   return (Nlm_GetNumItems ((Nlm_ChoicE) c));
  2833. }
  2834.  
  2835. static void Nlm_SetMenuItem (Nlm_MenU m, Nlm_Int2 item,
  2836.                              Nlm_CharPtr itemName)
  2837.  
  2838. {
  2839. #ifdef WIN_MAC
  2840.   Nlm_MenuTool  h;
  2841.   Nlm_Char      temp [256];
  2842.  
  2843.   h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  2844.   if (item > 0) {
  2845.     if (Nlm_StringLen (itemName) == 0) {
  2846.       temp [0] = '(';
  2847.       temp [1] = '\0';
  2848.       Nlm_CtoPstr (temp);
  2849.       SetItem (h, item, (StringPtr) temp);
  2850.     } else {
  2851.       Nlm_StringNCpy (temp, itemName, sizeof (temp));
  2852.       Nlm_CtoPstr (temp);
  2853.       SetItem (h, item, (StringPtr) temp);
  2854.     }
  2855.   }
  2856. #endif
  2857. }
  2858.  
  2859. static void Nlm_SetSingleTitle (Nlm_GraphiC i, Nlm_Int2 item,
  2860.                                 Nlm_CharPtr title, Nlm_Boolean savePort)
  2861.  
  2862. {
  2863.   Nlm_Int2    itm;
  2864.   Nlm_MenU    m;
  2865.   Nlm_WindoW  tempPort;
  2866.  
  2867.   tempPort = Nlm_SavePortIfNeeded (i, savePort);
  2868.   m = (Nlm_MenU) Nlm_GetParent (i);
  2869.   itm = Nlm_GetFirstItem ((Nlm_IteM) i);
  2870.   Nlm_SetMenuItem (m, itm, title);
  2871.   Nlm_RestorePort (tempPort);
  2872. }
  2873.  
  2874. static void Nlm_SetChoiceTitle (Nlm_GraphiC c, Nlm_Int2 item,
  2875.                                 Nlm_CharPtr title, Nlm_Boolean savePort)
  2876.  
  2877. {
  2878.   Nlm_Int2    first;
  2879.   Nlm_MenU    m;
  2880.   Nlm_Int2    num;
  2881.   Nlm_PrompT  p;
  2882.   Nlm_WindoW  tempPort;
  2883.  
  2884.   tempPort = Nlm_SavePortIfNeeded (c, savePort);
  2885.   first = Nlm_GetFirstItem ((Nlm_IteM) c);
  2886.   num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  2887.   m = (Nlm_MenU) Nlm_GetParent (c);
  2888.   if (item > 0 && item <= num) {
  2889.     Nlm_SetMenuItem (m, first + item - 1, title);
  2890.   } else if (item == 0) {
  2891.     p = Nlm_GetMenuPrompt (m);
  2892.     if (p != NULL) {
  2893.       Nlm_DoSetTitle ((Nlm_GraphiC) p, 0, title, FALSE);
  2894.     }
  2895.   }
  2896.   Nlm_RestorePort (tempPort);
  2897. }
  2898.  
  2899. static void Nlm_SetChoiceGroupTitle (Nlm_GraphiC c, Nlm_Int2 item,
  2900.                                      Nlm_CharPtr title, Nlm_Boolean savePort)
  2901.  
  2902. {
  2903.   Nlm_MenU    m;
  2904.   Nlm_PrompT  p;
  2905.   Nlm_WindoW  tempPort;
  2906.  
  2907.   tempPort = Nlm_SavePortIfNeeded (c, savePort);
  2908.   m = (Nlm_MenU) Nlm_GetParent (c);
  2909.   p = Nlm_GetMenuPrompt (m);
  2910.   if (p != NULL) {
  2911.     Nlm_DoSetTitle ((Nlm_GraphiC) p, 0, title, FALSE);
  2912.   }
  2913.   Nlm_RestorePort (tempPort);
  2914. }
  2915.  
  2916. static void Nlm_SetChoiceItemTitle (Nlm_GraphiC i, Nlm_Int2 item,
  2917.                                     Nlm_CharPtr title, Nlm_Boolean savePort)
  2918.  
  2919. {
  2920.   Nlm_ChoicE  c;
  2921.   Nlm_Int2    first;
  2922.   Nlm_Int2    index;
  2923.   Nlm_MenU    m;
  2924.   Nlm_WindoW  tempPort;
  2925.  
  2926.   tempPort = Nlm_SavePortIfNeeded (i, savePort);
  2927.   c = (Nlm_ChoicE) Nlm_GetParent (i);
  2928.   index = Nlm_GetFirstItem ((Nlm_IteM) i);
  2929.   first = Nlm_GetFirstItem ((Nlm_IteM) c);
  2930.   m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
  2931.   Nlm_SetMenuItem (m, first + index - 1, title);
  2932.   Nlm_RestorePort (tempPort);
  2933. }
  2934.  
  2935. static void Nlm_SetPopListTitle (Nlm_GraphiC c, Nlm_Int2 item,
  2936.                                  Nlm_CharPtr title, Nlm_Boolean savePort)
  2937.  
  2938. {
  2939. #ifdef WIN_MAC
  2940.   Nlm_SetChoiceTitle (c, item, title, savePort);
  2941. #endif
  2942. }
  2943.  
  2944. static void Nlm_SetSubmenuTitle (Nlm_GraphiC m, Nlm_Int2 item,
  2945.                                  Nlm_CharPtr title, Nlm_Boolean savePort)
  2946.  
  2947. {
  2948. #ifdef WIN_MAC
  2949.   Nlm_IteM    i;
  2950.   Nlm_WindoW  tempPort;
  2951.  
  2952.   tempPort = Nlm_SavePortIfNeeded (m, savePort);
  2953.   i = (Nlm_IteM) Nlm_GetParent (m);
  2954.   if (i != NULL) {
  2955.     Nlm_SetSingleTitle ((Nlm_GraphiC) i, item, title, FALSE);
  2956.   }
  2957.   Nlm_RestorePort (tempPort);
  2958. #endif
  2959. }
  2960.  
  2961. static void Nlm_GetMenuItem (Nlm_GraphiC m, Nlm_Int2 item,
  2962.                              Nlm_CharPtr itemName, Nlm_sizeT maxsize)
  2963.  
  2964. {
  2965.   Nlm_MenuTool  h;
  2966.   Nlm_Int2      id;
  2967.   Nlm_Char      temp [256];
  2968. #ifdef WIN_MOTIF
  2969.   XmString      label;
  2970.   char          *text;
  2971. #endif
  2972.  
  2973.   h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  2974.   if (item > 0) {
  2975. #ifdef WIN_MAC
  2976.     GetItem (h, item, (StringPtr) temp);
  2977.     Nlm_PtoCstr (temp);
  2978. #endif
  2979. #ifdef WIN_MSWIN
  2980.     id = Nlm_ItemToID ((Nlm_MenU) m, item);
  2981.     GetMenuString (h, id, temp, sizeof (temp), MF_BYCOMMAND);
  2982. #endif
  2983. #ifdef WIN_MOTIF
  2984.     XtVaGetValues (h, XmNlabelString, &label, NULL);
  2985.     temp [0] = '\0';
  2986.     if (XmStringGetLtoR (label, XmSTRING_DEFAULT_CHARSET, &text)) {
  2987.       Nlm_StringNCpy (temp, text, sizeof (temp));
  2988.       XtFree (text);
  2989.     }
  2990. #endif
  2991.   } else {
  2992.     temp [0] = '\0';
  2993.   }
  2994.   Nlm_StringNCpy (itemName, temp, maxsize);
  2995. }
  2996.  
  2997. static void Nlm_GetSingleTitle (Nlm_GraphiC i, Nlm_Int2 item,
  2998.                                 Nlm_CharPtr title, Nlm_sizeT maxsize)
  2999.  
  3000. {
  3001.   Nlm_Int2  itm;
  3002.   Nlm_MenU  m;
  3003.  
  3004.   m = (Nlm_MenU) Nlm_GetParent (i);
  3005.   itm = Nlm_GetFirstItem ((Nlm_IteM) i);
  3006.   Nlm_GetMenuItem ((Nlm_GraphiC) m, itm, title, maxsize);
  3007. }
  3008.  
  3009. extern void Nlm_GetChoiceTitle (Nlm_GraphiC c, Nlm_Int2 item,
  3010.                                 Nlm_CharPtr title, Nlm_sizeT maxsize)
  3011.  
  3012. {
  3013.   Nlm_Int2    first;
  3014.   Nlm_MenU    m;
  3015.   Nlm_Int2    num;
  3016.   Nlm_PrompT  p;
  3017.  
  3018.   first = Nlm_GetFirstItem ((Nlm_IteM) c);
  3019.   num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  3020.   m = (Nlm_MenU) Nlm_GetParent (c);
  3021.   if (item > 0 && item <= num) {
  3022.     Nlm_GetMenuItem ((Nlm_GraphiC) m, first + item - 1, title, maxsize);
  3023.   } else if (item == 0) {
  3024.     p = Nlm_GetMenuPrompt (m);
  3025.     if (p != NULL) {
  3026.       Nlm_DoGetTitle ((Nlm_GraphiC) p, 0, title, maxsize);
  3027.     }
  3028.   }
  3029. }
  3030.  
  3031. static void Nlm_GetChoiceGroupTitle (Nlm_GraphiC c, Nlm_Int2 item,
  3032.                                      Nlm_CharPtr title, Nlm_sizeT maxsize)
  3033.  
  3034. {
  3035.   Nlm_MenU    m;
  3036.   Nlm_PrompT  p;
  3037.  
  3038.   m = (Nlm_MenU) Nlm_GetParent (c);
  3039.   p = Nlm_GetMenuPrompt (m);
  3040.   if (p != NULL) {
  3041.     Nlm_DoGetTitle ((Nlm_GraphiC) p, 0, title, maxsize);
  3042.   }
  3043. }
  3044.  
  3045. static void Nlm_GetChoiceItemTitle (Nlm_GraphiC i, Nlm_Int2 item,
  3046.                                     Nlm_CharPtr title, Nlm_sizeT maxsize)
  3047.  
  3048. {
  3049.   Nlm_ChoicE  c;
  3050.   Nlm_Int2    first;
  3051.   Nlm_Int2    index;
  3052.   Nlm_MenU    m;
  3053.  
  3054.   c = (Nlm_ChoicE) Nlm_GetParent (i);
  3055.   index = Nlm_GetFirstItem ((Nlm_IteM) i);
  3056.   first = Nlm_GetFirstItem ((Nlm_IteM) c);
  3057.   m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
  3058.   Nlm_GetMenuItem ((Nlm_GraphiC) m, first + index - 1, title, maxsize);
  3059. }
  3060.  
  3061. static void Nlm_GetPopListTitle (Nlm_GraphiC c, Nlm_Int2 item,
  3062.                                  Nlm_CharPtr title, Nlm_sizeT maxsize)
  3063.  
  3064. {
  3065.   Nlm_MenU       m;
  3066.   Nlm_Char       temp [256];
  3067.   Nlm_PopupTool  u;
  3068.  
  3069.   m = (Nlm_MenU) Nlm_GetParent (c);
  3070. #ifdef WIN_MAC
  3071.   Nlm_GetChoiceTitle (c, item, title, maxsize);
  3072. #endif
  3073. #ifdef WIN_MSWIN
  3074.   u = Nlm_GetMenuPopup (m);
  3075.   if (u != NULL) {
  3076.     if (ComboBox_GetLBTextLen (u, item - 1) < sizeof (temp)) {
  3077.       ComboBox_GetLBText (u, item - 1, temp);
  3078.     } else {
  3079.       temp [0] = '\0';
  3080.     }
  3081.     Nlm_StringNCpy (title, temp, maxsize);
  3082.   }
  3083. #endif
  3084. #ifdef WIN_MOTIF
  3085. #endif
  3086. }
  3087.  
  3088. static void Nlm_GetSubmenuTitle (Nlm_GraphiC m, Nlm_Int2 item,
  3089.                                  Nlm_CharPtr title, Nlm_sizeT maxsize)
  3090.  
  3091. {
  3092. #ifdef WIN_MAC
  3093.   Nlm_IteM  i;
  3094.  
  3095.   i = (Nlm_IteM) Nlm_GetParent (m);
  3096.   if (i != NULL) {
  3097.     Nlm_GetSingleTitle ((Nlm_GraphiC) i, item, title, maxsize);
  3098.   }
  3099. #endif
  3100. #ifdef WIN_MSWIN
  3101.   if (title != NULL && maxsize > 0) {
  3102.     title [0] = '\0';
  3103.   }
  3104. #endif
  3105. #ifdef WIN_MOTIF
  3106.   if (title != NULL && maxsize > 0) {
  3107.     title [0] = '\0';
  3108.   }
  3109. #endif
  3110. }
  3111.  
  3112. static void Nlm_SetStatValue (Nlm_GraphiC i, Nlm_Int2 item,
  3113.                               Nlm_Boolean value, Nlm_Boolean savePort)
  3114.  
  3115. {
  3116.   Nlm_Int2      itm;
  3117.   Nlm_ItemTool  itool;
  3118.   Nlm_MenU      m;
  3119.   Nlm_WindoW    tempPort;
  3120.  
  3121.   tempPort = Nlm_SavePortIfNeeded (i, savePort);
  3122.   m = (Nlm_MenU) Nlm_GetParent (i);
  3123.   itm = Nlm_GetFirstItem ((Nlm_IteM) i);
  3124.   itool = Nlm_GetItemHandle ((Nlm_IteM) i);
  3125.   Nlm_CheckMenuItem (m, itool, itm, value);
  3126.   Nlm_RestorePort (tempPort);
  3127. }
  3128.  
  3129. static void Nlm_SetChoiceValue (Nlm_GraphiC c, Nlm_Int2 value, Nlm_Boolean savePort)
  3130.  
  3131. {
  3132.   Nlm_Int2      first;
  3133.   Nlm_ItemTool  PNTR hdls;
  3134.   Nlm_Int2      index;
  3135.   Nlm_ItemTool  itool;
  3136.   Nlm_MenU      m;
  3137.   Nlm_Int2      num;
  3138.   Nlm_WindoW    tempPort;
  3139.  
  3140.   tempPort = Nlm_SavePortIfNeeded (c, savePort);
  3141.   first = Nlm_GetFirstItem ((Nlm_IteM) c);
  3142.   num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  3143.   m = (Nlm_MenU) Nlm_GetParent (c);
  3144.   index = 1;
  3145.   hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
  3146.   while (index <= num) {
  3147.     if (hdls != NULL) {
  3148.       itool = hdls [index - 1];
  3149.     } else {
  3150.       itool = NULL;
  3151.     }
  3152.     Nlm_CheckMenuItem (m, itool, first + index - 1, FALSE);
  3153.     index++;
  3154.   }
  3155.   if (value > 0 && value <= num) {
  3156.     if (hdls != NULL) {
  3157.       itool = hdls [value - 1];
  3158.     } else {
  3159.       itool = NULL;
  3160.     }
  3161.     Nlm_CheckMenuItem (m, itool, first + value - 1, TRUE);
  3162.   }
  3163.   Nlm_RestorePort (tempPort);
  3164. }
  3165.  
  3166. static void Nlm_SetChoiceGroupValue (Nlm_GraphiC c, Nlm_Int2 value, Nlm_Boolean savePort)
  3167.  
  3168. {
  3169.   Nlm_Int2      first;
  3170.   Nlm_ItemTool  PNTR hdls;
  3171.   Nlm_Int2      index;
  3172.   Nlm_ItemTool  itool;
  3173.   Nlm_MenU      m;
  3174.   Nlm_Int2      num;
  3175.   Nlm_WindoW    tempPort;
  3176.  
  3177.   tempPort = Nlm_SavePortIfNeeded (c, savePort);
  3178.   first = Nlm_GetFirstItem ((Nlm_IteM) c);
  3179.   num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  3180.   m = (Nlm_MenU) Nlm_GetParent (c);
  3181.   index = 1;
  3182.   hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
  3183.   while (index <= num) {
  3184.     if (hdls != NULL) {
  3185.       itool = hdls [index - 1];
  3186.     } else {
  3187.       itool = NULL;
  3188.     }
  3189.     Nlm_CheckMenuItem (m, itool, first + index - 1, FALSE);
  3190.     index++;
  3191.   }
  3192.   if (value > 0 && value <= num) {
  3193.     if (hdls != NULL) {
  3194.       itool = hdls [value - 1];
  3195.     } else {
  3196.       itool = NULL;
  3197.     }
  3198.     Nlm_CheckMenuItem (m, itool, first + value - 1, TRUE);
  3199.   }
  3200.   Nlm_RestorePort (tempPort);
  3201. }
  3202.  
  3203. static void Nlm_SetPopListValue (Nlm_GraphiC c, Nlm_Int2 value, Nlm_Boolean savePort)
  3204.  
  3205. {
  3206.   Nlm_MenU       m;
  3207.   Nlm_WindoW     tempPort;
  3208.   Nlm_PopupTool  u;
  3209. #ifdef WIN_MAC
  3210.   Nlm_RecT       r;
  3211. #endif
  3212. #ifdef WIN_MOTIF
  3213.   Nlm_ItemTool   PNTR hdls;
  3214. #endif
  3215.  
  3216.   tempPort = Nlm_SavePortIfNeeded (c, savePort);
  3217.   m = (Nlm_MenU) Nlm_GetParent (c);
  3218. #ifdef WIN_MAC
  3219.   Nlm_SetChoiceValue (c, value, FALSE);
  3220.   if (Nlm_GetVisible (c) && Nlm_GetAllParentsVisible (c)) {
  3221.     Nlm_GetRect ((Nlm_GraphiC) m, &r);
  3222.     Nlm_UpsetRect (&r, 1, 1, 2, 2);
  3223.     Nlm_InvalRect (&r);
  3224.   }
  3225. #endif
  3226. #ifdef WIN_MSWIN
  3227.   u = Nlm_GetMenuPopup (m);
  3228.   if (u != NULL) {
  3229.     if (value > 0) {
  3230.       ComboBox_SetCurSel (u, value - 1);
  3231.     } else {
  3232.       ComboBox_SetCurSel (u, -1);
  3233.     }
  3234.   }
  3235. #endif
  3236. #ifdef WIN_MOTIF
  3237.   Nlm_SetPopupValue ((Nlm_ChoicE) c, value);
  3238.   u = Nlm_GetMenuPopup (m);
  3239.   if (u != NULL) {
  3240.     hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
  3241.     if (value > 0) {
  3242.       XtVaSetValues (u, XmNmenuHistory, hdls [value - 1], NULL);
  3243.       XtUnmanageChild (hdls [63]);
  3244.     } else {
  3245.       XtVaSetValues (u, XmNmenuHistory, hdls [63], NULL);
  3246.       XtManageChild (hdls [63]);
  3247.     }
  3248.   }
  3249. #endif
  3250.   Nlm_RestorePort (tempPort);
  3251. }
  3252.  
  3253. static Nlm_Boolean Nlm_GetStatValue (Nlm_GraphiC i, Nlm_Int2 item)
  3254.  
  3255. {
  3256.   Nlm_Int2      itm;
  3257.   Nlm_ItemTool  itool;
  3258.   Nlm_MenU      m;
  3259.  
  3260.   m = (Nlm_MenU) Nlm_GetParent (i);
  3261.   itm = Nlm_GetFirstItem ((Nlm_IteM) i);
  3262.   itool = Nlm_GetItemHandle ((Nlm_IteM) i);
  3263.   return (Nlm_IsMenuItemChecked (m, itool, itm));
  3264. }
  3265.  
  3266. static Nlm_Int2 Nlm_GetChoiceValue (Nlm_GraphiC c)
  3267.  
  3268. {
  3269.   Nlm_Int2      first;
  3270.   Nlm_ItemTool  PNTR hdls;
  3271.   Nlm_Int2      itm;
  3272.   Nlm_ItemTool  itool;
  3273.   Nlm_MenU      m;
  3274.   Nlm_Int2      num;
  3275.   Nlm_Int2      rsult;
  3276.  
  3277.   rsult = 0;
  3278.   first = Nlm_GetFirstItem ((Nlm_IteM) c);
  3279.   num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  3280.   m = (Nlm_MenU) Nlm_GetParent (c);
  3281.   itm = 1;
  3282.   hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
  3283.   while (itm <= num && rsult == 0) {
  3284.     if (hdls != NULL) {
  3285.       itool = hdls [itm - 1];
  3286.     } else {
  3287.       itool = NULL;
  3288.     }
  3289.     if (Nlm_IsMenuItemChecked (m, itool, first + itm - 1)) {
  3290.       rsult = itm;
  3291.     }
  3292.     itm++;
  3293.   }
  3294.   return rsult;
  3295. }
  3296.  
  3297. static Nlm_Int2 Nlm_GetChoiceGroupValue (Nlm_GraphiC c)
  3298.  
  3299. {
  3300.   Nlm_Int2      first;
  3301.   Nlm_ItemTool  PNTR hdls;
  3302.   Nlm_Int2      itm;
  3303.   Nlm_ItemTool  itool;
  3304.   Nlm_MenU      m;
  3305.   Nlm_Int2      num;
  3306.   Nlm_Int2      rsult;
  3307.  
  3308.   rsult = 0;
  3309.   first = Nlm_GetFirstItem ((Nlm_IteM) c);
  3310.   num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  3311.   m = (Nlm_MenU) Nlm_GetParent (c);
  3312.   itm = 1;
  3313.   hdls = Nlm_GetChoiceHandles ((Nlm_ChoicE) c);
  3314.   while (itm <= num && rsult == 0) {
  3315.     if (hdls != NULL) {
  3316.       itool = hdls [itm - 1];
  3317.     } else {
  3318.       itool = NULL;
  3319.     }
  3320.     if (Nlm_IsMenuItemChecked (m, itool, first + itm - 1)) {
  3321.       rsult = itm;
  3322.     }
  3323.     itm++;
  3324.   }
  3325.   return rsult;
  3326. }
  3327.  
  3328. static Nlm_Int2 Nlm_GetPopListValue (Nlm_GraphiC c)
  3329.  
  3330. {
  3331.   Nlm_MenU       m;
  3332.   Nlm_Int2       rsult;
  3333.   Nlm_PopupTool  u;
  3334.  
  3335.   rsult = 0;
  3336. #ifdef WIN_MAC
  3337.   rsult = Nlm_GetChoiceValue (c);
  3338. #endif
  3339. #ifdef WIN_MSWIN
  3340.   m = (Nlm_MenU) Nlm_GetParent (c);
  3341.   u = Nlm_GetMenuPopup (m);
  3342.   if (u != NULL) {
  3343.     rsult = (WORD) ComboBox_GetCurSel (u) + 1;
  3344.   }
  3345. #endif
  3346. #ifdef WIN_MOTIF
  3347.   rsult = Nlm_GetPopupValue ((Nlm_ChoicE) c);
  3348. #endif
  3349.   return rsult;
  3350. }
  3351.  
  3352.  
  3353. char * kMenuCommandFlag = "%$%"; /* dgg -- external global variable */
  3354.  
  3355. /* M.I */
  3356. static void Nlm_PrepareTitle (Nlm_CharPtr temp, Nlm_CharPtr title,
  3357.                               Nlm_sizeT siztemp, Nlm_Boolean isMenu)
  3358.  
  3359. {
  3360.   Nlm_Uint4     slash;
  3361.   Nlm_Uint4     pos;
  3362.   Nlm_sizeT        poslet;
  3363.   Nlm_Char      letter[2];
  3364.   Nlm_Boolean   found;
  3365.  
  3366.  
  3367.   Nlm_StringNCpy (temp, title, siztemp);
  3368.  
  3369. #ifdef DCLAP
  3370.     /* dgg -- distinguish titles that we want parsed for "/" from those to leave alone */
  3371.   if (!isMenu && StrNCmp(title, kMenuCommandFlag, 3) != 0)  
  3372.        return;    
  3373. #endif
  3374.  
  3375. #ifdef WIN_MAC
  3376.   if (isMenu && Nlm_StrngPos (title, "/", 0, FALSE, &slash)) {
  3377.     temp [slash] = '\0';
  3378.   }
  3379. #endif
  3380. #ifdef WIN_MSWIN
  3381.   if (Nlm_StrngPos (title, "/", 0, FALSE, &slash)) {
  3382.     letter[0] = temp[ slash+1 ];
  3383.     letter[1] = '\0';
  3384.  
  3385. /*  Let's try to match the case...  */
  3386.  
  3387.     found =      Nlm_StrngPos( title, letter, 0, TRUE,  &pos );
  3388.     found =      found && pos < slash;
  3389.     if( !found ) {
  3390.          found = Nlm_StrngPos( title, letter, 0, FALSE, &pos ) ;
  3391.     }
  3392.     poslet = (Nlm_sizeT) pos;
  3393.  
  3394.     if( found && poslet < slash ) {
  3395.  
  3396. /* temp := title[ 0..poslet-1 ] + '&' + title[ poslet..END ] */
  3397.  
  3398.       Nlm_StringNCpy( temp, title, poslet );
  3399.       temp[ poslet ] = '&';
  3400.       Nlm_StringNCpy( temp+poslet+1, title+poslet, siztemp-poslet-1 );
  3401.       temp[ slash+1 ] = '\0';
  3402.  
  3403.     } else {
  3404.       temp [slash] = '\0';
  3405.     }
  3406.   }
  3407. #endif
  3408. #ifdef WIN_MOTIF
  3409.   if (Nlm_StrngPos (title, "/", 0, FALSE, &slash)) {
  3410.     temp [slash] = '\0';
  3411.   }
  3412. #endif
  3413. }
  3414.  
  3415.  
  3416. #ifdef WIN_MOTIF
  3417. static void Nlm_MenuCallback (Widget w, XtPointer client_data, XtPointer call_data)
  3418.  
  3419. {
  3420.   Nlm_GraphiC  i;
  3421.  
  3422.   choiceWidget = w;
  3423.   i = (Nlm_GraphiC) client_data;
  3424.   Nlm_DoCallback (i);
  3425. }
  3426. #endif
  3427.  
  3428. #define COMMAND_ITEM  1
  3429. #define STATUS_ITEM   2
  3430. #define CHOICE_ITEM   3
  3431. #define POPUP_ITEM    4
  3432. #define CASCADE_ITEM  5
  3433.  
  3434. static Nlm_ItemTool Nlm_AppendItems (Nlm_MenU m, Nlm_IteM i, Nlm_CharPtr itemNames,
  3435.                                      Nlm_Int2 type, Nlm_Boolean savePort)
  3436.  
  3437. {
  3438.   Nlm_MenuTool  h;
  3439.   Nlm_ItemTool  rsult;
  3440.   Nlm_Char      temp [256];
  3441.   Nlm_WindoW    tempPort;
  3442. #ifdef WIN_MOTIF
  3443.   XmString      label;
  3444.   Cardinal      n;
  3445.   Arg           wargs [10];
  3446. #endif
  3447.   Nlm_Boolean    isCommandString;
  3448.   
  3449.   rsult = NULL;
  3450.   tempPort = Nlm_SavePortIfNeeded ((Nlm_GraphiC) m, savePort);
  3451.   h = Nlm_GetMenuHandle ((Nlm_MenU) m);
  3452. #ifdef DCLAP
  3453.   isCommandString= FALSE;
  3454.   if ( StrNCmp( itemNames, kMenuCommandFlag, 3 ) == 0) {
  3455.     itemNames += 3;
  3456.     isCommandString= TRUE;
  3457.     }
  3458. #endif
  3459.   Nlm_StringNCpy (temp, itemNames, sizeof (temp));
  3460.   if (temp [0] != '\0') {
  3461. #ifdef WIN_MAC
  3462. #ifdef DCLAP
  3463.     /* dgg fix for menu command char parsing... we dont' want to do that most of time !*/
  3464.   if ( isCommandString  ) {
  3465.      Nlm_CtoPstr (temp);
  3466.     AppendMenu (h, (StringPtr) temp);
  3467.     }
  3468.   else {
  3469.     char dummy[10];
  3470.     short item ;
  3471.     StrCpy(dummy, "empty");
  3472.      Nlm_CtoPstr (dummy);
  3473.     AppendMenu (h, (StringPtr) dummy);
  3474.     item= CountMItems(h);
  3475.     Nlm_CtoPstr (temp);
  3476.     SetItem( h, item, (StringPtr) temp);
  3477.     }
  3478. #else
  3479.     Nlm_CtoPstr (temp);
  3480.     AppendMenu (h, (StringPtr) temp);
  3481. #endif
  3482.  
  3483. #endif
  3484. #ifdef WIN_MSWIN
  3485.     AppendMenu (h, MF_ENABLED, nextMenuNum, itemNames);
  3486.     if (nextMenuNum < 32767) {
  3487.       nextMenuNum++;
  3488.     }
  3489. #endif
  3490. #ifdef WIN_MOTIF
  3491.     label = XmStringCreateSimple (temp);
  3492.     n = 0;
  3493.     XtSetArg (wargs [n], XmNlabelString, label); n++;
  3494.     XtSetArg (wargs [n], XmNfontList, Nlm_XfontList); n++;
  3495.     XtSetArg (wargs [n], XmNmarginHeight, 0); n++;
  3496.     XtSetArg (wargs [n], XmNmarginWidth, 0); n++;
  3497.     XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  3498.     XtSetArg (wargs [n], XmNheight, Nlm_stdLineHeight+10); n++;
  3499.     XtSetArg (wargs [n], XmNrecomputeSize, FALSE); n++;
  3500.     switch (type) {
  3501.       case COMMAND_ITEM:
  3502.         rsult = XmCreatePushButton (h, (String) "", wargs, n);
  3503.         XtAddCallback (rsult, XmNactivateCallback, Nlm_MenuCallback, (XtPointer) i);
  3504.         break;
  3505.       case STATUS_ITEM:
  3506.         XtSetArg (wargs [n], XmNindicatorType, XmN_OF_MANY); n++;
  3507.         rsult = XmCreateToggleButton (h, (String) "", wargs, n);
  3508.         XtAddCallback (rsult, XmNvalueChangedCallback, Nlm_MenuCallback, (XtPointer) i);
  3509.         break;
  3510.       case CHOICE_ITEM:
  3511.         XtSetArg (wargs [n], XmNindicatorType, XmONE_OF_MANY); n++;
  3512.         rsult = XmCreateToggleButton (h, (String) "", wargs, n);
  3513.         XtAddCallback (rsult, XmNvalueChangedCallback, Nlm_MenuCallback, (XtPointer) i);
  3514.         break;
  3515.       case POPUP_ITEM:
  3516.         rsult = XmCreatePushButton (h, (String) "", wargs, n);
  3517.         XtAddCallback (rsult, XmNactivateCallback, Nlm_MenuCallback, (XtPointer) i);
  3518.         break;
  3519.       default:
  3520.         break;
  3521.     }
  3522.     XmStringFree (label);
  3523. #endif
  3524.   }
  3525.   Nlm_RestorePort (tempPort);
  3526.   return rsult;
  3527. }
  3528.  
  3529. #ifdef WIN_MAC
  3530. static void Nlm_AppendResources (Nlm_MenU m, ResType res, Nlm_Boolean savePort)
  3531.  
  3532. {
  3533.   Nlm_MenuTool  h;
  3534.   Nlm_WindoW    tempPort;
  3535.  
  3536.   tempPort = Nlm_SavePortIfNeeded ((Nlm_GraphiC) m, savePort);
  3537.   h = Nlm_GetMenuHandle (m);
  3538.   AddResMenu (h, res);
  3539.   Nlm_RestorePort (tempPort);
  3540. }
  3541. #endif
  3542.  
  3543. static Nlm_IteM Nlm_AppendChoice (Nlm_ChoicE c, Nlm_CharPtr title,
  3544.                                   Nlm_Boolean poplist, Nlm_Boolean savePort)
  3545.  
  3546. {
  3547.   Nlm_IteM      i;
  3548.   Nlm_ItemTool  itool;
  3549.   Nlm_MenU      m;
  3550.   Nlm_Int2      num;
  3551.   Nlm_RecT      r;
  3552.   Nlm_WindoW    tempPort;
  3553.   Nlm_Char      temp [256];
  3554. #ifdef WIN_MOTIF
  3555.   Nlm_ItemTool  *hdls;
  3556. #endif
  3557.  
  3558.   i = NULL;
  3559.   tempPort = Nlm_SavePortIfNeeded ((Nlm_GraphiC) c, savePort);
  3560.   m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
  3561. #ifdef DCLAP
  3562.   Nlm_PrepareTitle (temp, title, sizeof (temp), FALSE); /* dgg */
  3563. #endif
  3564.   if (poplist) {
  3565.     itool = Nlm_AppendItems (m, (Nlm_IteM) c, temp, POPUP_ITEM, FALSE);
  3566.   } else {
  3567.     itool = Nlm_AppendItems (m, (Nlm_IteM) c, temp, CHOICE_ITEM, FALSE);
  3568.     Nlm_LoadRect (&r, 0, 0, 0, 0);
  3569.     i = (Nlm_IteM) Nlm_CreateLink ((Nlm_GraphiC) c, &r, sizeof (Nlm_ItemRec), choiceItemProcs);
  3570.     if (i != NULL) {
  3571.       Nlm_SetVisible ((Nlm_GraphiC) i, TRUE);
  3572.     }
  3573.   }
  3574.   num = Nlm_GetNumItems (c);
  3575.   num++;
  3576.   Nlm_SetNumItems (c, num);
  3577.   Nlm_LoadItemData (i, NULL, num, NULL);
  3578. #ifdef WIN_MOTIF
  3579.   hdls = Nlm_GetChoiceHandles (c);
  3580.   if (hdls == NULL) {
  3581.     hdls = (Nlm_ItemTool *) Nlm_MemNew (64 * sizeof (Nlm_ItemTool));
  3582.     Nlm_SetChoiceHandles (c, hdls);
  3583.   }
  3584.   if (hdls != NULL && num > 0 && num < 64) {
  3585.     hdls [num - 1] = itool;
  3586.   }
  3587.   XtManageChild (itool);
  3588.   if (NLM_QUIET) {
  3589.     if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (m))) {
  3590.       XtRealizeWidget (itool);
  3591.     }
  3592.   } else {
  3593.     XtRealizeWidget (itool);
  3594.   }
  3595. #endif
  3596.   Nlm_RestorePort (tempPort);
  3597.   return i;
  3598. }
  3599.  
  3600.  
  3601.  
  3602. #ifdef DCLAP
  3603. /* need to have fingers on the last appended popup item ! */
  3604. /* extern */ Nlm_IteM  gLastPopupItem;
  3605. #endif
  3606.  
  3607. static void Nlm_AppendPopList (Nlm_ChoicE c, Nlm_CharPtr title, Nlm_Boolean savePort)
  3608.  
  3609. {
  3610.   Nlm_MenU       m;
  3611.   Nlm_Int2       num;
  3612.   Nlm_RecT       r;
  3613.   Nlm_Int2       swid;
  3614.   Nlm_WindoW     tempPort;
  3615.   Nlm_PopupTool  u;
  3616.   Nlm_Int2       wid;
  3617. #ifdef WIN_MOTIF
  3618.   Nlm_Boolean    done;
  3619.   Nlm_ItemTool  *hdls;
  3620.   Nlm_ItemTool   itool;
  3621.   XmString       label;
  3622. #endif
  3623.  
  3624.   tempPort = Nlm_SavePortIfNeeded ((Nlm_GraphiC) c, savePort);
  3625.   m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
  3626. #ifdef DCLAP
  3627.   gLastPopupItem= NULL;
  3628. #endif
  3629.  
  3630. #ifdef WIN_MAC
  3631. #ifdef DCLAP
  3632.   gLastPopupItem= 
  3633. #endif
  3634.   Nlm_AppendChoice (c, title, TRUE, FALSE);
  3635. #endif
  3636.  
  3637. #ifdef WIN_MSWIN
  3638.   u = Nlm_GetMenuPopup (m);
  3639.   if (u != NULL) {
  3640.     ComboBox_AddString (u, title);
  3641.     num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  3642.     num++;
  3643.     Nlm_SetNumItems (c, num);
  3644.   }
  3645. #endif
  3646.  
  3647. #ifdef WIN_MOTIF
  3648.   done = FALSE;
  3649.   hdls = Nlm_GetChoiceHandles (c);
  3650.   if (hdls != NULL) {
  3651.     num = Nlm_GetNumItems ((Nlm_ChoicE) c);
  3652.     num++;
  3653.     if (num > 0 && num < 64) {
  3654.       itool = hdls [num - 1];
  3655.       if (itool != NULL) {
  3656.         label = XmStringCreateSimple (title);
  3657.         XtVaSetValues (itool, XmNlabelString, label, NULL);
  3658.         XmStringFree (label);
  3659.         XtManageChild (itool);
  3660.         Nlm_SetNumItems ((Nlm_ChoicE) c, num);
  3661.         done = TRUE;
  3662.       }
  3663.     }
  3664.   }
  3665.   if (! done) {
  3666. #ifdef DCLAP
  3667.       gLastPopupItem= 
  3668. #endif
  3669.     Nlm_AppendChoice (c, title, TRUE, FALSE);
  3670.   }
  3671. #endif
  3672.  
  3673.   Nlm_SelectFont (Nlm_systemFont);
  3674.   swid = Nlm_StringWidth (title);
  3675.   Nlm_GetRect ((Nlm_GraphiC) m, &r);
  3676. #ifdef WIN_MAC
  3677.   wid = r.right - r.left - 26;
  3678.   if (swid > wid) {
  3679.     r.right = r.left + swid + 26;
  3680.     Nlm_SetRect ((Nlm_GraphiC) m, &r);
  3681.     Nlm_SetRect ((Nlm_GraphiC) c, &r);
  3682.   }
  3683.   if (swid > wid) {
  3684.     if (Nlm_GetVisible ((Nlm_GraphiC) c) && Nlm_GetAllParentsVisible ((Nlm_GraphiC) c)) {
  3685.       Nlm_InsetRect (&r, -2, -2);
  3686.       Nlm_OffsetRect (&r, 1, 1);
  3687.       Nlm_InvalRect (&r);
  3688.     }
  3689.   }
  3690. #endif
  3691. #ifdef WIN_MSWIN
  3692.   wid = r.right - r.left - 26;
  3693.   if (swid > wid) {
  3694.     r.right = r.left + swid + 26;
  3695.     Nlm_SetRect ((Nlm_GraphiC) m, &r);
  3696.     Nlm_SetRect ((Nlm_GraphiC) c, &r);
  3697.   }
  3698.   u = Nlm_GetMenuPopup (m);
  3699.   if (u != NULL) {
  3700.     if (num > 10) {
  3701.       num = 10;
  3702.     }
  3703.     MoveWindow (u, r.left, r.top, r.right - r.left,
  3704.                 r.bottom - r.top + (num + 1) * Nlm_stdLineHeight, TRUE);
  3705.     UpdateWindow (u);
  3706.   }
  3707. #endif
  3708. #ifdef WIN_MOTIF
  3709.   wid = r.right - r.left - 48;
  3710.   if (swid > wid) {
  3711.     r.right = r.left + swid + 48;
  3712.     Nlm_SetRect ((Nlm_GraphiC) m, &r);
  3713.     Nlm_SetRect ((Nlm_GraphiC) c, &r);
  3714.   }
  3715.   u = Nlm_GetMenuPopup (m);
  3716.   if (u != NULL) {
  3717.     XtVaSetValues (u,
  3718.                    XmNx, (Position) r.left,
  3719.                    XmNy, (Position) r.top,
  3720.                    XmNwidth, (Dimension) (r.right - r.left),
  3721.                    XmNheight, (Dimension) (r.bottom - r.top), 
  3722.                    NULL);
  3723.   }
  3724. #endif
  3725.   Nlm_GetRect ((Nlm_GraphiC) m, &r);
  3726.   Nlm_DoAdjustPrnt ((Nlm_GraphiC) m, &r, TRUE, FALSE);
  3727.   Nlm_RestorePort (tempPort);
  3728. }
  3729.  
  3730. #ifdef WIN_MAC
  3731. static void Nlm_InvalPopup (Nlm_GraphiC m)
  3732.  
  3733. {
  3734.   Nlm_RecT  r;
  3735.  
  3736.   if (Nlm_GetVisible (m) && Nlm_GetAllParentsVisible (m)) {
  3737.     Nlm_GetRect (m, &r);
  3738.     Nlm_InsetRect (&r, -1, -1);
  3739.     Nlm_InvalRect (&r);
  3740.   }
  3741. }
  3742. #endif
  3743.  
  3744. static void Nlm_SetPopupPosition (Nlm_GraphiC m, Nlm_RectPtr r, Nlm_Boolean savePort)
  3745.  
  3746. {
  3747. #ifdef WIN_MAC
  3748.   Nlm_RecT    oldRect;
  3749.   Nlm_WindoW  tempPort;
  3750.  
  3751.   if (r != NULL) {
  3752.     Nlm_DoGetPosition (m, &oldRect);
  3753.     if (! Nlm_EqualRect (r, &oldRect)) {
  3754.       tempPort = Nlm_SavePortIfNeeded (m, savePort);
  3755.       Nlm_InvalPopup (m);
  3756.       Nlm_SetRect (m, r);
  3757.       Nlm_InvalPopup (m);
  3758.       Nlm_RestorePort (tempPort);
  3759.     }
  3760.   }
  3761. #endif
  3762. }
  3763.  
  3764. static void Nlm_GetPopupPosition (Nlm_GraphiC m, Nlm_RectPtr r)
  3765.  
  3766. {
  3767. #ifdef WIN_MAC
  3768.   if (r != NULL) {
  3769.     Nlm_GetRect (m, r);
  3770.   }
  3771. #endif
  3772. }
  3773.  
  3774. static void Nlm_SetPopListPosition (Nlm_GraphiC m, Nlm_RectPtr r, Nlm_Boolean savePort)
  3775.  
  3776. {
  3777.   Nlm_ChoicE     c;
  3778.   Nlm_Int2       num;
  3779.   Nlm_RecT       oldRect;
  3780.   Nlm_WindoW     tempPort;
  3781.   Nlm_PopupTool  u;
  3782.  
  3783.   if (r != NULL) {
  3784.     Nlm_DoGetPosition (m, &oldRect);
  3785.     if (! Nlm_EqualRect (r, &oldRect)) {
  3786.       tempPort = Nlm_SavePortIfNeeded (m, savePort);
  3787. #ifdef WIN_MAC
  3788.       Nlm_InvalPopup (m);
  3789. #endif
  3790.       Nlm_SetRect (m, r);
  3791.       c = (Nlm_ChoicE) Nlm_GetChild (m);
  3792.       Nlm_SetRect ((Nlm_GraphiC) c, r);
  3793. #ifdef WIN_MAC
  3794.       Nlm_InvalPopup (m);
  3795. #endif
  3796. #ifdef WIN_MSWIN
  3797.       u = Nlm_GetMenuPopup ((Nlm_MenU) m);
  3798.       if (u != NULL) {
  3799.         c = (Nlm_ChoicE) Nlm_GetChild (m);
  3800.         num = Nlm_GetNumItems (c);
  3801.         if (num > 10) {
  3802.           num = 10;
  3803.         }
  3804.         MoveWindow (u, r->left, r->top, r->right - r->left,
  3805.                     r->bottom - r->top + (num + 1) * Nlm_stdLineHeight, TRUE);
  3806.         UpdateWindow (u);
  3807.       }
  3808. #endif
  3809. #ifdef WIN_MOTIF
  3810.       u = Nlm_GetMenuPopup ((Nlm_MenU) m);
  3811.       XtVaSetValues (u,
  3812.                      XmNx, (Position) r->left,
  3813.                      XmNy, (Position) r->top,
  3814.                      XmNwidth, (Dimension) (r->right - r->left),
  3815.                      XmNheight, (Dimension) (r->bottom - r->top), 
  3816.                      NULL);
  3817. #endif
  3818.       Nlm_RestorePort (tempPort);
  3819.     }
  3820.   }
  3821. }
  3822.  
  3823. static void Nlm_GetPopListPosition (Nlm_GraphiC m, Nlm_RectPtr r)
  3824.  
  3825. {
  3826.   if (r != NULL) {
  3827.     Nlm_GetRect (m, r);
  3828.   }
  3829. }
  3830.  
  3831. static void Nlm_SetPopupChoicePosition (Nlm_GraphiC p, Nlm_RectPtr r, Nlm_Boolean savePort)
  3832.  
  3833. {
  3834.   Nlm_GraphiC  m;
  3835.  
  3836.   if (r != NULL) {
  3837.     m = Nlm_GetParent (p);
  3838.     Nlm_DoSetPosition (m, r, savePort);
  3839.   }
  3840. }
  3841.  
  3842. static void Nlm_GetPopupChoicePosition (Nlm_GraphiC p, Nlm_RectPtr r)
  3843.  
  3844. {
  3845.   Nlm_GraphiC  m;
  3846.  
  3847.   if (r != NULL) {
  3848.     m = Nlm_GetParent (p);
  3849.     Nlm_GetRect (m, r);
  3850.   }
  3851. }
  3852.  
  3853. #ifdef WIN_MSWIN
  3854. /* Message cracker functions */
  3855.  
  3856. static void MyCls_OnChar (HWND hwnd, UINT ch, int cRepeat)
  3857.  
  3858. {
  3859.   Nlm_PopuP  p;
  3860.  
  3861.   p = (Nlm_PopuP) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
  3862.   handlechar = FALSE;
  3863.   if (ch == '\t') {
  3864.     Nlm_DoSendFocus ((Nlm_GraphiC) p, (Nlm_Char) ch);
  3865.   } else if (ch == '\n' || ch == '\r') {
  3866.     Nlm_DoSendFocus ((Nlm_GraphiC) p, (Nlm_Char) ch);
  3867.   } else {
  3868.     handlechar = TRUE;
  3869.   }
  3870. }
  3871.  
  3872. LRESULT CALLBACK EXPORT PopupProc (HWND hwnd, UINT message,
  3873.                                    WPARAM wParam, LPARAM lParam)
  3874.  
  3875. {
  3876.   Nlm_PopuP  p;
  3877.   LRESULT    rsult;
  3878.   HDC        tempHDC;
  3879.   HWND       tempHWnd;
  3880.  
  3881.   if (Nlm_VibrantDisabled ()) {
  3882.     return CallWindowProc (lpfnOldPopupProc, hwnd, message, wParam, lParam);
  3883.   }
  3884.  
  3885.   rsult = 0;
  3886.   tempHWnd = Nlm_currentHWnd;
  3887.   tempHDC = Nlm_currentHDC;
  3888.   p = (Nlm_PopuP) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
  3889.   Nlm_theWindow = Nlm_GetParentWindow ((Nlm_GraphiC) p);
  3890.   Nlm_currentHWnd = GetParent (hwnd);
  3891.   Nlm_currentHDC = Nlm_ParentWindowPort ((Nlm_GraphiC) p);
  3892.   Nlm_currentWindowTool = hwnd;
  3893.   Nlm_currentKey = '\0';
  3894.   Nlm_currentWParam = wParam;
  3895.   Nlm_currentLParam = lParam;
  3896.   Nlm_cmmdKey = FALSE;
  3897.   Nlm_ctrlKey = FALSE;
  3898.   Nlm_optKey = FALSE;
  3899.   Nlm_shftKey = FALSE;
  3900.   Nlm_dblClick = FALSE;
  3901.  
  3902.   switch (message) {
  3903.     case WM_CHAR:
  3904.       HANDLE_WM_CHAR (hwnd, wParam, lParam, MyCls_OnChar);
  3905.       if (handlechar) {
  3906.         rsult = CallWindowProc (lpfnOldPopupProc, hwnd, message, wParam, lParam);
  3907.       }
  3908.       break;
  3909.     default:
  3910.       rsult = CallWindowProc (lpfnOldPopupProc, hwnd, message, wParam, lParam);
  3911.       break;
  3912.   }
  3913.   Nlm_currentHWnd = tempHWnd;
  3914.   Nlm_currentHDC = tempHDC;
  3915.   Nlm_currentWindowTool = tempHWnd;
  3916.   return rsult;
  3917. }
  3918. #endif
  3919.  
  3920. static void Nlm_NewMenuBar (Nlm_MenuBaR mb)
  3921.  
  3922. {
  3923.   Nlm_MenuTool    h;
  3924.   Nlm_PoinT       npt;
  3925.   Nlm_RecT        r;
  3926.   Nlm_WindowTool  wptr;
  3927. #ifdef WIN_MOTIF
  3928.   Cardinal        n;
  3929.   Nlm_MainTool    man;
  3930.   Arg             wargs [10];
  3931. #endif
  3932.  
  3933.   Nlm_GetRect ((Nlm_GraphiC) mb, &r);
  3934.   Nlm_LoadPt (&npt, r.left + 15, r.top);
  3935.   Nlm_LoadBoxData ((Nlm_BoX) mb, npt, npt, npt, npt.y, npt.x, 7, 7, 7, 7, 0, 0);
  3936. #ifdef WIN_MSWIN
  3937.   h = CreateMenu ();
  3938.   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) mb);
  3939.   SetMenu (wptr, h);
  3940.   Nlm_LoadMenuBarData (mb, h);
  3941. #endif
  3942. #ifdef WIN_MOTIF
  3943.   man = Nlm_ParentWindowMain ((Nlm_GraphiC) mb);
  3944.   n = 0;
  3945.   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  3946.   h = XmCreateMenuBar (man, (String) "", wargs, n);
  3947.   Nlm_LoadMenuBarData (mb, h);
  3948. #endif
  3949. }
  3950.  
  3951.  
  3952. #ifdef WIN_MAC
  3953. static void Nlm_NewDesktopMenu (Nlm_MenU m, Nlm_CharPtr title)
  3954.  
  3955. {
  3956.   Nlm_MenuTool  h;
  3957.   Nlm_Char      temp [256];
  3958.  
  3959. /* M.I */
  3960.   Nlm_PrepareTitle (temp, title, sizeof (temp), TRUE);
  3961. /* M.I */
  3962.   Nlm_CtoPstr (temp);
  3963.   h = NewMenu (nextMenuNum, (StringPtr) temp);
  3964.   Nlm_LoadMenuData (m, h, NULL, nextMenuNum, NULL);
  3965.   if (nextMenuNum < 32767) {
  3966.     nextMenuNum++;
  3967.   }
  3968. }
  3969. #endif
  3970.  
  3971. static void Nlm_NewPopup (Nlm_MenU m, Nlm_CharPtr title, Nlm_RectPtr r)
  3972.  
  3973. {
  3974.   Nlm_MenuTool   h;
  3975.   Nlm_MenuBaR    mb;
  3976.   Nlm_MenuTool   mbh;
  3977.   Nlm_PrompT     p;
  3978.   Nlm_PopupTool  pop;
  3979.   Nlm_Char       temp [256];
  3980. #ifdef WIN_MOTIF
  3981.   XmString       label;
  3982.   Cardinal       n;
  3983.   Arg            wargs [10];
  3984. #endif
  3985.  
  3986.   h = NULL;
  3987.   p = NULL;
  3988.   pop = NULL;
  3989. /* M.I */
  3990.   Nlm_PrepareTitle (temp, title, sizeof (temp), TRUE);
  3991. /* M.I */
  3992. #ifdef WIN_MAC
  3993.   h = NewMenu (nextMenuNum, (StringPtr) "");
  3994.   p = Nlm_DependentPrompt ((Nlm_GraphiC) m, r, temp, Nlm_systemFont, 'c');
  3995. #endif
  3996. #ifdef WIN_MSWIN
  3997.   p = NULL;
  3998.   mb = (Nlm_MenuBaR) Nlm_GetParent ((Nlm_GraphiC) m);
  3999.   mbh = Nlm_GetMenuBarHandle (mb);
  4000.   h = CreateMenu ();
  4001.   AppendMenu (mbh, MF_POPUP | MF_ENABLED, (UINT) h, temp);
  4002. #endif
  4003. #ifdef WIN_MOTIF
  4004.   p = NULL;
  4005.   mb = (Nlm_MenuBaR) Nlm_GetParent ((Nlm_GraphiC) m);
  4006.   mbh = Nlm_GetMenuBarHandle (mb);
  4007.   n = 0;
  4008.   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  4009.   h = XmCreatePulldownMenu (mbh, (String) "", wargs, n);
  4010.   label = XmStringCreateSimple (temp);
  4011.   n = 0;
  4012.   XtSetArg (wargs [n], XmNlabelString, label); n++;
  4013.   XtSetArg (wargs [n], XmNsubMenuId, h); n++;
  4014.   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  4015.   pop = XmCreateCascadeButton (mbh, (String) "", wargs, n);
  4016.   XmStringFree (label);
  4017.   XtManageChild (pop);
  4018.   if (NLM_QUIET) {
  4019.     if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (m))) {
  4020.       XtRealizeWidget (pop);
  4021.       XtRealizeWidget (h);
  4022.     }
  4023.   } else {
  4024.     XtRealizeWidget (pop);
  4025.     XtRealizeWidget (h);
  4026.   }
  4027. #endif
  4028.   Nlm_LoadMenuData (m, h, p, nextMenuNum, pop);
  4029.   if (nextMenuNum < 32767) {
  4030.     nextMenuNum++;
  4031.   }
  4032. }
  4033.  
  4034. static void Nlm_NewFloatingPopup (Nlm_MenU m, Nlm_CharPtr title, Nlm_RectPtr mr)
  4035.  
  4036. {
  4037.   Nlm_PopupTool   c;
  4038.   Nlm_RecT        r;
  4039.   Nlm_WindowTool  wptr;
  4040.  
  4041. #ifdef WIN_MAC
  4042.   Nlm_NewPopup (m, title, mr);
  4043. #endif
  4044. #ifdef WIN_MSWIN
  4045.   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) m);
  4046.   c = CreateWindow ("Combobox", title,
  4047.                      WS_CHILD | CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED,
  4048.                      r.left, r.top, r.right - r.left,
  4049.                      r.bottom - r.top, wptr, 0,
  4050.                      Nlm_currentHInst, NULL);
  4051.   if (c != NULL) {
  4052.     SetProp (c, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) m);
  4053.   }
  4054.   Nlm_LoadMenuData (m, NULL, NULL, nextMenuNum, c);
  4055.   if (nextMenuNum < 32767) {
  4056.     nextMenuNum++;
  4057.   }
  4058. #endif
  4059. #ifdef WIN_MOTIF
  4060. #endif
  4061. }
  4062.  
  4063. #ifdef WIN_MOTIF
  4064. static void Nlm_NewPopupList (Nlm_MenU m, Nlm_ChoicE c, Nlm_PupActnProc actn)
  4065.  
  4066. {
  4067.   Nlm_MenuTool    h;
  4068.   Nlm_ItemTool    PNTR hdls;
  4069.   Nlm_ItemTool    itool;
  4070.   Nlm_PopupTool   pop;
  4071.   Nlm_RecT        r;
  4072.   Nlm_WindowTool  wptr;
  4073.   Pixel           color;
  4074.   XmString        label;
  4075.   Widget          lbl;
  4076.   Cardinal        n;
  4077.   Arg             wargs [15];
  4078.  
  4079.   Nlm_GetRect ((Nlm_GraphiC) m, &r);
  4080.   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) m);
  4081.   n = 0;
  4082.   h = XmCreatePulldownMenu (wptr, (String) "", wargs, n);
  4083.   XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
  4084.   XtSetArg (wargs [n], XmNy, (Position) r.top); n++;
  4085.   XtSetArg (wargs [n], XmNwidth, (Dimension) (r.right - r.left)); n++;
  4086.   XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top)); n++;
  4087.   XtSetArg (wargs [n], XmNmarginHeight, 0); n++;
  4088.   XtSetArg (wargs [n], XmNmarginWidth, 0); n++;
  4089.   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  4090.   XtSetArg (wargs [n], XmNhighlightThickness, 0); n++;
  4091.   XtSetArg (wargs [n], XmNsubMenuId, h); n++;
  4092.   pop = XmCreateOptionMenu (wptr, (String) "", wargs, n);
  4093.   lbl = XmOptionLabelGadget (pop);
  4094.   XtVaGetValues (lbl, XmNforeground, &color, 0);
  4095.   n = 0;
  4096.   label = XmStringCreateSimple ("");
  4097.   XtSetArg (wargs [n], XmNlabelString, label); n++;
  4098.   XtSetArg (wargs [n], XmNwidth, (Dimension) 0); n++;
  4099.   XtSetArg (wargs [n], XmNheight, (Dimension) 0); n++;
  4100.   XtSetArg (wargs [n], XmNmarginHeight, (Dimension) 0); n++;
  4101.   XtSetArg (wargs [n], XmNmarginWidth, (Dimension) 0); n++;
  4102.   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  4103.   XtSetArg (wargs [n], XmNhighlightThickness, (Dimension) 0); n++;
  4104.   XtSetArg (wargs [n], XmNbackground, (Pixel) color); n++;
  4105.   XtSetValues (lbl, wargs, n);
  4106.   XmStringFree (label);
  4107.   if (NLM_QUIET) {
  4108.     if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (m))) {
  4109.       XtRealizeWidget (pop);
  4110.       XtRealizeWidget (h);
  4111.     }
  4112.   } else {
  4113.     XtRealizeWidget (pop);
  4114.     XtRealizeWidget (h);
  4115.   }
  4116.   Nlm_LoadMenuData (m, h, NULL, nextMenuNum, pop);
  4117.   if (nextMenuNum < 32767) {
  4118.     nextMenuNum++;
  4119.   }
  4120.   n = 0;
  4121.   label = XmStringCreateSimple (" ");
  4122.   XtSetArg (wargs [n], XmNlabelString, label); n++;
  4123.   XtSetArg (wargs [n], XmNfontList, Nlm_XfontList); n++;
  4124.   XtSetArg (wargs [n], XmNmarginHeight, 0); n++;
  4125.   XtSetArg (wargs [n], XmNmarginWidth, 0); n++;
  4126.   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  4127.   XtSetArg (wargs [n], XmNheight, Nlm_stdLineHeight+10); n++;
  4128.   XtSetArg (wargs [n], XmNrecomputeSize, FALSE); n++;
  4129.   itool = XmCreatePushButton (h, (String) "", wargs, n);
  4130.   XtAddCallback (itool, XmNactivateCallback, Nlm_MenuCallback, (XtPointer) c);
  4131.   XmStringFree (label);
  4132.   hdls = (Nlm_ItemTool *) Nlm_MemNew (64 * sizeof (Nlm_ItemTool));
  4133.   hdls [63] = itool;
  4134.   XtManageChild (itool);
  4135.   if (NLM_QUIET) {
  4136.     if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (m))) {
  4137.       XtRealizeWidget (itool);
  4138.     }
  4139.   } else {
  4140.     XtRealizeWidget (itool);
  4141.   }
  4142.   XtVaSetValues (pop, XmNmenuHistory, hdls [63], NULL);
  4143.   Nlm_LoadItemData ((Nlm_IteM) c, m, 1, pop);
  4144.   Nlm_LoadChoiceData (c, 0, TRUE, 0, hdls);
  4145.   Nlm_LoadAction ((Nlm_GraphiC) c, (Nlm_ActnProc) actn);
  4146. }
  4147. #endif
  4148.  
  4149. static void Nlm_NewPopListMenu (Nlm_MenU m)
  4150.  
  4151. {
  4152.   Nlm_PopupTool   c;
  4153.   Nlm_MenuTool    h;
  4154.   Nlm_RecT        r;
  4155.   Nlm_WindowTool  wptr;
  4156.  
  4157. #ifdef WIN_MAC
  4158.   h = NewMenu (nextMenuNum, (StringPtr) "");
  4159.   c = NULL;
  4160.   Nlm_LoadMenuData (m, h, NULL, nextMenuNum, c);
  4161. #endif
  4162. #ifdef WIN_MSWIN
  4163.   Nlm_GetRect ((Nlm_GraphiC) m, &r);
  4164.   h = NULL;
  4165.   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) m);
  4166.   c = CreateWindow ("Combobox", "", WS_CHILD | CBS_DROPDOWNLIST | WS_VSCROLL,
  4167.                      r.left, r.top, r.right - r.left,
  4168.                      r.bottom - r.top, wptr, 0,
  4169.                      Nlm_currentHInst, NULL);
  4170.   if (c != NULL) {
  4171.     SetProp (c, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) m);
  4172.   }
  4173.   Nlm_LoadMenuData (m, h, NULL, nextMenuNum, c);
  4174.   if (lpfnNewPopupProc == NULL) {
  4175.     lpfnNewPopupProc = (WNDPROC) MakeProcInstance ((FARPROC) PopupProc, Nlm_currentHInst);
  4176.   }
  4177.   if (lpfnOldPopupProc == NULL) {
  4178.     lpfnOldPopupProc = (WNDPROC) GetWindowLong (c, GWL_WNDPROC);
  4179.   } else if (lpfnOldPopupProc != (WNDPROC) GetWindowLong (c, GWL_WNDPROC)) {
  4180.     Nlm_Message (MSG_ERROR, "PopupProc subclass error");
  4181.   }
  4182.   SetWindowLong (c, GWL_WNDPROC, (LONG) lpfnNewPopupProc);
  4183. #endif
  4184.   if (nextMenuNum < 32767) {
  4185.     nextMenuNum++;
  4186.   }
  4187. }
  4188.  
  4189. #ifdef WIN_MAC
  4190. static void Nlm_NewSubMenu (Nlm_MenU m)
  4191.  
  4192. {
  4193.   Nlm_MenuTool  h;
  4194.  
  4195.   h = NewMenu (nextMenuNum, (StringPtr) "");
  4196.   Nlm_LoadMenuData (m, h, NULL, nextMenuNum, NULL);
  4197.   if (nextMenuNum < 32767) {
  4198.     nextMenuNum++;
  4199.   }
  4200. }
  4201.  
  4202. static void Nlm_NewSubmenuItem (Nlm_IteM i, Nlm_MenU sub, Nlm_CharPtr title)
  4203.  
  4204. {
  4205.   Nlm_MenuTool  h;
  4206.   Nlm_Int2      index;
  4207.   Nlm_MenU      m;
  4208.  
  4209.   m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) i);
  4210.   Nlm_AppendItems (m, i, title, CASCADE_ITEM, FALSE);
  4211.   index = Nlm_CountMenuItems ((Nlm_GraphiC) m);
  4212.   Nlm_LoadItemData (i, sub, index, NULL);
  4213.   h = Nlm_GetMenuHandle (sub);
  4214.   InsertMenu (h, -1);
  4215. }
  4216. #endif
  4217.  
  4218. #ifdef WIN_MSWIN
  4219. static void Nlm_NewSubMenuAndItem (Nlm_IteM i, Nlm_MenU sub, Nlm_CharPtr title)
  4220.  
  4221. {
  4222.   Nlm_MenuTool  h;
  4223.   Nlm_Int2      index;
  4224.   Nlm_MenU      m;
  4225.   Nlm_MenuTool  mh;
  4226.  
  4227.   m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) i);
  4228.   mh = Nlm_GetMenuHandle (m);
  4229.   h = CreateMenu ();
  4230.   AppendMenu (mh, MF_POPUP | MF_ENABLED, (UINT) h, title);
  4231.   Nlm_LoadMenuData (sub, h, NULL, nextMenuNum, NULL);
  4232.   if (nextMenuNum < 32767) {
  4233.     nextMenuNum++;
  4234.   }
  4235.   index = Nlm_CountMenuItems ((Nlm_GraphiC) m);
  4236.   Nlm_LoadItemData (i, sub, index, NULL);
  4237. }
  4238. #endif
  4239.  
  4240. #ifdef WIN_MOTIF
  4241. static void Nlm_NewCascadingMenu (Nlm_MenU m, Nlm_IteM i,
  4242.                                   Nlm_MenU sub, Nlm_CharPtr title)
  4243.  
  4244. {
  4245.   Nlm_MenuTool   h;
  4246.   Nlm_MenuTool   mh;
  4247.   Nlm_PopupTool  pop;
  4248.   XmString       label;
  4249.   Cardinal       n;
  4250.   Arg            wargs [10];
  4251.  
  4252.   mh = Nlm_GetMenuHandle (m);
  4253.   n = 0;
  4254.   h = XmCreatePulldownMenu (mh, (String) "", wargs, n);
  4255.   label = XmStringCreateSimple (title);
  4256.   n = 0;
  4257.   XtSetArg (wargs [n], XmNlabelString, label); n++;
  4258.   XtSetArg (wargs [n], XmNfontList, Nlm_XfontList); n++;
  4259.   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  4260.   XtSetArg (wargs [n], XmNsubMenuId, h); n++;
  4261.   XtSetArg (wargs [n], XmNrecomputeSize, FALSE); n++;
  4262.   pop = XmCreateCascadeButton (mh, (String) "", wargs, n);
  4263.   XmStringFree (label);
  4264.   XtManageChild (pop);
  4265.   if (NLM_QUIET) {
  4266.     if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (m))) {
  4267.       XtRealizeWidget (pop);
  4268.       XtRealizeWidget (h);
  4269.     }
  4270.   } else {
  4271.     XtRealizeWidget (pop);
  4272.     XtRealizeWidget (h);
  4273.   }
  4274.   Nlm_LoadMenuData (sub, h, NULL, nextMenuNum, pop);
  4275.   Nlm_LoadItemData (i, sub, 0, pop);
  4276. }
  4277. #endif
  4278.  
  4279. static void Nlm_NewComm (Nlm_IteM i, Nlm_CharPtr title, Nlm_ItmActnProc actn)
  4280.  
  4281. {
  4282.   Nlm_Int2      index;
  4283.   Nlm_ItemTool  itool;
  4284.   Nlm_MenU      m;
  4285.   Nlm_Char      temp [256];
  4286.  
  4287.   m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) i);
  4288. /* M.I */
  4289.   Nlm_PrepareTitle (temp, title, sizeof (temp), FALSE);
  4290. /* M.I */
  4291.   itool = Nlm_AppendItems (m, i, temp, COMMAND_ITEM, FALSE);
  4292.   index = Nlm_CountMenuItems ((Nlm_GraphiC) m);
  4293.   Nlm_LoadItemData (i, NULL, index, itool);
  4294.   Nlm_LoadAction ((Nlm_GraphiC) i, (Nlm_ActnProc) actn);
  4295. #ifdef WIN_MOTIF
  4296.   XtManageChild (itool);
  4297.   if (NLM_QUIET) {
  4298.     if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (m))) {
  4299.       XtRealizeWidget (itool);
  4300.     }
  4301.   } else {
  4302.     XtRealizeWidget (itool);
  4303.   }
  4304. #endif
  4305. }
  4306.  
  4307. static void Nlm_NewStat (Nlm_IteM i, Nlm_CharPtr title, Nlm_ItmActnProc actn)
  4308.  
  4309. {
  4310.   Nlm_Int2      index;
  4311.   Nlm_ItemTool  itool;
  4312.   Nlm_MenU      m;
  4313.   Nlm_Char      temp [256];
  4314.  
  4315.   m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) i);
  4316. /* M.I */
  4317.   Nlm_PrepareTitle (temp, title, sizeof (temp), FALSE);
  4318. /* M.I */
  4319.   itool = Nlm_AppendItems (m, i, temp, STATUS_ITEM, FALSE);
  4320.   index = Nlm_CountMenuItems ((Nlm_GraphiC) m);
  4321.   Nlm_LoadItemData (i, NULL, index, itool);
  4322.   Nlm_LoadAction ((Nlm_GraphiC) i, (Nlm_ActnProc) actn);
  4323. #ifdef WIN_MOTIF
  4324.   XtManageChild (itool);
  4325.   if (NLM_QUIET) {
  4326.     if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (m))) {
  4327.       XtRealizeWidget (itool);
  4328.     }
  4329.   } else {
  4330.     XtRealizeWidget (itool);
  4331.   }
  4332. #endif
  4333. }
  4334.  
  4335. static void Nlm_NewChoice (Nlm_ChoicE c, Nlm_ChsActnProc actn)
  4336.  
  4337. {
  4338.   Nlm_Int2  index;
  4339.   Nlm_MenU  m;
  4340.  
  4341.   m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
  4342.   index = Nlm_CountMenuItems ((Nlm_GraphiC) m);
  4343.   Nlm_LoadItemData ((Nlm_IteM) c, NULL, index + 1, NULL);
  4344.   Nlm_LoadChoiceData (c, 0, FALSE, 0, NULL);
  4345.   Nlm_LoadAction ((Nlm_GraphiC) c, (Nlm_ActnProc) actn);
  4346. }
  4347.  
  4348. static void Nlm_NewPopListChoice (Nlm_ChoicE c, Nlm_PupActnProc actn)
  4349.  
  4350. {
  4351.   Nlm_Int2  index;
  4352.   Nlm_MenU  sub;
  4353. #ifdef WIN_MAC
  4354.   Nlm_MenU  m;
  4355. #endif
  4356.  
  4357.   sub = NULL;
  4358.   index = 0;
  4359. #ifdef WIN_MAC
  4360.   m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
  4361.   index = Nlm_CountMenuItems ((Nlm_GraphiC) m);
  4362. #endif
  4363. #ifdef WIN_MSWIN
  4364.   index = 0;
  4365. #endif
  4366.   Nlm_LoadItemData ((Nlm_IteM) c, sub, index + 1, NULL);
  4367.   Nlm_LoadChoiceData (c, 0, TRUE, 0, NULL);
  4368.   Nlm_LoadAction ((Nlm_GraphiC) c, (Nlm_ActnProc) actn);
  4369. }
  4370.  
  4371. static void Nlm_NewDeskAcc (Nlm_ChoicE c)
  4372.  
  4373. {
  4374. #ifdef WIN_MAC
  4375.   Nlm_Int2  frst;
  4376.   Nlm_Int2  index;
  4377.   Nlm_MenU  m;
  4378.  
  4379.   m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
  4380.   index = Nlm_CountMenuItems ((Nlm_GraphiC) m);
  4381.   frst = index + 1;
  4382.   Nlm_AppendResources (m, 'DRVR', FALSE);
  4383.   index = Nlm_CountMenuItems ((Nlm_GraphiC) m);
  4384.   Nlm_LoadItemData ((Nlm_IteM) c, NULL, frst, NULL);
  4385.   Nlm_LoadChoiceData (c, index + 1 - frst, FALSE, 0, NULL);
  4386. #endif
  4387. }
  4388.  
  4389. static void Nlm_NewFontGroup (Nlm_ChoicE c)
  4390.  
  4391. {
  4392. #ifdef WIN_MAC
  4393.   Nlm_MenU  m;
  4394.   Nlm_Int2  newval;
  4395.   Nlm_Int2  oldval;
  4396.  
  4397.   m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
  4398.   oldval = Nlm_CountMenuItems ((Nlm_GraphiC) m);
  4399.   Nlm_AppendResources (m, 'FOND', FALSE);
  4400.   newval = Nlm_CountMenuItems ((Nlm_GraphiC) m);
  4401.   Nlm_LoadItemData ((Nlm_IteM) c, NULL, oldval + 1, NULL);
  4402.   Nlm_LoadChoiceData (c, newval - oldval, FALSE, 0, NULL);
  4403. #endif
  4404. #ifdef WIN_MSWIN
  4405.   /*
  4406.   WNDPROC   inst;
  4407.   */
  4408.   Nlm_MenU  m;
  4409.   Nlm_Int2  newval;
  4410.   Nlm_Int2  oldval;
  4411.  
  4412.   m = (Nlm_MenU) Nlm_GetParent ((Nlm_GraphiC) c);
  4413.   oldval = Nlm_CountMenuItems ((Nlm_GraphiC) m);
  4414.   /*
  4415.   inst = (WNDPROC) MakeProcInstance (EnumAllFaces, Nlm_currentHInst);
  4416.   FreeProcInstance (inst);
  4417.   */
  4418.   newval = Nlm_CountMenuItems ((Nlm_GraphiC) m);
  4419.   Nlm_LoadItemData ((Nlm_IteM) c, NULL, oldval + 1, NULL);
  4420.   Nlm_LoadChoiceData (c, newval - oldval, FALSE, 0, NULL);
  4421. #endif
  4422. #ifdef WIN_MOTIF
  4423. #endif
  4424. }
  4425.  
  4426. #ifdef WIN_MAC
  4427. static Nlm_MenuBaR Nlm_CreateDesktopMenuBar (Nlm_WindoW w)
  4428.  
  4429. {
  4430.   Nlm_MenuBaR  mb;
  4431.   Nlm_RecT     r;
  4432.  
  4433.   Nlm_LoadRect (&r, 0, 0, 0, 0);
  4434.   mb = (Nlm_MenuBaR) Nlm_HandNew (sizeof (Nlm_MenuBarRec));
  4435.   if (mb != NULL) {
  4436.     Nlm_LoadGraphicData ((Nlm_GraphiC) mb, NULL, (Nlm_GraphiC) w, NULL, NULL,
  4437.                          desktopMenuBarProcs, NULL, &r, TRUE, FALSE);
  4438.     if (Nlm_nextIdNumber < 32767) {
  4439.       Nlm_nextIdNumber++;
  4440.     }
  4441.     Nlm_SetWindowMenuBar (w, mb);
  4442.     Nlm_SetVisible ((Nlm_GraphiC) mb, TRUE);
  4443.   }
  4444.   return mb;
  4445. }
  4446. #endif
  4447.  
  4448. static Nlm_MenuBaR Nlm_CreateWindowMenuBar (Nlm_WindoW w)
  4449.  
  4450. {
  4451.   Nlm_MenuBaR  mb;
  4452.   Nlm_RecT     r;
  4453. #ifdef WIN_MAC
  4454.   Nlm_BoxData  bdata;
  4455. #endif
  4456.  
  4457.   Nlm_LoadRect (&r, 0, 0, 0, 20);
  4458.   mb = (Nlm_MenuBaR) Nlm_HandNew (sizeof (Nlm_MenuBarRec));
  4459.   if (mb != NULL) {
  4460.     Nlm_LoadGraphicData ((Nlm_GraphiC) mb, NULL, (Nlm_GraphiC) w, NULL, NULL,
  4461.                          windowMenuBarProcs, NULL, &r, TRUE, FALSE);
  4462.     if (Nlm_nextIdNumber < 32767) {
  4463.       Nlm_nextIdNumber++;
  4464.     }
  4465.   }
  4466.   if (mb != NULL) {
  4467. #ifdef WIN_MAC
  4468.     Nlm_DoAdjustPrnt ((Nlm_GraphiC) mb, &r, TRUE, FALSE);
  4469.     Nlm_GetBoxData ((Nlm_BoX) w, &bdata);
  4470.     bdata.topRow = bdata.limitPoint.y + bdata.yMargin;
  4471.     bdata.nextCol = bdata.resetPoint.x;
  4472.     bdata.nextPoint.y = bdata.topRow;
  4473.     bdata.nextPoint.x = bdata.nextCol;
  4474.     Nlm_SetBoxData ((Nlm_BoX) w, &bdata);
  4475. #endif
  4476.     Nlm_SetWindowMenuBar (w, mb);
  4477.     Nlm_NewMenuBar (mb);
  4478.     Nlm_DoShow ((Nlm_GraphiC) mb, TRUE, FALSE);
  4479.   }
  4480.   return mb;
  4481. }
  4482.  
  4483. extern Nlm_MenU Nlm_PulldownMenu (Nlm_WindoW w, Nlm_CharPtr title)
  4484.  
  4485. {
  4486.   Nlm_MenU     m;
  4487.   Nlm_MenuBaR  mb;
  4488.   Nlm_RecT     r;
  4489.   Nlm_WindoW   tempPort;
  4490. #ifdef WIN_MAC
  4491.   Nlm_PoinT    npt;
  4492. #endif
  4493. #ifdef WIN_MSWIN
  4494.   Nlm_PoinT    npt;
  4495. #endif
  4496.  
  4497.   m = NULL;
  4498.   if (w != NULL && title != NULL && w == Nlm_GetParentWindow ((Nlm_GraphiC) w)) {
  4499.     tempPort = Nlm_SavePort ((Nlm_GraphiC) w);
  4500.     Nlm_SelectFont (Nlm_systemFont);
  4501.     mb = Nlm_GetWindowMenuBar (w);
  4502.     if (mb == NULL) {
  4503.       mb = Nlm_CreateWindowMenuBar (w);
  4504.     }
  4505. #ifdef WIN_MAC
  4506.     Nlm_GetNextPosition ((Nlm_GraphiC) mb, &npt);
  4507.     r.top = npt.y;
  4508.     r.left = npt.x;
  4509.     r.bottom = r.top + 20;
  4510.     r.right = r.left + Nlm_StringWidth (title) + 5;
  4511.     Nlm_RecordRect ((Nlm_GraphiC) mb, &r);
  4512.     Nlm_Advance ((Nlm_GraphiC) mb);
  4513. #endif
  4514. #ifdef WIN_MSWIN
  4515.     Nlm_GetNextPosition ((Nlm_GraphiC) mb, &npt);
  4516.     r.top = npt.y;
  4517.     r.left = npt.x;
  4518.     r.bottom = r.top;
  4519.     r.right = r.left + Nlm_StringWidth (title) + 50;
  4520.     Nlm_DoAdjustPrnt ((Nlm_GraphiC) mb, &r, TRUE, FALSE);
  4521.     Nlm_Advance ((Nlm_GraphiC) mb);
  4522. #endif
  4523. #ifdef WIN_MOTIF
  4524.     Nlm_LoadRect (&r, 0, 0, 0, 0);
  4525. #endif
  4526.     m = (Nlm_MenU) Nlm_CreateLink ((Nlm_GraphiC) mb, &r, sizeof (Nlm_MenuRec),
  4527.                                    windowPulldownProcs);
  4528.     if (m != NULL) {
  4529.       r.top += 3;
  4530.       Nlm_NewPopup (m, title, &r);
  4531.       Nlm_DoShow ((Nlm_GraphiC) m, TRUE, FALSE);
  4532.     }
  4533.     Nlm_RestorePort (tempPort);
  4534.   } else if (title != NULL) {
  4535. #ifdef WIN_MAC
  4536.     w = Nlm_desktopWindow;
  4537.     mb = Nlm_GetWindowMenuBar (w);
  4538.     if (mb == NULL) {
  4539.       mb = Nlm_CreateDesktopMenuBar (w);
  4540.     }
  4541.     Nlm_LoadRect (&r, 0, 0, 0, 0);
  4542.     m = (Nlm_MenU) Nlm_CreateLink ((Nlm_GraphiC) mb, &r, sizeof (Nlm_MenuRec),
  4543.                                    desktopPulldownProcs);
  4544.     if (m != NULL) {
  4545.       Nlm_NewDesktopMenu (m, title);
  4546.       Nlm_DoShow ((Nlm_GraphiC) m, TRUE, TRUE);
  4547.     }
  4548. #endif
  4549.   }
  4550.   return m;
  4551. }
  4552.  
  4553. extern Nlm_MenU Nlm_AppleMenu (Nlm_WindoW w)
  4554.  
  4555. {
  4556.   Nlm_MenU  m;
  4557. #ifdef WIN_MAC
  4558.   Nlm_Char  appleStr [2] = {'\24', '\0'};
  4559. #endif
  4560.  
  4561.   m = NULL;
  4562. #ifdef WIN_MAC
  4563.   m = Nlm_PulldownMenu (w, appleStr);
  4564. #endif
  4565.   return m;
  4566. }
  4567.  
  4568. extern Nlm_MenU Nlm_PopupMenu (Nlm_GrouP prnt, Nlm_CharPtr title)
  4569.  
  4570. {
  4571.   Nlm_MenU    m;
  4572.   Nlm_PoinT   npt;
  4573.   Nlm_RecT    p;
  4574.   Nlm_RecT    r;
  4575.   Nlm_WindoW  tempPort;
  4576.   Nlm_Int2    wid;
  4577.  
  4578.   m = NULL;
  4579.   if (prnt != NULL && title != NULL) {
  4580.     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
  4581.     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
  4582.     Nlm_SelectFont (Nlm_systemFont);
  4583.     wid = Nlm_StringWidth (title);
  4584.     r.left = npt.x;
  4585.     r.top = npt.y;
  4586.     r.right = r.left + wid + 10;
  4587.     r.bottom = r.top + Nlm_stdLineHeight + 8;
  4588.     m = (Nlm_MenU) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r, sizeof (Nlm_MenuRec), popupProcs);
  4589.     if (m != NULL) {
  4590.       p = r;
  4591.       Nlm_UpsetRect (&p, 1, 1, 2, 2);
  4592.       Nlm_NewFloatingPopup (m, title, &p);
  4593.       Nlm_DoAdjustPrnt ((Nlm_GraphiC) m, &r, TRUE, FALSE);
  4594.       Nlm_DoShow ((Nlm_GraphiC) m, TRUE, FALSE);
  4595.     }
  4596.     Nlm_RestorePort (tempPort);
  4597.   }
  4598.   return m;
  4599. }
  4600.  
  4601. extern Nlm_MenU Nlm_SubMenu (Nlm_MenU m, Nlm_CharPtr title)
  4602.  
  4603. /*
  4604. *  WARNING -- Sub menus on the Macintosh link into the desktop window menu
  4605. *  bar in addition to their own parent items, so removing windows with
  4606. *  sub menus in them is dangerous.
  4607. */
  4608.  
  4609. {
  4610.   Nlm_IteM     i;
  4611.   Nlm_RecT     r;
  4612.   Nlm_MenU     sub;
  4613.   Nlm_Char     temp [256];
  4614. #ifdef WIN_MAC
  4615.   Nlm_Int2     len;
  4616.   Nlm_MenuBaR  mb;
  4617.   Nlm_WindoW   w;
  4618.   Nlm_Int2     tag;
  4619. #endif
  4620.  
  4621.   sub = NULL;
  4622.   if (m != NULL && title != NULL) {
  4623. #ifdef WIN_MAC
  4624.     w = Nlm_desktopWindow;
  4625.     mb = Nlm_GetWindowMenuBar (w);
  4626.     if (mb == NULL) {
  4627.       mb = Nlm_CreateDesktopMenuBar (w);
  4628.     }
  4629.     Nlm_LoadRect (&r, 0, 0, 0, 0);
  4630.     sub = (Nlm_MenU) Nlm_CreateLink ((Nlm_GraphiC) mb, &r, sizeof (Nlm_MenuRec), subMenuProcs);
  4631.     if (sub != NULL) {
  4632.       Nlm_NewSubMenu (sub);
  4633.       Nlm_SetVisible ((Nlm_GraphiC) sub, TRUE);
  4634. #ifdef DCLAP
  4635.       Nlm_StringNCpy (temp, kMenuCommandFlag, sizeof (temp));
  4636.       Nlm_StringNCat (temp, title, sizeof (temp));
  4637. #else
  4638.       Nlm_StringNCpy (temp, title, sizeof (temp));
  4639. #endif
  4640.       len = (Nlm_Int2) Nlm_StringLen (temp);
  4641.       tag = Nlm_GetMenuTag (sub);
  4642.       if (len < 250) {
  4643.         temp [len] = '/';
  4644.         temp [len + 1] = '\33';
  4645.         temp [len + 2] = '!';
  4646.         temp [len + 3] = (Nlm_Char) tag;
  4647.         temp [len + 4] = '\0';
  4648.       }
  4649.       i = (Nlm_IteM) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ItemRec), subItemProcs);
  4650.       if (i != NULL) {
  4651.         Nlm_NewSubmenuItem (i, sub, temp);
  4652.         Nlm_SetParent ((Nlm_GraphiC) sub, (Nlm_GraphiC) i);
  4653.         Nlm_SetVisible ((Nlm_GraphiC) i, TRUE);
  4654.       }
  4655.     }
  4656. #endif
  4657. #ifdef WIN_MSWIN
  4658.     sub = (Nlm_MenU) Nlm_HandNew (sizeof (Nlm_MenuRec));
  4659.     if (sub != NULL) {
  4660.       Nlm_LoadRect (&r, 0, 0, 0, 0);
  4661.       Nlm_LoadGraphicData ((Nlm_GraphiC) sub, NULL, (Nlm_GraphiC) m, NULL, NULL,
  4662.                            subMenuProcs, NULL, &r, TRUE, FALSE);
  4663.       if (Nlm_nextIdNumber < 32767) {
  4664.         Nlm_nextIdNumber++;
  4665.       }
  4666.       Nlm_StringNCpy (temp, title, sizeof (temp));
  4667.       i = (Nlm_IteM) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ItemRec), subItemProcs);
  4668.       if (i != NULL) {
  4669.         Nlm_NewSubMenuAndItem (i, sub, temp);
  4670.         Nlm_SetParent ((Nlm_GraphiC) sub, (Nlm_GraphiC) i);
  4671.         Nlm_SetVisible ((Nlm_GraphiC) sub, TRUE);
  4672.         Nlm_SetVisible ((Nlm_GraphiC) i, TRUE);
  4673.       }
  4674.     }
  4675. #endif
  4676. #ifdef WIN_MOTIF
  4677.     sub = (Nlm_MenU) Nlm_HandNew (sizeof (Nlm_MenuRec));
  4678.     if (sub != NULL) {
  4679.       Nlm_LoadRect (&r, 0, 0, 0, 0);
  4680.       Nlm_LoadGraphicData ((Nlm_GraphiC) sub, NULL, (Nlm_GraphiC) m, NULL, NULL,
  4681.                            subMenuProcs, NULL, &r, TRUE, FALSE);
  4682.       if (Nlm_nextIdNumber < 32767) {
  4683.         Nlm_nextIdNumber++;
  4684.       }
  4685.       Nlm_StringNCpy (temp, title, sizeof (temp));
  4686.       i = (Nlm_IteM) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ItemRec), subItemProcs);
  4687.       if (i != NULL) {
  4688.         Nlm_NewCascadingMenu (m, i, sub, temp);
  4689.         Nlm_SetParent ((Nlm_GraphiC) sub, (Nlm_GraphiC) i);
  4690.         Nlm_SetVisible ((Nlm_GraphiC) sub, TRUE);
  4691.         Nlm_SetVisible ((Nlm_GraphiC) i, TRUE);
  4692.       }
  4693.     }
  4694. #endif
  4695.   }
  4696.   return sub;
  4697. }
  4698.  
  4699. extern Nlm_IteM Nlm_CommandItem (Nlm_MenU m, Nlm_CharPtr title, Nlm_ItmActnProc actn)
  4700.  
  4701. {
  4702.   Nlm_IteM  i;
  4703.   Nlm_RecT  r;
  4704.  
  4705.   i = NULL;
  4706.   if (m != NULL && title != NULL) {
  4707.     Nlm_LoadRect (&r, 0, 0, 0, 0);
  4708.     i = (Nlm_IteM) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ItemRec), commandItemProcs);
  4709.     if (i != NULL) {
  4710.       Nlm_NewComm (i, title, actn);
  4711.       Nlm_SetVisible ((Nlm_GraphiC) i, TRUE);
  4712.     }
  4713.   }
  4714.   return i;
  4715. }
  4716.  
  4717. extern Nlm_IteM Nlm_StatusItem (Nlm_MenU m, Nlm_CharPtr title, Nlm_ItmActnProc actn)
  4718.  
  4719. {
  4720.   Nlm_IteM  i;
  4721.   Nlm_RecT  r;
  4722.  
  4723.   i = NULL;
  4724.   if (m != NULL && title != NULL) {
  4725.     Nlm_LoadRect (&r, 0, 0, 0, 0);
  4726.     i = (Nlm_IteM) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ItemRec), statusItemProcs);
  4727.     if (i != NULL) {
  4728.       Nlm_NewStat (i, title, actn);
  4729.       Nlm_SetVisible ((Nlm_GraphiC) i, TRUE);
  4730.     }
  4731.   }
  4732.   return i;
  4733. }
  4734.  
  4735. extern void Nlm_SeparatorItem (Nlm_MenU m)
  4736.  
  4737. {
  4738.   Nlm_MenuTool  h;
  4739. #ifdef WIN_MAC
  4740.   Nlm_Char      temp [256];
  4741. #endif
  4742. #ifdef WIN_MOTIF
  4743.   Nlm_ItemTool  itool;
  4744.   Cardinal      n;
  4745.   Arg           wargs [10];
  4746. #endif
  4747.  
  4748.   if (m != NULL) {
  4749.     h = Nlm_GetMenuHandle (m);
  4750. #ifdef WIN_MAC
  4751.     Nlm_StringNCpy (temp, "(-", sizeof (temp));
  4752.     Nlm_CtoPstr (temp);
  4753.     AppendMenu (h, (StringPtr) temp);
  4754. #endif
  4755. #ifdef WIN_MSWIN
  4756.     AppendMenu (h, MF_SEPARATOR, 0, NULL);
  4757. #endif
  4758. #ifdef WIN_MOTIF
  4759.     n = 0;
  4760.     XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  4761.     itool = XmCreateSeparator (h, (String) "", wargs, n);
  4762.     XtManageChild (itool);
  4763.     if (NLM_QUIET) {
  4764.       if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (m))) {
  4765.         XtRealizeWidget (itool);
  4766.       }
  4767.     } else {
  4768.       XtRealizeWidget (itool);
  4769.     }
  4770. #endif
  4771.   }
  4772. }
  4773.  
  4774. extern Nlm_ChoicE Nlm_ChoiceGroup (Nlm_MenU m, Nlm_ChsActnProc actn)
  4775.  
  4776. {
  4777.   Nlm_ChoicE  c;
  4778.   Nlm_RecT    r;
  4779.  
  4780.   c = NULL;
  4781.   if (m != NULL) {
  4782.     Nlm_LoadRect (&r, 0, 0, 0, 0);
  4783.     c = (Nlm_ChoicE) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ChoiceRec),
  4784.                                      choiceGroupProcs);
  4785.     if (c != NULL) {
  4786.       Nlm_NewChoice (c, actn);
  4787.       Nlm_SetVisible ((Nlm_GraphiC) c, TRUE);
  4788.     }
  4789.   }
  4790.   return c;
  4791. }
  4792.  
  4793. extern Nlm_PopuP Nlm_PopupList (Nlm_GrouP prnt, Nlm_Boolean macLike,
  4794.                                 Nlm_PupActnProc actn)
  4795.  
  4796. {
  4797.   Nlm_ChoicE   c;
  4798.   Nlm_GphPrcs  PNTR classPtr;
  4799.   Nlm_Int2     hbounds;
  4800.   Nlm_MenU     m;
  4801.   Nlm_PoinT    npt;
  4802.   Nlm_RecT     r;
  4803.   Nlm_WindoW   tempPort;
  4804.   Nlm_Int2     vbounds;
  4805.  
  4806.   c = NULL;
  4807.   if (prnt != NULL) {
  4808.     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
  4809.     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
  4810.     Nlm_SelectFont (Nlm_systemFont);
  4811.     if (macLike) {
  4812.       classPtr = macPopListProcs;
  4813.     } else {
  4814.       classPtr = msPopListProcs;
  4815.     }
  4816. #ifdef WIN_MAC
  4817.     hbounds = 13;
  4818.     vbounds = 2;
  4819. #endif
  4820. #ifdef WIN_MSWIN
  4821.     hbounds = 13;
  4822.     vbounds = 4;
  4823. #endif
  4824. #ifdef WIN_MOTIF
  4825.     hbounds = 24;
  4826.     vbounds = 5;
  4827. #endif
  4828.     r.left = npt.x;
  4829.     r.top = npt.y;
  4830.     r.right = r.left + hbounds * 2;
  4831.     r.bottom = r.top + Nlm_stdLineHeight + vbounds * 2;
  4832. #ifdef WIN_MAC
  4833.     m = (Nlm_MenU) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r, sizeof (Nlm_MenuRec), classPtr);
  4834.     if (m != NULL) {
  4835.       Nlm_NewPopListMenu (m);
  4836.       Nlm_DoAdjustPrnt ((Nlm_GraphiC) m, &r, TRUE, FALSE);
  4837.       Nlm_DoShow ((Nlm_GraphiC) m, TRUE, FALSE);
  4838.       c = (Nlm_ChoicE) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ChoiceRec),
  4839.                                        popUpChoiceProcs);
  4840.       if (c != NULL) {
  4841.         Nlm_NewPopListChoice (c, actn);
  4842.         Nlm_SetVisible ((Nlm_GraphiC) c, TRUE);
  4843.       }
  4844.     }
  4845. #endif
  4846. #ifdef WIN_MSWIN
  4847.     m = (Nlm_MenU) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r, sizeof (Nlm_MenuRec), classPtr);
  4848.     if (m != NULL) {
  4849.       Nlm_NewPopListMenu (m);
  4850.       Nlm_DoAdjustPrnt ((Nlm_GraphiC) m, &r, TRUE, FALSE);
  4851.       Nlm_DoShow ((Nlm_GraphiC) m, TRUE, FALSE);
  4852.       c = (Nlm_ChoicE) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ChoiceRec),
  4853.                                        popUpChoiceProcs);
  4854.       if (c != NULL) {
  4855.         Nlm_NewPopListChoice (c, actn);
  4856.         Nlm_SetVisible ((Nlm_GraphiC) c, TRUE);
  4857.       }
  4858.     }
  4859. #endif
  4860. #ifdef WIN_MOTIF
  4861.     m = (Nlm_MenU) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r, sizeof (Nlm_MenuRec), classPtr);
  4862.     if (m != NULL) {
  4863.       c = (Nlm_ChoicE) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ChoiceRec),
  4864.                                        popUpChoiceProcs);
  4865.       if (c != NULL) {
  4866.         Nlm_NewPopupList (m, c, actn);
  4867.         Nlm_DoAdjustPrnt ((Nlm_GraphiC) m, &r, TRUE, FALSE);
  4868.         Nlm_SetVisible ((Nlm_GraphiC) c, TRUE);
  4869.         Nlm_DoShow ((Nlm_GraphiC) m, TRUE, FALSE);
  4870.       }
  4871.     }
  4872. #endif
  4873.     Nlm_RestorePort (tempPort);
  4874.   }
  4875.   return (Nlm_PopuP) c;
  4876. }
  4877.  
  4878. extern Nlm_IteM Nlm_ChoiceItem (Nlm_ChoicE c, Nlm_CharPtr title)
  4879.  
  4880. {
  4881.   Nlm_IteM  i;
  4882.  
  4883.   i = NULL;
  4884.   if (c != NULL && title != NULL) {
  4885.     if (! Nlm_IsItAPopupList (c)) {
  4886.       i = Nlm_AppendChoice (c, title, FALSE, FALSE);
  4887.     }
  4888.   }
  4889.   return i;
  4890. }
  4891.  
  4892. extern void Nlm_PopupItem (Nlm_PopuP p, Nlm_CharPtr title)
  4893.  
  4894. {
  4895.   Nlm_ChoicE  c;
  4896.  
  4897.   c = (Nlm_ChoicE) p;
  4898.   if (c != NULL && title != NULL) {
  4899.     if (Nlm_IsItAPopupList (c)) {
  4900.       Nlm_AppendPopList (c, title, TRUE);
  4901.     }
  4902.   }
  4903. }
  4904.  
  4905. extern void Nlm_DeskAccGroup (Nlm_MenU m)
  4906.  
  4907. {
  4908. #ifdef WIN_MAC
  4909.   Nlm_ChoicE  c;
  4910.   Nlm_RecT    r;
  4911.  
  4912.   c = NULL;
  4913.   if (m != NULL) {
  4914.     Nlm_LoadRect (&r, 0, 0, 0, 0);
  4915.     c = (Nlm_ChoicE) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ChoiceRec), daProcs);
  4916.     if (c != NULL) {
  4917.       Nlm_NewDeskAcc (c);
  4918.       Nlm_SetVisible ((Nlm_GraphiC) c, TRUE);
  4919.     }
  4920.   }
  4921. #endif
  4922. }
  4923.  
  4924. extern Nlm_ChoicE Nlm_FontGroup (Nlm_MenU m)
  4925.  
  4926. {
  4927.   Nlm_ChoicE  c;
  4928.   Nlm_RecT    r;
  4929.  
  4930.   c = NULL;
  4931.   if (m != NULL) {
  4932.     Nlm_LoadRect (&r, 0, 0, 0, 0);
  4933.     c = (Nlm_ChoicE) Nlm_CreateLink ((Nlm_GraphiC) m, &r, sizeof (Nlm_ChoiceRec),
  4934.                                      choiceGroupProcs);
  4935.     if (c != NULL) {
  4936.       Nlm_NewFontGroup (c);
  4937.       Nlm_SetVisible ((Nlm_GraphiC) c, TRUE);
  4938.     }
  4939.   }
  4940.   return c;
  4941. }
  4942.  
  4943. extern void Nlm_FreeMenus (void)
  4944.  
  4945. {
  4946.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemFree (gphprcsptr);
  4947. }
  4948.  
  4949. extern void Nlm_InitMenus (void)
  4950.  
  4951. {
  4952.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemNew (sizeof (Nlm_GphPrcs) * 15);
  4953.  
  4954. #ifdef WIN_MAC
  4955.   desktopMenuBarProcs = &(gphprcsptr [0]);
  4956.   desktopMenuBarProcs->click = Nlm_DesktopMenuBarClick;
  4957.   desktopMenuBarProcs->key = Nlm_DesktopMenuBarKey;
  4958.   desktopMenuBarProcs->remove = Nlm_RemoveDesktopMenuBar;
  4959.   desktopMenuBarProcs->linkIn = Nlm_LinkIn;
  4960.  
  4961.   desktopPulldownProcs = &(gphprcsptr [1]);
  4962.   desktopPulldownProcs->click = Nlm_DesktopMenuClick;
  4963.   desktopPulldownProcs->key = Nlm_DesktopMenuKey;
  4964.   desktopPulldownProcs->draw = Nlm_DrawDesktopMenu;
  4965.   desktopPulldownProcs->show = Nlm_ShowDesktopMenu;
  4966.   desktopPulldownProcs->hide = Nlm_HideDesktopMenu;
  4967.   desktopPulldownProcs->enable = Nlm_EnableDesktopMenu;
  4968.   desktopPulldownProcs->disable = Nlm_DisableDesktopMenu;
  4969.   desktopPulldownProcs->remove = Nlm_RemoveDesktopMenu;
  4970.   desktopPulldownProcs->reset = Nlm_ResetMenu;
  4971.   desktopPulldownProcs->countItems = Nlm_CountMenuItems;
  4972.   desktopPulldownProcs->linkIn = Nlm_LinkIn;
  4973. #endif
  4974.  
  4975.   windowMenuBarProcs = &(gphprcsptr [2]);
  4976. #ifdef WIN_MAC
  4977.   windowMenuBarProcs->click = Nlm_WindowMenuBarClick;
  4978.   windowMenuBarProcs->key = Nlm_WindowMenuBarKey;
  4979.   windowMenuBarProcs->draw = Nlm_DrawWindowMenuBar;
  4980. #endif
  4981. #ifdef WIN_MSWIN
  4982.   windowMenuBarProcs->command = Nlm_WindowMenuBarCommand;
  4983. #endif
  4984. #ifdef WIN_MOTIF
  4985. #endif
  4986.   windowMenuBarProcs->show = Nlm_ShowWindowMenuBar;
  4987.   windowMenuBarProcs->remove = Nlm_RemoveWindowMenuBar;
  4988.   windowMenuBarProcs->linkIn = Nlm_LinkIn;
  4989.  
  4990.   windowPulldownProcs = &(gphprcsptr [3]);
  4991. #ifdef WIN_MAC
  4992.   windowPulldownProcs->click = Nlm_PulldownClick;
  4993.   windowPulldownProcs->key = Nlm_PopupKey;
  4994.   windowPulldownProcs->draw = Nlm_DrawWindowMenu;
  4995. #endif
  4996. #ifdef WIN_MSWIN
  4997.   windowPulldownProcs->command = Nlm_PulldownCommand;
  4998. #endif
  4999. #ifdef WIN_MOTIF
  5000. #endif
  5001.   windowPulldownProcs->show = Nlm_ShowPopup;
  5002.   windowPulldownProcs->hide = Nlm_HidePulldown;
  5003.   windowPulldownProcs->enable = Nlm_EnablePopup;
  5004.   windowPulldownProcs->disable = Nlm_DisablePopup;
  5005.   windowPulldownProcs->remove = Nlm_RemovePopupMenu;
  5006.   windowPulldownProcs->reset = Nlm_ResetMenu;
  5007.   windowPulldownProcs->countItems = Nlm_CountMenuItems;
  5008.   windowPulldownProcs->linkIn = Nlm_LinkIn;
  5009.  
  5010.   popupProcs = &(gphprcsptr [4]);
  5011. #ifdef WIN_MAC
  5012.   popupProcs->click = Nlm_PopupClick;
  5013.   popupProcs->key = Nlm_PopupKey;
  5014.   popupProcs->draw = Nlm_DrawPopup;
  5015. #endif
  5016. #ifdef WIN_MSWIN
  5017. #endif
  5018. #ifdef WIN_MOTIF
  5019. #endif
  5020.   popupProcs->show = Nlm_ShowPopup;
  5021.   popupProcs->hide = Nlm_HidePopup;
  5022.   popupProcs->enable = Nlm_EnablePopup;
  5023.   popupProcs->disable = Nlm_DisablePopup;
  5024.   popupProcs->remove = Nlm_RemovePopupMenu;
  5025.   popupProcs->reset = Nlm_ResetMenu;
  5026.   popupProcs->countItems = Nlm_CountMenuItems;
  5027.   popupProcs->linkIn = Nlm_LinkIn;
  5028.   popupProcs->setPosition = Nlm_SetPopupPosition;
  5029.   popupProcs->getPosition = Nlm_GetPopupPosition;
  5030.  
  5031.   subMenuProcs = &(gphprcsptr [5]);
  5032. #ifdef WIN_MAC
  5033.   subMenuProcs->click = Nlm_DesktopMenuClick;
  5034.   subMenuProcs->key = Nlm_SubMenuKey;
  5035. #endif
  5036.   subMenuProcs->enable = Nlm_EnableSubMenu;
  5037.   subMenuProcs->disable = Nlm_DisableSubMenu;
  5038.   subMenuProcs->remove = Nlm_RemoveSubMenu;
  5039.   subMenuProcs->reset = Nlm_ResetMenu;
  5040.   subMenuProcs->countItems = Nlm_CountMenuItems;
  5041.   subMenuProcs->linkIn = Nlm_LinkIn;
  5042.   subMenuProcs->setTitle = Nlm_SetSubmenuTitle;
  5043.   subMenuProcs->getTitle = Nlm_GetSubmenuTitle;
  5044.  
  5045.   subItemProcs = &(gphprcsptr [6]);
  5046. #ifdef WIN_MAC
  5047.   subItemProcs->click = Nlm_SubItemClick;
  5048. #endif
  5049. #ifdef WIN_MSWIN
  5050.   subItemProcs->command = Nlm_SubItemCommand;
  5051. #endif
  5052. #ifdef WIN_MOTIF
  5053. #endif
  5054.   subItemProcs->enable = Nlm_EnableMenuItem;
  5055.   subItemProcs->disable = Nlm_DisableMenuItem;
  5056.   subItemProcs->remove = Nlm_RemoveMenuItem;
  5057.   subItemProcs->linkIn = Nlm_LinkIn;
  5058.   subItemProcs->setTitle = Nlm_SetSingleTitle;
  5059.   subItemProcs->getTitle = Nlm_GetSingleTitle;
  5060.  
  5061.   commandItemProcs = &(gphprcsptr [7]);
  5062. #ifdef WIN_MAC
  5063.   commandItemProcs->click = Nlm_CommItemClick;
  5064.   commandItemProcs->key = Nlm_CommItemKey;
  5065. #endif
  5066. #ifdef WIN_MSWIN
  5067.   commandItemProcs->command = Nlm_CommItemCommand;
  5068. #endif
  5069. #ifdef WIN_MOTIF
  5070.   commandItemProcs->callback = Nlm_CommItemCallback;
  5071. #endif
  5072.   commandItemProcs->enable = Nlm_EnableMenuItem;
  5073.   commandItemProcs->disable = Nlm_DisableMenuItem;
  5074.   commandItemProcs->remove = Nlm_RemoveMenuItem;
  5075.   commandItemProcs->setTitle = Nlm_SetSingleTitle;
  5076.   commandItemProcs->getTitle = Nlm_GetSingleTitle;
  5077.  
  5078.   statusItemProcs = &(gphprcsptr [8]);
  5079. #ifdef WIN_MAC
  5080.   statusItemProcs->click = Nlm_StatItemClick;
  5081.   statusItemProcs->key = Nlm_StatItemKey;
  5082. #endif
  5083. #ifdef WIN_MSWIN
  5084.   statusItemProcs->command = Nlm_StatItemCommand;
  5085. #endif
  5086. #ifdef WIN_MOTIF
  5087.   statusItemProcs->callback = Nlm_StatItemCallback;
  5088. #endif
  5089.   statusItemProcs->enable = Nlm_EnableMenuItem;
  5090.   statusItemProcs->disable = Nlm_DisableMenuItem;
  5091.   statusItemProcs->remove = Nlm_RemoveMenuItem;
  5092.   statusItemProcs->setTitle = Nlm_SetSingleTitle;
  5093.   statusItemProcs->getTitle = Nlm_GetSingleTitle;
  5094.   statusItemProcs->setStatus = Nlm_SetStatValue;
  5095.   statusItemProcs->getStatus = Nlm_GetStatValue;
  5096.  
  5097.   choiceGroupProcs = &(gphprcsptr [9]);
  5098. #ifdef WIN_MAC
  5099.   choiceGroupProcs->click = Nlm_ChoiceGroupClick;
  5100.   choiceGroupProcs->key = Nlm_ChoiceGroupKey;
  5101. #endif
  5102. #ifdef WIN_MSWIN
  5103.   choiceGroupProcs->command = Nlm_ChoiceGroupCommand;
  5104. #endif
  5105. #ifdef WIN_MOTIF
  5106.   choiceGroupProcs->callback = Nlm_ChoiceGroupCallback;
  5107. #endif
  5108.   choiceGroupProcs->enable = Nlm_EnableChoiceGroup;
  5109.   choiceGroupProcs->disable = Nlm_DisableChoice;
  5110.   choiceGroupProcs->remove = Nlm_RemoveChoiceGroup;
  5111.   choiceGroupProcs->linkIn = Nlm_LinkIn;
  5112.   choiceGroupProcs->countItems = Nlm_CountChoiceItems;
  5113.   choiceGroupProcs->setTitle = Nlm_SetChoiceGroupTitle;
  5114.   choiceGroupProcs->getTitle = Nlm_GetChoiceGroupTitle;
  5115.   choiceGroupProcs->setValue = Nlm_SetChoiceGroupValue;
  5116.   choiceGroupProcs->getValue = Nlm_GetChoiceGroupValue;
  5117.  
  5118.   choiceItemProcs = &(gphprcsptr [10]);
  5119.   choiceItemProcs->enable = Nlm_EnableChoiceItem;
  5120.   choiceItemProcs->disable = Nlm_DisableChoiceItem;
  5121.   choiceItemProcs->remove = Nlm_RemoveChoiceItem;
  5122.   choiceItemProcs->setTitle = Nlm_SetChoiceItemTitle;
  5123.   choiceItemProcs->getTitle = Nlm_GetChoiceItemTitle;
  5124.   choiceItemProcs->setStatus = NULL;
  5125.   choiceItemProcs->getStatus = NULL;
  5126.  
  5127.   macPopListProcs = &(gphprcsptr [11]);
  5128. #ifdef WIN_MAC
  5129.   macPopListProcs->click = Nlm_MacPopListClick;
  5130.   macPopListProcs->key = Nlm_PopListKey;
  5131.   macPopListProcs->draw = Nlm_DrawPopList;
  5132. #endif
  5133. #ifdef WIN_MSWIN
  5134.   macPopListProcs->command = Nlm_MacPopListCommand;
  5135. #endif
  5136.   macPopListProcs->show = Nlm_ShowPopListMenu;
  5137.   macPopListProcs->hide = Nlm_HidePopListMenu;
  5138.   macPopListProcs->enable = Nlm_EnablePopList;
  5139.   macPopListProcs->disable = Nlm_DisablePopList;
  5140.   macPopListProcs->remove = Nlm_RemovePopListMenu;
  5141.   macPopListProcs->reset = Nlm_ResetMenu;
  5142.   macPopListProcs->countItems = Nlm_CountMenuItems;
  5143.   macPopListProcs->linkIn = Nlm_LinkIn;
  5144.   macPopListProcs->setPosition = Nlm_SetPopListPosition;
  5145.   macPopListProcs->getPosition = Nlm_GetPopListPosition;
  5146.  
  5147.   msPopListProcs = &(gphprcsptr [12]);
  5148. #ifdef WIN_MAC
  5149.   msPopListProcs->click = Nlm_MSPopListClick;
  5150.   msPopListProcs->key = Nlm_PopListKey;
  5151.   msPopListProcs->draw = Nlm_DrawPopList;
  5152. #endif
  5153. #ifdef WIN_MSWIN
  5154.   msPopListProcs->command = Nlm_MSPopListCommand;
  5155. #endif
  5156.   msPopListProcs->show = Nlm_ShowPopListMenu;
  5157.   msPopListProcs->hide = Nlm_HidePopListMenu;
  5158.   msPopListProcs->enable = Nlm_EnablePopList;
  5159.   msPopListProcs->disable = Nlm_DisablePopList;
  5160.   msPopListProcs->remove = Nlm_RemovePopListMenu;
  5161.   msPopListProcs->reset = Nlm_ResetMenu;
  5162.   msPopListProcs->countItems = Nlm_CountMenuItems;
  5163.   msPopListProcs->linkIn = Nlm_LinkIn;
  5164.   msPopListProcs->setPosition = Nlm_SetPopListPosition;
  5165.   msPopListProcs->getPosition = Nlm_GetPopListPosition;
  5166.  
  5167.   popUpChoiceProcs = &(gphprcsptr [13]);
  5168. #ifdef WIN_MAC
  5169.   popUpChoiceProcs->click = Nlm_PopupChoiceGroupClick;
  5170.   popUpChoiceProcs->key = Nlm_ChoiceGroupKey;
  5171. #endif
  5172. #ifdef WIN_MOTIF
  5173.   popUpChoiceProcs->callback = Nlm_PopupChoiceCallback;
  5174. #endif
  5175.   popUpChoiceProcs->show = Nlm_ShowPopListChoice;
  5176.   popUpChoiceProcs->hide = Nlm_HidePopListChoice;
  5177.   popUpChoiceProcs->enable = Nlm_EnableChoice;
  5178.   popUpChoiceProcs->disable = Nlm_DisableChoice;
  5179.   popUpChoiceProcs->remove = Nlm_RemovePopupList;
  5180.   popUpChoiceProcs->reset = Nlm_ResetPopList;
  5181.   popUpChoiceProcs->countItems = Nlm_CountChoiceItems;
  5182.   popUpChoiceProcs->setTitle = Nlm_SetPopListTitle;
  5183.   popUpChoiceProcs->getTitle = Nlm_GetPopListTitle;
  5184.   popUpChoiceProcs->setValue = Nlm_SetPopListValue;
  5185.   popUpChoiceProcs->getValue = Nlm_GetPopListValue;
  5186.   popUpChoiceProcs->setPosition = Nlm_SetPopupChoicePosition;
  5187.   popUpChoiceProcs->getPosition = Nlm_GetPopupChoicePosition;
  5188.  
  5189.   daProcs = &(gphprcsptr [14]);
  5190. #ifdef WIN_MAC
  5191.   daProcs->click = Nlm_DAClick;
  5192.   daProcs->key = Nlm_DAKey;
  5193. #endif
  5194.   daProcs->enable = Nlm_EnableChoice;
  5195.   daProcs->disable = Nlm_DisableChoice;
  5196.   daProcs->remove = Nlm_RemoveMenuItem;
  5197.   daProcs->countItems = Nlm_CountChoiceItems;
  5198.   daProcs->setTitle = Nlm_SetChoiceTitle;
  5199.   daProcs->getTitle = Nlm_GetChoiceTitle;
  5200.   daProcs->setValue = Nlm_SetChoiceValue;
  5201.   daProcs->getValue = Nlm_GetChoiceValue;
  5202. }
  5203.