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

  1.  
  2.  
  3. #ifndef _stred_h_
  4. #define _stred_h_
  5.  
  6.  
  7.  
  8.  
  9.  
  10. /*
  11.  *
  12.  *          Copyright (C) 1994, M. A. Sridhar
  13.  *  
  14.  *
  15.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  16.  *     to copy, modify or distribute this software  as you see fit,
  17.  *     and to use  it  for  any  purpose, provided   this copyright
  18.  *     notice and the following   disclaimer are included  with all
  19.  *     copies.
  20.  *
  21.  *                        DISCLAIMER
  22.  *
  23.  *     The author makes no warranties, either expressed or implied,
  24.  *     with respect  to  this  software, its  quality, performance,
  25.  *     merchantability, or fitness for any particular purpose. This
  26.  *     software is distributed  AS IS.  The  user of this  software
  27.  *     assumes all risks  as to its quality  and performance. In no
  28.  *     event shall the author be liable for any direct, indirect or
  29.  *     consequential damages, even if the  author has been  advised
  30.  *     as to the possibility of such damages.
  31.  *
  32.  */
  33.  
  34.  
  35.  
  36.  
  37.  
  38. // This SimpleVObject is  designed to support the  editing of a single line
  39. // of text  contained in its model, which  is a {\small\tt  CL_String}. The
  40. // selection on the model is a {\small\tt CL_Interval}, i.e., the positions
  41. // of the left and right ends of the substring currently selected.
  42.  
  43.  
  44. #if defined(__GNUC__)
  45. #pragma interface
  46. #endif
  47.  
  48.  
  49. #include "ui/simple.h"
  50. #include "ui/interval.h"
  51.  
  52. class CL_EXPORT UI_StringEditor: public UI_SimpleVObject {
  53.  
  54. public:
  55.  
  56.     //
  57.     // Construction:
  58.     //
  59.  
  60.     UI_StringEditor (UI_CompositeVObject* parent, const UI_Rectangle& shape,
  61.                      UI_ViewID id=-1, long style=-1);
  62.     // Own model
  63.  
  64.     UI_StringEditor (UI_CompositeVObject* parent, CL_String* model,
  65.                      const UI_Rectangle& shape,
  66.                      UI_ViewID id=-1, long style=-1);
  67.     // Not own model
  68.  
  69. #if defined(__MS_WINDOWS__)
  70.     UI_StringEditor (UI_CompositeVObject* parent, UI_ViewID id,
  71.                      UI_ViewHandle h); 
  72.     // Resource-based construction: only under MS-Windows
  73.  
  74. #endif
  75.  
  76.     CL_Object& Model ();
  77.     // Override the inherited method. Applications should not remember the
  78.     // pointer returned by this method; instead, they should call this
  79.     // method explicitly just before the data is needed, even if the
  80.     // application owns the model.
  81.     
  82.     virtual CL_Interval& Selection ();
  83.     // Return a {\tt CL_Interval} containing the range of positions
  84.     // selected. Modifying the return value causes a corresponding setting
  85.     // of selection in the displayed string.
  86.  
  87.     virtual bool SetLengthLimit (long n);
  88.     // Make the StringEditor enforce a  limit user type-in to $n$
  89.     // characters.
  90.  
  91.     virtual long LengthLimit () const;
  92.     // Return the current length limit. Returns -1 if there is no explicit
  93.     // limit.
  94.  
  95.     
  96.     const char* ClassName() const {return "UI_StringEditor";};
  97.  
  98.  
  99.  
  100.     virtual UI_WindowClass WindowClass () const;
  101.     
  102. protected:
  103.     
  104.     void _PrivateInitialize ();
  105.   
  106.     bool _ModelChanged (CL_Object&, long);
  107.     // For YACL internal use only.
  108.   
  109.     bool _TitleChanged (CL_Object&, long) {return TRUE;};
  110.     // String editors don't have titles. If we don't override it this way,
  111.     // things don't work right under OS/2.
  112.     
  113.     //  Instance Variables:
  114.  
  115.     CL_Interval _selection;
  116.     long        _limit;
  117.  
  118. #if defined(__X_MOTIF__)
  119.     void _SetupStyle (void* arg, short& argn);
  120.     // Motif-specific; for YACL internal use only.
  121.  
  122. #endif
  123.  
  124. private:
  125.     virtual bool _SelectionChanged (CL_Object&, long);
  126.     // Called when the application modifies the return value of the
  127.     // Selection() method.
  128.     
  129. };
  130.  
  131.  
  132.  
  133.  
  134. inline long UI_StringEditor::LengthLimit () const
  135. {
  136.     return _limit;
  137. }
  138.  
  139.  
  140. #endif
  141.