combobox.h
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:15k
- /*
- * combobox.h
- *
- * Combo 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: combobox.h,v $
- * Revision 1.24 1999/03/10 03:49:51 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:23:09 robertj
- * Added open source copyright license.
- *
- * Revision 1.20 1995/10/14 14:54:09 robertj
- * Added addition of colection as strings to box.
- *
- * Revision 1.19 1995/06/17 11:12:23 robertj
- * Documentation update.
- *
- * Revision 1.18 1995/03/14 12:41:10 robertj
- * Updated documentation to use HTML codes.
- *
- * Revision 1.17 1995/02/19 04:19:06 robertj
- * Added dynamically linked command processing.
- *
- * Revision 1.16 1995/02/05 00:46:08 robertj
- * Added notification of end input.
- *
- * Revision 1.15 1994/12/15 12:47:10 robertj
- * Documentation.
- *
- * Revision 1.14 1994/12/05 11:13:56 robertj
- * Documentation.
- *
- * Revision 1.13 1994/10/30 11:46:33 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:44 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 _PCOMBOBOX
- #ifdef __GNUC__
- #pragma interface
- #endif
- /**A combination of an edit text box and a drop down list box. This is
- typically used for arbitrary text entry with the ability to select from a
- set of pre-defined strings.
- The exact appearence of a check box is platform dependent, however, they
- all have a section for entring the editable text and some mechanism for
- displaying the list of strings.
- */
- class PComboBox : public PControl
- {
- PCLASSINFO(PComboBox, 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 combo-box with optional sorting of the list box items. */
- PComboBox(
- PInteractor * parent, /// Interactor into which the control is placed.
- StringSorting sorted = NotSorted /// Sorting option for strings in box.
- );
- PComboBox(
- 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. */
- PComboBox(
- 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.
- PString * valuePtr /// Variable to change to the check box state.
- );
- /** Destroy the combo-box and its contents. */
- ~PComboBox();
- /**Codes passed to the PNotifier function when the specified notification
- events occur.
- */
- enum {
- /// The text in the combo-box was changed.
- EditChange = NotifyChange,
- /// The edit box was tabbed out of so its value is final.
- EndEdit,
- /// A new choice was made from this list
- NewSelection,
- /// The list of selections has been presented.
- ListDropped,
- /// The list of selections has been hidden.
- ListClosed
- };
- /**@name Overrides from class PInteractor */
- /**The system calls this whenever the system wishes to change focus to
- another interactor in a given Ref{PTitledWindow} or
- Ref{PInteractorLayout}.
- This function in conjunction with the keyboard focus changing and the
- Ref{PInteractor::SetFocusInteractor()} function controls the transfer
- of focus from one interactor in a logical group (eg dialog) to another.
- It is primarily used for field level validation. For example the
- Ref{PIntegerEditBox} control uses this to prevent the user from
- exiting the control until a valid entry hash been made.
- Note that the focus {bf does} actually change with appropriate
- calls to the Ref{PInteractor::OnGainFocus()} and
- Ref{PInteractor::OnLostFocus()} functions. The focus gets set back to
- the original interactor when this function disallows the focus change.
- For edit boxes this will execute the notification function before
- returning TRUE.
- @return
- FALSE will prevent the focus change from occurring and TRUE allows the
- change.
- */
- virtual BOOL OnEndInput();
- /**@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 text in the edit text part of the combo-box. */
- void SetText(
- const PString & str /// New text to place in the text edit box.
- );
- /**Get the text in the edit text part of the combo-box.
- @return
- text string entered.
- */
- PString GetText() 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.
- */
- PString * 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 combo-box.
- */
- void SetValuePointer(
- PString * ptr /// New value pointer to associate with the control.
- );
- /**Set the maximum amount of text that the user may enter in the combo-box
- edit text part. Extra characters entered when it is full are ignored.
- */
- void SetMaxText(
- PINDEX max /// Maximum number of characters in text.
- );
- /**Get the current length of the text entered into the edit box. This is
- equivalent to #GetText().GetLength()#.
- @return
- number of characters in edit box.
- */
- PINDEX GetLength() const;
- /**Set the selected region in the text within the edit box. The selected
- region includes the character at the #start# position but
- does not include the character at the #finish# position.
-
- If #start# and #finish# are equal then there is
- no selected region. However, the caret is placed immediately before
- that position, ie so that the next character entered will be at
- #start# offset into the resultant string.
- If #finish# is less than #start# it is set to the
- same value as #start#. If either value is greater than the
- current length of the edit box, then they are set to the position of
- the end of the string.
- */
- void SetSelection(
- PINDEX start = 0, /// Start index position of selected text.
- PINDEX finish = P_MAX_INDEX /// Finish index position of selected text.
- );
- /**Get the selected region in the text in the edit box. If there is no
- selection active, the #start# and #finish#
- variables are both set to the caret position in the string.
- @return
- TRUE if has selection, FALSE if there is nothing selected.
- */
- BOOL GetSelection(
- PINDEX * start = NULL,
- /// Pointer to receive starting position of selected text.
- PINDEX * finish = NULL
- /// Pointer to receive finishing position of selected text.
- ) const;
- /**Cut the selected text to the clipboard. This copies the data and then
- deletes the current selection.
-
- If there is no current selection then this function does nothing.
- */
- void Cut();
- /**Copy the selected text to the clipboard.
- If there is no current selection then this function does nothing.
- */
- void Copy() const;
- /**Paste into the edit control from the clipboard into the edit box at the
- current caret position.
-
- If the paste would add so many characters that the limit set with
- Ref{SetMaxText()} would be exceeded then the paste does not take
- place.
-
- Also, if there is no text in the clipboard then this function does
- nothing.
- */
- void Paste();
- /**Delete the selected text. This does not copy the information to the
- clipboard and the selected text is lost.
-
- If there is no current selection then this function does nothing.
- */
- void Clear();
- /**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 combo-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 combo-box. */
- void DeleteString(
- PINDEX index /// Position in list of the string to remove.
- );
- /** Delete all the strings in the list 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
- combo-box.
- @return
- number of choices.
- */
- PINDEX GetCount() const;
- /**Set the current selection to the string specified by the index. The
- value of the string selectged is copied to the edit text box part of the
- combo-box. The string may then subsequently be edited.
- */
- void SetCurrent(
- PINDEX index /// Index into list of the string to copy.
- );
- /**Get the current selection. This is the selection made by either the user
- selecting an item in the list box part of the combo-box or the program
- using the SetCurrent() function. In either case once the edit text part
- has been edited by the user the "current" selection is no longer valid
- and the index returned is P_MAX_INDEX.
- @return
- index of the selected string in the list box.
- */
- PINDEX GetCurrent() 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 ///////////////