// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
-// Copyright: (c) Julian Smart and Markus Holzem
+// Copyright: (c) Julian Smart
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// number of items in icon/small icon view
static const int NUM_ICONS = 9;
-int wxCALLBACK MyCompareFunction(long item1, long item2, long sortData)
+int wxCALLBACK MyCompareFunction(long item1, long item2, long WXUNUSED(sortData))
{
// inverse the order
- return item1 < item2;
+ if (item1 < item2)
+ return -1;
+ if (item1 > item2)
+ return 1;
+
+ return 0;
}
// `Main program' equivalent, creating windows and returning main app frame
m_imageListSmall = new wxImageList(16, 16, TRUE);
#ifdef __WXMSW__
- m_imageListNormal->Add( wxIcon("icon1", wxBITMAP_TYPE_ICO_RESOURCE) );
- m_imageListNormal->Add( wxIcon("icon2", wxBITMAP_TYPE_ICO_RESOURCE) );
- m_imageListNormal->Add( wxIcon("icon3", wxBITMAP_TYPE_ICO_RESOURCE) );
- m_imageListNormal->Add( wxIcon("icon4", wxBITMAP_TYPE_ICO_RESOURCE) );
- m_imageListNormal->Add( wxIcon("icon5", wxBITMAP_TYPE_ICO_RESOURCE) );
- m_imageListNormal->Add( wxIcon("icon6", wxBITMAP_TYPE_ICO_RESOURCE) );
- 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) );
+ m_imageListNormal->Add( wxIcon(_T("icon1"), wxBITMAP_TYPE_ICO_RESOURCE) );
+ m_imageListNormal->Add( wxIcon(_T("icon2"), wxBITMAP_TYPE_ICO_RESOURCE) );
+ m_imageListNormal->Add( wxIcon(_T("icon3"), wxBITMAP_TYPE_ICO_RESOURCE) );
+ m_imageListNormal->Add( wxIcon(_T("icon4"), wxBITMAP_TYPE_ICO_RESOURCE) );
+ m_imageListNormal->Add( wxIcon(_T("icon5"), wxBITMAP_TYPE_ICO_RESOURCE) );
+ m_imageListNormal->Add( wxIcon(_T("icon6"), wxBITMAP_TYPE_ICO_RESOURCE) );
+ m_imageListNormal->Add( wxIcon(_T("icon7"), wxBITMAP_TYPE_ICO_RESOURCE) );
+ m_imageListNormal->Add( wxIcon(_T("icon8"), wxBITMAP_TYPE_ICO_RESOURCE) );
+ m_imageListNormal->Add( wxIcon(_T("icon9"), wxBITMAP_TYPE_ICO_RESOURCE) );
+
+ m_imageListSmall->Add( wxIcon(_T("iconsmall"), wxBITMAP_TYPE_ICO_RESOURCE) );
#else
m_imageListNormal->Add( wxIcon( toolbrai_xpm ) );
menubar->Append(menuCol, _T("&Colour"));
SetMenuBar(menubar);
- m_logWindow = new wxTextCtrl(this, -1, wxEmptyString,
+ m_panel = new wxPanel(this, -1);
+ m_logWindow = new wxTextCtrl(m_panel, -1, wxEmptyString,
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxSUNKEN_BORDER);
}
void MyFrame::OnSize(wxSizeEvent& event)
+{
+ DoSize();
+
+ event.Skip();
+}
+
+void MyFrame::DoSize()
{
if ( !m_logWindow )
return;
wxCoord y = (2*size.y)/3;
m_listCtrl->SetSize(0, 0, size.x, y);
m_logWindow->SetSize(0, y + 1, size.x, size.y - y);
-
- event.Skip();
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
dialog.ShowModal();
}
-void MyFrame::OnFreeze(wxCommandEvent& event)
+void MyFrame::OnFreeze(wxCommandEvent& WXUNUSED(event))
{
wxLogMessage(_T("Freezing the control"));
m_listCtrl->Freeze();
}
-void MyFrame::OnThaw(wxCommandEvent& event)
+void MyFrame::OnThaw(wxCommandEvent& WXUNUSED(event))
{
wxLogMessage(_T("Thawing the control"));
void MyFrame::OnToggleFirstSel(wxCommandEvent& WXUNUSED(event))
{
- m_listCtrl->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
+ m_listCtrl->SetItemState(0, (~m_listCtrl->GetItemState(0, wxLIST_STATE_SELECTED) ) & wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
}
void MyFrame::OnDeselectAll(wxCommandEvent& WXUNUSED(event))
{
delete m_listCtrl;
- m_listCtrl = new MyListCtrl(this, LIST_CTRL,
+ m_listCtrl = new MyListCtrl(m_panel, LIST_CTRL,
wxDefaultPosition, wxDefaultSize,
flags |
wxSUNKEN_BORDER | wxLC_EDIT_LABELS);
}
}
-#ifdef __WXMSW__
- SendSizeEvent();
-#endif
+ DoSize();
m_logWindow->Clear();
}
{
m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL);
- // under MSW for SetColumnWidth() to work we need to create the items with
- // images initially
-#if 1
+ // note that under MSW for SetColumnWidth() to work we need to create the
+ // items with images initially even if we specify dummy image id
wxListItem itemCol;
- itemCol.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE;
- itemCol.m_text = _T("Column 1");
- itemCol.m_image = -1;
+ itemCol.SetText(_T("Column 1"));
+ itemCol.SetImage(-1);
m_listCtrl->InsertColumn(0, itemCol);
- itemCol.m_text = _T("Column 2");
+
+ itemCol.SetText(_T("Column 2"));
+ itemCol.SetAlign(wxLIST_FORMAT_CENTRE);
m_listCtrl->InsertColumn(1, itemCol);
- itemCol.m_text = _T("Column 3");
+
+ itemCol.SetText(_T("Column 3"));
+ itemCol.SetAlign(wxLIST_FORMAT_RIGHT);
m_listCtrl->InsertColumn(2, itemCol);
-#else
- m_listCtrl->InsertColumn(0, _T("Column 1")); // , wxLIST_FORMAT_LEFT, 140);
- m_listCtrl->InsertColumn(1, _T("Column 2")); // , wxLIST_FORMAT_LEFT, 140);
- m_listCtrl->InsertColumn(2, _T("One More Column (2)")); // , wxLIST_FORMAT_LEFT, 140);
-#endif
// to speed up inserting we hide the control temporarily
m_listCtrl->Hide();
void MyFrame::InitWithVirtualItems()
{
+ m_listCtrl->SetImageList(m_imageListSmall, wxIMAGE_LIST_SMALL);
+
m_listCtrl->InsertColumn(0, _T("First Column"));
m_listCtrl->InsertColumn(1, _T("Second Column"));
m_listCtrl->SetColumnWidth(0, 150);
sw.Time()));
}
-void MyFrame::OnShowSelInfo(wxCommandEvent& event)
+void MyFrame::OnShowSelInfo(wxCommandEvent& WXUNUSED(event))
{
int selCount = m_listCtrl->GetSelectedItemCount();
wxLogMessage(_T("%d items selected:"), selCount);
}
}
-void MyFrame::OnShowColInfo(wxCommandEvent& event)
+void MyFrame::OnShowColInfo(wxCommandEvent& WXUNUSED(event))
{
int count = m_listCtrl->GetColumnCount();
wxLogMessage(wxT("%d columns:"), count);
wxLogMessage( wxT("OnColumnRightClick at %d."), event.GetColumn() );
}
+void MyListCtrl::LogColEvent(const wxListEvent& event, const wxChar *name)
+{
+ const int col = event.GetColumn();
+
+ wxLogMessage(wxT("%s: column %d (width = %d or %d)."),
+ name,
+ col,
+ event.GetItem().GetWidth(),
+ GetColumnWidth(col));
+}
+
void MyListCtrl::OnColBeginDrag(wxListEvent& event)
{
- wxLogMessage( wxT("OnColBeginDrag: column %d."), event.GetColumn() );
+ LogColEvent( event, wxT("OnColBeginDrag") );
+
+ if ( event.GetColumn() == 0 )
+ {
+ wxLogMessage(_T("Resizing this column shouldn't work."));
+
+ event.Veto();
+ }
}
void MyListCtrl::OnColDragging(wxListEvent& event)
{
- wxLogMessage( wxT("OnColDragging: column %d."), event.GetColumn() );
+ LogColEvent( event, wxT("OnColDragging") );
}
void MyListCtrl::OnColEndDrag(wxListEvent& event)
{
- wxLogMessage( wxT("OnColEndDrag: column %d."), event.GetColumn() );
+ LogColEvent( event, wxT("OnColEndDrag") );
}
void MyListCtrl::OnBeginDrag(wxListEvent& event)
void MyListCtrl::OnEndLabelEdit(wxListEvent& event)
{
- wxLogMessage( wxT("OnEndLabelEdit: %s"), event.m_item.m_text.c_str());
+ wxLogMessage( wxT("OnEndLabelEdit: %s"),
+ event.IsEditCancelled() ? _T("[cancelled]")
+ : event.m_item.m_text.c_str());
}
void MyListCtrl::OnDeleteItem(wxListEvent& event)
void MyListCtrl::OnFocused(wxListEvent& event)
{
LogEvent(event, _T("OnFocused"));
+
+ event.Skip();
}
void MyListCtrl::OnListKeyDown(wxListEvent& event)
{
- switch ( event.GetCode() )
+ switch ( event.GetKeyCode() )
{
case 'c': // colorize
case 'C':
return wxString::Format(_T("Column %ld of item %ld"), column, item);
}
-int MyListCtrl::OnGetItemImage(long item) const
+int MyListCtrl::OnGetItemImage(long WXUNUSED(item)) const
{
return 0;
}