home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / listpm4.zip / source / list.hpp < prev    next >
C/C++ Source or Header  |  1998-04-22  |  8KB  |  254 lines

  1. /*
  2.     listPM list files under Presentation Manager. Uses Open Class Libarary.
  3.     Copyright (C) 1998  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.     11900 Metric Blvd #J-181
  21.     Austin Tx 78758-3117
  22.     pelliott@io.com
  23. */
  24. #ifndef LIST
  25. #define LIST
  26.  
  27. #include "listrun.hpp"         // parameters of the interface with our caller,
  28.                                // listmain.
  29. #include "search.hpp"          // search dialog.
  30. #include "winthr.hpp"          // window thread processing.
  31.  
  32.                                // all open class libarary needed include files.
  33. #include <ithread.hpp>         // uses threads.
  34. #include <iframe.hpp>          // frame window
  35. #include <icmdhdr.hpp>         // command handler
  36. #include <iclipbrd.hpp>        // clipboard.
  37. #include <imle.hpp>            // multiline edit.
  38. #include <imsgbox.hpp>         // message box.
  39. #include <iexcbase.hpp>        // exceptions.
  40. #include <iinfoa.hpp>          // info area.
  41. #include <iaccel.hpp>          // keyboard accelerator.
  42. #include <ifiledlg.hpp>        // file dialog.
  43. #include <ifilehdr.hpp>        // file dialog handler.
  44. #include <imenuhdr.hpp>        // menu handler.
  45. #include <isubmenu.hpp>        // submenus.
  46. #include <ititle.hpp>          // title bar.
  47. #include <ifont.hpp>           // font
  48. #include <ifontdlg.hpp>        // font dialog.
  49. #include <isizehdr.hpp>        // Resize handler.
  50. #include <isizeevt.hpp>        // resize events.
  51. #include <ihelp.hpp>           // help Window.
  52. #include <ihelphdr.hpp>        // help window handler.
  53. #include <i0string.hpp>        // i0string.
  54.  
  55. #include <stdlib.h>            // define calls to C libarary
  56. #include <io.h>
  57.  
  58. /*
  59.  * This program is not an object oriented program,
  60.  * but a procedural one. Inheritance is used only as required to
  61.  * define callbacks required by the interface to open class libaray.
  62.  *
  63.  * This program displays a window in which the listing of a file can be
  64.  *  displayed.
  65.  * the user can switch displayed files, display a new file in a new window
  66.  * on another thread, control word wrap, and cut selected text to the system
  67.  * clippboard.
  68.  */
  69.  
  70. class ListWindowThread : public WindowThread
  71. {
  72.      private:
  73.  
  74.         // disable, declare but no define.
  75.         ListWindowThread(const ListWindowThread&);
  76.         ListWindowThread& operator=(const ListWindowThread&);
  77.  
  78.         // all varriables shared between the various search routines
  79.  
  80.  
  81.         // get text to search for
  82.         IString search_string;
  83.  
  84.         // get exact case match parameter.
  85.         Boolean exact;
  86.  
  87.         // get direction of search.
  88.         Boolean forward;
  89.  
  90.         IString looked_for;              // looking for this string.
  91.  
  92.         // direction sign is +- 1. direction mult is 0 or 1.
  93.         int direction_sign,direction_mult;
  94.  
  95.         unsigned long limit;              // last line to look at.
  96.  
  97.         // search member function forward or reverse?
  98.         // dir_search is a pointer to memeber which will be
  99.         // setup to do the search in the correct direction
  100.         // depending on direction. indexOf for forward.
  101.         // last indexOf for reverse.
  102.         unsigned (I0String::*dir_search)
  103.            (const IString& astring , unsigned startPos ) const;
  104.  
  105.         // default value 2nd par in above depends on direction!
  106.         unsigned start_pos;
  107.  
  108.         unsigned long current_line_no;
  109.  
  110.         unsigned long current_pos;
  111.  
  112.         unsigned long current_bol;
  113.  
  114.         unsigned offset_within_current_line;
  115.  
  116.         I0String current_line;
  117.  
  118.         // offset of cursor within 1st line.
  119.         unsigned offset;
  120.  
  121.         I0String line;
  122.  
  123.         unsigned long line_no;
  124.  
  125.         IString saved_text;
  126.  
  127.  
  128.         IInfoArea&   info;                  // info area status block
  129.  
  130.         IMultiLineEdit& mle;                // multiline editor cleint window.
  131.  
  132.  
  133.  
  134.      protected:
  135.        // optional call back to user before running thread.
  136.        virtual void begin();
  137.  
  138.        // code to run on other thread.
  139.        virtual void thread();
  140.  
  141.        // optional call back to user after running thread.
  142.        virtual void finish();
  143.  
  144.  
  145.      public:
  146.  
  147.       // construct a windows threader to search for text.
  148.       // save info area, mle, window, and command id to use later.
  149.       ListWindowThread(IWindow& window,const long eventid ,
  150.                        IMultiLineEdit& mle,
  151.                        IInfoArea&   info)
  152.  
  153.  
  154.       : mle(mle), info(info),
  155.         WindowThread(window,eventid)
  156.       {};
  157.       virtual ~ListWindowThread() {};
  158.  
  159.       // initialize threaded searcher and start
  160.       // initialize search parameters and start the thread.
  161.       void init_and_start(
  162.              IString& search_string_r, Boolean exact_v, Boolean forward_v)
  163.       {
  164.          // save the search parameters.
  165.          search_string = search_string_r;
  166.          exact = exact_v;
  167.          forward = forward_v;
  168.  
  169.          // and start the thread.
  170.          win_th_start( true );
  171.       };
  172. };
  173.  
  174.  
  175. // Define the main frame window for the program.
  176. // It has attacthed almost all control and call back structures attached.
  177. class ListFrame : public IFrameWindow ,
  178.                   // following protected handlers define call backs
  179.                   // required by Open class library.
  180.  
  181.                   protected ICommandHandler,
  182.                   protected IMenuHandler,
  183.                   protected IResizeHandler,
  184.                   protected IHelpHandler
  185. {
  186.    private:
  187.  
  188.       IString file_displayed;            // remember file we are dispalying
  189.  
  190.       IInfoArea   info;                  // info area status block
  191.  
  192.       IMultiLineEdit mle;                // multiline editor cleint window.
  193.  
  194.       IAccelerator acc;                   // key board accelerator,
  195.                                           // works with menu
  196.                                           // resources defined by URE.
  197.  
  198.       ITitle title;                       // Title for our window.
  199.  
  200.       IHelpWindow  help;                  // is there help for us?
  201.  
  202.  
  203.       SearchInfo         search_dialog;   // dialog to get search information.
  204.  
  205.       // starts threads for searching.
  206.       ListWindowThread   win_thread;       // window thread caller.
  207.  
  208.  
  209.       // disable default constructor, assignment op.
  210.       ListFrame(const ListFrame&);
  211.       ListFrame& operator=(const ListFrame&);
  212.  
  213.       unsigned long import( const char * file);
  214.                                             // import after checking format.
  215.       void setTaskList( const IString& myFile );
  216.                                             // set task list
  217.  
  218.    public:
  219.  
  220.  
  221.       // return currently  displayed file.
  222.       IString file(void) const { return file_displayed; };
  223.  
  224.       ListFrame(const IString file);      // construct ourselves from filename.
  225.       virtual ~ListFrame()
  226.       {
  227. //        close();
  228.       };
  229.  
  230.    protected:
  231.  
  232.       // command handler, handles all ICommandEvents for our window.
  233.       // called when user selects an item or accelerator command.
  234.  
  235.       virtual Boolean command( ICommandEvent& event );
  236.  
  237.  
  238.       // This menu handler gets control when Word wrap submenu is activated.
  239.       // inusres right option is checked.
  240.  
  241.       virtual Boolean menuShowing ( IMenuEvent& event,ISubmenu& submenu);
  242.  
  243.  
  244.       // resize event handler, catches user resizeing frame window,
  245.       // storing new size.
  246.  
  247.       virtual Boolean windowResize(IResizeEvent& evt);
  248.  
  249.       // returns panel id.
  250.       virtual Boolean keysHelpId(IEvent& evt);
  251.  
  252. };
  253. #endif   //LIST
  254.