]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/dataview.cpp
wxUniv compilation fixes in themed border drawing code
[wxWidgets.git] / src / gtk / dataview.cpp
index ef9823bf4a33696044c06418bbf4c36216dc7b4c..04d3f1d81169f702694a086cd5fd79ee595a970d 100644 (file)
@@ -92,6 +92,9 @@ public:
     void SetSortColumn( int column )            { m_sort_column = column; }
     int GetSortColumn()                         { return m_sort_column; }
     
+    void SetDataViewSortColumn( wxDataViewColumn *column ) { m_dataview_sort_column = column; }
+    wxDataViewColumn *GetDataViewSortColumn()   { return m_dataview_sort_column; }
+    
     bool IsSorted()                             { return (m_sort_column >= 0); }
     
     
@@ -109,6 +112,7 @@ private:
     GtkWxTreeModel       *m_gtk_model;
     wxDataViewCtrl       *m_owner;
     GtkSortType           m_sort_order;
+    wxDataViewColumn     *m_dataview_sort_column;
     int                   m_sort_column;
 };
 
@@ -614,6 +618,8 @@ gboolean wxgtk_tree_model_get_sort_column_id    (GtkTreeSortable        *sortabl
     return TRUE;
 }
 
+wxDataViewColumn *gs_lastLeftClickHeader = NULL;
+
 void     wxgtk_tree_model_set_sort_column_id  (GtkTreeSortable        *sortable,
                                                      gint                      sort_column_id,
                                                      GtkSortType               order)
@@ -621,23 +627,29 @@ void     wxgtk_tree_model_set_sort_column_id  (GtkTreeSortable        *sortable,
     GtkWxTreeModel *tree_model = (GtkWxTreeModel *) sortable;
     g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
 
-    if ((sort_column_id == (gint) tree_model->internal->GetSortColumn()) &&
-        (order == tree_model->internal->GetSortOrder()))
-        return;
-    
-    tree_model->internal->SetSortColumn( sort_column_id );
+    tree_model->internal->SetDataViewSortColumn( gs_lastLeftClickHeader );
     
-    tree_model->internal->SetSortOrder( order );
+    if ((sort_column_id != (gint) tree_model->internal->GetSortColumn()) ||
+        (order != tree_model->internal->GetSortOrder()))
+    {
+        tree_model->internal->SetSortColumn( sort_column_id );
+        tree_model->internal->SetSortOrder( order );
     
-    gtk_tree_sortable_sort_column_changed (sortable);
+        gtk_tree_sortable_sort_column_changed (sortable);
     
-    tree_model->internal->GetDataViewModel()->Resort();
+        tree_model->internal->GetDataViewModel()->Resort();
+    }
 
-    wxDataViewCtrl *dv = tree_model->internal->GetOwner();    
-    wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, dv->GetId() );
-    // TODO event.SetDataViewColumn( column );
-    event.SetModel( dv->GetModel() );
-    dv->GetEventHandler()->ProcessEvent( event );
+    if (gs_lastLeftClickHeader)
+    {
+        wxDataViewCtrl *dv = tree_model->internal->GetOwner();    
+        wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, dv->GetId() );
+        event.SetDataViewColumn( gs_lastLeftClickHeader );
+        event.SetModel( dv->GetModel() );
+        dv->GetEventHandler()->ProcessEvent( event );
+    }
+    
+    gs_lastLeftClickHeader = NULL;
 }
 
 void     wxgtk_tree_model_set_sort_func         (GtkTreeSortable        *sortable,
@@ -1967,6 +1979,8 @@ gtk_dataview_header_button_press_callback( GtkWidget *widget,
 
     if (gdk_event->button == 1)
     {
+        gs_lastLeftClickHeader = column;
+    
         wxDataViewCtrl *dv = column->GetOwner();
         wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, dv->GetId() );
         event.SetDataViewColumn( column );
@@ -1975,6 +1989,16 @@ gtk_dataview_header_button_press_callback( GtkWidget *widget,
             return FALSE;
     }
 
+    if (gdk_event->button == 3)
+    {
+        wxDataViewCtrl *dv = column->GetOwner();
+        wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, dv->GetId() );
+        event.SetDataViewColumn( column );
+        event.SetModel( dv->GetModel() );
+        if (dv->GetEventHandler()->ProcessEvent( event ))
+            return FALSE;
+    }
+
     return FALSE;
 }
 
@@ -2361,6 +2385,7 @@ wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl *owner,
     m_root = NULL; 
     m_sort_order = GTK_SORT_ASCENDING;
     m_sort_column = -1;
+    m_dataview_sort_column = NULL;
     InitTree();
 }
     
@@ -2410,13 +2435,7 @@ bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem &parent, const wxDa
         parent_node->AddNode( new wxGtkTreeModelNode( parent_node, item, this ) );
     else
         parent_node->AddLeave( item.GetID() );
-        
-    wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED, m_owner->GetId() );
-    event.SetEventObject( m_owner );
-    event.SetModel( m_owner->GetModel() );
-    event.SetItem( item );
-    m_owner->GetEventHandler()->ProcessEvent( event );
-
+    
     return true;
 }
 
@@ -2425,18 +2444,12 @@ bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem &parent, const wx
     wxGtkTreeModelNode *parent_node = FindNode( parent );
     parent_node->DeleteChild( item.GetID() );
     
-    wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED, m_owner->GetId() );
-    event.SetEventObject( m_owner );
-    event.SetModel( m_owner->GetModel() );
-    event.SetItem( item );
-    m_owner->GetEventHandler()->ProcessEvent( event );
-
     return true;
 }
 
 bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem &item )
 {
-    wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED, m_owner->GetId() );
+    wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, m_owner->GetId() );
     event.SetEventObject( m_owner );
     event.SetModel( m_owner->GetModel() );
     event.SetItem( item );
@@ -2447,10 +2460,11 @@ bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem &item )
 
 bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem &item, unsigned int col )
 {
-    wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED, m_owner->GetId() );
+    wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, m_owner->GetId() );
     event.SetEventObject( m_owner );
     event.SetModel( m_owner->GetModel() );
     event.SetColumn( col );
+    event.SetDataViewColumn( GetOwner()->GetColumn(col) );
     event.SetItem( item );
     m_owner->GetEventHandler()->ProcessEvent( event );
     
@@ -2459,11 +2473,6 @@ bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem &item, unsigned
 
 bool wxDataViewCtrlInternal::Cleared()
 {
-    wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED, m_owner->GetId() );
-    event.SetEventObject( m_owner );
-    event.SetModel( m_owner->GetModel() );
-    m_owner->GetEventHandler()->ProcessEvent( event );
-    
     return true;
 }
 
@@ -2681,7 +2690,7 @@ wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( GtkTreeIter *iter )
     
     if (!result)
     {
-        wxPrintf( "Not found %d\n", (int) iter->user_data );
+        wxLogDebug( "Not found %p", iter->user_data );
         char *crash = NULL;
         *crash = 0;
     }
@@ -2698,7 +2707,7 @@ wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( const wxDataViewItem &item
     
     if (!result)
     {
-        wxPrintf( "Not found %d\n", (int) item.GetID() );
+        wxLogDebug( "Not found %p", item.GetID() );
         char *crash = NULL;
         *crash = 0;
     }
@@ -2907,6 +2916,52 @@ void gtk_dataviewctrl_size_callback( GtkWidget *WXUNUSED(widget),
 }
 
 
+//-----------------------------------------------------------------------------
+// "motion_notify_event"
+//-----------------------------------------------------------------------------
+
+static gboolean
+gtk_dataview_motion_notify_callback( GtkWidget *widget,
+                                   GdkEventMotion *gdk_event,
+                                   wxDataViewCtrl *dv )
+{
+    if (gdk_event->is_hint)
+    {
+        int x = 0;
+        int y = 0;
+        GdkModifierType state;
+        gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
+        gdk_event->x = x;
+        gdk_event->y = y;
+    }
+
+    GtkTreePath *path = NULL;
+    GtkTreeViewColumn *column = NULL;
+    gint cell_x = 0;
+    gint cell_y = 0;
+    if (gtk_tree_view_get_path_at_pos( 
+        GTK_TREE_VIEW(dv->GtkGetTreeView()),
+        (int) gdk_event->x, (int) gdk_event->y,
+        &path,
+        &column,
+        &cell_x,
+        &cell_y))
+    {
+        if (path)
+        {
+            GtkTreeIter iter;
+            dv->GtkGetInternal()->get_iter( &iter, path );
+            
+            // wxPrintf( "mouse %d %d\n", (int) gdk_event->x, (int) gdk_event->y );
+        
+            gtk_tree_path_free( path );
+        }
+    }
+
+
+    return FALSE;
+}
+
 
 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase)
 
@@ -3011,6 +3066,9 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
     g_signal_connect_after (m_treeview, "row-expanded",
                             G_CALLBACK (wxdataview_row_expanded_callback), this);
 
+    g_signal_connect (m_treeview, "motion_notify_event",
+                      G_CALLBACK (gtk_dataview_motion_notify_callback), this);
+
     return true;
 }
 
@@ -3127,7 +3185,7 @@ int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const
 
 wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const
 {
-    return NULL;
+    return m_internal->GetDataViewSortColumn();
 }
 
 void wxDataViewCtrl::Expand( const wxDataViewItem & item )