editbox.h
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:12k
- /*
- * editbox.h
- *
- * Single line text edit 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: editbox.h,v $
- * Revision 1.23 2000/04/13 01:37:14 robertj
- * Added missing implementation of PEditBox::GetSelection() on Win32.
- * Added PEditBox::ReplaceSelection() function.
- *
- * Revision 1.22 1999/03/10 03:49:51 robertj
- * More documentation adjustments.
- *
- * Revision 1.21 1999/03/09 08:01:48 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:25 robertj
- * Added open source copyright license.
- *
- * Revision 1.18 1995/06/17 11:12:32 robertj
- * Documentation update.
- *
- * Revision 1.17 1995/06/04 08:47:27 robertj
- * Added missing virtual for SetText() - Unix implementation requirement.
- *
- * Revision 1.16 1995/03/14 12:41:22 robertj
- * Updated documentation to use HTML codes.
- *
- * Revision 1.15 1995/02/19 04:19:08 robertj
- * Added dynamically linked command processing.
- *
- * Revision 1.14 1995/02/05 00:46:10 robertj
- * Added notification of end input.
- *
- * Revision 1.13 1995/01/27 11:45:57 robertj
- * documentation.
- *
- * Revision 1.12 1994/12/15 12:47:13 robertj
- * Documentation.
- *
- * Revision 1.11 1994/10/30 11:46:36 robertj
- * Changed mechanism for doing notification callback functions.
- *
- * Revision 1.10 1994/08/23 11:32:52 robertj
- * Oops
- *
- * Revision 1.9 1994/08/22 00:46:48 robertj
- * Added pragma fro GNU C++ compiler.
- *
- * Revision 1.8 1994/06/25 11:55:15 robertj
- * Unix version synchronisation.
- *
- * Revision 1.7 1994/04/11 14:14:01 robertj
- * Added consts.
- *
- * Revision 1.6 1994/03/07 07:38:19 robertj
- * Major enhancementsacross the board.
- *
- * 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 _PEDITBOX
- #ifdef __GNUC__
- #pragma interface
- #endif
- /**This class defines a text edit box control. This control is for a single
- line of text. The usual capabilities for editing text are available,
- though the exact features are platform dependent.
- */
- class PEditBox : public PControl
- {
- PCLASSINFO(PEditBox, PControl);
- public:
- /**Create a new single line edit box control.
- */
- PEditBox(
- PInteractor * parent /// Interactor into which the control is placed.
- );
- /** Create control from interactor layout with the specified control ID. */
- PEditBox(
- 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 editor value.
- );
- /** Destroy the edit box control. */
- virtual ~PEditBox();
- /**@name PNotifier codes */
- /** Notification codes sent to the callback function. */
- enum {
- /**Notification code for each change of the edit text box string. This
- would notify the user on every key entered and may be used to take
- action on the particular value of the control.
- */
- EditChange = NotifyChange,
- /**Notification code for when the user exits the edit box. This occurs
- when the control loses the keyboard focus and the Ref{OnEndInput()}
- function has returned TRUE.
- */
- EndEdit
- };
- /**@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 edit box value changes.
- */
- );
- /**@name New functions for class */
- /**Set the text contents of the edit box control. This will be updated on
- the screen immediately (within OS constraints).
- A call to this function will cause the notification function to be
- called with a code of #EditChange#.
- */
- virtual void SetText(
- const PString & str /// New value string for the edit text box.
- );
- /**Get the current text contents of the edit box control as entered by the
- user, or set via the Ref{SetText()} function.
- @return
- string for the current contents of the edit box.
- */
- 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 edit 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 edit 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 /// New maximum character entry limit.
- );
- /**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;
- /**Determine if the edit control has been modified by the user since the
- last call to Ref{SetText()} or Ref{GetText()}.
- @return
- TRUE if the user has changed the text in the edit box.
- */
- BOOL IsModified() 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;
- /**Replace the selection with the string.
- If there is no selection then the string is inserted into the edit box
- at the curent cursor location.
- */
- void ReplaceSelection(
- const PString & text, /// Text to replace selection with
- BOOL canUndo = TRUE /// Flag to indicate replacement can be undone.
- );
- /**Determine if the edit control can undo the last edit operation performed
- by the user.
- @return
- TRUE if undo will succeed.
- */
- BOOL CanUndo() const;
- /** Undo the last edit operation performed by the user. */
- void Undo();
- /**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.
- A call to this function will cause the notification functionto be
- called with a code of #EditChange#.
- */
- 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.
- A call to this function will cause the notification functionto be
- called with a code of #EditChange#.
- */
- 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.
- A call to this function will cause the notification functionto be
- called with a code of #EditChange#.
- */
- void Clear();
- private:
- void Construct();
- // Common contructor code.
- #ifdef DOC_PLUS_PLUS
- };
- #endif
- // Class declaration continued in platform specific header file ///////////////