home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
ICOMBOBX.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
27KB
|
506 lines
#ifndef _ICOMBOBX_
#define _ICOMBOBX_
/*******************************************************************************
* FILE NAME: icombobx.hpp *
* *
* DESCRIPTION: *
* Declaration of the class(es): *
* IComboBox - This class creates and manages the combo-box 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 _IENTRYFD_
#include <ientryfd.hpp>
#endif
// Forward declarations for other classes:
class IListBox;
#ifndef _IRECT_
#include <irect.hpp>
#endif
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
/*----------------------------------------------------------------------------*/
/* Turn off warning for compiler generated copy/assignment */
/*----------------------------------------------------------------------------*/
#pragma info(nocpy)
class IComboBox : public IEntryField { // $JJB!c
typedef IEntryField Inherited;
/*******************************************************************************
* The IComboBox class creates and manages the combination box control window. *
* The IComboBox class combines an entry field and a list box to form one *
* control that contains the features of both. *
* *
* Specific keystroke processing, such as creating a numeric-only input field, *
* can be implemented by subclassing the IKeyboardHandler class and adding the *
* handler to the combination box object. *
* *
* EXAMPLE: *
* cb_test = new IComboBox (this, ID_COMBOBOX, IRectangle(x1, y1, x2, y2)); *
* *
* The example below shows how to add a item to the listbox part of the combobox.*
* cb_test.addAscending("First line"); *
*******************************************************************************/
public:
/*---------------------- Style --------------------------------------------
The following functions provide a means to set and query combination box
styles:
Style - Nested class that provides static members that define the set of
valid combination box 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 IComboBox::Style class and initialize
it like:
IComboBox::Style
style = IComboBox::dropDownType | IControl::tabStop;
An object of this type is provided when the combination box is
created. A customizable default is used if no styles are
specified. Once the object is constructed, IComboBox, IWindow,
and IControl member functions can be used to set or query the
object's style.
The declaration of the IComboBox::Style nested class is
generated by the INESTEDBITFLAGCLASSDEF2 macro.
The valid combination box styles are:
classDefaultStyle - Original default style for this class, which is
simpleType | IEntryField::alignLeft | anyData | IWindow::visible.
simpleType - Specifies both the entry field control and the list
box control are visible. When the selection changes
in the list box control, the text of the selected
item in the list box control is placed in the entry
field. An item can also be selected from the list
box control by typing a portion of the item into the
entry field. The entry will be completed with the
closest match from the list box.
NOTE: The parent of a simpleType IComboBox should not
set the IWindow::clipChildren style. Using
this style prevents OS/2 from painting a small
region below the list box part of the IComboBox
object.
dropDownType - Specifies the drop-down variation of the combination
box, which is the same as simpleType, except that the
list box control is hidden until the user requests
that it should be displayed.
dropDownListType - Specifies the drop-down list variation of the
combination box. The drop-down list only displays
one item in the entry field, until the user causes
the display of the list box control in order to make
alternative selections in the list box. The drop-
down list does not allow a user to type information
into the entry field. The entry field control is
replaced by a static control that displays the
current selection from the list box.
anyData - Sets the combination box entry field to accept text
that is a mixture of SBCS and DBCS characters.
Note: If the text contains both single-byte and
double-byte 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 combination box entry field to accept
single-byte text only.
dbcsData - Sets the combination box entry field to accept
double-byte text only.
mixedData - Sets the combination box 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
SI/SO characters, but will not exceed the text limit
of the entry field.
horizontalScroll - Provides horizontal scrolling for the list box
control.
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 combination
boxes.
-------------------------------------------------------------------------*/
INESTEDBITFLAGCLASSDEF2(Style, IComboBox, IWindow, IControl);
static const Style
classDefaultStyle,
simpleType,
dropDownType,
dropDownListType,
anyData,
sbcsData,
dbcsData,
mixedData,
horizontalScroll;
static Style
defaultStyle();
static void
setDefaultStyle(Style style);
/*------------------------ Constructors ----------------------------------------
| You can create instances of this class in the following ways: |
| - From a control ID, parent and owner windows, rectangle, and style. |
| This creates the specified combination box control and an object |
| for it. |
| - From the ID of a combination box control on a dialog window. |
| This creates the object for the specified combination box control. |
| - From the window handle of an existing combination box control. |
| This creates the object for the specified combination box control. |
------------------------------------------------------------------------------*/
IComboBox(unsigned long id,
IWindow* parent,
IWindow* owner,
const IRectangle& initial= IRectangle(),
const Style& style = defaultStyle() );
IComboBox(unsigned long id,
IWindow* parent);
IComboBox(const IWindowHandle& handle);
virtual ~IComboBox();
/*------------------------ Scrolling Style Operations --------------------------
| isHorizontalScroll - Returns true if the horizontalScroll style is |
| set. |
------------------------------------------------------------------------------*/
Boolean
isHorizontalScroll();
/*-------------------------------- Type Operations -----------------------------
| The following functions are used to set or return the type of combination |
| box: |
| ControlType - Enumeration that defines the types of combination boxes |
| (simple, dropDown, and dropDownList). |
| type - Returns the currently set combination box type. |
------------------------------------------------------------------------------*/
enum ControlType { simple, dropDown, dropDownList };
ControlType
type() const;
/*-------------------------------- List Box Operations -------------------------
| The following functions are used to query, show, or hide the list box part |
| of the combination box: |
| isListShowing - Returns true if the list box control is showing. |
| showList - Shows or hides the list box control. This is only valid |
| for the dropDown and dropDownList types. |
| hideList - Hides the list box control. |
------------------------------------------------------------------------------*/
Boolean
isListShowing() const;
IComboBox&
showList(Boolean show=true); // $JJB!c
IComboBox&
hideList();
/*------------------------ Add Item Operations ---------------------------------
| The following functions are used to add a line of text to the list box |
| part of the combination box: |
| add - Inserts the line in the list box in no specified order or |
| location. |
| addAsFirst - Inserts the line at the front of the list box. |
| addAsLast - Inserts the line at the end of the list box. |
| addAscending - Inserts the line in ascending sort order. |
| addDescending- Inserts the line in descending sort order. |
------------------------------------------------------------------------------*/
unsigned long
add(unsigned long index, const char* text),
addAsFirst(const char* text),
addAsLast(const char* text),
addAscending(const char* text),
addDescending(const char* text),
add(unsigned long index, const IResourceId& resid),
addAsFirst(const IResourceId& resid),
addAsLast(const IResourceId& resid),
addAscending(const IResourceId& resid),
addDescending(const IResourceId& resid);
/*------------------------ Get/Change Item Operations --------------------------
| The following functions get or change the text in the entryfield part of the |
| combination box. |
| itemText - Returns the text of an item in the list box portion of the |
| combination box. |
| setItemText - Changes the text of an item in the list box portion of the |
| combination box. |
------------------------------------------------------------------------------*/
IString
itemText(unsigned long index) const;
IComboBox&
setItemText(unsigned long index, const char* string);
/*------------------------ Remove Item Operations ------------------------------
| The following functions remove all items or one item from the list box part |
| of the combination box: |
| removeAll - Removes all items from the list box. |
| remove - Removes one item from the list box and returns the count of |
| the number of items that remain. |
------------------------------------------------------------------------------*/
IComboBox&
removeAll();
long
remove(unsigned long index );
/*------------------------ Selection-State Operations --------------------------
| The following functions set or return the selection-state operations: |
| select - Sets the selection state of an item based on the |
| Boolean value that is passed in. If true is passed |
| in, the item is selected and any item that was |
| previously selected is deselected. If false is |
| passed in, the item is deselected. |
| deselect - Removes the selection state from an item. |
| isSelected - Returns the selection state of an item. |
| deselectAll - Removes the selection state from all items in the |
| list box. |
| numberOfSelections - Returns 0 if no item is selected or 1 if an item is |
| selected. The current selection does not change. |
| selection - Returns the 0-based index of the selected item. If |
| no item is selected, -1 is returned. |
------------------------------------------------------------------------------*/
IComboBox
&select(unsigned long index, Boolean select = true ),
&deselect(unsigned long index ),
&deselectAll();
Boolean
isSelected(unsigned long index );
unsigned long
numberOfSelections() const;
long
selection();
/*------------------------ Scrolling Operations --------------------------------
| The following functions scroll an item to the top of the list box or returns |
| the item at the top of the list box: |
| setTop - Scrolls the requested item to the top of the list box. |
| top - Returns the item number of the item currently at the top of the |
| list box. If there are no items in the list box, an exception |
| is thrown. |
| ------------------------------------------------------------------------------*/
IComboBox&
setTop(unsigned long index);
unsigned long
top() const;
/*------------------------ Handle Operations -----------------------------------
| The following functions set or retrieve a handle of a list box item: |
| setItemHandle - Sets a handle of a list box item. |
| itemHandle - Returns a handle of a list box item. An item without a |
| handle returns 0. |
------------------------------------------------------------------------------*/
IComboBox&
setItemHandle(unsigned long index, unsigned long handle );
unsigned long
itemHandle(unsigned long index ) const;
/*---------------------------- Enumerations ------------------------------------
| The following enumerations are defined: |
| SearchType - Used for determining the type of search to perform. Values |
| are: |
| prefix - Matching occurs if the leading characters |
| of the item contain the specified characters. |
| substring - Matching occurs if the item contains a substring |
| of the specified characters. |
| exactMatch - Matching occurs if the item is an exact match for|
| the specified characters. |
------------------------------------------------------------------------------*/
enum SearchType {
prefix,
substring,
exactMatch
};
/*------------------------ Query Text Operation --------------------------------
| The following function is used to find a text string in the list box: |
| locateText - Returns the item number of the list box item that matches the |
| search string. Starts the search after the index. If no |
| match is found, it returns notFound. If there is an error, |
| an exception occurs. |
------------------------------------------------------------------------------*/
static const unsigned long notFound ;
static const long first ;
unsigned long
locateText(const char* searchString,
Boolean caseSensitive = true,
SearchType search = exactMatch,
long index = first) const;
/*------------------------ Miscellaneous Operations ----------------------------
| The following functions provide miscellaneous operations: |
| count - Returns the count of the number of items in the list box. |
------------------------------------------------------------------------------*/
unsigned long
count() const;
class Cursor : public IVBase {
/*******************************************************************************
* The IComboBox::Cursor nested class is used to iterate the items in the *
* combination box. *
* *
* EXAMPLE: *
* This code shows creating a combo-box, adding an item to it and returning the*
* index of the item pointed to by the cursor. *
* *
* #include <icombobx.hpp> *
* cb_test = new IComboBox(ID_COMBOBOX,this, this, IRectangle(x1, y1, x2, y2));*
* cb_test->addAscending("This is first item"); *
* cb_cursor = new IComboBox::Cursor(*cb_test); *
* cb_cursor->setToFirst(); *
* CurrentItem = cb_cursor->asIndex(); *
*******************************************************************************/
public :
/*------------------------ Filters -------------------------------+
| The following functions allow you to specify how list box items |
| will be filtered: |
| Filter - Enumeration that defines which items are to be|
| filtered in (selectedItems or allItems). |
+----------------------------------------------------------------*/
enum Filter { selectedItems, allItems };
/*------------------------ Constructors ---------------------------
| You can create instances of this class from a combination box |
| control and a filter type, thereby creating the specified |
| combination box cursor object. |
-----------------------------------------------------------------*/
Cursor(const IComboBox& rlb,
Filter type = selectedItems);
virtual ~Cursor();
/*------------------------ Cursor Movement -----------------------+
| The following functions control cursor movement in the list box |
| part of a combination box: |
| setToFirst - Points to the first list box item and |
| validates the cursor. |
| setToNext - Points to the next list box item. If no more |
| items exist, this will invalidate the cursor. |
| setToPrevious - Points to the previous list box item. If no |
| previous items exist, this will invalidate |
| the cursor. |
| setToLast - Points to the last list box item and |
| validates the cursor. |
| setToIndex - Points to the item with the given 0-based |
| index and validates the cursor. |
+----------------------------------------------------------------*/
Boolean
setToFirst(),
setToNext(),
setToPrevious(),
setToLast(),
setToIndex(unsigned long index);
/*--------------- Cursor Validation/Conversion -------------------+
| The following functions query or return information about the |
| item to which the cursor is pointing: |
| isValid - Queries whether the cursor is pointing to a |
| valid item. |
| invalidate - Flags the cursor as invalid. |
| asIndex - Returns the 0-based index of the item pointed to |
| by the cursor. |
+----------------------------------------------------------------*/
Boolean
isValid() const;
void
invalidate();
unsigned long
asIndex() const;
private :
const IComboBox&
rlbCl;
unsigned long
lClCurrent;
Filter
cursorTypeCl;
unsigned long
sameValidation;
};
/*------------------------ Cursor Operations ---------------------+
| The following functions use the cursor to operate on list box |
| items: |
| elementAt - Returns the item's string at the cursor position.|
| removeAt - Removes the item at the cursor position. |
| replaceAt - Replaces the item's string at the cursor |
| position. |
| add - Inserts an item after the cursor position. |
| addAsFirst - Inserts an item as the first item and puts the |
| cursor on that item. |
| addAsLast - Inserts an item as the last item and puts the |
| cursor on that item. |
| addAsNext - Inserts an item as the next item and places the |
| cursor on that item. |
+----------------------------------------------------------------*/
IString
elementAt(const Cursor& cursor) const;
IComboBox
&add(const char* strItem, Cursor& cursor),
&add(const IResourceId& resid , Cursor& cursor),
&removeAt(Cursor& cursor),
&replaceAt(const char* strNew,const Cursor& cursor),
&addAsFirst(const char* strItem, Cursor& cursor),
&addAsLast(const char* strItem, Cursor& cursor),
&addAsNext(const char* strItem, Cursor& cursor),
&addAsFirst(const IResourceId& resid, Cursor& cursor),
&addAsLast( const IResourceId& resid, Cursor& cursor),
&addAsNext( const IResourceId& resid, Cursor& cursor),
&replaceAt( const IResourceId& resid, const Cursor& cursor);
/*---------------------- Contents Operation ----------------------+
| The following function queries the contents of the list box part|
| of the combination box: |
| isEmpty - Returns true if the list box is empty. |
+----------------------------------------------------------------*/
Boolean
isEmpty() const;
protected:
/*----------------------------- Layout Size ------------------------------------
| calcMinimumSize - Returns the recommended minimum size of this combination |
| box. The size is based on the text limit times the |
| average character width by three times the maximum |
| character height. |
------------------------------------------------------------------------------*/
virtual ISize
calcMinimumSize() const;
private:
/*--------------------------------- Private ----------------------------------*/
IComboBox(const IComboBox&);
IComboBox& operator=(const IComboBox&);
static Style
currentDefaultStyle;
unsigned long
needValidation;
IEntryField::Alignment
alignment() const;
IComboBox
&setAlignment(IEntryField::Alignment alignment);
friend class IComboBox::Cursor;
}; /* IComboBox */
//Global Style Functions
INESTEDBITFLAGCLASSFUNCS(Style, IComboBox);
// global style functions
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing and warning messages. */
/*----------------------------------------------------------------------------*/
#pragma pack()
#pragma info(restore)
#endif /* _ICOMBOBX_ */