home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / vibrant / viblists.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-05  |  33.5 KB  |  1,418 lines  |  [TEXT/R*ch]

  1. /*   viblists.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:  viblists.c
  27. *
  28. * Author:  Jonathan Kans
  29. *
  30. * Version Creation Date:   7/1/91
  31. *
  32. * $Revision: 2.8 $
  33. *
  34. * File Description: 
  35. *       Vibrant list 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_ListTool ListHandle
  52. #endif
  53.  
  54. #ifdef WIN_MSWIN
  55. #define Nlm_ListTool HWND
  56. #endif
  57.  
  58. #ifdef WIN_MOTIF
  59. #define Nlm_ListTool Widget
  60. #endif
  61.  
  62. typedef  struct  Nlm_listdata {
  63.   Nlm_ListTool  handle;
  64.   Nlm_BaR       scrollBar;
  65.   Nlm_Int2      visLines;
  66.   Nlm_Int2      numItems;
  67.   Nlm_Int2      offset;
  68. } Nlm_ListData;
  69.  
  70. typedef  struct  Nlm_listrec {
  71.   Nlm_GraphicRec  graphicR;
  72.   Nlm_ListData    list;
  73. } Nlm_ListRec, PNTR Nlm_LstPtr;
  74.  
  75. static Nlm_GphPrcsPtr  gphprcsptr = NULL;
  76.  
  77. static Nlm_GphPrcsPtr  singleProcs;
  78. static Nlm_GphPrcsPtr  multiProcs;
  79.  
  80. static Nlm_LisT        recentList = NULL;
  81. static Nlm_ListData    recentListData;
  82.  
  83. #ifdef WIN_MSWIN
  84. static WNDPROC         lpfnNewListProc = NULL;
  85. static WNDPROC         lpfnOldListProc = NULL;
  86. static Nlm_Boolean     handlechar;
  87. #endif
  88.  
  89. static void Nlm_LoadListData (Nlm_LisT l, Nlm_ListTool hdl,
  90.                               Nlm_BaR bar, Nlm_Int2 vis,
  91.                               Nlm_Int2 nitm, Nlm_Int2 off)
  92.  
  93. {
  94.   Nlm_LstPtr    lp;
  95.   Nlm_ListData  PNTR ldptr;
  96.  
  97.   if (l != NULL) {
  98.     lp = (Nlm_LstPtr) Nlm_HandLock (l);
  99.     ldptr = &(lp->list);
  100.     ldptr->handle = hdl;
  101.     ldptr->scrollBar = bar;
  102.     ldptr->visLines = vis;
  103.     ldptr->numItems = nitm;
  104.     ldptr->offset = off;
  105.     Nlm_HandUnlock (l);
  106.     recentList = NULL;
  107.   }
  108. }
  109.  
  110. static void Nlm_SetListData (Nlm_LisT l, Nlm_ListData * ldata)
  111.  
  112. {
  113.   Nlm_LstPtr  lp;
  114.  
  115.   if (l != NULL && ldata != NULL) {
  116.     lp = (Nlm_LstPtr) Nlm_HandLock (l);
  117.     lp->list = *ldata;
  118.     Nlm_HandUnlock (l);
  119.     recentList = l;
  120.     recentListData = *ldata;
  121.   }
  122. }
  123.  
  124. static void Nlm_GetListData (Nlm_LisT l, Nlm_ListData * ldata)
  125.  
  126. {
  127.   Nlm_LstPtr  lp;
  128.  
  129.   if (l != NULL && ldata != NULL) {
  130.     if (l == recentList && NLM_RISKY) {
  131.       *ldata = recentListData;
  132.     } else {
  133.       lp = (Nlm_LstPtr) Nlm_HandLock (l);
  134.       *ldata = lp->list;
  135.       Nlm_HandUnlock (l);
  136.       recentList = l;
  137.       recentListData = *ldata;
  138.     }
  139.   }
  140. }
  141.  
  142. static Nlm_ListTool Nlm_GetListHandle (Nlm_LisT l)
  143.  
  144. {
  145.   Nlm_ListData  ldata;
  146.  
  147.   Nlm_GetListData (l, &ldata);
  148.   return ldata.handle;
  149. }
  150.  
  151. static Nlm_BaR Nlm_GetListScrollBar (Nlm_LisT l)
  152.  
  153. {
  154.   Nlm_ListData  ldata;
  155.  
  156.   Nlm_GetListData (l, &ldata);
  157.   return ldata.scrollBar;
  158. }
  159.  
  160. static void Nlm_SetListVisLines (Nlm_LisT l, Nlm_Int2 lns)
  161.  
  162. {
  163.   Nlm_ListData  ldata;
  164.  
  165.   Nlm_GetListData (l, &ldata);
  166.   ldata.visLines = lns;
  167.   Nlm_SetListData (l, &ldata);
  168. }
  169.  
  170. static Nlm_Int2 Nlm_GetListVisLines (Nlm_LisT l)
  171.  
  172. {
  173.   Nlm_ListData  ldata;
  174.  
  175.   Nlm_GetListData (l, &ldata);
  176.   return ldata.visLines;
  177. }
  178.  
  179. static void Nlm_SetListNumItems (Nlm_LisT l, Nlm_Int2 num)
  180.  
  181. {
  182.   Nlm_ListData  ldata;
  183.   
  184.   Nlm_GetListData (l, &ldata);
  185.   ldata.numItems = num;
  186.   Nlm_SetListData (l, &ldata);
  187. }
  188.  
  189. static Nlm_Int2 Nlm_GetListNumItems (Nlm_LisT l)
  190.  
  191. {
  192.   Nlm_ListData  ldata;
  193.   
  194.   Nlm_GetListData (l, &ldata);
  195.   return ldata.numItems;
  196. }
  197.  
  198. static void Nlm_SetListScrollOffset (Nlm_LisT l, Nlm_Int2 off)
  199.  
  200. {
  201.   Nlm_ListData  ldata;
  202.  
  203.   Nlm_GetListData (l, &ldata);
  204.   ldata.offset = off;
  205.   Nlm_SetListData (l, &ldata);
  206. }
  207.  
  208. static Nlm_Int2 Nlm_GetListScrollOffset (Nlm_LisT l)
  209.  
  210. {
  211.   Nlm_ListData  ldata;
  212.  
  213.   Nlm_GetListData (l, &ldata);
  214.   return ldata.offset;
  215. }
  216.  
  217. #ifdef WIN_MAC
  218. static Nlm_Boolean Nlm_SingleListClick (Nlm_GraphiC l, Nlm_PoinT pt)
  219.  
  220. {
  221.   Nlm_ListTool   c;
  222.   Nlm_Int2       newval;
  223.   Nlm_Int2       oldval;
  224.   Nlm_PoinT      point;
  225.   Nlm_PointTool  ptool;
  226.   Nlm_RecT       r;
  227.   Nlm_Boolean    rsult;
  228.   Nlm_BaR        sb;
  229.  
  230.   rsult = FALSE;
  231.   Nlm_GetRect (l, &r);
  232.   r.right += Nlm_vScrollBarWidth;
  233.   if (Nlm_PtInRect (pt, &r)) {
  234.     r.right -= Nlm_vScrollBarWidth;
  235.     Nlm_InsetRect (&r, 2, 2);
  236.     sb = Nlm_GetListScrollBar ((Nlm_LisT) l);
  237.     if (sb != NULL && Nlm_DoClick ((Nlm_GraphiC) sb, pt)) {
  238.     } else if (Nlm_PtInRect (pt, &r)) {
  239.       oldval = Nlm_DoGetValue (l);
  240.       c = Nlm_GetListHandle ((Nlm_LisT) l);
  241.       Nlm_PoinTToPointTool (pt, &ptool);
  242.       Nlm_dblClick = (LClick (ptool, Nlm_currentEvent.modifiers, c) != 0);
  243.       Nlm_MousePosition (&point);
  244.       if (Nlm_PtInRect (point, &r)) {
  245.         newval = Nlm_DoGetValue (l);
  246.         if (oldval != newval || Nlm_dblClick) {
  247.           Nlm_DoAction (l);
  248.         }
  249.       } else {
  250.         newval = Nlm_DoGetValue (l);
  251.         if (oldval != newval || Nlm_dblClick) {
  252.           Nlm_DoAction (l);
  253.         }
  254.       }
  255.       rsult = TRUE;
  256.     }
  257.   }
  258.   return rsult;
  259. }
  260.  
  261. static Nlm_Boolean Nlm_MultiListClick (Nlm_GraphiC l, Nlm_PoinT pt)
  262.  
  263. {
  264.   Nlm_ListTool   c;
  265.   Nlm_PoinT      point;
  266.   Nlm_PointTool  ptool;
  267.   Nlm_RecT       r;
  268.   Nlm_Boolean    rsult;
  269.   Nlm_BaR        sb;
  270.  
  271.   rsult = FALSE;
  272.   Nlm_GetRect (l, &r);
  273.   r.right += Nlm_vScrollBarWidth;
  274.   if (Nlm_PtInRect (pt, &r)) {
  275.     r.right -= Nlm_vScrollBarWidth;
  276.     Nlm_InsetRect (&r, 2, 2);
  277.     sb = Nlm_GetListScrollBar ((Nlm_LisT) l);
  278.     if (sb != NULL && Nlm_DoClick ((Nlm_GraphiC) sb, pt)) {
  279.     } else if (Nlm_PtInRect (pt, &r)) {
  280.       c = Nlm_GetListHandle ((Nlm_LisT) l);
  281.       Nlm_PoinTToPointTool (pt, &ptool);
  282.       Nlm_dblClick = (LClick (ptool, Nlm_currentEvent.modifiers, c) != 0);
  283.       Nlm_MousePosition (&point);
  284.       if (Nlm_PtInRect (point, &r)) {
  285.         Nlm_DoAction (l);
  286.       } else {
  287.         Nlm_DoAction (l);
  288.       }
  289.       rsult = TRUE;
  290.     }
  291.   }
  292.   return rsult;
  293. }
  294. #endif
  295.  
  296. #ifdef WIN_MSWIN
  297. static Nlm_Boolean Nlm_SingleListCommand (Nlm_GraphiC l)
  298.  
  299. {
  300.   Nlm_dblClick = (Nlm_Boolean) (Nlm_currentCode == LBN_DBLCLK);
  301.   if (Nlm_currentCode == LBN_SELCHANGE || Nlm_dblClick) {
  302.     Nlm_DoAction (l);
  303.   }
  304.   return TRUE;
  305. }
  306.  
  307. static Nlm_Boolean Nlm_MultiListCommand (Nlm_GraphiC l)
  308.  
  309. {
  310.   Nlm_dblClick = (Nlm_Boolean) (Nlm_currentCode == LBN_SELCHANGE);
  311.   if (Nlm_currentCode == LBN_SELCHANGE || Nlm_dblClick) {
  312.     Nlm_DoAction (l);
  313.   }
  314.   return TRUE;
  315. }
  316. #endif
  317.  
  318. #ifdef WIN_MOTIF
  319. static void Nlm_SingleListCallback (Nlm_GraphiC l)
  320.  
  321. {
  322.   Nlm_DoAction (l);
  323. }
  324.  
  325. static void Nlm_MultiListCallback (Nlm_GraphiC l)
  326.  
  327. {
  328.   Nlm_DoAction (l);
  329. }
  330. #endif
  331.  
  332. #ifdef WIN_MAC
  333. static void Nlm_DrawList (Nlm_GraphiC l)
  334.  
  335. {
  336.   Nlm_ListTool  c;
  337.   Nlm_RecT      r;
  338.   Nlm_BaR       sb;
  339.  
  340.   if (Nlm_GetVisible (l) && Nlm_GetAllParentsVisible (l)) {
  341.     Nlm_GetRect (l, &r);
  342.     r.right += Nlm_vScrollBarWidth;
  343.     if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
  344.       Nlm_FrameRect (&r);
  345.       sb = Nlm_GetListScrollBar ((Nlm_LisT) l);
  346.       if (sb != NULL) {
  347.         Nlm_DoDraw ((Nlm_GraphiC) sb);
  348.       }
  349.       r.right -= Nlm_vScrollBarWidth;
  350.       c = Nlm_GetListHandle ((Nlm_LisT) l);
  351.       if (c != NULL) {
  352.         Nlm_SelectFont (Nlm_systemFont);
  353.         LDoDraw (TRUE, c);
  354.         LUpdate ((Nlm_RgnTool) Nlm_updateRgn, c);
  355.       }
  356.     }
  357.   }
  358. }
  359. #endif
  360.  
  361. static void Nlm_ShowList (Nlm_GraphiC l, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  362.  
  363. {
  364.   Nlm_ListTool  c;
  365.   Nlm_WindoW    tempPort;
  366. #ifdef WIN_MAC
  367.   Nlm_BaR       sb;
  368. #endif
  369.  
  370.   if (setFlag) {
  371.     Nlm_SetVisible (l, TRUE);
  372.   }
  373.   if (Nlm_GetVisible (l) && Nlm_AllParentsButWindowVisible (l)) {
  374.     tempPort = Nlm_SavePortIfNeeded (l, savePort);
  375.     c = Nlm_GetListHandle ((Nlm_LisT) l);
  376. #ifdef WIN_MAC
  377.     sb = Nlm_GetListScrollBar ((Nlm_LisT) l);
  378.     if (sb != NULL) {
  379.       Nlm_DoShow ((Nlm_GraphiC) sb, TRUE, FALSE);
  380.     }
  381.     Nlm_DoDraw (l);
  382. #endif
  383. #ifdef WIN_MSWIN
  384.     ShowWindow (c, SW_SHOW);
  385.     UpdateWindow (c);
  386. #endif
  387. #ifdef WIN_MOTIF
  388.     XtManageChild (XtParent (c));
  389. #endif
  390.     Nlm_RestorePort (tempPort);
  391.   }
  392. }
  393.  
  394. static void Nlm_HideList (Nlm_GraphiC l, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  395.  
  396. {
  397.   Nlm_ListTool  c;
  398.   Nlm_BaR       sb;
  399.   Nlm_WindoW    tempPort;
  400. #ifdef WIN_MAC
  401.   Nlm_RecT      r;
  402. #endif
  403.  
  404.   if (setFlag) {
  405.     Nlm_SetVisible (l, FALSE);
  406.   }
  407.   tempPort = Nlm_SavePortIfNeeded (l, savePort);
  408.   sb = Nlm_GetListScrollBar ((Nlm_LisT) l);
  409.   if (sb != NULL) {
  410.     Nlm_DoHide ((Nlm_GraphiC) sb, TRUE, FALSE);
  411.   }
  412.   c = Nlm_GetListHandle ((Nlm_LisT) l);
  413. #ifdef WIN_MAC
  414.   if (Nlm_GetAllParentsVisible (l)) {
  415.     Nlm_GetRect (l, &r);
  416.     r.right += Nlm_vScrollBarWidth;
  417.     Nlm_InsetRect (&r, -1, -1);
  418.     Nlm_EraseRect (&r);
  419.     Nlm_ValidRect (&r);
  420.   }
  421. #endif
  422. #ifdef WIN_MSWIN
  423.   ShowWindow (c, SW_HIDE);
  424.   UpdateWindow (c);
  425. #endif
  426. #ifdef WIN_MOTIF
  427.   XtUnmanageChild (XtParent (c));
  428. #endif
  429.   Nlm_RestorePort (tempPort);
  430. }
  431.  
  432. static void Nlm_EnableList (Nlm_GraphiC l, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  433.  
  434. {
  435.   Nlm_ListTool  c;
  436.   Nlm_RecT      r;
  437.   Nlm_BaR       sb;
  438.   Nlm_WindoW    tempPort;
  439. #ifdef WIN_MAC
  440.   Nlm_Int2      newval;
  441.   Nlm_Int2      oldval;
  442. #endif
  443.  
  444.   if (setFlag) {
  445.     Nlm_SetEnabled (l, TRUE);
  446.   }
  447.   if (Nlm_GetEnabled (l) && Nlm_GetAllParentsEnabled (l)) {
  448.     tempPort = Nlm_SavePortIfNeeded (l, savePort);
  449.     sb = Nlm_GetListScrollBar ((Nlm_LisT) l);
  450.     c = Nlm_GetListHandle ((Nlm_LisT) l);
  451.     if (sb != NULL) {
  452.       Nlm_DoEnable ((Nlm_GraphiC) sb, TRUE, FALSE);
  453. #ifdef WIN_MAC
  454.       oldval = Nlm_GetListScrollOffset ((Nlm_LisT) l);
  455.       newval = Nlm_DoGetValue ((Nlm_GraphiC) sb);
  456.       if (oldval != newval) {
  457.         Nlm_SetListScrollOffset ((Nlm_LisT) l, newval);
  458.         LScroll (0, newval - oldval, c);
  459.       }
  460. #endif
  461.       if (Nlm_GetVisible (l) && Nlm_GetAllParentsVisible (l)) {
  462.         Nlm_GetRect (l, &r);
  463.         Nlm_InsetRect (&r, 1, 1);
  464.         Nlm_InvalRect (&r);
  465.       }
  466.     }
  467. #ifdef WIN_MSWIN
  468.     EnableWindow (c, TRUE);
  469.     SetWindowRedraw (c, TRUE);
  470. #endif
  471. #ifdef WIN_MOTIF
  472.     XtVaSetValues (c, XmNsensitive, TRUE, NULL);
  473. #endif
  474.     Nlm_RestorePort (tempPort);
  475.   }
  476. }
  477.  
  478. static void Nlm_DisableList (Nlm_GraphiC l, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  479.  
  480. {
  481.   Nlm_ListTool  c;
  482.   Nlm_BaR       sb;
  483.   Nlm_WindoW    tempPort;
  484.  
  485.   if (setFlag) {
  486.     Nlm_SetEnabled (l, FALSE);
  487.   }
  488.   tempPort = Nlm_SavePortIfNeeded (l, savePort);
  489.   sb = Nlm_GetListScrollBar ((Nlm_LisT) l);
  490.   if (sb != NULL) {
  491.     Nlm_DoDisable ((Nlm_GraphiC) sb, TRUE, FALSE);
  492.   }
  493.   c = Nlm_GetListHandle ((Nlm_LisT) l);
  494. #ifdef WIN_MSWIN
  495.   EnableWindow (c, FALSE);
  496.   SetWindowRedraw (c, FALSE);
  497. #endif
  498. #ifdef WIN_MOTIF
  499.   XtVaSetValues (c, XmNsensitive, FALSE, NULL);
  500. #endif
  501.   Nlm_RestorePort (tempPort);
  502. }
  503.  
  504. static void Nlm_RemoveList (Nlm_GraphiC l, Nlm_Boolean savePort)
  505.  
  506. {
  507.   Nlm_ListTool  c;
  508.   Nlm_WindoW    tempPort;
  509. #ifdef WIN_MAC
  510.   Nlm_BaR       sb;
  511. #endif
  512.  
  513.   tempPort = Nlm_SavePortIfNeeded (l, savePort);
  514.   c = Nlm_GetListHandle ((Nlm_LisT) l);
  515. #ifdef WIN_MAC
  516.   if (c != NULL) {
  517.     LDispose (c);
  518.   }
  519.   sb = Nlm_GetListScrollBar ((Nlm_LisT) l);
  520.   if (sb != NULL) {
  521.     Nlm_DoRemove ((Nlm_GraphiC) sb, FALSE);
  522.   }
  523. #endif
  524. #ifdef WIN_MSWIN
  525.   RemoveProp (c, (LPSTR) "Nlm_VibrantProp");
  526.   DestroyWindow (c);
  527. #endif
  528. #ifdef WIN_MOTIF
  529.   XtDestroyWidget (c);
  530. #endif
  531.   Nlm_RemoveLink (l);
  532.   recentList = NULL;
  533.   Nlm_RestorePort (tempPort);
  534. }
  535.  
  536. static void Nlm_ResetList (Nlm_GraphiC l, Nlm_Boolean savePort)
  537.  
  538. {
  539.   Nlm_ListTool  c;
  540.   Nlm_ListData  ldata;
  541.   Nlm_WindoW    tempPort;
  542. #ifdef WIN_MAC
  543.   Nlm_Int2      col;
  544.   Nlm_BaR       sb;
  545. #endif
  546.  
  547.   tempPort = Nlm_SavePortIfNeeded (l, savePort);
  548.   Nlm_GetListData ((Nlm_LisT) l, &ldata);
  549.   c = ldata.handle;
  550. #ifdef WIN_MAC
  551.   LDelColumn (0, 0, c);
  552.   LDelRow (0, 0, c);
  553.   col = LAddColumn (1, 0, c);
  554.   sb = ldata.scrollBar;
  555.   if (sb != NULL) {
  556.     Nlm_DoReset ((Nlm_GraphiC) sb, FALSE);
  557.   }
  558. #endif
  559. #ifdef WIN_MSWIN
  560.   ListBox_ResetContent (c);
  561. #endif
  562. #ifdef WIN_MOTIF
  563.   XmListSetPos (c, 1);
  564.   XmListDeleteAllItems (c);
  565. #endif
  566.   ldata.numItems = 0;
  567.   ldata.offset = 0;
  568.   Nlm_SetListData ((Nlm_LisT) l, &ldata);
  569.   Nlm_RestorePort (tempPort);
  570. }
  571.  
  572. static Nlm_Int2 Nlm_CountListItems (Nlm_GraphiC l)
  573.  
  574. {
  575.   return Nlm_GetListNumItems ((Nlm_LisT) l);
  576. }
  577.  
  578. static void Nlm_GetListTitle (Nlm_GraphiC l, Nlm_Int2 item,
  579.                               Nlm_CharPtr title, Nlm_sizeT maxsize)
  580.  
  581. {
  582.   Nlm_ListTool  c;
  583.   Nlm_Char      temp [256];
  584. #ifdef WIN_MAC
  585.   Cell          cell;
  586.   Nlm_Int2      len;
  587. #endif
  588.  
  589.   c = Nlm_GetListHandle ((Nlm_LisT) l);
  590.   if (item > 0) {
  591. #ifdef WIN_MAC
  592.     cell.h = 0;
  593.     cell.v = item - 1;
  594.     len = sizeof (temp);
  595.     LGetCell (temp, &len, cell, c);
  596.     if (len < sizeof (temp)) {
  597.       temp [len] = '\0';
  598.     }
  599. #endif
  600. #ifdef WIN_MSWIN
  601.     if (ListBox_GetTextLen (c, item - 1) < sizeof (temp)) {
  602.       ListBox_GetText (c, item - 1, temp);
  603.     } else {
  604.       temp [0] = '\0';
  605.     }
  606. #endif
  607. #ifdef WIN_MOTIF
  608. #endif
  609.   }
  610.   Nlm_StringNCpy (title, temp, maxsize);
  611. }
  612.  
  613. #ifdef WIN_MAC
  614. static void Nlm_ClearCellsInGroup (Nlm_LisT l, Nlm_Int2 excpt)
  615.  
  616. {
  617.   Nlm_ListTool  c;
  618.   Cell          cell;
  619.   Nlm_Int2      count;
  620.   Nlm_Int2      i;
  621.  
  622.   c = Nlm_GetListHandle (l);
  623.   count = Nlm_GetListNumItems (l);
  624.   i = 1;
  625.   cell.h = 0;
  626.   while (i <= count) {
  627.     if (i != excpt) {
  628.       cell.v = i - 1;
  629.       LSetSelect (FALSE, cell, c);
  630.     }
  631.     i++;
  632.   }
  633. }
  634. #endif
  635.  
  636. static void Nlm_SetListValue (Nlm_GraphiC l, Nlm_Int2 value, Nlm_Boolean savePort)
  637.  
  638. {
  639.   Nlm_ListTool  c;
  640.   Nlm_WindoW    tempPort;
  641. #ifdef WIN_MAC
  642.   Cell          cell;
  643.   Nlm_Int2      delta;
  644.   Nlm_Int2      newval;
  645.   Nlm_Int2      num;
  646.   Nlm_Int2      oldval;
  647.   Nlm_BaR       sb;
  648.   Nlm_Int2      vis;
  649. #endif
  650.  
  651.   tempPort = Nlm_SavePortIfNeeded (l, savePort);
  652.   c = Nlm_GetListHandle ((Nlm_LisT) l);
  653. #ifdef WIN_MAC
  654.   if (value > 0) {
  655.     Nlm_ClearCellsInGroup ((Nlm_LisT) l, value);
  656.     cell.h = 0;
  657.     cell.v = value - 1;
  658.     LSetSelect (TRUE, cell, c);
  659.     sb = Nlm_GetListScrollBar ((Nlm_LisT) l);
  660.     if (sb != NULL) {
  661.       oldval = Nlm_DoGetValue ((Nlm_GraphiC) sb);
  662.       num = Nlm_GetListNumItems ((Nlm_LisT) l);
  663.       vis = Nlm_GetListVisLines ((Nlm_LisT) l);
  664.       value--;
  665.       if (value < oldval) {
  666.         newval = value;
  667.       } else if (value < oldval + vis) {
  668.         newval = oldval;
  669.       } else if (value <= num - vis) {
  670.         newval = value;
  671.       } else {
  672.         newval = num - vis;
  673.       }
  674.       delta = newval - oldval;
  675.       if (delta != 0) {
  676.         Nlm_DoSetValue ((Nlm_GraphiC) sb, newval, FALSE);
  677.       }
  678.     }
  679.   } else {
  680.     Nlm_ClearCellsInGroup ((Nlm_LisT) l, 0);
  681.   }
  682. #endif
  683. #ifdef WIN_MSWIN
  684.   if (value > 0) {
  685.     ListBox_SetCurSel (c, value - 1);
  686.   } else {
  687.     ListBox_SetCurSel (c, -1);
  688.   }
  689. #endif
  690. #ifdef WIN_MOTIF
  691.   if (value > 0) {
  692.     XmListSelectPos (c, (int) value, FALSE);
  693.   } else {
  694.     XmListDeselectAllItems (c);
  695.   }
  696. #endif
  697.   Nlm_RestorePort (tempPort);
  698. }
  699.  
  700. static Nlm_Int2 Nlm_GetListValue (Nlm_GraphiC l)
  701.  
  702. {
  703.   Nlm_ListTool  c;
  704.   Nlm_Int2      value;
  705. #ifdef WIN_MAC
  706.   Cell          cell;
  707.   Nlm_Int2      count;
  708.   Nlm_Boolean   found;
  709.   Nlm_Int2      i;
  710. #endif
  711. #ifdef WIN_MOTIF
  712.   int           count;
  713.   int           *position;
  714. #endif
  715.  
  716.   value = 0;
  717.   c = Nlm_GetListHandle ((Nlm_LisT) l);
  718. #ifdef WIN_MAC
  719.   count = Nlm_GetListNumItems ((Nlm_LisT) l);
  720.   i = 0;
  721.   cell.h = 0;
  722.   found = FALSE;
  723.   while (i <= count && ! found) {
  724.     i++;
  725.     cell.v = i - 1;
  726.     found = LGetSelect (FALSE, &cell, c);
  727.   }
  728.   if (found) {
  729.     value = i;
  730.   }
  731. #endif
  732. #ifdef WIN_MSWIN
  733.   value = (Nlm_Int2) ListBox_GetCurSel (c) + 1;
  734. #endif
  735. #ifdef WIN_MOTIF
  736.   if (XmListGetSelectedPos (c, &position, &count)) {
  737.     if (position != NULL) {
  738.       value = *position;
  739.       XtFree ((char *) position);
  740.     } else {
  741.       value = 0;
  742.     }
  743.   } else {
  744.     value = 0;
  745.   }
  746. #endif
  747.   return value;
  748. }
  749.  
  750. static void Nlm_SetListStatus (Nlm_GraphiC l, Nlm_Int2 item,
  751.                                Nlm_Boolean value, Nlm_Boolean savePort)
  752.  
  753. {
  754.   Nlm_ListTool  c;
  755.   Nlm_WindoW    tempPort;
  756. #ifdef WIN_MAC
  757.   Cell          cell;
  758. #endif
  759.  
  760.   if (item > 0) {
  761.     tempPort = Nlm_SavePortIfNeeded (l, savePort);
  762.     c = Nlm_GetListHandle ((Nlm_LisT) l);
  763. #ifdef WIN_MAC
  764.     cell.h = 0;
  765.     cell.v = item - 1;
  766.     LSetSelect (value, cell, c);
  767. #endif
  768. #ifdef WIN_MSWIN
  769.     ListBox_SetSel (c, value, item);
  770. #endif
  771. #ifdef WIN_MOTIF
  772.     XmListSelectPos (c, (int) item, value);
  773. #endif
  774.     Nlm_RestorePort (tempPort);
  775.   }
  776. }
  777.  
  778. static Nlm_Boolean Nlm_GetListStatus (Nlm_GraphiC l, Nlm_Int2 item)
  779.  
  780. {
  781.   Nlm_ListTool  c;
  782.   Nlm_Boolean   value;
  783. #ifdef WIN_MAC
  784.   Cell          cell;
  785.   Nlm_Int2      count;
  786. #endif
  787. #ifdef WIN_MSWIN
  788.   Nlm_Int2      count;
  789. #endif
  790. #ifdef WIN_MOTIF
  791.   int           count;
  792.   int           *position;
  793. #endif
  794.  
  795.   value = FALSE;
  796.   c = Nlm_GetListHandle ((Nlm_LisT) l);
  797.   count = Nlm_GetListNumItems ((Nlm_LisT) l);
  798.   if (item > 0 && item <= count) {
  799. #ifdef WIN_MAC
  800.     cell.h = 0;
  801.     cell.v = item - 1;
  802.     value = LGetSelect (FALSE, &cell, c);
  803. #endif
  804. #ifdef WIN_MSWIN
  805.     value = (Nlm_Boolean) (ListBox_GetSel (c, item) != 0);
  806. #endif
  807. #ifdef WIN_MOTIF
  808.     if (XmListGetSelectedPos (c, &position, &count)) {
  809.       if (position != NULL) {
  810.         count--;
  811.         while (count >= 0 && (! value)) {
  812.           if (position [count] == item) {
  813.             value = TRUE;
  814.           }
  815.           count--;
  816.         }
  817.         XtFree ((char *) position);
  818.       }
  819.     }
  820. #endif
  821.   }
  822.   return value;
  823. }
  824.  
  825. static void Nlm_SetListOffset (Nlm_GraphiC l, Nlm_Int2 horiz,
  826.                                Nlm_Int2 vert, Nlm_Boolean savePort)
  827.  
  828. {
  829. #ifdef WIN_MAC
  830.   Nlm_BaR  sb;
  831.  
  832.   sb = Nlm_GetListScrollBar ((Nlm_LisT) l);
  833.   if (sb != NULL) {
  834.     Nlm_DoSetValue ((Nlm_GraphiC) sb, vert, savePort);
  835.   }
  836. #endif
  837. #ifdef WIN_MSWIN
  838.   Nlm_ListTool  c;
  839.  
  840.   c = Nlm_GetListHandle ((Nlm_LisT) l);
  841.   ListBox_SetTopIndex (c, vert);
  842. #endif
  843. #ifdef WIN_MOTIF
  844.   Nlm_ListTool  c;
  845.  
  846.   c = Nlm_GetListHandle ((Nlm_LisT) l);
  847.   XmListSetPos (c, vert);
  848. #endif
  849. }
  850.  
  851. static void Nlm_GetListOffset (Nlm_GraphiC l, Nlm_Int2Ptr horiz, Nlm_Int2Ptr vert)
  852.  
  853. {
  854. #ifdef WIN_MAC
  855.   Nlm_BaR   sb;
  856.   Nlm_Int2  rsult;
  857.  
  858.   sb = Nlm_GetListScrollBar ((Nlm_LisT) l);
  859.   rsult = 0;
  860.   if (sb != NULL) {
  861.     rsult = Nlm_DoGetValue ((Nlm_GraphiC) sb);
  862.   }
  863.   if (vert != NULL) {
  864.     *vert = rsult;
  865.   }
  866. #endif
  867. #ifdef WIN_MSWIN
  868.   Nlm_ListTool  c;
  869.  
  870.   c = Nlm_GetListHandle ((Nlm_LisT) l);
  871.   if (vert != NULL) {
  872.     *vert = (Nlm_Int2) ListBox_GetTopIndex (c);
  873.   }
  874. #endif
  875. #ifdef WIN_MOTIF
  876.   Nlm_ListTool  c;
  877.   int           top;
  878.  
  879.   c = Nlm_GetListHandle ((Nlm_LisT) l);
  880.   if (vert != NULL) {
  881.     XtVaGetValues (c, XmNtopItemPosition, &top, NULL);
  882.     *vert = (Nlm_Int2) top;
  883.   }
  884. #endif
  885. }
  886.  
  887. #ifdef WIN_MAC
  888. static void Nlm_ScrollAction (Nlm_BaR sb, Nlm_GraphiC l,
  889.                               Nlm_Int2 newval, Nlm_Int2 oldval)
  890.  
  891. {
  892.   Nlm_Int2      delta;
  893.   Nlm_ListTool  h;
  894.   Nlm_ListData  ldata;
  895.   Nlm_RecT      r;
  896.   Nlm_Int2      vis;
  897.   Nlm_WindoW    tempPort;
  898.  
  899.   tempPort = Nlm_SavePort (l);
  900.   Nlm_GetListData ((Nlm_LisT) l, &ldata);
  901.   vis = ldata.visLines;
  902.   h = ldata.handle;
  903.   ldata.offset = newval;
  904.   Nlm_SetListData ((Nlm_LisT) l, &ldata);
  905.   delta = oldval - newval;
  906.   if (oldval != newval) {
  907.     Nlm_SelectFont (Nlm_systemFont);
  908.     LScroll (0, -delta, h);
  909.   } else if (Nlm_GetVisible (l) && Nlm_GetAllParentsVisible (l)) {
  910.     Nlm_GetRect (l, &r);
  911.     Nlm_InsetRect (&r, 1, 1);
  912.     Nlm_InvalRect (&r);
  913.   }
  914.   Nlm_RestorePort (tempPort);
  915. }
  916. #endif
  917.  
  918. #ifdef WIN_MAC
  919. static void Nlm_InvalList (Nlm_GraphiC l)
  920.  
  921. {
  922.   Nlm_RecT  r;
  923.  
  924.   if (Nlm_GetVisible (l) && Nlm_GetAllParentsVisible (l)) {
  925.     Nlm_GetRect (l, &r);
  926.     r.right += Nlm_vScrollBarWidth;
  927.     Nlm_InsetRect (&r, -1, -1);
  928.     Nlm_InvalRect (&r);
  929.   }
  930. }
  931. #endif
  932.  
  933. static void Nlm_SetListPosition (Nlm_GraphiC l, Nlm_RectPtr r, Nlm_Boolean savePort)
  934.  
  935. {
  936.   Nlm_ListTool  c;
  937.   Nlm_RecT      lr;
  938.   Nlm_RecT      oldRect;
  939.   Nlm_WindoW    tempPort;
  940. #ifdef WIN_MAC
  941.   Nlm_PoinT     csize;
  942.   ListPtr       lp;
  943.   Nlm_BaR       sb;
  944.   Nlm_Int2      wid;
  945. #endif
  946.  
  947.   if (r != NULL) {
  948.     Nlm_DoGetPosition (l, &oldRect);
  949.     if (! Nlm_EqualRect (r, &oldRect)) {
  950.       tempPort = Nlm_SavePortIfNeeded (l, savePort);
  951.       c = Nlm_GetListHandle ((Nlm_LisT) l);
  952. #ifdef WIN_MAC
  953.       lr = *r;
  954.       Nlm_InvalList (l);
  955.       lr.right -= Nlm_vScrollBarWidth;
  956.       Nlm_SetRect (l, &lr);
  957.       Nlm_InsetRect (&lr, 2, 2);
  958.       HLock ((Handle) c);
  959.       lp = (ListPtr) *((Handle) c);
  960.       Nlm_RecTToRectTool (&lr, &(lp->rView));
  961.       Nlm_PointToolToPoinT (lp->cellSize, &csize);
  962.       csize.x = lr.right - lr.left;
  963.       Nlm_PoinTToPointTool (csize, &(lp->cellSize));
  964.       HUnlock ((Handle) c);
  965.       Nlm_InvalList (l);
  966.       sb = Nlm_GetListScrollBar ((Nlm_LisT) l);
  967.       if (sb != NULL) {
  968.         Nlm_GetRect (l, &lr);
  969.         lr.left = lr.right;
  970.         lr.right += Nlm_vScrollBarWidth;
  971.         Nlm_DoSetPosition ((Nlm_GraphiC) sb, &lr, FALSE);
  972.       }
  973. #endif
  974. #ifdef WIN_MSWIN
  975.       lr = *r;
  976.       MoveWindow (c, lr.left, lr.top, lr.right - lr.left, lr.bottom - lr.top, TRUE);
  977.       lr.right -= Nlm_vScrollBarWidth;
  978.       Nlm_SetRect (l, &lr);
  979.       UpdateWindow (c);
  980. #endif
  981. #ifdef WIN_MOTIF
  982.       XtVaSetValues (c,
  983.                      XmNx, (Position) r->left,
  984.                      XmNy, (Position) r->top,
  985.                      XmNwidth, (Dimension) (r->right - r->left),
  986.                      XmNheight, (Dimension) (r->bottom - r->top), 
  987.                      NULL);
  988.       Nlm_SetRect (l, r);
  989. #endif
  990.       Nlm_RestorePort (tempPort);
  991.     }
  992.   }
  993. }
  994.  
  995. static void Nlm_GetListPosition (Nlm_GraphiC l, Nlm_RectPtr r)
  996.  
  997. {
  998.   Nlm_RecT  lr;
  999.  
  1000.   if (r != NULL) {
  1001.     Nlm_GetRect (l, &lr);
  1002.     lr.right += Nlm_vScrollBarWidth;
  1003.     *r = lr;
  1004.   }
  1005. }
  1006.  
  1007. #ifdef WIN_MSWIN
  1008. /* Message cracker functions */
  1009.  
  1010. static void MyCls_OnChar (HWND hwnd, UINT ch, int cRepeat)
  1011.  
  1012. {
  1013.   Nlm_LisT  l;
  1014.  
  1015.   l = (Nlm_LisT) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
  1016.   handlechar = FALSE;
  1017.   if (ch == '\t') {
  1018.     Nlm_DoSendFocus ((Nlm_GraphiC) l, (Nlm_Char) ch);
  1019.   } else if (ch == '\n' || ch == '\r') {
  1020.     Nlm_DoSendFocus ((Nlm_GraphiC) l, (Nlm_Char) ch);
  1021.   } else {
  1022.     handlechar = TRUE;
  1023.   }
  1024. }
  1025.  
  1026. LRESULT CALLBACK EXPORT ListProc (HWND hwnd, UINT message,
  1027.                                   WPARAM wParam, LPARAM lParam)
  1028.  
  1029. {
  1030.   Nlm_LisT  l;
  1031.   LRESULT   rsult;
  1032.   HDC       tempHDC;
  1033.   HWND      tempHWnd;
  1034.  
  1035.   if (Nlm_VibrantDisabled ()) {
  1036.     return CallWindowProc (lpfnOldListProc, hwnd, message, wParam, lParam);
  1037.   }
  1038.  
  1039.   rsult = 0;
  1040.   tempHWnd = Nlm_currentHWnd;
  1041.   tempHDC = Nlm_currentHDC;
  1042.   l = (Nlm_LisT) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
  1043.   Nlm_theWindow = Nlm_GetParentWindow ((Nlm_GraphiC) l);
  1044.   Nlm_currentHWnd = GetParent (hwnd);
  1045.   Nlm_currentHDC = Nlm_ParentWindowPort ((Nlm_GraphiC) l);
  1046.   Nlm_currentWindowTool = hwnd;
  1047.   Nlm_currentKey = '\0';
  1048.   Nlm_currentWParam = wParam;
  1049.   Nlm_currentLParam = lParam;
  1050.   Nlm_cmmdKey = FALSE;
  1051.   Nlm_ctrlKey = FALSE;
  1052.   Nlm_optKey = FALSE;
  1053.   Nlm_shftKey = FALSE;
  1054.   Nlm_dblClick = FALSE;
  1055.  
  1056.   switch (message) {
  1057.     case WM_CHAR:
  1058.       HANDLE_WM_CHAR (hwnd, wParam, lParam, MyCls_OnChar);
  1059.       if (handlechar) {
  1060.         rsult = CallWindowProc (lpfnOldListProc, hwnd, message, wParam, lParam);
  1061.       }
  1062.       break;
  1063.     default:
  1064.       rsult = CallWindowProc (lpfnOldListProc, hwnd, message, wParam, lParam);
  1065.       break;
  1066.   }
  1067.   Nlm_currentHWnd = tempHWnd;
  1068.   Nlm_currentHDC = tempHDC;
  1069.   Nlm_currentWindowTool = tempHWnd;
  1070.   return rsult;
  1071. }
  1072. #endif
  1073.  
  1074. #ifdef WIN_MOTIF
  1075. static void Nlm_ListCallback (Widget w, XtPointer client_data, XtPointer call_data)
  1076.  
  1077. {
  1078.   Nlm_GraphiC  l;
  1079.  
  1080.   Nlm_dblClick = FALSE;
  1081.   l = (Nlm_GraphiC) client_data;
  1082.   Nlm_DoCallback (l);
  1083. }
  1084.  
  1085. static void Nlm_DoubleCallback (Widget w, XtPointer client_data, XtPointer call_data)
  1086.  
  1087. {
  1088.   Nlm_GraphiC  l;
  1089.  
  1090.   Nlm_dblClick = TRUE;
  1091.   l = (Nlm_GraphiC) client_data;
  1092.   Nlm_DoCallback (l);
  1093. }
  1094. #endif
  1095.  
  1096. static void Nlm_NewList (Nlm_LisT l, Nlm_Int2 width,
  1097.                          Nlm_Int2 height, Nlm_Int2 vis,
  1098.                          Nlm_Char flags, Nlm_Uint4 style,
  1099.                          Nlm_Boolean multi, Nlm_LstActnProc actn)
  1100.  
  1101. {
  1102.   Nlm_ListTool    c;
  1103.   Nlm_RecT        r;
  1104.   Nlm_BaR         sb;
  1105.   Nlm_WindowTool  wptr;
  1106. #ifdef WIN_MAC
  1107.   Nlm_PoinT       csize;
  1108.   Nlm_PointTool   cstool;
  1109.   Nlm_RecT        db;
  1110.   Nlm_RectTool    dbtool;
  1111.   ListPtr         lp;
  1112.   Nlm_PoinT       npt;
  1113.   Nlm_RectTool    rtool;
  1114.   Nlm_PoinT       zpt;
  1115. #endif
  1116. #ifdef WIN_MOTIF
  1117.   Cardinal        n;
  1118.   Arg             wargs [15];
  1119. #endif
  1120.  
  1121.   Nlm_GetRect ((Nlm_GraphiC) l, &r);
  1122.   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) l);
  1123. #ifdef WIN_MAC
  1124.   r.left = r.right;
  1125.   r.right += Nlm_vScrollBarWidth;
  1126.   sb = Nlm_VertScrollBar ((Nlm_GraphiC) l, &r, Nlm_ScrollAction);
  1127.   Nlm_DoSetRange ((Nlm_GraphiC) sb, vis - 1, vis - 1, 0, FALSE);
  1128.   Nlm_GetRect ((Nlm_GraphiC) l, &r);
  1129.   Nlm_InsetRect (&r, 2, 2);
  1130.   Nlm_LoadRect (&db, 0, 0, 1, 0);
  1131.   csize.x = width;
  1132.   csize.y = height;
  1133.   Nlm_PoinTToPointTool (csize, &cstool);
  1134.   Nlm_RecTToRectTool (&r, &rtool);
  1135.   Nlm_RecTToRectTool (&db, &dbtool);
  1136.   c = LNew (&rtool, &dbtool, cstool, 0, wptr, TRUE, FALSE, FALSE, FALSE);
  1137.   HLock ((Handle) c);
  1138.   lp = (ListPtr) *((Handle) c);
  1139.   lp->selFlags = flags;
  1140.   HUnlock ((Handle) c);
  1141.   LDoDraw (TRUE, c);
  1142.   Nlm_LoadListData (l, c, sb, vis, 0, 0);
  1143. #endif
  1144. #ifdef WIN_MSWIN
  1145.   sb = NULL;
  1146.   r.right += Nlm_vScrollBarWidth;
  1147.   c = CreateWindow ("Listbox", "", WS_CHILD | style,
  1148.                     r.left, r.top, r.right - r.left,
  1149.                     r.bottom - r.top, wptr, 0,
  1150.                     Nlm_currentHInst, NULL);
  1151.   if (c != NULL) {
  1152.     SetProp (c, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) l);
  1153.   }
  1154.   Nlm_LoadListData (l, c, sb, vis, 0, 0);
  1155.   if (lpfnNewListProc == NULL) {
  1156.     lpfnNewListProc = (WNDPROC) MakeProcInstance ((FARPROC) ListProc, Nlm_currentHInst);
  1157.   }
  1158.   if (lpfnOldListProc == NULL) {
  1159.     lpfnOldListProc = (WNDPROC) GetWindowLong (c, GWL_WNDPROC);
  1160.   } else if (lpfnOldListProc != (WNDPROC) GetWindowLong (c, GWL_WNDPROC)) {
  1161.     Nlm_Message (MSG_ERROR, "ListProc subclass error");
  1162.   }
  1163.   SetWindowLong (c, GWL_WNDPROC, (LONG) lpfnNewListProc);
  1164. #endif
  1165. #ifdef WIN_MOTIF
  1166.   sb = NULL;
  1167.   n = 0;
  1168.   XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
  1169.   XtSetArg (wargs [n], XmNy, (Position) r.top); n++;
  1170.   XtSetArg (wargs [n], XmNwidth, (Dimension) (r.right - r.left)); n++;
  1171.   XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top)); n++;
  1172.   XtSetArg (wargs [n], XmNmarginHeight, 0); n++;
  1173.   XtSetArg (wargs [n], XmNmarginWidth, 0); n++;
  1174.   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  1175.   XtSetArg (wargs [n], XmNvisibleItemCount, (int) vis); n++;
  1176.   if (multi) {
  1177.     XtSetArg (wargs [n], XmNselectionPolicy, XmMULTIPLE_SELECT); n++;
  1178.   } else {
  1179.     XtSetArg (wargs [n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
  1180.   }
  1181.   XtSetArg (wargs [n], XmNlistSizePolicy, XmCONSTANT); n++;
  1182.   XtSetArg (wargs [n], XmNhighlightThickness, 0); n++;
  1183.   c = XmCreateScrolledList (wptr, (String) "", wargs, n);
  1184.   if (multi) {
  1185.     XtAddCallback (c, XmNmultipleSelectionCallback, Nlm_ListCallback, (XtPointer) l);
  1186.   } else {
  1187.     XtAddCallback (c, XmNbrowseSelectionCallback, Nlm_ListCallback, (XtPointer) l);
  1188.   }
  1189.   XtAddCallback (c, XmNdefaultActionCallback, Nlm_DoubleCallback, (XtPointer) l);
  1190.   XtManageChild (c);
  1191.   if (NLM_QUIET) {
  1192.     if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (l))) {
  1193.       XtRealizeWidget (c);
  1194.     }
  1195.   } else {
  1196.     XtRealizeWidget (c);
  1197.   }
  1198.   Nlm_LoadListData (l, c, sb, vis, 0, 0);
  1199. #endif
  1200.   Nlm_LoadAction ((Nlm_GraphiC) l, (Nlm_ActnProc) actn);
  1201. }
  1202.  
  1203. static Nlm_LisT Nlm_CommonList (Nlm_GrouP prnt, Nlm_Int2 width,
  1204.                                 Nlm_Int2 height, Nlm_GphPrcs PNTR classPtr,
  1205.                                 Nlm_Char flags, Nlm_Uint4 style,
  1206.                                 Nlm_Boolean multi, Nlm_LstActnProc actn)
  1207.  
  1208. {
  1209.   Nlm_Int2    dwid;
  1210.   Nlm_LisT    l;
  1211.   Nlm_Int2    lhgt;
  1212.   Nlm_PoinT   npt;
  1213.   Nlm_RecT    r;
  1214.   Nlm_WindoW  tempPort;
  1215.  
  1216.   l = NULL;
  1217.   if (prnt != NULL) {
  1218.     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
  1219.     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
  1220.     Nlm_SelectFont (Nlm_systemFont);
  1221.     dwid = width * Nlm_stdCharWidth;
  1222.     lhgt = height * Nlm_stdLineHeight;
  1223.     Nlm_LoadRect (&r, npt.x, npt.y, npt.x+dwid+4, npt.y+lhgt);
  1224. #ifdef WIN_MAC
  1225.     r.bottom += 4;
  1226. #endif
  1227. #ifdef WIN_MSWIN
  1228.     r.bottom += Nlm_stdDescent - 1;
  1229. #endif
  1230. #ifdef WIN_MOTIF
  1231.     r.bottom += Nlm_stdDescent + 1;
  1232. #endif
  1233.     l = (Nlm_LisT) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r,
  1234.                                    sizeof (Nlm_ListRec), classPtr);
  1235.     if (l != NULL) {
  1236.       Nlm_NewList (l, dwid, Nlm_stdLineHeight, height, flags, style, multi, actn);
  1237.       r.right += Nlm_vScrollBarWidth;
  1238. #ifdef WIN_MSWIN
  1239.       r.bottom += 4;
  1240. #endif
  1241.       Nlm_DoAdjustPrnt ((Nlm_GraphiC) l, &r, TRUE, FALSE);
  1242.       Nlm_DoShow ((Nlm_GraphiC) l, TRUE, FALSE);
  1243.     }
  1244.     Nlm_RestorePort (tempPort);
  1245.   }
  1246.   return l;
  1247. }
  1248.  
  1249. extern Nlm_LisT Nlm_SingleList (Nlm_GrouP prnt, Nlm_Int2 width,
  1250.                                 Nlm_Int2 height, Nlm_LstActnProc actn)
  1251.  
  1252. {
  1253.   Nlm_LisT  l;
  1254.  
  1255.   l = NULL;
  1256. #ifdef WIN_MAC
  1257.   l = Nlm_CommonList (prnt, width, height, singleProcs, '\270', 0, FALSE, actn);
  1258. #endif
  1259. #ifdef WIN_MSWIN
  1260.   l = Nlm_CommonList (prnt, width, height, singleProcs, '\0',
  1261.                       LBS_NOTIFY | WS_VSCROLL | WS_BORDER |
  1262.                       LBS_NOINTEGRALHEIGHT, FALSE, actn);
  1263. #endif
  1264. #ifdef WIN_MOTIF
  1265.   l = Nlm_CommonList (prnt, width, height, singleProcs, '\0', 0, FALSE, actn);
  1266. #endif
  1267.   return l;
  1268. }
  1269.  
  1270. extern Nlm_LisT Nlm_MultiList (Nlm_GrouP prnt, Nlm_Int2 width,
  1271.                                Nlm_Int2 height, Nlm_LstActnProc actn)
  1272.  
  1273. {
  1274.   Nlm_LisT  l;
  1275.  
  1276.   l = NULL;
  1277. #ifdef WIN_MAC
  1278.   l = Nlm_CommonList (prnt, width, height, multiProcs, '\124', 0, TRUE, actn);
  1279. #endif
  1280. #ifdef WIN_MSWIN
  1281.   l = Nlm_CommonList (prnt, width, height, multiProcs, '\0',
  1282.                       LBS_NOTIFY | WS_VSCROLL | WS_BORDER |
  1283.                       LBS_NOINTEGRALHEIGHT | LBS_MULTIPLESEL, TRUE, actn);
  1284. #endif
  1285. #ifdef WIN_MOTIF
  1286.   l = Nlm_CommonList (prnt, width, height, multiProcs, '\0', 0, TRUE, actn);
  1287. #endif
  1288.   return l;
  1289. }
  1290.  
  1291. extern void Nlm_ListItem (Nlm_LisT l, Nlm_CharPtr title)
  1292.  
  1293. {
  1294.   Nlm_ListTool  c;
  1295.   Nlm_Int2      num;
  1296.   Nlm_WindoW    tempPort;
  1297. #ifdef WIN_MAC
  1298.   Cell          cell;
  1299.   Nlm_Int2      count;
  1300.   Nlm_Boolean   doUpdate;
  1301.   Nlm_Int2      len;
  1302.   Nlm_Boolean   parentWindowVisible;
  1303.   Nlm_RecT      r;
  1304.   Nlm_Int2      row;
  1305.   Nlm_BaR       sb;
  1306.   Nlm_Int2      vis;
  1307.   Nlm_Int2      visDelta;
  1308. #endif
  1309. #ifdef WIN_MOTIF
  1310.   XmString      string;
  1311. #endif
  1312.  
  1313.   if (l != NULL) {
  1314.     tempPort = Nlm_SavePortIfNeeded ((Nlm_GraphiC) l, TRUE);
  1315.     c = Nlm_GetListHandle (l);
  1316. #ifdef WIN_MAC
  1317.     doUpdate = Nlm_GetEnabled ((Nlm_GraphiC) l);
  1318.     parentWindowVisible = Nlm_GetAllParentsVisible ((Nlm_GraphiC) l);
  1319.     Nlm_SelectFont (Nlm_systemFont);
  1320.     LDoDraw (parentWindowVisible && doUpdate, c);
  1321.     count = Nlm_GetListNumItems (l);
  1322.     row = LAddRow (1, count, c);
  1323.     cell.h = 0;
  1324.     cell.v = row;
  1325.     num = Nlm_GetListNumItems (l);
  1326.     num++;
  1327.     Nlm_SetListNumItems (l, num);
  1328.     len = (Nlm_Int2) Nlm_StringLen (title);
  1329.     LSetCell (title, len, cell, c);
  1330.     LDoDraw (doUpdate, c);
  1331.     vis = Nlm_GetListVisLines (l);
  1332.     visDelta =  num - vis;
  1333.     if (visDelta > 0) {
  1334.       sb = Nlm_GetListScrollBar (l);
  1335.       if (sb != NULL) {
  1336.         Nlm_DoSetRange ((Nlm_GraphiC) sb, vis - 1, vis - 1, visDelta, FALSE);
  1337.       }
  1338.     }
  1339. #endif
  1340. #ifdef WIN_MSWIN
  1341.     ListBox_AddString (c, title);
  1342.     num = Nlm_GetListNumItems (l);
  1343.     num++;
  1344.     Nlm_SetListNumItems (l, num);
  1345. #endif
  1346. #ifdef WIN_MOTIF
  1347.     string = XmStringCreateSimple (title);
  1348.     XmListAddItemUnselected (c, string, 0);
  1349.     XmStringFree (string);
  1350. #endif
  1351.     Nlm_RestorePort (tempPort);
  1352.   }
  1353. }
  1354.  
  1355. extern void Nlm_FreeLists (void)
  1356.  
  1357. {
  1358.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemFree (gphprcsptr);
  1359. }
  1360.  
  1361. extern void Nlm_InitLists (void)
  1362.  
  1363. {
  1364.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemNew (sizeof (Nlm_GphPrcs) * 2);
  1365.  
  1366.   singleProcs = &(gphprcsptr [0]);
  1367. #ifdef WIN_MAC
  1368.   singleProcs->click = Nlm_SingleListClick;
  1369.   singleProcs->draw = Nlm_DrawList;
  1370. #endif
  1371. #ifdef WIN_MSWIN
  1372.   singleProcs->command = Nlm_SingleListCommand;
  1373. #endif
  1374. #ifdef WIN_MOTIF
  1375.   singleProcs->callback = Nlm_SingleListCallback;
  1376. #endif
  1377.   singleProcs->show = Nlm_ShowList;
  1378.   singleProcs->hide = Nlm_HideList;
  1379.   singleProcs->enable = Nlm_EnableList;
  1380.   singleProcs->disable = Nlm_DisableList;
  1381.   singleProcs->remove = Nlm_RemoveList;
  1382.   singleProcs->reset = Nlm_ResetList;
  1383.   singleProcs->countItems = Nlm_CountListItems;
  1384.   singleProcs->getTitle = Nlm_GetListTitle;
  1385.   singleProcs->setValue = Nlm_SetListValue;
  1386.   singleProcs->getValue = Nlm_GetListValue;
  1387.   singleProcs->setOffset = Nlm_SetListOffset;
  1388.   singleProcs->getOffset = Nlm_GetListOffset;
  1389.   singleProcs->setPosition = Nlm_SetListPosition;
  1390.   singleProcs->getPosition = Nlm_GetListPosition;
  1391.  
  1392.   multiProcs = &(gphprcsptr [1]);
  1393. #ifdef WIN_MAC
  1394.   multiProcs->click = Nlm_MultiListClick;
  1395.   multiProcs->draw = Nlm_DrawList;
  1396. #endif
  1397. #ifdef WIN_MSWIN
  1398.   multiProcs->command = Nlm_MultiListCommand;
  1399. #endif
  1400. #ifdef WIN_MOTIF
  1401.   multiProcs->callback = Nlm_MultiListCallback;
  1402. #endif
  1403.   multiProcs->show = Nlm_ShowList;
  1404.   multiProcs->hide = Nlm_HideList;
  1405.   multiProcs->enable = Nlm_EnableList;
  1406.   multiProcs->disable = Nlm_DisableList;
  1407.   multiProcs->remove = Nlm_RemoveList;
  1408.   multiProcs->reset = Nlm_ResetList;
  1409.   multiProcs->countItems = Nlm_CountListItems;
  1410.   multiProcs->getTitle = Nlm_GetListTitle;
  1411.   multiProcs->setStatus = Nlm_SetListStatus;
  1412.   multiProcs->getStatus = Nlm_GetListStatus;
  1413.   multiProcs->setOffset = Nlm_SetListOffset;
  1414.   multiProcs->getOffset = Nlm_GetListOffset;
  1415.   multiProcs->setPosition = Nlm_SetListPosition;
  1416.   multiProcs->getPosition = Nlm_GetListPosition;
  1417. }
  1418.