Drawing a widget as a drag icon (without going down to C)



I have a small widget that can be a drag/drop source/sink. When it's dragged, I want it to be the drag-icon, so you can see that you're dragging that particular widget (and its particular label, etc.)

However, Gtk::Widget::draw(Cairo::RefPtr<Cairo::Context> const&) is protected in gtkmm, so it seems that in order to draw the widget onto a surface that I can then set as drag-icon, I must do:

```
auto const allocation = m_box_label.get_allocation();
auto const surface = Cairo::ImageSurface::create(
  Cairo::FORMAT_ARGB32, allocation.get_width(), allocation.get_height() );
auto const cairoContext = Cairo::Context::create(surface);
gtk_widget_draw( reinterpret_cast<GtkWidget*>( m_box_label.gobj() ), cairoContext->cobj() );
dragContext->set_icon(surface);
```

Is there any better way that I didn't think of, any way to make this nicer in gtkmm, or is it just a fact of life at this point? (Since gtkmm-3 is stable and master is probably very different here.)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]