home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / listpm7.zip / list.hpp < prev    next >
C/C++ Source or Header  |  1999-07-19  |  11KB  |  334 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. #ifndef LIST
  26. #define LIST
  27.  
  28. #include "listrun.hpp"         // parameters of the interface with our caller,
  29.                                // listmain.
  30. #include "search.hpp"          // search dialog.
  31. #include "winthr.hpp"          // window thread processing.
  32.  
  33.                                // all open class libarary needed include files.
  34. #include <ithread.hpp>         // uses threads.
  35. #include <iframe.hpp>          // frame window
  36. #include <icmdhdr.hpp>         // command handler
  37. #include <ifocshdr.hpp>        // focus handler
  38. #include <iclipbrd.hpp>        // clipboard.
  39. #include <imle.hpp>            // multiline edit.
  40. #include <imsgbox.hpp>         // message box.
  41. #include <iexcbase.hpp>        // exceptions.
  42. #include <iinfoa.hpp>          // info area.
  43. #include <iaccel.hpp>          // keyboard accelerator.
  44. #include <ifiledlg.hpp>        // file dialog.
  45. #include <ifilehdr.hpp>        // file dialog handler.
  46. #include <imenuhdr.hpp>        // menu handler.
  47. #include <isubmenu.hpp>        // submenus.
  48. #include <ititle.hpp>          // title bar.
  49. #include <ifont.hpp>           // font
  50. #include <ifontdlg.hpp>        // font dialog.
  51. #include <isizehdr.hpp>        // Resize handler.
  52. #include <isizeevt.hpp>        // resize events.
  53. #include <ihelp.hpp>           // help Window.
  54. #include <ihelphdr.hpp>        // help window handler.
  55. #include <i0string.hpp>        // i0string.
  56.  
  57. #include <stdlib.h>            // define calls to C libarary
  58. #include <io.h>
  59.  
  60. /*
  61.  * This program is not an object oriented program,
  62.  * but a procedural one. Inheritance is used only as required to
  63.  * define callbacks required by the interface to open class libaray.
  64.  *
  65.  * This program displays a window in which the listing of a file can be
  66.  *  displayed.
  67.  * the user can switch displayed files, display a new file in a new window
  68.  * on another thread, control word wrap, and cut selected text to the system
  69.  * clippboard.
  70.  */
  71.  
  72. class ListWindowThread : public WindowThread
  73. {
  74.      private:
  75.  
  76.         // disable, declare but no define.
  77.         ListWindowThread(const ListWindowThread&);
  78.         ListWindowThread& operator=(const ListWindowThread&);
  79.  
  80.         // all varriables shared between the various search routines
  81.  
  82.  
  83.         // get text to search for
  84.         IString search_string;
  85.  
  86.         // get exact case match parameter.
  87.         Boolean exact;
  88.  
  89.         // get direction of search.
  90.         Boolean forward;
  91.  
  92.         IString looked_for;              // looking for this string.
  93.  
  94.         // direction sign is +- 1. direction mult is 0 or 1.
  95.         int direction_sign,direction_mult;
  96.  
  97.         unsigned long limit;              // last line to look at.
  98.  
  99.         // search member function forward or reverse?
  100.         // dir_search is a pointer to memeber which will be
  101.         // setup to do the search in the correct direction
  102.         // depending on direction. indexOf for forward.
  103.         // last indexOf for reverse.
  104.         unsigned (I0String::*dir_search)
  105.            (const IString& astring , unsigned startPos ) const;
  106.  
  107.         // default value 2nd par in above depends on direction!
  108.         unsigned start_pos;
  109.  
  110.         unsigned long current_line_no;
  111.  
  112.         unsigned long current_pos;
  113.  
  114.         unsigned long current_bol;
  115.  
  116.         unsigned offset_within_current_line;
  117.  
  118.         I0String current_line;
  119.  
  120.         // offset of cursor within 1st line.
  121.         unsigned offset;
  122.  
  123.         I0String line;
  124.  
  125.         unsigned long line_no;
  126.  
  127.         IString saved_text;
  128.  
  129.  
  130.         IInfoArea&   info;                  // info area status block
  131.  
  132.         IMultiLineEdit& mle;                // multiline editor cleint window.
  133.  
  134.  
  135.  
  136.      protected:
  137.        // optional call back to user before running thread.
  138.        virtual void begin();
  139.  
  140.        // code to run on other thread.
  141.        virtual void thread();
  142.  
  143.        // optional call back to user after running thread.
  144.        virtual void finish();
  145.  
  146.  
  147.      public:
  148.  
  149.       // construct a windows threader to search for text.
  150.       // save info area, mle, window, and command id to use later.
  151.       ListWindowThread(IWindow& window,const long eventid ,
  152.                        IMultiLineEdit& mle,
  153.                        IInfoArea&   info)
  154.  
  155.  
  156.       : mle(mle), info(info),
  157.         WindowThread(window,eventid)
  158.       {};
  159.       virtual ~ListWindowThread() {};
  160.  
  161.       // initialize threaded searcher and start
  162.       // initialize search parameters and start the thread.
  163.       void init_and_start(
  164.              IString& search_string_r, Boolean exact_v, Boolean forward_v)
  165.       {
  166.          // save the search parameters.
  167.          search_string = search_string_r;
  168.          exact = exact_v;
  169.          forward = forward_v;
  170.  
  171.          // and start the thread.
  172.          win_th_start( true );
  173.       };
  174. };
  175.  
  176.  
  177. // Define the main frame window for the program.
  178. // It has attacthed almost all control and call back structures attached.
  179. class ListFrame : public IFrameWindow ,
  180.                   // following protected handlers define call backs
  181.                   // required by Open class library.
  182.                   protected ICommandHandler,
  183.                   protected IMenuHandler,
  184.                   protected IResizeHandler,
  185.                   protected IHelpHandler,
  186.                   protected IFocusHandler
  187. {
  188.    private:
  189.  
  190.       IString file_displayed;            // remember file we are dispalying
  191.  
  192.       IInfoArea   info;                  // info area status block
  193.  
  194.       IMultiLineEdit mle;                // multiline editor cleint window.
  195.  
  196.       // Do not need to access the accelerator, the accelerator attribute insures that there is one (hidden)
  197.       //IAccelerator acc;                 // key board accelerator,
  198.                                           // works with menu
  199.                                           // resources defined by URE.
  200.  
  201.       ITitle title;                       // Title for our window.
  202.  
  203.       IHelpWindow  help;                  // is there help for us?
  204.  
  205.  
  206.       SearchInfo         search_dialog;   // dialog to get search information.
  207.  
  208.       // starts threads for searching.
  209.       ListWindowThread   win_thread;       // window thread caller.
  210.  
  211.  
  212.       // disable default constructor, assignment op.
  213.       ListFrame(const ListFrame&);
  214.       ListFrame& operator=(const ListFrame&);
  215.  
  216.       unsigned long import( const char * file);
  217.                                             // import after checking format.
  218.       void setTaskList( const IString& myFile );
  219.                                             // set task list
  220.    public:
  221.       // types of various member functions
  222.       typedef ITitle& ( ITitle::*titleSetColor) ( const IColor& color);
  223.       typedef ITitle& ( ITitle::*titleResetColor) ( );
  224.       typedef IWindow& ( IMultiLineEdit::*mleSetColor) ( const IColor& color);
  225.       typedef IWindow& ( IMultiLineEdit::*mleResetColor) ( );
  226.       typedef IWindow& ( ITitle::*titlebSetColor) ( const IColor& color);
  227.       typedef IWindow& ( ITitle::*titlebResetColor) ( );
  228.       typedef IWindow& ( IFrameWindow::*frameSetColor) ( const IColor& color);
  229.       typedef IWindow& ( IFrameWindow::*frameResetColor) ( );
  230.  
  231.       typedef IFrameWindow& ( IFrameWindow::*frameframeResetColor) ( );
  232.  
  233.       typedef IWindow& ( IWindow::*windowSetColor) ( const IColor& color);
  234.       typedef IWindow& ( IWindow::*windowResetColor) ( );
  235.  
  236.       typedef ListFrame& ( ListFrame::*listSetColor) ( const IColor& color);
  237.       typedef ListFrame& ( ListFrame::*listResetColor) ( );
  238.    private:
  239.       // templates for creating member functions all of the same type.
  240.       // input parameter is a member function of ListFrame in larger sense
  241.       template< titleSetColor colorSetFunc> ListFrame& setColor( const IColor& color )
  242.       {
  243.          (title.*colorSetFunc) ( color );
  244.          return *this;
  245.       };
  246.       template< titleResetColor recolorSetFunc> ListFrame& resetColor( )
  247.       {
  248.          (title.*recolorSetFunc) (  );
  249.          return *this;
  250.       };
  251.  
  252.  
  253.       template< windowSetColor colorSetFunc> ListFrame& setTitlebColor( const IColor& color )
  254.       {
  255.          (title.*colorSetFunc) ( color );
  256.          return *this;
  257.       };
  258.       template< windowResetColor recolorSetFunc> ListFrame& resetTitlebColor( )
  259.       {
  260.          (title.*recolorSetFunc) (  );
  261.          return *this;
  262.       };
  263.  
  264.  
  265.       template< windowSetColor colorSetFunc> ListFrame& setMleColor( const IColor& color )
  266.       {
  267.          (mle.*colorSetFunc) ( color );
  268.          return *this;
  269.       };
  270.       template< windowResetColor recolorSetFunc> ListFrame& resetMleColor( )
  271.       {
  272.          (mle.*recolorSetFunc) (  );
  273.          return *this;
  274.       };
  275.  
  276.  
  277.       template< windowSetColor colorSetFunc> ListFrame& setFrameColor( const IColor& color )
  278.       {
  279.          (this->*colorSetFunc) ( color );
  280.          return *this;
  281.       };
  282.       template< windowResetColor recolorSetFunc> ListFrame& resetFrameColor( )
  283.       {
  284.          (this->*recolorSetFunc) (  );
  285.          return *this;
  286.       };
  287.       template< frameframeResetColor recolorSetFunc> ListFrame& resetFrameColor( )
  288.       {
  289.          (this->*recolorSetFunc) (  );
  290.          return *this;
  291.       };
  292.  
  293.       // list of member functions
  294.  
  295.       static const listSetColor list_set_colors[];
  296.       static const listResetColor list_reset_colors[];
  297.  
  298.    public:
  299.  
  300.  
  301.       // return currently  displayed file.
  302.       IString file(void) const { return file_displayed; };
  303.  
  304.       ListFrame(const IString file);      // construct ourselves from filename.
  305.       virtual ~ListFrame()
  306.       {
  307. //        close();
  308.       };
  309.  
  310.    protected:
  311.  
  312.       // command handler, handles all ICommandEvents for our window.
  313.       // called when user selects an item or accelerator command.
  314.  
  315.       virtual Boolean command( ICommandEvent& event );
  316.  
  317.       virtual bool gotFocus( IControlEvent& ce);
  318.  
  319.       // This menu handler gets control when Word wrap submenu is activated.
  320.       // inusres right option is checked.
  321.  
  322.       virtual Boolean menuShowing ( IMenuEvent& event,ISubmenu& submenu);
  323.  
  324.  
  325.       // resize event handler, catches user resizeing frame window,
  326.       // storing new size.
  327.  
  328.       virtual Boolean windowResize(IResizeEvent& evt);
  329.  
  330.       // returns panel id.
  331.       virtual Boolean keysHelpId(IEvent& evt);
  332.  
  333. };
  334. #endif   //LIST