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

  1. //************************************************************
  2. // Using Help - Runtime Setting of Help Panels               
  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 <iframe.hpp>
  11. #include <ihelp.hpp>
  12. #include <ilistbox.hpp>
  13. #include <imcelcv.hpp>
  14. #include <imenubar.hpp>
  15. #include <istattxt.hpp>
  16.  
  17. #include "helpid.hpp"
  18. #include "helpid.h"
  19.  
  20. #ifdef IC_PM
  21.   #ifdef IPF_COMPATIBLE
  22.     #undef IPF_COMPATIBLE
  23.   #endif
  24. #endif
  25.  
  26. void main ( )
  27. {
  28.   ICoordinateSystem::setApplicationOrientation
  29.           ( ICoordinateSystem::originUpperLeft );
  30.  
  31.   // Create a primary window with a list box.
  32.   IFrameWindow
  33.     primary( "Runtime Setting of Help Panels", ID_PRIMARY );
  34.   IMenuBar
  35.     menubar( &primary );
  36.   menubar
  37.    .setMenu( ID_MENUBAR );
  38.  
  39.   IMultiCellCanvas
  40.     client( ID_CLIENT, &primary, &primary );
  41.   IStaticText
  42.     heading( ID_DUMMY, &client, &client );
  43.   heading
  44.    .setText( "Select a type of window to create." );
  45.   IListBox
  46.     list( ID_LISTBOX, &client, &client );
  47.   list
  48.    .addAsLast( "Primary" );
  49.   list
  50.    .addAsLast( "Secondary (modeless)" );
  51.   list
  52.    .addAsLast( "Secondary (modal)" );
  53.   list
  54.    .select( 0 )
  55.    .enableTabStop()
  56.    .enableGroup();
  57.  
  58.   // Create handler that processes an "open" event.
  59.   ListBoxSelectHandler
  60.     selHandler;
  61.   selHandler
  62.    .handleEventsFor( &client );
  63.  
  64.   client
  65.    .addToCell( &heading, 2, 2 )
  66.    .addToCell( &list,    2, 4 );
  67.   client
  68.    .setColumnWidth( 2, 1, true )
  69.    .setColumnWidth( 3, IMultiCellCanvas::defaultCell().width() )
  70.    .setRowHeight( 4, 1, true )
  71.    .setRowHeight( 5, IMultiCellCanvas::defaultCell().height() );
  72.  
  73.   // Create the help window and associate it with the primary window.
  74.   IHelpWindow::Settings
  75.     settings;
  76.   settings
  77.    .setTitle( "Runtime Setting of Help Panels - Help" )
  78.    .setLibraries( "HELPID.HLP" );
  79. #ifdef IPF_COMPATIBLE
  80.   IHelpWindow
  81.     help( settings, &primary,
  82.           IHelpWindow::classDefaultStyle
  83.            | IHelpWindow::ipfCompatible );
  84. #else
  85.   IHelpWindow
  86.     help( settings, &primary );
  87. #endif
  88.  
  89.   // Assign contextual and general help.
  90.   list
  91.    .setHelpId( PANEL_LISTBOX );
  92.   primary
  93.    .setHelpId( PANEL_PRIMARY );
  94.   menubar
  95.    .setItemHelpId( ID_FILE,    PANEL_FILE )
  96.    .setItemHelpId( ID_CHOICE1, PANEL_CHOICE1 )
  97.    .setItemHelpId( ID_CHOICE2, PANEL_CHOICE2 )
  98.    .setItemHelpId( ID_CLOSE,   PANEL_CLOSE );
  99.  
  100.   primary
  101.    .setClient( &client )
  102.    .setFocus()
  103.    .show();
  104.  
  105.   IApplication::current().run();
  106. }
  107.  
  108. IBase::Boolean
  109.   ListBoxSelectHandler::enter ( IControlEvent& event )
  110. {
  111.   Boolean
  112.     dontPassOn = false;
  113.   if ( event.controlId() == ID_LISTBOX )
  114.   {
  115.      long
  116.        selection = ((IListBox*)event.controlWindow())->selection();
  117.      switch ( selection )
  118.      {
  119.        case 0:     // Display another primary window.
  120.        {
  121.          PrimaryWindow
  122.           *frame = new PrimaryWindow;
  123.          frame->setAutoDeleteObject();
  124.          IHelpWindow
  125.           *help = IHelpWindow::helpWindow( event.dispatchingWindow() );
  126.          help->setAssociatedWindow( frame );
  127.          frame->show();
  128.          break;
  129.        }
  130.        case 1:     // Display a modeless secondary window.
  131.        {
  132.          SecondaryWindow
  133.           *frame = new SecondaryWindow( ID_SECONDARY_MODELESS,
  134.                                         event.dispatchingWindow() );
  135.          frame->setAutoDeleteObject();
  136.          IHelpWindow
  137.           *help = IHelpWindow::helpWindow( frame );
  138.          help->setAssociatedWindow( frame );
  139.          frame->show();
  140.          break;
  141.        }
  142.        case 2:     // Display a modal secondary window.
  143.        {
  144.          SecondaryWindow
  145.            frame( ID_SECONDARY_MODAL, event.dispatchingWindow() );
  146.          IHelpWindow
  147.           *help = IHelpWindow::helpWindow( &frame );
  148.          help->setAssociatedWindow( &frame );
  149.          frame.showModally();
  150.          break;
  151.        }
  152.      }
  153.      dontPassOn = true;
  154.   }
  155.  
  156.   return dontPassOn;
  157. }
  158.