Allow registering only a single window class in wxMSW

Add a flag to let wxApp::GetRegisteredClassName() register just a single Win32
class instead of always registering two of them: the "normal" (but rarely used)
version and the "NR" version used unless wxFULL_REPAINT_ON_RESIZE style is
specified.

With the new RegClass_OnlyNR, only the latter is registered and used.

This is not used yet, but will be soon.
This commit is contained in:
Vadim Zeitlin
2016-12-18 22:25:23 +01:00
parent 097f8a7f14
commit 842c441f01
2 changed files with 40 additions and 14 deletions

View File

@@ -60,7 +60,14 @@ public:
RegClass_Default = 0,
// Return the name with the GetNoRedrawClassSuffix() appended to it.
RegClass_ReturnNR = 1
RegClass_ReturnNR = 1,
// Don't register the class with CS_[HV]REDRAW styles. This is useful
// for internal windows for which we can guarantee that they will be
// never created with wxFULL_REPAINT_ON_RESIZE flag.
//
// Notice that this implies RegClass_ReturnNR.
RegClass_OnlyNR = 3
};
// get the name of the registered Win32 class with the given (unique) base

View File

@@ -106,10 +106,22 @@ extern void wxSetKeyboardHook(bool doIt);
// see http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/110282
struct ClassRegInfo
{
ClassRegInfo(const wxChar *name)
: regname(name),
regnameNR(regname + wxApp::GetNoRedrawClassSuffix())
ClassRegInfo(const wxChar *name, int flags)
{
if ( (flags & wxApp::RegClass_OnlyNR) == wxApp::RegClass_OnlyNR )
{
// We don't register the "normal" variant, so leave its name empty
// to indicate that it's not used and use the given name for the
// class that we do register: we don't need the "NR" suffix to
// distinguish it in this case as there is only a single variant.
regnameNR = name;
}
else // Register both normal and NR variants.
{
// Here we use a special suffix to make the class names unique.
regname = name;
regnameNR = regname + wxApp::GetNoRedrawClassSuffix();
}
}
// Return the appropriate string depending on the presence of
@@ -643,7 +655,8 @@ const wxChar *wxApp::GetRegisteredClassName(const wxChar *name,
const size_t count = gs_regClassesInfo.size();
for ( size_t n = 0; n < count; n++ )
{
if ( gs_regClassesInfo[n].regname == name )
if ( gs_regClassesInfo[n].regname == name ||
gs_regClassesInfo[n].regnameNR == name )
return gs_regClassesInfo[n].GetRequestedName(flags);
}
@@ -658,7 +671,9 @@ const wxChar *wxApp::GetRegisteredClassName(const wxChar *name,
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | extraStyles;
ClassRegInfo regClass(name);
ClassRegInfo regClass(name, flags);
if ( !regClass.regname.empty() )
{
wndclass.lpszClassName = regClass.regname.t_str();
if ( !::RegisterClass(&wndclass) )
{
@@ -666,6 +681,7 @@ const wxChar *wxApp::GetRegisteredClassName(const wxChar *name,
regClass.regname));
return NULL;
}
}
wndclass.style &= ~(CS_HREDRAW | CS_VREDRAW);
wndclass.lpszClassName = regClass.regnameNR.t_str();
@@ -705,11 +721,14 @@ void wxApp::UnregisterWindowClasses()
for ( size_t n = 0; n < count; n++ )
{
const ClassRegInfo& regClass = gs_regClassesInfo[n];
if ( !regClass.regname.empty() )
{
if ( !::UnregisterClass(regClass.regname.c_str(), wxGetInstance()) )
{
wxLogLastError(wxString::Format(wxT("UnregisterClass(%s)"),
regClass.regname));
}
}
if ( !::UnregisterClass(regClass.regnameNR.c_str(), wxGetInstance()) )
{