home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Graphics / Graphics.zip / xfitsvew.zip / XFITSview / messagebox.c < prev    next >
C/C++ Source or Header  |  1995-12-19  |  3KB  |  95 lines

  1. /* MessageBox routines for XFITSview */
  2. /* uses a ScrollText to display messages from XFITSview      */
  3. /*-----------------------------------------------------------------------
  4. *  Copyright (C) 1996
  5. *  Associated Universities, Inc. Washington DC, USA.
  6. *  This program is free software; you can redistribute it and/or
  7. *  modify it under the terms of the GNU General Public License as
  8. *  published by the Free Software Foundation; either version 2 of
  9. *  the License, or (at your option) any later version.
  10. *
  11. *  This program is distributed in the hope that it will be useful,
  12. *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. *  GNU General Public License for more details.
  15. *-----------------------------------------------------------------------*/
  16.  
  17. #include <Xm/Xm.h> 
  18. #include "scrolltext.h"
  19. #include "messagebox.h"
  20. #include "xfitsview.h"
  21. #include <stdio.h> 
  22.  
  23. /* MessageBox ScrollText, if non NULL then message box active */
  24. ScrollTextPtr MessScroll = NULL; 
  25.  
  26. /* internal prototypes */
  27. /* shutdown messagebox, arg not used */
  28. void MessageDismiss(XtPointer arg);
  29.  
  30. /* public functions */
  31. /* display message in message box, creating if necessary */
  32. void MessageShow (char *message)
  33. {
  34.   int next, length, new = 0;
  35.  
  36. /* new ScrollText? */
  37.   if (!MessScroll)
  38.     {
  39.       /* make ScrollText */
  40.       new = 1;
  41.       MessScroll = ScrollTextMake (Display_shell, "XFITSview Messages");
  42.       if (!MessScroll) { /* error, print to stderr */
  43.     fprintf (stderr, message); fprintf (stderr,"\n");
  44.     return;
  45.       } /* end create error */
  46.       /* add dismiss callback */
  47.       MessScroll->DismissProc = (TextFileProc)MessageDismiss;
  48.     } /* end create ScrollText */
  49.  
  50.   /* add text */
  51.   next = MessScroll->num_lines;
  52.   if (next>=MAX_LINE) next = MAX_LINE - 1; /* add to end no matter */
  53.   length = strlen(message);
  54.   MessScroll->lines[next] = (char*)malloc(length+1);
  55.   strcpy (MessScroll->lines[next], message);
  56.   next++;
  57.   MessScroll->num_lines = next; /* save number in ScrollText */
  58.   /* make some noise */
  59.   XBell(XtDisplay(MessScroll->Parent), 50); 
  60.   /*  setup */
  61.   ScrollTextInit (MessScroll);
  62.  
  63.   if (!new) { /* pop to front */
  64.     if (XtIsRealized (MessScroll->ScrollBox))
  65.       XMapRaised (XtDisplay(MessScroll->Parent), 
  66.           XtWindow(MessScroll->ScrollBox));
  67.     /* redraw */
  68.     STextExposeCB (MessScroll->ScrollBox, (XtPointer)MessScroll, NULL);
  69.   }
  70.  
  71. } /* end MessageShow */
  72.  
  73. /* shutdown messagebox, arg not used */
  74. /* as this is called when the ScrollText self destructs it does not delete
  75.    the ScrollText */
  76. void MessageDismiss(XtPointer arg)
  77. {
  78.   MessScroll = NULL;
  79. } /* end MessageDismiss */
  80.  
  81. /* redraw message box if it exists */
  82. void MessageRefresh (void)
  83. {
  84. /* does it exist? */
  85.   if (!MessScroll) return;
  86.  
  87.   /*  setup */
  88.   ScrollTextInit (MessScroll);
  89.   if (XtIsRealized (MessScroll->ScrollBox))
  90.     XMapRaised (XtDisplay(MessScroll->Parent), 
  91.         XtWindow(MessScroll->ScrollBox));
  92.   /* redraw */
  93.   STextExposeCB (MessScroll->ScrollBox, (XtPointer)MessScroll, NULL);
  94. } /* end MessageRefresh */
  95.