home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / debug / tracebox / filtdlg.cpp next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  11.5 KB  |  322 lines

  1. //************************************************************
  2. // Problem Determination  - Trace Queue Browser
  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 "filtdlg.hpp"
  9. #include "filtdlg.h"
  10.  
  11. #include <icmdhdr.hpp>
  12. #include <iedithdr.hpp>
  13. #include <ifont.hpp>
  14. #include <iselhdr.hpp>
  15.  
  16.  
  17. class FilterCommandHandler : public ICommandHandler {
  18. public:
  19. /*------------------------------- Constructors -------------------------------*/
  20.   FilterCommandHandler ( FilterDialog& dialog )
  21.       : fdialog( dialog ) { }
  22.  
  23. protected:
  24. /*----------------------------- Event Processing -----------------------------*/
  25. virtual Boolean
  26.   command       ( ICommandEvent& event );
  27.  
  28. private:
  29.   FilterDialog&   fdialog;
  30.  
  31.   FilterCommandHandler             ( const FilterCommandHandler&  );
  32.   FilterCommandHandler& operator = ( const FilterCommandHandler&  );
  33. };
  34.  
  35. class FilterSelectHandler : public ISelectHandler {
  36. public:
  37. /*------------------------------- Constructors -------------------------------*/
  38.   FilterSelectHandler ( FilterDialog& dialog )
  39.       : fdialog( dialog ) { }
  40.  
  41. protected:
  42. /*----------------------------- Event Processing -----------------------------*/
  43. virtual Boolean
  44.   enter    ( IControlEvent& event ),
  45.   selected ( IControlEvent& event );
  46.  
  47. private:
  48.   FilterDialog&   fdialog;
  49.  
  50.   FilterSelectHandler             ( const FilterSelectHandler&  );
  51.   FilterSelectHandler& operator = ( const FilterSelectHandler&  );
  52. };
  53.  
  54. class FilterEditHandler : public IEditHandler {
  55. public:
  56. /*------------------------------- Constructors -------------------------------*/
  57.   FilterEditHandler ( FilterDialog& dialog )
  58.       : fdialog( dialog ) { }
  59.  
  60. protected:
  61. /*----------------------------- Event Processing -----------------------------*/
  62. virtual Boolean
  63.   edit     ( IControlEvent& event );
  64.  
  65. private:
  66.   FilterDialog&   fdialog;
  67.  
  68.   FilterEditHandler             ( const FilterEditHandler&  );
  69.   FilterEditHandler& operator = ( const FilterEditHandler&  );
  70. };
  71.  
  72.  
  73. /*------------------------------------------------------------------------------
  74. | FilterDialog::FilterDialog                                                   |
  75. ------------------------------------------------------------------------------*/
  76. FilterDialog::FilterDialog( FilterSet& filterset, IWindow* owner )
  77.    :  IFrameWindow( IResourceId( FLTD_DIALOG ),
  78.                     0, owner,
  79.                     IRectangle(),
  80.                     IFrameWindow::defaultStyle() |
  81.                     IFrameWindow::dialogBorder |
  82.                     IFrameWindow::dialogBackground ),
  83.       ffilterset( filterset ),
  84.       fcanvas   (FLTD_CANVAS, this, this),
  85.       fisExclude(FLTD_EXCLUDE  ,  &fcanvas, &fcanvas,
  86.                  IRectangle(),
  87.                  ICheckBox::defaultStyle() | IControl::tabStop ),
  88.       flabel    (FLTD_LABEL    ,  &fcanvas, &fcanvas),
  89.       fentry    (FLTD_ENTRY    ,  &fcanvas, &fcanvas,
  90.                  IRectangle(),
  91.                  IEntryField::defaultStyle() | IControl::tabStop ),
  92.       flist     (FLTD_LIST     ,  &fcanvas, &fcanvas, IRectangle(),
  93.                  IListBox::defaultStyle() | IBaseListBox::multipleSelect ),
  94.       fbuttons1 (FLTD_BUTTONS1 ,  &fcanvas, &fcanvas, IRectangle(),
  95.                  (ISetCanvas::defaultStyle() &  ~ISetCanvas::packTight) |
  96.                  ISetCanvas::packExpanded  ),
  97.       fadd      (FLTD_ADD      ,  &fbuttons1, &fbuttons1,
  98.                  IRectangle(),
  99.                  IPushButton::defaultStyle() | IControl::tabStop ),
  100.       fremove   (FLTD_REMOVE   ,  &fbuttons1, &fbuttons1,
  101.                  IRectangle(),
  102.                  IPushButton::defaultStyle() | IControl::tabStop ),
  103.       fbuttons2 (FLTD_BUTTONS2 ,  this, this, IRectangle(),
  104.                  (ISetCanvas::defaultStyle() &  ~ISetCanvas::packTight) |
  105.                  ISetCanvas::packExpanded  ),
  106.       fok       (FLTD_OK       ,  &fbuttons2, &fbuttons2,
  107.                  IRectangle(),
  108.                  IPushButton::defaultStyle() |
  109.                  IPushButton::defaultButton | IControl::tabStop ),
  110.       fcancel   (FLTD_CANCEL   ,  &fbuttons2, &fbuttons2,
  111.                  IRectangle(),
  112.                  IPushButton::defaultStyle() | IControl::tabStop ),
  113.       fcmdhdr   (new FilterCommandHandler( *this )),
  114.       fselhdr   (new FilterSelectHandler( *this )),
  115.       fedithdr  (new FilterEditHandler( *this ))
  116. {
  117.    // set up handlers
  118.    fcmdhdr->handleEventsFor( this );
  119. //   fselhdr->handleEventsFor( &flist );
  120. //   fedithdr->handleEventsFor( &fentry );
  121.    fselhdr->handleEventsFor( &fcanvas );
  122.    fedithdr->handleEventsFor( &fcanvas );
  123.  
  124.    // set up control text
  125.    fisExclude.setText( IResourceId( FLTD_EXCLUDE ) );
  126.    fisExclude.select( ffilterset.isExcludeList );
  127.    if (ffilterset.isExcludeList)
  128.       flabel.setText  ( IResourceId( FLTD_LABEL1 ) );
  129.    else
  130.       flabel.setText  ( IResourceId( FLTD_LABEL0 ) );
  131.    fadd.setText    ( IResourceId( FLTD_ADD   ) );
  132.    fremove.setText ( IResourceId( FLTD_REMOVE) );
  133.    fok.setText     ( IResourceId( FLTD_OK    ) );
  134.    fcancel.setText ( IResourceId( FLTD_CANCEL) );
  135.  
  136.    // load the listbox with elements from filter set
  137.    FilterSet::Cursor cursor(ffilterset);
  138.    for (cursor.setToFirst(); cursor.isValid(); cursor.setToNext() )
  139.       {
  140.       flist.addAscending( cursor.element() );
  141.       }
  142.  
  143.  
  144.    // set up listbox and entry field size
  145.    flist.setMinimumRows(6);
  146.    flist.setMinimumCharacters(40);
  147.    fentry.setLimit( 999 );       // allow big entry field
  148.    IFont  entryFont( &fentry );
  149.    fentry.setMinimumSize(  ISize( entryFont.avgCharWidth() * 40,
  150.                                   fentry.minimumSize().height() ) );
  151.  
  152.    // add controls to canvas
  153.    //   1   2       3      4+       5
  154.    //2    fisExclude     flist
  155.    //3                     "
  156.    //4    flabel           "
  157.    //5    fentry           "
  158.    //6+                    "
  159.    //7    fbuttons1        "
  160.    //8
  161.  
  162.    fcanvas.addToCell( &fisExclude,2, 2 );
  163.    fcanvas.addToCell( &flabel,    2, 4 );
  164.    fcanvas.addToCell( &fentry,    2, 5 );
  165.    fcanvas.addToCell( &fbuttons1, 2, 7 );
  166.    fcanvas.addToCell( &flist,     4, 2, 1, 6 );
  167.    // setup canvas layout
  168.    fcanvas.setRowHeight( 6, IMultiCellCanvas::defaultCell().height(), true );
  169.    fcanvas.setColumnWidth( 4, IMultiCellCanvas::defaultCell().width(), true );
  170.    // padding
  171.    fcanvas.setRowHeight( 8, IMultiCellCanvas::defaultCell().height() );
  172.    fcanvas.setColumnWidth( 5, IMultiCellCanvas::defaultCell().width() );
  173.  
  174.    // Put OK and cancel buttons at bottom
  175.    addExtension(&fbuttons2, IFrameWindow::belowClient,
  176.                  (unsigned long)fbuttons2.minimumSize().height());
  177.  
  178.    // disable add and remove for now
  179.    fadd.disable();
  180.    fremove.disable();
  181.  
  182.    // Size the dialog around the client canvas
  183.    IRectangle  newrect( IPoint(0,0),  fcanvas.minimumSize() );
  184.    newrect.centerAt( owner->rect().center() );
  185.    moveSizeToClient( newrect );
  186. }
  187.  
  188.  
  189. /*------------------------------------------------------------------------------
  190. | FilterDialog::~FilterDialog                                                  |
  191. ------------------------------------------------------------------------------*/
  192. FilterDialog::~FilterDialog( )
  193. {
  194.    fcmdhdr->stopHandlingEventsFor( this );
  195. //   fselhdr->stopHandlingEventsFor( &flist );
  196. //   fedithdr->stopHandlingEventsFor( &fentry );
  197.    fselhdr->stopHandlingEventsFor( this );
  198.    fedithdr->stopHandlingEventsFor( this );
  199.    delete fselhdr;
  200.    delete fcmdhdr;
  201.    delete fedithdr;
  202. }
  203.  
  204. /*------------------------------------------------------------------------------
  205. | IBase::Boolean FilterCommandHandler::command                                 |
  206. ------------------------------------------------------------------------------*/
  207. IBase::Boolean FilterCommandHandler::command       ( ICommandEvent& event )
  208. {
  209.    Boolean handled = true;
  210.    switch ( event.commandId() )
  211.       {
  212.       case  FLTD_ADD     :
  213.          // Add entry field contents to listbox
  214.          if (fdialog.flist.locateText( fdialog.fentry.text() ) ==
  215.              IBaseListBox::notFound )
  216.             {
  217.             fdialog.flist.addAscending( fdialog.fentry.text() );
  218.             }
  219.          fdialog.fentry.setText("");
  220.          fdialog.fentry.setFocus();
  221.          break;
  222.  
  223.       case  FLTD_REMOVE  :
  224.          {
  225.          // remove all selections
  226.          IBaseListBox::Cursor cursor (fdialog.flist,
  227.                                       IBaseListBox::Cursor::selectedItems );
  228.          for (cursor.setToFirst(); cursor.isValid(); )
  229.             {
  230.             fdialog.flist.removeAt( cursor );
  231.             }
  232.          // disable remove till next selection
  233.          fdialog.fremove.disable();
  234.          }
  235.          break;
  236.       case  FLTD_OK      :
  237.          {
  238.          // copy listbox contents to collection
  239.          IBaseListBox::Cursor cursor (fdialog.flist,
  240.                                       IBaseListBox::Cursor::allItems );
  241.          fdialog.ffilterset.removeAll();
  242.          for (cursor.setToFirst(); cursor.isValid(); cursor.setToNext() )
  243.             {
  244.             fdialog.ffilterset.add( fdialog.flist.elementAt(cursor) );
  245.             }
  246.          }
  247.          fdialog.dismiss();
  248.          break;
  249.       case  FLTD_CANCEL  :
  250.          fdialog.dismiss();
  251.          break;
  252.       default:
  253.          handled = false;
  254.       }
  255.  
  256.    return handled;
  257. }
  258.  
  259. /*------------------------------------------------------------------------------
  260. | IBase::Boolean FilterSelectHandler::enter                                    |
  261. ------------------------------------------------------------------------------*/
  262. IBase::Boolean FilterSelectHandler::enter    ( IControlEvent& event )
  263. {
  264.  
  265.    return false;
  266. }
  267.  
  268. /*------------------------------------------------------------------------------
  269. | IBase::Boolean FilterSelectHandler::selected                                 |
  270. ------------------------------------------------------------------------------*/
  271. IBase::Boolean FilterSelectHandler::selected ( IControlEvent& event )
  272. {
  273.    // make include/exclude match button
  274.    Boolean excluded = fdialog.fisExclude.isSelected();
  275.    if ((excluded && !fdialog.ffilterset.isExcludeList)  ||
  276.        (!excluded && fdialog.ffilterset.isExcludeList) )
  277.       {
  278.       fdialog.ffilterset.isExcludeList = excluded;
  279.       if (excluded)
  280.          fdialog.flabel.setText  ( IResourceId( FLTD_LABEL1 ) );
  281.       else
  282.          fdialog.flabel.setText  ( IResourceId( FLTD_LABEL0 ) );
  283.       }
  284.  
  285.    // enable/disable the remove button
  286.    if (fdialog.flist.numberOfSelections() != 0)
  287.       {
  288.       fdialog.fremove.enable();
  289.       }
  290.    else
  291.       {
  292.       fdialog.fremove.disable();
  293.       }
  294.    return false;
  295. }
  296.  
  297. /*------------------------------------------------------------------------------
  298. | IBase::Boolean FilterEditHandler::edit                                       |
  299. ------------------------------------------------------------------------------*/
  300. IBase::Boolean FilterEditHandler::edit ( IControlEvent& event )
  301. {
  302.    // if there is text in the entry field enable the add button
  303.    if (fdialog.fentry.textLength() != 0)
  304.       {
  305.       if ( !fdialog.fadd.isEnabled() )
  306.          {
  307.          if (fdialog.fok.isDefault() )
  308.             fdialog.fok.disableDefault();
  309.          fdialog.fadd.enable();
  310.          fdialog.fadd.enableDefault();
  311.          }
  312.       }
  313.    else
  314.       {
  315.       fdialog.fadd.disable();
  316.       fdialog.fadd.disableDefault();
  317.       fdialog.fok.enableDefault();
  318.       }
  319.    return false;
  320. }
  321.  
  322.