Tooltips added to character grid
This commit is contained in:
parent
7bd217ec47
commit
d86c1d004d
@ -27,22 +27,50 @@
|
|||||||
BEGIN_EVENT_TABLE(wxZRColaCharGrid, wxGrid)
|
BEGIN_EVENT_TABLE(wxZRColaCharGrid, wxGrid)
|
||||||
EVT_SIZE(wxZRColaCharGrid::OnSize)
|
EVT_SIZE(wxZRColaCharGrid::OnSize)
|
||||||
EVT_KEY_DOWN(wxZRColaCharGrid::OnKeyDown)
|
EVT_KEY_DOWN(wxZRColaCharGrid::OnKeyDown)
|
||||||
|
EVT_TIMER(wxZRColaCharGrid::wxID_TOOLTIP_TIMER, wxZRColaCharGrid::OnTooltipTimer)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
|
||||||
wxZRColaCharGrid::wxZRColaCharGrid() :
|
wxZRColaCharGrid::wxZRColaCharGrid() : wxGrid()
|
||||||
m_isResizing(false),
|
|
||||||
wxGrid()
|
|
||||||
{
|
{
|
||||||
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxZRColaCharGrid::wxZRColaCharGrid(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) :
|
wxZRColaCharGrid::wxZRColaCharGrid(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) : wxGrid(parent, id, pos, size, wxWANTS_CHARS, name)
|
||||||
m_isResizing(false),
|
|
||||||
wxGrid(parent, id, pos, size, wxWANTS_CHARS, name)
|
|
||||||
{
|
{
|
||||||
// Cell Defaults
|
Init();
|
||||||
|
|
||||||
SetDefaultRowSize(wxZRColaCharacterGridRowHeight);
|
SetDefaultRowSize(wxZRColaCharacterGridRowHeight);
|
||||||
|
|
||||||
|
// Create timer for saving the state.
|
||||||
|
m_toolTipTimer = new wxTimer(this, wxID_TOOLTIP_TIMER);
|
||||||
|
|
||||||
|
// wxEVT_MOTION event must be connected to the wxGridWindow, not wxGrid itself.
|
||||||
|
GetGridWindow()->Connect(GetGridWindow()->GetId(), wxEVT_MOTION, wxMouseEventHandler(wxZRColaCharGrid::OnMotion), NULL, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
wxZRColaCharGrid::~wxZRColaCharGrid()
|
||||||
|
{
|
||||||
|
GetGridWindow()->Disconnect(GetGridWindow()->GetId(), wxEVT_MOTION, wxMouseEventHandler(wxZRColaCharGrid::OnMotion), NULL, this);
|
||||||
|
|
||||||
|
if (m_toolTipTimer)
|
||||||
|
delete m_toolTipTimer;
|
||||||
|
|
||||||
|
if (m_toolTip) {
|
||||||
|
m_toolTip->SetTipWindowPtr(NULL);
|
||||||
|
m_toolTip->Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxZRColaCharGrid::Init()
|
||||||
|
{
|
||||||
|
m_isResizing = false;
|
||||||
|
m_toolTip = NULL;
|
||||||
|
m_toolTipTimer = NULL;
|
||||||
|
m_toolTipIdx = (size_t)-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -125,3 +153,49 @@ void wxZRColaCharGrid::OnKeyDown(wxKeyEvent& event)
|
|||||||
|
|
||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxZRColaCharGrid::OnMotion(wxMouseEvent& event)
|
||||||
|
{
|
||||||
|
event.Skip();
|
||||||
|
|
||||||
|
wxPoint ptMouse(CalcUnscrolledPosition(event.GetPosition()));
|
||||||
|
int
|
||||||
|
col = XToCol(ptMouse.x - m_rowLabelWidth ),
|
||||||
|
row = YToRow(ptMouse.y - m_colLabelHeight);
|
||||||
|
|
||||||
|
if (col == wxNOT_FOUND || row == wxNOT_FOUND )
|
||||||
|
return;
|
||||||
|
|
||||||
|
size_t toolTipIdx = row*m_numCols + col;
|
||||||
|
if (toolTipIdx >= m_chars.Length()) {
|
||||||
|
// Index out of range.
|
||||||
|
m_toolTipIdx = (size_t)-1;
|
||||||
|
m_toolTipTimer->Stop();
|
||||||
|
return;
|
||||||
|
} else if (toolTipIdx != m_toolTipIdx) {
|
||||||
|
// Cell changed. Schedule tooltip display after 1s.
|
||||||
|
m_toolTipIdx = toolTipIdx;
|
||||||
|
m_toolTipTimer->Start(1000, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxZRColaCharGrid::OnTooltipTimer(wxTimerEvent& event)
|
||||||
|
{
|
||||||
|
event.Skip();
|
||||||
|
|
||||||
|
if (m_toolTipIdx >= m_chars.Length())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (m_toolTip) {
|
||||||
|
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,6 +26,7 @@ class wxZRColaCharGrid;
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <wx/grid.h>
|
#include <wx/grid.h>
|
||||||
|
#include <wx/tipwin.h>
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -42,8 +43,14 @@ class wxZRColaCharGrid;
|
|||||||
class wxZRColaCharGrid : public wxGrid
|
class wxZRColaCharGrid : public wxGrid
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
wxID_TOOLTIP_TIMER = 2000,
|
||||||
|
};
|
||||||
|
|
||||||
wxZRColaCharGrid();
|
wxZRColaCharGrid();
|
||||||
wxZRColaCharGrid(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxGridNameStr);
|
wxZRColaCharGrid(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxGridNameStr);
|
||||||
|
virtual ~wxZRColaCharGrid();
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Sets new array of characters to display
|
/// Sets new array of characters to display
|
||||||
@ -55,11 +62,19 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void OnSize(wxSizeEvent& event);
|
void OnSize(wxSizeEvent& event);
|
||||||
void OnKeyDown(wxKeyEvent& event);
|
void OnKeyDown(wxKeyEvent& event);
|
||||||
|
void OnMotion(wxMouseEvent& event);
|
||||||
|
void OnTooltipTimer(wxTimerEvent& event);
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Init(); // common part of all ctors
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxString m_chars; ///< Array of Unicode characters to display in the grid
|
wxString m_chars; ///< Array of Unicode characters to display in the grid
|
||||||
|
|
||||||
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
|
||||||
|
size_t m_toolTipIdx; ///< Index of cell for tooltip display
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user