From 5ea4780630b335a1b8b2d3a94c0b82e46f4c56f6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 23 Jul 1999 23:41:45 +0000 Subject: [PATCH] 1. changed spelling error in wxTR_HAS_VARIABLE_HEIGHT (missing 'E') 2. compile fix for dcscreen.cpp 3. editing labels in place works in the tree ctrl and shown in the sample 4. sped up items deletion in the listview git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3110 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/defs.h | 2 +- include/wx/msw/spinbutt.h | 2 +- include/wx/msw/treectrl.h | 12 +- samples/listctrl/listtest.cpp | 403 ++++++++++++++++++---------------- samples/listctrl/listtest.h | 55 ++--- samples/treectrl/treetest.cpp | 67 ++++-- samples/treectrl/treetest.h | 7 + src/msw/dcscreen.cpp | 3 +- src/msw/listctrl.cpp | 20 +- src/msw/treectrl.cpp | 63 ++++-- 10 files changed, 368 insertions(+), 266 deletions(-) diff --git a/include/wx/defs.h b/include/wx/defs.h index ba9105ed99..4b150036b4 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -768,7 +768,7 @@ enum #define wxTR_SINGLE 0x0000 #define wxTR_MULTIPLE 0x0020 #define wxTR_EXTENDED 0x0040 -#define wxTR_HAS_VARIABLE_ROW_HIGHT 0x0080 +#define wxTR_HAS_VARIABLE_ROW_HEIGHT 0x0080 /* * wxListCtrl flags diff --git a/include/wx/msw/spinbutt.h b/include/wx/msw/spinbutt.h index 9f74c568fc..afacb7ea8f 100644 --- a/include/wx/msw/spinbutt.h +++ b/include/wx/msw/spinbutt.h @@ -30,7 +30,7 @@ public: /* * Public interface */ - wxSpinButton(); + wxSpinButton() { } wxSpinButton(wxWindow *parent, wxWindowID id = -1, diff --git a/include/wx/msw/treectrl.h b/include/wx/msw/treectrl.h index b9b401cdbc..5aa9d41162 100644 --- a/include/wx/msw/treectrl.h +++ b/include/wx/msw/treectrl.h @@ -504,12 +504,16 @@ public: // keyboard code (for wxEVT_COMMAND_TREE_KEY_DOWN only) int GetCode() const { return m_code; } + // label (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only) + const wxString& GetLabel() const { return m_label; } + private: - // @@ we could save some space by using union here + // TODO we could save some space by using union here int m_code; wxTreeItemId m_item, m_itemOld; wxPoint m_pointDrag; + wxString m_label; DECLARE_DYNAMIC_CLASS(wxTreeEvent) }; @@ -524,7 +528,11 @@ typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&); #define EVT_TREE_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, #define EVT_TREE_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_TREE_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, -// GetItem() returns the itme whose label is being edited +// GetItem() returns the itme whose label is being edited, GetLabel() returns +// the current item label for BEGIN and the would be new one for END. +// +// Vetoing BEGIN event means that label editing won't happen at all, +// vetoing END means that the new value is discarded and the old one kept #define EVT_TREE_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, #define EVT_TREE_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_TREE_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxTreeEventFunction) & fn, (wxObject *) NULL }, diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index 11857e7add..8e6f0efad2 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -6,7 +6,7 @@ // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -33,32 +33,33 @@ #include "listtest.h" BEGIN_EVENT_TABLE(MyFrame, wxFrame) - EVT_MENU(BUSY_ON, MyFrame::BusyOn) - EVT_MENU(BUSY_OFF, MyFrame::BusyOff) - EVT_MENU(LIST_QUIT, MyFrame::OnQuit) - EVT_MENU(LIST_ABOUT, MyFrame::OnAbout) - EVT_MENU(LIST_LIST_VIEW, MyFrame::OnListView) - EVT_MENU(LIST_REPORT_VIEW, MyFrame::OnReportView) - EVT_MENU(LIST_ICON_VIEW, MyFrame::OnIconView) - EVT_MENU(LIST_ICON_TEXT_VIEW, MyFrame::OnIconTextView) - EVT_MENU(LIST_SMALL_ICON_VIEW, MyFrame::OnSmallIconView) - EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView) - EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll) - EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll) + EVT_MENU(BUSY_ON, MyFrame::BusyOn) + EVT_MENU(BUSY_OFF, MyFrame::BusyOff) + EVT_MENU(LIST_QUIT, MyFrame::OnQuit) + EVT_MENU(LIST_ABOUT, MyFrame::OnAbout) + EVT_MENU(LIST_LIST_VIEW, MyFrame::OnListView) + EVT_MENU(LIST_REPORT_VIEW, MyFrame::OnReportView) + EVT_MENU(LIST_ICON_VIEW, MyFrame::OnIconView) + EVT_MENU(LIST_ICON_TEXT_VIEW, MyFrame::OnIconTextView) + EVT_MENU(LIST_SMALL_ICON_VIEW, MyFrame::OnSmallIconView) + EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView) + EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll) + EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll) + EVT_MENU(LIST_DELETE_ALL, MyFrame::OnDeleteAll) END_EVENT_TABLE() BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl) - EVT_LIST_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnBeginDrag) - EVT_LIST_BEGIN_RDRAG(LIST_CTRL, MyListCtrl::OnBeginRDrag) - EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnBeginLabelEdit) - EVT_LIST_END_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnEndLabelEdit) - EVT_LIST_DELETE_ITEM(LIST_CTRL, MyListCtrl::OnDeleteItem) - EVT_LIST_GET_INFO(LIST_CTRL, MyListCtrl::OnGetInfo) - EVT_LIST_SET_INFO(LIST_CTRL, MyListCtrl::OnSetInfo) - EVT_LIST_ITEM_SELECTED(LIST_CTRL, MyListCtrl::OnSelected) - EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected) - EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown) - EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated) + EVT_LIST_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnBeginDrag) + EVT_LIST_BEGIN_RDRAG(LIST_CTRL, MyListCtrl::OnBeginRDrag) + EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnBeginLabelEdit) + EVT_LIST_END_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnEndLabelEdit) + EVT_LIST_DELETE_ITEM(LIST_CTRL, MyListCtrl::OnDeleteItem) + EVT_LIST_GET_INFO(LIST_CTRL, MyListCtrl::OnGetInfo) + EVT_LIST_SET_INFO(LIST_CTRL, MyListCtrl::OnSetInfo) + EVT_LIST_ITEM_SELECTED(LIST_CTRL, MyListCtrl::OnSelected) + EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected) + EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown) + EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated) END_EVENT_TABLE() IMPLEMENT_APP(MyApp) @@ -91,9 +92,9 @@ bool MyApp::OnInit(void) m_imageListNormal->Add( wxIcon("icon7", wxBITMAP_TYPE_ICO_RESOURCE) ); m_imageListNormal->Add( wxIcon("icon8", wxBITMAP_TYPE_ICO_RESOURCE) ); m_imageListNormal->Add( wxIcon("icon9", wxBITMAP_TYPE_ICO_RESOURCE) ); - + m_imageListSmall->Add( wxIcon("iconsmall", wxBITMAP_TYPE_ICO_RESOURCE) ); - + #else #include "bitmaps/toolbrai.xpm" @@ -114,25 +115,28 @@ bool MyApp::OnInit(void) m_imageListNormal->Add( wxIcon( tooltime_xpm ) ); #include "bitmaps/toolword.xpm" m_imageListNormal->Add( wxIcon( toolword_xpm ) ); - + #include "bitmaps/small1.xpm" m_imageListSmall->Add( wxIcon( small1_xpm) ); - + #endif // Make a menubar wxMenu *file_menu = new wxMenu; - file_menu->Append(LIST_LIST_VIEW, "&List view"); - file_menu->Append(LIST_REPORT_VIEW, "&Report view"); - file_menu->Append(LIST_ICON_VIEW, "&Icon view"); - file_menu->Append(LIST_ICON_TEXT_VIEW, "Icon view with &text"); - file_menu->Append(LIST_SMALL_ICON_VIEW, "&Small icon view"); - file_menu->Append(LIST_SMALL_ICON_TEXT_VIEW, "Small icon &view with text"); + file_menu->Append(LIST_LIST_VIEW, "&List view"); + file_menu->Append(LIST_REPORT_VIEW, "&Report view"); + file_menu->Append(LIST_ICON_VIEW, "&Icon view"); + file_menu->Append(LIST_ICON_TEXT_VIEW, "Icon view with &text"); + file_menu->Append(LIST_SMALL_ICON_VIEW, "&Small icon view"); + file_menu->Append(LIST_SMALL_ICON_TEXT_VIEW, "Small icon &view with text"); file_menu->Append(LIST_DESELECT_ALL, "&Deselect All"); file_menu->Append(LIST_SELECT_ALL, "S&elect All"); - file_menu->Append(BUSY_ON, "&Busy cursor on"); - file_menu->Append(BUSY_OFF, "&Busy cursor off"); + file_menu->AppendSeparator(); + file_menu->Append(LIST_DELETE_ALL, "Delete &all items"); + file_menu->AppendSeparator(); + file_menu->Append(BUSY_ON, "&Busy cursor on"); + file_menu->Append(BUSY_OFF, "&Busy cursor off"); file_menu->AppendSeparator(); file_menu->Append(LIST_ABOUT, "&About"); file_menu->Append(LIST_QUIT, "E&xit"); @@ -142,38 +146,38 @@ bool MyApp::OnInit(void) // Make a panel with a message frame->m_listCtrl = new MyListCtrl(frame, LIST_CTRL, wxPoint(0, 0), wxSize(400, 200), - wxLC_LIST|wxSUNKEN_BORDER); -// wxLC_LIST|wxLC_USER_TEXT|wxSUNKEN_BORDER); // wxLC_USER_TEXT requires app to supply all text on demand + wxLC_LIST|wxSUNKEN_BORDER); +// wxLC_LIST|wxLC_USER_TEXT|wxSUNKEN_BORDER); // wxLC_USER_TEXT requires app to supply all text on demand frame->m_logWindow = new wxTextCtrl(frame, -1, "", wxPoint(0, 0), wxSize(400, 200), wxTE_MULTILINE|wxSUNKEN_BORDER); wxLayoutConstraints *c = new wxLayoutConstraints; - c->top.SameAs (frame, wxTop); - c->left.SameAs (frame, wxLeft); - c->right.SameAs (frame, wxRight); - c->height.PercentOf (frame, wxHeight, 66); + c->top.SameAs (frame, wxTop); + c->left.SameAs (frame, wxLeft); + c->right.SameAs (frame, wxRight); + c->height.PercentOf (frame, wxHeight, 66); frame->m_listCtrl->SetConstraints(c); c = new wxLayoutConstraints; - c->top.Below (frame->m_listCtrl); - c->left.SameAs (frame, wxLeft); - c->right.SameAs (frame, wxRight); - c->bottom.SameAs (frame, wxBottom); + c->top.Below (frame->m_listCtrl); + c->left.SameAs (frame, wxLeft); + c->right.SameAs (frame, wxRight); + c->bottom.SameAs (frame, wxBottom); frame->m_logWindow->SetConstraints(c); frame->SetAutoLayout(TRUE); for ( int i=0; i < 30; i++) - { - wxChar buf[20]; - wxSprintf(buf, _T("Item %d"), i); - frame->m_listCtrl->InsertItem(i, buf); - } + { + wxChar buf[20]; + wxSprintf(buf, _T("Item %d"), i); + frame->m_listCtrl->InsertItem(i, buf); + } frame->CreateStatusBar(3); frame->SetStatusText("", 0); // Show the frame frame->Show(TRUE); - + SetTopWindow(frame); return TRUE; @@ -183,14 +187,14 @@ bool MyApp::OnInit(void) MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h): wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h)) { - m_listCtrl = (MyListCtrl *) NULL; - m_logWindow = (wxTextCtrl *) NULL; + m_listCtrl = (MyListCtrl *) NULL; + m_logWindow = (wxTextCtrl *) NULL; } MyFrame::~MyFrame(void) { - delete wxGetApp().m_imageListNormal; - delete wxGetApp().m_imageListSmall; + delete wxGetApp().m_imageListNormal; + delete wxGetApp().m_imageListSmall; } void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) @@ -210,24 +214,24 @@ void MyFrame::BusyOff(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { - wxMessageDialog dialog(this, "List test sample\nJulian Smart (c) 1997", - "About list test", wxOK|wxCANCEL); + wxMessageDialog dialog(this, "List test sample\nJulian Smart (c) 1997", + "About list test", wxOK|wxCANCEL); - dialog.ShowModal(); + dialog.ShowModal(); } void MyFrame::OnDeselectAll(wxCommandEvent& WXUNUSED(event)) { - int n = m_listCtrl->GetItemCount(); - for (int i = 0; i < n; i++) - m_listCtrl->SetItemState(i,0,wxLIST_STATE_SELECTED); + int n = m_listCtrl->GetItemCount(); + for (int i = 0; i < n; i++) + m_listCtrl->SetItemState(i,0,wxLIST_STATE_SELECTED); } void MyFrame::OnSelectAll(wxCommandEvent& WXUNUSED(event)) { - int n = m_listCtrl->GetItemCount(); - for (int i = 0; i < n; i++) - m_listCtrl->SetItemState(i,wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); + int n = m_listCtrl->GetItemCount(); + for (int i = 0; i < n; i++) + m_listCtrl->SetItemState(i,wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); } void MyFrame::OnListView(wxCommandEvent& WXUNUSED(event)) @@ -240,9 +244,9 @@ void MyFrame::OnListView(wxCommandEvent& WXUNUSED(event)) for ( int i=0; i < 30; i++) { - wxChar buf[20]; - wxSprintf(buf, _T("Item %d"), i); - m_listCtrl->InsertItem(i, buf); + wxChar buf[20]; + wxSprintf(buf, _T("Item %d"), i); + m_listCtrl->InsertItem(i, buf); } } @@ -251,7 +255,7 @@ void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event)) m_listCtrl->DeleteAllItems(); m_listCtrl->DeleteAllColumns(); m_logWindow->Clear(); - + m_listCtrl->SetSingleStyle(wxLC_REPORT); m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_NORMAL); m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL); @@ -260,19 +264,19 @@ void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event)) m_listCtrl->InsertColumn(1, "Column 2"); // , wxLIST_FORMAT_LEFT, 140); m_listCtrl->InsertColumn(2, "One More Column (2)"); // , wxLIST_FORMAT_LEFT, 140); - for ( int i=0; i < 30; i++) + for ( int i = 0; i < 3000; i++ ) { - wxChar buf[50]; - wxSprintf(buf, _T("This is item %d"), i); - long tmp = m_listCtrl->InsertItem(i, buf, 0); - - wxSprintf(buf, _T("Col 1, item %d"), i); - tmp = m_listCtrl->SetItem(i, 1, buf); - - wxSprintf(buf, _T("Item %d in column 2"), i); - tmp = m_listCtrl->SetItem(i, 2, buf); + wxChar buf[50]; + wxSprintf(buf, _T("This is item %d"), i); + long tmp = m_listCtrl->InsertItem(i, buf, 0); + + wxSprintf(buf, _T("Col 1, item %d"), i); + tmp = m_listCtrl->SetItem(i, 1, buf); + + wxSprintf(buf, _T("Item %d in column 2"), i); + tmp = m_listCtrl->SetItem(i, 2, buf); } - + m_listCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE ); m_listCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE ); m_listCtrl->SetColumnWidth( 2, wxLIST_AUTOSIZE ); @@ -280,220 +284,231 @@ void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnIconView(wxCommandEvent& WXUNUSED(event)) { - m_listCtrl->DeleteAllItems(); - m_logWindow->Clear(); - m_listCtrl->SetSingleStyle(wxLC_ICON); + m_listCtrl->DeleteAllItems(); + m_logWindow->Clear(); + m_listCtrl->SetSingleStyle(wxLC_ICON); m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL); m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL); - for ( int i=0; i < 9; i++) - { - m_listCtrl->InsertItem(i, i); - } + for ( int i=0; i < 9; i++) + { + m_listCtrl->InsertItem(i, i); + } } void MyFrame::OnIconTextView(wxCommandEvent& WXUNUSED(event)) { - m_listCtrl->DeleteAllItems(); - m_logWindow->Clear(); - m_listCtrl->SetSingleStyle(wxLC_ICON); + m_listCtrl->DeleteAllItems(); + m_logWindow->Clear(); + m_listCtrl->SetSingleStyle(wxLC_ICON); m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL); m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL); - for ( int i=0; i < 9; i++) - { - wxChar buf[20]; - wxSprintf(buf, _T("Label %d"), i); - m_listCtrl->InsertItem(i, buf, i); - } + for ( int i=0; i < 9; i++) + { + wxChar buf[20]; + wxSprintf(buf, _T("Label %d"), i); + m_listCtrl->InsertItem(i, buf, i); + } } void MyFrame::OnSmallIconView(wxCommandEvent& WXUNUSED(event)) { - m_listCtrl->DeleteAllItems(); - m_logWindow->Clear(); - m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON); + m_listCtrl->DeleteAllItems(); + m_logWindow->Clear(); + m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON); m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL); m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL); - for ( int i=0; i < 9; i++) - { - m_listCtrl->InsertItem(i, 0); - } + for ( int i=0; i < 9; i++) + { + m_listCtrl->InsertItem(i, 0); + } } void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event)) { - m_listCtrl->DeleteAllItems(); - m_logWindow->Clear(); - m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON); + m_listCtrl->DeleteAllItems(); + m_logWindow->Clear(); + m_listCtrl->SetSingleStyle(wxLC_SMALL_ICON); m_listCtrl->SetImageList(wxGetApp().m_imageListNormal, wxIMAGE_LIST_NORMAL); m_listCtrl->SetImageList(wxGetApp().m_imageListSmall, wxIMAGE_LIST_SMALL); - for ( int i=0; i < 9; i++) - { - m_listCtrl->InsertItem(i, "Label", 0); - } + for ( int i=0; i < 9; i++) + { + m_listCtrl->InsertItem(i, "Label", 0); + } +} + +void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event)) +{ + (void)wxGetElapsedTime(TRUE); + + int nItems = m_listCtrl->GetItemCount(); + m_listCtrl->DeleteAllItems(); + + wxLogMessage("Deleting %d items took %ld ms", + nItems, wxGetElapsedTime()); } // MyListCtrl void MyListCtrl::OnBeginDrag(wxListEvent& WXUNUSED(event)) { - if ( !wxGetApp().GetTopWindow() ) - return; + if ( !wxGetApp().GetTopWindow() ) + return; - wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; - if ( !text ) - return; + wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; + if ( !text ) + return; text->WriteText("OnBeginDrag\n"); } void MyListCtrl::OnBeginRDrag(wxListEvent& WXUNUSED(event)) { - if ( !wxGetApp().GetTopWindow() ) - return; + if ( !wxGetApp().GetTopWindow() ) + return; - wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; - if ( !text ) - return; + wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; + if ( !text ) + return; text->WriteText("OnBeginRDrag\n"); } void MyListCtrl::OnBeginLabelEdit(wxListEvent& WXUNUSED(event)) { - if ( !wxGetApp().GetTopWindow() ) - return; + if ( !wxGetApp().GetTopWindow() ) + return; - wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; - if ( !text ) - return; + wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; + if ( !text ) + return; text->WriteText("OnBeginLabelEdit\n"); } void MyListCtrl::OnEndLabelEdit(wxListEvent& WXUNUSED(event)) { - if ( !wxGetApp().GetTopWindow() ) - return; + if ( !wxGetApp().GetTopWindow() ) + return; - wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; - if ( !text ) - return; + wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; + if ( !text ) + return; text->WriteText("OnEndLabelEdit\n"); } void MyListCtrl::OnDeleteItem(wxListEvent& WXUNUSED(event)) { - if ( !wxGetApp().GetTopWindow() ) - return; + if ( !wxGetApp().GetTopWindow() ) + return; - wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; - if ( !text ) - return; + wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; + if ( !text ) + return; text->WriteText("OnDeleteItem\n"); } void MyListCtrl::OnGetInfo(wxListEvent& /*event*/) { - if ( !wxGetApp().GetTopWindow() ) - return; + if ( !wxGetApp().GetTopWindow() ) + return; - wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; - if ( !text ) - return; + wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; + if ( !text ) + return; text->WriteText("OnGetInfo\n"); /* - ostream str(text); - - str << "OnGetInfo (" << event.m_item.m_itemId << ", " << event.m_item.m_col << ")"; - if ( event.m_item.m_mask & wxLIST_MASK_STATE ) - str << " wxLIST_MASK_STATE"; - if ( event.m_item.m_mask & wxLIST_MASK_TEXT ) - str << " wxLIST_MASK_TEXT"; - if ( event.m_item.m_mask & wxLIST_MASK_IMAGE ) - str << " wxLIST_MASK_IMAGE"; - if ( event.m_item.m_mask & wxLIST_MASK_DATA ) - str << " wxLIST_MASK_DATA"; - if ( event.m_item.m_mask & wxLIST_SET_ITEM ) - str << " wxLIST_SET_ITEM"; - if ( event.m_item.m_mask & wxLIST_MASK_WIDTH ) - str << " wxLIST_MASK_WIDTH"; - if ( event.m_item.m_mask & wxLIST_MASK_FORMAT ) - str << " wxLIST_MASK_WIDTH"; - - if ( event.m_item.m_mask & wxLIST_MASK_TEXT ) - { - event.m_item.m_text = "My callback text"; - } - str << "\n"; - str.flush(); + ostream str(text); + + str << "OnGetInfo (" << event.m_item.m_itemId << ", " << event.m_item.m_col << ")"; + if ( event.m_item.m_mask & wxLIST_MASK_STATE ) + str << " wxLIST_MASK_STATE"; + if ( event.m_item.m_mask & wxLIST_MASK_TEXT ) + str << " wxLIST_MASK_TEXT"; + if ( event.m_item.m_mask & wxLIST_MASK_IMAGE ) + str << " wxLIST_MASK_IMAGE"; + if ( event.m_item.m_mask & wxLIST_MASK_DATA ) + str << " wxLIST_MASK_DATA"; + if ( event.m_item.m_mask & wxLIST_SET_ITEM ) + str << " wxLIST_SET_ITEM"; + if ( event.m_item.m_mask & wxLIST_MASK_WIDTH ) + str << " wxLIST_MASK_WIDTH"; + if ( event.m_item.m_mask & wxLIST_MASK_FORMAT ) + str << " wxLIST_MASK_WIDTH"; + + if ( event.m_item.m_mask & wxLIST_MASK_TEXT ) + { + event.m_item.m_text = "My callback text"; + } + str << "\n"; + str.flush(); */ } void MyListCtrl::OnSetInfo(wxListEvent& WXUNUSED(event)) { - if ( !wxGetApp().GetTopWindow() ) - return; + if ( !wxGetApp().GetTopWindow() ) + return; - wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; - if ( !text ) - return; + wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; + if ( !text ) + return; - text->WriteText("OnSetInfo\n"); + text->WriteText("OnSetInfo\n"); } void MyListCtrl::OnSelected(wxListEvent& WXUNUSED(event)) { - if ( !wxGetApp().GetTopWindow() ) - return; + if ( !wxGetApp().GetTopWindow() ) + return; - wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; - if ( !text ) - return; + wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; + if ( !text ) + return; - text->WriteText("OnSelected\n"); + text->WriteText("OnSelected\n"); } void MyListCtrl::OnDeselected(wxListEvent& WXUNUSED(event)) { - if ( !wxGetApp().GetTopWindow() ) - return; + if ( !wxGetApp().GetTopWindow() ) + return; - wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; - if ( !text ) - return; + wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; + if ( !text ) + return; - text->WriteText("OnDeselected\n"); + text->WriteText("OnDeselected\n"); } void MyListCtrl::OnActivated(wxListEvent& WXUNUSED(event)) { - if ( !wxGetApp().GetTopWindow() ) - return; + if ( !wxGetApp().GetTopWindow() ) + return; - wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; - if ( !text ) - return; + wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; + if ( !text ) + return; - text->WriteText("OnActivated\n"); + text->WriteText("OnActivated\n"); } void MyListCtrl::OnListKeyDown(wxListEvent& event) { - if ( !wxGetApp().GetTopWindow() ) - return; + if ( !wxGetApp().GetTopWindow() ) + return; - wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; - if ( !text ) - return; + wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow; + if ( !text ) + return; - text->WriteText("OnListKeyDown\n"); + text->WriteText("OnListKeyDown\n"); } diff --git a/samples/listctrl/listtest.h b/samples/listctrl/listtest.h index f6358de0b3..5818ac6557 100644 --- a/samples/listctrl/listtest.h +++ b/samples/listctrl/listtest.h @@ -6,13 +6,13 @@ // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// // Define a new application type class MyApp: public wxApp { public: - bool OnInit(void); + bool OnInit(); wxImageList *m_imageListNormal; wxImageList *m_imageListSmall; @@ -21,39 +21,40 @@ class MyApp: public wxApp class MyListCtrl: public wxListCtrl { public: - MyListCtrl(wxWindow *parent, const wxWindowID id, const wxPoint& pos, - const wxSize& size, long style): + MyListCtrl(wxWindow *parent, const wxWindowID id, const wxPoint& pos, + const wxSize& size, long style): wxListCtrl(parent, id, pos, size, style) - { - } - - void OnBeginDrag(wxListEvent& event); - void OnBeginRDrag(wxListEvent& event); - void OnBeginLabelEdit(wxListEvent& event); - void OnEndLabelEdit(wxListEvent& event); - void OnDeleteItem(wxListEvent& event); - void OnGetInfo(wxListEvent& event); - void OnSetInfo(wxListEvent& event); - void OnSelected(wxListEvent& event); - void OnDeselected(wxListEvent& event); - void OnListKeyDown(wxListEvent& event); - void OnActivated(wxListEvent& event); + { + } + + void OnBeginDrag(wxListEvent& event); + void OnBeginRDrag(wxListEvent& event); + void OnBeginLabelEdit(wxListEvent& event); + void OnEndLabelEdit(wxListEvent& event); + void OnDeleteItem(wxListEvent& event); + void OnGetInfo(wxListEvent& event); + void OnSetInfo(wxListEvent& event); + void OnSelected(wxListEvent& event); + void OnDeselected(wxListEvent& event); + void OnListKeyDown(wxListEvent& event); + void OnActivated(wxListEvent& event); void OnChar(wxKeyEvent& event); - DECLARE_EVENT_TABLE() + DECLARE_EVENT_TABLE() }; // Define a new frame type class MyFrame: public wxFrame -{ public: +{ +public: MyListCtrl *m_listCtrl; wxTextCtrl *m_logWindow; MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h); - ~MyFrame(void); - - public: + ~MyFrame(); + +public: void OnQuit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); void OnListView(wxCommandEvent& event); @@ -64,14 +65,17 @@ class MyFrame: public wxFrame void OnSmallIconTextView(wxCommandEvent& event); void OnDeselectAll(wxCommandEvent& event); void OnSelectAll(wxCommandEvent& event); + void OnDeleteAll(wxCommandEvent& event); + void BusyOn(wxCommandEvent& event); void BusyOff(wxCommandEvent& event); - DECLARE_EVENT_TABLE() + + DECLARE_EVENT_TABLE() }; // ID for the menu quit command -#define LIST_QUIT 1 +#define LIST_QUIT 1 #define LIST_LIST_VIEW 2 #define LIST_ICON_VIEW 3 #define LIST_ICON_TEXT_VIEW 4 @@ -83,6 +87,7 @@ class MyFrame: public wxFrame #define LIST_ABOUT 102 #define BUSY_ON 10 #define BUSY_OFF 11 +#define LIST_DELETE_ALL 12 #define LIST_CTRL 1000 diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index b4cc70b7a2..c626ea433f 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -35,22 +35,17 @@ #include "treetest.h" -#ifdef wxTR_HAS_VARIABLE_ROW_HIGHT -#define USE_TR_HAS_VARIABLE_ROW_HIGHT 1 -#else -#define USE_TR_HAS_VARIABLE_ROW_HIGHT 0 +#ifdef __WXMSW__ + #define NO_ADVANCED_FEATURES #endif // under Windows the icons are in the .rc file #ifndef __WXMSW__ -#if !USE_TR_HAS_VARIABLE_ROW_HIGHT #include "icon1.xpm" -#endif #include "icon2.xpm" #include "mondrian.xpm" #endif - // verify that the item is ok and insult the user if it is not #define CHECK_ITEM( item ) if ( !item.IsOk() ) { \ wxMessageBox("Please select some item first!", \ @@ -157,9 +152,8 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) tree_menu->Append(TreeTest_IncSpacing, "Add 5 points to spacing\tCtrl-I"); tree_menu->Append(TreeTest_DecSpacing, "Reduce spacing by 5 points\tCtrl-R"); - item_menu->AppendSeparator(); item_menu->Append(TreeTest_Dump, "&Dump item children"); -#ifdef wxTR_MULTIPLE +#ifndef NO_ADVANCED_FEATURES item_menu->Append(TreeTest_Dump_Selected, "Dump selected items\tAlt-S"); #endif item_menu->Append(TreeTest_Rename, "&Rename item..."); @@ -176,14 +170,13 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) m_treeCtrl = new MyTreeCtrl(this, TreeTest_Ctrl, wxDefaultPosition, wxDefaultSize, - wxTR_HAS_BUTTONS | -#ifdef wxTR_MULTIPLE - wxTR_MULTIPLE | -#endif -#if USE_TR_HAS_VARIABLE_ROW_HIGHT - wxTR_HAS_VARIABLE_ROW_HIGHT | + wxTR_HAS_BUTTONS | + wxTR_EDIT_LABELS | +#ifndef NO_ADVANCED_FEATURES + wxTR_MULTIPLE | + wxTR_HAS_VARIABLE_ROW_HEIGHT | #endif - wxSUNKEN_BORDER); + wxSUNKEN_BORDER); wxTextCtrl *textCtrl = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxSUNKEN_BORDER); @@ -231,8 +224,7 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { wxMessageBox("Tree test sample\n" - "Julian Smart (c) 1997,\n" - "Vadim Zeitlin (c) 1998", + "(c) Julian Smart 1997, Vadim Zeitlin 1998", "About tree test", wxOK | wxICON_INFORMATION, this); } @@ -243,6 +235,8 @@ void MyFrame::OnRename(wxCommandEvent& WXUNUSED(event)) CHECK_ITEM( item ); + // old code - now we edit in place +#if 0 static wxString s_text; s_text = wxGetTextFromUser("New name: ", "Tree sample question", s_text, this); @@ -250,6 +244,10 @@ void MyFrame::OnRename(wxCommandEvent& WXUNUSED(event)) { m_treeCtrl->SetItemText(item, s_text); } +#endif // 0 + + // TODO demonstrate creating a custom edit control... + (void)m_treeCtrl->EditLabel(item); } void MyFrame::DoSort(bool reverse) @@ -272,7 +270,7 @@ void MyFrame::OnDump(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnDumpSelected(wxCommandEvent& WXUNUSED(event)) { -#ifdef wxTR_MULTIPLE +#ifndef NO_ADVANCED_FEATURES wxArrayTreeItemIds array; m_treeCtrl->GetSelections(array); @@ -510,8 +508,6 @@ void MyTreeCtrl::name(wxTreeEvent& WXUNUSED(event)) \ TREE_EVENT_HANDLER(OnBeginDrag) TREE_EVENT_HANDLER(OnBeginRDrag) -TREE_EVENT_HANDLER(OnBeginLabelEdit) -TREE_EVENT_HANDLER(OnEndLabelEdit) TREE_EVENT_HANDLER(OnDeleteItem) TREE_EVENT_HANDLER(OnGetInfo) TREE_EVENT_HANDLER(OnSetInfo) @@ -523,13 +519,40 @@ TREE_EVENT_HANDLER(OnSelChanging) #undef TREE_EVENT_HANDLER +void MyTreeCtrl::OnBeginLabelEdit(wxTreeEvent& event) +{ + wxLogMessage("OnBeginLabelEdit"); + + // for testing, prevent this items label editing + wxTreeItemId itemId = event.GetItem(); + if ( IsTestItem(itemId) ) + { + wxMessageBox("You can't edit this item."); + + event.Veto(); + } +} + +void MyTreeCtrl::OnEndLabelEdit(wxTreeEvent& event) +{ + wxLogMessage("OnEndLabelEdit"); + + // don't allow anything except letters in the labels + if ( !event.GetLabel().IsWord() ) + { + wxMessageBox("The label should contain only letters."); + + event.Veto(); + } +} + void MyTreeCtrl::OnItemCollapsing(wxTreeEvent& event) { wxLogMessage("OnItemCollapsing"); // for testing, prevent the user from collapsing the first child folder wxTreeItemId itemId = event.GetItem(); - if ( GetParent(itemId) == GetRootItem() && !GetPrevSibling(itemId) ) + if ( IsTestItem(itemId) ) { wxMessageBox("You can't collapse this item."); diff --git a/samples/treectrl/treetest.h b/samples/treectrl/treetest.h index fdd2e9c720..12c6b2245b 100644 --- a/samples/treectrl/treetest.h +++ b/samples/treectrl/treetest.h @@ -71,6 +71,13 @@ public: protected: virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2); + // is this the test item which we use in several event handlers? + bool IsTestItem(const wxTreeItemId& item) + { + // the test item is the first child folder + return GetParent(item) == GetRootItem() && !GetPrevSibling(item); + } + private: void AddItemsRecursively(const wxTreeItemId& idParent, size_t nChildren, diff --git a/src/msw/dcscreen.cpp b/src/msw/dcscreen.cpp index 470feded37..65f897ccf3 100644 --- a/src/msw/dcscreen.cpp +++ b/src/msw/dcscreen.cpp @@ -23,9 +23,10 @@ #ifndef WX_PRECOMP #include "wx/string.h" #include "wx/window.h" - #include "wx/msw/private.h" #endif +#include "wx/msw/private.h" + #include "wx/dcscreen.h" diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 1470b9659c..811fadec21 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1231,13 +1231,21 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) event.m_col = hdr->iSubItem; break; } + case LVN_DELETEALLITEMS: - { - eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS; - // NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam; - event.m_itemIndex = -1; - break; - } + // what's the sense of generating a wxWin event for this when + // it's absolutely not portable? +#if 0 + eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS; + event.m_itemIndex = -1; +#endif // 0 + + // return TRUE to suppress all additional LVN_DELETEITEM + // notifications - this makes deleting all items from a list ctrl + // much faster + *result = TRUE; + return TRUE; + case LVN_DELETEITEM: { eventType = wxEVT_COMMAND_LIST_DELETE_ITEM; diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index 028f749428..6b89e11968 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -131,8 +131,8 @@ bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, m_windowId = (id == -1) ? NewControlId() : id; - DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | TVS_HASLINES | TVS_SHOWSELALWAYS ; - + DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP | + TVS_HASLINES | TVS_SHOWSELALWAYS; bool want3D; WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ; @@ -792,7 +792,12 @@ wxTextCtrl* wxTreeCtrl::EditLabel(const wxTreeItemId& item, HWND hWnd = (HWND) TreeView_EditLabel(GetHwnd(), (HTREEITEM) (WXHTREEITEM) item); - wxCHECK_MSG( hWnd, NULL, _T("Can't edit tree ctrl label") ); + // this is not an error - the TVN_BEGINLABELEDIT handler might have + // returned FALSE + if ( !hWnd ) + { + return NULL; + } DeleteTextCtrl(); @@ -960,6 +965,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) TV_DISPINFO *info = (TV_DISPINFO *)lParam; event.m_item = (WXHTREEITEM) info->item.hItem; + event.m_label = info->item.pszText; break; } @@ -977,7 +983,8 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) eventType = wxEVT_COMMAND_TREE_END_LABEL_EDIT; TV_DISPINFO *info = (TV_DISPINFO *)lParam; - event.m_item = (WXHTREEITEM) info->item.hItem; + event.m_item = (WXHTREEITEM)info->item.hItem; + event.m_label = info->item.pszText; break; } @@ -1074,18 +1081,46 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) bool processed = GetEventHandler()->ProcessEvent(event); // post processing - if ( hdr->code == TVN_DELETEITEM ) + switch ( hdr->code ) { - // NB: we might process this message using wxWindows event tables, but - // due to overhead of wxWin event system we prefer to do it here - // (otherwise deleting a tree with many items is just too slow) - NM_TREEVIEW* tv = (NM_TREEVIEW *)lParam; - wxTreeItemData *data = (wxTreeItemData *)tv->itemOld.lParam; - delete data; // may be NULL, ok - processed = TRUE; // Make sure we don't get called twice - } + case TVN_DELETEITEM: + { + // NB: we might process this message using wxWindows event + // tables, but due to overhead of wxWin event system we + // prefer to do it here ourself (otherwise deleting a tree + // with many items is just too slow) + NM_TREEVIEW* tv = (NM_TREEVIEW *)lParam; + wxTreeItemData *data = (wxTreeItemData *)tv->itemOld.lParam; + delete data; // may be NULL, ok - *result = !event.IsAllowed(); + processed = TRUE; // Make sure we don't get called twice + } + break; + + case TVN_BEGINLABELEDIT: + // return TRUE to cancel label editing + *result = !event.IsAllowed(); + break; + + case TVN_ENDLABELEDIT: + // return TRUE to set the label to the new string + *result = event.IsAllowed(); + + // ensure that we don't have the text ctrl which is going to be + // deleted any more + DeleteTextCtrl(); + break; + + case TVN_SELCHANGING: + case TVN_ITEMEXPANDING: + // return TRUE to prevent the action from happening + *result = !event.IsAllowed(); + break; + + //default: + // for the other messages the return value is ignored and there is + // nothing special to do + } return processed; } -- 2.45.2