From a47d0051656b3e197384aa686d52ff7a9a6d54bb Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 3 Dec 2022 23:40:46 +0100 Subject: [PATCH] Simplify and correct setting URL in wxHyperlinkCtrl::Create() It's unnecessary to call SetURL() twice and it's actually harmful to call it before creating the window as it tries to update the label of the window that doesn't exist yet (which results in a perfectly avoidable warning when using Wine). And it's unnecessary to call SetLabel() because we had just set the same label anyhow. But we do need to take empty label into account when either SetURL() or SetLabel() is called later, so move the check for this from Create() into GetLabelForSysLink() helper, so that it is used in all cases. Finally, also remove the redundant SetVisited(false) as "visited" flag is false by default. --- src/msw/hyperlink.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/msw/hyperlink.cpp b/src/msw/hyperlink.cpp index 9400c80bae..625c830c62 100644 --- a/src/msw/hyperlink.cpp +++ b/src/msw/hyperlink.cpp @@ -60,9 +60,12 @@ namespace { // Any "&"s in the text should appear on the screen and not be (mis) // interpreted as mnemonics. - return wxString::Format("%s", - url, - wxControl::EscapeMnemonics(text)); + return wxString::Format + ( + "%s", + url, + wxControl::EscapeMnemonics(text.empty() ? url : text) + ); } } @@ -90,8 +93,10 @@ bool wxHyperlinkCtrl::Create(wxWindow *parent, return false; } - SetURL( url ); - SetVisited( false ); + // Don't call our own version of SetURL() which would try to update the + // label of the not yet created window which wouldn't do anything and is + // unnecessary anyhow as we're going to set the label when creating it. + wxGenericHyperlinkCtrl::SetURL( url ); WXDWORD exstyle; WXDWORD msStyle = MSWGetStyle(style, &exstyle); @@ -102,10 +107,6 @@ bool wxHyperlinkCtrl::Create(wxWindow *parent, return false; } - // Make sure both the label and URL are non-empty strings. - SetURL(url.empty() ? label : url); - SetLabel(label.empty() ? url : label); - ConnectMenuHandlers(); return true;