X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/100f649f944be51ddbcc55216a3938186f8f0770..f5058cd7d926d45a6b0673a0b557ca0792f60e48:/samples/listctrl/listtest.cpp diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index 99013eec8f..116212c3bf 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -9,11 +9,6 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation -#pragma interface -#endif - // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" @@ -25,9 +20,11 @@ #include "wx/wx.h" #endif -#ifndef __WXMSW__ +#if !defined(__WXMSW__) && !defined(__WXPM__) #include "mondrian.xpm" +#endif +#ifndef __WXMSW__ #include "bitmaps/toolbrai.xpm" #include "bitmaps/toolchar.xpm" #include "bitmaps/tooldata.xpm" @@ -44,6 +41,7 @@ #include "wx/listctrl.h" #include "wx/timer.h" // for wxStopWatch #include "wx/colordlg.h" // for wxGetColourFromUser +#include "wx/settings.h" #include "listtest.h" @@ -95,7 +93,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(LIST_TOGGLE_LINES, MyFrame::OnToggleLines) EVT_UPDATE_UI(LIST_SHOW_COL_INFO, MyFrame::OnUpdateShowColInfo) - EVT_UPDATE_UI(LIST_TOGGLE_MULTI_SEL, MyFrame::OnUpdateToggleMultiSel) + EVT_UPDATE_UI(LIST_TOGGLE_MULTI_SEL, MyFrame::OnUpdateToggleMultiSel) END_EVENT_TABLE() BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl) @@ -123,6 +121,9 @@ BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl) EVT_LIST_CACHE_HINT(LIST_CTRL, MyListCtrl::OnCacheHint) +#if USE_CONTEXT_MENU + EVT_CONTEXT_MENU(MyListCtrl::OnContextMenu) +#endif EVT_CHAR(MyListCtrl::OnChar) END_EVENT_TABLE() @@ -149,7 +150,7 @@ int wxCALLBACK MyCompareFunction(long item1, long item2, long WXUNUSED(sortData) bool MyApp::OnInit() { // Create the main frame window - MyFrame *frame = new MyFrame(wxT("wxListCtrl Test"), 50, 50, 450, 340); + MyFrame *frame = new MyFrame(wxT("wxListCtrl Test")); // Show the frame frame->Show(true); @@ -160,13 +161,16 @@ bool MyApp::OnInit() } // My frame constructor -MyFrame::MyFrame(const wxChar *title, int x, int y, int w, int h) - : wxFrame(NULL, wxID_ANY, title, wxPoint(x, y), wxSize(w, h)) +MyFrame::MyFrame(const wxChar *title) + : wxFrame(NULL, wxID_ANY, title) { m_listCtrl = NULL; m_logWindow = NULL; m_smallVirtual = false; + if (wxSystemSettings::GetScreenType() > wxSYS_SCREEN_SMALL) + SetSize(wxSize(450, 340)); + // Give it an icon SetIcon( wxICON(mondrian) ); @@ -489,11 +493,22 @@ void MyFrame::InitWithReportItems() m_listCtrl->SetItem( item ); m_listCtrl->SetTextColour(*wxBLUE); - m_listCtrl->SetBackgroundColour(*wxLIGHT_GREY); m_listCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE ); m_listCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE ); m_listCtrl->SetColumnWidth( 2, wxLIST_AUTOSIZE ); + + // Set images in columns + m_listCtrl->SetItemColumnImage(1, 1, 0); + + wxListItem info; + info.SetImage(0); + info.SetId(3); + info.SetColumn(2); + m_listCtrl->SetItem(info); + + // test SetItemFont too + m_listCtrl->SetItemFont(0, *wxITALIC_FONT); } void MyFrame::InitWithIconItems(bool withText, bool sameIcon) @@ -717,7 +732,11 @@ void MyListCtrl::SetColumnImage(int col, int image) void MyListCtrl::OnColClick(wxListEvent& event) { int col = event.GetColumn(); - SetColumnImage(col, 0); + + // set or unset image + static bool x = false; + x = !x; + SetColumnImage(col, x ? 0 : -1); wxLogMessage( wxT("OnColumnClick at %d."), col ); } @@ -733,7 +752,7 @@ void MyListCtrl::OnColRightClick(wxListEvent& event) // Show popupmenu at position wxMenu menu(wxT("Test")); menu.Append(LIST_ABOUT, _T("&About")); - PopupMenu(&menu, event.GetPoint()); + PopupMenu(&menu, event.GetPoint()); wxLogMessage( wxT("OnColumnRightClick at %d."), event.GetColumn() ); } @@ -1009,9 +1028,15 @@ wxString MyListCtrl::OnGetItemText(long item, long column) const } } -int MyListCtrl::OnGetItemImage(long WXUNUSED(item)) const +int MyListCtrl::OnGetItemColumnImage(long item, long column) const { - return 0; + if (!column) + return 0; + + if (!(item %3) && column == 1) + return 0; + + return -1; } wxListItemAttr *MyListCtrl::OnGetItemAttr(long item) const @@ -1027,9 +1052,35 @@ void MyListCtrl::InsertItemInReportView(int i) SetItemData(tmp, i); buf.Printf(_T("Col 1, item %d"), i); - SetItem(i, 1, buf); + SetItem(tmp, 1, buf); buf.Printf(_T("Item %d in column 2"), i); - SetItem(i, 2, buf); + SetItem(tmp, 2, buf); } +#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); + } + ShowContextMenu(point); +} +#endif + +void MyListCtrl::ShowContextMenu(const wxPoint& pos) +{ + wxMenu menu; + + menu.Append(wxID_ABOUT, _T("&About")); + menu.AppendSeparator(); + menu.Append(wxID_EXIT, _T("E&xit")); + + PopupMenu(&menu, pos.x, pos.y); +}