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: 6.39 $
33 *
34 * File Description:
35 *       Vibrant edit text functions
36 *
37 * Modifications:
38 * --------------------------------------------------------------------------
39 *
40 * ==========================================================================
41 */
42 
43 #include <vibtypes.h>
44 #include <vibprocs.h>
45 #include <vibincld.h>
46 
47 #ifdef WIN_MAC
48 #ifdef WIN_MAC_QUARTZ
49 #define Nlm_TextTool TXNObject
50 extern CGRect Nlm_RecTToCGRect(Nlm_RecT r);
51 #else
52 #define Nlm_TextTool TEHandle
53 #endif
54 #endif
55 
56 #ifdef WIN_MSWIN
57 #  define Nlm_TextTool HWND
58 #endif
59 
60 #ifdef WIN_MOTIF
61 #define Nlm_TextTool Widget
62 #endif
63 
64 #define HSCROLL_POSITIONS 100
65 
66 typedef  struct  Nlm_textdata {
67   Nlm_TextTool     handle;
68   Nlm_BaR          vScrollBar;
69   Nlm_BaR          hScrollBar;
70   Nlm_Boolean      wrap;
71   Nlm_FonT         font;
72   Nlm_Int2         texthght;
73   Nlm_Boolean      active;
74   Nlm_Boolean      changed;
75   Nlm_Boolean      hidden;
76   Nlm_Boolean      special;
77   Nlm_Int2         visLines;
78   Nlm_TxtActnProc  select;
79   Nlm_TxtActnProc  deselect;
80   Nlm_TxtActnProc  tabnotify;
81   Nlm_TxtActnProc  returnnotify;
82   Nlm_Boolean      editable;
83 } Nlm_TextData;
84 
85 typedef  struct  Nlm_textrec {
86   Nlm_GraphicRec  graphicR;
87   Nlm_TextData    text;
88 } Nlm_TextRec, PNTR Nlm_TxtPtr;
89 
90 #define MAX_PASSWORD 32
91 typedef  struct  Nlm_passwdrec {
92   Nlm_TextRec  textR;
93   Nlm_Char     password [MAX_PASSWORD];
94 } Nlm_PasswdRec, PNTR Nlm_PwdPtr;
95 
96 Nlm_Boolean Nlm_textScrapFull = FALSE;
97 
98 static Nlm_GphPrcsPtr  gphprcsptr = NULL;
99 
100 static Nlm_GphPrcsPtr  dialogTextProcs;
101 static Nlm_GphPrcsPtr  hiddenTextProcs;
102 static Nlm_GphPrcsPtr  specialTextProcs;
103 static Nlm_GphPrcsPtr  passwordTextProcs;
104 static Nlm_GphPrcsPtr  scrollTextProcs;
105 
106 static Nlm_TexT        recentText = NULL;
107 static Nlm_TextData    recentTextData;
108 
109 static Nlm_TexT        currentText = NULL;
110 
111 #ifdef WIN_MSWIN
112 static WNDPROC         lpfnNewTextProc = NULL;
113 static WNDPROC         lpfnOldTextProc = NULL;
114 static Nlm_Boolean     handlechar;
115 #endif
116 
117 #if defined(WIN_MOTIF) || defined(WIN_MSWIN)
118 static Nlm_Boolean     allowTextCallback = TRUE;
119 #endif
120 
Nlm_LoadTextData(Nlm_TexT t,Nlm_TextTool hdl,Nlm_BaR vbar,Nlm_BaR hbar,Nlm_Boolean wrp,Nlm_FonT fnt,Nlm_Int2 hght,Nlm_Boolean actv,Nlm_Boolean chgd,Nlm_Boolean hidn,Nlm_Boolean spcl,Nlm_Int2 visl,Nlm_TxtActnProc slct,Nlm_TxtActnProc dslct,Nlm_TxtActnProc tabn,Nlm_TxtActnProc rtnn,Nlm_Boolean edtbl)121 static void Nlm_LoadTextData (Nlm_TexT t, Nlm_TextTool hdl,
122                               Nlm_BaR vbar, Nlm_BaR hbar,
123                               Nlm_Boolean wrp, Nlm_FonT fnt,
124                               Nlm_Int2 hght, Nlm_Boolean actv,
125                               Nlm_Boolean chgd, Nlm_Boolean hidn,
126                               Nlm_Boolean spcl, Nlm_Int2 visl,
127                               Nlm_TxtActnProc slct, Nlm_TxtActnProc dslct,
128                               Nlm_TxtActnProc tabn, Nlm_TxtActnProc rtnn,
129                               Nlm_Boolean edtbl)
130 
131 {
132   Nlm_TextData  PNTR tdptr;
133   Nlm_TxtPtr   tp;
134 
135   if (t != NULL) {
136     tp = (Nlm_TxtPtr) Nlm_HandLock (t);
137     tdptr = &(tp->text);
138     tdptr->handle = hdl;
139     tdptr->vScrollBar = vbar;
140     tdptr->hScrollBar = hbar;
141     tdptr->wrap = wrp;
142     tdptr->font = fnt;
143     tdptr->texthght = hght;
144     tdptr->active = actv;
145     tdptr->changed = chgd;
146     tdptr->hidden = hidn;
147     tdptr->special = spcl;
148     tdptr->visLines = visl;
149     tdptr->select = slct;
150     tdptr->deselect = dslct;
151     tdptr->tabnotify = tabn;
152     tdptr->returnnotify = rtnn;
153     tdptr->editable = edtbl;
154     Nlm_HandUnlock (t);
155     recentText = NULL;
156   }
157 }
158 
Nlm_SetTextData(Nlm_TexT t,Nlm_TextData * tdata)159 static void Nlm_SetTextData (Nlm_TexT t, Nlm_TextData * tdata)
160 
161 {
162   Nlm_TxtPtr  tp;
163 
164   if (t != NULL && tdata != NULL) {
165     tp = (Nlm_TxtPtr) Nlm_HandLock (t);
166     tp->text = *tdata;
167     Nlm_HandUnlock (t);
168     recentText = t;
169     recentTextData = *tdata;
170   }
171 }
172 
Nlm_GetTextData(Nlm_TexT t,Nlm_TextData * tdata)173 static void Nlm_GetTextData (Nlm_TexT t, Nlm_TextData * tdata)
174 
175 {
176   Nlm_TxtPtr  tp;
177 
178   if (t != NULL && tdata != NULL) {
179     if (t == recentText && NLM_RISKY) {
180       *tdata = recentTextData;
181     } else {
182       tp = (Nlm_TxtPtr) Nlm_HandLock (t);
183       *tdata = tp->text;
184       Nlm_HandUnlock (t);
185       recentText = t;
186       recentTextData = *tdata;
187     }
188   }
189 }
190 
Nlm_GetTextHandle(Nlm_TexT t)191 static Nlm_TextTool Nlm_GetTextHandle (Nlm_TexT t)
192 
193 {
194   Nlm_TextData  tdata;
195 
196   Nlm_GetTextData (t, &tdata);
197   return tdata.handle;
198 }
199 
Nlm_GetTextVScrollBar(Nlm_TexT t)200 static Nlm_BaR Nlm_GetTextVScrollBar (Nlm_TexT t)
201 
202 {
203   Nlm_TextData  tdata;
204 
205   Nlm_GetTextData (t, &tdata);
206   return tdata.vScrollBar;
207 }
208 
Nlm_GetTextHScrollBar(Nlm_TexT t)209 static Nlm_BaR Nlm_GetTextHScrollBar (Nlm_TexT t)
210 
211 {
212   Nlm_TextData  tdata;
213 
214   Nlm_GetTextData (t, &tdata);
215   return tdata.hScrollBar;
216 }
217 
Nlm_GetTextWrap(Nlm_TexT t)218 static Nlm_Boolean Nlm_GetTextWrap (Nlm_TexT t)
219 
220 {
221   Nlm_TextData  tdata;
222 
223   Nlm_GetTextData (t, &tdata);
224   return tdata.wrap;
225 }
226 
227 #ifdef WIN_MAC
Nlm_GetFontHeight(Nlm_TexT t)228 static Nlm_Int2 Nlm_GetFontHeight (Nlm_TexT t)
229 {
230   Nlm_TextData  tdata;
231   Nlm_GetTextData (t, &tdata);
232   return tdata.texthght;
233 }
234 #endif
235 
Nlm_SetActive(Nlm_TexT t,Nlm_Boolean act)236 static void Nlm_SetActive (Nlm_TexT t, Nlm_Boolean act)
237 
238 {
239   Nlm_TextData  tdata;
240 
241   Nlm_GetTextData (t, &tdata);
242   tdata.active = act;
243   Nlm_SetTextData (t, &tdata);
244 }
245 
Nlm_GetActive(Nlm_TexT t)246 static Nlm_Boolean Nlm_GetActive (Nlm_TexT t)
247 
248 {
249   Nlm_TextData  tdata;
250 
251   Nlm_GetTextData (t, &tdata);
252   return tdata.active;
253 }
254 
255 #ifdef WIN_MAC
Nlm_SetChanged(Nlm_TexT t,Nlm_Boolean chd)256 static void Nlm_SetChanged (Nlm_TexT t, Nlm_Boolean chd)
257 {
258   Nlm_TextData  tdata;
259   Nlm_GetTextData (t, &tdata);
260   tdata.changed = chd;
261   Nlm_SetTextData (t, &tdata);
262 }
263 #endif
264 
265 #ifdef WIN_MOTIF
Nlm_IsHiddenText(Nlm_TexT t)266 static Nlm_Boolean Nlm_IsHiddenText (Nlm_TexT t)
267 
268 {
269   Nlm_TextData  tdata;
270 
271   Nlm_GetTextData (t, &tdata);
272   return tdata.hidden;
273 }
274 #endif
275 
276 #ifndef WIN_MOTIF
Nlm_IsHiddenOrSpecialText(Nlm_TexT t)277 static Nlm_Boolean Nlm_IsHiddenOrSpecialText (Nlm_TexT t)
278 {
279   Nlm_TextData  tdata;
280   Nlm_GetTextData (t, &tdata);
281   return (Nlm_Boolean) (tdata.hidden || tdata.special);
282 }
283 
Nlm_GetVisLines(Nlm_TexT t)284 static Nlm_Int2 Nlm_GetVisLines (Nlm_TexT t)
285 {
286   Nlm_TextData  tdata;
287   Nlm_GetTextData (t, &tdata);
288   return tdata.visLines;
289 }
290 #endif
291 
Nlm_SetTextSelect(Nlm_TexT t,Nlm_TxtActnProc slct,Nlm_TxtActnProc dslct)292 extern void Nlm_SetTextSelect (Nlm_TexT t, Nlm_TxtActnProc slct, Nlm_TxtActnProc dslct)
293 
294 {
295   Nlm_TextData  tdata;
296 
297   if (t != NULL) {
298     Nlm_GetTextData (t, &tdata);
299     tdata.select = slct;
300     tdata.deselect = dslct;
301     Nlm_SetTextData (t, &tdata);
302   }
303 }
304 
305 
Nlm_SetPassword(Nlm_TexT t,Nlm_CharPtr passwd)306 static void Nlm_SetPassword (Nlm_TexT t, Nlm_CharPtr passwd)
307 {
308   if (t != NULL  &&  passwd != NULL)
309     {
310       Nlm_PwdPtr pp = (Nlm_PwdPtr) Nlm_HandLock (t);
311       Nlm_StringNCpy_0((Nlm_CharPtr)pp->password, passwd, MAX_PASSWORD);
312       Nlm_HandUnlock (t);
313     }
314 }
315 
316 
Nlm_GetPassword(Nlm_TexT t,Nlm_CharPtr passwd,size_t maxsize)317 static void Nlm_GetPassword (Nlm_TexT t, Nlm_CharPtr passwd,
318                              size_t maxsize)
319 {
320   if (t != NULL  &&  passwd != NULL)
321     {
322       Nlm_PwdPtr pp = (Nlm_PwdPtr) Nlm_HandLock (t);
323       Nlm_StringNCpy_0(passwd, (Nlm_CharPtr)pp->password, maxsize);
324       Nlm_HandUnlock (t);
325     }
326 }
327 
328 
Nlm_GetPasswordLength(Nlm_TexT t)329 static size_t Nlm_GetPasswordLength (Nlm_TexT t)
330 {
331   Nlm_PwdPtr pp = (Nlm_PwdPtr) Nlm_HandLock (t);
332   size_t len = Nlm_StringLen( pp->password );
333   Nlm_HandUnlock (t);
334   return len;
335 }
336 
337 
Nlm_GetTextEditable(Nlm_TexT t)338 static Nlm_Boolean Nlm_GetTextEditable (Nlm_TexT t)
339 
340 {
341   Nlm_TextData  tdata;
342 
343   Nlm_GetTextData (t, &tdata);
344   return tdata.editable;
345 }
346 
347 
348 #ifdef WIN_MAC
Nlm_GetTextLines(Nlm_TexT t)349 static Nlm_Int2 Nlm_GetTextLines (Nlm_TexT t)
350 
351 {
352   Nlm_TextTool  h;
353   Nlm_Int2      lines;
354 #ifdef WIN_MAC_QUARTZ
355   {
356       ItemCount llines = 0;
357       OSStatus stat = TXNGetLineCount(h, &llines);
358       if (stat != noErr) {
359           llines = 0;
360       }
361       lines = lines;
362   }
363 #else
364   {
365       TEPtr         tptr;
366 
367       h = Nlm_GetTextHandle (t);
368       HLock ((Handle) h);
369       tptr = (TEPtr) *((Handle) h);
370       lines = tptr->nLines;
371       HUnlock ((Handle) h);
372   }
373 #endif
374   return lines;
375 }
376 
Nlm_GetLineHeight(Nlm_TexT t)377 static Nlm_Int2 Nlm_GetLineHeight (Nlm_TexT t)
378 
379 {
380   Nlm_TextTool  h;
381   Nlm_Int2      height;
382 
383   h = Nlm_GetTextHandle (t);
384 #ifdef WIN_MAC_QUARTZ
385   {
386       Fixed lineWidth, lineHeight;
387       OSStatus stat = TXNGetLineMetrics(h, 0, &lineWidth, &lineHeight);
388       if (stat != noErr) {
389           height = 0;
390       } else {
391           float fHeight = FixedToFloat(lineHeight);
392           height = fHeight;
393       }
394   }
395 #else
396   {
397       TEPtr         tptr;
398       HLock ((Handle) h);
399       tptr = (TEPtr) *((Handle) h);
400       height = tptr->lineHeight;
401       HUnlock ((Handle) h);
402   }
403 #endif
404   return height;
405 }
406 
407 #ifndef WIN_MAC_QUARTZ
Nlm_GetInsertionStartLine(Nlm_TexT t)408 static Nlm_Int2 Nlm_GetInsertionStartLine (Nlm_TexT t)
409 
410 {
411   Nlm_TextTool  h;
412   Nlm_Int2      i;
413   short         *lines;
414   Nlm_Int2      numLines;
415   Nlm_Int2      startLoc;
416   TEPtr         tptr;
417 
418   h = Nlm_GetTextHandle (t);
419   HLock ((Handle) h);
420   tptr = (TEPtr) *((Handle) h);
421   numLines = tptr->nLines;
422   startLoc = tptr->selStart;
423   i = 0;
424   lines = &(tptr->lineStarts[0]);
425   while (i < numLines && startLoc > lines [i]) {
426     i++;
427   }
428   HUnlock ((Handle) h);
429   return i;
430 }
431 
Nlm_ScrollToInsertionPoint(Nlm_TexT t)432 static void Nlm_ScrollToInsertionPoint (Nlm_TexT t)
433 
434 {
435   Nlm_BaR   sb;
436   Nlm_Int2  start;
437   Nlm_Int2  val;
438   Nlm_Int2  vis;
439 
440   sb = Nlm_GetTextVScrollBar (t);
441   if (sb != NULL) {
442     start = Nlm_GetInsertionStartLine (t);
443     vis = Nlm_GetVisLines (t);
444     val = Nlm_DoGetValue ((Nlm_GraphiC) sb);
445     if (val + vis < start) {
446       Nlm_DoSetValue ((Nlm_GraphiC) sb, start - (vis / 2), TRUE);
447     } else if (val > start) {
448       Nlm_DoSetValue ((Nlm_GraphiC) sb, start - (vis / 2), TRUE);
449     }
450   }
451 }
452 #endif
453 
Nlm_UpdateScrollBar(Nlm_TexT t)454 static void Nlm_UpdateScrollBar (Nlm_TexT t)
455 
456 {
457   Nlm_Int2  lines;
458   Nlm_Int2  newval;
459   Nlm_BaR   sb;
460   Nlm_Int2  vis;
461 
462   sb = Nlm_GetTextVScrollBar (t);
463   if (sb != NULL) {
464     lines = Nlm_GetTextLines (t);
465     vis = Nlm_GetVisLines (t);
466     newval = 0;
467     if (lines > vis) {
468       newval = lines - vis;
469     }
470     if (newval == 0) {
471       if (Nlm_DoGetValue ((Nlm_GraphiC) sb) > newval) {
472         Nlm_DoSetValue ((Nlm_GraphiC) sb, newval, FALSE);
473       }
474       Nlm_DoReset ((Nlm_GraphiC) sb, FALSE);
475     } else {
476       Nlm_DoSetRange ((Nlm_GraphiC) sb, vis - 1, vis - 1, newval, FALSE);
477       if (Nlm_DoGetValue ((Nlm_GraphiC) sb) > newval) {
478         Nlm_DoSetValue ((Nlm_GraphiC) sb, newval, FALSE);
479       }
480     }
481   }
482   sb = Nlm_GetTextHScrollBar (t);
483   if (sb != NULL) {
484     Nlm_CorrectBarPage (sb, 10, 10);
485     Nlm_CorrectBarMax (sb, HSCROLL_POSITIONS);
486   }
487 }
488 
Nlm_DeactivateBoxesInList(Nlm_TexT t)489 static void Nlm_DeactivateBoxesInList (Nlm_TexT t)
490 {
491   Nlm_WindoW  w;
492   w = Nlm_GetParentWindow ((Nlm_GraphiC) t);
493   Nlm_DoLoseFocus ((Nlm_GraphiC) w, (Nlm_GraphiC) t, FALSE);
494 }
495 #endif
496 
Nlm_DoTextSelect(Nlm_TexT t)497 static void Nlm_DoTextSelect (Nlm_TexT t)
498 
499 {
500   Nlm_TxtActnProc  sel;
501   Nlm_TextData     tdata;
502 
503   if (t != NULL) {
504     Nlm_GetTextData (t, &tdata);
505     sel = tdata.select;
506     if (sel != NULL && currentText != t) {
507       currentText = t;
508       sel (t);
509     }
510   }
511   currentText = t;
512 }
513 
Nlm_DoTextDeselect(Nlm_TexT t)514 static void Nlm_DoTextDeselect (Nlm_TexT t)
515 
516 {
517   Nlm_TxtActnProc  desel;
518   Nlm_TextData     tdata;
519 
520   if (t != NULL) {
521     Nlm_GetTextData (t, &tdata);
522     desel = tdata.deselect;
523     if (desel != NULL) {
524       desel (t);
525     }
526   }
527 }
528 
Nlm_DoTabCallback(Nlm_TexT t)529 static void Nlm_DoTabCallback (Nlm_TexT t)
530 
531 {
532   Nlm_TextData  tdata;
533 
534   Nlm_GetTextData (t, &tdata);
535   if (tdata.tabnotify != NULL) {
536     tdata.tabnotify (t);
537   }
538 }
539 
Nlm_DoReturnCallback(Nlm_TexT t)540 static Nlm_Boolean Nlm_DoReturnCallback (Nlm_TexT t)
541 
542 {
543   Nlm_TextData  tdata;
544 
545   Nlm_GetTextData (t, &tdata);
546   if (tdata.returnnotify != NULL) {
547     tdata.returnnotify (t);
548     return TRUE;
549   }
550   return FALSE;
551 }
552 
Nlm_SelectAText(Nlm_TexT t,Nlm_Int4 begin,Nlm_Int4 end)553 static void Nlm_SelectAText (Nlm_TexT t, Nlm_Int4 begin, Nlm_Int4 end)
554 
555 {
556   Nlm_TextTool  h;
557 #ifdef WIN_MAC
558 #ifndef WIN_MAC_QUARTZ
559   TEPtr         hp;
560   short         len;
561   Nlm_Int4      selStart;
562   Nlm_Int4      selEnd;
563 #endif
564 
565   Nlm_DeactivateBoxesInList (t);
566   h = Nlm_GetTextHandle (t);
567 #ifdef WIN_MAC_QUARTZ
568   TXNSetSelection(h, begin, end);
569 #else
570   HLock ((Handle) h);
571   hp = (TEPtr) *((Handle) h);
572   len = hp->teLength;
573   HUnlock ((Handle) h);
574   selStart = begin;
575   selEnd = end;
576   if (selEnd > (Nlm_Int4) len) {
577     selEnd = (Nlm_Int4) len;
578   }
579   if (Nlm_Visible (t) && Nlm_AllParentsVisible (t)) {
580     TESetSelect (selStart, selEnd, h);
581   }
582   Nlm_SetActive (t, TRUE);
583   Nlm_DoActivate ((Nlm_GraphiC) t, FALSE);
584   Nlm_DoTextSelect (t);
585 #endif
586 #endif
587 #ifdef WIN_MSWIN
588   h = Nlm_GetTextHandle (t);
589   Edit_SetSel (h, begin, end);
590   Edit_ScrollCaret (h);
591   Nlm_SetActive (t, TRUE);
592   Nlm_DoActivate ((Nlm_GraphiC) t, FALSE);
593   Nlm_DoTextSelect (t);
594 #endif
595 #ifdef WIN_MOTIF
596   XmTextPosition  max;
597 
598   if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (t))) {
599     allowTextCallback = FALSE;
600     h = Nlm_GetTextHandle (t);
601     XmProcessTraversal (h, XmTRAVERSE_CURRENT);
602     max = XmTextGetLastPosition (h);
603     if (max > (XmTextPosition) end) {
604       max = (XmTextPosition) end;
605     }
606     if (max > 0)
607       {
608         XmTextSetSelection (h, (XmTextPosition) begin,
609                             (XmTextPosition) max, (Time) 0);
610         XmTextSetHighlight (h, (XmTextPosition) begin,
611                             (XmTextPosition) max, XmHIGHLIGHT_SELECTED);
612       }
613     allowTextCallback = TRUE;
614   }
615   Nlm_DoTextSelect (t);
616 #endif
617 }
618 
Nlm_TextSelectionRange(Nlm_TexT t,Nlm_Int4Ptr begin,Nlm_Int4Ptr end)619 extern Nlm_Boolean Nlm_TextSelectionRange(Nlm_TexT t,
620                                           Nlm_Int4Ptr begin, Nlm_Int4Ptr end)
621 {
622   Nlm_Int4 x_begin, x_end;
623   Nlm_TextTool h = Nlm_GetTextHandle( t );
624   if ( !h )
625     return FALSE;
626 
627   {{
628 #if defined(WIN_MAC)
629 #if defined(WIN_MAC_QUARTZ)
630     TXNGetSelection(h, (TXNOffset*) &x_begin, (TXNOffset*) &x_end);
631 #else
632     TEPtr hp;
633 
634     HLock( (Handle)h );
635     hp = (TEPtr) *( (Handle)h );
636     x_begin = hp->selStart;
637     x_end   = hp->selEnd;
638     HUnlock( (Handle)h );
639 #endif
640 #elif defined(WIN_MSWIN)
641     DWORD dwBegin, dwEnd;
642     SNDMSG(h, EM_GETSEL, (WPARAM)(&dwBegin), (LPARAM)(&dwEnd));
643 
644     x_begin = dwBegin;
645     x_end   = dwEnd;
646 
647 #elif defined(WIN_MOTIF)
648     XmTextPosition left;
649     XmTextPosition right;
650 
651     if (!Nlm_WindowHasBeenShown( Nlm_ParentWindow(t) )  ||
652         !XmTextGetSelectionPosition(h, &left, &right))
653       return FALSE;
654     x_begin = left;
655     x_end   = right;
656 
657 #else
658     return FALSE;
659 #endif
660   }}
661 
662 #if !defined(WIN_MAC)
663   /* MAC implmementation uses Nlm_TextSelectionRange()
664      to get current cursor position even when selection is empty */
665   if (x_begin == x_end)
666     return FALSE;
667 #endif
668 
669   if ( begin )
670     *begin = x_begin;
671   if ( end )
672     *end   = x_end;
673 
674 #if defined(WIN_MAC)
675   /* MAC implmementation uses Nlm_TextSelectionRange()
676      to get current cursor position even when selection is empty */
677   if (x_begin == x_end)
678     return FALSE;
679 #endif
680 
681   return TRUE;
682 }
683 
684 #ifdef WIN_MAC
685 
Nlm_DialogTextClick(Nlm_GraphiC t,Nlm_PoinT pt)686 static Nlm_Boolean Nlm_DialogTextClick (Nlm_GraphiC t, Nlm_PoinT pt)
687 
688 {
689   Nlm_TextTool   h;
690   Nlm_PointTool  ptool;
691   Nlm_RecT       r;
692   Nlm_Boolean    rsult;
693   Nlm_WindoW     w;
694 
695   rsult = FALSE;
696   if (! Nlm_GetTextEditable ((Nlm_TexT) t)) return FALSE;
697 #ifdef WIN_MAC_QUARTZ
698   h = Nlm_GetTextHandle ((Nlm_TexT) t);
699   TXNClick(h, &Nlm_currentEvent);
700 #else
701   Nlm_GetRect (t, &r);
702   if (Nlm_PtInRect (pt, &r)) {
703     Nlm_DeactivateBoxesInList ((Nlm_TexT) t);
704     h = Nlm_GetTextHandle ((Nlm_TexT) t);
705     Nlm_GetRect (t, &r);
706     Nlm_PoinTToPointTool (pt, &ptool);
707     TEClick (ptool, Nlm_shftKey, h);
708     Nlm_SetActive ((Nlm_TexT) t, TRUE);
709     w = Nlm_GetParentWindow (t);
710     Nlm_DoActivate (t, FALSE);
711     do {
712     } while (Nlm_MouseButton ());
713     Nlm_DoTextSelect ((Nlm_TexT) t);
714     rsult = TRUE;
715   }
716 #endif
717   return rsult;
718 }
719 
720 #ifndef WIN_MAC_QUARTZ
Nlm_ScrollTextClick(Nlm_GraphiC t,Nlm_PoinT pt)721 static Nlm_Boolean Nlm_ScrollTextClick (Nlm_GraphiC t, Nlm_PoinT pt)
722 
723 {
724   Nlm_TextTool   h;
725   Nlm_BaR        hsb;
726   Nlm_PointTool  ptool;
727   Nlm_RecT       r;
728   Nlm_Boolean    rsult;
729   Nlm_BaR        vsb;
730   Nlm_WindoW     w;
731   Nlm_Boolean    wrap;
732 
733   rsult = FALSE;
734   Nlm_GetRect (t, &r);
735   wrap = Nlm_GetTextWrap ((Nlm_TexT) t);
736   r.right += Nlm_vScrollBarWidth;
737   if (! wrap) {
738     r.bottom += Nlm_hScrollBarHeight;
739   }
740   if (Nlm_PtInRect (pt, &r)) {
741     vsb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
742     hsb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
743     if (vsb != NULL && Nlm_DoClick ((Nlm_GraphiC) vsb, pt)) {
744     } else if (hsb != NULL && Nlm_DoClick ((Nlm_GraphiC) hsb, pt)) {
745     } else {
746       if (! Nlm_GetTextEditable ((Nlm_TexT) t)) return FALSE;
747       Nlm_DeactivateBoxesInList ((Nlm_TexT) t);
748       h = Nlm_GetTextHandle ((Nlm_TexT) t);
749       r.right -= Nlm_vScrollBarWidth;
750       if (! wrap) {
751         r.bottom -= Nlm_hScrollBarHeight;
752       }
753       Nlm_PoinTToPointTool (pt, &ptool);
754       TEClick (ptool, Nlm_shftKey, h);
755       Nlm_SetActive ((Nlm_TexT) t, TRUE);
756       w = Nlm_GetParentWindow (t);
757       Nlm_DoActivate (t, FALSE);
758       do {
759       } while (Nlm_MouseButton ());
760       Nlm_DoTextSelect ((Nlm_TexT) t);
761       rsult = TRUE;
762     }
763   }
764   return rsult;
765 }
766 #endif
767 
Nlm_DrawDialogText(Nlm_GraphiC t)768 static void Nlm_DrawDialogText (Nlm_GraphiC t)
769 
770 {
771   Nlm_TextTool  h;
772   Nlm_RecT      r;
773   Nlm_RectTool  ttool;
774 
775   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
776 #ifdef WIN_MAC_QUARTZ
777     h = Nlm_GetTextHandle ((Nlm_TexT) t);
778     TXNDrawObject(h, NULL, kTXNDrawItemAllMask );
779 #else
780     Nlm_GetRect (t, &r);
781     if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
782       Nlm_EraseRect (&r);
783       if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t)) {
784         h = Nlm_GetTextHandle ((Nlm_TexT) t);
785         if (Nlm_GetActive ((Nlm_TexT) t)) {
786           TEActivate (h);
787         } else {
788           TEDeactivate (h);
789         }
790         TECalText (h);
791         Nlm_InsetRect (&r, 2, 2);
792         Nlm_RecTToRectTool (&r, &ttool);
793         Nlm_SelectFont (Nlm_systemFont);
794         TEUpdate (&ttool, h);
795         Nlm_InsetRect (&r, -2, -2);
796         Nlm_FrameRect (&r);
797       } else {
798 #ifdef DCLAP
799         h = Nlm_GetTextHandle ((Nlm_TexT) t);
800         TEDeactivate (h);
801         TECalText (h);
802         Nlm_InsetRect (&r, 2, 2);
803         Nlm_RecTToRectTool (&r, &ttool);
804         Nlm_SelectFont (Nlm_systemFont);
805         TEUpdate (&ttool, h);
806         Nlm_InsetRect (&r, -2, -2);
807 #endif
808         Nlm_Dotted ();
809         Nlm_FrameRect (&r);
810         Nlm_Solid ();
811       }
812     }
813 #endif /* WIN_MAC_QUARTZ */
814   }
815 }
816 
Nlm_DrawHiddenText(Nlm_GraphiC t)817 static void Nlm_DrawHiddenText (Nlm_GraphiC t)
818 
819 {
820   Nlm_TextTool  h;
821   Nlm_RecT      r;
822   Nlm_RectTool  ttool;
823 
824   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
825 #ifdef WIN_MAC_QUARTZ
826     h = Nlm_GetTextHandle ((Nlm_TexT) t);
827     TXNDrawObject(h, NULL, kTXNDrawItemAllMask );
828 #else
829     Nlm_GetRect (t, &r);
830     if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
831       Nlm_EraseRect (&r);
832       if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t)) {
833         h = Nlm_GetTextHandle ((Nlm_TexT) t);
834         if (Nlm_GetActive ((Nlm_TexT) t)) {
835           TEActivate (h);
836         } else {
837           TEDeactivate (h);
838         }
839         TECalText (h);
840         Nlm_RecTToRectTool (&r, &ttool);
841         Nlm_SelectFont (Nlm_systemFont);
842         TEUpdate (&ttool, h);
843       }
844     }
845 #endif
846   }
847 }
848 
Nlm_DrawScrollText(Nlm_GraphiC t)849 static void Nlm_DrawScrollText (Nlm_GraphiC t)
850 
851 {
852   Nlm_TextTool  h;
853   Nlm_BaR       hsb;
854   Nlm_RecT      r;
855   Nlm_RectTool  rtool;
856   Nlm_BaR       vsb;
857   Nlm_Boolean   wrap;
858 
859   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
860 #ifdef WIN_MAC_QUARTZ
861     h = Nlm_GetTextHandle ((Nlm_TexT) t);
862     TXNDrawObject(h, NULL, kTXNDrawItemAllMask );
863 #else
864     Nlm_GetRect (t, &r);
865     r.right += Nlm_vScrollBarWidth;
866     wrap = Nlm_GetTextWrap ((Nlm_TexT) t);
867     if (! wrap) {
868       r.bottom += Nlm_hScrollBarHeight;
869     }
870     if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
871       if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t)) {
872         Nlm_FrameRect (&r);
873         vsb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
874         if (vsb != NULL) {
875           Nlm_DoDraw ((Nlm_GraphiC) vsb);
876         }
877         hsb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
878         if (hsb != NULL) {
879           Nlm_DoDraw ((Nlm_GraphiC) hsb);
880         }
881         r.right -= Nlm_vScrollBarWidth;
882         if (! wrap) {
883           r.bottom -= Nlm_hScrollBarHeight;
884         }
885         Nlm_InsetRect (&r, 4, 2);
886         r.bottom = r.top + Nlm_GetVisLines ((Nlm_TexT) t) * Nlm_GetFontHeight ((Nlm_TexT) t);
887         h = Nlm_GetTextHandle ((Nlm_TexT) t);
888         if (Nlm_GetActive ((Nlm_TexT) t)) {
889           TEActivate (h);
890         } else {
891           TEDeactivate (h);
892         }
893         TECalText (h);
894         Nlm_RecTToRectTool (&r, &rtool);
895         Nlm_SelectFont (Nlm_systemFont);
896         TEUpdate (&rtool, h);
897       } else {
898 #ifdef DCLAP
899         h = Nlm_GetTextHandle ((Nlm_TexT) t);
900         TEDeactivate (h);
901         TECalText (h);
902         Nlm_RecTToRectTool (&r, &rtool);
903         Nlm_SelectFont (Nlm_systemFont);
904         TEUpdate (&rtool, h);
905 #else
906         Nlm_EraseRect (&r);
907 #endif
908         Nlm_Dotted ();
909         Nlm_FrameRect (&r);
910         Nlm_Solid ();
911       }
912     }
913 #endif
914   }
915 }
916 
917 
Nlm_TextKey(Nlm_GraphiC t,Nlm_Char ch)918 static Nlm_Boolean Nlm_TextKey (Nlm_GraphiC t, Nlm_Char ch)
919 
920 {
921     Nlm_Boolean   act;
922     Nlm_TextTool  h;
923     Nlm_Boolean   rsult;
924 
925     rsult = FALSE;
926     if (! Nlm_GetTextEditable ((Nlm_TexT) t)) return FALSE;
927     act = Nlm_GetActive ((Nlm_TexT) t);
928     if (act && ! Nlm_cmmdKey) {
929         if (ch != '\0') {
930             h = Nlm_GetTextHandle ((Nlm_TexT) t);
931 #ifdef WIN_MAC_QUARTZ
932             TXNKeyDown(h, &Nlm_currentEvent );
933 #else
934             Nlm_ScrollToInsertionPoint ((Nlm_TexT) t);
935             TEKey (ch, h);
936             TECalText (h);
937             Nlm_UpdateScrollBar ((Nlm_TexT) t);
938             Nlm_ScrollToInsertionPoint ((Nlm_TexT) t);
939 #endif
940             Nlm_DoAction (t);
941             Nlm_SetChanged ((Nlm_TexT) t, TRUE);
942             rsult = TRUE;
943         }
944     }
945     return rsult;
946 }
947 
Nlm_DialogKey(Nlm_GraphiC t,Nlm_Char ch)948 static Nlm_Boolean Nlm_DialogKey (Nlm_GraphiC t, Nlm_Char ch)
949 
950 {
951     Nlm_Boolean  rsult;
952     Nlm_Boolean  act;
953 
954     rsult = FALSE;
955     if (! Nlm_GetTextEditable ((Nlm_TexT) t)) return FALSE;
956     act = Nlm_GetActive ((Nlm_TexT) t);
957     if (act && ! Nlm_cmmdKey) {
958         if (ch == '\t' && Nlm_IsHiddenOrSpecialText ((Nlm_TexT) t)) {
959             Nlm_DoTabCallback ((Nlm_TexT) t);
960             rsult = TRUE;
961         } else if (ch == '\t') {
962             Nlm_DoSendFocus (t, ch);
963             rsult = TRUE;
964         } else if (ch == '\n'  || ch == '\r' || ch == '\3') {
965             rsult = Nlm_DoReturnCallback ((Nlm_TexT) t);
966         } else if (ch != '\0') {
967             rsult = Nlm_TextKey (t, ch);
968         }
969     }
970     return rsult;
971 }
972 
973 #ifndef WIN_MAC_QUARTZ
Nlm_PasswordKey(Nlm_GraphiC t,Nlm_Char ch)974 static Nlm_Boolean Nlm_PasswordKey (Nlm_GraphiC t, Nlm_Char ch)
975 
976 {
977     Nlm_Boolean   act;
978     Nlm_TextTool  h;
979     TEPtr         hp;
980     Nlm_Int2      len;
981     Nlm_Char      password [MAX_PASSWORD];
982     Nlm_RecT      r;
983     Nlm_RectTool  rtool;
984     Nlm_Boolean   rsult;
985     Nlm_Int4      selStart;
986     Nlm_Int4      selEnd;
987 
988     rsult = FALSE;
989     if (! Nlm_GetTextEditable ((Nlm_TexT) t)) return FALSE;
990     act = Nlm_GetActive ((Nlm_TexT) t);
991     if (act && ! Nlm_cmmdKey) {
992         if (ch == '\t') {
993             Nlm_DoSendFocus (t, ch);
994             rsult = TRUE;
995         } else if (ch == '\n'  || ch == '\r' || ch == '\3') {
996         } else if (ch == '\b') {
997             rsult = TRUE;
998             Nlm_SetPassword ((Nlm_TexT) t, "");
999             h = Nlm_GetTextHandle ((Nlm_TexT) t);
1000             selStart = 0;
1001             HLock ((Handle) h);
1002             hp = (TEPtr) *((Handle) h);
1003             selEnd = hp->teLength;
1004             HUnlock ((Handle) h);
1005             Nlm_GetRect (t, &r);
1006             if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
1007                 TESetSelect (selStart, selEnd, h);
1008                 TEDelete (h);
1009                 Nlm_InsetRect (&r, 2, 2);
1010                 Nlm_EraseRect (&r);
1011                 Nlm_RecTToRectTool (&r, &rtool);
1012                 TEUpdate (&rtool, h);
1013             }
1014             Nlm_DoAction (t);
1015         } else if (ch != '\0') {
1016             Nlm_GetPassword ((Nlm_TexT) t, password, sizeof (password));
1017             len = (Nlm_Int2) Nlm_StringLen (password);
1018             if (len < sizeof (password) - 2) {
1019                 password [len] = ch;
1020                 password [len + 1] = '\0';
1021             }
1022             Nlm_SetPassword ((Nlm_TexT) t, password);
1023             rsult = Nlm_TextKey (t, '*');
1024         }
1025     }
1026     return rsult;
1027 }
1028 #endif /* ! WIN_MAC_QUARTZ */
1029 
Nlm_IdleText(Nlm_GraphiC t,Nlm_PoinT pt)1030 static Nlm_Boolean Nlm_IdleText (Nlm_GraphiC t, Nlm_PoinT pt)
1031 
1032 {  Nlm_TextTool  h;
1033 
1034   if (Nlm_GetVisible (t) && Nlm_GetEnabled (t) && Nlm_GetActive ((Nlm_TexT) t)) {
1035     h = Nlm_GetTextHandle ((Nlm_TexT) t);
1036 #ifdef WIN_MAC_QUARTZ
1037     TXNIdle(h);
1038 #else
1039     TEIdle (h);
1040 #endif
1041   }
1042   return TRUE;
1043 }
1044 #endif
1045 
1046 #ifdef WIN_MSWIN
Nlm_DialogTextCommand(Nlm_GraphiC t)1047 static Nlm_Boolean Nlm_DialogTextCommand (Nlm_GraphiC t)
1048 
1049 {
1050   if (Nlm_currentCode == EN_CHANGE && allowTextCallback) {
1051     Nlm_DoAction (t);
1052   }
1053   return TRUE;
1054 }
1055 
Nlm_PasswordTextCommand(Nlm_GraphiC t)1056 static Nlm_Boolean Nlm_PasswordTextCommand (Nlm_GraphiC t)
1057 
1058 {
1059   Nlm_TextTool  h;
1060   Nlm_Char      password [MAX_PASSWORD];
1061 
1062   if (Nlm_currentCode == EN_CHANGE && allowTextCallback) {
1063     h = Nlm_GetTextHandle ((Nlm_TexT) t);
1064     GetWindowText (h, password, sizeof (password) - 2);
1065     Nlm_SetPassword ((Nlm_TexT) t, password);
1066     Nlm_DoAction (t);
1067   }
1068   return TRUE;
1069 }
1070 
Nlm_ScrollTextCommand(Nlm_GraphiC t)1071 static Nlm_Boolean Nlm_ScrollTextCommand (Nlm_GraphiC t)
1072 
1073 {
1074  if (allowTextCallback)
1075    switch (Nlm_currentCode) {
1076      case EN_CHANGE:
1077        Nlm_DoAction (t);
1078        break;
1079      case EN_KILLFOCUS:
1080        Nlm_DoLoseFocus (t, NULL, TRUE);
1081        break;
1082      case EN_SETFOCUS:
1083        Nlm_DoGainFocus (t, 0 /* '\t' */, TRUE);
1084        /* Nlm_SelectText ((Nlm_TexT) t, 0, 0); */
1085        break;
1086    }
1087   return TRUE;
1088 }
1089 #endif
1090 
1091 
Nlm_ShowText(Nlm_GraphiC t,Nlm_Boolean setFlag,Nlm_Boolean savePort)1092 static void Nlm_ShowText (Nlm_GraphiC t, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1093 
1094 {
1095   Nlm_TextTool  h;
1096   Nlm_WindoW    tempPort;
1097 
1098   if (setFlag) {
1099     Nlm_SetVisible (t, TRUE);
1100   }
1101   if (Nlm_GetVisible (t) && Nlm_AllParentsButWindowVisible (t)) {
1102     tempPort = Nlm_SavePortIfNeeded (t, savePort);
1103     h = Nlm_GetTextHandle ((Nlm_TexT) t);
1104 #ifdef WIN_MAC
1105     Nlm_DoDraw (t);
1106 #endif
1107 #ifdef WIN_MSWIN
1108     ShowWindow (h, SW_SHOW);
1109     UpdateWindow (h);
1110 #endif
1111 #ifdef WIN_MOTIF
1112     XtManageChild (h);
1113 #endif
1114     Nlm_RestorePort (tempPort);
1115   }
1116 }
1117 
Nlm_ShowScrollText(Nlm_GraphiC t,Nlm_Boolean setFlag,Nlm_Boolean savePort)1118 static void Nlm_ShowScrollText (Nlm_GraphiC t, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1119 
1120 {
1121   Nlm_TextTool  h;
1122   Nlm_BaR       sb;
1123   Nlm_WindoW    tempPort;
1124 
1125   if (setFlag) {
1126     Nlm_SetVisible (t, TRUE);
1127   }
1128   if (Nlm_GetVisible (t) && Nlm_AllParentsButWindowVisible (t)) {
1129     tempPort = Nlm_SavePortIfNeeded (t, savePort);
1130     sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
1131     if (sb != NULL) {
1132       Nlm_DoShow ((Nlm_GraphiC) sb, TRUE, FALSE);
1133     }
1134     sb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
1135     if (sb != NULL) {
1136       Nlm_DoShow ((Nlm_GraphiC) sb, TRUE, FALSE);
1137     }
1138     h = Nlm_GetTextHandle ((Nlm_TexT) t);
1139 #ifdef WIN_MAC
1140     Nlm_DoDraw (t);
1141 #endif
1142 #ifdef WIN_MSWIN
1143     ShowWindow (h, SW_SHOW);
1144     UpdateWindow (h);
1145 #endif
1146 #ifdef WIN_MOTIF
1147     XtManageChild (XtParent (h));
1148 #endif
1149     Nlm_RestorePort (tempPort);
1150   }
1151 }
1152 
Nlm_HideText(Nlm_GraphiC t,Nlm_Boolean setFlag,Nlm_Boolean savePort)1153 static void Nlm_HideText (Nlm_GraphiC t, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1154 
1155 {
1156   Nlm_TextTool  h;
1157   Nlm_WindoW    tempPort;
1158 #ifdef WIN_MAC
1159   Nlm_RecT      r;
1160 #endif
1161 
1162   if (setFlag) {
1163     Nlm_SetVisible (t, FALSE);
1164   }
1165   tempPort = Nlm_SavePortIfNeeded (t, savePort);
1166   h = Nlm_GetTextHandle ((Nlm_TexT) t);
1167 #ifdef WIN_MAC
1168   if (Nlm_GetAllParentsVisible (t)) {
1169     Nlm_GetRect (t, &r);
1170     Nlm_InsetRect (&r, -1, -1);
1171     Nlm_EraseRect (&r);
1172     Nlm_ValidRect (&r);
1173   }
1174 #endif
1175 #ifdef WIN_MSWIN
1176   ShowWindow (h, SW_HIDE);
1177   UpdateWindow (h);
1178 #endif
1179 #ifdef WIN_MOTIF
1180   XtUnmanageChild (h);
1181 #endif
1182   Nlm_RestorePort (tempPort);
1183 }
1184 
Nlm_HideScrollText(Nlm_GraphiC t,Nlm_Boolean setFlag,Nlm_Boolean savePort)1185 static void Nlm_HideScrollText (Nlm_GraphiC t, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1186 
1187 {
1188   Nlm_TextTool  h;
1189   Nlm_BaR       sb;
1190   Nlm_WindoW    tempPort;
1191 #ifdef WIN_MAC
1192   Nlm_RecT      r;
1193 #endif
1194 
1195   if (setFlag) {
1196     Nlm_SetVisible (t, FALSE);
1197   }
1198   tempPort = Nlm_SavePortIfNeeded (t, savePort);
1199   sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
1200   if (sb != NULL) {
1201     Nlm_DoHide ((Nlm_GraphiC) sb, TRUE, FALSE);
1202   }
1203   sb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
1204   if (sb != NULL) {
1205     Nlm_DoHide ((Nlm_GraphiC) sb, TRUE, FALSE);
1206   }
1207   h = Nlm_GetTextHandle ((Nlm_TexT) t);
1208 #ifdef WIN_MAC
1209   if (Nlm_GetAllParentsVisible (t)) {
1210     Nlm_GetRect (t, &r);
1211     if (sb != NULL) {
1212       r.right += Nlm_vScrollBarWidth;
1213     }
1214     Nlm_InsetRect (&r, -1, -1);
1215     Nlm_EraseRect (&r);
1216     Nlm_ValidRect (&r);
1217   }
1218 #endif
1219 #ifdef WIN_MSWIN
1220   ShowWindow (h, SW_HIDE);
1221   UpdateWindow (h);
1222 #endif
1223 #ifdef WIN_MOTIF
1224   XtUnmanageChild (XtParent (h));
1225 #endif
1226   Nlm_RestorePort (tempPort);
1227 }
1228 
1229 #ifndef WIN_MAC_QUARTZ
Nlm_EnableText(Nlm_GraphiC t,Nlm_Boolean setFlag,Nlm_Boolean savePort)1230 static void Nlm_EnableText (Nlm_GraphiC t, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1231 
1232 {
1233   Nlm_TextTool  h;
1234   Nlm_BaR       sb;
1235   Nlm_WindoW    tempPort;
1236 
1237   if (setFlag) {
1238     Nlm_SetEnabled (t, TRUE);
1239   }
1240   if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t)) {
1241     tempPort = Nlm_SavePortIfNeeded (t, savePort);
1242     sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
1243     if (sb != NULL) {
1244       Nlm_DoEnable ((Nlm_GraphiC) sb, TRUE, FALSE);
1245     }
1246     sb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
1247     if (sb != NULL) {
1248       Nlm_DoEnable ((Nlm_GraphiC) sb, TRUE, FALSE);
1249     }
1250     h = Nlm_GetTextHandle ((Nlm_TexT) t);
1251 #ifdef WIN_MAC
1252     if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
1253       Nlm_DoDraw (t);
1254     }
1255 #endif
1256 #ifdef WIN_MSWIN
1257     EnableWindow (h, TRUE);
1258 #endif
1259 #ifdef WIN_MOTIF
1260     XtVaSetValues (h, XmNsensitive, TRUE, NULL);
1261 #endif
1262     Nlm_RestorePort (tempPort);
1263   }
1264 }
1265 
Nlm_DisableText(Nlm_GraphiC t,Nlm_Boolean setFlag,Nlm_Boolean savePort)1266 static void Nlm_DisableText (Nlm_GraphiC t, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1267 
1268 {
1269   Nlm_TextTool  h;
1270   Nlm_BaR       sb;
1271   Nlm_WindoW    tempPort;
1272 
1273   if (setFlag) {
1274     Nlm_SetEnabled (t, FALSE);
1275   }
1276   tempPort = Nlm_SavePortIfNeeded (t, savePort);
1277   sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
1278   if (sb != NULL) {
1279     Nlm_DoDisable ((Nlm_GraphiC) sb, TRUE, FALSE);
1280   }
1281   sb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
1282   if (sb != NULL) {
1283     Nlm_DoDisable ((Nlm_GraphiC) sb, TRUE, FALSE);
1284   }
1285   h = Nlm_GetTextHandle ((Nlm_TexT) t);
1286 #ifdef WIN_MAC
1287   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
1288     Nlm_DoDraw (t);
1289   }
1290 #endif
1291 #ifdef WIN_MSWIN
1292   EnableWindow (h, FALSE);
1293 #endif
1294 #ifdef WIN_MOTIF
1295   XtVaSetValues (h, XmNsensitive, FALSE, NULL);
1296 #endif
1297   Nlm_RestorePort (tempPort);
1298 }
1299 
1300 
Nlm_ActivateText(Nlm_GraphiC t,Nlm_Boolean savePort)1301 static void Nlm_ActivateText (Nlm_GraphiC t, Nlm_Boolean savePort)
1302 
1303 {
1304 #ifdef WIN_MAC
1305   Nlm_TextTool  h;
1306   Nlm_RecT      r;
1307   Nlm_RectTool  rtool;
1308 #endif
1309 
1310   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
1311     if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t) && Nlm_GetActive ((Nlm_TexT) t)) {
1312 #ifdef WIN_MAC
1313       h = Nlm_GetTextHandle ((Nlm_TexT) t);
1314       Nlm_GetRect (t, &r);
1315       Nlm_InsetRect (&r, 2, 2);
1316       TEActivate (h);
1317       TECalText (h);
1318       Nlm_RecTToRectTool (&r, &rtool);
1319       TEUpdate (&rtool, h);
1320 #endif
1321 #ifdef WIN_MSWIN
1322       Nlm_TextTool h = Nlm_GetTextHandle ((Nlm_TexT) t);
1323       if (t != NULL && h != NULL) {
1324         if (Nlm_Visible (t) && Nlm_AllParentsVisible (t)) {
1325           SetFocus (h);
1326         }
1327       }
1328 #endif
1329 #ifdef WIN_MOTIF
1330 #endif
1331     }
1332   }
1333 }
1334 
Nlm_ActivateHiddenText(Nlm_GraphiC t,Nlm_Boolean savePort)1335 static void Nlm_ActivateHiddenText (Nlm_GraphiC t, Nlm_Boolean savePort)
1336 
1337 {
1338 #ifdef WIN_MAC
1339   Nlm_TextTool  h;
1340   Nlm_RecT      r;
1341   Nlm_RectTool  rtool;
1342 #endif
1343 #ifdef WIN_MSWIN
1344   Nlm_TextTool  h;
1345 #endif
1346 
1347   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
1348     if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t) && Nlm_GetActive ((Nlm_TexT) t)) {
1349 #ifdef WIN_MAC
1350       h = Nlm_GetTextHandle ((Nlm_TexT) t);
1351       Nlm_GetRect (t, &r);
1352       TEActivate (h);
1353       TECalText (h);
1354       Nlm_RecTToRectTool (&r, &rtool);
1355       TEUpdate (&rtool, h);
1356 #endif
1357 #ifdef WIN_MSWIN
1358       h = Nlm_GetTextHandle ((Nlm_TexT) t);
1359       if (t != NULL && h != NULL) {
1360         if (Nlm_Visible (t) && Nlm_AllParentsVisible (t)) {
1361           SetFocus (h);
1362         }
1363       }
1364 #endif
1365     }
1366   }
1367 }
1368 
Nlm_ActivateScrollText(Nlm_GraphiC t,Nlm_Boolean savePort)1369 static void Nlm_ActivateScrollText (Nlm_GraphiC t, Nlm_Boolean savePort)
1370 
1371 {
1372 #ifndef WIN_MOTIF
1373   Nlm_TextTool  h;
1374 #endif
1375 #ifdef WIN_MAC
1376   Nlm_RecT      r;
1377   Nlm_RectTool  rtool;
1378 #endif
1379 
1380   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
1381     if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t) && Nlm_GetActive ((Nlm_TexT) t)) {
1382 #ifdef WIN_MAC
1383       h = Nlm_GetTextHandle ((Nlm_TexT) t);
1384       Nlm_GetRect (t, &r);
1385       Nlm_InsetRect (&r, 4, 2);
1386       r.bottom = r.top + Nlm_GetVisLines ((Nlm_TexT) t) * Nlm_GetFontHeight ((Nlm_TexT) t);
1387       TEActivate (h);
1388       TECalText (h);
1389       Nlm_RecTToRectTool (&r, &rtool);
1390       TEUpdate (&rtool, h);
1391 #endif
1392 #ifdef WIN_MSWIN
1393       h = Nlm_GetTextHandle ((Nlm_TexT) t);
1394       if (t != NULL && h != NULL) {
1395         if (Nlm_Visible (t) && Nlm_AllParentsVisible (t)) {
1396           SetFocus (h);
1397         }
1398       }
1399 #endif
1400     }
1401   }
1402 }
1403 
Nlm_DeactivateText(Nlm_GraphiC t,Nlm_Boolean savePort)1404 static void Nlm_DeactivateText (Nlm_GraphiC t, Nlm_Boolean savePort)
1405 
1406 {
1407 #ifdef WIN_MAC
1408   Nlm_TextTool  h;
1409   Nlm_RecT      r;
1410   Nlm_RectTool  rtool;
1411 
1412   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
1413     if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t)) {
1414       h = Nlm_GetTextHandle ((Nlm_TexT) t);
1415       Nlm_GetRect (t, &r);
1416       Nlm_InsetRect (&r, 2, 2);
1417       TEDeactivate (h);
1418       TECalText (h);
1419       Nlm_RecTToRectTool (&r, &rtool);
1420       TEUpdate (&rtool, h);
1421     }
1422   }
1423 #endif
1424 }
1425 
Nlm_DeactivateScrollText(Nlm_GraphiC t,Nlm_Boolean savePort)1426 static void Nlm_DeactivateScrollText (Nlm_GraphiC t, Nlm_Boolean savePort)
1427 
1428 {
1429 #ifdef WIN_MAC
1430   Nlm_TextTool  h;
1431   Nlm_RecT      r;
1432   Nlm_RectTool  rtool;
1433 
1434   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
1435     if (Nlm_GetEnabled (t) && Nlm_GetAllParentsEnabled (t)) {
1436       h = Nlm_GetTextHandle ((Nlm_TexT) t);
1437       Nlm_GetRect (t, &r);
1438       Nlm_InsetRect (&r, 4, 2);
1439       r.bottom = r.top + Nlm_GetVisLines ((Nlm_TexT) t) * Nlm_GetFontHeight ((Nlm_TexT) t);
1440       TEDeactivate (h);
1441       TECalText (h);
1442       Nlm_RecTToRectTool (&r, &rtool);
1443       TEUpdate (&rtool, h);
1444     }
1445   }
1446 #endif
1447 }
1448 #endif /* ! WIN_MAC_QUARTZ */
1449 
Nlm_ResetText(Nlm_GraphiC t,Nlm_Boolean savePort)1450 static void Nlm_ResetText (Nlm_GraphiC t, Nlm_Boolean savePort)
1451 
1452 {
1453 #ifdef WIN_MAC
1454   Nlm_Int2      delta;
1455   Nlm_TextTool  h;
1456   Nlm_Int2      height;
1457   Nlm_BaR       sb;
1458   Nlm_WindoW    tempPort;
1459   Nlm_Int2      width;
1460 
1461   tempPort = Nlm_SavePortIfNeeded (t, savePort);
1462   h = Nlm_GetTextHandle ((Nlm_TexT) t);
1463 #ifdef WIN_MAC_QUARTZ
1464   TXNSetSelection(h, kTXNStartOffset, kTXNEndOffset);
1465   TXNClear(h);
1466 #else
1467   TESetSelect (0, 32767, h);
1468   TEDelete (h);
1469   sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
1470   if (sb != NULL) {
1471     delta = Nlm_DoGetValue ((Nlm_GraphiC) sb);
1472     height = Nlm_GetLineHeight ((Nlm_TexT) t);
1473     TEScroll (0, delta * height, h);
1474     Nlm_DoReset ((Nlm_GraphiC) sb, FALSE);
1475   }
1476   sb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
1477   if (sb != NULL) {
1478     delta = Nlm_DoGetValue ((Nlm_GraphiC) sb);
1479     width = Nlm_stdCharWidth;
1480     TEScroll (delta * width, 0, h);
1481     Nlm_DoReset ((Nlm_GraphiC) sb, FALSE);
1482   }
1483 #endif
1484   Nlm_RestorePort (tempPort);
1485 #endif
1486 #ifdef WIN_MSWIN
1487   Nlm_TextTool  h;
1488 
1489   h = Nlm_GetTextHandle ((Nlm_TexT) t);
1490   allowTextCallback = FALSE;
1491   SetWindowText (h, "");
1492   allowTextCallback = TRUE;
1493 #endif
1494 #ifdef WIN_MOTIF
1495   Nlm_TextTool  h = Nlm_GetTextHandle ((Nlm_TexT) t);
1496 
1497   allowTextCallback = FALSE;
1498   XmTextSetString (h, NULL);
1499   XmTextShowPosition (h, 0);
1500   allowTextCallback = TRUE;
1501 #endif
1502 }
1503 
Nlm_RemoveText(Nlm_GraphiC t,Nlm_Boolean savePort)1504 static void Nlm_RemoveText (Nlm_GraphiC t, Nlm_Boolean savePort)
1505 
1506 {
1507   Nlm_TextTool  h;
1508   Nlm_WindoW    tempPort;
1509 #ifdef WIN_MAC
1510   Nlm_BaR       sb;
1511 #endif
1512 
1513   tempPort = Nlm_SavePortIfNeeded (t, savePort);
1514   if (currentText == (Nlm_TexT) t) {
1515     currentText = NULL;
1516   }
1517   h = Nlm_GetTextHandle ((Nlm_TexT) t);
1518 #ifdef WIN_MAC
1519 #ifdef WIN_MAC_QUARTZ
1520   TXNDeleteObject(h);
1521 #else
1522   TEDispose (h);
1523   sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
1524   if (sb != NULL) {
1525     Nlm_DoRemove ((Nlm_GraphiC) sb, FALSE);
1526   }
1527   sb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
1528   if (sb != NULL) {
1529     Nlm_DoRemove ((Nlm_GraphiC) sb, FALSE);
1530   }
1531 #endif
1532 #endif
1533 #ifdef WIN_MSWIN
1534   RemoveProp (h, (LPSTR) "Nlm_VibrantProp");
1535   DestroyWindow (h);
1536 #endif
1537 #ifdef WIN_MOTIF
1538   XtDestroyWidget (h);
1539 #endif
1540   Nlm_RemoveLink (t);
1541   recentText = NULL;
1542   Nlm_RestorePort (tempPort);
1543 }
1544 
Nlm_TextSelectProc(Nlm_GraphiC t,Nlm_Boolean savePort)1545 static void Nlm_TextSelectProc (Nlm_GraphiC t, Nlm_Boolean savePort)
1546 
1547 {
1548 #ifdef WIN_MAC
1549   Nlm_Int2      end;
1550   Nlm_TextTool  h;
1551   Nlm_WindoW    tempPort;
1552 #ifndef WIN_MAC_QUARTZ
1553   TEPtr         hp;
1554 #endif
1555 
1556   if (t != NULL) {
1557     tempPort = Nlm_SavePortIfNeeded (t, savePort);
1558     h = Nlm_GetTextHandle ((Nlm_TexT) t);
1559 #ifdef WIN_MAC_QUARTZ
1560     TXNSelectAll(h);
1561 #else
1562     HLock ((Handle) h);
1563     hp = (TEPtr) *((Handle) h);
1564     end = hp->teLength;
1565     HUnlock ((Handle) h);
1566     Nlm_SelectAText ((Nlm_TexT) t, 0, end);
1567 #endif
1568     Nlm_RestorePort (tempPort);
1569   }
1570 #endif
1571 #ifdef WIN_MSWIN
1572   Nlm_WindoW  tempPort;
1573 
1574   if (t != NULL) {
1575     size_t len;
1576     tempPort = Nlm_SavePortIfNeeded (t, savePort);
1577     len = Nlm_TextLength ((Nlm_TexT) t);
1578     Nlm_SelectAText ((Nlm_TexT) t, 0, len);
1579     Nlm_RestorePort (tempPort);
1580   }
1581 #endif
1582 #ifdef WIN_MOTIF
1583   Nlm_WindoW  tempPort;
1584 
1585   if (t != NULL) {
1586     size_t len;
1587     tempPort = Nlm_SavePortIfNeeded (t, savePort);
1588     len = Nlm_TextLength ((Nlm_TexT) t);
1589     Nlm_SelectAText ((Nlm_TexT) t, 0, len);
1590     Nlm_RestorePort (tempPort);
1591   }
1592 #endif
1593 }
1594 
Nlm_TextLength(Nlm_TexT t)1595 extern size_t Nlm_TextLength (Nlm_TexT t)
1596 
1597 {
1598   Nlm_TextTool  h;
1599   size_t        len;
1600 #if defined(WIN_MAC) && ! defined(WIN_MAC_QUARTZ)
1601   TEPtr         hp;
1602 #endif
1603 #ifdef WIN_MOTIF
1604   Nlm_CharPtr   ptr;
1605 #endif
1606 
1607   len = 0;
1608   if (t != NULL) {
1609     h = Nlm_GetTextHandle (t);
1610 #ifdef WIN_MAC
1611 #ifdef WIN_MAC_QUARTZ
1612     len = TXNDataSize(h);
1613 #else
1614     HLock ((Handle) h);
1615     hp = (TEPtr) *((Handle) h);
1616     len = hp->teLength;
1617     HUnlock ((Handle) h);
1618 #endif
1619 #endif
1620 #ifdef WIN_MSWIN
1621     len = (size_t) GetWindowTextLength (h);
1622 #endif
1623 #ifdef WIN_MOTIF
1624     ptr = XmTextGetString (h);
1625     if ( ptr )
1626       {
1627         len = Nlm_StringLen (ptr);
1628         XtFree (ptr);
1629       }
1630 #endif
1631   }
1632   return len;
1633 }
1634 
1635 
Nlm_SelectText(Nlm_TexT t,Nlm_Int4 begin,Nlm_Int4 end)1636 extern void Nlm_SelectText(Nlm_TexT t, Nlm_Int4 begin, Nlm_Int4 end)
1637 {
1638   Nlm_WindoW tempPort;
1639   if ( !t )
1640     return;
1641 
1642   tempPort = Nlm_SavePortIfNeeded((Nlm_GraphiC)t, TRUE);
1643   if (begin < 0)
1644     begin = 0;
1645   if (end < 0)
1646     end = 0;
1647   Nlm_SelectAText((Nlm_TexT)t, begin, end);
1648   Nlm_RestorePort( tempPort );
1649 }
1650 
1651 
Nlm_SetDialogText(Nlm_GraphiC t,Nlm_Int2 item,Nlm_CharPtr title,Nlm_Boolean savePort)1652 static void Nlm_SetDialogText (Nlm_GraphiC t, Nlm_Int2 item,
1653                                Nlm_CharPtr title, Nlm_Boolean savePort)
1654 
1655 {
1656   Nlm_TextTool  h;
1657   Nlm_WindoW    tempPort;
1658 #ifdef WIN_MAC
1659   Nlm_Uint4     len;
1660   Nlm_RecT      r;
1661 #endif
1662 #ifdef WIN_MOTIF
1663   Nlm_CharPtr   str;
1664 #endif
1665 
1666   tempPort = Nlm_SavePortIfNeeded (t, savePort);
1667   h = Nlm_GetTextHandle ((Nlm_TexT) t);
1668 #ifdef WIN_MAC
1669   len = Nlm_StringLen (title);
1670 #ifdef WIN_MAC_QUARTZ
1671   TXNSetData(h, kTXNTextData, title, len, kTXNStartOffset, kTXNEndOffset);
1672 #else
1673   TESetText (title, len, h);
1674   TECalText (h);
1675   Nlm_GetRect (t, &r);
1676   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
1677     Nlm_InsetRect (&r, 1, 1);
1678     Nlm_InvalRect (&r);
1679   }
1680   Nlm_UpdateScrollBar ((Nlm_TexT) t);
1681 #endif
1682 #endif
1683 #ifdef WIN_MSWIN
1684   allowTextCallback = FALSE;
1685   SetWindowText (h, title);
1686   allowTextCallback = TRUE;
1687 #endif
1688 #ifdef WIN_MOTIF
1689   allowTextCallback = FALSE;
1690   str = Nlm_StringSave (title);
1691   XmTextSetString (h, str);
1692   Nlm_MemFree (str);
1693   XmTextShowPosition (h, 0);
1694   allowTextCallback = TRUE;
1695 #endif
1696   Nlm_RestorePort (tempPort);
1697 }
1698 
1699 
Nlm_SetPasswordText(Nlm_GraphiC t,Nlm_Int2 item,Nlm_CharPtr title,Nlm_Boolean savePort)1700 static void Nlm_SetPasswordText (Nlm_GraphiC t, Nlm_Int2 item,
1701                                  Nlm_CharPtr title, Nlm_Boolean savePort)
1702 {
1703   Nlm_TextTool  h        = Nlm_GetTextHandle( (Nlm_TexT)t );
1704   Nlm_WindoW    tempPort = Nlm_SavePortIfNeeded(t, savePort);
1705   Nlm_CharPtr   actual_title;
1706   size_t        len;
1707 
1708   if (title == NULL)
1709     title = "";
1710   Nlm_SetPassword((Nlm_TexT)t, title);
1711   len = Nlm_GetPasswordLength( (Nlm_TexT)t );
1712   actual_title = (Nlm_CharPtr) Nlm_MemNew(len + 1);
1713   Nlm_MemSet(actual_title, '*', len);
1714 
1715 #ifdef WIN_MAC
1716 #ifdef WIN_MAC_QUARTZ
1717   TXNSetData(h, kTXNTextData, title, len, kTXNStartOffset, kTXNEndOffset);
1718 #else
1719   TESetText (actual_title, len, h);
1720   TECalText (h);
1721   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
1722     Nlm_RecT r;
1723     Nlm_GetRect (t, &r);
1724     Nlm_InsetRect (&r, 1, 1);
1725     Nlm_InvalRect (&r);
1726   }
1727   Nlm_UpdateScrollBar ((Nlm_TexT) t);
1728 #endif
1729 #endif
1730 #ifdef WIN_MSWIN
1731   allowTextCallback = FALSE;
1732   SetWindowText (h, actual_title);
1733   allowTextCallback = TRUE;
1734 #endif
1735 #ifdef WIN_MOTIF
1736   allowTextCallback = FALSE;
1737   XmTextSetString    (h, (*actual_title ? actual_title : 0));
1738   XmTextShowPosition         (h, len);
1739   XmTextSetInsertionPosition (h, len);
1740   allowTextCallback = TRUE;
1741 #endif
1742 
1743   Nlm_MemFree( actual_title );
1744   Nlm_RestorePort( tempPort );
1745 }
1746 
1747 
Nlm_SetScrollText(Nlm_GraphiC t,Nlm_Int2 item,Nlm_CharPtr title,Nlm_Boolean savePort)1748 static void Nlm_SetScrollText (Nlm_GraphiC t, Nlm_Int2 item,
1749                                Nlm_CharPtr title, Nlm_Boolean savePort)
1750 
1751 {
1752   Nlm_TextTool  h;
1753   Nlm_WindoW    tempPort;
1754 #ifdef WIN_MAC
1755   Nlm_Uint4     len;
1756   Nlm_RecT      r;
1757 #endif
1758 #ifdef WIN_MSWIN
1759   Nlm_Uint4    count;
1760   Nlm_Uint4     len;
1761   Nlm_CharPtr    tmp, newTitle;
1762 #endif
1763 
1764   tempPort = Nlm_SavePortIfNeeded (t, savePort);
1765   h = Nlm_GetTextHandle ((Nlm_TexT) t);
1766 #ifdef WIN_MAC
1767   len = Nlm_StringLen (title);
1768 #ifdef WIN_MAC_QUARTZ
1769   TXNSetData(h, kTXNTextData, title, len, kTXNStartOffset, kTXNEndOffset);
1770 #else
1771   TESetText (title, len, h);
1772   TECalText (h);
1773   Nlm_GetRect (t, &r);
1774   Nlm_InsetRect (&r, 4, 2);
1775   r.bottom = r.top + Nlm_GetVisLines ((Nlm_TexT) t) * Nlm_GetFontHeight ((Nlm_TexT) t);
1776   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
1777     Nlm_InsetRect (&r, -1, -1);
1778     Nlm_InvalRect (&r);
1779   }
1780   Nlm_UpdateScrollBar ((Nlm_TexT) t);
1781 #endif
1782 #endif
1783 #ifdef WIN_MSWIN
1784   allowTextCallback = FALSE;
1785 
1786   /* count number of newlines */
1787   tmp = title;
1788   count = 0;
1789   for (tmp = title; tmp != NULL && *tmp; ++tmp) {
1790       if (*tmp == '\n')
1791       ++count;
1792   }
1793 
1794   if (count == 0)
1795     SetWindowText (h, title);
1796   else { /* replace UNIX <lf> with DOS <cr><lf> */
1797     len = Nlm_StringLen (title);
1798     newTitle = (Nlm_CharPtr) MemNew(len+count+1);
1799     tmp = newTitle;
1800     for (count=0; count < len; ++count) {
1801     if (title[count] == '\n' && (count == 0 || title[count-1] != '\r'))
1802         *tmp++ = '\r';
1803     *tmp++ = title[count];
1804     }
1805     *tmp = '\0';
1806     SetWindowText (h, newTitle);
1807     MemFree(newTitle);
1808   }
1809 
1810   allowTextCallback = TRUE;
1811 #endif
1812 #ifdef WIN_MOTIF
1813   allowTextCallback = FALSE;
1814   /*
1815      The gcc compiler puts static strings in read only memory.  Motif 1.1 dies
1816      at this point for text objects (Dialog, Hidden and Password) that use the
1817      modifyVerify callback.  In those cases, the strings are copied.
1818   */
1819   XmTextSetString (h, title);
1820   allowTextCallback = TRUE;
1821 #endif
1822   Nlm_RestorePort (tempPort);
1823 }
1824 
Nlm_GetDialogText(Nlm_GraphiC t,Nlm_Int2 item,Nlm_CharPtr title,size_t maxsize)1825 static void Nlm_GetDialogText (Nlm_GraphiC t, Nlm_Int2 item,
1826                                Nlm_CharPtr title, size_t maxsize)
1827 
1828 {
1829   Nlm_TextTool  h;
1830 #ifdef WIN_MAC
1831   Nlm_Char      **chars;
1832   Nlm_Int2      i;
1833   Nlm_Int2      length;
1834   Nlm_Char      *ptr;
1835 #ifndef WIN_MAC_QUARTZ
1836   TEPtr         hp;
1837 #endif
1838 #endif
1839 #ifdef WIN_MOTIF
1840   Nlm_CharPtr   ptr;
1841 #endif
1842 
1843   if (title != NULL && maxsize > 0) {
1844     h = Nlm_GetTextHandle ((Nlm_TexT) t);
1845 #ifdef WIN_MAC
1846     i = 0;
1847 #ifdef WIN_MAC_QUARTZ
1848     TXNGetDataEncoded(h, kTXNStartOffset, kTXNEndOffset, &chars, kTXNTextData);
1849     length = Nlm_StrLen(*chars);
1850 #else
1851     HLock ((Handle) h);
1852     hp = (TEPtr) *((Handle) h);
1853     chars = hp->hText;
1854     length = hp->teLength;
1855     HUnlock ((Handle) h);
1856 #endif
1857     if (length > maxsize - 1) {
1858       length = maxsize - 1;
1859     }
1860     if (chars != NULL) {
1861       HLock ((Handle) chars);
1862       ptr = (Nlm_Char *) *((Handle) chars);
1863       Nlm_StringNCpy (title, ptr, length); /* remains StringNCpy, not _0 */
1864       title [length] = '\0';
1865       HUnlock ((Handle) chars);
1866     }
1867 #endif
1868 #ifdef WIN_MSWIN
1869     GetWindowText (h, title, maxsize);
1870 /*    title [maxsize - 1] = '\0';*/
1871 #endif
1872 #ifdef WIN_MOTIF
1873     ptr = XmTextGetString (h);
1874     Nlm_StringNCpy_0(title, ptr, maxsize);
1875     XtFree (ptr);
1876 #endif
1877   }
1878 }
1879 
Nlm_GetPasswordText(Nlm_GraphiC t,Nlm_Int2 item,Nlm_CharPtr title,size_t maxsize)1880 static void Nlm_GetPasswordText (Nlm_GraphiC t, Nlm_Int2 item,
1881                                  Nlm_CharPtr title, size_t maxsize)
1882 
1883 {
1884   Nlm_GetPassword ((Nlm_TexT) t, title, maxsize);
1885 }
1886 
Nlm_GetScrollText(Nlm_GraphiC t,Nlm_Int2 item,Nlm_CharPtr title,size_t maxsize)1887 static void Nlm_GetScrollText (Nlm_GraphiC t, Nlm_Int2 item,
1888                                Nlm_CharPtr title, size_t maxsize)
1889 
1890 {
1891   Nlm_TextTool  h;
1892 #ifdef WIN_MAC
1893   Nlm_Char      **chars;
1894   Nlm_Int2      i;
1895   Nlm_Int2      length;
1896   Nlm_Char      *ptr;
1897 #ifndef WIN_MAC_QUARTZ
1898   TEPtr         hp;
1899 #endif
1900 #endif
1901 #ifdef WIN_MOTIF
1902   Nlm_CharPtr   ptr;
1903 #endif
1904 
1905   if (title != NULL && maxsize > 0) {
1906     h = Nlm_GetTextHandle ((Nlm_TexT) t);
1907 #ifdef WIN_MAC
1908     i = 0;
1909 #ifdef WIN_MAC_QUARTZ
1910     TXNGetDataEncoded(h, kTXNStartOffset, kTXNEndOffset, &chars, kTXNTextData);
1911     length = Nlm_StrLen(*chars);
1912 #else
1913     HLock ((Handle) h);
1914     hp = (TEPtr) *((Handle) h);
1915     chars = hp->hText;
1916     length = hp->teLength;
1917     HUnlock ((Handle) h);
1918 #endif
1919     if (length > maxsize - 1) {
1920       length = maxsize - 1;
1921     }
1922     HUnlock ((Handle) h);
1923     if (chars != NULL) {
1924       HLock ((Handle) chars);
1925       ptr = (Nlm_Char *) *((Handle) chars);
1926       Nlm_StringNCpy (title, ptr, length); /* remains StringNCpy, not _0 */
1927       title [length] = '\0';
1928       HUnlock ((Handle) chars);
1929     }
1930 #endif
1931 #ifdef WIN_MSWIN
1932     GetWindowText (h, title, maxsize);
1933 /*    title [maxsize - 1] = '\0'; */
1934 #endif
1935 #ifdef WIN_MOTIF
1936     ptr = XmTextGetString (h);
1937     Nlm_StringNCpy_0(title, ptr, maxsize);
1938     XtFree (ptr);
1939 #endif
1940   }
1941 }
1942 
Nlm_CurrentText(void)1943 extern Nlm_TexT Nlm_CurrentText (void)
1944 
1945 {
1946   return currentText;
1947 }
1948 
1949 #ifdef WIN_MAC
1950 
1951 #ifndef WIN_MAC_QUARTZ
Clipboard_TEToDeskScrap()1952 static void Clipboard_TEToDeskScrap()
1953 {
1954   OSErr err;
1955   /* Copy the TE scrap to the desk scrap. */
1956   err = TEToScrap();
1957 }
1958 #endif
1959 
Clipboard_TECut(Nlm_TextTool inTE)1960 static void Clipboard_TECut(Nlm_TextTool inTE)
1961 {
1962 #ifdef WIN_MAC_QUARTZ
1963   TXNCut(inTE);
1964 #else
1965   /* Cut the text into the TE scrap. */
1966   TECut(inTE);
1967   /* Update the desk scrap. */
1968   Clipboard_TEToDeskScrap();
1969 #endif
1970 }
1971 
Clipboard_TECopy(Nlm_TextTool inTE)1972 static void Clipboard_TECopy(Nlm_TextTool inTE)
1973 {
1974 #ifdef WIN_MAC_QUARTZ
1975   TXNCopy(inTE);
1976 #else
1977   /* Copy the text into the TE scrap. */
1978   TECopy(inTE);
1979   /* Update the desk scrap. */
1980   Clipboard_TEToDeskScrap();
1981 #endif
1982 }
1983 
Clipboard_TEPaste(Nlm_TextTool inTE)1984 static void Clipboard_TEPaste(Nlm_TextTool inTE)
1985 {
1986 #ifdef WIN_MAC_QUARTZ
1987   if (TXNIsScrapPastable()) {
1988     TXNPaste(inTE);
1989   }
1990 #else
1991   TEFromScrap();
1992   TEPaste(inTE);
1993 #endif
1994 }
1995 
1996 #endif  /* WIN_MAC */
1997 
Nlm_CutText(Nlm_TexT t)1998 extern void Nlm_CutText (Nlm_TexT t)
1999 
2000 {
2001   Nlm_TextTool  h;
2002 
2003   if (t != NULL) {
2004     h = Nlm_GetTextHandle (t);
2005 #ifdef WIN_MAC
2006     Clipboard_TECut(h);
2007 #endif
2008 #ifdef WIN_MSWIN
2009     allowTextCallback = FALSE;
2010     SendMessage (h, WM_CUT, 0, 0);
2011     allowTextCallback = TRUE;
2012 #endif
2013 #ifdef WIN_MOTIF
2014     allowTextCallback = FALSE;
2015     XmTextCut (h, CurrentTime);
2016     allowTextCallback = TRUE;
2017 #endif
2018     Nlm_DoAction ((Nlm_GraphiC) t);
2019     Nlm_textScrapFull = TRUE;
2020   }
2021 }
2022 
Nlm_CopyText(Nlm_TexT t)2023 extern void Nlm_CopyText (Nlm_TexT t)
2024 
2025 {
2026   Nlm_TextTool  h;
2027 
2028   if (t != NULL) {
2029     h = Nlm_GetTextHandle (t);
2030 #ifdef WIN_MAC
2031     Clipboard_TECopy(h);
2032 #endif
2033 #ifdef WIN_MSWIN
2034     allowTextCallback = FALSE;
2035     SendMessage (h, WM_COPY, 0, 0);
2036     allowTextCallback = TRUE;
2037 #endif
2038 #ifdef WIN_MOTIF
2039     allowTextCallback = FALSE;
2040     XmTextCopy (h, CurrentTime);
2041     allowTextCallback = TRUE;
2042 #endif
2043     Nlm_textScrapFull = TRUE;
2044   }
2045 }
2046 
Nlm_PasteText(Nlm_TexT t)2047 extern void Nlm_PasteText (Nlm_TexT t)
2048 
2049 {
2050   Nlm_TextTool  h;
2051 
2052   if (t != NULL) {
2053     if (! Nlm_GetTextEditable (t)) return;
2054     h = Nlm_GetTextHandle (t);
2055 #ifdef WIN_MAC
2056     Clipboard_TEPaste(h);
2057 #endif
2058 #ifdef WIN_MSWIN
2059     allowTextCallback = FALSE;
2060     SendMessage (h, WM_PASTE, 0, 0);
2061     allowTextCallback = TRUE;
2062 #endif
2063 #ifdef WIN_MOTIF
2064     allowTextCallback = FALSE;
2065     XmTextPaste (h);
2066     allowTextCallback = TRUE;
2067 #endif
2068     Nlm_DoAction ((Nlm_GraphiC) t);
2069   }
2070 }
2071 
Nlm_ClearText(Nlm_TexT t)2072 extern void Nlm_ClearText (Nlm_TexT t)
2073 
2074 {
2075   Nlm_TextTool  h;
2076 
2077   if (t != NULL) {
2078     if (! Nlm_GetTextEditable (t)) return;
2079     h = Nlm_GetTextHandle (t);
2080 #ifdef WIN_MAC
2081 #ifdef WIN_MAC_QUARTZ
2082     TXNClear(h);
2083 #else
2084     TEDelete (h);
2085 #endif
2086 #endif
2087 #ifdef WIN_MSWIN
2088     allowTextCallback = FALSE;
2089     SendMessage (h, WM_CLEAR, 0, 0);
2090     allowTextCallback = TRUE;
2091 #endif
2092 #ifdef WIN_MOTIF
2093     allowTextCallback = FALSE;
2094     XmTextClearSelection (h, CurrentTime);
2095     allowTextCallback = TRUE;
2096 #endif
2097     Nlm_DoAction ((Nlm_GraphiC) t);
2098     Nlm_textScrapFull = TRUE;
2099   }
2100 }
2101 
Nlm_CurrentVisibleText(void)2102 extern Nlm_TexT Nlm_CurrentVisibleText (void)
2103 
2104 {
2105   Nlm_TexT  t;
2106 
2107   t = Nlm_CurrentText ();
2108   if (t != NULL && Nlm_Visible (t) && Nlm_AllParentsVisible (t)) {
2109     return t;
2110   } else {
2111     return NULL;
2112   }
2113 }
2114 
Nlm_StdCutTextProc(Nlm_IteM i)2115 extern void Nlm_StdCutTextProc (Nlm_IteM i)
2116 
2117 {
2118   Nlm_CutText (Nlm_CurrentVisibleText ());
2119 }
2120 
Nlm_StdCopyTextProc(Nlm_IteM i)2121 extern void Nlm_StdCopyTextProc (Nlm_IteM i)
2122 
2123 {
2124   Nlm_CopyText (Nlm_CurrentVisibleText ());
2125 }
2126 
Nlm_StdPasteTextProc(Nlm_IteM i)2127 extern void Nlm_StdPasteTextProc (Nlm_IteM i)
2128 
2129 {
2130   Nlm_PasteText (Nlm_CurrentVisibleText ());
2131 }
2132 
Nlm_StdDeleteTextProc(Nlm_IteM i)2133 extern void Nlm_StdDeleteTextProc (Nlm_IteM i)
2134 
2135 {
2136   Nlm_ClearText (Nlm_CurrentVisibleText ());
2137 }
2138 
2139 #ifdef WIN_MSWIN
2140 /* Message cracker functions */
2141 
MyCls_OnChar(HWND hwnd,UINT ch,int cRepeat)2142 static void MyCls_OnChar (HWND hwnd, UINT ch, int cRepeat)
2143 
2144 {
2145   Nlm_Boolean  ishidden;
2146   Nlm_Boolean  iseditable;
2147   Nlm_TexT     t;
2148   Nlm_TextTool h;
2149 
2150   t = (Nlm_TexT) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
2151   h = Nlm_GetTextHandle(t);
2152   handlechar = FALSE;
2153   ishidden = Nlm_IsHiddenOrSpecialText ((Nlm_TexT) t);
2154   iseditable = Nlm_GetTextEditable(t);
2155   if (ch == '\t' && ishidden) {
2156     Nlm_DoTabCallback (t);
2157   } else if (ch == '\1') {
2158     /* control-A should select all text */
2159     if (h) {
2160       SNDMSG(h, EM_SETSEL, (WPARAM)(0), (LPARAM)(MAKELONG(0, 0xffff)));
2161     }
2162   } else if (ch == '\t'  && !Nlm_ctrlKey && iseditable && (GetWindowLongPtr(hwnd, GWL_STYLE) & ES_MULTILINE)) {
2163     /* editable multiline boxes accept tab as input character not as focus change to stay
2164        consistent with behavior on MOTIF */
2165     handlechar = TRUE;
2166   } else if (ch == '\t') {
2167     Nlm_DoSendFocus ((Nlm_GraphiC) t, (Nlm_Char) ch);
2168   } else if ((ch == '\n' || ch == '\r') && ishidden) {
2169     Nlm_DoReturnCallback (t);
2170   } else if ((ch == '\n' || ch == '\r') && iseditable) {
2171     if (GetWindowLongPtr(hwnd, GWL_STYLE) & ES_MULTILINE) {
2172     /* multiline edit box */
2173     if (Nlm_ctrlKey)
2174         /* Ctrl-Enter goes to dialog box buttons */
2175             Nlm_DoSendFocus ((Nlm_GraphiC) t, (Nlm_Char) ch);
2176     else
2177         /* plain Enter goes as character to the edit field */
2178         handlechar = TRUE;
2179     }
2180     else
2181     Nlm_DoSendFocus ((Nlm_GraphiC) t, (Nlm_Char) ch);
2182   } else if (!iseditable && ch == '\3') { /* pass Ctrl-C ("Copy") to default handler */
2183     handlechar = TRUE;
2184   } else if (iseditable) {
2185     handlechar = TRUE;
2186   }
2187 }
2188 
MyCls_OnSetFocus(HWND hwnd,HWND hwndOldFocus)2189 static void MyCls_OnSetFocus (HWND hwnd, HWND hwndOldFocus)
2190 
2191 {
2192   Nlm_TexT  t;
2193 
2194   t = (Nlm_TexT) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
2195   Nlm_SetActive (t, TRUE);
2196   Nlm_DoTextSelect (t);
2197 }
2198 
MyCls_OnKillFocus(HWND hwnd,HWND hwndNewFocus)2199 static void MyCls_OnKillFocus (HWND hwnd, HWND hwndNewFocus)
2200 
2201 {
2202   Nlm_TexT  t;
2203 
2204   t = (Nlm_TexT) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
2205   if (Nlm_GetActive (t)) {
2206     Nlm_DoTextDeselect (t);
2207   }
2208   /*
2209   currentText = NULL;
2210   */
2211 }
2212 
TextProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)2213 static LRESULT CALLBACK EXPORT TextProc (HWND hwnd, UINT message,
2214                                   WPARAM wParam, LPARAM lParam)
2215 
2216 {
2217   Nlm_TexT  t;
2218   BOOL      call_win_proc = TRUE;
2219   LRESULT   rsult = 0;
2220   HDC       tempHDC;
2221   HWND      tempHWnd;
2222 
2223   if ( Nlm_VibrantDisabled() )
2224     return CallWindowProc (lpfnOldTextProc, hwnd, message, wParam, lParam);
2225 
2226   tempHWnd = Nlm_currentHWnd;
2227   tempHDC = Nlm_currentHDC;
2228   t = (Nlm_TexT) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
2229   Nlm_theWindow = Nlm_GetParentWindow ((Nlm_GraphiC) t);
2230   Nlm_currentHWnd = GetParent (hwnd);
2231   Nlm_currentHDC = Nlm_ParentWindowPort ((Nlm_GraphiC) t);
2232   Nlm_currentWindowTool = hwnd;
2233   Nlm_currentKey = '\0';
2234   Nlm_currentWParam = wParam;
2235   Nlm_currentLParam = lParam;
2236   Nlm_cmmdKey = FALSE;
2237   Nlm_optKey = FALSE;
2238   Nlm_ctrlKey = (Nlm_Boolean) ((GetKeyState (VK_CONTROL) & 0x8000) != 0);
2239   Nlm_shftKey = (Nlm_Boolean) ((GetKeyState (VK_SHIFT)   & 0x8000) != 0);
2240   Nlm_dblClick = FALSE;
2241 
2242   switch ( message ) {
2243     case WM_KEYDOWN:
2244       if(!Nlm_GetTextEditable(t) && Nlm_KeydownToChar( wParam ) == NLM_DEL)
2245       {
2246       call_win_proc = FALSE;
2247       break;
2248       }
2249       call_win_proc = !(Nlm_GetVisLines(t) == 1  &&
2250                         Nlm_ProcessKeydown((Nlm_GraphiC)t,
2251                                            wParam, VERT_PAGE|VERT_ARROW));
2252       break;
2253     case WM_CHAR:
2254       HANDLE_WM_CHAR(hwnd, wParam, lParam, MyCls_OnChar);
2255       call_win_proc = handlechar;
2256       break;
2257     case WM_SETFOCUS:
2258       HANDLE_WM_SETFOCUS (hwnd, wParam, lParam, MyCls_OnSetFocus);
2259       break;
2260     case WM_KILLFOCUS:
2261       HANDLE_WM_KILLFOCUS (hwnd, wParam, lParam, MyCls_OnKillFocus);
2262       break;
2263     case WM_PASTE:
2264       if ( !Nlm_GetTextEditable(t) )
2265       {
2266       call_win_proc = FALSE;
2267       break;
2268       }
2269       if ( !(GetWindowLongPtr(hwnd, GWL_STYLE) & ES_MULTILINE) ) {
2270         LPSTR text = NULL, str;
2271         HANDLE h_text;
2272         VERIFY ( OpenClipboard(hwnd) );
2273         if (IsClipboardFormatAvailable(CF_TEXT)  &&
2274             (h_text = GetClipboardData(CF_TEXT)) != NULL) {
2275           str = GlobalLock(h_text);
2276           if (str  &&  *str  &&  (text = malloc(strlen(str)+1)) != NULL)
2277             strcpy(text, str);
2278           GlobalUnlock(h_text);
2279         }
2280         VERIFY ( CloseClipboard() );
2281         if ( !text )
2282           break;  /* no suitable data found in the clipboard */
2283 
2284         for (str = text;  *str;  str++)
2285           if ( !isprint((unsigned char)*str) ) {
2286             *str = ' ';
2287             call_win_proc = FALSE;
2288           }
2289         if ( !call_win_proc ) { /* the pasted text contains non-print. chars */
2290           Edit_ReplaceSel(hwnd, text);
2291         }
2292         free(text);
2293       }
2294   } /* switch (message) */
2295 
2296   if ( call_win_proc )
2297     rsult = CallWindowProc(lpfnOldTextProc, hwnd, message, wParam, lParam);
2298 
2299   Nlm_currentHWnd = tempHWnd;
2300   Nlm_currentHDC = tempHDC;
2301   Nlm_currentWindowTool = tempHWnd;
2302   return rsult;
2303 }
2304 #endif
2305 
Nlm_TextGainFocus(Nlm_GraphiC t,Nlm_Char ch,Nlm_Boolean savePort)2306 static Nlm_GraphiC Nlm_TextGainFocus (Nlm_GraphiC t, Nlm_Char ch, Nlm_Boolean savePort)
2307 
2308 {
2309 #ifdef WIN_MAC
2310   Nlm_TextTool  h;
2311   Nlm_Int2      len;
2312   Nlm_GraphiC   rsult;
2313 
2314   rsult = NULL;
2315   if (ch == '\t' && Nlm_GetVisible (t) && Nlm_GetEnabled (t)) {
2316     h = Nlm_GetTextHandle ((Nlm_TexT) t);
2317     Nlm_SetActive ((Nlm_TexT) t, TRUE);
2318     Nlm_TextSelectProc(t, savePort);
2319     rsult = t;
2320   }
2321   return rsult;
2322 #endif
2323 #ifdef WIN_MSWIN
2324   Nlm_GraphiC   rsult;
2325 
2326   rsult = NULL;
2327   if (ch == '\t' && Nlm_GetVisible (t) && Nlm_GetEnabled (t)) {
2328     Nlm_TextTool h = Nlm_GetTextHandle ((Nlm_TexT) t);
2329     Nlm_SetActive ((Nlm_TexT) t, TRUE);
2330     if (GetWindowLongPtr(h, GWL_STYLE) & ES_MULTILINE) {
2331     /* multiline edit box */
2332     Nlm_Int4 begin = 0, end = 0;
2333     Nlm_TextSelectionRange((Nlm_TexT) t, &begin, &end);
2334     Nlm_SelectAText ((Nlm_TexT) t, begin, end);
2335     } else {
2336         /* singleline edit box - make it consistent with MOTIF by setting len = 0
2337            which just sets the cursor pos to the beginning and does not highlight
2338            the text
2339         */
2340         size_t len = 0;  /* Nlm_TextLength ((Nlm_TexT) t); */
2341     Nlm_SelectAText ((Nlm_TexT) t, 0, len);
2342     }
2343     rsult = t;
2344   }
2345   return rsult;
2346 #endif
2347 #ifdef WIN_MOTIF
2348   Nlm_GraphiC   rsult;
2349 
2350   rsult = NULL;
2351   if (ch == '\t' && Nlm_GetVisible (t) && Nlm_GetEnabled (t)) {
2352     size_t len;
2353     Nlm_SetActive ((Nlm_TexT) t, TRUE);
2354     len = Nlm_TextLength ((Nlm_TexT) t);
2355     Nlm_SelectAText ((Nlm_TexT) t, 0, len);
2356     rsult = t;
2357   }
2358   return rsult;
2359 #endif
2360 }
2361 
Nlm_TextLoseFocus(Nlm_GraphiC t,Nlm_GraphiC excpt,Nlm_Boolean savePort)2362 static void Nlm_TextLoseFocus (Nlm_GraphiC t, Nlm_GraphiC excpt, Nlm_Boolean savePort)
2363 
2364 {
2365 #ifndef WIN_MAC_QUARTZ
2366   Nlm_WindoW  tempPort;
2367 
2368   if (t != excpt) {
2369     if (Nlm_GetActive ((Nlm_TexT) t)) {
2370       Nlm_DoTextDeselect ((Nlm_TexT) t);
2371     }
2372     Nlm_SetActive ((Nlm_TexT) t, FALSE);
2373     tempPort = Nlm_SavePortIfNeeded (t, savePort);
2374     Nlm_DeactivateText (t, FALSE);
2375     Nlm_RestorePort (tempPort);
2376   }
2377 #endif
2378 }
2379 
2380 #ifdef WIN_MAC
Nlm_InvalText(Nlm_GraphiC t)2381 static void Nlm_InvalText (Nlm_GraphiC t)
2382 
2383 {
2384   Nlm_RecT  r;
2385 
2386   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
2387     Nlm_GetRect (t, &r);
2388     Nlm_InsetRect (&r, -1, -1);
2389     Nlm_InvalRect (&r);
2390   }
2391 }
2392 
Nlm_InvalScrollText(Nlm_GraphiC t)2393 static void Nlm_InvalScrollText (Nlm_GraphiC t)
2394 
2395 {
2396   Nlm_RecT  r;
2397 
2398   if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
2399     Nlm_GetRect (t, &r);
2400     r.right += Nlm_vScrollBarWidth;
2401     if (! Nlm_GetTextWrap ((Nlm_TexT) t)) {
2402       r.bottom += Nlm_hScrollBarHeight;
2403     }
2404     Nlm_InsetRect (&r, -1, -1);
2405     Nlm_InvalRect (&r);
2406   }
2407 }
2408 #endif
2409 
2410 
Nlm_SetTextPosition(Nlm_GraphiC t,Nlm_RectPtr r,Nlm_Boolean savePort,Nlm_Boolean force)2411 static void Nlm_SetTextPosition (Nlm_GraphiC t, Nlm_RectPtr r,
2412                                  Nlm_Boolean savePort, Nlm_Boolean force)
2413 {
2414   Nlm_TextTool  h;
2415   Nlm_RecT      oldRect;
2416   Nlm_WindoW    tempPort;
2417   Nlm_RecT      tr;
2418 #ifdef WIN_MAC
2419 #ifndef WIN_MAC_QUARTZ
2420   TEPtr         hp;
2421 #endif
2422   Nlm_RectTool  rtool;
2423 #endif
2424 
2425   if (r == NULL)  return;
2426 
2427   if ( !Nlm_GetRealized( t ) )
2428     {
2429       Nlm_SetRect (t, r);
2430       return;
2431     }
2432 
2433   Nlm_DoGetPosition (t, &oldRect);
2434   if (!force  &&  Nlm_EqualRect(r, &oldRect))  return;
2435 
2436   tempPort = Nlm_SavePortIfNeeded (t, savePort);
2437   h = Nlm_GetTextHandle ((Nlm_TexT) t);
2438 #ifdef WIN_MAC
2439   Nlm_InvalText (t);
2440 #endif
2441   tr = *r;
2442 #ifdef WIN_MAC
2443 #ifdef WIN_MAC_QUARTZ
2444   Nlm_RecTToRectTool (&tr, &rtool);
2445   TXNSetFrameBounds(h, rtool.top, rtool.left, rtool.bottom, rtool.right, 0);
2446 #else
2447   Nlm_InsetRect (&tr, 2, 2);
2448   Nlm_RecTToRectTool (&tr, &rtool);
2449   HLock ((Handle) h);
2450   hp = (TEPtr) *((Handle) h);
2451   hp->destRect = rtool;
2452   hp->viewRect = rtool;
2453   HUnlock ((Handle) h);
2454   Nlm_SetRect (t, r);
2455   Nlm_InvalText (t);
2456 #endif
2457 #endif
2458 #ifdef WIN_MSWIN
2459   MoveWindow (h, tr.left, tr.top, tr.right - tr.left, tr.bottom - tr.top, TRUE);
2460   Nlm_SetRect (t, r);
2461   UpdateWindow (h);
2462 #endif
2463 #ifdef WIN_MOTIF
2464   allowTextCallback = FALSE;
2465   XtVaSetValues (h,
2466        XmNx, (Position) (tr.left + 1),
2467        XmNy, (Position) (tr.top  + 1),
2468        XmNwidth,  (Dimension) (tr.right - tr.left),
2469        XmNheight, (Dimension) (tr.bottom - tr.top),
2470        NULL);
2471   Nlm_SetRect (t, r);
2472   allowTextCallback = TRUE;
2473 #endif
2474 
2475   Nlm_RestorePort (tempPort);
2476 }
2477 
2478 
Nlm_SetHiddenTextPosition(Nlm_GraphiC t,Nlm_RectPtr r,Nlm_Boolean savePort,Nlm_Boolean force)2479 static void Nlm_SetHiddenTextPosition (Nlm_GraphiC t, Nlm_RectPtr r,
2480                     Nlm_Boolean savePort, Nlm_Boolean force)
2481 {
2482   Nlm_TextTool  h;
2483   Nlm_RecT      oldRect;
2484   Nlm_WindoW    tempPort;
2485   Nlm_RecT      tr;
2486 #ifdef WIN_MAC
2487 #ifndef WIN_MAC_QUARTZ
2488   TEPtr         hp;
2489 #endif
2490   Nlm_RectTool  rtool;
2491 #endif
2492 
2493   if (r == NULL)  return;
2494 
2495   if ( !Nlm_GetRealized( t ) )
2496     {
2497       Nlm_SetRect (t, r);
2498       return;
2499     }
2500 
2501   Nlm_DoGetPosition (t, &oldRect);
2502   if (!force  &&  Nlm_EqualRect(r, &oldRect))  return;
2503 
2504   tempPort = Nlm_SavePortIfNeeded (t, savePort);
2505   h = Nlm_GetTextHandle ((Nlm_TexT) t);
2506 #ifdef WIN_MAC
2507   Nlm_InvalText (t);
2508 #endif
2509   tr = *r;
2510 #ifdef WIN_MAC
2511   Nlm_RecTToRectTool (&tr, &rtool);
2512 #ifdef WIN_MAC_QUARTZ
2513   CGRect viewCG = Nlm_RectQDToCG (rtool);
2514   CGRect destCG = Nlm_RectQDToCG (rtool);
2515   TXNSetHIRectBounds (h, &viewCG, &destCG, 1);
2516 #else
2517   HLock ((Handle) h);
2518   hp = (TEPtr) *((Handle) h);
2519   hp->destRect = rtool;
2520   hp->viewRect = rtool;
2521   HUnlock ((Handle) h);
2522 #endif
2523   Nlm_SetRect (t, r);
2524   Nlm_InvalText (t);
2525 #endif
2526 #ifdef WIN_MSWIN
2527   MoveWindow (h, tr.left, tr.top, tr.right - tr.left, tr.bottom - tr.top, TRUE);
2528   Nlm_SetRect (t, r);
2529   UpdateWindow (h);
2530 #endif
2531 #ifdef WIN_MOTIF
2532   allowTextCallback = FALSE;
2533   XtVaSetValues (h,
2534          XmNx, (Position) tr.left + 1,
2535          XmNy, (Position) tr.top  + 1,
2536          XmNwidth,  (Dimension) (tr.right - tr.left),
2537          XmNheight, (Dimension) (tr.bottom - tr.top),
2538          NULL);
2539   Nlm_SetRect (t, r);
2540   allowTextCallback = TRUE;
2541 #endif
2542 
2543   Nlm_RestorePort (tempPort);
2544 }
2545 
2546 
Nlm_ResetVisLines(Nlm_TexT t)2547 static void Nlm_ResetVisLines (Nlm_TexT t)
2548 
2549 {
2550   Nlm_RecT      r;
2551   Nlm_TextData  tdata;
2552 
2553   Nlm_GetTextData (t, &tdata);
2554   Nlm_GetRect ((Nlm_GraphiC) t, &r);
2555   Nlm_InsetRect (&r, 4, 2);
2556   if (tdata.texthght > 0) {
2557     tdata.visLines = (Nlm_Int2)((r.bottom - r.top + 1) / tdata.texthght);
2558   } else {
2559     tdata.visLines = 0;
2560   }
2561   Nlm_SetTextData (t, &tdata);
2562 }
2563 
2564 
Nlm_SetScrollTextOffset(Nlm_GraphiC t,Nlm_Int2 horiz,Nlm_Int2 vert,Nlm_Boolean savePort)2565 static void Nlm_SetScrollTextOffset (Nlm_GraphiC t, Nlm_Int2 horiz,
2566                                      Nlm_Int2 vert, Nlm_Boolean savePort)
2567 
2568 {
2569 #ifdef WIN_MAC
2570   Nlm_BaR  sb;
2571 
2572   sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
2573   if (sb != NULL) {
2574     Nlm_DoSetValue ((Nlm_GraphiC) sb, vert, savePort);
2575   }
2576 #endif
2577 #ifdef WIN_MSWIN
2578   Nlm_TextTool  h;
2579 
2580   h = Nlm_GetTextHandle ((Nlm_TexT) t);
2581   PostMessage (h, WM_VSCROLL, MAKEWPARAM (SB_THUMBPOSITION, vert), 0L);
2582   SetScrollPos (h, SB_VERT, vert, TRUE);
2583 
2584 #endif
2585 #ifdef WIN_MOTIF
2586   Nlm_Int4 value, slider_size, increment, page_increment;
2587   Nlm_TextTool  h;
2588   Widget        scrolled_window;
2589   Widget        vscroll;
2590 
2591   h = Nlm_GetTextHandle ((Nlm_TexT) t);
2592   value = 0;
2593   slider_size = 0;
2594   increment = 0;
2595   page_increment = 0;
2596   vscroll = NULL;
2597 
2598   scrolled_window = XtParent (h);
2599   if (scrolled_window == NULL) return;
2600 
2601   XtVaGetValues (scrolled_window, XmNverticalScrollBar, &vscroll, NULL);
2602   if (vscroll == NULL) return;
2603 
2604   XmScrollBarGetValues (vscroll, &value, &slider_size, &increment, &page_increment);
2605   XmScrollBarSetValues (vscroll, vert, slider_size, increment, page_increment, TRUE);
2606 
2607 #endif
2608 }
2609 
Nlm_SetScrollTextOffset4(Nlm_GraphiC t,Nlm_Int4 horiz,Nlm_Int4 vert,Nlm_Boolean savePort)2610 extern void Nlm_SetScrollTextOffset4 (Nlm_GraphiC t, Nlm_Int4 horiz,
2611                                       Nlm_Int4 vert, Nlm_Boolean savePort)
2612 
2613 {
2614 #ifdef WIN_MAC
2615   Nlm_BaR  sb;
2616 
2617   sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
2618   if (sb != NULL) {
2619     Nlm_DoSetValue ((Nlm_GraphiC) sb, vert, savePort);
2620   }
2621 #endif
2622 #ifdef WIN_MSWIN
2623   Nlm_TextTool  h;
2624 
2625   h = Nlm_GetTextHandle ((Nlm_TexT) t);
2626   PostMessage (h, WM_VSCROLL, MAKEWPARAM (SB_THUMBPOSITION, vert), 0L);
2627   SetScrollPos (h, SB_VERT, vert, TRUE);
2628 
2629 #endif
2630 #ifdef WIN_MOTIF
2631   Nlm_Int4 value, slider_size, increment, page_increment;
2632   Nlm_TextTool  h;
2633   Widget        scrolled_window;
2634   Widget        vscroll;
2635 
2636   h = Nlm_GetTextHandle ((Nlm_TexT) t);
2637   value = 0;
2638   slider_size = 0;
2639   increment = 0;
2640   page_increment = 0;
2641   vscroll = NULL;
2642 
2643   scrolled_window = XtParent (h);
2644   if (scrolled_window == NULL) return;
2645 
2646   XtVaGetValues (scrolled_window, XmNverticalScrollBar, &vscroll, NULL);
2647   if (vscroll == NULL) return;
2648 
2649   XmScrollBarGetValues (vscroll, &value, &slider_size, &increment, &page_increment);
2650   XmScrollBarSetValues (vscroll, vert, slider_size, increment, page_increment, TRUE);
2651 
2652 #endif
2653 }
2654 
Nlm_GetScrollTextOffset(Nlm_GraphiC t,Nlm_Int2Ptr horiz,Nlm_Int2Ptr vert)2655 static void Nlm_GetScrollTextOffset (Nlm_GraphiC t, Nlm_Int2Ptr horiz, Nlm_Int2Ptr vert)
2656 
2657 {
2658 #ifdef WIN_MAC
2659   Nlm_BaR   sb;
2660   Nlm_Int2  rsult;
2661 
2662   sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
2663   rsult = 0;
2664   if (sb != NULL) {
2665     rsult = Nlm_DoGetValue ((Nlm_GraphiC) sb);
2666   }
2667   if (vert != NULL) {
2668     *vert = rsult;
2669   }
2670   if (horiz != NULL) {
2671     *horiz = 0;
2672   }
2673 #endif
2674 #ifdef WIN_MSWIN
2675   Nlm_TextTool  h;
2676 
2677   h = Nlm_GetTextHandle ((Nlm_TexT) t);
2678   if (vert != NULL) {
2679     *vert = (Nlm_Int2) GetScrollPos (h, SB_VERT);
2680   }
2681   if (horiz != NULL) {
2682     *horiz = 0;
2683   }
2684 #endif
2685 #ifdef WIN_MOTIF
2686   if (vert != NULL) {
2687     *vert = 0;
2688   }
2689   if (horiz != NULL) {
2690     *horiz = 0;
2691   }
2692 #endif
2693 }
2694 
Nlm_GetScrollTextOffset4(Nlm_GraphiC t,Nlm_Int4Ptr horiz,Nlm_Int4Ptr vert)2695 extern void Nlm_GetScrollTextOffset4 (Nlm_GraphiC t, Nlm_Int4Ptr horiz, Nlm_Int4Ptr vert)
2696 
2697 {
2698 #ifdef WIN_MAC
2699   Nlm_BaR   sb;
2700   Nlm_Int2  rsult;
2701 
2702   sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
2703   rsult = 0;
2704   if (sb != NULL) {
2705     rsult = Nlm_DoGetValue ((Nlm_GraphiC) sb);
2706   }
2707   if (vert != NULL) {
2708     *vert = rsult;
2709   }
2710   if (horiz != NULL) {
2711     *horiz = 0;
2712   }
2713 #endif
2714 #ifdef WIN_MSWIN
2715   Nlm_TextTool  h;
2716 
2717   h = Nlm_GetTextHandle ((Nlm_TexT) t);
2718   if (vert != NULL) {
2719     *vert = GetScrollPos (h, SB_VERT);
2720   }
2721   if (horiz != NULL) {
2722     *horiz = 0;
2723   }
2724 #endif
2725 #ifdef WIN_MOTIF
2726   Nlm_Int4 value, slider_size, increment, page_increment;
2727   Nlm_TextTool  h;
2728   Widget        scrolled_window;
2729   Widget        vscroll;
2730 
2731   h = Nlm_GetTextHandle ((Nlm_TexT) t);
2732   value = 0;
2733   slider_size = 0;
2734   increment = 0;
2735   page_increment = 0;
2736   vscroll = NULL;
2737 
2738   scrolled_window = XtParent (h);
2739   if (scrolled_window == NULL) return;
2740 
2741   XtVaGetValues (scrolled_window, XmNverticalScrollBar, &vscroll, NULL);
2742   if (vscroll == NULL) return;
2743 
2744   XmScrollBarGetValues (vscroll, &value, &slider_size, &increment, &page_increment);
2745 
2746   if (vert != NULL) {
2747     *vert = value;
2748   }
2749   if (horiz != NULL) {
2750     *horiz = 0;
2751   }
2752 #endif
2753 }
2754 
Nlm_SetScrollTextPosition(Nlm_GraphiC t,Nlm_RectPtr r,Nlm_Boolean savePort,Nlm_Boolean force)2755 static void Nlm_SetScrollTextPosition (Nlm_GraphiC t, Nlm_RectPtr r,
2756                 Nlm_Boolean savePort, Nlm_Boolean force)
2757 {
2758   Nlm_TextTool  h;
2759   Nlm_RecT      oldRect;
2760   Nlm_WindoW    tempPort = NULL;
2761   Nlm_RecT      tr;
2762   Nlm_Boolean   wrap;
2763 #ifdef WIN_MAC
2764   Nlm_Int2      deltax;
2765   Nlm_Int2      deltay;
2766   Nlm_RectTool  dtool;
2767 #ifndef WIN_MAC_QUARTZ
2768   TEPtr         hp;
2769 #endif
2770   Nlm_RectTool  rtool;
2771   Nlm_BaR       sb;
2772   Rect          textViewRect;
2773   Rect          textDestRect;
2774 #endif
2775   Nlm_Boolean   is_realized;
2776 
2777   if (r == NULL)  return;
2778 
2779   Nlm_DoGetPosition (t, &oldRect);
2780   if (!force  &&  Nlm_EqualRect(r, &oldRect))  return;
2781 
2782   h = Nlm_GetTextHandle ((Nlm_TexT) t);
2783   if (h == NULL)  return;
2784 
2785   tr = *r;
2786   wrap = Nlm_GetTextWrap ((Nlm_TexT) t);
2787   is_realized = Nlm_GetRealized( t );
2788   if (is_realized)
2789     {
2790       tempPort = Nlm_SavePortIfNeeded (t, savePort);
2791 #ifdef WIN_MAC
2792       Nlm_InvalScrollText (t);
2793 #endif
2794 #ifdef WIN_MSWIN
2795       MoveWindow (h,  tr.left,  tr.top,
2796           tr.right - tr.left,  tr.bottom - tr.top,  TRUE);
2797 #endif
2798 #ifdef WIN_MOTIF
2799       allowTextCallback = FALSE;
2800       XtVaSetValues (XtParent (h),
2801              XmNx, (Position) tr.left,
2802              XmNy, (Position) tr.top,
2803              XmNwidth,  (Dimension)(tr.right - tr.left),
2804              XmNheight, (Dimension)(tr.bottom - tr.top),
2805              NULL);
2806 #endif
2807     }
2808 
2809   tr.right -= Nlm_vScrollBarWidth;
2810   if ( !wrap )
2811     tr.bottom -= Nlm_hScrollBarHeight;
2812   Nlm_SetRect (t, &tr);
2813 
2814   if ( is_realized )
2815     {
2816 #ifdef WIN_MAC
2817       Nlm_ResetVisLines ((Nlm_TexT) t);
2818       Nlm_InsetRect (&tr, 4, 2);
2819       tr.bottom = tr.top + Nlm_GetVisLines ((Nlm_TexT) t) * Nlm_GetFontHeight ((Nlm_TexT) t);
2820 #ifdef WIN_MAC_QUARTZ
2821       TXNGetViewRect (h, &textViewRect);
2822       CGRect cgr;
2823       TXNGetHIRect (h, kTXNDestinationRectKey, &cgr);
2824       textDestRect = Nlm_RectCGToQD (cgr);
2825 #else
2826       HLock ((Handle) h);
2827       hp = (TEPtr) *((Handle) h);
2828       textViewRect = hp->viewRect;
2829       textDestRect = hp->destRect;
2830 #endif
2831       deltax = textDestRect.left - textViewRect.left;
2832       deltay = textDestRect.top - textViewRect.top;
2833       Nlm_RecTToRectTool (&tr, &rtool);
2834       Nlm_OffsetRect (&tr, deltax, deltay);
2835       Nlm_RecTToRectTool (&tr, &dtool);
2836       if (! wrap) {
2837     dtool.right += HSCROLL_POSITIONS * Nlm_stdCharWidth;
2838       }
2839 #ifdef WIN_MAC_QUARTZ
2840       CGRect viewCG = Nlm_RectQDToCG (textViewRect);
2841       CGRect destCG = Nlm_RectQDToCG (textDestRect);
2842       TXNSetHIRectBounds (h, &viewCG, &destCG, 1);
2843 #else
2844       hp->destRect = dtool;
2845       hp->viewRect = rtool;
2846       HUnlock ((Handle) h);
2847 #endif
2848       Nlm_InvalScrollText (t);
2849     }
2850 
2851   sb = Nlm_GetTextVScrollBar ((Nlm_TexT) t);
2852   if (sb != NULL) {
2853     Nlm_GetRect (t, &tr);
2854     tr.left = tr.right;
2855     tr.right += Nlm_vScrollBarWidth;
2856     Nlm_DoSetPosition ((Nlm_GraphiC) sb, &tr, FALSE, force);
2857   }
2858   sb = Nlm_GetTextHScrollBar ((Nlm_TexT) t);
2859   if (sb != NULL) {
2860     Nlm_GetRect (t, &tr);
2861     tr.top = tr.bottom;
2862     tr.bottom += Nlm_hScrollBarHeight;
2863     Nlm_DoSetPosition ((Nlm_GraphiC) sb, &tr, FALSE, force);
2864   }
2865 
2866   if ( is_realized )
2867     {
2868       Nlm_UpdateScrollBar ((Nlm_TexT) t);
2869 #endif
2870 #ifdef WIN_MSWIN
2871       Nlm_ResetVisLines ((Nlm_TexT) t);
2872       UpdateWindow (h);
2873 #endif
2874 #ifdef WIN_MOTIF
2875       Nlm_ResetVisLines ((Nlm_TexT) t);
2876       allowTextCallback = TRUE;
2877 #endif
2878 
2879       Nlm_RestorePort (tempPort);
2880     }
2881 }
2882 
2883 
Nlm_GetTextPosition(Nlm_GraphiC t,Nlm_RectPtr r)2884 static void Nlm_GetTextPosition (Nlm_GraphiC t, Nlm_RectPtr r)
2885 
2886 {
2887   if (r != NULL) {
2888     Nlm_GetRect (t, r);
2889   }
2890 }
2891 
Nlm_GetScrollTextPosition(Nlm_GraphiC t,Nlm_RectPtr r)2892 static void Nlm_GetScrollTextPosition (Nlm_GraphiC t, Nlm_RectPtr r)
2893 
2894 {
2895   if (r != NULL) {
2896     Nlm_GetRect (t, r);
2897     r->right += Nlm_vScrollBarWidth;
2898     if (! Nlm_GetTextWrap ((Nlm_TexT) t)) {
2899       r->bottom += Nlm_hScrollBarHeight;
2900     }
2901   }
2902 }
2903 
2904 #ifdef WIN_MAC
Nlm_VScrollAction(Nlm_BaR sb,Nlm_GraphiC t,Nlm_Int2 newval,Nlm_Int2 oldval)2905 static void Nlm_VScrollAction (Nlm_BaR sb, Nlm_GraphiC t,
2906                                Nlm_Int2 newval, Nlm_Int2 oldval)
2907 
2908 {
2909   Nlm_Int2      delta;
2910   Nlm_TextTool  h;
2911   Nlm_Int2      height;
2912   Nlm_RecT      r;
2913 
2914   h = Nlm_GetTextHandle ((Nlm_TexT) t);
2915   delta = oldval - newval;
2916   if (oldval != newval) {
2917     Nlm_SelectFont (Nlm_systemFont);
2918 #ifdef WIN_MAC_QUARTZ
2919     {
2920       SInt32 vdelta = delta, hdelta = 0;
2921       TXNScroll(h, kTXNScrollUnitsInLines, kTXNScrollUnitsInLines,
2922               &vdelta, &hdelta);
2923     }
2924 #else
2925     height = Nlm_GetLineHeight ((Nlm_TexT) t);
2926     TEScroll (0, delta * height, h);
2927 #endif
2928   } else if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
2929     Nlm_GetRect (t, &r);
2930     Nlm_InsetRect (&r, 2, 1);
2931     Nlm_InvalRect (&r);
2932   }
2933   Nlm_Update ();
2934 }
2935 
Nlm_HScrollAction(Nlm_BaR sb,Nlm_GraphiC t,Nlm_Int2 newval,Nlm_Int2 oldval)2936 static void Nlm_HScrollAction (Nlm_BaR sb, Nlm_GraphiC t,
2937                                Nlm_Int2 newval, Nlm_Int2 oldval)
2938 
2939 {
2940   Nlm_Int2      delta;
2941   Nlm_TextTool  h;
2942   Nlm_Int2      width;
2943   Nlm_RecT      r;
2944 
2945   h = Nlm_GetTextHandle ((Nlm_TexT) t);
2946   delta = oldval - newval;
2947   if (oldval != newval) {
2948     Nlm_SelectFont (Nlm_systemFont);
2949 #ifdef WIN_MAC_QUARTZ
2950     {
2951       SInt32 vdelta = 0, hdelta = delta;
2952       TXNScroll(h, kTXNScrollUnitsInLines, kTXNScrollUnitsInLines,
2953                 &vdelta, &hdelta);
2954     }
2955 #else
2956     width = Nlm_stdCharWidth;
2957     TEScroll (delta * width, 0, h);
2958 #endif
2959   } else if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
2960     Nlm_GetRect (t, &r);
2961     Nlm_InsetRect (&r, 2, 1);
2962     Nlm_InvalRect (&r);
2963   }
2964   Nlm_Update ();
2965 }
2966 #endif
2967 
2968 #ifdef WIN_MOTIF
Nlm_ReturnCallback(Widget w,XtPointer client_data,XtPointer call_data)2969 static void Nlm_ReturnCallback(Widget w,
2970                                XtPointer client_data, XtPointer call_data)
2971 {
2972   XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *)call_data;
2973 
2974   if (cbs->event != NULL)
2975     Nlm_DoSendFocus((Nlm_GraphiC)client_data, '\r');
2976 }
2977 
2978 
Nlm_TextCallback(Widget w,XtPointer client_data,XtPointer call_data)2979 static void Nlm_TextCallback(Widget w,
2980                              XtPointer client_data, XtPointer call_data)
2981 {
2982   XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *)call_data;
2983 
2984   if ( allowTextCallback )
2985     Nlm_DoAction( (Nlm_GraphiC)client_data );
2986 }
2987 
2988 
Nlm_FocusCallback(Widget w,XtPointer client_data,XtPointer call_data)2989 static void Nlm_FocusCallback(Widget w, XtPointer client_data, XtPointer call_data)
2990 {
2991   Nlm_TexT t = (Nlm_TexT) client_data;
2992   Nlm_SetActive (t, TRUE);
2993   Nlm_DoTextSelect (t);
2994 }
2995 
2996 
Nlm_LoseFocusCallback(Widget w,XtPointer client_data,XtPointer call_data)2997 static void Nlm_LoseFocusCallback (Widget w, XtPointer client_data, XtPointer call_data)
2998 {
2999   XmAnyCallbackStruct  *cbs;
3000   Nlm_TexT             t;
3001 
3002   cbs = (XmAnyCallbackStruct *) call_data;
3003   t = (Nlm_TexT) client_data;
3004   if (Nlm_GetActive (t)) {
3005     Nlm_DoTextDeselect (t);
3006   }
3007   /*
3008   currentText = NULL;
3009   */
3010 }
3011 
Nlm_RefreshCallback(Widget w,XtPointer client_data,XtPointer call_data)3012 static void Nlm_RefreshCallback (Widget w, XtPointer client_data, XtPointer call_data)
3013 
3014 {
3015   XmTextVerifyCallbackStruct  *cbs;
3016   Nlm_RecT                    r;
3017   Nlm_TexT                    t;
3018   Window                      ww;
3019 
3020   cbs = (XmTextVerifyCallbackStruct *) call_data;
3021   t = (Nlm_TexT) client_data;
3022   if (cbs->text->ptr == NULL) {
3023     Nlm_ObjectRect ((Nlm_GraphiC) t, &r);
3024     Nlm_OffsetRect (&r, -r.left, -r.top);
3025     if (! Nlm_IsHiddenText (t)) {
3026       Nlm_InsetRect (&r, 4, 4);
3027 #ifdef OS_VMS
3028       Nlm_InsetRect (&r, 5, 3);
3029 #else
3030       Nlm_InsetRect (&r, 5, 5);
3031 #endif
3032     }
3033     if (Nlm_currentXDisplay != NULL && (ww = XtWindow(w)) != 0)
3034     {
3035         XClearArea (Nlm_currentXDisplay, ww, r.left, r.top,
3036                     r.right - r.left, r.bottom - r.top, TRUE);
3037     }
3038   }
3039 }
3040 
3041 
Nlm_TextFieldCallback(Widget w,XtPointer client_data,XtPointer call_data)3042 static void Nlm_TextFieldCallback(Widget w,
3043                                   XtPointer client_data, XtPointer call_data)
3044 {
3045   XmTextVerifyCallbackStruct *cbs = (XmTextVerifyCallbackStruct *)call_data;
3046 
3047   int i;
3048 
3049   /* recalculate the correct length by detecting the null byte */
3050   for (i = 0;  i < cbs->text->length;  i++) {
3051     if (cbs->text->ptr[i] == '\0') {
3052       cbs->text->length = i + 1;
3053       break;
3054     }
3055   }
3056 
3057   /* Don't convert carriage returns and linefeeds into space */
3058   for (i = 0;  i < cbs->text->length;  i++) {
3059     if ( !isprint(cbs->text->ptr[i])  &&  !isspace (cbs->text->ptr[i]) )
3060       cbs->text->ptr[i] = ' ';
3061   }
3062 }
3063 
3064 
Nlm_PasswordCallback(Widget w,XtPointer client_data,XtPointer call_data)3065 static void Nlm_PasswordCallback (Widget w,
3066                                   XtPointer client_data,
3067                                   XtPointer call_data)
3068 {
3069   Nlm_GraphiC                 t    = (Nlm_GraphiC) client_data;
3070   XmTextVerifyCallbackStruct  *cbs = (XmTextVerifyCallbackStruct *)
3071     call_data;
3072   Nlm_Boolean                 IsSpecSym = (cbs->text->length == 0);
3073   Nlm_Char                    password [MAX_PASSWORD];
3074 
3075   /*  the Widget/password synchronization is under the caller's control */
3076   if (cbs->event == NULL)
3077     return;
3078 
3079   /*  X-event processing  -- all the Widget/password sync. is here */
3080   if ((!IsSpecSym  &&  cbs->currInsert >= MAX_PASSWORD - 1)  ||
3081       cbs->text->length > 1  ||
3082       (IsSpecSym  &&  cbs->currInsert == 0  &&
3083       Nlm_GetInputChar(&cbs->event->xkey) != NLM_DEL))
3084     { /*  min/max password length achieved  */
3085       cbs->doit = FALSE;
3086       return;
3087     }
3088 
3089   Nlm_GetPassword ((Nlm_TexT)t, password, sizeof(password));
3090   if ( !IsSpecSym )
3091     {
3092       cbs->startPos = cbs->currInsert;
3093       if (cbs->startPos + cbs->text->length  >=  MAX_PASSWORD)
3094         cbs->text->length = MAX_PASSWORD - cbs->startPos - 1;
3095       Nlm_MemCpy(password + cbs->startPos, cbs->text->ptr,
3096                  (size_t)cbs->text->length);
3097       Nlm_MemSet(cbs->text->ptr, '*', (size_t)cbs->text->length);
3098     }
3099 
3100   cbs->endPos = XmTextGetLastPosition( w );
3101   password[cbs->startPos + (size_t)cbs->text->length] = '\0';
3102   Nlm_SetPassword ((Nlm_TexT)t, password);
3103 }
3104 
3105 
Nlm_TabCallback(Widget w,XEvent * ev,String * args,Cardinal * num_args)3106 static void Nlm_TabCallback (Widget w, XEvent *ev, String *args, Cardinal *num_args)
3107 
3108 {
3109   XKeyEvent  *event;
3110   XtPointer  ptr;
3111   Nlm_TexT   t;
3112 
3113   event = (XKeyEvent *) ev;
3114   XtVaGetValues (w, XmNuserData, &ptr, NULL);
3115   t = (Nlm_TexT) ptr;
3116   Nlm_DoTabCallback (t);
3117 }
3118 
Nlm_HiddenReturnCallback(Widget w,XEvent * ev,String * args,Cardinal * num_args)3119 static void Nlm_HiddenReturnCallback (Widget w, XEvent *ev, String *args, Cardinal *num_args)
3120 
3121 {
3122   XKeyEvent  *event;
3123   XtPointer  ptr;
3124   Nlm_TexT   t;
3125 
3126   event = (XKeyEvent *) ev;
3127   XtVaGetValues (w, XmNuserData, &ptr, NULL);
3128   t = (Nlm_TexT) ptr;
3129   Nlm_DoReturnCallback (t);
3130 }
3131 
Nlm_HiddenActivateCallback(Widget w,XtPointer client_data,XtPointer call_data)3132 static void Nlm_HiddenActivateCallback (Widget w, XtPointer client_data, XtPointer call_data)
3133 
3134 {
3135   XmAnyCallbackStruct  *cbs;
3136   Nlm_TexT             t;
3137 
3138   cbs = (XmAnyCallbackStruct *) call_data;
3139   t = (Nlm_TexT) client_data;
3140   Nlm_DoReturnCallback (t);
3141 }
3142 #endif
3143 
3144 
Nlm_NewDialogText(Nlm_TexT t,Nlm_CharPtr dfault,Nlm_TxtActnProc actn)3145 static void Nlm_NewDialogText (Nlm_TexT t, Nlm_CharPtr dfault, Nlm_TxtActnProc actn)
3146 
3147 {
3148   Nlm_TextTool    h;
3149   Nlm_Char        local [128];
3150   Nlm_RecT        r;
3151   Nlm_WindowTool  wptr;
3152 #ifdef WIN_MAC
3153   Nlm_RectTool    rtool;
3154 #ifdef WIN_MAC_QUARTZ
3155   CGRect          cgr;
3156 #endif
3157 #endif
3158 #ifdef WIN_MSWIN
3159   Nlm_Uint4       style;
3160   Nlm_FntPtr      fntptr;
3161 #endif
3162 #ifdef WIN_MOTIF
3163   XmFontList      fontlist;
3164   Nlm_FntPtr      fntptr;
3165   Cardinal        n;
3166   Arg             wargs [20];
3167   XmFontListEntry font_entry;
3168 #endif
3169 
3170   Nlm_StringNCpy_0(local, dfault, sizeof(local));
3171 
3172   Nlm_GetRect ((Nlm_GraphiC) t, &r);
3173   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) t);
3174 
3175 #ifdef WIN_MAC
3176   Nlm_InsetRect (&r, 2, 2);
3177   Nlm_RecTToRectTool (&r, &rtool);
3178 #ifdef WIN_MAC_QUARTZ
3179   cgr = Nlm_RecTToCGRect(r);
3180   TXNCreateObject( &cgr, kTXNSingleLineOnlyMask, &h);
3181   TXNAttachObjectToWindowRef(h, wptr);
3182 #else
3183   h = TENew (&rtool, &rtool);
3184 #endif
3185   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
3186                     FALSE, FALSE, FALSE, 1, NULL, NULL, NULL, NULL, TRUE);
3187   Nlm_SetDialogText ((Nlm_GraphiC) t, 0, local, FALSE);
3188 #ifndef WIN_MAC_QUARTZ
3189   if (h != NULL) {
3190     TEAutoView (TRUE, h);
3191   }
3192 #endif
3193 #endif
3194 
3195 #ifdef WIN_MSWIN
3196   allowTextCallback = FALSE;
3197   style = WS_CHILD | WS_BORDER | ES_AUTOHSCROLL | ES_LEFT;
3198   h = CreateWindow ("Edit", local, style,
3199                     r.left, r.top, r.right - r.left,
3200                     r.bottom - r.top, wptr, 0,
3201                     Nlm_currentHInst, NULL);
3202   if (h != NULL) {
3203     SetProp (h, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) t);
3204   }
3205   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
3206                     FALSE, FALSE, FALSE, 1, NULL, NULL, NULL, NULL, TRUE);
3207   if (lpfnNewTextProc == NULL) {
3208     lpfnNewTextProc = (WNDPROC) MakeProcInstance ((FARPROC) TextProc, Nlm_currentHInst);
3209   }
3210   if (lpfnOldTextProc == NULL) {
3211     lpfnOldTextProc = (WNDPROC) GetWindowLongPtr (h, GWLP_WNDPROC);
3212   } else if (lpfnOldTextProc != (WNDPROC) GetWindowLongPtr (h, GWLP_WNDPROC)) {
3213     Nlm_Message (MSG_ERROR, "TextProc subclass error");
3214   }
3215   SetWindowLongPtr (h, GWLP_WNDPROC, (LONG_PTR) lpfnNewTextProc);
3216   allowTextCallback = TRUE;
3217   fntptr = (Nlm_FntPtr) Nlm_HandLock (Nlm_systemFont);
3218   SetWindowFont(h, fntptr->handle, FALSE);
3219   Nlm_HandUnlock(Nlm_systemFont);
3220 #endif
3221 
3222 #ifdef WIN_MOTIF
3223   allowTextCallback = FALSE;
3224   fntptr = (Nlm_FntPtr) Nlm_HandLock (Nlm_systemFont);
3225   font_entry = XmFontListEntryCreate (XmFONTLIST_DEFAULT_TAG,
3226                                       XmFONT_IS_FONT,
3227                                       fntptr->handle);
3228   fontlist = XmFontListAppendEntry (NULL, font_entry);
3229   Nlm_HandUnlock (Nlm_systemFont);
3230 
3231   n = 0;
3232   XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
3233   XtSetArg (wargs [n], XmNy, (Position) r.top); n++;
3234   XtSetArg (wargs [n], XmNwidth,  (Dimension) (r.right - r.left + 1)); n++;
3235   XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top + 1)); n++;
3236   XtSetArg (wargs [n], XmNfontList, fontlist); n++;
3237   XtSetArg (wargs [n], XmNmarginHeight, (Dimension) 1); n++;
3238   XtSetArg (wargs [n], XmNmarginWidth,  (Dimension) 2); n++;
3239   XtSetArg (wargs [n], XmNborderWidth,  (Dimension) 0); n++;
3240   XtSetArg (wargs [n], XmNeditMode, XmSINGLE_LINE_EDIT); n++;
3241   XtSetArg (wargs [n], XmNhighlightThickness, 0); n++;
3242   XtSetArg (wargs [n], XmNautoShowCursorPosition, TRUE); n++;
3243   h = XmCreateText(wptr, (String) "", wargs, n);
3244   Nlm_OverrideStdTranslations((Nlm_GraphiC)t, h, VERT_PAGE|VERT_ARROW);
3245   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
3246                     FALSE, FALSE, FALSE, 1, NULL, NULL, NULL, NULL, TRUE);
3247   XmTextSetString (h, local);
3248   XmTextShowPosition (h, 0);
3249   XtAddCallback (h, XmNmodifyVerifyCallback, Nlm_TextFieldCallback, (XtPointer)t);
3250   XtAddCallback (h, XmNvalueChangedCallback, Nlm_TextCallback, (XtPointer) t);
3251   XtAddCallback (h, XmNactivateCallback, Nlm_ReturnCallback, (XtPointer) t);
3252   XtAddCallback (h, XmNfocusCallback, Nlm_FocusCallback, (XtPointer) t);
3253   XtAddCallback (h, XmNlosingFocusCallback, Nlm_LoseFocusCallback, (XtPointer) t);
3254   XtManageChild( h );
3255 
3256   if (fontlist != NULL) XmFontListFree (fontlist);
3257   allowTextCallback = TRUE;
3258 #endif
3259 
3260   Nlm_LoadAction ((Nlm_GraphiC) t, (Nlm_ActnProc) actn);
3261 }
3262 
3263 
Nlm_NewPasswordText(Nlm_TexT t,Nlm_CharPtr dfault,Nlm_TxtActnProc actn)3264 static void Nlm_NewPasswordText (Nlm_TexT t, Nlm_CharPtr dfault, Nlm_TxtActnProc actn)
3265 
3266 {
3267   Nlm_TextTool    h;
3268   Nlm_Char        local [128];
3269   Nlm_RecT        r;
3270   Nlm_WindowTool  wptr;
3271 #ifdef WIN_MAC
3272   Nlm_RectTool    rtool;
3273 #ifdef WIN_MAC_QUARTZ
3274   CGRect          cgr;
3275 #endif
3276 #endif
3277 #ifdef WIN_MSWIN
3278   Nlm_Uint4       style;
3279 #endif
3280 #ifdef WIN_MOTIF
3281   XmFontList      fontlist;
3282   Nlm_FntPtr      fntptr;
3283   Cardinal        n;
3284   Arg             wargs [20];
3285   XmFontListEntry font_entry;
3286 #endif
3287 
3288   Nlm_StringNCpy_0(local, dfault, sizeof(local));
3289 
3290   Nlm_GetRect ((Nlm_GraphiC) t, &r);
3291   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) t);
3292 
3293 #ifdef WIN_MAC
3294   Nlm_InsetRect (&r, 2, 2);
3295   Nlm_RecTToRectTool (&r, &rtool);
3296 #ifdef WIN_MAC_QUARTZ
3297   cgr = Nlm_RecTToCGRect(r);
3298   TXNCreateObject( &cgr, kTXNSingleLineOnlyMask, &h);
3299   TXNAttachObjectToWindowRef(h, wptr);
3300 #else
3301   h = TENew (&rtool, &rtool);
3302 #endif
3303   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
3304                     FALSE, FALSE, FALSE, 1, NULL, NULL, NULL, NULL, TRUE);
3305   Nlm_SetPasswordText ((Nlm_GraphiC) t, 0, local, FALSE);
3306 #endif
3307 
3308 #ifdef WIN_MSWIN
3309   style = WS_CHILD | WS_BORDER |  ES_AUTOVSCROLL | ES_LEFT | ES_PASSWORD;
3310   h = CreateWindow ("Edit", local, style,
3311                     r.left, r.top, r.right - r.left,
3312                     r.bottom - r.top, wptr, 0,
3313                     Nlm_currentHInst, NULL);
3314   if (h != NULL) {
3315     SetProp (h, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) t);
3316   }
3317   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
3318                     FALSE, FALSE, FALSE, 1, NULL, NULL, NULL, NULL, TRUE);
3319   if (lpfnNewTextProc == NULL) {
3320     lpfnNewTextProc = (WNDPROC) MakeProcInstance ((FARPROC) TextProc, Nlm_currentHInst);
3321   }
3322   if (lpfnOldTextProc == NULL) {
3323     lpfnOldTextProc = (WNDPROC) GetWindowLongPtr (h, GWLP_WNDPROC);
3324   } else if (lpfnOldTextProc != (WNDPROC) GetWindowLongPtr (h, GWLP_WNDPROC)) {
3325     Nlm_Message (MSG_ERROR, "TextProc subclass error");
3326   }
3327   SetWindowLongPtr (h, GWLP_WNDPROC, (LONG_PTR) lpfnNewTextProc);
3328   Nlm_SetPassword (t, local);
3329 #endif
3330 
3331 #ifdef WIN_MOTIF
3332   allowTextCallback = FALSE;
3333   fntptr = (Nlm_FntPtr) Nlm_HandLock (Nlm_systemFont);
3334   font_entry = XmFontListEntryCreate (XmFONTLIST_DEFAULT_TAG,
3335                                       XmFONT_IS_FONT,
3336                                       fntptr->handle);
3337   fontlist = XmFontListAppendEntry (NULL, font_entry);
3338   Nlm_HandUnlock (Nlm_systemFont);
3339   Nlm_InsetRect (&r, 3, 3);
3340 
3341   n = 0;
3342   XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
3343   XtSetArg (wargs [n], XmNy, (Position) r.top); n++;
3344   XtSetArg (wargs [n], XmNwidth,  (Dimension) (r.right - r.left + 1)); n++;
3345   XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top + 1)); n++;
3346   XtSetArg (wargs [n], XmNmarginHeight, (Dimension) 1); n++;
3347   XtSetArg (wargs [n], XmNmarginWidth,  (Dimension) 2); n++;
3348   XtSetArg (wargs [n], XmNborderWidth,  (Dimension) 0); n++;
3349   XtSetArg (wargs [n], XmNeditMode, XmSINGLE_LINE_EDIT); n++;
3350   XtSetArg (wargs [n], XmNfontList, fontlist); n++;
3351   XtSetArg (wargs [n], XmNhighlightThickness, 0); n++;
3352   XtSetArg (wargs [n], XmNautoShowCursorPosition, TRUE); n++;
3353   h = XmCreateText (wptr, (String) "", wargs, n);
3354   Nlm_OverrideStdTranslations((Nlm_GraphiC)t, h, VERT_PAGE|VERT_ARROW);
3355   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
3356                     FALSE, FALSE, FALSE, 1, NULL, NULL, NULL, NULL, TRUE);
3357   XtAddCallback (h, XmNmodifyVerifyCallback, Nlm_PasswordCallback, (XtPointer) t);
3358   XtAddCallback (h, XmNvalueChangedCallback, Nlm_TextCallback, (XtPointer) t);
3359   XtAddCallback (h, XmNactivateCallback, Nlm_ReturnCallback, (XtPointer) t);
3360   XtAddCallback (h, XmNfocusCallback, Nlm_FocusCallback, (XtPointer) t);
3361   XtAddCallback (h, XmNlosingFocusCallback, Nlm_LoseFocusCallback, (XtPointer) t);
3362   Nlm_SetPasswordText((Nlm_GraphiC)t, 0, local, FALSE);
3363   XtManageChild( h );
3364 
3365   if (fontlist != NULL) XmFontListFree (fontlist);
3366   allowTextCallback = TRUE;
3367 #endif
3368 
3369   Nlm_LoadAction ((Nlm_GraphiC) t, (Nlm_ActnProc) actn);
3370 }
3371 
3372 
Nlm_NewHiddenText(Nlm_TexT t,Nlm_CharPtr dfault,Nlm_TxtActnProc actn,Nlm_TxtActnProc tabProc,Nlm_TxtActnProc rtnProc)3373 static void Nlm_NewHiddenText (Nlm_TexT t, Nlm_CharPtr dfault,
3374                                Nlm_TxtActnProc actn, Nlm_TxtActnProc tabProc,
3375                                Nlm_TxtActnProc rtnProc)
3376 
3377 {
3378   Nlm_TextTool    h;
3379   Nlm_Char        local [128];
3380   Nlm_RecT        r;
3381   Nlm_WindowTool  wptr;
3382 #ifdef WIN_MAC
3383   Nlm_RectTool    rtool;
3384 #ifdef WIN_MAC_QUARTZ
3385   CGRect          cgr;
3386 #endif
3387 #endif
3388 #ifdef WIN_MSWIN
3389   Nlm_Uint4       style;
3390   Nlm_FntPtr fntptr;
3391 #endif
3392 #ifdef WIN_MOTIF
3393   Cardinal        n;
3394   Arg             wargs [20];
3395   XmFontList      fontlist;
3396   Nlm_FntPtr      fntptr;
3397   XmFontListEntry font_entry;
3398 #endif
3399 
3400   Nlm_StringNCpy_0(local, dfault, sizeof(local));
3401 
3402   Nlm_GetRect ((Nlm_GraphiC) t, &r);
3403   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) t);
3404 
3405 #ifdef WIN_MAC
3406   Nlm_RecTToRectTool (&r, &rtool);
3407 #ifdef WIN_MAC_QUARTZ
3408   cgr = Nlm_RecTToCGRect(r);
3409   TXNCreateObject( &cgr, kTXNSingleLineOnlyMask, &h);
3410   TXNAttachObjectToWindowRef(h, wptr);
3411 #else
3412   h = TENew (&rtool, &rtool);
3413 #endif
3414   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
3415                     FALSE, TRUE, FALSE, 1, NULL, NULL, tabProc, rtnProc, TRUE);
3416   Nlm_SetDialogText ((Nlm_GraphiC) t, 0, local, FALSE);
3417 #ifndef WIN_MAC_QUARTZ
3418   if (h != NULL) {
3419     TEAutoView (TRUE, h);
3420   }
3421 #endif
3422 #endif
3423 
3424 #ifdef WIN_MSWIN
3425   style = WS_CHILD | ES_MULTILINE | ES_AUTOVSCROLL | ES_LEFT;
3426   h = CreateWindow ("Edit", local, style,
3427                     r.left, r.top, r.right - r.left,
3428                     r.bottom - r.top, wptr, 0,
3429                     Nlm_currentHInst, NULL);
3430   if (h != NULL) {
3431     SetProp (h, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) t);
3432   }
3433   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
3434                     FALSE, TRUE, FALSE, 1, NULL, NULL, tabProc, rtnProc, TRUE);
3435   if (lpfnNewTextProc == NULL) {
3436     lpfnNewTextProc = (WNDPROC) MakeProcInstance ((FARPROC) TextProc, Nlm_currentHInst);
3437   }
3438   if (lpfnOldTextProc == NULL) {
3439     lpfnOldTextProc = (WNDPROC) GetWindowLongPtr (h, GWLP_WNDPROC);
3440   } else if (lpfnOldTextProc != (WNDPROC) GetWindowLongPtr (h, GWLP_WNDPROC)) {
3441     Nlm_Message (MSG_ERROR, "TextProc subclass error");
3442   }
3443   SetWindowLongPtr (h, GWLP_WNDPROC, (LONG_PTR) lpfnNewTextProc);
3444   fntptr = (Nlm_FntPtr) Nlm_HandLock (Nlm_systemFont);
3445   SetWindowFont(h, fntptr->handle, FALSE);
3446   Nlm_HandUnlock(Nlm_systemFont);
3447 #endif
3448 
3449 #ifdef WIN_MOTIF
3450   allowTextCallback = FALSE;
3451   fntptr = (Nlm_FntPtr) Nlm_HandLock (Nlm_systemFont);
3452   font_entry = XmFontListEntryCreate (XmFONTLIST_DEFAULT_TAG,
3453                                       XmFONT_IS_FONT,
3454                                       fntptr->handle);
3455   fontlist = XmFontListAppendEntry (NULL, font_entry);
3456   Nlm_HandUnlock (Nlm_systemFont);
3457 
3458   n = 0;
3459   XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
3460   XtSetArg (wargs [n], XmNy, (Position) r.top); n++;
3461   XtSetArg (wargs [n], XmNwidth,  (Dimension) (r.right - r.left + 1)); n++;
3462   XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top + 1)); n++;
3463   XtSetArg (wargs [n], XmNfontList, fontlist); n++;
3464   XtSetArg (wargs [n], XmNmarginHeight, 0); n++;
3465   XtSetArg (wargs [n], XmNmarginWidth,  0); n++;
3466   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
3467   XtSetArg (wargs [n], XmNshadowThickness, (Dimension) 0); n++;
3468   XtSetArg (wargs [n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
3469   XtSetArg (wargs [n], XmNhighlightThickness, 0); n++;
3470   XtSetArg (wargs [n], XmNautoShowCursorPosition, TRUE); n++;
3471   XtSetArg (wargs [n], XmNverifyBell, FALSE); n++;
3472   h = XmCreateText (wptr, (String) "", wargs, n);
3473   XtVaSetValues (h, XmNuserData, (XtPointer) t, NULL);
3474   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
3475                     FALSE, TRUE, FALSE, 1, NULL, NULL, tabProc, rtnProc, TRUE);
3476   XmTextSetString (h, local);
3477   XmTextShowPosition (h, 0);
3478   XtAddCallback (h, XmNmodifyVerifyCallback, Nlm_RefreshCallback, (XtPointer) t);
3479   XtAddCallback (h, XmNvalueChangedCallback, Nlm_TextCallback, (XtPointer) t);
3480   XtAddCallback (h, XmNactivateCallback, Nlm_HiddenActivateCallback, (XtPointer) t);
3481   XtAddCallback (h, XmNfocusCallback, Nlm_FocusCallback, (XtPointer) t);
3482   XtAddCallback (h, XmNlosingFocusCallback, Nlm_LoseFocusCallback, (XtPointer) t);
3483   XtManageChild( h );
3484 
3485   if (fontlist != NULL) XmFontListFree (fontlist);
3486   allowTextCallback = TRUE;
3487 #endif
3488 
3489   Nlm_LoadAction ((Nlm_GraphiC) t, (Nlm_ActnProc) actn);
3490 }
3491 
3492 
Nlm_NewSpecialText(Nlm_TexT t,Nlm_CharPtr dfault,Nlm_TxtActnProc actn,Nlm_TxtActnProc tabProc,Nlm_TxtActnProc rtnProc)3493 static void Nlm_NewSpecialText (Nlm_TexT t, Nlm_CharPtr dfault,
3494                                 Nlm_TxtActnProc actn, Nlm_TxtActnProc tabProc,
3495                                 Nlm_TxtActnProc rtnProc)
3496 
3497 {
3498   Nlm_TextTool    h;
3499   Nlm_Char        local [128];
3500   Nlm_RecT        r;
3501   Nlm_WindowTool  wptr;
3502 #ifdef WIN_MAC
3503   Nlm_RectTool    rtool;
3504 #ifdef WIN_MAC_QUARTZ
3505   CGRect          cgr;
3506 #endif
3507 #endif
3508 #ifdef WIN_MSWIN
3509   Nlm_Uint4       style;
3510   Nlm_FntPtr fntptr;
3511 #endif
3512 #ifdef WIN_MOTIF
3513   XmFontList      fontlist;
3514   Nlm_FntPtr      fntptr;
3515   Cardinal        n;
3516   Arg             wargs[20];
3517   String          trans =
3518     "<Key>Tab:     do_tab()  \n\
3519      <Key>Return:  do_return()";
3520   XmFontListEntry font_entry;
3521 #endif
3522 
3523   Nlm_StringNCpy_0(local, dfault, sizeof(local));
3524 
3525   Nlm_GetRect ((Nlm_GraphiC) t, &r);
3526   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) t);
3527 
3528 #ifdef WIN_MAC
3529   Nlm_InsetRect (&r, 2, 2);
3530   Nlm_RecTToRectTool (&r, &rtool);
3531 #ifdef WIN_MAC_QUARTZ
3532   cgr = Nlm_RecTToCGRect(r);
3533   TXNCreateObject( &cgr, kTXNSingleLineOnlyMask, &h);
3534   TXNAttachObjectToWindowRef(h, wptr);
3535 #else
3536   h = TENew (&rtool, &rtool);
3537 #endif
3538   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
3539                     FALSE, FALSE, TRUE, 1, NULL, NULL, tabProc, rtnProc, TRUE);
3540   Nlm_SetDialogText ((Nlm_GraphiC) t, 0, local, FALSE);
3541 #ifndef WIN_MAC_QUARTZ
3542   if (h != NULL) {
3543     TEAutoView (TRUE, h);
3544   }
3545 #endif
3546 #endif
3547 
3548 #ifdef WIN_MSWIN
3549   allowTextCallback = FALSE;
3550   style = WS_CHILD | WS_BORDER | ES_MULTILINE | ES_AUTOVSCROLL | ES_LEFT;
3551   h = CreateWindow ("Edit", local, style,
3552                     r.left, r.top, r.right - r.left,
3553                     r.bottom - r.top, wptr, 0,
3554                     Nlm_currentHInst, NULL);
3555   if (h != NULL) {
3556     SetProp (h, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) t);
3557   }
3558   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
3559                     FALSE, FALSE, TRUE, 1, NULL, NULL, tabProc, rtnProc, TRUE);
3560   if (lpfnNewTextProc == NULL) {
3561     lpfnNewTextProc = (WNDPROC) MakeProcInstance ((FARPROC) TextProc, Nlm_currentHInst);
3562   }
3563   if (lpfnOldTextProc == NULL) {
3564     lpfnOldTextProc = (WNDPROC) GetWindowLongPtr (h, GWLP_WNDPROC);
3565   } else if (lpfnOldTextProc != (WNDPROC) GetWindowLongPtr (h, GWLP_WNDPROC)) {
3566     Nlm_Message (MSG_ERROR, "TextProc subclass error");
3567   }
3568   SetWindowLongPtr (h, GWLP_WNDPROC, (LONG_PTR) lpfnNewTextProc);
3569   allowTextCallback = TRUE;
3570   fntptr = (Nlm_FntPtr) Nlm_HandLock (Nlm_systemFont);
3571   SetWindowFont(h, fntptr->handle, FALSE);
3572   Nlm_HandUnlock(Nlm_systemFont);
3573 #endif
3574 
3575 #ifdef WIN_MOTIF
3576   allowTextCallback = FALSE;
3577   fntptr = (Nlm_FntPtr) Nlm_HandLock (Nlm_systemFont);
3578   font_entry = XmFontListEntryCreate (XmFONTLIST_DEFAULT_TAG,
3579                                       XmFONT_IS_FONT,
3580                                       fntptr->handle);
3581   fontlist = XmFontListAppendEntry (NULL, font_entry);
3582   Nlm_HandUnlock (Nlm_systemFont);
3583   Nlm_InsetRect (&r, 3, 3);
3584 
3585   n = 0;
3586   XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
3587   XtSetArg (wargs [n], XmNy, (Position) r.top); n++;
3588   XtSetArg (wargs [n], XmNwidth,  (Dimension) (r.right - r.left + 1)); n++;
3589   XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top + 1)); n++;
3590   XtSetArg (wargs [n], XmNmarginHeight, (Dimension) 1); n++;
3591   XtSetArg (wargs [n], XmNmarginWidth,  (Dimension) 2); n++;
3592   XtSetArg (wargs [n], XmNborderWidth,  (Dimension) 0); n++;
3593   XtSetArg (wargs [n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
3594   XtSetArg (wargs [n], XmNfontList, fontlist); n++;
3595   XtSetArg (wargs [n], XmNhighlightThickness, 0); n++;
3596   XtSetArg (wargs [n], XmNautoShowCursorPosition, TRUE); n++;
3597   XtSetArg (wargs [n], XmNverifyBell, FALSE); n++;
3598   h = XmCreateText (wptr, (String) "", wargs, n);
3599   XtOverrideTranslations (h, XtParseTranslationTable (trans));
3600   XtVaSetValues (h, XmNuserData, (XtPointer) t, NULL);
3601   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
3602                     FALSE, FALSE, TRUE, 1, NULL, NULL, tabProc, rtnProc, TRUE);
3603   XmTextSetString (h, local);
3604   XmTextShowPosition (h, 0);
3605   XtAddCallback (h, XmNmodifyVerifyCallback, Nlm_RefreshCallback, (XtPointer) t);
3606   XtAddCallback (h, XmNvalueChangedCallback, Nlm_TextCallback, (XtPointer) t);
3607   XtAddCallback (h, XmNactivateCallback, Nlm_HiddenActivateCallback, (XtPointer) t);
3608   XtAddCallback (h, XmNfocusCallback, Nlm_FocusCallback, (XtPointer) t);
3609   XtAddCallback (h, XmNlosingFocusCallback, Nlm_LoseFocusCallback, (XtPointer) t);
3610   XtManageChild( h );
3611 
3612   if (fontlist != NULL) XmFontListFree (fontlist);
3613   allowTextCallback = TRUE;
3614 #endif
3615 
3616   Nlm_LoadAction ((Nlm_GraphiC) t, (Nlm_ActnProc) actn);
3617 }
3618 
3619 
Nlm_NewScrollText(Nlm_TexT t,Nlm_Int2 height,Nlm_FonT font,Nlm_Int2 fnthgt,Nlm_Boolean wrap,Nlm_TxtActnProc actn)3620 static void Nlm_NewScrollText (Nlm_TexT t, Nlm_Int2 height,
3621                                Nlm_FonT font, Nlm_Int2 fnthgt,
3622                                Nlm_Boolean wrap, Nlm_TxtActnProc actn)
3623 
3624 {
3625   Nlm_TextTool    h;
3626   Nlm_BaR         hsb;
3627   Nlm_RecT        r;
3628   Nlm_BaR         vsb;
3629   Nlm_WindowTool  wptr;
3630 #ifdef WIN_MAC
3631   Nlm_RectTool    dtool;
3632   Nlm_RectTool    rtool;
3633   Nlm_Int2        width;
3634 #ifdef WIN_MAC_QUARTZ
3635   CGRect          cgr;
3636 #endif
3637 #endif
3638 #ifdef WIN_MSWIN
3639   Nlm_FntPtr      fntptr;
3640   HFONT           oldFont;
3641   Nlm_Uint4       style;
3642 #endif
3643 #ifdef WIN_MOTIF
3644   Nlm_FntPtr      fntptr;
3645   XmFontList      fontlist;
3646   Cardinal        n;
3647   Arg             wargs [15];
3648   XmFontListEntry font_entry;
3649 #endif
3650 
3651   Nlm_GetRect ((Nlm_GraphiC) t, &r);
3652   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) t);
3653 
3654 #ifdef WIN_MAC
3655   vsb = NULL;
3656   hsb = NULL;
3657   r.left = r.right;
3658   r.right += Nlm_vScrollBarWidth;
3659   vsb = Nlm_VertScrollBar ((Nlm_GraphiC) t, &r, Nlm_VScrollAction);
3660   if (! wrap) {
3661     Nlm_GetRect ((Nlm_GraphiC) t, &r);
3662     r.top = r.bottom;
3663     r.bottom += Nlm_hScrollBarHeight;
3664     hsb = Nlm_HorizScrollBar ((Nlm_GraphiC) t, &r, Nlm_HScrollAction);
3665   }
3666   Nlm_GetRect ((Nlm_GraphiC) t, &r);
3667   Nlm_InsetRect (&r, 4, 2);
3668   if (fnthgt > 0) {
3669     height = (r.bottom - r.top + 1) / fnthgt;
3670   } else {
3671     height = 0;
3672   }
3673   Nlm_DoSetRange ((Nlm_GraphiC) vsb, height - 1, height - 1, 0, FALSE);
3674   r.bottom = r.top + height * fnthgt;
3675   Nlm_RecTToRectTool (&r, &rtool);
3676   if (! wrap) {
3677     width = (r.right - r.left + 1) / Nlm_stdCharWidth;
3678     Nlm_DoSetRange ((Nlm_GraphiC) hsb, width - 1, width - 1, 0, FALSE);
3679     r.right += HSCROLL_POSITIONS * Nlm_stdCharWidth;
3680   }
3681   Nlm_RecTToRectTool (&r, &dtool);
3682 #ifdef WIN_MAC_QUARTZ
3683   cgr = Nlm_RecTToCGRect(r);
3684   TXNCreateObject( &cgr, 0, &h);
3685   TXNAttachObjectToWindowRef(h, wptr);
3686 #else
3687   h = TENew (&rtool, &rtool);
3688 #endif
3689   Nlm_LoadTextData (t, h, vsb, hsb, wrap, font, fnthgt, FALSE,
3690                     FALSE, FALSE, FALSE, height, NULL, NULL, NULL, NULL, TRUE);
3691 #endif
3692 
3693 #ifdef WIN_MSWIN
3694   vsb = NULL;
3695   hsb = NULL;
3696   r.right += Nlm_vScrollBarWidth;
3697   allowTextCallback = FALSE;
3698   style = WS_CHILD | WS_BORDER | ES_MULTILINE | WS_VSCROLL | ES_AUTOVSCROLL | ES_LEFT;
3699   if (! wrap) {
3700     style |= WS_HSCROLL | ES_AUTOHSCROLL;
3701     r.bottom += Nlm_hScrollBarHeight;
3702   }
3703   h = CreateWindow ("Edit", "", style,
3704                     r.left, r.top, r.right - r.left,
3705                     r.bottom - r.top, wptr, (Nlm_HandleTool) t,
3706                     Nlm_currentHInst, NULL);
3707   if (h != NULL) {
3708     SetProp (h, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) t);
3709   }
3710   Edit_LimitText (h, 0);
3711   oldFont = NULL;
3712   if (font != NULL) {
3713     fntptr = (Nlm_FntPtr) Nlm_HandLock (font);
3714     if (fntptr != NULL && fntptr->handle != NULL) {
3715       oldFont = SelectObject (Nlm_currentHDC, fntptr->handle);
3716     }
3717     Nlm_HandUnlock (font);
3718   } else {
3719     oldFont = SelectObject (Nlm_currentHDC, GetStockObject (ANSI_FIXED_FONT));
3720   }
3721   if (oldFont != NULL) {
3722     SelectObject (Nlm_currentHDC, oldFont);
3723     SetWindowFont (h, oldFont, FALSE);
3724   }
3725   Nlm_LoadTextData (t, h, vsb, hsb, wrap, font, fnthgt, FALSE,
3726                     FALSE, FALSE, FALSE, height, NULL, NULL, NULL, NULL, TRUE);
3727   if (lpfnNewTextProc == NULL) {
3728     lpfnNewTextProc = (WNDPROC) MakeProcInstance ((FARPROC) TextProc, Nlm_currentHInst);
3729   }
3730   if (lpfnOldTextProc == NULL) {
3731     lpfnOldTextProc = (WNDPROC) GetWindowLongPtr (h, GWLP_WNDPROC);
3732   } else if (lpfnOldTextProc != (WNDPROC) GetWindowLongPtr (h, GWLP_WNDPROC)) {
3733     Nlm_Message (MSG_ERROR, "TextProc subclass error");
3734   }
3735   SetWindowLongPtr (h, GWLP_WNDPROC, (LONG_PTR) lpfnNewTextProc);
3736   allowTextCallback = TRUE;
3737 #endif
3738 
3739 #ifdef WIN_MOTIF
3740   allowTextCallback = FALSE;
3741   vsb = NULL;
3742   hsb = NULL;
3743   r.right += Nlm_vScrollBarWidth;
3744   if (! wrap) {
3745     r.bottom += Nlm_hScrollBarHeight;
3746   }
3747   fontlist = NULL;
3748   if (font != NULL) {
3749     fntptr = (Nlm_FntPtr) Nlm_HandLock (font);
3750     if (fntptr != NULL && fntptr->handle != NULL) {
3751       font_entry = XmFontListEntryCreate (XmFONTLIST_DEFAULT_TAG,
3752                                           XmFONT_IS_FONT,
3753                                           fntptr->handle);
3754       fontlist = XmFontListAppendEntry (NULL, font_entry);
3755     }
3756     Nlm_HandUnlock (font);
3757   }
3758 
3759   n = 0;
3760   XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
3761   XtSetArg (wargs [n], XmNy, (Position) r.top); n++;
3762   XtSetArg (wargs [n], XmNmarginHeight, (Dimension) 1); n++;
3763   XtSetArg (wargs [n], XmNmarginWidth,  (Dimension) 2); n++;
3764   XtSetArg (wargs [n], XmNborderWidth,  (Dimension) 0); n++;
3765   XtSetArg (wargs [n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
3766   if (wrap) {
3767     XtSetArg (wargs [n], XmNscrollHorizontal, FALSE); n++;
3768     XtSetArg (wargs [n], XmNwordWrap, TRUE); n++;
3769   }
3770   XtSetArg (wargs [n], XmNfontList, fontlist); n++;
3771   XtSetArg (wargs [n], XmNhighlightThickness, 0); n++;
3772   h = XmCreateScrolledText (wptr, (String) "", wargs, n);
3773   Nlm_LoadTextData (t, h, vsb, hsb, wrap, font, fnthgt, FALSE,
3774                     FALSE, FALSE, FALSE, height, NULL, NULL, NULL, NULL, TRUE);
3775   XtAddCallback (h, XmNvalueChangedCallback, Nlm_TextCallback, (XtPointer) t);
3776   XtAddCallback (h, XmNfocusCallback, Nlm_FocusCallback, (XtPointer) t);
3777   XtAddCallback (h, XmNlosingFocusCallback, Nlm_LoseFocusCallback, (XtPointer) t);
3778   XtAddCallback (h, XmNmodifyVerifyCallback, Nlm_TextFieldCallback, (XtPointer)t);
3779   XtManageChild (h);
3780 
3781   allowTextCallback = TRUE;
3782   if (fontlist != NULL) {
3783     XmFontListFree (fontlist);
3784   }
3785 #endif
3786 
3787   Nlm_LoadAction ((Nlm_GraphiC) t, (Nlm_ActnProc) actn);
3788 }
3789 
3790 
Nlm_DialogText(Nlm_GrouP prnt,Nlm_CharPtr dfault,Nlm_Int2 charWidth,Nlm_TxtActnProc actn)3791 extern Nlm_TexT Nlm_DialogText (Nlm_GrouP prnt, Nlm_CharPtr dfault,
3792                                 Nlm_Int2 charWidth, Nlm_TxtActnProc actn)
3793 
3794 {
3795   Nlm_Int2    cwid;
3796   Nlm_Int2    hbounds;
3797   Nlm_PoinT   npt;
3798   Nlm_RecT    r;
3799   Nlm_TexT    t;
3800   Nlm_WindoW  tempPort;
3801   Nlm_Int2    vbounds;
3802 
3803   t = NULL;
3804   if (prnt != NULL) {
3805     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
3806     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
3807     Nlm_SelectFont (Nlm_systemFont);
3808     if (charWidth == 0) {
3809       cwid = Nlm_StringWidth (dfault);
3810     } else {
3811       cwid = (Nlm_Int2)(charWidth * Nlm_stdCharWidth);
3812     }
3813 #ifdef WIN_MAC
3814     hbounds = 2;
3815     vbounds = 2;
3816 #endif
3817 #ifdef WIN_MSWIN
3818     hbounds = 3;
3819     vbounds = (Nlm_Int2)((Nlm_stdFontHeight * 3 / 2 - Nlm_stdLineHeight) / 2);
3820 #endif
3821 #ifdef WIN_MOTIF
3822     hbounds = 3;
3823     vbounds = 3;
3824 #endif
3825     r.left = npt.x;
3826     r.top  = npt.y;
3827     r.right  = (Nlm_Int2)(r.left + cwid + 2 + hbounds * 2);
3828     r.bottom = (Nlm_Int2)(r.top + Nlm_stdLineHeight + vbounds * 2);
3829     t = (Nlm_TexT) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r,
3830                                    sizeof (Nlm_TextRec), dialogTextProcs);
3831     if (t != NULL) {
3832       Nlm_NewDialogText (t, dfault, actn);
3833 #ifdef WIN_MAC
3834       Nlm_DoSelect ((Nlm_GraphiC) t, FALSE);
3835 #endif
3836       Nlm_DoAdjustPrnt ((Nlm_GraphiC) t, &r, TRUE, FALSE);
3837       Nlm_DoShow ((Nlm_GraphiC) t, TRUE, FALSE);
3838     }
3839     Nlm_RestorePort (tempPort);
3840   }
3841   return t;
3842 }
3843 
Nlm_HiddenText(Nlm_GrouP prnt,Nlm_CharPtr dfault,Nlm_Int2 charWidth,Nlm_TxtActnProc actn,Nlm_TxtActnProc tabProc,Nlm_TxtActnProc rtnProc)3844 extern Nlm_TexT Nlm_HiddenText (Nlm_GrouP prnt, Nlm_CharPtr dfault,
3845                                 Nlm_Int2 charWidth, Nlm_TxtActnProc actn,
3846                                 Nlm_TxtActnProc tabProc, Nlm_TxtActnProc rtnProc)
3847 
3848 {
3849   Nlm_Int2    cwid;
3850   Nlm_Int2    hbounds;
3851   Nlm_PoinT   npt;
3852   Nlm_RecT    r;
3853   Nlm_TexT    t;
3854   Nlm_WindoW  tempPort;
3855   Nlm_Int2    vbounds;
3856 
3857   t = NULL;
3858   if (prnt != NULL) {
3859     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
3860     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
3861     Nlm_SelectFont (Nlm_systemFont);
3862     if (charWidth == 0) {
3863       cwid = Nlm_StringWidth (dfault);
3864     } else {
3865       cwid = (Nlm_Int2)(charWidth * Nlm_stdCharWidth);
3866     }
3867     hbounds = 0;
3868     vbounds = 0;
3869     r.left = npt.x;
3870     r.top  = npt.y;
3871     r.right  = (Nlm_Int2)(r.left + cwid + 2 + hbounds * 2);
3872     r.bottom = (Nlm_Int2)(r.top + Nlm_stdLineHeight + vbounds * 2);
3873     t = (Nlm_TexT) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r,
3874                                    sizeof (Nlm_TextRec), hiddenTextProcs);
3875     if (t != NULL) {
3876       Nlm_NewHiddenText (t, dfault, actn, tabProc, rtnProc);
3877 #ifdef WIN_MAC
3878       Nlm_DoSelect ((Nlm_GraphiC) t, FALSE);
3879 #endif
3880       Nlm_DoAdjustPrnt ((Nlm_GraphiC) t, &r, TRUE, FALSE);
3881       Nlm_DoShow ((Nlm_GraphiC) t, TRUE, FALSE);
3882     }
3883     Nlm_RestorePort (tempPort);
3884   }
3885   return t;
3886 }
3887 
Nlm_SpecialText(Nlm_GrouP prnt,Nlm_CharPtr dfault,Nlm_Int2 charWidth,Nlm_TxtActnProc actn,Nlm_TxtActnProc tabProc,Nlm_TxtActnProc rtnProc)3888 extern Nlm_TexT Nlm_SpecialText (Nlm_GrouP prnt, Nlm_CharPtr dfault,
3889                                  Nlm_Int2 charWidth, Nlm_TxtActnProc actn,
3890                                  Nlm_TxtActnProc tabProc, Nlm_TxtActnProc rtnProc)
3891 
3892 {
3893   Nlm_Int2    cwid;
3894   Nlm_Int2    hbounds;
3895   Nlm_PoinT   npt;
3896   Nlm_RecT    r;
3897   Nlm_TexT    t;
3898   Nlm_WindoW  tempPort;
3899   Nlm_Int2    vbounds;
3900 
3901   t = NULL;
3902   if (prnt != NULL) {
3903     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
3904     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
3905     Nlm_SelectFont (Nlm_systemFont);
3906     if (charWidth == 0) {
3907       cwid = Nlm_StringWidth (dfault);
3908     } else {
3909       cwid = (Nlm_Int2)(charWidth * Nlm_stdCharWidth);
3910     }
3911 #ifdef WIN_MAC
3912     hbounds = 2;
3913     vbounds = 2;
3914 #endif
3915 #ifdef WIN_MSWIN
3916     hbounds = 3;
3917     vbounds = (Nlm_Int2)((Nlm_stdFontHeight * 3 / 2 - Nlm_stdLineHeight) / 2);
3918 #endif
3919 #ifdef WIN_MOTIF
3920     hbounds = 3;
3921     vbounds = 3;
3922 #endif
3923     r.left = npt.x;
3924     r.top  = npt.y;
3925     r.right  = (Nlm_Int2)(r.left + cwid + 2 + hbounds * 2);
3926     r.bottom = (Nlm_Int2)(r.top + Nlm_stdLineHeight + vbounds * 2);
3927     t = (Nlm_TexT) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r,
3928                                    sizeof (Nlm_TextRec), specialTextProcs);
3929     if (t != NULL) {
3930       Nlm_NewSpecialText (t, dfault, actn, tabProc, rtnProc);
3931 #ifdef WIN_MAC
3932       Nlm_DoSelect ((Nlm_GraphiC) t, FALSE);
3933 #endif
3934       Nlm_DoAdjustPrnt ((Nlm_GraphiC) t, &r, TRUE, FALSE);
3935       Nlm_DoShow ((Nlm_GraphiC) t, TRUE, FALSE);
3936     }
3937     Nlm_RestorePort (tempPort);
3938   }
3939   return t;
3940 }
3941 
Nlm_PasswordText(Nlm_GrouP prnt,Nlm_CharPtr dfault,Nlm_Int2 charWidth,Nlm_TxtActnProc actn)3942 extern Nlm_TexT Nlm_PasswordText (Nlm_GrouP prnt, Nlm_CharPtr dfault,
3943                                   Nlm_Int2 charWidth, Nlm_TxtActnProc actn)
3944 
3945 {
3946   Nlm_Int2    cwid;
3947   Nlm_Int2    hbounds;
3948   Nlm_PoinT   npt;
3949   Nlm_RecT    r;
3950   Nlm_TexT    t;
3951   Nlm_WindoW  tempPort;
3952   Nlm_Int2    vbounds;
3953 
3954   t = NULL;
3955   if (prnt != NULL) {
3956     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
3957     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
3958     Nlm_SelectFont (Nlm_systemFont);
3959     if (charWidth == 0) {
3960       cwid = Nlm_StringWidth (dfault);
3961     } else {
3962       cwid = (Nlm_Int2)(charWidth * Nlm_stdCharWidth);
3963     }
3964 #ifdef WIN_MAC
3965     hbounds = 2;
3966     vbounds = 2;
3967 #endif
3968 #ifdef WIN_MSWIN
3969     hbounds = 3;
3970     vbounds = (Nlm_Int2)((Nlm_stdFontHeight * 3 / 2 - Nlm_stdLineHeight) / 2);
3971 #endif
3972 #ifdef WIN_MOTIF
3973     hbounds = 3;
3974     vbounds = 3;
3975 #endif
3976     r.left = npt.x;
3977     r.top  = npt.y;
3978     r.right  = (Nlm_Int2)(r.left + cwid + 2 + hbounds * 2);
3979     r.bottom = (Nlm_Int2)(r.top + Nlm_stdLineHeight + vbounds * 2);
3980     t = (Nlm_TexT) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r,
3981                                    sizeof (Nlm_PasswdRec), passwordTextProcs);
3982     if (t != NULL) {
3983       Nlm_NewPasswordText (t, dfault, actn);
3984 #ifdef WIN_MAC
3985       Nlm_DoSelect ((Nlm_GraphiC) t, FALSE);
3986 #endif
3987       Nlm_DoAdjustPrnt ((Nlm_GraphiC) t, &r, TRUE, FALSE);
3988       Nlm_DoShow ((Nlm_GraphiC) t, TRUE, FALSE);
3989     }
3990     Nlm_RestorePort (tempPort);
3991   }
3992   return t;
3993 }
3994 
Nlm_ScrollText(Nlm_GrouP prnt,Nlm_Int2 width,Nlm_Int2 height,Nlm_FonT font,Nlm_Boolean wrap,Nlm_TxtActnProc actn)3995 extern Nlm_TexT Nlm_ScrollText (Nlm_GrouP prnt, Nlm_Int2 width,
3996                                 Nlm_Int2 height, Nlm_FonT font,
3997                                 Nlm_Boolean wrap, Nlm_TxtActnProc actn)
3998 
3999 {
4000   Nlm_Int2    dwid;
4001   Nlm_Int2    fnthgt;
4002   Nlm_PoinT   npt;
4003   Nlm_RecT    r;
4004   Nlm_TexT    t;
4005   Nlm_WindoW  tempPort;
4006   Nlm_Int2    thgt;
4007 
4008   t = NULL;
4009   if (prnt != NULL) {
4010     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
4011     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
4012     fnthgt = Nlm_stdLineHeight;
4013     if ( !font )
4014       font = Nlm_programFont;
4015     Nlm_SelectFont (font);
4016     dwid = (Nlm_Int2)(width  * Nlm_stdCharWidth);
4017     thgt = (Nlm_Int2)(height * fnthgt);
4018     Nlm_LoadRect(&r, npt.x, npt.y,
4019                  (Nlm_Int2)(npt.x + dwid + 8), (Nlm_Int2)(npt.y + thgt + 4));
4020     t = (Nlm_TexT) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r, sizeof (Nlm_TextRec), scrollTextProcs);
4021     if (t != NULL) {
4022       Nlm_NewScrollText (t, height, font, fnthgt, wrap, actn);
4023       r.right += Nlm_vScrollBarWidth;
4024       if (! wrap) {
4025         r.bottom += Nlm_hScrollBarHeight;
4026       }
4027       Nlm_DoAdjustPrnt ((Nlm_GraphiC) t, &r, TRUE, FALSE);
4028       Nlm_SelectFont (Nlm_systemFont);
4029       Nlm_DoShow ((Nlm_GraphiC) t, TRUE, FALSE);
4030     }
4031     Nlm_RestorePort (tempPort);
4032   }
4033   return t;
4034 }
4035 
4036 
Nlm_SetTextEditable(Nlm_TexT t,Nlm_Boolean editable)4037 extern void Nlm_SetTextEditable(Nlm_TexT t, Nlm_Boolean editable)
4038 {
4039 #if defined(WIN_MOTIF)
4040   XtVaSetValues(Nlm_GetTextHandle(t), XmNeditable, (Boolean)editable, NULL);
4041 #else
4042   Nlm_TextData  tdata;
4043   Nlm_GetTextData (t, &tdata);
4044   tdata.editable = editable;
4045   Nlm_SetTextData (t, &tdata);
4046 #endif
4047 }
4048 
4049 
Nlm_SetTextCursorPos(Nlm_TexT t,Nlm_Int4 pos)4050 extern Nlm_Int4 Nlm_SetTextCursorPos(Nlm_TexT t, Nlm_Int4 pos)
4051 {
4052   Nlm_Int4 actual_pos = 0;
4053 #if defined(WIN_MOTIF) || defined(WIN_MSWIN)
4054   Nlm_TextTool h = Nlm_GetTextHandle( t );
4055   allowTextCallback = FALSE;
4056 #endif
4057 #if defined(WIN_MAC)
4058   Nlm_SelectText(t, pos, pos);
4059   Nlm_TextSelectionRange(t, &actual_pos, NULL);
4060 #elif defined(WIN_MOTIF)
4061   XmTextSetSelection(h, (XmTextPosition)0, (XmTextPosition)0, (Time)0);
4062   XmTextShowPosition(h, pos);
4063   XmTextSetInsertionPosition(h, pos);
4064   actual_pos = XmTextGetInsertionPosition( h );
4065 #elif defined(WIN_MSWIN)
4066   Edit_SetSel(h, pos, pos);
4067 #ifdef WIN32
4068   Edit_ScrollCaret( h );
4069 #endif
4070   {{
4071   DWORD dwBegin = 0;
4072   SNDMSG(h, EM_GETSEL, (WPARAM)(&dwBegin), 0L);
4073   actual_pos = dwBegin;
4074   }}
4075 #endif
4076 #if defined(WIN_MOTIF) || defined(WIN_MSWIN)
4077   allowTextCallback = TRUE;
4078 #endif
4079   return actual_pos;
4080 }
4081 
4082 
Nlm_GetTextCursorPos(Nlm_TexT t)4083 extern Nlm_Int4 Nlm_GetTextCursorPos(Nlm_TexT t)
4084 {
4085   Nlm_Int4     pos = 0;
4086   Nlm_TextTool h   = Nlm_GetTextHandle( t );
4087   if ( !h )
4088     return 0;
4089 
4090 #if   defined(WIN_MAC)
4091   Nlm_TextSelectionRange(t, &pos, NULL);
4092 #elif defined(WIN_MOTIF)
4093   pos = (Nlm_Int4)XmTextGetInsertionPosition( h );
4094 #elif defined(WIN_MSWIN)
4095   {{
4096   DWORD dwBegin = 0;
4097   SNDMSG(h, EM_GETSEL, (WPARAM)&dwBegin, 0L);
4098   pos = dwBegin;
4099   }}
4100 #endif
4101 
4102   return pos;
4103 }
4104 
4105 
Nlm_PassPanelClickToText(Nlm_PaneL p,Nlm_TexT t,Nlm_PoinT pt)4106 extern void Nlm_PassPanelClickToText (Nlm_PaneL p, Nlm_TexT t, Nlm_PoinT pt)
4107 
4108 {
4109 #ifdef WIN_MSWIN
4110   Nlm_TextTool  h;
4111   UINT          message;
4112   WPARAM        wParam;
4113 #endif
4114 #ifdef WIN_MOTIF
4115   Nlm_TextTool  h;
4116 #endif
4117 
4118   if (t != NULL) {
4119     Nlm_KillSlateTimer ();
4120 #ifdef WIN_MAC
4121     Nlm_DoClick ((Nlm_GraphiC) t, pt);
4122 #endif
4123 #ifdef WIN_MSWIN
4124     ReleaseCapture ();
4125     h = Nlm_GetTextHandle (t);
4126     if (Nlm_dblClick) {
4127       message = WM_LBUTTONDBLCLK;
4128     } else {
4129       message = WM_LBUTTONDOWN;
4130     }
4131     if (Nlm_shftKey) {
4132       wParam = MK_SHIFT;
4133     } else {
4134       wParam = 0;
4135     }
4136 /*
4137     Edit_SetSel (h, 0, 0);
4138     if (Nlm_Visible (t) && Nlm_AllParentsVisible (t)) {
4139       SetFocus (h);
4140       Nlm_DoTextSelect (t);
4141     }
4142 */
4143     SendMessage (h, message, Nlm_currentWParam, Nlm_currentLParam);
4144 #endif
4145 #ifdef WIN_MOTIF
4146   if (Nlm_WindowHasBeenShown (Nlm_ParentWindow ((Nlm_Handle) t))) {
4147     allowTextCallback = FALSE;
4148     h = Nlm_GetTextHandle (t);
4149     XmTextSetSelection (h, (XmTextPosition) 0,
4150                         (XmTextPosition) 0, (Time) 0);
4151     XmProcessTraversal (h, XmTRAVERSE_CURRENT);
4152     XmTextSetHighlight (h, (XmTextPosition) 0,
4153                         (XmTextPosition) 0, XmHIGHLIGHT_SELECTED);
4154     allowTextCallback = TRUE;
4155   }
4156   Nlm_DoTextSelect (t);
4157 #endif
4158   }
4159 }
4160 
4161 #ifdef WIN_MAC
Nlm_RegisterTexts(void)4162 extern Nlm_Boolean Nlm_RegisterTexts (void)
4163 
4164 {
4165   return TRUE;
4166 }
4167 #endif
4168 
4169 #ifdef WIN_MSWIN
Nlm_RegisterTexts(void)4170 extern Nlm_Boolean Nlm_RegisterTexts (void)
4171 
4172 {
4173   return TRUE;
4174 }
4175 #endif
4176 
4177 #ifdef WIN_MOTIF
Nlm_RegisterTexts(void)4178 extern Nlm_Boolean Nlm_RegisterTexts (void)
4179 {
4180   XtActionsRec  actions;
4181 
4182   actions.string = "do_tab";
4183   actions.proc = Nlm_TabCallback;
4184   XtAppAddActions (Nlm_appContext, &actions, 1);
4185   actions.string = "do_return";
4186   actions.proc = Nlm_HiddenReturnCallback;
4187   XtAppAddActions (Nlm_appContext, &actions, 1);
4188   return TRUE;
4189 }
4190 #endif
4191 
Nlm_FreeTexts(void)4192 extern void Nlm_FreeTexts (void)
4193 
4194 {
4195   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemFree (gphprcsptr);
4196 }
4197 
Nlm_InitTexts(void)4198 extern void Nlm_InitTexts (void)
4199 
4200 {
4201   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemNew (sizeof (Nlm_GphPrcs) * 5);
4202 
4203   dialogTextProcs = &(gphprcsptr [0]);
4204 #ifdef WIN_MAC
4205 #ifndef WIN_MAC_QUARTZ
4206 #endif
4207   dialogTextProcs->click = Nlm_DialogTextClick;
4208   dialogTextProcs->draw = Nlm_DrawDialogText;
4209   dialogTextProcs->key = Nlm_DialogKey;
4210   dialogTextProcs->idle = Nlm_IdleText;
4211 #endif
4212 #ifdef WIN_MSWIN
4213   dialogTextProcs->command = Nlm_DialogTextCommand;
4214 #endif
4215 #ifdef WIN_MOTIF
4216 #endif
4217   dialogTextProcs->show = Nlm_ShowText;
4218   dialogTextProcs->hide = Nlm_HideText;
4219 #ifndef WIN_MAC_QUARTZ
4220   dialogTextProcs->enable = Nlm_EnableText;
4221   dialogTextProcs->disable = Nlm_DisableText;
4222   dialogTextProcs->activate = Nlm_ActivateText;
4223   dialogTextProcs->deactivate = Nlm_DeactivateText;
4224 #endif
4225   dialogTextProcs->remove = Nlm_RemoveText;
4226   dialogTextProcs->reset = Nlm_ResetText;
4227   dialogTextProcs->select = Nlm_TextSelectProc;
4228   dialogTextProcs->setTitle = Nlm_SetDialogText;
4229   dialogTextProcs->getTitle = Nlm_GetDialogText;
4230   dialogTextProcs->setPosition = Nlm_SetTextPosition;
4231   dialogTextProcs->getPosition = Nlm_GetTextPosition;
4232   dialogTextProcs->gainFocus = Nlm_TextGainFocus;
4233   dialogTextProcs->loseFocus = Nlm_TextLoseFocus;
4234 
4235   hiddenTextProcs = &(gphprcsptr [1]);
4236 #ifdef WIN_MAC
4237 #ifndef WIN_MAC_QUARTZ
4238   hiddenTextProcs->click = Nlm_DialogTextClick;
4239 #endif
4240   hiddenTextProcs->draw = Nlm_DrawHiddenText;
4241   hiddenTextProcs->key = Nlm_DialogKey;
4242   hiddenTextProcs->idle = Nlm_IdleText;
4243 #endif
4244 #ifdef WIN_MSWIN
4245   hiddenTextProcs->command = Nlm_DialogTextCommand;
4246 #endif
4247 #ifdef WIN_MOTIF
4248 #endif
4249   hiddenTextProcs->show = Nlm_ShowText;
4250   hiddenTextProcs->hide = Nlm_HideText;
4251 #ifndef WIN_MAC_QUARTZ
4252   hiddenTextProcs->enable = Nlm_EnableText;
4253   hiddenTextProcs->disable = Nlm_DisableText;
4254   hiddenTextProcs->activate = Nlm_ActivateHiddenText;
4255   hiddenTextProcs->deactivate = Nlm_DeactivateText;
4256 #endif
4257   hiddenTextProcs->remove = Nlm_RemoveText;
4258   hiddenTextProcs->reset = Nlm_ResetText;
4259   hiddenTextProcs->select = Nlm_TextSelectProc;
4260   hiddenTextProcs->setTitle = Nlm_SetDialogText;
4261   hiddenTextProcs->getTitle = Nlm_GetDialogText;
4262   hiddenTextProcs->setPosition = Nlm_SetHiddenTextPosition;
4263   hiddenTextProcs->getPosition = Nlm_GetTextPosition;
4264   hiddenTextProcs->gainFocus = Nlm_TextGainFocus;
4265   hiddenTextProcs->loseFocus = Nlm_TextLoseFocus;
4266 
4267   specialTextProcs = &(gphprcsptr [2]);
4268 #ifdef WIN_MAC
4269 #ifndef WIN_MAC_QUARTZ
4270   specialTextProcs->click = Nlm_DialogTextClick;
4271 #endif
4272   specialTextProcs->draw = Nlm_DrawDialogText;
4273   specialTextProcs->key = Nlm_DialogKey;
4274   specialTextProcs->idle = Nlm_IdleText;
4275 #endif
4276 #ifdef WIN_MSWIN
4277   specialTextProcs->command = Nlm_DialogTextCommand;
4278 #endif
4279 #ifdef WIN_MOTIF
4280 #endif
4281   specialTextProcs->show = Nlm_ShowText;
4282   specialTextProcs->hide = Nlm_HideText;
4283 #ifndef WIN_MAC_QUARTZ
4284   specialTextProcs->enable = Nlm_EnableText;
4285   specialTextProcs->disable = Nlm_DisableText;
4286   specialTextProcs->activate = Nlm_ActivateHiddenText;
4287   specialTextProcs->deactivate = Nlm_DeactivateText;
4288 #endif
4289   specialTextProcs->remove = Nlm_RemoveText;
4290   specialTextProcs->reset = Nlm_ResetText;
4291   specialTextProcs->select = Nlm_TextSelectProc;
4292   specialTextProcs->setTitle = Nlm_SetDialogText;
4293   specialTextProcs->getTitle = Nlm_GetDialogText;
4294   specialTextProcs->setPosition = Nlm_SetTextPosition;
4295   specialTextProcs->getPosition = Nlm_GetTextPosition;
4296   specialTextProcs->gainFocus = Nlm_TextGainFocus;
4297   specialTextProcs->loseFocus = Nlm_TextLoseFocus;
4298 
4299   passwordTextProcs = &(gphprcsptr [3]);
4300 #ifdef WIN_MAC
4301 #ifdef WIN_MAC_QUARTZ
4302   passwordTextProcs->key = Nlm_DialogKey;
4303 #else
4304   passwordTextProcs->click = Nlm_DialogTextClick;
4305   passwordTextProcs->draw = Nlm_DrawDialogText;
4306   passwordTextProcs->key = Nlm_PasswordKey;
4307 #endif
4308   passwordTextProcs->idle = Nlm_IdleText;
4309 #endif
4310 #ifdef WIN_MSWIN
4311   passwordTextProcs->command = Nlm_PasswordTextCommand;
4312 #endif
4313 #ifdef WIN_MOTIF
4314 #endif
4315   passwordTextProcs->show = Nlm_ShowText;
4316   passwordTextProcs->hide = Nlm_HideText;
4317 #ifndef WIN_MAC_QUARTZ
4318   passwordTextProcs->enable = Nlm_EnableText;
4319   passwordTextProcs->disable = Nlm_DisableText;
4320   passwordTextProcs->activate = Nlm_ActivateText;
4321   passwordTextProcs->deactivate = Nlm_DeactivateText;
4322 #endif
4323   passwordTextProcs->remove = Nlm_RemoveText;
4324   passwordTextProcs->reset = Nlm_ResetText;
4325   passwordTextProcs->select = Nlm_TextSelectProc;
4326   passwordTextProcs->setTitle = Nlm_SetPasswordText;
4327   passwordTextProcs->getTitle = Nlm_GetPasswordText;
4328   passwordTextProcs->setPosition = Nlm_SetTextPosition;
4329   passwordTextProcs->getPosition = Nlm_GetTextPosition;
4330   passwordTextProcs->gainFocus = Nlm_TextGainFocus;
4331   passwordTextProcs->loseFocus = Nlm_TextLoseFocus;
4332 
4333   scrollTextProcs = &(gphprcsptr [4]);
4334 #ifdef WIN_MAC
4335 #ifndef WIN_MAC_QUARTZ
4336   scrollTextProcs->click = Nlm_ScrollTextClick;
4337 #endif
4338   scrollTextProcs->draw = Nlm_DrawScrollText;
4339   scrollTextProcs->key = Nlm_TextKey;
4340   scrollTextProcs->idle = Nlm_IdleText;
4341 #endif
4342 #ifdef WIN_MSWIN
4343   scrollTextProcs->command = Nlm_ScrollTextCommand;
4344 #endif
4345 #ifdef WIN_MOTIF
4346 #endif
4347   scrollTextProcs->show = Nlm_ShowScrollText;
4348   scrollTextProcs->hide = Nlm_HideScrollText;
4349 #ifndef WIN_MAC_QUARTZ
4350   scrollTextProcs->enable = Nlm_EnableText;
4351   scrollTextProcs->disable = Nlm_DisableText;
4352   scrollTextProcs->activate = Nlm_ActivateScrollText;
4353   scrollTextProcs->deactivate = Nlm_DeactivateScrollText;
4354 #endif
4355   scrollTextProcs->remove = Nlm_RemoveText;
4356   scrollTextProcs->reset = Nlm_ResetText;
4357   scrollTextProcs->select = Nlm_TextSelectProc;
4358   scrollTextProcs->setTitle = Nlm_SetScrollText;
4359   scrollTextProcs->getTitle = Nlm_GetScrollText;
4360   scrollTextProcs->setOffset = Nlm_SetScrollTextOffset;
4361   scrollTextProcs->getOffset = Nlm_GetScrollTextOffset;
4362   scrollTextProcs->setPosition = Nlm_SetScrollTextPosition;
4363   scrollTextProcs->getPosition = Nlm_GetScrollTextPosition;
4364   scrollTextProcs->gainFocus = Nlm_TextGainFocus;
4365   scrollTextProcs->loseFocus = Nlm_TextLoseFocus;
4366 }
4367 
Nlm_SetTextCursorBlinkRate(Nlm_TexT t,Nlm_Int2 msec)4368 extern void Nlm_SetTextCursorBlinkRate(Nlm_TexT t, Nlm_Int2 msec)
4369 {
4370 #ifdef WIN_MOTIF
4371     Nlm_TextTool h;
4372     Arg          args[2];
4373 
4374     if(t == NULL || msec < 0)
4375         return;
4376     h = Nlm_GetTextHandle(t);
4377     if(h == NULL)
4378         return;
4379     XtSetArg(args[0], XmNblinkRate, msec);
4380     XtSetValues(h, args, 1);
4381 #endif
4382     return;
4383 }
4384 
Nlm_SetTextColor(Nlm_TexT t,Nlm_Uint4 r,Nlm_Uint4 g,Nlm_Uint4 b)4385 extern void Nlm_SetTextColor(Nlm_TexT t, Nlm_Uint4 r, Nlm_Uint4 g, Nlm_Uint4 b)
4386 {
4387 #ifdef WIN_MOTIF
4388     Nlm_TextTool h;
4389     Arg          args[2];
4390 
4391     if(t == NULL)
4392         return;
4393     h = Nlm_GetTextHandle(t);
4394     if(h == NULL)
4395         return;
4396     XtSetArg(args[0], XmNforeground, Nlm_GetColorRGB(r, g, b));
4397     XtSetValues(h, args, 1);
4398 #endif
4399     return;
4400 }
4401 
4402 #ifdef WIN_MOTIF
Nlm_KeepCrNlTextFieldCallback(Widget w,XtPointer client_data,XtPointer call_data)4403 static void Nlm_KeepCrNlTextFieldCallback(Widget w,
4404                                           XtPointer client_data,
4405                                           XtPointer call_data)
4406 {
4407     XmTextVerifyCallbackStruct *cbs = (XmTextVerifyCallbackStruct *) call_data;
4408     char *p;
4409     int i;
4410 
4411     /* recalculate the correct length by detecting the null byte
4412      */
4413     p = cbs->text->ptr;
4414     for(i = 0; i < cbs->text->length; i++)
4415     {
4416         if(p[i] == '\0')
4417         {
4418             cbs->text->length = i + 1;
4419             break;
4420         }
4421     }
4422 
4423     for(i = 0; i < cbs->text->length; i++)
4424         if((!isprint(p[i]) && !isspace(p[i])) || p[i] == '\r' || p[i] == '\n')
4425             p[i] = ' ';
4426 }
4427 #endif
4428 
Nlm_SetKeepCrNlTextFieldCallback(Nlm_TexT t)4429 extern void Nlm_SetKeepCrNlTextFieldCallback(Nlm_TexT t)
4430 {
4431 #ifdef WIN_MOTIF
4432     Nlm_TextTool h;
4433 
4434     if(t == NULL)
4435         return;
4436     h = Nlm_GetTextHandle(t);
4437     if(h == NULL)
4438         return;
4439     XtAddCallback(h, XmNmodifyVerifyCallback,
4440                   Nlm_KeepCrNlTextFieldCallback, (XtPointer) t);
4441 #endif
4442     return;
4443 }
4444 
4445 
Nlm_NewDialogTextWithFont(Nlm_TexT t,Nlm_CharPtr dfault,Nlm_TxtActnProc actn,Nlm_FonT font)4446 static void Nlm_NewDialogTextWithFont (Nlm_TexT t, Nlm_CharPtr dfault, Nlm_TxtActnProc actn,
4447 							   Nlm_FonT font)
4448 
4449 {
4450   Nlm_TextTool    h;
4451   Nlm_Char        local [128];
4452   Nlm_RecT        r;
4453   Nlm_WindowTool  wptr;
4454 #ifdef WIN_MAC
4455   Nlm_RectTool    rtool;
4456 #endif
4457 #ifdef WIN_MSWIN
4458   Nlm_Uint4       style;
4459   Nlm_FntPtr      fntptr;
4460 #endif
4461 #ifdef WIN_MOTIF
4462   XmFontList      fontlist;
4463   Nlm_FntPtr      fntptr;
4464   Cardinal        n;
4465   Arg             wargs [20];
4466 #endif
4467 
4468   Nlm_StringNCpy_0(local, dfault, sizeof(local));
4469 
4470   Nlm_GetRect ((Nlm_GraphiC) t, &r);
4471   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) t);
4472 
4473 #ifdef WIN_MAC
4474   Nlm_InsetRect (&r, 2, 2);
4475   Nlm_RecTToRectTool (&r, &rtool);
4476   h = TENew (&rtool, &rtool);
4477   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
4478                     FALSE, FALSE, FALSE, 1, NULL, NULL, NULL, NULL, TRUE);
4479   Nlm_SetDialogText ((Nlm_GraphiC) t, 0, local, FALSE);
4480   if (h != NULL) {
4481     TEAutoView (TRUE, h);
4482   }
4483 #endif
4484 
4485 #ifdef WIN_MSWIN
4486   allowTextCallback = FALSE;
4487   style = WS_CHILD | WS_BORDER | ES_AUTOHSCROLL | ES_LEFT;
4488   h = CreateWindow ("Edit", local, style,
4489                     r.left, r.top, r.right - r.left,
4490                     r.bottom - r.top, wptr, 0,
4491                     Nlm_currentHInst, NULL);
4492   if (h != NULL) {
4493     SetProp (h, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) t);
4494   }
4495   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
4496                     FALSE, FALSE, FALSE, 1, NULL, NULL, NULL, NULL, TRUE);
4497   if (lpfnNewTextProc == NULL) {
4498     lpfnNewTextProc = (WNDPROC) MakeProcInstance ((FARPROC) TextProc, Nlm_currentHInst);
4499   }
4500   if (lpfnOldTextProc == NULL) {
4501     lpfnOldTextProc = (WNDPROC) GetWindowLongPtr (h, GWLP_WNDPROC);
4502   } else if (lpfnOldTextProc != (WNDPROC) GetWindowLongPtr (h, GWLP_WNDPROC)) {
4503     Nlm_Message (MSG_ERROR, "TextProc subclass error");
4504   }
4505   SetWindowLongPtr (h, GWLP_WNDPROC, (LONG_PTR) lpfnNewTextProc);
4506   allowTextCallback = TRUE;
4507   fntptr = (Nlm_FntPtr) Nlm_HandLock (font);
4508   SetWindowFont(h, fntptr->handle, FALSE);
4509   Nlm_HandUnlock(font);
4510 #endif
4511 
4512 #ifdef WIN_MOTIF
4513   allowTextCallback = FALSE;
4514   fntptr = (Nlm_FntPtr) Nlm_HandLock (font);
4515   fontlist = XmFontListCreate (fntptr->handle, XmSTRING_DEFAULT_CHARSET);
4516   Nlm_HandUnlock (font);
4517 
4518   n = 0;
4519   XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
4520   XtSetArg (wargs [n], XmNy, (Position) r.top); n++;
4521   XtSetArg (wargs [n], XmNwidth,  (Dimension) (r.right - r.left + 1)); n++;
4522   XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top + 1)); n++;
4523   XtSetArg (wargs [n], XmNfontList, fontlist); n++;
4524   XtSetArg (wargs [n], XmNmarginHeight, (Dimension) 1); n++;
4525   XtSetArg (wargs [n], XmNmarginWidth,  (Dimension) 2); n++;
4526   XtSetArg (wargs [n], XmNborderWidth,  (Dimension) 0); n++;
4527   XtSetArg (wargs [n], XmNeditMode, XmSINGLE_LINE_EDIT); n++;
4528   XtSetArg (wargs [n], XmNhighlightThickness, 0); n++;
4529   XtSetArg (wargs [n], XmNautoShowCursorPosition, TRUE); n++;
4530   h = XmCreateText(wptr, (String) "", wargs, n);
4531   Nlm_OverrideStdTranslations((Nlm_GraphiC)t, h, VERT_PAGE|VERT_ARROW);
4532   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
4533                     FALSE, FALSE, FALSE, 1, NULL, NULL, NULL, NULL, TRUE);
4534   XmTextSetString (h, local);
4535   XmTextShowPosition (h, 0);
4536   XtAddCallback (h, XmNmodifyVerifyCallback, Nlm_TextFieldCallback, (XtPointer)t);
4537   XtAddCallback (h, XmNvalueChangedCallback, Nlm_TextCallback, (XtPointer) t);
4538   XtAddCallback (h, XmNactivateCallback, Nlm_ReturnCallback, (XtPointer) t);
4539   XtAddCallback (h, XmNfocusCallback, Nlm_FocusCallback, (XtPointer) t);
4540   XtAddCallback (h, XmNlosingFocusCallback, Nlm_LoseFocusCallback, (XtPointer) t);
4541   XtManageChild( h );
4542 
4543   if (fontlist != NULL) XmFontListFree (fontlist);
4544   allowTextCallback = TRUE;
4545 #endif
4546 
4547   Nlm_LoadAction ((Nlm_GraphiC) t, (Nlm_ActnProc) actn);
4548 }
4549 
4550 
Nlm_NewSpecialTextWithFont(Nlm_TexT t,Nlm_CharPtr dfault,Nlm_TxtActnProc actn,Nlm_TxtActnProc tabProc,Nlm_TxtActnProc rtnProc,Nlm_FonT font)4551 static void Nlm_NewSpecialTextWithFont (Nlm_TexT t, Nlm_CharPtr dfault,
4552                                 Nlm_TxtActnProc actn, Nlm_TxtActnProc tabProc,
4553                                 Nlm_TxtActnProc rtnProc,
4554                                 Nlm_FonT font)
4555 
4556 {
4557   Nlm_TextTool    h;
4558   Nlm_Char        local [128];
4559   Nlm_RecT        r;
4560   Nlm_WindowTool  wptr;
4561 #ifdef WIN_MAC
4562   Nlm_RectTool    rtool;
4563 #endif
4564 #ifdef WIN_MSWIN
4565   Nlm_Uint4       style;
4566   Nlm_FntPtr fntptr;
4567 #endif
4568 #ifdef WIN_MOTIF
4569   XmFontList      fontlist;
4570   Nlm_FntPtr      fntptr;
4571   Cardinal        n;
4572   Arg             wargs[20];
4573   String          trans =
4574     "<Key>Tab:     do_tab()  \n\
4575      <Key>Return:  do_return()";
4576 #endif
4577 
4578   Nlm_StringNCpy_0(local, dfault, sizeof(local));
4579 
4580   Nlm_GetRect ((Nlm_GraphiC) t, &r);
4581   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) t);
4582 
4583 #ifdef WIN_MAC
4584   Nlm_InsetRect (&r, 2, 2);
4585   Nlm_RecTToRectTool (&r, &rtool);
4586   h = TENew (&rtool, &rtool);
4587   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
4588                     FALSE, FALSE, TRUE, 1, NULL, NULL, tabProc, rtnProc, TRUE);
4589   Nlm_SetDialogText ((Nlm_GraphiC) t, 0, local, FALSE);
4590   if (h != NULL) {
4591     TEAutoView (TRUE, h);
4592   }
4593 #endif
4594 
4595 #ifdef WIN_MSWIN
4596   allowTextCallback = FALSE;
4597   style = WS_CHILD | WS_BORDER | ES_MULTILINE | ES_AUTOVSCROLL | ES_LEFT;
4598   h = CreateWindow ("Edit", local, style,
4599                     r.left, r.top, r.right - r.left,
4600                     r.bottom - r.top, wptr, 0,
4601                     Nlm_currentHInst, NULL);
4602   if (h != NULL) {
4603     SetProp (h, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) t);
4604   }
4605   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
4606                     FALSE, FALSE, TRUE, 1, NULL, NULL, tabProc, rtnProc, TRUE);
4607   if (lpfnNewTextProc == NULL) {
4608     lpfnNewTextProc = (WNDPROC) MakeProcInstance ((FARPROC) TextProc, Nlm_currentHInst);
4609   }
4610   if (lpfnOldTextProc == NULL) {
4611     lpfnOldTextProc = (WNDPROC) GetWindowLongPtr (h, GWLP_WNDPROC);
4612   } else if (lpfnOldTextProc != (WNDPROC) GetWindowLongPtr (h, GWLP_WNDPROC)) {
4613     Nlm_Message (MSG_ERROR, "TextProc subclass error");
4614   }
4615   SetWindowLongPtr (h, GWLP_WNDPROC, (LONG_PTR) lpfnNewTextProc);
4616   allowTextCallback = TRUE;
4617   fntptr = (Nlm_FntPtr) Nlm_HandLock (font);
4618   SetWindowFont(h, fntptr->handle, FALSE);
4619   Nlm_HandUnlock(font);
4620 #endif
4621 
4622 #ifdef WIN_MOTIF
4623   allowTextCallback = FALSE;
4624   fntptr = (Nlm_FntPtr) Nlm_HandLock (font);
4625   fontlist = XmFontListCreate (fntptr->handle, XmSTRING_DEFAULT_CHARSET);
4626   Nlm_HandUnlock (font);
4627   Nlm_InsetRect (&r, 3, 3);
4628 
4629   n = 0;
4630   XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
4631   XtSetArg (wargs [n], XmNy, (Position) r.top); n++;
4632   XtSetArg (wargs [n], XmNwidth,  (Dimension) (r.right - r.left + 1)); n++;
4633   XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top + 1)); n++;
4634   XtSetArg (wargs [n], XmNmarginHeight, (Dimension) 1); n++;
4635   XtSetArg (wargs [n], XmNmarginWidth,  (Dimension) 2); n++;
4636   XtSetArg (wargs [n], XmNborderWidth,  (Dimension) 0); n++;
4637   XtSetArg (wargs [n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
4638   XtSetArg (wargs [n], XmNfontList, fontlist); n++;
4639   XtSetArg (wargs [n], XmNhighlightThickness, 0); n++;
4640   XtSetArg (wargs [n], XmNautoShowCursorPosition, TRUE); n++;
4641   XtSetArg (wargs [n], XmNverifyBell, FALSE); n++;
4642   h = XmCreateText (wptr, (String) "", wargs, n);
4643   XtOverrideTranslations (h, XtParseTranslationTable (trans));
4644   XtVaSetValues (h, XmNuserData, (XtPointer) t, NULL);
4645   Nlm_LoadTextData (t, h, NULL, NULL, FALSE, NULL, 0, FALSE,
4646                     FALSE, FALSE, TRUE, 1, NULL, NULL, tabProc, rtnProc, TRUE);
4647   XmTextSetString (h, local);
4648   XmTextShowPosition (h, 0);
4649   XtAddCallback (h, XmNmodifyVerifyCallback, Nlm_RefreshCallback, (XtPointer) t);
4650   XtAddCallback (h, XmNvalueChangedCallback, Nlm_TextCallback, (XtPointer) t);
4651   XtAddCallback (h, XmNactivateCallback, Nlm_HiddenActivateCallback, (XtPointer) t);
4652   XtAddCallback (h, XmNfocusCallback, Nlm_FocusCallback, (XtPointer) t);
4653   XtAddCallback (h, XmNlosingFocusCallback, Nlm_LoseFocusCallback, (XtPointer) t);
4654   XtManageChild( h );
4655 
4656   if (fontlist != NULL) XmFontListFree (fontlist);
4657   allowTextCallback = TRUE;
4658 #endif
4659 
4660   Nlm_LoadAction ((Nlm_GraphiC) t, (Nlm_ActnProc) actn);
4661 }
4662 
4663 
Nlm_DialogTextWithFont(Nlm_GrouP prnt,Nlm_CharPtr dfault,Nlm_Int2 charWidth,Nlm_TxtActnProc actn,Nlm_FonT font)4664 extern Nlm_TexT Nlm_DialogTextWithFont (Nlm_GrouP prnt, Nlm_CharPtr dfault,
4665                                 Nlm_Int2 charWidth, Nlm_TxtActnProc actn,
4666 								Nlm_FonT font)
4667 
4668 {
4669   Nlm_Int2    cwid;
4670   Nlm_Int2    hbounds;
4671   Nlm_PoinT   npt;
4672   Nlm_RecT    r;
4673   Nlm_TexT    t;
4674   Nlm_WindoW  tempPort;
4675   Nlm_Int2    vbounds;
4676 
4677   t = NULL;
4678   if (prnt != NULL) {
4679     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
4680     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
4681     Nlm_SelectFont (font);
4682     if (charWidth == 0) {
4683       cwid = Nlm_StringWidth (dfault);
4684     } else {
4685       cwid = (Nlm_Int2)(charWidth * Nlm_stdCharWidth);
4686     }
4687 #ifdef WIN_MAC
4688     hbounds = 2;
4689     vbounds = 2;
4690 #endif
4691 #ifdef WIN_MSWIN
4692     hbounds = 3;
4693     vbounds = (Nlm_Int2)((Nlm_stdFontHeight * 3 / 2 - Nlm_stdLineHeight) / 2);
4694 #endif
4695 #ifdef WIN_MOTIF
4696     hbounds = 3;
4697     vbounds = 3;
4698 #endif
4699     r.left = npt.x;
4700     r.top  = npt.y;
4701     r.right  = (Nlm_Int2)(r.left + cwid + 2 + hbounds * 2);
4702     r.bottom = (Nlm_Int2)(r.top + Nlm_stdLineHeight + vbounds * 2);
4703     t = (Nlm_TexT) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r,
4704                                    sizeof (Nlm_TextRec), dialogTextProcs);
4705     if (t != NULL) {
4706       Nlm_NewDialogTextWithFont (t, dfault, actn, font);
4707 #ifdef WIN_MAC
4708       Nlm_DoSelect ((Nlm_GraphiC) t, FALSE);
4709 #endif
4710       Nlm_DoAdjustPrnt ((Nlm_GraphiC) t, &r, TRUE, FALSE);
4711       Nlm_DoShow ((Nlm_GraphiC) t, TRUE, FALSE);
4712     }
4713     Nlm_RestorePort (tempPort);
4714   }
4715   return t;
4716 }
4717 
4718 
Nlm_SpecialTextWithFont(Nlm_GrouP prnt,Nlm_CharPtr dfault,Nlm_Int2 charWidth,Nlm_TxtActnProc actn,Nlm_TxtActnProc tabProc,Nlm_TxtActnProc rtnProc,Nlm_FonT font)4719 extern Nlm_TexT Nlm_SpecialTextWithFont (Nlm_GrouP prnt, Nlm_CharPtr dfault,
4720                                  Nlm_Int2 charWidth, Nlm_TxtActnProc actn,
4721                                  Nlm_TxtActnProc tabProc, Nlm_TxtActnProc rtnProc,
4722                                  Nlm_FonT font)
4723 
4724 {
4725   Nlm_Int2    cwid;
4726   Nlm_Int2    hbounds;
4727   Nlm_PoinT   npt;
4728   Nlm_RecT    r;
4729   Nlm_TexT    t;
4730   Nlm_WindoW  tempPort;
4731   Nlm_Int2    vbounds;
4732 
4733   t = NULL;
4734   if (prnt != NULL) {
4735     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
4736     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
4737     Nlm_SelectFont (font);
4738     if (charWidth == 0) {
4739       cwid = Nlm_StringWidth (dfault);
4740     } else {
4741       cwid = (Nlm_Int2)(charWidth * Nlm_stdCharWidth);
4742     }
4743 #ifdef WIN_MAC
4744     hbounds = 2;
4745     vbounds = 2;
4746 #endif
4747 #ifdef WIN_MSWIN
4748     hbounds = 3;
4749     vbounds = (Nlm_Int2)((Nlm_stdFontHeight * 3 / 2 - Nlm_stdLineHeight) / 2);
4750 #endif
4751 #ifdef WIN_MOTIF
4752     hbounds = 3;
4753     vbounds = 3;
4754 #endif
4755     r.left = npt.x;
4756     r.top  = npt.y;
4757     r.right  = (Nlm_Int2)(r.left + cwid + 2 + hbounds * 2);
4758     r.bottom = (Nlm_Int2)(r.top + Nlm_stdLineHeight + vbounds * 2);
4759     t = (Nlm_TexT) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r,
4760                                    sizeof (Nlm_TextRec), specialTextProcs);
4761     if (t != NULL) {
4762       Nlm_NewSpecialTextWithFont (t, dfault, actn, tabProc, rtnProc, font);
4763 #ifdef WIN_MAC
4764       Nlm_DoSelect ((Nlm_GraphiC) t, FALSE);
4765 #endif
4766       Nlm_DoAdjustPrnt ((Nlm_GraphiC) t, &r, TRUE, FALSE);
4767       Nlm_DoShow ((Nlm_GraphiC) t, TRUE, FALSE);
4768     }
4769     Nlm_RestorePort (tempPort);
4770   }
4771   return t;
4772 }
4773 
4774