]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/datavcmn.cpp
fixing modal dialog quit after nested message box problem
[wxWidgets.git] / src / common / datavcmn.cpp
index 21aec07ef7ca66629dc019d19e5781b9aa3d38bb..72475e06b21b0b86e807bbc1ce5f9045fa5f0b22 100644 (file)
@@ -38,13 +38,6 @@ bool operator == (const wxDataViewItem &left, const wxDataViewItem &right)
     return (left.GetID() == right.GetID() );
 }
 
-#ifdef __WXDEBUG__
-void wxDataViewItem::Print(const wxString& text) const
-{
-    wxPrintf(wxT("item %s: %lu\n"), text.GetData(), wxPtrToUInt(m_id));
-}
-#endif
-
 // ---------------------------------------------------------
 // wxDataViewModelNotifier
 // ---------------------------------------------------------
@@ -233,7 +226,7 @@ void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier *notifier )
 }
 
 int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
-                              unsigned int column, bool ascending )
+                              unsigned int column, bool ascending ) const
 {
     // sort branches before leaves
     bool item1_is_container = IsContainer(item1);
@@ -432,7 +425,7 @@ bool wxDataViewIndexListModel::HasDefaultCompare() const
 int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1,
                                       const wxDataViewItem& item2,
                                       unsigned int WXUNUSED(column),
-                                      bool ascending)
+                                      bool ascending) const
 {
     if (m_ordered)
     {
@@ -587,7 +580,7 @@ bool wxDataViewVirtualListModel::HasDefaultCompare() const
 int wxDataViewVirtualListModel::Compare(const wxDataViewItem& item1,
                                       const wxDataViewItem& item2,
                                       unsigned int WXUNUSED(column),
-                                      bool ascending)
+                                      bool ascending) const
 {
     unsigned int pos1 = wxPtrToUInt(item1.GetID());
     unsigned int pos2 = wxPtrToUInt(item2.GetID());
@@ -688,13 +681,30 @@ public:
 
 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect )
 {
+    wxDataViewCtrl* dv_ctrl = GetOwner()->GetOwner();
+
+    // Before doing anything we send an event asking if editing of this item is really wanted.
+    wxDataViewEvent start_event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING, dv_ctrl->GetId() );
+    start_event.SetDataViewColumn( GetOwner() );
+    start_event.SetModel( dv_ctrl->GetModel() );
+    start_event.SetItem( item );
+    start_event.SetEventObject( dv_ctrl );
+    dv_ctrl->GetEventHandler()->ProcessEvent( start_event );
+    if( !start_event.IsAllowed() )
+        return false;
+
     m_item = item; // remember for later
 
     unsigned int col = GetOwner()->GetModelColumn();
     wxVariant value;
-    GetOwner()->GetOwner()->GetModel()->GetValue( value, item, col );
+    dv_ctrl->GetModel()->GetValue( value, item, col );
+
+    m_editorCtrl = CreateEditorCtrl( dv_ctrl->GetMainWindow(), labelRect, value );
+
+       // there might be no editor control for the given item
+    if(!m_editorCtrl)
+        return false;
 
-    m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value );
     (void) new wxKillRef( m_editorCtrl.get() );
 
     wxDataViewEditorCtrlEvtHandler *handler =
@@ -709,18 +719,20 @@ bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect la
 #endif
 
     // Now we should send Editing Started event
-    wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, GetOwner()->GetOwner()->GetId() );
+    wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, dv_ctrl->GetId() );
     event.SetDataViewColumn( GetOwner() );
-    event.SetModel( GetOwner()->GetOwner()->GetModel() );
+    event.SetModel( dv_ctrl->GetModel() );
     event.SetItem( item );
-    GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event );
+    event.SetEventObject( dv_ctrl );
+    dv_ctrl->GetEventHandler()->ProcessEvent( event );
 
     return true;
 }
 
 void wxDataViewRendererBase::CancelEditing()
 {
-    if (!m_editorCtrl) return;
+    if (!m_editorCtrl)
+        return;
 
     GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
 
@@ -730,12 +742,15 @@ void wxDataViewRendererBase::CancelEditing()
 
 bool wxDataViewRendererBase::FinishEditing()
 {
-    if (!m_editorCtrl) return true;
+    if (!m_editorCtrl)
+        return true;
 
     wxVariant value;
     GetValueFromEditorCtrl( m_editorCtrl, value );
 
-    GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
+    wxDataViewCtrl* dv_ctrl = GetOwner()->GetOwner();
+
+    dv_ctrl->GetMainWindow()->SetFocus();
 
     m_editorCtrl->Hide();
     wxPendingDelete.Append( m_editorCtrl );
@@ -744,15 +759,16 @@ bool wxDataViewRendererBase::FinishEditing()
         return false;
 
     unsigned int col = GetOwner()->GetModelColumn();
-    GetOwner()->GetOwner()->GetModel()->SetValue( value, m_item, col );
-    GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item, col );
+    dv_ctrl->GetModel()->SetValue( value, m_item, col );
+    dv_ctrl->GetModel()->ValueChanged( m_item, col );
 
     // Now we should send Editing Done event
-    wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, GetOwner()->GetOwner()->GetId() );
+    wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, dv_ctrl->GetId() );
     event.SetDataViewColumn( GetOwner() );
-    event.SetModel( GetOwner()->GetOwner()->GetModel() );
+    event.SetModel( dv_ctrl->GetModel() );
     event.SetItem( m_item );
-    GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event );
+    event.SetEventObject( dv_ctrl );
+    dv_ctrl->GetEventHandler()->ProcessEvent( event );
 
     return true;
 }
@@ -1210,27 +1226,28 @@ wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos), wxDataViewColumn *
 
 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent)
 
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEvent )
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEvent );
 
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, wxDataViewEvent )
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, wxDataViewEvent )
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, wxDataViewEvent )
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, wxDataViewEvent )
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, wxDataViewEvent )
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, wxDataViewEvent )
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, wxDataViewEvent )
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEvent )
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, wxDataViewEvent );
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, wxDataViewEvent );
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, wxDataViewEvent );
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, wxDataViewEvent );
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, wxDataViewEvent );
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, wxDataViewEvent );
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING, wxDataViewEvent );
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, wxDataViewEvent );
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEvent );
 
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, wxDataViewEvent )
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, wxDataViewEvent );
 
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, wxDataViewEvent )
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, wxDataViewEvent )
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, wxDataViewEvent )
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED, wxDataViewEvent )
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, wxDataViewEvent );
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, wxDataViewEvent );
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, wxDataViewEvent );
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED, wxDataViewEvent );
 
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, wxDataViewEvent )
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE, wxDataViewEvent )
-wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP, wxDataViewEvent )
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, wxDataViewEvent );
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE, wxDataViewEvent );
+wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP, wxDataViewEvent );
 
 // -------------------------------------
 // wxDataViewSpinRenderer
@@ -1300,7 +1317,7 @@ bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const
 // wxDataViewChoiceRenderer
 // -------------------------------------
 
-#if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXMAC__)
+#if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
 
 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString& choices, wxDataViewCellMode mode, int alignment ) :
    wxDataViewCustomRenderer(wxT("string"), mode, alignment )
@@ -1415,7 +1432,8 @@ void wxDataViewListStore::PrependItem( const wxVector<wxVariant> &values, wxClie
     RowPrepended();
 }
 
-void wxDataViewListStore::InsertItem(  unsigned int row, const wxVector<wxVariant> &values, wxClientData *data )
+void wxDataViewListStore::InsertItem(  unsigned int row, const wxVector<wxVariant> &values, 
+                                       wxClientData *data )
 {
     wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
     line->m_values = values;
@@ -1424,7 +1442,7 @@ void wxDataViewListStore::InsertItem(  unsigned int row, const wxVector<wxVarian
     RowInserted( row );
 }
 
-void wxDataViewListStore::DeleteItem( unsigned row )
+void wxDataViewListStore::DeleteItem( unsigned int row )
 {
     wxVector<wxDataViewListStoreLine*>::iterator it = m_data.begin() + row;
     m_data.erase( it );
@@ -1441,6 +1459,8 @@ void wxDataViewListStore::DeleteAllItems()
         delete line;
     }
 
+    m_data.clear();
+
     Reset( 0 );
 }
 
@@ -1935,7 +1955,7 @@ unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem &item, wxDat
 }
 
 int wxDataViewTreeStore::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
-                         unsigned int WXUNUSED(column), bool WXUNUSED(ascending) )
+                         unsigned int WXUNUSED(column), bool WXUNUSED(ascending) ) const
 {
     wxDataViewTreeStoreNode *node1 = FindNode( item1 );
     wxDataViewTreeStoreNode *node2 = FindNode( item2 );