X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/107ff6689aefa5022ad0ea864ef54e7aaf933c1a..8ef089485c6a880c56d5755b7771bb1aa73328bc:/samples/listctrl/listtest.cpp diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index 7250a74c38..dd09aa34cc 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -125,6 +125,8 @@ BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl) EVT_CONTEXT_MENU(MyListCtrl::OnContextMenu) #endif EVT_CHAR(MyListCtrl::OnChar) + + EVT_RIGHT_DOWN(MyListCtrl::OnRightClick) END_EVENT_TABLE() IMPLEMENT_APP(MyApp) @@ -162,15 +164,15 @@ bool MyApp::OnInit() // My frame constructor MyFrame::MyFrame(const wxChar *title) - : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxDefaultSize)) + : wxFrame(NULL, wxID_ANY, title) { - if (wxSystemSettings::GetScreenType() > wxSYS_SCREEN_SMALL) - SetSize(wxSize(450, 340)); - m_listCtrl = NULL; m_logWindow = NULL; m_smallVirtual = false; + if (wxSystemSettings::GetScreenType() > wxSYS_SCREEN_SMALL) + SetSize(wxSize(450, 340)); + // Give it an icon SetIcon( wxICON(mondrian) ); @@ -1009,6 +1011,36 @@ void MyListCtrl::OnChar(wxKeyEvent& event) } } +void MyListCtrl::OnRightClick(wxMouseEvent& event) +{ + if ( !event.ControlDown() ) + { + event.Skip(); + return; + } + + int flags; + long subitem; + long item = HitTest(event.GetPosition(), flags, &subitem); + + wxString where; + switch ( flags ) + { + case wxLIST_HITTEST_ABOVE: where = _T("above"); break; + case wxLIST_HITTEST_BELOW: where = _T("below"); break; + case wxLIST_HITTEST_NOWHERE: where = _T("nowhere near"); break; + case wxLIST_HITTEST_ONITEMICON: where = _T("on icon of"); break; + case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of"); break; + case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on"); break; + case wxLIST_HITTEST_TOLEFT: where = _T("to the left of"); break; + case wxLIST_HITTEST_TORIGHT: where = _T("to the right of"); break; + default: where = _T("not clear exactly where on"); break; + } + + wxLogMessage(_T("Right double click %s item %ld, subitem %ld"), + where.c_str(), item, subitem); +} + void MyListCtrl::LogEvent(const wxListEvent& event, const wxChar *eventName) { wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"), @@ -1052,10 +1084,10 @@ void MyListCtrl::InsertItemInReportView(int i) SetItemData(tmp, i); buf.Printf(_T("Col 1, item %d"), i); - SetItem(i, 1, buf); + SetItem(tmp, 1, buf); buf.Printf(_T("Item %d in column 2"), i); - SetItem(i, 2, buf); + SetItem(tmp, 2, buf); } #if USE_CONTEXT_MENU @@ -1084,4 +1116,3 @@ void MyListCtrl::ShowContextMenu(const wxPoint& pos) PopupMenu(&menu, pos.x, pos.y); } -