home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / MotifApp / ch12 / ControlPanel.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  2.9 KB  |  85 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. // ControlPanel.C
  23. //////////////////////////////////////////////////////////
  24. #include "ControlPanel.h"
  25. #include "ButtonInterface.h"
  26. #include "Clock.h"
  27. #include "RunCmd.h"
  28. #include "StopCmd.h"
  29. #include "StepCmd.h"
  30. #include <Xm/RowColumn.h>
  31.  
  32. ControlPanel::ControlPanel ( Widget parent, 
  33.                 char  *name, 
  34.                 Clock *clock ) : UIComponent ( name )
  35. {
  36.     CmdInterface *runBtn, *stopBtn, *stepBtn;
  37.     Cmd          *runCmd, *stopCmd, *stepCmd;
  38.     
  39.     // Manage all command buttons in a single horizontal row.
  40.     
  41.     _w = XtVaCreateManagedWidget ( _name, xmRowColumnWidgetClass, 
  42.                   parent, 
  43.                   XmNnumColumns, 1,
  44.                   XmNorientation, XmHORIZONTAL, 
  45.                   NULL );
  46.     installDestroyHandler();
  47.     
  48.     // Instantiate one object for each command. The clock will
  49.     // initially be stopped, so activate the step and run 
  50.     // commands, but deactivate the stop command.
  51.     
  52.     runCmd  = new RunCmd  ( "Run",  TRUE,  clock );
  53.     stopCmd = new StopCmd ( "Stop", FALSE, clock );
  54.     stepCmd = new StepCmd ( "Step", TRUE,  clock );
  55.     
  56.     // Set up dependencies between the various commands.
  57.     // A running clock can be stopped, but not stepped
  58.     // A stopped clock can be run, or stepped. It doesn't
  59.     // make sense to stop a stopped clock, or to run a 
  60.     // running  clock, so have these commands deactivate
  61.     // themselves automatically.
  62.     
  63.     runCmd->addToActivationList ( stopCmd );
  64.     runCmd->addToDeactivationList ( stepCmd );
  65.     runCmd->addToDeactivationList ( runCmd );
  66.     
  67.     stopCmd->addToActivationList ( runCmd );
  68.     stopCmd->addToActivationList ( stepCmd );
  69.     stopCmd->addToDeactivationList ( stopCmd );
  70.     
  71.     stepCmd->addToActivationList ( runCmd );
  72.     stepCmd->addToDeactivationList ( stopCmd );
  73.     
  74.     // Finally, create the user interface (buttons) for
  75.     // each of the commands.
  76.     
  77.     runBtn   = new ButtonInterface ( _w, runCmd );   
  78.     stopBtn  = new ButtonInterface ( _w, stopCmd );
  79.     stepBtn  = new ButtonInterface ( _w, stepCmd );
  80.  
  81.     runBtn->manage();
  82.     stopBtn->manage();
  83.     stepBtn->manage();
  84. }
  85.