]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/dataview.cpp
don't allow TAB-bing away to other TLWs
[wxWidgets.git] / src / gtk / dataview.cpp
index 18488e8ab6128316ea3e6a1e16298e26b808882a..929fa97c4d86acafa16438d81ccd129a310958d5 100644 (file)
@@ -32,6 +32,8 @@
 #include "wx/listimpl.cpp"
 
 #include "wx/gtk/private.h"
 #include "wx/listimpl.cpp"
 
 #include "wx/gtk/private.h"
+#include "wx/gtk/dc.h"
+#include "wx/gtk/dcclient.h"
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -642,26 +644,26 @@ void     wxgtk_tree_model_set_sort_column_id  (GtkTreeSortable        *sortable,
         wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, dv->GetId() );
         event.SetDataViewColumn( gs_lastLeftClickHeader );
         event.SetModel( dv->GetModel() );
         wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, dv->GetId() );
         event.SetDataViewColumn( gs_lastLeftClickHeader );
         event.SetModel( dv->GetModel() );
-        dv->GetEventHandler()->ProcessEvent( event );
+        dv->HandleWindowEvent( event );
     }
 
     gs_lastLeftClickHeader = NULL;
 }
 
     }
 
     gs_lastLeftClickHeader = NULL;
 }
 
-void     wxgtk_tree_model_set_sort_func         (GtkTreeSortable        *sortable,
-                                                     gint                      sort_column_id,
-                                                     GtkTreeIterCompareFunc    func,
-                                                     gpointer                  data,
-                                                     GtkDestroyNotify          destroy)
+void     wxgtk_tree_model_set_sort_func         (GtkTreeSortable          *sortable,
+                                                gint                      WXUNUSED(sort_column_id),
+                                                GtkTreeIterCompareFunc    func,
+                                                gpointer                  WXUNUSED(data),
+                                                GtkDestroyNotify          WXUNUSED(destroy) )
 {
     g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
     g_return_if_fail (func != NULL);
 }
 
 {
     g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
     g_return_if_fail (func != NULL);
 }
 
-void     wxgtk_tree_model_set_default_sort_func (GtkTreeSortable        *sortable,
-                                                     GtkTreeIterCompareFunc    func,
-                                                     gpointer                  data,
-                                                     GtkDestroyNotify          destroy)
+void     wxgtk_tree_model_set_default_sort_func (GtkTreeSortable          *sortable,
+                                                GtkTreeIterCompareFunc    func,
+                                                gpointer                  WXUNUSED(data),
+                                                GtkDestroyNotify          WXUNUSED(destroy) )
 {
     g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
     g_return_if_fail (func != NULL);
 {
     g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
     g_return_if_fail (func != NULL);
@@ -671,6 +673,8 @@ void     wxgtk_tree_model_set_default_sort_func (GtkTreeSortable        *sortabl
 
 gboolean wxgtk_tree_model_has_default_sort_func (GtkTreeSortable        *sortable)
 {
 
 gboolean wxgtk_tree_model_has_default_sort_func (GtkTreeSortable        *sortable)
 {
+    g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable), FALSE );
+    
     return FALSE;
 }
 
     return FALSE;
 }
 
@@ -819,12 +823,12 @@ gtk_wx_cell_renderer_new (void)
 
 static GtkCellEditable *gtk_wx_cell_renderer_start_editing(
                         GtkCellRenderer         *renderer,
 
 static GtkCellEditable *gtk_wx_cell_renderer_start_editing(
                         GtkCellRenderer         *renderer,
-                        GdkEvent                *event,
+                        GdkEvent                *WXUNUSED(event),
                         GtkWidget               *widget,
                         const gchar             *path,
                         GtkWidget               *widget,
                         const gchar             *path,
-                        GdkRectangle            *background_area,
+                        GdkRectangle            *WXUNUSED(background_area),
                         GdkRectangle            *cell_area,
                         GdkRectangle            *cell_area,
-                        GtkCellRendererState     flags )
+                        GtkCellRendererState     WXUNUSED(flags) )
 {
     GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
     wxDataViewCustomRenderer *cell = wxrenderer->cell;
 {
     GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
     wxDataViewCustomRenderer *cell = wxrenderer->cell;
@@ -859,7 +863,7 @@ static GtkCellEditable *gtk_wx_cell_renderer_start_editing(
 
 static void
 gtk_wx_cell_renderer_get_size (GtkCellRenderer *renderer,
 
 static void
 gtk_wx_cell_renderer_get_size (GtkCellRenderer *renderer,
-                               GtkWidget       *widget,
+                               GtkWidget       *WXUNUSED(widget),
                                GdkRectangle    *cell_area,
                                gint            *x_offset,
                                gint            *y_offset,
                                GdkRectangle    *cell_area,
                                gint            *x_offset,
                                gint            *y_offset,
@@ -939,20 +943,12 @@ gtk_wx_cell_renderer_render (GtkCellRenderer      *renderer,
     {
         wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
         wxWindowDC* dc = (wxWindowDC*) cell->GetDC();
     {
         wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
         wxWindowDC* dc = (wxWindowDC*) cell->GetDC();
-#if wxUSE_NEW_DC
-        wxGTKWindowDCImpl *impldc = (wxGTKWindowDCImpl *) dc->GetImpl();
-        if (impldc->m_window == NULL)
-        {
-            impldc->m_window = window;
-            impldc->SetUpDC();
-        }
-#else
-        if (dc->m_window == NULL)
+        wxWindowDCImpl *impl = (wxWindowDCImpl *) dc->GetImpl();
+        if (impl->m_gdkwindow == NULL)
         {
         {
-            dc->m_window = window;
-            dc->SetUpDC();
+            impl->m_gdkwindow = window;
+            impl->SetUpDC();
         }
         }
-#endif
 
         int state = 0;
         if (flags & GTK_CELL_RENDERER_SELECTED)
 
         int state = 0;
         if (flags & GTK_CELL_RENDERER_SELECTED)
@@ -975,9 +971,9 @@ gtk_wx_cell_renderer_activate(
                         GdkEvent                *event,
                         GtkWidget               *widget,
                         const gchar             *path,
                         GdkEvent                *event,
                         GtkWidget               *widget,
                         const gchar             *path,
-                        GdkRectangle            *background_area,
+                        GdkRectangle            *WXUNUSED(background_area),
                         GdkRectangle            *cell_area,
                         GdkRectangle            *cell_area,
-                        GtkCellRendererState     flags )
+                        GtkCellRendererState     WXUNUSED(flags) )
 {
     GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
     wxDataViewCustomRenderer *cell = wxrenderer->cell;
 {
     GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
     wxDataViewCustomRenderer *cell = wxrenderer->cell;
@@ -1202,7 +1198,7 @@ bool wxGtkDataViewModelNotifier::Cleared()
 static gpointer s_user_data = NULL;
 
 static void
 static gpointer s_user_data = NULL;
 
 static void
-wxgtk_cell_editable_editing_done( GtkCellEditable *editable,
+wxgtk_cell_editable_editing_done( GtkCellEditable *WXUNUSED(editable),
                                   wxDataViewRenderer *wxrenderer )
 {
     wxDataViewColumn *column = wxrenderer->GetOwner();
                                   wxDataViewRenderer *wxrenderer )
 {
     wxDataViewColumn *column = wxrenderer->GetOwner();
@@ -1212,11 +1208,11 @@ wxgtk_cell_editable_editing_done( GtkCellEditable *editable,
     event.SetModel( dv->GetModel() );
     wxDataViewItem item( s_user_data );
     event.SetItem( item );
     event.SetModel( dv->GetModel() );
     wxDataViewItem item( s_user_data );
     event.SetItem( item );
-    dv->GetEventHandler()->ProcessEvent( event );
+    dv->HandleWindowEvent( event );
 }
 
 static void
 }
 
 static void
-wxgtk_renderer_editing_started( GtkCellRenderer *cell, GtkCellEditable *editable,
+wxgtk_renderer_editing_started( GtkCellRenderer *WXUNUSED(cell), GtkCellEditable *editable,
                                 gchar *path, wxDataViewRenderer *wxrenderer )
 {
     wxDataViewColumn *column = wxrenderer->GetOwner();
                                 gchar *path, wxDataViewRenderer *wxrenderer )
 {
     wxDataViewColumn *column = wxrenderer->GetOwner();
@@ -1230,7 +1226,7 @@ wxgtk_renderer_editing_started( GtkCellRenderer *cell, GtkCellEditable *editable
     gtk_tree_path_free( tree_path );
     wxDataViewItem item( iter.user_data );
     event.SetItem( item );
     gtk_tree_path_free( tree_path );
     wxDataViewItem item( iter.user_data );
     event.SetItem( item );
-    dv->GetEventHandler()->ProcessEvent( event );
+    dv->HandleWindowEvent( event );
 
     if (GTK_IS_CELL_EDITABLE(editable))
     {
 
     if (GTK_IS_CELL_EDITABLE(editable))
     {
@@ -1390,7 +1386,7 @@ static void wxGtkTextRendererEditedCallback( GtkCellRendererText *renderer,
     gchar *arg1, gchar *arg2, gpointer user_data );
 }
 
     gchar *arg1, gchar *arg2, gpointer user_data );
 }
 
-static void wxGtkTextRendererEditedCallback( GtkCellRendererText *renderer,
+static void wxGtkTextRendererEditedCallback( GtkCellRendererText *WXUNUSED(renderer),
     gchar *arg1, gchar *arg2, gpointer user_data )
 {
     wxDataViewTextRenderer *cell = (wxDataViewTextRenderer*) user_data;
     gchar *arg1, gchar *arg2, gpointer user_data )
 {
     wxDataViewTextRenderer *cell = (wxDataViewTextRenderer*) user_data;
@@ -1555,7 +1551,7 @@ bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value )
     return false;
 }
 
     return false;
 }
 
-bool wxDataViewBitmapRenderer::GetValue( wxVariant &value ) const
+bool wxDataViewBitmapRenderer::GetValue( wxVariant &WXUNUSED(value) ) const
 {
     return false;
 }
 {
     return false;
 }
@@ -1657,41 +1653,38 @@ bool wxDataViewToggleRenderer::GetValue( wxVariant &value ) const
 // wxDataViewCustomRenderer
 // ---------------------------------------------------------
 
 // wxDataViewCustomRenderer
 // ---------------------------------------------------------
 
-class wxDataViewCtrlDC: public wxWindowDC
+class wxDataViewCtrlDCImpl: public wxWindowDCImpl
 {
 public:
 {
 public:
-    wxDataViewCtrlDC( wxDataViewCtrl *window )
-    {
-#if wxUSE_NEW_DC
-        wxGTKWindowDCImpl *impl = (wxGTKWindowDCImpl*) GetImpl();
-
+   wxDataViewCtrlDCImpl( wxDC *owner, wxDataViewCtrl *window ) :
+       wxWindowDCImpl( owner )
+   {
         GtkWidget *widget = window->m_treeview;
         // Set later
         GtkWidget *widget = window->m_treeview;
         // Set later
-        impl->m_window = NULL;
-
-        impl->m_context = window->GtkGetPangoDefaultContext();
-        impl->m_layout = pango_layout_new( impl->m_context );
-        impl->m_fontdesc = pango_font_description_copy( widget->style->font_desc );
-
-        impl->m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget );
-
-#else
-        GtkWidget *widget = window->m_treeview;
-        // Set later
-        m_window = NULL;
+        m_gdkwindow = NULL;
+        
+        m_window = window;
 
         m_context = window->GtkGetPangoDefaultContext();
         m_layout = pango_layout_new( m_context );
         m_fontdesc = pango_font_description_copy( widget->style->font_desc );
 
         m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget );
 
         m_context = window->GtkGetPangoDefaultContext();
         m_layout = pango_layout_new( m_context );
         m_fontdesc = pango_font_description_copy( widget->style->font_desc );
 
         m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget );
-#endif
-        // Set m_window later
+
+        // Set m_gdkwindow later
         // SetUpDC();
         // SetUpDC();
-        // m_owner = window;
     }
 };
 
     }
 };
 
+class wxDataViewCtrlDC: public wxWindowDC
+{
+public:
+    wxDataViewCtrlDC( wxDataViewCtrl *window ) :
+        wxWindowDC( new wxDataViewCtrlDCImpl( this, window ) )
+        { } 
+};
+    
+
 // ---------------------------------------------------------
 // wxDataViewCustomRenderer
 // ---------------------------------------------------------
 // ---------------------------------------------------------
 // wxDataViewCustomRenderer
 // ---------------------------------------------------------
@@ -2068,7 +2061,7 @@ gtk_dataview_header_button_press_callback( GtkWidget *widget,
         wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, dv->GetId() );
         event.SetDataViewColumn( column );
         event.SetModel( dv->GetModel() );
         wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, dv->GetId() );
         event.SetDataViewColumn( column );
         event.SetModel( dv->GetModel() );
-        if (dv->GetEventHandler()->ProcessEvent( event ))
+        if (dv->HandleWindowEvent( event ))
             return FALSE;
     }
 
             return FALSE;
     }
 
@@ -2078,7 +2071,7 @@ gtk_dataview_header_button_press_callback( GtkWidget *widget,
         wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, dv->GetId() );
         event.SetDataViewColumn( column );
         event.SetModel( dv->GetModel() );
         wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, dv->GetId() );
         event.SetDataViewColumn( column );
         event.SetModel( dv->GetModel() );
-        if (dv->GetEventHandler()->ProcessEvent( event ))
+        if (dv->HandleWindowEvent( event ))
             return FALSE;
     }
 
             return FALSE;
     }
 
@@ -2654,7 +2647,7 @@ bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem &item )
     event.SetEventObject( m_owner );
     event.SetModel( m_owner->GetModel() );
     event.SetItem( item );
     event.SetEventObject( m_owner );
     event.SetModel( m_owner->GetModel() );
     event.SetItem( item );
-    m_owner->GetEventHandler()->ProcessEvent( event );
+    m_owner->HandleWindowEvent( event );
 
     return true;
 }
 
     return true;
 }
@@ -2667,7 +2660,7 @@ bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem &item, unsigned
     event.SetColumn( col );
     event.SetDataViewColumn( GetOwner()->GetColumn(col) );
     event.SetItem( item );
     event.SetColumn( col );
     event.SetDataViewColumn( GetOwner()->GetColumn(col) );
     event.SetItem( item );
-    m_owner->GetEventHandler()->ProcessEvent( event );
+    m_owner->HandleWindowEvent( event );
 
     return true;
 }
 
     return true;
 }
@@ -2693,7 +2686,7 @@ gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path
 
         unsigned int i = (unsigned int)gtk_tree_path_get_indices (path)[0];
 
 
         unsigned int i = (unsigned int)gtk_tree_path_get_indices (path)[0];
 
-        if (i >= wx_model->GetLastIndex())
+        if (i >= wx_model->GetLastIndex() + 1)
             return FALSE;
 
         iter->stamp = m_gtk_model->stamp;
             return FALSE;
 
         iter->stamp = m_gtk_model->stamp;
@@ -2783,7 +2776,7 @@ gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
         if (n == -1)
             return FALSE;
 
         if (n == -1)
             return FALSE;
 
-        if (n >= (int) wx_model->GetLastIndex()-2)
+        if (n >= (int) wx_model->GetLastIndex())
             return FALSE;
 
         iter->user_data = (gpointer) ++n;
             return FALSE;
 
         iter->user_data = (gpointer) ++n;
@@ -2869,7 +2862,7 @@ gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter )
         wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
 
         if (iter == NULL)
         wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
 
         if (iter == NULL)
-            return (gint) wx_model->GetLastIndex()-1;
+            return (gint) wx_model->GetLastIndex() + 1;
 
         return 0;
     }
 
         return 0;
     }
@@ -2901,7 +2894,7 @@ gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter
         if (n < 0)
             return FALSE;
 
         if (n < 0)
             return FALSE;
 
-        if (n >= (gint) wx_model->GetLastIndex()-1)
+        if (n >= (gint) wx_model->GetLastIndex() + 1)
             return FALSE;
 
         iter->stamp = m_gtk_model->stamp;
             return FALSE;
 
         iter->stamp = m_gtk_model->stamp;
@@ -3120,7 +3113,7 @@ wxdataview_selection_changed_callback( GtkTreeSelection* selection, wxDataViewCt
     wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, dv->GetId() );
     event.SetItem( dv->GetSelection() );
     event.SetModel( dv->GetModel() );
     wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, dv->GetId() );
     event.SetItem( dv->GetSelection() );
     event.SetModel( dv->GetModel() );
-    dv->GetEventHandler()->ProcessEvent( event );
+    dv->HandleWindowEvent( event );
 }
 
 static void
 }
 
 static void
@@ -3134,7 +3127,7 @@ wxdataview_row_activated_callback( GtkTreeView* treeview, GtkTreePath *path,
     wxDataViewItem item( (void*) iter.user_data );;
     event.SetItem( item );
     event.SetModel( dv->GetModel() );
     wxDataViewItem item( (void*) iter.user_data );;
     event.SetItem( item );
     event.SetModel( dv->GetModel() );
-    dv->GetEventHandler()->ProcessEvent( event );
+    dv->HandleWindowEvent( event );
 }
 
 static gboolean
 }
 
 static gboolean
@@ -3146,7 +3139,7 @@ wxdataview_test_expand_row_callback( GtkTreeView* treeview, GtkTreeIter* iter,
     wxDataViewItem item( (void*) iter->user_data );;
     event.SetItem( item );
     event.SetModel( dv->GetModel() );
     wxDataViewItem item( (void*) iter->user_data );;
     event.SetItem( item );
     event.SetModel( dv->GetModel() );
-    dv->GetEventHandler()->ProcessEvent( event );
+    dv->HandleWindowEvent( event );
 
     return !event.IsAllowed();
 }
 
     return !event.IsAllowed();
 }
@@ -3160,7 +3153,7 @@ wxdataview_row_expanded_callback( GtkTreeView* treeview, GtkTreeIter* iter,
     wxDataViewItem item( (void*) iter->user_data );;
     event.SetItem( item );
     event.SetModel( dv->GetModel() );
     wxDataViewItem item( (void*) iter->user_data );;
     event.SetItem( item );
     event.SetModel( dv->GetModel() );
-    dv->GetEventHandler()->ProcessEvent( event );
+    dv->HandleWindowEvent( event );
 }
 
 static gboolean
 }
 
 static gboolean
@@ -3172,7 +3165,7 @@ wxdataview_test_collapse_row_callback( GtkTreeView* treeview, GtkTreeIter* iter,
     wxDataViewItem item( (void*) iter->user_data );;
     event.SetItem( item );
     event.SetModel( dv->GetModel() );
     wxDataViewItem item( (void*) iter->user_data );;
     event.SetItem( item );
     event.SetModel( dv->GetModel() );
-    dv->GetEventHandler()->ProcessEvent( event );
+    dv->HandleWindowEvent( event );
 
     return !event.IsAllowed();
 }
 
     return !event.IsAllowed();
 }
@@ -3186,7 +3179,7 @@ wxdataview_row_collapsed_callback( GtkTreeView* treeview, GtkTreeIter* iter,
     wxDataViewItem item( (void*) iter->user_data );;
     event.SetItem( item );
     event.SetModel( dv->GetModel() );
     wxDataViewItem item( (void*) iter->user_data );;
     event.SetItem( item );
     event.SetModel( dv->GetModel() );
-    dv->GetEventHandler()->ProcessEvent( event );
+    dv->HandleWindowEvent( event );
 }
 
 //-----------------------------------------------------------------------------
 }
 
 //-----------------------------------------------------------------------------
@@ -3351,13 +3344,12 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
         else if (style & wxDV_HORIZ_RULES)
             grid = GTK_TREE_VIEW_GRID_LINES_HORIZONTAL;
 
         else if (style & wxDV_HORIZ_RULES)
             grid = GTK_TREE_VIEW_GRID_LINES_HORIZONTAL;
 
-        gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview), grid );
+        if (grid != GTK_TREE_VIEW_GRID_LINES_NONE)
+            gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview), grid );
     }
     }
-    else
 #endif
 #endif
-    {
-        gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview), (style & wxDV_HORIZ_RULES) != 0 );
-    }
+
+    gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview), (style & wxDV_ROW_LINES) != 0 );
 
     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget),
         GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
 
     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget),
         GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);