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

  1. /*   vibtexts.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:  vibtexts.c
  27. *
  28. * Author:  Jonathan Kans
  29. *
  30. * Version Creation Date:   7/1/91
  31. *
  32. * $Revision: 2.32 $
  33. *
  34. * File Description: 
  35. *       Vibrant edit text 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_TextTool TEHandle
  52. #endif
  53.  
  54. #ifdef WIN_MSWIN
  55. #define Nlm_TextTool HWND
  56. #endif
  57.  
  58. #ifdef WIN_MOTIF
  59. #define Nlm_TextTool Widget
  60. #endif
  61.  
  62. #define HSCROLL_POSITIONS 100
  63.  
  64. typedef  struct  Nlm_textdata {
  65.   Nlm_TextTool     handle;
  66.   Nlm_BaR          vScrollBar;
  67.   Nlm_BaR          hScrollBar;
  68.   Nlm_Boolean      wrap;
  69.   Nlm_FonT         font;
  70.   Nlm_Int2         texthght;
  71.   Nlm_Boolean      active;
  72.   Nlm_Boolean      changed;
  73.   Nlm_Boolean      hidden;
  74.   Nlm_Int2         visLines;
  75.   Nlm_TxtActnProc  select;
  76.   Nlm_TxtActnProc  deselect;
  77.   Nlm_TxtActnProc  tabnotify;
  78. } Nlm_TextData;
  79.  
  80. typedef  struct  Nlm_textrec {
  81.   Nlm_GraphicRec  graphicR;
  82.   Nlm_TextData    text;
  83. } Nlm_TextRec, PNTR Nlm_TxtPtr;
  84.  
  85. typedef  struct  Nlm_passwdrec {
  86.   Nlm_TextRec  textR;
  87.   Nlm_Char     password [32];
  88. } Nlm_PasswdRec, PNTR Nlm_PwdPtr;
  89.  
  90. static Nlm_GphPrcsPtr  gphprcsptr = NULL;
  91.  
  92. static Nlm_GphPrcsPtr  dialogTextProcs;
  93. static Nlm_GphPrcsPtr  hiddenTextProcs;
  94. static Nlm_GphPrcsPtr  passwordTextProcs;
  95. static Nlm_GphPrcsPtr  scrollTextProcs;
  96.  
  97. static Nlm_TexT        recentText = NULL;
  98. static Nlm_TextData    recentTextData;
  99.  
  100. static Nlm_TexT        currentText = NULL;
  101.  
  102. #ifdef WIN_MSWIN
  103. static WNDPROC         lpfnNewTextProc = NULL;
  104. static WNDPROC         lpfnOldTextProc = NULL;
  105. static Nlm_Boolean     handlechar;
  106. #endif
  107.  
  108. #ifdef WIN_MOTIF
  109. static Nlm_Boolean     allowTextCallback = TRUE;
  110. #endif
  111.  
  112. /* dgg */
  113. Nlm_FonT        gDialogTextFont = NULL;
  114. static Nlm_Int2        gDlogTextHeight = 0;
  115.  
  116. static void SelectDialogFont()
  117. {
  118. #ifdef DCLAP
  119.     if (gDialogTextFont == NULL) 
  120.         gDialogTextFont= Nlm_systemFont;  /* mswin,?xwin needs work to use other fonts */
  121.     Nlm_SelectFont (gDialogTextFont); 
  122.     gDlogTextHeight= Nlm_LineHeight ();
  123. #else
  124.   Nlm_SelectFont (Nlm_systemFont);
  125.   gDialogTextFont= Nlm_systemFont;
  126.   gDlogTextHeight= Nlm_stdLineHeight;
  127. #endif
  128. }
  129.  
  130.  
  131. static void Nlm_LoadTextData (Nlm_TexT t, Nlm_TextTool hdl,
  132.                               Nlm_BaR vbar, Nlm_BaR hbar,
  133.                               Nlm_Boolean wrp, Nlm_FonT fnt,
  134.                               Nlm_Int2 hght, Nlm_Boolean actv,
  135.                               Nlm_Boolean chgd, Nlm_Boolean hidn,
  136.                               Nlm_Int2 visl, Nlm_TxtActnProc slct,
  137.                               Nlm_TxtActnProc dslct, Nlm_TxtActnProc tabn)
  138.  
  139. {
  140.   Nlm_TextData  PNTR tdptr;
  141.   Nlm_TxtPtr   tp;
  142.  
  143.   if (t != NULL) {
  144.     tp = (Nlm_TxtPtr) Nlm_HandLock (t);
  145.     tdptr = &(tp->text);
  146.     tdptr->handle = hdl;
  147.     tdptr->vScrollBar = vbar;
  148.     tdptr->hScrollBar = hbar;
  149.     tdptr->wrap = wrp;
  150.     tdptr->font = fnt;
  151.     tdptr->texthght = hght;
  152.     tdptr->active = actv;
  153.     tdptr->changed = chgd;
  154.     tdptr->hidden = hidn;
  155.     tdptr->visLines = visl;
  156.     tdptr->select = slct;
  157.     tdptr->deselect = dslct;
  158.     tdptr->tabnotify = tabn;
  159.     Nlm_HandUnlock (t);
  160.     recentText = NULL;
  161.   }
  162. }
  163.  
  164. static void Nlm_SetTextData (Nlm_TexT t, Nlm_TextData * tdata)
  165.  
  166. {
  167.   Nlm_TxtPtr  tp;
  168.  
  169.   if (t != NULL && tdata != NULL) {
  170.     tp = (Nlm_TxtPtr) Nlm_HandLock (t);
  171.     tp->text = *tdata;
  172.     Nlm_HandUnlock (t);
  173.     recentText = t;
  174.     recentTextData = *tdata;
  175.   }
  176. }
  177.  
  178. static void Nlm_GetTextData (Nlm_TexT t, Nlm_TextData * tdata)
  179.  
  180. {
  181.   Nlm_TxtPtr  tp;
  182.  
  183.   if (t != NULL && tdata != NULL) {
  184.     if (t == recentText && NLM_RISKY) {
  185.       *tdata = recentTextData;
  186.     } else {
  187.       tp = (Nlm_TxtPtr) Nlm_HandLock (t);
  188.       *tdata = tp->text;
  189.       Nlm_HandUnlock (t);
  190.       recentText = t;
  191.       recentTextData = *tdata;
  192.     }
  193.   }
  194. }
  195.  
  196. static void Nlm_SetTextHandle (Nlm_TexT t, Nlm_TextTool hdl)
  197.  
  198. {
  199.   Nlm_TextData  tdata;
  200.  
  201.   Nlm_GetTextData (t, &tdata);
  202.   tdata.handle = hdl;
  203.   Nlm_SetTextData (t, &tdata);
  204. }
  205.  
  206. static Nlm_TextTool Nlm_GetTextHandle (Nlm_TexT t)
  207.  
  208. {
  209.   Nlm_TextData  tdata;
  210.  
  211.   Nlm_GetTextData (t, &tdata);
  212.   return tdata.handle;
  213. }
  214.  
  215. static Nlm_BaR Nlm_GetTextVScrollBar (Nlm_TexT t)
  216.  
  217. {
  218.   Nlm_TextData  tdata;
  219.  
  220.   Nlm_GetTextData (t, &tdata);
  221.   return tdata.vScrollBar;
  222. }
  223.  
  224. static Nlm_BaR Nlm_GetTextHScrollBar (Nlm_TexT t)
  225.  
  226. {
  227.   Nlm_TextData  tdata;
  228.  
  229.   Nlm_GetTextData (t, &tdata);
  230.   return tdata.hScrollBar;
  231. }
  232.  
  233. static Nlm_Boolean Nlm_GetTextWrap (Nlm_TexT t)
  234.  
  235. {
  236.   Nlm_TextData  tdata;
  237.  
  238.   Nlm_GetTextData (t, &tdata);
  239.   return tdata.wrap;
  240. }
  241.  
  242. static Nlm_Int2 Nlm_GetFontHeight (Nlm_TexT t)
  243.  
  244. {
  245.   Nlm_TextData  tdata;
  246.  
  247.   Nlm_GetTextData (t, &tdata);
  248.   return tdata.texthght;
  249. }
  250.  
  251. static void Nlm_SetActive (Nlm_TexT t, Nlm_Boolean act)
  252.  
  253. {
  254.   Nlm_TextData  tdata;
  255.  
  256.   Nlm_GetTextData (t, &tdata);
  257.   tdata.active = act;
  258.   Nlm_SetTextData (t, &tdata);
  259. }
  260.  
  261. static Nlm_Boolean Nlm_GetActive (Nlm_TexT t)
  262.  
  263. {
  264.   Nlm_TextData  tdata;
  265.  
  266.   Nlm_GetTextData (t, &tdata);
  267.   return tdata.active;
  268. }
  269.  
  270. static void Nlm_SetChanged (Nlm_TexT t, Nlm_Boolean chd)
  271.  
  272. {
  273.   Nlm_TextData  tdata;
  274.  
  275.   Nlm_GetTextData (t, &tdata);
  276.   tdata.changed = chd;
  277.   Nlm_SetTextData (t, &tdata);
  278. }
  279.  
  280. static Nlm_Boolean Nlm_GetChanged (Nlm_TexT t)
  281.  
  282. {
  283.   Nlm_TextData  tdata;
  284.  
  285.   Nlm_GetTextData (t, &tdata);
  286.   return tdata.changed;
  287. }
  288.  
  289. static Nlm_Boolean Nlm_IsHiddenText (Nlm_TexT t)
  290.  
  291. {
  292.   Nlm_TextData  tdata;
  293.  
  294.   Nlm_GetTextData (t, &tdata);
  295.   return tdata.hidden;
  296. }
  297.  
  298. static Nlm_Int2 Nlm_GetVisLines (Nlm_TexT t)
  299.  
  300. {
  301.   Nlm_TextData  tdata;
  302.  
  303.   Nlm_GetTextData (t, &tdata);
  304.   return tdata.visLines;
  305. }
  306.  
  307. extern void Nlm_SetTextSelect (Nlm_TexT t, Nlm_TxtActnProc slct, Nlm_TxtActnProc dslct)
  308.  
  309. {
  310.   Nlm_TextData  tdata;
  311.  
  312.   if (t != NULL) {
  313.     Nlm_GetTextData (t, &tdata);
  314.     tdata.select = slct;
  315.     tdata.deselect = dslct;
  316.     Nlm_SetTextData (t, &tdata);
  317.   }
  318. }
  319.  
  320. static void Nlm_SetPassword (Nlm_TexT t, Nlm_CharPtr passwd)
  321.  
  322. {
  323.   Nlm_PwdPtr  pp;
  324.  
  325.   if (t != NULL && passwd != NULL) {
  326.     pp = (Nlm_PwdPtr) Nlm_HandLock (t);
  327.     Nlm_StringNCpy ((Nlm_CharPtr) pp->password, passwd, 31);
  328.     Nlm_HandUnlock (t);
  329.   }
  330. }
  331.  
  332. static void Nlm_GetPassword (Nlm_TexT t, Nlm_CharPtr passwd, Nlm_sizeT maxsize)
  333.  
  334. {
  335.   Nlm_PwdPtr  pp;
  336.  
  337.   if (t != NULL && passwd != NULL) {
  338.     pp = (Nlm_PwdPtr) Nlm_HandLock (t);
  339.     Nlm_StringNCpy (passwd, (Nlm_CharPtr) pp->password, maxsize);
  340.     Nlm_HandUnlock (t);
  341.   }
  342. }
  343.  
  344. #ifdef WIN_MAC
  345. static Nlm_Int2 Nlm_GetTextLines (Nlm_TexT t)
  346.  
  347. {
  348.   Nlm_TextTool  h;
  349.   Nlm_Int2      lines;
  350.   TEPtr         tptr;
  351.  
  352.   h = Nlm_GetTextHandle (t);
  353.   HLock ((Handle) h);
  354.   tptr = (TEPtr) *((Handle) h);
  355.   lines = tptr->nLines;
  356.   HUnlock ((Handle) h);
  357.   return lines;
  358. }
  359.  
  360. static Nlm_Int2 Nlm_GetLineHeight (Nlm_TexT t)
  361.  
  362. {
  363.   Nlm_TextTool  h;
  364.   Nlm_Int2      height;
  365.   TEPtr         tptr;
  366.  
  367.   h = Nlm_GetTextHandle (t);
  368.   HLock ((Handle) h);
  369.   tptr = (TEPtr) *((Handle) h);
  370.   height = tptr->lineHeight;
  371.   HUnlock ((Handle) h);
  372.   return height;
  373. }
  374.  
  375. static Nlm_Int2 Nlm_GetInsertionStartLine (Nlm_TexT t)
  376.  
  377. {
  378.   Nlm_TextTool  h;
  379.   Nlm_Int2      i;
  380.   short         *lines;
  381.   Nlm_Int2      numLines;
  382.   Nlm_Int2      startLoc;
  383.   TEPtr         tptr;
  384.  
  385.   h = Nlm_GetTextHandle (t);
  386.   HLock ((Handle) h);
  387.   tptr = (TEPtr) *((Handle) h);
  388.   numLines = tptr->nLines;
  389.   startLoc = tptr->selStart;
  390.   i = 0;
  391.   lines = &(tptr->lineStarts[0]);
  392.   while (i < numLines && startLoc > lines [i]) {
  393.     i++;
  394.   }
  395.   HUnlock ((Handle) h);
  396.   return i;
  397. }
  398.  
  399. static void Nlm_ScrollToInsertionPoint (Nlm_TexT t)
  400.  
  401. {
  402.   Nlm_BaR   sb;
  403.   Nlm_Int2  start;
  404.   Nlm_Int2  val;
  405.   Nlm_Int2  vis;
  406.  
  407.   sb = Nlm_GetTextVScrollBar (t);
  408.   if (sb != NULL) {
  409.     start = Nlm_GetInsertionStartLine (t);
  410.     vis = Nlm_GetVisLines (t);
  411.     val = Nlm_DoGetValue ((Nlm_GraphiC) sb);
  412.     if (val + vis < start) {
  413.       Nlm_DoSetValue ((Nlm_GraphiC) sb, start - (vis / 2), TRUE);
  414.     } else if (val > start) {
  415.       Nlm_DoSetValue ((Nlm_GraphiC) sb, start - (vis / 2), TRUE);
  416.     }
  417.   }
  418. }
  419.  
  420. static void Nlm_UpdateScrollBar (Nlm_TexT t)
  421.  
  422. {
  423.   Nlm_Int2  lines;
  424.   Nlm_Int2  newval;
  425.   Nlm_BaR   sb;
  426.   Nlm_Int2  start;
  427.   Nlm_Int2  vis;
  428.  
  429.   sb = Nlm_GetTextVScrollBar (t);
  430.   if (sb != NULL) {
  431.     lines = Nlm_GetTextLines (t);
  432.     start = Nlm_GetInsertionStartLine (t);
  433.     vis = Nlm_GetVisLines (t);
  434.     newval = 0;
  435.     if (lines > vis) {
  436.       newval = lines - vis;
  437.     }
  438.     Nlm_DoSetRange ((Nlm_GraphiC) sb, vis - 1, vis - 1, newval, FALSE);
  439.     if (Nlm_DoGetValue ((Nlm_GraphiC) sb) > newval) {
  440.       Nlm_DoSetValue ((Nlm_GraphiC) sb, newval, FALSE);
  441.     }
  442.   }
  443.   sb = Nlm_GetTextHScrollBar (t);
  444.   if (sb != NULL) {
  445.     Nlm_CorrectBarMax (sb, HSCROLL_POSITIONS);
  446.   }
  447. }
  448. #endif
  449.  
  450. static void Nlm_DeactivateBoxesInList (Nlm_TexT t)
  451.  
  452. {
  453.   Nlm_WindoW  w;
  454.  
  455.   w = Nlm_GetParentWindow ((Nlm_GraphiC) t);
  456.   Nlm_DoLoseFocus ((Nlm_GraphiC) w, (Nlm_GraphiC) t, FALSE);
  457. }
  458.  
  459. static void Nlm_DoTextSelect (Nlm_TexT t)
  460.  
  461. {
  462.   Nlm_TxtActnProc  sel;
  463.   Nlm_TextData     tdata;
  464.  
  465.   if (t != NULL) {
  466.     Nlm_GetTextData (t, &tdata);
  467.     sel = tdata.select;
  468.     if (sel != NULL && currentText != t) {
  469.       currentText = t;
  470.       sel (t);
  471.     }
  472.   }
  473.   currentText = t;
  474. }
  475.  
  476. static void Nlm_DoTextDeselect (Nlm_TexT t)
  477.  
  478. {
  479.   Nlm_TxtActnProc  desel;
  480.   Nlm_TextData     tdata;
  481.  
  482.   if (t != NULL) {
  483.     Nlm_GetTextData (t, &tdata);
  484.     desel = tdata.deselect;
  485.     if (desel != NULL) {
  486.       desel (t);
  487.     }
  488.   }
  489. }
  490.  
  491. static void Nlm_DoTabCallback (Nlm_TexT t)
  492.  
  493. {
  494.   Nlm_TextData  tdata;
  495.  
  496.   Nlm_GetTextData (t, &tdata);
  497.   if (tdata.tabnotify != NULL) {
  498.     tdata.tabnotify (t);
  499.   }
  500. }
  501.  
  502. static void Nlm_SelectAText (Nlm_TexT t, Nlm_Int2 begin, Nlm_Int2 end)
  503.  
  504. {
  505. #ifdef WIN_MAC
  506.   Nlm_TextTool  h;
  507.   TEPtr         hp;
  508.   short         len;
  509.   Nlm_Int4      selStart;
  510.   Nlm_Int4      selEnd;
  511.  
  512.   Nlm_DeactivateBoxesInList (t);
  513.   h = Nlm_GetTextHandle (t);
  514.   HLock ((Handle) h);
  515.   hp = (TEPtr) *((Handle) h);
  516.   len = hp->teLength;
  517.   HUnlock ((Handle) h);
  518.   selStart = begin;
  519.   selEnd = end;
  520.   if (selEnd > (Nlm_Int4) len) {
  521.     selEnd = (Nlm_Int4) len;
  522.   }
  523.   TESetSelect (selStart, selEnd, h);
  524.   Nlm_SetActive (t, TRUE);
  525.   Nlm_DoActivate ((Nlm_GraphiC) t, FALSE);
  526.   Nlm_DoTextSelect (t);
  527. #endif
  528. #ifdef WIN_MSWIN
  529.   Nlm_TextTool  h;
  530.  
  531.   h = Nlm_GetTextHandle (t);
  532.   Edit_SetSel (h, begin, end);
  533.   if (Nlm_Visible (t) && Nlm_AllParentsVisible (t)) {
  534.     SetFocus (h);
  535.     Nlm_DoTextSelect (t);
  536.   }
  537. #endif
  538. #ifdef WIN_MOTIF
  539.   Nlm_TextTool    h;
  540.   XmTextPosition  max;
  541.  
  542.   if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (t))) {
  543.     allowTextCallback = FALSE;
  544.     h = Nlm_GetTextHandle (t);
  545.     XmProcessTraversal (h, XmTRAVERSE_CURRENT);
  546.     max = XmTextGetLastPosition (h);
  547.     if (max > (XmTextPosition) end) {
  548.       max = (XmTextPosition) end;
  549.     }
  550.     XmTextSetSelection (h, (XmTextPosition) begin,
  551.                         (XmTextPosition) max, (Time) 0);
  552.     XmTextSetHighlight (h, (XmTextPosition) begin,
  553.                         (XmTextPosition) max, XmHIGHLIGHT_SELECTED);
  554.     allowTextCallback = TRUE;
  555.   }
  556.   Nlm_DoTextSelect (t);
  557. #endif
  558. }
  559.  
  560. extern void Nlm_TextSelectionRange (Nlm_TexT t, Nlm_Int2Ptr begin, Nlm_Int2Ptr end)
  561.  
  562. {
  563. #ifdef WIN_MAC
  564.   Nlm_TextTool  h;
  565.   TEPtr         hp;
  566.   Nlm_Int4      selStart;
  567.   Nlm_Int4      selEnd;
  568.  
  569.   if (t != NULL) {
  570.     h = Nlm_GetTextHandle (t);
  571.     HLock ((Handle) h);
  572.     hp = (TEPtr) *((Handle) h);
  573.     selStart = hp->selStart;
  574.     selEnd = hp->selEnd;
  575.     HUnlock ((Handle) h);
  576.     if (begin != NULL) {
  577.       *begin = (Nlm_Int2) selStart;
  578.     }
  579.     if (end != NULL) {
  580.       *end = (Nlm_Int2) selEnd;
  581.     }
  582.   }
  583. #endif
  584. #ifdef WIN_MSWIN
  585.   Nlm_TextTool  h;
  586.   DWORD         val;
  587.  
  588.   if (t != NULL) {
  589.     h = Nlm_GetTextHandle (t);
  590.     val = Edit_GetSel (h);
  591.     if (begin != NULL) {
  592.       *begin = (Nlm_Int2) (LOWORD (val));
  593.     }
  594.     if (end != NULL) {
  595.       *end = (Nlm_Int2) (HIWORD (val));
  596.     }
  597.   }
  598. #endif
  599. #ifdef WIN_MOTIF
  600.   Nlm_TextTool    h;
  601.   XmTextPosition  left;
  602.   XmTextPosition  right;
  603.  
  604.   if (t != NULL) {
  605.     if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (t))) {
  606.       h = Nlm_GetTextHandle (t);
  607.       XmTextGetSelectionPosition (h, &left, &right);
  608.       if (begin != NULL) {
  609.         *begin = (Nlm_Int2) left;
  610.       }
  611.       if (end != NULL) {
  612.         *end = (Nlm_Int2) right;
  613.       }
  614.     }
  615.   }
  616. #endif
  617. }
  618.  
  619. #ifdef WIN_MAC
  620. static Nlm_Boolean Nlm_DialogTextClick (Nlm_GraphiC t, Nlm_PoinT pt)
  621.  
  622. {
  623.   Nlm_TextTool   h;
  624.   Nlm_PointTool  ptool;
  625.   Nlm_RecT       r;
  626.   Nlm_Boolean    rsult;
  627.   Nlm_WindoW     w;
  628.  
  629.   rsult = FALSE;
  630.   Nlm_GetRect (t, &r);
  631.   if (Nlm_PtInRect (pt, &r)) {
  632.     Nlm_DeactivateBoxesInList ((Nlm_TexT) t);
  633.     h = Nlm_GetTextHandle ((Nlm_TexT) t);
  634.     Nlm_GetRect (t, &r);
  635.     Nlm_PoinTToPointTool (pt, &ptool);
  636.     TEClick (ptool, Nlm_shftKey, h);
  637.     Nlm_SetActive ((Nlm_TexT) t, TRUE);
  638.     w = Nlm_GetParentWindow (t);
  639.     Nlm_DoActivate (t, FALSE);
  640.     do {
  641.     } while (Nlm_MouseButton ());
  642.     Nlm_DoTextSelect ((Nlm_TexT) t);
  643.     rsult = TRUE;
  644.   }
  645.   return rsult;
  646. }
  647.  
  648. static Nlm_Boolean Nlm_ScrollTextClick (Nlm_GraphiC t, Nlm_PoinT pt)
  649.  
  650. {
  651.   Nlm_TextTool   h;
  652.   Nlm_BaR        hsb;
  653.   Nlm_PointTool  ptool;
  654.   Nlm_RecT       r;
  655.   Nlm_Boolean    rsult;
  656.   Nlm_BaR        vsb;
  657.   Nlm_WindoW     w;
  658.   Nlm_Boolean    wrap;
  659.  
  660.   rsult = FALSE;
  661.   Nlm_GetRect (t, &r);
  662.   wrap = Nlm_GetTextWrap ((Nlm_TexT) t);
  663.   r.right += Nlm_vScrollBarWidth;
  664.   if (! wrap) {
  665.     r.bottom += Nlm_hScrollBarHeight;
  666.   }
  667.   if (Nlm_PtInRect (pt, &r)) {
  668.     vsb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
  669.     hsb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
  670.     if (vsb != NULL && Nlm_DoClick ((Nlm_GraphiC) vsb, pt)) {
  671.     } else if (hsb != NULL && Nlm_DoClick ((Nlm_GraphiC) hsb, pt)) {
  672.     } else {
  673.       Nlm_DeactivateBoxesInList ((Nlm_TexT) t);
  674.       h = Nlm_GetTextHandle ((Nlm_TexT) t);
  675.       r.right -= Nlm_vScrollBarWidth;
  676.       if (! wrap) {
  677.         r.bottom -= Nlm_hScrollBarHeight;
  678.       }
  679.       Nlm_PoinTToPointTool (pt, &ptool);
  680.       TEClick (ptool, Nlm_shftKey, h);
  681.  
  682. #ifdef DCLAP
  683. /* only call the DoActivate if we were inactive -- it is a big time drag w/ TERecal ! */
  684. /* note that SetActive must be done before DoActivate call !! */
  685.           {
  686.           Nlm_Boolean   act;
  687.           act = Nlm_GetActive ((Nlm_TexT) t);
  688.       Nlm_SetActive ((Nlm_TexT) t, TRUE);
  689.       if (!act) Nlm_DoActivate (t, FALSE);
  690.       }
  691. #else
  692.       Nlm_SetActive ((Nlm_TexT) t, TRUE);
  693.       w = Nlm_GetParentWindow (t);
  694.       Nlm_DoActivate (t, FALSE);
  695. #endif
  696.  
  697.       do {
  698.       } while (Nlm_MouseButton ());
  699.       Nlm_DoTextSelect ((Nlm_TexT) t);
  700.       rsult = TRUE;
  701.     }
  702.   }
  703.   return rsult;
  704. }
  705.  
  706. static Nlm_Boolean Nlm_TextKey (Nlm_GraphiC t, Nlm_Char ch)
  707.  
  708. {
  709.   Nlm_Boolean   act;
  710.   Nlm_TextTool  h;
  711.   Nlm_Boolean   rsult;
  712.  
  713.   rsult = FALSE;
  714.   act = Nlm_GetActive ((Nlm_TexT) t);
  715.   if (act && ! Nlm_cmmdKey) {
  716.     if (ch != '\0') {
  717.       h = Nlm_GetTextHandle ((Nlm_TexT) t);
  718.       Nlm_ScrollToInsertionPoint ((Nlm_TexT) t);
  719.       TEKey (ch, h);
  720.       TECalText (h);
  721.       Nlm_UpdateScrollBar ((Nlm_TexT) t);
  722.       Nlm_ScrollToInsertionPoint ((Nlm_TexT) t);
  723.       Nlm_DoAction (t);
  724.       Nlm_SetChanged ((Nlm_TexT) t, TRUE);
  725.       rsult = TRUE;
  726.     }
  727.   }
  728.   return rsult;
  729. }
  730.  
  731. static Nlm_Boolean Nlm_DialogKey (Nlm_GraphiC t, Nlm_Char ch)
  732.  
  733. {
  734.   Nlm_Boolean  act;
  735.   Nlm_Boolean  rsult;
  736.  
  737.   rsult = FALSE;
  738.   act = Nlm_GetActive ((Nlm_TexT) t);
  739.   if (act && ! Nlm_cmmdKey) {
  740.     if (ch == '\t' && Nlm_IsHiddenText ((Nlm_TexT) t)) {
  741.       Nlm_DoTabCallback ((Nlm_TexT) t);
  742.     } else if (ch == '\t') {
  743.       Nlm_DoSendFocus (t, ch);
  744.       rsult = TRUE;
  745.     } else if (ch == '\n'  || ch == '\r' || ch == '\3') {
  746.     } else if (ch != '\0') {
  747.       rsult = Nlm_TextKey (t, ch);
  748.     }
  749.   }
  750.   return rsult;
  751. }
  752.  
  753. static Nlm_Boolean Nlm_PasswordKey (Nlm_GraphiC t, Nlm_Char ch)
  754.  
  755. {
  756.   Nlm_Boolean   act;
  757.   Nlm_TextTool  h;
  758.   TEPtr         hp;
  759.   Nlm_Int2      len;
  760.   Nlm_Char      password [32];
  761.   Nlm_RecT      r;
  762.   Nlm_RectTool  rtool;
  763.   Nlm_Boolean   rsult;
  764.   Nlm_Int4      selStart;
  765.   Nlm_Int4      selEnd;
  766.  
  767.   rsult = FALSE;
  768.   act = Nlm_GetActive ((Nlm_TexT) t);
  769.   if (act && ! Nlm_cmmdKey) {
  770.     if (ch == '\t') {
  771.       Nlm_DoSendFocus (t, ch);
  772.       rsult = TRUE;
  773.     } else if (ch == '\n'  || ch == '\r' || ch == '\3') {
  774.     } else if (ch == '\b') {
  775.       rsult = TRUE;
  776.       Nlm_SetPassword ((Nlm_TexT) t, "");
  777.       h = Nlm_GetTextHandle ((Nlm_TexT) t);
  778.       selStart = 0;
  779.       HLock ((Handle) h);
  780.       hp = (TEPtr) *((Handle) h);
  781.       selEnd = hp->teLength;
  782.       HUnlock ((Handle) h);
  783.       TESetSelect (selStart, selEnd, h);
  784.       TEDelete (h);
  785.       Nlm_GetRect (t, &r);
  786.       if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  787.         Nlm_InsetRect (&r, 2, 2);
  788.         Nlm_EraseRect (&r);
  789.         Nlm_RecTToRectTool (&r, &rtool);
  790.         TEUpdate (&rtool, h);
  791.       }
  792.     } else if (ch != '\0') {
  793.       Nlm_GetPassword ((Nlm_TexT) t, password, sizeof (password));
  794.       len = (Nlm_Int2) Nlm_StringLen (password);
  795.       if (len < sizeof (password) - 2) {
  796.         password [len] = ch;
  797.         password [len + 1] = '\0';
  798.       }
  799.       Nlm_SetPassword ((Nlm_TexT) t, password);
  800.       rsult = Nlm_TextKey (t, '*');
  801.     }
  802.   }
  803.   return rsult;
  804. }
  805.  
  806. static void Nlm_DrawDialogText (Nlm_GraphiC t)
  807.  
  808. {
  809.   Nlm_TextTool  h;
  810.   Nlm_RecT      r;
  811.   Nlm_RectTool  ttool;
  812.  
  813.   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  814.     Nlm_GetRect (t, &r);
  815.     if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
  816.       Nlm_EraseRect (&r);
  817.       if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t)) {
  818.         h = Nlm_GetTextHandle ((Nlm_TexT) t);
  819.         if (Nlm_GetActive ((Nlm_TexT) t)) {
  820.           TEActivate (h);
  821.         } else {
  822.           TEDeactivate (h);
  823.         }
  824.         TECalText (h);
  825.         Nlm_InsetRect (&r, 2, 2);
  826.         Nlm_RecTToRectTool (&r, &ttool);
  827.         SelectDialogFont();
  828.         TEUpdate (&ttool, h);
  829.         Nlm_InsetRect (&r, -2, -2);
  830.         Nlm_FrameRect (&r);
  831.       } else {
  832. #ifdef DCLAP
  833.     /* dgg -- we want to show this text, just not edit it... */
  834.         h = Nlm_GetTextHandle ((Nlm_TexT) t);
  835.             TEDeactivate (h);
  836.         TECalText (h);
  837.         Nlm_InsetRect (&r, 2, 2);
  838.         Nlm_RecTToRectTool (&r, &ttool);
  839.                 SelectDialogFont();
  840.         TEUpdate (&ttool, h);
  841.         Nlm_InsetRect (&r, -2, -2);
  842. #endif
  843.         Nlm_Dotted ();
  844.         Nlm_FrameRect (&r);
  845.         Nlm_Solid ();
  846.       }
  847.     }
  848.   }
  849. }
  850.  
  851. static void Nlm_DrawHiddenText (Nlm_GraphiC t)
  852.  
  853. {
  854.   Nlm_TextTool  h;
  855.   Nlm_RecT      r;
  856.   Nlm_RectTool  ttool;
  857.  
  858.   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  859.     Nlm_GetRect (t, &r);
  860.     if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
  861.       Nlm_EraseRect (&r);
  862.       if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t)) {
  863.         h = Nlm_GetTextHandle ((Nlm_TexT) t);
  864.         if (Nlm_GetActive ((Nlm_TexT) t)) {
  865.           TEActivate (h);
  866.         } else {
  867.           TEDeactivate (h);
  868.         }
  869.         TECalText (h);
  870.         Nlm_RecTToRectTool (&r, &ttool);
  871.                 SelectDialogFont();
  872.         TEUpdate (&ttool, h);
  873.       }
  874.     }
  875.   }
  876. }
  877.  
  878. static void Nlm_DrawScrollText (Nlm_GraphiC t)
  879.  
  880. {
  881.   Nlm_TextTool  h;
  882.   Nlm_BaR       hsb;
  883.   Nlm_RecT      r;
  884.   Nlm_RectTool  rtool;
  885.   Nlm_BaR       vsb;
  886.   Nlm_Boolean   wrap;
  887.  
  888.   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  889.     Nlm_GetRect (t, &r);
  890.     r.right += Nlm_vScrollBarWidth;
  891.     wrap = Nlm_GetTextWrap ((Nlm_TexT) t);
  892.     if (! wrap) {
  893.       r.bottom += Nlm_hScrollBarHeight;
  894.     }
  895.     if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
  896.       if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t)) {
  897.         Nlm_FrameRect (&r);
  898.         vsb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
  899.         if (vsb != NULL) {
  900.           Nlm_DoDraw ((Nlm_GraphiC) vsb);
  901.         }
  902.         hsb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
  903.         if (hsb != NULL) {
  904.           Nlm_DoDraw ((Nlm_GraphiC) hsb);
  905.         }
  906.         r.right -= Nlm_vScrollBarWidth;
  907.         if (! wrap) {
  908.           r.bottom -= Nlm_hScrollBarHeight;
  909.         }
  910.         Nlm_InsetRect (&r, 4, 2);
  911.         r.bottom = r.top + Nlm_GetVisLines ((Nlm_TexT) t) * Nlm_GetFontHeight ((Nlm_TexT) t);
  912.         h = Nlm_GetTextHandle ((Nlm_TexT) t);
  913.         if (Nlm_GetActive ((Nlm_TexT) t)) {
  914.           TEActivate (h);
  915.         } else {
  916.           TEDeactivate (h);
  917.         }
  918.         TECalText (h);
  919.         Nlm_RecTToRectTool (&r, &rtool);
  920.                 SelectDialogFont();
  921.         TEUpdate (&rtool, h);
  922.       } else {
  923. #ifdef DCLAP
  924.          /* dgg -- we want to see text, just not edit it */
  925.          /* this may need some work */
  926.         h = Nlm_GetTextHandle ((Nlm_TexT) t);
  927.         TEDeactivate (h);
  928.         TECalText (h);
  929.         Nlm_RecTToRectTool (&r, &rtool);
  930.                 SelectDialogFont();
  931.         TEUpdate (&rtool, h);
  932. #else
  933.         Nlm_EraseRect (&r);
  934. #endif
  935.         Nlm_Dotted ();
  936.         Nlm_FrameRect (&r);
  937.         Nlm_Solid ();
  938.       }
  939.     }
  940.   }
  941. }
  942.  
  943. static Nlm_Boolean Nlm_IdleText (Nlm_GraphiC t, Nlm_PoinT pt)
  944.  
  945. {  Nlm_TextTool  h;
  946.  
  947.   if (Nlm_GetVisible (t) && Nlm_GetEnabled (t) && Nlm_GetActive ((Nlm_TexT) t)) {
  948.     h = Nlm_GetTextHandle ((Nlm_TexT) t);
  949.     TEIdle (h);
  950.   }
  951.   return TRUE;
  952. }
  953. #endif
  954.  
  955. #ifdef WIN_MSWIN
  956. static Nlm_Boolean Nlm_DialogTextCommand (Nlm_GraphiC t)
  957.  
  958. {
  959.   if (Nlm_currentCode == EN_CHANGE) {
  960.     Nlm_DoAction (t);
  961.   }
  962.   return TRUE;
  963. }
  964.  
  965. static Nlm_Boolean Nlm_PasswordTextCommand (Nlm_GraphiC t)
  966.  
  967. {
  968.   Nlm_TextTool  h;
  969.   Nlm_Char      password [32];
  970.  
  971.   if (Nlm_currentCode == EN_CHANGE) {
  972.     h = Nlm_GetTextHandle ((Nlm_TexT) t);
  973.     GetWindowText (h, password, sizeof (password) - 2);
  974.     Nlm_SetPassword ((Nlm_TexT) t, password);
  975.     Nlm_DoAction (t);
  976.   }
  977.   return TRUE;
  978. }
  979.  
  980. static Nlm_Boolean Nlm_ScrollTextCommand (Nlm_GraphiC t)
  981.  
  982. {
  983.   if (Nlm_currentCode == EN_CHANGE) {
  984.     Nlm_DoAction (t);
  985.   }
  986.   return TRUE;
  987. }
  988. #endif
  989.  
  990. #ifdef WIN_MOTIF
  991. #endif
  992.  
  993. static void Nlm_ShowText (Nlm_GraphiC t, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  994.  
  995. {
  996.   Nlm_TextTool  h;
  997.   Nlm_WindoW    tempPort;
  998.  
  999.   if (setFlag) {
  1000.     Nlm_SetVisible (t, TRUE);
  1001.   }
  1002.   if (Nlm_GetVisible (t) && Nlm_AllParentsButWindowVisible (t)) {
  1003.     tempPort = Nlm_SavePortIfNeeded (t, savePort);
  1004.     h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1005. #ifdef WIN_MAC
  1006.     Nlm_DoDraw (t);
  1007. #endif
  1008. #ifdef WIN_MSWIN
  1009.     ShowWindow (h, SW_SHOW);
  1010.     UpdateWindow (h);
  1011. #endif
  1012. #ifdef WIN_MOTIF
  1013.     XtManageChild (h);
  1014. #endif
  1015.     Nlm_RestorePort (tempPort);
  1016.   }
  1017. }
  1018.  
  1019. static void Nlm_ShowScrollText (Nlm_GraphiC t, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1020.  
  1021. {
  1022.   Nlm_TextTool  h;
  1023.   Nlm_BaR       sb;
  1024.   Nlm_WindoW    tempPort;
  1025.  
  1026.   if (setFlag) {
  1027.     Nlm_SetVisible (t, TRUE);
  1028.   }
  1029.   if (Nlm_GetVisible (t) && Nlm_AllParentsButWindowVisible (t)) {
  1030.     tempPort = Nlm_SavePortIfNeeded (t, savePort);
  1031.     sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
  1032.     if (sb != NULL) {
  1033.       Nlm_DoShow ((Nlm_GraphiC) sb, TRUE, FALSE);
  1034.     }
  1035.     sb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
  1036.     if (sb != NULL) {
  1037.       Nlm_DoShow ((Nlm_GraphiC) sb, TRUE, FALSE);
  1038.     }
  1039.     h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1040. #ifdef WIN_MAC
  1041.     Nlm_DoDraw (t);
  1042. #endif
  1043. #ifdef WIN_MSWIN
  1044.     ShowWindow (h, SW_SHOW);
  1045.     UpdateWindow (h);
  1046. #endif
  1047. #ifdef WIN_MOTIF
  1048.     XtManageChild (XtParent (h));
  1049. #endif
  1050.     Nlm_RestorePort (tempPort);
  1051.   }
  1052. }
  1053.  
  1054. static void Nlm_HideText (Nlm_GraphiC t, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1055.  
  1056. {
  1057.   Nlm_TextTool  h;
  1058.   Nlm_WindoW    tempPort;
  1059. #ifdef WIN_MAC
  1060.   Nlm_RecT      r;
  1061. #endif
  1062.  
  1063.   if (setFlag) {
  1064.     Nlm_SetVisible (t, FALSE);
  1065.   }
  1066.   tempPort = Nlm_SavePortIfNeeded (t, savePort);
  1067.   h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1068. #ifdef WIN_MAC
  1069.   if (Nlm_GetAllParentsVisible (t)) {
  1070.     Nlm_GetRect (t, &r);
  1071.     Nlm_InsetRect (&r, -1, -1);
  1072.     Nlm_EraseRect (&r);
  1073.     Nlm_ValidRect (&r);
  1074.   }
  1075. #endif
  1076. #ifdef WIN_MSWIN
  1077.   ShowWindow (h, SW_HIDE);
  1078.   UpdateWindow (h);
  1079. #endif
  1080. #ifdef WIN_MOTIF
  1081.   XtUnmanageChild (h);
  1082. #endif
  1083.   Nlm_RestorePort (tempPort);
  1084. }
  1085.  
  1086. static void Nlm_HideScrollText (Nlm_GraphiC t, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1087.  
  1088. {
  1089.   Nlm_TextTool  h;
  1090.   Nlm_BaR       sb;
  1091.   Nlm_WindoW    tempPort;
  1092. #ifdef WIN_MAC
  1093.   Nlm_RecT      r;
  1094. #endif
  1095.  
  1096.   if (setFlag) {
  1097.     Nlm_SetVisible (t, FALSE);
  1098.   }
  1099.   tempPort = Nlm_SavePortIfNeeded (t, savePort);
  1100.   sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
  1101.   if (sb != NULL) {
  1102.     Nlm_DoHide ((Nlm_GraphiC) sb, TRUE, FALSE);
  1103.   }
  1104.   sb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
  1105.   if (sb != NULL) {
  1106.     Nlm_DoHide ((Nlm_GraphiC) sb, TRUE, FALSE);
  1107.   }
  1108.   h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1109. #ifdef WIN_MAC
  1110.   if (Nlm_GetAllParentsVisible (t)) {
  1111.     Nlm_GetRect (t, &r);
  1112.     r.right += Nlm_vScrollBarWidth;
  1113.     Nlm_InsetRect (&r, -1, -1);
  1114.     Nlm_EraseRect (&r);
  1115.     Nlm_ValidRect (&r);
  1116.   }
  1117. #endif
  1118. #ifdef WIN_MSWIN
  1119.   ShowWindow (h, SW_HIDE);
  1120.   UpdateWindow (h);
  1121. #endif
  1122. #ifdef WIN_MOTIF
  1123.   XtUnmanageChild (XtParent (h));
  1124. #endif
  1125.   Nlm_RestorePort (tempPort);
  1126. }
  1127.  
  1128. static void Nlm_EnableText (Nlm_GraphiC t, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1129.  
  1130. {
  1131.   Nlm_TextTool  h;
  1132.   Nlm_BaR       sb;
  1133.   Nlm_WindoW    tempPort;
  1134.  
  1135.   if (setFlag) {
  1136.     Nlm_SetEnabled (t, TRUE);
  1137.   }
  1138.   if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t)) {
  1139.     tempPort = Nlm_SavePortIfNeeded (t, savePort);
  1140.     sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
  1141.     if (sb != NULL) {
  1142.       Nlm_DoEnable ((Nlm_GraphiC) sb, TRUE, FALSE);
  1143.     }
  1144.     sb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
  1145.     if (sb != NULL) {
  1146.       Nlm_DoEnable ((Nlm_GraphiC) sb, TRUE, FALSE);
  1147.     }
  1148.     h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1149. #ifdef WIN_MAC
  1150.     if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  1151.       Nlm_DoDraw (t);
  1152.     }
  1153. #endif
  1154. #ifdef WIN_MSWIN
  1155.     EnableWindow (h, TRUE);
  1156. #endif
  1157. #ifdef WIN_MOTIF
  1158.     XtVaSetValues (h, XmNsensitive, TRUE, NULL);
  1159. #endif
  1160.     Nlm_RestorePort (tempPort);
  1161.   }
  1162. }
  1163.  
  1164. static void Nlm_DisableText (Nlm_GraphiC t, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1165.  
  1166. {
  1167.   Nlm_TextTool  h;
  1168.   Nlm_BaR       sb;
  1169.   Nlm_WindoW    tempPort;
  1170.  
  1171.   if (setFlag) {
  1172.     Nlm_SetEnabled (t, FALSE);
  1173.   }
  1174.   tempPort = Nlm_SavePortIfNeeded (t, savePort);
  1175.   sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
  1176.   if (sb != NULL) {
  1177.     Nlm_DoDisable ((Nlm_GraphiC) sb, TRUE, FALSE);
  1178.   }
  1179.   sb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
  1180.   if (sb != NULL) {
  1181.     Nlm_DoDisable ((Nlm_GraphiC) sb, TRUE, FALSE);
  1182.   }
  1183.   h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1184. #ifdef WIN_MAC
  1185.   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  1186.     Nlm_DoDraw (t);
  1187.   }
  1188. #endif
  1189. #ifdef WIN_MSWIN
  1190.   EnableWindow (h, FALSE);
  1191. #endif
  1192. #ifdef WIN_MOTIF
  1193.   XtVaSetValues (h, XmNsensitive, FALSE, NULL);
  1194. #endif
  1195.   Nlm_RestorePort (tempPort);
  1196. }
  1197.  
  1198. static void Nlm_ActivateText (Nlm_GraphiC t, Nlm_Boolean savePort)
  1199.  
  1200. {
  1201. #ifdef WIN_MAC
  1202.   Nlm_TextTool  h;
  1203.   Nlm_RecT      r;
  1204.   Nlm_RectTool  rtool;
  1205. #endif
  1206.  
  1207.   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  1208.     if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t) && Nlm_GetActive ((Nlm_TexT) t)) {
  1209. #ifdef WIN_MAC
  1210.       h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1211.       Nlm_GetRect (t, &r);
  1212.       Nlm_InsetRect (&r, 2, 2);
  1213.       TEActivate (h);
  1214.       TECalText (h);
  1215.       Nlm_RecTToRectTool (&r, &rtool);
  1216.       TEUpdate (&rtool, h);
  1217. #endif
  1218. #ifdef WIN_MSWIN
  1219.       if (t != NULL) {
  1220.         Nlm_SelectAText ((Nlm_TexT) t, 0, 32767);
  1221.       }
  1222. #endif
  1223. #ifdef WIN_MOTIF
  1224.       if (t != NULL) {
  1225.         Nlm_SelectAText ((Nlm_TexT) t, 0, 32767);
  1226.       }
  1227. #endif
  1228.     }
  1229.   }
  1230. }
  1231.  
  1232. static void Nlm_ActivateHiddenText (Nlm_GraphiC t, Nlm_Boolean savePort)
  1233.  
  1234. {
  1235. #ifdef WIN_MAC
  1236.   Nlm_TextTool  h;
  1237.   Nlm_RecT      r;
  1238.   Nlm_RectTool  rtool;
  1239. #endif
  1240. #ifdef WIN_MSWIN
  1241.   Nlm_TextTool  h;
  1242. #endif
  1243.  
  1244.   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  1245.     if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t) && Nlm_GetActive ((Nlm_TexT) t)) {
  1246. #ifdef WIN_MAC
  1247.       h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1248.       Nlm_GetRect (t, &r);
  1249.       TEActivate (h);
  1250.       TECalText (h);
  1251.       Nlm_RecTToRectTool (&r, &rtool);
  1252.       TEUpdate (&rtool, h);
  1253. #endif
  1254. #ifdef WIN_MSWIN
  1255.       h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1256.       if (t != NULL && h != NULL) {
  1257.         if (Nlm_Visible (t) && Nlm_AllParentsVisible (t)) {
  1258.           SetFocus (h);
  1259.         }
  1260.       }
  1261. #endif
  1262.     }
  1263.   }
  1264. }
  1265.  
  1266. static void Nlm_ActivateScrollText (Nlm_GraphiC t, Nlm_Boolean savePort)
  1267.  
  1268. {
  1269.   Nlm_TextTool  h;
  1270. #ifdef WIN_MAC
  1271.   Nlm_RecT      r;
  1272.   Nlm_RectTool  rtool;
  1273. #endif
  1274.  
  1275.   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  1276.     if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t) && Nlm_GetActive ((Nlm_TexT) t)) {
  1277. #ifdef WIN_MAC
  1278.       h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1279.       Nlm_GetRect (t, &r);
  1280.       Nlm_InsetRect (&r, 4, 2);
  1281.       r.bottom = r.top + Nlm_GetVisLines ((Nlm_TexT) t) * Nlm_GetFontHeight ((Nlm_TexT) t);
  1282.       TEActivate (h);
  1283.       TECalText (h);
  1284.       Nlm_RecTToRectTool (&r, &rtool);
  1285.       TEUpdate (&rtool, h);
  1286. #endif
  1287. #ifdef WIN_MSWIN
  1288.       h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1289.       if (t != NULL && h != NULL) {
  1290.         if (Nlm_Visible (t) && Nlm_AllParentsVisible (t)) {
  1291.           SetFocus (h);
  1292.         }
  1293.       }
  1294. #endif
  1295.     }
  1296.   }
  1297. }
  1298.  
  1299. static void Nlm_DeactivateText (Nlm_GraphiC t, Nlm_Boolean savePort)
  1300.  
  1301. {
  1302. #ifdef WIN_MAC
  1303.   Nlm_TextTool  h;
  1304.   Nlm_RecT      r;
  1305.   Nlm_RectTool  rtool;
  1306.  
  1307.   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  1308.     if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t)) {
  1309.       h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1310.       Nlm_GetRect (t, &r);
  1311.       Nlm_InsetRect (&r, 2, 2);
  1312.       TEDeactivate (h);
  1313.       TECalText (h);
  1314.       Nlm_RecTToRectTool (&r, &rtool);
  1315.       TEUpdate (&rtool, h);
  1316.     }
  1317.   }
  1318. #endif
  1319. }
  1320.  
  1321. static void Nlm_DeactivateScrollText (Nlm_GraphiC t, Nlm_Boolean savePort)
  1322.  
  1323. {
  1324. #ifdef WIN_MAC
  1325.   Nlm_TextTool  h;
  1326.   Nlm_RecT      r;
  1327.   Nlm_RectTool  rtool;
  1328.  
  1329.   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  1330.     if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t)) {
  1331.       h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1332.       Nlm_GetRect (t, &r);
  1333.       Nlm_InsetRect (&r, 4, 2);
  1334.       r.bottom = r.top + Nlm_GetVisLines ((Nlm_TexT) t) * Nlm_GetFontHeight ((Nlm_TexT) t);
  1335.       TEDeactivate (h);
  1336.       TECalText (h);
  1337.       Nlm_RecTToRectTool (&r, &rtool);
  1338.       TEUpdate (&rtool, h);
  1339.     }
  1340.   }
  1341. #endif
  1342. }
  1343.  
  1344. static void Nlm_ResetText (Nlm_GraphiC t, Nlm_Boolean savePort)
  1345.  
  1346. {
  1347. #ifdef WIN_MAC
  1348.   Nlm_Int2      delta;
  1349.   Nlm_TextTool  h;
  1350.   Nlm_Int2      height;
  1351.   Nlm_BaR       sb;
  1352.   Nlm_WindoW    tempPort;
  1353.   Nlm_Int2      width;
  1354.  
  1355.   tempPort = Nlm_SavePortIfNeeded (t, savePort);
  1356.   h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1357.   TESetSelect (0, 32767, h);
  1358.   TEDelete (h);
  1359.   sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
  1360.   if (sb != NULL) {
  1361.     delta = Nlm_DoGetValue ((Nlm_GraphiC) sb);
  1362.     height = Nlm_GetLineHeight ((Nlm_TexT) t);
  1363.     TEScroll (0, delta * height, h);
  1364.     Nlm_DoReset ((Nlm_GraphiC) sb, FALSE);
  1365.   }
  1366.   sb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
  1367.   if (sb != NULL) {
  1368.     delta = Nlm_DoGetValue ((Nlm_GraphiC) sb);
  1369.     width = Nlm_stdCharWidth;
  1370.     TEScroll (delta * width, 0, h);
  1371.     Nlm_DoReset ((Nlm_GraphiC) sb, FALSE);
  1372.   }
  1373.   Nlm_RestorePort (tempPort);
  1374. #endif
  1375. #ifdef WIN_MSWIN
  1376.   Nlm_TextTool  h;
  1377.  
  1378.   h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1379.   SetWindowText (h, "");
  1380. #endif
  1381. #ifdef WIN_MOTIF
  1382.   Nlm_TextTool  h;
  1383.   Nlm_Char      str [5];
  1384.  
  1385.   h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1386.   allowTextCallback = FALSE;
  1387.   str [0] = '\0';
  1388.   XmTextSetString (h, str);
  1389.   XmTextShowPosition (h, 0);
  1390.   allowTextCallback = TRUE;
  1391. #endif
  1392. }
  1393.  
  1394. static void Nlm_RemoveText (Nlm_GraphiC t, Nlm_Boolean savePort)
  1395.  
  1396. {
  1397.   Nlm_TextTool  h;
  1398.   Nlm_WindoW    tempPort;
  1399. #ifdef WIN_MAC
  1400.   Nlm_BaR       sb;
  1401. #endif
  1402.  
  1403.   tempPort = Nlm_SavePortIfNeeded (t, savePort);
  1404.   if (currentText == (Nlm_TexT) t) {
  1405.     currentText = NULL;
  1406.   }
  1407.   h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1408. #ifdef WIN_MAC
  1409.   TEDispose (h);
  1410.   sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
  1411.   if (sb != NULL) {
  1412.     Nlm_DoRemove ((Nlm_GraphiC) sb, FALSE);
  1413.   }
  1414.   sb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
  1415.   if (sb != NULL) {
  1416.     Nlm_DoRemove ((Nlm_GraphiC) sb, FALSE);
  1417.   }
  1418. #endif
  1419. #ifdef WIN_MSWIN
  1420.   RemoveProp (h, (LPSTR) "Nlm_VibrantProp");
  1421.   DestroyWindow (h);
  1422. #endif
  1423. #ifdef WIN_MOTIF
  1424.   XtDestroyWidget (h);
  1425. #endif
  1426.   Nlm_RemoveLink (t);
  1427.   recentText = NULL;
  1428.   Nlm_RestorePort (tempPort);
  1429. }
  1430.  
  1431. static void Nlm_TextSelectProc (Nlm_GraphiC t, Nlm_Boolean savePort)
  1432.  
  1433. {
  1434. #ifdef WIN_MAC
  1435.   Nlm_Int2      end;
  1436.   Nlm_TextTool  h;
  1437.   TEPtr         hp;
  1438.   Nlm_WindoW    tempPort;
  1439.  
  1440.   if (t != NULL) {
  1441.     tempPort = Nlm_SavePortIfNeeded (t, savePort);
  1442.     h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1443.     HLock ((Handle) h);
  1444.     hp = (TEPtr) *((Handle) h);
  1445.     end = hp->teLength;
  1446.     HUnlock ((Handle) h);
  1447.     Nlm_SelectAText ((Nlm_TexT) t, 0, end);
  1448.     Nlm_RestorePort (tempPort);
  1449.   }
  1450. #endif
  1451. #ifdef WIN_MSWIN
  1452.   Nlm_WindoW  tempPort;
  1453.  
  1454.   if (t != NULL) {
  1455.     tempPort = Nlm_SavePortIfNeeded (t, savePort);
  1456.     Nlm_SelectAText ((Nlm_TexT) t, 0, 32767);
  1457.     Nlm_RestorePort (tempPort);
  1458.   }
  1459. #endif
  1460. #ifdef WIN_MOTIF
  1461.   Nlm_WindoW  tempPort;
  1462.  
  1463.   if (t != NULL) {
  1464.     tempPort = Nlm_SavePortIfNeeded (t, savePort);
  1465.     Nlm_SelectAText ((Nlm_TexT) t, 0, 32767);
  1466.     Nlm_RestorePort (tempPort);
  1467.   }
  1468. #endif
  1469. }
  1470.  
  1471. extern Nlm_sizeT Nlm_TextLength (Nlm_TexT t)
  1472.  
  1473. {
  1474.   Nlm_TextTool  h;
  1475.   Nlm_sizeT        len;
  1476. #ifdef WIN_MAC
  1477.   TEPtr         hp;
  1478. #endif
  1479. #ifdef WIN_MOTIF
  1480.   Nlm_CharPtr   ptr;
  1481. #endif
  1482.  
  1483.   len = 0;
  1484.   if (t != NULL) {
  1485.     h = Nlm_GetTextHandle (t);
  1486. #ifdef WIN_MAC
  1487.     HLock ((Handle) h);
  1488.     hp = (TEPtr) *((Handle) h);
  1489.     len = hp->teLength;
  1490.     HUnlock ((Handle) h);
  1491. #endif
  1492. #ifdef WIN_MSWIN
  1493.     len = (Nlm_sizeT) GetWindowTextLength (h);
  1494. #endif
  1495. #ifdef WIN_MOTIF
  1496.     ptr = XmTextGetString (h);
  1497.     len = Nlm_StringLen (ptr);
  1498.     XtFree (ptr);
  1499. #endif
  1500.   }
  1501.   return len;
  1502. }
  1503.  
  1504. extern void Nlm_SelectText (Nlm_TexT t, Nlm_Int2 begin, Nlm_Int2 end)
  1505.  
  1506. {
  1507.   Nlm_WindoW  tempPort;
  1508.  
  1509.   if (t != NULL) {
  1510.     tempPort = Nlm_SavePortIfNeeded ((Nlm_GraphiC) t, TRUE);
  1511.     begin = MAX (begin, 0);
  1512.     end = MAX (end, 0);
  1513.     Nlm_SelectAText ((Nlm_TexT) t, begin, end);
  1514.     Nlm_RestorePort (tempPort);
  1515.   }
  1516. }
  1517.  
  1518. static void Nlm_SetDialogText (Nlm_GraphiC t, Nlm_Int2 item,
  1519.                                Nlm_CharPtr title, Nlm_Boolean savePort)
  1520.  
  1521. {
  1522.   Nlm_TextTool  h;
  1523.   Nlm_WindoW    tempPort;
  1524. #ifdef WIN_MAC
  1525.   TEPtr         hp;
  1526.   Nlm_Uint4     len;
  1527.   Nlm_RecT      r;
  1528.   Nlm_Int4      selStart;
  1529.   Nlm_Int4      selEnd;
  1530. #endif
  1531. #ifdef WIN_MOTIF
  1532.   Nlm_CharPtr   str;
  1533. #endif
  1534.  
  1535.   tempPort = Nlm_SavePortIfNeeded (t, savePort);
  1536.   h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1537. #ifdef WIN_MAC
  1538.   len = Nlm_StringLen (title);
  1539.   if (len > 0) {
  1540.     TESetText (title, len, h);
  1541.     TECalText (h);
  1542.   } else {
  1543.     selStart = 0;
  1544.     HLock ((Handle) h);
  1545.     hp = (TEPtr) *((Handle) h);
  1546.     selEnd = hp->teLength;
  1547.     HUnlock ((Handle) h);
  1548.     TESetSelect (selStart, selEnd, h);
  1549.     TEDelete (h);
  1550.   }
  1551.   Nlm_GetRect (t, &r);
  1552.   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  1553.     Nlm_InsetRect (&r, 1, 1);
  1554.     Nlm_InvalRect (&r);
  1555.   }
  1556.   Nlm_UpdateScrollBar ((Nlm_TexT) t);
  1557. #endif
  1558. #ifdef WIN_MSWIN
  1559.   SetWindowText (h, title);
  1560. #endif
  1561. #ifdef WIN_MOTIF
  1562.   allowTextCallback = FALSE;
  1563.   str = Nlm_StringSave (title);
  1564.   XmTextSetString (h, str);
  1565.   Nlm_MemFree (str);
  1566.   XmTextShowPosition (h, 0);
  1567.   allowTextCallback = TRUE;
  1568. #endif
  1569.   Nlm_RestorePort (tempPort);
  1570. }
  1571.  
  1572. static void Nlm_SetPasswordText (Nlm_GraphiC t, Nlm_Int2 item,
  1573.                                  Nlm_CharPtr title, Nlm_Boolean savePort)
  1574.  
  1575. {
  1576.   Nlm_TextTool  h;
  1577.   Nlm_Int2      leng;
  1578.   Nlm_Char      stars [32];
  1579.   Nlm_WindoW    tempPort;
  1580. #ifdef WIN_MAC
  1581.   TEPtr         hp;
  1582.   Nlm_Uint4     len;
  1583.   Nlm_RecT      r;
  1584.   Nlm_Int4      selStart;
  1585.   Nlm_Int4      selEnd;
  1586. #endif
  1587. #ifdef WIN_MOTIF
  1588.   Nlm_Char      bspace [5];
  1589.   Nlm_CharPtr   str;
  1590. #endif
  1591.  
  1592.   tempPort = Nlm_SavePortIfNeeded (t, savePort);
  1593.   h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1594.   Nlm_SetPassword ((Nlm_TexT) t, title);
  1595.   Nlm_StringCpy (stars, "******************************");
  1596.   leng = (Nlm_Int2) Nlm_StringLen (title);
  1597.   if (leng < 32) {
  1598.     stars [leng] = '\0';
  1599.   }
  1600. #ifdef WIN_MAC
  1601.   len = Nlm_StringLen (stars);
  1602.   if (len > 0) {
  1603.     TESetText (stars, len, h);
  1604.     TECalText (h);
  1605.   } else {
  1606.     selStart = 0;
  1607.     HLock ((Handle) h);
  1608.     hp = (TEPtr) *((Handle) h);
  1609.     selEnd = hp->teLength;
  1610.     HUnlock ((Handle) h);
  1611.     TESetSelect (selStart, selEnd, h);
  1612.     TEDelete (h);
  1613.   }
  1614.   Nlm_GetRect (t, &r);
  1615.   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  1616.     Nlm_InsetRect (&r, 1, 1);
  1617.     Nlm_InvalRect (&r);
  1618.   }
  1619.   Nlm_UpdateScrollBar ((Nlm_TexT) t);
  1620. #endif
  1621. #ifdef WIN_MSWIN
  1622.   SetWindowText (h, title);
  1623. #endif
  1624. #ifdef WIN_MOTIF
  1625.   allowTextCallback = FALSE;
  1626.   Nlm_StringCpy (bspace, "\b");
  1627.   XmTextSetString (h, bspace);
  1628.   str = Nlm_StringSave (title);
  1629.   XmTextSetString (h, str);
  1630.   Nlm_MemFree (str);
  1631.   allowTextCallback = TRUE;
  1632. #endif
  1633.   Nlm_RestorePort (tempPort);
  1634. }
  1635.  
  1636. static void Nlm_SetScrollText (Nlm_GraphiC t, Nlm_Int2 item,
  1637.                                Nlm_CharPtr title, Nlm_Boolean savePort)
  1638.  
  1639. {
  1640.   Nlm_TextTool  h;
  1641.   Nlm_WindoW    tempPort;
  1642. #ifdef WIN_MAC
  1643.   TEPtr         hp;
  1644.   Nlm_Uint4     len;
  1645.   Nlm_RecT      r;
  1646.   Nlm_Int4      selStart;
  1647.   Nlm_Int4      selEnd;
  1648. #endif
  1649.  
  1650.   tempPort = Nlm_SavePortIfNeeded (t, savePort);
  1651.   h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1652. #ifdef WIN_MAC
  1653.   len = Nlm_StringLen (title);
  1654.   if (len > 0) {
  1655.     TESetText (title, len, h);
  1656.     TECalText (h);
  1657.   } else {
  1658.     selStart = 0;
  1659.     HLock ((Handle) h);
  1660.     hp = (TEPtr) *((Handle) h);
  1661.     selEnd = hp->teLength;
  1662.     HUnlock ((Handle) h);
  1663.     TESetSelect (selStart, selEnd, h);
  1664.     TEDelete (h);
  1665.   }
  1666.   Nlm_GetRect (t, &r);
  1667.   Nlm_InsetRect (&r, 4, 2);
  1668.   r.bottom = r.top + Nlm_GetVisLines ((Nlm_TexT) t) * Nlm_GetFontHeight ((Nlm_TexT) t);
  1669.   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  1670.     Nlm_InsetRect (&r, -1, -1);
  1671.     Nlm_InvalRect (&r);
  1672.   }
  1673.   Nlm_UpdateScrollBar ((Nlm_TexT) t);
  1674. #endif
  1675. #ifdef WIN_MSWIN
  1676.   SetWindowText (h, title);
  1677. #endif
  1678. #ifdef WIN_MOTIF
  1679.   allowTextCallback = FALSE;
  1680.   /*
  1681.      The gcc compiler puts static strings in read only memory.  Motif 1.1 dies
  1682.      at this point for text objects (Dialog, Hidden and Password) that use the
  1683.      modifyVerify callback.  In those cases, the strings are copied.
  1684.   */
  1685.   XmTextSetString (h, title);
  1686.   allowTextCallback = TRUE;
  1687. #endif
  1688.   Nlm_RestorePort (tempPort);
  1689. }
  1690.  
  1691. static void Nlm_GetDialogText (Nlm_GraphiC t, Nlm_Int2 item,
  1692.                                Nlm_CharPtr title, Nlm_sizeT maxsize)
  1693.  
  1694. {
  1695.   Nlm_TextTool  h;
  1696.   Nlm_Char      temp [256];
  1697. #ifdef WIN_MAC
  1698.   Nlm_Char      **chars;
  1699.   TEPtr         hp;
  1700.   Nlm_Int2      i;
  1701.   Nlm_Int2      length;
  1702.   Nlm_Char      *ptr;
  1703. #endif
  1704. #ifdef WIN_MOTIF
  1705.   Nlm_CharPtr   ptr;
  1706. #endif
  1707.  
  1708.   h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1709. #ifdef WIN_MAC
  1710.   i = 0;
  1711.   HLock ((Handle) h);
  1712.   hp = (TEPtr) *((Handle) h);
  1713.   chars = hp->hText;
  1714.   length = hp->teLength;
  1715.   if (length > maxsize - 1) {
  1716.     length = maxsize - 1;
  1717.   }
  1718.   HUnlock ((Handle) h);
  1719.   if (chars != NULL) {
  1720.     HLock ((Handle) chars);
  1721.     ptr = (Nlm_Char *) *((Handle) chars);
  1722.     Nlm_StringNCpy (title, ptr, length);
  1723.     title [length] = '\0';
  1724.     HUnlock ((Handle) chars);
  1725.   }
  1726. #endif
  1727. #ifdef WIN_MSWIN
  1728.   GetWindowText (h, temp, sizeof (temp));
  1729.   Nlm_StringNCpy (title, temp, maxsize);
  1730. #endif
  1731. #ifdef WIN_MOTIF
  1732.   ptr = XmTextGetString (h);
  1733.   Nlm_StringNCpy (title, ptr, maxsize);
  1734.   XtFree (ptr);
  1735. #endif
  1736. }
  1737.  
  1738. static void Nlm_GetPasswordText (Nlm_GraphiC t, Nlm_Int2 item,
  1739.                                  Nlm_CharPtr title, Nlm_sizeT maxsize)
  1740.  
  1741. {
  1742.   Nlm_GetPassword ((Nlm_TexT) t, title, maxsize);
  1743. }
  1744.  
  1745. static void Nlm_GetScrollText (Nlm_GraphiC t, Nlm_Int2 item,
  1746.                                Nlm_CharPtr title, Nlm_sizeT maxsize)
  1747.  
  1748. {
  1749.   Nlm_TextTool  h;
  1750.   Nlm_Char      temp [256];
  1751. #ifdef WIN_MAC
  1752.   Nlm_Char      **chars;
  1753.   TEPtr         hp;
  1754.   Nlm_Int2      i;
  1755.   Nlm_Int2      length;
  1756.   Nlm_Char      *ptr;
  1757. #endif
  1758. #ifdef WIN_MOTIF
  1759.   Nlm_CharPtr   ptr;
  1760. #endif
  1761.  
  1762.   h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1763. #ifdef WIN_MAC
  1764.   i = 0;
  1765.   HLock ((Handle) h);
  1766.   hp = (TEPtr) *((Handle) h);
  1767.   chars = hp->hText;
  1768.   length = hp->teLength;
  1769.   if (length > maxsize - 1) {
  1770.     length = maxsize - 1;
  1771.   }
  1772.   HUnlock ((Handle) h);
  1773.   if (chars != NULL) {
  1774.     HLock ((Handle) chars);
  1775.     ptr = (Nlm_Char *) *((Handle) chars);
  1776.     Nlm_StringNCpy (title, ptr, length);
  1777.     title [length] = '\0';
  1778.     HUnlock ((Handle) chars);
  1779.   }
  1780. #endif
  1781. #ifdef WIN_MSWIN
  1782.   GetWindowText (h, temp, sizeof (temp));
  1783.   Nlm_StringNCpy (title, temp, maxsize);
  1784. #endif
  1785. #ifdef WIN_MOTIF
  1786.   ptr = XmTextGetString (h);
  1787.   Nlm_StringNCpy (title, ptr, maxsize);
  1788.   XtFree (ptr);
  1789. #endif
  1790. }
  1791.  
  1792. extern Nlm_TexT Nlm_CurrentText (void)
  1793.  
  1794. {
  1795.   return currentText;
  1796. }
  1797.  
  1798. extern void Nlm_CutText (Nlm_TexT t)
  1799.  
  1800. {
  1801.   Nlm_TextTool  h;
  1802.  
  1803.   if (t != NULL) {
  1804.     h = Nlm_GetTextHandle (t);
  1805. #ifdef WIN_MAC
  1806.     TECut (h);
  1807. #endif
  1808. #ifdef WIN_MSWIN
  1809.     SendMessage (h, WM_CUT, 0, 0);
  1810. #endif
  1811. #ifdef WIN_MOTIF
  1812.     allowTextCallback = FALSE;
  1813.     XmTextCut (h, CurrentTime);
  1814.     allowTextCallback = TRUE;
  1815. #endif
  1816.     Nlm_DoAction ((Nlm_GraphiC) t);
  1817.   }
  1818. }
  1819.  
  1820. extern void Nlm_CopyText (Nlm_TexT t)
  1821.  
  1822. {
  1823.   Nlm_TextTool  h;
  1824.  
  1825.   if (t != NULL) {
  1826.     h = Nlm_GetTextHandle (t);
  1827. #ifdef WIN_MAC
  1828.     TECopy (h);
  1829. #endif
  1830. #ifdef WIN_MSWIN
  1831.     SendMessage (h, WM_COPY, 0, 0);
  1832. #endif
  1833. #ifdef WIN_MOTIF
  1834.     allowTextCallback = FALSE;
  1835.     XmTextCopy (h, CurrentTime);
  1836.     allowTextCallback = TRUE;
  1837. #endif
  1838.   }
  1839. }
  1840.  
  1841. extern void Nlm_PasteText (Nlm_TexT t)
  1842.  
  1843. {
  1844.   Nlm_TextTool  h;
  1845.  
  1846.   if (t != NULL) {
  1847.     h = Nlm_GetTextHandle (t);
  1848. #ifdef WIN_MAC
  1849.     TEPaste (h);
  1850. #endif
  1851. #ifdef WIN_MSWIN
  1852.     SendMessage (h, WM_PASTE, 0, 0);
  1853. #endif
  1854. #ifdef WIN_MOTIF
  1855.     allowTextCallback = FALSE;
  1856.     XmTextPaste (h);
  1857.     allowTextCallback = TRUE;
  1858. #endif
  1859.     Nlm_DoAction ((Nlm_GraphiC) t);
  1860.   }
  1861. }
  1862.  
  1863. extern void Nlm_ClearText (Nlm_TexT t)
  1864.  
  1865. {
  1866.   Nlm_TextTool  h;
  1867.  
  1868.   if (t != NULL) {
  1869.     h = Nlm_GetTextHandle (t);
  1870. #ifdef WIN_MAC
  1871.     TEDelete (h);
  1872. #endif
  1873. #ifdef WIN_MSWIN
  1874.     SendMessage (h, WM_CLEAR, 0, 0);
  1875. #endif
  1876. #ifdef WIN_MOTIF
  1877.     allowTextCallback = FALSE;
  1878.     XmTextClearSelection (h, CurrentTime);
  1879.     allowTextCallback = TRUE;
  1880. #endif
  1881.     Nlm_DoAction ((Nlm_GraphiC) t);
  1882.   }
  1883. }
  1884.  
  1885. #ifdef WIN_MSWIN
  1886. /* Message cracker functions */
  1887.  
  1888. static void MyCls_OnChar (HWND hwnd, UINT ch, int cRepeat)
  1889.  
  1890. {
  1891.   Nlm_TexT  t;
  1892.  
  1893.   t = (Nlm_TexT) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
  1894.   handlechar = FALSE;
  1895.   if (ch == '\t' && Nlm_IsHiddenText ((Nlm_TexT) t)) {
  1896.     Nlm_DoTabCallback (t);
  1897.   } else if (ch == '\t') {
  1898.     Nlm_DoSendFocus ((Nlm_GraphiC) t, (Nlm_Char) ch);
  1899.   } else if (ch == '\n' || ch == '\r') {
  1900.     Nlm_DoSendFocus ((Nlm_GraphiC) t, (Nlm_Char) ch);
  1901.   } else {
  1902.     handlechar = TRUE;
  1903.   }
  1904. }
  1905.  
  1906. static void MyCls_OnSetFocus (HWND hwnd, HWND hwndOldFocus)
  1907.  
  1908. {
  1909.   Nlm_TexT  t;
  1910.  
  1911.   t = (Nlm_TexT) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
  1912.   Nlm_SetActive (t, TRUE);
  1913.   Nlm_DoTextSelect (t);
  1914. }
  1915.  
  1916. static void MyCls_OnKillFocus (HWND hwnd, HWND hwndNewFocus)
  1917.  
  1918. {
  1919.   Nlm_TexT  t;
  1920.  
  1921.   t = (Nlm_TexT) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
  1922.   if (Nlm_GetActive (t)) {
  1923.     Nlm_DoTextDeselect (t);
  1924.   }
  1925.   /*
  1926.   currentText = NULL;
  1927.   */
  1928. }
  1929.  
  1930. LRESULT CALLBACK EXPORT TextProc (HWND hwnd, UINT message,
  1931.                                   WPARAM wParam, LPARAM lParam)
  1932.  
  1933. {
  1934.   LRESULT   rsult;
  1935.   Nlm_TexT  t;
  1936.   HDC       tempHDC;
  1937.   HWND      tempHWnd;
  1938.  
  1939.   if (Nlm_VibrantDisabled ()) {
  1940.     return CallWindowProc (lpfnOldTextProc, hwnd, message, wParam, lParam);
  1941.   }
  1942.  
  1943.   rsult = 0;
  1944.   tempHWnd = Nlm_currentHWnd;
  1945.   tempHDC = Nlm_currentHDC;
  1946.   t = (Nlm_TexT) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
  1947.   Nlm_theWindow = Nlm_GetParentWindow ((Nlm_GraphiC) t);
  1948.   Nlm_currentHWnd = GetParent (hwnd);
  1949.   Nlm_currentHDC = Nlm_ParentWindowPort ((Nlm_GraphiC) t);
  1950.   Nlm_currentWindowTool = hwnd;
  1951.   Nlm_currentKey = '\0';
  1952.   Nlm_currentWParam = wParam;
  1953.   Nlm_currentLParam = lParam;
  1954.   Nlm_cmmdKey = FALSE;
  1955.   Nlm_ctrlKey = FALSE;
  1956.   Nlm_optKey = FALSE;
  1957.   Nlm_shftKey = FALSE;
  1958.   Nlm_dblClick = FALSE;
  1959.  
  1960.   switch (message) {
  1961.     case WM_CHAR:
  1962.       HANDLE_WM_CHAR (hwnd, wParam, lParam, MyCls_OnChar);
  1963.       if (handlechar) {
  1964.         rsult = CallWindowProc (lpfnOldTextProc, hwnd, message, wParam, lParam);
  1965.       }
  1966.       break;
  1967.     case WM_SETFOCUS:
  1968.       HANDLE_WM_SETFOCUS (hwnd, wParam, lParam, MyCls_OnSetFocus);
  1969.       rsult = CallWindowProc (lpfnOldTextProc, hwnd, message, wParam, lParam);
  1970.       break;
  1971.     case WM_KILLFOCUS:
  1972.       HANDLE_WM_KILLFOCUS (hwnd, wParam, lParam, MyCls_OnKillFocus);
  1973.       rsult = CallWindowProc (lpfnOldTextProc, hwnd, message, wParam, lParam);
  1974.       break;
  1975.     default:
  1976.       rsult = CallWindowProc (lpfnOldTextProc, hwnd, message, wParam, lParam);
  1977.       break;
  1978.   }
  1979.   Nlm_currentHWnd = tempHWnd;
  1980.   Nlm_currentHDC = tempHDC;
  1981.   Nlm_currentWindowTool = tempHWnd;
  1982.   return rsult;
  1983. }
  1984. #endif
  1985.  
  1986. static Nlm_GraphiC Nlm_TextGainFocus (Nlm_GraphiC t, Nlm_Char ch, Nlm_Boolean savePort)
  1987.  
  1988. {
  1989. #ifdef WIN_MAC
  1990.   Nlm_TextTool  h;
  1991.   TEPtr         hp;
  1992.   Nlm_Int2      len;
  1993.   Nlm_GraphiC   rsult;
  1994.  
  1995.   rsult = NULL;
  1996.   if (ch == '\t' && Nlm_GetVisible (t) && Nlm_GetEnabled (t)) {
  1997.     h = Nlm_GetTextHandle ((Nlm_TexT) t);
  1998.     HLock ((Handle) h);
  1999.     hp = (TEPtr) *((Handle) h);
  2000.     len = hp->teLength;
  2001.     HUnlock ((Handle) h);
  2002.     Nlm_SetActive ((Nlm_TexT) t, TRUE);
  2003.     Nlm_SelectAText ((Nlm_TexT) t, 0, len);
  2004.     rsult = t;
  2005.   }
  2006.   return rsult;
  2007. #endif
  2008. #ifdef WIN_MSWIN
  2009.   Nlm_GraphiC   rsult;
  2010.  
  2011.   rsult = NULL;
  2012.   if (ch == '\t' && Nlm_GetVisible (t) && Nlm_GetEnabled (t)) {
  2013.     Nlm_SetActive ((Nlm_TexT) t, TRUE);
  2014.     Nlm_SelectAText ((Nlm_TexT) t, 0, 32767);
  2015.     rsult = t;
  2016.   }
  2017.   return rsult;
  2018. #endif
  2019. #ifdef WIN_MOTIF
  2020.   Nlm_GraphiC   rsult;
  2021.  
  2022.   rsult = NULL;
  2023.   if (ch == '\t' && Nlm_GetVisible (t) && Nlm_GetEnabled (t)) {
  2024.     Nlm_SetActive ((Nlm_TexT) t, TRUE);
  2025.     Nlm_SelectAText ((Nlm_TexT) t, 0, 32767);
  2026.     rsult = t;
  2027.   }
  2028.   return rsult;
  2029. #endif
  2030. }
  2031.  
  2032. static void Nlm_TextLoseFocus (Nlm_GraphiC t, Nlm_GraphiC excpt, Nlm_Boolean savePort)
  2033.  
  2034. {
  2035.   Nlm_WindoW  tempPort;
  2036.  
  2037.   if (t != excpt) {
  2038.     if (Nlm_GetActive ((Nlm_TexT) t)) {
  2039.       Nlm_DoTextDeselect ((Nlm_TexT) t);
  2040.     }
  2041.     Nlm_SetActive ((Nlm_TexT) t, FALSE);
  2042.     tempPort = Nlm_SavePortIfNeeded (t, savePort);
  2043.     Nlm_DeactivateText (t, FALSE);
  2044.     Nlm_RestorePort (tempPort);
  2045.   }
  2046. }
  2047.  
  2048. #ifdef WIN_MAC
  2049. static void Nlm_InvalText (Nlm_GraphiC t)
  2050.  
  2051. {
  2052.   Nlm_RecT  r;
  2053.  
  2054.   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  2055.     Nlm_GetRect (t, &r);
  2056.     Nlm_InsetRect (&r, -1, -1);
  2057.     Nlm_InvalRect (&r);
  2058.   }
  2059. }
  2060.  
  2061. static void Nlm_InvalScrollText (Nlm_GraphiC t)
  2062.  
  2063. {
  2064.   Nlm_RecT  r;
  2065.  
  2066.   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  2067.     Nlm_GetRect (t, &r);
  2068.     r.right += Nlm_vScrollBarWidth;
  2069.     if (! Nlm_GetTextWrap ((Nlm_TexT) t)) {
  2070.       r.bottom += Nlm_hScrollBarHeight;
  2071.     }
  2072.     Nlm_InsetRect (&r, -1, -1);
  2073.     Nlm_InvalRect (&r);
  2074.   }
  2075. }
  2076. #endif
  2077.  
  2078. static void Nlm_SetTextPosition (Nlm_GraphiC t, Nlm_RectPtr r, Nlm_Boolean savePort)
  2079.  
  2080. {
  2081.   Nlm_TextTool  h;
  2082.   Nlm_RecT      oldRect;
  2083.   Nlm_WindoW    tempPort;
  2084.   Nlm_RecT      tr;
  2085. #ifdef WIN_MAC
  2086.   TEPtr         hp;
  2087.   Nlm_RectTool  rtool;
  2088. #endif
  2089.  
  2090.   if (r != NULL) {
  2091.     Nlm_DoGetPosition (t, &oldRect);
  2092.     if (! Nlm_EqualRect (r, &oldRect)) {
  2093.       tempPort = Nlm_SavePortIfNeeded (t, savePort);
  2094.       h = Nlm_GetTextHandle ((Nlm_TexT) t);
  2095. #ifdef WIN_MAC
  2096.       Nlm_InvalText (t);
  2097. #endif
  2098.       tr = *r;
  2099. #ifdef WIN_MAC
  2100.       Nlm_InsetRect (&tr, 2, 2);
  2101.       Nlm_RecTToRectTool (&tr, &rtool);
  2102.       HLock ((Handle) h);
  2103.       hp = (TEPtr) *((Handle) h);
  2104.       hp->destRect = rtool;
  2105.       hp->viewRect = rtool;
  2106.       HUnlock ((Handle) h);
  2107.       Nlm_SetRect (t, r);
  2108.       Nlm_InvalText (t);
  2109. #endif
  2110. #ifdef WIN_MSWIN
  2111.       MoveWindow (h, tr.left, tr.top, tr.right - tr.left, tr.bottom - tr.top, TRUE);
  2112.       Nlm_SetRect (t, r);
  2113.       UpdateWindow (h);
  2114. #endif
  2115. #ifdef WIN_MOTIF
  2116.       allowTextCallback = FALSE;
  2117.       XtVaSetValues (h,
  2118.                      XmNx, (Position) tr.left + 3,
  2119.                      XmNy, (Position) tr.top + 3,
  2120.                      XmNwidth, (Dimension) (tr.right - tr.left - 6),
  2121.                      XmNheight, (Dimension) (tr.bottom - tr.top - 6), 
  2122.                      NULL);
  2123.       Nlm_SetRect (t, r);
  2124.       allowTextCallback = TRUE;
  2125. #endif
  2126.       Nlm_RestorePort (tempPort);
  2127.     }
  2128.   }
  2129. }
  2130.  
  2131. static void Nlm_SetHiddenTextPosition (Nlm_GraphiC t, Nlm_RectPtr r, Nlm_Boolean savePort)
  2132.  
  2133. {
  2134.   Nlm_TextTool  h;
  2135.   Nlm_RecT      oldRect;
  2136.   Nlm_WindoW    tempPort;
  2137.   Nlm_RecT      tr;
  2138. #ifdef WIN_MAC
  2139.   TEPtr         hp;
  2140.   Nlm_RectTool  rtool;
  2141. #endif
  2142.  
  2143.   if (r != NULL) {
  2144.     Nlm_DoGetPosition (t, &oldRect);
  2145.     if (! Nlm_EqualRect (r, &oldRect)) {
  2146.       tempPort = Nlm_SavePortIfNeeded (t, savePort);
  2147.       h = Nlm_GetTextHandle ((Nlm_TexT) t);
  2148. #ifdef WIN_MAC
  2149.       Nlm_InvalText (t);
  2150. #endif
  2151.       tr = *r;
  2152. #ifdef WIN_MAC
  2153.       Nlm_RecTToRectTool (&tr, &rtool);
  2154.       HLock ((Handle) h);
  2155.       hp = (TEPtr) *((Handle) h);
  2156.       hp->destRect = rtool;
  2157.       hp->viewRect = rtool;
  2158.       HUnlock ((Handle) h);
  2159.       Nlm_SetRect (t, r);
  2160.       Nlm_InvalText (t);
  2161. #endif
  2162. #ifdef WIN_MSWIN
  2163.       MoveWindow (h, tr.left, tr.top, tr.right - tr.left, tr.bottom - tr.top, TRUE);
  2164.       Nlm_SetRect (t, r);
  2165.       UpdateWindow (h);
  2166. #endif
  2167. #ifdef WIN_MOTIF
  2168.       allowTextCallback = FALSE;
  2169.       XtVaSetValues (h,
  2170.                      XmNx, (Position) tr.left,
  2171.                      XmNy, (Position) tr.top,
  2172.                      XmNwidth, (Dimension) (tr.right - tr.left),
  2173.                      XmNheight, (Dimension) (tr.bottom - tr.top), 
  2174.                      NULL);
  2175.       Nlm_SetRect (t, r);
  2176.       allowTextCallback = TRUE;
  2177. #endif
  2178.       Nlm_RestorePort (tempPort);
  2179.     }
  2180.   }
  2181. }
  2182.  
  2183. static void Nlm_SetScrollTextPosition (Nlm_GraphiC t, Nlm_RectPtr r, Nlm_Boolean savePort)
  2184.  
  2185. {
  2186.   Nlm_TextTool  h;
  2187.   Nlm_RecT      oldRect;
  2188.   Nlm_WindoW    tempPort;
  2189.   Nlm_RecT      tr;
  2190.   Nlm_Boolean   wrap;
  2191. #ifdef WIN_MAC
  2192.   Nlm_RectTool  dtool;
  2193.   TEPtr         hp;
  2194.   Nlm_RectTool  rtool;
  2195.   Nlm_BaR       sb;
  2196. #endif
  2197.  
  2198.   if (r != NULL) {
  2199.     Nlm_DoGetPosition (t,&oldRect);
  2200.     if (! Nlm_EqualRect (r, &oldRect)) {
  2201.       tempPort = Nlm_SavePortIfNeeded (t, savePort);
  2202.       h = Nlm_GetTextHandle ((Nlm_TexT) t);
  2203.       if (h != NULL) {
  2204.         wrap = Nlm_GetTextWrap ((Nlm_TexT) t);
  2205.         tr = *r;
  2206. #ifdef WIN_MAC
  2207.         Nlm_InvalScrollText (t);
  2208.         tr.right -= Nlm_vScrollBarWidth;
  2209.         if (! wrap) {
  2210.           tr.bottom -= Nlm_hScrollBarHeight;
  2211.         }
  2212.         Nlm_SetRect (t, &tr);
  2213.         Nlm_InsetRect (&tr, 4, 2);
  2214.         tr.bottom = tr.top + Nlm_GetVisLines ((Nlm_TexT) t) * Nlm_GetFontHeight ((Nlm_TexT) t);
  2215.         Nlm_RecTToRectTool (&tr, &rtool);
  2216.         Nlm_RecTToRectTool (&tr, &dtool);
  2217.         if (! wrap) {
  2218. #ifdef DCLAP
  2219.           dtool.right = 32767;
  2220. #else
  2221.           dtool.right += HSCROLL_POSITIONS * Nlm_stdCharWidth;
  2222. #endif
  2223.         }
  2224.         HLock ((Handle) h);
  2225.         hp = (TEPtr) *((Handle) h);
  2226.         hp->destRect = dtool;
  2227.         hp->viewRect = rtool;
  2228.         HUnlock ((Handle) h);
  2229.         Nlm_InvalScrollText (t);
  2230.         sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
  2231.         if (sb != NULL) {
  2232.           Nlm_GetRect (t, &tr);
  2233.           tr.left = tr.right;
  2234.           tr.right += Nlm_vScrollBarWidth;
  2235.           Nlm_DoSetPosition ((Nlm_GraphiC) sb, &tr, FALSE);
  2236.         }
  2237.         sb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
  2238.         if (sb != NULL) {
  2239.           Nlm_GetRect (t, &tr);
  2240.           tr.top = tr.bottom;
  2241.           tr.bottom += Nlm_hScrollBarHeight;
  2242.           Nlm_DoSetPosition ((Nlm_GraphiC) sb, &tr, FALSE);
  2243.         }
  2244. #endif
  2245. #ifdef WIN_MSWIN
  2246.         MoveWindow (h, tr.left, tr.top, tr.right - tr.left, tr.bottom - tr.top, TRUE);
  2247.         tr.right -= Nlm_vScrollBarWidth;
  2248.         if (! wrap) {
  2249.           tr.bottom -= Nlm_hScrollBarHeight;
  2250.         }
  2251.         Nlm_SetRect (t, &tr);
  2252.         UpdateWindow (h);
  2253. #endif
  2254. #ifdef WIN_MOTIF
  2255.         allowTextCallback = FALSE;
  2256.         XtVaSetValues (XtParent (h),
  2257.                        XmNx, (Position) tr.left + 3,
  2258.                        XmNy, (Position) tr.top + 3,
  2259.                        XmNwidth, (Dimension) (tr.right - tr.left) - 6,
  2260.                        XmNheight, (Dimension) (tr.bottom - tr.top) - 6,
  2261.                        NULL);
  2262.         tr.right -= Nlm_vScrollBarWidth;
  2263.         if (! wrap) {
  2264.           tr.bottom -= Nlm_hScrollBarHeight;
  2265.         }
  2266.         Nlm_SetRect (t, &tr);
  2267.         allowTextCallback = TRUE;
  2268. #endif
  2269.       }
  2270.       Nlm_RestorePort (tempPort);
  2271.     }
  2272.   }
  2273. }
  2274.  
  2275. static void Nlm_GetTextPosition (Nlm_GraphiC t, Nlm_RectPtr r)
  2276.  
  2277. {
  2278.   if (r != NULL) {
  2279.     Nlm_GetRect (t, r);
  2280.   }
  2281. }
  2282.  
  2283. static void Nlm_GetScrollTextPosition (Nlm_GraphiC t, Nlm_RectPtr r)
  2284.  
  2285. {
  2286.   if (r != NULL) {
  2287.     Nlm_GetRect (t, r);
  2288.     r->right += Nlm_vScrollBarWidth;
  2289.     if (! Nlm_GetTextWrap ((Nlm_TexT) t)) {
  2290.       r->bottom += Nlm_hScrollBarHeight;
  2291.     }
  2292.   }
  2293. }
  2294.  
  2295. #ifdef WIN_MAC
  2296. static void Nlm_VScrollAction (Nlm_BaR sb, Nlm_GraphiC t,
  2297.                                Nlm_Int2 newval, Nlm_Int2 oldval)
  2298.  
  2299. {
  2300.   Nlm_Int2      delta;
  2301.   Nlm_TextTool  h;
  2302.   Nlm_Int2      height;
  2303.   Nlm_RecT      r;
  2304.  
  2305.   h = Nlm_GetTextHandle ((Nlm_TexT) t);
  2306.   delta = oldval - newval;
  2307.   if (oldval != newval) {
  2308.         SelectDialogFont();
  2309.       height = Nlm_GetLineHeight ((Nlm_TexT) t);
  2310.     TEScroll (0, delta * height, h);
  2311.   } else if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  2312.     Nlm_GetRect (t, &r);
  2313.     Nlm_InsetRect (&r, 2, 1);
  2314.     Nlm_InvalRect (&r);
  2315.   }
  2316.   Nlm_Update ();
  2317. }
  2318.  
  2319. static void Nlm_HScrollAction (Nlm_BaR sb, Nlm_GraphiC t,
  2320.                                Nlm_Int2 newval, Nlm_Int2 oldval)
  2321. {
  2322.   Nlm_Int2      delta;
  2323.   Nlm_TextTool  h;
  2324.   Nlm_Int2      width;
  2325.   Nlm_RecT      r;
  2326.  
  2327.   h = Nlm_GetTextHandle ((Nlm_TexT) t);
  2328.   delta = oldval - newval;
  2329.   if (oldval != newval) {
  2330.         SelectDialogFont();
  2331. #ifdef DCLAP
  2332.         width= Nlm_CharWidth('A');
  2333. #else
  2334.     width = Nlm_stdCharWidth;
  2335. #endif
  2336.     TEScroll (delta * width, 0, h);
  2337.   } else if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
  2338.     Nlm_GetRect (t, &r);
  2339.     Nlm_InsetRect (&r, 2, 1);
  2340.     Nlm_InvalRect (&r);
  2341.   }
  2342.   Nlm_Update ();
  2343. }
  2344. #endif
  2345.  
  2346.  
  2347. #ifdef DCLAP
  2348. extern void Nlm_HScrollText(Nlm_BaR sb, Nlm_GraphiC t, Nlm_Int2 newval, Nlm_Int2 oldval)
  2349. {
  2350. #ifdef WIN_MAC
  2351.     Nlm_HScrollAction( sb, t, newval, oldval);
  2352. #endif
  2353.  
  2354. #ifdef WIN_MSWIN
  2355.   Nlm_TextTool  h;
  2356.   if (t && oldval != newval) {
  2357.     h = Nlm_GetTextHandle ((Nlm_TexT) t);
  2358.         SendMessage( h, WM_HSCROLL, SB_THUMBTRACK, newval);
  2359.         }
  2360. #endif
  2361.  
  2362. #ifdef WIN_MOTIF
  2363.  /* ??? */
  2364. #endif
  2365. }
  2366. #endif
  2367.  
  2368. #ifdef WIN_MOTIF
  2369. static void Nlm_ReturnCallback (Widget w, XtPointer client_data, XtPointer call_data)
  2370.  
  2371. {
  2372.   XmAnyCallbackStruct  *cbs;
  2373.   Nlm_GraphiC          t;
  2374.  
  2375.   cbs = (XmAnyCallbackStruct *) call_data;
  2376.   t = (Nlm_GraphiC) client_data;
  2377.   if (cbs->event != NULL) {
  2378.     Nlm_DoSendFocus ((Nlm_GraphiC) t, '\r');
  2379.   }
  2380. }
  2381.  
  2382. static void Nlm_TextCallback (Widget w, XtPointer client_data, XtPointer call_data)
  2383.  
  2384. {
  2385.   XmAnyCallbackStruct  *cbs;
  2386.   Nlm_GraphiC          t;
  2387.  
  2388.   cbs = (XmAnyCallbackStruct *) call_data;
  2389.   t = (Nlm_GraphiC) client_data;
  2390.   if (cbs->event != NULL) {
  2391.     Nlm_DoAction (t);
  2392.   } else if (allowTextCallback) {
  2393.     Nlm_DoAction (t);
  2394.   }
  2395. }
  2396.  
  2397. static void Nlm_FocusCallback (Widget w, XtPointer client_data, XtPointer call_data)
  2398.  
  2399. {
  2400.   XmAnyCallbackStruct  *cbs;
  2401.   Nlm_TexT             t;
  2402.  
  2403.   cbs = (XmAnyCallbackStruct *) call_data;
  2404.   t = (Nlm_TexT) client_data;
  2405.   Nlm_SetActive (t, TRUE);
  2406.   Nlm_DoTextSelect (t);
  2407. }
  2408.  
  2409. static void Nlm_LoseFocusCallback (Widget w, XtPointer client_data, XtPointer call_data)
  2410.  
  2411. {
  2412.   XmAnyCallbackStruct  *cbs;
  2413.   Nlm_TexT             t;
  2414.  
  2415.   cbs = (XmAnyCallbackStruct *) call_data;
  2416.   t = (Nlm_TexT) client_data;
  2417.   if (Nlm_GetActive (t)) {
  2418.     Nlm_DoTextDeselect (t);
  2419.   }
  2420.   /*
  2421.   currentText = NULL;
  2422.   */
  2423. }
  2424.  
  2425. static void Nlm_RefreshCallback (Widget w, XtPointer client_data, XtPointer call_data)
  2426.  
  2427. {
  2428.   XmTextVerifyCallbackStruct  *cbs;
  2429.   Nlm_RecT                    r;
  2430.   Nlm_TexT                    t;
  2431.  
  2432.   cbs = (XmTextVerifyCallbackStruct *) call_data;
  2433.   t = (Nlm_TexT) client_data;
  2434.   if (cbs->text->ptr == NULL) {
  2435.     Nlm_ObjectRect ((Nlm_GraphiC) t, &r);
  2436.     Nlm_OffsetRect (&r, -r.left, -r.top);
  2437.     if (! Nlm_IsHiddenText (t)) {
  2438.       Nlm_InsetRect (&r, 4, 4);
  2439. #ifdef OS_VMS
  2440.       Nlm_InsetRect (&r, 5, 3);
  2441. #else
  2442.       Nlm_InsetRect (&r, 5, 5);
  2443. #endif
  2444.     }
  2445.     if (Nlm_currentXDisplay != NULL) {
  2446.       XClearArea (Nlm_currentXDisplay, XtWindow (w), r.left, r.top,
  2447.                   r.right - r.left, r.bottom - r.top, TRUE);
  2448.     }
  2449.   }
  2450. }
  2451.  
  2452. static void Nlm_PasswordCallback (Widget w, XtPointer client_data, XtPointer call_data)
  2453.  
  2454. {
  2455.   XmTextVerifyCallbackStruct  *cbs;
  2456.   int                         len;
  2457.   Nlm_Char                    password [32];
  2458.   Nlm_GraphiC                 t;
  2459.  
  2460.   cbs = (XmTextVerifyCallbackStruct *) call_data;
  2461.   t = (Nlm_GraphiC) client_data;
  2462.   if (cbs->text->length > 1) {
  2463.     cbs->doit = FALSE;
  2464.     return;
  2465.   }
  2466.   if (cbs->text->ptr == NULL) {
  2467.     Nlm_GetPassword ((Nlm_TexT) t, password, sizeof (password) - 1);
  2468.     cbs->endPos = (long) Nlm_StringLen (password);
  2469.     cbs->startPos = 0;
  2470.     password [cbs->startPos] = '\0';
  2471.     Nlm_SetPassword ((Nlm_TexT) t, password);
  2472.     return;
  2473.   }
  2474.   Nlm_GetPassword ((Nlm_TexT) t, password, sizeof (password) - 1);
  2475.   Nlm_StringNCat (password, cbs->text->ptr, cbs->text->length);
  2476.   password [cbs->endPos + cbs->text->length] = '\0';
  2477.   Nlm_SetPassword ((Nlm_TexT) t, password);
  2478.   for (len = 0; len < cbs->text->length; len++) {
  2479.     cbs->text->ptr [len] = '*';
  2480.   }
  2481. }
  2482.  
  2483. static void Nlm_TabCallback (Widget w, XEvent *ev, String *args, Cardinal *num_args)
  2484.  
  2485. {
  2486.   XKeyEvent  *event;
  2487.   XtPointer     ptr;
  2488.   Nlm_TexT   t;
  2489.  
  2490.   event = (XKeyEvent *) ev;
  2491.   XtVaGetValues (w, XmNuserData, &ptr, NULL);
  2492.   t = (Nlm_TexT) ptr;
  2493.   Nlm_DoTabCallback (t);
  2494. }
  2495. #endif
  2496.  
  2497. static void Nlm_NewDialogText (Nlm_TexT t, Nlm_CharPtr dfault, Nlm_TxtActnProc actn)
  2498.  
  2499. {
  2500.   Nlm_TextTool    h;
  2501.   Nlm_Int2        leng;
  2502.   Nlm_Char        local [128];
  2503.   Nlm_RecT        r;
  2504.   Nlm_Char        stars [32];
  2505.   Nlm_WindowTool  wptr;
  2506. #ifdef WIN_MAC
  2507.   Nlm_RectTool    rtool;
  2508. #endif
  2509. #ifdef WIN_MSWIN
  2510.   Nlm_Uint4       style;
  2511. #endif
  2512. #ifdef WIN_MOTIF
  2513.   Cardinal        n;
  2514.   Arg             wargs [20];
  2515. #endif
  2516.  
  2517.   Nlm_StringCpy (stars, "******************************");
  2518.   local [0] = '\0';
  2519.   Nlm_StringNCpy (local, dfault, sizeof (local) - 1);
  2520.   leng = (Nlm_Int2) Nlm_StringLen (local);
  2521.   if (leng < 32) {
  2522.     stars [leng] = '\0';
  2523.   }
  2524.   Nlm_GetRect ((Nlm_GraphiC) t, &r);
  2525.   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) t);
  2526. #ifdef WIN_MAC
  2527.   Nlm_InsetRect (&r, 2, 2);
  2528.   Nlm_RecTToRectTool (&r, &rtool);
  2529.   h = TENew (&rtool, &rtool);
  2530.   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, gDialogTextFont, gDlogTextHeight, FALSE, FALSE, FALSE, 1, NULL, NULL, NULL);
  2531.   Nlm_SetDialogText ((Nlm_GraphiC) t, 0, local, FALSE);
  2532.   if (h != NULL) {
  2533.     TEAutoView (TRUE, h);
  2534.   }
  2535. #endif
  2536. #ifdef WIN_MSWIN
  2537.   style = WS_CHILD | WS_BORDER | ES_MULTILINE | ES_AUTOVSCROLL | ES_LEFT;
  2538.   h = CreateWindow ("Edit", local, style,
  2539.                     r.left, r.top, r.right - r.left,
  2540.                     r.bottom - r.top, wptr, 0,
  2541.                     Nlm_currentHInst, NULL);
  2542.   if (h != NULL) {
  2543.     SetProp (h, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) t);
  2544. #ifdef DCLAP
  2545. #if 1
  2546. {
  2547.     /* this is vibrant way */
  2548.   HFONT    oldFont;
  2549.   Nlm_FntPtr      fntptr;
  2550.   oldFont = NULL;
  2551.   if (gDialogTextFont != NULL) {
  2552.     fntptr = (Nlm_FntPtr) Nlm_HandLock (gDialogTextFont);
  2553.     if (fntptr != NULL && fntptr->handle != NULL) {
  2554.       oldFont = SelectObject (Nlm_currentHDC, fntptr->handle);
  2555.     }
  2556.     Nlm_HandUnlock (gDialogTextFont);
  2557.   } else {
  2558.     oldFont = SelectObject (Nlm_currentHDC, GetStockObject (ANSI_FIXED_FONT));
  2559.   }
  2560.   if (oldFont != NULL) {
  2561.     SelectObject (Nlm_currentHDC, oldFont);
  2562.     SetWindowFont (h, oldFont, FALSE);
  2563.   }
  2564.  }
  2565. #else
  2566.         {
  2567.         /* dgg way */
  2568.         Nlm_FontData    fdata;
  2569.         Nlm_GetFontData( gDialogTextFont, &fdata);
  2570.         PostMessage( h, WM_SETFONT, fdata.handle, 0L);
  2571.         }
  2572. #endif
  2573. #endif
  2574.   }
  2575.   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, gDialogTextFont, gDlogTextHeight, FALSE, FALSE, FALSE, 1, NULL, NULL, NULL);
  2576.   if (lpfnNewTextProc == NULL) {
  2577.     lpfnNewTextProc = (WNDPROC) MakeProcInstance ((FARPROC) TextProc, Nlm_currentHInst);
  2578.   }
  2579.   if (lpfnOldTextProc == NULL) {
  2580.     lpfnOldTextProc = (WNDPROC) GetWindowLong (h, GWL_WNDPROC);
  2581.   } else if (lpfnOldTextProc != (WNDPROC) GetWindowLong (h, GWL_WNDPROC)) {
  2582.     Nlm_Message (MSG_ERROR, "TextProc subclass error");
  2583.   }
  2584.   SetWindowLong (h, GWL_WNDPROC, (LONG) lpfnNewTextProc);
  2585. #endif
  2586. #ifdef WIN_MOTIF
  2587.   allowTextCallback = FALSE;
  2588.   Nlm_InsetRect (&r, 3, 3);
  2589.   n = 0;
  2590.   XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
  2591.   XtSetArg (wargs [n], XmNy, (Position) r.top); n++;
  2592.   XtSetArg (wargs [n], XmNwidth, (Dimension) (r.right - r.left)); n++;
  2593.   XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top)); n++;
  2594. #ifdef OS_VMS
  2595.   XtSetArg (wargs [n], XmNmarginHeight, 1); n++;
  2596. #else
  2597.   XtSetArg (wargs [n], XmNmarginHeight, 3); n++;
  2598. #endif
  2599.   XtSetArg (wargs [n], XmNmarginWidth, 3); n++;
  2600.   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  2601.   XtSetArg (wargs [n], XmNeditMode, XmSINGLE_LINE_EDIT); n++;
  2602.   XtSetArg (wargs [n], XmNfontList, NULL); n++;
  2603.   XtSetArg (wargs [n], XmNhighlightThickness, 0); n++;
  2604.   XtSetArg (wargs [n], XmNautoShowCursorPosition, TRUE); n++;
  2605.   h = XmCreateText (wptr, (String) "", wargs, n);
  2606.   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, gDialogTextFont, gDlogTextHeight, FALSE, FALSE, FALSE, 1, NULL, NULL, NULL);
  2607.   XmTextSetString (h, local);
  2608.   XmTextShowPosition (h, 0);
  2609.   XtAddCallback (h, XmNmodifyVerifyCallback, Nlm_RefreshCallback, (XtPointer) t);
  2610.   XtAddCallback (h, XmNvalueChangedCallback, Nlm_TextCallback, (XtPointer) t);
  2611.   XtAddCallback (h, XmNactivateCallback, Nlm_ReturnCallback, (XtPointer) t);
  2612.   XtAddCallback (h, XmNfocusCallback, Nlm_FocusCallback, (XtPointer) t);
  2613.   XtAddCallback (h, XmNlosingFocusCallback, Nlm_LoseFocusCallback, (XtPointer) t);
  2614.   if (NLM_QUIET) {
  2615.     if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (t))) {
  2616.       XtRealizeWidget (h);
  2617.     }
  2618.   } else {
  2619.     XtRealizeWidget (h);
  2620.   }
  2621.   allowTextCallback = TRUE;
  2622. #endif
  2623.   Nlm_LoadAction ((Nlm_GraphiC) t, (Nlm_ActnProc) actn);
  2624. }
  2625.  
  2626. static void Nlm_NewPasswordText (Nlm_TexT t, Nlm_CharPtr dfault, Nlm_TxtActnProc actn)
  2627.  
  2628. {
  2629.   Nlm_TextTool    h;
  2630.   Nlm_Int2        leng;
  2631.   Nlm_Char        local [128];
  2632.   Nlm_RecT        r;
  2633.   Nlm_Char        stars [32];
  2634.   Nlm_WindowTool  wptr;
  2635. #ifdef WIN_MAC
  2636.   Nlm_RectTool    rtool;
  2637. #endif
  2638. #ifdef WIN_MSWIN
  2639.   Nlm_Uint4       style;
  2640. #endif
  2641. #ifdef WIN_MOTIF
  2642.   Cardinal        n;
  2643.   Arg             wargs [20];
  2644. #endif
  2645.  
  2646.   Nlm_StringCpy (stars, "******************************");
  2647.   local [0] = '\0';
  2648.   Nlm_StringNCpy (local, dfault, sizeof (local) - 1);
  2649.   leng = (Nlm_Int2) Nlm_StringLen (local);
  2650.   if (leng < 32) {
  2651.     stars [leng] = '\0';
  2652.   }
  2653.   Nlm_GetRect ((Nlm_GraphiC) t, &r);
  2654.   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) t);
  2655. #ifdef WIN_MAC
  2656.   Nlm_InsetRect (&r, 2, 2);
  2657.   Nlm_RecTToRectTool (&r, &rtool);
  2658.   h = TENew (&rtool, &rtool);
  2659.   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, gDialogTextFont, gDlogTextHeight, FALSE, FALSE, FALSE, 1, NULL, NULL, NULL);
  2660.   Nlm_SetPasswordText ((Nlm_GraphiC) t, 0, local, FALSE);
  2661. #endif
  2662. #ifdef WIN_MSWIN
  2663.   style = WS_CHILD | WS_BORDER |  ES_AUTOVSCROLL | ES_LEFT | ES_PASSWORD;
  2664.   h = CreateWindow ("Edit", local, style,
  2665.                     r.left, r.top, r.right - r.left,
  2666.                     r.bottom - r.top, wptr, 0,
  2667.                     Nlm_currentHInst, NULL);
  2668.   if (h != NULL) {
  2669.     SetProp (h, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) t);
  2670.   }
  2671.   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, gDialogTextFont, gDlogTextHeight, FALSE, FALSE, FALSE, 1, NULL, NULL, NULL);
  2672.   if (lpfnNewTextProc == NULL) {
  2673.     lpfnNewTextProc = (WNDPROC) MakeProcInstance ((FARPROC) TextProc, Nlm_currentHInst);
  2674.   }
  2675.   if (lpfnOldTextProc == NULL) {
  2676.     lpfnOldTextProc = (WNDPROC) GetWindowLong (h, GWL_WNDPROC);
  2677.   } else if (lpfnOldTextProc != (WNDPROC) GetWindowLong (h, GWL_WNDPROC)) {
  2678.     Nlm_Message (MSG_ERROR, "TextProc subclass error");
  2679.   }
  2680.   SetWindowLong (h, GWL_WNDPROC, (LONG) lpfnNewTextProc);
  2681.   Nlm_SetPassword (t, local);
  2682. #endif
  2683. #ifdef WIN_MOTIF
  2684.   allowTextCallback = FALSE;
  2685.   Nlm_InsetRect (&r, 3, 3);
  2686.   n = 0;
  2687.   XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
  2688.   XtSetArg (wargs [n], XmNy, (Position) r.top); n++;
  2689.   XtSetArg (wargs [n], XmNwidth, (Dimension) (r.right - r.left)); n++;
  2690.   XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top)); n++;
  2691.   XtSetArg (wargs [n], XmNmarginHeight, 3); n++;
  2692.   XtSetArg (wargs [n], XmNmarginWidth, 3); n++;
  2693.   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  2694.   XtSetArg (wargs [n], XmNeditMode, XmSINGLE_LINE_EDIT); n++;
  2695.   XtSetArg (wargs [n], XmNfontList, NULL); n++;
  2696.   XtSetArg (wargs [n], XmNhighlightThickness, 0); n++;
  2697.   h = XmCreateText (wptr, (String) "", wargs, n);
  2698.   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, gDialogTextFont, gDlogTextHeight, FALSE, FALSE, FALSE, 1, NULL, NULL, NULL);
  2699.   XmTextSetString (h, local);
  2700.   XtAddCallback (h, XmNmodifyVerifyCallback, Nlm_PasswordCallback, (XtPointer) t);
  2701.   XtAddCallback (h, XmNvalueChangedCallback, Nlm_TextCallback, (XtPointer) t);
  2702.   XtAddCallback (h, XmNactivateCallback, Nlm_ReturnCallback, (XtPointer) t);
  2703.   XtAddCallback (h, XmNfocusCallback, Nlm_FocusCallback, (XtPointer) t);
  2704.   XtAddCallback (h, XmNlosingFocusCallback, Nlm_LoseFocusCallback, (XtPointer) t);
  2705.   if (NLM_QUIET) {
  2706.     if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (t))) {
  2707.       XtRealizeWidget (h);
  2708.     }
  2709.   } else {
  2710.     XtRealizeWidget (h);
  2711.   }
  2712.   Nlm_SetPassword (t, dfault);
  2713.   allowTextCallback = TRUE;
  2714. #endif
  2715.   Nlm_LoadAction ((Nlm_GraphiC) t, (Nlm_ActnProc) actn);
  2716. }
  2717.  
  2718. static void Nlm_NewHiddenText (Nlm_TexT t, Nlm_CharPtr dfault,
  2719.                                Nlm_TxtActnProc actn, Nlm_TxtActnProc tabProc)
  2720.  
  2721. {
  2722.   Nlm_TextTool    h;
  2723.   Nlm_Int2        leng;
  2724.   Nlm_Char        local [128];
  2725.   Nlm_RecT        r;
  2726.   Nlm_Char        stars [32];
  2727.   Nlm_WindowTool  wptr;
  2728. #ifdef WIN_MAC
  2729.   Nlm_RectTool    rtool;
  2730.   Nlm_RectTool    dtool;
  2731. #endif
  2732. #ifdef WIN_MSWIN
  2733.   Nlm_Uint4       style;
  2734. #endif
  2735. #ifdef WIN_MOTIF
  2736.   Cardinal        n;
  2737.   Arg             wargs [20];
  2738. #endif
  2739.  
  2740.   Nlm_StringCpy (stars, "******************************");
  2741.   local [0] = '\0';
  2742.   Nlm_StringNCpy (local, dfault, sizeof (local) - 1);
  2743.   leng = (Nlm_Int2) Nlm_StringLen (local);
  2744.   if (leng < 32) {
  2745.     stars [leng] = '\0';
  2746.   }
  2747.   Nlm_GetRect ((Nlm_GraphiC) t, &r);
  2748.   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) t);
  2749. #ifdef WIN_MAC
  2750.   Nlm_RecTToRectTool (&r, &rtool);  
  2751.   h = TENew (&rtool, &rtool);
  2752.   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, gDialogTextFont, gDlogTextHeight, FALSE, FALSE, TRUE, 1, NULL, NULL, tabProc);
  2753.   Nlm_SetDialogText ((Nlm_GraphiC) t, 0, local, FALSE);
  2754.   if (h != NULL) {
  2755.     TEAutoView (TRUE, h);
  2756.   }
  2757. #endif
  2758. #ifdef WIN_MSWIN
  2759.   style = WS_CHILD | ES_MULTILINE | ES_AUTOVSCROLL | ES_LEFT;
  2760.   h = CreateWindow ("Edit", local, style,
  2761.                     r.left, r.top, r.right - r.left,
  2762.                     r.bottom - r.top, wptr, 0,
  2763.                     Nlm_currentHInst, NULL);
  2764.   if (h != NULL) {
  2765.     SetProp (h, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) t);
  2766. #ifdef DCLAP
  2767. #if 1
  2768. {
  2769.     /* vibrant way */
  2770.   HFONT    oldFont;
  2771.   Nlm_FntPtr      fntptr;
  2772.   oldFont = NULL;
  2773.   if (gDialogTextFont != NULL) {
  2774.     fntptr = (Nlm_FntPtr) Nlm_HandLock (gDialogTextFont);
  2775.     if (fntptr != NULL && fntptr->handle != NULL) {
  2776.       oldFont = SelectObject (Nlm_currentHDC, fntptr->handle);
  2777.     }
  2778.     Nlm_HandUnlock (gDialogTextFont);
  2779.   } else {
  2780.     oldFont = SelectObject (Nlm_currentHDC, GetStockObject (ANSI_FIXED_FONT));
  2781.   }
  2782.   if (oldFont != NULL) {
  2783.     SelectObject (Nlm_currentHDC, oldFont);
  2784.     SetWindowFont (h, oldFont, FALSE);
  2785.   }
  2786.  }
  2787. #else
  2788.     /* dgg way */
  2789.         {
  2790.         Nlm_FontData    fdata;
  2791.         Nlm_GetFontData( gDialogTextFont, &fdata);
  2792.         PostMessage( h, WM_SETFONT, fdata.handle, 0L);
  2793.         }
  2794. #endif
  2795. #endif
  2796.   }
  2797.   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, gDialogTextFont, gDlogTextHeight, FALSE, FALSE, TRUE, 1, NULL, NULL, tabProc);
  2798.   if (lpfnNewTextProc == NULL) {
  2799.     lpfnNewTextProc = (WNDPROC) MakeProcInstance ((FARPROC) TextProc, Nlm_currentHInst);
  2800.   }
  2801.   if (lpfnOldTextProc == NULL) {
  2802.     lpfnOldTextProc = (WNDPROC) GetWindowLong (h, GWL_WNDPROC);
  2803.   } else if (lpfnOldTextProc != (WNDPROC) GetWindowLong (h, GWL_WNDPROC)) {
  2804.     Nlm_Message (MSG_ERROR, "TextProc subclass error");
  2805.   }
  2806.   SetWindowLong (h, GWL_WNDPROC, (LONG) lpfnNewTextProc);
  2807. #endif
  2808.  
  2809. #ifdef WIN_MOTIF
  2810.   allowTextCallback = FALSE;
  2811.   n = 0;
  2812.   XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
  2813.   XtSetArg (wargs [n], XmNy, (Position) r.top); n++;
  2814.   XtSetArg (wargs [n], XmNwidth, (Dimension) (r.right - r.left)); n++;
  2815.   XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top)); n++;
  2816. #ifdef OS_VMS
  2817.   XtSetArg (wargs [n], XmNmarginHeight, 0); n++;
  2818. #else
  2819.   XtSetArg (wargs [n], XmNmarginHeight, 0); n++;
  2820. #endif
  2821.   XtSetArg (wargs [n], XmNmarginWidth, 0); n++;
  2822.   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  2823.   XtSetArg (wargs [n], XmNshadowThickness, (Dimension) 0); n++;
  2824.   XtSetArg (wargs [n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
  2825.   XtSetArg (wargs [n], XmNfontList, NULL); n++;
  2826.   XtSetArg (wargs [n], XmNhighlightThickness, 0); n++;
  2827.   XtSetArg (wargs [n], XmNautoShowCursorPosition, TRUE); n++;
  2828.   XtSetArg (wargs [n], XmNverifyBell, FALSE); n++;
  2829.   h = XmCreateText (wptr, (String) "", wargs, n);
  2830.   XtOverrideTranslations (h, XtParseTranslationTable ("<Key>Tab: do_tab()"));
  2831.   XtVaSetValues (h, XmNuserData, (XtPointer) t, NULL);
  2832.   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, gDialogTextFont, gDlogTextHeight, FALSE, FALSE, TRUE, 1, NULL, NULL, tabProc);
  2833.   XmTextSetString (h, local);
  2834.   XmTextShowPosition (h, 0);
  2835.   XtAddCallback (h, XmNmodifyVerifyCallback, Nlm_RefreshCallback, (XtPointer) t);
  2836.   XtAddCallback (h, XmNvalueChangedCallback, Nlm_TextCallback, (XtPointer) t);
  2837.   XtAddCallback (h, XmNactivateCallback, Nlm_ReturnCallback, (XtPointer) t);
  2838.   XtAddCallback (h, XmNfocusCallback, Nlm_FocusCallback, (XtPointer) t);
  2839.   XtAddCallback (h, XmNlosingFocusCallback, Nlm_LoseFocusCallback, (XtPointer) t);
  2840.   if (NLM_QUIET) {
  2841.     if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (t))) {
  2842.       XtRealizeWidget (h);
  2843.     }
  2844.   } else {
  2845.     XtRealizeWidget (h);
  2846.   }
  2847.   allowTextCallback = TRUE;
  2848. #endif
  2849.   Nlm_LoadAction ((Nlm_GraphiC) t, (Nlm_ActnProc) actn);
  2850. }
  2851.  
  2852.  
  2853. #ifdef DCLAP
  2854.  
  2855. static void Nlm_NewTextLine (Nlm_TexT t, Nlm_CharPtr dfault,
  2856.                                Nlm_TxtActnProc actn, Nlm_TxtActnProc tabProc)
  2857.  
  2858. {
  2859.   Nlm_TextTool    h;
  2860.   Nlm_Int2        leng;
  2861.   Nlm_Char        local [128];
  2862.   Nlm_RecT        r;
  2863.   Nlm_Char        stars [32];
  2864.   Nlm_WindowTool  wptr;
  2865. #ifdef WIN_MAC
  2866.   Nlm_RectTool    rtool;
  2867.   Nlm_RectTool    dtool;
  2868. #endif
  2869. #ifdef WIN_MSWIN
  2870.   Nlm_Uint4       style;
  2871. #endif
  2872. #ifdef WIN_MOTIF
  2873.   Cardinal        n;
  2874.   Arg             wargs [20];
  2875. #endif
  2876.  
  2877.   Nlm_StringCpy (stars, "******************************");
  2878.   local [0] = '\0';
  2879.   Nlm_StringNCpy (local, dfault, sizeof (local) - 1);
  2880.   leng = (Nlm_Int2) Nlm_StringLen (local);
  2881.   if (leng < 32) {
  2882.     stars [leng] = '\0';
  2883.   }
  2884.   Nlm_GetRect ((Nlm_GraphiC) t, &r);
  2885.   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) t);
  2886.  
  2887. #ifdef WIN_MAC
  2888.   Nlm_RecTToRectTool (&r, &rtool);
  2889.     Nlm_RecTToRectTool (&r, &dtool);
  2890.     dtool.right= 32000;  
  2891.     h = TENew (&rtool, &dtool);
  2892.     (**h).crOnly= -1;
  2893.   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, gDialogTextFont, gDlogTextHeight, FALSE, FALSE, TRUE, 1, NULL, NULL, tabProc);
  2894.   Nlm_SetDialogText ((Nlm_GraphiC) t, 0, local, FALSE);
  2895.   if (h != NULL) {
  2896.     TEAutoView (TRUE, h);
  2897.   }
  2898. #endif
  2899.  
  2900. #ifdef WIN_MSWIN
  2901.   style = WS_CHILD | ES_LEFT | ES_AUTOHSCROLL;
  2902.   h = CreateWindow ("Edit", local, style,
  2903.                     r.left, r.top, r.right - r.left,
  2904.                     r.bottom - r.top, wptr, 0,
  2905.                     Nlm_currentHInst, NULL);
  2906.   if (h != NULL) {
  2907.     SetProp (h, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) t);
  2908. #if 1
  2909. {
  2910.     /* vibrant way */
  2911.   HFONT    oldFont;
  2912.   Nlm_FntPtr      fntptr;
  2913.   oldFont = NULL;
  2914.   if (gDialogTextFont != NULL) {
  2915.     fntptr = (Nlm_FntPtr) Nlm_HandLock (gDialogTextFont);
  2916.     if (fntptr != NULL && fntptr->handle != NULL) {
  2917.       oldFont = SelectObject (Nlm_currentHDC, fntptr->handle);
  2918.     }
  2919.     Nlm_HandUnlock (gDialogTextFont);
  2920.   } else {
  2921.     oldFont = SelectObject (Nlm_currentHDC, GetStockObject (ANSI_FIXED_FONT));
  2922.   }
  2923.   if (oldFont != NULL) {
  2924.     SelectObject (Nlm_currentHDC, oldFont);
  2925.     SetWindowFont (h, oldFont, FALSE);
  2926.   }
  2927.  }
  2928. #else
  2929.     /* dgg way */
  2930.         {
  2931.         Nlm_FontData    fdata;
  2932.         Nlm_GetFontData( gDialogTextFont, &fdata);
  2933.         PostMessage( h, WM_SETFONT, fdata.handle, 0L);
  2934.         }
  2935. #endif
  2936.  
  2937.   }
  2938.   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, gDialogTextFont, gDlogTextHeight, FALSE, FALSE, TRUE, 1, NULL, NULL, tabProc);
  2939.   if (lpfnNewTextProc == NULL) {
  2940.     lpfnNewTextProc = (WNDPROC) MakeProcInstance ((FARPROC) TextProc, Nlm_currentHInst);
  2941.   }
  2942.   if (lpfnOldTextProc == NULL) {
  2943.     lpfnOldTextProc = (WNDPROC) GetWindowLong (h, GWL_WNDPROC);
  2944.   } else if (lpfnOldTextProc != (WNDPROC) GetWindowLong (h, GWL_WNDPROC)) {
  2945.     Nlm_Message (MSG_ERROR, "TextProc subclass error");
  2946.   }
  2947.   SetWindowLong (h, GWL_WNDPROC, (LONG) lpfnNewTextProc);
  2948. #endif
  2949.  
  2950. #ifdef WIN_MOTIF
  2951.   allowTextCallback = FALSE;
  2952.   n = 0;
  2953.   XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
  2954.   XtSetArg (wargs [n], XmNy, (Position) r.top); n++;
  2955.   XtSetArg (wargs [n], XmNwidth, (Dimension) (r.right - r.left)); n++;
  2956.   XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top)); n++;
  2957. #ifdef OS_VMS
  2958.   XtSetArg (wargs [n], XmNmarginHeight, 0); n++;
  2959. #else
  2960.   XtSetArg (wargs [n], XmNmarginHeight, 0); n++;
  2961. #endif
  2962.   XtSetArg (wargs [n], XmNmarginWidth, 0); n++;
  2963.   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  2964.   XtSetArg (wargs [n], XmNshadowThickness, (Dimension) 0); n++;
  2965.   XtSetArg (wargs [n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
  2966.   XtSetArg (wargs [n], XmNfontList, NULL); n++;
  2967.   XtSetArg (wargs [n], XmNhighlightThickness, 0); n++;
  2968.   XtSetArg (wargs [n], XmNautoShowCursorPosition, TRUE); n++;
  2969.   XtSetArg (wargs [n], XmNverifyBell, FALSE); n++;
  2970.   h = XmCreateText (wptr, (String) "", wargs, n);
  2971.   XtOverrideTranslations (h, XtParseTranslationTable ("<Key>Tab: do_tab()"));
  2972.   XtVaSetValues (h, XmNuserData, (XtPointer) t, NULL);
  2973.   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, gDialogTextFont, gDlogTextHeight, FALSE, FALSE, TRUE, 1, NULL, NULL, tabProc);
  2974.   XmTextSetString (h, local);
  2975.   XmTextShowPosition (h, 0);
  2976.   XtAddCallback (h, XmNmodifyVerifyCallback, Nlm_RefreshCallback, (XtPointer) t);
  2977.   XtAddCallback (h, XmNvalueChangedCallback, Nlm_TextCallback, (XtPointer) t);
  2978.   XtAddCallback (h, XmNactivateCallback, Nlm_ReturnCallback, (XtPointer) t);
  2979.   XtAddCallback (h, XmNfocusCallback, Nlm_FocusCallback, (XtPointer) t);
  2980.   XtAddCallback (h, XmNlosingFocusCallback, Nlm_LoseFocusCallback, (XtPointer) t);
  2981.   if (NLM_QUIET) {
  2982.     if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (t))) {
  2983.       XtRealizeWidget (h);
  2984.     }
  2985.   } else {
  2986.     XtRealizeWidget (h);
  2987.   }
  2988.   allowTextCallback = TRUE;
  2989. #endif
  2990.   Nlm_LoadAction ((Nlm_GraphiC) t, (Nlm_ActnProc) actn);
  2991. }
  2992.  
  2993. extern Nlm_TexT Nlm_TextLine(Nlm_GrouP prnt, Nlm_CharPtr dfault,
  2994.                                 Nlm_Int2 charWidth, Nlm_TxtActnProc actn,
  2995.                                 Nlm_TxtActnProc tabProc)
  2996.  
  2997. {
  2998.   Nlm_Int2    cwid;
  2999.   Nlm_Int2    hbounds;
  3000.   Nlm_PoinT   npt;
  3001.   Nlm_RecT    r;
  3002.   Nlm_Int2    swid;
  3003.   Nlm_TexT    t;
  3004.   Nlm_WindoW  tempPort;
  3005.   Nlm_Int2    vbounds;
  3006.  
  3007.   t = NULL;
  3008.   if (prnt != NULL) {
  3009.     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
  3010.     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
  3011.         SelectDialogFont();
  3012.     cwid = charWidth * Nlm_MaxCharWidth();
  3013.     swid = Nlm_StringWidth (dfault);
  3014.     if (cwid > swid) {
  3015.       swid = cwid;
  3016.     }
  3017. #ifdef WIN_MAC
  3018.     hbounds = 0;
  3019.     vbounds = 0;
  3020. #endif
  3021. #ifdef WIN_MSWIN
  3022.     hbounds = 0;
  3023.     vbounds = 0;
  3024. #endif
  3025. #ifdef WIN_MOTIF
  3026.     hbounds = 0;
  3027.     vbounds = 0;
  3028. #endif
  3029.     r.left = npt.x;
  3030.     r.top = npt.y;
  3031.     r.right = r.left + swid + 2 + hbounds * 2;
  3032.     r.bottom = r.top + gDlogTextHeight + vbounds * 2;
  3033.     t = (Nlm_TexT) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r,
  3034.                                    sizeof (Nlm_TextRec), hiddenTextProcs);
  3035.     if (t != NULL) {
  3036.       Nlm_NewTextLine (t, dfault, actn, tabProc);
  3037. #ifdef WIN_MAC
  3038.       Nlm_DoSelect ((Nlm_GraphiC) t, FALSE);
  3039. #endif
  3040.       Nlm_DoAdjustPrnt ((Nlm_GraphiC) t, &r, TRUE, FALSE);
  3041.       Nlm_DoShow ((Nlm_GraphiC) t, TRUE, FALSE);
  3042.     }
  3043.     Nlm_RestorePort (tempPort);
  3044.   }
  3045.   return t;
  3046. }
  3047.  
  3048. #endif /* DCLAP */
  3049.  
  3050.  
  3051. static void Nlm_NewScrollText (Nlm_TexT t, Nlm_Int2 height,
  3052.                                Nlm_FonT font, Nlm_Int2 fnthgt,
  3053.                                Nlm_Boolean wrap, Nlm_TxtActnProc actn)
  3054.  
  3055. {
  3056.   Nlm_TextTool    h;
  3057.   Nlm_BaR         hsb;
  3058.   Nlm_RecT        r;
  3059.   Nlm_BaR         vsb;
  3060.   Nlm_WindowTool  wptr;
  3061. #ifdef WIN_MAC
  3062.   Nlm_RectTool    dtool;
  3063.   Nlm_RectTool    rtool;
  3064.   Nlm_Int2        width;
  3065. #endif
  3066. #ifdef WIN_MSWIN
  3067.   Nlm_FntPtr      fntptr;
  3068.   HFONT           oldFont;
  3069.   Nlm_Uint4       style;
  3070. #endif
  3071. #ifdef WIN_MOTIF
  3072.   Nlm_FntPtr      fntptr;
  3073.   XmFontList      fontlist;
  3074.   Cardinal        n;
  3075.   Arg             wargs [15];
  3076. #endif
  3077.  
  3078.   Nlm_GetRect ((Nlm_GraphiC) t, &r);
  3079.   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) t);
  3080. #ifdef WIN_MAC
  3081.   vsb = NULL;
  3082.   hsb = NULL;
  3083.   r.left = r.right;
  3084.   r.right += Nlm_vScrollBarWidth;
  3085.   vsb = Nlm_VertScrollBar ((Nlm_GraphiC) t, &r, Nlm_VScrollAction);
  3086.   if (! wrap) {
  3087.     Nlm_GetRect ((Nlm_GraphiC) t, &r);
  3088.     r.top = r.bottom;
  3089.     r.bottom += Nlm_hScrollBarHeight;
  3090.     hsb = Nlm_HorizScrollBar ((Nlm_GraphiC) t, &r, Nlm_HScrollAction);
  3091.   }
  3092.   Nlm_GetRect ((Nlm_GraphiC) t, &r);
  3093.   Nlm_InsetRect (&r, 4, 2);
  3094.   if (fnthgt > 0) {
  3095.     height = (r.bottom - r.top + 1) / fnthgt;
  3096.   } else {
  3097.     height = 0;
  3098.   }
  3099.   Nlm_DoSetRange ((Nlm_GraphiC) vsb, height - 1, height - 1, 0, FALSE);
  3100.   r.bottom = r.top + height * fnthgt;
  3101.   Nlm_RecTToRectTool (&r, &rtool);
  3102.   if (! wrap) {
  3103.     width = (r.right - r.left + 1) / Nlm_stdCharWidth;
  3104.     Nlm_DoSetRange ((Nlm_GraphiC) hsb, width - 1, width - 1, 0, FALSE);
  3105.     r.right += HSCROLL_POSITIONS * Nlm_stdCharWidth;
  3106.   }
  3107.   Nlm_RecTToRectTool (&r, &dtool);
  3108.   h = TENew (&dtool, &rtool);
  3109.   Nlm_LoadTextData (t, h, vsb, hsb, wrap, font, fnthgt, FALSE, FALSE, FALSE, height, NULL, NULL, NULL);
  3110. #endif
  3111. #ifdef WIN_MSWIN
  3112.   vsb = NULL;
  3113.   hsb = NULL;
  3114.   r.right += Nlm_vScrollBarWidth;
  3115.   style = WS_CHILD | WS_BORDER | ES_MULTILINE | WS_VSCROLL | ES_AUTOVSCROLL | ES_LEFT;
  3116.   if (! wrap) {
  3117.     style |= WS_HSCROLL | ES_AUTOHSCROLL;
  3118.     r.bottom += Nlm_hScrollBarHeight;
  3119.   }
  3120.   h = CreateWindow ("Edit", "", style,
  3121.                     r.left, r.top, r.right - r.left,
  3122.                     r.bottom - r.top, wptr, (Nlm_HandleTool) t,
  3123.                     Nlm_currentHInst, NULL);
  3124.   if (h != NULL) {
  3125.     SetProp (h, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) t);
  3126.   }
  3127.   oldFont = NULL;
  3128.   if (font != NULL) {
  3129.     fntptr = (Nlm_FntPtr) Nlm_HandLock (font);
  3130.     if (fntptr != NULL && fntptr->handle != NULL) {
  3131.       oldFont = SelectObject (Nlm_currentHDC, fntptr->handle);
  3132.     }
  3133.     Nlm_HandUnlock (font);
  3134.   } else {
  3135.     oldFont = SelectObject (Nlm_currentHDC, GetStockObject (ANSI_FIXED_FONT));
  3136.   }
  3137.   if (oldFont != NULL) {
  3138.     SelectObject (Nlm_currentHDC, oldFont);
  3139.     SetWindowFont (h, oldFont, FALSE);
  3140.   }
  3141.   Nlm_LoadTextData (t, h, vsb, hsb, wrap, font, fnthgt, FALSE, FALSE, FALSE, height, NULL, NULL, NULL);
  3142. #endif
  3143. #ifdef WIN_MOTIF
  3144.   allowTextCallback = FALSE;
  3145.   vsb = NULL;
  3146.   hsb = NULL;
  3147.   r.right += Nlm_vScrollBarWidth;
  3148.   if (! wrap) {
  3149.     r.bottom += Nlm_hScrollBarHeight;
  3150.   }
  3151.   Nlm_InsetRect (&r, 3, 3);
  3152.   fontlist = NULL;
  3153.   if (font != NULL) {
  3154.     fntptr = (Nlm_FntPtr) Nlm_HandLock (font);
  3155.     if (fntptr != NULL && fntptr->handle != NULL) {
  3156.       fontlist = XmFontListCreate (fntptr->handle, XmSTRING_DEFAULT_CHARSET);
  3157.     }
  3158.     Nlm_HandUnlock (font);
  3159.   }
  3160.   n = 0;
  3161.   XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
  3162.   XtSetArg (wargs [n], XmNy, (Position) r.top); n++;
  3163.   XtSetArg (wargs [n], XmNwidth, (Dimension) (r.right - r.left)); n++;
  3164.   XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top)); n++;
  3165.   XtSetArg (wargs [n], XmNmarginHeight, 3); n++;
  3166.   XtSetArg (wargs [n], XmNmarginWidth, 3); n++;
  3167.   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  3168.   XtSetArg (wargs [n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
  3169.   if (wrap) {
  3170.     XtSetArg (wargs [n], XmNscrollHorizontal, FALSE); n++;
  3171.     XtSetArg (wargs [n], XmNwordWrap, TRUE); n++;
  3172.   }
  3173.   XtSetArg (wargs [n], XmNfontList, fontlist); n++;
  3174.   XtSetArg (wargs [n], XmNhighlightThickness, 0); n++;
  3175.   h = XmCreateScrolledText (wptr, (String) "", wargs, n);
  3176.   Nlm_LoadTextData (t, h, vsb, hsb, wrap, font, fnthgt, FALSE, FALSE, FALSE, height, NULL, NULL, NULL);
  3177.   XtAddCallback (h, XmNvalueChangedCallback, Nlm_TextCallback, (XtPointer) t);
  3178.   XtAddCallback (h, XmNfocusCallback, Nlm_FocusCallback, (XtPointer) t);
  3179.   XtAddCallback (h, XmNlosingFocusCallback, Nlm_LoseFocusCallback, (XtPointer) t);
  3180.   XtManageChild (h);
  3181.   if (NLM_QUIET) {
  3182.     if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (t))) {
  3183.       XtRealizeWidget (h);
  3184.     }
  3185.   } else {
  3186.     XtRealizeWidget (h);
  3187.   }
  3188.   allowTextCallback = TRUE;
  3189.   if (fontlist != NULL) {
  3190.     XmFontListFree (fontlist);
  3191.   }
  3192. #endif
  3193.   Nlm_LoadAction ((Nlm_GraphiC) t, (Nlm_ActnProc) actn);
  3194. }
  3195.  
  3196.  
  3197.  
  3198.  
  3199. /*#ifdef DCLAP*/
  3200.  
  3201. extern void Nlm_SetDialogTextFont(Nlm_FonT theFont)
  3202. {
  3203.     gDialogTextFont= theFont; /* dgg -- let users choose font */
  3204. }
  3205. /*#endif*/
  3206.  
  3207. extern Nlm_TexT Nlm_DialogText (Nlm_GrouP prnt, Nlm_CharPtr dfault,
  3208.                                 Nlm_Int2 charWidth, Nlm_TxtActnProc actn)
  3209.  
  3210. {
  3211.   Nlm_Int2    cwid;
  3212.   Nlm_Int2    hbounds;
  3213.   Nlm_PoinT   npt;
  3214.   Nlm_RecT    r;
  3215.   Nlm_Int2    swid;
  3216.   Nlm_TexT    t;
  3217.   Nlm_WindoW  tempPort;
  3218.   Nlm_Int2    vbounds;
  3219.  
  3220.   t = NULL;
  3221.   if (prnt != NULL) {
  3222.     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
  3223.     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
  3224.         SelectDialogFont();
  3225. #ifdef DCLAP
  3226.     cwid = charWidth * Nlm_MaxCharWidth();
  3227. #else
  3228.     cwid = charWidth * Nlm_stdCharWidth;
  3229. #endif
  3230.     swid = Nlm_StringWidth (dfault);
  3231.     if (cwid > swid) {
  3232.       swid = cwid;
  3233.     }
  3234. #ifdef WIN_MAC
  3235.     hbounds = 2;
  3236.     vbounds = 2;
  3237. #endif
  3238. #ifdef WIN_MSWIN
  3239.     hbounds = 3;
  3240. #ifdef DCLAP
  3241.     vbounds = (Nlm_FontHeight() * 3 / 2 - gDlogTextHeight) / 2;
  3242. #else
  3243.     vbounds = (Nlm_stdFontHeight * 3 / 2 - gDlogTextHeight) / 2;
  3244. #endif
  3245. #endif
  3246. #ifdef WIN_MOTIF
  3247.     hbounds = 8;
  3248.     vbounds = 8;
  3249. #endif
  3250.     r.left = npt.x;
  3251.     r.top = npt.y;
  3252.     r.right = r.left + swid + 2 + hbounds * 2;
  3253.     r.bottom = r.top + gDlogTextHeight + vbounds * 2;
  3254.     t = (Nlm_TexT) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r,
  3255.                                    sizeof (Nlm_TextRec), dialogTextProcs);
  3256.     if (t != NULL) {
  3257.       Nlm_NewDialogText (t, dfault, actn);
  3258. #ifdef WIN_MAC
  3259.       Nlm_DoSelect ((Nlm_GraphiC) t, FALSE);
  3260. #endif
  3261.       Nlm_DoAdjustPrnt ((Nlm_GraphiC) t, &r, TRUE, FALSE);
  3262.       Nlm_DoShow ((Nlm_GraphiC) t, TRUE, FALSE);
  3263.     }
  3264.     Nlm_RestorePort (tempPort);
  3265.   }
  3266.   return t;
  3267. }
  3268.  
  3269. extern Nlm_TexT Nlm_HiddenText (Nlm_GrouP prnt, Nlm_CharPtr dfault,
  3270.                                 Nlm_Int2 charWidth, Nlm_TxtActnProc actn,
  3271.                                 Nlm_TxtActnProc tabProc)
  3272.  
  3273. {
  3274.   Nlm_Int2    cwid;
  3275.   Nlm_Int2    hbounds;
  3276.   Nlm_PoinT   npt;
  3277.   Nlm_RecT    r;
  3278.   Nlm_Int2    swid;
  3279.   Nlm_TexT    t;
  3280.   Nlm_WindoW  tempPort;
  3281.   Nlm_Int2    vbounds;
  3282.  
  3283.   t = NULL;
  3284.   if (prnt != NULL) {
  3285.     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
  3286.     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
  3287.         SelectDialogFont();
  3288. #ifdef DCLAP
  3289.     cwid = charWidth * Nlm_MaxCharWidth();
  3290. #else
  3291.     cwid = charWidth * Nlm_stdCharWidth;
  3292. #endif
  3293.     swid = Nlm_StringWidth (dfault);
  3294.     if (cwid > swid) {
  3295.       swid = cwid;
  3296.     }
  3297. #ifdef WIN_MAC
  3298.     hbounds = 0;
  3299.     vbounds = 0;
  3300. #endif
  3301. #ifdef WIN_MSWIN
  3302.     hbounds = 0;
  3303.     vbounds = 0;
  3304. #endif
  3305. #ifdef WIN_MOTIF
  3306.     hbounds = 0;
  3307.     vbounds = 0;
  3308. #endif
  3309.     r.left = npt.x;
  3310.     r.top = npt.y;
  3311.     r.right = r.left + swid + 2 + hbounds * 2;
  3312.     r.bottom = r.top + gDlogTextHeight + vbounds * 2;
  3313.     t = (Nlm_TexT) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r,
  3314.                                    sizeof (Nlm_TextRec), hiddenTextProcs);
  3315.     if (t != NULL) {
  3316.       Nlm_NewHiddenText (t, dfault, actn, tabProc);
  3317. #ifdef WIN_MAC
  3318.       Nlm_DoSelect ((Nlm_GraphiC) t, FALSE);
  3319. #endif
  3320.       Nlm_DoAdjustPrnt ((Nlm_GraphiC) t, &r, TRUE, FALSE);
  3321.       Nlm_DoShow ((Nlm_GraphiC) t, TRUE, FALSE);
  3322.     }
  3323.     Nlm_RestorePort (tempPort);
  3324.   }
  3325.   return t;
  3326. }
  3327.  
  3328. extern Nlm_TexT Nlm_PasswordText (Nlm_GrouP prnt, Nlm_CharPtr dfault,
  3329.                                   Nlm_Int2 charWidth, Nlm_TxtActnProc actn)
  3330.  
  3331. {
  3332.   Nlm_Int2    cwid;
  3333.   Nlm_Int2    hbounds;
  3334.   Nlm_PoinT   npt;
  3335.   Nlm_RecT    r;
  3336.   Nlm_Int2    swid;
  3337.   Nlm_TexT    t;
  3338.   Nlm_WindoW  tempPort;
  3339.   Nlm_Int2    vbounds;
  3340.  
  3341.   t = NULL;
  3342.   if (prnt != NULL) {
  3343.     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
  3344.     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
  3345.         SelectDialogFont();
  3346. #ifdef DCLAP
  3347.     cwid = charWidth * Nlm_MaxCharWidth();
  3348. #else
  3349.     cwid = charWidth * Nlm_stdCharWidth;
  3350. #endif
  3351.     swid = Nlm_StringWidth (dfault);
  3352.     if (cwid > swid) {
  3353.       swid = cwid;
  3354.     }
  3355. #ifdef WIN_MAC
  3356.     hbounds = 2;
  3357.     vbounds = 2;
  3358. #endif
  3359. #ifdef WIN_MSWIN
  3360.     hbounds = 3;
  3361.     vbounds = (Nlm_stdFontHeight * 3 / 2 - gDlogTextHeight) / 2;
  3362. #endif
  3363. #ifdef WIN_MOTIF
  3364.     hbounds = 8;
  3365.     vbounds = 8;
  3366. #endif
  3367.     r.left = npt.x;
  3368.     r.top = npt.y;
  3369.     r.right = r.left + swid + 2 + hbounds * 2;
  3370.     r.bottom = r.top + gDlogTextHeight + vbounds * 2;
  3371.     t = (Nlm_TexT) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r,
  3372.                                    sizeof (Nlm_PasswdRec), passwordTextProcs);
  3373.     if (t != NULL) {
  3374.       Nlm_NewPasswordText (t, dfault, actn);
  3375. #ifdef WIN_MAC
  3376.       Nlm_DoSelect ((Nlm_GraphiC) t, FALSE);
  3377. #endif
  3378.       Nlm_DoAdjustPrnt ((Nlm_GraphiC) t, &r, TRUE, FALSE);
  3379.       Nlm_DoShow ((Nlm_GraphiC) t, TRUE, FALSE);
  3380.     }
  3381.     Nlm_RestorePort (tempPort);
  3382.   }
  3383.   return t;
  3384. }
  3385.  
  3386. extern Nlm_TexT Nlm_ScrollText (Nlm_GrouP prnt, Nlm_Int2 width,
  3387.                                 Nlm_Int2 height, Nlm_FonT font,
  3388.                                 Nlm_Boolean wrap, Nlm_TxtActnProc actn)
  3389.  
  3390. {
  3391.   Nlm_Int2    dwid;
  3392.   Nlm_Int2    fnthgt;
  3393.   Nlm_PoinT   npt;
  3394.   Nlm_RecT    r;
  3395.   Nlm_TexT    t;
  3396.   Nlm_WindoW  tempPort;
  3397.   Nlm_Int2    thgt;
  3398.  
  3399.   t = NULL;
  3400.   if (prnt != NULL) {
  3401.     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
  3402.     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
  3403.     dwid = width * Nlm_stdCharWidth;
  3404.     thgt = height * Nlm_stdLineHeight;
  3405.     if (font == NULL) {
  3406.       font = Nlm_programFont;
  3407.     }
  3408.     Nlm_SelectFont (font);
  3409.     fnthgt = Nlm_LineHeight ();
  3410.     Nlm_LoadRect (&r, npt.x, npt.y, npt.x+dwid+8, npt.y+thgt+4);
  3411.     t = (Nlm_TexT) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r, sizeof (Nlm_TextRec), scrollTextProcs);
  3412.     if (t != NULL) {
  3413.       Nlm_NewScrollText (t, height, font, fnthgt, wrap, actn);
  3414.       r.right += Nlm_vScrollBarWidth;
  3415.       if (! wrap) {
  3416.         r.bottom += Nlm_hScrollBarHeight;
  3417.       }
  3418.       Nlm_DoAdjustPrnt ((Nlm_GraphiC) t, &r, TRUE, FALSE);
  3419.             SelectDialogFont();
  3420.       Nlm_DoShow ((Nlm_GraphiC) t, TRUE, FALSE);
  3421.     }
  3422.     Nlm_RestorePort (tempPort);
  3423.   }
  3424.   return t;
  3425. }
  3426.  
  3427.  
  3428.  
  3429. extern void Nlm_PassPanelClickToText (Nlm_PaneL p, Nlm_TexT t, Nlm_PoinT pt)
  3430.  
  3431. {
  3432. #ifdef WIN_MSWIN
  3433.   Nlm_TextTool  h;
  3434.   UINT          message;
  3435.   WPARAM        wParam;
  3436. #endif
  3437. #ifdef WIN_MOTIF
  3438.   Nlm_TextTool  h;
  3439. #endif
  3440.  
  3441.   if (t != NULL) {
  3442.     Nlm_KillSlateTimer ();
  3443. #ifdef WIN_MAC
  3444.     Nlm_DoClick ((Nlm_GraphiC) t, pt);
  3445. #endif
  3446. #ifdef WIN_MSWIN
  3447.     ReleaseCapture ();
  3448.     h = Nlm_GetTextHandle (t);
  3449.     if (Nlm_dblClick) {
  3450.       message = WM_LBUTTONDBLCLK;
  3451.     } else {
  3452.       message = WM_LBUTTONDOWN;
  3453.     }
  3454.     if (Nlm_shftKey) {
  3455.       wParam = MK_SHIFT;
  3456.     } else {
  3457.       wParam = 0;
  3458.     }
  3459. /*
  3460.     Edit_SetSel (h, 0, 0);
  3461.     if (Nlm_Visible (t) && Nlm_AllParentsVisible (t)) {
  3462.       SetFocus (h);
  3463.       Nlm_DoTextSelect (t);
  3464.     }
  3465. */
  3466.     SendMessage (h, message, Nlm_currentWParam, Nlm_currentLParam);
  3467. #endif
  3468. #ifdef WIN_MOTIF
  3469.   if (Nlm_WindowHasBeenShown (Nlm_ParentWindow ((Nlm_Handle) t))) {
  3470.     allowTextCallback = FALSE;
  3471.     h = Nlm_GetTextHandle (t);
  3472.     XmTextSetSelection (h, (XmTextPosition) 0,
  3473.                         (XmTextPosition) 0, (Time) 0);
  3474.     XmProcessTraversal (h, XmTRAVERSE_CURRENT);
  3475.     XmTextSetHighlight (h, (XmTextPosition) 0,
  3476.                         (XmTextPosition) 0, XmHIGHLIGHT_SELECTED);
  3477.     allowTextCallback = TRUE;
  3478.   }
  3479.   Nlm_DoTextSelect (t);
  3480. #endif
  3481.   }
  3482. }
  3483.  
  3484. #ifdef WIN_MAC
  3485. extern Nlm_Boolean Nlm_RegisterTexts (void)
  3486.  
  3487. {
  3488.   return TRUE;
  3489. }
  3490. #endif
  3491.  
  3492. #ifdef WIN_MSWIN
  3493. extern Nlm_Boolean Nlm_RegisterTexts (void)
  3494.  
  3495. {
  3496.   return TRUE;
  3497. }
  3498. #endif
  3499.  
  3500. #ifdef WIN_MOTIF
  3501. extern Nlm_Boolean Nlm_RegisterTexts (void)
  3502.  
  3503. {
  3504.   XtActionsRec  actions;
  3505.  
  3506.   actions.string = "do_tab";
  3507.   actions.proc = Nlm_TabCallback;
  3508.   XtAppAddActions (Nlm_appContext, &actions, 1);
  3509.   return TRUE;
  3510. }
  3511. #endif
  3512.  
  3513. extern void Nlm_FreeTexts (void)
  3514.  
  3515. {
  3516.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemFree (gphprcsptr);
  3517. }
  3518.  
  3519. extern void Nlm_InitTexts (void)
  3520.  
  3521. {
  3522.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemNew (sizeof (Nlm_GphPrcs) * 4);
  3523.  
  3524.   dialogTextProcs = &(gphprcsptr [0]);
  3525. #ifdef WIN_MAC
  3526.   dialogTextProcs->click = Nlm_DialogTextClick;
  3527.   dialogTextProcs->key = Nlm_DialogKey;
  3528.   dialogTextProcs->draw = Nlm_DrawDialogText;
  3529.   dialogTextProcs->idle = Nlm_IdleText;
  3530. #endif
  3531. #ifdef WIN_MSWIN
  3532.   dialogTextProcs->command = Nlm_DialogTextCommand;
  3533. #endif
  3534. #ifdef WIN_MOTIF
  3535. #endif
  3536.   dialogTextProcs->show = Nlm_ShowText;
  3537.   dialogTextProcs->hide = Nlm_HideText;
  3538.   dialogTextProcs->enable = Nlm_EnableText;
  3539.   dialogTextProcs->disable = Nlm_DisableText;
  3540.   dialogTextProcs->activate = Nlm_ActivateText;
  3541.   dialogTextProcs->deactivate = Nlm_DeactivateText;
  3542.   dialogTextProcs->remove = Nlm_RemoveText;
  3543.   dialogTextProcs->reset = Nlm_ResetText;
  3544.   dialogTextProcs->select = Nlm_TextSelectProc;
  3545.   dialogTextProcs->setTitle = Nlm_SetDialogText;
  3546.   dialogTextProcs->getTitle = Nlm_GetDialogText;
  3547.   dialogTextProcs->setPosition = Nlm_SetTextPosition;
  3548.   dialogTextProcs->getPosition = Nlm_GetTextPosition;
  3549.   dialogTextProcs->gainFocus = Nlm_TextGainFocus;
  3550.   dialogTextProcs->loseFocus = Nlm_TextLoseFocus;
  3551.  
  3552.   hiddenTextProcs = &(gphprcsptr [1]);
  3553. #ifdef WIN_MAC
  3554.   hiddenTextProcs->click = Nlm_DialogTextClick;
  3555.   hiddenTextProcs->key = Nlm_DialogKey;
  3556.   hiddenTextProcs->draw = Nlm_DrawHiddenText;
  3557.   hiddenTextProcs->idle = Nlm_IdleText;
  3558. #endif
  3559. #ifdef WIN_MSWIN
  3560.   hiddenTextProcs->command = Nlm_DialogTextCommand;
  3561. #endif
  3562. #ifdef WIN_MOTIF
  3563. #endif
  3564.   hiddenTextProcs->show = Nlm_ShowText;
  3565.   hiddenTextProcs->hide = Nlm_HideText;
  3566.   hiddenTextProcs->enable = Nlm_EnableText;
  3567.   hiddenTextProcs->disable = Nlm_DisableText;
  3568.   hiddenTextProcs->activate = Nlm_ActivateHiddenText;
  3569.   hiddenTextProcs->deactivate = Nlm_DeactivateText;
  3570.   hiddenTextProcs->remove = Nlm_RemoveText;
  3571.   hiddenTextProcs->reset = Nlm_ResetText;
  3572.   hiddenTextProcs->select = Nlm_TextSelectProc;
  3573.   hiddenTextProcs->setTitle = Nlm_SetDialogText;
  3574.   hiddenTextProcs->getTitle = Nlm_GetDialogText;
  3575.   hiddenTextProcs->setPosition = Nlm_SetHiddenTextPosition;
  3576.   hiddenTextProcs->getPosition = Nlm_GetTextPosition;
  3577.   hiddenTextProcs->gainFocus = Nlm_TextGainFocus;
  3578.   hiddenTextProcs->loseFocus = Nlm_TextLoseFocus;
  3579.  
  3580.   passwordTextProcs = &(gphprcsptr [2]);
  3581. #ifdef WIN_MAC
  3582.   passwordTextProcs->click = Nlm_DialogTextClick;
  3583.   passwordTextProcs->key = Nlm_PasswordKey;
  3584.   passwordTextProcs->draw = Nlm_DrawDialogText;
  3585.   passwordTextProcs->idle = Nlm_IdleText;
  3586. #endif
  3587. #ifdef WIN_MSWIN
  3588.   passwordTextProcs->command = Nlm_PasswordTextCommand;
  3589. #endif
  3590. #ifdef WIN_MOTIF
  3591. #endif
  3592.   passwordTextProcs->show = Nlm_ShowText;
  3593.   passwordTextProcs->hide = Nlm_HideText;
  3594.   passwordTextProcs->enable = Nlm_EnableText;
  3595.   passwordTextProcs->disable = Nlm_DisableText;
  3596.   passwordTextProcs->activate = Nlm_ActivateText;
  3597.   passwordTextProcs->deactivate = Nlm_DeactivateText;
  3598.   passwordTextProcs->remove = Nlm_RemoveText;
  3599.   passwordTextProcs->reset = Nlm_ResetText;
  3600.   passwordTextProcs->select = Nlm_TextSelectProc;
  3601.   passwordTextProcs->setTitle = Nlm_SetPasswordText;
  3602.   passwordTextProcs->getTitle = Nlm_GetPasswordText;
  3603.   passwordTextProcs->setPosition = Nlm_SetTextPosition;
  3604.   passwordTextProcs->getPosition = Nlm_GetTextPosition;
  3605.   passwordTextProcs->gainFocus = Nlm_TextGainFocus;
  3606.   passwordTextProcs->loseFocus = Nlm_TextLoseFocus;
  3607.  
  3608.   scrollTextProcs = &(gphprcsptr [3]);
  3609. #ifdef WIN_MAC
  3610.   scrollTextProcs->click = Nlm_ScrollTextClick;
  3611.   scrollTextProcs->key = Nlm_TextKey;
  3612.   scrollTextProcs->draw = Nlm_DrawScrollText;
  3613.   scrollTextProcs->idle = Nlm_IdleText;
  3614. #endif
  3615. #ifdef WIN_MSWIN
  3616.   scrollTextProcs->command = Nlm_ScrollTextCommand;
  3617. #endif
  3618. #ifdef WIN_MOTIF
  3619. #endif
  3620.   scrollTextProcs->show = Nlm_ShowScrollText;
  3621.   scrollTextProcs->hide = Nlm_HideScrollText;
  3622.   scrollTextProcs->enable = Nlm_EnableText;
  3623.   scrollTextProcs->disable = Nlm_DisableText;
  3624.   scrollTextProcs->activate = Nlm_ActivateScrollText;
  3625.   scrollTextProcs->deactivate = Nlm_DeactivateScrollText;
  3626.   scrollTextProcs->remove = Nlm_RemoveText;
  3627.   scrollTextProcs->reset = Nlm_ResetText;
  3628.   scrollTextProcs->select = Nlm_TextSelectProc;
  3629.   scrollTextProcs->setTitle = Nlm_SetScrollText;
  3630.   scrollTextProcs->getTitle = Nlm_GetScrollText;
  3631.   scrollTextProcs->setPosition = Nlm_SetScrollTextPosition;
  3632.   scrollTextProcs->getPosition = Nlm_GetScrollTextPosition;
  3633.   scrollTextProcs->loseFocus = Nlm_TextLoseFocus;
  3634. }
  3635.