home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / MotifApp / ch9 / MenuDemoWindow.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  3.2 KB  |  104 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. // MenuDemoWindow.C: Demonstrate Cmd and MenuBar classes
  23. ////////////////////////////////////////////////////////////////////
  24. #include "MenuDemoWindow.h"
  25. #include "MenuBar.h"
  26. #include "MenuDemoApp.h"
  27. #include "NoOpCmd.h"
  28. #include "UndoCmd.h"
  29. #include "CmdList.h"
  30. #include <Xm/DrawingA.h>
  31.  
  32. MenuDemoWindow::MenuDemoWindow ( char *name ) : MenuWindow ( name )
  33. {
  34.     // Create three NoOpCmd objects to demonstrate relationships
  35.     // between objects, as well as MotifApp's undo facility
  36.     
  37.     _a = new NoOpCmd ( "A", TRUE );
  38.     _b = new NoOpCmd ( "B", TRUE );
  39.     _c = new NoOpCmd ( "C", FALSE );
  40.     
  41.     // Set up dependencies between objects. Each command disables
  42.     // itself once it is executed, and enables the other two
  43.     
  44.     _a->addToActivationList ( _b );
  45.     _a->addToActivationList ( _c );
  46.     _a->addToDeactivationList ( _a );
  47.     
  48.     _b->addToActivationList ( _a );
  49.     _b->addToActivationList ( _c );
  50.     _b->addToDeactivationList ( _b );
  51.     
  52.     _c->addToActivationList ( _a );
  53.     _c->addToActivationList ( _b );
  54.     _c->addToDeactivationList ( _c );
  55. }
  56.  
  57. Widget MenuDemoWindow::createWorkArea ( Widget parent )
  58. {
  59.     _canvas = XtCreateWidget ( "canvas", 
  60.                   xmDrawingAreaWidgetClass,
  61.                   parent, 
  62.                   NULL, 0 );
  63.     return _canvas;    
  64. }
  65.  
  66. void MenuDemoWindow::createMenuPanes()
  67. {
  68.     CmdList *cmdList;
  69.     
  70.     // Create an Application pane containing undo, 
  71.     // and other application-wide commands
  72.     
  73.     cmdList = new CmdList();
  74.     cmdList->add ( theUndoCmd );        
  75.     cmdList->add ( theMenuDemoApp->manageCmd() );
  76.     cmdList->add ( theMenuDemoApp->iconifyCmd() );
  77.     cmdList->add ( theMenuDemoApp->quitCmd() );
  78.     _menuBar->addCommands ( cmdList, "Application" );
  79.     
  80.     delete cmdList;
  81.     
  82.     // Create a menu pane of NoOpCmd objects to demonstrate
  83.     // Cmd objects that have multiple interfaces 
  84.     
  85.     cmdList = new CmdList();
  86.     cmdList->add ( theMenuDemoApp->xCmd() );
  87.     cmdList->add ( theMenuDemoApp->yCmd() );
  88.     cmdList->add ( theMenuDemoApp->zCmd() );
  89.     _menuBar->addCommands ( cmdList, "XYZ" );
  90.     
  91.     delete cmdList;
  92.     
  93.     // Create a window-specific menu pane, containing 
  94.     // commands that are independent within each window.
  95.     
  96.     cmdList = new CmdList();
  97.     cmdList->add ( _a );
  98.     cmdList->add ( _b );
  99.     cmdList->add ( _c );
  100.     _menuBar->addCommands ( cmdList, "ABC" );
  101.     
  102.     delete cmdList;
  103. }
  104.