Here is code of my custom control:
Code: Select all
class wxListViewShares : public wxDataViewListCtrl
{
public:
using share_list_t = std::vector<std::shared_ptr<MatchMaker::Share>>;
wxListViewShares(wxWindow* parent, const share_list_t& shares, const std::shared_ptr<ApplicationHelper>& appHelper,
const SharesSerializer::used_shares_t& usedShares);
// ... some methods here
protected:
// ... some methods here
void OnSelectionChanged(wxDataViewEvent& event);
void OnMouseMove(wxMouseEvent& event);
share_list_t m_shares;
std::shared_ptr<MatchMaker::Share> m_chosenShare;
const std::shared_ptr<ApplicationHelper> m_applicationHelper;
SharesSerializer::used_shares_t m_usedShares;
int m_currentRowIndex; // current selected row
int m_currentHoveredRowIndex;
};
wxListViewShares::wxListViewShares(wxWindow* parent, const share_list_t& shares, const std::shared_ptr<ApplicationHelper>& appHelper,
const SharesSerializer::used_shares_t& usedShares) :
wxDataViewListCtrl(parent, wxID_ANY, wxDefaultPosition, wxSize(parent->FromDIP(740), parent->FromDIP(175)), wxDV_ROW_LINES | wxDV_SINGLE),
m_shares(shares),
m_applicationHelper(appHelper),
m_usedShares(usedShares)
{
FillHeaders();
FillList();
Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &wxListViewShares::OnSelectionChanged, this);
GetMainWindow()->Bind(wxEVT_MOTION, &wxListViewShares::OnMouseMove, this);
}
void wxListViewShares::OnSelectionChanged(wxDataViewEvent& event)
{
int row = ItemToRow(event.GetItem());
if (row >= 0)
{
m_chosenShare = m_shares[row];
m_currentRowIndex = row;
event.SetInt(row);
event.SetString(GetTextValue(row, 0));
}
else
{
event.SetInt(-1);
event.SetString("");
}
event.Skip();
}
void wxListViewShares::OnMouseMove(wxMouseEvent& event)
{
wxDataViewItem item;
wxDataViewColumn *column;
wxWindow* main = GetMainWindow();
wxPoint pos = ScreenToClient(main->ClientToScreen(event.GetPosition()));
HitTest(pos, item, column);
if (item != NULL && column != NULL)
{
if (column->GetTitle() != _("header.Target"))
{
main->UnsetToolTip();
return;
}
int row = ItemToRow(item);
if (row == m_currentHoveredRowIndex)
{
return;
}
if (row >= 0)
{
wxString text = GetTextValue(row, 0);
m_currentHoveredRowIndex = row;
if (main->GetTextExtent(text).GetWidth() > FromDIP(190))
{
main->SetToolTip(text);
}
else
{
main->UnsetToolTip();
}
}
else
{
m_currentHoveredRowIndex = -1;
main->UnsetToolTip();
}
}
else
{
m_currentHoveredRowIndex = -1;
GetMainWindow()->UnsetToolTip();
}
event.Skip();
}
Code: Select all
GetMainWindow()->Bind(wxEVT_MOTION, &wxListViewShares::OnMouseMove, this);
Also OnMouseMove event overrided in the dialog's class (to handle resize), but don't think it's a problem.
I noticed that my custom control doesn't lose focus after clicking out of control's area. How to make it lost focus?