]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxDataViewListCtrl, use it in the sample
authorRobert Roebling <robert@roebling.de>
Fri, 16 Jan 2009 15:04:00 +0000 (15:04 +0000)
committerRobert Roebling <robert@roebling.de>
Fri, 16 Jan 2009 15:04:00 +0000 (15:04 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58136 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dataview.h
samples/dataview/dataview.cpp
src/common/datavcmn.cpp

index 63a565efc4d744ceb74c29bef657fec7818fee79..37013791d165d1145feb9811c454857b251dd20a 100644 (file)
@@ -959,11 +959,6 @@ public:
     void DeleteItem( unsigned pos );
     void DeleteAllItems();
 
     void DeleteItem( unsigned pos );
     void DeleteAllItems();
 
-    void SetStringValue( const wxString &value, unsigned int row, unsigned int col )
-        { SetValueByRow( value, row, col ); }
-    wxString GetStringValue( unsigned int row, unsigned int col )
-        { wxVariant value; GetValueByRow( value, row, col ); return value.GetString(); }
-
     // override base virtuals
 
     virtual unsigned int GetColumnCount() const;
     // override base virtuals
 
     virtual unsigned int GetColumnCount() const;
@@ -982,6 +977,75 @@ public:
     wxArrayString                      m_cols;
 };
 
     wxArrayString                      m_cols;
 };
 
+//-----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_ADV wxDataViewListCtrl: public wxDataViewCtrl
+{
+public:
+    wxDataViewListCtrl();
+    wxDataViewListCtrl( wxWindow *parent, wxWindowID id,
+           const wxPoint& pos = wxDefaultPosition,
+           const wxSize& size = wxDefaultSize, long style = wxDV_ROW_LINES,
+           const wxValidator& validator = wxDefaultValidator );
+    ~wxDataViewListCtrl();
+
+    bool Create( wxWindow *parent, wxWindowID id,
+           const wxPoint& pos = wxDefaultPosition,
+           const wxSize& size = wxDefaultSize, long style = wxDV_ROW_LINES,
+           const wxValidator& validator = wxDefaultValidator );
+
+    wxDataViewListStore *GetStore()
+        { return (wxDataViewListStore*) GetModel(); }
+    const wxDataViewListStore *GetStore() const
+        { return (const wxDataViewListStore*) GetModel(); }
+
+    void AppendCol( wxDataViewColumn *column, const wxString &varianttype );
+    void PrependCol( wxDataViewColumn *column, const wxString &varianttype );
+    void InsertCol( unsigned int pos, wxDataViewColumn *column, const wxString &varianttype );
+                    
+    wxDataViewColumn *AppendTextCol( const wxString &label, 
+          wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, 
+          int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
+    wxDataViewColumn *AppendToggleCol( const wxString &label, 
+          wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, 
+          int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
+    wxDataViewColumn *AppendProgressCol( const wxString &label, 
+          wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, 
+          int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
+    wxDataViewColumn *AppendIconTextCol( const wxString &label, 
+          wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, 
+          int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
+
+    void AppendItem( const wxVector<wxVariant> &values, wxClientData *data = NULL )
+        { GetStore()->AppendItem( values, data ); }
+    void PrependItem( const wxVector<wxVariant> &values, wxClientData *data = NULL )
+        { GetStore()->PrependItem( values, data ); }
+    void InsertItem(  unsigned int row, const wxVector<wxVariant> &values, wxClientData *data = NULL )
+        { GetStore()->InsertItem( row, values, data ); }
+    void DeleteItem( unsigned row )
+        { GetStore()->DeleteItem( row ); }
+    void DeleteAllItems()
+        { GetStore()->DeleteAllItems(); }
+
+    void SetValue( const wxVariant &value, unsigned int row, unsigned int col )
+        { GetStore()->SetValueByRow( value, row, col ); }
+
+    void SetTextValue( const wxString &value, unsigned int row, unsigned int col )
+        { GetStore()->SetValueByRow( value, row, col ); }
+    wxString GetTextValue( unsigned int row, unsigned int col ) const
+        { wxVariant value; GetStore()->GetValueByRow( value, row, col ); return value.GetString(); }
+
+    void SetToggleValue( bool value, unsigned int row, unsigned int col )
+        { GetStore()->SetValueByRow( value, row, col ); }
+    bool GetToggleValue( unsigned int row, unsigned int col ) const
+        { wxVariant value; GetStore()->GetValueByRow( value, row, col ); return value.GetBool(); }
+
+    void OnSize( wxSizeEvent &event );
+
+private:
+    DECLARE_EVENT_TABLE()
+    DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewListCtrl)
+};
 
 //-----------------------------------------------------------------------------
 // wxDataViewTreeStore
 
 //-----------------------------------------------------------------------------
 // wxDataViewTreeStore
@@ -1127,6 +1191,8 @@ public:
     wxDataViewTreeStoreNode *m_root;
 };
 
     wxDataViewTreeStoreNode *m_root;
 };
 
+//-----------------------------------------------------------------------------
+
 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl
 {
 public:
 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl
 {
 public:
index 37e754170893c98b73127290eae5ab1263d7905f..dc7fbb846d0bc7dd642c7de543ecc9c358cfb5f1 100644 (file)
@@ -331,7 +331,7 @@ public:
         MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
 
         // "MyMusic" also has no parent
         MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
 
         // "MyMusic" also has no parent
-        if (node == m_root || node == NULL)
+        if (node == m_root)
             return wxDataViewItem(0);
 
         return wxDataViewItem( (void*) node->GetParent() );
             return wxDataViewItem(0);
 
         return wxDataViewItem( (void*) node->GetParent() );
@@ -409,7 +409,7 @@ public:
             memcpy( dest, buffer, strlen(buffer)+1 );
             return true;
         }
             memcpy( dest, buffer, strlen(buffer)+1 );
             return true;
         }
-
+    
     wxDataViewItem GetNinthItem()
     {
        return wxDataViewItem( m_ninth );
     wxDataViewItem GetNinthItem()
     {
        return wxDataViewItem( m_ninth );
@@ -819,7 +819,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
 
     SetMenuBar(menu_bar);
     CreateStatusBar();
 
     SetMenuBar(menu_bar);
     CreateStatusBar();
-
+    
     wxPanel *panel = new wxPanel( this, -1 );
 
     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
     wxPanel *panel = new wxPanel( this, -1 );
 
     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
@@ -921,24 +921,26 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
 
     bottom_sizer->Add( m_log, 1, wxGROW );
 
 
     bottom_sizer->Add( m_log, 1, wxGROW );
 
-#if 1
-    // wxDataViewTreeStore
-
-    wxDataViewCtrl *treectrl = new wxDataViewCtrl( panel, -1,
-        wxDefaultPosition, wxSize(100,200), wxDV_NO_HEADER );
-
-    wxDataViewTreeStore *store = new wxDataViewTreeStore;
-    wxDataViewItem parent = store->AppendContainer( wxDataViewItem(0),wxT("Root 1"), wxIcon(small1_xpm) );
-    wxDataViewItem child = store->AppendItem( parent,wxT("Child 1"), wxIcon(small1_xpm) );
-    child = store->AppendItem( parent,wxT("Child 2"), wxIcon(small1_xpm) );
-    child = store->AppendItem( parent,wxT("Child 3, very long, long, long, long"), wxIcon(small1_xpm) );
-    treectrl->AssociateModel( store );
-    store->DecRef();
-
-    treectrl->AppendIconTextColumn( wxT("no label"), 0, wxDATAVIEW_CELL_INERT, -1, (wxAlignment) 0,
-        wxDATAVIEW_COL_RESIZABLE );
-
-    bottom_sizer->Add( treectrl, 1 );
+    // wxDataViewListCtrl
+    
+    wxDataViewListCtrl *listctrl = new wxDataViewListCtrl( panel, -1,
+        wxDefaultPosition, wxSize(100,200) );
+        
+    listctrl->AppendToggleCol( wxT("Toggle") );
+    listctrl->AppendTextCol( wxT("Text") );
+    
+    wxVector<wxVariant> data;
+    data.push_back( true );
+    data.push_back( "row 1" );
+    listctrl->AppendItem( data );
+    
+    data.clear();
+    data.push_back( false );
+    data.push_back( "row 3" );
+    listctrl->AppendItem( data );
+    
+    bottom_sizer->Add( listctrl, 1 );
+    
 
     // wxDataViewTreeCtrl
 
 
     // wxDataViewTreeCtrl
 
@@ -948,13 +950,12 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
     ilist->Add( wxIcon(small1_xpm) );
     treectrl2->SetImageList( ilist );
 
     ilist->Add( wxIcon(small1_xpm) );
     treectrl2->SetImageList( ilist );
 
-    parent = treectrl2->AppendContainer( wxDataViewItem(0),wxT("Root 1"), 0 );
-    child = treectrl2->AppendItem( parent,wxT("Child 1"), 0 );
-    child = treectrl2->AppendItem( parent,wxT("Child 2"), 0 );
-    child = treectrl2->AppendItem( parent,wxT("Child 3, very long, long, long, long"), 0 );
+    wxDataViewItem parent2 = treectrl2->AppendContainer( wxDataViewItem(0),wxT("Root 1"), 0 );
+    wxDataViewItem child2 = treectrl2->AppendItem( parent2, wxT("Child 1"), 0 );
+    child2 = treectrl2->AppendItem( parent2, wxT("Child 2"), 0 );
+    child2 = treectrl2->AppendItem( parent2, wxT("Child 3, very long, long, long, long"), 0 );
 
     bottom_sizer->Add( treectrl2, 1 );
 
     bottom_sizer->Add( treectrl2, 1 );
-#endif
 
     // main sizer
 
 
     // main sizer
 
@@ -1026,7 +1027,7 @@ void MyFrame::OnActivated( wxDataViewEvent &event )
 
     wxString title = m_music_model->GetTitle( event.GetItem() );
     wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item: %s"), title );
 
     wxString title = m_music_model->GetTitle( event.GetItem() );
     wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item: %s"), title );
-
+    
     if (m_musicCtrl->IsExpanded( event.GetItem() ))
     wxLogMessage(wxT("Item: %s is expanded"), title );
 }
     if (m_musicCtrl->IsExpanded( event.GetItem() ))
     wxLogMessage(wxT("Item: %s is expanded"), title );
 }
index 6e84094301b9c711b68c00673110947af2c032d9..b38d9489f60443a529a6a822396e935fe0b9b086 100644 (file)
@@ -1458,6 +1458,94 @@ bool wxDataViewListStore::SetValueByRow( const wxVariant &value, unsigned int ro
     return true;
 }
 
     return true;
 }
 
+//-----------------------------------------------------------------------------
+// wxDataViewListCtrl
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl,wxDataViewCtrl)
+
+BEGIN_EVENT_TABLE(wxDataViewListCtrl,wxDataViewCtrl)
+   EVT_SIZE( wxDataViewListCtrl::OnSize )
+END_EVENT_TABLE()
+
+wxDataViewListCtrl::wxDataViewListCtrl()
+{
+}
+
+wxDataViewListCtrl::wxDataViewListCtrl( wxWindow *parent, wxWindowID id,
+           const wxPoint& pos, const wxSize& size, long style,
+           const wxValidator& validator )
+{
+    Create( parent, id, pos, size, style, validator );
+
+    wxDataViewListStore *store = new wxDataViewListStore;
+    AssociateModel( store );
+    store->DecRef();
+}
+
+wxDataViewListCtrl::~wxDataViewListCtrl()
+{
+}
+
+
+bool wxDataViewListCtrl::Create( wxWindow *parent, wxWindowID id,
+           const wxPoint& pos, const wxSize& size, long style,
+           const wxValidator& validator )
+{
+    return wxDataViewCtrl::Create( parent, id, pos, size, style, validator );
+}
+
+void wxDataViewListCtrl::AppendCol( wxDataViewColumn *column, const wxString &varianttype )
+{
+    GetStore()->AppendColumn( varianttype );
+    AppendColumn( column );
+}
+
+void wxDataViewListCtrl::PrependCol( wxDataViewColumn *column, const wxString &varianttype )
+{
+    GetStore()->PrependColumn( varianttype );
+    PrependColumn( column );
+}
+
+void wxDataViewListCtrl::InsertCol( unsigned int pos, wxDataViewColumn *column, const wxString &varianttype )
+{
+    GetStore()->InsertColumn( pos, varianttype );
+    InsertColumn( pos, column );
+}
+                    
+wxDataViewColumn *wxDataViewListCtrl::AppendTextCol( const wxString &label, 
+          wxDataViewCellMode mode, int width, wxAlignment align, int flags )
+{
+    GetStore()->AppendColumn( wxT("string") );
+    return AppendTextColumn( label, GetStore()->GetColumnCount()-1, mode, width, align, flags );
+}
+
+wxDataViewColumn *wxDataViewListCtrl::AppendToggleCol( const wxString &label, 
+          wxDataViewCellMode mode, int width, wxAlignment align, int flags )
+{
+    GetStore()->AppendColumn( wxT("bool") );
+    return AppendToggleColumn( label, GetStore()->GetColumnCount()-1, mode, width, align, flags );
+}
+
+wxDataViewColumn *wxDataViewListCtrl::AppendProgressCol( const wxString &label, 
+          wxDataViewCellMode mode, int width, wxAlignment align, int flags )
+{
+    GetStore()->AppendColumn( wxT("long") );
+    return AppendProgressColumn( label, GetStore()->GetColumnCount()-1, mode, width, align, flags );
+}
+
+wxDataViewColumn *wxDataViewListCtrl::AppendIconTextCol( const wxString &label, 
+          wxDataViewCellMode mode, int width, wxAlignment align, int flags )
+{
+    GetStore()->AppendColumn( wxT("wxDataViewIconText") );
+    return AppendIconTextColumn( label, GetStore()->GetColumnCount()-1, mode, width, align, flags );
+}
+
+void wxDataViewListCtrl::OnSize( wxSizeEvent &event )
+{
+    event.Skip( true );
+}
+
 //-----------------------------------------------------------------------------
 // wxDataViewTreeStore
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // wxDataViewTreeStore
 //-----------------------------------------------------------------------------