listbox.h
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:16k
- /*
- * listbox.h
- *
- * List Box control.
- *
- * Portable Windows Library
- *
- * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Portable Windows Library.
- *
- * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
- *
- * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
- * All Rights Reserved.
- *
- * Contributor(s): ______________________________________.
- *
- * $Log: listbox.h,v $
- * Revision 1.26 1999/11/16 06:51:41 robertj
- * Created PCustomListBox to allow motif native code PStringListBox implementation
- *
- * Revision 1.25 1999/11/16 05:19:36 craigs
- * Created PCustomListBox to allow native code PStringListBox implementation
- *
- * Revision 1.24 1999/03/10 03:49:52 robertj
- * More documentation adjustments.
- *
- * Revision 1.23 1999/03/09 08:01:48 robertj
- * Changed comments for doc++ support (more to come).
- *
- * Revision 1.22 1999/02/16 08:08:45 robertj
- * MSVC 6.0 compatibility changes.
- *
- * Revision 1.21 1998/09/23 06:24:05 robertj
- * Added open source copyright license.
- *
- * Revision 1.20 1995/10/14 14:57:43 robertj
- * Added addition of colection as strings to box.
- *
- * Revision 1.19 1995/06/17 11:12:42 robertj
- * Documentation update.
- *
- * Revision 1.18 1995/03/14 12:41:40 robertj
- * Updated documentation to use HTML codes.
- *
- * Revision 1.17 1995/02/19 04:19:13 robertj
- * Added dynamically linked command processing.
- *
- * Revision 1.16 1995/01/14 06:22:48 robertj
- * Documentation
- *
- * Revision 1.15 1995/01/02 12:15:15 robertj
- * Documentation
- *
- * Revision 1.14 1994/10/30 11:46:47 robertj
- * Changed mechanism for doing notification callback functions.
- *
- * Revision 1.13 1994/08/23 11:32:52 robertj
- * Oops
- *
- * Revision 1.12 1994/08/22 00:46:48 robertj
- * Added pragma fro GNU C++ compiler.
- *
- * Revision 1.11 1994/06/25 11:55:15 robertj
- * Unix version synchronisation.
- *
- * Revision 1.10 1994/04/03 08:34:18 robertj
- * Added help and focus functionality.
- *
- * Revision 1.9 1994/03/07 07:38:19 robertj
- * Major enhancementsacross the board.
- *
- * Revision 1.8 1994/01/15 02:50:29 robertj
- * Moved control contructors to common and added a platform dependent Construct() function.
- *
- * Revision 1.7 1994/01/03 04:42:23 robertj
- * Mass changes to common container classes and interactors etc etc etc.
- *
- * Revision 1.6 1993/12/16 02:02:52 robertj
- * As can delete objects in listbox, objects should not be const.
- *
- * Revision 1.5 1993/12/15 21:10:10 robertj
- * Added optional deletion of objects in the list box.
- *
- * Revision 1.4 1993/09/27 16:35:25 robertj
- * Removed special constructor for dialog resource loading.
- *
- * Revision 1.3 1993/07/15 04:23:39 robertj
- * Added optional update screen parameter to list box modification functions.
- *
- * Revision 1.2 1993/07/14 12:49:16 robertj
- * Fixed RCS keywords.
- *
- */
- #define _PLISTBOX
- #ifdef __GNUC__
- #pragma interface
- #endif
- /**A scrollable list box control for selection of a one or more of items. The
- application writer should not normally descend from this class directly but
- descend from either the PStringListBox or PCustomListBox class.
- */
- class PListBox : public PControl
- {
- PCLASSINFO(PListBox, PControl);
- public:
- /**Option used when constructing a list box for whether the list box
- entries are sorted or unsorted.
- */
- enum StringSorting {
- /// Entries are added to list in any order.
- NotSorted,
- /// Entries are added to list in correct sorted position.
- Sorted
- };
- /**Option used when constructing a list box for whether the list box
- may have single or multiple entries selected.
- */
- enum SelectType {
- /// Only zero or one entry may be selected at a time.
- SingleSelect,
- /// Any number of entries may be selected.
- MultiSelect
- };
- /** Create a list box with the specified options. */
- PListBox(
- PInteractor * parent, /// Interactor into which the control is placed.
- StringSorting sorted = Sorted,
- /**If set to #Sorted# then strings will be inserted in sorted
- order. This requires that the Ref{PObject::Compare()} function
- operate correctly for objects placed into the list box.
- */
- SelectType select = SingleSelect,
- /**If set to #MultiSelect# then more than one item may be
- selected at a time. Otherwise only zero or one item may be selected.
- */
- PDIMENSION columnWidth = 0,
- /**If this parameter is zero then only one column with a vertical scroll
- bar is displayed. If non-zero, then multiple columns of this width,
- in font based coordinates, will be used and a horizontal scroll bar
- displayed.
- */
- BOOL deleteObj = TRUE
- /**If this parameter is TRUE then when the list box is destroyed all
- entries objects are deleted as well using the delete operator.
- Similarly if Ref{DeleteEntry()} or Ref{DeleteAllEntries()} is
- called the entry or entries are deleted, again using the delete
- operator).
- */
- );
- PListBox(
- PInteractor * parent, /// Interactor into which the control is placed.
- const PNotifier & notify, /// Function to call when changes state.
- StringSorting sorted = Sorted,
- /**If set to #Sorted# then strings will be inserted in sorted
- order. This requires that the Ref{PObject::Compare()} function
- operate correctly for objects placed into the list box.
- */
- SelectType select = SingleSelect,
- /**If set to #MultiSelect# then more than one item may be
- selected at a time. Otherwise only zero or one item may be selected.
- */
- PDIMENSION columnWidth = 0,
- /**If this parameter is zero then only one column with a vertical scroll
- bar is displayed. If non-zero, then multiple columns of this width,
- in font based coordinates, will be used and a horizontal scroll bar
- displayed.
- */
- BOOL deleteObj = TRUE
- /**If this parameter is TRUE then when the list box is destroyed all
- entries objects are deleted as well using the delete operator.
- Similarly if Ref{DeleteEntry()} or Ref{DeleteAllEntries()} is
- called the entry or entries are deleted, again using the delete
- operator).
- */
- );
- /** Create control from interactor layout with the specified control ID. */
- PListBox(
- PInteractorLayout * parent, /// Interactor into which the box is placed.
- PRESOURCE_ID ctlID, /// Identifier for the control in the layout.
- const PNotifier & notify, /// Function to call when changes state.
- PINDEX * valuePtr /// Variable to change to the list box state.
- );
- /** Destroy the list box and all its contents. */
- virtual ~PListBox();
- /**@name PNotifier codes */
- /**Notification codes passed to the PNotifier function when the specified
- notification events occur.
- */
- enum {
- /// A new entry was selected or deselected.
- NewSelection = NotifyChange,
- /// An entry was double clicked.
- DoubleClick
- };
- /**@name Overrides from class PControl */
- /**This function transfers the value of the control to or from the variable
- pointed to by the value pointer member variable.
- */
- virtual void TransferValue(
- int option
- /**Transfer value option. When this is -1 when the function transfers
- the value from the value pointer into the control. This is called in
- Ref{PDialog::OnInit()} function. When option is zero then the
- function transfers the value from the control to the value pointer
- variable. This is called just before the callback function every time
- the list box value changes.
- */
- );
- /**@name New functions for class */
- /** Set flag to delete entry objects using delete operator. */
- virtual void AllowDeleteObjects(
- BOOL yes = TRUE /// New flag for deleting entries in list box.
- );
- /**Reset flag to delete entry objects using delete operator. This is
- equivalent to #AllowDeleteObjects(FALSE)#.
- */
- virtual void DisallowDeleteObjects();
- /**Delete the entry from the list box. If the delete objects option was
- selected then all the objects added to the list box are deleted as well.
- If the #update# parameter is FALSE then it is the users
- responsibility to redraw the list box, ie call
- Ref{PInteractor::Invalidate()} or Ref{PInteractor::Update()} some
- time afterward. This is typically used if a large number of entries are
- to be deleted to the list box in one go. The user would delete the
- entries and then call the Ref{PInteractor::Invalidate()} function on
- the list box to force a redraw. This is much faster and tidier in
- appearance.
- */
- virtual void DeleteEntry(
- PINDEX index, /// Index position in list box to delete entry.
- BOOL update = TRUE /// Flag to indicate screen should be updated.
- );
- /**Delete all of the entries in the list box. If the delete objects option
- was selected then all the objects added to the list box are deleted as
- well.
- If the #update# parameter is FALSE then it is the users
- responsibility to redraw the list box, ie call
- Ref{PInteractor::Invalidate()} or Ref{PInteractor::Update()} some
- time afterward. This is typically used if entries are to be added to the
- list box immediately after deleting then. This is much faster and tidier
- in appearance.
- */
- virtual void DeleteAllEntries(
- BOOL update = TRUE /// Flag to indicate screen should be updated.
- );
- /**Get the count of the number of items in the list of entries in the
- list box.
- @return
- number of entries.
- */
- virtual PINDEX GetCount() const;
- /**Set the index of the list box entry that is currently visible at the
- top of the list. The list is scrolled accordingly.
- If the #update# parameter is FALSE then it is the users
- responsibility to redraw the list box, ie call
- Ref{PInteractor::Invalidate()} or Ref{PInteractor::Update()} some
- time afterward.
- */
- virtual void SetTopIndex(
- PINDEX index, /// Index position in list box to make the top item.
- BOOL update = TRUE /// Flag to indicate screen should be updated.
- );
- /**Get the index of the list box entry that is currently visible at the
- top of the list.
- @return
- index position of the list boxes top entry.
- */
- virtual PINDEX GetTopIndex() const;
- /**Set the new width of columns in the list box.
-
- Note that the list box must have been created with a non-zero width in
- the first place for this to work. It only allows the width to be
- readjusted.
- For the same reason the function will assert if the
- #newWidth# parameter is zero.
- If the #update# parameter is FALSE then it is the users
- responsibility to redraw the list box, ie call
- Ref{PInteractor::Invalidate()} or Ref{PInteractor::Update()} some
- time afterward.
- */
- virtual void SetColumnWidth(
- PDIMENSION newWidth, /// New width for the columns in the list box.
- BOOL update = TRUE /// Flag to indicate screen should be updated.
- );
- /**Set the current selection to the entry specified by the index.
-
- If the multiple selection option is used then this will deselect all
- other items and only have the specified entry selected.
- If the #index# parameter is beyond the end of the list box
- then all entries are deselected.
- */
- virtual void SetSelection(
- PINDEX index /// Index of entry to become the single selection.
- );
- /**Get the current selection index. If the list box has the multi-select
- option this only indicates the item that has the focus.
- @return
- currently selected item or P_MAX_INDEX if nothing selected.
- */
- virtual PINDEX GetSelection() const;
- /**Set the selection state of the list box item. If the list box is not a
- multi-select then deselects all others before selecting or deselecting
- the item specified.
- If the #update# parameter is FALSE then it is the users
- responsibility to redraw the list box, ie call
- Ref{PInteractor::Invalidate()} or Ref{PInteractor::Update()} some
- time afterward. This is typically used if a large number of entries are
- to be changed in the list box in one go. The user would change the
- entries and then call the Ref{PInteractor::Invalidate()} function on
- the list box to force a redraw. This is much faster and tidier in
- appearance.
- */
- virtual void Select(
- PINDEX index, /// Index position in list box to select.
- BOOL update = TRUE, /// Flag to indicate screen should be updated.
- BOOL sel = TRUE /// State in which to set the entries selection.
- );
- /**Reset the selection state of the list box item. This is equivalent to
- #Select(index, FALSE, update)#.
- If the list box was not multi select then all entries a deselected.
- */
- virtual void Deselect(
- PINDEX index, /// Index position in list box to select.
- BOOL update = TRUE /// Flag to indicate screen should be updated.
- );
- /** Get the selection state of the list box item. */
- virtual BOOL IsSelected(
- PINDEX index /// Index of entry to check for being selected.
- ) const;
- /**Get the number of list box items that are selected. This would only be
- one or zero unless multiple selection option is used.
- @return
- total items selected in list box.
- */
- virtual PINDEX GetSelCount() const;
- /**Get the current value pointer associated with the control. The variable
- pointed to by this is autamatically updated with the current value of
- the list box.
- @return
- value pointer associated with the control.
- */
- virtual PINDEX * GetValuePointer() const;
- /**Set the current value pointer associated with the control. The variable
- pointed to by this is autamatically updated with the current value of
- the list box.
- */
- virtual void SetValuePointer(
- PINDEX * ptr /// New value pointer to associate with the control.
- );
- protected:
- // Member variables
- /** Flag indicating list is sorted. */
- BOOL sort;
- /** Flag indicating the list may have multiple selections. */
- BOOL multi;
- /** Width of multi-column list box. */
- PDIMENSION width;
- /** Flag to indicate objects placed in list should be deleted when removed. */
- BOOL deleteObjects;
- private:
- // New functions for class
- void Construct();
- // Common constructor code
- #ifdef DOC_PLUS_PLUS
- };
- #endif
- // Class declaration continued in platform specific header file ///////////////