1 /*   vibslate.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:  vibslate.c
27 *
28 * Author:  Jonathan Kans
29 *
30 * Version Creation Date:   7/1/91
31 *
32 * $Revision: 6.50 $
33 *
34 * File Description:
35 *       Vibrant slate (universal drawing environment) functions
36 *
37 * Modifications:
38 * --------------------------------------------------------------------------
39 *
40 * ==========================================================================
41 */
42 
43 #ifdef _WIN32
44 #  /* Ensure availability of WM_MOUSEWHEEL, available from NT 4.0 on */
45 #  if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0400
46 #    undef _WIN32_WINNT
47 #  endif
48 #  ifndef _WIN32_WINNT
49 #    define _WIN32_WINNT 0x0400
50 #  endif
51 #endif
52 
53 #include <vibtypes.h>
54 #include <vibprocs.h>
55 #include <vibincld.h>
56 
57 #ifdef _OPENGL
58 
59 #ifdef WIN32  /* braindead MS GL header dependency */
60 #include <windows.h>
61 
62 #elif defined(WIN_MOTIF)
63 #include <GL/glx.h>
64 
65 #elif defined(WIN_MAC)
66 #include <agl.h>
67 
68 #else
69   OpenGL has not yet been implemented for this platform!
70 
71 #endif
72 
73 #include <GL/gl.h>
74 #ifdef WIN_MAC
75 #include <glu.h>
76 #else
77 #include <GL/glu.h>
78 #endif
79 
80 #endif /* _OPENGL */
81 
82 
83 #ifdef WIN_MAC
84 #define Nlm_SlateTool Nlm_Handle
85 #endif /* WIN_MAC */
86 
87 #ifdef WIN_MSWIN
88 #define Nlm_SlateTool HWND
89 #endif /* WIN_MSWIN */
90 
91 #ifdef WIN_MOTIF
92 #define Nlm_SlateTool Widget
93 #endif /* WIN_MOTIF */
94 
95 
96 typedef  struct  Nlm_slatedata {
97   Nlm_SlateTool    handle;
98   Nlm_BaR          vScrollBar;
99   Nlm_BaR          hScrollBar;
100   Nlm_Handle       rowHandles;
101   Nlm_Handle       colHandles;
102   Nlm_Int2         numRows;
103   Nlm_Int2         numCols;
104   Nlm_Boolean      border;
105   Nlm_Int2         barRows;
106   Nlm_Int2         vBefore;
107   Nlm_Int2         vAfter;
108   Nlm_SltScrlProc  vAction;
109   Nlm_SltCharProc  keyProc;
110   Nlm_Boolean      hasFocus;
111   Nlm_Int4         policy;
112 #ifdef _OPENGL
113   Nlm_ColorMTool   cMap;  /* used to hold the palette */
114   Nlm_Int2         cMapStatus;
115 #endif /* _OPENGL */
116 } Nlm_SlateData;
117 
118 
119 typedef  struct  Nlm_paneldata {
120   Nlm_PnlClckProc  click;
121   Nlm_PnlClckProc  drag;
122   Nlm_PnlClckProc  hold;
123   Nlm_PnlClckProc  release;
124   Nlm_PnlActnProc  draw;
125   Nlm_Int2         extra;
126   Nlm_PnlActnProc  reset;
127   Nlm_PaneL        prev;
128 } Nlm_PanelData;
129 
130 
131 /*
132 *  Panel data is on top of a slate record to allow simple and
133 *  autonomous panels (such as repeat buttons) to be implemented
134 *  as single entities.
135 */
136 
137 typedef  struct  Nlm_panelslaterec {
138   Nlm_BoxRec     boxR;
139   Nlm_SlateData  slate;
140   Nlm_PanelData  panel;
141   long           align; /* unused; for improved portability */
142 } Nlm_PanelRec, Nlm_SlateRec, PNTR Nlm_PnlPtr, PNTR Nlm_SltPtr;
143 
144 
145 typedef  struct  Nlm_offsetrec {
146   Nlm_Int2  offset;
147   Nlm_Int2  height;
148 } Nlm_OffsetRec, PNTR Nlm_OfsPtr;
149 
150 typedef struct Nlm_displaydata {
151   Nlm_Boolean  active;
152   Nlm_Boolean  changed;
153   Nlm_VoidPtr  buffer;
154   Nlm_Int2     offset;
155   Nlm_Int2     visLines;
156   Nlm_PoinT    cursorPos;
157 } Nlm_DisplayData;
158 
159 typedef struct Nlm_displayrec {
160   Nlm_PanelRec     panelR;
161   Nlm_DisplayData  display;
162 } Nlm_DisplayRec, PNTR Nlm_DspPtr;
163 
164 #define screenBufSize 100
165 
166 static Nlm_GphPrcsPtr   gphprcsptr = NULL;
167 
168 static Nlm_GphPrcsPtr   slateProcs;
169 static Nlm_GphPrcsPtr   panelProcs;
170 static Nlm_GphPrcsPtr   displayProcs;
171 
172 #ifdef WIN_MSWIN
173 static Nlm_SlatE        currentSlate = NULL;
174 #endif
175 
176 static Nlm_SlatE        recentSlate = NULL;
177 static Nlm_SlateData    recentSlateData;
178 
179 static Nlm_SlatE        recentlyClickedSlate = NULL;
180 #ifndef WIN_MSWIN
181 static Nlm_Int4         lastClickTime = 0;
182 #endif
183 
184 static Nlm_PaneL        recentlyClickedPanel = NULL;
185 
186 static Nlm_DisplaY      recentDisplay = NULL;
187 static Nlm_DisplayData  recentDisplayData;
188 
189 static Nlm_Uint2        screenPos;
190 static Nlm_Char         screenBfr [screenBufSize];
191 
192 static Nlm_Int2         disphght;
193 static Nlm_FonT         dispfont;
194 
195 #ifdef WIN_MSWIN
196 static Nlm_Char         slateclass [32];
197 static Nlm_Boolean      handlechar;
198 static Nlm_SlateTool    slateTimer;
199 static Nlm_Boolean      slateTimerUsed = FALSE;
200 #endif
201 
202 #ifdef WIN_MOTIF
203 static XtIntervalId     slateTimer;
204 static Nlm_Boolean      slateTimerUsed = FALSE;
205 static Nlm_PoinT        currentMousePos;
206 #endif
207 
208 extern Nlm_Boolean okayToDrawContents;
209 
210 extern void Nlm_AddSubwindowShell (Nlm_WindoW w, Nlm_ShellTool shell );
211 extern void Nlm_DelSubwindowShell (Nlm_WindoW w, Nlm_ShellTool shell );
212 
213 
214 static void Nlm_LoadSlateData (Nlm_SlatE s, Nlm_SlateTool hdl,
215                                Nlm_BaR vsb, Nlm_BaR hsb,
216                                Nlm_Handle rhdl, Nlm_Handle chdl,
217                                Nlm_Int2 nrws, Nlm_Int2 ncls,
218                                Nlm_Boolean bdr, Nlm_Int2 barrws,
219                                Nlm_Int2 vbfr, Nlm_Int2 vaftr,
220                                Nlm_SltScrlProc vact, Nlm_SltCharProc key,
221                                Nlm_Boolean fcs)
222 
223 {
224   Nlm_SltPtr     sp;
225   Nlm_SlateData  PNTR sptr;
226 
227   if (s != NULL) {
228     sp = (Nlm_SltPtr) Nlm_HandLock (s);
229     sptr = &(sp->slate);
230     sptr->handle = hdl;
231     sptr->vScrollBar = vsb;
232     sptr->hScrollBar = hsb;
233     sptr->rowHandles = rhdl;
234     sptr->colHandles = chdl;
235     sptr->numRows = nrws;
236     sptr->numCols = ncls;
237     sptr->border = bdr;
238     sptr->barRows = barrws;
239     sptr->vBefore = vbfr;
240     sptr->vAfter = vaftr;
241     sptr->vAction = vact;
242     sptr->keyProc = key;
243     sptr->hasFocus = fcs;
244 #ifdef _OPENGL
245     sptr->cMap = 0;
246 #endif
247     Nlm_HandUnlock (s);
248     recentSlate = NULL;
249   }
250 }
251 
252 static void Nlm_SetSlateData (Nlm_SlatE s, Nlm_SlateData * sdata)
253 
254 {
255   Nlm_SltPtr  sp;
256 
257   if (s != NULL && sdata != NULL) {
258     sp = (Nlm_SltPtr) Nlm_HandLock (s);
259     sp->slate = *sdata;
260     Nlm_HandUnlock (s);
261     recentSlate = s;
262     recentSlateData = *sdata;
263   }
264 }
265 
266 static void Nlm_GetSlateData (Nlm_SlatE s, Nlm_SlateData * sdata)
267 
268 {
269   Nlm_SltPtr  sp;
270 
271   if (s != NULL && sdata != NULL) {
272     if (s == recentSlate && NLM_RISKY) {
273       *sdata = recentSlateData;
274     } else {
275       sp = (Nlm_SltPtr) Nlm_HandLock (s);
276       *sdata = sp->slate;
277       Nlm_HandUnlock (s);
278       recentSlate = s;
279       recentSlateData = *sdata;
280     }
281   }
282 }
283 
284 static void Nlm_LoadPanelData (Nlm_PaneL p, Nlm_PnlClckProc clk,
285                                Nlm_PnlClckProc drg, Nlm_PnlClckProc hld,
286                                Nlm_PnlClckProc rls, Nlm_PnlActnProc drw,
287                                Nlm_Int2 xtra, Nlm_PnlActnProc rst,
288                                Nlm_PaneL prv)
289 
290 {
291   Nlm_PnlPtr     pp;
292   Nlm_PanelData  PNTR pptr;
293 
294   if (p != NULL) {
295     pp = (Nlm_PnlPtr) Nlm_HandLock (p);
296     pptr = &(pp->panel);
297     pptr->click = clk;
298     pptr->drag = drg;
299     pptr->hold = hld;
300     pptr->release = rls;
301     pptr->draw = drw;
302     pptr->extra = xtra;
303     pptr->reset = rst;
304     pptr->prev = prv;
305     Nlm_HandUnlock (p);
306   }
307 }
308 
309 static void Nlm_SetPanelData (Nlm_PaneL p, Nlm_PanelData * pdata)
310 
311 {
312   Nlm_PnlPtr  pp;
313 
314   if (p != NULL && pdata != NULL) {
315     pp = (Nlm_PnlPtr) Nlm_HandLock (p);
316     pp->panel = *pdata;
317     Nlm_HandUnlock (p);
318   }
319 }
320 
321 static void Nlm_GetPanelData (Nlm_PaneL p, Nlm_PanelData * pdata)
322 
323 {
324   Nlm_PnlPtr  pp;
325 
326   if (p != NULL && pdata != NULL) {
327     pp = (Nlm_PnlPtr) Nlm_HandLock (p);
328     *pdata = pp->panel;
329     Nlm_HandUnlock (p);
330   }
331 }
332 
333 static void Nlm_LoadDisplayData (Nlm_DisplaY d, Nlm_Boolean actv,
334                                  Nlm_Boolean chgd, Nlm_VoidPtr bufr,
335                                  Nlm_Int2 off, Nlm_Int2 vis,
336                                  Nlm_PoinT pos)
337 
338 {
339   Nlm_DisplayData  PNTR ddptr;
340   Nlm_DspPtr       dp;
341 
342   if (d != NULL) {
343     dp = (Nlm_DspPtr) Nlm_HandLock (d);
344     ddptr = &(dp->display);
345     ddptr->active = actv;
346     ddptr->changed = chgd;
347     ddptr->buffer = bufr;
348     ddptr->offset = off;
349     ddptr->visLines = vis;
350     ddptr->cursorPos = pos;
351     Nlm_HandUnlock (d);
352     recentDisplay = NULL;
353   }
354 }
355 
356 static void Nlm_SetDisplayData (Nlm_DisplaY d, Nlm_DisplayData * ddata)
357 
358 {
359   Nlm_DspPtr  dp;
360 
361   if (d != NULL && ddata != NULL) {
362     dp = (Nlm_DspPtr) Nlm_HandLock (d);
363     dp->display = *ddata;
364     Nlm_HandUnlock (d);
365     recentDisplay = d;
366     recentDisplayData = *ddata;
367   }
368 }
369 
370 static void Nlm_GetDisplayData (Nlm_DisplaY d, Nlm_DisplayData * ddata)
371 
372 {
373   Nlm_DspPtr  dp;
374 
375   if (d != NULL && ddata != NULL) {
376     if (d == recentDisplay && NLM_RISKY) {
377       *ddata = recentDisplayData;
378     } else {
379       dp = (Nlm_DspPtr) Nlm_HandLock (d);
380       *ddata = dp->display;
381       Nlm_HandUnlock (d);
382       recentDisplay = d;
383       recentDisplayData = *ddata;
384     }
385   }
386 }
387 
388 extern void Nlm_SetPanelExtra (Nlm_PaneL p, Nlm_VoidPtr sptr)
389 
390 {
391   Nlm_BytePtr  dst;
392   Nlm_Int2     extra;
393   Nlm_PnlPtr   pp;
394   Nlm_BytePtr  src;
395 
396   if (p != NULL && sptr != NULL) {
397     pp = (Nlm_PnlPtr) Nlm_HandLock (p);
398     extra = pp->panel.extra;
399     dst = (Nlm_BytePtr) pp + sizeof (Nlm_PanelRec);
400     src = (Nlm_BytePtr) sptr;
401     while (extra > 0) {
402       *dst = *src;
403       dst++;
404       src++;
405       extra--;
406     }
407     Nlm_HandUnlock (p);
408   }
409 }
410 
411 extern void Nlm_GetPanelExtra (Nlm_PaneL p, Nlm_VoidPtr sptr)
412 
413 {
414   Nlm_BytePtr  dst;
415   Nlm_Int2     extra;
416   Nlm_PnlPtr   pp;
417   Nlm_BytePtr  src;
418 
419   if (p != NULL && sptr != NULL) {
420     pp = (Nlm_PnlPtr) Nlm_HandLock (p);
421     extra = pp->panel.extra;
422     src = (Nlm_BytePtr) pp + sizeof (Nlm_PanelRec);
423     dst = (Nlm_BytePtr) sptr;
424     while (extra > 0) {
425       *dst = *src;
426       dst++;
427       src++;
428       extra--;
429     }
430     Nlm_HandUnlock (p);
431   }
432 }
433 
434 static Nlm_SlateTool Nlm_GetSlateHandle (Nlm_SlatE s)
435 
436 {
437   Nlm_SlateData  sdata;
438 
439   Nlm_GetSlateData (s, &sdata);
440   return sdata.handle;
441 }
442 
443 extern Nlm_BaR Nlm_GetSlateVScrollBar (Nlm_SlatE s)
444 
445 {
446   Nlm_SlateData  sdata;
447 
448   Nlm_GetSlateData (s, &sdata);
449   return sdata.vScrollBar;
450 }
451 
452 extern Nlm_BaR Nlm_GetSlateHScrollBar (Nlm_SlatE s)
453 
454 {
455   Nlm_SlateData  sdata;
456 
457   Nlm_GetSlateData (s, &sdata);
458   return sdata.hScrollBar;
459 }
460 
461 
462 static Nlm_Boolean Nlm_GetSlateBorder (Nlm_SlatE s)
463 
464 {
465   Nlm_SlateData  sdata;
466 
467   Nlm_GetSlateData (s, &sdata);
468   return sdata.border;
469 }
470 
471 /* dgg -- lets turn off that border sometimes */
472 
473 extern void Nlm_SetSlateBorder (Nlm_SlatE s, Nlm_Boolean turnon)
474 
475 {
476   Nlm_SlateData  sdata;
477 
478   Nlm_GetSlateData (s, &sdata);
479   sdata.border = turnon;
480   Nlm_SetSlateData (s, &sdata);
481 }
482 
483 static Nlm_SltCharProc Nlm_GetSlateCharProc (Nlm_SlatE s)
484 
485 {
486   Nlm_SlateData  sdata;
487 
488   Nlm_GetSlateData (s, &sdata);
489   return sdata.keyProc;
490 }
491 
492 extern void Nlm_SetSlateChar (Nlm_SlatE s, Nlm_SltCharProc chr)
493 
494 {
495   Nlm_SlateData  sdata;
496 
497   Nlm_GetSlateData (s, &sdata);
498   sdata.keyProc = chr;
499   Nlm_SetSlateData (s, &sdata);
500 }
501 
502 static Nlm_Boolean Nlm_SlateHasFocus (Nlm_SlatE s)
503 
504 {
505   Nlm_SlateData  sdata;
506 
507   Nlm_GetSlateData (s, &sdata);
508   return sdata.hasFocus;
509 }
510 
511 static void Nlm_ChangeSlateFocus (Nlm_SlatE s, Nlm_Boolean fcs)
512 
513 {
514   Nlm_SlateData  sdata;
515 
516   Nlm_GetSlateData (s, &sdata);
517   sdata.hasFocus = fcs;
518   Nlm_SetSlateData (s, &sdata);
519 }
520 
521 static Nlm_PnlClckProc Nlm_GetPanelClick (Nlm_PaneL p)
522 
523 {
524   Nlm_PanelData  pdata;
525 
526   Nlm_GetPanelData (p, &pdata);
527   return pdata.click;
528 }
529 
530 static Nlm_PnlClckProc Nlm_GetPanelDrag (Nlm_PaneL p)
531 
532 {
533   Nlm_PanelData  pdata;
534 
535   Nlm_GetPanelData (p, &pdata);
536   return pdata.drag;
537 }
538 
539 static Nlm_PnlClckProc Nlm_GetPanelHold (Nlm_PaneL p)
540 
541 {
542   Nlm_PanelData  pdata;
543 
544   Nlm_GetPanelData (p, &pdata);
545   return pdata.hold;
546 }
547 
548 static Nlm_PnlClckProc Nlm_GetPanelRelease (Nlm_PaneL p)
549 
550 {
551   Nlm_PanelData  pdata;
552 
553   Nlm_GetPanelData (p, &pdata);
554   return pdata.release;
555 }
556 
557 static Nlm_PnlActnProc Nlm_GetPanelDraw (Nlm_PaneL p)
558 
559 {
560   Nlm_PanelData  pdata;
561 
562   Nlm_GetPanelData (p, &pdata);
563   return pdata.draw;
564 }
565 
566 static void Nlm_SetPanelPrev (Nlm_PaneL p, Nlm_PaneL prv)
567 
568 {
569   Nlm_PanelData  pdata;
570 
571   Nlm_GetPanelData (p, &pdata);
572   pdata.prev = prv;
573   Nlm_SetPanelData (p, &pdata);
574 }
575 
576 static Nlm_PaneL Nlm_GetPanelPrev (Nlm_PaneL p)
577 
578 {
579   Nlm_PanelData  pdata;
580 
581   Nlm_GetPanelData (p, &pdata);
582   return pdata.prev;
583 }
584 
585 
586 static void Nlm_SetCursorPos (Nlm_DisplaY d, Nlm_PoinT pt)
587 
588 {
589   Nlm_DisplayData  ddata;
590 
591   Nlm_GetDisplayData (d, &ddata);
592   ddata.cursorPos = pt;
593   Nlm_SetDisplayData (d, &ddata);
594 }
595 
596 static void Nlm_GetCursorPos (Nlm_DisplaY d, Nlm_PointPtr pt)
597 
598 {
599   Nlm_DisplayData  ddata;
600 
601   Nlm_GetDisplayData (d, &ddata);
602   *pt = ddata.cursorPos;
603 }
604 
605 static Nlm_PaneL Nlm_CreateReverseLinks (Nlm_SlatE s)
606 
607 {
608   Nlm_PaneL  last;
609   Nlm_PaneL  n;
610   Nlm_PaneL  p;
611 
612   p = (Nlm_PaneL) Nlm_GetChild ((Nlm_GraphiC) s);
613   Nlm_SetPanelPrev (p, NULL);
614   last = p;
615   while (p != NULL) {
616     n = (Nlm_PaneL) Nlm_GetNext ((Nlm_GraphiC) p);
617     if (n != NULL) {
618       Nlm_SetPanelPrev (n, p);
619       last = n;
620     }
621     p = n;
622   }
623   return last;
624 }
625 
626 
627 /* return TRUE if the "ch" has been processed */
628 static Nlm_Boolean Nlm_HandleSlateInput(Nlm_SlatE s, Nlm_Char ch)
629 {
630   Nlm_Boolean     has_focus = Nlm_SlateHasFocus( s );
631   Nlm_Int4        policy    = Nlm_SetSlatePolicy(s, GET_VALUE);
632   Nlm_SltCharProc keyProc   = Nlm_GetSlateCharProc( s );
633 
634   if ((policy & FOCUS_NAVIG)  ||  !has_focus  ||  !keyProc)
635     { /* try standard slate navigation keys, if activated */
636       Nlm_BaR  vsb = Nlm_GetSlateVScrollBar( s );
637       Nlm_BaR  hsb = Nlm_GetSlateHScrollBar( s );
638 
639       switch ( ch )
640         {
641         case NLM_RIGHT:
642         case NLM_LEFT:
643           if (policy & HORIZ_ARROW) {
644             Nlm_Scroll(hsb, (ch == NLM_RIGHT) ? SCROLL_LINEDN : SCROLL_LINEUP);
645             return TRUE;
646           }
647           break;
648 
649         case NLM_DOWN:
650         case NLM_UP:
651           if (policy & VERT_ARROW) {
652             Nlm_Scroll(vsb, (ch == NLM_DOWN) ? SCROLL_LINEDN : SCROLL_LINEUP);
653             return TRUE;
654           }
655           break;
656 
657         case NLM_END:
658         case NLM_HOME:
659           if (policy & HORIZ_PAGE) {
660             Nlm_Scroll(hsb, (ch == NLM_END) ? SCROLL_PAGEDN : SCROLL_PAGEUP);
661             return TRUE;
662           }
663           break;
664 
665         case NLM_NEXT:
666         case NLM_PREV:
667           if (policy & VERT_PAGE) {
668             Nlm_Scroll(vsb, (ch == NLM_NEXT) ? SCROLL_PAGEDN : SCROLL_PAGEUP);
669             return TRUE;
670           }
671           break;
672         }
673     }
674 
675   /* try the user-specified key handling, if any */
676   if (has_focus  &&  keyProc)
677     {
678       keyProc(s, ch);
679       return TRUE;
680     }
681 
682   return FALSE;
683 }
684 
685 
686 #ifdef WIN_MAC
687 static Nlm_Boolean Nlm_SlateClick (Nlm_GraphiC s, Nlm_PoinT pt)
688 
689 {
690   Nlm_PnlClckProc  clk;
691   Nlm_Int4         delta;
692   Nlm_PnlClckProc  drg;
693   Nlm_Int2         hOffset;
694   Nlm_BaR          hsb;
695   Nlm_PoinT        mpt;
696   Nlm_PaneL        n;
697   Nlm_Int4         newtime;
698   Nlm_Boolean      notInside;
699   Nlm_Int4         oldtime;
700   Nlm_PoinT        opt;
701   Nlm_PaneL        p;
702   Nlm_PanelData    pdata;
703   Nlm_PnlClckProc  prs;
704   Nlm_RecT         r;
705   Nlm_PnlClckProc  rls;
706   Nlm_Boolean      rsult;
707   Nlm_RecT         sr;
708   Nlm_Int4         ticks;
709   Nlm_Int2         vOffset;
710   Nlm_BaR          vsb;
711 
712   ticks = Nlm_ComputerTime ();
713   rsult = FALSE;
714   Nlm_GetRect (s, &r);
715   Nlm_GetRect (s, &sr);
716   vsb = Nlm_GetSlateVScrollBar ((Nlm_SlatE) s);
717   hsb = Nlm_GetSlateHScrollBar ((Nlm_SlatE) s);
718   if (vsb != NULL) {
719     r.right += Nlm_vScrollBarWidth;
720   }
721   if (hsb != NULL) {
722     r.bottom += Nlm_hScrollBarHeight;
723   }
724   if (Nlm_PtInRect (pt, &r)) {
725     if ((Nlm_SlatE) s == recentlyClickedSlate) {
726       delta = ticks - lastClickTime;
727       if (delta <= GetDblTime ()) {
728         Nlm_dblClick = TRUE;
729       }
730     }
731     lastClickTime = ticks;
732     recentlyClickedSlate = (Nlm_SlatE) s;
733     recentlyClickedPanel = NULL;
734     if (vsb != NULL) {
735       r.right -= Nlm_vScrollBarWidth;
736     }
737     if (hsb != NULL) {
738       r.bottom -= Nlm_hScrollBarHeight;
739     }
740     if (vsb != NULL && Nlm_DoClick ((Nlm_GraphiC) vsb, pt)) {
741       Nlm_dblClick = FALSE;
742       recentlyClickedSlate = NULL;
743     } else if (hsb != NULL && Nlm_DoClick ((Nlm_GraphiC) hsb, pt)) {
744       Nlm_dblClick = FALSE;
745       recentlyClickedSlate = NULL;
746     } else if (Nlm_PtInRect (pt, &r)) {
747       Nlm_SelectFont (Nlm_systemFont);
748       Nlm_ResetDrawingTools ();
749       Nlm_GetPanelData ((Nlm_PaneL) s, &pdata);
750       if (pdata.click != NULL || pdata.drag != NULL || pdata.hold != NULL ||
751           pdata.release != NULL || pdata.draw != NULL || pdata.reset != NULL) {
752         p = (Nlm_PaneL) s;
753         recentlyClickedPanel = p;
754         clk = Nlm_GetPanelClick (p);
755         if (clk != NULL && Nlm_GetEnabled ((Nlm_GraphiC) p) && Nlm_GetVisible ((Nlm_GraphiC) p)) {
756           Nlm_ClipRect (&sr);
757           clk (p, pt);
758           Nlm_Update ();
759         }
760       } else {
761         p = Nlm_CreateReverseLinks ((Nlm_SlatE) s);
762         notInside = TRUE;
763         while (p != NULL && notInside) {
764           n = Nlm_GetPanelPrev (p);
765           Nlm_GetPanelData (p, &pdata);
766           if (pdata.click != NULL || pdata.drag != NULL ||
767               pdata.hold != NULL || pdata.release != NULL) {
768             Nlm_GetRect ((Nlm_GraphiC) p, &r);
769             Nlm_DoGetOffset ((Nlm_GraphiC) p, &hOffset, &vOffset);
770             Nlm_OffsetRect (&r, -hOffset, -vOffset);
771             if (Nlm_PtInRect (pt, &r) && Nlm_GetEnabled ((Nlm_GraphiC) p) &&
772                 Nlm_GetVisible ((Nlm_GraphiC) p)) {
773               recentlyClickedPanel = p;
774               notInside = FALSE;
775               clk = Nlm_GetPanelClick (p);
776               if (clk != NULL) {
777                 Nlm_ClipRect (&sr);
778                 clk (p, pt);
779                 Nlm_Update ();
780               }
781             }
782           }
783           p = n;
784         }
785       }
786       if (recentlyClickedPanel != NULL) {
787         p = recentlyClickedPanel;
788         mpt = pt;
789         oldtime = Nlm_ComputerTime ();
790         drg = Nlm_GetPanelDrag (p);
791         prs = Nlm_GetPanelHold (p);
792         while (StillDown () && recentlyClickedPanel != NULL) {
793           opt = mpt;
794           newtime = Nlm_ComputerTime ();
795           Nlm_MousePosition (&mpt);
796           if (Nlm_EqualPt (opt, mpt)) {
797             if (prs != NULL && newtime >= oldtime + 6) {
798               Nlm_ResetDrawingTools ();
799               Nlm_ClipRect (&sr);
800               prs (p, mpt);
801               oldtime += 6;
802             }
803           } else {
804             if (drg != NULL) {
805               Nlm_ResetDrawingTools ();
806               Nlm_ClipRect (&sr);
807               drg (p, mpt);
808             }
809           }
810           Nlm_Update ();
811           Nlm_ProcessTimerEvent ();
812         }
813         rls = Nlm_GetPanelRelease (p);
814         if (rls != NULL && recentlyClickedPanel != NULL) {
815           Nlm_MousePosition (&mpt);
816           Nlm_ResetDrawingTools ();
817           Nlm_ClipRect (&sr);
818           rls (p, mpt);
819         }
820       }
821       Nlm_SelectFont (Nlm_systemFont);
822       Nlm_ResetDrawingTools ();
823       Nlm_ResetClip ();
824       rsult = TRUE;
825     }
826   }
827   return rsult;
828 }
829 
830 static Nlm_Boolean Nlm_SlateKey (Nlm_GraphiC s, Nlm_Char ch)
831 
832 {
833   Nlm_Boolean      act;
834   Nlm_SltCharProc  keyProc;
835   Nlm_Boolean      rsult;
836 
837   rsult = FALSE;
838   act = Nlm_SlateHasFocus ((Nlm_SlatE) s);
839   if (act && ! Nlm_cmmdKey) {
840     if (ch != '\0') {
841       keyProc = Nlm_GetSlateCharProc ((Nlm_SlatE) s);
842       if (keyProc != NULL) {
843         keyProc ((Nlm_SlatE) s, ch);
844         rsult = TRUE;
845       }
846     }
847   }
848   return rsult;
849 }
850 #endif
851 
852 #ifdef WIN_MSWIN
853 static Nlm_Boolean Nlm_SlateCommand (Nlm_GraphiC s)
854 
855 {
856   return FALSE;
857 }
858 #endif
859 
860 #ifdef WIN_MOTIF
861 static void Nlm_SlateCallback (Nlm_GraphiC s)
862 
863 {
864 }
865 #endif
866 
867 #ifdef WIN_MAC
868 static void Nlm_DrawSlate (Nlm_GraphiC s)
869 
870 {
871   Nlm_PnlActnProc  drw;
872   Nlm_BaR          hsb;
873   Nlm_PaneL        n;
874   Nlm_PaneL        p;
875   Nlm_PanelData    pdata;
876   Nlm_RecT         r;
877   Nlm_BaR          vsb;
878 
879   if (Nlm_GetVisible (s) && Nlm_GetAllParentsVisible (s) && okayToDrawContents) {
880     Nlm_GetRect (s, &r);
881 
882     vsb = Nlm_GetSlateVScrollBar ((Nlm_SlatE) s);
883     hsb = Nlm_GetSlateHScrollBar ((Nlm_SlatE) s);
884     if (vsb != NULL) {
885       r.right += Nlm_vScrollBarWidth;
886     }
887     if (hsb != NULL) {
888       r.bottom += Nlm_hScrollBarHeight;
889     }
890 
891     if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
892       if (vsb != NULL) {
893         Nlm_DoDraw ((Nlm_GraphiC) vsb);
894       }
895       if (hsb != NULL) {
896         Nlm_DoDraw ((Nlm_GraphiC) hsb);
897       }
898       Nlm_SelectFont (Nlm_systemFont);
899       Nlm_ResetDrawingTools ();
900       if (Nlm_GetSlateBorder ((Nlm_SlatE) s)) {
901         Nlm_FrameRect (&r);
902       }
903       Nlm_GetRect (s, &r);
904       Nlm_GetPanelData ((Nlm_PaneL) s, &pdata);
905       if (pdata.click != NULL || pdata.drag != NULL || pdata.hold != NULL ||
906           pdata.release != NULL || pdata.draw != NULL || pdata.reset != NULL) {
907         p = (Nlm_PaneL) s;
908 /*
909         recentlyClickedPanel = p;
910 */
911         drw = Nlm_GetPanelDraw (p);
912         if (drw != NULL && Nlm_GetVisible ((Nlm_GraphiC) p)) {
913           Nlm_ClipRect (&r);
914           drw (p);
915           Nlm_ResetDrawingTools ();
916         }
917       } else {
918         p = (Nlm_PaneL) Nlm_GetChild (s);
919         while (p != NULL) {
920           n = (Nlm_PaneL) Nlm_GetNext ((Nlm_GraphiC) p);
921           drw = Nlm_GetPanelDraw (p);
922           if (drw != NULL && Nlm_GetVisible ((Nlm_GraphiC) p)) {
923             Nlm_ClipRect (&r);
924             drw (p);
925             Nlm_ResetDrawingTools ();
926           }
927           p = n;
928         }
929       }
930       Nlm_ResetClip ();
931     }
932   }
933 }
934 #endif
935 
936 static void Nlm_SlateVertScrollAction (Nlm_BaR sb, Nlm_SlatE s,
937                                        Nlm_Int2 newval, Nlm_Int2 oldval)
938 
939 {
940   Nlm_SltScrlProc  actn;
941   Nlm_Int2         barRows;
942   Nlm_Int2         before;
943   Nlm_Int2         delta;
944   Nlm_Int2         height;
945   Nlm_Int2         i;
946   Nlm_Int2         last;
947   Nlm_Int2         limit = 0;
948   Nlm_Int2         numRows;
949   Nlm_Int2         oldPgDn;
950   Nlm_OfsPtr       optr;
951   Nlm_Int2         pgDn;
952   Nlm_Int2         pgUp;
953   Nlm_RecT         r;
954   Nlm_Handle       rhdl;
955   Nlm_SlateData    sdata;
956 
957   if (s != NULL && oldval != newval) {
958     if (Nlm_GetVisible ((Nlm_GraphiC) s) && Nlm_GetAllParentsVisible ((Nlm_GraphiC) s)) {
959       Nlm_GetRect ((Nlm_GraphiC) s, &r);
960       Nlm_InsetRect (&r, 4, 4);
961       height = (Nlm_Int2)(r.bottom - r.top);
962       Nlm_GetSlateData (s, &sdata);
963       numRows = sdata.numRows;
964       before = sdata.vBefore;
965       barRows = sdata.barRows;
966       if (newval >= before && newval <= before + barRows) {
967         newval -= before;
968         oldval -= before;
969         rhdl = sdata.rowHandles;
970         if (rhdl != NULL) {
971           optr = (Nlm_OfsPtr) Nlm_HandLock (rhdl);
972           i = (Nlm_Int2)(newval + 1);
973           pgDn = 0;
974           while (i < numRows && optr [i].offset + optr [i].height -
975                  optr [newval].offset <= height) {
976             i++;
977             pgDn++;
978           }
979           i = (Nlm_Int2)(newval - 1);
980           pgUp = 0;
981           while (i >= 0 && optr [newval].offset + optr [newval].height -
982                  optr [i].offset <= height) {
983             i--;
984             pgUp++;
985           }
986           delta = (Nlm_Int2)(optr[oldval].offset - optr[newval].offset);
987           if (delta < 0) {
988             i = (Nlm_Int2)(oldval + 1);
989             oldPgDn = 0;
990             while (i < numRows && optr [i].offset + optr [i].height -
991                    optr [oldval].offset <= height) {
992               i++;
993               oldPgDn++;
994             }
995             last  = (Nlm_Int2)(oldval + oldPgDn);
996             limit = (Nlm_Int2)(r.top + optr[last].offset + optr[last].height -
997                                optr[newval].offset);
998           } else if (delta > 0) {
999             last  = (Nlm_Int2)(newval + pgDn);
1000             limit = (Nlm_Int2)(r.top + optr[last].offset + optr[last].height -
1001                                optr[newval].offset);
1002           }
1003           Nlm_HandUnlock (rhdl);
1004           Nlm_DoSelect ((Nlm_GraphiC) s, FALSE);
1005           if (delta < 0 && -delta < height) {
1006             Nlm_ScrollRect (&r, 0, delta);
1007             r.top = limit;
1008             Nlm_InsetRect (&r, -1, -1);
1009             Nlm_InvalRect (&r);
1010           } else if (delta > 0 && delta < height) {
1011             Nlm_ScrollRect (&r, 0, delta);
1012             r.top = limit;
1013             Nlm_InsetRect (&r, -1, -1);
1014             Nlm_InvalRect (&r);
1015           } else {
1016             Nlm_InsetRect (&r, -1, -1);
1017             Nlm_InvalRect (&r);
1018           }
1019           if (pgUp < 1) {
1020             pgUp = 1;
1021           }
1022           if (pgDn < 1) {
1023             pgDn = 1;
1024           }
1025           Nlm_DoSetRange ((Nlm_GraphiC) sb, pgUp, pgDn, 0, FALSE);
1026           Nlm_Update ();
1027         }
1028       } else {
1029         actn = sdata.vAction;
1030         if (actn != NULL) {
1031           actn (sb, s, newval, oldval);
1032         }
1033       }
1034     }
1035   }
1036 }
1037 
1038 static void Nlm_SlateHorizScrollAction (Nlm_BaR sb, Nlm_SlatE s,
1039                                         Nlm_Int2 newval, Nlm_Int2 oldval)
1040 
1041 {
1042 }
1043 
1044 static void Nlm_ShowSlate (Nlm_GraphiC s, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1045 
1046 {
1047   Nlm_SlateTool  h;
1048   Nlm_BaR        hsb;
1049   Nlm_WindoW     tempPort;
1050   Nlm_BaR        vsb;
1051 
1052   if (setFlag) {
1053     Nlm_SetVisible (s, TRUE);
1054   }
1055   if (Nlm_GetVisible (s) && Nlm_AllParentsButWindowVisible (s)) {
1056     tempPort = Nlm_SavePortIfNeeded (s, savePort);
1057     vsb = Nlm_GetSlateVScrollBar ((Nlm_SlatE) s);
1058     hsb = Nlm_GetSlateHScrollBar ((Nlm_SlatE) s);
1059     if (vsb != NULL) {
1060       Nlm_DoShow ((Nlm_GraphiC) vsb, TRUE, FALSE);
1061     }
1062     if (hsb != NULL) {
1063       Nlm_DoShow ((Nlm_GraphiC) hsb, TRUE, FALSE);
1064     }
1065     h = Nlm_GetSlateHandle ((Nlm_SlatE) s);
1066 #ifdef WIN_MAC
1067 #ifdef WIN_MAC_QUARTZ
1068     Nlm_SetGraphicNeedsDisplay (s);
1069 #else
1070     Nlm_DoDraw (s);
1071 #endif
1072 #endif
1073 #ifdef WIN_MSWIN
1074     ShowWindow (h, SW_SHOW);
1075     UpdateWindow (h);
1076 #endif
1077 #ifdef WIN_MOTIF
1078     XtManageChild (h);
1079 #endif
1080     Nlm_RestorePort (tempPort);
1081   }
1082 }
1083 
1084 static void Nlm_ShowPanel (Nlm_GraphiC p, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1085 
1086 {
1087   Nlm_RecT    dr;
1088   Nlm_Int2    hOffset;
1089   Nlm_RecT    r;
1090   Nlm_SlatE   s;
1091   Nlm_RecT    sr;
1092   Nlm_Int2    vOffset;
1093   Nlm_WindoW  tempPort;
1094 
1095   if (setFlag) {
1096     Nlm_SetVisible (p, TRUE);
1097   }
1098   if (Nlm_GetVisible (p) && Nlm_AllParentsButWindowVisible (p)) {
1099     tempPort = Nlm_SavePortIfNeeded (p, savePort);
1100     Nlm_GetRect (p, &r);
1101     Nlm_DoGetOffset ((Nlm_GraphiC) p, &hOffset, &vOffset);
1102     Nlm_OffsetRect(&r, (Nlm_Int2)(-hOffset), (Nlm_Int2)(-vOffset));
1103     s = (Nlm_SlatE) Nlm_GetParent (p);
1104     Nlm_GetRect ((Nlm_GraphiC) s, &sr);
1105     Nlm_SectRect (&r, &sr, &dr);
1106     if (Nlm_RectInRect (&dr, &sr)) {
1107       Nlm_InsetRect (&dr, -1, -1);
1108       Nlm_InvalRect (&dr);
1109     }
1110     Nlm_RestorePort (tempPort);
1111   }
1112 }
1113 
1114 static void Nlm_HideSlate (Nlm_GraphiC s, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1115 
1116 {
1117   Nlm_SlateTool  h;
1118   Nlm_BaR        hsb;
1119   Nlm_WindoW     tempPort;
1120   Nlm_BaR        vsb;
1121 #ifdef WIN_MAC
1122   Nlm_RecT       r;
1123 #endif
1124 
1125   if (setFlag) {
1126     Nlm_SetVisible (s, FALSE);
1127   }
1128   tempPort = Nlm_SavePortIfNeeded (s, savePort);
1129   vsb = Nlm_GetSlateVScrollBar ((Nlm_SlatE) s);
1130   hsb = Nlm_GetSlateHScrollBar ((Nlm_SlatE) s);
1131   if (vsb != NULL) {
1132     Nlm_DoHide ((Nlm_GraphiC) vsb, TRUE, FALSE);
1133   }
1134   if (hsb != NULL) {
1135     Nlm_DoHide ((Nlm_GraphiC) hsb, TRUE, FALSE);
1136   }
1137   h = Nlm_GetSlateHandle ((Nlm_SlatE) s);
1138 #ifdef WIN_MAC
1139   if (Nlm_AllParentsButWindowVisible (s)) {
1140 #ifdef WIN_MAC_QUARTZ
1141     Nlm_SetGraphicNeedsDisplay (s);
1142 #else
1143     Nlm_GetRect (s, &r);
1144     if (vsb != NULL) {
1145       r.right += Nlm_vScrollBarWidth;
1146     }
1147     if (hsb != NULL) {
1148       r.bottom += Nlm_hScrollBarHeight;
1149     }
1150     Nlm_InsetRect (&r, -1, -1);
1151     Nlm_EraseRect (&r);
1152     Nlm_ValidRect (&r);
1153 #endif
1154   }
1155 #endif
1156 #ifdef WIN_MSWIN
1157   ShowWindow (h, SW_HIDE);
1158   UpdateWindow (h);
1159 #endif
1160 #ifdef WIN_MOTIF
1161   XtUnmanageChild (h);
1162 #endif
1163   Nlm_RestorePort (tempPort);
1164 }
1165 
1166 static void Nlm_HidePanel (Nlm_GraphiC p, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1167 
1168 {
1169   Nlm_RecT    dr;
1170   Nlm_Int2    hOffset;
1171   Nlm_RecT    r;
1172   Nlm_SlatE   s;
1173   Nlm_RecT    sr;
1174   Nlm_Int2    vOffset;
1175   Nlm_WindoW  tempPort;
1176 
1177   if (setFlag) {
1178     Nlm_SetVisible (p, FALSE);
1179   }
1180   tempPort = Nlm_SavePortIfNeeded (p, savePort);
1181   if (Nlm_AllParentsButWindowVisible (p)) {
1182     Nlm_GetRect (p, &r);
1183     Nlm_DoGetOffset ((Nlm_GraphiC) p, &hOffset, &vOffset);
1184     Nlm_OffsetRect(&r, (Nlm_Int2)(-hOffset), (Nlm_Int2)(-vOffset));
1185     s = (Nlm_SlatE) Nlm_GetParent (p);
1186     Nlm_GetRect ((Nlm_GraphiC) s, &sr);
1187     Nlm_SectRect (&r, &sr, &dr);
1188     if (Nlm_RectInRect (&dr, &sr)) {
1189       Nlm_InsetRect (&dr, -1, -1);
1190       Nlm_InvalRect (&dr);
1191     }
1192   }
1193   Nlm_RestorePort (tempPort);
1194 }
1195 
1196 static void Nlm_EnableSlate (Nlm_GraphiC s, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1197 
1198 {
1199   Nlm_SlateTool  h;
1200   Nlm_BaR        hsb;
1201   Nlm_RecT       r;
1202   Nlm_WindoW     tempPort;
1203   Nlm_BaR        vsb;
1204 
1205   if (setFlag) {
1206     Nlm_SetEnabled (s, TRUE);
1207   }
1208   if (Nlm_GetEnabled (s) && Nlm_GetAllParentsEnabled (s)) {
1209     tempPort = Nlm_SavePortIfNeeded (s, savePort);
1210     vsb = Nlm_GetSlateVScrollBar ((Nlm_SlatE) s);
1211     hsb = Nlm_GetSlateHScrollBar ((Nlm_SlatE) s);
1212     if (vsb != NULL) {
1213       Nlm_DoEnable ((Nlm_GraphiC) vsb, TRUE, FALSE);
1214     }
1215     if (hsb != NULL) {
1216       Nlm_DoEnable ((Nlm_GraphiC) hsb, TRUE, FALSE);
1217     }
1218     h = Nlm_GetSlateHandle ((Nlm_SlatE) s);
1219 #ifdef WIN_MSWIN
1220     EnableWindow (h, TRUE);
1221 #endif
1222 #ifdef WIN_MOTIF
1223     /*
1224     XtVaSetValues (h, XmNsensitive, TRUE, NULL);
1225     */
1226 #endif
1227     if (setFlag) {
1228       if (Nlm_GetVisible (s) && Nlm_GetAllParentsVisible (s)) {
1229         Nlm_DoSelect ((Nlm_GraphiC) s, FALSE);
1230         Nlm_GetRect (s, &r);
1231         Nlm_InsetRect (&r, 1, 1);
1232         Nlm_InvalRect (&r);
1233       }
1234     }
1235     Nlm_RestorePort (tempPort);
1236   }
1237 }
1238 
1239 static void Nlm_EnablePanel (Nlm_GraphiC p, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1240 
1241 {
1242   Nlm_SlatE  s;
1243 
1244   if (setFlag) {
1245     Nlm_SetEnabled (p, TRUE);
1246   }
1247   s = (Nlm_SlatE) Nlm_GetParent (p);
1248   Nlm_DoEnable ((Nlm_GraphiC) s, TRUE, savePort);
1249 }
1250 
1251 static void Nlm_DisableSlate (Nlm_GraphiC s, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1252 
1253 {
1254   Nlm_SlateTool  h;
1255   Nlm_BaR        hsb;
1256   Nlm_WindoW     tempPort;
1257   Nlm_BaR        vsb;
1258 
1259   if (setFlag) {
1260     Nlm_SetEnabled (s, FALSE);
1261   }
1262   tempPort = Nlm_SavePortIfNeeded (s, savePort);
1263   vsb = Nlm_GetSlateVScrollBar ((Nlm_SlatE) s);
1264   hsb = Nlm_GetSlateHScrollBar ((Nlm_SlatE) s);
1265   if (vsb != NULL) {
1266     Nlm_DoDisable ((Nlm_GraphiC) vsb, TRUE, FALSE);
1267   }
1268   if (hsb != NULL) {
1269     Nlm_DoDisable ((Nlm_GraphiC) hsb, TRUE, FALSE);
1270   }
1271   h = Nlm_GetSlateHandle ((Nlm_SlatE) s);
1272 #ifdef WIN_MSWIN
1273   EnableWindow (h, FALSE);
1274 #endif
1275 #ifdef WIN_MOTIF
1276   /*
1277   XtVaSetValues (h, XmNsensitive, FALSE, NULL);
1278   */
1279 #endif
1280   Nlm_RestorePort (tempPort);
1281 }
1282 
1283 static void Nlm_DisablePanel (Nlm_GraphiC p, Nlm_Boolean setFlag, Nlm_Boolean savePort)
1284 
1285 {
1286   Nlm_SlatE  s;
1287 
1288   if (setFlag) {
1289     Nlm_SetEnabled (p, FALSE);
1290   }
1291   s = (Nlm_SlatE) Nlm_GetParent (p);
1292   Nlm_DoDisable ((Nlm_GraphiC) s, TRUE, savePort);
1293 }
1294 
1295 static void Nlm_ResetSlate (Nlm_GraphiC s, Nlm_Boolean savePort)
1296 
1297 {
1298   Nlm_Handle       chdl;
1299   Nlm_BaR          hsb;
1300   Nlm_PaneL        n;
1301   Nlm_PoinT        npt;
1302   Nlm_PaneL        p;
1303   Nlm_PanelData    pdata;
1304   Nlm_RecT         r;
1305   Nlm_Handle       rhdl;
1306   Nlm_PnlActnProc  rst;
1307   Nlm_SlateData    sdata;
1308   Nlm_WindoW       tempPort;
1309   Nlm_BaR          vsb;
1310 
1311   tempPort = Nlm_SavePortIfNeeded (s, savePort);
1312   Nlm_GetSlateData ((Nlm_SlatE) s, &sdata);
1313   rhdl = sdata.rowHandles;
1314   if (rhdl != NULL) {
1315     Nlm_HandFree (rhdl);
1316   }
1317   chdl = sdata.colHandles;
1318   if (chdl != NULL) {
1319     Nlm_HandFree (chdl);
1320   }
1321   sdata.rowHandles = NULL;
1322   sdata.colHandles = NULL;
1323   sdata.numRows = 0;
1324   sdata.numCols = 0;
1325   sdata.barRows = 0;
1326   sdata.vBefore = 0;
1327   sdata.vAfter = 0;
1328   sdata.vAction = NULL;
1329   Nlm_SetSlateData ((Nlm_SlatE) s, &sdata);
1330   if (Nlm_GetVisible (s) && Nlm_GetAllParentsVisible (s) && Nlm_GetEnabled (s)) {
1331     Nlm_ResetClip ();
1332   }
1333   vsb = sdata.vScrollBar;
1334   hsb = sdata.hScrollBar;
1335   if (vsb != NULL) {
1336     Nlm_DoReset ((Nlm_GraphiC) vsb, FALSE);
1337   }
1338   if (hsb != NULL) {
1339     Nlm_DoReset ((Nlm_GraphiC) hsb, FALSE);
1340   }
1341   Nlm_GetRect (s, &r);
1342   Nlm_InsetRect (&r, 4, 4);
1343   Nlm_LoadPt (&npt, r.left, r.top);
1344   Nlm_LoadBoxData ((Nlm_BoX) s, npt, npt, npt, npt.y, npt.x, 0, 0, 0, 0, 0, 0);
1345   Nlm_GetPanelData ((Nlm_PaneL) s, &pdata);
1346   if (pdata.click != NULL || pdata.drag != NULL || pdata.hold != NULL ||
1347       pdata.release != NULL || pdata.draw != NULL || pdata.reset != NULL) {
1348     p = (Nlm_PaneL) s;
1349     Nlm_GetRect ((Nlm_GraphiC) p, &r);
1350     Nlm_LoadPt (&npt, r.left, r.top);
1351     Nlm_LoadBoxData ((Nlm_BoX) p, npt, npt, npt, npt.y, npt.x, 0, 0, 0, 0, 0, 0);
1352     rst = pdata.reset;
1353     if (rst != NULL) {
1354       rst (p);
1355     }
1356   } else {
1357     p = (Nlm_PaneL) Nlm_GetChild (s);
1358     while (p != NULL) {
1359       n = (Nlm_PaneL) Nlm_GetNext ((Nlm_GraphiC) p);
1360       Nlm_DoReset ((Nlm_GraphiC) p, FALSE);
1361       p = n;
1362     }
1363   }
1364   if (Nlm_GetVisible (s) && Nlm_GetAllParentsVisible (s) && Nlm_GetEnabled (s)) {
1365     Nlm_DoSelect (s, FALSE);
1366     Nlm_GetRect (s, &r);
1367     Nlm_InsetRect (&r, 1, 1);
1368     Nlm_EraseRect (&r);
1369     Nlm_ValidRect (&r);
1370   }
1371   Nlm_RestorePort (tempPort);
1372 }
1373 
1374 static void Nlm_ResetPanel (Nlm_GraphiC p, Nlm_Boolean savePort)
1375 
1376 {
1377   Nlm_PoinT        npt;
1378   Nlm_PanelData    pdata;
1379   Nlm_RecT         r;
1380   Nlm_PnlActnProc  rst;
1381   Nlm_WindoW       tempPort;
1382 
1383   tempPort = Nlm_SavePortIfNeeded (p, savePort);
1384   Nlm_GetRect (p, &r);
1385   Nlm_LoadPt (&npt, r.left, r.top);
1386   Nlm_LoadBoxData ((Nlm_BoX) p, npt, npt, npt, npt.y, npt.x, 0, 0, 0, 0, 0, 0);
1387   Nlm_GetPanelData ((Nlm_PaneL) p, &pdata);
1388   rst = pdata.reset;
1389   if (rst != NULL) {
1390     rst ((Nlm_PaneL) p);
1391   }
1392   Nlm_RestorePort (tempPort);
1393 }
1394 
1395 static void Nlm_RemoveSlate (Nlm_GraphiC s, Nlm_Boolean savePort)
1396 
1397 {
1398   Nlm_Handle       chdl;
1399   Nlm_SlateTool    h;
1400   Nlm_BaR          hsb;
1401   Nlm_PaneL        n;
1402   Nlm_PaneL        p;
1403   Nlm_PanelData    pdata;
1404   Nlm_Handle       rhdl;
1405   Nlm_PnlActnProc  rst;
1406   Nlm_SlateData    sdata;
1407   Nlm_WindoW       tempPort;
1408   Nlm_BaR          vsb;
1409 
1410 /* M.I: this lines are to be removed --
1411         assignments and CHECK are performed at the end of the
1412         routine.
1413   recentSlate = NULL;
1414   recentlyClickedSlate = NULL;
1415   recentlyClickedPanel = NULL;
1416 */
1417 
1418 #ifdef WIN_MOTIF
1419   if (Nlm_currentXDisplay != NULL) {
1420     XSync (Nlm_currentXDisplay, FALSE);
1421   }
1422   if (slateTimerUsed) {
1423     slateTimerUsed = FALSE;
1424     XtRemoveTimeOut (slateTimer);
1425   }
1426   if (Nlm_currentXDisplay != NULL) {
1427     XSync (Nlm_currentXDisplay, FALSE);
1428   }
1429 #endif
1430   tempPort = Nlm_SavePortIfNeeded (s, savePort);
1431   Nlm_GetSlateData ((Nlm_SlatE) s, &sdata);
1432   rhdl = sdata.rowHandles;
1433   if (rhdl != NULL) {
1434     Nlm_HandFree (rhdl);
1435   }
1436   chdl = sdata.colHandles;
1437   if (chdl != NULL) {
1438     Nlm_HandFree (chdl);
1439   }
1440   vsb = sdata.vScrollBar;
1441   hsb = sdata.hScrollBar;
1442   if (vsb != NULL) {
1443     Nlm_DoRemove ((Nlm_GraphiC) vsb, FALSE);
1444   }
1445   if (hsb != NULL) {
1446     Nlm_DoRemove ((Nlm_GraphiC) hsb, FALSE);
1447   }
1448   Nlm_GetPanelData ((Nlm_PaneL) s, &pdata);
1449   if (pdata.click != NULL || pdata.drag != NULL || pdata.hold != NULL ||
1450       pdata.release != NULL || pdata.draw != NULL || pdata.reset != NULL) {
1451     p = (Nlm_PaneL) s;
1452     rst = pdata.reset;
1453     if (rst != NULL) {
1454       rst (p);
1455     }
1456   } else {
1457     p = (Nlm_PaneL) Nlm_GetChild (s);
1458     while (p != NULL) {
1459       n = (Nlm_PaneL) Nlm_GetNext ((Nlm_GraphiC) p);
1460       Nlm_DoReset ((Nlm_GraphiC) p, FALSE);
1461       Nlm_DoRemove ((Nlm_GraphiC) p, FALSE);
1462       p = n;
1463     }
1464   }
1465   h = sdata.handle;
1466 #ifdef WIN_MSWIN
1467   RemoveProp (h, (LPSTR) "Nlm_VibrantProp");
1468   DestroyWindow (h);
1469 #endif
1470 #ifdef WIN_MOTIF
1471 #ifndef LESSTIF_VERSION
1472   /* causes crash using LessTif - is this necessary? (thiessen) */
1473   XtUnrealizeWidget(h);
1474 #endif
1475   XtDestroyWidget (h);
1476   Nlm_DelSubwindowShell ( Nlm_GetParentWindow((Nlm_GraphiC)s),
1477                           (Nlm_ShellTool) h );
1478 #endif
1479   Nlm_RemoveLink (s);
1480   if (recentSlate == recentlyClickedSlate) { /* M.I. */
1481     recentlyClickedSlate = NULL;
1482     recentlyClickedPanel = NULL;
1483   }
1484   recentSlate = NULL;
1485   Nlm_RestorePort (tempPort);
1486 }
1487 
1488 static void Nlm_RemovePanel (Nlm_GraphiC p, Nlm_Boolean savePort)
1489 
1490 {
1491   Nlm_WindoW  tempPort;
1492 
1493   tempPort = Nlm_SavePortIfNeeded (p, savePort);
1494   Nlm_RemoveLink (p);
1495   Nlm_RestorePort (tempPort);
1496 }
1497 
1498 static void Nlm_SelectSlate (Nlm_GraphiC s, Nlm_Boolean savePort)
1499 
1500 {
1501 #ifdef WIN_MOTIF
1502   Pixel          color;
1503   Nlm_SlateTool  h;
1504   Nlm_RecT       r;
1505   Nlm_WindoW     w;
1506 
1507   w = Nlm_ParentWindow (s);
1508   if (Nlm_WindowHasBeenShown (w) && (! Nlm_IsWindowDying (w))) {
1509     h = Nlm_GetSlateHandle ((Nlm_SlatE) s);
1510     Nlm_GetRect (s, &r);
1511     Nlm_XOffset = r.left;
1512     Nlm_YOffset = r.top;
1513     Nlm_UseWindow( w );
1514     Nlm_currentXWindow = XtWindow (h);
1515     XtVaGetValues (h, XmNbackground, &color, 0);
1516     Nlm_XbackColor = color;
1517     XtVaGetValues (h, XmNforeground, &color, 0);
1518     Nlm_XforeColor = color;
1519   }
1520 #endif
1521 }
1522 
1523 
1524 static void Nlm_SelectPanel (Nlm_GraphiC p, Nlm_Boolean savePort)
1525 {
1526 #ifdef WIN_MOTIF
1527   Pixel          color;
1528   Nlm_SlateTool  h;
1529   Nlm_RecT       r;
1530   Nlm_SlatE      s;
1531   Nlm_WindoW     w;
1532 
1533   w = Nlm_ParentWindow (p);
1534   if (!Nlm_WindowHasBeenShown( w )  ||  Nlm_IsWindowDying( w ))
1535     return;
1536 
1537   s = (Nlm_SlatE) Nlm_GetParent (p);
1538   h = Nlm_GetSlateHandle ((Nlm_SlatE) s);
1539   Nlm_GetRect ((Nlm_GraphiC) s, &r);
1540   Nlm_XOffset = r.left;
1541   Nlm_YOffset = r.top;
1542   Nlm_UseWindow( w );
1543   Nlm_currentXWindow = XtWindow (h);
1544   XtVaGetValues (h, XmNbackground, &color, 0);
1545   Nlm_XbackColor = color;
1546   XtVaGetValues (h, XmNforeground, &color, 0);
1547   Nlm_XforeColor = color;
1548 #endif
1549 }
1550 
1551 static void Nlm_SetSlateOffset (Nlm_GraphiC s, Nlm_Int2 horiz,
1552                                 Nlm_Int2 vert, Nlm_Boolean savePort)
1553 
1554 {
1555   Nlm_BaR        hsb;
1556   Nlm_SlateData  sdata;
1557   Nlm_WindoW     tempPort;
1558   Nlm_BaR        vsb;
1559 
1560   tempPort = Nlm_SavePortIfNeeded (s, savePort);
1561   Nlm_GetSlateData ((Nlm_SlatE) s, &sdata);
1562   /*
1563   if (vert > sdata.barRows) {
1564     vert = sdata.barRows;
1565   }
1566   */
1567   vsb = sdata.vScrollBar;
1568   hsb = sdata.hScrollBar;
1569   if (vsb != NULL) {
1570     Nlm_DoSetValue((Nlm_GraphiC)vsb, (Nlm_Int2)(vert + sdata.vBefore), FALSE);
1571   }
1572   if (hsb != NULL) {
1573     Nlm_DoSetValue((Nlm_GraphiC)hsb, horiz, FALSE);
1574   }
1575   Nlm_RestorePort (tempPort);
1576 }
1577 
1578 static void Nlm_GetSlateOffset (Nlm_GraphiC s, Nlm_Int2Ptr horiz, Nlm_Int2Ptr vert)
1579 
1580 {
1581   Nlm_BaR        hsb;
1582   Nlm_SlateData  sdata;
1583   Nlm_BaR        vsb;
1584 
1585   Nlm_GetSlateData ((Nlm_SlatE) s, &sdata);
1586   if (vert != NULL) {
1587     vsb = sdata.vScrollBar;
1588     if (vsb != NULL) {
1589       *vert = (Nlm_Int2)(Nlm_DoGetValue( (Nlm_GraphiC)vsb ) - sdata.vBefore);
1590     } else {
1591       *vert = 0;
1592     }
1593   }
1594   if (horiz != NULL) {
1595     hsb = sdata.hScrollBar;
1596     if (hsb != NULL) {
1597       *horiz = Nlm_DoGetValue ((Nlm_GraphiC) hsb);
1598     } else {
1599       *horiz = 0;
1600     }
1601   }
1602 }
1603 
1604 static void Nlm_GetPanelOffset (Nlm_GraphiC p,  Nlm_Int2Ptr horiz, Nlm_Int2Ptr vert)
1605 
1606 {
1607   Nlm_Int2       hOff;
1608   Nlm_Int2       numRows;
1609   Nlm_OfsPtr     optr;
1610   Nlm_Handle     rhdl;
1611   Nlm_SlatE      s;
1612   Nlm_SlateData  sdata;
1613   Nlm_Int2       vOff;
1614 
1615   s = (Nlm_SlatE) Nlm_GetParent (p);
1616   Nlm_DoGetOffset ((Nlm_GraphiC) s, &hOff, &vOff);
1617   if (vert != NULL) {
1618     Nlm_GetSlateData (s, &sdata);
1619     numRows = sdata.numRows;
1620     rhdl = sdata.rowHandles;
1621     if (rhdl != NULL && vOff > 0 && vOff < numRows) {
1622       optr = (Nlm_OfsPtr) Nlm_HandLock (rhdl);
1623       *vert = optr [vOff].offset;
1624       Nlm_HandUnlock (rhdl);
1625     } else {
1626       *vert = 0;
1627     }
1628   }
1629   if (horiz != NULL) {
1630     *horiz = 0;
1631   }
1632 }
1633 
1634 static void Nlm_InvalSlate (Nlm_GraphiC s, Nlm_BaR vsb, Nlm_BaR hsb)
1635 
1636 {
1637   Nlm_RecT  r;
1638 
1639   if (Nlm_GetVisible (s) && Nlm_GetAllParentsVisible (s)) {
1640     Nlm_GetRect (s, &r);
1641     if (vsb != NULL) {
1642       r.right += Nlm_vScrollBarWidth;
1643     }
1644     if (hsb != NULL) {
1645       r.bottom += Nlm_hScrollBarHeight;
1646     }
1647     Nlm_InsetRect (&r, -1, -1);
1648     Nlm_InvalRect (&r);
1649   }
1650 }
1651 
1652 
1653 static void Nlm_SetSlatePosition(Nlm_GraphiC s, Nlm_RectPtr r,
1654                                  Nlm_Boolean savePort, Nlm_Boolean force)
1655 {
1656   Nlm_Int2       deltaX;
1657   Nlm_Int2       deltaY;
1658   Nlm_SlateTool  h;
1659   Nlm_BaR        hsb;
1660   Nlm_RecT       oldRect;
1661   Nlm_PaneL      p;
1662   Nlm_RecT       pr;
1663   Nlm_RecT       sr;
1664   Nlm_WindoW     tempPort = NULL;
1665   Nlm_BaR        vsb;
1666   Nlm_Boolean    is_realized;
1667 
1668   if ( !r )
1669     return;
1670 
1671   Nlm_DoGetPosition(s, &oldRect);
1672   if (!force  &&  Nlm_EqualRect(r, &oldRect))
1673     return;
1674 
1675   sr = *r;
1676   deltaX = (Nlm_Int2)(sr.left - oldRect.left);
1677   deltaY = (Nlm_Int2)(sr.top  - oldRect.top );
1678   vsb = Nlm_GetSlateVScrollBar ((Nlm_SlatE) s);
1679   hsb = Nlm_GetSlateHScrollBar ((Nlm_SlatE) s);
1680   h   = Nlm_GetSlateHandle     ((Nlm_SlatE) s);
1681 
1682   is_realized = Nlm_GetRealized( s );
1683   if (is_realized) {
1684     tempPort = Nlm_SavePortIfNeeded (s, savePort);
1685 #ifdef WIN_MOTIF
1686     Nlm_DoSelect (s, FALSE);
1687 #endif
1688     Nlm_InvalSlate (s, vsb, hsb);
1689   }
1690 
1691   if (vsb != NULL) {
1692     sr.right -= Nlm_vScrollBarWidth;
1693   }
1694   if (hsb != NULL) {
1695     sr.bottom -= Nlm_hScrollBarHeight;
1696   }
1697   Nlm_SetRect (s, &sr);
1698 
1699 
1700   if ( is_realized )
1701     {
1702 #ifdef WIN_MAC
1703       Nlm_InvalSlate (s, vsb, hsb);
1704 #endif
1705 #ifdef WIN_MSWIN
1706       if (h != NULL) {
1707         MoveWindow (h,  sr.left,  sr.top,
1708                     sr.right - sr.left + 1,  sr.bottom - sr.top + 1,  TRUE);
1709       }
1710       Nlm_InvalSlate (s, vsb, hsb);
1711 #endif
1712 #ifdef WIN_MOTIF
1713       if (h != NULL) {
1714         XtVaSetValues (h,
1715                        XmNx, (Position) sr.left,
1716                        XmNy, (Position) sr.top,
1717                        XmNwidth, (Dimension) (sr.right - sr.left + 1),
1718                        XmNheight, (Dimension) (sr.bottom - sr.top + 1),
1719                        NULL);
1720       }
1721       Nlm_InvalSlate (s, vsb, hsb);
1722 #endif
1723     }
1724 
1725   p = (Nlm_PaneL) Nlm_GetChild (s);
1726   while (p != NULL) {
1727     Nlm_DoGetPosition ((Nlm_GraphiC) p, &pr);
1728     Nlm_OffsetRect (&pr, deltaX, deltaY);
1729     Nlm_DoSetPosition ((Nlm_GraphiC) p, &pr, FALSE, force);
1730     p = (Nlm_PaneL) Nlm_GetNext ((Nlm_GraphiC) p);
1731   }
1732 
1733   if (vsb != NULL) {
1734     Nlm_GetRect (s, &sr);
1735     sr.left = sr.right /* + 1 */ ;
1736     sr.right += Nlm_vScrollBarWidth;
1737     Nlm_DoSetPosition ((Nlm_GraphiC) vsb, &sr, FALSE, force);
1738   }
1739 
1740   if (hsb != NULL) {
1741     Nlm_GetRect (s, &sr);
1742     sr.top = sr.bottom /* + 1 */ ;
1743     sr.bottom += Nlm_hScrollBarHeight;
1744     Nlm_DoSetPosition ((Nlm_GraphiC) hsb, &sr, FALSE, force);
1745   }
1746 
1747   if ( is_realized )
1748     Nlm_RestorePort (tempPort);
1749 }
1750 
1751 
1752 static void Nlm_SetPanelPosition (Nlm_GraphiC p, Nlm_RectPtr r,
1753                                   Nlm_Boolean savePort, Nlm_Boolean force)
1754 {
1755   Nlm_RecT    oldRect;
1756   Nlm_WindoW  tempPort;
1757 
1758   if (r == NULL)  return;
1759 
1760   if ( !Nlm_GetRealized( p ) )
1761     {
1762       Nlm_SetRect (p, r);
1763       return;
1764     }
1765 
1766   Nlm_DoGetPosition (p, &oldRect);
1767   if (!force  &&  Nlm_EqualRect(r, &oldRect))  return;
1768 
1769   tempPort = Nlm_SavePortIfNeeded (p, savePort);
1770   Nlm_SetRect (p, r);
1771   Nlm_RestorePort (tempPort);
1772 }
1773 
1774 
1775 static void Nlm_GetSlatePosition (Nlm_GraphiC s, Nlm_RectPtr r)
1776 
1777 {
1778   if (r != NULL) {
1779     Nlm_GetRect (s, r);
1780     if (Nlm_GetSlateVScrollBar ((Nlm_SlatE) s) != NULL) {
1781       r->right += Nlm_vScrollBarWidth;
1782     }
1783     if (Nlm_GetSlateHScrollBar ((Nlm_SlatE) s) != NULL) {
1784       r->bottom += Nlm_hScrollBarHeight;
1785     }
1786   }
1787 }
1788 
1789 static void Nlm_GetPanelPosition (Nlm_GraphiC p, Nlm_RectPtr r)
1790 
1791 {
1792   if (r != NULL) {
1793     Nlm_GetRect (p, r);
1794   }
1795 }
1796 
1797 static void Nlm_AdjustSlate (Nlm_GraphiC a, Nlm_RectPtr r,
1798                              Nlm_Boolean align, Nlm_Boolean savePort)
1799 
1800 {
1801   Nlm_SlatE  s;
1802 
1803   s = (Nlm_SlatE) Nlm_GetParent (a);
1804   Nlm_RecordRect ((Nlm_GraphiC) s, r);
1805   Nlm_NextPosition ((Nlm_GraphiC) s, r);
1806 }
1807 
1808 static void Nlm_SetSlateRange (Nlm_GraphiC s, Nlm_Int2 pgUp,
1809                                Nlm_Int2 pgDn, Nlm_Int2 max,
1810                                Nlm_Boolean savePort)
1811 
1812 {
1813   Nlm_BaR        sb;
1814   Nlm_SlateData  sdata;
1815   Nlm_WindoW     tempPort;
1816 
1817   tempPort = Nlm_SavePortIfNeeded (s, savePort);
1818   Nlm_GetSlateData ((Nlm_SlatE) s, &sdata);
1819   if (max > sdata.barRows) {
1820     sdata.barRows = max;
1821     Nlm_SetSlateData ((Nlm_SlatE) s, &sdata);
1822   }
1823   sb = sdata.vScrollBar;
1824   if (sb != NULL) {
1825     Nlm_DoSetRange ((Nlm_GraphiC) sb, pgUp, pgDn, max, FALSE);
1826   }
1827   Nlm_RestorePort (tempPort);
1828 }
1829 
1830 static void Nlm_NextScreenLine (Nlm_DisplaY d)
1831 
1832 {
1833   Nlm_RecT   p;
1834   Nlm_PoinT  pt;
1835   Nlm_RecT   r;
1836 
1837   Nlm_GetCursorPos (d, &pt);
1838   Nlm_GetRect ((Nlm_GraphiC) d, &r);
1839   Nlm_InsetRect (&r, 4, 4);
1840   p = r;
1841 #ifdef WIN_MSWIN
1842   r.bottom -= disphght;
1843 #endif
1844   while (pt.y + disphght >= r.bottom) {
1845     Nlm_ScrollRect(&p, 0, (Nlm_Int2)(-disphght));
1846     pt.y -= disphght;
1847   }
1848   if (pt.y + disphght >= r.bottom) {
1849     Nlm_ScrollRect(&p, 0, (Nlm_Int2)(-disphght));
1850   } else {
1851     pt.y += disphght;
1852   }
1853   pt.x = r.left;
1854   Nlm_SetCursorPos (d, pt);
1855 }
1856 
1857 static void Nlm_PaintOneCharacter (Nlm_DisplaY d, Nlm_Char ch)
1858 
1859 {
1860   Nlm_PoinT  nx;
1861   Nlm_PoinT  pt;
1862   Nlm_RecT   r;
1863 
1864   Nlm_GetCursorPos (d, &pt);
1865   Nlm_GetRect ((Nlm_GraphiC) d, &r);
1866   Nlm_InsetRect (&r, 4, 4);
1867   nx = pt;
1868   nx.x += Nlm_CharWidth (ch);
1869 #ifdef WIN_MSWIN
1870   nx.y -= disphght;
1871 #endif
1872   if (Nlm_PtInRect (pt, &r) && Nlm_PtInRect (nx, &r)) {
1873   } else {
1874     screenPos = 0;
1875     Nlm_NextScreenLine (d);
1876   }
1877   Nlm_GetCursorPos (d, &pt);
1878   nx = pt;
1879   nx.x += Nlm_CharWidth (ch);
1880   if (Nlm_PtInRect (pt, &r) && Nlm_PtInRect (nx, &r)) {
1881     Nlm_MoveTo (pt.x, pt.y);
1882     Nlm_PaintChar (ch);
1883     Nlm_SetCursorPos (d, nx);
1884     if (screenPos < screenBufSize) {
1885       screenBfr [screenPos] = ch;
1886     }
1887     screenPos++;
1888   }
1889 }
1890 
1891 static void Nlm_EraseLastChar (Nlm_DisplaY d)
1892 
1893 {
1894   Nlm_Char   ch;
1895   Nlm_PoinT  pt;
1896 
1897   if (screenPos > 0) {
1898     screenPos--;
1899     if (screenPos < screenBufSize) {
1900       Nlm_GetCursorPos (d, &pt);
1901       ch = screenBfr [screenPos];
1902       pt.x -= Nlm_CharWidth (ch);
1903       Nlm_MoveTo (pt.x, pt.y);
1904       Nlm_SetCursorPos (d, pt);
1905       Nlm_InvertMode ();
1906       Nlm_PaintOneCharacter (d, ch);
1907       Nlm_MoveTo (pt.x, pt.y);
1908       Nlm_SetCursorPos (d, pt);
1909       screenPos--;
1910       Nlm_CopyMode ();
1911     }
1912   }
1913 }
1914 
1915 static void Nlm_PaintOrFormatChar (Nlm_GraphiC d, Nlm_Char ch, Nlm_Boolean savePort)
1916 
1917 {
1918   Nlm_PoinT   pt;
1919   Nlm_RecT    r;
1920   Nlm_WindoW  tempPort;
1921 #ifdef WIN_MAC
1922   PenState    state;
1923 #endif
1924 
1925   if (Nlm_GetVisible (d) && Nlm_AllParentsButWindowVisible (d)) {
1926     tempPort = Nlm_SavePortIfNeeded (d, savePort);
1927     Nlm_DoSelect (d, FALSE);
1928 #if defined(WIN_MAC) && !defined(WIN_MAC_QUARTZ)
1929     GetPenState (&state);
1930     PenNormal ();
1931 #endif
1932     Nlm_SelectFont (dispfont);
1933     switch (ch) {
1934       case '\n':
1935         screenPos = 0;
1936         Nlm_NextScreenLine ((Nlm_DisplaY) d);
1937         break;
1938       case '\r':
1939 #ifndef WIN_MSWIN
1940         screenPos = 0;
1941         Nlm_NextScreenLine ((Nlm_DisplaY) d);
1942 #endif
1943         break;
1944       case '\t':
1945         do {
1946           Nlm_PaintOneCharacter ((Nlm_DisplaY) d, ' ');
1947         } while ((screenPos % 8) != 0);
1948         break;
1949       case '\b':
1950         if (screenPos > 0) {
1951           Nlm_EraseLastChar ((Nlm_DisplaY) d);
1952         }
1953         break;
1954       case '\f':
1955         screenPos = 0;
1956         Nlm_GetRect (d, &r);
1957         Nlm_LoadPt(&pt, r.left, (Nlm_Int2)(r.top + disphght));
1958         Nlm_SetCursorPos ((Nlm_DisplaY) d, pt);
1959         Nlm_InsetRect (&r, 2, 2);
1960         Nlm_EraseRect (&r);
1961         break;
1962       case '\7':
1963         Nlm_Beep ();
1964         break;
1965       default:
1966         if (ch >= ' ') {
1967           Nlm_PaintOneCharacter ((Nlm_DisplaY) d, ch);
1968         }
1969         break;
1970     }
1971 #if defined(WIN_MAC) && !defined(WIN_MAC_QUARTZ)
1972     SetPenState (&state);
1973 #endif
1974     Nlm_SelectFont (Nlm_systemFont);
1975     Nlm_RestorePort (tempPort);
1976   }
1977 }
1978 
1979 static void Nlm_SelectDisplay (Nlm_GraphiC d, Nlm_Boolean savePort)
1980 
1981 {
1982   Nlm_WindoW  w;
1983 
1984   if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (d))) {
1985     w = Nlm_GetParentWindow (d);
1986     Nlm_SetWindowCharDisplay (w, (Nlm_DisplaY) d);
1987   }
1988 }
1989 
1990 #ifdef WIN_MOTIF
1991 #define MOUSE_DOWN 1
1992 #define MOUSE_MOVE 2
1993 #define MOUSE_UP   3
1994 
1995 static void Nlm_SlateTimer (XtPointer client_data, XtIntervalId *id)
1996 
1997 {
1998   Nlm_PaneL        p;
1999   Nlm_PnlClckProc  prs;
2000   Nlm_PoinT        pt;
2001   Nlm_SlatE        s;
2002 
2003   if (slateTimerUsed) {
2004     s = (Nlm_SlatE) client_data;
2005     pt = currentMousePos;
2006     if ((Nlm_SlatE) s == recentlyClickedSlate &&
2007         recentlyClickedSlate != NULL && recentlyClickedPanel != NULL) {
2008       p = recentlyClickedPanel;
2009       Nlm_DoSelect ((Nlm_GraphiC) p, FALSE);
2010       prs = Nlm_GetPanelHold (p);
2011       if (prs != NULL) {
2012         Nlm_ResetDrawingTools ();
2013         prs (p, pt);
2014       }
2015     }
2016     slateTimer = XtAppAddTimeOut (Nlm_appContext, 50, Nlm_SlateTimer, (XtPointer) s);
2017     slateTimerUsed = TRUE;
2018   }
2019 }
2020 
2021 static void Nlm_SlateClick (Nlm_SlatE s, Nlm_PoinT pt, Nlm_Int2 mouseAction)
2022 
2023 {
2024   Nlm_PnlClckProc  clk;
2025   Nlm_PnlClckProc  drg;
2026   Nlm_SlateTool    h;
2027   Nlm_Int2         hOffset;
2028   Nlm_PaneL        n;
2029   Nlm_Boolean      notInside;
2030   Nlm_PaneL        p;
2031   Nlm_PanelData    pdata;
2032   Nlm_RecT         r;
2033   Nlm_PnlClckProc  rls;
2034   Nlm_Int2         vOffset;
2035 
2036   h = Nlm_GetSlateHandle ((Nlm_SlatE) s);
2037   currentMousePos = pt;
2038   switch (mouseAction) {
2039     case MOUSE_DOWN:
2040       slateTimer = XtAppAddTimeOut (Nlm_appContext, 50, Nlm_SlateTimer, (XtPointer) s);
2041       slateTimerUsed = TRUE;
2042       Nlm_GetRect ((Nlm_GraphiC) s, &r);
2043       recentlyClickedSlate = (Nlm_SlatE) s;
2044       recentlyClickedPanel = NULL;
2045       Nlm_SelectFont (Nlm_systemFont);
2046       Nlm_ResetDrawingTools ();
2047       Nlm_GetPanelData ((Nlm_PaneL) s, &pdata);
2048       if (pdata.click != NULL || pdata.drag != NULL || pdata.hold != NULL ||
2049           pdata.release != NULL || pdata.draw != NULL || pdata.reset != NULL) {
2050         p = (Nlm_PaneL) s;
2051         recentlyClickedPanel = p;
2052         clk = Nlm_GetPanelClick (p);
2053         if (clk != NULL && Nlm_GetEnabled ((Nlm_GraphiC) p)
2054             && Nlm_GetVisible ((Nlm_GraphiC) p)) {
2055           clk (p, pt);
2056           Nlm_Update ();
2057         }
2058       } else {
2059         p = Nlm_CreateReverseLinks ((Nlm_SlatE) s);
2060         notInside = TRUE;
2061         while (p != NULL && notInside) {
2062           n = Nlm_GetPanelPrev (p);
2063           Nlm_GetPanelData (p, &pdata);
2064           if (pdata.click != NULL || pdata.drag != NULL ||
2065               pdata.hold != NULL || pdata.release != NULL) {
2066             Nlm_GetRect ((Nlm_GraphiC) p, &r);
2067             Nlm_DoGetOffset ((Nlm_GraphiC) p, &hOffset, &vOffset);
2068             Nlm_OffsetRect (&r, -hOffset, -vOffset);
2069             if (Nlm_PtInRect (pt, &r) && Nlm_GetEnabled ((Nlm_GraphiC) p) &&
2070                 Nlm_GetVisible ((Nlm_GraphiC) p)) {
2071               recentlyClickedPanel = p;
2072               notInside = FALSE;
2073               clk = Nlm_GetPanelClick (p);
2074               if (clk != NULL) {
2075                 clk (p, pt);
2076                 Nlm_Update ();
2077               }
2078             }
2079           }
2080           p = n;
2081         }
2082       }
2083       break;
2084     case MOUSE_MOVE:
2085       Nlm_GetRect ((Nlm_GraphiC) s, &r);
2086       if ((Nlm_SlatE) s == recentlyClickedSlate && recentlyClickedPanel != NULL) {
2087         p = recentlyClickedPanel;
2088         drg = Nlm_GetPanelDrag (p);
2089         if (drg != NULL) {
2090           Nlm_ResetDrawingTools ();
2091           drg (p, pt);
2092         }
2093       }
2094       break;
2095     case MOUSE_UP:
2096       if (slateTimerUsed) {
2097         XtRemoveTimeOut (slateTimer);
2098       }
2099       slateTimerUsed = FALSE;
2100       Nlm_GetRect ((Nlm_GraphiC) s, &r);
2101       if ((Nlm_SlatE) s == recentlyClickedSlate && recentlyClickedPanel != NULL) {
2102         p = recentlyClickedPanel;
2103         rls = Nlm_GetPanelRelease (p);
2104         if (rls != NULL) {
2105           Nlm_ResetDrawingTools ();
2106           rls (p, pt);
2107         }
2108       }
2109       Nlm_SelectFont (Nlm_systemFont);
2110       Nlm_ResetDrawingTools ();
2111 /*
2112       recentlyClickedSlate = NULL;
2113 */
2114       recentlyClickedPanel = NULL;
2115       break;
2116     default:
2117       break;
2118   }
2119 }
2120 
2121 static void Nlm_SlateClickCallback (Widget w, XEvent *ev,
2122                                     String *args, Cardinal *num_args)
2123 
2124 {
2125   XButtonEvent  *event = (XButtonEvent *)ev;
2126   Pixel         color;
2127   Nlm_Uint4     delta;
2128   Nlm_WindoW    newWindow;
2129   Nlm_WindoW    oldWindow;
2130   Nlm_PoinT     pt;
2131   XtPointer     ptr;
2132   Nlm_RecT      r;
2133   Nlm_SlatE     s;
2134   Nlm_Uint4     state;
2135   Window        tempWind;
2136   Nlm_Uint4     ticks;
2137 
2138   XtVaGetValues (w, XmNuserData, &ptr, NULL);
2139   s = (Nlm_SlatE) ptr;
2140   if (!Nlm_GetEnabled( (Nlm_GraphiC)s )  ||
2141       !Nlm_GetAllParentsEnabled( (Nlm_GraphiC)s ))
2142     return;
2143 
2144   newWindow = Nlm_GetParentWindow ((Nlm_GraphiC) s);
2145   if ( Nlm_IsWindowDying(newWindow) )
2146     return;
2147 
2148   tempWind  = Nlm_currentXWindow;
2149   oldWindow = Nlm_CurrentWindow ();
2150   if (oldWindow != newWindow)
2151     Nlm_UseWindow(newWindow);
2152   Nlm_currentXWindow = XtWindow (w);
2153 
2154   Nlm_GetRect ((Nlm_GraphiC) s, &r);
2155   Nlm_XOffset = r.left;
2156   Nlm_YOffset = r.top;
2157   XtVaGetValues (w, XmNbackground, &color, 0);
2158   Nlm_XbackColor = color;
2159   XtVaGetValues (w, XmNforeground, &color, 0);
2160   Nlm_XforeColor = color;
2161   pt.x = (Nlm_Int2) event->x + Nlm_XOffset;
2162   pt.y = (Nlm_Int2) event->y + Nlm_YOffset;
2163 
2164   Nlm_cmmdKey  = FALSE;
2165   Nlm_optKey   = FALSE;
2166   Nlm_dblClick = FALSE;
2167   state = event->state;
2168   Nlm_ctrlKey  = ((state & ControlMask) != 0);
2169   Nlm_shftKey  = ((state & ShiftMask  ) != 0);
2170 
2171   if (Nlm_StringCmp (args [0], "down") == 0) {
2172     ticks = (Nlm_Uint4) event->time;
2173     if (s == recentlyClickedSlate) {
2174       delta = ticks - (Nlm_Uint4) lastClickTime;
2175       if (delta <= (Nlm_Uint4) XtGetMultiClickTime (Nlm_currentXDisplay))
2176         Nlm_dblClick = TRUE;
2177     }
2178     lastClickTime = (Nlm_Int4) ticks;
2179     Nlm_SlateClick (s, pt, MOUSE_DOWN);
2180   }
2181   else if (Nlm_StringCmp (args [0], "up") == 0)
2182     Nlm_SlateClick (s, pt, MOUSE_UP);
2183   else if (Nlm_StringCmp (args [0], "motion") == 0)
2184     Nlm_SlateClick (s, pt, MOUSE_MOVE);
2185 
2186   if (Nlm_currentXDisplay != NULL)
2187     XSync (Nlm_currentXDisplay, FALSE);
2188 
2189   if (oldWindow != newWindow)
2190     Nlm_UseWindow (oldWindow);
2191   Nlm_currentXWindow = tempWind;
2192 }
2193 
2194 
2195 static void Nlm_DrawSlate (Nlm_SlatE s)
2196 
2197 {
2198   Nlm_PnlActnProc  drw;
2199   Nlm_SlateTool    h;
2200   Nlm_PaneL        n;
2201   Nlm_PaneL        p;
2202   Nlm_PanelData    pdata;
2203   Nlm_RecT         r;
2204 
2205   if (Nlm_GetVisible ((Nlm_GraphiC) s) && Nlm_GetAllParentsVisible ((Nlm_GraphiC) s) && okayToDrawContents) {
2206     h = Nlm_GetSlateHandle ((Nlm_SlatE) s);
2207     if (h != NULL) {
2208       Nlm_GetRect ((Nlm_GraphiC) s, &r);
2209       Nlm_SelectFont (Nlm_systemFont);
2210       Nlm_ResetDrawingTools ();
2211       if (Nlm_GetSlateBorder ((Nlm_SlatE) s)) {
2212         Nlm_FrameRect (&r);
2213       }
2214       Nlm_GetPanelData ((Nlm_PaneL) s, &pdata);
2215       if (pdata.click != NULL || pdata.drag != NULL || pdata.hold != NULL ||
2216           pdata.release != NULL || pdata.draw != NULL || pdata.reset != NULL) {
2217         p = (Nlm_PaneL) s;
2218 /*
2219         recentlyClickedPanel = p;
2220 */
2221         drw = Nlm_GetPanelDraw (p);
2222         if (drw != NULL && Nlm_GetVisible ((Nlm_GraphiC) p)) {
2223           drw (p);
2224           Nlm_ResetDrawingTools ();
2225         }
2226       } else {
2227         p = (Nlm_PaneL) Nlm_GetChild ((Nlm_GraphiC) s);
2228         while (p != NULL) {
2229           n = (Nlm_PaneL) Nlm_GetNext ((Nlm_GraphiC) p);
2230           drw = Nlm_GetPanelDraw (p);
2231           if (drw != NULL && Nlm_GetVisible ((Nlm_GraphiC) p)) {
2232             drw (p);
2233             Nlm_ResetDrawingTools ();
2234           }
2235           p = n;
2236         }
2237       }
2238     }
2239   }
2240 }
2241 
2242 static void Nlm_ClipXRgn (Nlm_RegioN rgn)
2243 
2244 {
2245   Nlm_RgnTool  ntool1;
2246   Nlm_RgnTool  ntool2;
2247 
2248   if (rgn != NULL && Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
2249     ntool1 = XCreateRegion ();
2250     ntool2 = XCreateRegion ();
2251     XUnionRegion ((Nlm_RgnTool) rgn, ntool1, ntool2);
2252     XOffsetRegion (ntool2, -Nlm_XOffset, -Nlm_YOffset);
2253     XSetRegion (Nlm_currentXDisplay, Nlm_currentXGC, ntool2);
2254     if (Nlm_clpRgn != NULL) {
2255       XDestroyRegion ((Nlm_RgnTool) Nlm_clpRgn);
2256       Nlm_clpRgn = NULL;
2257     }
2258     Nlm_clpRgn = (Nlm_RegioN) XCreateRegion ();
2259     XUnionRegion ((Nlm_RgnTool) rgn, ntool1, (Nlm_RgnTool) Nlm_clpRgn);
2260     XOffsetRegion ((Nlm_RgnTool) Nlm_clpRgn, -Nlm_XOffset, -Nlm_YOffset);
2261     XDestroyRegion (ntool1);
2262     XDestroyRegion (ntool2);
2263   }
2264 }
2265 
2266 
2267 static void Nlm_SlateInputCallback(Widget w,
2268                                    XtPointer client_data, XtPointer call_data)
2269 {
2270   XmDrawingAreaCallbackStruct *cbs = (XmDrawingAreaCallbackStruct *)call_data;
2271   Nlm_SlatE                    s   = (Nlm_SlatE)client_data;
2272   XEvent                       *event  = cbs->event;
2273 
2274   Nlm_Char         ch;
2275   Nlm_WindoW       newWindow;
2276 
2277   if (cbs->reason      != XmCR_INPUT  ||
2278       event->xany.type != KeyPress    ||
2279       !Nlm_GetEnabled( (Nlm_GraphiC)s )  ||
2280       !Nlm_GetAllParentsEnabled( (Nlm_GraphiC)s ))
2281     return;
2282 
2283   newWindow = Nlm_GetParentWindow( (Nlm_GraphiC)s );
2284   if ( Nlm_IsWindowDying( newWindow ) )
2285     return;
2286 
2287   Nlm_ctrlKey  = (event->xkey.state & ControlMask) ? TRUE : FALSE;
2288   Nlm_shftKey  = (event->xkey.state & ShiftMask  ) ? TRUE : FALSE;
2289   Nlm_cmmdKey  = FALSE;
2290   Nlm_optKey   = FALSE;
2291   Nlm_dblClick = FALSE;
2292 
2293   ch = Nlm_GetInputChar( &event->xkey );
2294   if (ch == '\0')
2295     return;
2296 
2297   {{
2298     Nlm_WindoW oldWindow = Nlm_CurrentWindow();
2299     Window     tempWind  = Nlm_currentXWindow;
2300     if (oldWindow != newWindow)
2301       Nlm_UseWindow( newWindow );
2302     Nlm_currentXWindow = XtWindow( w );
2303 
2304     {{
2305       Nlm_RecT r;
2306       Nlm_GetRect((Nlm_GraphiC)s, &r);
2307       Nlm_XOffset = r.left;
2308       Nlm_YOffset = r.top;
2309     }}
2310 
2311     {{
2312       Pixel color;
2313       XtVaGetValues(w, XmNbackground, &color, 0);
2314       Nlm_XbackColor = color;
2315       XtVaGetValues(w, XmNforeground, &color, 0);
2316       Nlm_XforeColor = color;
2317     }}
2318 
2319     Nlm_HandleSlateInput(s, ch);
2320 
2321     if (Nlm_currentXDisplay != NULL)
2322       XSync(Nlm_currentXDisplay, FALSE);
2323 
2324     if (oldWindow != newWindow)
2325       Nlm_UseWindow( oldWindow );
2326     Nlm_currentXWindow = tempWind;
2327   }}
2328 }
2329 
2330 
2331 static void Nlm_SlateDrawCallback(Widget w,
2332                                   XtPointer client_data, XtPointer call_data)
2333 {
2334   XmDrawingAreaCallbackStruct  *cbs = (XmDrawingAreaCallbackStruct *)call_data;
2335   Nlm_SlatE                    s    = (Nlm_SlatE)client_data;
2336   Pixel                        color;
2337   XEvent                       event;
2338   Nlm_WindoW                   newWindow;
2339   Nlm_WindoW                   oldWindow;
2340   Nlm_RecT                     r;
2341   Nlm_RegioN                   rgn1;
2342   Nlm_RegioN                   rgn2;
2343   Nlm_RegioN                   tempRgn;
2344   Window                       tempWind;
2345 
2346   newWindow = Nlm_GetParentWindow ((Nlm_GraphiC) s);
2347   if ( Nlm_IsWindowDying(newWindow) )
2348     return;
2349 
2350   tempWind  = Nlm_currentXWindow;
2351   oldWindow = Nlm_CurrentWindow ();
2352   if (oldWindow != newWindow)
2353     Nlm_UseWindow(newWindow);
2354   Nlm_currentXWindow = XtWindow( w );
2355 
2356   Nlm_GetRect ((Nlm_GraphiC) s, &r);
2357   Nlm_XOffset = r.left;
2358   Nlm_YOffset = r.top;
2359   XtVaGetValues (w, XmNbackground, &color, 0);
2360   Nlm_XbackColor = color;
2361   XtVaGetValues (w, XmNforeground, &color, 0);
2362   Nlm_XforeColor = color;
2363   rgn1 = Nlm_CreateRgn ();
2364   event = (*(cbs->event));
2365   do {
2366     r.left = event.xexpose.x;
2367     r.top = event.xexpose.y;
2368     r.right = r.left + event.xexpose.width;
2369     r.bottom = r.top + event.xexpose.height;
2370     rgn2 = Nlm_CreateRgn ();
2371     Nlm_LoadRectRgn (rgn2, r.left, r.top, r.right, r.bottom);
2372     Nlm_UnionRgn (rgn1, rgn2, rgn1);
2373     Nlm_DestroyRgn (rgn2);
2374   } while (XCheckTypedWindowEvent (Nlm_currentXDisplay,
2375                                    Nlm_currentXWindow, Expose, &event));
2376 
2377   Nlm_OffsetRgn (rgn1, Nlm_XOffset, Nlm_YOffset);
2378   Nlm_ClipXRgn (rgn1);
2379   Nlm_DestroyRgn (rgn1);
2380   if (Nlm_updateRgn != NULL)
2381     Nlm_DestroyRgn (Nlm_updateRgn);
2382   Nlm_updateRgn = Nlm_CreateRgn ();
2383   tempRgn = Nlm_CreateRgn ();
2384   Nlm_UnionRgn (Nlm_clpRgn, tempRgn, Nlm_updateRgn);
2385   Nlm_DestroyRgn (tempRgn);
2386   XOffsetRegion ((Nlm_RgnTool)Nlm_updateRgn, Nlm_XOffset, Nlm_YOffset);
2387   {{
2388     Nlm_RectTool x_updateRect;
2389     XClipBox((Nlm_RgnTool)Nlm_updateRgn, &x_updateRect);
2390     Nlm_RectToolToRecT(&x_updateRect, &Nlm_updateRect);
2391   }}
2392 
2393   Nlm_DrawSlate (s);
2394 
2395   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
2396     XSetClipMask (Nlm_currentXDisplay, Nlm_currentXGC, None);
2397     if (Nlm_clpRgn != NULL) {
2398       XDestroyRegion ((Nlm_RgnTool) Nlm_clpRgn);
2399       Nlm_clpRgn = NULL;
2400     }
2401   }
2402   if (Nlm_currentXDisplay != NULL)
2403     XSync (Nlm_currentXDisplay, FALSE);
2404 
2405   if (oldWindow != newWindow)
2406     Nlm_UseWindow(oldWindow);
2407   Nlm_currentXWindow = tempWind;
2408 }
2409 
2410 
2411 static void Nlm_SlateFocusCB(Widget w, XtPointer client_data,
2412                              XEvent *event, Boolean *contin)
2413 {
2414   Nlm_SlatE s = (Nlm_SlatE)client_data;
2415 
2416   switch ( event->type )
2417     {
2418     case FocusOut:
2419       Nlm_ChangeSlateFocus(s, FALSE);
2420       XtVaSetValues(Nlm_GetSlateHandle( s ),
2421                     XmNsensitive,
2422                     (Boolean)(Nlm_SetSlatePolicy(s, GET_VALUE) & AUTO_FOCUS),
2423                     NULL);
2424       break;
2425     case FocusIn:
2426       if (!Nlm_SlateHasFocus( s )  &&
2427           (Nlm_SetSlatePolicy(s, GET_VALUE) & AUTO_FOCUS))
2428         Nlm_CaptureSlateFocus( s );
2429       break;
2430     }
2431 }
2432 #endif
2433 
2434 
2435 static void Nlm_NewSlate (Nlm_SlatE s, Nlm_Boolean border,
2436                           Nlm_Boolean vScroll, Nlm_Boolean hScroll,
2437                           Nlm_SltScrlProc4 vscrl4, Nlm_SltScrlProc4 hscrl4,
2438                           Nlm_SltScrlProc vscrl, Nlm_SltScrlProc hscrl,
2439                           Nlm_Int2 extra)
2440 
2441 {
2442   Nlm_SlateTool   h;
2443   Nlm_BaR         hsb;
2444   Nlm_PoinT       npt;
2445   Nlm_RecT        r;
2446   Nlm_BaR         vsb;
2447   Nlm_WindowTool  wptr;
2448 #ifdef WIN_MOTIF
2449   Cardinal        n;
2450   Arg             wargs [10];
2451   String          trans =
2452     "<Btn1Down>:     slate(down)   ManagerGadgetArm()  \n\
2453      <Btn1Up>:       slate(up)     ManagerGadgetActivate() \n\
2454      <Btn1Motion>:   slate(motion) ManagerGadgetButtonMotion() \n\
2455      <Key>:          DrawingAreaInput()";
2456 #endif
2457 #ifdef WIN_MSWIN
2458     Nlm_FntPtr      fntptr;
2459 #endif
2460 
2461   Nlm_GetRect ((Nlm_GraphiC) s, &r);
2462   h = NULL;
2463   vsb = NULL;
2464   hsb = NULL;
2465   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) s);
2466 
2467 #ifdef WIN_MSWIN
2468   h = CreateWindow (slateclass, "", WS_CHILD,
2469                     r.left, r.top, r.right - r.left + 1,
2470                     r.bottom - r.top + 1, wptr, 0,
2471                     Nlm_currentHInst, NULL);
2472   if (h != NULL) {
2473     SetProp (h, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) s);
2474   }
2475   fntptr = (Nlm_FntPtr) Nlm_HandLock (Nlm_systemFont);
2476   SetWindowFont(h, fntptr->handle, FALSE);
2477   Nlm_HandUnlock(Nlm_systemFont);
2478 
2479 #endif
2480 
2481 #ifdef WIN_MOTIF
2482   n = 0;
2483   XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
2484   XtSetArg (wargs [n], XmNy, (Position) r.top); n++;
2485   XtSetArg (wargs [n], XmNwidth, (Dimension) (r.right - r.left + 1)); n++;
2486   XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top + 1)); n++;
2487   XtSetArg (wargs [n], XmNmarginHeight, 0); n++;
2488   XtSetArg (wargs [n], XmNmarginWidth, 0); n++;
2489   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
2490   XtSetArg (wargs [n], XmNtranslations, XtParseTranslationTable (trans)); n++;
2491   h = XtCreateManagedWidget ((String) "", xmDrawingAreaWidgetClass,
2492                              wptr, wargs, n);
2493   Nlm_AddSubwindowShell(Nlm_GetParentWindow((Nlm_GraphiC)s), (Nlm_ShellTool)h);
2494 
2495   XtVaSetValues(h, XmNuserData, (XtPointer)s, NULL);
2496   XtAddCallback(h, XmNexposeCallback, Nlm_SlateDrawCallback,  (XtPointer)s);
2497   XtAddCallback(h, XmNinputCallback,  Nlm_SlateInputCallback, (XtPointer)s);
2498   XtAddEventHandler(h, FocusChangeMask, FALSE, Nlm_SlateFocusCB, (XtPointer)s);
2499   XtManageChild( h );
2500 #endif
2501 
2502   if (vScroll) {
2503     Nlm_GetRect ((Nlm_GraphiC) s, &r);
2504     r.left = r.right /* + 1 */ ;
2505     r.right += Nlm_vScrollBarWidth;
2506     if (vscrl4 != NULL) {
2507       vsb = Nlm_VertScrollBar4((Nlm_GraphiC) s, &r, (Nlm_BarScrlProc4)vscrl4);
2508     } else if (vscrl != NULL) {
2509       vsb = Nlm_VertScrollBar ((Nlm_GraphiC) s, &r, (Nlm_BarScrlProc) vscrl);
2510     } else {
2511       vsb = Nlm_VertScrollBar ((Nlm_GraphiC) s, &r,
2512                                (Nlm_BarScrlProc) Nlm_SlateVertScrollAction);
2513     }
2514   }
2515 
2516   if (hScroll) {
2517     Nlm_GetRect ((Nlm_GraphiC) s, &r);
2518     r.top = r.bottom /* + 1 */ ;
2519     r.bottom += Nlm_hScrollBarHeight;
2520     if (hscrl4 != NULL) {
2521       hsb = Nlm_HorizScrollBar4 ((Nlm_GraphiC) s, &r, (Nlm_BarScrlProc4) hscrl4);
2522     } else if (hscrl != NULL) {
2523       hsb = Nlm_HorizScrollBar ((Nlm_GraphiC) s, &r, (Nlm_BarScrlProc) hscrl);
2524     } else {
2525       hsb = Nlm_HorizScrollBar ((Nlm_GraphiC) s, &r,
2526                                 (Nlm_BarScrlProc) Nlm_SlateHorizScrollAction);
2527     }
2528   }
2529 
2530   Nlm_GetRect ((Nlm_GraphiC) s, &r);
2531   Nlm_InsetRect (&r, 4, 4);
2532   Nlm_LoadPt (&npt, r.left, r.top);
2533   Nlm_LoadBoxData ((Nlm_BoX) s, npt, npt, npt, npt.y, npt.x, 0, 0, 0, 0, 0, 0);
2534   Nlm_GetRect ((Nlm_GraphiC) s, &r);
2535   Nlm_LoadSlateData (s, h, vsb, hsb, NULL, NULL, 0, 0,
2536                      border, 0, 0, 0, NULL, NULL, FALSE);
2537   Nlm_SetSlatePolicy(s, DEFAULT_SLATE_POLICY);
2538   Nlm_LoadPanelData ((Nlm_PaneL) s, NULL, NULL, NULL, NULL, NULL, extra, NULL, NULL);
2539 }
2540 
2541 
2542 #ifdef _OPENGL
2543 /*
2544 Nlm_Set3DColorMap sets the color map for an OpenGL window.  A separate function
2545 is necessary because on windows, the pallete must be set using the device context
2546 bound to the OpenGL context.  Changing the palette of the parent window has no effect.
2547 lyg
2548 */
2549 
2550 
2551 
2552 extern void Nlm_Set3DColorMap (Nlm_PaneL w, Nlm_Uint2 totalColors,
2553                              Nlm_Uint1Ptr red, Nlm_Uint1Ptr green,
2554                              Nlm_Uint1Ptr blue, void **dpyh)
2555 {
2556   Nlm_SlateData  wdata;
2557 
2558 #ifdef WIN_MSWIN
2559   Nlm_Uint2       i;
2560   LOGPALETTE    * palette;
2561   PALETTEENTRY  * p;
2562 #endif
2563 
2564   if (w == NULL  ||  totalColors > 256)
2565     return;
2566 
2567   Nlm_GetSlateData ((Nlm_SlatE)w, &wdata);
2568 
2569 #ifdef WIN_MSWIN
2570   if ( GetDeviceCaps (wglGetCurrentDC(), RASTERCAPS) &  RC_PALETTE ){
2571     if ( wdata.cMap != NULL ){
2572       DeleteObject( wdata.cMap );
2573       wdata.cMap = NULL;
2574     }
2575     if ( totalColors!=0 ) {
2576       palette = (LOGPALETTE*)MemNew (sizeof(LOGPALETTE) +
2577                                      totalColors*sizeof(PALETTEENTRY));
2578       if ( palette != NULL ) {
2579         palette->palVersion = 0x300;
2580         palette->palNumEntries = totalColors;
2581         for( i=0; i<totalColors; i++ ) {
2582           p = &(palette->palPalEntry[i]);
2583           /*p->peFlags = (BYTE)((i != 0) ? 0 : PC_RESERVED);*/
2584           p->peFlags = PC_NOCOLLAPSE;
2585           p->peRed   = red[i];
2586           p->peGreen = green[i];
2587           p->peBlue  = blue[i];
2588         }
2589         wdata.cMap = CreatePalette(palette);
2590         if ( wdata.cMap != NULL ) {
2591           /*SetForegroundWindow(Nlm_ParentWindowPtr((Nlm_GraphiC) w));*/
2592           SelectPalette ( wglGetCurrentDC(),wdata.cMap,FALSE );
2593           RealizePalette ( wglGetCurrentDC() );
2594         }
2595         MemFree (palette);
2596       }
2597     }
2598   }
2599 #endif
2600 
2601 #ifdef WIN_MAC
2602   {
2603     /* use OpenGL context's own color map (but set window's cmap to same...)  (thiessen) */
2604     Nlm_Int2 i;
2605     RGBColor col;
2606     GLint cme[4];
2607     AGLContext ctx = aglGetCurrentContext();
2608     WindowPtr OGLwin = (WindowPtr) aglGetDrawable(ctx);
2609 
2610     if ( wdata.cMap != NULL ){
2611       if ( wdata.cMapStatus ){
2612         SetPalette( OGLwin, NULL, FALSE);
2613       }
2614       DisposePalette ( wdata.cMap );
2615       wdata.cMap = NULL;
2616     }
2617     wdata.cMapStatus = 0;
2618     if ( totalColors!=0 ) {
2619       wdata.cMap = NewPalette(totalColors,(CTabHandle)0,pmTolerant,0);
2620       if ( wdata.cMap != NULL ) {
2621         for( i=0; i<totalColors; i++ ) {
2622           col.red   = (Nlm_Uint2)red[i]<<8 | (Nlm_Uint2)red[i];
2623           col.green = (Nlm_Uint2)green[i]<<8 | (Nlm_Uint2)green[i];
2624           col.blue  = (Nlm_Uint2)blue[i]<<8 | (Nlm_Uint2)blue[i];
2625           SetEntryColor(wdata.cMap,i,&col);
2626           /* agl expects rgb colors from [0..65535] */
2627           cme[0]=i; cme[1]=col.red*256; cme[2]=col.green*256; cme[3]=col.blue*256;
2628           aglSetInteger(ctx,AGL_COLORMAP_ENTRY,cme);
2629         }
2630         SetPalette( OGLwin, wdata.cMap, FALSE);
2631         ActivatePalette ( OGLwin );
2632         wdata.cMapStatus = 1;
2633       }
2634     }
2635   }
2636 #endif
2637 
2638 #ifdef WIN_MOTIF
2639   do { /* TRY */
2640     unsigned long  pixel;
2641     int            n_savedColors = 0;
2642     XColor         colorCells[256];
2643     Display *dpy = *dpyh;
2644 
2645     if (!dpy) return;
2646 
2647     /* Uninstall, store first several colors and free current
2648      * colormap -- if necessary */
2649     if ( wdata.cMap )
2650       {
2651         n_savedColors = 32;
2652         if (n_savedColors > (int)totalColors)
2653           return;
2654 
2655         if ( wdata.cMapStatus )
2656           {
2657             XUninstallColormap(dpy, wdata.cMap);
2658             wdata.cMapStatus = 0;
2659           }
2660 
2661         /*if ( !wdata.cMap_fixed )
2662           { */
2663             if (totalColors != 0)
2664               {
2665                 for (pixel = 0;  pixel < n_savedColors;  pixel++)
2666                   colorCells[pixel].pixel = pixel;
2667                 XQueryColors(dpy, wdata.cMap,
2668                              colorCells, n_savedColors);
2669               }
2670 
2671             XFreeColormap(dpy, wdata.cMap);
2672             wdata.cMap = (Nlm_ColorMTool) 0;
2673          /* } */
2674       }
2675 
2676     if (totalColors == 0)
2677       break;    /* no colors specified for the new colormap */
2678 
2679     /* Create new colormap, if necessary */
2680     if ( !wdata.cMap )
2681       {
2682         XVisualInfo    visinfo;
2683         unsigned long  plane_m[1];
2684         unsigned long  pixels[256];
2685         int defaultdepth;
2686         Boolean testvisual;
2687 
2688         defaultdepth = DefaultDepth(dpy,
2689                   DefaultScreen(dpy));
2690 #ifdef OS_UNIX_LINUX
2691         if(!Nlm_CheckX(&visinfo))
2692 #else /* OS_UNIX_LINUX */
2693         if( !(XMatchVisualInfo(dpy,
2694                          DefaultScreen(dpy),
2695                          8,PseudoColor,&visinfo) ||
2696             XMatchVisualInfo(dpy,
2697                          DefaultScreen(dpy),
2698                          8,GrayScale,&visinfo)) )
2699 #endif /* else OS_UNIX_LINUX */
2700         break;  /* no matching visuals found */
2701 
2702 #ifdef OS_UNIX_LINUX
2703         if(visinfo.class > PseudoColor) break;  /* no palette needed */
2704 #endif
2705         wdata.cMap = XCreateColormap(dpy,
2706                                      RootWindow(dpy, DefaultScreen(dpy)),
2707                                      visinfo.visual, AllocNone);
2708         if (wdata.cMap == DefaultColormap(dpy,
2709                                           DefaultScreen(dpy)))
2710           {
2711             wdata.cMap = (Nlm_ColorMTool) 0;
2712             break;  /* hardware colormap is immutable */
2713           }
2714 
2715         if ( !XAllocColorCells ( dpy, wdata.cMap, FALSE,
2716                                  (unsigned long*) plane_m, 0,
2717                                  (unsigned long*) pixels, totalColors) )
2718           {
2719             XFreeColormap (dpy,wdata.cMap);
2720             wdata.cMap = (Nlm_ColorMTool) 0;
2721             break;  /* cannot allocate color cells for the new colormap */
2722           }
2723       }
2724 
2725     for (pixel = n_savedColors;  pixel < totalColors;  pixel++)
2726       {
2727         colorCells[pixel].red   = (((Nlm_Uint2)red  [pixel]) << 8) |
2728           (Nlm_Uint2)red  [pixel];
2729         colorCells[pixel].green = (((Nlm_Uint2)green[pixel]) << 8) |
2730           (Nlm_Uint2)green[pixel];
2731         colorCells[pixel].blue  = (((Nlm_Uint2)blue [pixel]) << 8) |
2732           (Nlm_Uint2)blue [pixel];
2733 
2734         colorCells[pixel].flags = DoRed | DoGreen | DoBlue;
2735         colorCells[pixel].pixel = pixel;
2736         colorCells[pixel].pad = 0;
2737       }
2738     XStoreColors(dpy, wdata.cMap,
2739                  colorCells + n_savedColors,
2740                  (int)(pixel - n_savedColors));
2741 
2742     XInstallColormap(dpy, wdata.cMap);
2743     XSetWindowColormap (dpy, XtWindow( wdata.handle ),
2744                         wdata.cMap);
2745 /*
2746     {{
2747       Nlm_ShellDataPtr sptr = wdata.allShells;
2748       while (sptr != NULL)
2749         {
2750           XSetWindowColormap (Nlm_currentXDisplay, XtWindow( sptr->shell ),
2751                               wdata.cMap);
2752           sptr = sptr->next;
2753         }
2754     }}
2755 */
2756 
2757     wdata.cMapStatus = 1;
2758   }  while ( 0 );
2759 #endif
2760 
2761   Nlm_SetSlateData ((Nlm_SlatE)w, &wdata);
2762 }
2763 
2764 /*
2765  * This defines a list of choices for opengl graphics type - that way we can
2766  * try different color attributes (in order of decreasing "quality") for the
2767  * opengl window, since not every color type is always available (especially
2768  * in X).
2769  */
2770 static int Nlm_OGLColorPreferences[][4] = {
2771 /* dbl.buf.  cIndexBits  RGBbits  z-depth  */
2772 /* */
2773   {   1    ,      0    ,    8   ,    8     },
2774   {   1    ,      0    ,    4   ,    8     },
2775   {   1    ,     16    ,    0   ,    8     },
2776   {   1    ,      8    ,    0   ,    8     },
2777 
2778   {   1    ,      0    ,    8   ,    16    },
2779   {   1    ,      0    ,    4   ,    16    },
2780   {   1    ,     16    ,    0   ,    16    },
2781   {   1    ,      8    ,    0   ,    16    },
2782 
2783   {   0    ,      0    ,    8   ,    8     },
2784   {   0    ,      0    ,    4   ,    8     },
2785   {   0    ,     16    ,    0   ,    8     },
2786   {   0    ,      8    ,    0   ,    8     },
2787 
2788   {   0    ,      0    ,    8   ,    16    },
2789   {   0    ,      0    ,    4   ,    16    },
2790   {   0    ,     16    ,    0   ,    16    },
2791   {   0    ,      8    ,    0   ,    16    },
2792 
2793   {   1    ,      0    ,    8   ,    0     },
2794   {   1    ,      0    ,    4   ,    0     },
2795   {   1    ,     16    ,    0   ,    0     },
2796   {   1    ,      8    ,    0   ,    0     },
2797 
2798   {   0    ,      0    ,    8   ,    0     },
2799   {   0    ,      0    ,    4   ,    0     },
2800   {   0    ,     16    ,    0   ,    0     },
2801   {   0    ,      8    ,    0   ,    0     },
2802 
2803   {  -1    ,      0    ,    0   ,    0     }
2804 };
2805 
2806 
2807 #ifdef WIN_MOTIF
2808 
2809 /*
2810   This is a bit crude, but in order to ensure that X and OpenGL
2811   will cooperate, need to create a (temporary and unseen) window
2812   to check whether OpenGL rendering context can be successfully
2813   attached to a window with the selected visual. This is called
2814   early on by vibrant to determine the visual that will be used
2815   for the application.
2816 */
2817 XVisualInfo * Nlm_GetBestOGLVisual(void)
2818 {
2819     int i, nAttribs, attribs[20], success=0;
2820     Display *dpy = Nlm_currentXDisplay;
2821     static XVisualInfo *visinfo = NULL;
2822 
2823     if (visinfo) return visinfo; /* only need to do this once */
2824 
2825     if (!glXQueryExtension(dpy, NULL, NULL)) {
2826         puts("X server has no GLX extension - required to use OpenGL!");
2827         exit(10);
2828     }
2829 
2830     for (i=0; Nlm_OGLColorPreferences[i][0] != -1; i++) {
2831 
2832         GLXContext glCtx;
2833         Colormap        cmap;
2834         XSetWindowAttributes swa;
2835         Window          win;
2836 
2837         nAttribs = 0;
2838         attribs[nAttribs++] = GLX_USE_GL;
2839         if (Nlm_OGLColorPreferences[i][0])
2840             attribs[nAttribs++] = GLX_DOUBLEBUFFER;
2841         if (Nlm_OGLColorPreferences[i][1]) {
2842             attribs[nAttribs++] = GLX_BUFFER_SIZE;
2843             attribs[nAttribs++] = Nlm_OGLColorPreferences[i][1];
2844         } else {
2845             attribs[nAttribs++] = GLX_RGBA;
2846             attribs[nAttribs++] = GLX_RED_SIZE;
2847             attribs[nAttribs++] = Nlm_OGLColorPreferences[i][2];
2848             attribs[nAttribs++] = GLX_GREEN_SIZE;
2849             attribs[nAttribs++] = Nlm_OGLColorPreferences[i][2];
2850             attribs[nAttribs++] = GLX_BLUE_SIZE;
2851             attribs[nAttribs++] = Nlm_OGLColorPreferences[i][2];
2852         }
2853         if (Nlm_OGLColorPreferences[i][3]) {
2854             attribs[nAttribs++] = GLX_DEPTH_SIZE;
2855             attribs[nAttribs++] = Nlm_OGLColorPreferences[i][3];
2856         }
2857         attribs[nAttribs++] = None;
2858 
2859         visinfo = glXChooseVisual(dpy, DefaultScreen(dpy), attribs);
2860         if (!visinfo) continue;
2861 
2862         glCtx = glXCreateContext(dpy, visinfo, None, GL_TRUE);
2863         if (!glCtx) {
2864             XFree(visinfo);
2865             continue;
2866         }
2867 
2868         cmap = XCreateColormap(dpy, RootWindow(dpy, visinfo->screen),
2869                                visinfo->visual, AllocNone);
2870         swa.colormap = cmap;
2871         swa.border_pixel = 0;
2872         swa.event_mask = ExposureMask | ButtonPressMask | StructureNotifyMask;
2873         win = XCreateWindow(dpy, RootWindow(dpy, visinfo->screen),
2874                             0, 0, 25, 25, 0, visinfo->depth,
2875                             InputOutput, visinfo->visual,
2876                             CWBorderPixel | CWColormap | CWEventMask, &swa);
2877         XSetStandardProperties(dpy, win, "test", "test", None, NULL, 0, NULL);
2878 
2879         success = glXMakeCurrent(dpy, win, glCtx);
2880 
2881         if (success) glXMakeCurrent(dpy, None, NULL);
2882         glXDestroyContext(dpy, glCtx);
2883         XDestroyWindow(dpy, win);
2884         XFreeColormap(dpy, cmap);
2885 
2886         if (success)
2887             break;
2888         else
2889             XFree(visinfo);
2890     }
2891 
2892     if (!success) {
2893         puts("Couldn't find X visual appropriate for OpenGL!");
2894         exit(1);
2895     }
2896     return visinfo;
2897 }
2898 
2899 /*
2900    Call this function twice - once with proper arguments to store window
2901    and context; then later, once all windows are realized, call with
2902    both arguments NULL to actually set the stored context. (thiessen)
2903 */
2904 
2905 void Nlm_SetOGLContext(Nlm_SlateTool a, Nlm_Boolean *im,
2906                       Display **d, XVisualInfo **v)
2907 {
2908   static Nlm_SlateTool area;
2909   static Nlm_Boolean *indexed=NULL;
2910   static int alreadyDone=FALSE;
2911   static Display **display=NULL;
2912   static XVisualInfo **visinfo=NULL;
2913 
2914   if (a != NULL) {
2915     area = a;
2916     indexed = im;
2917     display = d;
2918     visinfo = v;
2919 
2920   } else {
2921 
2922     GLXContext glCtx;
2923     int success;
2924 
2925     if (!indexed || !display || !visinfo) {
2926         puts("Nlm_SetOGLContext() : don't have required pointers");
2927         exit(3);
2928     }
2929 
2930     if (alreadyDone) return;
2931     alreadyDone = TRUE;
2932 
2933     *visinfo = Nlm_GetBestOGLVisual();
2934     if ((*visinfo)->depth < 12)
2935       *indexed = TRUE;
2936     else
2937       *indexed = FALSE;
2938 
2939     *display = XtDisplay(area);
2940 
2941     glCtx = glXCreateContext(*display, *visinfo, None, GL_TRUE);
2942     if (!glCtx) {
2943         puts("glXCreateContext in OpenGL window failed!\n");
2944         exit(2);
2945     }
2946     success = glXMakeCurrent(*display, XtWindow(area), glCtx);
2947     if (!glCtx || !success) {
2948         puts("glXMakeCurrent in OpenGL window failed!\n");
2949         exit(2);
2950     }
2951   }
2952 
2953 }
2954 
2955 /* Callback for 3DSlate that tells OpenGL window has been resized */
2956 static void Nlm_OGLResizeViewport(Widget w,
2957                                   XtPointer client_data,
2958                                   XtPointer call_data)
2959 {
2960   Nlm_RecT r;
2961 
2962 #ifdef MESA
2963   if (!glXGetCurrentContext()) return;
2964 #endif
2965 
2966   Nlm_GetRect ((Nlm_GraphiC) client_data, &r);
2967   glViewport(0,0,r.right-r.left+1,r.bottom-r.top+1);
2968 }
2969 
2970 #endif /* WIN_MOTIF */
2971 
2972 
2973 static void Nlm_New3DSlate (Nlm_SlatE s, Nlm_Boolean border,
2974                           Nlm_Boolean vScroll, Nlm_Boolean hScroll,
2975                           Nlm_SltScrlProc4 vscrl4, Nlm_SltScrlProc4 hscrl4,
2976                           Nlm_SltScrlProc vscrl, Nlm_SltScrlProc hscrl,
2977                           Nlm_Int2 extra, Nlm_Boolean *IndexMode,
2978                           void **display, void **visinfo)
2979 
2980 {
2981   Nlm_SlateTool   h;
2982   Nlm_BaR         hsb;
2983   Nlm_PoinT       npt;
2984   Nlm_RecT        r;
2985   Nlm_BaR         vsb;
2986   Nlm_WindowTool  wptr;
2987 #ifdef WIN_MOTIF
2988   Cardinal        n;
2989   Arg             wargs [20];
2990   String          trans =
2991     "<Btn1Down>:     slate(down)   ManagerGadgetArm()  \n\
2992      <Btn1Up>:       slate(up)     ManagerGadgetActivate() \n\
2993      <Btn1Motion>:   slate(motion) ManagerGadgetButtonMotion() \n\
2994      <Key>:          DrawingAreaInput()";
2995 #endif
2996 
2997 #ifdef WIN_MSWIN
2998   PIXELFORMATDESCRIPTOR pfd;
2999   int pf;
3000   HDC hDC;                /* device context */
3001   HGLRC hRC;              /* opengl context */
3002   int BitsPixel;
3003 #endif /* WIN_MSWIN */
3004 
3005   Nlm_GetRect ((Nlm_GraphiC) s, &r);
3006   h = NULL;
3007   vsb = NULL;
3008   hsb = NULL;
3009   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) s);
3010   *IndexMode = FALSE;
3011 
3012 #ifdef WIN_MSWIN
3013   h = CreateWindow (slateclass, "", WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
3014                     r.left, r.top, r.right - r.left + 1,
3015                     r.bottom - r.top + 1, wptr, 0,
3016                     Nlm_currentHInst, NULL);
3017   if (h != NULL) {
3018     SetProp (h, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) s);
3019   }
3020 
3021   hDC = GetDC(h);
3022 
3023   BitsPixel = GetDeviceCaps(hDC, BITSPIXEL);  /* number of bits per pixel */
3024   /* there is no guarantee that the contents of the stack that become
3025      the pfd are zeroed, therefore _make sure_ to clear these bits. */
3026   memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
3027   pfd.nSize        = sizeof(PIXELFORMATDESCRIPTOR);
3028   pfd.nVersion     = 1;
3029   pfd.dwFlags      = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
3030   pfd.cColorBits   = BitsPixel;
3031   pfd.dwLayerMask  = PFD_MAIN_PLANE;
3032 
3033   /* use colorindex mode if less that 16 bits per pixel */
3034   if (BitsPixel < 16) {
3035       pfd.iPixelType   = PFD_TYPE_COLORINDEX;
3036       *IndexMode = TRUE;
3037   }
3038   else {
3039       pfd.iPixelType   = PFD_TYPE_RGBA;
3040       *IndexMode = FALSE;
3041   }
3042 
3043   pf = ChoosePixelFormat(hDC, &pfd);
3044   if (pf == 0) {
3045   MessageBox(NULL, "ChoosePixelFormat() failed:  "
3046          "Cannot find a suitable pixel format.", "Error", MB_OK);
3047   }
3048 
3049   if (SetPixelFormat(hDC, pf, &pfd) == FALSE) {
3050   MessageBox(NULL, "SetPixelFormat() failed:  "
3051          "Cannot set format specified.", "Error", MB_OK);
3052   }
3053 
3054   /*DescribePixelFormat(hDC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);*/
3055 
3056   hRC = wglCreateContext(hDC);
3057   wglMakeCurrent(hDC, hRC);
3058 /* Do not ReleaseDC(h, hDC).  GL owns this */
3059 
3060 #endif
3061 
3062 #ifdef WIN_MOTIF
3063 
3064   n=0;
3065   XtSetArg (wargs [n], XmNwidth, (Dimension) (r.right - r.left + 1)); n++;
3066   XtSetArg (wargs [n], XmNheight, (Dimension) (r.bottom - r.top + 1)); n++;
3067   XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
3068   XtSetArg (wargs [n], XmNy, (Position) r.top); n++;
3069   XtSetArg (wargs [n], XmNmarginHeight, 0); n++;
3070   XtSetArg (wargs [n], XmNmarginWidth, 0); n++;
3071   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
3072   XtSetArg (wargs [n], XmNtranslations, XtParseTranslationTable (trans)); n++;
3073   h = XtCreateManagedWidget ((String) "", xmDrawingAreaWidgetClass,
3074                              wptr, wargs, n);
3075   Nlm_AddSubwindowShell(Nlm_GetParentWindow((Nlm_GraphiC)s), (Nlm_ShellTool)h); /* */
3076 
3077   XtVaSetValues(h, XmNuserData, (XtPointer)s, NULL);
3078 
3079   XtAddCallback(h, XmNresizeCallback, Nlm_OGLResizeViewport, (XtPointer)s);
3080   XtAddCallback(h, XmNexposeCallback, Nlm_SlateDrawCallback,  (XtPointer)s);
3081   XtAddCallback(h, XmNinputCallback,  Nlm_SlateInputCallback, (XtPointer)s);
3082   XtAddEventHandler(h, FocusChangeMask, FALSE, Nlm_SlateFocusCB, (XtPointer)s);
3083 
3084   XtManageChild( h );
3085 
3086   Nlm_SetOGLContext(h, IndexMode,
3087     (Display **) display, (XVisualInfo **) visinfo);
3088 
3089 #endif
3090 
3091 #ifdef WIN_MAC
3092   /* set up opengl format and context  (thiessen) */
3093   {
3094     GLint attrib[20];
3095     int na, i;
3096     GLboolean success=GL_FALSE;
3097     AGLPixelFormat fmt;
3098     static AGLContext ctx; /* should really be destroyed later... */
3099     /*GLint wrect[4];*/
3100 
3101     h = wptr; /* */
3102 
3103     for (i=0; Nlm_OGLColorPreferences[i][0] != -1; i++) {
3104 
3105       na = 0;
3106       attrib[na++] = AGL_MINIMUM_POLICY;
3107       attrib[na++] = AGL_ROBUST;
3108       if (Nlm_OGLColorPreferences[i][0]) attrib[na++] = AGL_DOUBLEBUFFER;
3109 
3110       if (Nlm_OGLColorPreferences[i][1]) {
3111         attrib[na++] = AGL_BUFFER_SIZE;
3112         attrib[na++] = Nlm_OGLColorPreferences[i][1];
3113         *IndexMode = TRUE;
3114       } else {
3115           attrib[na++] = AGL_RGBA;
3116           attrib[na++] = AGL_RED_SIZE;
3117           attrib[na++] = Nlm_OGLColorPreferences[i][2];
3118           attrib[na++] = AGL_GREEN_SIZE;
3119           attrib[na++] = Nlm_OGLColorPreferences[i][2];
3120           attrib[na++] = AGL_BLUE_SIZE;
3121           attrib[na++] = Nlm_OGLColorPreferences[i][2];
3122           *IndexMode = FALSE;
3123         }
3124 
3125       if (Nlm_OGLColorPreferences[i][3]) {
3126           attrib[na++] = AGL_DEPTH_SIZE;
3127           attrib[na++] = Nlm_OGLColorPreferences[i][3];
3128       }
3129 
3130       attrib[na++] = AGL_NONE;
3131 
3132       if ((fmt=aglChoosePixelFormat(NULL, 0, attrib)) == NULL) {
3133         continue;
3134       }
3135       if ((ctx=aglCreateContext(fmt,NULL)) == NULL) {
3136         aglDestroyPixelFormat(fmt);
3137         continue;
3138       }
3139       if (!aglSetDrawable(ctx,h)) {
3140         aglDestroyPixelFormat(fmt);
3141         aglDestroyContext(ctx);
3142         continue;
3143       }
3144       success = aglSetCurrentContext(ctx);
3145       aglDestroyPixelFormat(fmt);
3146       if (success == GL_TRUE) {
3147           break;
3148       } else {
3149         aglDestroyContext(ctx);
3150       }
3151 
3152     }
3153     if (success == GL_FALSE) return;
3154 
3155     /* make opengl context use its own colormap - tracking with parent window's
3156        colormap didn't work for some reason... (thiessen) */
3157     if (*IndexMode) aglDisable(ctx, AGL_COLORMAP_TRACKING);
3158   }
3159 #endif /* WIN_MAC */
3160 
3161   if (*IndexMode)
3162     Message(MSG_ERROR, "8-Bit (256 color) mode may be buggy, due to many platform bugs and inconsitencies.\n"
3163                        "Consider using a >= 16 bit display setting, which will provide higher quality graphics.");
3164 
3165   if (vScroll) {
3166     Nlm_GetRect ((Nlm_GraphiC) s, &r);
3167     r.left = r.right /* + 1 */;
3168     r.right += Nlm_vScrollBarWidth;
3169     if (vscrl4 != NULL) {
3170       vsb = Nlm_VertScrollBar4((Nlm_GraphiC) s, &r, (Nlm_BarScrlProc4)vscrl4);
3171     } else if (vscrl != NULL) {
3172       vsb = Nlm_VertScrollBar ((Nlm_GraphiC) s, &r, (Nlm_BarScrlProc) vscrl);
3173     } else {
3174       vsb = Nlm_VertScrollBar ((Nlm_GraphiC) s, &r,
3175                                (Nlm_BarScrlProc) Nlm_SlateVertScrollAction);
3176     }
3177   }
3178 
3179   if (hScroll) {
3180     Nlm_GetRect ((Nlm_GraphiC) s, &r);
3181     r.top = r.bottom /* + 1 */;
3182     r.bottom += Nlm_hScrollBarHeight;
3183     if (hscrl4 != NULL) {
3184       hsb = Nlm_HorizScrollBar4 ((Nlm_GraphiC) s, &r, (Nlm_BarScrlProc4) hscrl4);
3185     } else if (hscrl != NULL) {
3186       hsb = Nlm_HorizScrollBar ((Nlm_GraphiC) s, &r, (Nlm_BarScrlProc) hscrl);
3187     } else {
3188       hsb = Nlm_HorizScrollBar ((Nlm_GraphiC) s, &r,
3189                                 (Nlm_BarScrlProc) Nlm_SlateHorizScrollAction);
3190     }
3191   }
3192 
3193   Nlm_GetRect ((Nlm_GraphiC) s, &r);
3194   Nlm_InsetRect (&r, 4, 4);
3195   Nlm_LoadPt (&npt, r.left, r.top);
3196   Nlm_LoadBoxData ((Nlm_BoX) s, npt, npt, npt, npt.y, npt.x, 0, 0, 0, 0, 0, 0);
3197   Nlm_GetRect ((Nlm_GraphiC) s, &r);
3198   Nlm_LoadSlateData (s, h, vsb, hsb, NULL, NULL, 0, 0,
3199                      border, 0, 0, 0, NULL, NULL, FALSE);
3200   Nlm_SetSlatePolicy(s, DEFAULT_SLATE_POLICY);
3201   Nlm_LoadPanelData ((Nlm_PaneL) s, NULL, NULL, NULL, NULL, NULL, extra, NULL, NULL);
3202 }
3203 
3204 #endif /* _OPENGL */
3205 
3206 
3207 static void Nlm_NewPanel (Nlm_PaneL p, Nlm_PnlActnProc draw,
3208                           Nlm_Int2 extra, Nlm_PnlActnProc reset)
3209 
3210 /*
3211 *  MemNew already sets the extra data to NULL.  If the window is visible,
3212 *  the draw request may occur before the extra data is initialized.
3213 */
3214 
3215 {
3216   Nlm_PoinT  npt;
3217   Nlm_RecT   r;
3218 
3219   Nlm_GetRect ((Nlm_GraphiC) p, &r);
3220   Nlm_LoadPt (&npt, r.left, r.top);
3221   Nlm_LoadBoxData ((Nlm_BoX) p, npt, npt, npt, npt.y, npt.x, 0, 0, 0, 0, 0, 0);
3222   Nlm_LoadPanelData (p, NULL, NULL, NULL, NULL, draw, extra, reset, NULL);
3223 }
3224 
3225 static void Nlm_NewDisplay (Nlm_DisplaY d)
3226 
3227 {
3228   Nlm_PoinT   pos;
3229   Nlm_RecT    r;
3230   Nlm_Int2    vis;
3231   Nlm_WindoW  w;
3232 
3233   Nlm_GetRect ((Nlm_GraphiC) d, &r);
3234   Nlm_InsetRect (&r, 4, 4);
3235   Nlm_LoadPt(&pos, r.left, (Nlm_Int2)(r.top + disphght));
3236   if (disphght > 0) {
3237     vis = (Nlm_Int2)((r.bottom - r.top + 1) / disphght);
3238   } else {
3239     vis = 0;
3240   }
3241   Nlm_LoadDisplayData (d, FALSE, FALSE, NULL, 0, vis, pos);
3242   w = Nlm_GetParentWindow ((Nlm_GraphiC) d);
3243   Nlm_SetWindowCharDisplay (w, d);
3244 }
3245 
3246 static Nlm_SlatE Nlm_CommonSlate (Nlm_GrouP prnt, Nlm_Int2 width,
3247                                   Nlm_Int2 height, Nlm_Boolean border,
3248                                   Nlm_Boolean vScroll, Nlm_Boolean hScroll,
3249                                   Nlm_SltScrlProc vscrl, Nlm_SltScrlProc hscrl,
3250                                   Nlm_Int2 extra, Nlm_GphPrcsPtr classPtr)
3251 
3252 {
3253   Nlm_GraphicData  gdata;
3254   Nlm_PoinT        npt;
3255   Nlm_RecT         r;
3256   Nlm_SlatE        s;
3257   Nlm_WindoW       tempPort;
3258 
3259   s = NULL;
3260   if (prnt != NULL) {
3261     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
3262     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
3263     Nlm_SelectFont (Nlm_systemFont);
3264     Nlm_LoadRect(&r, npt.x, npt.y,
3265                  (Nlm_Int2)(npt.x + width), (Nlm_Int2)(npt.y + height));
3266     s = (Nlm_SlatE)Nlm_CreateLink((Nlm_GraphiC)prnt, &r,
3267                                   (Nlm_Int2)(sizeof(Nlm_SlateRec) + extra),
3268                                   classPtr);
3269     if (s != NULL) {
3270       if (classPtr != NULL) {
3271         classPtr->ancestor = slateProcs;
3272       } else {
3273         Nlm_GetGraphicData ((Nlm_GraphiC) s, &gdata);
3274         gdata.classptr = slateProcs;
3275         Nlm_SetGraphicData ((Nlm_GraphiC) s, &gdata);
3276       }
3277       Nlm_NewSlate (s, border, vScroll, hScroll, NULL, NULL, vscrl, hscrl, extra);
3278       if (vScroll) {
3279         r.right += Nlm_vScrollBarWidth;
3280       }
3281       Nlm_DoAdjustPrnt ((Nlm_GraphiC) s, &r, TRUE, FALSE);
3282       Nlm_DoShow ((Nlm_GraphiC) s, TRUE, FALSE);
3283     }
3284     Nlm_RestorePort (tempPort);
3285   }
3286   return s;
3287 }
3288 
3289 extern Nlm_SlatE Nlm_GeneralSlate(Nlm_GrouP prnt, Nlm_Int2 width,
3290                                   Nlm_Int2 height, Nlm_SltScrlProc scrl,
3291                                   Nlm_Int2 extra, Nlm_GphPrcsPtr classPtr)
3292 {
3293   return Nlm_CommonSlate(prnt,
3294                          (Nlm_Int2)(width *Nlm_stdCharWidth  +8),
3295                          (Nlm_Int2)(height*Nlm_stdLineHeight +8),
3296                          TRUE, TRUE, FALSE, scrl, NULL, extra, classPtr);
3297 }
3298 
3299 extern Nlm_SlatE Nlm_ScrollSlate (Nlm_GrouP prnt, Nlm_Int2 width,
3300                                   Nlm_Int2 height)
3301 {
3302   return Nlm_CommonSlate(prnt,
3303                          (Nlm_Int2)(width *Nlm_stdCharWidth  +8),
3304                          (Nlm_Int2)(height*Nlm_stdLineHeight +8),
3305                          TRUE, TRUE, FALSE, NULL, NULL, 0, NULL);
3306 }
3307 
3308 extern Nlm_SlatE Nlm_NormalSlate(Nlm_GrouP prnt, Nlm_Int2 width,
3309                                  Nlm_Int2 height)
3310 {
3311   return Nlm_CommonSlate(prnt,
3312                          (Nlm_Int2)(width *Nlm_stdCharWidth  +8),
3313                          (Nlm_Int2)(height*Nlm_stdLineHeight +8),
3314                          TRUE, FALSE, FALSE, NULL, NULL, 0, NULL);
3315 }
3316 
3317 extern Nlm_SlatE Nlm_HiddenSlate(Nlm_GrouP prnt, Nlm_Int2 width,
3318                                  Nlm_Int2 height)
3319 {
3320   return Nlm_CommonSlate(prnt,
3321                         (Nlm_Int2)(width *Nlm_stdCharWidth  +8),
3322                         (Nlm_Int2)(height*Nlm_stdLineHeight +8),
3323                         FALSE, FALSE, FALSE, NULL, NULL, 0, NULL);
3324 }
3325 
3326 extern void Nlm_VirtualSlate (Nlm_SlatE s, Nlm_Int2 before,
3327                               Nlm_Int2 after, Nlm_SltScrlProc actn)
3328 
3329 {
3330   Nlm_Handle     chdl;
3331   Nlm_Handle     rhdl;
3332   Nlm_BaR        sb;
3333   Nlm_SlateData  sdata;
3334 
3335   Nlm_GetSlateData (s, &sdata);
3336   rhdl = sdata.rowHandles;
3337   if (rhdl != NULL) {
3338     Nlm_HandFree (rhdl);
3339   }
3340   chdl = sdata.colHandles;
3341   if (chdl != NULL) {
3342     Nlm_HandFree (chdl);
3343   }
3344   sdata.rowHandles = NULL;
3345   sdata.colHandles = NULL;
3346   sdata.numRows = 0;
3347   sdata.numCols = 0;
3348   sdata.barRows = 0;
3349   sdata.vBefore = before;
3350   sdata.vAfter = after;
3351   sdata.vAction = actn;
3352   Nlm_SetSlateData (s, &sdata);
3353   sb = sdata.hScrollBar;
3354   if (sb != NULL) {
3355     Nlm_DoReset ((Nlm_GraphiC) sb, TRUE);
3356   }
3357   sb = sdata.vScrollBar;
3358   if (sb != NULL) {
3359     Nlm_DoReset ((Nlm_GraphiC) sb, TRUE);
3360   }
3361 }
3362 
3363 extern void Nlm_RegisterRow (Nlm_SlatE s, Nlm_Int2 position,
3364                              Nlm_Int2 height, Nlm_Int2 count)
3365 
3366 {
3367   Nlm_Boolean    added;
3368   Nlm_Int2       after;
3369   Nlm_Int2       barmax;
3370   Nlm_Int2       before;
3371   Nlm_Int2       chunk;
3372   Nlm_Int2       numRows;
3373   Nlm_Int2       delta;
3374   Nlm_Int2       i;
3375   Nlm_OfsPtr     optr;
3376   Nlm_RecT       r;
3377   Nlm_Handle     rhdl;
3378   Nlm_BaR        sb;
3379   Nlm_SlateData  sdata;
3380   Nlm_WindoW     tempPort;
3381   Nlm_Int2       vis;
3382 
3383   if (s != NULL) {
3384     Nlm_GetRect ((Nlm_GraphiC) s, &r);
3385     Nlm_InsetRect (&r, 4, 4);
3386     Nlm_GetSlateData (s, &sdata);
3387     numRows = sdata.numRows;
3388     rhdl = sdata.rowHandles;
3389     added = FALSE;
3390     chunk = 128;
3391     delta = (Nlm_Int2)(position - r.top);
3392     if (rhdl == NULL) {
3393       numRows = 1;
3394       rhdl = Nlm_HandNew (sizeof (Nlm_OffsetRec) * chunk);
3395       if (rhdl != NULL) {
3396         optr = (Nlm_OfsPtr) Nlm_HandLock (rhdl);
3397         optr [numRows - 1].offset = delta;
3398         optr [numRows - 1].height = height;
3399         added = TRUE;
3400         Nlm_HandUnlock (rhdl);
3401       }
3402       delta += height;
3403       count--;
3404     }
3405     if (rhdl != NULL && count > 0) {
3406       optr = (Nlm_OfsPtr) Nlm_HandLock (rhdl);
3407       for (i = 0; i < count; i++) {
3408         if (delta >= optr [numRows - 1].offset + optr [numRows - 1].height) {
3409           if (numRows % chunk == 0) {
3410             Nlm_HandUnlock (rhdl);
3411             rhdl = Nlm_HandMore (rhdl, sizeof (Nlm_OffsetRec) *
3412                                  (numRows / chunk + 1) * chunk);
3413             optr = (Nlm_OfsPtr) Nlm_HandLock (rhdl);
3414           }
3415           numRows++;
3416           optr [numRows - 1].offset = delta;
3417           optr [numRows - 1].height = height;
3418           added = TRUE;
3419         } else if (delta == optr [numRows - 1].offset &&
3420                    height > optr [numRows - 1].height) {
3421           optr [numRows - 1].height = height;
3422           added = TRUE;
3423         }
3424         delta += height;
3425       }
3426       Nlm_HandUnlock (rhdl);
3427     }
3428     sdata.numRows = numRows;
3429     sdata.rowHandles = rhdl;
3430     Nlm_SetSlateData (s, &sdata);
3431     if (added) {
3432       optr = (Nlm_OfsPtr) Nlm_HandLock (rhdl);
3433       if (numRows > 1) {
3434         i = (Nlm_Int2)(numRows - 2);
3435         vis = 0;
3436         while (i >= 0 && optr [numRows - 1].offset + optr [numRows - 1].height -
3437                optr [i].offset <= r.bottom - r.top) {
3438           i--;
3439           vis++;
3440         }
3441         barmax = (Nlm_Int2)(numRows - vis - 1);
3442       } else {
3443         barmax = 0;
3444       }
3445       sdata.barRows = barmax;
3446       Nlm_SetSlateData (s, &sdata);
3447       i = 1;
3448       vis = 0;
3449       while (i < numRows && optr [i].offset + optr [i].height -
3450              optr [0].offset <= r.bottom - r.top) {
3451         i++;
3452         vis++;
3453       }
3454       Nlm_HandUnlock (rhdl);
3455       sb = sdata.vScrollBar;
3456       if (sb != NULL) {
3457         before = sdata.vBefore;
3458         after = sdata.vAfter;
3459         tempPort = Nlm_SavePort ((Nlm_GraphiC) s);
3460         Nlm_DoSetRange((Nlm_GraphiC)sb, 1, vis,
3461                        (Nlm_Int2)(barmax + before + after), FALSE);
3462         if (before > 0) {
3463           Nlm_CorrectBarValue (sb, before);
3464         }
3465         Nlm_RestorePort (tempPort);
3466       }
3467     }
3468   }
3469 }
3470 
3471 extern void Nlm_RegisterColumn (Nlm_SlatE s, Nlm_Int2 position,
3472                                 Nlm_Int2 width, Nlm_Int2 count)
3473 
3474 {
3475 }
3476 
3477 extern void Nlm_SetPanelClick (Nlm_PaneL p, Nlm_PnlClckProc click,
3478                                Nlm_PnlClckProc drag, Nlm_PnlClckProc hold,
3479                                Nlm_PnlClckProc release)
3480 
3481 {
3482   Nlm_PanelData  pdata;
3483 
3484   if (p != NULL) {
3485     Nlm_GetPanelData (p, &pdata);
3486     pdata.click = click;
3487     pdata.drag = drag;
3488     pdata.hold = hold;
3489     pdata.release = release;
3490     Nlm_SetPanelData (p, &pdata);
3491   }
3492 }
3493 
3494 extern Nlm_PaneL Nlm_GeneralPanel (Nlm_SlatE s, Nlm_PnlActnProc draw,
3495                                    Nlm_Int2 extra, Nlm_PnlActnProc reset,
3496                                    Nlm_GphPrcsPtr classPtr)
3497 
3498 {
3499   Nlm_GraphicData  gdata;
3500   Nlm_PoinT        npt;
3501   Nlm_PaneL        p;
3502   Nlm_RecT         r;
3503   Nlm_WindoW       tempPort;
3504 
3505   p = NULL;
3506   if (s != NULL) {
3507     tempPort = Nlm_SavePort ((Nlm_GraphiC) s);
3508     Nlm_GetNextPosition ((Nlm_GraphiC) s, &npt);
3509     Nlm_SelectFont (Nlm_systemFont);
3510     Nlm_LoadRect (&r, npt.x, npt.y, npt.x, npt.y);
3511     p = (Nlm_PaneL)Nlm_CreateLink((Nlm_GraphiC)s, &r,
3512                                   (Nlm_Int2)(sizeof(Nlm_PanelRec) + extra),
3513                                   classPtr);
3514     if (p != NULL) {
3515       if (classPtr != NULL) {
3516         classPtr->ancestor = panelProcs;
3517       } else {
3518         Nlm_GetGraphicData ((Nlm_GraphiC) p, &gdata);
3519         gdata.classptr = panelProcs;
3520         Nlm_SetGraphicData ((Nlm_GraphiC) p, &gdata);
3521       }
3522       Nlm_NewPanel (p, draw, extra, reset);
3523       Nlm_DoAdjustPrnt ((Nlm_GraphiC) p, &r, TRUE, FALSE);
3524       Nlm_DoShow ((Nlm_GraphiC) p, TRUE, FALSE);
3525     }
3526     Nlm_RestorePort (tempPort);
3527   }
3528   return p;
3529 }
3530 
3531 extern Nlm_PaneL Nlm_CustomPanel (Nlm_SlatE s, Nlm_PnlActnProc draw,
3532                                   Nlm_Int2 extra, Nlm_PnlActnProc reset)
3533 
3534 {
3535   return (Nlm_GeneralPanel (s, draw, extra, reset, NULL));
3536 }
3537 
3538 extern Nlm_PaneL Nlm_AutonomousPanel4 (Nlm_GrouP prnt, Nlm_Int2 pixwidth,
3539                                        Nlm_Int2 pixheight, Nlm_PnlActnProc draw,
3540                                        Nlm_SltScrlProc4 vscrl, Nlm_SltScrlProc4 hscrl,
3541                                        Nlm_Int2 extra, Nlm_PnlActnProc reset,
3542                                        Nlm_GphPrcsPtr classPtr)
3543 
3544 /*
3545 *  Note that an autonomous panel is really a combination of slate and
3546 *  panel in one object, and thus uses the slateProcs class function.
3547 */
3548 
3549 {
3550   Nlm_Boolean      border;
3551   Nlm_GraphicData  gdata;
3552   Nlm_Boolean      hScroll;
3553   Nlm_PoinT        npt;
3554   Nlm_PaneL        p;
3555   Nlm_RecT         r;
3556   Nlm_WindoW       tempPort;
3557   Nlm_Boolean      vScroll;
3558 
3559 
3560   p = NULL;
3561   if (prnt != NULL) {
3562     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
3563     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
3564     Nlm_SelectFont (Nlm_systemFont);
3565     border = (Nlm_Boolean) (vscrl != NULL || hscrl != NULL);
3566     vScroll = (Nlm_Boolean) (vscrl != NULL);
3567     hScroll = (Nlm_Boolean) (hscrl != NULL);
3568     if (vScroll || hScroll) {
3569       Nlm_LoadRect(&r, npt.x, npt.y,
3570                    (Nlm_Int2)(npt.x+pixwidth +8),
3571                    (Nlm_Int2)(npt.y+pixheight+8));
3572     } else {
3573       Nlm_LoadRect(&r, npt.x, npt.y,
3574                    (Nlm_Int2)(npt.x+pixwidth),
3575                    (Nlm_Int2)(npt.y+pixheight));
3576     }
3577     p = (Nlm_PaneL)Nlm_CreateLink((Nlm_GraphiC)prnt, &r,
3578                                   (Nlm_Int2)(sizeof(Nlm_PanelRec) + extra),
3579                                   classPtr);
3580     if (p != NULL) {
3581       if (classPtr != NULL) {
3582         classPtr->ancestor = slateProcs;
3583       } else {
3584         Nlm_GetGraphicData ((Nlm_GraphiC) p, &gdata);
3585         gdata.classptr = slateProcs;
3586         Nlm_SetGraphicData ((Nlm_GraphiC) p, &gdata);
3587       }
3588       Nlm_NewSlate ((Nlm_SlatE) p, border, vScroll, hScroll, vscrl, hscrl, NULL, NULL, extra);
3589       Nlm_NewPanel (p, draw, extra, reset);
3590       if (vScroll) {
3591         r.right += Nlm_vScrollBarWidth;
3592       }
3593       if (hScroll) {
3594         r.bottom += Nlm_hScrollBarHeight;
3595       }
3596       Nlm_DoAdjustPrnt ((Nlm_GraphiC) p, &r, TRUE, FALSE);
3597       Nlm_DoShow ((Nlm_GraphiC) p, TRUE, FALSE);
3598     }
3599     Nlm_RestorePort (tempPort);
3600   }
3601   return p;
3602 }
3603 
3604 
3605 #ifdef _OPENGL
3606 
3607 
3608 extern Nlm_PaneL Nlm_Autonomous3DPanel (Nlm_GrouP prnt, Nlm_Int2 pixwidth,
3609                                       Nlm_Int2 pixheight, Nlm_PnlActnProc draw,
3610                                       Nlm_SltScrlProc vscrl, Nlm_SltScrlProc hscrl,
3611                                       Nlm_Int2 extra, Nlm_PnlActnProc reset,
3612                                       Nlm_GphPrcsPtr classPtr, Nlm_Boolean *IndexMode,
3613                                       void **display, void **visinfo)
3614 
3615 /*
3616 *  Note that an autonomous panel is really a combination of slate and
3617 *  panel in one object, and thus uses the slateProcs class function.
3618 */
3619 
3620 {
3621   Nlm_Boolean      border;
3622   Nlm_GraphicData  gdata;
3623   Nlm_Boolean      hScroll;
3624   Nlm_PoinT        npt;
3625   Nlm_PaneL        p;
3626   Nlm_RecT         r;
3627   Nlm_WindoW       tempPort;
3628   Nlm_Boolean      vScroll;
3629 
3630 
3631   p = NULL;
3632   if (prnt != NULL) {
3633     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
3634     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
3635     Nlm_SelectFont (Nlm_systemFont);
3636     border = (Nlm_Boolean) (vscrl != NULL || hscrl != NULL);
3637     vScroll = (Nlm_Boolean) (vscrl != NULL);
3638     hScroll = (Nlm_Boolean) (hscrl != NULL);
3639     if (vScroll || hScroll) {
3640       Nlm_LoadRect(&r, npt.x, npt.y,
3641                   (Nlm_Int2)(npt.x+pixwidth+8), (Nlm_Int2)(npt.y+pixheight+8));
3642     } else {
3643       Nlm_LoadRect(&r, npt.x, npt.y,
3644                   (Nlm_Int2)(npt.x+pixwidth), (Nlm_Int2)(npt.y+pixheight));
3645     }
3646     p = (Nlm_PaneL)Nlm_CreateLink((Nlm_GraphiC) prnt, &r,
3647                                   (Nlm_Int2)(sizeof(Nlm_PanelRec) + extra),
3648                                   classPtr);
3649     if (p != NULL) {
3650       if (classPtr != NULL) {
3651         classPtr->ancestor = slateProcs;
3652       } else {
3653         Nlm_GetGraphicData ((Nlm_GraphiC) p, &gdata);
3654         gdata.classptr = slateProcs;
3655         Nlm_SetGraphicData ((Nlm_GraphiC) p, &gdata);
3656       }
3657       Nlm_New3DSlate ((Nlm_SlatE) p, border, vScroll, hScroll, NULL, NULL, vscrl, hscrl,
3658           extra, IndexMode, display, visinfo);
3659       Nlm_NewPanel (p, draw, extra, reset);
3660       if (vScroll) {
3661         r.right += Nlm_vScrollBarWidth;
3662       }
3663       if (hScroll) {
3664         r.bottom += Nlm_hScrollBarHeight;
3665       }
3666       Nlm_DoAdjustPrnt ((Nlm_GraphiC) p, &r, TRUE, FALSE);
3667       Nlm_DoShow ((Nlm_GraphiC) p, TRUE, FALSE);
3668     }
3669     Nlm_RestorePort (tempPort);
3670   }
3671   return p;
3672 }
3673 
3674 #endif /* _OPENGL */
3675 
3676 extern Nlm_PaneL Nlm_AutonomousPanel (Nlm_GrouP prnt, Nlm_Int2 pixwidth,
3677                                       Nlm_Int2 pixheight, Nlm_PnlActnProc draw,
3678                                       Nlm_SltScrlProc vscrl, Nlm_SltScrlProc hscrl,
3679                                       Nlm_Int2 extra, Nlm_PnlActnProc reset,
3680                                       Nlm_GphPrcsPtr classPtr)
3681 
3682 /*
3683 *  Note that an autonomous panel is really a combination of slate and
3684 *  panel in one object, and thus uses the slateProcs class function.
3685 */
3686 
3687 {
3688   Nlm_Boolean      border;
3689   Nlm_GraphicData  gdata;
3690   Nlm_Boolean      hScroll;
3691   Nlm_PoinT        npt;
3692   Nlm_PaneL        p;
3693   Nlm_RecT         r;
3694   Nlm_WindoW       tempPort;
3695   Nlm_Boolean      vScroll;
3696 
3697 
3698   p = NULL;
3699   if (prnt != NULL) {
3700     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
3701     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
3702     Nlm_SelectFont (Nlm_systemFont);
3703     border = (Nlm_Boolean) (vscrl != NULL || hscrl != NULL);
3704     vScroll = (Nlm_Boolean) (vscrl != NULL);
3705     hScroll = (Nlm_Boolean) (hscrl != NULL);
3706     if (vScroll || hScroll) {
3707       Nlm_LoadRect(&r, npt.x, npt.y,
3708                   (Nlm_Int2)(npt.x+pixwidth+8), (Nlm_Int2)(npt.y+pixheight+8));
3709     } else {
3710       Nlm_LoadRect(&r, npt.x, npt.y,
3711                   (Nlm_Int2)(npt.x+pixwidth), (Nlm_Int2)(npt.y+pixheight));
3712     }
3713     p = (Nlm_PaneL)Nlm_CreateLink((Nlm_GraphiC) prnt, &r,
3714                                   (Nlm_Int2)(sizeof(Nlm_PanelRec) + extra),
3715                                   classPtr);
3716     if (p != NULL) {
3717       if (classPtr != NULL) {
3718         classPtr->ancestor = slateProcs;
3719       } else {
3720         Nlm_GetGraphicData ((Nlm_GraphiC) p, &gdata);
3721         gdata.classptr = slateProcs;
3722         Nlm_SetGraphicData ((Nlm_GraphiC) p, &gdata);
3723       }
3724       Nlm_NewSlate ((Nlm_SlatE) p, border, vScroll, hScroll, NULL, NULL, vscrl, hscrl, extra);
3725       Nlm_NewPanel (p, draw, extra, reset);
3726       if (vScroll) {
3727         r.right += Nlm_vScrollBarWidth;
3728       }
3729       if (hScroll) {
3730         r.bottom += Nlm_hScrollBarHeight;
3731       }
3732       Nlm_DoAdjustPrnt ((Nlm_GraphiC) p, &r, TRUE, FALSE);
3733       Nlm_DoShow ((Nlm_GraphiC) p, TRUE, FALSE);
3734     }
3735     Nlm_RestorePort (tempPort);
3736   }
3737   return p;
3738 }
3739 
3740 extern Nlm_PaneL Nlm_SimplePanel (Nlm_GrouP prnt, Nlm_Int2 pixwidth,
3741                                   Nlm_Int2 pixheight, Nlm_PnlActnProc draw)
3742 
3743 {
3744   Nlm_PaneL  p;
3745 
3746   p = Nlm_AutonomousPanel (prnt, pixwidth, pixheight, draw, NULL, NULL, 0, NULL, NULL);
3747   return p;
3748 }
3749 
3750 extern void Nlm_RegisterRect (Nlm_PaneL p, Nlm_RectPtr r)
3751 
3752 {
3753   Nlm_BoxData  bdata;
3754   Nlm_RecT     pr;
3755 
3756   if (p != NULL && r != NULL) {
3757     Nlm_RecordRect ((Nlm_GraphiC) p, r);
3758     Nlm_NextPosition ((Nlm_GraphiC) p, r);
3759     Nlm_GetRect ((Nlm_GraphiC) p, &pr);
3760     Nlm_GetBoxData ((Nlm_BoX) p, &bdata);
3761     pr.right = bdata.limitPoint.x;
3762     pr.bottom = bdata.limitPoint.y;
3763     Nlm_SetRect ((Nlm_GraphiC) p, &pr);
3764     Nlm_DoAdjustPrnt ((Nlm_GraphiC) p, r, TRUE, TRUE);
3765   }
3766 }
3767 
3768 static Nlm_DisplaY Nlm_CommonDisplay (Nlm_GrouP prnt, Nlm_Int2 width,
3769                                       Nlm_Int2 height, Nlm_Boolean hidden,
3770                                       Nlm_Boolean scroll)
3771 
3772 {
3773   Nlm_DisplaY  d;
3774   Nlm_WindoW   tempPort;
3775 
3776   d = NULL;
3777   if (prnt != NULL) {
3778     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
3779     dispfont = Nlm_programFont;
3780     Nlm_SelectFont (dispfont);
3781     disphght = Nlm_LineHeight ();
3782     if (hidden) {
3783       d = (Nlm_DisplaY)Nlm_CommonSlate(prnt,
3784                                        (Nlm_Int2)(width *Nlm_stdCharWidth  +8),
3785                                        (Nlm_Int2)(height*Nlm_stdLineHeight +8),
3786                                        FALSE, FALSE, FALSE, NULL, NULL,
3787                                        sizeof (Nlm_DisplayData), displayProcs);
3788     } else if (scroll) {
3789       d = (Nlm_DisplaY)Nlm_CommonSlate(prnt,
3790                                        (Nlm_Int2)(width*Nlm_stdCharWidth   +8),
3791                                        (Nlm_Int2)(height*Nlm_stdLineHeight +8),
3792                                        TRUE, TRUE, FALSE, NULL, NULL,
3793                                        sizeof (Nlm_DisplayData), displayProcs);
3794     } else {
3795       d = (Nlm_DisplaY)Nlm_CommonSlate(prnt,
3796                                        (Nlm_Int2)(width*Nlm_stdCharWidth   +8),
3797                                        (Nlm_Int2)(height*Nlm_stdLineHeight +8),
3798                                        TRUE, FALSE, FALSE, NULL, NULL,
3799                                        sizeof (Nlm_DisplayData), displayProcs);
3800     }
3801     if (d != NULL) {
3802       Nlm_NewDisplay (d);
3803     }
3804     Nlm_SelectFont (Nlm_systemFont);
3805     Nlm_RestorePort (tempPort);
3806   }
3807   return d;
3808 }
3809 
3810 extern Nlm_DisplaY Nlm_NormalDisplay (Nlm_GrouP prnt, Nlm_Int2 width,
3811                                       Nlm_Int2 height)
3812 
3813 {
3814   return (Nlm_CommonDisplay (prnt, width, height, FALSE, FALSE));
3815 }
3816 
3817 extern Nlm_DisplaY Nlm_ScrollDisplay (Nlm_GrouP prnt, Nlm_Int2 width,
3818                                       Nlm_Int2 height)
3819 {
3820   return (Nlm_CommonDisplay (prnt, width, height, FALSE, TRUE));
3821 }
3822 
3823 
3824 extern void Nlm_CaptureSlateFocus(Nlm_SlatE s)
3825 {
3826   Nlm_WindoW    w = Nlm_GetParentWindow( (Nlm_GraphiC)s );
3827 #if defined(WIN_MSWIN)  ||  defined(WIN_MOTIF)
3828   Nlm_SlateTool h = Nlm_GetSlateHandle( s );
3829 #endif
3830 
3831   Nlm_DoLoseFocus((Nlm_GraphiC)w, (Nlm_GraphiC)s, FALSE);
3832   Nlm_ChangeSlateFocus(s, TRUE);
3833 #ifdef WIN_MSWIN
3834   if (h != NULL)
3835     SetFocus( h );
3836 #endif
3837 #ifdef WIN_MOTIF
3838   XtVaSetValues(h, XmNsensitive, True, NULL);
3839   if (h != NULL)
3840     XmProcessTraversal(h, XmTRAVERSE_CURRENT);
3841 #endif
3842 }
3843 
3844 
3845 static Nlm_GraphiC Nlm_SlateGainFocus(Nlm_GraphiC s, Nlm_Char ch,
3846                                       Nlm_Boolean savePort)
3847 {
3848   return (ch != '\t'  &&  ch != '\n'  &&  ch != '\r'  &&
3849           Nlm_GetVisible( s )  &&  Nlm_GetAllParentsVisible( s )  &&
3850           Nlm_HandleSlateInput((Nlm_SlatE)s, ch)) ?
3851     s : 0;
3852 }
3853 
3854 
3855 static void Nlm_SlateLoseFocus(Nlm_GraphiC s, Nlm_GraphiC excpt, Nlm_Boolean savePort)
3856 {
3857   if (s != excpt)
3858     Nlm_ChangeSlateFocus((Nlm_SlatE)s, FALSE);
3859 }
3860 
3861 
3862 #ifdef WIN_MAC
3863 extern Nlm_Boolean Nlm_RegisterSlates(void)
3864 {
3865   return TRUE;
3866 }
3867 #endif
3868 
3869 #ifdef WIN_MSWIN
3870 static void Nlm_DrawSlate (Nlm_SlatE s)
3871 
3872 {
3873   Nlm_PnlActnProc  drw;
3874   Nlm_SlateTool    h;
3875   Nlm_PaneL        n;
3876   Nlm_PaneL        p;
3877   Nlm_PanelData    pdata;
3878   Nlm_RecT         r;
3879 
3880   if (Nlm_GetVisible ((Nlm_GraphiC) s) && Nlm_GetAllParentsVisible ((Nlm_GraphiC) s) && okayToDrawContents) {
3881     h = Nlm_GetSlateHandle ((Nlm_SlatE) s);
3882     if (h != NULL && IsWindowVisible (h)) {
3883       Nlm_GetRect ((Nlm_GraphiC) s, &r);
3884       Nlm_SelectFont (Nlm_systemFont);
3885       Nlm_ResetDrawingTools ();
3886       if (Nlm_GetSlateBorder ((Nlm_SlatE) s)) {
3887         Nlm_FrameRect (&r);
3888       }
3889       Nlm_GetPanelData ((Nlm_PaneL) s, &pdata);
3890       if (pdata.click != NULL || pdata.drag != NULL || pdata.hold != NULL ||
3891           pdata.release != NULL || pdata.draw != NULL || pdata.reset != NULL) {
3892         p = (Nlm_PaneL) s;
3893 /*
3894         recentlyClickedPanel = p;
3895 */
3896         drw = Nlm_GetPanelDraw (p);
3897         if (drw != NULL && Nlm_GetVisible ((Nlm_GraphiC) p)) {
3898           drw (p);
3899           Nlm_ResetDrawingTools ();
3900         }
3901       } else {
3902         p = (Nlm_PaneL) Nlm_GetChild ((Nlm_GraphiC) s);
3903         while (p != NULL) {
3904           n = (Nlm_PaneL) Nlm_GetNext ((Nlm_GraphiC) p);
3905           drw = Nlm_GetPanelDraw (p);
3906           if (drw != NULL && Nlm_GetVisible ((Nlm_GraphiC) p)) {
3907             drw (p);
3908             Nlm_ResetDrawingTools ();
3909           }
3910           p = n;
3911         }
3912       }
3913     }
3914   }
3915 }
3916 
3917 /* Message cracker functions */
3918 
3919 static void MyCls_OnLButtonDown(HWND hwnd, BOOL fDoubleClick,
3920                                 int x, int y, UINT keyFlags)
3921 {
3922   Nlm_SlatE s = (Nlm_SlatE)GetProp(hwnd, (LPSTR)"Nlm_VibrantProp");
3923   Nlm_PaneL p = (Nlm_PaneL)s;
3924 
3925   Nlm_SlateTool h;
3926   Nlm_PanelData pdata;
3927   Nlm_PoinT     pt;
3928   Nlm_RecT      r;
3929 
3930   if (!fDoubleClick  &&  !Nlm_SlateHasFocus( s )  &&
3931       (Nlm_SetSlatePolicy(s, GET_VALUE) & AUTO_FOCUS))
3932     Nlm_CaptureSlateFocus( s );
3933 
3934   SetCapture( hwnd );
3935   currentSlate = s;
3936   Nlm_dblClick = (Nlm_Boolean)fDoubleClick;
3937   if (!Nlm_GetEnabled( (Nlm_GraphiC)s )  ||  !Nlm_GetVisible( (Nlm_GraphiC)s) )
3938     return;
3939 
3940   h = Nlm_GetSlateHandle( s );
3941   SetTimer(h, 2, 100, NULL);
3942   slateTimerUsed = TRUE;
3943   slateTimer = h;
3944   Nlm_GetRect((Nlm_GraphiC)s, &r);
3945   Nlm_LoadPt(&pt, (Nlm_Int2)(x + r.left), (Nlm_Int2)(y + r.top));
3946   recentlyClickedSlate = s;
3947   Nlm_SelectFont( Nlm_systemFont );
3948   Nlm_ResetDrawingTools();
3949 
3950   recentlyClickedPanel = NULL;
3951   Nlm_GetPanelData(p, &pdata);
3952 
3953   if (pdata.click   != NULL || pdata.drag != NULL || pdata.hold  != NULL ||
3954       pdata.release != NULL || pdata.draw != NULL || pdata.reset != NULL)
3955     {
3956       recentlyClickedPanel = p;
3957     }
3958   else
3959     {
3960       Nlm_PaneL n;
3961       for (p = Nlm_CreateReverseLinks( s );  p;  p = n)
3962         {
3963           Nlm_GraphiC gp = (Nlm_GraphiC)p;
3964           Nlm_Int2 hOffset, vOffset;
3965 
3966           n = Nlm_GetPanelPrev( p );
3967           Nlm_GetPanelData(p, &pdata);
3968           if ((!pdata.click  &&  !pdata.drag  &&  !pdata.hold   &&  !pdata.release) ||
3969               !Nlm_GetEnabled( gp )  ||  !Nlm_GetVisible( gp ))
3970             continue;
3971 
3972           Nlm_GetRect(gp, &r);
3973           Nlm_DoGetOffset(gp, &hOffset, &vOffset);
3974           Nlm_OffsetRect(&r, (Nlm_Int2)(-hOffset), (Nlm_Int2)(-vOffset));
3975           if ( Nlm_PtInRect(pt, &r) )
3976             {
3977               recentlyClickedPanel = p;
3978               break;
3979             }
3980         }
3981     }
3982 
3983   if ( recentlyClickedPanel )
3984     {
3985       Nlm_PnlClckProc clk = Nlm_GetPanelClick( recentlyClickedPanel );
3986       if (clk != NULL) {
3987         clk(recentlyClickedPanel, pt);
3988         Nlm_Update();
3989       }
3990     }
3991 }
3992 
3993 static void MyCls_OnLButtonUp (HWND hwnd, int x, int y, UINT keyFlags);     /* M.I */
3994 static void MyCls_OnMouseMove (HWND hwnd, int x, int y, UINT keyFlags)
3995 
3996 {
3997   Nlm_PnlClckProc  drg;
3998   Nlm_PaneL        p;
3999   Nlm_PoinT        pt;
4000   Nlm_RecT         r;
4001   Nlm_SlatE        s;
4002 
4003   SetCursor (Nlm_currentCursor);     /* M.I */
4004    if( (keyFlags & MK_LBUTTON) == 0  &&                                /* M.I */
4005        (recentlyClickedSlate != NULL || recentlyClickedPanel != NULL)) /* M.I */
4006        MyCls_OnLButtonUp( hwnd, x, y, keyFlags );                      /* M.I */
4007   s = (Nlm_SlatE) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
4008   if (currentSlate == s) {
4009     if (Nlm_GetEnabled ((Nlm_GraphiC) s) &&
4010         Nlm_GetVisible ((Nlm_GraphiC) s)) {
4011       Nlm_GetRect ((Nlm_GraphiC) s, &r);
4012       Nlm_LoadPt (&pt, (Nlm_Int2)(x + r.left), (Nlm_Int2)(y + r.top));
4013       if ((Nlm_SlatE) s == recentlyClickedSlate && recentlyClickedPanel != NULL) {
4014         p = recentlyClickedPanel;
4015         drg = Nlm_GetPanelDrag (p);
4016         if (drg != NULL) {
4017           Nlm_ResetDrawingTools ();
4018           drg (p, pt);
4019         }
4020       }
4021     }
4022   }
4023 }
4024 
4025 static void MyCls_OnLButtonUp (HWND hwnd, int x, int y, UINT keyFlags)
4026 
4027 {
4028   Nlm_SlateTool    h;
4029   Nlm_PaneL        p;
4030   Nlm_PoinT        pt;
4031   Nlm_RecT         r;
4032   Nlm_PnlClckProc  rls;
4033   Nlm_SlatE        s;
4034 
4035   s = (Nlm_SlatE) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
4036   ReleaseCapture ();
4037   h = Nlm_GetSlateHandle ((Nlm_SlatE) s);
4038   if (slateTimerUsed) {
4039     KillTimer (h, 2);
4040     slateTimer = NULL;
4041   }
4042   slateTimerUsed = FALSE;
4043   if (currentSlate == s) {
4044     if (Nlm_GetEnabled ((Nlm_GraphiC) s) &&
4045         Nlm_GetVisible ((Nlm_GraphiC) s)) {
4046       Nlm_GetRect ((Nlm_GraphiC) s, &r);
4047       Nlm_LoadPt (&pt, (Nlm_Int2)(x + r.left), (Nlm_Int2)(y + r.top));
4048       if ((Nlm_SlatE) s == recentlyClickedSlate && recentlyClickedPanel != NULL) {
4049         p = recentlyClickedPanel;
4050         rls = Nlm_GetPanelRelease (p);
4051         if (rls != NULL) {
4052           Nlm_ResetDrawingTools ();
4053           rls (p, pt);
4054         }
4055       }
4056       Nlm_SelectFont (Nlm_systemFont);
4057       Nlm_ResetDrawingTools ();
4058       recentlyClickedSlate = NULL;
4059       recentlyClickedPanel = NULL;
4060     }
4061   }
4062   currentSlate = NULL;
4063 }
4064 
4065 static void MyCls_OnTimer (HWND hwnd, UINT id)
4066 
4067 {
4068   Nlm_PaneL        p;
4069   Nlm_PnlClckProc  prs;
4070   Nlm_PoinT        pt;
4071   Nlm_SlatE        s;
4072 
4073   s = (Nlm_SlatE) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
4074   if (currentSlate == s) {
4075     if (Nlm_GetEnabled ((Nlm_GraphiC) s) && Nlm_GetVisible ((Nlm_GraphiC) s)) {
4076       Nlm_MousePosition (&pt);
4077       if ((Nlm_SlatE) s == recentlyClickedSlate && recentlyClickedPanel != NULL) {
4078         p = recentlyClickedPanel;
4079         prs = Nlm_GetPanelHold (p);
4080         if (prs != NULL) {
4081           Nlm_ResetDrawingTools ();
4082           prs (p, pt);
4083         }
4084       }
4085     }
4086   }
4087 }
4088 
4089 static void MyCls_OnPaint (HWND hwnd)
4090 
4091 {
4092   PAINTSTRUCT    ps;
4093   Nlm_PointTool  ptool;
4094   Nlm_RectTool   rtool;
4095   Nlm_SlatE      s;
4096   Nlm_PortTool   temp;
4097 
4098   s = (Nlm_SlatE) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
4099   temp = Nlm_currentHDC;
4100   GetUpdateRgn (hwnd, (Nlm_RgnTool) Nlm_updateRgn, TRUE);
4101   GetWindowRect (hwnd, &rtool);
4102   ptool = * (PPOINT) &rtool.left;
4103   ScreenToClient (Nlm_currentHWnd, &ptool);
4104   Nlm_OffsetRgn (Nlm_updateRgn, (Nlm_Int2) ptool.x, (Nlm_Int2) ptool.y);
4105   BeginPaint (hwnd, &ps);
4106   Nlm_currentHDC = Nlm_ParentWindowPort ((Nlm_GraphiC) s);
4107   SelectClipRgn (Nlm_currentHDC, (Nlm_RgnTool) Nlm_updateRgn);
4108   GetRgnBox ((Nlm_RgnTool) Nlm_updateRgn, &rtool);
4109   Nlm_RectToolToRecT (&rtool, &Nlm_updateRect);
4110   Nlm_DrawSlate (s);
4111   EndPaint (hwnd, &ps);
4112   GetWindowRect (Nlm_currentHWnd, &rtool);
4113   ptool = * (PPOINT) &rtool.left;
4114   SetRectRgn ((Nlm_RgnTool) Nlm_updateRgn, rtool.left,
4115               rtool.top, rtool.right + 1, rtool.bottom + 1);
4116   Nlm_OffsetRgn (Nlm_updateRgn, (Nlm_Int2) (-ptool.x), (Nlm_Int2) (-ptool.y));
4117   SelectClipRgn (Nlm_currentHDC, NULL);
4118   GetRgnBox ((Nlm_RgnTool) Nlm_updateRgn, &rtool);
4119   Nlm_RectToolToRecT (&rtool, &Nlm_updateRect);
4120   Nlm_currentHDC = temp;
4121 }
4122 
4123 
4124 static void MyCls_OnChar (HWND hwnd, UINT ch, int cRepeat)
4125 {
4126   Nlm_SlatE        s = (Nlm_SlatE)GetProp(hwnd, (LPSTR)"Nlm_VibrantProp");
4127   Nlm_SltCharProc  keyProc = Nlm_GetSlateCharProc (s);
4128 
4129   handlechar = FALSE;
4130   if (keyProc != NULL)
4131     keyProc(s, (Nlm_Char)ch);
4132   else if (ch == '\t'  ||  ch == '\n'  ||  ch == '\r')
4133     Nlm_DoSendFocus((Nlm_GraphiC)s, (Nlm_Char)ch);
4134   else
4135     handlechar = TRUE;
4136 }
4137 
4138 
4139 static void MyCls_OnSetFocus (HWND hwnd, HWND hwndOldFocus)
4140 {
4141   Nlm_SlatE s = (Nlm_SlatE)GetProp(hwnd, (LPSTR)"Nlm_VibrantProp");
4142   Nlm_ChangeSlateFocus(s, TRUE);
4143 }
4144 
4145 
4146 static void MyCls_OnKillFocus (HWND hwnd, HWND hwndNewFocus)
4147 {
4148   Nlm_SlatE s = (Nlm_SlatE)GetProp(hwnd, (LPSTR)"Nlm_VibrantProp");
4149   Nlm_ChangeSlateFocus(s, FALSE);
4150 }
4151 
4152 #define SQN_GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD (wparam))
4153 
4154 static LRESULT CALLBACK EXPORT SlateProc(HWND hwnd, UINT message,
4155                                   WPARAM wParam, LPARAM lParam)
4156 {
4157   Nlm_SlatE    s;
4158   LRESULT      rsult = 0;
4159   HDC          tempHDC;
4160   HWND         tempHWnd;
4161   Nlm_Boolean  clearRecent;  /* dgg */
4162   Nlm_BaR      vsb;
4163   int          zDelta;
4164 
4165   if ( Nlm_VibrantDisabled() )
4166     return DefWindowProc(hwnd, message, wParam, lParam);
4167 
4168   clearRecent = FALSE;
4169   tempHWnd = Nlm_currentHWnd;
4170   tempHDC  = Nlm_currentHDC;
4171   s = (Nlm_SlatE)GetProp(hwnd, (LPSTR)"Nlm_VibrantProp");
4172   Nlm_theWindow = Nlm_GetParentWindow ((Nlm_GraphiC) s);
4173   Nlm_currentHWnd = GetParent (hwnd);
4174   Nlm_currentHDC  = Nlm_ParentWindowPort ((Nlm_GraphiC) s);
4175   Nlm_currentWindowTool = hwnd;
4176   Nlm_currentKey = '\0';
4177   Nlm_currentWParam = wParam;
4178   Nlm_currentLParam = lParam;
4179   Nlm_cmmdKey  = FALSE;
4180   Nlm_optKey   = FALSE;
4181   Nlm_dblClick = FALSE;
4182   switch (message) {
4183     case WM_LBUTTONDBLCLK:
4184       HANDLE_WM_LBUTTONDBLCLK (hwnd, wParam, lParam, MyCls_OnLButtonDown);
4185       break;
4186     case WM_LBUTTONDOWN:
4187       HANDLE_WM_LBUTTONDOWN (hwnd, wParam, lParam, MyCls_OnLButtonDown);
4188       break;
4189     case WM_MOUSEMOVE:
4190       HANDLE_WM_MOUSEMOVE (hwnd, wParam, lParam, MyCls_OnMouseMove);
4191       break;
4192     case WM_TIMER:
4193       HANDLE_WM_TIMER (hwnd, wParam, lParam, MyCls_OnTimer);
4194       break;
4195     case WM_LBUTTONUP:
4196       HANDLE_WM_LBUTTONUP (hwnd, wParam, lParam, MyCls_OnLButtonUp);
4197 #ifdef DCLAP
4198       clearRecent = TRUE;
4199 #endif
4200       break;
4201     case WM_PAINT:
4202       HANDLE_WM_PAINT (hwnd, wParam, lParam, MyCls_OnPaint);
4203       break;
4204     case WM_KEYDOWN:
4205         if ( !Nlm_HandleSlateInput(s, Nlm_KeydownToChar( wParam )) )
4206           rsult = DefWindowProc(hwnd, message, wParam, lParam);
4207         break;
4208     case WM_MOUSEWHEEL:
4209       {
4210         zDelta = SQN_GET_WHEEL_DELTA_WPARAM(wParam);
4211         if (zDelta > 0) {
4212           vsb = Nlm_GetSlateVScrollBar( s );
4213           Nlm_Scroll(vsb, SCROLL_PAGEUP);
4214         } else if (zDelta < 0) {
4215           vsb = Nlm_GetSlateVScrollBar( s );
4216           Nlm_Scroll(vsb, SCROLL_PAGEDN);
4217         }
4218       }
4219       break;
4220     case WM_CHAR:
4221       handlechar = FALSE;
4222       HANDLE_WM_CHAR(hwnd, wParam, lParam, MyCls_OnChar);
4223       if ( handlechar )
4224         rsult = DefWindowProc (hwnd, message, wParam, lParam);
4225       break;
4226     case WM_SETFOCUS:
4227       HANDLE_WM_SETFOCUS (hwnd, wParam, lParam, MyCls_OnSetFocus);
4228       rsult = DefWindowProc (hwnd, message, wParam, lParam);
4229       break;
4230     case WM_KILLFOCUS:
4231       HANDLE_WM_KILLFOCUS (hwnd, wParam, lParam, MyCls_OnKillFocus);
4232       rsult = DefWindowProc (hwnd, message, wParam, lParam);
4233       break;
4234     default:
4235       rsult = DefWindowProc (hwnd, message, wParam, lParam);
4236 #ifdef DCLAP
4237       clearRecent = TRUE;
4238 #endif
4239       break;
4240   }
4241 
4242 /* jk modification of dgg addition -- clear problems w/ drag message appearing after mouseup */
4243   if (clearRecent) {
4244     recentlyClickedSlate = NULL;
4245     recentlyClickedPanel = NULL;
4246   }
4247 
4248   Nlm_currentHWnd = tempHWnd;
4249   Nlm_currentHDC = tempHDC;
4250   Nlm_currentWindowTool = tempHWnd;
4251   return rsult;
4252 }
4253 
4254 
4255 extern BOOLEAN Nlm_hasBackColor;
4256 extern COLORREF Nlm_crBackColor;
4257 extern HBRUSH Nlm_hbrWindowBackground;
4258 
4259 
4260 extern Nlm_Boolean Nlm_RegisterSlates (void)
4261 
4262 {
4263   Nlm_Boolean  rsult;
4264   WNDCLASS     wc;
4265 
4266   rsult = FALSE;
4267   wc.style = CS_PARENTDC | CS_DBLCLKS;
4268   wc.lpfnWndProc = SlateProc;
4269   wc.cbClsExtra = 0;
4270   wc.cbWndExtra = 0;
4271   wc.hInstance = Nlm_currentHInst;
4272   wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
4273 /*wc.hCursor = LoadCursor (NULL, IDC_ARROW);      M.I */
4274   wc.hCursor = NULL;                           /* M.I */
4275   wc.hbrBackground = Nlm_hasBackColor ?
4276                            CreateSolidBrush( Nlm_crBackColor ) :
4277                            CreateSolidBrush( GetSysColor(COLOR_WINDOW));
4278   wc.lpszMenuName = NULL;
4279   sprintf (slateclass, "Nlm_SlateClass%ld", (long) (int) Nlm_currentHInst);
4280   wc.lpszClassName = slateclass;
4281   rsult = (Nlm_Boolean) RegisterClass (&wc);
4282   return rsult;
4283 }
4284 #endif
4285 
4286 #ifdef WIN_MOTIF
4287 extern Nlm_Boolean Nlm_RegisterSlates (void)
4288 {
4289   XtActionsRec actions;
4290 
4291   actions.string = "slate";
4292   actions.proc = Nlm_SlateClickCallback;
4293   XtAppAddActions(Nlm_appContext, &actions, 1);
4294 
4295   return TRUE;
4296 }
4297 #endif
4298 
4299 extern void Nlm_KillSlateTimer (void)
4300 
4301 {
4302   recentlyClickedSlate = NULL;
4303   recentlyClickedPanel = NULL;
4304 #ifdef WIN_MAC
4305 #endif
4306 #ifdef WIN_MSWIN
4307   if (slateTimerUsed) {
4308     KillTimer (slateTimer, 2);
4309     slateTimer = NULL;
4310   }
4311   slateTimerUsed = FALSE;
4312 #endif
4313 #ifdef WIN_MOTIF
4314   if (slateTimerUsed) {
4315     XtRemoveTimeOut (slateTimer);
4316     slateTimer = 0;
4317   }
4318   slateTimerUsed = FALSE;
4319 #endif
4320 }
4321 
4322 
4323 extern Nlm_Int4 Nlm_SetSlatePolicy(Nlm_SlatE s, Nlm_Int4 flag)
4324 {
4325   Nlm_SlateData data;
4326   Nlm_Int4 prev_policy;
4327 
4328   Nlm_GetSlateData(s, &data);
4329 
4330   if (flag == GET_VALUE)
4331     return data.policy;
4332 
4333   prev_policy = data.policy;
4334   data.policy = flag;
4335 
4336   if ( !data.vScrollBar )
4337     data.policy &= ~(VERT_ARROW | VERT_PAGE);
4338 
4339   if ( !data.hScrollBar )
4340     data.policy &= ~(HORIZ_ARROW | HORIZ_PAGE);
4341 
4342 #ifdef WIN_MOTIF
4343   XtVaSetValues(Nlm_GetSlateHandle( s ),
4344                 XmNsensitive, (Boolean)(flag & AUTO_FOCUS), NULL);
4345 #endif
4346 
4347   Nlm_SetSlateData(s, &data);
4348   return prev_policy;
4349 }
4350 
4351 
4352 extern void Nlm_FreeSlate (void)
4353 {
4354   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemFree (gphprcsptr);
4355 }
4356 
4357 extern void Nlm_InitSlate (void)
4358 
4359 {
4360   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemNew (sizeof (Nlm_GphPrcs) * 3);
4361 
4362   slateProcs = &(gphprcsptr [0]);
4363 #ifdef WIN_MAC
4364   slateProcs->click = Nlm_SlateClick;
4365   slateProcs->key = Nlm_SlateKey;
4366   slateProcs->draw = Nlm_DrawSlate;
4367 #endif
4368 #ifdef WIN_MSWIN
4369   slateProcs->command = Nlm_SlateCommand;
4370 #endif
4371 #ifdef WIN_MOTIF
4372   slateProcs->callback = Nlm_SlateCallback;
4373 #endif
4374   slateProcs->show = Nlm_ShowSlate;
4375   slateProcs->hide = Nlm_HideSlate;
4376   slateProcs->enable = Nlm_EnableSlate;
4377   slateProcs->disable = Nlm_DisableSlate;
4378   slateProcs->remove = Nlm_RemoveSlate;
4379   slateProcs->reset = Nlm_ResetSlate;
4380   slateProcs->select = Nlm_SelectSlate;
4381   slateProcs->countItems = Nlm_CountGroupItems;
4382   slateProcs->linkIn = Nlm_LinkIn;
4383   slateProcs->adjustPrnt = Nlm_AdjustSlate;
4384   slateProcs->setOffset = Nlm_SetSlateOffset;
4385   slateProcs->getOffset = Nlm_GetSlateOffset;
4386   slateProcs->setPosition = Nlm_SetSlatePosition;
4387   slateProcs->getPosition = Nlm_GetSlatePosition;
4388   slateProcs->setRange = Nlm_SetSlateRange;
4389   slateProcs->gainFocus = Nlm_SlateGainFocus;
4390   slateProcs->loseFocus = Nlm_SlateLoseFocus;
4391 
4392   panelProcs = &(gphprcsptr [1]);
4393   panelProcs->show = Nlm_ShowPanel;
4394   panelProcs->hide = Nlm_HidePanel;
4395   panelProcs->enable = Nlm_EnablePanel;
4396   panelProcs->disable = Nlm_DisablePanel;
4397   panelProcs->remove = Nlm_RemovePanel;
4398   panelProcs->reset = Nlm_ResetPanel;
4399   panelProcs->select = Nlm_SelectPanel;
4400   panelProcs->getOffset = Nlm_GetPanelOffset;
4401   panelProcs->setPosition = Nlm_SetPanelPosition;
4402   panelProcs->getPosition = Nlm_GetPanelPosition;
4403   panelProcs->gainFocus = Nlm_SlateGainFocus;
4404   panelProcs->loseFocus = Nlm_SlateLoseFocus;
4405 
4406   displayProcs = &(gphprcsptr [2]);
4407   displayProcs->select = Nlm_SelectDisplay;
4408   displayProcs->sendChar = Nlm_PaintOrFormatChar;
4409 }
4410 
4411 
4412