I have MyGrid derived from wxGrid. I created function to recieve mouse event(when right click on white space)
Code: Select all
MyGrid* m_Grid;
wxMenu* myMenu= new wxMenu(wxEmptyString, 0);
for(int col = 0; col < m_Grid->GetNumberCols(); col++ ) {
myMenu->AppendCheckItem(wdCOL_LIST_0 + col
, m_Grid->GetColLabelValue(col)
, wxEmptyString);
myMenu->Check(wdCOL_LIST_0 + col, false);
}
this->GetGridWindow()->Connect( GetGridWindow()->GetId(), wxEVT_RIGHT_DOWN, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction) &MyGrid::onWhiteSpaceRightClick);
void MyGrid::onWhiteSpaceRightClick(wxMouseEvent &event)
{
wxWindow* window = (wxWindow*)event.GetEventObject();
wxGrid* grid = (wxGrid*)window->GetParent();
int x = event.GetX();
int y = event.GetY();
// Get real coordinates for grid
int sX, sY;
( ( wxScrolledWindow* ) grid )->CalcUnscrolledPosition( x, y, &sX, &sY );
int row = grid->YToRow( sY );
int col = grid->XToCol( sX );
DEBUG("row = %d col = %d", row, col);
//right click on white space
if( col < 0 || row < 0) {
doPopupMenu(event.GetPosition());
return;
}
else {
event.Skip(true);
return;
}
}
void MyGrid::doPopupMenu(wxPoint pos)
{
for(int i = 0 ; i < m_Grid->GetNumberCols(); i++) {
if(m_Grid->GetColSize(i) > 0)
myMenu->Check(wdCOL_LIST_0 + i , true);
else
myMenu->Check(wdCOL_LIST_0 + i , false);
}
PopupMenu(myMenu, pos);
}
and cannot get GetNumberCols()... and I lost myMenu too
So Any idea how to fix it or where my fault is ?
Thanks,
violethiLL