wxHexValidator extended with leading zeros support

Version set to 1.2
This commit is contained in:
Simon Rozman 2016-05-23 14:05:37 +02:00
parent 28f244cf2f
commit cdefd74f3f
5 changed files with 31 additions and 20 deletions

View File

@ -40,13 +40,13 @@ Component ComponentId Directory_ Attributes Condition KeyPath
s$(MSIBUILD_LENGTH_ID) S38 s$(MSIBUILD_LENGTH_ID) i2 S255 S$(MSIBUILD_LENGTH_ID) s$(MSIBUILD_LENGTH_ID) S38 s$(MSIBUILD_LENGTH_ID) i2 S255 S$(MSIBUILD_LENGTH_ID)
Component Component Component Component
!IF "$(PLAT)" == "Win32" !IF "$(PLAT)" == "Win32"
compwxExtend.dll.Win32 {239F2FF9-E998-4F81-85A8-DA2C0A5F860B} $(WXEXTEND_BIN_DIR) 0 filewxExtend.dll.Win32 compwxExtend.dll.Win32 {7645D753-4A8C-40C6-BD6F-6DDE54F2B8F8} $(WXEXTEND_BIN_DIR) 0 filewxExtend.dll.Win32
!ENDIF !ENDIF
!IF "$(PLAT)" == "x64" !IF "$(PLAT)" == "x64"
compwxExtend.dll.x64 {AA798500-8E4F-4554-8611-F2C225046606} $(WXEXTEND_BIN_DIR) 256 filewxExtend.dll.x64 compwxExtend.dll.x64 {919135CB-B106-467E-A3DA-CBC463FBB7FF} $(WXEXTEND_BIN_DIR) 256 filewxExtend.dll.x64
!ENDIF !ENDIF
!IF "$(LANG)" == "Sl" !IF "$(LANG)" == "Sl"
compwxExtend.mo.sl_SI {026F2E74-4190-4B49-820B-94141F32F04B} WXEXTENDLOCSLSIDIR $(MSIBUILD_COMPONENT_ATTRIB_FILE) filewxExtend.mo.sl_SI compwxExtend.mo.sl_SI {08656BB6-0887-4605-B6D3-20B0444624BA} WXEXTENDLOCSLSIDIR $(MSIBUILD_COMPONENT_ATTRIB_FILE) filewxExtend.mo.sl_SI
!ENDIF !ENDIF
<<NOKEEP <<NOKEEP
@ -79,22 +79,22 @@ s$(MSIBUILD_LENGTH_ID) s$(MSIBUILD_LENGTH_ID) l255 i4 S$(MSIBUILD_LENGTH_ID) S20
File File File File
!IF "$(PLAT)" == "Win32" !IF "$(PLAT)" == "Win32"
!IF "$(CFG)" == "Release" !IF "$(CFG)" == "Release"
filewxExtend.dll.Win32 compwxExtend.dll.Win32 WXEXTE~2.DLL|wxExtend11u_vc100.dll 0 0 1536 1 filewxExtend.dll.Win32 compwxExtend.dll.Win32 WXEXTE~2.DLL|wxExtend12u_vc100.dll 0 0 1536 1
!ENDIF !ENDIF
!IF "$(CFG)" == "Debug" !IF "$(CFG)" == "Debug"
filewxExtend.dll.Win32 compwxExtend.dll.Win32 WXEXTE~4.DLL|wxExtend11ud_vc100.dll 0 0 1536 1 filewxExtend.dll.Win32 compwxExtend.dll.Win32 WXEXTE~4.DLL|wxExtend12ud_vc100.dll 0 0 1536 1
!ENDIF !ENDIF
!ENDIF !ENDIF
!IF "$(PLAT)" == "x64" !IF "$(PLAT)" == "x64"
!IF "$(CFG)" == "Release" !IF "$(CFG)" == "Release"
filewxExtend.dll.x64 compwxExtend.dll.x64 WXEXTE~6.DLL|wxExtend11u_vc100_x64.dll 0 0 1536 1 filewxExtend.dll.x64 compwxExtend.dll.x64 WXEXTE~6.DLL|wxExtend12u_vc100_x64.dll 0 0 1536 1
!ENDIF !ENDIF
!IF "$(CFG)" == "Debug" !IF "$(CFG)" == "Debug"
filewxExtend.dll.x64 compwxExtend.dll.x64 WXEXTE~8.DLL|wxExtend11ud_vc100_x64.dll 0 0 1536 1 filewxExtend.dll.x64 compwxExtend.dll.x64 WXEXTE~8.DLL|wxExtend12ud_vc100_x64.dll 0 0 1536 1
!ENDIF !ENDIF
!ENDIF !ENDIF
!IF "$(LANG)" == "Sl" !IF "$(LANG)" == "Sl"
filewxExtend.mo.sl_SI compwxExtend.mo.sl_SI WXEXTE~1.MO|wxExtend11.mo 0 1060 0 1 filewxExtend.mo.sl_SI compwxExtend.mo.sl_SI WXEXTE~1.MO|wxExtend12.mo 0 1060 0 1
!ENDIF !ENDIF
<<NOKEEP <<NOKEEP

View File

@ -2,7 +2,7 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" /> <ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros"> <PropertyGroup Label="UserMacros">
<wxExtendVersion>11</wxExtendVersion> <wxExtendVersion>12</wxExtendVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<OutDir>..\..\..\output\$(Platform).$(Configuration)\</OutDir> <OutDir>..\..\..\output\$(Platform).$(Configuration)\</OutDir>

View File

@ -23,17 +23,17 @@
/// ///
/// wxExtend Version /// wxExtend Version
/// ///
#define wxEXTEND_VERSION 0x01010000 #define wxEXTEND_VERSION 0x01020000
#define wxEXTEND_VERSION_MAJ 1 #define wxEXTEND_VERSION_MAJ 1
#define wxEXTEND_VERSION_MIN 1 #define wxEXTEND_VERSION_MIN 2
#define wxEXTEND_VERSION_REV 0 #define wxEXTEND_VERSION_REV 0
#define wxEXTEND_VERSION_BUILD 0 #define wxEXTEND_VERSION_BUILD 0
#define wxEXTEND_VERSION_STR "1.1" #define wxEXTEND_VERSION_STR "1.2"
#define wxEXTEND_BUILD_YEAR_STR "2016" #define wxEXTEND_BUILD_YEAR_STR "2016"
#define wxExtendVersion "11" #define wxExtendVersion "12"
#if !defined(RC_INVOKED) && !defined(MIDL_PASS) #if !defined(RC_INVOKED) && !defined(MIDL_PASS)

View File

@ -51,8 +51,14 @@ protected:
#endif #endif
wxString ToString(LongestValueType value) const; wxString ToString(LongestValueType value) const;
protected:
void DoSetWidth(unsigned int width) { m_width = width; }
private: private:
virtual bool IsCharOk(const wxString& val, int pos, wxChar ch) const; virtual bool IsCharOk(const wxString& val, int pos, wxChar ch) const;
private:
unsigned int m_width; ///< Preferred width of the string - zero padding (<=1 disables padding)
}; };
@ -65,8 +71,9 @@ class wxHexValidator : public wxPrivate::wxNumValidator<wxHexValidatorBase, T>
public: public:
typedef wxPrivate::wxNumValidator<wxHexValidatorBase, T> Base; typedef wxPrivate::wxNumValidator<wxHexValidatorBase, T> Base;
wxHexValidator(ValueType *value = NULL, int style = wxNUM_VAL_DEFAULT) : Base(value, style) wxHexValidator(ValueType *value = NULL, int style = wxNUM_VAL_DEFAULT, unsigned int width = 0) : Base(value, style)
{ {
this->DoSetWidth(width);
this->DoSetMin(std::numeric_limits<ValueType>::min()); this->DoSetMin(std::numeric_limits<ValueType>::min());
this->DoSetMax(std::numeric_limits<ValueType>::max()); this->DoSetMax(std::numeric_limits<ValueType>::max());
} }

View File

@ -24,12 +24,16 @@
// wxHexValidatorBase // wxHexValidatorBase
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
wxHexValidatorBase::wxHexValidatorBase(int style) : wxIntegerValidatorBase(style) wxHexValidatorBase::wxHexValidatorBase(int style) :
m_width(0),
wxIntegerValidatorBase(style)
{ {
} }
wxHexValidatorBase::wxHexValidatorBase(const wxHexValidatorBase& other) : wxIntegerValidatorBase(other) wxHexValidatorBase::wxHexValidatorBase(const wxHexValidatorBase& other) :
m_width(other.m_width),
wxIntegerValidatorBase(other)
{ {
} }
@ -59,13 +63,13 @@ bool wxHexValidatorBase::FromString(const wxString &s, wxLongLong_t *value)
wxString wxHexValidatorBase::ToString(LongestValueType value) const wxString wxHexValidatorBase::ToString(LongestValueType value) const
{ {
const wxStringCharType hexa = (HasFlag((wxNumValidatorStyle)wxNUM_VAL_HEX_LOWERCASE) ? wxT('a') : wxT('A')) - 0xa; const wxStringCharType hexa = (HasFlag((wxNumValidatorStyle)wxNUM_VAL_HEX_LOWERCASE) ? wxT('a') : wxT('A')) - 0xa;
int offset = sizeof(LongestValueType)*8 - 4; unsigned int offset = sizeof(LongestValueType)*8 - 4, offset_s = m_width*4 - 4;
wxULongLong_t m = ((wxULongLong_t)0xf) << offset; wxULongLong_t m = ((wxULongLong_t)0xf) << offset;
unsigned int x = 0; unsigned int x = 0;
// Skip leading zeros. // Skip leading zeros.
while (m && !x) { while (m && !x && offset >= offset_s) {
x = (int)((m & (wxULongLong_t)value) >> offset); x = (unsigned int)((m & (wxULongLong_t)value) >> offset);
m >>= 4, offset -= 4; m >>= 4, offset -= 4;
} }
@ -74,7 +78,7 @@ wxString wxHexValidatorBase::ToString(LongestValueType value) const
// Rest of the digits. // Rest of the digits.
while (m) { while (m) {
x = (int)((m & (wxULongLong_t)value) >> offset); x = (unsigned int)((m & (wxULongLong_t)value) >> offset);
m >>= 4, offset -= 4; m >>= 4, offset -= 4;
str += (wxStringCharType)((x < 0xa ? wxT('0') : hexa) + x); str += (wxStringCharType)((x < 0xa ? wxT('0') : hexa) + x);
} }