void GUITooltip::HideTooltip(const CStr& style, CGUI* gui) { // Ignore attempts to use tooltip "" if (style.empty()) return; IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style); if (! tooltipobj) { LOGERROR(L"Cannot find tooltip named '%hs'", style.c_str()); return; } CStr usedObjectName; if (GUI<CStr>::GetSetting(tooltipobj, "use_object", usedObjectName) == PSRETURN_OK && !usedObjectName.empty()) { IGUIObject* usedobj = gui->FindObjectByName(usedObjectName); if (! usedobj) { LOGERROR(L"Cannot find object named '%hs' used by tooltip '%hs'", usedObjectName.c_str(), style.c_str()); return; } // Clear the caption usedobj->SetSetting("caption", L""); SGUIMessage msg(GUIM_SETTINGS_UPDATED, "caption"); usedobj->HandleMessage(msg); bool hideobject = true; GUI<bool>::GetSetting(tooltipobj, "hide_object", hideobject); // If hide_object was enabled, hide it if (hideobject) GUI<bool>::SetSetting(usedobj, "hidden", true); } else { GUI<bool>::SetSetting(tooltipobj, "hidden", true); } }
void GUITooltip::ShowTooltip(IGUIObject* obj, CPos pos, const CStr& style, CGUI* gui) { ENSURE(obj); // Ignore attempts to use tooltip "" if (style.empty()) return; // Get the object referenced by 'tooltip_style' IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style); if (! tooltipobj) { LOGERROR(L"Cannot find tooltip named '%hs'", style.c_str()); return; } IGUIObject* usedobj = tooltipobj; // object actually used to display the tooltip in CStr usedObjectName; if (GUI<CStr>::GetSetting(tooltipobj, "use_object", usedObjectName) == PSRETURN_OK && !usedObjectName.empty()) { usedobj = gui->FindObjectByName(usedObjectName); if (! usedobj) { LOGERROR(L"Cannot find object named '%hs' used by tooltip '%hs'", usedObjectName.c_str(), style.c_str()); return; } // Unhide the object. (If it had use_object and hide_object="true", // still unhide it, because the used object might be hidden by default) GUI<bool>::SetSetting(usedobj, "hidden", false); } else { // Unhide the object GUI<bool>::SetSetting(usedobj, "hidden", false); // Store mouse position inside the CTooltip if (GUI<CPos>::SetSetting(usedobj, "_mousepos", pos) != PSRETURN_OK) debug_warn(L"Failed to set tooltip mouse position"); } // Retrieve object's 'tooltip' setting CStrW text; if (m_IsIconTooltip) { // Use icon tooltip property if (GUI<CStrW>::GetSetting(obj, "_icon_tooltip", text) != PSRETURN_OK) debug_warn(L"Failed to retrieve icon tooltip text"); // shouldn't fail } else { // Use normal tooltip property if (GUI<CStrW>::GetSetting(obj, "tooltip", text) != PSRETURN_OK) debug_warn(L"Failed to retrieve tooltip text"); // shouldn't fail } // Do some minimal processing ("\n" -> newline, etc) text = text.UnescapeBackslashes(); // Set tooltip's caption if (usedobj->SetSetting("caption", text) != PSRETURN_OK) debug_warn(L"Failed to set tooltip caption"); // shouldn't fail // Make the tooltip object regenerate its text SGUIMessage msg(GUIM_SETTINGS_UPDATED, "caption"); usedobj->HandleMessage(msg); }