]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/listctrl/listtest.cpp
new makefiles (part I)
[wxWidgets.git] / samples / listctrl / listtest.cpp
index cd7686f53bdc3085fc73cca4cb1cbf36efbf7d86..7e3afcc677042961eb439524d17ee077e04a2eb7 100644 (file)
@@ -55,7 +55,8 @@ BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
        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::OnKeyDown)
+       EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)
+       EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated)
 END_EVENT_TABLE()
 
 IMPLEMENT_APP(MyApp)
@@ -64,7 +65,7 @@ IMPLEMENT_APP(MyApp)
 bool MyApp::OnInit(void)
 {
   // Create the main frame window
-  MyFrame *frame = new MyFrame((wxFrame *) NULL, (char *) "wxListCtrl Test", 50, 50, 450, 340);
+  MyFrame *frame = new MyFrame((wxFrame *) NULL, "wxListCtrl Test", 50, 50, 450, 340);
 
   // This reduces flicker effects - even better would be to define OnEraseBackground
   // to do nothing. When the list control's scrollbars are show or hidden, the
@@ -158,8 +159,8 @@ bool MyApp::OnInit(void)
 
   for ( int i=0; i < 30; i++)
        {
-               char buf[20];
-               sprintf(buf, "Item %d", i);
+               wxChar buf[20];
+               wxSprintf(buf, _T("Item %d"), i);
                frame->m_listCtrl->InsertItem(i, buf);
        }
 
@@ -219,24 +220,24 @@ void MyFrame::OnSelectAll(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::OnListView(wxCommandEvent& WXUNUSED(event))
 {
-       m_logWindow->Clear();
        m_listCtrl->DeleteAllItems();
+       m_logWindow->Clear();
        m_listCtrl->SetSingleStyle(wxLC_LIST);
     m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_NORMAL);
     m_listCtrl->SetImageList((wxImageList *) NULL, wxIMAGE_LIST_SMALL);
 
        for ( int i=0; i < 30; i++)
        {
-               char buf[20];
-               sprintf(buf, "Item %d", i);
+               wxChar buf[20];
+               wxSprintf(buf, _T("Item %d"), i);
                m_listCtrl->InsertItem(i, buf);
        }
 }
 
 void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event))
 {
-       m_logWindow->Clear();
        m_listCtrl->DeleteAllItems();
+       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);
@@ -246,19 +247,19 @@ void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event))
 
        for ( int i=0; i < 30; i++)
        {
-               char buf[20];
-               sprintf(buf, "Item %d, col 1", i);
+               wxChar buf[50];
+               wxSprintf(buf, _T("Item %d, col 1"), i);
                long tmp = m_listCtrl->InsertItem(i, buf, 0);
 
-               sprintf(buf, "Item %d, col 2", i);
+               wxSprintf(buf, _T("Item %d, broad column 2"), i);
                tmp = m_listCtrl->SetItem(i, 1, buf);
        }
 }
 
 void MyFrame::OnIconView(wxCommandEvent& WXUNUSED(event))
 {
-       m_logWindow->Clear();
        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);
@@ -271,24 +272,24 @@ void MyFrame::OnIconView(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::OnIconTextView(wxCommandEvent& WXUNUSED(event))
 {
-       m_logWindow->Clear();
        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++)
        {
-               char buf[20];
-               sprintf(buf, "Label %d", i);
+               wxChar buf[20];
+               wxSprintf(buf, _T("Label %d"), i);
                m_listCtrl->InsertItem(i, buf, i);
        }
 }
 
 void MyFrame::OnSmallIconView(wxCommandEvent& WXUNUSED(event))
 {
-       m_logWindow->Clear();
        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);
@@ -301,8 +302,8 @@ void MyFrame::OnSmallIconView(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event))
 {
-       m_logWindow->Clear();
        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);
@@ -374,7 +375,7 @@ void MyListCtrl::OnDeleteItem(wxListEvent& WXUNUSED(event))
         text->WriteText("OnDeleteItem\n");
 }
 
-void MyListCtrl::OnGetInfo(wxListEvent& event)
+void MyListCtrl::OnGetInfo(wxListEvent& /*event*/)
 {
        if ( !wxGetApp().GetTopWindow() )
                return;
@@ -449,7 +450,7 @@ void MyListCtrl::OnDeselected(wxListEvent& WXUNUSED(event))
        text->WriteText("OnDeselected\n");
 }
 
-void MyListCtrl::OnKeyDown(wxListEvent& WXUNUSED(event))
+void MyListCtrl::OnActivated(wxListEvent& WXUNUSED(event))
 {
        if ( !wxGetApp().GetTopWindow() )
                return;
@@ -458,6 +459,19 @@ void MyListCtrl::OnKeyDown(wxListEvent& WXUNUSED(event))
        if ( !text )
                return;
 
-       text->WriteText("OnKeyDown\n");
+       text->WriteText("OnActivated\n");
 }
 
+void MyListCtrl::OnListKeyDown(wxListEvent& event)
+{
+       if ( !wxGetApp().GetTopWindow() )
+               return;
+
+       wxTextCtrl *text = ((MyFrame *)wxGetApp().GetTopWindow())->m_logWindow;
+       if ( !text )
+               return;
+
+       text->WriteText("OnListKeyDown\n");
+}
+
+