From 842c441f01cc39e394fac7445f00a9de56b3b320 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 18 Dec 2016 22:25:23 +0100 Subject: [PATCH] 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. --- include/wx/msw/app.h | 9 ++++++++- src/msw/app.cpp | 45 +++++++++++++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/include/wx/msw/app.h b/include/wx/msw/app.h index 3476fceb25..8ac49eb5fa 100644 --- a/include/wx/msw/app.h +++ b/include/wx/msw/app.h @@ -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 diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 89a99758d0..910a96979e 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -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,13 +671,16 @@ const wxChar *wxApp::GetRegisteredClassName(const wxChar *name, wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | extraStyles; - ClassRegInfo regClass(name); - wndclass.lpszClassName = regClass.regname.t_str(); - if ( !::RegisterClass(&wndclass) ) + ClassRegInfo regClass(name, flags); + if ( !regClass.regname.empty() ) { - wxLogLastError(wxString::Format(wxT("RegisterClass(%s)"), - regClass.regname)); - return NULL; + wndclass.lpszClassName = regClass.regname.t_str(); + if ( !::RegisterClass(&wndclass) ) + { + wxLogLastError(wxString::Format(wxT("RegisterClass(%s)"), + regClass.regname)); + return NULL; + } } wndclass.style &= ~(CS_HREDRAW | CS_VREDRAW); @@ -705,10 +721,13 @@ void wxApp::UnregisterWindowClasses() for ( size_t n = 0; n < count; n++ ) { const ClassRegInfo& regClass = gs_regClassesInfo[n]; - if ( !::UnregisterClass(regClass.regname.c_str(), wxGetInstance()) ) + if ( !regClass.regname.empty() ) { - wxLogLastError(wxString::Format(wxT("UnregisterClass(%s)"), - regClass.regname)); + if ( !::UnregisterClass(regClass.regname.c_str(), wxGetInstance()) ) + { + wxLogLastError(wxString::Format(wxT("UnregisterClass(%s)"), + regClass.regname)); + } } if ( !::UnregisterClass(regClass.regnameNR.c_str(), wxGetInstance()) )