#if wxUSE_DATAVIEWCTRL
-#include "wx/control.h"
#include "wx/textctrl.h"
#include "wx/headercol.h"
#include "wx/variant.h"
#include "wx/dynarray.h"
#include "wx/icon.h"
-#include "wx/imaglist.h"
#include "wx/weakref.h"
#include "wx/vector.h"
+#include "wx/dataobj.h"
+
+class WXDLLIMPEXP_FWD_CORE wxImageList;
#if !(defined(__WXGTK20__) || defined(__WXMAC__)) || defined(__WXUNIVERSAL__)
// #if !(defined(__WXMAC__)) || defined(__WXUNIVERSAL__)
#define wxHAS_GENERIC_DATAVIEWCTRL
#endif
-class WXDLLIMPEXP_FWD_CORE wxDataFormat;
-
// ----------------------------------------------------------------------------
// wxDataViewCtrl flags
// ----------------------------------------------------------------------------
const wxDataViewColumn *column = NULL ) = 0;
virtual void HitTest( const wxPoint & point, wxDataViewItem &item, wxDataViewColumn* &column ) const = 0;
virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const = 0;
-
+
virtual bool EnableDragSource( const wxDataFormat &format );
virtual bool EnableDropTarget( const wxDataFormat &format );
// For drag operations
void SetDataObject( wxDataObject *obj ) { m_dataObject = obj; }
wxDataObject *GetDataObject() const { return m_dataObject; }
-
+
// For drop operations
void SetDataFormat( const wxDataFormat &format ) { m_dataFormat = format; }
wxDataFormat GetDataFormat() const { return m_dataFormat; }
wxVariant m_value;
wxDataViewColumn *m_column;
wxPoint m_pos;
-
+
wxDataObject *m_dataObject;
-
+
wxDataFormat m_dataFormat;
void* m_dataBuffer;
size_t m_dataSize;
{ if (m_data) delete m_data; m_data = data; }
wxClientData *GetData() const
{ return m_data; }
-
+
wxVector<wxVariant> m_values;
-
+
private:
wxClientData *m_data;
};
void PrependColumn( const wxString &varianttype );
void InsertColumn( unsigned int pos, const wxString &varianttype );
void AppendColumn( const wxString &varianttype );
-
+
void AppendItem( const wxVector<wxVariant> &values, wxClientData *data = NULL );
void PrependItem( const wxVector<wxVariant> &values, wxClientData *data = NULL );
void InsertItem( unsigned int row, const wxVector<wxVariant> &values, wxClientData *data = NULL );
virtual bool SetValueByRow( const wxVariant &value,
unsigned int row, unsigned int col );
-
+
public:
wxVector<wxDataViewListStoreLine*> m_data;
wxArrayString m_cols;
bool AppendColumn( wxDataViewColumn *column, const wxString &varianttype );
bool PrependColumn( wxDataViewColumn *column, const wxString &varianttype );
bool InsertColumn( unsigned int pos, wxDataViewColumn *column, const wxString &varianttype );
-
+
// overridden from base class
virtual bool PrependColumn( wxDataViewColumn *col );
virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
virtual bool IsExpanded( const wxDataViewItem & item ) const;
virtual bool EnableDragSource( const wxDataFormat &format );
+ virtual bool EnableDropTarget( const wxDataFormat &format );
static wxVisualAttributes
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
#include "wx/wx.h"
#endif
+#include "wx/dataview.h"
#include "wx/datetime.h"
#include "wx/splitter.h"
#include "wx/aboutdlg.h"
#include "wx/choicdlg.h"
#include "wx/numdlg.h"
-#include "wx/dataview.h"
#include "wx/spinctrl.h"
-#include "wx/menu.h"
+#include "wx/imaglist.h"
#ifndef __WXMSW__
#include "../sample.xpm"
};
-#define DEFAULT_ALIGN wxALIGN_LEFT
-#define DATAVIEW_DEFAULT_STYLE (wxDV_MULTIPLE|wxDV_HORIZ_RULES|wxDV_VERT_RULES)
-
// -------------------------------------
// MyMusicModel
// -------------------------------------
void OnRightClick( wxMouseEvent &event );
void OnGoto( wxCommandEvent &event);
void OnAddMany( wxCommandEvent &event);
-
+
void OnBeginDrag( wxDataViewEvent &event );
void OnDropPossible( wxDataViewEvent &event );
void OnDrop( wxDataViewEvent &event );
EVT_DATAVIEW_COLUMN_SORTED(ID_MUSIC_CTRL, MyFrame::OnSorted)
EVT_DATAVIEW_ITEM_CONTEXT_MENU(ID_MUSIC_CTRL, MyFrame::OnContextMenu)
-
+
EVT_DATAVIEW_ITEM_BEGIN_DRAG( ID_MUSIC_CTRL, MyFrame::OnBeginDrag )
EVT_DATAVIEW_ITEM_DROP_POSSIBLE( ID_MUSIC_CTRL, MyFrame::OnDropPossible )
EVT_DATAVIEW_ITEM_DROP( ID_MUSIC_CTRL, MyFrame::OnDrop )
SetMenuBar(menu_bar);
CreateStatusBar();
-
+
wxPanel *panel = new wxPanel( this, -1 );
wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
m_music_model = new MyMusicModel;
m_musicCtrl->AssociateModel( m_music_model.get() );
-
+
m_musicCtrl->EnableDragSource( wxDF_TEXT );
m_musicCtrl->EnableDropTarget( wxDF_TEXT );
bottom_sizer->Add( m_log, 1, wxGROW );
// wxDataViewListCtrl
-
+
wxDataViewListCtrl *listctrl = new wxDataViewListCtrl( panel, -1,
wxDefaultPosition, wxSize(100,200) );
-
+
listctrl->AppendToggleColumn( wxT("Toggle") );
listctrl->AppendTextColumn( 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
treectrl2->SetImageList( ilist );
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 );
+ treectrl2->AppendItem( parent2, wxT("Child 1"), 0 );
+ treectrl2->AppendItem( parent2, wxT("Child 2"), 0 );
+ treectrl2->AppendItem( parent2, wxT("Child 3, very long, long, long, long"), 0 );
bottom_sizer->Add( treectrl2, 1 );
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 );
+ wxLogMessage(wxT("Item: %s is expanded"), title );
}
void MyFrame::OnSelectionChanged( wxDataViewEvent &event )
void MyFrame::OnBeginDrag( wxDataViewEvent &event )
{
wxDataViewItem item( event.GetItem() );
-
+
// only allow drags for item, not containers
if (m_music_model->IsContainer( item ) )
{
event.Veto();
return;
}
-
+
MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
wxTextDataObject *obj = new wxTextDataObject;
obj->SetText( node->m_title );
void MyFrame::OnDropPossible( wxDataViewEvent &event )
{
wxDataViewItem item( event.GetItem() );
-
+
// only allow drags for item, not containers
if (m_music_model->IsContainer( item ) )
event.Veto();
-
+
if (event.GetDataFormat() != wxDF_TEXT)
event.Veto();
}
void MyFrame::OnDrop( wxDataViewEvent &event )
{
wxDataViewItem item( event.GetItem() );
-
+
// only allow drops for item, not containers
if (m_music_model->IsContainer( item ) )
{
event.Veto();
return;
}
-
+
if (event.GetDataFormat() != wxDF_TEXT)
{
event.Veto();
return;
}
-
+
wxTextDataObject obj;
obj.SetData( wxDF_TEXT, event.GetDataSize(), event.GetDataBuffer() );
-
+
wxLogMessage(wxT("Text dropped: %s"), obj.GetText() );
}
#if wxUSE_DATAVIEWCTRL
#include "wx/dataview.h"
-#include "wx/spinctrl.h"
-#include "wx/choice.h"
-
-#include "wx/weakref.h"
-#include "wx/vector.h"
#ifndef WX_PRECOMP
#include "wx/dc.h"
#include "wx/settings.h"
#include "wx/log.h"
- #include "wx/icon.h"
#include "wx/crt.h"
#endif
+#include "wx/spinctrl.h"
+#include "wx/imaglist.h"
+
const char wxDataViewCtrlNameStr[] = "dataviewCtrl";
void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem & item )
{
if (!m_model) return;
-
+
if (!item.IsOk()) return;
wxVector<wxDataViewItem> parentChain;
-
+
// at first we get all the parents of the selected item
wxDataViewItem parent = m_model->GetParent(item);
while (parent.IsOk())
parentChain.push_back(parent);
parent = m_model->GetParent(parent);
}
-
+
// then we expand the parents, starting at the root
while (!parentChain.empty())
{
{
return m_cols[pos];
}
-
+
void wxDataViewListStore::AppendItem( const wxVector<wxVariant> &values, wxClientData *data )
{
wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
line->m_values = values;
m_data.push_back( line );
-
+
RowAppended();
}
wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
line->m_values = values;
m_data.insert( m_data.begin(), line );
-
+
RowPrepended();
}
wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
line->m_values = values;
m_data.insert( m_data.begin()+row, line );
-
+
RowInserted( row );
}
{
wxVector<wxDataViewListStoreLine*>::iterator it = m_data.begin() + row;
m_data.erase( it );
-
+
RowDeleted( row );
}
wxDataViewListStoreLine* line = *it;
delete line;
}
-
+
Reset( 0 );
}
{
wxDataViewListStoreLine *line = m_data[row];
line->m_values[col] = value;
-
+
return true;
}
{
return AppendColumn( col, "string" );
}
-
+
wxDataViewColumn *wxDataViewListCtrl::AppendTextColumn( const wxString &label,
wxDataViewCellMode mode, int width, wxAlignment align, int flags )
{
GetStore()->AppendColumn( wxT("string") );
-
+
wxDataViewColumn *ret = new wxDataViewColumn( label,
new wxDataViewTextRenderer( wxT("string"), mode ),
GetStore()->GetColumnCount()-1, width, align, flags );
-
+
wxDataViewCtrl::AppendColumn( ret );
-
+
return ret;
}
wxDataViewCellMode mode, int width, wxAlignment align, int flags )
{
GetStore()->AppendColumn( wxT("bool") );
-
+
wxDataViewColumn *ret = new wxDataViewColumn( label,
new wxDataViewToggleRenderer( wxT("bool"), mode ),
GetStore()->GetColumnCount()-1, width, align, flags );
-
+
wxDataViewCtrl::AppendColumn( ret );
-
+
return ret;
}
wxDataViewCellMode mode, int width, wxAlignment align, int flags )
{
GetStore()->AppendColumn( wxT("long") );
-
+
wxDataViewColumn *ret = new wxDataViewColumn( label,
new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
GetStore()->GetColumnCount()-1, width, align, flags );
-
+
wxDataViewCtrl::AppendColumn( ret );
-
+
return ret;
}
wxDataViewCellMode mode, int width, wxAlignment align, int flags )
{
GetStore()->AppendColumn( wxT("wxDataViewIconText") );
-
+
wxDataViewColumn *ret = new wxDataViewColumn( label,
new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
GetStore()->GetColumnCount()-1, width, align, flags );
-
+
wxDataViewCtrl::AppendColumn( ret );
-
+
return ret;
}
{
wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
if (!parent_node) return wxDataViewItem(0);
-
+
wxDataViewTreeStoreNode *previous_node = FindNode( previous );
int pos = parent_node->GetChildren().IndexOf( previous_node );
if (pos == wxNOT_FOUND) return wxDataViewItem(0);
-
+
wxDataViewTreeStoreContainerNode *node =
new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
parent_node->GetChildren().Insert( (size_t) pos, node );
icon = m_imageList->GetIcon( iconIndex );
wxDataViewItem res = GetStore()->AppendItem( parent, text, icon, data );
-
+
GetStore()->ItemAdded( parent, res );
-
+
return res;
}
icon = m_imageList->GetIcon( iconIndex );
wxDataViewItem res = GetStore()->PrependItem( parent, text, icon, data );
-
+
GetStore()->ItemAdded( parent, res );
-
+
return res;
}
icon = m_imageList->GetIcon( iconIndex );
wxDataViewItem res = GetStore()->InsertItem( parent, previous, text, icon, data );
-
+
GetStore()->ItemAdded( parent, res );
-
+
return res;
}
expanded = m_imageList->GetIcon( expandedIndex );
wxDataViewItem res = GetStore()->PrependContainer( parent, text, icon, expanded, data );
-
+
GetStore()->ItemAdded( parent, res );
-
+
return res;
}
expanded = m_imageList->GetIcon( expandedIndex );
wxDataViewItem res = GetStore()->AppendContainer( parent, text, icon, expanded, data );
-
+
GetStore()->ItemAdded( parent, res );
-
+
return res;
}
expanded = m_imageList->GetIcon( expandedIndex );
wxDataViewItem res = GetStore()->InsertContainer( parent, previous, text, icon, expanded, data );
-
+
GetStore()->ItemAdded( parent, res );
-
+
return res;
}
void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem& item, const wxString &text )
{
GetStore()->SetItemText(item,text);
-
+
// notify control
GetStore()->ValueChanged( item, 0 );
}
void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon )
{
GetStore()->SetItemIcon(item,icon);
-
+
// notify control
GetStore()->ValueChanged( item, 0 );
}
void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon )
{
GetStore()->SetItemExpandedIcon(item,icon);
-
+
// notify control
GetStore()->ValueChanged( item, 0 );
}
wxDataViewItem parent_item = GetStore()->GetParent( item );
GetStore()->DeleteItem(item);
-
+
// notify control
GetStore()->ItemDeleted( parent_item, item );
}
void wxDataViewTreeCtrl::DeleteAllItems()
{
GetStore()->DeleteAllItems();
-
+
GetStore()->Cleared();
}
if (!container) return;
container->SetExpanded( true );
-
+
GetStore()->ItemChanged( event.GetItem() );
}
if (!container) return;
container->SetExpanded( false );
-
+
GetStore()->ItemChanged( event.GetItem() );
}
#include "wx/log.h"
#include "wx/dcclient.h"
#include "wx/sizer.h"
- #include "wx/icon.h"
- #include "wx/list.h"
#include "wx/settings.h"
- #include "wx/dataobj.h"
#include "wx/crt.h"
#endif
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-class wxDataViewCtrlInternal;
-
-wxDataViewCtrlInternal *g_internal = NULL;
+static wxDataViewCtrlInternal *gs_internal = NULL;
class wxGtkTreeModelNode;
WX_DECLARE_LIST(wxDataViewItem, ItemList);
WX_DEFINE_LIST(ItemList)
-class wxDataViewCtrlInternal
+class WXDLLIMPEXP_ADV wxDataViewCtrlInternal
{
public:
wxDataViewCtrlInternal( wxDataViewCtrl *owner, wxDataViewModel *wx_model, GtkWxTreeModel *gtk_model );
gboolean iter_parent( GtkTreeIter *iter, GtkTreeIter *child );
// dnd iface
-
+
bool EnableDragSource( const wxDataFormat &format );
bool EnableDropTarget( const wxDataFormat &format );
-
+
gboolean row_draggable( GtkTreeDragSource *drag_source, GtkTreePath *path );
gboolean drag_data_delete( GtkTreeDragSource *drag_source, GtkTreePath* path );
gboolean drag_data_get( GtkTreeDragSource *drag_source, GtkTreePath *path,
GtkSortType m_sort_order;
wxDataViewColumn *m_dataview_sort_column;
int m_sort_column;
-
+
GtkTargetEntry m_dragSourceTargetEntry;
wxCharBuffer m_dragSourceTargetEntryTarget;
wxDataObject *m_dragDataObject;
-
+
GtkTargetEntry m_dropTargetTargetEntry;
wxCharBuffer m_dropTargetTargetEntryTarget;
wxDataObject *m_dropDataObject;
// wxGtkTreeModelNode
//-----------------------------------------------------------------------------
+static
int LINKAGEMODE wxGtkTreeModelChildCmp( void** id1, void** id2 )
{
- int ret = g_internal->GetDataViewModel()->Compare( *id1, *id2,
- g_internal->GetSortColumn(), (g_internal->GetSortOrder() == GTK_SORT_ASCENDING) );
+ int ret = gs_internal->GetDataViewModel()->Compare( *id1, *id2,
+ gs_internal->GetSortColumn(), (gs_internal->GetSortOrder() == GTK_SORT_ASCENDING) );
return ret;
}
if (m_internal->IsSorted() || m_internal->GetDataViewModel()->HasDefaultCompare())
{
- g_internal = m_internal;
+ gs_internal = m_internal;
m_children.Sort( &wxGtkTreeModelChildCmp );
return m_children.Index( id );
}
if (m_internal->IsSorted() || m_internal->GetDataViewModel()->HasDefaultCompare())
{
- g_internal = m_internal;
+ gs_internal = m_internal;
m_children.Sort( &wxGtkTreeModelChildCmp );
return m_children.Index( id );
}
wxGtkTreeModelChildren temp;
WX_APPEND_ARRAY( temp, m_children );
- g_internal = m_internal;
+ gs_internal = m_internal;
m_children.Sort( &wxGtkTreeModelChildCmp );
gint *new_order = new gint[child_count];
m_sort_order = GTK_SORT_ASCENDING;
m_sort_column = -1;
m_dataview_sort_column = NULL;
-
+
m_dragDataObject = NULL;
m_dropDataObject = NULL;
wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
{
g_object_unref( m_gtk_model );
-
+
delete m_dragDataObject;
delete m_dropDataObject;
}
{
wxGtkString atom_str( gdk_atom_name( format ) );
m_dragSourceTargetEntryTarget = wxCharBuffer( atom_str );
-
+
m_dragSourceTargetEntry.target = m_dragSourceTargetEntryTarget.data();
m_dragSourceTargetEntry.flags = 0;
m_dragSourceTargetEntry.info = static_cast<guint>(-1);
-
+
gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner->GtkGetTreeView() ),
GDK_BUTTON1_MASK, &m_dragSourceTargetEntry, 1, (GdkDragAction) GDK_ACTION_COPY );
-
+
return true;
}
{
wxGtkString atom_str( gdk_atom_name( format ) );
m_dropTargetTargetEntryTarget = wxCharBuffer( atom_str );
-
+
m_dropTargetTargetEntry.target = m_dragSourceTargetEntryTarget.data();
m_dropTargetTargetEntry.flags = 0;
m_dropTargetTargetEntry.info = static_cast<guint>(-1);
-
+
gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner->GtkGetTreeView() ),
&m_dropTargetTargetEntry, 1, (GdkDragAction) GDK_ACTION_COPY );
-
+
return true;
}
GtkTreePath *path )
{
delete m_dragDataObject;
-
+
GtkTreeIter iter;
if (!get_iter( &iter, path )) return FALSE;
wxDataViewItem item( (void*) iter.user_data );
event.SetModel( m_wx_model );
if (!m_owner->HandleWindowEvent( event ))
return FALSE;
-
+
if (!event.IsAllowed())
return FALSE;
-
+
wxDataObject *obj = event.GetDataObject();
if (!obj)
return FALSE;
-
+
m_dragDataObject = obj;
-
+
return TRUE;
}
size_t size = m_dragDataObject->GetDataSize( selection_data->target );
if (size == 0)
return FALSE;
-
+
void *buf = malloc( size );
-
+
gboolean res = FALSE;
if (m_dragDataObject->GetDataHere( selection_data->target, buf ))
{
res = TRUE;
-
+
gtk_selection_data_set( selection_data, selection_data->target,
8, (const guchar*) buf, size );
}
GtkTreeIter iter;
if (!get_iter( &iter, path )) return FALSE;
wxDataViewItem item( (void*) iter.user_data );
-
+
wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP, m_owner->GetId() );
event.SetEventObject( m_owner );
event.SetItem( item );
event.SetDataBuffer( selection_data->data );
if (!m_owner->HandleWindowEvent( event ))
return FALSE;
-
+
if (!event.IsAllowed())
return FALSE;
GtkTreeIter iter;
if (!get_iter( &iter, path )) return FALSE;
wxDataViewItem item( (void*) iter.user_data );
-
+
wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner->GetId() );
event.SetEventObject( m_owner );
event.SetItem( item );
event.SetDataFormat( selection_data->target );
if (!m_owner->HandleWindowEvent( event ))
return FALSE;
-
+
if (!event.IsAllowed())
return FALSE;
-
+
return TRUE;
}
GtkTreePath *path = m_internal->get_path( &iter );
bool res = gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview), path );
gtk_tree_path_free( path );
-
+
return res;
}