added a small helper ToggleWindowStyle() function

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43796 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2006-12-04 11:10:59 +00:00
parent 9ec927f89b
commit d63312a977
3 changed files with 47 additions and 2 deletions

View File

@ -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}

View File

@ -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; }

View File

@ -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 )