home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / ui / strview.h < prev    next >
C/C++ Source or Header  |  1995-04-08  |  6KB  |  238 lines

  1.  
  2. #ifndef _strview_h_
  3. #define _strview_h_
  4.  
  5.  
  6.  
  7.  
  8.  
  9. /*
  10.  *
  11.  *          Copyright (C) 1994, M. A. Sridhar
  12.  *  
  13.  *
  14.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  15.  *     to copy, modify or distribute this software  as you see fit,
  16.  *     and to use  it  for  any  purpose, provided   this copyright
  17.  *     notice and the following   disclaimer are included  with all
  18.  *     copies.
  19.  *
  20.  *                        DISCLAIMER
  21.  *
  22.  *     The author makes no warranties, either expressed or implied,
  23.  *     with respect  to  this  software, its  quality, performance,
  24.  *     merchantability, or fitness for any particular purpose. This
  25.  *     software is distributed  AS IS.  The  user of this  software
  26.  *     assumes all risks  as to its quality  and performance. In no
  27.  *     event shall the author be liable for any direct, indirect or
  28.  *     consequential damages, even if the  author has been  advised
  29.  *     as to the possibility of such damages.
  30.  *
  31.  */
  32.  
  33.  
  34.  
  35.  
  36. #if defined(__GNUC__)
  37. #pragma interface
  38. #endif
  39.  
  40.  
  41. #include "base/intset.h"
  42. #include "base/integer.h"
  43.  
  44. #include "ui/simple.h"
  45. #include "ui/strseq.h"
  46.  
  47.  
  48. //  This class provides a pictorial representation of a string sequence. One
  49. //  or more strings in the sequence may be selected by either an explicit
  50. //  call to the method Select() or by the {\small\tt Event_LButtonPress}.
  51. //  A mouse click 
  52. //  on an unselected string selects it while that on a selected string
  53. //  unselects it.
  54.  
  55.  
  56.  
  57.  
  58. class CL_EXPORT UI_StringView: public UI_SimpleVObject {
  59.  
  60.  
  61. public:
  62.     virtual long  TopIndex () const;
  63.     // Return the index of the topmost visible string in the view.
  64.  
  65.     virtual short VisibleCount () const;
  66.     // Return the number of visible strings. [Not yet implemented under
  67.     // OS/2.]
  68.     
  69.     virtual void  ScrollTo (long index);
  70.     // Scroll the view so that the String at the given index is at the top.
  71.     
  72.  
  73.     virtual void MakeInvisible ();
  74.     // Override inherited method.
  75.     
  76.     virtual void MakeVisible ();
  77.     // Override inherited method.
  78.     
  79.  
  80.  
  81.  
  82.     // ---------------- Overridden SimpleVObject methods -------------
  83.  
  84.     virtual UI_WindowClass WindowClass () const;
  85.  
  86.     // ---------------- Overridden basic methods ---------------------
  87.     
  88.     const char* ClassName () const { return "UI_StringView";};
  89.  
  90. protected:
  91.  
  92.     UI_StringView (UI_VObjCollection* parent, UI_StringSequence* model,
  93.                    const UI_Rectangle& shape,
  94.                    bool multiple_select = FALSE,
  95.                    UI_ViewID id = -1, long style = -1);
  96.     // Model not owned
  97.  
  98.     UI_StringView (UI_VObjCollection* parent,  
  99.                    const UI_Rectangle& shape, bool multiple_select = FALSE,
  100.                    UI_ViewID id = -1, long style = -1);
  101.     // Model owned
  102.  
  103.  
  104. #if defined(__MS_WINDOWS__)
  105.     UI_StringView (UI_CompositeVObject* parent, UI_ViewID id,
  106.                    UI_ViewHandle h);
  107.     // [MS-Windows-specific] Resource-based construction.
  108.  
  109. #endif
  110.     
  111.  
  112.     virtual void _UpdateSelection () = 0;
  113.     // Called by {\tt ItemInserted} and {\tt ItemRemoved} to tell us
  114.     // to update our selection.
  115.  
  116.     // ---------------- Overridden VisualObject methods --------------
  117.  
  118.     ~UI_StringView ();
  119.  
  120.     bool MakeVisualElement ();
  121.     
  122.     void _PrivateInitialize ();
  123.  
  124.  
  125.  
  126.  
  127. #if defined (__X_MOTIF__)
  128.  
  129.     static void Callback (struct _WidgetRec*, void *, void *);
  130.  
  131.     virtual void _SetupStyle (void* arg, short& argn);
  132.     // [YACL internal use only] X-windows-specific.
  133.  
  134.     UI_ViewHandle  _frame;
  135.     
  136. #endif
  137.  
  138.     bool           _multiple;
  139.  
  140.  
  141. public:
  142.     virtual void ItemInserted (long pos);
  143.     //  [YACL internal use only] Called by the model to notify this view
  144.     //  that the model just added a new item immediately  after the given
  145.     //  position.
  146.  
  147.     virtual void ItemRemoved (long);
  148.     // [YACL internal use only]
  149.  
  150.     virtual void ItemChanged (long);
  151.     // [YACL internal use only]
  152.  
  153.     virtual void ModelEmptied ();
  154.     // [YACL internal use only]
  155.     
  156.     virtual bool _SelectionChanged (CL_Object&, long) = 0;
  157.     // [YACL internal use only] Called by the selection when it is modified
  158.     // by the application.
  159.     
  160. };
  161.  
  162.  
  163.  
  164.  
  165. class CL_EXPORT UI_StringViewSingleSel: public UI_StringView {
  166.  
  167. public:
  168.     UI_StringViewSingleSel (UI_VObjCollection* parent,  
  169.                             const UI_Rectangle& shape,
  170.                             UI_ViewID id = -1);
  171.     // Model owned
  172.  
  173.     UI_StringViewSingleSel
  174.         (UI_VObjCollection* parent, UI_StringSequence* model,
  175.          const UI_Rectangle& shape, UI_ViewID id = -1);
  176.     // Model not owned
  177.  
  178. #if defined(__MS_WINDOWS__)
  179.     UI_StringViewSingleSel (UI_CompositeVObject* parent, UI_ViewID id,
  180.                             UI_ViewHandle h);
  181.     // [MS-Windows-specific] Resource-based construction.
  182.     
  183. #endif
  184.  
  185.     CL_Integer& Selection () {return _selection;};
  186.     // Return the index of the currently selected string. This index is -1
  187.     // if no string is currently selected. The return value may be assigned
  188.     // to, thus modifying the selection.
  189.     
  190. protected:
  191.     bool Select ();
  192.  
  193.     bool _SelectionChanged (CL_Object&, long);
  194.  
  195.     void _UpdateSelection ();
  196.     
  197.     CL_Integer _selection;
  198. };
  199.  
  200.  
  201.  
  202. class CL_EXPORT UI_StringViewMultiSel: public UI_StringView {
  203.  
  204. public:
  205.     UI_StringViewMultiSel (UI_VObjCollection* parent,  
  206.                            const UI_Rectangle& shape,
  207.                            UI_ViewID id = -1);
  208.     // Model owned
  209.  
  210.     UI_StringViewMultiSel (UI_VObjCollection* parent,
  211.                            UI_StringSequence* model,
  212.                            const UI_Rectangle& shape, UI_ViewID id = -1);
  213.     // Model not owned
  214.  
  215. #if defined(__MS_WINDOWS__)
  216.     UI_StringViewMultiSel (UI_CompositeVObject* parent, UI_ViewID id,
  217.                            UI_ViewHandle h);
  218.     // [MS-Windows-specific] Resource-based construction
  219.  
  220. #endif
  221.  
  222.     CL_IntegerSet& Selection () {return _selection;};
  223.     // Return the set of indices of strings that are currently selected. The
  224.     // return value may be assigned to, thus modifying the selection.
  225.     
  226. protected:
  227.     bool Select ();
  228.  
  229.     bool _SelectionChanged (CL_Object&, long);
  230.     
  231.     void _UpdateSelection ();
  232.     
  233.     CL_IntegerSet _selection;
  234. };
  235.  
  236.  
  237. #endif
  238.