14#include <owl/validate.rh>
17#if !defined(__CYGWIN__)
27#if defined(__BORLANDC__)
64TEdit* TEdit::ValidatorReFocus =
nullptr;
102:
TStatic(parent,
id, text, x, y, w, h, textLen, module), Validator(
nullptr), Requirement(
roNone)
106 ModifyStyle(SS_LEFT, ES_LEFT | ES_AUTOHSCROLL |WS_BORDER | WS_TABSTOP);
109 Attr.Style |= ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL | WS_HSCROLL;
117:
TStatic(parent, id, text, x, y, w, h, textLen, module), Validator(nullptr), Requirement(
roNone)
121 ModifyStyle(SS_LEFT, ES_LEFT | ES_AUTOHSCROLL |WS_BORDER | WS_TABSTOP);
124 Attr.Style |= ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL | WS_HSCROLL;
136:
TStatic(parent, resourceId, textLen, module), Validator(nullptr), Requirement(
roNone)
145:
TStatic(hWnd, module), Validator(nullptr), Requirement(
roNone)
198 retVal |= DLGC_WANTTAB;
216 if (Validator && key != VK_BACK) {
219 GetText(oldBuff, oldBuffLen+1);
221 int startSel, endSel;
223 bool wasAppending = endSel == oldBuffLen;
237 LPTSTR buff =
LockBuffer(std::max(
static_cast<int>(TextLimit), std::max(oldBuffLen, buffLen)) +
sizeof(
tchar) + 1024);
243 if (!Validator->HasOption(
voOnAppend) || (wasAppending && endSel == buffLen)) {
244 if (!Validator->IsValidInput(buff,
false)) {
246 postMsgModify = preMsgModify;
250 startSel = endSel =
static_cast<int>(
::_tcslen(buff));
256 if (endSel == buffLen && !Validator->IsValidInput(buff,
false))
257 Validator->Error(
this);
287 if (key == VK_TAB && !
IsValid(
false))
292 if (Validator && Validator->HasOption(
voOnAppend)) {
293 int startSel, endSel;
297 bool wasAppending = endSel == buffLen;
304 bool err = endSel ==
static_cast<int>(
::_tcslen(buff)) && !Validator->IsValidInput(buff,
false);
307 Validator->Error(
this);
334 if ((Validator ||
IsRequired()) && !ValidatorReFocus)
352 if (btnId != IDCANCEL && btnId != IDOK && !
IsValid(
false)) {
353 ValidatorReFocus =
this;
370 if (ValidatorReFocus ==
this)
371 ValidatorReFocus =
nullptr;
385 int startSel, endSel;
390 bool changed = Validator->Adjust(s, startSel, endSel, 1) != 0;
447 commandHandler.
Enable(sPos != ePos);
496 return static_cast<int>(
CONST_CAST(
TEdit*,
this)->SendMessage(EM_LINELENGTH,
517 bool success = strSize >= lineLength + 1;
522 if (
static_cast<unsigned int>(strSize) <
sizeof(
int16)) {
524 return lineLength == 0;
526 (
reinterpret_cast<int16 *
>(textString))[0] =
int16(strSize);
530 int n = min(strSize - 1, bytesCopied);
544 TEditGetLine(
const TEdit& c,
int line_) : edit(c), line(line_) {}
546 int operator()(LPTSTR buf,
int buf_size)
548 bool ok = edit.
GetLine(buf, buf_size, line);
549 WARN(!ok,
_T(
"TEdit::GetLine failed, line = ") << line);
550 static_cast<void>(ok);
578 if (!(
GetWindowLong(GWL_STYLE) & ES_MULTILINE) || v >= 0x60000)
582 LPTSTR buffer =
new tchar[newSize];
590 hBuffer = LocalReAlloc(hBuffer, newSize *
sizeof(
tchar), LHND);
594 return static_cast<LPTSTR
>(LocalLock(hBuffer));
612 if (!(
GetWindowLong(GWL_STYLE) & ES_MULTILINE) || v >= 0x60000)
616 delete[]
const_cast<LPTSTR
>(buffer);
620 HLOCAL hBuffer = LocalHandle(
const_cast<LPTSTR
>(buffer));
621 LocalUnlock(hBuffer);
634strstrcd(LPCTSTR str1, LPCTSTR str2,
bool caseSens)
637 int len2 =
static_cast<int>(
::_tcslen(str2));
638 LPTSTR p =
const_cast<LPTSTR
>(str1);
639 LPCTSTR endp = str1 +
::_tcslen(str1) - len2 + 1;
650#if defined(BI_DBCS_SUPPORT) && !defined(UNICODE)
668#if defined(BI_DBCS_SUPPORT) && !defined(UNICODE)
685strrstrcd(LPCTSTR str1,
uint len1, LPCTSTR str2,
689 int len2 =
static_cast<int>(
::_tcslen(str2));
690 LPTSTR p =
const_cast<LPTSTR
>(str1 + len1 - len2);
692#if defined(BI_DBCS_SUPPORT) && !defined(UNICODE)
705#if defined(BI_DBCS_SUPPORT) && !defined(UNICODE)
723#if defined(BI_DBCS_SUPPORT) && !defined(UNICODE)
747 bool wholeWord,
bool up)
749 if (!text || !text[0])
752 if (startPos == -1) {
755 startPos = up ? sBeg : sEnd;
757 int textLen =
static_cast<int>(
::_tcslen(text));
765 pos = strrstrcd(buffer, startPos, text, caseSensitive);
767 pos = strstrcd(buffer+startPos, text, caseSensitive);
772 if (wholeWord && pos) {
773#if defined(BI_DBCS_SUPPORT)
778 if ((pos > buffer &&
_istalnum(*prevPos)) ||
782 startPos =
static_cast<int>(prevPos - buffer +
::_tcslen(text));
784 startPos =
static_cast<int>(
::AnsiNext(pos) - buffer);
788 if ((pos > buffer &&
_istalnum(pos[-1])) ||
791 startPos =
static_cast<uint>(pos-buffer) + !up;
802 int sBeg =
static_cast<int>(pos - buffer);
821 int startPos, endPos;
825 if (startPos != endPos) {
856 if (lineNumber == -1)
861 if (firstPos != -1) {
867 if (firstPos == 0 && firstPos == lastPos) {
889 WARN(
true,
_T(
"TEdit::GetSubText is deprecated. Use GetTextRange instead."));
890 if (!textBuf)
return;
912 const int begin = r.
cpMin;
922 if (begin == 0 && end == -1)
928 if (begin < 0 || end < 0)
930 WARN(
true,
_T(
"Arguments out of range"));
933 else if (begin == end)
935 WARN(
true,
_T(
"Empty range"));
938 else if (begin > end)
940 WARN(
true,
_T(
"Inverted range"));
953 end = std::min(end, n);
963 for (
int i = startLine; i <= endLine; ++i)
966 int b = (i == startLine) ? startChar : 0;
967 int e = (i == endLine) ? endChar :
static_cast<int>(line.length());
969 s.append(line, b, e - b);
1025 struct TRefocusGuard
1029 TRefocusGuard(
TEdit* edit,
bool& valid) : edit(edit), valid(valid) {}
1030 ~TRefocusGuard() {
if (valid && edit == ValidatorReFocus) ValidatorReFocus =
nullptr; }
1032 reFocusGuard = {
this, valid };
1040 bool reFocus =
GetFocus() != *
this;
1041 if (reportError) ValidatorReFocus =
this;
1054 if (!valid && reportError)
1060 if (valid && Validator)
1061 valid = reportError ? Validator->Valid(buffer,
this) : Validator->IsValid(buffer);
1069 if (reportError && !valid && reFocus)
1084 Validator = validator;
1112 const size_t bigEnough = max<size_t>(1024, TextLimit + 1);
1113 vector<tchar> text(bigEnough);
1114 GetText(&text[0],
static_cast<int>(text.size()));
1116 uint result = Validator->Transfer(&text[0], buffer, direction);
1129#if OWL_PERSISTENT_STREAMS
1137 auto t = GetObject();
1156TEdit::Streamer::Write(
opstream& os)
const
1158 auto t = GetObject();
1162 os << static_cast<int>(t->Requirement);
#define WARN(condition, message)
#define PRECONDITION(condition)
Pointer to an array of type T.
The clipboard class encapsulates the methods for the clipboard object of Windows.
bool IsClipboardFormatAvailable(uint format) const
Indicates if the format specified in format exists for use in the Clipboard.
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
virtual void Enable(bool enable=true)
Enables or disables the command sender.
A TEdit is an interface object that represents an edit control interface element.
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
TNmUpDown is a wrapper of the NM_UPDOWN structure sent with notifications from an 'UpDown' control.
An interface object that represents a static text interface element.
int GetTextLen() const
Return the current length of the text in the control, excluding the terminating null character.
TStatic(TWindow *parent, int id, LPCTSTR title, int x, int y, int w, int h, uint textLen=0, TModule *=nullptr)
Constructs a static control object with the supplied parent window (parent), control ID (Id),...
void SetText(LPCTSTR str)
Sets the static control's text to the string supplied in str.
int GetText(TCHAR *str, int maxChars) const
Retrieves the static control's text, stores it in the str argument of maxChars size,...
auto Transfer(void *buffer, TTransferDirection) -> uint override
TWindow override Transfers TextLimit characters of text to or from a transfer buffer pointed to by bu...
Classes that inherit from TStreamableBase are known as streamable classes (their objects can be writt...
A streamable class, TValidator defines an abstract data validation object.
Type-safe encapsulation of a Windows class name, a union between ATOM and LPCTSTR.
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
HWND SetFocus()
Sets the keyboard focus to current window and activates the window that receives the focus by sending...
tstring LoadString(uint id) const
int MessageBox(LPCTSTR text, LPCTSTR caption=0, uint flags=MB_OK) const
Displays a message in a modal pop-up dialog box.
TWindow * GetParent() const
Retrieves the OWL object of the parent window. If none exists, returns 0.
bool IsWindowEnabled() const
Returns true if the window is enabled.
virtual auto GetWindowClassName() -> TWindowClassName
long GetWindowLong(int index) const
Retrieves information about the window depending on the value stored in index.
TWindow * GetParentO() const
Return the OWL's parent for this window.
uint EvGetDlgCode(const MSG *msg)
The default message handler for WM_GETDLGCODE.
void EnableTransfer()
Enables the transfer mechanism, which allows state data to be transferred between the window and a tr...
void EvKillFocus(HWND hWndGetFocus)
Handle WM_KILLFOCUS so that we can have a parent window hold onto our Handle and possibly restore foc...
bool ModifyStyle(uint32 offBits, uint32 onBits, uint swpFlags=0)
Modifies the style bits of the window.
TResult DefaultProcessing()
Handles default processing of events, which includes continued processing of menu/accelerators comman...
int GetDlgCtrlID() const
Returns the ID of the control.
virtual bool CanClose()
Use this function to determine if it is okay to close a window.
void EvSetFocus(HWND hWndLostFocus)
The default message handler for WM_SETFOCUS.
bool PostMessage(TMsgId, TParam1=0, TParam2=0)
Posts a message (msg) to the window in the application's message queue.
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
virtual void SetupWindow()
Performs setup following creation of an associated MS-Windows window.
void EvChar(uint key, uint repeatCount, uint flags)
The default message handler for WM_CHAR.
bool ModifyExStyle(uint32 offBits, uint32 onBits, uint swpFlags=0)
Modifies the style bits of the window.
static HWND GetFocus()
Gets a handle to the window that has the focus.
HWND THandle
TWindow encapsulates an HWND.
HWND GetHandle() const
Returns the handle of the window.
int GetWindowTextLength() const
Returns the length, in characters, of the specified window's title.
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Base class for writing streamable objects.
Definition of class TEdit.
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
void ReadBaseObject(Base *base, ipstream &in)
void WriteBaseObject(Base *base, opstream &out)
TRequireOption GetRequired() const
Returns the requirement option for the edit control.
void SetValidator(TValidator *validator)
Sets a new validator for this control, can be 0. Cleans up the old validator.
bool DeleteSubText(int startPos, int endPos)
Deletes the text between the starting and ending positions specified by startPos and endPos,...
void CmPasteEnable(TCommandEnabler &commandHandler)
This function is called for the Paste menu item to determine whether or not the item is enabled.
bool DeleteSelection()
Deletes the currently selected text, and returns false if no text is selected.
void EvChildInvalid(HWND)
Handler for input validation message sent by parent.
void EvSetFocus(HWND hWndLostFocus)
Handle the set focus message and make sure the anti-oscillation flag is cleared.
virtual void GetSelection(int &startPos, int &endPos) const
Return the starting and ending positions of the selected text.
void SetMemHandle(HLOCAL localMem)
Sets the memory handle for the edit control's buffer.
bool EvUpDown(TNmUpDown &)
Handles up-down messages from an up-down control and adjusts contents if there is a validator to help...
void ValidatorError()
Handles validation errors that occur as a result of validating the edit control.
virtual void LimitText(int)
Limit the amount of new text that can be entered in the edit control.
bool DeleteLine(int lineNumber)
Deletes the text in the line specified by lineNumber in a multiline edit control.
void EvChar(uint key, uint repeatCount, uint flags)
Validates Self whenever a character is entered.
void EvKillFocus(HWND hWndGetFocus)
Validates this whenever the focus is about to be lost.
virtual tstring GetTextRange(const TRange &) const
Retrieves a specified range of text from the edit control.
HLOCAL GetMemHandle() const
Return the memory handle for the edit control's buffer.
void SetupWindow() override
void ENErrSpace()
EN_ERRSPACE.
bool IsValid(bool reportErr=false)
Always returns true if the TEdit object does not have an associated TValidator object (i....
void CmModEnable(TCommandEnabler &commandHandler)
This function is called for the Undo menu item to determine whether or not the item is enabled.
void EvKeyDown(uint key, uint repeatCount, uint flags)
EvKeyDown translates the virtual key code into a movement.
void UnlockBuffer(LPCTSTR buffer, bool updateHandle=false)
Unlock the edit control's buffer locked by LockBuffer.
virtual int GetLineFromPos(int charPos) const
Return the line number associated with character index "CharPos".
bool IsRequired() const
Returns true if a value is required for the edit control.
int GetLineLength(int lineNumber) const
Return the length of line number "lineNumber".
auto Transfer(void *buffer, TTransferDirection) -> uint override
Transfers state information for TEdit controls.
uint EvGetDlgCode(const MSG *)
Responds to WM_GETDLGCODE messages that are sent to a dialog box associated with a control.
virtual void GetSubText(TCHAR *textBuf, int startPos, int endPos) const
Deprecated. Use GetTextRange instead.
void CmSelectEnable(TCommandEnabler &commandHandler)
This function is called for Cut/Copy/Delete menu items to determine whether or not the item is enable...
bool IsModified() const
Returns true if the user has changed the text in the edit control.
TCHAR * LockBuffer(uint newSize=0)
Lock and unlock this edit control's buffer.
~TEdit() override
Destructor for a TEdit control.
int GetNumLines() const
Return the number of lines in the associated edit control.
void Clear() override
Override TStatic virtual member functions.
void CmCharsEnable(TCommandEnabler &commandHandler)
This function is called for the Clear menu item to determine whether or not the item is enabled.
virtual int Search(int startPos, LPCTSTR text, bool caseSensitive=false, bool wholeWord=false, bool up=false)
searches for and selects the given text and returns the offset of the text or -1 if the text is not f...
int GetLineIndex(int lineNumber) const
In a multiline edit control, GetLineIndex returns the number of characters that appear before the lin...
virtual bool SetSelection(int startPos, int endPos)
Select the characters in the range "startPos .. endPos".
TRange GetSelection() const
Functional style overload.
TRange(int b=0, int e=-1)
TEdit(TWindow *parent, int id, LPCTSTR text, int x, int y, int w, int h, uint textLimit=0, bool multiline=false, TModule *=nullptr)
Constructs an edit control object with a parent window (parent).
bool GetLine(TCHAR *str, int strSize, int lineNumber) const
Return the text of line number "lineNumber" (0-terminated).
@ voTransfer
Option to perform conversion & transfer.
@ voOnAppend
Option to only validate input on appending.
TTransferDirection
The TTransferDirection enum describes the constants that the transfer function uses to determine how ...
@ tdSetData
Set data from the buffer into the window.
Object Windows Library (OWLNext Core).
TWindow * GetWindowPtr(HWND, const TApplication *)
Raw function to retrieve a TWindow pointer given an HWND from the a given app, or any app (app==0).
LPARAM TParam2
Second parameter type.
tstring CopyText(int size, TGetText get_text)
Copies text from a C-string (null-terminated character array) into a string object,...
auto GetCommCtrlVersion() -> DWORD
Returns the version number of the Common Control library (ComCtl32.dll).
EV_UDN_DELTAPOS(UINT_MAX, EvUpDown)
EV_NOTIFY_AT_CHILD(BN_CLICKED, BNClicked)
WPARAM TParam1
First parameter type.
EV_COMMAND_ENABLE(CM_FILENEW, CeFileNew)
IMPLEMENT_STREAMABLE1(TApplication, TModule)
EV_COMMAND(IDOK, CmOkCancel)
#define CONST_CAST(targetType, object)
Definition of class TString, a flexible universal string envelope class.
Represents a half-open range of positions in the edit control, e.g.
Definition of class TUpDown.