home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / MotifApp / ch5 / Message.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  1.9 KB  |  65 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////////////////////////////////////////
  3. //         This example code is from the book:
  4. //
  5. //           Object-Oriented Programming with C++ and OSF/Motif
  6. //         by
  7. //           Douglas Young
  8. //           Prentice Hall, 1992
  9. //           ISBN 0-13-630252-1    
  10. //
  11. //         Copyright 1991 by Prentice Hall
  12. //         All Rights Reserved
  13. //
  14. //  Permission to use, copy, modify, and distribute this software for 
  15. //  any purpose except publication and without fee is hereby granted, provided 
  16. //  that the above copyright notice appear in all copies of the software.
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. /////////////////////////////////////////////////////////
  22. // Message.C: Manages a message panel, 
  23. //            using an XmLabel widget
  24. /////////////////////////////////////////////////////////
  25. #include "Message.h"
  26. #include <Xm/Xm.h>
  27. #include <Xm/Label.h>
  28. #include <assert.h>
  29.  
  30. Message::Message ( Widget parent, char * name ) : UIComponent( name )
  31. {
  32.     _w = XmCreateLabel ( parent, _name, NULL, 0 );
  33.     installDestroyHandler();
  34.     postMessage ( " " );  // Clear the widget
  35. }
  36.  
  37. void Message::postMessage ( char *msg )
  38. {
  39.     assert ( _w );
  40.     
  41.     // Convert the character string to a compound string for Motif
  42.     
  43.     XmString xmstr = XmStringCreateSimple ( msg );
  44.     
  45.     // Display the new label
  46.     
  47.     XtVaSetValues ( _w, XmNlabelString, xmstr, NULL ); 
  48.     
  49.     // XmLabel copies the string, so we can free our copy
  50.     
  51.     XmStringFree ( xmstr );
  52. }
  53.  
  54. void Message::postAlert ( char *msg )
  55. {
  56.     assert ( _w );  // Must have a widget to display message
  57.     
  58.     if ( msg )
  59.     postMessage ( msg );  // Display the string
  60.     
  61.     // Sound a bell as an alert. 
  62.     
  63.     XBell ( XtDisplay ( _w ), 100 );
  64. }
  65.