Is it allowed to use Bitmap column in wxDataViewListCtrl Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
walderich
Earned a small fee
Earned a small fee
Posts: 24
Joined: Sat Sep 17, 2011 6:09 pm

Is it allowed to use Bitmap column in wxDataViewListCtrl

Post by walderich »

I wanted to add a simple icon column to my wxDataViewListCtrl. I don't need to display any text there, and therefore I only wanted to show an icon in the column header. Unfortunately, I saw wxDataViewListCtrl has no "AppendIconTextColumn" method which allows bitmaps. Is it allowed to use the parent's method for creating a bitmap as column header? I tried the following:

Code: Select all

wxDataViewListCtrl *ctrl;
((wxDataViewCtrl*) ctrl)->AppendIconTextColumn(wxArtProvider::GetBitmap(wxART_TIP), 0);
This seems to work well under GTK, but I have troubles using it under Windows. Having two such bitmap columns crashes my application, when resizing either of them. I could also reproduce this by manipulating the dataview sample. So: Is is prohibited to use this method from wxDataViewListCtrl, or should it work?
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is it allowed to use Bitmap column in wxDataViewListCtrl

Post by doublemax »

I think it should work. Can you show the modification to reproduce it in the sample?
Use the source, Luke!
walderich
Earned a small fee
Earned a small fee
Posts: 24
Joined: Sat Sep 17, 2011 6:09 pm

Re: Is it allowed to use Bitmap column in wxDataViewListCtrl

Post by walderich »

Sorry for the long response. Here is the diff to the current mainline:

Code: Select all

diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp
index 29f1110..885f505 100644
--- a/samples/dataview/dataview.cpp
+++ b/samples/dataview/dataview.cpp
@@ -33,6 +33,7 @@
 #include "wx/spinctrl.h"
 #include "wx/imaglist.h"
 #include "wx/notebook.h"
+#include "wx/artprov.h"
 
 #include "mymodels.h"
 
@@ -668,7 +669,9 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l
             page2_model->DecRef();
 
             lc->AppendToggleColumn( "Toggle" );
+            ((wxDataViewCtrl*) lc)->AppendIconTextColumn(wxArtProvider::GetBitmap(wxART_TIP, wxART_OTHER, wxSize(16, 16)), 1);
             lc->AppendTextColumn( "Text" );
+            ((wxDataViewCtrl*) lc)->AppendIconTextColumn(wxArtProvider::GetBitmap(wxART_WARNING, wxART_OTHER, wxSize(16, 16)), 1);
             lc->AppendProgressColumn( "Progress" );
 
             wxVector<wxVariant> data;
@@ -676,7 +679,9 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l
             {
                 data.clear();
                 data.push_back( (i%3) == 0 );
+                data.push_back( wxVariant(wxDataViewIconText(wxEmptyString, wxNullIcon)) );
                 data.push_back( wxString::Format("row %d", i) );
+                data.push_back( wxVariant(wxDataViewIconText(wxEmptyString, wxNullIcon)) );
                 data.push_back( long(5*i) );
 
                 lc->AppendItem( data );
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is it allowed to use Bitmap column in wxDataViewListCtrl

Post by doublemax »

The fact that you need a cast to (wxDataViewCtrl*) to make it compile, probably means that it's not supposed to work.
Use the source, Luke!
walderich
Earned a small fee
Earned a small fee
Posts: 24
Joined: Sat Sep 17, 2011 6:09 pm

Re: Is it allowed to use Bitmap column in wxDataViewListCtrl

Post by walderich »

All right. I feared you would say that. But the cast was why I asked the question in the first place.

As I only need a simple image column, I found that there is another method "AppendBitmapColumn". Using this, I have the same problem, but now without the explicit cast:

Code: Select all

diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp
index 29f1110..885f505 100644
--- a/samples/dataview/dataview.cpp
+++ b/samples/dataview/dataview.cpp
@@ -33,6 +33,7 @@
 #include "wx/spinctrl.h"
 #include "wx/imaglist.h"
 #include "wx/notebook.h"
+#include "wx/artprov.h"
 
 #include "mymodels.h"
 
@@ -668,7 +669,9 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l
             page2_model->DecRef();
 
             lc->AppendToggleColumn( "Toggle" );
+            lc->AppendBitmapColumn(wxArtProvider::GetBitmap(wxART_TIP, wxART_OTHER, wxSize(16, 16)), 1);
             lc->AppendTextColumn( "Text" );
+            lc->AppendBitmapColumn(wxArtProvider::GetBitmap(wxART_WARNING, wxART_OTHER, wxSize(16, 16)), 1);
             lc->AppendProgressColumn( "Progress" );
 
             wxVector<wxVariant> data;
@@ -676,7 +679,9 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l
             {
                 data.clear();
                 data.push_back( (i%3) == 0 );
+                data.push_back( wxVariant(wxNullBitmap) );
                 data.push_back( wxString::Format("row %d", i) );
+                data.push_back( wxVariant(wxNullBitmap) );
                 data.push_back( long(5*i) );
 
                 lc->AppendItem( data );
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is it allowed to use Bitmap column in wxDataViewListCtrl

Post by doublemax »

Seems to work for me. What exactly do you have to do to trigger the crash?
Use the source, Luke!
walderich
Earned a small fee
Earned a small fee
Posts: 24
Joined: Sat Sep 17, 2011 6:09 pm

Re: Is it allowed to use Bitmap column in wxDataViewListCtrl

Post by walderich »

Resizing one of the bitmap columns. All other columns are working correctly.
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is it allowed to use Bitmap column in wxDataViewListCtrl

Post by doublemax »

Can't reproduce a crash. Tested with 2.9.5 and 3.1.0 (today's SVN).
Use the source, Luke!
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is it allowed to use Bitmap column in wxDataViewListCtrl

Post by doublemax »

Ok, i saw a crash now. But it doesn't happen all the time and it crashes at different code lines. I suggest to open a bug report at http://trac.wxwidgets.org/
Use the source, Luke!
walderich
Earned a small fee
Earned a small fee
Posts: 24
Joined: Sat Sep 17, 2011 6:09 pm

Re: Is it allowed to use Bitmap column in wxDataViewListCtrl

Post by walderich »

I've done that, and the ticket (http://trac.wxwidgets.org/ticket/16008) is already resolved. Thanks for your help.
Post Reply