port-to-gtk3: Use draw signal in the partition resizer (#7)

In Gtk2 widgets draw themselves in response to the expose event signal.
In Gtk3 widgets draw themselves in response to the GtkWidget::draw
signal, and the signal handler gets a Cairo context as an argument.

Convert Gtk::DrawingArea rendering code to respond to the
GtkWidget::draw signal.

This commit is specific to the drawing area in the Create new Partition
dialog and the Resize/Move dialog.

Reference:

[1] Migrating from GTK+ 2.x to GTK+ 3 - "The GtkWidget::draw signal":
    https://developer.gnome.org/gtk3/stable/ch26s02.html#id-1.6.3.4.11

Closes #7 - Port to Gtk3
This commit is contained in:
Luca Bacci 2018-08-03 19:33:54 +02:00 committed by Mike Fleetwood
parent 93b1425549
commit 21d8ad218e
2 changed files with 4 additions and 16 deletions

View File

@ -68,7 +68,7 @@ protected:
//signal handlers
void drawingarea_on_realize();
bool drawingarea_on_expose( GdkEventExpose * ev );
bool drawingarea_on_draw(const Cairo::RefPtr<Cairo::Context>& cr);
virtual bool drawingarea_on_mouse_motion( GdkEventMotion * ev ) ;
bool drawingarea_on_button_press_event( GdkEventButton * ev ) ;
bool drawingarea_on_button_release_event( GdkEventButton * ev ) ;

View File

@ -40,8 +40,8 @@ void Frame_Resizer_Base::init()
drawingarea .signal_realize() .connect(
sigc::mem_fun(*this, &Frame_Resizer_Base::drawingarea_on_realize) ) ;
drawingarea .signal_expose_event() .connect(
sigc::mem_fun(*this, &Frame_Resizer_Base::drawingarea_on_expose) ) ;
drawingarea.signal_draw().connect(
sigc::mem_fun(*this, &Frame_Resizer_Base::drawingarea_on_draw));
drawingarea .signal_motion_notify_event() .connect(
sigc::mem_fun(*this, &Frame_Resizer_Base::drawingarea_on_mouse_motion) ) ;
drawingarea .signal_button_press_event() .connect(
@ -138,20 +138,8 @@ void Frame_Resizer_Base::drawingarea_on_realize()
drawingarea .add_events( Gdk::LEAVE_NOTIFY_MASK );
}
bool Frame_Resizer_Base::drawingarea_on_expose( GdkEventExpose * ev )
bool Frame_Resizer_Base::drawingarea_on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
Glib::RefPtr<Gdk::Window> window = drawingarea.get_window();
if (!window)
return true;
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
// Clip to the area indicated by the expose event so that we only redraw
// the portion of the window that needs to be redrawn.
cr->rectangle(ev->area.x, ev->area.y,
ev->area.width, ev->area.height);
cr->clip();
cr->set_line_cap(Cairo::LINE_CAP_SQUARE);
cr->set_line_width(1.0);