home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / ibmcli / imle.hp_ / IMLE.HPP
Encoding:
C/C++ Source or Header  |  1992-10-26  |  18.2 KB  |  367 lines

  1. #ifndef _IMLE_
  2.   #define _IMLE_
  3. /*******************************************************************************
  4. * FILE NAME: imle.hpp                                                          *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     Imle     - This class creates and manages the multi-line edit control.   *
  9. *                                                                              *
  10. * COPYRIGHT:                                                                   *
  11. *   Licensed Materials - Property of IBM                                       *
  12. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  13. *   All Rights Reserved                                                        *
  14. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  15. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  16. *                                                                              *
  17. * $Log:   R:/IBMCLASS/IBASECTL/VCS/IMLE.HPV  $
  18. //
  19. //   Rev 1.7   25 Oct 1992 17:05:36   nunn
  20. //changed library name to ICLUI
  21. //
  22. //   Rev 1.6   25 Oct 1992 10:55:20   boezeman
  23. //Add documentation and converted file to skeleton.hpp format.
  24.  
  25.       Rev 1.5   29 Sep 1992 21:17:36   Susan Nunn
  26.    Added declare for isWordWrap()
  27.  
  28.       Rev 1.4   26 Feb 1992 20:55:52   Ken Fichthorn
  29.    Added methods for manipulating lines, plus insertText(),unMark(),
  30.    disableRefresh(), and enableRefresh()
  31.  
  32.       Rev 1.3   30 Oct 1991 21:17:36   Ken Fichthorn
  33.    Redesign and implement.
  34.  
  35.       Rev 1.2   23 May 1991 20:55:52   Mike Chan
  36.    Converted to new naming convention
  37.  
  38.       Rev 1.1   17 Aug 1990 19:02:08   James Hsieh
  39.    Initial code
  40. *******************************************************************************/
  41. #ifndef _ICONTROL_
  42.   #include <icontrol.hpp>
  43. #endif
  44.  
  45. // Forward declarations for other classes:
  46. class IMultiLineEdit;
  47. class IWindowHandle;
  48. class IFontMgr;
  49.  
  50. /* Defines for MLE   */
  51. const long IC_MARK_TO_END = -2;
  52. const long IC_APPEND_TO_END = -1;
  53.  
  54. class IMultiLineEdit : public IControl {
  55. /*******************************************************************************
  56. * This class creates and manages the multi-line edit control.                  *
  57. *                                                                              *
  58. * To use this class, create an instance of this class as follows:              *
  59. *   #include <imle.hpp>                                                        *
  60. *   char pchInitText[100];                                                     *
  61. *   pmle= 0;                                                                   *
  62. *   pmle = new IMultiLineEdit( this, ID_MLE,                                   *
  63. *                              IRectangle(IPoint(50, 15),                      *
  64. *                                         ISize(200, 200)),                    *
  65. *                              IC_DEFAULTMLESTYLE);                            *
  66. *   sprintf( pchInitText,                                                      *
  67. *       "Text init'd by setText, marked by setMarkedArea.");                   *
  68. *   pmle->setText( pchInitText, 1+strlen(pchInitText));                        *
  69. *   pmle->setMarkedArea(1, IC_MARK_TO_END);                                    *
  70. *   pmle->setFocus();   // must setfocus to show marked area                   *
  71. *                                                                              *
  72. * EXAMPLE:                                                                     *
  73. *   <sample code>                                                              *
  74. *******************************************************************************/
  75. public:
  76. typedef IControl
  77.   Inherited;
  78. INESTEDBITFLAGCLASSDEF2(Style, IMultiLineEdit, IWindow, IControl);
  79.                                     // style class definition
  80. static const Style
  81.   border,
  82.   readOnly,
  83.   wordWrap,
  84.   horzScroll,
  85.   vertScroll,
  86.   ignoreTab;
  87. static const Style&
  88.   defaultStyle;
  89.  
  90. /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------------
  91. | There are 3 ways to construct instances of this class:                       |
  92. |   1. default                                                                 |
  93. |   2. From a Dialog Template                                                  |
  94. |   3. From a Window                                                           |
  95. ------------------------------------------------------------------------------*/
  96.   IMultiLineEdit(unsigned long ulId,
  97.                  const IWindow* pwndParent,
  98.                  const IWindow* pwndOwner,
  99.                  const IRectangle& rectInit,
  100.                  Style mles = defaultStyle);
  101.   IMultiLineEdit(unsigned long ulId,
  102.                  const IWindow* pwndParent);
  103.   IMultiLineEdit(IWindowHandle wh);
  104. virtual
  105.   ~IMultiLineEdit() {;}
  106.  
  107. /*-------------------------------- CHANGE OPERATIONS ---------------------------
  108. | setChangedFlag   - Sets a flag to indicate that the MLE contents have changed|
  109. | clearChangedFlag - Resets the changed flag, so that addition changes to the  |
  110. |                    mle from this point forward can be detected.              |
  111. | isChanged        - Queries whether any changes have been made to the mls     |
  112. |                    since the last time the changed flag was reset.           |
  113. ------------------------------------------------------------------------------*/
  114. void
  115.   setChangedFlag(),
  116.   clearChangedFlag();
  117. Boolean
  118.   isChanged() const;
  119.  
  120. /*-------------------------------- READONLY OPERATIONS -------------------------
  121. |  setReadOnly      - Prohibits changes to the current mle text.               |
  122. |  cancelReadOnly   - Puts the mle into read/write mode, where the user can    |
  123. |                     update the mle text.                                     |
  124. |  isReadOnly       - Queries whether or not the mle is in readonly mode.      |
  125. ------------------------------------------------------------------------------*/
  126. void
  127.   setReadOnly(),
  128.   cancelReadOnly();
  129. Boolean
  130.   isReadOnly() const;
  131.  
  132. /*-------------------------------- REFRESH OPERATIONS --------------------------
  133. |  enableRefresh    - Enables screen refreshes.  The screen is brought up to   |
  134. |                     date with the contents of the text.                      |
  135. |  disableRefresh   - Disables screen refreshes.  This allows an application to|
  136. |                     make changes throughout an mle while avoiding unnecessary|
  137. |                     overhead caused by attempts to keep the screen display   |
  138. |                     current.  While refresh is disabled, mouse and keyboard  |
  139. |                     messages are processed by beeping an ignoring them.  The |
  140. |                     mouse pointer changes to the system standard "wait" pointer.|
  141. ------------------------------------------------------------------------------*/
  142. void
  143.   enableRefresh(),
  144.   disableRefresh();
  145.  
  146. /*-------------------------------- TEXT OPERATIONS -----------------------------
  147. |  setText          - Overwrites the current contents of the mle with the new  |
  148. |                     text contained in the input butter.  The input buffer can|
  149. |                     contain NULL characters -- the buffer size parameter     |
  150. |                     determines how much text is copied in the mle.           |
  151. |  text             - Returns the current contents of the mle.                 |
  152. |  lineText         - Returns the current mle text at a given line.            |
  153. |  insert           - Inserts the specified text into the MLE at the current   |
  154. |                     cursor position.  At the conclusion of this operation, the|
  155. |                     cursor will be positioned at the end of the inserted text.|
  156. |  append           - Inserts the specified text into the MLE at the end of the|
  157. |                     current text.  This operation will not change the cursor |
  158. |                     position.                                                |
  159. |  insertAt         - Inserts the specified text into the MLE at the point     |
  160. |                     specified.  At the conclusion of this insert, the cursor |
  161. |                     will be positioned at the same character as it was before|
  162. |                     the insert.                                              |
  163. |  markedText       - Returns the currently marked text of the mle.            |
  164. |  setEndOfLineFormat-Changes the format used for copying mle text to and from |
  165. |                     buffers.                                                 |
  166. |  endOfLineFormat  - Returns the format used for copying mle text.            |
  167. ------------------------------------------------------------------------------*/
  168. IString
  169.   text(),
  170.   lineText( long lLineNumber),
  171.   markedText();
  172. long
  173.   setText(char* pszBuffer,
  174.           unsigned long ulBufferSize =0),
  175.   insert( char * pszBuffer,                       // insert at cursor pos
  176.           unsigned long ulBufferSize =0),
  177.   append( char * pszBuffer,                       // insert at end of text
  178.           unsigned long ulBufferSize =0),
  179.   insertAt( char * pszBuffer,                     // insert at spec'd pos
  180.             long lInsertionPoint,
  181.             unsigned long ulBufferSize =0);
  182. void
  183.   setEndOfLineFormat( unsigned long ulEOLFormat);
  184. unsigned long
  185.   endOfLineFormat();
  186.  
  187. /*-------------------------------- IMPORT/EXPORT OPERATIONS --------------------
  188. |  importFromFile   - Inserts the contents of the specified file into the mle  |
  189. |                     at the current cursor position.                          |
  190. |  exportToFile     - Saves the contents of the mle to the specified file      |
  191. |  exportMarkedTextToFile - Saves the currently marked text to the specifed file|
  192. ------------------------------------------------------------------------------*/
  193. long
  194.   importFromFile(char* pszFileName),
  195.   exportToFile(char * pszFileName),
  196.   exportMarkedTextToFile(char* pszFileName);
  197.  
  198. /*-------------------------------- TEXT LIMIT OPERATION ------------------------
  199. |  setTextLimit  - Sets a limit on the number of characters that can be input  |
  200. |                  into the mle.  Returns 0 for successful completion.         |
  201. |                  Otherwise, if the MLE already contains more characters than |
  202. |                  the proposed limit, then the call fails and returns the     |
  203. |                  number of characters by which the limit is exceeded.        |
  204. ------------------------------------------------------------------------------*/
  205. long
  206.   setTextLimit(long lNewLimit);
  207.  
  208. /*-------------------------------- MARKED TEXT OPERATIONS ----------------------
  209. |  setMarkedArea - Specifies a range of characters as the marked area.  If no  |
  210. |                  range is specified, all of the mle text will be marked.     |
  211. |  unMark        - Unmarks the currently marked text, if any, in the mle.      |
  212. |  isClipboardOpen-Checks if the clipboard is open in a format that is         |
  213. |                  compatible with the mle.                                    |
  214. |  isAreaMarked  - Checks if any text is currently marked.                     |
  215. |  cut           - Copies the currently marked text from the mle to the        |
  216. |                  clipboard, and then deletes it from the mle.                |
  217. |  copy          - Copies the currently marked text from the mle to the        |
  218. |                  clipboard.                                                  |
  219. |  paste         - Inserts the contents of the clipboard into the mle at the   |
  220. |                  current cursor position.                                    |
  221. |  clearMarkedText-Replaces the currently marked text with blank spaces.       |
  222. |  deleteMarkedText-Deletes all of the currently marked text.                  |
  223. ------------------------------------------------------------------------------*/
  224. void
  225.   setMarkedArea(long lFirstMarkedChar = 1,
  226.                 long lLastMarkedChar = IC_MARK_TO_END),
  227.   unMark();
  228. Boolean
  229.   isClipboardOpen() const,
  230.   isAreaMarked()    const;
  231. unsigned long
  232.   cut(),
  233.   copy(),
  234.   paste();
  235. long
  236.   clearMarkedText(); /* replace marked area with blanks */
  237. unsigned long
  238.   deleteMarkedText();
  239.  
  240. /*-------------------------------- UNDO OPERATIONS -----------------------------
  241. |  isUndoAvailable - Checks if any un-doable actions have been performed on the|
  242. |                    contents of the mle.                                      |
  243. |  undo            - This backs out the last "undoable" change to the mle      |
  244. |                    contents.                                                 |
  245. ------------------------------------------------------------------------------*/
  246. Boolean
  247.   isUndoAvailable() const;
  248. void
  249.   undo();
  250.  
  251. /*-------------------------------- DELETE TEXT OPERATION------------------------
  252. |  deleteAllText - Deletes the entire contents of the mle.                     |
  253. ------------------------------------------------------------------------------*/
  254. unsigned long
  255.   deleteAllText();
  256.  
  257. /*-------------------------------- SIZE OPERATIONS -----------------------------
  258. |  setEditRegion - Sets the size of the edit region so that it covers the      |
  259. |                  entire mle window.  The edit region is the rectangular area |
  260. |                  in whih the text is displayed.                              |
  261. |  setEditRegionWidth-Sets the width of the edit region, in pixels.            |
  262. |  setEditRegionHeight-Sets the height of the edit region, in pixels.          |
  263. |  editRegionWidth-Returns the width of the edit region.                       |
  264. |  editRegionHeight-Returns the height of the edit region.                     |
  265. ------------------------------------------------------------------------------*/
  266. void
  267.   setEditRegion(),   // Set edit region to size of MLE window
  268.   setEditRegion( const ISize& sizeEditRegion),
  269.   setEditRegionWidth( long lWidth),
  270.   setEditRegionHeight( long lHeight);
  271. long
  272.   editRegionWidth()  const,
  273.   editRegionHeight() const;
  274.  
  275. /*-------------------------------- TAB STOP OPERATION --------------------------
  276. |  setTabStopInterval - Sets the number of pixels between tab stops inside     |
  277. |                       the mle                                                |
  278. ------------------------------------------------------------------------------*/
  279. void
  280.   setTabStopInterval( long lTabPixelInterval);
  281.  
  282. /*-------------------------------- WORD-WRAP OPERATIONS ------------------------
  283. |  isWordWrap     -  Checks if the mle is in word-wrap mode.                   |
  284. |  setWordWrap    -  Sets the mle into word-wrap mode.                         |
  285. |  cancelWordWrap -  Takes the mle out of word-wrap mode.                      |
  286. ------------------------------------------------------------------------------*/
  287. Boolean
  288.   isWordWrap();                // (a) SHN
  289. void
  290.   setWordWrap(),
  291.   cancelWordWrap();
  292.  
  293. /*-------------------------------- COLOR OPERATIONS ----------------------------
  294. |  setTextColor   -  Sets the color of the text inside the mle.                |
  295. |  setBackgoundColor-Sets the color of the mle background.                     |
  296. ------------------------------------------------------------------------------*/
  297. long
  298.   setTextColor( long lColor),
  299.   setBackgroundColor( long lColor);
  300.  
  301. /********************************************************************/
  302. /* Method to allow the user to change the font of the MLE text.     */
  303. /********************************************************************/
  304. //void        setFont( const IFontMgr& fontmgr);
  305.  
  306. /*-------------------------------- LINE OPERATIONS -----------------------------
  307. |  insertLine       - Inserts teh specified null-teminated text at the line    |
  308. |                     number specified                                         |
  309. |  deleteLine       - Deletes the specified line of text.                      |
  310. |  setTopLine       - Makes the specified line be the top visible line on the  |
  311. |                     screen.                                                  |
  312. |  setCursorLine    - Moves the cursor position to the specified line number.  |
  313. |  setCursorChar    - Places the cursor on the specified character in the mle. |
  314. |  topLine          - Returns the number of the line currently visible as the  |
  315. |                     top mle line on the screen                               |
  316. |  cursorLine       - Returns the line number of the line that currently       |
  317. |                     contains the cursor.                                     |
  318. |  lineCount        - Returns the total number of lines of text in the mle.    |
  319. |  visibleLineCount - Returns the number of lines that completely fit inside   |
  320. |                     the mle on the screen.                                   |
  321. ------------------------------------------------------------------------------*/
  322. void
  323.   insertLine( char * pszLineText,
  324.               long lLineNumber = IC_APPEND_TO_END),
  325.   deleteLine( long lLineNumber),
  326.   setTopLine( long lLineNumber),
  327.   setCursorLine( long lLineNumber),
  328.   setCursorChar( long lCursorPosition);
  329. long
  330.   topLine() const,
  331.   cursorLine() const,
  332.   lineCount() const,
  333.   visibleLineCount() const;
  334.  
  335. /********************************************************************/
  336. /* OUTDATED METHODS                                                 */
  337. /********************************************************************/
  338. long
  339.   getEditRegionWidth()  const    {return editRegionWidth();}
  340. long
  341.   getEditRegionHeight() const    {return editRegionHeight();}
  342.  
  343. protected:
  344.   static Style  classDefaultStyle;
  345.  
  346. private:
  347. /*--------------------------------- PRIVATE ----------------------------------*/
  348. long
  349.   exportFile(char *pszFileName, Boolean flMarkedAreaOnly);
  350. unsigned long
  351.   export(long *insertion_point,unsigned long *buffer_length),
  352.   import(long *insertion_point,unsigned long buffer_length);
  353. void
  354.   setIEBuffer(char *pchBuffer,unsigned long ulLength);
  355.  
  356. /* These methods were moved from public to private when we decided */
  357. /* to return IString's instead of char *                           */
  358. unsigned long
  359.   getMarkedTextLen() const,
  360.   getTextLen() const;
  361.  
  362. } ;
  363.  
  364. INESTEDBITFLAGCLASSFUNCS(Style, IMultiLineEdit);
  365.  
  366. #endif
  367.