home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lstbx3.zip / ic.cpp < prev    next >
Text File  |  1994-08-16  |  8KB  |  213 lines

  1. //------------------------------------------------------------------------------
  2. //
  3. // Sample Direct Manipulation program
  4. //
  5. //------------------------------------------------------------------------------
  6. //
  7. // This program demonstrates the ability to drag/drop between the entry fields
  8. // and the list box, but not the combination box.
  9. //
  10. //------------------------------------------------------------------------------
  11. extern "C"
  12. {
  13.   #define INCL_WINSYS
  14.   #define INCL_WINLISTBOXES
  15.   #include <os2.h>
  16. }
  17. #include <iapp.hpp>
  18. #include <icolor.hpp>
  19.  
  20. #include "ic.hpp"
  21. #include "ic.h"
  22. #include "listbox.h"
  23.  
  24. void main()
  25. {
  26.   DemoWindow mainWindow( IC_MAIN );
  27.   IApplication::current().run();
  28. }
  29.  
  30. /*------------------------------------------------------------------------------
  31. | ListBox32::ListBox32                                                         |
  32. |                                                                              |
  33. | Construct a ListBox32 on an IWindow.                                         |
  34. ------------------------------------------------------------------------------*/
  35. DemoWindow::DemoWindow( unsigned long ulId )
  36.            : IFrameWindow( IFrameWindow::defaultStyle(), ulId ),
  37.              ICommandHandler(),
  38.              ISelectHandler(),
  39.              clientCanvas( IC_CLIENT, this, this ),
  40.              titleText( IC_TITLE, &clientCanvas, &clientCanvas ),
  41.              soundCanvas( IC_SOUNDCANVAS, &clientCanvas, &clientCanvas ),
  42.              soundBox( IC_SOUNDBOX, &soundCanvas, &soundCanvas ),
  43.              chkAllButton( IC_CHECKALL, &clientCanvas, &clientCanvas ),
  44.              unChkAllButton( IC_UNCHECKALL, &clientCanvas, &clientCanvas ),
  45.              selAllButton( IC_SELECTALL, &clientCanvas, &clientCanvas ),
  46.              deSelAllButton( IC_DESELECTALL, &clientCanvas, &clientCanvas )
  47. {
  48.   /***************************************************************/
  49.   /* Multicell canvas is the client                              */
  50.   /***************************************************************/
  51.   setClient( &clientCanvas );
  52.  
  53.   ICommandHandler::handleEventsFor( this );
  54.   ISelectHandler::handleEventsFor( &soundBox );
  55.  
  56.   /***************************************************************/
  57.   /* Create the 32-Bit replacement list box                      */
  58.   /***************************************************************/
  59.   pListBox = new ListBox32( IC_LISTBOX,
  60.                             &clientCanvas,
  61.                             &clientCanvas,
  62.                             IRectangle( 10,10,100,175 ),
  63.                             IWindow::visible |
  64.                                   IListBox::horizontalScroll |
  65.                                   IListBox::extendedSelect,
  66.                             ListBox32::checkBox );
  67.  
  68.   /***************************************************************/
  69.   /* Add entries into the listbox                                */
  70.   /***************************************************************/
  71.   pListBox->addAsLast( "animal"   );
  72.   pListBox->addAsLast( "bear"     );
  73.   pListBox->addAsLast( "camel"    );
  74.   pListBox->addAsLast( "donkey"   );
  75.   pListBox->addAsLast( "elephanttttttttttttttttttttttttttttttt" );
  76.   pListBox->addAsLast( "fox"      );
  77.   pListBox->addAsLast( "gopher"   );
  78.   pListBox->addAsLast( "hound"    );
  79.   pListBox->addAsLast( "iguana"   );
  80.   pListBox->addAsLast( "jackal"   );
  81.  
  82.   pListBox->select( 0 );
  83.  
  84.   /***************************************************************/
  85.   /* Set the background color                                    */
  86.   /***************************************************************/
  87.   pListBox->setColor( IListBox::background, IColor::cyan );
  88.  
  89.   /***************************************************************/
  90.   /* Init list box title                                         */
  91.   /***************************************************************/
  92.   titleText.setAlignment( IStaticText::centerCenter );
  93.   titleText.setText( "32-Bit Replacement List box" );
  94.  
  95.   /***************************************************************/
  96.   /* Sound enablement                                            */
  97.   /***************************************************************/
  98.   soundBox.setText( "Sound" );
  99.   soundCanvas.addToCell( &soundBox, 2, 1 );
  100.   soundCanvas.setColumnWidth( 1, 1, true );
  101.   soundCanvas.setColumnWidth( 3, 1, true );
  102.   if (!pListBox->isSound())
  103.     soundBox.disable();
  104.  
  105.   /***************************************************************/
  106.   /* Init push buttons                                           */
  107.   /***************************************************************/
  108.   chkAllButton.setText( "Check All" );
  109.   unChkAllButton.setText( "Uncheck All" );
  110.   selAllButton.setText( "Select All" );
  111.   deSelAllButton.setText( "Deselect All" );
  112.   unChkAllButton.disable();
  113.   deSelAllButton.disable();
  114.  
  115.   /***************************************************************/
  116.   /* Set tabstop and group styles                                */
  117.   /***************************************************************/
  118.   chkAllButton.enableGroup().enableTabStop();
  119.  
  120.   clientCanvas.addToCell( &titleText, 3, 2 );
  121.   clientCanvas.addToCell( pListBox, 3, 4 );
  122.   clientCanvas.addToCell( &soundCanvas, 3, 6 );
  123.   clientCanvas.addToCell( &chkAllButton, 2, 7 );
  124.   clientCanvas.addToCell( &selAllButton, 4, 7 );
  125.   clientCanvas.addToCell( &unChkAllButton, 2, 8 );
  126.   clientCanvas.addToCell( &deSelAllButton, 4, 8 );
  127.  
  128.   clientCanvas.setRowHeight( 1, 5 );
  129.   clientCanvas.setRowHeight( 3, 10 );
  130.   clientCanvas.setRowHeight( 5, 15 );
  131.   clientCanvas.setColumnWidth( 1, 10 );
  132.  
  133.   setDestroyOnClose( true );
  134.   pListBox->setFocus();
  135.   show();
  136. }
  137.  
  138. DemoWindow::~DemoWindow( )
  139. {
  140. }
  141.  
  142. Boolean DemoWindow::command( ICommandEvent &evt )
  143. {
  144.   Boolean fProcessed;
  145.  
  146.   switch(evt.commandId())
  147.   {
  148.     case IC_CHECKALL:
  149.     {
  150.       long lCount =
  151.           pListBox->sendEvent( LMX_QUERYITEMCOUNT, 0, 0 );
  152.       if ( lCount != LIT_NONE )
  153.       {
  154.         long i;
  155.         for (i=0; i < lCount; i++)
  156.           evt.setResult( pListBox->sendEvent( LMX_SETCHECK, (int)i, 0 ) );
  157.       }
  158.       chkAllButton.disable();
  159.       unChkAllButton.enable();
  160.       fProcessed = true;
  161.       break;
  162.     }
  163.  
  164.     case IC_UNCHECKALL:
  165.       evt.setResult( pListBox->sendEvent( LMX_SETCHECK, LIT_NONE, 0 ) );
  166.       unChkAllButton.disable();
  167.       chkAllButton.enable();
  168.       fProcessed = true;
  169.       break;
  170.  
  171.     case IC_SELECTALL:
  172.       evt.setResult( pListBox->sendEvent( LMX_SELECTALL, 0, 0 ) );
  173.       selAllButton.disable();
  174.       deSelAllButton.enable();
  175.       fProcessed = true;
  176.       break;
  177.  
  178.     case IC_DESELECTALL:
  179.       evt.setResult( pListBox->sendEvent( LM_SELECTITEM, LIT_NONE, 0 ) );
  180.       deSelAllButton.disable();
  181.       selAllButton.enable();
  182.       fProcessed = true;
  183.       break;
  184.  
  185.     default:
  186.       fProcessed = false;
  187.       break;
  188.   }
  189.  
  190.   return( fProcessed );
  191. }
  192.  
  193. Boolean DemoWindow::selected( IControlEvent &evt )
  194. {
  195.   if (evt.controlId() == IC_SOUNDBOX)
  196.   {
  197.     /*************************************************************/
  198.     /* Test selection state and set the sound event if selected. */
  199.     /* Note that there is no current way to disable the sound    */
  200.     /* once it is set.  However, you can modify the              */
  201.     /* LMXM_SETSOUNDEVENT api to allow you to disable the sound, */
  202.     /* making the appropriate modifications here as well.        */
  203.     /*************************************************************/
  204.     if (soundBox.isSelected())
  205.       pListBox->setSoundEvent( ListBox32::singleClick, "ahooga.wav" );
  206.  
  207.     return( true );
  208.   }
  209.  
  210.   return( false );
  211. }
  212.  
  213.