home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / MotifApp / ch3B / Stopwatch.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  2.2 KB  |  82 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. // StopWatch.C: Group subcomponents into one stopwatch component
  23. /////////////////////////////////////////////////////////////////
  24. #include "Stopwatch.h"
  25. #include <Xm/Xm.h>
  26. #include <Xm/RowColumn.h>
  27. #include "Timer.h"
  28. #include "Face.h"
  29. #include "Control.h"
  30.  
  31. // Callback function used to communicate between 
  32. // the Timer and the Face objects
  33.  
  34. void updateFace ( float time, void *data )
  35. {
  36.     Face *face = (Face *) data;    // Coerce to expected type
  37.     face->setTime ( time );        // Display time in Face object
  38. }
  39.  
  40. Stopwatch::Stopwatch ( Widget parent, char *name ) : 
  41.               BasicComponent ( name )
  42. {
  43.     // Create a manager widget to hold all components
  44.     
  45.     _w = XmCreateRowColumn ( parent, _name, NULL, 0 );
  46.     
  47.     // Instantiate the three sub-components of the stopwatch
  48.     
  49.     _face = new  Face ( _w, "face" );
  50.     _timer = new Timer ( XtWidgetToApplicationContext ( parent ), 
  51.             updateFace, 
  52.             1000,
  53.             (void *) _face);
  54.     
  55.     _control = new Control ( _w, "control", this, _timer );
  56.     
  57.     // Manage the two user interface components
  58.     
  59.     _face->manage();
  60.     _control->manage();
  61. }
  62.  
  63. Stopwatch::~Stopwatch ( )
  64. {
  65.     delete _face;
  66.     delete _timer;
  67.     delete _control;
  68. }
  69.  
  70. void Stopwatch::timerStarted()
  71. {
  72.     // Empty
  73. }
  74.  
  75. void Stopwatch::timerStopped()
  76. {
  77.     // Empty
  78. }
  79.  
  80.  
  81.  
  82.