home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / listpm7.zip / search.cpp < prev    next >
C/C++ Source or Header  |  1999-06-27  |  4KB  |  129 lines

  1. /*
  2.     listPM list files under Presentation Manager. Uses Open Class Libarary.
  3.     Copyright (C) 1998, 1999  Paul Elliott
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.     Paul Elliott
  20.     PMB # 181
  21.     11900 Metric Blvd Ste. J
  22.     Austin Tx 78758-3117
  23.     pelliott@io.com
  24. */
  25. #include "search.hpp"
  26.  
  27. #include "listpm.h"
  28.  
  29. SearchInfo::SearchInfo(IWindow & owner , IHelpWindow & help) :
  30. // set up the parts.
  31. IFrameWindow( DLG_SEARCHFORTEXT , &owner, IFrameWindow::tryDialogResource  ),
  32. search_text_field( ENT_TEXT ,this ),
  33. exact_box( BOX_CASE ,this ),
  34. forward( BUT_FORWARD, this ) ,
  35. reverse( BUT_REVERSE, this ) ,
  36. acc( DLG_SEARCHFORTEXT, this),
  37. fcshand(*this)
  38. {
  39.     // provide help for search dialog.
  40.     help.setAssociatedWindow( this );
  41.  
  42.      // set the focus to entry field.
  43.      search_text_field.setFocus();
  44.  
  45.      // select forward direction.
  46.      forward.select(true); reverse.select(false);
  47.  
  48.      forward.select();
  49.      forward.enableGroup();
  50.      forward.enableTabStop();
  51.  
  52.      reverse.enableTabStop();
  53.  
  54.      // disable this hidden dialog till it is requested.
  55.      disable();
  56.                                                // do not destroy on close.
  57.      setDestroyOnClose(false);                 // use dialog over and over.
  58.  
  59. };
  60.  
  61. Boolean SearchInfo::Exact(void)
  62. {                                              // exact case wanted
  63.      return exact_box.isSelected();
  64. };
  65. Boolean SearchInfo::DirectionForward(void)
  66. {                                              // forward direction selected.
  67.      return forward.isSelected();
  68. };
  69. SearchInfo::operator IString()
  70. {                                              // returns entry field text.
  71.      return search_text_field.text();
  72. };
  73.  
  74. // called when we get focus.
  75. bool SearchInfo::FocusHand::gotFocus( IControlEvent& ce )
  76. {
  77.  
  78.    // if the search field already has focus, skip.
  79.    if ( si.search_text_field.hasFocus() ) return IFocusHandler::gotFocus( ce );
  80.  
  81.    // when we get focus we post GOTFOCUS message.
  82.    si.postEvent( control, GOTFOCUS );
  83.  
  84.    return IFocusHandler::gotFocus( ce );
  85. };
  86.  
  87. // scans for ICommandEvent s
  88. bool SearchInfo::FocusHand::command( ICommandEvent& ce )
  89. {
  90.    switch ( ce.commandId() )
  91.    {
  92.       // when we set a GOT FOCUS command.
  93.       case GOTFOCUS:
  94.       // if the search_text_field does not already have focus,,,
  95.       if ( ! si.search_text_field.hasFocus() )
  96.       {
  97.          // select the range
  98.          si.search_text_field.selectRange();
  99.          // set the focus of the search_text_field.
  100.          si.search_text_field.setFocus();
  101.       };
  102.       break;
  103.    };
  104.    return ICommandHandler::command( ce );
  105. };
  106. IString SearchInfo::GetToBeSearched(void)      // display the dialog.
  107. {
  108.      // highlight all the current content of entry field
  109.      search_text_field.selectRange();
  110.  
  111.      // endable the dialog.
  112.      enable();
  113.  
  114.      // set focus to entry field.
  115.      search_text_field.setFocus();
  116.  
  117.      // simulate getting focus
  118.      postEvent( command, GOTFOCUS );
  119.  
  120.      // show dialog modally.
  121.      showModally();
  122.  
  123.      // hide and disable dialog again.
  124.      hide();
  125.      disable();
  126.  
  127.      return *this;
  128. };
  129.