From 097f8a7f14c6a2d1c7fc4b4fd34daf2403fb8f63 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 18 Dec 2016 22:04:06 +0100 Subject: [PATCH] Refactor code finding the name of the windows class to use in wxMSW Determine which class name to use in MSWCreate() caller instead of doing it partly there and partly in MSWCreate() itself, which used to add the "NR" suffix if necessary -- now it doesn't do this any more and just really created the window using the given class. No real changes, just prepare for future enhancements. --- include/wx/msw/app.h | 13 ++++++++++++- include/wx/msw/window.h | 7 +++++-- src/msw/app.cpp | 14 +++++++++++--- src/msw/toplevel.cpp | 3 +-- src/msw/window.cpp | 28 ++++++++++++---------------- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/include/wx/msw/app.h b/include/wx/msw/app.h index 5d55406004..3476fceb25 100644 --- a/include/wx/msw/app.h +++ b/include/wx/msw/app.h @@ -53,6 +53,16 @@ public: // variant registered without CS_[HV]REDRAW styles static const wxChar *GetNoRedrawClassSuffix() { return wxT("NR"); } + // Flags for GetRegisteredClassName() + enum + { + // Just a symbolic name indicating absence of any special flags. + RegClass_Default = 0, + + // Return the name with the GetNoRedrawClassSuffix() appended to it. + RegClass_ReturnNR = 1 + }; + // get the name of the registered Win32 class with the given (unique) base // name: this function constructs the unique class name using this name as // prefix, checks if the class is already registered and registers it if it @@ -68,7 +78,8 @@ public: // or (default) -1 meaning that the class paints its background itself static const wxChar *GetRegisteredClassName(const wxChar *name, int bgBrushCol = -1, - int extraStyles = 0); + int extraStyles = 0, + int flags = RegClass_Default); // return true if this name corresponds to one of the classes we registered // in the previous GetRegisteredClassName() calls diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index 54d937b38b..3f61afbe27 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -230,8 +230,11 @@ public: // get the HWND to be used as parent of this window with CreateWindow() virtual WXHWND MSWGetParent() const; - // get the Win32 window class name used by all wxWindow objects by default - static const wxChar *MSWGetRegisteredClassName(); + // Return the name of the Win32 class that should be used by this wxWindow + // object, taking into account wxFULL_REPAINT_ON_RESIZE style (if it's not + // specified, the wxApp::GetNoRedrawClassSuffix()-suffixed version of the + // class is used). + const wxChar *GetMSWClassName() const; // creates the window of specified Windows class with given style, extended // style, title and geometry (default values diff --git a/src/msw/app.cpp b/src/msw/app.cpp index c8f49b8306..89a99758d0 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -112,6 +112,13 @@ struct ClassRegInfo { } + // Return the appropriate string depending on the presence of + // RegClass_ReturnNR bit in the flags. + const wxChar* GetRequestedName(int flags) const + { + return (flags & wxApp::RegClass_ReturnNR ? regnameNR : regname).t_str(); + } + // the name of the registered class with and without CS_[HV]REDRAW styles wxString regname; wxString regnameNR; @@ -630,13 +637,14 @@ bool wxApp::Initialize(int& argc_, wxChar **argv_) /* static */ const wxChar *wxApp::GetRegisteredClassName(const wxChar *name, int bgBrushCol, - int extraStyles) + int extraStyles, + int flags) { const size_t count = gs_regClassesInfo.size(); for ( size_t n = 0; n < count; n++ ) { if ( gs_regClassesInfo[n].regname == name ) - return gs_regClassesInfo[n].regname.c_str(); + return gs_regClassesInfo[n].GetRequestedName(flags); } // we need to register this class @@ -675,7 +683,7 @@ const wxChar *wxApp::GetRegisteredClassName(const wxChar *name, // function returns (it could be invalidated later if new elements are // added to the vector and it's reallocated but this shouldn't matter as // this pointer should be used right now, not stored) - return gs_regClassesInfo.back().regname.t_str(); + return gs_regClassesInfo.back().GetRequestedName(flags); } bool wxApp::IsRegisteredClassName(const wxString& name) diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index c9576fb9f1..a9a331a184 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -407,8 +407,7 @@ bool wxTopLevelWindowMSW::CreateFrame(const wxString& title, if ( wxApp::MSWGetDefaultLayout(m_parent) == wxLayout_RightToLeft ) exflags |= WS_EX_LAYOUTRTL; - return MSWCreate(MSWGetRegisteredClassName(), - title.t_str(), pos, sz, flags, exflags); + return MSWCreate(GetMSWClassName(), title.t_str(), pos, sz, flags, exflags); } bool wxTopLevelWindowMSW::Create(wxWindow *parent, diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 17085898c4..7ba7d80eec 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -468,10 +468,16 @@ wxWindowMSW::~wxWindowMSW() } -/* static */ -const wxChar *wxWindowMSW::MSWGetRegisteredClassName() +const wxChar *wxWindowMSW::GetMSWClassName() const { - return wxApp::GetRegisteredClassName(wxT("wxWindow"), COLOR_BTNFACE); + return wxApp::GetRegisteredClassName + ( + wxT("wxWindow"), + COLOR_BTNFACE, + 0, // no special extra style + HasFlag(wxFULL_REPAINT_ON_RESIZE) ? wxApp::RegClass_Default + : wxApp::RegClass_ReturnNR + ); } // real construction (Init() must have been called before!) @@ -506,8 +512,7 @@ bool wxWindowMSW::Create(wxWindow *parent, msflags |= WS_VISIBLE; } - if ( !MSWCreate(MSWGetRegisteredClassName(), - NULL, pos, size, msflags, exstyle) ) + if ( !MSWCreate(GetMSWClassName(), NULL, pos, size, msflags, exstyle) ) return false; InheritAttributes(); @@ -3695,22 +3700,13 @@ bool wxWindowMSW::MSWCreate(const wxChar *wclass, // unless we're creating a child window int controlId = style & WS_CHILD ? GetId() : 0; - // for each class "Foo" we have we also have "FooNR" ("no repaint") class - // which is the same but without CS_[HV]REDRAW class styles so using it - // ensures that the window is not fully repainted on each resize - wxString className(wclass); - if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) ) - { - className += wxApp::GetNoRedrawClassSuffix(); - } - // do create the window wxWindowCreationHook hook(this); m_hWnd = (WXHWND)::CreateWindowEx ( extendedStyle, - className.t_str(), + wclass, title ? title : m_windowName.t_str(), style, x, y, w, h, @@ -3722,7 +3718,7 @@ bool wxWindowMSW::MSWCreate(const wxChar *wclass, if ( !m_hWnd ) { - wxLogSysError(_("Can't create window of class %s"), className.c_str()); + wxLogSysError(_("Can't create window of class %s"), wclass); return false; }