home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IMLE.HPP < prev    next >
C/C++ Source or Header  |  1993-10-22  |  26KB  |  465 lines

  1. #ifndef _IMLE_
  2.   #define _IMLE_
  3. /*******************************************************************************
  4. * FILE NAME: imle.hpp                                                          *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     IMultiLineEdit - This class creates and manages the multiple-line entry  *
  9. *                      field control.                                          *
  10. *                                                                              *
  11. * COPYRIGHT:                                                                   *
  12. *   Licensed Materials - Property of IBM                                       *
  13. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  14. *   All Rights Reserved                                                        *
  15. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  16. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  17. *                                                                              *
  18. *******************************************************************************/
  19. #ifndef _ITEXTCTL_
  20.   #include <itextctl.hpp>
  21. #endif
  22.  
  23. // Forward declarations for other classes:
  24. class IWindowHandle;
  25. class IFont;
  26. class IColor;
  27. #ifndef _IRECT_
  28.   #include <irect.hpp>
  29. #endif
  30.  
  31. /*----------------------------------------------------------------------------*/
  32. /* Align classes on four byte boundary.                                       */
  33. /*----------------------------------------------------------------------------*/
  34. #pragma pack(4)
  35.  
  36. /*----------------------------------------------------------------------------*/
  37. /* Turn off warning for compiler generated copy/assignment                    */
  38. /*----------------------------------------------------------------------------*/
  39. #pragma info(nocpy)
  40.  
  41. class IMultiLineEdit : public ITextControl {
  42. typedef ITextControl Inherited;
  43. /*******************************************************************************
  44. * The IMultiLineEdit class creates and manages the multiple-line entry field   *
  45. * (MLE) control.                                                               *
  46. *                                                                              *
  47. *                                                                              *
  48. * EXAMPLE:                                                                     *
  49. *   #include <imle.hpp>                                                        *
  50. *   IString pchInitText[100];                                                  *
  51. *   pmle = new IMultiLineEdit( ID_MLE, this, this,                             *
  52. *                              IRectangle(IPoint(50, 15),                      *
  53. *                                         IPoint(200, 200)),                   *
  54. *                              IMultiLineEdit::classDefaultStyle );            *
  55. *   strcpy(pchInitText, "Text init'd by setText, selected by selectRange.");   *
  56. *   pmle->setText( pchInitText, strlen(pchInitText)+1);                        *
  57. *   pmle->selectRange();                                                       *
  58. *   pmle->setFocus();   // must setFocus to show marked area                   *
  59. *******************************************************************************/
  60. public:
  61.  
  62. /*---------------- Style -----------------------------------------------------
  63.   The following functions provide a means to set and query MLE styles:
  64.  
  65.     Style - Nested class that provides static members that define the set of
  66.             valid MLE styles.  These styles can be used in conjunction with
  67.             the styles defined by the nested classes IWindow::Style and
  68.             IControl::Style.  For example, you could define an instance of
  69.             the IMultiLineEdit::Style class and initialize it like:
  70.               IMultiLIneEdit::Style
  71.                 style = IMultiLineEdit::border | IControl::tabStop;
  72.             An object of this type is provided when the MLE is created.  A
  73.             customizable default is used if no styles are specified.  Once
  74.             the object is constructed, IMultiLineEdit, IWindow, and IControl
  75.             member functions can be used to set or query the object's style.
  76.  
  77.             The declaration of the IMultiLineEdit::Style nested class is
  78.             generated by the INESTEDBITFLAGCLASSDEF2 macro.
  79.  
  80.   The valid MLE styles are:
  81.     classDefaultStyle - Original default style for this class.  This style is
  82.                         border | vertScroll | wordWrap | autoScroll |
  83.                         IWindow::visible.
  84.     border            - Causes a thin border to be drawn around the MLE.
  85.     readOnly          - Restricts the user from entering any data.
  86.     wordWrap          - Causes text to word-wrap at the end of a line.
  87.     horizontalScroll  - Adds a horizontal scroll bar to the MLE.
  88.     verticalScroll    - Adds a vertical scroll bar to the MLE.
  89.     ignoreTab         - Causes the MLE to ignore tab key strokes.  This
  90.                         function sends a keyboard event to the owner of the
  91.                         MLE.
  92.  
  93.   The following functions provide a means of getting and setting the default
  94.   style for this class:
  95.     defaultStyle    - Returns the current default style.  This is the same as
  96.                       classDefaultStyle unless setDefaultStyle has been
  97.                       called.
  98.     setDefaultStyle - Sets the default style for all subsequent MLEs.
  99. -------------------------------------------------------------------------*/
  100. INESTEDBITFLAGCLASSDEF2(Style, IMultiLineEdit, IWindow, IControl);
  101.  
  102. static const Style
  103.   classDefaultStyle,
  104.   border,
  105.   readOnly,
  106.   wordWrap,
  107.   horizontalScroll,
  108.   verticalScroll,
  109.   ignoreTab;
  110.  
  111. static Style
  112.   defaultStyle();
  113.  
  114. static void
  115.   setDefaultStyle(Style style);
  116.  
  117. /*------------------------ Constructors ----------------------------------------
  118. | You can construct an instance of this class in the following ways:           |
  119. |   - The specified multiple-line entry field control and an object for it     |
  120. |     is created from a control ID, parent and owner windows, rectangle, and   |
  121. |     style.                                                                   |
  122. |   - The object for the specified multiple-line entry field control is        |
  123. |     created from the ID of a multiple-line entry field control on a dialog   |
  124. |     window.                                                                  |
  125. |   - The object for the specified multiple-line entry field control is        |
  126. |     created from the window handle of an existing multiple-line entry        |
  127. |     field control.                                                           |
  128. |                                                                              |
  129. | NOTE: You can type past the text limit of an IMultiLineEdit window that is   |
  130. |       constructed from direct editing in a container.                        |
  131. ------------------------------------------------------------------------------*/
  132.   IMultiLineEdit(unsigned long id,
  133.                  IWindow* parent,
  134.                  IWindow* owner,
  135.                  const IRectangle& initial= IRectangle(),
  136.                  const Style& style = defaultStyle() );
  137.   IMultiLineEdit(unsigned long id,
  138.                  IWindow* parent);
  139.   IMultiLineEdit(const IWindowHandle& handle);
  140.  
  141.   virtual ~IMultiLineEdit();
  142.  
  143. /*-------------------------------- Change Operations ---------------------------
  144. | setChangedFlag    - Sets a flag to indicate that the MLE contents have       |
  145. |                     changed.                                                 |
  146. | removeChangedFlag - Resets the changed flag so that changes to the MLE from  |
  147. |                     this point forward can be detected.                      |
  148. | isChanged         - Queries whether any changes have been made to the MLE    |
  149. |                     since the last time the changed flag was reset.          |
  150. ------------------------------------------------------------------------------*/
  151. IMultiLineEdit
  152.   &setChangedFlag(),
  153.   &removeChangedFlag();
  154. Boolean
  155.   isChanged() const;
  156.  
  157. /*-------------------------------- Read-only Operations ------------------------
  158. |  disableDataUpdate - Prohibits changes to the current MLE text.              |
  159. |  enableDataUpdate  - Sets the MLE to read-write mode, which allows the user  |
  160. |                      to update the MLE text.                                 |
  161. |  isReadOnly        - Queries whether the MLE is in read-only mode.           |
  162. ------------------------------------------------------------------------------*/
  163. IMultiLineEdit
  164.   &disableDataUpdate(),
  165.   &enableDataUpdate(Boolean update=true);
  166. Boolean
  167.   isReadOnly() const;
  168.  
  169. /*-------------------------------- Refresh Operations --------------------------
  170. |  enableRefresh  - Enables screen refreshes.  The screen is updated with the  |
  171. |                   contents of the text.                                      |
  172. |  disableRefresh - Disables screen refreshes.  Allows an application to make  |
  173. |                   changes throughout an MLE while avoiding unnecessary       |
  174. |                   overhead caused by attempts to keep the screen display     |
  175. |                   updated.  While refresh is disabled, mouse and keyboard    |
  176. |                   messages are processed by beeping and ignoring them.  The  |
  177. |                   mouse pointer changes to the system standard "wait"        |
  178. |                   pointer.                                                   |
  179. ------------------------------------------------------------------------------*/
  180. IMultiLineEdit
  181.   &enableRefresh(Boolean refresh=true),
  182.   &disableRefresh();
  183.  
  184. /*-------------------------------- Text Operations -----------------------------
  185. |  EOLFormat   - Enumerates the formats for the end-of-line characters for     |
  186. |                importing and exporting.  Valid formats are:                  |
  187. |                  cfText    - Each line ends with a carriage-return/line-     |
  188. |                              feed combination.  Tab characters separate      |
  189. |                              fields within a line.  A NULL character         |
  190. |                              signals the end of the data.                    |
  191. |                  noTran    - Uses LF for line delineation and guarantees     |
  192. |                              any text imported into the MLE in this format   |
  193. |                              can be recovered in exactly the same form when  |
  194. |                              exported.                                       |
  195. |                  MLEFormat - On import, recognizes CRLF as denoting hard     |
  196. |                              line-breaks, and ignores the sequence CRCRLF.   |
  197. |                              On export, uses CRLF to denote a hard line-     |
  198. |                              break and CRCRLF to denote a soft line-break    |
  199. |                              caused by word-wrapping.                        |
  200. |  setText     - Overwrites the current contents of the MLE with the new text  |
  201. |                contained in the input buffer.  The input buffer can contain  |
  202. |                NULL characters; the bufferSize argument determines how much  |
  203. |                text is copied into the MLE.                                  |
  204. |  text        - If no parameter is specified, it returns the current          |
  205. |                contents of the MLE.  If a line number is specified, it       |
  206. |                returns the current MLE text at the given line.               |
  207. |  setLimit    - Sets a limit on the number of bytes that can be input into    |
  208. |                the MLE.  If the MLE already contains more bytes than the     |
  209. |                proposed limit, an exception is thrown.                       |
  210. |  limit       - Returns the currently set number of bytes the MLE can hold.   |
  211. |  textLength  - Returns the current length of the MLE text, in bytes.  The    |
  212. |                length includes any CRLFs present.                            |
  213. |  addAtOffset - Inserts the specified text into the MLE at the point          |
  214. |                specified.  At the conclusion of this insert, the cursor      |
  215. |                will be positioned at the same character as it was before     |
  216. |                the insert.  The textSize argument is used in case you want   |
  217. |                want to add text that contains more than one NULL character.  |
  218. |                If textSize is not specified, the function will add the       |
  219. |                characters up to the first NULL character.                    |
  220. |  add         - Inserts the specified text into the MLE at the current        |
  221. |                cursor position.  At the conclusion of this operation, the    |
  222. |                cursor will be positioned at the end of the inserted text.    |
  223. |                The textSize argument is used in case you want to add text    |
  224. |                that contains more than one NULL character.  If textSize is   |
  225. |                not specified, the function will add the characters up to     |
  226. |                the first NULL character.                                     |
  227. |  addAsLast   - Inserts the specified text into the MLE at the end of the     |
  228. |                current text.  This operation will not change the cursor      |
  229. |                position.  The textSize argument is used in case you want to  |
  230. |                add text that contains more than one NULL character.  If      |
  231. |                textSize is not specified, the function will add the          |
  232. |                characters up to the first NULL character.                    |
  233. ------------------------------------------------------------------------------*/
  234. enum EOLFormat {cfText,noTran,MLEFormat};
  235. IString
  236.   text() const,
  237.   text( unsigned long lineNumber) const;
  238. unsigned long
  239.   limit() const;
  240. virtual unsigned long
  241.   textLength() const;
  242. IMultiLineEdit
  243.   &setText(const char* text),
  244.   &setText(const IResourceId& text),
  245.   &setText(char* buffer,
  246.           unsigned long bufferSize ),
  247.   &setLimit(unsigned long newLimit),
  248.   &add(char* text, unsigned long textSize=0, EOLFormat type=cfText),
  249.   &addAsLast(char* text, unsigned long textSize=0,
  250.              EOLFormat type=cfText),
  251.   &addAtOffset(char* text, unsigned long charnumber,
  252.                unsigned long textSize=0,  EOLFormat type=cfText);
  253.  
  254. /*-------------------------------- Import/Export Operations --------------------
  255. |  importFromFile           - Inserts the contents of the specified file into  |
  256. |                             the MLE at the current cursor position and       |
  257. |                             returns the number of characters imported.       |
  258. |  exportToFile             - Saves the contents of the MLE to the specified   |
  259. |                             file and returns the number of bytes written to  |
  260. |                             the file.                                        |
  261. |  exportSelectedTextToFile - Saves the currently marked text to the           |
  262. |                             specified file and returns the number of bytes   |
  263. |                             written to the file.                             |
  264. ------------------------------------------------------------------------------*/
  265. unsigned long
  266.   importFromFile(char* fileName, EOLFormat type=cfText),
  267.   exportToFile(char * fileName, EOLFormat type=cfText),
  268.   exportSelectedTextToFile(char* fileName, EOLFormat type=cfText);
  269.  
  270. /*-------------------------------- Selected Text -------------------------------
  271. |   end                - Used to denote the end of the text for selecting      |
  272. |                        text.                                                 |
  273. |   selectRange        - Selects a range of text.  The selected range is the   |
  274. |                        0-based index of the first character selected (or to  |
  275. |                        be selected) and the 0-based index of the last        |
  276. |                        character selected (or to be selected).  If no range  |
  277. |                        is specified, all of the text will be selected.       |
  278. |                        Specifying a range where the lower and upper values   |
  279. |                        are equal will cause the selection to become an       |
  280. |                        insertion point.                                      |
  281. |   selectedRange      - Returns the range of the selected text. If no text    |
  282. |                        is selected, a range of (cursor position, cursor      |
  283. |                        position) is returned by selectedRange.  The          |
  284. |                        selected range is the 0-based index of the first      |
  285. |                        character being selected and the 0-based index of     |
  286. |                        the last character being selected.                    |
  287. |   selectedText       - Returns the selected text string.                     |
  288. |   selectedTextLength - Returns the size of the selected area, in bytes.      |
  289. |                        The length includes CRLFs, but not NULL terminators.  |
  290. |   hasSelectedText    - Queries whether any of the MLE's text is selected.    |
  291. ------------------------------------------------------------------------------*/
  292. static const long end ;
  293. IMultiLineEdit&
  294.   selectRange(const IRange& range=IRange(0,end));
  295. IRange
  296.   selectedRange() const;
  297. IString
  298.   selectedText() const;
  299. unsigned long
  300.   selectedTextLength() const;
  301. Boolean
  302.   hasSelectedText() const;
  303. /*-------------------------------- Clipboard Operations ------------------------
  304. |  cut     - Copies the currently selected text from the MLE to the clipboard  |
  305. |            and then deletes the selected text from the MLE.                  |
  306. |  copy    - Copies the currently selected text from the MLE to the clipboard. |
  307. |  paste   - Inserts the contents of the clipboard into the MLE at the         |
  308. |            current cursor position.                                          |
  309. |  clear   - Replaces the currently selected text with blank spaces.           |
  310. |  discard - Deletes all of the currently selected text.                       |
  311. ------------------------------------------------------------------------------*/
  312. virtual IMultiLineEdit
  313.   &cut(),
  314.   ©(),
  315.   &paste(),
  316.   &clear(),
  317.   &discard();
  318.  
  319. /*-------------------------------- Undo Operations -----------------------------
  320. |  isUndoable - Queries whether any undoable actions have been performed on    |
  321. |               the contents of the MLE.                                       |
  322. |  undo       - Restores the MLE contents to the state they were in before     |
  323. |               the last change.                                               |
  324. ------------------------------------------------------------------------------*/
  325. Boolean
  326.   isUndoable() const;
  327. IMultiLineEdit&
  328.   undo();
  329.  
  330. /*-------------------------------- Delete Text Operation -----------------------
  331. |  removeAll - Deletes the entire contents of the MLE.                         |
  332. ------------------------------------------------------------------------------*/
  333. IMultiLineEdit&
  334.   removeAll();
  335.  
  336. /*-------------------------------- Size Operations -----------------------------
  337. |  setEditRegion       - Sets the size of the edit region so that it covers    |
  338. |                        the entire MLE window.  The edit region is the        |
  339. |                        rectangular area in which the text is displayed.      |
  340. |  setEditRegionWidth  - Sets the width of the edit region, in pixels.         |
  341. |  setEditRegionHeight - Sets the height of the edit region, in pixels.        |
  342. |  editRegionWidth     - Returns the width of the edit region.                 |
  343. |  editRegionHeight    - Returns the height of the edit region.                |
  344. ------------------------------------------------------------------------------*/
  345. IMultiLineEdit
  346.   &setEditRegion(),
  347.   &setEditRegion( const ISize& sizeEditRegion),
  348.   &setEditRegionWidth( long width),
  349.   &setEditRegionHeight( long height);
  350. unsigned long
  351.   editRegionWidth()  const,
  352.   editRegionHeight() const;
  353.  
  354. /*-------------------------------- Tab Stop Operation --------------------------
  355. |  setTab - Sets the number of pixels between tab stops inside the MLE.        |
  356. ------------------------------------------------------------------------------*/
  357. IMultiLineEdit&
  358.   setTab(unsigned long tabPixelInterval);
  359.  
  360. /*-------------------------------- Word-wrap Operations ------------------------
  361. |  isWordWrap      - Queries whether the MLE is in word-wrap mode.             |
  362. |  enableWordWrap  - Enables word-wrap mode in the MLE.                        |
  363. |  disableWordWrap - Disables word-wrap mode in the MLE.                       |
  364. ------------------------------------------------------------------------------*/
  365. Boolean
  366.   isWordWrap() const;
  367. IMultiLineEdit
  368.   &enableWordWrap(Boolean enable=true),
  369.   &disableWordWrap();
  370.  
  371. /*---------------------------- Enumerations ------------------------------------
  372. | The following enumeration is defined:                                        |
  373. |   ColorArea - Enumeration that is used to replace the color for a            |
  374. |               particular region.  Values are:                                |
  375. |               foreground  - Sets the color of the foreground text.           |
  376. |               background  - Sets the color of the background for the text.   |
  377. |               bordercolor - Sets the color of the border that surrounds the  |
  378. |                             MLE window.                                      |
  379. ------------------------------------------------------------------------------*/
  380. enum ColorArea {
  381.   foreground,
  382.   background,
  383.   bordercolor
  384. };
  385.  
  386. /*------------------------ Color and Font Functions ----------------------------
  387. | These functions provide a means to change and query string attributes of     |
  388. | instances of this class:                                                     |
  389. |  setColor - Changes the color of the specified color area.                   |
  390. |  color    - Returns the color of the specified color area.                   |
  391. |  setFont  - Changes the font of the displayed text.                          |
  392. ------------------------------------------------------------------------------*/
  393. virtual IMultiLineEdit
  394.   &setColor(ColorArea value, const IColor& color),
  395.   &setFont(const IFont& font);
  396.  
  397. IColor
  398.   color(ColorArea value) const;
  399.  
  400. /*-------------------------------- Line Operations -----------------------------
  401. | These functions use the terms line and line number as arguments or returns   |
  402. | from these functions.  A line is defined as a line on the display after the  |
  403. | application of word-wrap.  It does not mean a line as defined by the CRLF    |
  404. | line-break sequence.                                                         |
  405. |  addLine         - Inserts the specified NULL-terminated text at the         |
  406. |                    specified line number.                                    |
  407. |  addLineAsLast   - Inserts the specified NULL-terminated text at the last    |
  408. |                    line.                                                     |
  409. |  removeLine      - Deletes the specified line of text.                       |
  410. |  setTop          - Makes the specified line the topmost visible line on the  |
  411. |                    screen.                                                   |
  412. |  setCursorAtLine - Moves the cursor position to the specified line number.   |
  413. |  setCursorAt     - Moves the cursor a specified number of positions from     |
  414. |                    left to right in the MLE.  The count begins with the      |
  415. |                    first position in the MLE, not the cursor's current       |
  416. |                    position.                                                 |
  417. |  top             - Returns the line number of the line currently visible at  |
  418. |                    the top of the screen.                                    |
  419. |  cursor          - Returns the line number of the line that currently        |
  420. |                    contains the cursor.                                      |
  421. |  numberOfLines   - Returns the total number of lines of text in the MLE.     |
  422. |  visibleLines    - Returns the number of lines that completely fit inside    |
  423. |                    the edit region of the MLE based on the current font.     |
  424. ------------------------------------------------------------------------------*/
  425. IMultiLineEdit
  426.   &addLine(char* text, unsigned long lineNumber, EOLFormat type=cfText),
  427.   &addLineAsLast(char* text, EOLFormat type=cfText),
  428.   &removeLine(unsigned long lineNumber),
  429.   &setTop(unsigned long lineNumber),
  430.   &setCursorAtLine(unsigned long lineNumber),
  431.   &setCursorAt(unsigned long cursorPosition);
  432. unsigned long
  433.   top() const,
  434.   cursor() const,
  435.   numberOfLines() const,
  436.   visibleLines() const;
  437.  
  438.  
  439. private:
  440. /*--------------------------------- Private ----------------------------------*/
  441. static Style
  442.   currentDefaultStyle;
  443. long
  444.   exportFile(char *fileName, Boolean flMarkedAreaOnly);
  445. unsigned long
  446.   export(long *insertion_point,unsigned long *buffer_length),
  447.   import(long *insertion_point,unsigned long buffer_length);
  448. IMultiLineEdit&
  449.   setIEBuffer(char *buffer,unsigned long length);
  450. Boolean
  451.   bRefresh;
  452. unsigned long
  453.   textLengthAfterFormat() const;
  454. } ;
  455.  
  456. INESTEDBITFLAGCLASSFUNCS(Style, IMultiLineEdit);
  457.  
  458. /*----------------------------------------------------------------------------*/
  459. /* Resume compiler default packing and warning messages.                      */
  460. /*----------------------------------------------------------------------------*/
  461. #pragma pack()
  462. #pragma info(restore)
  463.  
  464. #endif
  465.