X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c4e1d0fc473f5213a2ea68a5eaa305f0a7164094..a7d980f639a5051b62bacc17ef5bfb84986a7f58:/src/msw/button.cpp diff --git a/src/msw/button.cpp b/src/msw/button.cpp index 01ebb8539b..9ccd939cc1 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -182,8 +182,7 @@ bool wxButton::Create(wxWindow *parent, // black boxes) // // NB: we do it here and not in MSWGetStyle() because we need the label - // value and m_label is not set yet when MSWGetStyle() is called; - // besides changing BS_MULTILINE during run-time is pointless anyhow + // value and the label is not set yet when MSWGetStyle() is called if ( label.find(_T('\n')) != wxString::npos ) { msStyle |= BS_MULTILINE; @@ -237,6 +236,25 @@ WXDWORD wxButton::MSWGetStyle(long style, WXDWORD *exstyle) const return msStyle; } +void wxButton::SetLabel(const wxString& label) +{ + // update BS_MULTILINE style depending on the new label (resetting it + // doesn't seem to do anything very useful but it shouldn't hurt and we do + // have to set it whenever the label becomes multi line as otherwise it + // wouldn't be shown correctly) + long styleOld = ::GetWindowLong(GetHwnd(), GWL_STYLE), + styleNew; + if ( label.find(_T('\n')) != wxString::npos ) + styleNew = styleOld | BS_MULTILINE; + else + styleNew = styleOld & ~BS_MULTILINE; + + if ( styleNew != styleOld ) + ::SetWindowLong(GetHwnd(), GWL_STYLE, styleNew); + + wxButtonBase::SetLabel(label); +} + // ---------------------------------------------------------------------------- // size management including autosizing // ---------------------------------------------------------------------------- @@ -349,25 +367,32 @@ wxWindow *wxButton::SetDefault() return winOldDefault; } -// special version of wxGetTopLevelParent() which is safe to call when the -// parent is being destroyed: wxGetTopLevelParent() would just return NULL in -// this case because wxWindow version of IsTopLevel() is used when it's called -// during window destruction instead of wxTLW one, but we want to distinguish -// between these cases +// return the top level parent window if it's not being deleted yet, otherwise +// return NULL static wxTopLevelWindow *GetTLWParentIfNotBeingDeleted(wxWindow *win) { - for ( ; win; win = win->GetParent() ) + for ( ;; ) { - if ( win->IsBeingDeleted() ) - return NULL; + // IsTopLevel() will return false for a wxTLW being deleted, so we also + // need the parent test for this case + wxWindow * const parent = win->GetParent(); + if ( !parent || win->IsTopLevel() ) + { + if ( win->IsBeingDeleted() ) + return NULL; - if ( win->IsTopLevel() ) break; + } + + win = parent; } wxASSERT_MSG( win, _T("button without top level parent?") ); - return wxDynamicCast(win, wxTopLevelWindow); + wxTopLevelWindow * const tlw = wxDynamicCast(win, wxTopLevelWindow); + wxASSERT_MSG( tlw, _T("logic error in GetTLWParentIfNotBeingDeleted()") ); + + return tlw; } // set this button as being currently default