home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / latour / shopping / shopping.cpp < prev    next >
Text File  |  1996-10-31  |  5KB  |  177 lines

  1.  
  2. /************************************************************
  3. / Tour of the UICL - Shopping List Example Program
  4. /
  5. / Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  6. / Copyright (c) 1997 John Wiley & Sons, Inc.
  7. / All Rights Reserved.
  8. ************************************************************/
  9. #include <iapp.hpp>
  10. #include <icmdhdr.hpp>
  11. #include <icnrctl.hpp>
  12. #include <icnrhdr.hpp>
  13. #include <idmsrch.hpp>
  14. #include <idmtgth.hpp>
  15. #include <iflytext.hpp>
  16. #include <iflyhhdr.hpp>
  17. #include <iframe.hpp>
  18. #include <imsgbox.hpp>
  19. #include <isplitcv.hpp>
  20. #include <istattxt.hpp>
  21. #include <itbar.hpp>
  22. #include <itbarbut.hpp>
  23.  
  24. #include "puritem.hpp"
  25. #include "shopping.h"
  26.  
  27.  
  28. /********************************************************
  29. / ToolBarHandler class - Handle tool bar buttons
  30. ********************************************************/
  31.  
  32. class ToolBarHandler : public ICommandHandler {
  33. public:
  34. virtual IBase::Boolean
  35.   command ( ICommandEvent& event );
  36. };
  37.  
  38. IBase::Boolean ToolBarHandler::command( ICommandEvent& event)
  39. {
  40.    switch (event.commandId())
  41.    {
  42.      case IC_ID_OPEN:
  43.      case IC_ID_SAVE:
  44.      case IC_ID_CUT:
  45.      case IC_ID_COPY:
  46.      case IC_ID_PASTE:
  47.      {
  48.         IMessageBox message( IWindow::desktopWindow() );
  49.         message.setTitle( "Informational Message Box" );
  50.         message.show( "This capability is not implemented in this example.",
  51.                       IMessageBox::information );
  52.         break;
  53.      }
  54.    }
  55.    return true;
  56. }
  57.  
  58. //=========================== Main ============================
  59.  
  60. void main ( )
  61. {
  62.   // Create the primary window with the two container views.
  63.   IFrameWindow primary( "Shopping List", ID_SHOPPINGLIST );
  64.   ISplitCanvas splitWindow( ID_LISTCLIENT, &primary, &primary );
  65.   splitWindow.setOrientation( ISplitCanvas::horizontalSplit );
  66.   primary.setClient( &splitWindow );
  67.  
  68.   // Add a tool bar to the primary window.
  69.   IToolBar toolBar( ID_TOOLBAR, &primary );
  70.   IToolBarButton
  71.     openButton( IC_ID_OPEN, &toolBar, &toolBar ),
  72.     saveButton( IC_ID_SAVE, &toolBar, &toolBar ),
  73.     cutButton( IC_ID_CUT, &toolBar, &toolBar ),
  74.     copyButton( IC_ID_COPY, &toolBar, &toolBar ),
  75.     pasteButton( IC_ID_PASTE, &toolBar, &toolBar );
  76.   toolBar
  77.    .addAsLast( &openButton, true )
  78.    .addAsLast( &saveButton )
  79.    .addAsLast( &cutButton, true )
  80.    .addAsLast( ©Button )
  81.    .addAsLast( &pasteButton )
  82.    .disableDragDrop( );
  83.  
  84.   // Add fly-over help to the tool bar.
  85.   IFlyText flyText( ID_FLYTEXT, &primary );
  86.   IFlyOverHelpHandler flyHandler( &flyText );
  87.   flyHandler
  88.    .setDefaultText( "\0" )
  89.    .setResourceLibrary( 0 )
  90.    .handleEventsFor( &toolBar );
  91.   ToolBarHandler commandHandler;
  92.   commandHandler
  93.    .handleEventsFor( &primary )
  94.    .handleEventsFor( &toolBar );
  95.  
  96.   // Create the buy list and not-needed list containers.
  97.   IContainerControl
  98.     buyList( ID_BUYLIST, &splitWindow, &splitWindow ),
  99.     dontBuyList( ID_DONTBUYLIST, &splitWindow, &splitWindow );
  100.  
  101.   // Set up the two containers.
  102.   buyList
  103.    .setTitle( "Items to buy" )
  104.    .showTitle()
  105.    .showTitleSeparator()
  106.    .showIconView()
  107.    .arrangeIconView()
  108.    .setDeleteObjectsOnClose()
  109.    .enableTabStop();
  110.   dontBuyList
  111.    .setTitle( "Unneeded items" )
  112.    .showTitle()
  113.    .showTitleSeparator()
  114.    .showIconView()
  115.    .arrangeIconView()
  116.    .setDeleteObjectsOnClose()
  117.    .enableTabStop();
  118.  
  119.   // Get default processing for an "open" event.
  120.   ICnrHandler cnrHandler;
  121.   cnrHandler
  122.    .handleEventsFor( &buyList )
  123.    .handleEventsFor( &dontBuyList );
  124.  
  125.   // Support drag and drop of purchase items.
  126.   IDMHandler::enableDragDropFor( &buyList );
  127.   IDMHandler::enableDragDropFor( &dontBuyList );
  128.  
  129.   // Create some purchase items.
  130.   PurchaseItem* p1 = new PurchaseItem( "Apple juice" );
  131.   p1->setNotes( "Kids won't drink anything else." );
  132.   PurchaseItem* p2 = new PurchaseItem( "Diskettes" );
  133.   (*p2)
  134.    .setQuantity( "1 box of 10 diskettes" )
  135.    .addNotes( "3.5 inch, double-sided, high-density." )
  136.    .addNotes( "Prefer preformatted." );
  137.   PurchaseItem* p3 =
  138.       new PurchaseItem( "Milk", "2 gallons", "Any", 3.75,
  139.                         "Skim" );
  140.   PurchaseItem* p4 = new PurchaseItem( "Fruit snacks" );
  141.   p4->setNotes( "These are for the kids." );
  142.   PurchaseItem* p5 =
  143.       new PurchaseItem( "Eggs", "1 dozen", 0, 1.50,
  144.                         "Extra large size." );
  145.   p5->addNotes( "Be sure none are cracked." );
  146.   IString bookName;
  147.   #ifdef IC_PM
  148.      bookName = "Power GUI Programming \n with  \n VisualAge for C++";
  149.   #else
  150.      bookName = "Power GUI Programming with VisualAge for C++";
  151.   #endif
  152.   PurchaseItem* p6 =
  153.       new PurchaseItem( bookName, "100",
  154.                         "John Wiley & Sons, Inc.", 49.95,
  155.                         "Updated for Windows release." );
  156.   (*p6)
  157.    .addNotes( "Love the book!" )
  158.    .setIcon( ID_THEBOOKICON );
  159.  
  160.   // Fill the split windows.
  161.   dontBuyList
  162.    .addObject( p1 )
  163.    .addObject( p2 )
  164.    .addObject( p3 )
  165.    .addObject( p4 )
  166.    .addObject( p5 );
  167.   buyList.addObject( p6 );
  168.  
  169.   // Give the buy list the input focus and
  170.   // show the window.
  171.   buyList.setFocus();
  172.   primary.show();
  173.  
  174.   // Start event processing.
  175.   IApplication::current().run();
  176. }
  177.