1. fixed bug with the index of the last column in EVT_COL_CLICK being shifted
by 1 (always) 2. added a menu item to toggle single/multiple selection to the sample git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5954 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -52,6 +52,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
EVT_MENU(LIST_SORT, MyFrame::OnSort)
|
EVT_MENU(LIST_SORT, MyFrame::OnSort)
|
||||||
EVT_MENU(LIST_SET_FG_COL, MyFrame::OnSetFgColour)
|
EVT_MENU(LIST_SET_FG_COL, MyFrame::OnSetFgColour)
|
||||||
EVT_MENU(LIST_SET_BG_COL, MyFrame::OnSetBgColour)
|
EVT_MENU(LIST_SET_BG_COL, MyFrame::OnSetBgColour)
|
||||||
|
EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
|
BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
|
||||||
@@ -156,6 +157,9 @@ bool MyApp::OnInit()
|
|||||||
menuList->Append(LIST_SORT, "&Sort\tCtrl-S");
|
menuList->Append(LIST_SORT, "&Sort\tCtrl-S");
|
||||||
menuList->AppendSeparator();
|
menuList->AppendSeparator();
|
||||||
menuList->Append(LIST_DELETE_ALL, "Delete &all items");
|
menuList->Append(LIST_DELETE_ALL, "Delete &all items");
|
||||||
|
menuList->AppendSeparator();
|
||||||
|
menuList->Append(LIST_TOGGLE_MULTI_SEL, "&Multiple selection\tCtrl-M",
|
||||||
|
"Toggle multiple selection", TRUE);
|
||||||
|
|
||||||
wxMenu *menuCol = new wxMenu;
|
wxMenu *menuCol = new wxMenu;
|
||||||
menuCol->Append(LIST_SET_FG_COL, "&Foreground colour...");
|
menuCol->Append(LIST_SET_FG_COL, "&Foreground colour...");
|
||||||
@@ -168,9 +172,15 @@ bool MyApp::OnInit()
|
|||||||
menubar->Append(menuCol, "&Colour");
|
menubar->Append(menuCol, "&Colour");
|
||||||
frame->SetMenuBar(menubar);
|
frame->SetMenuBar(menubar);
|
||||||
|
|
||||||
frame->m_listCtrl = new MyListCtrl(frame, LIST_CTRL, wxPoint(0, 0), wxSize(400, 200),
|
frame->m_listCtrl = new MyListCtrl(frame, LIST_CTRL,
|
||||||
wxLC_LIST|wxSUNKEN_BORDER|wxLC_EDIT_LABELS );
|
wxPoint(0, 0), wxSize(400, 200),
|
||||||
// wxLC_LIST|wxLC_USER_TEXT|wxSUNKEN_BORDER); // wxLC_USER_TEXT requires app to supply all text on demand
|
wxLC_LIST |
|
||||||
|
wxSUNKEN_BORDER |
|
||||||
|
wxLC_EDIT_LABELS |
|
||||||
|
// wxLC_USER_TEXT requires app to supply all text on demand
|
||||||
|
// wxLC_USER_TEXT |
|
||||||
|
wxLC_SINGLE_SEL
|
||||||
|
);
|
||||||
|
|
||||||
frame->m_logWindow = new wxTextCtrl(frame, -1, "", wxPoint(0, 0), wxSize(400, 200), wxTE_MULTILINE|wxSUNKEN_BORDER);
|
frame->m_logWindow = new wxTextCtrl(frame, -1, "", wxPoint(0, 0), wxSize(400, 200), wxTE_MULTILINE|wxSUNKEN_BORDER);
|
||||||
|
|
||||||
@@ -408,6 +418,25 @@ void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event))
|
|||||||
sw.Time()));
|
sw.Time()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnToggleMultiSel(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
m_logWindow->WriteText("Current selection mode: ");
|
||||||
|
|
||||||
|
long flags = m_listCtrl->GetWindowStyleFlag();
|
||||||
|
if ( flags & wxLC_SINGLE_SEL )
|
||||||
|
{
|
||||||
|
m_listCtrl->SetWindowStyleFlag(flags & ~wxLC_SINGLE_SEL);
|
||||||
|
m_logWindow->WriteText("multiple");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_listCtrl->SetWindowStyleFlag(flags | wxLC_SINGLE_SEL);
|
||||||
|
m_logWindow->WriteText("single");
|
||||||
|
}
|
||||||
|
|
||||||
|
m_logWindow->WriteText("\nRecreate the control now\n");
|
||||||
|
}
|
||||||
|
|
||||||
void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
m_listCtrl->SetForegroundColour(wxGetColourFromUser(this));
|
m_listCtrl->SetForegroundColour(wxGetColourFromUser(this));
|
||||||
|
@@ -72,6 +72,7 @@ public:
|
|||||||
void OnSort(wxCommandEvent& event);
|
void OnSort(wxCommandEvent& event);
|
||||||
void OnSetFgColour(wxCommandEvent& event);
|
void OnSetFgColour(wxCommandEvent& event);
|
||||||
void OnSetBgColour(wxCommandEvent& event);
|
void OnSetBgColour(wxCommandEvent& event);
|
||||||
|
void OnToggleMultiSel(wxCommandEvent& event);
|
||||||
|
|
||||||
void BusyOn(wxCommandEvent& event);
|
void BusyOn(wxCommandEvent& event);
|
||||||
void BusyOff(wxCommandEvent& event);
|
void BusyOff(wxCommandEvent& event);
|
||||||
@@ -99,6 +100,7 @@ enum
|
|||||||
LIST_SORT,
|
LIST_SORT,
|
||||||
LIST_SET_FG_COL,
|
LIST_SET_FG_COL,
|
||||||
LIST_SET_BG_COL,
|
LIST_SET_BG_COL,
|
||||||
|
LIST_TOGGLE_MULTI_SEL,
|
||||||
|
|
||||||
LIST_CTRL = 1000
|
LIST_CTRL = 1000
|
||||||
};
|
};
|
||||||
|
@@ -952,7 +952,7 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
|
|||||||
m_minX = 0;
|
m_minX = 0;
|
||||||
bool hit_border = FALSE;
|
bool hit_border = FALSE;
|
||||||
int xpos = 0;
|
int xpos = 0;
|
||||||
for (int j = 0; j < m_owner->GetColumnCount()-1; j++)
|
for (int j = 0; j < m_owner->GetColumnCount(); j++)
|
||||||
{
|
{
|
||||||
xpos += m_owner->GetColumnWidth( j );
|
xpos += m_owner->GetColumnWidth( j );
|
||||||
m_column = j;
|
m_column = j;
|
||||||
|
Reference in New Issue
Block a user