From d63312a977127f6b3a3f61db2ed933f50c308aa1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 4 Dec 2006 11:10:59 +0000 Subject: [PATCH] added a small helper ToggleWindowStyle() function git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43796 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/window.tex | 20 +++++++++++++++++++- include/wx/window.h | 5 +++++ src/common/wincmn.cpp | 24 +++++++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/docs/latex/wx/window.tex b/docs/latex/wx/window.tex index cc3f221ea8..7ff0b46081 100644 --- a/docs/latex/wx/window.tex +++ b/docs/latex/wx/window.tex @@ -3443,7 +3443,8 @@ Identical to \helpref{SetWindowStyleFlag}{wxwindowsetwindowstyleflag}. Sets the style of the window. Please note that some styles cannot be changed after the window creation and that \helpref{Refresh()}{wxwindowrefresh} might -be called after changing the others for the change to take place immediately. +need to be be called after changing the others for the change to take place +immediately. See \helpref{Window styles}{windowstyles} for more information about flags. @@ -3523,6 +3524,23 @@ exactly the same number of times as \helpref{Freeze}{wxwindowfreeze}. \helpref{wxWindowUpdateLocker}{wxwindowupdatelocker} +\membersection{wxWindow::ToggleWindowStyle}\label{wxwindowtogglewindowstyle} + +\func{void}{ToggleWindowStyle}{\param{int }{flag}} + +Turns the given \arg{flag} on if it's currently turned off and vice versa. +This function cannot be used if the value of the flag is $0$ (which is often +the case for default flags). + +Also, please notice that not all styles can be changed after the control +creation. + +\wxheading{See also} + +\helpref{wxWindow::SetWindowStyleFlag}{wxwindowsetwindowstyleflag},\rtfsp +\helpref{wxWindow::HasFlag}{wxwindowhasflag} + + \membersection{wxWindow::TransferDataFromWindow}\label{wxwindowtransferdatafromwindow} \func{virtual bool}{TransferDataFromWindow}{\void} diff --git a/include/wx/window.h b/include/wx/window.h index acff5abc8e..30f4f2f57c 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -506,9 +506,14 @@ public: void SetWindowStyle( long style ) { SetWindowStyleFlag(style); } long GetWindowStyle() const { return GetWindowStyleFlag(); } + // check if the flag is set bool HasFlag(int flag) const { return (m_windowStyle & flag) != 0; } virtual bool IsRetained() const { return HasFlag(wxRETAINED); } + // turn the flag on if it had been turned off before and vice versa, + // return true if the flag is currently turned on + bool ToggleWindowStyle(int flag); + // extra style: the less often used style bits which can't be set with // SetWindowStyleFlag() virtual void SetExtraStyle(long exStyle) { m_exStyle = exStyle; } diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index a2f7a42766..8c393888f3 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -274,6 +274,28 @@ bool wxWindowBase::CreateBase(wxWindowBase *parent, return true; } +bool wxWindowBase::ToggleWindowStyle(int flag) +{ + wxASSERT_MSG( flag, _T("flags with 0 value can't be toggled") ); + + bool rc; + long style = GetWindowStyleFlag(); + if ( style & flag ) + { + style &= ~flag; + rc = false; + } + else // currently off + { + style |= flag; + rc = true; + } + + SetWindowStyleFlag(style); + + return rc; +} + // ---------------------------------------------------------------------------- // destruction // ---------------------------------------------------------------------------- @@ -301,7 +323,7 @@ wxWindowBase::~wxWindowBase() { wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent((wxWindow*)this), wxTopLevelWindow); - + if ( tlw && tlw->GetDefaultItem() == this ) tlw->SetDefaultItem(NULL); if ( tlw && tlw->GetTmpDefaultItem() == this ) -- 2.45.2