EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel)
EVT_MENU(LIST_SHOW_COL_INFO, MyFrame::OnShowColInfo)
EVT_MENU(LIST_SHOW_SEL_INFO, MyFrame::OnShowSelInfo)
+ EVT_MENU(LIST_SHOW_VIEW_RECT, MyFrame::OnShowViewRect)
+#ifdef wxHAS_LISTCTRL_COLUMN_ORDER
+ EVT_MENU(LIST_SET_COL_ORDER, MyFrame::OnSetColOrder)
+ EVT_MENU(LIST_GET_COL_ORDER, MyFrame::OnGetColOrder)
+#endif // wxHAS_LISTCTRL_COLUMN_ORDER
EVT_MENU(LIST_FREEZE, MyFrame::OnFreeze)
EVT_MENU(LIST_THAW, MyFrame::OnThaw)
EVT_MENU(LIST_TOGGLE_LINES, MyFrame::OnToggleLines)
menuList->AppendSeparator();
menuList->Append(LIST_SHOW_COL_INFO, _T("Show &column info\tCtrl-C"));
menuList->Append(LIST_SHOW_SEL_INFO, _T("Show &selected items\tCtrl-S"));
+ menuList->Append(LIST_SHOW_VIEW_RECT, _T("Show &view rect"));
+#ifdef wxHAS_LISTCTRL_COLUMN_ORDER
+ menuList->Append(LIST_SET_COL_ORDER, _T("Se&t columns order\tShift-Ctrl-O"));
+ menuList->Append(LIST_GET_COL_ORDER, _T("Show&w columns order\tCtrl-O"));
+#endif // wxHAS_LISTCTRL_COLUMN_ORDER
menuList->AppendSeparator();
- menuList->Append(LIST_SORT, _T("&Sort\tCtrl-S"));
+ menuList->Append(LIST_SORT, _T("Sor&t\tCtrl-T"));
menuList->AppendSeparator();
menuList->Append(LIST_ADD, _T("&Append an item\tCtrl-P"));
menuList->Append(LIST_EDIT, _T("&Edit the item\tCtrl-E"));
}
}
+void MyFrame::OnShowViewRect(wxCommandEvent& WXUNUSED(event))
+{
+ const wxRect r = m_listCtrl->GetViewRect();
+ wxLogMessage("View rect: (%d, %d)-(%d, %d)",
+ r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom());
+}
+
+// ----------------------------------------------------------------------------
+// column order tests
+// ----------------------------------------------------------------------------
+
+#ifdef wxHAS_LISTCTRL_COLUMN_ORDER
+
+static wxString DumpIntArray(const wxArrayInt& a)
+{
+ wxString s("{ ");
+ const size_t count = a.size();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ if ( n )
+ s += ", ";
+ s += wxString::Format("%lu", (unsigned long)a[n]);
+ }
+
+ s += " }";
+
+ return s;
+}
+
+void MyFrame::OnSetColOrder(wxCommandEvent& WXUNUSED(event))
+{
+ wxArrayInt order(3);
+ order[0] = 2;
+ order[1] = 0;
+ order[2] = 1;
+ if ( m_listCtrl->SetColumnsOrder(order) )
+ wxLogMessage("Column order set to %s", DumpIntArray(order));
+}
+
+void MyFrame::OnGetColOrder(wxCommandEvent& WXUNUSED(event))
+{
+ // show what GetColumnsOrder() returns
+ const wxArrayInt order = m_listCtrl->GetColumnsOrder();
+ wxString msg = "Columns order: " +
+ DumpIntArray(m_listCtrl->GetColumnsOrder()) + "\n";
+
+ int n;
+ const int count = m_listCtrl->GetColumnCount();
+
+ // show the results of GetColumnOrder() for each column
+ msg += "GetColumnOrder() results:\n";
+ for ( n = 0; n < count; n++ )
+ {
+ msg += wxString::Format(" %2d -> %2d\n",
+ n, m_listCtrl->GetColumnOrder(n));
+ }
+
+ // and the results of GetColumnIndexFromOrder() too
+ msg += "GetColumnIndexFromOrder() results:\n";
+ for ( n = 0; n < count; n++ )
+ {
+ msg += wxString::Format(" %2d -> %2d\n",
+ n, m_listCtrl->GetColumnIndexFromOrder(n));
+ }
+
+ wxLogMessage("%s", msg);
+}
+
+#endif // wxHAS_LISTCTRL_COLUMN_ORDER
+
void MyFrame::OnShowColInfo(wxCommandEvent& WXUNUSED(event))
{
int count = m_listCtrl->GetColumnCount();
void MyListCtrl::OnBeginLabelEdit(wxListEvent& event)
{
wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str());
+
+ wxTextCtrl * const text = GetEditControl();
+ if ( !text )
+ {
+ wxLogMessage("BUG: started to edit but no edit control");
+ }
+ else
+ {
+ wxLogMessage("Edit control value: \"%s\"", text->GetValue());
+ }
}
void MyListCtrl::OnEndLabelEdit(wxListEvent& event)
}
break;
+ case '1': // show sub item bounding rectangle
+ case '2':
+ case '3':
+ case '4': // this column is invalid but we want to test it too
+ if ( InReportView() )
+ {
+ int subItem = event.GetKeyCode() - '1';
+ item = event.GetIndex();
+ wxRect r;
+ if ( !GetSubItemRect(item, subItem, r) )
+ {
+ wxLogError(_T("Failed to retrieve rect of item %ld column %d"), item, subItem + 1);
+ break;
+ }
+
+ wxLogMessage(_T("Bounding rect of item %ld column %d is (%d, %d)-(%d, %d)"),
+ item, subItem + 1,
+ r.x, r.y, r.x + r.width, r.y + r.height);
+ }
+ break;
+
case 'U': // update
if ( !IsVirtual() )
break;
}
break;
- case WXK_DELETE:
+ case 'D': // delete
item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
while ( item != -1 )
{
}
break;
- case WXK_INSERT:
+ case 'I': // insert
if ( GetWindowStyle() & wxLC_REPORT )
{
if ( GetWindowStyle() & wxLC_VIRTUAL )
case 'R':
case 'u':
case 'U':
- case WXK_DELETE:
- case WXK_INSERT:
+ case 'd':
+ case 'D':
+ case 'i':
+ case 'I':
// these are the keys we process ourselves
break;
#if USE_CONTEXT_MENU
void MyListCtrl::OnContextMenu(wxContextMenuEvent& event)
{
- wxPoint point = event.GetPosition();
- // If from keyboard
- if (point.x == -1 && point.y == -1) {
- wxSize size = GetSize();
- point.x = size.x / 2;
- point.y = size.y / 2;
- } else {
- point = ScreenToClient(point);
+ if (GetEditControl() == NULL)
+ {
+ wxPoint point = event.GetPosition();
+ // If from keyboard
+ if ( (point.x == -1) && (point.y == -1) )
+ {
+ wxSize size = GetSize();
+ point.x = size.x / 2;
+ point.y = size.y / 2;
+ }
+ else
+ {
+ point = ScreenToClient(point);
+ }
+ ShowContextMenu(point);
+ }
+ else
+ {
+ // the user is editing:
+ // allow the text control to display its context menu
+ // if it has one (it has on Windows) rather than display our one
+ event.Skip();
}
- ShowContextMenu(point);
}
#endif