edit.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19. //
  20. // Edit.H
  21. //
  22. // History:
  23. // 01/18/97 JMI Started tracking history of this file.
  24. // Converted Do() to take an RInputEvent* instead of a
  25. // long*.
  26. //
  27. // 01/21/97 JMI Added ReadMembers() and WriteMembers() overloads to read
  28. // and write members of this class.
  29. //
  30. // 03/14/97 JMI Added ClipCaret().
  31. //
  32. // 03/19/97 JMI Converted to using the RHot::m_iecUser (was using
  33. // RHot::m_epcUser) so HotCall and CursorEvent now take
  34. // RInputEvent ptrs.
  35. //
  36. // 08/25/97 JMI Added m_sFirstVisibleCharIndex which is the first visible
  37. // character in the field.
  38. //
  39. // 09/22/97 JMI Also, added friend class CEditPropPage for GUI
  40. // editor.
  41. //
  42. // 09/23/97 JMI Flags for m_sBehavior started at 0 instead of 1. Fixed.
  43. //
  44. //////////////////////////////////////////////////////////////////////////////
  45. //
  46. // See CPP for description.
  47. //
  48. //////////////////////////////////////////////////////////////////////////////
  49. #ifndef EDIT_H
  50. #define EDIT_H
  51. //////////////////////////////////////////////////////////////////////////////
  52. // Headers.
  53. //////////////////////////////////////////////////////////////////////////////
  54. #include "System.h"
  55. // If PATHS_IN_INCLUDES macro is defined, we can utilized relative
  56. // paths to a header file. In this case we generally go off of our
  57. // RSPiX root directory. System.h MUST be included before this macro
  58. // is evaluated. System.h is the header that, based on the current
  59. // platform (or more so in this case on the compiler), defines
  60. // PATHS_IN_INCLUDES. Blue.h includes system.h so you can include that
  61. // instead.
  62. #ifdef PATHS_IN_INCLUDES
  63. #include "ORANGE/GUI/txt.h"
  64. #else
  65. #include "txt.h"
  66. #endif // PATHS_IN_INCLUDES
  67. //////////////////////////////////////////////////////////////////////////////
  68. // Macros.
  69. //////////////////////////////////////////////////////////////////////////////
  70. //////////////////////////////////////////////////////////////////////////////
  71. // Typedefs.
  72. //////////////////////////////////////////////////////////////////////////////
  73. //////////////////////////////////////////////////////////////////////////////
  74. class REdit : public RTxt
  75. {
  76. public: // Construction/Destruction.
  77. // Default constructor.
  78. REdit(void);
  79. // Destructor.
  80. ~REdit(void);
  81. //////////////////////////////////////////////////////////////////////////////
  82. public: // Typedefs.
  83. typedef struct
  84. {
  85. short sX;
  86. short sY;
  87. } Point;
  88. typedef void (*EditNotifyCall)( // Called when a user input notification
  89. // should occur.
  90. REdit* pedit); // this.
  91. public: // Enums.
  92. enum // Values for member flags.
  93. {
  94. // Values for m_sBehavior.
  95. None = 0x0000,
  96. NumbersOnly = 0x0001, // Allow only numbers as input.
  97. Multiline = 0x0002 // Allow GK/SK_ENTER to cause CR/LF.
  98. };
  99. public: // Methods.
  100. ////////////////////////////////////////////////////////////////////////
  101. // Methods.
  102. ////////////////////////////////////////////////////////////////////////
  103. // Draw this item and all its subitems into the provided RImage.
  104. // This override adds in the caret.
  105. virtual // If you override this, call this base if possible.
  106. short Draw( // Returns 0 on success.
  107. RImage* pimDst, // Destination image.
  108. short sDstX = 0, // X position in destination.
  109. short sDstY = 0, // Y position in destination.
  110. short sSrcX = 0, // X position in source.
  111. short sSrcY = 0, // Y position in source.
  112. short sW = 0, // Amount to draw.
  113. short sH = 0, // Amount to draw.
  114. RRect* prc = NULL); // Clip to.
  115. // Draw text in m_szText in m_u32TextColor with transparent
  116. // background at sX, sY with sW and m_sJustification.
  117. // Does nothing if m_szText is empty.
  118. virtual // If you override this, call this base if possible.
  119. short DrawText( // Returns 0 on success.
  120. short sX, // X position in image.
  121. short sY, // Y position in image.
  122. short sW = 0, // Width of text area.
  123. short sH = 0, // Height of test area.
  124. RImage* pim = NULL); // Destination image. NULL == use m_im.
  125. // Does REdit stuff like check for text, update caret, and draw new
  126. // text.
  127. virtual // If you override this, call this base if possible.
  128. void Do( // Returns nothing.
  129. RInputEvent* pie); // In: Most recent user input event.
  130. // Out: pie->sUsed = TRUE, if used.
  131. // Calls user input error callback if one is set.
  132. virtual // If you override this, call this base if
  133. // possible.
  134. void NotifyCall(void) // Returns nothing.
  135. { if (m_encCall != NULL) (*m_encCall)(this); }
  136. // Cursor event notification.
  137. // Events in event area.
  138. virtual // If you override this, call this base if possible.
  139. void CursorEvent( // Returns nothing.
  140. RInputEvent* pie); // In: Most recent user input event.
  141. // Out: pie->sUsed = TRUE, if used.
  142. // Called by the static implementation of SetFocus() on the item losing
  143. // the focus.
  144. // I'm not exactly sure of the effects of calling SetFocus() from within
  145. // this function, but I would suggest that it might not be as expected.
  146. virtual // If you override this, call this base if possible.
  147. void OnLoseFocus(void)
  148. {
  149. // Call base class implementation.
  150. RTxt::OnLoseFocus();
  151. // Give up our caret, if we had it.
  152. m_sCaretState = 0;
  153. }
  154. ////////////////////////////////////////////////////////////////////////
  155. // Querries.
  156. ////////////////////////////////////////////////////////////////////////
  157. //////////////////////////////////////////////////////////////////////////////
  158. public: // Static
  159. //////////////////////////////////////////////////////////////////////////////
  160. protected: // Internal functions.
  161. // Read item's members from file.
  162. virtual // Overridden here.
  163. short ReadMembers( // Returns 0 on success.
  164. RFile* pfile, // File to read from.
  165. U32 u32Version); // File format version to use.
  166. // Write item's members to file.
  167. virtual // Overridden here.
  168. short WriteMembers( // Returns 0 on success.
  169. RFile* pfile); // File to write to.
  170. // Clips the caret to within the string length.
  171. void ClipCaret(void); // Returns nothing.
  172. //////////////////////////////////////////////////////////////////////////////
  173. public: // Member variables.
  174. char m_cCaretChar; // Character to use as caret.
  175. U32 m_u32CaretColor; // Color to use for caret.
  176. short m_sCaretPos; // Text position of caret.
  177. long m_lCaretBlinkRate;// Rate at which character blinks in ms. Can be
  178. // 0 indicating no blinkage.
  179. short m_sMaxText; // Maximum text to allow. Limited to GUI_MAX_STR.
  180. short m_sBehavior; // Flags. See enums above.
  181. EditNotifyCall m_encCall; // Callback when a user input notification
  182. // should occur such as too much input or
  183. // invalid character generated (e.g., alphas
  184. // in NUMBERS_ONLY mode). A good place to
  185. // generate a beep or something.
  186. long m_lNextCaretUpdate; // Time in ms of next caret update.
  187. short m_sCaretState; // Current state the caret is in until
  188. // m_lNextCaretUpdate. (0 == hidden,
  189. // 1 == shown).
  190. short m_sFirstVisibleCharIndex; // Index of the first visible character.
  191. Point m_aptTextPos[GUI_MAX_STR]; // Positions for characters in m_szText.
  192. // This is no longer dynamically allocated
  193. // do to the amount of overhead that added
  194. // when adding characters.
  195. protected: // Internal typedefs.
  196. protected: // Protected member variables.
  197. ///////////////////////////////////////////////////////////////////////////
  198. // Friends.
  199. ///////////////////////////////////////////////////////////////////////////
  200. friend class CEditPropPage;
  201. };
  202. #endif // EDIT_H
  203. //////////////////////////////////////////////////////////////////////////////
  204. // EOF
  205. //////////////////////////////////////////////////////////////////////////////