Commit 005e3bbc authored by Tavmjong Bah's avatar Tavmjong Bah
Browse files

Remove use of SP_ACTIVE_DESKTOP in Canvas. Check for valid desktop before rendering.

parent fabcf01f
Pipeline #169363793 passed with stages
in 47 minutes and 36 seconds
......@@ -22,7 +22,7 @@
#include "color.h" // Background color
#include "cms-system.h" // Color correction
#include "inkscape.h" // SP_ACTIVE_DESKTOP TEMP TEMP TEMP
#include "desktop.h"
#include "preferences.h"
#include "display/sp-canvas-item.h" // Canvas group TEMP TEMP TEMP
......@@ -258,7 +258,11 @@ Canvas::scroll_to(Geom::Point const &c, bool clear)
Geom::IntRect new_area = old_area + Geom::IntPoint(dx, dy);
bool overlap = new_area.intersects(old_area);
SPCanvasArena *arena = SP_CANVAS_ARENA(SP_ACTIVE_DESKTOP->drawing);
if (!_desktop) {
return; // Might be in destruction
}
SPCanvasArena *arena = SP_CANVAS_ARENA(_desktop->drawing);
if (arena) {
Geom::IntRect expanded = new_area;
Geom::IntPoint expansion(new_area.width()/2, new_area.height()/2);
......@@ -586,7 +590,7 @@ Canvas::on_motion_notify_event(GdkEventMotion *motion_event)
_split_position = Geom::Point(_allocation.get_width()/2, _allocation.get_height()/2);
set_cursor();
queue_draw();
SP_ACTIVE_DESKTOP->setSplitMode(_split_mode);
_desktop->setSplitMode(_split_mode);
return true;
}
}
......@@ -846,6 +850,12 @@ Canvas::remove_idle()
bool
Canvas::on_idle()
{
// Desktop is destroyed before canvas.
if (!_desktop) {
std::cerr << "Canvas::on_idle: Called after desktop destroyed!" << std::endl;
return false;
}
if (_in_destruction) {
std::cerr << "Canvas::on_idle: Called after canvas destroyed!" << std::endl;
return false; // Disconnect
......@@ -1006,9 +1016,7 @@ Canvas::paint_rect_internal(PaintRectSetup const *setup, Geom::IntRect const &th
if (bw * bh < setup->max_pixels) {
// We are small enough!
// TODO Find better solution
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
SPCanvasArena *arena = SP_CANVAS_ARENA(desktop->drawing);
SPCanvasArena *arena = SP_CANVAS_ARENA(_desktop->drawing);
arena->drawing.setRenderMode(_render_mode);
paint_single_buffer(this_rect, setup->canvas_rect, _backing_store);
......@@ -1271,7 +1279,7 @@ Canvas::set_cursor() {
switch (_hover_direction) {
case Inkscape::SPLITDIRECTION_NONE:
get_window()->set_cursor(SP_ACTIVE_DESKTOP->event_context->cursor);
get_window()->set_cursor(_desktop->event_context->cursor);
break;
case Inkscape::SPLITDIRECTION_NORTH:
......@@ -1388,8 +1396,7 @@ Canvas::pick_current_item(GdkEvent *event)
}
// If in split mode, look at where cursor is to see if one should pick with outline mode.
SPDesktop *desktop = SP_ACTIVE_DESKTOP; // TODO Find better solution
SPCanvasArena *arena = SP_CANVAS_ARENA(desktop->drawing);
SPCanvasArena *arena = SP_CANVAS_ARENA(_desktop->drawing);
arena->drawing.setRenderMode(_render_mode);
if (_split_mode == Inkscape::SPLITMODE_SPLIT) {
if ((_split_direction == Inkscape::SPLITDIRECTION_NORTH && y > _split_position.y()) ||
......
......@@ -22,6 +22,7 @@
#include "display/rendermode.h"
class SPDesktop;
class SPCanvasItem;
class SPCanvasGroup;
......@@ -42,6 +43,9 @@ public:
Canvas();
~Canvas() override;
// Structure
void set_desktop(SPDesktop *desktop) { _desktop = desktop; }
// Geometry
bool world_point_inside_canvas(Geom::Point const &world); // desktop-events.cpp
Geom::Point canvas_to_world(Geom::Point const &window);
......@@ -149,6 +153,9 @@ private:
// ====== Data members =======
// Structure
SPDesktop * _desktop = nullptr;
// Geometry
int _x0 = 0; ///< World coordinate of the leftmost pixels of window.
int _y0 = 0; ///< World coordinate of the topmost pixels of window.
......
......@@ -194,33 +194,6 @@ void CMSPrefWatcher::_setCmsSensitive(bool enabled)
static CMSPrefWatcher* watcher = nullptr;
void
SPDesktopWidget::setMessage (Inkscape::MessageType type, const gchar *message)
{
_select_status->set_markup(message ? message : "");
// make sure the important messages are displayed immediately!
if (type == Inkscape::IMMEDIATE_MESSAGE && _select_status->get_is_drawable()) {
_select_status->queue_draw();
}
_select_status->set_tooltip_text(_select_status->get_text());
}
Geom::Point
SPDesktopWidget::window_get_pointer()
{
int x, y;
auto window = _canvas->get_window();
auto display = window->get_display();
auto seat = display->get_default_seat();
auto device = seat->get_pointer();
Gdk::ModifierType m;
window->get_device_position(device, x, y, m);
return Geom::Point(x, y);
}
SPDesktopWidget::SPDesktopWidget()
{
auto *const dtw = this;
......@@ -448,6 +421,33 @@ SPDesktopWidget::SPDesktopWidget()
dtw->_canvas->grab_focus();
}
void
SPDesktopWidget::setMessage (Inkscape::MessageType type, const gchar *message)
{
_select_status->set_markup(message ? message : "");
// make sure the important messages are displayed immediately!
if (type == Inkscape::IMMEDIATE_MESSAGE && _select_status->get_is_drawable()) {
_select_status->queue_draw();
}
_select_status->set_tooltip_text(_select_status->get_text());
}
Geom::Point
SPDesktopWidget::window_get_pointer()
{
int x, y;
auto window = _canvas->get_window();
auto display = window->get_display();
auto seat = display->get_default_seat();
auto device = seat->get_pointer();
Gdk::ModifierType m;
window->get_device_position(device, x, y, m);
return Geom::Point(x, y);
}
/**
* Called before SPDesktopWidget destruction.
* (Might be called more than once)
......@@ -468,6 +468,9 @@ SPDesktopWidget::on_unrealize()
conn.disconnect();
}
// Canvas
dtw->_canvas->set_desktop(nullptr); // Canvas may still attempt to draw during destruction.
// Zoom
dtw->_zoom_status_input_connection.disconnect();
dtw->_zoom_status_output_connection.disconnect();
......@@ -1414,6 +1417,7 @@ SPDesktopWidget::SPDesktopWidget(SPDocument *document)
// This section seems backwards!
dtw->desktop = new SPDesktop();
dtw->desktop->init (namedview, dtw->_canvas, this);
dtw->_canvas->set_desktop(desktop);
INKSCAPE.add_desktop (dtw->desktop);
// Add the shape geometry to libavoid for autorouting connectors.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment