/* This is called when ddisp->shell is destroyed... */ void ddisplay_really_destroy(DDisplay *ddisp) { if (active_display == ddisp) display_set_active(NULL); /* last chance to avoid crashing in the idle update */ if (ddisp->update_id) { g_source_remove (ddisp->update_id); ddisp->update_id = 0; } if (ddisp->diagram) { diagram_remove_ddisplay(ddisp->diagram, ddisp); /* if we are the last user of the diagram it will be unref'ed */ g_object_unref(ddisp->diagram); ddisp->diagram = NULL; } g_object_unref (ddisp->renderer); ddisp->renderer = NULL; /* Free update_areas list: */ ddisplay_free_update_areas(ddisp); /* Free display_areas list */ ddisplay_free_display_areas(ddisp); g_free(ddisp); }
/** Ensure the object is visible but minimize scrolling */ gboolean ddisplay_present_object(DDisplay *ddisp, DiaObject *obj) { const Rectangle *r = dia_object_get_enclosing_box(obj); const Rectangle *v = &ddisp->visible; display_set_active(ddisp); if (!rectangle_in_rectangle(v, r)) { Point delta = { 0, 0 }; if ((r->right - r->left) > (v->right - v->left)) /* object bigger than visible area */ delta.x = (r->left - v->left + r->right - v->right) / 2; else if (r->left < v->left) delta.x = r->left - v->left; else if (r->right > v->right) delta.x = r->right - v->right; if ((r->bottom - r->top) > (v->bottom - v->top)) /* object bigger than visible area */ delta.y = (r->top - v->top + r->bottom - v->bottom) / 2; else if (r->top < v->top) delta.y = r->top - v->top; else if (r->bottom > v->bottom) delta.y = r->bottom - v->bottom; ddisplay_scroll(ddisp, &delta); return TRUE; } return FALSE; }
/** Scroll display so that obj is centered. * Returns TRUE if anything changed. */ gboolean ddisplay_scroll_to_object(DDisplay *ddisp, DiaObject *obj) { Rectangle r = obj->bounding_box; Point p; p.x = (r.left+r.right)/2; p.y = (r.top+r.bottom)/2; display_set_active(ddisp); return ddisplay_scroll_center_point(ddisp, &p); }
static gint origin_button_press(GtkWidget *widget, GdkEventButton *event, gpointer data) { DDisplay *ddisp = (DDisplay *)data; display_set_active(ddisp); ddisplay_popup_menu(ddisp, event); /* stop the signal emission so the button doesn't grab the * pointer from us */ g_signal_stop_emission_by_name (G_OBJECT(widget), "button_press_event"); return FALSE; }
Diagram * diagram_load(const char *filename, DiaImportFilter *ifilter) { Diagram *diagram = NULL; GList *diagrams; gboolean was_default = FALSE; for (diagrams = open_diagrams; diagrams != NULL; diagrams = g_list_next(diagrams)) { Diagram *old_diagram = (Diagram*)diagrams->data; if (old_diagram->is_default) { diagram = old_diagram; was_default = TRUE; break; } } /* TODO: Make diagram not be initialized twice */ if (diagram == NULL) { diagram = new_diagram(filename); } if (diagram == NULL) return NULL; if ( !diagram_init(diagram, filename) || !diagram_load_into (diagram, filename, ifilter)) { if (!was_default) /* don't kill the default diagram on import failure */ diagram_destroy(diagram); diagram = NULL; } else { /* not modifying 'diagram->unsaved' the state depends on the import filter used */ diagram_set_modified(diagram, FALSE); if (app_is_interactive()) { recent_file_history_add(filename); if (was_default) /* replacing it is like first remove than add */ dia_diagram_remove(diagram); dia_diagram_add(diagram); } } if (diagram != NULL && was_default && app_is_interactive()) { diagram_update_for_filename(diagram); diagram->is_default = FALSE; if ( g_slist_length(diagram->displays) == 1 ) display_set_active (diagram->displays->data); } return diagram; }
/*! * Called when the widget's window "size, position or stacking" * changes. Needs GDK_STRUCTURE_MASK set. */ static gboolean canvas_configure_event (GtkWidget *widget, GdkEventConfigure *cevent, DDisplay *ddisp) { gboolean new_size = FALSE; int width, height; g_return_val_if_fail (widget == ddisp->canvas, FALSE); if (ddisp->renderer) { width = dia_renderer_get_width_pixels (ddisp->renderer); height = dia_renderer_get_height_pixels (ddisp->renderer); } else { /* We can continue even without a renderer here because * ddisplay_resize_canvas () does the setup for us. */ width = height = 0; } /* Only do this when size is really changing */ if (width != cevent->width || height != cevent->height) { g_print ("Canvas size change...\n"); ddisplay_resize_canvas (ddisp, cevent->width, cevent->height); ddisplay_update_scrollbars(ddisp); /* on resize stop further propagation - does not help */ new_size = TRUE; } /* If the UI is not integrated, resizing should set the resized * window as active. With integrated UI, there is only one window. */ if (is_integrated_ui () == 0) display_set_active(ddisp); /* continue propagation with FALSE */ return new_size; }