Bo's patch adding Selection API and some more changes, doesn't compile yet

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48182 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2007-08-19 19:03:01 +00:00
parent 0c6fcb099e
commit b7e9f8b136
5 changed files with 458 additions and 211 deletions
+28 -6
View File
@@ -2,7 +2,7 @@
// Name: wx/dataview.h
// Purpose: wxDataViewCtrl base classes
// Author: Robert Roebling
// Modified by:
// Modified by: Bo Yang
// Created: 08.01.06
// RCS-ID: $Id$
// Copyright: (c) Robert Roebling
@@ -21,10 +21,11 @@
#include "wx/bitmap.h"
#include "wx/variant.h"
#include "wx/listctrl.h"
#include "wx/dynarray.h"
#if defined(__WXGTK20__)
// for testing
// #define wxUSE_GENERICDATAVIEWCTRL 1
#define wxUSE_GENERICDATAVIEWCTRL 1
#elif defined(__WXMAC__)
#else
#define wxUSE_GENERICDATAVIEWCTRL 1
@@ -44,7 +45,6 @@ class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
class WXDLLIMPEXP_FWD_ADV wxDataViewColumn;
class WXDLLIMPEXP_FWD_ADV wxDataViewRenderer;
class WXDLLIMPEXP_FWD_ADV wxDataViewModelNotifier;
class wxDataViewEventModelNotifier;
extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxDataViewCtrlNameStr[];
@@ -396,6 +396,8 @@ protected:
// wxDataViewCtrlBase
// ---------------------------------------------------------
WX_DECLARE_OBJARRAY(wxDataViewItem, wxDataViewItemArray);
#define wxDV_SINGLE 0x0000 // for convenience
#define wxDV_MULTIPLE 0x0001 // can select multiple items
@@ -472,8 +474,29 @@ public:
int GetIndent() const
{ return m_indent; }
// TODO selection code
virtual wxDataViewItem GetSelection() = 0;
//Selection Code
virtual int GetSelections( wxDataViewItemArray & sel ) const = 0;
virtual void SetSelections( const wxDataViewItemArray & sel ) = 0;
virtual void Select( const wxDataViewItem & item ) = 0;
virtual void Unselect( const wxDataViewItem & item ) = 0;
virtual bool IsSelected( const wxDataViewItem & item ) const = 0;
virtual int GetSelections( wxArrayInt & sel ) const = 0;
virtual void SetSelections( const wxArrayInt & sel ) = 0;
virtual void Select( int row ) = 0;
virtual void Unselect( int row ) = 0;
virtual bool IsSelected( int row ) const = 0;
virtual void SelectRange( int from, int to ) = 0;
virtual void UnselectRange( int from, int to ) = 0;
virtual void SelectAll() = 0;
virtual void UnselectAll() = 0;
virtual void EnsureVisible( int row ) = 0;
virtual void EnsureVisible( const wxDataViewItem & item ) = 0;
virtual wxDataViewItem GetItemByRow( unsigned int row ) const = 0;
virtual int GetRowByItem( const wxDataViewItem & item ) const = 0;
protected:
virtual void DoSetExpanderColumn() = 0 ;
@@ -482,7 +505,6 @@ protected:
private:
wxDataViewModel *m_model;
wxList m_cols;
wxDataViewEventModelNotifier *m_eventNotifier;
unsigned int m_expander_column;
int m_indent ;
+23 -11
View File
@@ -2,6 +2,7 @@
// Name: wx/generic/dataview.h
// Purpose: wxDataViewCtrl generic implementation header
// Author: Robert Roebling
// Modified By: Bo Yang
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
@@ -352,18 +353,29 @@ public:
virtual void DoSetExpanderColumn();
virtual void DoSetIndent();
virtual wxDataViewItem GetSelection() ;
virtual int GetSelections( wxDataViewItemArray & sel ) const;
virtual void SetSelections( const wxDataViewItemArray & sel );
virtual void Select( const wxDataViewItem & item );
virtual void Unselect( const wxDataViewItem & item );
virtual bool IsSelected( const wxDataViewItem & item ) const;
virtual int GetSelections( wxArrayInt & sel ) const;
virtual void SetSelections( const wxArrayInt & sel );
virtual void Select( int row );
virtual void Unselect( int row );
virtual bool IsSelected( int row ) const;
virtual void SelectRange( int from, int to );
virtual void UnselectRange( int from, int to );
virtual void SelectAll();
virtual void UnselectAll();
virtual void EnsureVisible( int row );
virtual void EnsureVisible( const wxDataViewItem & item );
virtual wxDataViewItem GetItemByRow( unsigned int row ) const;
virtual int GetRowByItem( const wxDataViewItem & item ) const;
/********************selection code*********************
virtual void SetSelection( int row ); // -1 for unselect
virtual void SetSelectionRange( unsigned int from, unsigned int to );
virtual void SetSelections( const wxArrayInt& aSelections);
virtual void Unselect( unsigned int row );
virtual bool IsSelected( unsigned int row ) const;
virtual int GetSelection() const;
virtual int GetSelections(wxArrayInt& aSelections) const;
*****************************************************/
public: // utility functions not part of the API
+88 -14
View File
@@ -2,7 +2,7 @@
// Name: dataview.cpp
// Purpose: wxDataViewCtrl wxWidgets sample
// Author: Robert Roebling
// Modified by: Francesco Montorsi
// Modified by: Francesco Montorsi, Bo Yang
// Created: 06/01/06
// RCS-ID: $Id$
// Copyright: (c) Robert Roebling
@@ -146,6 +146,7 @@ public:
// add to data
MyMusicModelNode *child_node =
new MyMusicModelNode( m_classical, title, artist, year );
m_classical->Append( child_node );
if (m_classicalMusicIsKnownToControl)
@@ -164,6 +165,11 @@ public:
// notify control
ItemDeleted( parent, item );
//We must delete the node after we call ItemDeleted
//The reason is that:
//When we use wxSortedArray, the array find a node through binary search for speed.
//And when the array is searching for some node, it call the model's compare function.
//The compare function need the node to be compared. So we should delete the node later, here.
node->GetParent()->GetChildren().Remove( node );
delete node;
}
@@ -417,6 +423,13 @@ public:
void OnValueChanged( wxDataViewEvent &event );
void OnItemAdded( wxDataViewEvent &event );
void OnItemDeleted( wxDataViewEvent &event );
void OnActivated( wxDataViewEvent &event );
void OnHeaderClick( wxDataViewEvent &event );
void OnHeaderRightClick( wxDataViewEvent &event );
void OnSorted( wxDataViewEvent &event );
void OnRightClick( wxMouseEvent &event );
void OnGoto( wxCommandEvent &event);
private:
wxDataViewCtrl* m_musicCtrl;
@@ -426,6 +439,7 @@ private:
wxObjectDataPtr<MyListModel> m_list_model;
wxTextCtrl * m_log;
wxLog *m_logOld;
private:
DECLARE_EVENT_TABLE()
@@ -473,7 +487,8 @@ enum
ID_DELETE_MUSIC = 101,
ID_PREPEND_LIST = 200,
ID_DELETE_LIST = 201
ID_DELETE_LIST = 201,
ID_GOTO = 202
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
@@ -483,9 +498,16 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_BUTTON( ID_DELETE_MUSIC, MyFrame::OnDeleteMusic )
EVT_BUTTON( ID_PREPEND_LIST, MyFrame::OnPrependList )
EVT_BUTTON( ID_DELETE_LIST, MyFrame::OnDeleteList )
EVT_BUTTON( ID_GOTO, MyFrame::OnGoto)
EVT_DATAVIEW_MODEL_ITEM_ADDED( ID_MUSIC_CTRL, MyFrame::OnItemAdded )
EVT_DATAVIEW_MODEL_ITEM_DELETED( ID_MUSIC_CTRL, MyFrame::OnItemDeleted )
EVT_DATAVIEW_MODEL_VALUE_CHANGED( ID_MUSIC_CTRL, MyFrame::OnValueChanged )
EVT_DATAVIEW_MODEL_ITEM_CHANGED( ID_MUSIC_CTRL, MyFrame::OnValueChanged )
EVT_DATAVIEW_ITEM_ACTIVATED(ID_MUSIC_CTRL, MyFrame::OnActivated )
EVT_DATAVIEW_COLUMN_HEADER_CLICK(ID_MUSIC_CTRL, MyFrame::OnHeaderClick)
EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(ID_MUSIC_CTRL, MyFrame::OnHeaderRightClick)
EVT_DATAVIEW_COLUMN_SORTED(ID_MUSIC_CTRL, MyFrame::OnSorted)
EVT_RIGHT_UP(MyFrame::OnRightClick)
END_EVENT_TABLE()
MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
@@ -515,7 +537,7 @@ MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
// MyMusic
m_musicCtrl = new wxDataViewCtrl( this, ID_MUSIC_CTRL, wxDefaultPosition,
wxDefaultSize );
wxDefaultSize, wxDV_MULTIPLE );
m_music_model = new MyMusicModel;
m_musicCtrl->AssociateModel( m_music_model.get() );
@@ -534,7 +556,7 @@ MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
// MyList
m_listCtrl = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition,
wxDefaultSize );
wxDefaultSize, wxDV_MULTIPLE );
m_list_model = new MyListModel;
m_listCtrl->AssociateModel( m_list_model.get() );
@@ -555,11 +577,14 @@ MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
button_sizer->Add( 10, 10, 1 );
button_sizer->Add( new wxButton( this, ID_PREPEND_LIST, "Prepend"), 0, wxALL, 10 );
button_sizer->Add( new wxButton( this, ID_DELETE_LIST, "Delete selected"), 0, wxALL, 10 );
button_sizer->Add( new wxButton( this, ID_GOTO, "Goto 50"), 0, wxALL, 10 );
main_sizer->Add( button_sizer, 0, wxGROW, 0 );
m_log = new wxTextCtrl( this, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_log));
wxLogMessage("This is the log window");
main_sizer->Add( m_log, 1, wxGROW );
SetSizer( main_sizer );
@@ -577,9 +602,11 @@ void MyFrame::OnAddMozart(wxCommandEvent& WXUNUSED(event) )
void MyFrame::OnDeleteMusic(wxCommandEvent& WXUNUSED(event) )
{
wxDataViewItem item = m_musicCtrl->GetSelection();
if (item.IsOk())
m_music_model->Delete( item );
wxDataViewItemArray items;
int len = m_musicCtrl->GetSelections( items );
for( int i = 0; i < len; i ++ )
if (items[i].IsOk())
m_music_model->Delete( items[i] );
}
void MyFrame::OnPrependList( wxCommandEvent& WXUNUSED(event) )
@@ -589,9 +616,11 @@ void MyFrame::OnPrependList( wxCommandEvent& WXUNUSED(event) )
void MyFrame::OnDeleteList( wxCommandEvent& WXUNUSED(event) )
{
wxDataViewItem item = m_listCtrl->GetSelection();
if (item.IsOk())
m_list_model->DeleteItem( item );
wxDataViewItemArray items;
int len = m_listCtrl->GetSelections( items );
for( int i = 0; i < len; i ++ )
if (items[i].IsOk())
m_list_model->DeleteItem( items[i] );
}
void MyFrame::OnItemAdded( wxDataViewEvent &event )
@@ -599,7 +628,7 @@ void MyFrame::OnItemAdded( wxDataViewEvent &event )
if (!m_log)
return;
m_log->AppendText( "EVT_DATAVIEW_MODEL_ITEM_ADDED\n" );
wxLogMessage("wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED, Item Id: %d",event.GetItem().GetID());
}
void MyFrame::OnItemDeleted( wxDataViewEvent &event )
@@ -607,7 +636,7 @@ void MyFrame::OnItemDeleted( wxDataViewEvent &event )
if (!m_log)
return;
m_log->AppendText( "EVT_DATAVIEW_MODEL_ITEM_DELETED\n" );
wxLogMessage( "EVT_DATAVIEW_MODEL_ITEM_DELETED, Item Id: %d", event.GetItem().GetID() );
}
void MyFrame::OnValueChanged( wxDataViewEvent &event )
@@ -615,7 +644,52 @@ void MyFrame::OnValueChanged( wxDataViewEvent &event )
if (!m_log)
return;
m_log->AppendText( "EVT_DATAVIEW_MODEL_VALUE_CHANGED\n" );
wxLogMessage( "EVT_DATAVIEW_MODEL_VALUE_CHANGED, Item Id: %d; Column: %d", event.GetItem().GetID(), event.GetColumn() );
}
void MyFrame::OnActivated( wxDataViewEvent &event )
{
if(!m_log)
return;
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item Id: %d; Column: %d", event.GetItem().GetID(), event.GetColumn());
}
void MyFrame::OnHeaderClick( wxDataViewEvent &event )
{
if(!m_log)
return;
wxLogMessage("wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, Column: %d", event.GetColumn());
}
void MyFrame::OnHeaderRightClick( wxDataViewEvent &event )
{
if(!m_log)
return;
wxLogMessage("wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, Column: %d", event.GetColumn());
}
void MyFrame::OnSorted( wxDataViewEvent &event )
{
if(!m_log)
return;
wxLogMessage("wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, Column: %d", event.GetColumn());
}
void MyFrame::OnRightClick( wxMouseEvent &event )
{
if(!m_log)
return;
wxLogMessage("wxEVT_MOUSE_RIGHT_UP, Click Point is X: %d, Y: %d", event.GetX(), event.GetY());
}
void MyFrame::OnGoto( wxCommandEvent &event)
{
m_listCtrl->EnsureVisible(50);
}
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
+3
View File
@@ -533,6 +533,9 @@ void wxDataViewColumnBase::SetFlags(int flags)
// wxDataViewCtrlBase
// ---------------------------------------------------------
#include "wx/arrimpl.cpp"
WX_DEFINE_OBJARRAY(wxDataViewItemArray);
IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl)
wxDataViewCtrlBase::wxDataViewCtrlBase()
+316 -180
View File
File diff suppressed because it is too large Load Diff