choicbox.h
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:10k
- /*
- * choicbox.h
- *
- * Choice 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: choicbox.h,v $
- * Revision 1.22 1999/03/10 03:49:51 robertj
- * More documentation adjustments.
- *
- * Revision 1.21 1999/03/09 08:01:47 robertj
- * Changed comments for doc++ support (more to come).
- *
- * Revision 1.20 1999/02/16 08:08:45 robertj
- * MSVC 6.0 compatibility changes.
- *
- * Revision 1.19 1998/09/23 06:23:03 robertj
- * Added open source copyright license.
- *
- * Revision 1.18 1995/10/14 14:53:55 robertj
- * Added addition of colection as strings to box.
- * Changed SetChoice to SetSelection for consistencies sake.
- *
- * Revision 1.17 1995/03/14 12:41:06 robertj
- * Updated documentation to use HTML codes.
- *
- * Revision 1.16 1995/02/19 04:19:05 robertj
- * Added dynamically linked command processing.
- *
- * Revision 1.15 1995/01/14 06:20:25 robertj
- * Documentation
- *
- * Revision 1.14 1994/12/05 11:14:53 robertj
- * Documentation.
- *
- * Revision 1.13 1994/10/30 11:46:32 robertj
- * Changed mechanism for doing notification callback functions.
- *
- * Revision 1.12 1994/08/23 11:32:52 robertj
- * Oops
- *
- * Revision 1.11 1994/08/22 00:46:48 robertj
- * Added pragma fro GNU C++ compiler.
- *
- * Revision 1.10 1994/06/25 11:55:15 robertj
- * Unix version synchronisation.
- *
- * Revision 1.9 1994/04/11 14:11:15 robertj
- * Added consts.
- *
- * Revision 1.8 1994/04/03 08:34:18 robertj
- * Added help and focus functionality.
- *
- * Revision 1.7 1994/03/07 07:38:19 robertj
- * Major enhancementsacross the board.
- *
- * Revision 1.6 1994/01/15 02:50:29 robertj
- * Moved control contructors to common and added a platform dependent Construct() function.
- *
- * Revision 1.5 1994/01/03 04:42:23 robertj
- * Mass changes to common container classes and interactors etc etc etc.
- *
- * Revision 1.4 1993/09/27 16:35:25 robertj
- * Removed special constructor for dialog resource loading.
- *
- * Revision 1.3 1993/08/21 01:50:33 robertj
- * Made Clone() function optional, default will assert if called.
- *
- * Revision 1.2 1993/07/14 12:49:16 robertj
- * Fixed RCS keywords.
- *
- */
- #define _PCHOICEBOX
- #ifdef __GNUC__
- #pragma interface
- #endif
- /**A control for selecting one of a number of choices, similar to radio
- buttons but typically for larger numbers of options in a smaller space.
- The exact appearence of a choice box is platform dependent, for example,
- in MS-Windows this is a fixed combo-box, in Mac-OS it is a popup menu.
- */
- class PChoiceBox : public PControl
- {
- PCLASSINFO(PChoiceBox, PControl);
- public:
- /** Option for the strings in the choice box. */
- enum StringSorting {
- /// Strings are in the order they are added.
- NotSorted,
- /// Strings are in alphabetic order.
- Sorted
- };
- /** Create a choice box with optional sorting of the list elements. */
- PChoiceBox(
- PInteractor * parent, /// Interactor into which the control is placed.
- StringSorting sorted = NotSorted /// Sorting option for strings in box.
- );
- PChoiceBox(
- PInteractor * parent, /// Interactor into which the control is placed.
- const PNotifier & notify, /// Function to call when changes state.
- StringSorting sorted = NotSorted /// Sorting option for strings in box.
- );
- /** Create control from interactor layout with the specified control ID. */
- PChoiceBox(
- 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 check box state.
- );
- /** Destroy the choice box and its contents. */
- virtual ~PChoiceBox();
- /**Codes passed to the PNotifier function when the specified notification
- events occur.
- */
- enum {
- /// A new choice was made from this list
- NewSelection = NotifyChange,
- /// The list of selections has been presented.
- ListDropped,
- /// The list of selections has been hidden.
- ListClosed
- };
- /**@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 choice box value changes.
- */
- );
- /**@name New functions for class */
- /**Set the index of the string that is currently selected and visible in
- the non-popped up state. The first string is index 0 etc. This will be
- updated on the screen immediately (within OS constraints).
- */
- void SetSelection(
- PINDEX newValue /// New index of the choice box string selected,
- );
- /**Get the index of the string that is currently selected.
- @return
- index of choice box selection.
- */
- PINDEX GetSelection() 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 choice box.
- @return
- value pointer associated with the control.
- */
- 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 choice box.
- */
- void SetValuePointer(
- PINDEX * ptr /// New value pointer to associate with the control.
- );
- /**Add a new string to the list box. If the sorted option was used this
- will place the string in the correct position. Otherwise it adds it to
- the end of the list.
-
- @return
- the index that the string was placed.
- */
- PINDEX AddString(
- const PString & str /// String to add to the list of choices.
- );
- /**Add a collection of new entries to the choice box. Each element of the
- collection is added in order using the Ref{AddEntry()} function. Thus,
- for example, a sorted list string will be added in sorted order.
- If the collection is not of string objects then they are translated into
- a string by the use of the Ref{operator<<} function.
- */
- void AddStrings(
- const PCollection & objects /// New objects to add to list box.
- );
- /**Insert a string at the specified location. This ignores the sort order
- and explicitly places the string at the index position.
- */
- void InsertString(
- const PString & str, /// String to add to the list of choices.
- PINDEX index /// Position in list to place the new string.
- );
- /** Delete a string from the list of choices in the choice box. */
- void DeleteString(
- PINDEX index /// Position in list of the string to remove.
- );
- /** Delete all the strings in the list of choices in the choice box. */
- void DeleteAllStrings();
- /**Find the string in the list of choices starting at the entry after the
- specified starting index. If the index is P_MAX_INDEX then searches the
- whole list. The exact flag indicates that the whole string must match
- otherwise a string in the list box that matches up to the length of the
- argument string will be found.
- @return
- index position of the string that meets the matching criteria or
- #P_MAX_INDEX# if it was not found.
- */
- PINDEX FindString(
- const PString & str, /// String to search for in the list of choices.
- PINDEX startIndex = P_MAX_INDEX, /// Index into list to start search.
- BOOL exact = FALSE /// Flag for whether search is exact or partial.
- ) const;
- /**Set the string at the index position. If the index is beyond the end of
- the list then simply adds the string to the end of the list.
- */
- void SetString(
- const PString & str, /// String to set in the list of choices.
- PINDEX index /// Position in the list of choices to set.
- );
- /**Get the string at the index. If the index is beyond the end of the list
- then returns the empty string.
- @return
- string for the entry in the list of choices.
- */
- PString GetString(
- PINDEX index /// Position in the list of choices to retrieve.
- ) const;
- /**Get the count of the number of items in the list of choices in the
- choice box.
- @return
- number of choices.
- */
- PINDEX GetCount() const;
- protected:
- // Member variables
- /** The coice box strings are sorted. */
- BOOL sort;
- private:
- // New functions for class
- void Construct();
- // Common constructor code
- #ifdef DOC_PLUS_PLUS
- };
- #endif
- // Class declaration continued in platform specific header file ///////////////