home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / help / helpmenu / helpmenu.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  4.4 KB  |  181 lines

  1. //*********************************************************
  2. // Using Help - Help Menu Choices
  3. //
  4. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. // Copyright (c) 1997 John Wiley & Sons, Inc.
  6. // All Rights Reserved.
  7. //*********************************************************
  8. #include <iapp.hpp>
  9. #include <icoordsy.hpp>
  10. #include <ihelp.hpp>
  11. #include <ititle.hpp>
  12.  
  13. #include "helpmenu.hpp"
  14. #include "hcmdhdr.hpp"
  15. #include "hkeyshdr.hpp"
  16. #include "helpmenu.h"
  17.  
  18. #ifdef IC_PM
  19.   #ifdef IPF_COMPATIBLE
  20.     #undef IPF_COMPATIBLE
  21.   #endif
  22. #endif
  23.  
  24. static HelpCommandHandler
  25.   helpCommandHdr;
  26. static KeysHelpHandler
  27.   keysHelpHdr;
  28.  
  29. void main ( )
  30. {
  31.   ICoordinateSystem::setApplicationOrientation
  32.           ( ICoordinateSystem::originUpperLeft );
  33.  
  34.   // Create a primary window with a help menu.
  35.   HelpMenuWindow
  36.     primary( ID_PRIMARY, 0 );
  37.  
  38.   // Create the help window and associate it with the primary window.
  39.   IHelpWindow::Settings
  40.     settings;
  41.   settings
  42.    .setTitle( "Help Menu Choices - Help" )
  43.    .setLibraries( "HELPMENU.HLP" )
  44.    .setHelpTable( ID_HELPTABLE );
  45. #ifdef IPF_COMPATIBLE
  46.   IHelpWindow
  47.     help( settings, &primary,
  48.           IHelpWindow::classDefaultStyle
  49.            | IHelpWindow::ipfCompatible );
  50. #else
  51.   IHelpWindow
  52.     help( settings, &primary );
  53. #endif
  54.  
  55.   // Attach static help-specific handlers to the associated window.
  56.   helpCommandHdr
  57.    .handleEventsFor( &primary );
  58.   keysHelpHdr
  59.    .handleEventsFor( &primary );
  60.  
  61.   primary
  62.    .setFocus()
  63.    .show();
  64.  
  65.   IApplication::current().run();
  66. }
  67.  
  68. IBase::Boolean
  69.   CommandHandler::command ( ICommandEvent& event )
  70. {
  71.   Boolean
  72.     dontPassOn = false;
  73.   if ( event.commandId() == ID_SECONDARY_PB )
  74.   {
  75.      // Create a modeless secondary window.
  76.      HelpMenuWindow
  77.       *frame = new HelpMenuWindow( ID_SECONDARY,
  78.                                    event.dispatchingWindow() );
  79.      frame->setAutoDeleteObject();
  80.      IHelpWindow
  81.       *help = IHelpWindow::helpWindow( frame );
  82.      help->setAssociatedWindow( frame );
  83.  
  84.      // Attach static help-specific handlers to the associated window.
  85.      helpCommandHdr
  86.       .handleEventsFor( frame );
  87.      keysHelpHdr
  88.       .handleEventsFor( frame );
  89.  
  90.      (*frame)
  91.       .setFocus()
  92.       .show();
  93.  
  94.      dontPassOn = true;
  95.   }
  96.   else if ( event.commandId() == ID_EXIT_PB )
  97.   {
  98.      // Dismiss the frame window.
  99.      IFrameWindow
  100.       *frame = (IFrameWindow*)event.dispatchingWindow();
  101.      frame->close();
  102.      dontPassOn = true;
  103.   }
  104.  
  105.   return dontPassOn;
  106. }
  107.  
  108. HelpMenuWindow::HelpMenuWindow ( unsigned long id,
  109.                                  IWindow*      owner )
  110.   : IFrameWindow( id, 0, owner ),
  111.     menuBar( ID_MENUBAR, this ),
  112.     canvasClient( ID_CLIENT, this, this ),
  113.     heading ( ID_HEADING, &canvasClient, &canvasClient ),
  114.     showSecondaryPB( owner ?
  115.                        0 :
  116.                        new IPushButton( ID_SECONDARY_PB,
  117.                                         &canvasClient,
  118.                                         &canvasClient ) ),
  119.     exitPB( ID_EXIT_PB, &canvasClient, &canvasClient ),
  120.     cmdHandler()
  121. {
  122.   ITitle( this, "Help Menu Choices" );
  123.  
  124.   heading
  125.    .setText( "Select an item from the Help menu." );
  126.   if ( showSecondaryPB )
  127.   {
  128.      (*showSecondaryPB)
  129.       .enableDefault()
  130.       .setText( "Show secondary window" )
  131.       .enableTabStop()
  132.       .enableGroup();
  133.   }
  134.   exitPB
  135.    .setText( "Exit" );
  136.   if ( ! showSecondaryPB )
  137.   {
  138.      exitPB
  139.       .enableDefault()
  140.       .enableTabStop()
  141.       .enableGroup();
  142.   }
  143.  
  144.   cmdHandler
  145.    .handleEventsFor( this );
  146.  
  147.   unsigned long
  148.     lastColumn( 4 );
  149.   if ( showSecondaryPB )
  150.   {
  151.      canvasClient
  152.       .addToCell( &heading,        2, 2, 4 )
  153.       .addToCell( showSecondaryPB, 2, 4 )
  154.       .addToCell( &exitPB,         4, 4 );
  155.      lastColumn = 6;
  156.   }
  157.   else
  158.   {
  159.      canvasClient
  160.       .addToCell( &heading,        2, 2, 2 )
  161.       .addToCell( &exitPB,         2, 4 );
  162.   }
  163.   canvasClient
  164.    .setColumnWidth( lastColumn - 1, 0, true )
  165.    .setColumnWidth( lastColumn,
  166.                     IMultiCellCanvas::defaultCell().width() )
  167.    .setRowHeight( 3, IMultiCellCanvas::defaultCell().height(), true )
  168.    .setRowHeight( 5, IMultiCellCanvas::defaultCell().height() );
  169.  
  170.   (*this)
  171.    .setClient( &canvasClient );
  172. }
  173.  
  174. HelpMenuWindow::~HelpMenuWindow ( )
  175. {
  176.   if ( showSecondaryPB )
  177.   {
  178.      delete showSecondaryPB;
  179.   }
  180. }
  181.