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:
@@ -60,7 +60,14 @@ public:
|
|||||||
RegClass_Default = 0,
|
RegClass_Default = 0,
|
||||||
|
|
||||||
// Return the name with the GetNoRedrawClassSuffix() appended to it.
|
// 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
|
// get the name of the registered Win32 class with the given (unique) base
|
||||||
|
@@ -106,10 +106,22 @@ extern void wxSetKeyboardHook(bool doIt);
|
|||||||
// see http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/110282
|
// see http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/110282
|
||||||
struct ClassRegInfo
|
struct ClassRegInfo
|
||||||
{
|
{
|
||||||
ClassRegInfo(const wxChar *name)
|
ClassRegInfo(const wxChar *name, int flags)
|
||||||
: regname(name),
|
|
||||||
regnameNR(regname + wxApp::GetNoRedrawClassSuffix())
|
|
||||||
{
|
{
|
||||||
|
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
|
// 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();
|
const size_t count = gs_regClassesInfo.size();
|
||||||
for ( size_t n = 0; n < count; n++ )
|
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);
|
return gs_regClassesInfo[n].GetRequestedName(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -658,13 +671,16 @@ const wxChar *wxApp::GetRegisteredClassName(const wxChar *name,
|
|||||||
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | extraStyles;
|
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | extraStyles;
|
||||||
|
|
||||||
|
|
||||||
ClassRegInfo regClass(name);
|
ClassRegInfo regClass(name, flags);
|
||||||
wndclass.lpszClassName = regClass.regname.t_str();
|
if ( !regClass.regname.empty() )
|
||||||
if ( !::RegisterClass(&wndclass) )
|
|
||||||
{
|
{
|
||||||
wxLogLastError(wxString::Format(wxT("RegisterClass(%s)"),
|
wndclass.lpszClassName = regClass.regname.t_str();
|
||||||
regClass.regname));
|
if ( !::RegisterClass(&wndclass) )
|
||||||
return NULL;
|
{
|
||||||
|
wxLogLastError(wxString::Format(wxT("RegisterClass(%s)"),
|
||||||
|
regClass.regname));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wndclass.style &= ~(CS_HREDRAW | CS_VREDRAW);
|
wndclass.style &= ~(CS_HREDRAW | CS_VREDRAW);
|
||||||
@@ -705,10 +721,13 @@ void wxApp::UnregisterWindowClasses()
|
|||||||
for ( size_t n = 0; n < count; n++ )
|
for ( size_t n = 0; n < count; n++ )
|
||||||
{
|
{
|
||||||
const ClassRegInfo& regClass = gs_regClassesInfo[n];
|
const ClassRegInfo& regClass = gs_regClassesInfo[n];
|
||||||
if ( !::UnregisterClass(regClass.regname.c_str(), wxGetInstance()) )
|
if ( !regClass.regname.empty() )
|
||||||
{
|
{
|
||||||
wxLogLastError(wxString::Format(wxT("UnregisterClass(%s)"),
|
if ( !::UnregisterClass(regClass.regname.c_str(), wxGetInstance()) )
|
||||||
regClass.regname));
|
{
|
||||||
|
wxLogLastError(wxString::Format(wxT("UnregisterClass(%s)"),
|
||||||
|
regClass.regname));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !::UnregisterClass(regClass.regnameNR.c_str(), wxGetInstance()) )
|
if ( !::UnregisterClass(regClass.regnameNR.c_str(), wxGetInstance()) )
|
||||||
|
Reference in New Issue
Block a user