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.
This commit is contained in:
parent
e1e50655bb
commit
a47d005165
1 changed files with 10 additions and 9 deletions
|
|
@ -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("<A HREF=\"%s\">%s</A>",
|
||||
url,
|
||||
wxControl::EscapeMnemonics(text));
|
||||
return wxString::Format
|
||||
(
|
||||
"<A HREF=\"%s\">%s</A>",
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue