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

@@ -978,19 +978,9 @@ inline bool wxStyleHasBorder(long style)
wxSUNKEN_BORDER | wxDOUBLE_BORDER)) != 0; wxSUNKEN_BORDER | wxDOUBLE_BORDER)) != 0;
} }
inline long wxGetWindowExStyle(const wxWindowMSW *win)
{
return ::GetWindowLong(GetHwndOf(win), GWL_EXSTYLE);
}
inline bool wxHasWindowExStyle(const wxWindowMSW *win, long style) inline bool wxHasWindowExStyle(const wxWindowMSW *win, long style)
{ {
return (wxGetWindowExStyle(win) & style) != 0; return (::GetWindowLong(GetHwndOf(win), GWL_EXSTYLE) & style) != 0;
}
inline long wxSetWindowExStyle(const wxWindowMSW *win, long style)
{
return ::SetWindowLong(GetHwndOf(win), GWL_EXSTYLE, style);
} }
// Common helper of wxUpdate{,Edit}LayoutDirection() below: sets or clears the // Common helper of wxUpdate{,Edit}LayoutDirection() below: sets or clears the

View File

@@ -0,0 +1,134 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/private/winstyle.h
// Purpose: Small helper class for updating MSW windows style
// Author: Vadim Zeitlin
// Created: 2017-12-09
// Copyright: (c) 2017 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MSW_PRIVATE_WINSTYLE_H_
#define _WX_MSW_PRIVATE_WINSTYLE_H_
// ----------------------------------------------------------------------------
// wxMSWWinLongUpdater
// ----------------------------------------------------------------------------
/*
This class is not used directly, but either as wxMSWWinStyleUpdater or
wxMSWWinExStyleUpdater, both of which inherit from it and can be used like
this:
void SomeFunction()
{
wxMSWWinStyleUpdater updateStyle(GetHwndOf(m_win));
if ( some-condition )
updateStyle.TurnOn(XX_YYY);
// Style update happens here implicitly -- or call Apply().
}
*/
class wxMSWWinLongUpdater
{
public:
// Get the current style.
LONG_PTR Get() const
{
return m_styleCurrent;
}
// Check if the given style bit(s) is (are all) currently turned on.
bool IsOn(LONG_PTR style) const
{
return (m_styleCurrent & style) == style;
}
// Turn on some bit(s) in the style.
wxMSWWinLongUpdater& TurnOn(LONG_PTR on)
{
m_style |= on;
return *this;
}
// Turn off some bit(s) in the style.
wxMSWWinLongUpdater& TurnOff(LONG_PTR off)
{
m_style &= ~off;
return *this;
}
// Turn some bit(s) on or off depending on the condition.
wxMSWWinLongUpdater& TurnOnOrOff(bool cond, LONG_PTR style)
{
return cond ? TurnOn(style) : TurnOff(style);
}
// Perform the style update (only if necessary, i.e. if the style really
// changed).
//
// Notice that if this method is not called, it's still done from the dtor,
// so it's just a convenient way to do it sooner and avoid having to create
// a new scope for ensuring that the dtor runs at the right place, but
// otherwise is equivalent to do this.
bool Apply()
{
if ( m_style == m_styleCurrent )
return false;
::SetWindowLongPtr(m_hwnd, m_gwlSlot, m_style);
m_styleCurrent = m_style;
return true;
}
~wxMSWWinLongUpdater()
{
Apply();
}
protected:
// Create the object for updating the style or extended style of the given
// window.
//
// Ctor is protected, this class can only be used as wxMSWWinStyleUpdater
// or wxMSWWinExStyleUpdater.
wxMSWWinLongUpdater(HWND hwnd, int gwlSlot)
: m_hwnd(hwnd),
m_gwlSlot(gwlSlot),
m_styleCurrent(::GetWindowLongPtr(hwnd, gwlSlot)),
m_style(m_styleCurrent)
{
}
private:
const HWND m_hwnd;
const int m_gwlSlot;
LONG_PTR m_styleCurrent;
LONG_PTR m_style;
wxDECLARE_NO_COPY_CLASS(wxMSWWinLongUpdater);
};
// A variant of wxMSWWinLongUpdater which updates the extended style.
class wxMSWWinStyleUpdater : public wxMSWWinLongUpdater
{
public:
explicit wxMSWWinStyleUpdater(HWND hwnd)
: wxMSWWinLongUpdater(hwnd, GWL_STYLE)
{
}
};
// A variant of wxMSWWinLongUpdater which updates the extended style.
class wxMSWWinExStyleUpdater : public wxMSWWinLongUpdater
{
public:
explicit wxMSWWinExStyleUpdater(HWND hwnd)
: wxMSWWinLongUpdater(hwnd, GWL_EXSTYLE)
{
}
};
#endif // _WX_MSW_PRIVATE_WINSTYLE_H_

View File

@@ -44,6 +44,7 @@
#include "wx/stockitem.h" #include "wx/stockitem.h"
#include "wx/msw/private/button.h" #include "wx/msw/private/button.h"
#include "wx/msw/private/dc.h" #include "wx/msw/private/dc.h"
#include "wx/msw/private/winstyle.h"
#include "wx/msw/uxtheme.h" #include "wx/msw/uxtheme.h"
#include "wx/private/window.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 // 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 // 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) // the control unless it already has new lines in its label)
long styleOld = ::GetWindowLong(hwnd, GWL_STYLE), wxMSWWinStyleUpdater updateStyle(hwnd);
styleNew;
if ( label.find(wxT('\n')) != wxString::npos ) if ( label.find(wxT('\n')) != wxString::npos )
styleNew = styleOld | BS_MULTILINE; updateStyle.TurnOn(BS_MULTILINE);
else else
styleNew = styleOld & ~BS_MULTILINE; updateStyle.TurnOff(BS_MULTILINE);
if ( styleNew != styleOld )
::SetWindowLong(hwnd, GWL_STYLE, styleNew);
} }
wxSize wxMSWButton::GetFittingSize(wxWindow *win, wxSize wxMSWButton::GetFittingSize(wxWindow *win,
@@ -1177,11 +1174,7 @@ void wxAnyButton::MakeOwnerDrawn()
if ( !IsOwnerDrawn() ) if ( !IsOwnerDrawn() )
{ {
// make it so // make it so
// note that BS_OWNERDRAW is not independent from other style bits wxMSWWinStyleUpdater(GetHwnd()).TurnOff(BS_TYPEMASK).TurnOn(BS_OWNERDRAW);
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);
} }
} }

View File

@@ -40,6 +40,7 @@
#include "wx/clipbrd.h" #include "wx/clipbrd.h"
#include "wx/wupdlock.h" #include "wx/wupdlock.h"
#include "wx/msw/private.h" #include "wx/msw/private.h"
#include "wx/msw/private/winstyle.h"
#if wxUSE_UXTHEME #if wxUSE_UXTHEME
#include "wx/msw/uxtheme.h" #include "wx/msw/uxtheme.h"
@@ -711,11 +712,10 @@ void wxComboBox::SetLayoutDirection(wxLayoutDirection dir)
} }
else else
{ {
LONG_PTR style = ::GetWindowLongPtr(GetEditHWND(), GWL_STYLE); wxMSWWinStyleUpdater styleUpdater(GetEditHWND());
if ( !(style & ES_CENTER) ) if ( !styleUpdater.IsOn(ES_CENTER) )
{ {
style &= ~ES_RIGHT; styleUpdater.TurnOff(ES_RIGHT);
::SetWindowLongPtr(GetEditHWND(), GWL_STYLE, style);
} }
} }
} }

View File

@@ -51,6 +51,7 @@
#include "wx/msw/uxtheme.h" #include "wx/msw/uxtheme.h"
#include "wx/msw/dc.h" // for wxDCTemp #include "wx/msw/dc.h" // for wxDCTemp
#include "wx/msw/ownerdrawnbutton.h" #include "wx/msw/ownerdrawnbutton.h"
#include "wx/msw/private/winstyle.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxWin macros // wxWin macros
@@ -421,14 +422,13 @@ bool wxMSWOwnerDrawnButtonBase::MSWIsOwnerDrawn() const
void wxMSWOwnerDrawnButtonBase::MSWMakeOwnerDrawn(bool ownerDrawn) void wxMSWOwnerDrawnButtonBase::MSWMakeOwnerDrawn(bool ownerDrawn)
{ {
long style = ::GetWindowLong(GetHwndOf(m_win), GWL_STYLE); wxMSWWinStyleUpdater updateStyle(GetHwndOf(m_win));
// note that BS_CHECKBOX & BS_OWNERDRAW != 0 so we can't operate on // note that BS_CHECKBOX & BS_OWNERDRAW != 0 so we can't operate on
// them as on independent style bits // them as on independent style bits
if ( ownerDrawn ) if ( ownerDrawn )
{ {
style &= ~BS_TYPEMASK; updateStyle.TurnOff(BS_TYPEMASK).TurnOn(BS_OWNERDRAW);
style |= BS_OWNERDRAW;
m_win->Bind(wxEVT_ENTER_WINDOW, m_win->Bind(wxEVT_ENTER_WINDOW,
&wxMSWOwnerDrawnButtonBase::OnMouseEnterOrLeave, this); &wxMSWOwnerDrawnButtonBase::OnMouseEnterOrLeave, this);
@@ -448,8 +448,7 @@ void wxMSWOwnerDrawnButtonBase::MSWMakeOwnerDrawn(bool ownerDrawn)
} }
else // reset to default colour else // reset to default colour
{ {
style &= ~BS_OWNERDRAW; updateStyle.TurnOff(BS_OWNERDRAW).TurnOn(MSWGetButtonStyle());
style |= MSWGetButtonStyle();
m_win->Unbind(wxEVT_ENTER_WINDOW, m_win->Unbind(wxEVT_ENTER_WINDOW,
&wxMSWOwnerDrawnButtonBase::OnMouseEnterOrLeave, this); &wxMSWOwnerDrawnButtonBase::OnMouseEnterOrLeave, this);
@@ -467,7 +466,7 @@ void wxMSWOwnerDrawnButtonBase::MSWMakeOwnerDrawn(bool ownerDrawn)
&wxMSWOwnerDrawnButtonBase::OnFocus, this); &wxMSWOwnerDrawnButtonBase::OnFocus, this);
} }
::SetWindowLong(GetHwndOf(m_win), GWL_STYLE, style); updateStyle.Apply();
if ( !ownerDrawn ) if ( !ownerDrawn )
MSWOnButtonResetOwnerDrawn(); MSWOnButtonResetOwnerDrawn();

View File

@@ -35,6 +35,7 @@
#include "wx/appprogress.h" #include "wx/appprogress.h"
#include "wx/msw/private.h" #include "wx/msw/private.h"
#include "wx/msw/private/winstyle.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// constants // constants
@@ -190,8 +191,7 @@ void wxGauge::SetIndeterminateMode()
// Switch the control into indeterminate mode if necessary. // Switch the control into indeterminate mode if necessary.
if ( !IsInIndeterminateMode() ) if ( !IsInIndeterminateMode() )
{ {
const long style = ::GetWindowLong(GetHwnd(), GWL_STYLE); wxMSWWinStyleUpdater(GetHwnd()).TurnOn(PBS_MARQUEE);
::SetWindowLong(GetHwnd(), GWL_STYLE, style | PBS_MARQUEE);
::SendMessage(GetHwnd(), PBM_SETMARQUEE, TRUE, 0); ::SendMessage(GetHwnd(), PBM_SETMARQUEE, TRUE, 0);
} }
} }
@@ -200,9 +200,8 @@ void wxGauge::SetDeterminateMode()
{ {
if ( IsInIndeterminateMode() ) if ( IsInIndeterminateMode() )
{ {
const long style = ::GetWindowLong(GetHwnd(), GWL_STYLE);
::SendMessage(GetHwnd(), PBM_SETMARQUEE, FALSE, 0); ::SendMessage(GetHwnd(), PBM_SETMARQUEE, FALSE, 0);
::SetWindowLong(GetHwnd(), GWL_STYLE, style & ~PBS_MARQUEE); wxMSWWinStyleUpdater(GetHwnd()).TurnOff(PBS_MARQUEE);
} }
} }

View File

@@ -38,6 +38,7 @@
#include "wx/msw/wrapcctl.h" #include "wx/msw/wrapcctl.h"
#include "wx/msw/private.h" #include "wx/msw/private.h"
#include "wx/msw/private/customdraw.h" #include "wx/msw/private/customdraw.h"
#include "wx/msw/private/winstyle.h"
#ifndef HDM_SETBITMAPMARGIN #ifndef HDM_SETBITMAPMARGIN
#define HDM_SETBITMAPMARGIN 0x1234 #define HDM_SETBITMAPMARGIN 0x1234
@@ -402,12 +403,8 @@ void wxHeaderCtrl::DoInsertItem(const wxHeaderColumn& col, unsigned int idx)
} }
} }
long controlStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE); wxMSWWinStyleUpdater(GetHwnd())
if ( hasResizableColumns ) .TurnOnOrOff(!hasResizableColumns, HDS_NOSIZING);
controlStyle &= ~HDS_NOSIZING;
else
controlStyle |= HDS_NOSIZING;
::SetWindowLong(GetHwnd(), GWL_STYLE, controlStyle);
} }
void wxHeaderCtrl::DoSetColumnsOrder(const wxArrayInt& order) void wxHeaderCtrl::DoSetColumnsOrder(const wxArrayInt& order)

View File

@@ -44,6 +44,7 @@
#include "wx/stockitem.h" #include "wx/stockitem.h"
#include "wx/msw/private.h" #include "wx/msw/private.h"
#include "wx/msw/private/winstyle.h"
#include <string.h> #include <string.h>
@@ -1313,24 +1314,20 @@ bool wxMDIChildFrame::ResetWindowStyle(void *vrect)
if (!pChild || (pChild == this)) if (!pChild || (pChild == this))
{ {
HWND hwndClient = GetWinHwnd(pFrameWnd->GetClientWindow()); HWND hwndClient = GetWinHwnd(pFrameWnd->GetClientWindow());
DWORD dwStyle = ::GetWindowLong(hwndClient, GWL_EXSTYLE);
wxMSWWinStyleUpdater updateStyle(hwndClient);
// we want to test whether there is a maximized child, so just set // we want to test whether there is a maximized child, so just set
// dwThisStyle to 0 if there is no child at all // dwThisStyle to 0 if there is no child at all
DWORD dwThisStyle = pChild DWORD dwThisStyle = pChild
? ::GetWindowLong(GetWinHwnd(pChild), GWL_STYLE) : 0; ? ::GetWindowLong(GetWinHwnd(pChild), GWL_STYLE) : 0;
DWORD dwNewStyle = dwStyle; updateStyle.TurnOnOrOff(!(dwThisStyle & WS_MAXIMIZE), WS_EX_CLIENTEDGE);
if ( dwThisStyle & WS_MAXIMIZE )
dwNewStyle &= ~(WS_EX_CLIENTEDGE);
else
dwNewStyle |= WS_EX_CLIENTEDGE;
if (dwStyle != dwNewStyle) if ( updateStyle.Apply() )
{ {
// force update of everything // force update of everything
::RedrawWindow(hwndClient, NULL, NULL, ::RedrawWindow(hwndClient, NULL, NULL,
RDW_INVALIDATE | RDW_ALLCHILDREN); RDW_INVALIDATE | RDW_ALLCHILDREN);
::SetWindowLong(hwndClient, GWL_EXSTYLE, dwNewStyle);
::SetWindowPos(hwndClient, NULL, 0, 0, 0, 0, ::SetWindowPos(hwndClient, NULL, 0, 0, 0, 0,
SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_NOACTIVATE |
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |

View File

@@ -36,6 +36,7 @@
#endif #endif
#include "wx/msw/private.h" #include "wx/msw/private.h"
#include "wx/msw/private/winstyle.h"
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
#include "wx/tooltip.h" #include "wx/tooltip.h"
@@ -549,15 +550,8 @@ void wxSpinCtrl::UpdateBuddyStyle()
// otherwise this would become impossible and also if we don't use // otherwise this would become impossible and also if we don't use
// hexadecimal as entering "x" of the "0x" prefix wouldn't be allowed // hexadecimal as entering "x" of the "0x" prefix wouldn't be allowed
// neither then // neither then
const DWORD styleOld = ::GetWindowLong(GetBuddyHwnd(), GWL_STYLE); wxMSWWinStyleUpdater(GetBuddyHwnd())
DWORD styleNew; .TurnOnOrOff(m_min >= 0 && GetBase() == 10, ES_NUMBER);
if ( m_min < 0 || GetBase() != 10 )
styleNew = styleOld & ~ES_NUMBER;
else
styleNew = styleOld | ES_NUMBER;
if ( styleNew != styleOld )
::SetWindowLong(GetBuddyHwnd(), GWL_STYLE, styleNew);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -36,6 +36,7 @@
#include "wx/msw/private.h" #include "wx/msw/private.h"
#include "wx/msw/dib.h" #include "wx/msw/dib.h"
#include "wx/msw/private/winstyle.h"
#include "wx/sysopt.h" #include "wx/sysopt.h"
@@ -312,9 +313,9 @@ void wxStaticBitmap::SetImageNoCopy( wxGDIImage* image)
} }
} }
#endif // wxUSE_WXDIB #endif // wxUSE_WXDIB
LONG style = ::GetWindowLong( (HWND)GetHWND(), GWL_STYLE ) ; wxMSWWinStyleUpdater(GetHwnd())
::SetWindowLong( (HWND)GetHWND(), GWL_STYLE, ( style & ~( SS_BITMAP|SS_ICON ) ) | .TurnOff(SS_BITMAP | SS_ICON)
( m_isIcon ? SS_ICON : SS_BITMAP ) ); .TurnOn(m_isIcon ? SS_ICON : SS_BITMAP);
MSWReplaceImageHandle((WXLPARAM)handle); MSWReplaceImageHandle((WXLPARAM)handle);

View File

@@ -45,6 +45,7 @@
#include "wx/msw/private.h" #include "wx/msw/private.h"
#include "wx/msw/missing.h" #include "wx/msw/missing.h"
#include "wx/msw/dc.h" #include "wx/msw/dc.h"
#include "wx/msw/private/winstyle.h"
// the values coincide with those in tmschema.h // the values coincide with those in tmschema.h
#define BP_GROUPBOX 4 #define BP_GROUPBOX 4
@@ -303,10 +304,10 @@ WXHRGN wxStaticBox::MSWGetRegionWithoutChildren()
continue; continue;
} }
LONG style = ::GetWindowLong(child, GWL_STYLE); wxMSWWinStyleUpdater updateStyle(child);
wxString str(wxGetWindowClass(child)); wxString str(wxGetWindowClass(child));
str.UpperCase(); str.UpperCase();
if ( str == wxT("BUTTON") && (style & BS_GROUPBOX) == BS_GROUPBOX ) if ( str == wxT("BUTTON") && updateStyle.IsOn(BS_GROUPBOX) )
{ {
if ( child == GetHwnd() ) if ( child == GetHwnd() )
foundThis = true; foundThis = true;
@@ -329,10 +330,9 @@ WXHRGN wxStaticBox::MSWGetRegionWithoutChildren()
{ {
// need to remove WS_CLIPSIBLINGS from all sibling windows // need to remove WS_CLIPSIBLINGS from all sibling windows
// that are within this staticbox if set // that are within this staticbox if set
if ( style & WS_CLIPSIBLINGS ) if ( updateStyle.IsOn(WS_CLIPSIBLINGS) )
{ {
style &= ~WS_CLIPSIBLINGS; updateStyle.TurnOff(WS_CLIPSIBLINGS).Apply();
::SetWindowLong(child, GWL_STYLE, style);
// MSDN: "If you have changed certain window data using // MSDN: "If you have changed certain window data using
// SetWindowLong, you must call SetWindowPos to have the // SetWindowLong, you must call SetWindowPos to have the

View File

@@ -28,6 +28,7 @@
#endif #endif
#include "wx/msw/private.h" #include "wx/msw/private.h"
#include "wx/msw/private/winstyle.h"
bool wxStaticText::Create(wxWindow *parent, bool wxStaticText::Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
@@ -155,25 +156,21 @@ void wxStaticText::SetLabel(const wxString& label)
return; return;
#ifdef SS_ENDELLIPSIS #ifdef SS_ENDELLIPSIS
long styleReal = ::GetWindowLong(GetHwnd(), GWL_STYLE); wxMSWWinStyleUpdater updateStyle(GetHwnd());
if ( HasFlag(wxST_ELLIPSIZE_END) ) if ( HasFlag(wxST_ELLIPSIZE_END) )
{ {
// adding SS_ENDELLIPSIS or SS_ENDELLIPSIS "disables" the correct // adding SS_ENDELLIPSIS or SS_ENDELLIPSIS "disables" the correct
// newline handling in static texts: the newlines in the labels are // newline handling in static texts: the newlines in the labels are
// shown as square. Thus we don't use it even on newer OS when // shown as square. Thus we don't use it even on newer OS when
// the static label contains a newline. // the static label contains a newline.
if ( label.Contains(wxT('\n')) ) updateStyle.TurnOnOrOff(!label.Contains(wxT('\n')), SS_ENDELLIPSIS);
styleReal &= ~SS_ENDELLIPSIS;
else
styleReal |= SS_ENDELLIPSIS;
::SetWindowLong(GetHwnd(), GWL_STYLE, styleReal);
} }
else // style not supported natively else // style not supported natively
{ {
styleReal &= ~SS_ENDELLIPSIS; updateStyle.TurnOff(SS_ENDELLIPSIS);
::SetWindowLong(GetHwnd(), GWL_STYLE, styleReal);
} }
updateStyle.Apply();
#endif // SS_ENDELLIPSIS #endif // SS_ENDELLIPSIS
// save the label in m_labelOrig with both the markup (if any) and // save the label in m_labelOrig with both the markup (if any) and
@@ -181,7 +178,7 @@ void wxStaticText::SetLabel(const wxString& label)
m_labelOrig = label; m_labelOrig = label;
#ifdef SS_ENDELLIPSIS #ifdef SS_ENDELLIPSIS
if ( styleReal & SS_ENDELLIPSIS ) if ( updateStyle.IsOn(SS_ENDELLIPSIS) )
DoSetLabel(GetLabel()); DoSetLabel(GetLabel());
else else
#endif // SS_ENDELLIPSIS #endif // SS_ENDELLIPSIS

View File

@@ -34,6 +34,7 @@
#include "wx/dynlib.h" #include "wx/dynlib.h"
#include "wx/msw/private.h" #include "wx/msw/private.h"
#include "wx/msw/private/winstyle.h"
#if wxUSE_UXTHEME #if wxUSE_UXTHEME
#include "wx/msw/uxtheme.h" #include "wx/msw/uxtheme.h"
@@ -913,9 +914,7 @@ void wxTextEntry::ForceUpper()
{ {
ConvertToUpperCase(); ConvertToUpperCase();
const HWND hwnd = GetEditHwnd(); wxMSWWinStyleUpdater(GetEditHwnd()).TurnOn(ES_UPPERCASE);
const LONG styleOld = ::GetWindowLong(hwnd, GWL_STYLE);
::SetWindowLong(hwnd, GWL_STYLE, styleOld | ES_UPPERCASE);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -41,6 +41,7 @@
#include "wx/tooltip.h" #include "wx/tooltip.h"
#include "wx/msw/private.h" #include "wx/msw/private.h"
#include "wx/msw/private/winstyle.h"
#include "wx/msw/winundef.h" #include "wx/msw/winundef.h"
#include "wx/msw/missing.h" #include "wx/msw/missing.h"
@@ -858,14 +859,14 @@ bool wxTopLevelWindowMSW::ShowFullScreen(bool show, long style)
// zap the frame borders // zap the frame borders
// save the 'normal' window style // save the 'normal' window style
m_fsOldWindowStyle = GetWindowLong(GetHwnd(), GWL_STYLE); wxMSWWinStyleUpdater updateStyle(GetHwnd());
m_fsOldWindowStyle = updateStyle.Get();
// save the old position, width & height, maximize state // save the old position, width & height, maximize state
m_fsOldSize = GetRect(); m_fsOldSize = GetRect();
m_fsIsMaximized = IsMaximized(); m_fsIsMaximized = IsMaximized();
// decide which window style flags to turn off // decide which window style flags to turn off
LONG newStyle = m_fsOldWindowStyle;
LONG offFlags = 0; LONG offFlags = 0;
if (style & wxFULLSCREEN_NOBORDER) if (style & wxFULLSCREEN_NOBORDER)
@@ -876,16 +877,16 @@ bool wxTopLevelWindowMSW::ShowFullScreen(bool show, long style)
if (style & wxFULLSCREEN_NOCAPTION) if (style & wxFULLSCREEN_NOCAPTION)
offFlags |= WS_CAPTION | WS_SYSMENU; offFlags |= WS_CAPTION | WS_SYSMENU;
newStyle &= ~offFlags; updateStyle.TurnOff(offFlags);
// Full screen windows should logically be popups as they don't have // Full screen windows should logically be popups as they don't have
// decorations (and are definitely not children) and while not using // decorations (and are definitely not children) and while not using
// this style doesn't seem to make any difference for most windows, it // this style doesn't seem to make any difference for most windows, it
// breaks wxGLCanvas in some cases, see #15434, so just always use it. // breaks wxGLCanvas in some cases, see #15434, so just always use it.
newStyle |= WS_POPUP; updateStyle.TurnOn(WS_POPUP);
// change our window style to be compatible with full-screen mode // change our window style to be compatible with full-screen mode
::SetWindowLong(GetHwnd(), GWL_STYLE, newStyle); updateStyle.Apply();
wxRect rect; wxRect rect;
#if wxUSE_DISPLAY #if wxUSE_DISPLAY
@@ -1137,19 +1138,18 @@ wxMenu *wxTopLevelWindowMSW::MSWGetSystemMenu() const
bool wxTopLevelWindowMSW::SetTransparent(wxByte alpha) bool wxTopLevelWindowMSW::SetTransparent(wxByte alpha)
{ {
LONG exstyle = GetWindowLong(GetHwnd(), GWL_EXSTYLE); wxMSWWinExStyleUpdater updateExStyle(GetHwnd());
// if setting alpha to fully opaque then turn off the layered style // if setting alpha to fully opaque then turn off the layered style
if (alpha == 255) if (alpha == 255)
{ {
SetWindowLong(GetHwnd(), GWL_EXSTYLE, exstyle & ~WS_EX_LAYERED); updateExStyle.TurnOff(WS_EX_LAYERED).Apply();
Refresh(); Refresh();
return true; return true;
} }
// Otherwise, set the layered style if needed and set the alpha value // Otherwise, set the layered style if needed and set the alpha value
if ((exstyle & WS_EX_LAYERED) == 0 ) updateExStyle.TurnOn(WS_EX_LAYERED).Apply();
SetWindowLong(GetHwnd(), GWL_EXSTYLE, exstyle | WS_EX_LAYERED);
if ( ::SetLayeredWindowAttributes(GetHwnd(), 0, (BYTE)alpha, LWA_ALPHA) ) if ( ::SetLayeredWindowAttributes(GetHwnd(), 0, (BYTE)alpha, LWA_ALPHA) )
return true; return true;

View File

@@ -40,6 +40,7 @@
#include "wx/msw/private.h" #include "wx/msw/private.h"
#include "wx/msw/winundef.h" #include "wx/msw/winundef.h"
#include "wx/msw/private/winstyle.h"
#include "wx/imaglist.h" #include "wx/imaglist.h"
#include "wx/itemattr.h" #include "wx/itemattr.h"
@@ -3904,15 +3905,13 @@ void wxTreeCtrl::DoFreeze()
// In addition to disabling redrawing, we also need to disable scrollbar // In addition to disabling redrawing, we also need to disable scrollbar
// updates that would still happen otherwise. // updates that would still happen otherwise.
const LONG_PTR styleOld = ::GetWindowLongPtr(GetHwnd(), GWL_STYLE); wxMSWWinStyleUpdater(GetHwnd()).TurnOn(TVS_NOSCROLL);
::SetWindowLongPtr(GetHwnd(), GWL_STYLE, styleOld | TVS_NOSCROLL);
} }
void wxTreeCtrl::DoThaw() void wxTreeCtrl::DoThaw()
{ {
// Undo temporary TVS_NOSCROLL addition. // Undo temporary TVS_NOSCROLL addition.
const LONG_PTR styleOld = ::GetWindowLongPtr(GetHwnd(), GWL_STYLE); wxMSWWinStyleUpdater(GetHwnd()).TurnOff(TVS_NOSCROLL);
::SetWindowLongPtr(GetHwnd(), GWL_STYLE, styleOld & ~TVS_NOSCROLL);
wxTreeCtrlBase::DoThaw(); wxTreeCtrlBase::DoThaw();
} }

View File

@@ -79,6 +79,7 @@
#include "wx/msw/private.h" #include "wx/msw/private.h"
#include "wx/msw/private/keyboard.h" #include "wx/msw/private/keyboard.h"
#include "wx/msw/private/winstyle.h"
#include "wx/msw/dcclient.h" #include "wx/msw/dcclient.h"
#include "wx/msw/seh.h" #include "wx/msw/seh.h"
#include "wx/private/textmeasure.h" #include "wx/private/textmeasure.h"
@@ -341,12 +342,8 @@ static void EnsureParentHasControlParentStyle(wxWindow *parent)
*/ */
while ( parent && !parent->IsTopLevel() ) while ( parent && !parent->IsTopLevel() )
{ {
LONG exStyle = wxGetWindowExStyle(parent); // force the parent to have this style
if ( !(exStyle & WS_EX_CONTROLPARENT) ) wxMSWWinExStyleUpdater(GetHwndOf(parent)).TurnOn(WS_EX_CONTROLPARENT);
{
// force the parent to have this style
wxSetWindowExStyle(parent, exStyle | WS_EX_CONTROLPARENT);
}
parent = parent->GetParent(); parent = parent->GetParent();
} }
@@ -1406,11 +1403,8 @@ void wxWindowMSW::MSWUpdateStyle(long flagsOld, long exflagsOld)
// this function so instead of simply setting the style to the new // this function so instead of simply setting the style to the new
// value we clear the bits which were set in styleOld but are set in // value we clear the bits which were set in styleOld but are set in
// the new one and set the ones which were not set before // the new one and set the ones which were not set before
long styleReal = ::GetWindowLong(GetHwnd(), GWL_STYLE); wxMSWWinStyleUpdater updateStyle(GetHwnd());
styleReal &= ~styleOld; updateStyle.TurnOff(styleOld).TurnOn(style);
styleReal |= style;
::SetWindowLong(GetHwnd(), GWL_STYLE, styleReal);
// we need to call SetWindowPos() if any of the styles affecting the // we need to call SetWindowPos() if any of the styles affecting the
// frame appearance have changed // frame appearance have changed
@@ -1424,15 +1418,9 @@ void wxWindowMSW::MSWUpdateStyle(long flagsOld, long exflagsOld)
} }
// and the extended style // and the extended style
long exstyleReal = wxGetWindowExStyle(this); wxMSWWinExStyleUpdater updateExStyle(GetHwnd());
if ( updateExStyle.TurnOff(exstyleOld).TurnOn(exstyle).Apply() )
if ( exstyle != exstyleOld )
{ {
exstyleReal &= ~exstyleOld;
exstyleReal |= exstyle;
wxSetWindowExStyle(this, exstyleReal);
// ex style changes don't take effect without calling SetWindowPos // ex style changes don't take effect without calling SetWindowPos
callSWP = true; callSWP = true;
} }
@@ -1443,8 +1431,8 @@ void wxWindowMSW::MSWUpdateStyle(long flagsOld, long exflagsOld)
// also to make the change to wxSTAY_ON_TOP style take effect: just // also to make the change to wxSTAY_ON_TOP style take effect: just
// setting the style simply doesn't work // setting the style simply doesn't work
if ( !::SetWindowPos(GetHwnd(), if ( !::SetWindowPos(GetHwnd(),
exstyleReal & WS_EX_TOPMOST ? HWND_TOPMOST updateExStyle.IsOn(WS_EX_TOPMOST) ? HWND_TOPMOST
: HWND_NOTOPMOST, : HWND_NOTOPMOST,
0, 0, 0, 0, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
SWP_FRAMECHANGED) ) SWP_FRAMECHANGED) )
@@ -2434,7 +2422,7 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
// must not call IsDialogMessage() then, it would simply hang (see #15458). // must not call IsDialogMessage() then, it would simply hang (see #15458).
if ( m_hWnd && if ( m_hWnd &&
HasFlag(wxTAB_TRAVERSAL) && HasFlag(wxTAB_TRAVERSAL) &&
(wxGetWindowExStyle(this) & WS_EX_CONTROLPARENT) ) wxHasWindowExStyle(this, WS_EX_CONTROLPARENT) )
{ {
// intercept dialog navigation keys // intercept dialog navigation keys
MSG *msg = (MSG *)pMsg; MSG *msg = (MSG *)pMsg;
@@ -4470,17 +4458,7 @@ bool wxWindowMSW::IsDoubleBuffered() const
void wxWindowMSW::SetDoubleBuffered(bool on) void wxWindowMSW::SetDoubleBuffered(bool on)
{ {
// Get the current extended style bits wxMSWWinExStyleUpdater(GetHwnd()).TurnOnOrOff(on, WS_EX_COMPOSITED);
long exstyle = wxGetWindowExStyle(this);
// Twiddle the bit as needed
if ( on )
exstyle |= WS_EX_COMPOSITED;
else
exstyle &= ~WS_EX_COMPOSITED;
// put it back
wxSetWindowExStyle(this, exstyle);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@@ -1508,10 +1508,8 @@ void wxPropertyGridManager::RecreateControls()
#define WS_EX_COMPOSITED 0x02000000L #define WS_EX_COMPOSITED 0x02000000L
#endif #endif
HWND hWnd = (HWND)m_pToolbar->GetHWND(); wxMSWWinExStyleUpdater(GetHwndOf(m_pToolbar))
.TurnOn(WS_EX_COMPOSITED);
::SetWindowLong( hWnd, GWL_EXSTYLE,
::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED );
*/ */
#endif #endif