[dia] [embedded image] introduce ddisplay_get_clicked_position()
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] [embedded image] introduce ddisplay_get_clicked_position()
- Date: Fri, 11 Mar 2011 21:16:48 +0000 (UTC)
commit 0b7106e3ea9ca9d49d7144e82a4c8dddcda071aa
Author: Hans Breuer <hans breuer org>
Date: Fri Mar 11 22:10:41 2011 +0100
[embedded image] introduce ddisplay_get_clicked_position()
The positioning for "Paste image" was depending on the menu entries position.
Now the display remembers the last clicked point and that's used for more
reliable pasting.
Also there was a bug with undo, now fixed.
app/commands.c | 12 ++++++++----
app/disp_callbacks.c | 18 ++++++++----------
app/display.c | 26 ++++++++++++++++++++++++++
app/display.h | 6 ++++++
4 files changed, 48 insertions(+), 14 deletions(-)
---
diff --git a/app/commands.c b/app/commands.c
index e80e364..7d93401 100644
--- a/app/commands.c
+++ b/app/commands.c
@@ -268,10 +268,7 @@ received_clipboard_image_handler(GtkClipboard *clipboard,
Handle *handle2;
DiaObject *obj;
- gdk_window_get_pointer (gtk_widget_get_window (ddisp->canvas),
- &x, &y, NULL);
- ddisplay_untransform_coords (ddisp, x, y, &pt.x, &pt.y);
-
+ pt = ddisplay_get_clicked_position(ddisp);
snap_to_grid(ddisp, &pt.x, &pt.y);
if ( ((type = object_get_type ("Standard - Image")) != NULL)
@@ -288,12 +285,19 @@ received_clipboard_image_handler(GtkClipboard *clipboard,
diagram_add_object (dia, obj);
diagram_select(dia, obj);
object_add_updates(obj, dia);
+
ddisplay_do_update_menu_sensitivity(ddisp);
diagram_flush(dia);
} else {
message_warning (_("No selected object can take an image."));
}
}
+ /* although freed above it is still the indicator of diagram modification */
+ if (change) {
+ diagram_update_extents(dia);
+ undo_set_transactionpoint(dia->undo);
+ diagram_modified(dia);
+ }
}
void
diff --git a/app/disp_callbacks.c b/app/disp_callbacks.c
index 667f13f..543f2dd 100644
--- a/app/disp_callbacks.c
+++ b/app/disp_callbacks.c
@@ -47,9 +47,6 @@
#include "dia_dirs.h"
#include "object.h"
-/* This contains the point that was clicked to get this menu */
-static Point object_menu_clicked_point;
-
typedef struct {
GdkEvent *event; /* Button down event which may be holding */
DDisplay *ddisp; /* DDisplay where event occurred */
@@ -67,15 +64,17 @@ object_menu_proxy(GtkWidget *widget, gpointer data)
ObjectChange *obj_change;
DiaObject *obj;
DDisplay *ddisp = ddisplay_active();
+ Point last_clicked_pos;
if (!ddisp) return;
+ last_clicked_pos = ddisplay_get_clicked_position(ddisp);
obj = (DiaObject *)ddisp->diagram->data->selected->data;
dia_menu_item = (DiaMenuItem *) data;
object_add_updates(obj, ddisp->diagram);
- obj_change = (dia_menu_item->callback)(obj, &object_menu_clicked_point,
+ obj_change = (dia_menu_item->callback)(obj, &last_clicked_pos,
dia_menu_item->callback_data);
object_add_updates(obj, ddisp->diagram);
diagram_update_connections_object(ddisp->diagram, obj, TRUE);
@@ -254,6 +253,7 @@ popup_object_menu(DDisplay *ddisp, GdkEventButton *bevent)
GList *selected_list;
int i;
int num_items;
+ Point last_clicked_pos;
diagram = ddisp->diagram;
if (g_list_length (diagram->data->selected) < 1)
@@ -268,6 +268,7 @@ popup_object_menu(DDisplay *ddisp, GdkEventButton *bevent)
return;
}
+ last_clicked_pos = ddisplay_get_clicked_position(ddisp);
obj = (DiaObject *)g_list_first(selected_list)->data;
/* Possibly react differently at a handle? */
@@ -275,7 +276,7 @@ popup_object_menu(DDisplay *ddisp, GdkEventButton *bevent)
/* Get its menu, and remember the # of object-generated items */
if ( g_list_length (diagram->data->selected) > 1
|| obj->ops->get_object_menu == NULL
- || (obj->ops->get_object_menu)(obj, &object_menu_clicked_point) == NULL) {
+ || (obj->ops->get_object_menu)(obj, &last_clicked_pos) == NULL) {
dia_menu = &empty_menu;
if (dia_menu->title &&
(0 != strcmp(dia_menu->title,obj->type->name))) {
@@ -287,7 +288,7 @@ popup_object_menu(DDisplay *ddisp, GdkEventButton *bevent)
dia_menu->title = obj->type->name;
num_items = 0;
} else {
- dia_menu = (obj->ops->get_object_menu)(obj, &object_menu_clicked_point);
+ dia_menu = (obj->ops->get_object_menu)(obj, &last_clicked_pos);
num_items = dia_menu->num_items;
}
@@ -708,10 +709,7 @@ ddisplay_canvas_events (GtkWidget *canvas,
display_set_active(ddisp);
bevent = (GdkEventButton *) event;
- ddisplay_untransform_coords(ddisp,
- (int)bevent->x, (int)bevent->y,
- &object_menu_clicked_point.x,
- &object_menu_clicked_point.y);
+ ddisplay_set_clicked_point (ddisp, bevent->x, bevent->y);
switch (bevent->button)
{
diff --git a/app/display.c b/app/display.c
index a2ba76c..f6846d3 100644
--- a/app/display.c
+++ b/app/display.c
@@ -248,6 +248,8 @@ copy_display(DDisplay *orig_ddisp)
ddisp->display_areas = orig_ddisp->display_areas;
ddisp->update_id = 0;
+ ddisp->clicked_position.x = ddisp->clicked_position.y = 0.0;
+
diagram_add_ddisplay(dia, ddisp);
g_signal_connect (dia, "selection_changed", G_CALLBACK(selection_changed), ddisp);
ddisp->origo = orig_ddisp->origo;
@@ -305,6 +307,8 @@ new_display(Diagram *dia)
ddisp->display_areas = NULL;
ddisp->update_id = 0;
+ ddisp->clicked_position.x = ddisp->clicked_position.y = 0.0;
+
diagram_add_ddisplay(dia, ddisp);
g_signal_connect (dia, "selection_changed", G_CALLBACK(selection_changed), ddisp);
ddisp->origo.x = 0.0;
@@ -1098,6 +1102,28 @@ ddisplay_present_object(DDisplay *ddisp, DiaObject *obj)
return FALSE;
}
+/*!
+ * Remember the last clicked point given in pixel coodinates
+ */
+void
+ddisplay_set_clicked_point(DDisplay *ddisp, int x, int y)
+{
+ Point pt;
+
+ ddisplay_untransform_coords(ddisp, x, y, &pt.x, &pt.y);
+
+ ddisp->clicked_position = pt;
+}
+
+/*! Get the last clicked point in diagram coordinates
+ */
+Point
+ddisplay_get_clicked_position(DDisplay *ddisp)
+{
+ return ddisp->clicked_position;
+}
+
+
/**
* Kind of dirty way to init an antialiased renderer, there should be some plug-in interface to do this.
* Now with the Libart renderer being a plug-in and the cairo renderer having issues with highlighting
diff --git a/app/display.h b/app/display.h
index a91088f..8c81184 100644
--- a/app/display.h
+++ b/app/display.h
@@ -107,6 +107,9 @@ struct _DDisplay {
/* Private field, indicates which text, if any, is being edited */
Focus *active_focus;
+
+ /* Rember the last clicked point per display, but in diagram coordinates */
+ Point clicked_position;
};
extern GdkCursor *default_cursor;
@@ -160,6 +163,9 @@ void ddisplay_set_title(DDisplay *ddisp, char *title);
void ddisplay_set_cursor(DDisplay *ddisp, GdkCursor *cursor);
void ddisplay_set_all_cursor(GdkCursor *cursor);
+void ddisplay_set_clicked_point(DDisplay *ddisp, int x, int y);
+Point ddisplay_get_clicked_position(DDisplay *ddisp);
+
gboolean display_get_rulers_showing(DDisplay *ddisp);
void display_rulers_show (DDisplay *ddisp);
void display_rulers_hide (DDisplay *ddisp);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]