Add wxTextEntry::ForceUpper()

Allow automatically converting lower-case letters entered into wxTextCtrl to
upper-case equivalents. Provide generic fallback and implement the method
natively for all the major platforms.

Also update the text sample to show it in action.
This commit is contained in:
Vadim Zeitlin
2015-11-25 03:40:40 +01:00
parent 99d9a81e28
commit 69b66e9e2e
14 changed files with 238 additions and 18 deletions

View File

@@ -21,7 +21,7 @@ typedef struct _GtkEntry GtkEntry;
class WXDLLIMPEXP_CORE wxTextEntry : public wxTextEntryBase
{
public:
wxTextEntry() { }
wxTextEntry() { m_isUpperCase = false; }
// implement wxTextEntryBase pure virtual methods
virtual void WriteText(const wxString& text) wxOVERRIDE;
@@ -47,6 +47,7 @@ public:
virtual void SetEditable(bool editable) wxOVERRIDE;
virtual void SetMaxLength(unsigned long len) wxOVERRIDE;
virtual void ForceUpper() wxOVERRIDE;
#ifdef __WXGTK3__
virtual bool SetHint(const wxString& hint) wxOVERRIDE;
@@ -56,6 +57,7 @@ public:
// implementation only from now on
void SendMaxLenEvent();
bool GTKEntryOnInsertText(const char* text);
bool GTKIsUpperCase() const { return m_isUpperCase; }
protected:
// This method must be called from the derived class Create() to connect
@@ -85,7 +87,12 @@ private:
// implement this to return the associated GtkEntry
virtual GtkEntry *GetEntry() const = 0;
bool m_isUpperCase;
};
// We don't need the generic version.
#define wxHAS_NATIVE_TEXT_FORCEUPPER
#endif // _WX_GTK_TEXTENTRY_H_

View File

@@ -47,6 +47,7 @@ public:
virtual void SetEditable(bool editable);
virtual void SetMaxLength(unsigned long len);
virtual void ForceUpper();
#if wxUSE_UXTHEME
virtual bool SetHint(const wxString& hint);
@@ -98,5 +99,8 @@ private:
#endif // wxUSE_OLE
};
// We don't need the generic version.
#define wxHAS_NATIVE_TEXT_FORCEUPPER
#endif // _WX_MSW_TEXTENTRY_H_

View File

@@ -14,6 +14,8 @@
#include "wx/combobox.h"
#include "wx/osx/private.h"
@class wxTextEntryFormatter;
// implementation exposed, so that search control can pull it
class wxNSTextFieldControl : public wxWidgetCocoaImpl, public wxTextWidgetImpl
@@ -29,7 +31,10 @@ public :
virtual bool CanClipMaxLength() const { return true; }
virtual void SetMaxLength(unsigned long len);
virtual bool CanForceUpper() { return true; }
virtual void ForceUpper();
virtual wxString GetStringValue() const ;
virtual void SetStringValue( const wxString &str) ;
virtual void Copy() ;
@@ -57,6 +62,9 @@ protected :
private:
// Common part of both ctors.
void Init(WXWidget w);
// Get our formatter, creating it if necessary.
wxTextEntryFormatter* GetFormatter();
};
class wxNSTextViewControl : public wxWidgetCocoaImpl, public wxTextWidgetImpl

View File

@@ -655,7 +655,10 @@ public :
virtual bool CanClipMaxLength() const { return false; }
virtual void SetMaxLength(unsigned long WXUNUSED(len)) {}
virtual bool CanForceUpper() { return false; }
virtual void ForceUpper() {}
virtual bool GetStyle( long position, wxTextAttr& style);
virtual void SetStyle( long start, long end, const wxTextAttr& style ) ;
virtual void Copy() ;

View File

@@ -50,6 +50,8 @@ public:
// in a single line text control
virtual void SetMaxLength(unsigned long len);
virtual void ForceUpper();
// writing text inserts it at the current position;
// appending always inserts it at the end
virtual void WriteText(const wxString& text);

View File

@@ -138,10 +138,16 @@ public:
virtual void SetEditable(bool editable) = 0;
// input restrictions
// ------------------
// set the max number of characters which may be entered in a single line
// text control
virtual void SetMaxLength(unsigned long WXUNUSED(len)) { }
// convert any lower-case characters to upper-case on the fly in this entry
virtual void ForceUpper();
// hints
// -----
@@ -208,6 +214,10 @@ public:
SuppressTextChangedEvents();
}
// change the entry value to be in upper case only, if needed (i.e. if it's
// not already the case)
void ConvertToUpperCase();
protected:
// flags for DoSetValue(): common part of SetValue() and ChangeValue() and
// also used to implement WriteText() in wxMSW