Toggle column in wxDataViewCtrl with toggle control hidden on some rows

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Toggle column in wxDataViewCtrl with toggle control hidden on some rows

Frédéric
Hi,
I would like a column in wxDataViewCtrl that shows a toggle control
only on some rows but not on all rows. Is this possible?
Thanks,
F

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: Toggle column in wxDataViewCtrl with toggle control hidden on some rows

Vadim Zeitlin-4
On Thu, 22 Nov 2018 06:23:30 +0100 Frédéric wrote:

F> I would like a column in wxDataViewCtrl that shows a toggle control
F> only on some rows but not on all rows. Is this possible?

 To the best of my knowledge, the native versions always shows the same
control in all rows, so you won't be able to do this with
wxDataViewToggleRenderer which is implemented natively in GTK+ and macOS
versions.

 You might be able to implement this with a custom renderer, which can draw
its contents in any way it wants and, in particular, either call
wxRendererNative::DrawCheckBox() or not, depending on e.g. the state.

 However there are other problems with custom renderers, notably I seem to
remember that they currently can't be activated under Mac, so you should
test this (just build the dataview sample, maybe with some changes to make
it closer to your use case, and run it under all platforms) before
committing to this.

 Finally, there is also a solution of just using the generic version of
wxDataViewCtrl on all platforms. This obviously looks less natively, but if
you really must go beyond the functionality available in the native
versions, this is the only choice.

 Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/

attachment0 (203 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Toggle column in wxDataViewCtrl with toggle control hidden on some rows

Manolo
In reply to this post by Frédéric
Yes, tough, but possible.
I've only tested it with the generic wxDVC, but I hope it to work also with the native control.

First, you apply a wxDataViewCustomRenderer("wxBitmap", wxDATAVIEW_CELL_ACTIVATABLE,....) derived (let's call myToggleCR) to the column.

Next, handle wxEVT_DATAVIEW_ITEM_START_EDITING event. Here you retrieve column and item:
  long itemId = VoidP2Long(event.GetItem().GetID()); //Notice the 'void*->long' conversion yo do elsewhere
  int column = event.GetColumn();
You can have a test, somewhere, to see if this item is editable (if it uses a "toggle" or nothing to draw):
  if ( ! model->IsEditable(itemId, column) )
      event.Veto();

Your model defines a tri-state value: 0= no bitmap, 1= off-bitmap, 2= on-bitmap
In the model::GetValue() function the first parameter is a wxVariant, which is used for wxBitmap.
Depending on the state, which you can select with the other two parameters (item, col), you pass-back the proper image:
  variant << state == 0 ? wxNullBitmap : (state == 1 ? offbmp : onbmp);

In your myToggleCR::SetValue, be aware of invalid values, i.e. perhaps you want to store a wxNullBitmap

In your myToggleCR::Render(wxRect cell, wxDC* dc, ...), with a 'm_bitmap' member which stores current-shown bitmap:
  dc->DrawBitmap(m_bitmap, cell.x, cell.y,...


--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
 
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: Toggle column in wxDataViewCtrl with toggle control hidden on some rows

Frédéric
> Yes, tough, but possible.
> I've only tested it with the generic wxDVC, but I hope it to work also with the native control.

Thank you, that looks interesting.

Kind regards,

F

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: Toggle column in wxDataViewCtrl with toggle control hidden on some rows

Frédéric
In reply to this post by Vadim Zeitlin-4
> F> I would like a column in wxDataViewCtrl that shows a toggle control
> F> only on some rows but not on all rows. Is this possible?
>
>  To the best of my knowledge, the native versions always shows the same
> control in all rows, so you won't be able to do this with
> wxDataViewToggleRenderer which is implemented natively in GTK+ and macOS
> versions.


OK, it is not so critical to hide the check boxes as soon as I can
disable them and I can.
But I tried to use the wxDataViewToggleRenderer but I do not get a
check box on lines that have children items. This is really annoying.
Any way to do that?

Kind regards,

F

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: Toggle column in wxDataViewCtrl with toggle control hidden on some rows

Frédéric
> OK, it is not so critical to hide the check boxes as soon as I can
> disable them and I can.
> But I tried to use the wxDataViewToggleRenderer but I do not get a
> check box on lines that have children items. This is really annoying.
> Any way to do that?

I found the answer: I can override
wxDataViewModel::HasContainerColumns() to return true.

Thanks,

F

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users