4 * Single line text edit box control.
6 * Portable Windows Library
8 * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25 * All Rights Reserved.
27 * Contributor(s): ______________________________________.
30 * Revision 1.24 2001/05/22 12:49:33 robertj
31 * Did some seriously wierd rewrite of platform headers to eliminate the
32 * stupid GNU compiler warning about braces not matching.
34 * Revision 1.23 2000/04/13 01:37:14 robertj
35 * Added missing implementation of PEditBox::GetSelection() on Win32.
36 * Added PEditBox::ReplaceSelection() function.
38 * Revision 1.22 1999/03/10 03:49:51 robertj
39 * More documentation adjustments.
41 * Revision 1.21 1999/03/09 08:01:48 robertj
42 * Changed comments for doc++ support (more to come).
44 * Revision 1.20 1999/02/16 08:08:45 robertj
45 * MSVC 6.0 compatibility changes.
47 * Revision 1.19 1998/09/23 06:23:25 robertj
48 * Added open source copyright license.
50 * Revision 1.18 1995/06/17 11:12:32 robertj
51 * Documentation update.
53 * Revision 1.17 1995/06/04 08:47:27 robertj
54 * Added missing virtual for SetText() - Unix implementation requirement.
56 * Revision 1.16 1995/03/14 12:41:22 robertj
57 * Updated documentation to use HTML codes.
59 * Revision 1.15 1995/02/19 04:19:08 robertj
60 * Added dynamically linked command processing.
62 * Revision 1.14 1995/02/05 00:46:10 robertj
63 * Added notification of end input.
65 * Revision 1.13 1995/01/27 11:45:57 robertj
68 * Revision 1.12 1994/12/15 12:47:13 robertj
71 * Revision 1.11 1994/10/30 11:46:36 robertj
72 * Changed mechanism for doing notification callback functions.
74 * Revision 1.10 1994/08/23 11:32:52 robertj
77 * Revision 1.9 1994/08/22 00:46:48 robertj
78 * Added pragma fro GNU C++ compiler.
80 * Revision 1.8 1994/06/25 11:55:15 robertj
81 * Unix version synchronisation.
83 * Revision 1.7 1994/04/11 14:14:01 robertj
86 * Revision 1.6 1994/03/07 07:38:19 robertj
87 * Major enhancementsacross the board.
89 * Revision 1.5 1994/01/03 04:42:23 robertj
90 * Mass changes to common container classes and interactors etc etc etc.
92 * Revision 1.4 1993/09/27 16:35:25 robertj
93 * Removed special constructor for dialog resource loading.
95 * Revision 1.3 1993/08/21 01:50:33 robertj
96 * Made Clone() function optional, default will assert if called.
98 * Revision 1.2 1993/07/14 12:49:16 robertj
110 /**This class defines a text edit box control. This control is for a single
111 line of text. The usual capabilities for editing text are available,
112 though the exact features are platform dependent.
114 class PEditBox
: public PControl
116 PCLASSINFO(PEditBox
, PControl
);
119 /**Create a new single line edit box control.
122 PInteractor
* parent
/// Interactor into which the control is placed.
125 /** Create control from interactor layout with the specified control ID. */
127 PInteractorLayout
* parent
, /// Interactor into which the box is placed.
128 PRESOURCE_ID ctlID
, /// Identifier for the control in the layout.
129 const PNotifier
& notify
, /// Function to call when changes state.
130 PString
* valuePtr
/// Variable to change to the editor value.
133 /** Destroy the edit box control. */
137 /**@name PNotifier codes */
138 /** Notification codes sent to the callback function. */
140 /**Notification code for each change of the edit text box string. This
141 would notify the user on every key entered and may be used to take
142 action on the particular value of the control.
144 EditChange
= NotifyChange
,
145 /**Notification code for when the user exits the edit box. This occurs
146 when the control loses the keyboard focus and the \Ref{OnEndInput()}
147 function has returned TRUE.
153 /**@name Overrides from class PInteractor */
154 /**The system calls this whenever the system wishes to change focus to
155 another interactor in a given \Ref{PTitledWindow} or
156 \Ref{PInteractorLayout}.
158 This function in conjunction with the keyboard focus changing and the
159 \Ref{PInteractor::SetFocusInteractor()} function controls the transfer
160 of focus from one interactor in a logical group (eg dialog) to another.
161 It is primarily used for field level validation. For example the
162 \Ref{PIntegerEditBox} control uses this to prevent the user from
163 exiting the control until a valid entry hash been made.
165 Note that the focus {\bf does} actually change with appropriate
166 calls to the \Ref{PInteractor::OnGainFocus()} and
167 \Ref{PInteractor::OnLostFocus()} functions. The focus gets set back to
168 the original interactor when this function disallows the focus change.
170 For edit boxes this will execute the notification function before
174 FALSE will prevent the focus change from occurring and TRUE allows the
177 virtual BOOL
OnEndInput();
180 /**@name Overrides from class PControl */
181 /**This function transfers the value of the control to or from the variable
182 pointed to by the value pointer member variable.
184 virtual void TransferValue(
186 /**Transfer value option. When this is -1 when the function transfers
187 the value from the value pointer into the control. This is called in
188 \Ref{PDialog::OnInit()} function. When option is zero then the
189 function transfers the value from the control to the value pointer
190 variable. This is called just before the callback function every time
191 the edit box value changes.
196 /**@name New functions for class */
197 /**Set the text contents of the edit box control. This will be updated on
198 the screen immediately (within OS constraints).
200 A call to this function will cause the notification function to be
201 called with a code of #EditChange#.
203 virtual void SetText(
204 const PString
& str
/// New value string for the edit text box.
207 /**Get the current text contents of the edit box control as entered by the
208 user, or set via the \Ref{SetText()} function.
211 string for the current contents of the edit box.
213 PString
GetText() const;
215 /**Get the current value pointer associated with the control. The variable
216 pointed to by this is autamatically updated with the current value of
220 value pointer associated with the control.
222 PString
* GetValuePointer() const;
224 /**Set the current value pointer associated with the control. The variable
225 pointed to by this is autamatically updated with the current value of
228 void SetValuePointer(
229 PString
* ptr
/// New value pointer to associate with the control.
233 /**Set the maximum amount of text that the user may enter in the combo-box
234 edit text part. Extra characters entered when it is full are ignored.
237 PINDEX max
/// New maximum character entry limit.
240 /**Get the current length of the text entered into the edit box. This is
241 equivalent to #GetText().GetLength()#.
244 number of characters in edit box.
246 PINDEX
GetLength() const;
248 /**Determine if the edit control has been modified by the user since the
249 last call to \Ref{SetText()} or \Ref{GetText()}.
252 TRUE if the user has changed the text in the edit box.
254 BOOL
IsModified() const;
256 /**Set the selected region in the text within the edit box. The selected
257 region includes the character at the #start# position but
258 does not include the character at the #finish# position.
260 If #start# and #finish# are equal then there is
261 no selected region. However, the caret is placed immediately before
262 that position, ie so that the next character entered will be at
263 #start# offset into the resultant string.
265 If #finish# is less than #start# it is set to the
266 same value as #start#. If either value is greater than the
267 current length of the edit box, then they are set to the position of
268 the end of the string.
271 PINDEX start
= 0, /// Start index position of selected text.
272 PINDEX finish
= P_MAX_INDEX
/// Finish index position of selected text.
275 /**Get the selected region in the text in the edit box. If there is no
276 selection active, the #start# and #finish#
277 variables are both set to the caret position in the string.
280 TRUE if has selection, FALSE if there is nothing selected.
283 PINDEX
* start
= NULL
,
284 /// Pointer to receive starting position of selected text.
285 PINDEX
* finish
= NULL
286 /// Pointer to receive finishing position of selected text.
289 /**Replace the selection with the string.
290 If there is no selection then the string is inserted into the edit box
291 at the curent cursor location.
293 void ReplaceSelection(
294 const PString
& text
, /// Text to replace selection with
295 BOOL canUndo
= TRUE
/// Flag to indicate replacement can be undone.
298 /**Determine if the edit control can undo the last edit operation performed
302 TRUE if undo will succeed.
304 BOOL
CanUndo() const;
306 /** Undo the last edit operation performed by the user. */
309 /**Cut the selected text to the clipboard. This copies the data and then
310 deletes the current selection.
312 If there is no current selection then this function does nothing.
314 A call to this function will cause the notification functionto be
315 called with a code of #EditChange#.
319 /**Copy the selected text to the clipboard.
321 If there is no current selection then this function does nothing.
325 /**Paste into the edit control from the clipboard into the edit box at the
326 current caret position.
328 If the paste would add so many characters that the limit set with
329 \Ref{SetMaxText()} would be exceeded then the paste does not take
332 Also, if there is no text in the clipboard then this function does
335 A call to this function will cause the notification functionto be
336 called with a code of #EditChange#.
340 /**Delete the selected text. This does not copy the information to the
341 clipboard and the selected text is lost.
343 If there is no current selection then this function does nothing.
345 A call to this function will cause the notification functionto be
346 called with a code of #EditChange#.
353 // Common contructor code.
356 // Include platform dependent part of class
357 #include <pwlib/editbox.h>
361 // End Of File ///////////////////////////////////////////////////////////////