Simplify changing window styles in wxMSW code

Add wxMSWWinStyleUpdater and wxMSWWinExStyleUpdater helper classes which
allow writing code changing GWL_STYLE and GWL_EXSTYLE bits,
respectively, in a shorter and more clear way.

There should be no real changes in behaviour.
This commit is contained in:
Vadim Zeitlin
2017-12-09 23:47:05 +01:00
parent 588ae3744c
commit 17105cfd07
17 changed files with 206 additions and 131 deletions

View File

@@ -44,6 +44,7 @@
#include "wx/stockitem.h"
#include "wx/msw/private/button.h"
#include "wx/msw/private/dc.h"
#include "wx/msw/private/winstyle.h"
#include "wx/msw/uxtheme.h"
#include "wx/private/window.h"
@@ -387,15 +388,11 @@ void wxMSWButton::UpdateMultilineStyle(HWND hwnd, const wxString& label)
// have to set it whenever the label becomes multi line as otherwise it
// wouldn't be shown correctly as we don't use BS_MULTILINE when creating
// the control unless it already has new lines in its label)
long styleOld = ::GetWindowLong(hwnd, GWL_STYLE),
styleNew;
wxMSWWinStyleUpdater updateStyle(hwnd);
if ( label.find(wxT('\n')) != wxString::npos )
styleNew = styleOld | BS_MULTILINE;
updateStyle.TurnOn(BS_MULTILINE);
else
styleNew = styleOld & ~BS_MULTILINE;
if ( styleNew != styleOld )
::SetWindowLong(hwnd, GWL_STYLE, styleNew);
updateStyle.TurnOff(BS_MULTILINE);
}
wxSize wxMSWButton::GetFittingSize(wxWindow *win,
@@ -1177,11 +1174,7 @@ void wxAnyButton::MakeOwnerDrawn()
if ( !IsOwnerDrawn() )
{
// make it so
// note that BS_OWNERDRAW is not independent from other style bits
long style = GetWindowLong(GetHwnd(), GWL_STYLE);
style &= ~(BS_3STATE | BS_AUTO3STATE | BS_AUTOCHECKBOX | BS_AUTORADIOBUTTON | BS_CHECKBOX | BS_DEFPUSHBUTTON | BS_GROUPBOX | BS_PUSHBUTTON | BS_RADIOBUTTON | BS_PUSHLIKE);
style |= BS_OWNERDRAW;
SetWindowLong(GetHwnd(), GWL_STYLE, style);
wxMSWWinStyleUpdater(GetHwnd()).TurnOff(BS_TYPEMASK).TurnOn(BS_OWNERDRAW);
}
}