X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ebc9b89d52acc331e89b4ab44e51f850d58dbd01..8946ede10c2702c7acbb194fe8bd2793d7fb8358:/samples/listctrl/listtest.cpp?ds=sidebyside diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index c4c71463ac..f18999f66d 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -75,6 +75,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(LIST_VIRTUAL_VIEW, MyFrame::OnVirtualView) EVT_MENU(LIST_SMALL_VIRTUAL_VIEW, MyFrame::OnSmallVirtualView) + EVT_MENU(LIST_GOTO, MyFrame::OnGoTo) EVT_MENU(LIST_FOCUS_LAST, MyFrame::OnFocusLast) EVT_MENU(LIST_TOGGLE_FIRST, MyFrame::OnToggleFirstSel) EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll) @@ -89,6 +90,11 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) 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) @@ -225,6 +231,7 @@ MyFrame::MyFrame(const wxChar *title) #endif wxMenu *menuList = new wxMenu; + menuList->Append(LIST_GOTO, _T("&Go to item #3\tCtrl-3")); menuList->Append(LIST_FOCUS_LAST, _T("&Make last item current\tCtrl-L")); menuList->Append(LIST_TOGGLE_FIRST, _T("To&ggle first item\tCtrl-G")); menuList->Append(LIST_DESELECT_ALL, _T("&Deselect All\tCtrl-D")); @@ -232,8 +239,13 @@ MyFrame::MyFrame(const wxChar *title) 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")); @@ -346,6 +358,18 @@ void MyFrame::OnToggleMacUseGeneric(wxCommandEvent& event) wxSystemOptions::SetOption(wxT("mac.listctrl.always_use_generic"), event.IsChecked()); } +void MyFrame::OnGoTo(wxCommandEvent& WXUNUSED(event)) +{ + long index = 3; + m_listCtrl->SetItemState(index, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); + + long sel = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL, + wxLIST_STATE_SELECTED); + if ( sel != -1 ) + m_listCtrl->SetItemState(sel, 0, wxLIST_STATE_SELECTED); + m_listCtrl->SetItemState(index, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); +} + void MyFrame::OnFocusLast(wxCommandEvent& WXUNUSED(event)) { long index = m_listCtrl->GetItemCount() - 1; @@ -629,6 +653,76 @@ void MyFrame::OnShowSelInfo(wxCommandEvent& WXUNUSED(event)) } } +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(); @@ -816,13 +910,27 @@ void MyListCtrl::OnBeginRDrag(wxListEvent& event) 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) { wxLogMessage( wxT("OnEndLabelEdit: %s"), - event.IsEditCancelled() ? _T("[cancelled]") - : event.m_item.m_text.c_str()); + ( + event.IsEditCancelled() ? + wxString("[cancelled]") : + event.m_item.m_text + ).c_str() + ); } void MyListCtrl::OnDeleteItem(wxListEvent& event) @@ -933,6 +1041,27 @@ void MyListCtrl::OnListKeyDown(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; @@ -953,7 +1082,7 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event) } break; - case WXK_DELETE: + case 'D': // delete item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); while ( item != -1 ) { @@ -967,7 +1096,7 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event) } break; - case WXK_INSERT: + case 'I': // insert if ( GetWindowStyle() & wxLC_REPORT ) { if ( GetWindowStyle() & wxLC_VIRTUAL ) @@ -1002,8 +1131,10 @@ void MyListCtrl::OnChar(wxKeyEvent& event) 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; @@ -1102,16 +1233,29 @@ void MyListCtrl::InsertItemInReportView(int i) #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