31#define TOOLTIP_TIMER_ID 10002
37BEGIN_EVENT_TABLE(
Tooltip, wxFrame)
38EVT_PAINT(Tooltip::OnPaint)
39EVT_TIMER(TOOLTIP_TIMER_ID, Tooltip::OnTimer)
43 : wxFrame(parent, wxID_ANY, "", wxPoint(0, 0), wxSize(1, 1),
44 wxNO_BORDER | wxFRAME_FLOAT_ON_PARENT | wxFRAME_NO_TASKBAR),
45 m_showTimer(this, TOOLTIP_TIMER_ID),
46 m_on_destroy(std::move(on_destroy)) {
49 m_showPending =
false;
52 SetColorScheme(GLOBAL_COLOR_SCHEME_RGB);
54 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
55 SetBackgroundColour(m_back_color);
65bool Tooltip::Destroy() {
67 return wxFrame::Destroy();
74 m_requestedPosition = pt;
82 GetGlobalColor(
"DILG0");
83 m_text_color = GetGlobalColor(
"DILG4");
90 pos.x = windowRect.x + windowRect.width + offsetX;
91 pos.y = windowRect.y + offsetY;
95 wxSize screenSize = wxGetDisplaySize();
98 wxPoint screenPos = pos;
99 if (GetParent() && GetParent() != wxTheApp->GetTopWindow()) {
100 screenPos = GetParent()->ClientToScreen(pos);
104 if (screenPos.x + tooltipSize.x > screenSize.x) {
106 pos.x = windowRect.x - tooltipSize.x - offsetX;
107 if (GetParent() && GetParent() != wxTheApp->GetTopWindow()) {
108 screenPos = GetParent()->ClientToScreen(pos);
114 if (screenPos.x < 0) {
115 screenPos.x = offsetX;
120 if (screenPos.y + tooltipSize.y > screenSize.y) {
122 pos.y = windowRect.y - tooltipSize.y - offsetY;
123 if (GetParent() && GetParent() != wxTheApp->GetTopWindow()) {
124 screenPos = GetParent()->ClientToScreen(pos);
130 if (screenPos.y < 0) {
131 screenPos.y = offsetY;
140 if (m_string.IsEmpty()) {
147 wxFont *plabelFont = FontMgr::Get().
GetFont(_(
"ToolTips"));
148 wxFont sFont = plabelFont->Scaled(1.0 / scaler);
151 cdc.GetMultiLineTextExtent(m_string, &w, &h,
nullptr, &sFont);
152 int sizeX = w + GetCharWidth() * 2;
153 int sizeY = h + GetCharHeight() / 2;
158 return wxSize(sizeX, sizeY);
161void Tooltip::CreateBitmap() {
162 if (m_string.IsEmpty())
return;
167 wxFont *plabelFont = FontMgr::Get().
GetFont(_(
"ToolTips"));
168 wxFont sFont = plabelFont->Scaled(1.0 / scaler);
171 cdc.GetMultiLineTextExtent(m_string, &w, &h,
nullptr, &sFont);
173 m_size.x = w + GetCharWidth() * 2;
174 m_size.y = h + GetCharHeight() / 2;
182 m_pbm =
new wxBitmap(m_size.x, m_size.y, -1);
183 mdc.SelectObject(*m_pbm);
185 wxPen pborder(m_text_color);
186 wxBrush bback(m_back_color);
192 if ((m_cs == GLOBAL_COLOR_SCHEME_DUSK) ||
193 (m_cs == GLOBAL_COLOR_SCHEME_NIGHT)) {
194 wxBrush hv_back(wxColour(200, 200, 200));
195 mdc.SetBrush(hv_back);
199 mdc.DrawRectangle(0, 0, m_size.x, m_size.y);
203 mdc.SetTextForeground(m_text_color);
204 mdc.SetTextBackground(m_back_color);
206 int offx = GetCharWidth();
207 int offy = GetCharHeight() / 4;
210 mdc.DrawText(m_string, offx, offy);
212 SetClientSize(m_size.x, m_size.y);
217 CalculateOptimalPosition();
218 SetSize(m_position.x, m_position.y, m_size.x, m_size.y);
221void Tooltip::CalculateOptimalPosition() {
222 if (!GetParent())
return;
224 wxPoint screenPos = m_requestedPosition;
228 wxSize screenSize = wxGetDisplaySize();
230 if (screenPos.x + tooltipSize.x > screenSize.x) {
231 screenPos.x = screenSize.x - tooltipSize.x - 10;
233 if (screenPos.y + tooltipSize.y > screenSize.y) {
234 screenPos.y = screenSize.y - tooltipSize.y - 10;
237 if (screenPos.x < 0) screenPos.x = 10;
238 if (screenPos.y < 0) screenPos.y = 10;
240 m_position = screenPos;
244 if (m_string.IsEmpty())
return;
247 m_showPending =
true;
248 m_showTimer.Start(delay_ms, wxTIMER_ONE_SHOT);
253 if (top_frame::Get()) top_frame::Get()->Raise();
260 m_showPending =
false;
264void Tooltip::OnPaint(wxPaintEvent &event) {
266 GetClientSize(&width, &height);
269 if (m_string.Len() && m_pbm) {
271 mdc.SelectObject(*m_pbm);
272 dc.Blit(0, 0, width, height, &mdc, 0, 0);
276void Tooltip::OnTimer(wxTimerEvent &event) {
277 if (event.GetId() == TOOLTIP_TIMER_ID && m_showPending) {
278 m_showPending =
false;
280 if (!IsBeingDeleted()) {
284 if (top_frame::Get()) top_frame::Get()->Raise();
296TooltipManager::TooltipManager()
297 : m_currentTooltip(nullptr),
298 m_currentParent(nullptr),
299 m_colorScheme(GLOBAL_COLOR_SCHEME_RGB),
304TooltipManager::~TooltipManager() { CleanupTooltip(); }
314 const wxString &text,
315 const wxPoint &position,
317 if (!m_enabled || text.IsEmpty())
return;
323 m_currentTooltip = GetOrCreateTooltip(parent);
324 m_currentParent = parent;
337 const wxString &text,
bool hiviz) {
344 m_currentTooltip = GetOrCreateTooltip(window->GetParent());
345 m_currentParent = window->GetParent();
353 wxRect windowRect = window->GetRect();
361 if (m_currentTooltip) {
373 if (m_currentTooltip) {
386 return m_currentTooltip && m_currentTooltip->IsShown();
389Tooltip *TooltipManager::GetOrCreateTooltip(wxWindow *parent) {
390 if (m_currentTooltip && m_currentParent == parent) {
391 return m_currentTooltip;
397 if (t == m_currentTooltip) m_currentTooltip =
nullptr;
399 m_currentParent = parent;
401 return m_currentTooltip;
403void TooltipManager::CleanupTooltip() {
404 if (m_currentTooltip) {
406 m_currentTooltip->Destroy();
407 m_currentTooltip =
nullptr;
408 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.
Global variables stored in configuration file.
Abstract gFrame/MyFrame interface.