]> git.saurik.com Git - wxWidgets.git/commitdiff
Partial impl of auto resizing columns
authorRobert Roebling <robert@roebling.de>
Mon, 14 Jan 2008 11:04:57 +0000 (11:04 +0000)
committerRobert Roebling <robert@roebling.de>
Mon, 14 Jan 2008 11:04:57 +0000 (11:04 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51205 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/dataview.h
samples/dataview/dataview.cpp
src/common/datavcmn.cpp
src/generic/datavgen.cpp
src/gtk/dataview.cpp

index 51faf5f7c2de4d49212efb8dd90b90bb3f6ca1e8..eecad6d6eb83b17c3d64a758fdaab52ebe4ce37b 100644 (file)
@@ -357,6 +357,7 @@ private:
     wxAlignment              m_align;
     wxString                 m_title;
     bool                     m_ascending;
+    bool                     m_autosize;
 
     void Init(int width);
 
@@ -478,11 +479,11 @@ public:     // utility functions not part of the API
     wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }
 
 private:
-    wxDataViewColumnList m_cols;
-    wxDataViewModelNotifier *m_notifier;
-    wxDataViewMainWindow        *m_clientArea;
-    wxDataViewHeaderWindow      *m_headerArea;
-    wxDataViewColumnm_sortingColumn;
+    wxDataViewColumnList      m_cols;
+    wxDataViewModelNotifier  *m_notifier;
+    wxDataViewMainWindow     *m_clientArea;
+    wxDataViewHeaderWindow   *m_headerArea;
+    wxDataViewColumn         *m_sortingColumn;
 
 private:
     void OnSize( wxSizeEvent &event );
index 16546966153c085d57752f4ffcbb886d28c6eb89..5f9c879d28a6065ca85be572769b1e27a60e4513 100644 (file)
@@ -28,6 +28,9 @@
 #include "wx/dataview.h"
 #include "wx/spinctrl.h"
 
+#include "wx/ptr_shrd.h"
+#include "wx/vector.h"
+
 #ifndef __WXMSW__
     #include "../sample.xpm"
 #endif
@@ -64,11 +67,9 @@ static const char *small1_xpm[] = {
 };
 
 
-
 #define DEFAULT_ALIGN                   wxALIGN_LEFT
 #define DATAVIEW_DEFAULT_STYLE          (wxDV_MULTIPLE|wxDV_HORIZ_RULES|wxDV_VERT_RULES)
 
-
 // -------------------------------------
 // MyMusicModel
 // -------------------------------------
@@ -803,7 +804,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
 
     wxBoxSizer *bottom_sizer = new wxBoxSizer( wxHORIZONTAL );
     
-    m_log = new wxTextCtrl( this, -1,wxString(), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
+    m_log = new wxTextCtrl( this, -1, wxString(), wxDefaultPosition, wxSize(100,200), wxTE_MULTILINE );
     m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_log));
     wxLogMessage(_("This is the log window"));
 
@@ -812,23 +813,23 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
     // wxDataViewTreeStore
 
     wxDataViewCtrl *treectrl = new wxDataViewCtrl( this, -1, 
-        wxDefaultPosition, wxSize(300,200), wxDV_NO_HEADER );
+        wxDefaultPosition, wxSize(100,200), wxDV_NO_HEADER );
         
     wxDataViewTreeStore *store = new wxDataViewTreeStore;
     wxDataViewItem parent = store->AppendContainer( wxDataViewItem(0),wxT("Root 1"), wxIcon(small1_xpm) );
     wxDataViewItem child = store->AppendItem( parent,wxT("Child 1"), wxIcon(small1_xpm) );
     child = store->AppendItem( parent,wxT("Child 2"), wxIcon(small1_xpm) );
-    child = store->AppendItem( parent,wxT("Child 3"), wxIcon(small1_xpm) );
+    child = store->AppendItem( parent,wxT("Child 3, very long, long, long, long"), wxIcon(small1_xpm) );
     treectrl->AssociateModel( store );
     store->DecRef();
 
-    treectrl->AppendIconTextColumn(wxT("no label"), 0, wxDATAVIEW_CELL_INERT, 200 );
+    treectrl->AppendIconTextColumn(wxT("no label"), 0, wxDATAVIEW_CELL_INERT, -1 );
 
-    bottom_sizer->Add( treectrl );
+    bottom_sizer->Add( treectrl, 1 );
 
     // wxDataViewTreeCtrl
 
-    wxDataViewTreeCtrl *treectrl2 = new wxDataViewTreeCtrl( this, -1, wxDefaultPosition, wxSize(300,200) );
+    wxDataViewTreeCtrl *treectrl2 = new wxDataViewTreeCtrl( this, -1, wxDefaultPosition, wxSize(100,200) );
     
     wxImageList *ilist = new wxImageList( 16, 16 );
     ilist->Add( wxIcon(small1_xpm) );
@@ -837,9 +838,9 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
     parent = treectrl2->AppendContainer( wxDataViewItem(0),wxT("Root 1"), 0 );
     child = treectrl2->AppendItem( parent,wxT("Child 1"), 0 );
     child = treectrl2->AppendItem( parent,wxT("Child 2"), 0 );
-    child = treectrl2->AppendItem( parent,wxT("Child 3"), 0 );
+    child = treectrl2->AppendItem( parent,wxT("Child 3, very long, long, long, long"), 0 );
 
-    bottom_sizer->Add( treectrl2 );
+    bottom_sizer->Add( treectrl2, 1 );
     
     // main sizer
     
index 196a0ea5d9408b8244d7e8c19e0a50466a4c7041..7303a0b119de0af19abb2aa14fffd07385335aa4 100644 (file)
@@ -1660,14 +1660,7 @@ wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow *parent, wxWindowID id,
     AssociateModel( store );
     store->DecRef();
     
-#if !defined(__WXGTK20__) || defined(wxUSE_GENERICDATAVIEWCTRL)
-    wxDataViewColumn *col = AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT,40);
-    
-    wxSize cient_size = GetClientSize();
-    col->SetWidth( size.x );
-#else
-    AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT,40);
-#endif    
+    AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT,-1);
 }
 
 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
@@ -1786,10 +1779,11 @@ void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent &event )
 
 void wxDataViewTreeCtrl::OnSize( wxSizeEvent &event )
 {
-#if !defined(__WXGTK20__) || defined(wxUSE_GENERICDATAVIEWCTRL)
+#if defined(wxUSE_GENERICDATAVIEWCTRL)
     wxSize size = GetClientSize();
     wxDataViewColumn *col = GetColumn( 0 );
-    if (col) col->SetWidth( size.x );
+    if (col) 
+       col->SetWidth( size.x );
 #endif
     event.Skip( true );
 }
index 5d80ef9d13ff2c1b196413a1d8b47ffebf229352..1a442101fc5adea9ac728bd50687b00e5b60ceb6 100644 (file)
@@ -1147,6 +1147,8 @@ wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *c
     SetTitle(title);
     SetFlags(flags);
 
+    m_autosize = width < 0;  // TODO
+    
     Init(width < 0 ? wxDVC_DEFAULT_WIDTH : width);
 }
 
index 5f31a0fa055df6f204bdaacbebb4ef3d9c6352fd..878cabacc7d6ddf6c61f1f9cceea7f2a25cc4458 100644 (file)
@@ -2149,7 +2149,7 @@ bool wxDataViewIconTextRenderer::SetValue( const wxVariant &value )
     return true;
 }
 
-bool wxDataViewIconTextRenderer::GetValue( wxVariant &value ) const
+bool wxDataViewIconTextRenderer::GetValue( wxVariant &WXUNUSED(value) ) const
 {
     return false;
 }
@@ -2182,12 +2182,14 @@ wxSize wxDataViewIconTextRenderer::GetSize() const
     return size;
 }
 
-wxControl* wxDataViewIconTextRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
+wxControl* wxDataViewIconTextRenderer::CreateEditorCtrl( 
+    wxWindow *WXUNUSED(parent), wxRect WXUNUSED(labelRect), const wxVariant &WXUNUSED(value) )
 {
     return NULL;
 }
 
-bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value )
+bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( 
+   wxControl* WXUNUSED(editor), wxVariant &WXUNUSED(value) )
 {
     return false;
 }
@@ -2198,7 +2200,7 @@ bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVa
 
 
 static gboolean
-gtk_dataview_header_button_press_callback( GtkWidget *widget,
+gtk_dataview_header_button_press_callback( GtkWidget *WXUNUSED(widget),
                                            GdkEventButton *gdk_event,
                                            wxDataViewColumn *column )
 {
@@ -2239,7 +2241,7 @@ static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column,
 }
 
 
-static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column,
+static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *WXUNUSED(column),
                             GtkCellRenderer *renderer,
                             GtkTreeModel *model,
                             GtkTreeIter *iter,
@@ -2435,14 +2437,7 @@ void wxDataViewColumn::Init(wxAlignment align, int flags, int width)
     SetFlags( flags );
     SetAlignment( align );
 
-    // NOTE: we prefer not to call SetMinWidth(wxDVC_DEFAULT_MINWIDTH);
-    //       as GTK+ is smart and unless explicitely told, will set the minimal
-    //       width to the title's lenght, which is a better default
-
-    // the GTK_TREE_VIEW_COLUMN_FIXED is required by the "fixed height" mode
-    // that we use for the wxDataViewCtrl
-    gtk_tree_view_column_set_fixed_width( column, width < 0 ? wxDVC_DEFAULT_WIDTH : width );
-    gtk_tree_view_column_set_sizing( column, GTK_TREE_VIEW_COLUMN_FIXED );
+    SetWidth( width );
 
     gtk_tree_view_column_pack_end( column, renderer, TRUE );
 
@@ -2646,7 +2641,16 @@ int wxDataViewColumn::GetWidth() const
 
 void wxDataViewColumn::SetWidth( int width )
 {
-    gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column), width );
+    if (width < 0)
+    {
+        gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column), GTK_TREE_VIEW_COLUMN_AUTOSIZE );
+    }
+    else
+    {
+        gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column), GTK_TREE_VIEW_COLUMN_FIXED );
+            
+        gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column), width );
+    }
 }
 
 void wxDataViewColumn::SetReorderable( bool reorderable )
@@ -3337,7 +3341,7 @@ wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem
 //-----------------------------------------------------------------------------
 
 static void
-wxdataview_selection_changed_callback( GtkTreeSelection* selection, wxDataViewCtrl *dv )
+wxdataview_selection_changed_callback( GtkTreeSelection* WXUNUSED(selection), wxDataViewCtrl *dv )
 {
     if (!GTK_WIDGET_REALIZED(dv->m_widget))
         return;
@@ -3349,8 +3353,8 @@ wxdataview_selection_changed_callback( GtkTreeSelection* selection, wxDataViewCt
 }
 
 static void
-wxdataview_row_activated_callback( GtkTreeView* treeview, GtkTreePath *path,
-                                   GtkTreeViewColumn *column, wxDataViewCtrl *dv )
+wxdataview_row_activated_callback( GtkTreeView* WXUNUSED(treeview), GtkTreePath *path,
+                                   GtkTreeViewColumn *WXUNUSED(column), wxDataViewCtrl *dv )
 {
     wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, dv->GetId() );
 
@@ -3363,8 +3367,8 @@ wxdataview_row_activated_callback( GtkTreeView* treeview, GtkTreePath *path,
 }
 
 static gboolean
-wxdataview_test_expand_row_callback( GtkTreeView* treeview, GtkTreeIter* iter,
-                                     GtkTreePath *path, wxDataViewCtrl *dv )
+wxdataview_test_expand_row_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
+                                     GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
 {
     wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, dv->GetId() );
 
@@ -3377,8 +3381,8 @@ wxdataview_test_expand_row_callback( GtkTreeView* treeview, GtkTreeIter* iter,
 }
 
 static void
-wxdataview_row_expanded_callback( GtkTreeView* treeview, GtkTreeIter* iter,
-                                  GtkTreePath *path, wxDataViewCtrl *dv )
+wxdataview_row_expanded_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
+                                  GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
 {
     wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, dv->GetId() );
 
@@ -3389,8 +3393,8 @@ wxdataview_row_expanded_callback( GtkTreeView* treeview, GtkTreeIter* iter,
 }
 
 static gboolean
-wxdataview_test_collapse_row_callback( GtkTreeView* treeview, GtkTreeIter* iter,
-                                       GtkTreePath *path, wxDataViewCtrl *dv )
+wxdataview_test_collapse_row_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
+                                       GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
 {
     wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, dv->GetId() );
 
@@ -3403,8 +3407,8 @@ wxdataview_test_collapse_row_callback( GtkTreeView* treeview, GtkTreeIter* iter,
 }
 
 static void
-wxdataview_row_collapsed_callback( GtkTreeView* treeview, GtkTreeIter* iter,
-                                   GtkTreePath *path, wxDataViewCtrl *dv )
+wxdataview_row_collapsed_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
+                                   GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
 {
     wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, dv->GetId() );
 
@@ -3436,7 +3440,7 @@ static void wxInsertChildInDataViewCtrl( wxWindowGTK* parent, wxWindowGTK* child
 
 static
 void gtk_dataviewctrl_size_callback( GtkWidget *WXUNUSED(widget),
-                                     GtkAllocation *alloc,
+                                     GtkAllocation *WXUNUSED(gtk_alloc),
                                      wxDataViewCtrl *win )
 {
     wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst();
@@ -3464,7 +3468,7 @@ void gtk_dataviewctrl_size_callback( GtkWidget *WXUNUSED(widget),
 //-----------------------------------------------------------------------------
 
 static gboolean
-gtk_dataview_motion_notify_callback( GtkWidget *widget,
+gtk_dataview_motion_notify_callback( GtkWidget *WXUNUSED(widget),
                                      GdkEventMotion *gdk_event,
                                      wxDataViewCtrl *dv )
 {
@@ -3600,7 +3604,6 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
     gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_treeview), 
        GDK_BUTTON1_MASK, &gs_target, 1, (GdkDragAction) GDK_ACTION_COPY );
     
-
 #ifdef __WXGTK26__
     if (!gtk_check_version(2,6,0))
         gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), TRUE );
@@ -3718,6 +3721,15 @@ bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col )
 
     m_cols.Append( col );
 
+#ifdef __WXGTK26__
+    if (!gtk_check_version(2,6,0))
+    {
+        if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ) !=
+               GTK_TREE_VIEW_COLUMN_FIXED)
+           gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), FALSE );
+    }
+#endif
+
     gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview),
                                  GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) );
 
@@ -3731,6 +3743,15 @@ bool wxDataViewCtrl::PrependColumn( wxDataViewColumn *col )
 
     m_cols.Insert( col );
 
+#ifdef __WXGTK26__
+    if (!gtk_check_version(2,6,0))
+    {
+        if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ) !=
+               GTK_TREE_VIEW_COLUMN_FIXED)
+           gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), FALSE );
+    }
+#endif
+
     gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview),
                                  GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()), 0 );