forked from 0ad/0ad
Allowed \\ in tooltip text. Fixed tooltips.
This was SVN commit r1587.
This commit is contained in:
parent
c97077f971
commit
9e2413acab
@ -70,7 +70,22 @@ static bool GetTooltip(IGUIObject* obj, CStr &style)
|
||||
&& GUI<CStr>::GetSetting(obj, "tooltip-style", style) == PS_OK)
|
||||
{
|
||||
if (style.Length() == 0)
|
||||
style = "default";
|
||||
{
|
||||
// If there's no style, there's probably no tooltip
|
||||
|
||||
CStr text;
|
||||
if (GUI<CStr>::GetSetting(obj, "tooltip", text) == PS_OK && text.Length())
|
||||
{
|
||||
// There is a tooltip, so just use the default style;
|
||||
style = "default";
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No tooltip
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -121,7 +136,7 @@ static void ShowTooltip(IGUIObject* obj, CPos pos, CStr& style, CGUI* gui)
|
||||
debug_warn("Failed to retrieve tooltip text"); // shouldn't fail
|
||||
|
||||
// Do some minimal processing ("\n" -> newline, etc)
|
||||
text.Replace("\\n", "\n"); // TODO: Allow tooltip="\\n" etc
|
||||
text = text.UnescapeBackslashes();
|
||||
|
||||
// Set tooltip's caption
|
||||
if (usedobj->SetSetting("caption", text) != PS_OK)
|
||||
|
@ -220,6 +220,34 @@ void CStr::Replace(const CStr& ToReplace, const CStr& ReplaceWith)
|
||||
}
|
||||
}
|
||||
|
||||
CStr CStr::UnescapeBackslashes()
|
||||
{
|
||||
// Currently only handle \n and \\, because they're the only interesting ones
|
||||
CStr NewString;
|
||||
bool escaping = false;
|
||||
for (size_t i = 0; i < length(); i++)
|
||||
{
|
||||
TCHAR ch = (*this)[i];
|
||||
if (escaping)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case _T('n'): NewString += _T('\n'); break;
|
||||
default: NewString += ch; break;
|
||||
}
|
||||
escaping = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ch == _T('\\'))
|
||||
escaping = true;
|
||||
else
|
||||
NewString += ch;
|
||||
}
|
||||
}
|
||||
return NewString;
|
||||
}
|
||||
|
||||
// Returns a trimmed string, removes whitespace from the left/right/both
|
||||
CStr CStr::Trim(PS_TRIM_MODE Mode) const
|
||||
{
|
||||
|
@ -181,6 +181,9 @@ public:
|
||||
// Replace all occurrences of some substring by another
|
||||
void Replace(const CStr& StrToReplace, const CStr& ReplaceWith);
|
||||
|
||||
// Convert strings like \\\n into <backslash><newline>
|
||||
CStr UnescapeBackslashes();
|
||||
|
||||
// Returns a trimmed string, removes whitespace from the left/right/both
|
||||
CStr Trim(PS_TRIM_MODE Mode) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user