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

  1.  
  2.  
  3.  
  4.  
  5. /*
  6.  *
  7.  *          Copyright (C) 1994, M. A. Sridhar
  8.  *  
  9.  *
  10.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  11.  *     to copy, modify or distribute this software  as you see fit,
  12.  *     and to use  it  for  any  purpose, provided   this copyright
  13.  *     notice and the following   disclaimer are included  with all
  14.  *     copies.
  15.  *
  16.  *                        DISCLAIMER
  17.  *
  18.  *     The author makes no warranties, either expressed or implied,
  19.  *     with respect  to  this  software, its  quality, performance,
  20.  *     merchantability, or fitness for any particular purpose. This
  21.  *     software is distributed  AS IS.  The  user of this  software
  22.  *     assumes all risks  as to its quality  and performance. In no
  23.  *     event shall the author be liable for any direct, indirect or
  24.  *     consequential damages, even if the  author has been  advised
  25.  *     as to the possibility of such damages.
  26.  *
  27.  */
  28.  
  29.  
  30. #if defined(__GNUC__)
  31. #pragma implementation
  32. #endif
  33.  
  34. #if defined(__MS_WINDOWS__)
  35. #include <windows.h>
  36. #elif defined(__X_MOTIF__)
  37. #include <Xm/Text.h>
  38. #endif
  39.  
  40.  
  41. #include "ui/textedit.h"
  42.  
  43. #if defined(__GNUC__)
  44. template class CL_Binding<UI_TextEditor>;
  45. #endif
  46.  
  47.  
  48.  
  49. UI_TextEditor::UI_TextEditor
  50.     (UI_CompositeVObject* parent, const UI_Rectangle& shape, UI_ViewID id)
  51. : UI_StringEditor (parent, shape, id, -1)
  52. {
  53. #if defined(__MS_WINDOWS__)
  54.     _style |= ES_MULTILINE | WS_VSCROLL;
  55. #elif defined(__OS2__)
  56.     _style = WS_VISIBLE | MLS_HSCROLL | MLS_VSCROLL | MLS_BORDER |
  57.         MLS_WORDWRAP;
  58. #endif
  59. }
  60.  
  61.  
  62. #if defined(__MS_WINDOWS__)
  63. UI_TextEditor::UI_TextEditor (UI_CompositeVObject* parent, UI_ViewID id,
  64.                UI_ViewHandle h)
  65. : UI_StringEditor (parent, id, h)
  66. {
  67. }
  68. #endif
  69.  
  70.  
  71. #if defined(__X_MOTIF__)
  72. void UI_TextEditor::_SetupStyle (void* p, short& argn)
  73. {
  74.     Arg* arg = (Arg*) p;
  75.     UI_SimpleVObject::_SetupStyle (arg, argn);
  76.     XtSetArg (arg[argn], XmNeditMode, XmMULTI_LINE_EDIT); argn++;
  77. }
  78.     
  79. #endif
  80.     
  81.  
  82.  
  83. UI_WindowClass UI_TextEditor::WindowClass () const
  84. {
  85. #if defined(__MS_WINDOWS__)
  86.     return "edit";
  87. #elif defined(__OS2__)
  88.     return WC_MLE;
  89. #elif defined(__X_MOTIF__)
  90.     return  xmTextWidgetClass;
  91. #endif
  92. }
  93.  
  94.  
  95. bool UI_TextEditor::SetLengthLimit (long n)
  96. {
  97. #if defined (__MS_WINDOWS__) || defined(__X_MOTIF__)
  98.     return UI_StringEditor::SetLengthLimit (n);
  99. #elif defined (__OS2__)
  100.     _limit = n;
  101.     if (_handle)
  102.         WinSendMsg (_handle, MLM_SETTEXTLIMIT, (MPARAM) n, 0);
  103.     return TRUE;
  104. #endif
  105. }
  106.  
  107.  
  108. #if defined(__OS2__)
  109. bool UI_TextEditor::_SelectionChanged (CL_Object&, long)
  110. {
  111.     if (_handle) {
  112.         WinSendMsg (_handle, MLM_SETSEL, (MPARAM)_selection.Low(),
  113.                     (MPARAM) (_selection.High()+1));
  114.     }
  115.     return TRUE;
  116. }
  117. #endif
  118.  
  119.  
  120. CL_Interval& UI_TextEditor::Selection ()
  121. {
  122. #if defined(__MS_WINDOWS__) || defined(__X_MOTIF__)
  123.     return UI_StringEditor::Selection ();
  124. #elif defined(__OS2__)
  125.     CL_Binding<UI_TextEditor> bind (this, &UI_TextEditor::_SelectionChanged);
  126.     _selection.RemoveDependent (bind);
  127.     MPARAM pos = WinSendMsg  (_handle, MLM_QUERYSEL, MLFQS_MINMAXSEL, 0);
  128.     _selection = CL_Interval (SHORT1FROMMP(pos), SHORT2FROMMP(pos)-1);
  129.     _selection.AddDependent (bind, 1);
  130.     return _selection;
  131. #endif
  132. }
  133.