Character grid updated to show wxAui style tool tips
This commit is contained in:
parent
5c9a9cab03
commit
dd87605ac2
@ -47,28 +47,24 @@ wxZRColaCharGrid::wxZRColaCharGrid(wxWindow *parent, wxWindowID id, const wxPoin
|
|||||||
m_toolTipTimer = new wxTimer(this, wxID_TOOLTIP_TIMER);
|
m_toolTipTimer = new wxTimer(this, wxID_TOOLTIP_TIMER);
|
||||||
|
|
||||||
// wxEVT_MOTION event must be connected to the wxGridWindow, not wxGrid itself.
|
// wxEVT_MOTION event must be connected to the wxGridWindow, not wxGrid itself.
|
||||||
GetGridWindow()->Connect(GetGridWindow()->GetId(), wxEVT_MOTION, wxMouseEventHandler(wxZRColaCharGrid::OnMotion), NULL, this);
|
wxWindow *gridWnd = GetGridWindow();
|
||||||
|
gridWnd->Connect(gridWnd->GetId(), wxEVT_MOTION, wxMouseEventHandler(wxZRColaCharGrid::OnMotion), NULL, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxZRColaCharGrid::~wxZRColaCharGrid()
|
wxZRColaCharGrid::~wxZRColaCharGrid()
|
||||||
{
|
{
|
||||||
GetGridWindow()->Disconnect(GetGridWindow()->GetId(), wxEVT_MOTION, wxMouseEventHandler(wxZRColaCharGrid::OnMotion), NULL, this);
|
wxWindow *gridWnd = GetGridWindow();
|
||||||
|
gridWnd->Disconnect(gridWnd->GetId(), wxEVT_MOTION, wxMouseEventHandler(wxZRColaCharGrid::OnMotion), NULL, this);
|
||||||
|
|
||||||
if (m_toolTipTimer)
|
if (m_toolTipTimer)
|
||||||
delete m_toolTipTimer;
|
delete m_toolTipTimer;
|
||||||
|
|
||||||
if (m_toolTip) {
|
|
||||||
m_toolTip->SetTipWindowPtr(NULL);
|
|
||||||
m_toolTip->Close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wxZRColaCharGrid::Init()
|
void wxZRColaCharGrid::Init()
|
||||||
{
|
{
|
||||||
m_isResizing = false;
|
m_isResizing = false;
|
||||||
m_toolTip = NULL;
|
|
||||||
m_toolTipTimer = NULL;
|
m_toolTipTimer = NULL;
|
||||||
m_toolTipIdx = (size_t)-1;
|
m_toolTipIdx = (size_t)-1;
|
||||||
}
|
}
|
||||||
@ -174,11 +170,18 @@ void wxZRColaCharGrid::OnMotion(wxMouseEvent& event)
|
|||||||
m_toolTipTimer->Stop();
|
m_toolTipTimer->Stop();
|
||||||
return;
|
return;
|
||||||
} else if (toolTipIdx != m_toolTipIdx) {
|
} else if (toolTipIdx != m_toolTipIdx) {
|
||||||
// Cell changed. Schedule tooltip display after 1s.
|
// Cell changed.
|
||||||
m_toolTipIdx = toolTipIdx;
|
m_toolTipIdx = toolTipIdx;
|
||||||
|
wxWindow *gridWnd = GetGridWindow();
|
||||||
|
if (gridWnd->GetToolTip()) {
|
||||||
|
// The tooltip is already shown. Update it immediately.
|
||||||
|
gridWnd->SetToolTip(wxString::Format(wxT("U+%04X"), (int)m_chars[m_toolTipIdx]));
|
||||||
|
} else {
|
||||||
|
// This must be our initial entry. Schedule tooltip display after 1s.
|
||||||
m_toolTipTimer->Start(1000, true);
|
m_toolTipTimer->Start(1000, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void wxZRColaCharGrid::OnTooltipTimer(wxTimerEvent& event)
|
void wxZRColaCharGrid::OnTooltipTimer(wxTimerEvent& event)
|
||||||
@ -188,14 +191,5 @@ void wxZRColaCharGrid::OnTooltipTimer(wxTimerEvent& event)
|
|||||||
if (m_toolTipIdx >= m_chars.Length())
|
if (m_toolTipIdx >= m_chars.Length())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_toolTip) {
|
GetGridWindow()->SetToolTip(wxString::Format(wxT("U+%04X"), (int)m_chars[m_toolTipIdx]));
|
||||||
m_toolTip->SetTipWindowPtr(NULL);
|
|
||||||
m_toolTip->Close();
|
|
||||||
m_toolTip = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set tooltip.
|
|
||||||
wxRect rcCell(CellToRect(m_toolTipIdx / m_numCols, m_toolTipIdx % m_numCols));
|
|
||||||
rcCell.SetLeftTop(GetGridWindow()->ClientToScreen(CalcScrolledPosition(rcCell.GetLeftTop())));
|
|
||||||
m_toolTip = new wxTipWindow(this, wxString::Format(wxT("U+%04X"), (int)m_chars[m_toolTipIdx]), 100, &m_toolTip, &rcCell);
|
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ class wxZRColaCharGrid;
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <wx/grid.h>
|
#include <wx/grid.h>
|
||||||
#include <wx/tipwin.h>
|
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -74,7 +73,6 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_isResizing; ///< Prevents nesting of OnSize() method.
|
bool m_isResizing; ///< Prevents nesting of OnSize() method.
|
||||||
wxTipWindow *m_toolTip; ///< Tooltip window
|
|
||||||
wxTimer *m_toolTipTimer;///< Timer for displaying tooltip
|
wxTimer *m_toolTipTimer;///< Timer for displaying tooltip
|
||||||
size_t m_toolTipIdx; ///< Index of cell for tooltip display
|
size_t m_toolTipIdx; ///< Index of cell for tooltip display
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user