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

  1. /*   vibextra.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:  vibextra.c
  27. *
  28. * Author:  Jonathan Kans
  29. *
  30. * Version Creation Date:   3/9/93
  31. *
  32. * $Revision: 1.15 $
  33. *
  34. * File Description: 
  35. *       Vibrant miscellaneous extensions
  36. *
  37. * Modifications:  
  38. * --------------------------------------------------------------------------
  39. * Date     Name        Description of modification
  40. * -------  ----------  -----------------------------------------------------
  41. *
  42. *
  43. * ==========================================================================
  44. */
  45.  
  46. #include <vibtypes.h>
  47. #include <vibprocs.h>
  48. #include <vibincld.h>
  49. #include <ncbiport.h>
  50.  
  51. #ifdef VAR_ARGS
  52. #include <varargs.h>
  53. #else
  54. #include <stdarg.h>
  55. #endif
  56.  
  57. typedef  struct  Nlm_repeatdata {
  58.   Nlm_Handle       title;
  59.   Nlm_RptClckProc  action;
  60. } Nlm_RepeatData;
  61.  
  62. typedef struct Nlm_switchdata {
  63.   Nlm_Int2         max;
  64.   Nlm_Int2         val;
  65.   Nlm_Boolean      text;
  66.   Nlm_Boolean      vert;
  67.   Nlm_Boolean      upActv;
  68.   Nlm_Boolean      dnActv;
  69.   Nlm_SwtChngProc  actn;
  70. } Nlm_SwitchData;
  71.  
  72. typedef  struct  Nlm_icondata {
  73.   Nlm_IcnChngProc  inval;
  74.   Nlm_Int2         value;
  75.   Nlm_Boolean      status;
  76.   Nlm_Handle       title;
  77. } Nlm_IconData;
  78.  
  79. static Nlm_GphPrcsPtr  gphprcsptr = NULL;
  80.  
  81. static Nlm_GphPrcsPtr  repeatProcs;
  82. static Nlm_GphPrcsPtr  switchProcs;
  83. static Nlm_GphPrcsPtr  iconProcs;
  84.  
  85. static Nlm_Boolean     inRepeatButton;
  86.  
  87. static Nlm_Uint1 upFillArrow [] = {
  88.   0x10, 0x38, 0x38, 0x7C, 0x7C, 0xFE, 0xFE, 0x00
  89. };
  90.  
  91. static Nlm_Uint1 downFillArrow [] = {
  92.   0xFE, 0xFE, 0x7C, 0x7C, 0x38, 0x38, 0x10, 0x00
  93. };
  94.  
  95. static Nlm_Uint1 leftFillArrow [] = {
  96.   0x06, 0x1E, 0x7E, 0xFE, 0x7E, 0x1E, 0x06, 0x00
  97. };
  98.  
  99. static Nlm_Uint1 rightFillArrow [] = {
  100.   0xC0, 0xF0, 0xFC, 0xFE, 0xFC, 0xF0, 0xC0, 0x00
  101. };
  102.  
  103. static Nlm_Uint1 upOpenArrow [] = {
  104.   0x10, 0x28, 0x28, 0x44, 0x44, 0x82, 0xFE, 0x00
  105. };
  106.  
  107. static Nlm_Uint1 downOpenArrow [] = {
  108.   0xFE, 0x82, 0x44, 0x44, 0x28, 0x28, 0x10, 0x00
  109. };
  110.  
  111. static Nlm_Uint1 leftOpenArrow [] = {
  112.   0x06, 0x1A, 0x62, 0x82, 0x62, 0x1A, 0x06, 0x00
  113. };
  114.  
  115. static Nlm_Uint1 rightOpenArrow [] = {
  116.   0xC0, 0xB0, 0x8C, 0x82, 0x8C, 0xB0, 0xC0, 0x00
  117. };
  118.  
  119. #ifdef VAR_ARGS
  120. extern void CDECL Nlm_AlignObjects (align, va_alist)
  121. int align;
  122. va_dcl
  123. #else
  124. extern void CDECL Nlm_AlignObjects (int align, ...)
  125. #endif
  126.  
  127. {
  128.   va_list     args;
  129.   Nlm_Int2    delta;
  130.   Nlm_Int2    maxX;
  131.   Nlm_Int2    maxY;
  132.   Nlm_Int2    minX;
  133.   Nlm_Int2    minY;
  134.   Nlm_Handle  obj;
  135.   Nlm_RecT    r;
  136.  
  137. #ifdef VAR_ARGS
  138.   va_start (args);
  139. #else
  140.   va_start (args, align);
  141. #endif
  142.   minX = 0;
  143.   minY = 0;
  144.   maxX = 0;
  145.   maxY = 0;
  146.   obj = (Nlm_Handle) va_arg (args, Nlm_HANDLE);
  147.   while (obj != NULL) {
  148.     Nlm_GetPosition (obj, &r);
  149.     minX = MAX (minX, r.left);
  150.     minY = MAX (minY, r.top);
  151.     maxX = MAX (maxX, r.right);
  152.     maxY = MAX (maxY, r.bottom);
  153.     obj = (Nlm_Handle) va_arg (args, Nlm_HANDLE);
  154.   }
  155.   va_end(args);
  156.  
  157. #ifdef VAR_ARGS
  158.   va_start (args);
  159. #else
  160.   va_start (args, align);
  161. #endif
  162.   obj = (Nlm_Handle) va_arg (args, Nlm_HANDLE);
  163.   while (obj != NULL) {
  164.     Nlm_GetPosition (obj, &r);
  165.     switch (align) {
  166.       case ALIGN_LEFT:
  167.         if (r.left < minX) {
  168.           r.left = minX;
  169.           Nlm_SetPosition (obj, &r);
  170.           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
  171.         }
  172.         break;
  173.       case ALIGN_RIGHT:
  174.         if (r.right < maxX) {
  175.           r.right = maxX;
  176.           Nlm_SetPosition (obj, &r);
  177.           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
  178.         }
  179.         break;
  180.       case ALIGN_CENTER:
  181.         delta = maxX - r.right;
  182.         if (delta > 0) {
  183.           Nlm_OffsetRect (&r, delta/2, 0);
  184.           Nlm_SetPosition (obj, &r);
  185.           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
  186.         }
  187.         break;
  188.       case ALIGN_JUSTIFY:
  189.         if (r.left < minX || r.right < maxX) {
  190.           r.left = minX;
  191.           r.right = maxX;
  192.           Nlm_SetPosition (obj, &r);
  193.           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
  194.         }
  195.         break;
  196.       case ALIGN_UPPER:
  197.         if (r.top < minY) {
  198.           r.top = minY;
  199.           Nlm_SetPosition (obj, &r);
  200.           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
  201.         }
  202.         break;
  203.       case ALIGN_LOWER:
  204.         if (r.bottom < maxY) {
  205.           r.bottom = maxY;
  206.           Nlm_SetPosition (obj, &r);
  207.           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
  208.         }
  209.         break;
  210.       case ALIGN_MIDDLE:
  211.         delta = maxY - r.bottom;
  212.         if (delta > 0) {
  213.           Nlm_OffsetRect (&r, 0, delta/2);
  214.           Nlm_SetPosition (obj, &r);
  215.           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
  216.         }
  217.         break;
  218.       case ALIGN_VERTICAL:
  219.         if (r.top < minY || r.bottom < maxY) {
  220.           r.top = minY;
  221.           r.bottom = maxY;
  222.           Nlm_SetPosition (obj, &r);
  223.           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
  224.         }
  225.         break;
  226.       default:
  227.         break;
  228.     }
  229.     obj = (Nlm_Handle) va_arg (args, Nlm_HANDLE);
  230.   }
  231.   va_end(args);
  232. }
  233.  
  234. static void Nlm_DrawSwitchProc (Nlm_PaneL s)
  235.  
  236. {
  237.   Nlm_RecT        dn;
  238.   Nlm_SwitchData  extra;
  239.   Nlm_Int2        mid;
  240.   Nlm_RecT        r;
  241.   Nlm_Char        str [32];
  242.   Nlm_RecT        tx;
  243.   Nlm_RecT        up;
  244.  
  245.   Nlm_GetPanelExtra (s, &extra);
  246.   Nlm_ObjectRect (s, &r);
  247.   if (extra.text && extra.max > 0 && extra.val > 0) {
  248.     sprintf (str, "%d/%d", (int) extra.val, (int) extra.max);
  249.     Nlm_SelectFont (Nlm_programFont);
  250.     if (extra.vert) {
  251.       Nlm_LoadRect (&tx, r.left + 1, r.top + 1, r.right - 11, r.bottom - 1);
  252.     } else {
  253.       Nlm_LoadRect (&tx, r.left + 1, r.top + 1, r.right - 20, r.bottom - 1);
  254.     }
  255.     Nlm_DrawString (&tx, str, 'r', FALSE);
  256.     Nlm_SelectFont (Nlm_systemFont);
  257.   }
  258.   Nlm_FrameRect (&r);
  259.   if (extra.vert) {
  260.     Nlm_LoadRect (&up, r.right - 9, r.top + 2, r.right - 2, r.top + 9);
  261.     if (extra.upActv) {
  262.       Nlm_CopyBits (&up, upFillArrow);
  263.     } else {
  264.       Nlm_CopyBits (&up, upOpenArrow);
  265.     }
  266.   } else {
  267.     mid = (r.top + r.bottom) / 2;
  268.     Nlm_LoadRect (&up, r.right - 9, mid - 3, r.right - 2, mid + 4);
  269.     if (extra.upActv) {
  270.       Nlm_CopyBits (&up, rightFillArrow);
  271.     } else {
  272.       Nlm_CopyBits (&up, rightOpenArrow);
  273.     }
  274.   }
  275.   if (extra.vert) {
  276.     Nlm_LoadRect (&dn, r.right - 9, r.bottom - 9, r.right - 2, r.bottom - 2);
  277.     if (extra.dnActv) {
  278.       Nlm_CopyBits (&dn, downFillArrow);
  279.     } else {
  280.       Nlm_CopyBits (&dn, downOpenArrow);
  281.     }
  282.   } else {
  283.     mid = (r.top + r.bottom) / 2;
  284.     Nlm_LoadRect (&dn, r.right - 18, mid - 3, r.right - 11, mid + 4);
  285.     if (extra.dnActv) {
  286.       Nlm_CopyBits (&dn, leftFillArrow);
  287.     } else {
  288.       Nlm_CopyBits (&dn, leftOpenArrow);
  289.     }
  290.   }
  291. }
  292.  
  293. static void Nlm_SwitchClickProc (Nlm_PaneL s, Nlm_PoinT pt)
  294.  
  295. {
  296.   Nlm_RecT        dn;
  297.   Nlm_SwitchData  extra;
  298.   Nlm_Int2        mid;
  299.   Nlm_RecT        r;
  300.   Nlm_RecT        up;
  301.  
  302.   Nlm_GetPanelExtra (s, &extra);
  303.   Nlm_ObjectRect (s, &r);
  304.   if (extra.vert) {
  305.     Nlm_LoadRect (&up, r.right - 9, r.top + 2, r.right - 2, r.top + 9);
  306.     Nlm_LoadRect (&dn, r.right - 9, r.bottom - 9, r.right - 2, r.bottom - 2);
  307.   } else {
  308.     mid = (r.top + r.bottom) / 2;
  309.     Nlm_LoadRect (&up, r.right - 9, mid - 3, r.right - 2, mid + 4);
  310.     Nlm_LoadRect (&dn, r.right - 18, mid - 3, r.right - 11, mid + 4);
  311.   }
  312.   if (Nlm_PtInRect (pt, &up)) {
  313.     if (extra.val < extra.max) {
  314.       Nlm_DoSetValue ((Nlm_GraphiC) s, extra.val + 1, FALSE);
  315.       if (extra.actn != NULL) {
  316.         extra.actn ((Nlm_SwitcH) s, extra.val + 1, extra.val);
  317.       }
  318.     }
  319.   } else if (Nlm_PtInRect (pt, &dn)) {
  320.     if (extra.val > 1) {
  321.       Nlm_DoSetValue ((Nlm_GraphiC) s, extra.val - 1, FALSE);
  322.       if (extra.actn != NULL) {
  323.         extra.actn ((Nlm_SwitcH) s, extra.val - 1, extra.val);
  324.       }
  325.     }
  326.   }
  327. }
  328.  
  329.  
  330.  
  331. static Nlm_SwitcH Nlm_CommonSwitch (Nlm_GrouP prnt, Nlm_Boolean text,
  332.                                     Nlm_Boolean vert, Nlm_SwtChngProc actn)
  333.  
  334. {
  335.   Nlm_SwitchData  extra;
  336.   Nlm_Int2        height;
  337.   Nlm_PaneL       s;
  338.   Nlm_Int2        width;
  339.  
  340.   s = NULL;
  341.   if (prnt != NULL) {
  342.     Nlm_SelectFont (Nlm_programFont);
  343.     if (vert) {
  344.       height = 20;
  345.       width = 11;
  346.     } else {
  347.       height = 11;
  348.       width = 20;
  349.     }
  350.     if (text) {
  351. #ifdef DCLAP
  352.       width += Nlm_StringWidth ("99/999") + 4;
  353. #else
  354.       width += Nlm_StringWidth ("99/99") + 4;
  355. #endif
  356.       height = MAX (height, Nlm_LineHeight () + 2);
  357.     }
  358.     Nlm_SelectFont (Nlm_systemFont);
  359.     s = Nlm_AutonomousPanel (prnt, width, height, Nlm_DrawSwitchProc, NULL,
  360.                              NULL, sizeof (Nlm_SwitchData), NULL, switchProcs);
  361.     if (s != NULL) {
  362.       Nlm_SetPanelClick (s, Nlm_SwitchClickProc, NULL, NULL, NULL);
  363.       Nlm_MemSet ((Nlm_VoidPtr) (&extra), 0, sizeof (Nlm_SwitchData));
  364.       extra.max = 0;
  365.       extra.val = 0;
  366.       extra.text = text;
  367.       extra.vert = vert;
  368.       extra.upActv = FALSE;
  369.       extra.dnActv = FALSE;
  370.       extra.actn = actn;
  371.       Nlm_SetPanelExtra (s, &extra);
  372.     }
  373.   }
  374.   return (Nlm_SwitcH) s;
  375. }
  376.  
  377. extern Nlm_SwitcH Nlm_UpDownSwitch (Nlm_GrouP prnt, Nlm_Boolean text, Nlm_SwtChngProc actn)
  378.  
  379. {
  380.   return Nlm_CommonSwitch (prnt, text, TRUE, actn);
  381. }
  382.  
  383. extern Nlm_SwitcH Nlm_LeftRightSwitch (Nlm_GrouP prnt, Nlm_Boolean text, Nlm_SwtChngProc actn)
  384.  
  385. {
  386.   return Nlm_CommonSwitch (prnt, text, FALSE, actn);
  387. }
  388.  
  389. static void Nlm_UpdateSwitch (Nlm_SwitcH s)
  390.  
  391. {
  392.   Nlm_RecT        dn;
  393.   Nlm_SwitchData  extra;
  394.   Nlm_Int2        mid;
  395.   Nlm_RecT        r;
  396.   Nlm_RecT        tx;
  397.   Nlm_RecT        up;
  398.  
  399.   Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
  400.   if (Nlm_Visible (s) && Nlm_AllParentsVisible (s)) {
  401.     Nlm_ObjectRect (s, &r);
  402.     if (extra.vert) {
  403.       Nlm_LoadRect (&up, r.right - 9, r.top + 2, r.right - 2, r.top + 9);
  404.       Nlm_LoadRect (&dn, r.right - 9, r.bottom - 9, r.right - 2, r.bottom - 2);
  405.     } else {
  406.       mid = (r.top + r.bottom) / 2;
  407.       Nlm_LoadRect (&up, r.right - 9, mid - 3, r.right - 2, mid + 4);
  408.       Nlm_LoadRect (&dn, r.right - 18, mid - 3, r.right - 11, mid + 4);
  409.     }
  410.     Nlm_Select (s);
  411.     if (extra.upActv != (Nlm_Boolean) (extra.val < extra.max)) {
  412.       Nlm_InsetRect (&up, -1, -1);
  413.       Nlm_InvalRect (&up);
  414.     }
  415.     if (extra.dnActv != (Nlm_Boolean) (extra.val > 1)) {
  416.       Nlm_InsetRect (&dn, -1, -1);
  417.       Nlm_InvalRect (&dn);
  418.     }
  419.     if (extra.text) {
  420.       if (extra.vert) {
  421.         Nlm_LoadRect (&tx, r.left + 1, r.top + 1, r.right - 10, r.bottom - 1);
  422.       } else {
  423.         Nlm_LoadRect (&tx, r.left + 1, r.top + 1, r.right - 19, r.bottom - 1);
  424.       }
  425.       Nlm_InvalRect (&tx);
  426.     }
  427.   }
  428.   extra.upActv = (Nlm_Boolean) (extra.val < extra.max);
  429.   extra.dnActv = (Nlm_Boolean) (extra.val > 1);
  430.   Nlm_SetPanelExtra ((Nlm_PaneL) s, &extra);
  431. }
  432.  
  433. static void Nlm_SetSwitchValue (Nlm_GraphiC s, Nlm_Int2 value, Nlm_Boolean savePort)
  434.  
  435. {
  436.   Nlm_SwitchData  extra;
  437.   Nlm_Int2        oldval;
  438.   Nlm_WindoW      tempPort;
  439.  
  440.   tempPort = Nlm_SavePortIfNeeded (s, savePort);
  441.   if (s != NULL) {
  442.     Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
  443.     oldval = extra.val;
  444.     extra.val = value;
  445.     Nlm_SetPanelExtra ((Nlm_PaneL) s, &extra);
  446.     if (oldval != value) {
  447.       Nlm_UpdateSwitch ((Nlm_SwitcH) s);
  448.     }
  449.   }
  450.   Nlm_RestorePort (tempPort);
  451. }
  452.  
  453. static Nlm_Int2 Nlm_GetSwitchValue (Nlm_GraphiC s)
  454.  
  455. {
  456.   Nlm_SwitchData  extra;
  457.   Nlm_Int2        value;
  458.  
  459.   value = 0;
  460.   if (s != NULL) {
  461.     Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
  462.     value = extra.val;
  463.   }
  464.   return value;
  465. }
  466.  
  467. extern void Nlm_SetSwitchMax (Nlm_SwitcH s, Nlm_Int2 max)
  468.  
  469. {
  470.   Nlm_SwitchData  extra;
  471.   Nlm_Int2        oldmax;
  472.   Nlm_WindoW      tempPort;
  473.  
  474.   tempPort = Nlm_SavePort (s);
  475.   if (s != NULL) {
  476.     Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
  477.     oldmax = extra.max;
  478.     extra.max = max;
  479.     if (max == 0) {
  480.       extra.val = 0;
  481.     }
  482.     Nlm_SetPanelExtra ((Nlm_PaneL) s, &extra);
  483.     if (oldmax != max) {
  484.       Nlm_UpdateSwitch (s);
  485.     }
  486.   }
  487.   Nlm_RestorePort (tempPort);
  488. }
  489.  
  490. extern Nlm_Int2 Nlm_GetSwitchMax (Nlm_SwitcH s)
  491.  
  492. {
  493.   Nlm_SwitchData  extra;
  494.   Nlm_Int2        max;
  495.  
  496.   max = 0;
  497.   if (s != NULL) {
  498.     Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
  499.     max = extra.max;
  500.   }
  501.   return max;
  502. }
  503.  
  504. extern void Nlm_SetSwitchParams (Nlm_SwitcH s, Nlm_Int2 value, Nlm_Int2 max)
  505.  
  506. {
  507.   Nlm_SwitchData  extra;
  508.   Nlm_Int2        oldmax;
  509.   Nlm_Int2        oldval;
  510.   Nlm_WindoW      tempPort;
  511.  
  512.   tempPort = Nlm_SavePort (s);
  513.   if (s != NULL) {
  514.     Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
  515.     oldmax = extra.max;
  516.     extra.max = max;
  517.     if (value > max) {
  518.       value = max;
  519.     }
  520.     oldval = extra.val;
  521.     extra.val = value;
  522.     Nlm_SetPanelExtra ((Nlm_PaneL) s, &extra);
  523.     if (oldval != value || oldmax != max) {
  524.       Nlm_UpdateSwitch (s);
  525.     }
  526.   }
  527.   Nlm_RestorePort (tempPort);
  528. }
  529.  
  530. static void Nlm_DoRepeatAction (Nlm_RepeaT rb, Nlm_PoinT pt)
  531.  
  532. {
  533.   Nlm_RptClckProc  actn;
  534.   Nlm_RepeatData   rdata;
  535.  
  536.   Nlm_GetPanelExtra ((Nlm_PaneL) rb, &rdata);
  537.   actn = rdata.action;
  538.   if (actn != NULL) {
  539.     actn (rb, pt);
  540.   }
  541. }
  542.  
  543. static void Nlm_RepeatClick (Nlm_PaneL rb, Nlm_PoinT pt)
  544.  
  545. {
  546.   Nlm_RecT  r;
  547.  
  548.   Nlm_GetRect ((Nlm_GraphiC) rb, &r);
  549.   if (Nlm_PtInRect (pt, &r)) {
  550.     inRepeatButton = TRUE;
  551.     Nlm_InsetRect (&r, 2, 2);
  552.     Nlm_InvertRect (&r);
  553.     Nlm_DoRepeatAction ((Nlm_RepeaT) rb, pt);
  554.   }
  555. }
  556.  
  557. static void Nlm_RepeatPress (Nlm_PaneL rb, Nlm_PoinT pt)
  558.  
  559. {
  560.   Nlm_RecT  r;
  561.  
  562.   Nlm_GetRect ((Nlm_GraphiC) rb, &r);
  563.   if (Nlm_PtInRect (pt, &r)) {
  564.     if (! inRepeatButton) {
  565.       inRepeatButton = TRUE;
  566.       Nlm_InsetRect (&r, 2, 2);
  567.       Nlm_InvertRect (&r);
  568.     }
  569.     Nlm_DoRepeatAction ((Nlm_RepeaT) rb, pt);
  570.   } else if (inRepeatButton) {
  571.     inRepeatButton = FALSE;
  572.     Nlm_InsetRect (&r, 2, 2);
  573.     Nlm_InvertRect (&r);
  574.   }
  575. }
  576.  
  577. static void Nlm_RepeatRelease (Nlm_PaneL rb, Nlm_PoinT pt)
  578.  
  579. {
  580.   Nlm_RecT  r;
  581.  
  582.   Nlm_GetRect ((Nlm_GraphiC) rb, &r);
  583.   if (inRepeatButton) {
  584.     inRepeatButton = FALSE;
  585.     Nlm_InsetRect (&r, 2, 2);
  586.     Nlm_InvertRect (&r);
  587.   }
  588. }
  589.  
  590. static void Nlm_DrawRepeat (Nlm_PaneL rb)
  591.  
  592. {
  593.   Nlm_Handle      h;
  594.   Nlm_RecT        r;
  595.   Nlm_RepeatData  rdata;
  596.   Nlm_Char        str [64];
  597.  
  598.   if (Nlm_GetVisible ((Nlm_GraphiC) rb) && Nlm_GetAllParentsVisible ((Nlm_GraphiC) rb)) {
  599.     Nlm_GetRect ((Nlm_GraphiC) rb, &r);
  600.     Nlm_FrameRect (&r);
  601.     Nlm_InsetRect (&r, 1, 1);
  602.     Nlm_FrameRect (&r);
  603.     Nlm_InsetRect (&r, 1, 1);
  604.     Nlm_GetPanelExtra (rb, &rdata);
  605.     h = rdata.title;
  606.     if (h != NULL) {
  607.       Nlm_SelectFont (Nlm_systemFont);
  608.       Nlm_GetString (h, str, sizeof (str));
  609.       if (Nlm_StringLen (str) > 0) {
  610.         Nlm_DrawString (&r, str, 'c', FALSE);
  611.       }
  612.     }
  613.   }
  614. }
  615.  
  616. static void Nlm_SetRepeatTitle (Nlm_GraphiC rb, Nlm_Int2 item,
  617.                                 Nlm_CharPtr title, Nlm_Boolean savePort)
  618.  
  619. {
  620.   Nlm_Handle      h;
  621.   Nlm_RecT        r;
  622.   Nlm_RepeatData  rdata;
  623.   Nlm_WindoW      tempPort;
  624.  
  625.   tempPort = Nlm_SavePortIfNeeded (rb, savePort);
  626.   Nlm_GetPanelExtra ((Nlm_PaneL) rb, &rdata);
  627.   h = rdata.title;
  628.   h = Nlm_SetString (h, title);
  629.   rdata.title = h;
  630.   Nlm_SetPanelExtra ((Nlm_PaneL) rb, &rdata);
  631.   if (Nlm_GetVisible (rb) && Nlm_GetAllParentsVisible (rb)) {
  632.     Nlm_GetRect (rb, &r);
  633.     Nlm_InvalRect (&r);
  634.   }
  635.   Nlm_RestorePort (tempPort);
  636. }
  637.  
  638. static void Nlm_GetRepeatTitle (Nlm_GraphiC rb, Nlm_Int2 item,
  639.                                 Nlm_CharPtr title, Nlm_sizeT maxsize)
  640.  
  641. {
  642.   Nlm_Handle      h;
  643.   Nlm_RepeatData  rdata;
  644.  
  645.   if (title != NULL) {
  646.     Nlm_GetPanelExtra ((Nlm_PaneL) rb, &rdata);
  647.     h = rdata.title;
  648.     Nlm_GetString (h, title, maxsize);
  649.   }
  650. }
  651.  
  652. static void Nlm_ResetRepeat (Nlm_PaneL rb)
  653.  
  654. {
  655.   Nlm_RepeatData  rdata;
  656.  
  657.   Nlm_GetPanelExtra (rb, &rdata);
  658.   if (rdata.title != NULL) {
  659.     rdata.title = Nlm_HandFree (rdata.title);
  660.   }
  661.   Nlm_SetPanelExtra (rb, &rdata);
  662. }
  663.  
  664. extern Nlm_RepeaT Nlm_RepeatButton (Nlm_GrouP prnt, Nlm_CharPtr title,
  665.                                     Nlm_RptClckProc actn)
  666.  
  667. {
  668.   Nlm_RepeaT      rb;
  669.   Nlm_RepeatData  rdata;
  670.   Nlm_Int2        vbounds;
  671.   Nlm_Int2        width;
  672.  
  673.   rb = NULL;
  674.   if (prnt != NULL) {
  675.     Nlm_SelectFont (Nlm_systemFont);
  676.     width = Nlm_StringWidth (title);
  677. #ifdef WIN_MAC
  678.     vbounds = 2;
  679. #endif
  680. #ifdef WIN_MSWIN
  681.     vbounds = 4;
  682. #endif
  683. #ifdef WIN_MOTIF
  684.     vbounds = 2;
  685. #endif
  686.     rb = (Nlm_RepeaT) Nlm_AutonomousPanel (prnt, width+8, Nlm_stdLineHeight+vbounds*2,
  687.                                            Nlm_DrawRepeat, NULL, NULL,
  688.                                            sizeof (Nlm_RepeatData), Nlm_ResetRepeat,
  689.                                            repeatProcs);
  690.     if (rb != NULL) {
  691.       Nlm_SetPanelClick ((Nlm_PaneL) rb, Nlm_RepeatClick, NULL,
  692.                          Nlm_RepeatPress, Nlm_RepeatRelease);
  693.       rdata.title = NULL;
  694.       rdata.action = actn;
  695.       Nlm_SetPanelExtra ((Nlm_PaneL) rb, &rdata);
  696.       Nlm_SetRepeatTitle ((Nlm_GraphiC) rb, 0, title, FALSE);
  697.     }
  698.   }
  699.   return rb;
  700. }
  701.  
  702. static void Nlm_SetIconValue (Nlm_GraphiC i, Nlm_Int2 value, Nlm_Boolean savePort)
  703.  
  704. {
  705.   Nlm_IconData  extra;
  706.   Nlm_Int2      oldval;
  707.   Nlm_RecT      r;
  708.   Nlm_WindoW    tempPort;
  709.  
  710.   tempPort = Nlm_SavePortIfNeeded (i, savePort);
  711.   if (i != NULL) {
  712.     Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
  713.     oldval = extra.value;
  714.     extra.value = value;
  715.     Nlm_SetPanelExtra ((Nlm_PaneL) i, &extra);
  716.     if (oldval != value) {
  717.       if (Nlm_Visible (i) && Nlm_AllParentsVisible (i)) {
  718.         Nlm_Select (i);
  719.         if (extra.inval != NULL) {
  720.           extra.inval ((Nlm_IcoN) i, value, oldval);
  721.         } else {
  722.           Nlm_ObjectRect (i, &r);
  723.           Nlm_InsetRect (&r, -1, -1);
  724.           Nlm_InvalRect (&r);
  725.         }
  726.       }
  727.     }
  728.   }
  729.   Nlm_RestorePort (tempPort);
  730. }
  731.  
  732. static Nlm_Int2 Nlm_GetIconValue (Nlm_GraphiC i)
  733.  
  734. {
  735.   Nlm_IconData  extra;
  736.   Nlm_Int2      value;
  737.  
  738.   value = 0;
  739.   if (i != NULL) {
  740.     Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
  741.     value = extra.value;
  742.   }
  743.   return value;
  744. }
  745.  
  746. static void Nlm_SetIconStatus (Nlm_GraphiC i, Nlm_Int2 item,
  747.                                Nlm_Boolean set, Nlm_Boolean savePort)
  748.  
  749. {
  750.   Nlm_IconData  extra;
  751.   Nlm_Boolean   oldstat;
  752.   Nlm_RecT      r;
  753.   Nlm_WindoW    tempPort;
  754.  
  755.   tempPort = Nlm_SavePortIfNeeded (i, savePort);
  756.   if (i != NULL) {
  757.     Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
  758.     oldstat = extra.status;
  759.     extra.status = set;
  760.     Nlm_SetPanelExtra ((Nlm_PaneL) i, &extra);
  761.     if (oldstat != set) {
  762.       if (Nlm_Visible (i) && Nlm_AllParentsVisible (i)) {
  763.         Nlm_Select (i);
  764.         if (extra.inval != NULL) {
  765.           extra.inval ((Nlm_IcoN) i, extra.value, extra.value);
  766.         } else {
  767.           Nlm_ObjectRect (i, &r);
  768.           Nlm_InsetRect (&r, -1, -1);
  769.           Nlm_InvalRect (&r);
  770.         }
  771.       }
  772.     }
  773.   }
  774.   Nlm_RestorePort (tempPort);
  775. }
  776.  
  777. static Nlm_Boolean Nlm_GetIconStatus (Nlm_GraphiC i, Nlm_Int2 item)
  778.  
  779. {
  780.   Nlm_IconData  extra;
  781.   Nlm_Boolean   status;
  782.  
  783.   status = 0;
  784.   if (i != NULL) {
  785.     Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
  786.     status = extra.status;
  787.   }
  788.   return status;
  789. }
  790.  
  791. static void Nlm_SetIconTitle (Nlm_GraphiC i, Nlm_Int2 item,
  792.                               Nlm_CharPtr title, Nlm_Boolean savePort)
  793.  
  794. {
  795.   Nlm_IconData  extra;
  796.   Nlm_Handle    h;
  797.   Nlm_RecT      r;
  798.   Nlm_WindoW    tempPort;
  799.  
  800.   tempPort = Nlm_SavePortIfNeeded (i, savePort);
  801.   Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
  802.   h = extra.title;
  803.   h = Nlm_SetString (h, title);
  804.   extra.title = h;
  805.   Nlm_SetPanelExtra ((Nlm_PaneL) i, &extra);
  806.   if (Nlm_GetVisible (i) && Nlm_GetAllParentsVisible (i)) {
  807.     Nlm_GetRect (i, &r);
  808.     Nlm_InvalRect (&r);
  809.   }
  810.   Nlm_RestorePort (tempPort);
  811. }
  812.  
  813. static void Nlm_GetIconTitle (Nlm_GraphiC i, Nlm_Int2 item,
  814.                               Nlm_CharPtr title, Nlm_sizeT maxsize)
  815.  
  816. {
  817.   Nlm_IconData  extra;
  818.   Nlm_Handle    h;
  819.  
  820.   if (title != NULL) {
  821.     Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
  822.     h = extra.title;
  823.     Nlm_GetString (h, title, maxsize);
  824.   }
  825. }
  826.  
  827. static void Nlm_ResetIcon (Nlm_PaneL i)
  828.  
  829. {
  830.   Nlm_IconData  extra;
  831.  
  832.   Nlm_GetPanelExtra (i, &extra);
  833.   if (extra.title != NULL) {
  834.     extra.title = Nlm_HandFree (extra.title);
  835.   }
  836.   Nlm_SetPanelExtra (i, &extra);
  837. }
  838.  
  839. extern Nlm_IcoN Nlm_IconButton (Nlm_GrouP prnt, Nlm_Int2 pixwidth, Nlm_Int2 pixheight,
  840.                                 Nlm_IcnActnProc draw, Nlm_IcnChngProc inval,
  841.                                 Nlm_IcnClckProc click, Nlm_IcnClckProc drag,
  842.                                 Nlm_IcnClckProc hold, Nlm_IcnClckProc release)
  843.  
  844. {
  845.   Nlm_IcoN      ic;
  846.   Nlm_IconData  idata;
  847.  
  848.   ic = NULL;
  849.   if (prnt != NULL) {
  850.     Nlm_SelectFont (Nlm_systemFont);
  851.     ic = (Nlm_IcoN) Nlm_AutonomousPanel (prnt, pixwidth, pixheight,
  852.                                          (Nlm_PnlActnProc) draw, NULL, NULL,
  853.                                          sizeof (Nlm_IconData), Nlm_ResetIcon,
  854.                                          iconProcs);
  855.     if (ic != NULL) {
  856.       Nlm_SetPanelClick ((Nlm_PaneL) ic, (Nlm_PnlClckProc) click, (Nlm_PnlClckProc) drag,
  857.                          (Nlm_PnlClckProc) hold, (Nlm_PnlClckProc) release);
  858.       idata.inval = inval;
  859.       idata.value = 0;
  860.       idata.status = FALSE;
  861.       idata.title = NULL;
  862.       Nlm_SetPanelExtra ((Nlm_PaneL) ic, &idata);
  863.     }
  864.   }
  865.   return ic;
  866. }
  867.  
  868. extern void Nlm_FreeExtras (void)
  869.  
  870. {
  871.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemFree (gphprcsptr);
  872. }
  873.  
  874. extern void Nlm_InitExtras (void)
  875.  
  876. {
  877.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemNew (sizeof (Nlm_GphPrcs) * 3);
  878.  
  879.   repeatProcs = &(gphprcsptr [0]);
  880.   repeatProcs->setTitle = Nlm_SetRepeatTitle;
  881.   repeatProcs->getTitle = Nlm_GetRepeatTitle;
  882.  
  883.   switchProcs = &(gphprcsptr [1]);
  884.   switchProcs->setValue = Nlm_SetSwitchValue;
  885.   switchProcs->getValue = Nlm_GetSwitchValue;
  886.  
  887.   iconProcs = &(gphprcsptr [2]);
  888.   iconProcs->setValue = Nlm_SetIconValue;
  889.   iconProcs->getValue = Nlm_GetIconValue;
  890.   iconProcs->setStatus = Nlm_SetIconStatus;
  891.   iconProcs->getStatus = Nlm_GetIconStatus;
  892.   iconProcs->setTitle = Nlm_SetIconTitle;
  893.   iconProcs->getTitle = Nlm_GetIconTitle;
  894. }
  895.