home *** CD-ROM | disk | FTP | other *** search
- #ifndef _ILISTBOX_
- #define _ILISTBOX_
- /*******************************************************************************
- * FILE NAME: ilistbox.hpp *
- * *
- * DESCRIPTION: *
- * Declaration of the class(es): *
- * Ilistbox - This class creates and manages the listbox 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. *
- * *
- * $Log: R:/IBMCLASS/IBASECTL/VCS/ILISTBOX.HPV $
- //
- // Rev 1.4 25 Oct 1992 17:05:32 nunn
- //changed library name to ICLUI
- //
- // Rev 1.3 25 Oct 1992 10:55:02 boezeman
- //Add documentation and converted file to skeleton.hpp format.
-
- Rev 1.6 15 Oct 1992 21:17:36 Ph Gregoire
- Added BBXX-like nested cursors
-
- Rev 1.6 16 Sep 1992 21:17:36 Jeff Shusterman
- Code for IBM C++ - OS2 2.0
-
- Rev 1.4 23 Jan 1992 20:55:52 Jeff Shusterman
- Up to IBM Class V2.0 Level
-
- Rev 1.3 01 Nov 1991 19:02:08 Jeff Shusterman
- Refined & enhanced.
-
- Rev 1.2 22 Apr 1991 19:02:08 David Nguyen
- Refined; added methods
-
- Rev 1.1 28 Oct 1989 19:02:08 Larry Morley
- Initial
- *******************************************************************************/
- #ifndef _ICONTROL_
- #include "icontrol.hpp"
- #endif
- // Forward declarations for other classes:
- class IListBox;
- class IString;
- class IRectangle;
- class IResourceMgr;
- class IWindowHandle;
- typedef long itemInfo;
- static const itemInfo FIRSTITEM = -1;
- static const itemInfo NOITEMS = -1;
-
- class IListBox : public virtual IControl {
- /*******************************************************************************
- * This class creates and manages the listbox control window. *
- * *
- * A ListBox operates as if it is a zero based arrays of items. In the *
- * following methods, the item index requested or returned is the zero *
- * based index number of the location of the item in question. *
- * A ListBox can have one or more of the following styles: *
- * LS_HORZSCROLL allows horizontall scroll of the ListBox. *
- * LS_MULTIPLESEL allows more than one item to be selected. A ListBox without *
- * this style allows only single selection. *
- * LS_OWNERDRAW allows ListBox items to be drawn. Typically used to display *
- * bit maps. This style is used and is required to support *
- * multiple columns on the ListBox. *
- * LS_NOADJUSTPOS if this style is included, the ListBox control is drawn at *
- * the size specified. This can cause parts of an item to be *
- * shown. *
- * *
- * EXAMPLE: *
- * #include <ilistbox.hpp> *
- * lb_test = new IListBox(ID_LISTBOX, this, IRectangle(IPoint(px, py), *
- * ISize(sx, sy))); *
- * lb_test->addItemAsc("This is first item"); *
- * SelectedItem = lb_test->selection(); *
- * This code shows creating a ListBox, adding an item to it and returning the *
- * index of the selected item. *
- *******************************************************************************/
- typedef IControl
- Inherited;
- public:
- INESTEDBITFLAGCLASSDEF2(Style, IListBox, IWindow, IControl);
- //Style class definition
- static const Style
- horizontalscroll,
- multipleselect,
- extendedselect,
- ownerdraw,
- noadjustposition;
- static const Style&
- defStyle;
- /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------------
- | There are 3 ways to construct instances of this class: |
- | 1. default |
- | 2. From a Dialog Template |
- | 3. From a Window |
- ------------------------------------------------------------------------------*/
- IListBox(unsigned long Id,
- const IWindow* pParent,
- const IWindow* pOwner,
- const IRectangle& initial,
- Style style = defStyle);
-
- IListBox(unsigned long Id,
- const IWindow* pParentDialog);
-
- IListBox(IWindowHandle handle);
-
- virtual
- ~IListBox() {;}
-
- /*-------------------------------- STYLES --------------------------------------
- | These function provide means of getting and setting the default style |
- | attributes of instances of this class: |
- | defaultStyle - returns the listbox default style setting |
- | setDefaultStyle - sets the listbox default style |
- ------------------------------------------------------------------------------*/
- static Style
- defaultStyle();
- static void
- setDefaultStyle(Style style);
-
- /*------------------------ ADD ITEM OPERATIONS ---------------------------------
- | Add a line of text to the listbox. |
- | addItem - allows the line to be inserted anyplace in the listbox |
- | addItemToFront - allows the line to be inserted to the front of the listbox |
- | addItemToEnd - allows the line to be inserted to the end of the listbox |
- | addItemAsc - allows the line to be inserted in ascending sort order |
- | addItemDesc - allows the line to be inserted in descending sort order |
- ------------------------------------------------------------------------------*/
- long
- addItem(long lIndex, const char* pszString),
- addItemToFront(const char* pszString),
- addItemToEnd(const char* pszString),
- addItemAsc(const char*pszString),
- addItemDesc(const char* pszString);
-
- /*------------------------ GET/CHANGE ITEM OPERATIONS --------------------------
- | Get or change the text of an item in the listbox. Return the length of an |
- | an item in the listbox. |
- | itemText - Return the text of an item in the listbox |
- | itemTextLen - Return the length of an item in the listbox |
- | setItemText - Change the text of an item in the listbox. |
- ------------------------------------------------------------------------------*/
- IString
- itemText(unsigned long lIndex) const;
- long
- itemTextLen(unsigned long lIndex) const;
- void
- setItemText(long lIndex, const char* pszString); /* Change an item */
-
- /*------------------------ REMOVE ITEM OPERATIONS ------------------------------
- | Remove all or one item from the listbox. |
- | removeAll - Remove all items from the listbox. |
- | removeItem - Remove one item from the listbox and return the count of |
- | the number of items that remain. |
- ------------------------------------------------------------------------------*/
- void
- removeAll();
- long
- removeItem(long lIndex );
-
- /*------------------------ SELECTION STATE OPERATIONS --------------------------
- | Set or return the selection state operations. |
- | selectItem - Sets the selection state of an item. |
- | deselectItem - Removes the selection state from an item. |
- | isSelected - Returns the selection state of an item. |
- | selectAll - Sets the selection state for all items in the listbox. |
- | deselectAll - Removes the selection state from all items in the listbox. |
- | resetSelection - Sets the "current" selection to LIT_FIRST. This can be |
- | used for looping through the set of selected items, starting|
- | with the first selection. A better way to loop through the |
- | selections is to use the IListBoxCursor. |
- | selection - Returns the item number of the next selection after the |
- | requested item number. LIT_FIRST starts the search with the |
- | first item. If the rest of the list has no selection, |
- | LIT_NONE is returned. The result of the search is also set |
- | as the "current" selection. |
- | firstSelection - Reset "current" selection with their result. |
- | nextSelection - Reset "current" selection with their result. |
- | prevSelection - Use "current" selection as the starting point and also |
- | reset "current" selection with their result. |
- | lastSelection - Use "current" selection as the starting point and also |
- | reset "current" selection with their result. |
- | selectionCount - Returns the number of selected items and does not change |
- | "current" selection |
- ------------------------------------------------------------------------------*/
- void
- selectItem(long lIndex ),
- deselectItem(long lIndex ),
- selectAll(),
- deselectAll();
- void
- resetSelection() {lClSelection = FIRSTITEM;} /* For looping */
- Boolean
- isSelected(long lIndex ); /* Returns true if selected */
- long
- selection(long lAfterItem = FIRSTITEM),
- firstSelection(),
- nextSelection(),
- prevSelection(),
- lastSelection(),
- selectionCount(); /* Does not affect lClSelection */
-
- /*------------------------ SCROLLING OPERATIONS --------------------------------
- | Scrolls an item to the top of the listbox or returns the item at the top of |
- | the listbox. |
- | setTopItem - Scrolls the requested item to the top of the listbox. |
- | topItem - Returns the item number of the item currently at the top |
- | of the listbox or LIT_NONE if there are no items in the |
- | listbox. |
- ------------------------------------------------------------------------------*/
- void
- setTopItem(long lIndex);
- long
- topItem() const;
-
- /*------------------------ HANDLE OPERATIONS -----------------------------------
- | Set or retrieve a handle of a listbox item. |
- | setItemHandle - Sets a handle of a listbox item. |
- | itemHandle - Returns a handle of a listbox item. An item without a |
- | handle returns 0. |
- ------------------------------------------------------------------------------*/
- void
- setItemHandle(unsigned long lIndex, unsigned long ulHandle ); /*Returns OK or warning*/
- unsigned long
- itemHandle(unsigned long lIndex ) const;
-
- /*------------------------ QUERY OPERATIONS ------------------------------------
- | findString - Return the item number of the listbox item that matches the |
- | search string. Start the search after the index. If no |
- | match is found the method returns LIT_NONE. |
- ------------------------------------------------------------------------------*/
- long findString(const char* pszSearchString,
- Boolean caseSensitive = true, /*unsigned long ulFindOptions = LSS_CASESENSITIVE | LSS_SUBSTRING,*/
- Boolean checkSubstring = true,
- long lIndex = FIRSTITEM) const;
-
- /*------------------------ MISCELLANEOUS OPERATIONS ----------------------------
- | itemCount - Return the count of the number of items in the listbox. |
- | setItemHeight - Set the height of a listbox item. This does not change the |
- | font size, it changes the cell within which an item is displayed|
- ------------------------------------------------------------------------------*/
- long
- itemCount() const;
- void
- setItemHeight(long lNewHeight);
- //void setForegdColor(COLOR clrForegdColor);
- //void setBackgdColor(COLOR clrBackgdColor);
- //COLOR color( HPS hpsItem, unsigned long ulAttrType1,
- // unsigned long ulAttrType2, COLOR clrDefault );
- /*------------------------ STYLES ----------------------------------------------
- | isHorizontalscroll - Returns true if the horizontal scroll style is set. |
- | isMultipleselect - Returns true if the mulipleselect style is set. |
- | isExtendedselect - Returns true if the extendedselect style is set. |
- | isOwnerdraw - Returns true if the ownerdraw style is set. |
- | isNoadjustposition - Returns true if the noadjustposition style is set. |
- | setHorizontalscroll - enables or disable the horizontal scroll style for |
- | the listbox |
- | setMultipleselect - enables or disable the multipleselect style for |
- | the listbox |
- | setExtendedselect - enables or disable the extended select style for |
- | the listbox |
- | setOwnerdraw - enables or disable the ownerdraw style for |
- | the listbox |
- | setNoadjustposition - enables or disable the noadjustposition style for |
- | the listbox |
- ------------------------------------------------------------------------------*/
- Boolean isHorizontalscroll(),
- isMultipleselect(),
- isExtendedselect(),
- isOwnerdraw(),
- isNoadjustposition();
- void
- setHorizontalscroll(Boolean setTheStyle = true),
- setMultipleselect(Boolean setTheStyle = true),
- setExtendedselect(Boolean setTheStyle = true),
- setOwnerdraw(Boolean setTheStyle = true),
- setNoadjustposition(Boolean setTheStyle = true);
-
- /*------------------------- CURSOR SUPPORT -----------------------
- | - Nested cursor class |
- | - Functions to retrieve/set add/remove elements at cursor |
- ----------------------------------------------------------------*/
- class Cursor {
- enum CursorType { selectedItems, allItems };
- public :
- Cursor(const IListBox& rlb,
- CursorType type = selectedItems);
-
- /*------------------------ CURSOR MOVEMENT ------------------------
- | setToFirst - point to first object item of LB |
- | setToNext - point to next item or invalidates if none |
- | setToPrevious - point to previous item of LB or invalid if none |
- | setToLast - point to last object of LB |
- | setToIndex - point to item with given 0-based index |
- -----------------------------------------------------------------*/
- Boolean
- setToFirst(),
- setToNext(),
- setToPrevious(),
- setToLast(),
- setToIndex(long lIndex);
-
- /*--------------- CURSOR VALIDATION / CONVERSION -----------------+
- | isValid - does this cursor point to a valid item? |
- | invalidate - flag this cursor as invalid |
- | asIndex - returns the index of the item pointed to by cursor |
- +----------------------------------------------------------------*/
- Boolean
- isValid() const;
- void
- invalidate();
- long
- asIndex() const;
-
- private :
- const IListBox&
- rlbCl;
- long
- lClCurrent;
- CursorType
- cursorTypeCl;
- };
- /*------------------------ CURSOR OPERATIONS ---------------------+
- | Operations on listbox items using cursor |
- | elementAt - Returns the item's string at cursor |
- | removeAt - Remove item at cursor |
- | replaceAt - Replace item's string at cursor |
- | add - add item at cursor (push evrything after cursor)|
- | addAsFirst - add item as first and set cursor to first |
- | addAsLast - add item as last and set cursor there |
- | addAsNext - add item as next and set cursor there |
- +----------------------------------------------------------------*/
- IString
- elementAt(const Cursor& cursor);
- void
- removeAt(const Cursor& cursor),
- replaceAt(const Cursor& cursor, const IString& strNew);
- Boolean
- add(const IString& strItem, Cursor& cursor);
- void
- addAsFirst(const IString& strItem, Cursor& cursor),
- addAsLast(const IString& strItem, Cursor& cursor),
- addAsNext(const IString& strItem, Cursor& cursor);
-
- /*----------------------- ISET OPERATIONS ------------------------+
- | Operations on listbox with same terminology as BBXX ISet |
- | isEmpty - returns true if the LB is empty |
- | numberOfElements - returns the count of elements in the LB |
- +----------------------------------------------------------------*/
- Boolean
- isEmpty() const;
- unsigned long
- numberOfElements() const;
-
- protected:
- /*----------------------------- LAYOUT SIZE ------------------------------------
- | This operation returns the minimum size for the listbox control. |
- | calcMinSize - returns the minimum size that this listbox should be. |
- ------------------------------------------------------------------------------*/
- virtual ISize
- calcMinSize() {return (ISize)(0,0);/**???????????????**/}
-
- static Style
- classDefaultStyle;
-
- /*???? To be implemented in IWindow ?????*/
- unsigned long
- style() const;
- void
- setStyle(unsigned long style);
-
- /* "Current" Location - Used & set by next/prevSelection(); set by selection,first&last */
- long
- lClSelection;
-
- // /******************************************************************************/
- // /* Protected Constructor - used by IListBoxMultiCol */
- // /******************************************************************************/
- // IListBox(Boolean protectSwitch,
- // unsigned long Id,
- // const IWindow* pParent,
- // const IWindow* pOwner,
- // const IRectangle& intial,
- // Style style = defStyle);
-
- /*------------------------------------------------------------------------------
- | Protected Constructors - used by IComboBox |
- ------------------------------------------------------------------------------*/
- IListBox();
- }; //ILISTBOX
- enum CursorType{selectedItems, allItems};
-
- class IListBoxCursor {
- public :
- IListBoxCursor (IListBox* plb,
- CursorType type = selectedItems);
- long
- current(),
- first(),
- last(),
- next(),
- prior(),
- after(long lAfterItem);
- void
- reset();
-
- private :
- IListBox*
- plbCl;
- long
- lClCurrent;
- CursorType
- cursorTypeCl;
- };
-
- //Global Style Functions
- INESTEDBITFLAGCLASSFUNCS(Style, IListBox);
-
-
- // global style functions
- #endif /* _ILISTBOX_ */