1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gdk/gdkkeysyms.h>
35 #include "interface.h"
37 #include "object_ops.h"
38 #include "connectionpoint_ops.h"
44 #include "preferences.h"
45 #include "scroll_tool.h"
47 #include "highlight.h"
49 #include "lib/parent.h"
51 /* This contains the point that was clicked to get this menu */
52 static Point object_menu_clicked_point
;
55 object_menu_proxy(GtkWidget
*widget
, gpointer data
)
57 DiaMenuItem
*dia_menu_item
;
58 ObjectChange
*obj_change
;
60 DDisplay
*ddisp
= ddisplay_active();
64 obj
= (DiaObject
*)ddisp
->diagram
->data
->selected
->data
;
65 dia_menu_item
= (DiaMenuItem
*) data
;
68 object_add_updates(obj
, ddisp
->diagram
);
69 obj_change
= (dia_menu_item
->callback
)(obj
, &object_menu_clicked_point
,
70 dia_menu_item
->callback_data
);
71 object_add_updates(obj
, ddisp
->diagram
);
72 diagram_update_connections_object(ddisp
->diagram
, obj
, TRUE
);
74 if (obj_change
!= NULL
) {
75 undo_object_change(ddisp
->diagram
, obj
, obj_change
);
77 diagram_modified(ddisp
->diagram
);
79 diagram_update_extents(ddisp
->diagram
);
81 if (obj_change
!= NULL
) {
82 undo_set_transactionpoint(ddisp
->diagram
->undo
);
84 message_warning(_("This object doesn't support Undo/Redo.\n"
85 "Undo information erased."));
86 undo_clear(ddisp
->diagram
->undo
);
89 diagram_flush(ddisp
->diagram
);
93 dia_menu_free(DiaMenu
*dia_menu
)
95 if (dia_menu
->app_data
)
96 gtk_object_destroy((GtkObject
*)dia_menu
->app_data
);
97 dia_menu
->app_data
= NULL
;
98 dia_menu
->app_data_free
= NULL
;
102 This add a Properties... menu item to the GtkMenu passed, at the
103 end and set the callback to raise de properties dialog
105 pass TRUE in separator if you want to insert a separator before the poperty
109 add_properties_menu_item (GtkMenu
*menu
, gboolean separator
)
111 GtkWidget
*menu_item
= NULL
;
114 menu_item
= gtk_menu_item_new();
115 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), menu_item
);
116 gtk_widget_show(menu_item
);
119 menu_item
= gtk_menu_item_new_with_label(_("Properties..."));
120 g_signal_connect(GTK_OBJECT(menu_item
), "activate", G_CALLBACK(dialogs_properties_callback
), NULL
);
121 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), menu_item
);
122 gtk_widget_show(menu_item
);
126 create_object_menu(DiaMenu
*dia_menu
)
130 GtkWidget
*menu_item
;
132 menu
= gtk_menu_new();
134 if ( dia_menu
->title
) {
135 menu_item
= gtk_menu_item_new_with_label(gettext(dia_menu
->title
));
136 gtk_widget_set_sensitive(menu_item
, FALSE
);
137 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), menu_item
);
138 gtk_widget_show(menu_item
);
141 menu_item
= gtk_menu_item_new();
142 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), menu_item
);
143 gtk_widget_show(menu_item
);
145 for (i
=0;i
<dia_menu
->num_items
;i
++) {
146 DiaMenuItem
*item
= &dia_menu
->items
[i
];
148 if (item
->active
& DIAMENU_TOGGLE
) {
150 menu_item
= gtk_check_menu_item_new_with_label(gettext(item
->text
));
152 menu_item
= gtk_check_menu_item_new();
153 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_item
),
154 item
->active
& DIAMENU_TOGGLE_ON
);
155 gtk_check_menu_item_set_show_toggle(GTK_CHECK_MENU_ITEM(menu_item
),
159 menu_item
= gtk_menu_item_new_with_label(gettext(item
->text
));
161 menu_item
= gtk_menu_item_new();
163 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), menu_item
);
164 gtk_widget_show(menu_item
);
165 item
->app_data
= menu_item
;
166 if ( dia_menu
->items
[i
].callback
) {
167 /* only connect signal handler if there is actually a callback */
168 gtk_signal_connect(GTK_OBJECT(menu_item
), "activate",
169 (GtkSignalFunc
)object_menu_proxy
, &dia_menu
->items
[i
]);
171 if ( item
->callback_data
) {
172 /* This menu item is a submenu if it has no callback, but does
173 * Have callback_data. In this case the callback_data is a
174 * DiaMenu pointer for the submenu. */
175 if ( ((DiaMenu
*)item
->callback_data
)->app_data
== NULL
) {
176 /* Create the popup menu items for the submenu. */
177 create_object_menu((DiaMenu
*)(item
->callback_data
) ) ;
178 gtk_menu_item_set_submenu( GTK_MENU_ITEM (menu_item
),
179 GTK_WIDGET(((DiaMenu
*)(item
->callback_data
))->app_data
));
185 /* Finally add a Properties... menu item for objects*/
186 add_properties_menu_item(GTK_MENU (menu
), i
> 0);
188 dia_menu
->app_data
= menu
;
189 dia_menu
->app_data_free
= dia_menu_free
;
192 static DiaMenuItem empty_menu_items
[] = { {0, } };
193 static DiaMenu empty_menu
= {
195 sizeof(empty_menu_items
)/sizeof(DiaMenuItem
),
201 popup_object_menu(DDisplay
*ddisp
, GdkEventButton
*bevent
)
205 GtkMenu
*menu
= NULL
;
206 DiaMenu
*dia_menu
= NULL
;
207 GList
*selected_list
;
211 diagram
= ddisp
->diagram
;
212 if (g_list_length (diagram
->data
->selected
) != 1)
215 selected_list
= diagram
->data
->selected
;
217 /* Have to have exactly one selected object */
218 if (selected_list
== NULL
|| g_list_next(selected_list
) != NULL
) {
219 message_error("Selected list is %s while selected_count is %d\n",
220 (selected_list
?"long":"empty"), g_list_length (diagram
->data
->selected
));
224 obj
= (DiaObject
*)g_list_first(selected_list
)->data
;
226 /* Possibly react differently at a handle? */
228 /* Get its menu, and remember the # of object-generated items */
229 if (obj
->ops
->get_object_menu
== NULL
) {
230 dia_menu
= &empty_menu
;
231 if (dia_menu
->title
&&
232 (0 != strcmp(dia_menu
->title
,obj
->type
->name
))) {
233 dia_menu
->app_data_free(dia_menu
);
235 dia_menu
->title
= obj
->type
->name
;
238 dia_menu
= (obj
->ops
->get_object_menu
)(obj
, &object_menu_clicked_point
);
239 num_items
= dia_menu
->num_items
;
242 if (dia_menu
->app_data
== NULL
) {
243 create_object_menu(dia_menu
);
245 /* Update active/nonactive menuitems */
246 for (i
=0;i
<num_items
;i
++) {
247 DiaMenuItem
*item
= &dia_menu
->items
[i
];
248 gtk_widget_set_sensitive(GTK_WIDGET(item
->app_data
),
249 item
->active
& DIAMENU_ACTIVE
);
250 if (item
->active
& DIAMENU_TOGGLE
) {
251 g_signal_handlers_block_by_func(GTK_CHECK_MENU_ITEM(item
->app_data
),
252 (GtkSignalFunc
)object_menu_proxy
, item
);
253 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item
->app_data
),
254 item
->active
& DIAMENU_TOGGLE_ON
);
255 g_signal_handlers_unblock_by_func(GTK_CHECK_MENU_ITEM(item
->app_data
),
256 (GtkSignalFunc
)object_menu_proxy
, item
);
260 menu
= GTK_MENU(dia_menu
->app_data
);
261 /* add the properties menu item to raise the properties from the contextual menu */
263 gtk_menu_popup(menu
, NULL
, NULL
, NULL
, NULL
, bevent
->button
, bevent
->time
);
267 ddisplay_focus_in_event(GtkWidget
*widget
, GdkEventFocus
*event
, gpointer data
)
271 g_return_val_if_fail (widget
!= NULL
, FALSE
);
272 g_return_val_if_fail (event
!= NULL
, FALSE
);
273 g_return_val_if_fail (data
!= NULL
, FALSE
);
275 ddisp
= (DDisplay
*)data
;
277 GTK_WIDGET_SET_FLAGS(widget
, GTK_HAS_FOCUS
);
279 gtk_im_context_focus_in(GTK_IM_CONTEXT(ddisp
->im_context
));
285 ddisplay_focus_out_event(GtkWidget
*widget
, GdkEventFocus
*event
,gpointer data
)
290 g_return_val_if_fail (widget
!= NULL
, FALSE
);
291 g_return_val_if_fail (event
!= NULL
, FALSE
);
292 g_return_val_if_fail (data
!= NULL
, FALSE
);
296 ddisp
= (DDisplay
*)data
;
298 GTK_WIDGET_UNSET_FLAGS (widget
, GTK_HAS_FOCUS
);
300 gtk_im_context_focus_out(GTK_IM_CONTEXT(ddisp
->im_context
));
306 ddisplay_realize(GtkWidget
*widget
, gpointer data
)
310 g_return_if_fail(widget
!= NULL
);
311 g_return_if_fail(data
!= NULL
);
313 ddisp
= (DDisplay
*)data
;
315 gtk_im_context_set_client_window(GTK_IM_CONTEXT(ddisp
->im_context
),
316 GDK_WINDOW(ddisp
->shell
->window
));
320 ddisplay_unrealize (GtkWidget
*widget
, gpointer data
)
324 g_return_if_fail (widget
!= NULL
);
325 g_return_if_fail (data
!= NULL
);
327 ddisp
= (DDisplay
*) data
;
329 if (ddisp
->im_context
)
330 gtk_im_context_set_client_window(GTK_IM_CONTEXT(ddisp
->im_context
),
331 GDK_WINDOW(ddisp
->shell
->window
));
335 ddisplay_size_allocate (GtkWidget
*widget
,
336 GtkAllocation
*allocation
,
341 g_return_if_fail (widget
!= NULL
);
342 g_return_if_fail (allocation
!= NULL
);
343 g_return_if_fail (data
!= NULL
);
346 g_print ("ddisp::size_allocate: %d,%d -> %d,%d\n", allocation
->width
, allocation
->height
,
347 widget
->allocation
.width
, widget
->allocation
.height
);
349 widget
->allocation
= *allocation
;
350 ddisp
= (DDisplay
*)data
;
354 ddisplay_popup_menu(DDisplay
*ddisp
, GdkEventButton
*event
)
358 menu
= menus_get_display_popup();
360 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
, NULL
, NULL
,
361 event
->button
, event
->time
);
364 handle_key_event(DDisplay
*ddisp
, Focus
*focus
, guint keysym
,
365 const gchar
*str
, int strlen
)
367 DiaObject
*obj
= focus_get_object(focus
);
368 Point p
= obj
->position
;
369 ObjectChange
*obj_change
= NULL
;
372 object_add_updates(obj
, ddisp
->diagram
);
374 modified
= (focus
->key_event
)(focus
, keysym
, str
, strlen
,
377 /* Make sure object updates its data and its connected: */
379 (obj
->ops
->move
)(obj
,&p
);
380 diagram_update_connections_object(ddisp
->diagram
,obj
,TRUE
);
382 object_add_updates(obj
, ddisp
->diagram
);
385 if (obj_change
!= NULL
) {
386 undo_object_change(ddisp
->diagram
, obj
, obj_change
);
387 undo_set_transactionpoint(ddisp
->diagram
->undo
);
389 diagram_modified(ddisp
->diagram
);
392 diagram_flush(ddisp
->diagram
);
397 ddisplay_im_context_commit(GtkIMContext
*context
, const gchar
*str
,
400 /* When using IM, we'll not get many key events past the IM filter,
403 regardless of the platform, "str" should be a clean UTF8 string
404 (the default IM on X should perform the local->UTF8 conversion)
407 Focus
*focus
= active_focus();
409 ddisplay_im_context_preedit_reset(ddisp
, focus
);
412 handle_key_event(ddisp
, focus
, 0, str
, g_utf8_strlen(str
,-1));
416 ddisplay_im_context_preedit_changed(GtkIMContext
*context
,
420 Focus
*focus
= active_focus();
422 ddisplay_im_context_preedit_reset(ddisp
, focus
);
424 gtk_im_context_get_preedit_string(context
, &ddisp
->preedit_string
,
425 &ddisp
->preedit_attrs
, &cursor_pos
);
426 if (ddisp
->preedit_string
!= NULL
) {
428 handle_key_event(ddisp
, focus
, 0, ddisp
->preedit_string
,
429 g_utf8_strlen(ddisp
->preedit_string
,-1));
431 ddisplay_im_context_preedit_reset(ddisp
, focus
);
436 /** Main input handler for a diagram canvas.
439 ddisplay_canvas_events (GtkWidget
*canvas
,
443 GdkEventExpose
*eevent
;
444 GdkEventMotion
*mevent
;
445 GdkEventButton
*bevent
;
447 GdkEventScroll
*sevent
;
449 GdkModifierType tmask
;
460 static gboolean moving
= FALSE
;
470 eevent
= (GdkEventExpose
*) event
;
471 ddisplay_add_display_area(ddisp
,
472 eevent
->area
.x
, eevent
->area
.y
,
473 eevent
->area
.x
+ eevent
->area
.width
,
474 eevent
->area
.y
+ eevent
->area
.height
);
475 ddisplay_flush(ddisp
);
479 sevent
= (GdkEventScroll
*) event
;
481 switch (sevent
->direction
)
484 if (sevent
->state
& GDK_SHIFT_MASK
)
485 ddisplay_scroll_left(ddisp
);
486 else if (sevent
->state
& GDK_CONTROL_MASK
) {
487 ddisplay_untransform_coords(ddisp
, sevent
->x
, sevent
->y
, &middle
.x
, &middle
.y
);
488 ddisplay_zoom(ddisp
, &middle
, 2);
491 ddisplay_scroll_up(ddisp
);
493 case GDK_SCROLL_DOWN
:
494 if (sevent
->state
& GDK_SHIFT_MASK
)
495 ddisplay_scroll_right(ddisp
);
496 else if (sevent
->state
& GDK_CONTROL_MASK
) {
497 ddisplay_untransform_coords(ddisp
, sevent
->x
, sevent
->y
, &middle
.x
, &middle
.y
);
498 ddisplay_zoom(ddisp
, &middle
, 0.5);
501 ddisplay_scroll_down(ddisp
);
503 case GDK_SCROLL_LEFT
:
504 ddisplay_scroll_left(ddisp
);
506 case GDK_SCROLL_RIGHT
:
507 ddisplay_scroll_right(ddisp
);
512 ddisplay_flush (ddisp
);
516 if (ddisp
->renderer
!= NULL
) {
517 width
= dia_renderer_get_width_pixels (ddisp
->renderer
);
518 height
= dia_renderer_get_height_pixels (ddisp
->renderer
);
519 new_size
= ((width
!= ddisp
->canvas
->allocation
.width
) ||
520 (height
!= ddisp
->canvas
->allocation
.height
));
525 ddisplay_resize_canvas(ddisp
,
526 ddisp
->canvas
->allocation
.width
,
527 ddisp
->canvas
->allocation
.height
);
528 ddisplay_update_scrollbars(ddisp
);
530 display_set_active(ddisp
);
533 case GDK_FOCUS_CHANGE
: {
534 GdkEventFocus
*focus
= (GdkEventFocus
*)event
;
536 display_set_active(ddisp
);
537 ddisplay_do_update_menu_sensitivity(ddisp
);
541 case GDK_2BUTTON_PRESS
:
542 display_set_active(ddisp
);
543 bevent
= (GdkEventButton
*) event
;
544 state
= bevent
->state
;
546 switch (bevent
->button
)
551 if (active_tool
->double_click_func
)
552 (*active_tool
->double_click_func
) (active_tool
, bevent
, ddisp
);
566 case GDK_BUTTON_PRESS
:
567 display_set_active(ddisp
);
568 bevent
= (GdkEventButton
*) event
;
569 state
= bevent
->state
;
571 ddisplay_untransform_coords(ddisp
,
572 (int)bevent
->x
, (int)bevent
->y
,
573 &object_menu_clicked_point
.x
,
574 &object_menu_clicked_point
.y
);
576 switch (bevent
->button
)
581 /* get the focus again, may be lost by zoom combo */
583 gtk_widget_grab_focus(canvas
);
584 if (active_tool
->button_press_func
)
585 (*active_tool
->button_press_func
) (active_tool
, bevent
, ddisp
);
589 if (ddisp
->menu_bar
== NULL
) {
590 popup_object_menu(ddisp
, bevent
);
592 else if (!transient_tool
) {
593 gtk_widget_grab_focus(canvas
);
594 transient_tool
= create_scroll_tool();
595 (*transient_tool
->button_press_func
) (transient_tool
, bevent
, ddisp
);
602 if (ddisp
->menu_bar
== NULL
) {
603 if (bevent
->state
& GDK_CONTROL_MASK
) {
604 /* for two button mouse users ... */
605 popup_object_menu(ddisp
, bevent
);
608 ddisplay_popup_menu(ddisp
, bevent
);
612 popup_object_menu(ddisp
, bevent
);
620 case GDK_BUTTON_RELEASE
:
621 display_set_active(ddisp
);
622 bevent
= (GdkEventButton
*) event
;
623 state
= bevent
->state
;
625 switch (bevent
->button
)
630 if (active_tool
->button_release_func
)
631 (*active_tool
->button_release_func
) (active_tool
,
636 if (transient_tool
) {
637 (*transient_tool
->button_release_func
) (transient_tool
,
640 tool_free(transient_tool
);
641 transient_tool
= NULL
;
653 case GDK_MOTION_NOTIFY
:
654 /* get the pointer position */
655 gdk_window_get_pointer (canvas
->window
, &tx
, &ty
, &tmask
);
657 mevent
= (GdkEventMotion
*) event
;
658 state
= mevent
->state
;
660 if (mevent
->is_hint
) {
663 mevent
->state
= tmask
;
664 mevent
->is_hint
= FALSE
;
666 if (transient_tool
&& (*transient_tool
->motion_func
))
667 (*transient_tool
->motion_func
) (transient_tool
, mevent
, ddisp
);
668 else if (active_tool
->motion_func
)
669 (*active_tool
->motion_func
) (active_tool
, mevent
, ddisp
);
673 if (moving
) /*Disable Keyboard accels whilst draggin an object*/
675 display_set_active(ddisp
);
676 kevent
= (GdkEventKey
*)event
;
677 state
= kevent
->state
;
679 im_context_used
= FALSE
;
681 focus
= active_focus();
683 /* Keys goes to the active focus. */
684 obj
= focus_get_object(focus
);
685 if (diagram_is_selected(ddisp
->diagram
, obj
)) {
687 if (!gtk_im_context_filter_keypress(
688 GTK_IM_CONTEXT(ddisp
->im_context
), kevent
)) {
690 if (kevent
->keyval
== GDK_Tab
) {
691 focus
= textedit_move_focus(ddisp
, focus
,
692 (state
& GDK_SHIFT_MASK
) == 0);
693 obj
= focus_get_object(focus
);
695 /*! key event not swallowed by the input method ? */
696 handle_key_event(ddisp
, focus
, kevent
->keyval
,
697 kevent
->string
, kevent
->length
);
699 diagram_flush(ddisp
->diagram
);
702 return_val
= key_handled
= im_context_used
= TRUE
;
706 #if 0 /* modifier requirment added 2004-07-17, IMO reenabling unmodified keys here
707 * shouldn't break im_context handling. How to test? --hb
709 if (!key_handled
&& (state
& (GDK_CONTROL_MASK
| GDK_MOD1_MASK
))) {
713 /* IM doesn't need receive keys, take care of it ourselves. */
716 switch(kevent
->keyval
) {
718 ddisplay_scroll_up(ddisp
);
719 ddisplay_flush(ddisp
);
722 ddisplay_scroll_down(ddisp
);
723 ddisplay_flush(ddisp
);
726 ddisplay_scroll_left(ddisp
);
727 ddisplay_flush(ddisp
);
730 ddisplay_scroll_right(ddisp
);
731 ddisplay_flush(ddisp
);
735 visible
= &ddisp
->visible
;
736 middle
.x
= visible
->left
*0.5 + visible
->right
*0.5;
737 middle
.y
= visible
->top
*0.5 + visible
->bottom
*0.5;
739 ddisplay_zoom(ddisp
, &middle
, M_SQRT2
);
741 case GDK_KP_Subtract
:
743 visible
= &ddisp
->visible
;
744 middle
.x
= visible
->left
*0.5 + visible
->right
*0.5;
745 middle
.y
= visible
->top
*0.5 + visible
->bottom
*0.5;
747 ddisplay_zoom(ddisp
, &middle
, M_SQRT1_2
);
751 if (active_tool
->type
== MAGNIFY_TOOL
)
752 set_zoom_out(active_tool
);
758 if (kevent
->string
&& kevent
->keyval
== ' ') {
759 tool_select_former();
760 } else if ((kevent
->state
& (GDK_MOD1_MASK
|GDK_CONTROL_MASK
)) == 0 &&
761 kevent
->length
!= 0) {
762 /* Find first editable */
764 modify_edit_first_text(ddisp
);
771 if (!im_context_used
)
772 gtk_im_context_reset(GTK_IM_CONTEXT(ddisp
->im_context
));
776 case GDK_KEY_RELEASE
:
777 kevent
= (GdkEventKey
*) event
;
778 state
= kevent
->state
;
779 if (gtk_im_context_filter_keypress(GTK_IM_CONTEXT(ddisp
->im_context
),
783 switch(kevent
->keyval
) {
786 if (active_tool
->type
== MAGNIFY_TOOL
)
787 set_zoom_in(active_tool
);
803 ddisplay_hsb_update (GtkAdjustment
*adjustment
,
806 ddisplay_set_origo(ddisp
, adjustment
->value
, ddisp
->origo
.y
);
807 ddisplay_add_update_all(ddisp
);
808 ddisplay_flush(ddisp
);
813 ddisplay_vsb_update (GtkAdjustment
*adjustment
,
816 ddisplay_set_origo(ddisp
, ddisp
->origo
.x
, adjustment
->value
);
817 ddisplay_add_update_all(ddisp
);
818 ddisplay_flush(ddisp
);
823 ddisplay_delete (GtkWidget
*widget
, GdkEvent
*event
, gpointer data
)
827 ddisp
= (DDisplay
*)data
;
829 ddisplay_close(ddisp
);
834 ddisplay_destroy (GtkWidget
*widget
, gpointer data
)
838 ddisp
= (DDisplay
*) data
;
840 ddisplay_really_destroy(ddisp
);
843 /* returns NULL if object cannot be created */
845 ddisplay_drop_object(DDisplay
*ddisp
, gint x
, gint y
, DiaObjectType
*otype
,
849 Point droppoint_orig
;
850 Handle
*handle1
, *handle2
;
851 DiaObject
*obj
, *p_obj
;
855 ddisplay_untransform_coords(ddisp
, x
, y
, &droppoint
.x
, &droppoint
.y
);
857 /* save it before snap_to_grid modifies it */
858 droppoint_orig
= droppoint
;
860 snap_to_grid(ddisp
, &droppoint
.x
, &droppoint
.y
);
862 obj
= dia_object_default_create (otype
, &droppoint
,
867 click_distance
= ddisplay_untransform_length(ddisp
, 3.0);
869 /* Notice that using diagram_find_clicked_object doesn't allow any object
870 * below the first to be a parent. This should be fixed.
873 p_obj
= diagram_find_clicked_object(ddisp
->diagram
, &droppoint_orig
,
876 if (p_obj
&& object_flags_set(p_obj
, DIA_OBJECT_CAN_PARENT
))
877 /* the tool was dropped inside an object that takes children*/
879 Rectangle p_ext
, c_ext
;
880 real parent_height
, child_height
, parent_width
, child_width
;
881 real vadjust
= 0.0, hadjust
= 0.0;
885 p_obj
->children
= g_list_append(p_obj
->children
, obj
);
887 /* This is not really what we want. We want the box containing all
888 * rendered parts of the object (not the bbox). But it'll do for now,
889 * since we don't have the 'rendered bbox'.
892 parent_handle_extents(p_obj
, &p_ext
);
893 parent_handle_extents(obj
, &c_ext
);
895 parent_height
= p_ext
.bottom
- p_ext
.top
;
896 child_height
= c_ext
.bottom
- c_ext
.top
;
898 parent_width
= p_ext
.right
- p_ext
.left
;
899 child_width
= c_ext
.right
- c_ext
.left
;
901 /* we need the pre-snap position, but must remember that handles can
902 * be to the left of the droppoint */
903 c_ext
.left
= droppoint_orig
.x
- (obj
->position
.x
- c_ext
.left
);
904 c_ext
.top
= droppoint_orig
.y
- (obj
->position
.y
- c_ext
.top
);
905 c_ext
.right
= c_ext
.left
+ child_width
;
906 c_ext
.bottom
= c_ext
.top
+ child_height
;
908 if (c_ext
.left
< p_ext
.left
) {
909 hadjust
= p_ext
.left
- c_ext
.left
;
910 } else if (c_ext
.right
> p_ext
.right
) {
911 hadjust
= p_ext
.right
- c_ext
.right
;
913 if (c_ext
.top
< p_ext
.top
) {
914 vadjust
= p_ext
.top
- c_ext
.top
;
915 } else if (c_ext
.bottom
> p_ext
.bottom
) {
916 vadjust
= p_ext
.bottom
- c_ext
.bottom
;
919 if (child_width
> parent_width
||
920 child_height
> parent_height
) {
921 message_error(_("The object you dropped cannot fit into its parent. \nEither expand the parent object, or drop the object elsewhere."));
922 obj
->parent
->children
= g_list_remove(obj
->parent
->children
, obj
);
923 obj
->ops
->destroy (obj
);
927 if (hadjust
|| vadjust
) {
928 new_pos
.x
= droppoint
.x
+ hadjust
;
929 new_pos
.y
= droppoint
.y
+ vadjust
;
930 obj
->ops
->move(obj
, &new_pos
);
934 diagram_add_object(ddisp
->diagram
, obj
);
935 diagram_remove_all_selected(ddisp
->diagram
, TRUE
); /* unselect all */
936 diagram_select(ddisp
->diagram
, obj
);
937 obj
->ops
->selectf(obj
, &droppoint
, ddisp
->renderer
);
938 textedit_activate_object(ddisp
, obj
, NULL
);
940 /* Connect first handle if possible: */
941 if ((handle1
!= NULL
) &&
942 (handle1
->connect_type
!= HANDLE_NONCONNECTABLE
)) {
943 object_connect_display(ddisp
, obj
, handle1
, FALSE
);
945 object_add_updates(obj
, ddisp
->diagram
);
946 ddisplay_do_update_menu_sensitivity(ddisp
);
947 diagram_flush(ddisp
->diagram
);
949 list
= g_list_prepend(NULL
, obj
);
950 undo_insert_objects(ddisp
->diagram
, list
, 1);
951 diagram_update_extents(ddisp
->diagram
);
953 undo_set_transactionpoint(ddisp
->diagram
->undo
);
954 diagram_modified(ddisp
->diagram
);
955 if (prefs
.reset_tools_after_create
)