You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

259 lines
7.0 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Turbo Vision - Version 2.0
  3. *
  4. * Copyright (c) 1994 by Borland International
  5. * All Rights Reserved.
  6. *
  7. Modified by Robert H�hne to be used for RHIDE.
  8. Heavily modified by Salvador E. Tropea to support multibyte encodings.
  9. Now the original TInputLine is composed by:
  10. TInputLineBase -> TInputLineBaseT<T,D> |-> TInputLine
  11. |-> TInputLineU16
  12. The template class is used to avoid maintaining two versions of the same
  13. code.
  14. Added: TInput1Line class by SET (based on TVTools idea).
  15. *
  16. *
  17. */
  18. /* ---------------------------------------------------------------------- */
  19. /* class TInputLine */
  20. /* */
  21. /* Palette layout */
  22. /* 1 = Passive */
  23. /* 2 = Active */
  24. /* 3 = Selected */
  25. /* 4 = Arrows */
  26. /* ---------------------------------------------------------------------- */
  27. #if defined( Uses_TInputLine ) && !defined( TInputLine_defined )
  28. #define TInputLine_defined
  29. class TRect;
  30. struct TEvent;
  31. class TValidator;
  32. class TInputLineBase : public TView
  33. {
  34. public:
  35. TInputLineBase(const TRect& bounds, int aMaxLen);
  36. ~TInputLineBase();
  37. virtual uint32 dataSize();
  38. virtual void getData(void *rec);
  39. virtual TPalette& getPalette() const;
  40. virtual void handleEvent(TEvent& event);
  41. void selectAll(Boolean enable);
  42. virtual void setState(ushort aState, Boolean enable);
  43. void SetValidator(TValidator *);
  44. virtual Boolean valid(ushort);
  45. virtual Boolean insertChar(unsigned val); // Added by SET
  46. virtual Boolean insertChar(TEvent &event)=0;
  47. virtual void assignPos(int index, unsigned val)=0;
  48. virtual Boolean pasteFromOSClipboard()=0;
  49. virtual void copyToOSClipboard()=0;
  50. virtual void setDataFromStr(void *str)=0;
  51. const void *getData() { return data; };
  52. int curPos;
  53. int firstPos;
  54. int selStart;
  55. int selEnd;
  56. static char rightArrow;
  57. static char leftArrow;
  58. static char orightArrow;
  59. static char oleftArrow;
  60. protected:
  61. virtual void resizeData() {}
  62. TValidator * validator;
  63. void deleteSelect();
  64. void makeVisible(); // Added by SET
  65. Boolean canScroll( int delta );
  66. // Inline helpers to make the code cleaner
  67. int insertModeOn();
  68. int lineIsFull();
  69. int posIsEnd();
  70. // IMHO exposing these two is a very bad idea, I added a couple of members to
  71. // work with them: setDataFromStr & getData. All TV code uses these new
  72. // members. If we don't hide them then we must compute the string length all
  73. // the time. SET.
  74. char *data;
  75. int maxLen;
  76. int cellSize;
  77. int dataLen;
  78. private:
  79. int mouseDelta( TEvent& event );
  80. int mousePos( TEvent& event );
  81. #if !defined( NO_STREAM )
  82. //virtual const char *streamableName() const
  83. // { return name; }
  84. protected:
  85. TInputLineBase(StreamableInit);
  86. virtual void write(opstream&);
  87. virtual void *read(ipstream&);
  88. virtual void writeData(opstream&)=0;
  89. virtual void *readData(ipstream&)=0;
  90. public:
  91. //static const char * const name;
  92. //static TStreamable *build();
  93. #endif // NO_STREAM
  94. };
  95. #if !defined( NO_STREAM )
  96. inline ipstream& operator >> ( ipstream& is, TInputLineBase& cl )
  97. { return is >> (TStreamable&)cl; }
  98. inline ipstream& operator >> ( ipstream& is, TInputLineBase*& cl )
  99. { return is >> (void *&)cl; }
  100. inline opstream& operator << ( opstream& os, TInputLineBase& cl )
  101. { return os << (TStreamable&)cl; }
  102. inline opstream& operator << ( opstream& os, TInputLineBase* cl )
  103. { return os << (TStreamable *)cl; }
  104. #endif // NO_STREAM
  105. inline
  106. int TInputLineBase::insertModeOn()
  107. {
  108. return (state & sfCursorIns)==0;
  109. }
  110. inline
  111. int TInputLineBase::lineIsFull()
  112. {
  113. return dataLen>=maxLen;
  114. }
  115. inline
  116. int TInputLineBase::posIsEnd()
  117. {
  118. return curPos>=dataLen;
  119. }
  120. template <typename T, typename D>
  121. class TInputLineBaseT: public TInputLineBase
  122. {
  123. public:
  124. TInputLineBaseT(const TRect& bounds, int aMaxLen);
  125. virtual void setData(void *rec);
  126. virtual void setDataFromStr(void *str);
  127. virtual void assignPos(int index, unsigned val);
  128. virtual Boolean pasteFromOSClipboard();
  129. virtual void copyToOSClipboard();
  130. virtual void draw();
  131. #if !defined( NO_STREAM )
  132. protected:
  133. TInputLineBaseT(StreamableInit) : TInputLineBase(streamableInit) {}
  134. virtual void writeData(opstream&);
  135. virtual void *readData(ipstream&);
  136. #endif // NO_STREAM
  137. };
  138. class TInputLine : public TInputLineBaseT<char,TDrawBuffer>
  139. {
  140. public:
  141. TInputLine(const TRect& bounds, int aMaxLen) :
  142. TInputLineBaseT<char,TDrawBuffer>(bounds,aMaxLen) {};
  143. virtual Boolean insertChar(TEvent &event);
  144. #if !defined( NO_STREAM )
  145. virtual const char *streamableName() const
  146. { return name; }
  147. protected:
  148. //TInputLine::TInputLine(StreamableInit) :
  149. TInputLine(StreamableInit) :
  150. TInputLineBaseT<char,TDrawBuffer>(streamableInit) {}
  151. public:
  152. static const char * const name;
  153. static TStreamable *build();
  154. #endif // NO_STREAM
  155. };
  156. #if !defined( NO_STREAM )
  157. inline ipstream& operator >> ( ipstream& is, TInputLine& cl )
  158. { return is >> (TStreamable&)cl; }
  159. inline ipstream& operator >> ( ipstream& is, TInputLine*& cl )
  160. { return is >> (void *&)cl; }
  161. inline opstream& operator << ( opstream& os, TInputLine& cl )
  162. { return os << (TStreamable&)cl; }
  163. inline opstream& operator << ( opstream& os, TInputLine* cl )
  164. { return os << (TStreamable *)cl; }
  165. #endif // NO_STREAM
  166. class TInputLineU16 : public TInputLineBaseT<uint16,TDrawBufferU16>
  167. {
  168. public:
  169. TInputLineU16(const TRect& bounds, int aMaxLen) :
  170. TInputLineBaseT<uint16,TDrawBufferU16>(bounds,aMaxLen) {};
  171. virtual Boolean insertChar(TEvent &event);
  172. #if !defined( NO_STREAM )
  173. virtual const char *streamableName() const
  174. { return name; }
  175. protected:
  176. TInputLineU16(StreamableInit) :
  177. TInputLineBaseT<uint16,TDrawBufferU16>(streamableInit) {}
  178. public:
  179. static const char * const name;
  180. static TStreamable *build();
  181. #endif // NO_STREAM
  182. };
  183. #if !defined( NO_STREAM )
  184. inline ipstream& operator >> ( ipstream& is, TInputLineU16& cl )
  185. { return is >> (TStreamable&)cl; }
  186. inline ipstream& operator >> ( ipstream& is, TInputLineU16*& cl )
  187. { return is >> (void *&)cl; }
  188. inline opstream& operator << ( opstream& os, TInputLineU16& cl )
  189. { return os << (TStreamable&)cl; }
  190. inline opstream& operator << ( opstream& os, TInputLineU16* cl )
  191. { return os << (TStreamable *)cl; }
  192. #endif // NO_STREAM
  193. #endif // Uses_TInputLine
  194. #if defined( Uses_TInput1Line ) && !defined( TInput1Line_defined )
  195. #define TInput1Line_defined
  196. // This is based on TVTools idea, but I think is better to implement it
  197. // in this way and not like a macro.
  198. class TInput1Line : public TInputLine
  199. {
  200. public:
  201. TInput1Line(int x, int y, int max) :
  202. TInputLine(TRect(x,y,x+max+2,y+1), max)) {};
  203. };
  204. class TInput1LineU16 : public TInputLineU16
  205. {
  206. public:
  207. TInput1LineU16(int x, int y, int max) :
  208. TInputLineU16(TRect(x,y,x+max+2,y+1), max)) {};
  209. }
  210. #endif // Uses_TInput1Line