33#define TOOLTIP_TIMER_ID 10002
39BEGIN_EVENT_TABLE(
Tooltip, wxFrame)
40EVT_PAINT(Tooltip::OnPaint)
41EVT_TIMER(TOOLTIP_TIMER_ID, Tooltip::OnTimer)
45 : wxFrame(parent, wxID_ANY, "", wxPoint(0, 0), wxSize(1, 1),
46 wxNO_BORDER | wxFRAME_FLOAT_ON_PARENT | wxFRAME_NO_TASKBAR),
47 m_showTimer(this, TOOLTIP_TIMER_ID),
48 m_on_destroy(std::move(on_destroy)) {
51 m_showPending =
false;
54 SetColorScheme(GLOBAL_COLOR_SCHEME_RGB);
56 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
57 SetBackgroundColour(m_back_color);
67bool Tooltip::Destroy() {
69 return wxFrame::Destroy();
76 m_requestedPosition = pt;
84 GetGlobalColor(
"DILG0");
85 m_text_color = GetGlobalColor(
"DILG4");
92 pos.x = windowRect.x + windowRect.width + offsetX;
93 pos.y = windowRect.y + offsetY;
97 wxSize screenSize = wxGetDisplaySize();
100 wxPoint screenPos = pos;
101 if (GetParent() && GetParent() != wxTheApp->GetTopWindow()) {
102 screenPos = GetParent()->ClientToScreen(pos);
106 if (screenPos.x + tooltipSize.x > screenSize.x) {
108 pos.x = windowRect.x - tooltipSize.x - offsetX;
109 if (GetParent() && GetParent() != wxTheApp->GetTopWindow()) {
110 screenPos = GetParent()->ClientToScreen(pos);
116 if (screenPos.x < 0) {
117 screenPos.x = offsetX;
122 if (screenPos.y + tooltipSize.y > screenSize.y) {
124 pos.y = windowRect.y - tooltipSize.y - offsetY;
125 if (GetParent() && GetParent() != wxTheApp->GetTopWindow()) {
126 screenPos = GetParent()->ClientToScreen(pos);
132 if (screenPos.y < 0) {
133 screenPos.y = offsetY;
142 if (m_string.IsEmpty()) {
149 wxFont *plabelFont = FontMgr::Get().
GetFont(_(
"ToolTips"));
150 wxFont sFont = plabelFont->Scaled(1.0 / scaler);
153 cdc.GetMultiLineTextExtent(m_string, &w, &h,
nullptr, &sFont);
154 int sizeX = w + GetCharWidth() * 2;
155 int sizeY = h + GetCharHeight() / 2;
160 return wxSize(sizeX, sizeY);
163void Tooltip::CreateBitmap() {
164 if (m_string.IsEmpty())
return;
169 wxFont *plabelFont = FontMgr::Get().
GetFont(_(
"ToolTips"));
170 wxFont sFont = plabelFont->Scaled(1.0 / scaler);
173 cdc.GetMultiLineTextExtent(m_string, &w, &h,
nullptr, &sFont);
175 m_size.x = w + GetCharWidth() * 2;
176 m_size.y = h + GetCharHeight() / 2;
184 m_pbm =
new wxBitmap(m_size.x, m_size.y, -1);
185 mdc.SelectObject(*m_pbm);
187 wxPen pborder(m_text_color);
188 wxBrush bback(m_back_color);
194 if ((m_cs == GLOBAL_COLOR_SCHEME_DUSK) ||
195 (m_cs == GLOBAL_COLOR_SCHEME_NIGHT)) {
196 wxBrush hv_back(wxColour(200, 200, 200));
197 mdc.SetBrush(hv_back);
201 mdc.DrawRectangle(0, 0, m_size.x, m_size.y);
205 mdc.SetTextForeground(m_text_color);
206 mdc.SetTextBackground(m_back_color);
208 int offx = GetCharWidth();
209 int offy = GetCharHeight() / 4;
212 mdc.DrawText(m_string, offx, offy);
214 SetClientSize(m_size.x, m_size.y);
219 CalculateOptimalPosition();
220 SetSize(m_position.x, m_position.y, m_size.x, m_size.y);
223void Tooltip::CalculateOptimalPosition() {
224 if (!GetParent())
return;
226 wxPoint screenPos = m_requestedPosition;
230 wxSize screenSize = wxGetDisplaySize();
232 if (screenPos.x + tooltipSize.x > screenSize.x) {
233 screenPos.x = screenSize.x - tooltipSize.x - 10;
235 if (screenPos.y + tooltipSize.y > screenSize.y) {
236 screenPos.y = screenSize.y - tooltipSize.y - 10;
239 if (screenPos.x < 0) screenPos.x = 10;
240 if (screenPos.y < 0) screenPos.y = 10;
242 m_position = screenPos;
246 if (m_string.IsEmpty())
return;
249 m_showPending =
true;
250 m_showTimer.Start(delay_ms, wxTIMER_ONE_SHOT);
255 if (gFrame) gFrame->Raise();
262 m_showPending =
false;
266void Tooltip::OnPaint(wxPaintEvent &event) {
268 GetClientSize(&width, &height);
271 if (m_string.Len() && m_pbm) {
273 mdc.SelectObject(*m_pbm);
274 dc.Blit(0, 0, width, height, &mdc, 0, 0);
278void Tooltip::OnTimer(wxTimerEvent &event) {
279 if (event.GetId() == TOOLTIP_TIMER_ID && m_showPending) {
280 m_showPending =
false;
282 if (!IsBeingDeleted()) {
286 if (gFrame) gFrame->Raise();
298TooltipManager::TooltipManager()
299 : m_currentTooltip(nullptr),
300 m_currentParent(nullptr),
301 m_colorScheme(GLOBAL_COLOR_SCHEME_RGB),
306TooltipManager::~TooltipManager() { CleanupTooltip(); }
316 const wxString &text,
317 const wxPoint &position,
319 if (!m_enabled || text.IsEmpty())
return;
325 m_currentTooltip = GetOrCreateTooltip(parent);
326 m_currentParent = parent;
339 const wxString &text,
bool hiviz) {
346 m_currentTooltip = GetOrCreateTooltip(window->GetParent());
347 m_currentParent = window->GetParent();
355 wxRect windowRect = window->GetRect();
363 if (m_currentTooltip) {
375 if (m_currentTooltip) {
388 return m_currentTooltip && m_currentTooltip->IsShown();
391Tooltip *TooltipManager::GetOrCreateTooltip(wxWindow *parent) {
392 if (m_currentTooltip && m_currentParent == parent) {
393 return m_currentTooltip;
399 if (t == m_currentTooltip) m_currentTooltip =
nullptr;
401 m_currentParent = parent;
403 return m_currentTooltip;
405void TooltipManager::CleanupTooltip() {
406 if (m_currentTooltip) {
408 m_currentTooltip->Destroy();
409 m_currentTooltip =
nullptr;
410 m_currentParent =
nullptr;
Generic Chart canvas base.
wxFont * GetFont(const wxString &TextElement, int requested_font_size=0)
Get a font object for a UI element.
Global color handling by name.