home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
ISPINBT.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
27KB
|
504 lines
#ifndef _ISPINBT_
#define _ISPINBT_
/*******************************************************************************
* FILE NAME: ispinbt.hpp *
* *
* DESCRIPTION: *
* Declaration of the class(es): *
* ISpinButton - This class creates and manages the spin button 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 _ICONTROL_
#include <icontrol.hpp>
#endif
#ifndef _IRECT_
#include <irect.hpp>
#endif
#ifndef _ISTRING_
#include <istring.hpp>
#endif
class IColor;
class IRange;
class IResourceId;
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
/*----------------------------------------------------------------------------*/
/* Turn off warning for compiler generated copy/assignment */
/*----------------------------------------------------------------------------*/
#pragma info(nocpy)
class ISpinButton : public IControl {
typedef IControl
Inherited;
/*******************************************************************************
* The ISpinButton class creates and manages the spin button control window. *
*******************************************************************************/
public :
/*----------------------------- Style ------------------------------------------
| The valid spin button styles are: |
| classDefaultStyle - The original default style for this class, which is |
| master | leftAlign | allCharacters | IWindow::visible. |
| master - Specifies that the spin button component consists of: |
| - At least one single line entry field (SLE), or |
| spin field. |
| - Two arrows, the Up arrow and the Down arrow. |
| When a spin button contains more than one spin field, |
| the master component contains the spin arrows. If |
| the component contains only one spin field, it must |
| be a master. |
| servant - Allows you to create a multiple field spin button by |
| spinning servants from the master. This style |
| requires the setMaster function be called to define |
| the master spin field. |
| leftAlign - Makes the text left-justified. |
| centerAlign - Centers the text. |
| rightAlign - Makes the text right-justified. |
| allCharacters - Permits any character to be typed in the spin field. |
| numericOnly - Specifies that only digits between 0 and 9 and the |
| minus sign (-) can be typed in the spin field. |
| noBorder - Suppresses the drawing of a border. |
| readOnly - Prevents entering input into the spin field. |
| fastSpin - Enables the spin button to increase the spin speed |
| with time. The speed doubles every two seconds. |
| padWithZeros - Pads the displayed number with zeros at the front. |
| |
| 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 spin buttons. |
-------------------------------------------------------------------------------*/
INESTEDBITFLAGCLASSDEF2(Style, ISpinButton, IWindow, IControl);
static const Style
classDefaultStyle,
master,
servant,
allCharacters,
numericOnly,
readOnly,
leftAlign,
centerAlign,
rightAlign,
noBorder,
fastSpin,
padWithZeros;
static Style
defaultStyle();
static void
setDefaultStyle(const Style& style);
/*------------------------ Constructors ----------------------------------------
| You can construct instances of this class in the following ways: |
| - From a control ID, parent and owner windows, rectangle, and style. |
| This creates the specified spin button control and an object for it. |
| - From the ID of a spin button control on a dialog window. This creates |
| the object for the specified spin button control. |
| - From the window handle of an existing spin button control. This |
| creates the object for the specified spin button control. |
------------------------------------------------------------------------------*/
ISpinButton ( unsigned long id,
IWindow* parent,
IWindow* owner,
const IRectangle &initial = IRectangle(),
const Style &style = defaultStyle() );
ISpinButton ( unsigned long id,
IWindow* parentDialog );
ISpinButton ( const IWindowHandle& handle );
virtual
~ISpinButton ( );
/*---------------------------- Enumerator --------------------------------------
| The following enumerations provide a means of setting the style of |
| instances of this class: |
| Type - Enumeration used to define the types of values that can be |
| entered in the spin button field. The valid values are: |
| alphanumeric - Specifies the spin button field contains a |
| list of text. |
| numeric - Specifies the spin button field contains a |
| range of numbers. |
| |
| Alignment - Enumeration used to align the text in the spin field. The |
| valid values are: |
| left - Left-justifies the text in the spin field. |
| center - Centers the text in the spin field. |
| right - Right-justifies the text in the spin field. |
------------------------------------------------------------------------------*/
enum Type {
alphanumeric,
numeric
};
enum Alignment {
left,
right,
center
};
/*---------------------------- Style Functions ---------------------------------
| The following functions provide a means to change the style of instances |
| of this class: |
| setReadOnly - Disables input in the spin field. |
| setFastSpin - Causes the spin button to increase the spin speed with |
| time. The speed doubles every two seconds until the |
| upper or lower range is reached. At this point, the |
| speed resets to the original speed and again doubles |
| every two seconds. This member function should not be |
| invoked on a master spin button that has servants spun |
| from it. |
| setInputType - Changes the permitted input type for the spin field. |
| NOTE: This function does not work in OS/2 Version 2.0. |
| setAlignment - Changes the text alignment in the spin field. |
| enableBorder - Draws a border. |
| disableBorder - Suppresses the drawing of a border. |
------------------------------------------------------------------------------*/
ISpinButton
&setReadOnly ( Boolean readOnly = true ),
&setFastSpin ( Boolean fast = true ),
&setInputType ( Type aValue = alphanumeric ),
&setAlignment ( Alignment aValue = left ),
&enableBorder ( Boolean enable = true ),
&disableBorder ( );
/*-------------------------- Style Testing -------------------------------------
| The following functions provides a mean to test the style of instances of |
| this class: |
| isMaster - Returns true if the spin button is a master. |
| isServant - Returns true if the spin button is a servant. |
| isReadOnly - Returns true if the user is not permitted to type in |
| the spin field. |
| isFastSpin - Returns true if the spin speed is doubled every two |
| seconds. |
| isBorder - Returns true if the spin button has a border. |
| alignment - Returns the text alignment in the spin field. |
| inputTypeAllowed - Returns the data type permitted in the spin field. |
------------------------------------------------------------------------------*/
Boolean
isMaster ( ) const,
isServant ( ) const,
isReadOnly ( ) const,
isFastSpin ( ) const,
isBorder ( ) const;
Alignment
alignment ( ) const;
Type
inputTypeAllowed ( ) const;
/*---------------------- ColorArea Enumerator ----------------------------------
| ColorArea - Enumeration that is used to replace the color of a |
| particular region of the spin field. The valid values are: |
| foreground - Sets the color of the foreground 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 spin field, if any. |
------------------------------------------------------------------------------*/
enum ColorArea {
foreground,
disabledForeground,
highlightForeground,
border };
/*------------------------- Set Limit & Spin -----------------------------------
| The following functions provide a means to manage the spin field of |
| instances of this class: |
| setMaster - Defines a servant spin button's master. The spin button must |
| be a servant, and the spin button passed as the master |
| argument must be a master. |
| setColor - Changes the color of the specified spin field area. |
| setLimit - Sets the number of characters permitted in the spin field. |
| The original value at construction is 255. |
| NOTE: Calling this function with a limit that does not allow |
| all numbers in the spin button range to be displayed |
| leads to erratic results when the button is spun. For |
| example, if the range is 1 to 100 and the limit is set |
| to 2, the button will spin up to 99 and wrap to 10 |
| instead of 1. Spinning down, the button wraps from |
| 1 to 10. This is an OS/2 Version 2.0 problem. |
| spinDown - Spins the button down the specified number of times. |
| spinUp - Spins the button up the specified number of times. |
| color - Returns the color of the specific spin field area. |
| isValid - Returns true if the contents of the spin field are within the |
| number range or matches one of the text values. If the |
| updateContents argument is set to true, the spin field will |
| be updated as follows: |
| - If the spin button contains a number range and the contents |
| of the spin field are out-of-range, the spin field is set |
| to the last valid value. |
| - If the spin button contains text values and the contents of |
| the spin field matches a text value, but the case is |
| different, the contents of the spin field are set to match |
| the case of the spin button text. If the values do not |
| match, the spin field is set to the last valid value. |
------------------------------------------------------------------------------*/
ISpinButton
&setMaster ( const ISpinButton& master ),
&setColor ( ColorArea value,
const IColor& color ),
&setLimit ( unsigned long aNumber ),
&spinDown ( unsigned long spinBy = 1 ),
&spinUp ( unsigned long spinBy = 1 );
IColor
color ( ColorArea value ) const;
Boolean
isValid ( Boolean updateContents = false ) const;
/*------------------------- Number Range Operations ----------------------------
| The following functions provides a means to manage the number range of |
| instances of this class. These functions only apply to spin buttons that |
| have a number range: |
| setCurrent - Sets the spin field to the specified value. This function |
| is the same as spinTo. |
| spinTo - Sets the spin field to the specified value. This function |
| is the same as setCurrent. |
| setRange - Sets the lower and upper range of the spin button numbers. |
| If the override argument is set to true and the current |
| value in the spin field is outside the new range, the |
| current value in the spin field will not change. |
| range - Returns the lower and upper range of the spin button. |
| NOTE: This function causes a trap in OS/2 Version 2.0. |
| value - Returns the current value displayed in the spin field. |
| setValue - Sets the displayed value of the spin field, regardless of |
| the validity of the number. |
------------------------------------------------------------------------------*/
ISpinButton
&setCurrent ( long aValue ),
&spinTo ( long aValue ),
&setRange ( const IRange& aNewRange,
Boolean override = false );
IRange
range ( ) const;
long
value ( ) const;
ISpinButton
&setValue ( long aValue );
/*-------------------- Text Query, Validate & Remove ---------------------------
| The following functions provide the means to query the text contents of |
| the spin field and remove the contents of instances of this class. |
| These functions only apply to spin buttons with text: |
| text - Returns the displayed contents of the spin field. |
| setText - Sets the displayed contents of the spin field, regardless of |
| the validity of the text. This does not alter the contents |
| of the spin button array. |
| removeAll - Removes all text in the spin button. |
------------------------------------------------------------------------------*/
IString
text ( ) const;
ISpinButton
&setText ( const char* string ),
&setText ( const IResourceId& residText ),
&removeAll ( );
class Cursor : public IVBase {
/*******************************************************************************
* The ISpinButton::Cursor class creates and manages the cursor for a spin *
* button that has text. Each cursor maintains a copy of the spin button text *
* on construction. It is not necessary to use a cursor in a spin button that *
* has a number range. *
*******************************************************************************/
public:
/*------------------ Constructor/Destructor ---------------------------------
| The only way to construct instances of this class is with an instance |
| of a spin button. The spin button text is copied into the cursor. |
---------------------------------------------------------------------------*/
Cursor ( const ISpinButton& spinButton );
virtual
~Cursor ( );
/*------------------------ Cursor Movement ------------------------
| The following functions provides the means to change the cursor |
| position: |
| setToFirst - Points to the first item in the text list. |
| setToNext - Points to the next item in the text list. If |
| there is none, it invalidates the cursor. |
| setToPrevious - Points to the previous item in the text list. |
| If there is none, it invalidates the cursor. |
| setToLast - Points to the last item in the text list. |
-----------------------------------------------------------------*/
Boolean
setToFirst ( ),
setToNext ( ),
setToPrevious ( ),
setToLast ( );
/*--------------- Cursor Validation -------------------------------
| The following functions provide a means of checking the |
| validity, and invalidating the cursor: |
| isValid - Queries whether this cursor points to a valid |
| item. |
| invalidate - Flags this cursor as invalid. |
+----------------------------------------------------------------*/
Boolean
isValid ( ) const;
void
invalidate ( );
private: /*------------------- PRIVATE ------------------------*/
friend class
ISpinButton;
long
lCurrent;
unsigned long
ulCurCount;
const ISpinButton
&rSpBut;
};
/*-------------------------- Text-List Operations ------------------------------
| The following functions provides the means to manage the text array of |
| instances of this class. These functions only apply to spin buttons that |
| have the allCharacters style. |
| |
| elementAt - Returns the string at the cursor position. |
| refreshText - Sets the local list of text in the instance to the real |
| spin button. This function provides the ability to add, |
| remove, and replace multiple text entries before applying |
| the changes to the spin button. This is recommended when |
| adding a large quantity of text. Otherwise, if the |
| immediateUpdate argument is set to true on add, remove, and |
| replace functions, the spin button will be updated |
| immediately. |
| removeAt - Removes the item at the cursor position and sets the cursor |
| to the item that precedes the removed item. |
| replaceAt - Replaces the string at the cursor position. |
| add - Adds a new item at the cursor location by pushing all the |
| following items after the cursor. |
| addAsFirst - Adds the item as the first item and sets the cursor on it. |
| This function allows you to add an item to an empty text |
| ISpinButton object. The only other way to add an item to |
| an empty text ISpinButton object is to use the addAsLast |
| function. |
| addAsLast - Adds the item as the last item and sets the cursor on it. |
| This function allows you to add an item to an empty text |
| ISpinButton object. The only other way to add an item to |
| an empty text ISpinButton object is to use the addAsFirst |
| function. |
| addAsNext - Adds the item as the next item and sets the cursor on it. |
| setCurrent - Sets the spin field to the cursor position and calls the |
| refreshText member function to update the spin button. |
| This function is the same as spinTo. |
| spinTo - Sets the spin field to the cursor position and calls the |
| refreshText member function to update the spin button. |
| This function is the same as setCurrent. |
------------------------------------------------------------------------------*/
IString
elementAt ( const Cursor& cursor ) const;
ISpinButton
&refreshText ( ),
&removeAt ( Cursor& cursor,
Boolean immediateUpdate = false ),
&replaceAt ( const char* newString,
Cursor& cursor,
Boolean immediateUpdate = false ),
&replaceAt ( const IResourceId& resid,
Cursor& cursor,
Boolean immediateUpdate = false ),
&add ( const char* string,
Cursor& cursor,
Boolean immediateUpdate = false ),
&add ( const IResourceId& resid,
Cursor& cursor,
Boolean immediateUpdate = false ),
&addAsNext ( const char* string,
Cursor& cursor,
Boolean immediateUpdate = false ),
&addAsNext ( const IResourceId& resid,
Cursor& cursor,
Boolean immediateUpdate = false ),
&addAsFirst ( const char* string,
Cursor& object,
Boolean immediateUpdate = false ),
&addAsFirst ( const IResourceId& resid,
Cursor& object,
Boolean immediateUpdate = false ),
&addAsLast ( const char* string,
Cursor& object,
Boolean immediateUpdate = false ),
&addAsLast ( const IResourceId& resid,
Cursor& object,
Boolean immediateUpdate = false ),
&setCurrent ( const Cursor& cursor ),
&spinTo ( const Cursor& cursor );
/*--------------------------------- Override -----------------------------------
| This function is overriden to ensure the control is redrawn correctly: |
| enable - Enables the window to accept keyboard and mouse input. |
------------------------------------------------------------------------------*/
virtual ISpinButton
&enable ( Boolean enableControl = true );
protected:
/*----------------------------- Layout Size ------------------------------------
| calcMinimumSize - Returns the recommended minimum size of this spin button |
| control. The size is based on the font and text limit. |
------------------------------------------------------------------------------*/
virtual ISize
calcMinimumSize() const;
private:
/*--------------------------------- PRIVATE ----------------------------------*/
ISpinButton(const ISpinButton&);
ISpinButton& operator=(const ISpinButton&);
unsigned long
limit ( ) const;
friend class
ISpinButton::Cursor;
static Style
currentDefaultStyle;
Boolean
bDelayedItems;
IString
spinText;
unsigned long
findStringIndex(const Cursor & cursor) const,
lCount,
textLimit;
char** pList;
};
INESTEDBITFLAGCLASSFUNCS( Style, ISpinButton);
#ifndef I_NO_INLINES
#include <ispinbt.inl>
#endif
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing and warning messages. */
/*----------------------------------------------------------------------------*/
#pragma pack()
#pragma info(restore)
#endif // _ISPINBT_