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

  1. #ifndef _IENTRYFD_
  2.   #define _IENTRYFD_
  3. /*******************************************************************************
  4. * FILE NAME: ientryfd.hpp                                                      *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *    IEntryField - This class creates and manages the entry field control      *
  9. *                  window.                                                     *
  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 IRange;
  25. class ISize;
  26. class IString;
  27. class IResourceId;
  28. class IColor;
  29. #ifndef _IRECT_
  30.   #include <irect.hpp>
  31. #endif
  32. #ifndef _IBITFLAG_
  33.   #include <ibitflag.hpp>
  34. #endif
  35.  
  36. /*----------------------------------------------------------------------------*/
  37. /* Align classes on four byte boundary.                                       */
  38. /*----------------------------------------------------------------------------*/
  39. #pragma pack(4)
  40.  
  41. class IEntryField : public ITextControl  {
  42. typedef ITextControl Inherited;
  43. /*******************************************************************************
  44. * The IEntryField class creates and manages an entry field control.            *
  45. *                                                                              *
  46. * Specific keystroke processing, such as creating a numeric-only input field,  *
  47. * can be implemented by subclassing the IKeyboardHandler class and attaching   *
  48. * the handler to the entry field object.                                       *
  49. *                                                                              *
  50. * EXAMPLE:                                                                     *
  51. *   IEntryField efEntry(ID_ENTRY, this, this, IRectangle(10,10,90,22));        *
  52. *                                                                              *
  53. * To change the style of the entry field after it has been created, use        *
  54. * functions such as:                                                           *
  55. *    setAlignment(IEntryField::center).                                        *
  56. *******************************************************************************/
  57.  
  58. public:
  59. /*---------------------- Style --------------------------------------------
  60.   The following functions provide a means to set and query entry field
  61.   styles:
  62.  
  63.     Style - Nested class that provides static members that define the set of
  64.             valid entry field styles.  These styles can be used in
  65.             conjunction with the styles defined by the nested classes
  66.             IWindow::Style and IControl::Style.  For example, you could
  67.             define an instance of the IEntryField::Style class and
  68.             initialize it like:
  69.               IEntryField::Style
  70.                 style = IEntryField::alignLeft | IControl::tabStop;
  71.             You can specify and object of this type when constructing the
  72.             IEntryField object.  A customizable default is used if no styles
  73.             are specified.  Once the object is constructed, IEntryField,
  74.             IWindow, and IControl member functions can be used to set or
  75.             query the object's style.
  76.  
  77.             The declaration of the IEntryField::Style nested class is
  78.             generated by the INESTEDBITFLAGCLASSDEF2 macro.
  79.  
  80.   The valid entry field styles are:
  81.     classDefaultStyle - Original default style for this class, which is
  82.                         alignLeft | anyData | margin | autoScroll |
  83.                         IWindow::visible.
  84.     autoScroll        - If the user tries to move off the end of a line, the
  85.                         entry field automatically scrolls one-third the width
  86.                         of the window in the appropriate direction.
  87.     margin            - Causes a border to be drawn around the entry field,
  88.                         with a margin between the border and the entry field.
  89.                         The margin's size is determined by the current font
  90.                         being used for entry field text (half a
  91.                         character-width wide and half a character-height
  92.                         high).
  93.  
  94.                         Since the margin and border are drawn around the
  95.                         entry field, using the margin style does not change
  96.                         the position of the entry field itself.  For example,
  97.                         if an entry field is positioned at (100,100), and has
  98.                         a margin and border width and height of 2, the
  99.                         lower-left corner of the border would be positioned
  100.                         at (98,98).
  101.     autoTab           - Causes a tab key to be generated when the entry field
  102.                         is filled by adding a character at the text limit of
  103.                         the entry field text.
  104.     readOnly          - Prevents insertions or changes to the text in the
  105.                         control.
  106.     command           - Creates information used by the Help Manager to
  107.                         provide command help if the user requests help for
  108.                         this field.  No more than one entry field on each
  109.                         window should be given this style.
  110.     unreadable        - Causes the text to be displayed as an asterisk for
  111.                         each character.
  112.     leftAlign         - Makes the text in the entry field left-justified.
  113.     centerAlign       - Makes the text in the entry field centered.
  114.     rightAlign        - Makes the text in the entry field right-justified.
  115.     anyData           - Sets the entry field to accept text that is a mixture
  116.                         of single-byte character set (SBCS) and double-byte
  117.                         character set (DBCS) characters.
  118.                         NOTE: If the text contains both SBCS and DBCS
  119.                               characters and will be converted from an ASCII
  120.                               code page into an EBCDIC code page, this style
  121.                               causes an entry field to ignore accounting for
  122.                               shift-in and shift-out characters that would be
  123.                               introduced into its text.  The opposite of
  124.                               mixedData.
  125.     sbcsData          - Sets the entry field to accept single-byte text only.
  126.     dbcsData          - Sets the entry field to accept double-byte text only.
  127.     mixedData         - Sets the entry field to accept text that is a mixture
  128.                         of SBCS and DBCS characters.  Conversion from an
  129.                         ASCII DBCS code page to an EBCDIC DBCS code page can
  130.                         result in a possible increase in the length of the
  131.                         data because of the addition of shift-in/shift-out
  132.                         characters, but will not exceed the text limit of the
  133.                         entry field.
  134.  
  135.   The following functions provide a means of getting and setting the default
  136.   style for this class:
  137.     defaultStyle    - Returns the current default style.  This is the same as
  138.                       classDefaultStyle unless setDefaultStyle has been
  139.                       called.
  140.     setDefaultStyle - Sets the default style for all subsequent entry fields.
  141. -------------------------------------------------------------------------*/
  142. INESTEDBITFLAGCLASSDEF2(Style, IEntryField, IWindow, IControl);
  143.  
  144. static const Style
  145.   classDefaultStyle,
  146.   autoScroll,
  147.   margin,
  148.   autoTab,
  149.   readOnly,
  150.   command,
  151.   unreadable,
  152.   leftAlign,
  153.   centerAlign,
  154.   rightAlign,
  155.   anyData,
  156.   sbcsData,
  157.   dbcsData,
  158.   mixedData;
  159.  
  160. static Style
  161.   defaultStyle();
  162. static void
  163.   setDefaultStyle(Style style);
  164.  
  165. /*------------------------ Constructors ----------------------------------------
  166. | You can construct an instance of this class in the following ways:           |
  167. |    - From a control ID for the entry field, parent and owner windows,        |
  168. |      initial rectangle, and style.  This creates the specified entry field   |
  169. |      control and an object for it.                                           |
  170. |    - From the ID of an existing entry field control on a parent dialog       |
  171. |      window.  This creates the object for the specified entry field control. |
  172. |    - From the window handle of an existing entry field control.  This        |
  173. |      creates the object for the specified entry field control.               |
  174. ------------------------------------------------------------------------------*/
  175.   IEntryField(unsigned long id,
  176.               IWindow* parent,
  177.               IWindow* owner,
  178.               const IRectangle& initial= IRectangle(),
  179.               const Style& style = defaultStyle() );
  180.  
  181.   IEntryField(unsigned long id,
  182.               IWindow* parent);
  183.  
  184.   IEntryField(const IWindowHandle& handle);
  185.  
  186.   virtual ~IEntryField();
  187.  
  188. /*---------------------------- Enumerations ------------------------------------
  189. | The following enumerations are defined:                                      |
  190. |   Alignment - Used to replace the alignment style.  Values are:              |
  191. |               left   - Sets the text in the control as left-justified.       |
  192. |               center - Sets the text in the control as centered.             |
  193. |               right  - Sets the text in the control as right-justified.      |
  194. |                                                                              |
  195. |   CharType  - Used to replace the character type style.  Values are:         |
  196. |                sbcs  - Sets the entry field to accept single-byte text only. |
  197. |                dbcs  - Sets the entry field to accept double-byte text only. |
  198. |                mixed - Sets the entry field to accept text that is a mixture |
  199. |                        of single-byte character set (SBCS) and double-byte   |
  200. |                        character set (DBCS) characters.  Conversion from an  |
  201. |                        ASCII DBCS code page to an EBCDIC DBCS code page can  |
  202. |                        result in a possible increase in the length of the    |
  203. |                        data because of the addition of shift-in/shift-out    |
  204. |                        characters, but will not exceed the text limit of     |
  205. |                        the entry field.                                      |
  206. |                any   - Sets the entry field to accept text that is a mixture |
  207. |                        of SBCS and DBCS characters.                          |
  208. |                        NOTE: If the text contains both SBCS and DBCS         |
  209. |                              characters and will be converted from an ASCII  |
  210. |                              code page into an EBCDIC code page, this style  |
  211. |                              causes an entry field to ignore accounting for  |
  212. |                              shift-in and shift-out characters that would    |
  213. |                              be introduced into its text.  The opposite of   |
  214. |                              mixed.                                          |
  215. |                                                                              |
  216. |   ColorArea - Used to replace the color for a particular region.  Values     |
  217. |               are:                                                           |
  218. |               foreground          - Sets the color for foreground text.      |
  219. |               background          - Sets the color of the background for     |
  220. |                                     the text.                                |
  221. |               disabledForeground  - Sets the foreground color for disabled   |
  222. |                                     text.                                    |
  223. |               highlightForeground - Sets the foreground color for selected   |
  224. |                                     text.                                    |
  225. |               border              - Sets the color of the border that        |
  226. |                                     surrounds the entry field control.       |
  227. |                                     See margin.                              |
  228. ------------------------------------------------------------------------------*/
  229. enum ColorArea {
  230.   foreground,
  231.   background,
  232.   disabledForeground,
  233.   highlightForeground,
  234.   border };
  235. enum Alignment {
  236.   left,
  237.   center,
  238.   right };
  239. enum CharType {
  240.   sbcs,
  241.   dbcs,
  242.   any,
  243.   mixed };
  244.  
  245. /*-------------------------------- Attributes ----------------------------------
  246. | These operations can be used to query and change the style of the entry field|
  247. | control.                                                                     |
  248. |   setAlignment      - Sets the alignment of the entry field control.         |
  249. |   alignment         - Returns the currently set alignment.                   |
  250. |   setCharType       - Sets the character type of the entry field control.    |
  251. |   charType          - Returns the currently set character type.              |
  252. |   enableAutoScroll  - Enables or disables the auto-scroll style on an entry  |
  253. |                       field control.                                         |
  254. |   disableAutoScroll - Disables the auto-scroll style on an entry field       |
  255. |                       control.                                               |
  256. |   isAutoScroll      - Queries whether the auto-scroll style is set on an     |
  257. |                       entry field control.                                   |
  258. |   enableMargin      - Enables or disables the margin style on an entry field |
  259. |                       control.                                               |
  260. |   disableMargin     - Disables the margin style on an entry field control.   |
  261. |   isMargin          - Queries whether the margin style is set on an entry    |
  262. |                       field control.                                         |
  263. |   enableCommand     - Enables or disables the command style on an entry      |
  264. |                       field control.                                         |
  265. |   disableCommand    - Disables the command style on an entry field control.  |
  266. |   isCommand         - Queries whether the command style is set on an entry   |
  267. |                       field control.                                         |
  268. |   enableAutoTab     - Enables or disables the auto-tab style on an entry     |
  269. |                       field control.                                         |
  270. |   disableAutoTab    - Disables the auto-tab style on an entry field control. |
  271. |   isAutoTab         - Queries whether the auto-tab style is set on an entry  |
  272. |                       field control.                                         |
  273. ------------------------------------------------------------------------------*/
  274. Alignment
  275.   alignment() const;
  276. CharType
  277.   charType() const;
  278. IEntryField
  279.   &setAlignment(Alignment alignment),
  280.   &setCharType(CharType type),
  281.   &enableAutoScroll(Boolean enable=true),
  282.   &disableAutoScroll(),
  283.   &enableMargin(Boolean enable=true),
  284.   &disableMargin(),
  285.   &enableCommand(Boolean enable=true),
  286.   &disableCommand(),
  287.   &enableAutoTab(Boolean enable=true),
  288.   &disableAutoTab();
  289. Boolean
  290.   isAutoScroll() const,
  291.   isMargin() const,
  292.   isCommand() const,
  293.   isAutoTab() const;
  294.  
  295. /*-------------------------------- Clipboard Operations ------------------------
  296. | These operations allow data to be transferred between the clipboard and the  |
  297. | entry field control.  Each of these operations deals with the selected text  |
  298. | in the entry field control.                                                  |
  299. |   cut     - Removes the selected text from the entry field control and       |
  300. |             puts it in the clipboard.                                        |
  301. |   copy    - Copies the selected text to the clipboard.                       |
  302. |   paste   - Copies text from the clipboard to the entry field control,       |
  303. |             replacing any text that is selected.                             |
  304. |   clear   - Replaces the selected text in the entry field with blanks.       |
  305. |   discard - Deletes the selected text.                                       |
  306. ------------------------------------------------------------------------------*/
  307. virtual IEntryField
  308.   &cut(),
  309.   ©(),
  310.   &paste(),
  311.   &clear(),
  312.   &discard();
  313.  
  314.  
  315. /*-------------------------------- Overloaded Disable/Enable Window ------------
  316. | These operations are overloaded to ensure a disabled entry field is set to   |
  317. | read-only state to prevent user input.                                       |
  318. |   disable - Disables an entry field control.                                 |
  319. |   enable  - Enables or disables an entry field control.                      |
  320. ------------------------------------------------------------------------------*/
  321. IEntryField
  322.   &disable(),
  323.   &enable(Boolean enable=true);
  324.  
  325. /*-------------------------------- Insert Mode ---------------------------------
  326. | The following operations toggle insert mode in the entry field.              |
  327. |   enableInsertMode  - Enables the entry field for insert mode and changes    |
  328. |                       the cursor appearance accordingly.                     |
  329. |   disableInsertMode - Enables the entry field for overtype mode and changes  |
  330. |                       the cursor appearance accordingly.                     |
  331. |   isInsertMode      - Queries whether the entry field is in insert mode.     |
  332. ------------------------------------------------------------------------------*/
  333. IEntryField
  334.   &enableInsertMode(Boolean insert=true),
  335.   &disableInsertMode();
  336. Boolean
  337.   isInsertMode() const;
  338.  
  339. /*-------------------------------- Read-only Mode ------------------------------
  340. | The following operations toggle read-only mode in the entry field, which     |
  341. | specifies if the end user can change the entry field text.                   |
  342. |   enableDataUpdate  - Enables or disables the read-only mode on an entry     |
  343. |                       field control.                                         |
  344. |   disableDataUpdate - Prevents characters from being inserted or changed in  |
  345. |                       the text of the control.                               |
  346. |   isReadOnly        - Queries whether the entry field control is in          |
  347. |                       read-only mode.                                        |
  348. ------------------------------------------------------------------------------*/
  349. IEntryField
  350.   &enableDataUpdate(Boolean update=true),
  351.   &disableDataUpdate();
  352. Boolean
  353.   isReadOnly() const;
  354.  
  355.  
  356. /*-------------------------------- Text Limit ----------------------------------
  357. | The following operations set and query the text limit of the entry field:    |
  358. |   setLimit - Sets the maximum number of bytes the entry field is             |
  359. |              is allowed to hold.  Throws an IInvalidParameter exception if   |
  360. |              the entry field already contains more characters than the       |
  361. |              proposed limit.                                                 |
  362. |   limit    - Returns the length of the longest text the entry field can      |
  363. |              hold, in bytes.                                                 |
  364. ------------------------------------------------------------------------------*/
  365. IEntryField
  366.   &setLimit(unsigned long textLimit),
  367.   &setLimit(const IResourceId& textLimit);
  368. unsigned long
  369.   limit() const;
  370.  
  371. /*-------------------------------- Selected Text -------------------------------
  372. | The following operations may be used to manipulate selected text:            |
  373. |   end           - Data member that denotes the end of the text for           |
  374. |                   selecting text.                                            |
  375. |   selectRange   - Selects a range of text.  The selected range is the        |
  376. |                   0-based index of the first character being selected and    |
  377. |                   the 0-based index of the last character being selected.    |
  378. |                   If no range is specified, all of the text will be          |
  379. |                   selected.  Specifying a range with the lower and upper     |
  380. |                   values equal will cause the selection to become an         |
  381. |                   insertion point.                                           |
  382. |   selectedRange - Returns the range of the selected text.  If no text is     |
  383. |                   selected, a range of (cursor position, cursor position)    |
  384. |                   is returned by selectedRange.  The selected range is the   |
  385. |                   0-based index of the first character selected and the      |
  386. |                   0-based index of the last character selected.              |
  387. |   selectedText  - Returns the selected text string.                          |
  388. ------------------------------------------------------------------------------*/
  389. static const long end;
  390. IEntryField&
  391.   selectRange(const IRange& range=IRange(0,end));
  392. IRange
  393.   selectedRange() const;
  394. IString
  395.   selectedText() const;
  396.  
  397. /*-------------------------------- Left Index ----------------------------------
  398. |   setLeftIndex - Sets the first character displayed at the left edge of the  |
  399. |                  entry field control. The index is 0-based.                  |
  400. |   leftIndex    - Returns the index of the first character displayed at the   |
  401. |                  left edge of the entry field control. The index is 0-based. |
  402. ------------------------------------------------------------------------------*/
  403. IEntryField&
  404.   setLeftIndex(unsigned long index);
  405. unsigned long
  406.   leftIndex() const;
  407.  
  408. /*-------------------------------- Test Operations -----------------------------
  409. |   hasChanged      - Queries whether the entry field text has changed since   |
  410. |                     the last query.                                          |
  411. |   isEmpty         - Queries whether the entry field is empty.                |
  412. |   hasSelectedText - Queries whether any of the entry field text is selected. |
  413. ------------------------------------------------------------------------------*/
  414. Boolean
  415.   hasChanged() const,
  416.   isEmpty() const,
  417.   hasSelectedText() const;
  418.  
  419.  
  420. /*----------------------------- Color Functions --------------------------------
  421. |  setColor - Changes the color of the given color region.                     |
  422. |  color    - Returns the color of the given color region.                     |
  423. ------------------------------------------------------------------------------*/
  424. IEntryField
  425.   &setColor(ColorArea value, const IColor& color);
  426.  
  427. IColor
  428.   color(ColorArea value) const;
  429.  
  430. protected:
  431. /*----------------------------- Layout Size ------------------------------------
  432. | calcMinimumSize - Returns the recommended minimum size of this entry field   |
  433. |                   control.  The size is based on the length limit of the     |
  434. |                   text string and the current font.                          |
  435. ------------------------------------------------------------------------------*/
  436. virtual ISize
  437.   calcMinimumSize() const;
  438.  
  439. /*----------------------------- SetStyle ---------------------------------------
  440. | setStyle - Replaces the style of an entry field control, while preserving    |
  441. |            the cursor position and selected text.                            |
  442. ------------------------------------------------------------------------------*/
  443. virtual IEntryField&
  444.   setStyle(unsigned long style);
  445.  
  446.   IEntryField();
  447.  
  448.  
  449. private:
  450. /*--------------------------------- PRIVATE ----------------------------------*/
  451.   IEntryField(const IEntryField&);
  452.   IEntryField& operator=(const IEntryField&);
  453.  
  454. static Style
  455.    currentDefaultStyle;
  456. IRange
  457.   getCursorInfo() const;
  458. void
  459.   setCursorInfo(const IRange& range);
  460.  
  461. enum ReadStatus { doesntMatter, wasInput, wasRead,
  462.                   wasInputButReset, wasReadButReset };
  463. ReadStatus
  464.   eReadStatus;
  465. };  // class IEntryField
  466.  
  467. INESTEDBITFLAGCLASSFUNCS(Style, IEntryField);
  468.                                   // global style functions
  469.  
  470. /*----------------------------------------------------------------------------*/
  471. /* Resume compiler default packing.                                           */
  472. /*----------------------------------------------------------------------------*/
  473. #pragma pack()
  474.  
  475. #endif  /* _IENTRYFD_ */
  476.