home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IENTRYFD.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
26KB
|
476 lines
#ifndef _IENTRYFD_
#define _IENTRYFD_
/*******************************************************************************
* FILE NAME: ientryfd.hpp *
* *
* DESCRIPTION: *
* Declaration of the class(es): *
* IEntryField - This class creates and manages the entry field control *
* window. *
* *
* COPYRIGHT: *
* Licensed Materials - Property of IBM *
* (C) Copyright IBM Corporation 1992, 1993 *
* All Rights Reserved *
* US Government Users Restricted Rights - Use, duplication, or disclosure *
* restricted by GSA ADP Schedule Contract with IBM Corp. *
* *
*******************************************************************************/
#ifndef _ITEXTCTL_
#include <itextctl.hpp>
#endif
// Forward declarations for other classes:
class IRange;
class ISize;
class IString;
class IResourceId;
class IColor;
#ifndef _IRECT_
#include <irect.hpp>
#endif
#ifndef _IBITFLAG_
#include <ibitflag.hpp>
#endif
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
class IEntryField : public ITextControl {
typedef ITextControl Inherited;
/*******************************************************************************
* The IEntryField class creates and manages an entry field control. *
* *
* Specific keystroke processing, such as creating a numeric-only input field, *
* can be implemented by subclassing the IKeyboardHandler class and attaching *
* the handler to the entry field object. *
* *
* EXAMPLE: *
* IEntryField efEntry(ID_ENTRY, this, this, IRectangle(10,10,90,22)); *
* *
* To change the style of the entry field after it has been created, use *
* functions such as: *
* setAlignment(IEntryField::center). *
*******************************************************************************/
public:
/*---------------------- Style --------------------------------------------
The following functions provide a means to set and query entry field
styles:
Style - Nested class that provides static members that define the set of
valid entry field styles. These styles can be used in
conjunction with the styles defined by the nested classes
IWindow::Style and IControl::Style. For example, you could
define an instance of the IEntryField::Style class and
initialize it like:
IEntryField::Style
style = IEntryField::alignLeft | IControl::tabStop;
You can specify and object of this type when constructing the
IEntryField object. A customizable default is used if no styles
are specified. Once the object is constructed, IEntryField,
IWindow, and IControl member functions can be used to set or
query the object's style.
The declaration of the IEntryField::Style nested class is
generated by the INESTEDBITFLAGCLASSDEF2 macro.
The valid entry field styles are:
classDefaultStyle - Original default style for this class, which is
alignLeft | anyData | margin | autoScroll |
IWindow::visible.
autoScroll - If the user tries to move off the end of a line, the
entry field automatically scrolls one-third the width
of the window in the appropriate direction.
margin - Causes a border to be drawn around the entry field,
with a margin between the border and the entry field.
The margin's size is determined by the current font
being used for entry field text (half a
character-width wide and half a character-height
high).
Since the margin and border are drawn around the
entry field, using the margin style does not change
the position of the entry field itself. For example,
if an entry field is positioned at (100,100), and has
a margin and border width and height of 2, the
lower-left corner of the border would be positioned
at (98,98).
autoTab - Causes a tab key to be generated when the entry field
is filled by adding a character at the text limit of
the entry field text.
readOnly - Prevents insertions or changes to the text in the
control.
command - Creates information used by the Help Manager to
provide command help if the user requests help for
this field. No more than one entry field on each
window should be given this style.
unreadable - Causes the text to be displayed as an asterisk for
each character.
leftAlign - Makes the text in the entry field left-justified.
centerAlign - Makes the text in the entry field centered.
rightAlign - Makes the text in the entry field right-justified.
anyData - Sets the entry field to accept text that is a mixture
of single-byte character set (SBCS) and double-byte
character set (DBCS) characters.
NOTE: If the text contains both SBCS and DBCS
characters and will be converted from an ASCII
code page into an EBCDIC code page, this style
causes an entry field to ignore accounting for
shift-in and shift-out characters that would be
introduced into its text. The opposite of
mixedData.
sbcsData - Sets the entry field to accept single-byte text only.
dbcsData - Sets the entry field to accept double-byte text only.
mixedData - Sets the entry field to accept text that is a mixture
of SBCS and DBCS characters. Conversion from an
ASCII DBCS code page to an EBCDIC DBCS code page can
result in a possible increase in the length of the
data because of the addition of shift-in/shift-out
characters, but will not exceed the text limit of the
entry field.
The following functions provide a means of getting and setting the default
style for this class:
defaultStyle - Returns the current default style. This is the same as
classDefaultStyle unless setDefaultStyle has been
called.
setDefaultStyle - Sets the default style for all subsequent entry fields.
-------------------------------------------------------------------------*/
INESTEDBITFLAGCLASSDEF2(Style, IEntryField, IWindow, IControl);
static const Style
classDefaultStyle,
autoScroll,
margin,
autoTab,
readOnly,
command,
unreadable,
leftAlign,
centerAlign,
rightAlign,
anyData,
sbcsData,
dbcsData,
mixedData;
static Style
defaultStyle();
static void
setDefaultStyle(Style style);
/*------------------------ Constructors ----------------------------------------
| You can construct an instance of this class in the following ways: |
| - From a control ID for the entry field, parent and owner windows, |
| initial rectangle, and style. This creates the specified entry field |
| control and an object for it. |
| - From the ID of an existing entry field control on a parent dialog |
| window. This creates the object for the specified entry field control. |
| - From the window handle of an existing entry field control. This |
| creates the object for the specified entry field control. |
------------------------------------------------------------------------------*/
IEntryField(unsigned long id,
IWindow* parent,
IWindow* owner,
const IRectangle& initial= IRectangle(),
const Style& style = defaultStyle() );
IEntryField(unsigned long id,
IWindow* parent);
IEntryField(const IWindowHandle& handle);
virtual ~IEntryField();
/*---------------------------- Enumerations ------------------------------------
| The following enumerations are defined: |
| Alignment - Used to replace the alignment style. Values are: |
| left - Sets the text in the control as left-justified. |
| center - Sets the text in the control as centered. |
| right - Sets the text in the control as right-justified. |
| |
| CharType - Used to replace the character type style. Values are: |
| sbcs - Sets the entry field to accept single-byte text only. |
| dbcs - Sets the entry field to accept double-byte text only. |
| mixed - Sets the entry field to accept text that is a mixture |
| of single-byte character set (SBCS) and double-byte |
| character set (DBCS) characters. Conversion from an |
| ASCII DBCS code page to an EBCDIC DBCS code page can |
| result in a possible increase in the length of the |
| data because of the addition of shift-in/shift-out |
| characters, but will not exceed the text limit of |
| the entry field. |
| any - Sets the entry field to accept text that is a mixture |
| of SBCS and DBCS characters. |
| NOTE: If the text contains both SBCS and DBCS |
| characters and will be converted from an ASCII |
| code page into an EBCDIC code page, this style |
| causes an entry field to ignore accounting for |
| shift-in and shift-out characters that would |
| be introduced into its text. The opposite of |
| mixed. |
| |
| ColorArea - Used to replace the color for a particular region. Values |
| are: |
| foreground - Sets the color for foreground text. |
| background - Sets the color of the background for |
| the text. |
| disabledForeground - Sets the foreground color for disabled |
| text. |
| highlightForeground - Sets the foreground color for selected |
| text. |
| border - Sets the color of the border that |
| surrounds the entry field control. |
| See margin. |
------------------------------------------------------------------------------*/
enum ColorArea {
foreground,
background,
disabledForeground,
highlightForeground,
border };
enum Alignment {
left,
center,
right };
enum CharType {
sbcs,
dbcs,
any,
mixed };
/*-------------------------------- Attributes ----------------------------------
| These operations can be used to query and change the style of the entry field|
| control. |
| setAlignment - Sets the alignment of the entry field control. |
| alignment - Returns the currently set alignment. |
| setCharType - Sets the character type of the entry field control. |
| charType - Returns the currently set character type. |
| enableAutoScroll - Enables or disables the auto-scroll style on an entry |
| field control. |
| disableAutoScroll - Disables the auto-scroll style on an entry field |
| control. |
| isAutoScroll - Queries whether the auto-scroll style is set on an |
| entry field control. |
| enableMargin - Enables or disables the margin style on an entry field |
| control. |
| disableMargin - Disables the margin style on an entry field control. |
| isMargin - Queries whether the margin style is set on an entry |
| field control. |
| enableCommand - Enables or disables the command style on an entry |
| field control. |
| disableCommand - Disables the command style on an entry field control. |
| isCommand - Queries whether the command style is set on an entry |
| field control. |
| enableAutoTab - Enables or disables the auto-tab style on an entry |
| field control. |
| disableAutoTab - Disables the auto-tab style on an entry field control. |
| isAutoTab - Queries whether the auto-tab style is set on an entry |
| field control. |
------------------------------------------------------------------------------*/
Alignment
alignment() const;
CharType
charType() const;
IEntryField
&setAlignment(Alignment alignment),
&setCharType(CharType type),
&enableAutoScroll(Boolean enable=true),
&disableAutoScroll(),
&enableMargin(Boolean enable=true),
&disableMargin(),
&enableCommand(Boolean enable=true),
&disableCommand(),
&enableAutoTab(Boolean enable=true),
&disableAutoTab();
Boolean
isAutoScroll() const,
isMargin() const,
isCommand() const,
isAutoTab() const;
/*-------------------------------- Clipboard Operations ------------------------
| These operations allow data to be transferred between the clipboard and the |
| entry field control. Each of these operations deals with the selected text |
| in the entry field control. |
| cut - Removes the selected text from the entry field control and |
| puts it in the clipboard. |
| copy - Copies the selected text to the clipboard. |
| paste - Copies text from the clipboard to the entry field control, |
| replacing any text that is selected. |
| clear - Replaces the selected text in the entry field with blanks. |
| discard - Deletes the selected text. |
------------------------------------------------------------------------------*/
virtual IEntryField
&cut(),
©(),
&paste(),
&clear(),
&discard();
/*-------------------------------- Overloaded Disable/Enable Window ------------
| These operations are overloaded to ensure a disabled entry field is set to |
| read-only state to prevent user input. |
| disable - Disables an entry field control. |
| enable - Enables or disables an entry field control. |
------------------------------------------------------------------------------*/
IEntryField
&disable(),
&enable(Boolean enable=true);
/*-------------------------------- Insert Mode ---------------------------------
| The following operations toggle insert mode in the entry field. |
| enableInsertMode - Enables the entry field for insert mode and changes |
| the cursor appearance accordingly. |
| disableInsertMode - Enables the entry field for overtype mode and changes |
| the cursor appearance accordingly. |
| isInsertMode - Queries whether the entry field is in insert mode. |
------------------------------------------------------------------------------*/
IEntryField
&enableInsertMode(Boolean insert=true),
&disableInsertMode();
Boolean
isInsertMode() const;
/*-------------------------------- Read-only Mode ------------------------------
| The following operations toggle read-only mode in the entry field, which |
| specifies if the end user can change the entry field text. |
| enableDataUpdate - Enables or disables the read-only mode on an entry |
| field control. |
| disableDataUpdate - Prevents characters from being inserted or changed in |
| the text of the control. |
| isReadOnly - Queries whether the entry field control is in |
| read-only mode. |
------------------------------------------------------------------------------*/
IEntryField
&enableDataUpdate(Boolean update=true),
&disableDataUpdate();
Boolean
isReadOnly() const;
/*-------------------------------- Text Limit ----------------------------------
| The following operations set and query the text limit of the entry field: |
| setLimit - Sets the maximum number of bytes the entry field is |
| is allowed to hold. Throws an IInvalidParameter exception if |
| the entry field already contains more characters than the |
| proposed limit. |
| limit - Returns the length of the longest text the entry field can |
| hold, in bytes. |
------------------------------------------------------------------------------*/
IEntryField
&setLimit(unsigned long textLimit),
&setLimit(const IResourceId& textLimit);
unsigned long
limit() const;
/*-------------------------------- Selected Text -------------------------------
| The following operations may be used to manipulate selected text: |
| end - Data member that denotes the end of the text for |
| selecting text. |
| selectRange - Selects a range of text. The selected range is the |
| 0-based index of the first character being selected and |
| the 0-based index of the last character being selected. |
| If no range is specified, all of the text will be |
| selected. Specifying a range with the lower and upper |
| values equal will cause the selection to become an |
| insertion point. |
| selectedRange - Returns the range of the selected text. If no text is |
| selected, a range of (cursor position, cursor position) |
| is returned by selectedRange. The selected range is the |
| 0-based index of the first character selected and the |
| 0-based index of the last character selected. |
| selectedText - Returns the selected text string. |
------------------------------------------------------------------------------*/
static const long end;
IEntryField&
selectRange(const IRange& range=IRange(0,end));
IRange
selectedRange() const;
IString
selectedText() const;
/*-------------------------------- Left Index ----------------------------------
| setLeftIndex - Sets the first character displayed at the left edge of the |
| entry field control. The index is 0-based. |
| leftIndex - Returns the index of the first character displayed at the |
| left edge of the entry field control. The index is 0-based. |
------------------------------------------------------------------------------*/
IEntryField&
setLeftIndex(unsigned long index);
unsigned long
leftIndex() const;
/*-------------------------------- Test Operations -----------------------------
| hasChanged - Queries whether the entry field text has changed since |
| the last query. |
| isEmpty - Queries whether the entry field is empty. |
| hasSelectedText - Queries whether any of the entry field text is selected. |
------------------------------------------------------------------------------*/
Boolean
hasChanged() const,
isEmpty() const,
hasSelectedText() const;
/*----------------------------- Color Functions --------------------------------
| setColor - Changes the color of the given color region. |
| color - Returns the color of the given color region. |
------------------------------------------------------------------------------*/
IEntryField
&setColor(ColorArea value, const IColor& color);
IColor
color(ColorArea value) const;
protected:
/*----------------------------- Layout Size ------------------------------------
| calcMinimumSize - Returns the recommended minimum size of this entry field |
| control. The size is based on the length limit of the |
| text string and the current font. |
------------------------------------------------------------------------------*/
virtual ISize
calcMinimumSize() const;
/*----------------------------- SetStyle ---------------------------------------
| setStyle - Replaces the style of an entry field control, while preserving |
| the cursor position and selected text. |
------------------------------------------------------------------------------*/
virtual IEntryField&
setStyle(unsigned long style);
IEntryField();
private:
/*--------------------------------- PRIVATE ----------------------------------*/
IEntryField(const IEntryField&);
IEntryField& operator=(const IEntryField&);
static Style
currentDefaultStyle;
IRange
getCursorInfo() const;
void
setCursorInfo(const IRange& range);
enum ReadStatus { doesntMatter, wasInput, wasRead,
wasInputButReset, wasReadButReset };
ReadStatus
eReadStatus;
}; // class IEntryField
INESTEDBITFLAGCLASSFUNCS(Style, IEntryField);
// global style functions
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing. */
/*----------------------------------------------------------------------------*/
#pragma pack()
#endif /* _IENTRYFD_ */