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
This commit is contained in:
Vadim Zeitlin
1999-07-23 23:41:45 +00:00
parent 9be9b97445
commit 5ea4780630
10 changed files with 365 additions and 263 deletions

View File

@@ -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);
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);
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);
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";
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();
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");
}

View File

@@ -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

View File

@@ -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 |
wxTR_HAS_BUTTONS |
wxTR_EDIT_LABELS |
#ifndef NO_ADVANCED_FEATURES
wxTR_MULTIPLE |
wxTR_HAS_VARIABLE_ROW_HEIGHT |
#endif
#if USE_TR_HAS_VARIABLE_ROW_HIGHT
wxTR_HAS_VARIABLE_ROW_HIGHT |
#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.");

View File

@@ -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,