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