static gint properties_apply(GtkWidget *canvas, gpointer data) { ObjectChange *obj_change = NULL; if ( (current_obj == NULL) || (current_dia == NULL) ) return 0; object_add_updates(current_obj, current_dia); obj_change = current_obj->ops->apply_properties(current_obj); object_add_updates(current_obj, current_dia); diagram_update_connections_object(current_dia, current_obj, TRUE); if (obj_change != NULL) { undo_object_change(current_dia, current_obj, obj_change); } diagram_modified(current_dia); diagram_update_extents(current_dia); if (obj_change != NULL) { undo_set_transactionpoint(current_dia->undo); } else { message_warning(_("This object doesn't support Undo/Redo.\n" "Undo information erased.")); undo_clear(current_dia->undo); } diagram_flush(current_dia); return 0; }
/* Match and replace property values. */ static gboolean _replace (DiaObject *obj, const SearchData *sd, const char *replacement) { ObjectChange *obj_change; GPtrArray *plist = NULL; plist = _match_props (obj, sd, replacement); if (!plist) return FALSE; /* Refresh screen and free the list of modified properties. */ obj_change = object_apply_props (obj, plist); prop_list_free (plist); if (obj_change) undo_object_change(sd->diagram, obj, obj_change); object_add_updates(obj, sd->diagram); diagram_update_connections_object(sd->diagram, obj, TRUE); diagram_modified(sd->diagram); diagram_object_modified(sd->diagram, obj); diagram_update_extents(sd->diagram); diagram_flush(sd->diagram); return TRUE; }
static void edit_layer_add_ok_callback (GtkWidget *w, gpointer client_data) { EditLayerDialog *dialog = (EditLayerDialog *) client_data; Diagram *dia = ddisplay_active_diagram(); Layer *layer; int pos = data_layer_get_index (dia->data, dia->data->active_layer) + 1; layer = new_layer(g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->name_entry))), dia->data); data_add_layer_at(dia->data, layer, pos); data_set_active_layer(dia->data, layer); diagram_add_update_all(dia); diagram_flush(dia); undo_layer(dia, layer, TYPE_ADD_LAYER, pos); undo_set_transactionpoint(dia->undo); /* ugly way of updating the layer widget */ if (layer_dialog && layer_dialog->diagram == dia) { layer_dialog_set_diagram(dia); } gtk_widget_destroy (dialog->dialog); g_free (dialog); }
static void modify_double_click(ModifyTool *tool, GdkEventButton *event, DDisplay *ddisp) { Point clickedpoint; DiaObject *clicked_obj; ddisplay_untransform_coords(ddisp, (int)event->x, (int)event->y, &clickedpoint.x, &clickedpoint.y); clicked_obj = click_select_object(ddisp, &clickedpoint, event); if ( clicked_obj != NULL ) { object_list_properties_show(ddisp->diagram, ddisp->diagram->data->selected); } else { /* No object selected */ /*printf("didn't select object\n");*/ if (!(event->state & GDK_SHIFT_MASK)) { /* Not Multi-select => Remove all selected */ ddisplay_do_update_menu_sensitivity(ddisp); diagram_remove_all_selected(ddisp->diagram, TRUE); diagram_flush(ddisp->diagram); } } }
static void dia_layer_widget_connectable_toggled(GtkToggleButton *widget, gpointer userdata) { DiaLayerWidget *lw = DIA_LAYER_WIDGET(userdata); if (!lw->layer) return; if (shifted) { shifted = FALSE; internal_call = TRUE; dia_layer_widget_exclusive_connectable(lw); internal_call = FALSE; } else { lw->layer->connectable = gtk_toggle_button_get_active(widget); } if (lw->layer == lw->dia->data->active_layer) { lw->connect_off = !gtk_toggle_button_get_active(widget); if (lw->connect_off) lw->connect_on = FALSE; } else { lw->connect_on = gtk_toggle_button_get_active(widget); if (lw->connect_on) lw->connect_off = FALSE; } gtk_widget_queue_draw(GTK_WIDGET(lw)); if (!internal_call) { diagram_add_update_all(lw->dia); diagram_flush(lw->dia); } }
static void layer_dialog_delete_callback(GtkWidget *widget, gpointer gdata) { Diagram *dia; GtkWidget *selected; Layer *layer; int pos; dia = layer_dialog->diagram; if ((dia != NULL) && (dia->data->layers->len>1)) { assert(GTK_LIST(layer_dialog->layer_list)->selection != NULL); selected = GTK_LIST(layer_dialog->layer_list)->selection->data; layer = dia->data->active_layer; data_remove_layer(dia->data, layer); diagram_add_update_all(dia); diagram_flush(dia); pos = gtk_list_child_position(GTK_LIST(layer_dialog->layer_list), selected); gtk_container_remove(GTK_CONTAINER(layer_dialog->layer_list), selected); undo_layer(dia, layer, TYPE_DELETE_LAYER, dia->data->layers->len - pos); undo_set_transactionpoint(dia->undo); if (--pos<0) pos = 0; gtk_list_select_item(GTK_LIST(layer_dialog->layer_list), pos); } }
/** Remove all selected objects from their parents (if any). */ void diagram_unparent_selected(Diagram *dia) { GList *list; DiaObject *obj, *parent; Change *change; gboolean any_unparented = FALSE; for (list = dia->data->selected; list != NULL; list = g_list_next(list)) { obj = (DiaObject *) list->data; parent = obj->parent; if (!parent) continue; change = undo_parenting(dia, parent, obj, FALSE); (change->apply)(change, dia); any_unparented = TRUE; /* parent->children = g_list_remove(parent->children, obj); obj->parent = NULL; */ } if (any_unparented) { diagram_modified(dia); diagram_flush(dia); undo_set_transactionpoint(dia->undo); } }
/** Remove all children from the selected parents. */ void diagram_unparent_children_selected(Diagram *dia) { GList *list; DiaObject *obj, *child; gboolean any_unparented = FALSE; for (list = dia->data->selected; list != NULL; list = g_list_next(list)) { obj = (DiaObject *) list->data; if (!object_flags_set(obj, DIA_OBJECT_CAN_PARENT) || !obj->children) continue; any_unparented = TRUE; /* Yes, this creates a whole bunch of Changes. They're lightweight * structures, though, and it's easier to assure correctness this * way. If needed, we can make a parent undo with a list of children. */ while (obj->children != NULL) { Change *change; child = (DiaObject *) obj->children->data; change = undo_parenting(dia, obj, child, FALSE); /* This will remove one item from the list, so the while terminates. */ (change->apply)(change, dia); } if (obj->children != NULL) printf("Obj still has %d children\n", g_list_length(obj->children)); } if (any_unparented) { diagram_modified(dia); diagram_flush(dia); undo_set_transactionpoint(dia->undo); } }
void diagram_update_extents(Diagram *dia) { gfloat cur_scale = dia->data->paper.scaling; /* anropar update_scrollbars() */ if (data_update_extents(dia->data)) { /* Update scrollbars because extents were changed: */ GSList *l; DDisplay *ddisp; l = dia->displays; while (l!=NULL) { ddisp = (DDisplay *) l->data; ddisplay_update_scrollbars(ddisp); l = g_slist_next(l); } if (cur_scale != dia->data->paper.scaling) { diagram_add_update_all(dia); diagram_flush(dia); } } }
static PyObject * PyDiaDiagram_Flush(PyDiaDiagram *self, PyObject *args) { if (!PyArg_ParseTuple(args, ":Diagram.flush")) return NULL; diagram_flush(self->dia); Py_INCREF(Py_None); return Py_None; }
static gint properties_respond(GtkWidget *widget, gint response_id, gpointer data) { ObjectChange *obj_change = NULL; gboolean set_tp = TRUE; GList *tmp; if ( response_id == GTK_RESPONSE_APPLY || response_id == GTK_RESPONSE_OK) { if ((current_objects != NULL) && (current_dia != NULL)) { object_add_updates_list(current_objects, current_dia); for (tmp = current_objects; tmp != NULL; tmp = tmp->next) { DiaObject *current_obj = (DiaObject*)tmp->data; obj_change = current_obj->ops->apply_properties_from_dialog(current_obj, object_part); object_add_updates(current_obj, current_dia); diagram_update_connections_object(current_dia, current_obj, TRUE); if (obj_change != NULL) { undo_object_change(current_dia, current_obj, obj_change); set_tp = set_tp && TRUE; } else set_tp = FALSE; diagram_object_modified(current_dia, current_obj); } diagram_modified(current_dia); diagram_update_extents(current_dia); if (set_tp) { undo_set_transactionpoint(current_dia->undo); } else { message_warning(_("This object doesn't support Undo/Redo.\n" "Undo information erased.")); undo_clear(current_dia->undo); } diagram_flush(current_dia); } } if (response_id != GTK_RESPONSE_APPLY) { #ifdef G_OS_WIN32 /* on windows we are not hiding the dialog, because shrinking when hidden does * not work (the dialog shows up with the same size as before, bug #333751) */ gtk_widget_destroy (dialog); #else properties_dialog_hide(); #endif } return 0; }
void diagram_group_selected(Diagram *dia) { GList *list; GList *group_list; DiaObject *group; DiaObject *obj; GList *orig_list; Change *change; if (g_list_length(dia->data->selected) < 1) { message_error(_("Trying to group with no selected objects.")); return; } #if 0 /* the following is wrong as it screws up the selected list, see bug #153525 * I just don't get what was originally intented so please speak up if you know --hb */ dia->data->selected = parent_list_affected(dia->data->selected); #endif orig_list = g_list_copy(dia->data->active_layer->objects); /* We have to rebuild the selection list so that it is the same order as in the Diagram list. */ group_list = diagram_get_sorted_selected_remove(dia); list = group_list; while (list != NULL) { obj = (DiaObject *)list->data; /* Remove connections from obj to objects outside created group. */ /* strip_connections sets up its own undo info. */ /* The connections aren't reattached by ungroup. */ strip_connections(obj, dia->data->selected, dia); list = g_list_next(list); } /* Remove list of selected objects */ textedit_remove_focus_all(dia); data_remove_all_selected(dia->data); group = group_create(group_list); change = undo_group_objects(dia, group_list, group, orig_list); (change->apply)(change, dia); /* Select the created group */ diagram_select(dia, group); diagram_modified(dia); diagram_flush(dia); undo_set_transactionpoint(dia->undo); }
/* needs faster algorithm -- if we find that parenting is slow. * If it works, don't optimize it until it's a hotspot. */ void diagram_parent_selected(Diagram *dia) { GList *list = dia->data->selected; int length = g_list_length(list); int idx, idx2; ObjectExtent *oe; gboolean any_parented = FALSE; GPtrArray *extents = g_ptr_array_sized_new(length); while (list) { oe = g_new(ObjectExtent, 1); oe->object = list->data; parent_handle_extents(list->data, &oe->extent); g_ptr_array_add(extents, oe); list = g_list_next(list); } /* sort all the objects by their left position */ g_ptr_array_sort(extents, diagram_parent_sort_cb); for (idx = 0; idx < length; idx++) { ObjectExtent *oe1 = g_ptr_array_index(extents, idx); if (oe1->object->parent) continue; for (idx2 = idx + 1; idx2 < length; idx2++) { ObjectExtent *oe2 = g_ptr_array_index(extents, idx2); if (!object_flags_set(oe2->object, DIA_OBJECT_CAN_PARENT)) continue; if (oe1->extent.right <= oe2->extent.right && oe1->extent.bottom <= oe2->extent.bottom) { Change *change; change = undo_parenting(dia, oe2->object, oe1->object, TRUE); (change->apply)(change, dia); any_parented = TRUE; /* oe1->object->parent = oe2->object; oe2->object->children = g_list_append(oe2->object->children, oe1->object); */ break; } } } g_ptr_array_free(extents, TRUE); if (any_parented) { diagram_modified(dia); diagram_flush(dia); undo_set_transactionpoint(dia->undo); } }
static void edit_layer_rename_ok_callback (GtkWidget *w, gpointer client_data) { EditLayerDialog *dialog = (EditLayerDialog *) client_data; Diagram *dia = ddisplay_active_diagram(); Layer *layer = dia->data->active_layer; g_free (layer->name); layer->name = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->name_entry))); diagram_add_update_all(dia); diagram_flush(dia); /* FIXME: undo handling */ gtk_widget_destroy (dialog->dialog); g_free (dialog); }
void diagram_place_down_selected(Diagram *dia) { GList *sorted_list; GList *orig_list; GList *tmp, *stmp; GList *new_list = NULL; if (g_list_length (dia->data->selected) == 0) return; orig_list = g_list_copy(dia->data->active_layer->objects); sorted_list = diagram_get_sorted_selected(dia); object_add_updates_list(orig_list, dia); /* Sanity check */ g_assert(g_list_length (dia->data->selected) == g_list_length(sorted_list)); new_list = g_list_copy(orig_list); stmp = sorted_list; for (tmp = new_list; tmp != NULL; tmp = g_list_next(tmp)) { if (stmp == NULL) break; if (tmp->next == NULL) break; if (tmp->data == stmp->data) { /* This just takes care of any starting matches */ stmp = g_list_next(stmp); } else if (tmp->next->data == stmp->data) { /* This flips the non-selected element forwards, ala bubblesort */ void *swap = tmp->data; tmp->data = tmp->next->data; tmp->next->data = swap; stmp = g_list_next(stmp); } } layer_set_object_list(dia->data->active_layer, new_list); undo_reorder_objects(dia, g_list_copy(sorted_list), orig_list); diagram_modified(dia); diagram_flush(dia); undo_set_transactionpoint(dia->undo); }
void diagram_redraw_all() { GList *list; Diagram *dia; list = open_diagrams; while (list != NULL) { dia = (Diagram *) list->data; diagram_add_update_all(dia); diagram_flush(dia); list = g_list_next(list); } return; }
void diagram_ungroup_selected(Diagram *dia) { DiaObject *group; GList *group_list; GList *selected, *selection_copy; int group_index; int any_groups = 0; if (g_list_length(dia->data->selected) < 1) { message_error("Trying to ungroup with no selected objects."); return; } selection_copy = g_list_copy(dia->data->selected); selected = selection_copy; while (selected != NULL) { group = (DiaObject *)selected->data; if (IS_GROUP(group)) { Change *change; /* Fix selection */ diagram_unselect_object(dia, group); group_list = group_objects(group); group_index = layer_object_get_index(dia->data->active_layer, group); change = undo_ungroup_objects(dia, group_list, group, group_index); (change->apply)(change, dia); diagram_select_list(dia, group_list); any_groups = 1; } selected = g_list_next(selected); } g_list_free(selection_copy); if (any_groups) { diagram_modified(dia); diagram_flush(dia); undo_set_transactionpoint(dia->undo); } }
static void _dtv_select_items (GtkAction *action, DiagramTreeView *dtv) { GtkTreeSelection *selection; GtkTreeModel *model; GList *rows, *r; gboolean once = TRUE; selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dtv)); rows = gtk_tree_selection_get_selected_rows (selection, &model); r = rows; while (r) { GtkTreeIter iter; if (gtk_tree_model_get_iter (model, &iter, r->data)) { Diagram *diagram; Layer *layer; DiaObject *object; gtk_tree_model_get (model, &iter, DIAGRAM_COLUMN, &diagram, -1); gtk_tree_model_get (model, &iter, LAYER_COLUMN, &layer, -1); gtk_tree_model_get (model, &iter, OBJECT_COLUMN, &object, -1); if (once) { /* destroy previous selection in first iteration */ diagram_remove_all_selected(diagram, TRUE); once = FALSE; } if (layer) /* fixme: layer dialog update missing */ data_set_active_layer (DIA_DIAGRAM_DATA(diagram), layer); if (object) diagram_select (diagram, object); if (diagram) { diagram_add_update_all (diagram); diagram_flush(diagram); g_object_unref (diagram); } } r = g_list_next (r); } g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL); g_list_free (rows); }
static void layer_dialog_lower_callback(GtkWidget *widget, gpointer gdata) { Layer *layer; Diagram *dia; GtkWidget *selected; GList *list = NULL; int pos; dia = layer_dialog->diagram; if ((dia != NULL) && (dia->data->layers->len>1)) { assert(GTK_LIST(layer_dialog->layer_list)->selection != NULL); selected = GTK_LIST(layer_dialog->layer_list)->selection->data; pos = gtk_list_child_position(GTK_LIST(layer_dialog->layer_list), selected); if (pos < dia->data->layers->len-1) { layer = DIA_LAYER_WIDGET(selected)->layer; data_lower_layer(dia->data, layer); list = g_list_prepend(list, selected); g_object_ref(selected); gtk_list_remove_items(GTK_LIST(layer_dialog->layer_list), list); gtk_list_insert_items(GTK_LIST(layer_dialog->layer_list), list, pos + 1); g_object_unref(selected); gtk_list_select_item(GTK_LIST(layer_dialog->layer_list), pos+1); diagram_add_update_all(dia); diagram_flush(dia); undo_layer(dia, layer, TYPE_LOWER_LAYER, 0); undo_set_transactionpoint(dia->undo); } } }
void diagram_place_up_selected(Diagram *dia) { GList *sorted_list; GList *orig_list; GList *tmp, *stmp; GList *new_list = NULL; if (g_list_length (dia->data->selected) == 0) return; orig_list = g_list_copy(dia->data->active_layer->objects); sorted_list = diagram_get_sorted_selected(dia); object_add_updates_list(orig_list, dia); new_list = g_list_copy(orig_list); stmp = g_list_last(sorted_list); for (tmp = g_list_last(new_list); tmp != NULL; tmp = g_list_previous(tmp)) { if (stmp == NULL) break; if (tmp->prev == NULL) break; if (tmp->data == stmp->data) { stmp = g_list_previous(stmp); } else if (tmp->prev->data == stmp->data) { void *swap = tmp->data; tmp->data = tmp->prev->data; tmp->prev->data = swap; stmp = g_list_previous(stmp); } } layer_set_object_list(dia->data->active_layer, new_list); undo_reorder_objects(dia, g_list_copy(sorted_list), orig_list); diagram_modified(dia); diagram_flush(dia); undo_set_transactionpoint(dia->undo); }
void diagram_place_over_selected(Diagram *dia) { GList *sorted_list; GList *orig_list; if (g_list_length (dia->data->selected) == 0) return; orig_list = g_list_copy(dia->data->active_layer->objects); sorted_list = diagram_get_sorted_selected_remove(dia); object_add_updates_list(sorted_list, dia); layer_add_objects(dia->data->active_layer, sorted_list); undo_reorder_objects(dia, g_list_copy(sorted_list), orig_list); diagram_modified(dia); diagram_flush(dia); undo_set_transactionpoint(dia->undo); }
static void layer_dialog_new_callback(GtkWidget *widget, gpointer gdata) { Layer *layer; Diagram *dia; GtkWidget *selected; GList *list = NULL; GtkWidget *layer_widget; int pos; static int next_layer_num = 1; dia = layer_dialog->diagram; if (dia != NULL) { gchar* new_layer_name = g_strdup_printf(_("New layer %d"), next_layer_num++); layer = new_layer(new_layer_name, dia->data); assert(GTK_LIST(layer_dialog->layer_list)->selection != NULL); selected = GTK_LIST(layer_dialog->layer_list)->selection->data; pos = gtk_list_child_position(GTK_LIST(layer_dialog->layer_list), selected); data_add_layer_at(dia->data, layer, dia->data->layers->len - pos); diagram_add_update_all(dia); diagram_flush(dia); layer_widget = dia_layer_widget_new(dia, layer); gtk_widget_show(layer_widget); list = g_list_prepend(list, layer_widget); gtk_list_insert_items(GTK_LIST(layer_dialog->layer_list), list, pos); gtk_list_select_item(GTK_LIST(layer_dialog->layer_list), pos); undo_layer(dia, layer, TYPE_ADD_LAYER, dia->data->layers->len - pos); undo_set_transactionpoint(dia->undo); } }
/* called from the layer widget for rename */ static void edit_layer_ok_callback (GtkWidget *w, gpointer client_data) { EditLayerDialog *dialog = (EditLayerDialog *) client_data; Layer *layer; g_return_if_fail (dialog->layer_widget != NULL); layer = dialog->layer_widget->layer; g_free (layer->name); layer->name = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->name_entry))); diagram_add_update_all (dialog->layer_widget->dia); diagram_flush (dialog->layer_widget->dia); dia_layer_update_from_layer (dialog->layer_widget); dialog->layer_widget->edit_dialog = NULL; gtk_widget_destroy (dialog->dialog); g_free (dialog); }
static void diagram_properties_respond(GtkWidget *widget, gint response_id, gpointer user_data) { Diagram *active_diagram = ddisplay_active_diagram(); if (response_id == GTK_RESPONSE_OK || response_id == GTK_RESPONSE_APPLY) { if (active_diagram) { active_diagram->grid.dynamic = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dynamic_check)); active_diagram->grid.width_x = gtk_spin_button_get_value(GTK_SPIN_BUTTON(width_x_entry)); active_diagram->grid.width_y = gtk_spin_button_get_value(GTK_SPIN_BUTTON(width_y_entry)); active_diagram->grid.visible_x = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(visible_x_entry)); active_diagram->grid.visible_y = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(visible_y_entry)); active_diagram->grid.hex = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(hex_check)); active_diagram->grid.hex_size = gtk_spin_button_get_value(GTK_SPIN_BUTTON(hex_size_entry)); dia_color_selector_get_color(bg_colour, &active_diagram->data->bg_color); dia_color_selector_get_color(grid_colour, &active_diagram->grid.colour); dia_color_selector_get_color(pagebreak_colour, &active_diagram->pagebreak_color); diagram_add_update_all(active_diagram); diagram_flush(active_diagram); diagram_set_modified(active_diagram, TRUE); } } if (response_id != GTK_RESPONSE_APPLY) gtk_widget_hide(dialog); }
static void dia_layer_select_callback(GtkWidget *widget, gpointer data) { DiaLayerWidget *lw; lw = DIA_LAYER_WIDGET(widget); /* Don't deselect if we're selected the active layer. This can happen * if the window has been defocused. */ if (lw->dia->data->active_layer != lw->layer) { diagram_remove_all_selected(lw->dia, TRUE); } diagram_update_extents(lw->dia); data_set_active_layer(lw->dia->data, lw->layer); diagram_add_update_all(lw->dia); diagram_flush(lw->dia); internal_call = TRUE; if (lw->connect_off) { /* If the user wants this off, it becomes so */ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lw->connectable), FALSE); } else { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lw->connectable), TRUE); } internal_call = FALSE; }
static void create_object_motion(CreateObjectTool *tool, GdkEventMotion *event, DDisplay *ddisp) { Point to; ConnectionPoint *connectionpoint = NULL; gchar *postext; GtkStatusbar *statusbar; guint context_id; if (!tool->moving) return; ddisplay_untransform_coords(ddisp, event->x, event->y, &to.x, &to.y); /* make sure the new object is restricted to its parent */ parent_handle_move_out_check(tool->obj, &to); /* Move to ConnectionPoint if near: */ if (tool->handle != NULL && tool->handle->connect_type != HANDLE_NONCONNECTABLE) { connectionpoint = object_find_connectpoint_display(ddisp, &to, tool->obj, TRUE); if (connectionpoint != NULL) { to = connectionpoint->pos; highlight_object(connectionpoint->object, DIA_HIGHLIGHT_CONNECTIONPOINT, ddisp->diagram); ddisplay_set_all_cursor(get_cursor(CURSOR_CONNECT)); } } if (connectionpoint == NULL) { /* No connectionopoint near, then snap to grid (if enabled) */ snap_to_grid(ddisp, &to.x, &to.y); highlight_reset_all(ddisp->diagram); ddisplay_set_all_cursor(get_cursor(CURSOR_SCROLL)); } object_add_updates(tool->obj, ddisp->diagram); tool->obj->ops->move_handle(tool->obj, tool->handle, &to, connectionpoint, HANDLE_MOVE_CREATE, 0); object_add_updates(tool->obj, ddisp->diagram); /* Put current mouse position in status bar */ statusbar = GTK_STATUSBAR (ddisp->modified_status); context_id = gtk_statusbar_get_context_id (statusbar, "ObjectPos"); postext = g_strdup_printf("%.3f, %.3f - %.3f, %.3f", tool->obj->bounding_box.left, tool->obj->bounding_box.top, tool->obj->bounding_box.right, tool->obj->bounding_box.bottom); gtk_statusbar_pop (statusbar, context_id); gtk_statusbar_push (statusbar, context_id, postext); g_free(postext); diagram_flush(ddisp->diagram); tool->last_to = to; return; }
static void modify_button_release(ModifyTool *tool, GdkEventButton *event, DDisplay *ddisp) { Point *dest_pos, to; GList *list; int i; ObjectChange *objchange; tool->break_connections = FALSE; ddisplay_set_all_cursor(default_cursor); /* remove position from status bar */ { GtkStatusbar *statusbar = GTK_STATUSBAR (ddisp->modified_status); guint context_id = gtk_statusbar_get_context_id (statusbar, "ObjectPos"); gtk_statusbar_pop (statusbar, context_id); } switch (tool->state) { case STATE_MOVE_OBJECT: /* Return to normal state */ gdk_pointer_ungrab (event->time); ddisplay_untransform_coords(ddisp, event->x, event->y, &to.x, &to.y); if (!modify_move_already(tool, ddisp, &to)) { tool->orig_pos = NULL; tool->state = STATE_NONE; return; } diagram_update_connections_selection(ddisp->diagram); if (tool->orig_pos != NULL) { /* consider the non-selected children affected */ list = parent_list_affected(ddisp->diagram->data->selected); dest_pos = g_new(Point, g_list_length(list)); i=0; while (list != NULL) { DiaObject *obj = (DiaObject *) list->data; dest_pos[i] = obj->position; list = g_list_next(list); i++; } undo_move_objects(ddisp->diagram, tool->orig_pos, dest_pos, parent_list_affected(ddisp->diagram->data->selected)); } ddisplay_connect_selected(ddisp); /* pushes UNDO info */ diagram_update_extents(ddisp->diagram); diagram_modified(ddisp->diagram); diagram_flush(ddisp->diagram); undo_set_transactionpoint(ddisp->diagram->undo); tool->orig_pos = NULL; tool->state = STATE_NONE; break; case STATE_MOVE_HANDLE: gdk_pointer_ungrab (event->time); tool->state = STATE_NONE; if (tool->orig_pos != NULL) { undo_move_handle(ddisp->diagram, tool->handle, tool->object, *tool->orig_pos, tool->last_to, gdk_event_to_dia_ModifierKeys(event->state)); } /* Final move: */ object_add_updates(tool->object, ddisp->diagram); objchange = tool->object->ops->move_handle(tool->object, tool->handle, &tool->last_to, NULL, HANDLE_MOVE_USER_FINAL,gdk_event_to_dia_ModifierKeys(event->state)); if (objchange != NULL) { undo_object_change(ddisp->diagram, tool->object, objchange); } object_add_updates(tool->object, ddisp->diagram); /* Connect if possible: */ if (tool->handle->connect_type != HANDLE_NONCONNECTABLE) { object_connect_display(ddisp, tool->object, tool->handle, TRUE); /* pushes UNDO info */ diagram_update_connections_selection(ddisp->diagram); } highlight_reset_all(ddisp->diagram); diagram_flush(ddisp->diagram); diagram_modified(ddisp->diagram); diagram_update_extents(ddisp->diagram); undo_set_transactionpoint(ddisp->diagram->undo); if (tool->orig_pos != NULL) { g_free(tool->orig_pos); tool->orig_pos = NULL; } break; case STATE_BOX_SELECT: gdk_pointer_ungrab (event->time); /* Remove last box: */ dia_interactive_renderer_set_selection (ddisp->renderer, FALSE, 0, 0, 0, 0); { GList *list, *list_to_free; list = list_to_free = find_selected_objects(ddisp, tool); if (selection_style == SELECT_REPLACE && !(event->state & GDK_SHIFT_MASK)) { /* Not Multi-select => Remove all selected */ diagram_remove_all_selected(ddisp->diagram, TRUE); } if (selection_style == SELECT_INTERSECTION) { GList *intersection = NULL; while (list != NULL) { DiaObject *obj = (DiaObject *)list->data; if (diagram_is_selected(ddisp->diagram, obj)) { intersection = g_list_append(intersection, obj); } list = g_list_next(list); } list = intersection; diagram_remove_all_selected(ddisp->diagram, TRUE); while (list != NULL) { DiaObject *obj = (DiaObject *)list->data; diagram_select(ddisp->diagram, obj); list = g_list_next(list); } g_list_free(intersection); } else { while (list != NULL) { DiaObject *obj = (DiaObject *)list->data; if (selection_style == SELECT_REMOVE) { if (diagram_is_selected(ddisp->diagram, obj)) diagram_unselect_object(ddisp->diagram, obj); } else if (selection_style == SELECT_INVERT) { if (diagram_is_selected(ddisp->diagram, obj)) diagram_unselect_object(ddisp->diagram, obj); else diagram_select(ddisp->diagram, obj); } else { if (!diagram_is_selected(ddisp->diagram, obj)) diagram_select(ddisp->diagram, obj); } list = g_list_next(list); } } g_list_free(list_to_free); } ddisplay_do_update_menu_sensitivity(ddisp); ddisplay_flush(ddisp); tool->state = STATE_NONE; break; case STATE_NONE: break; default: message_error("Internal error: Strange state in modify_tool\n"); } }
static void modify_motion (ModifyTool *tool, GdkEventMotion *event, DDisplay *ddisp) { Point to; Point now, delta, full_delta; gboolean auto_scroll, vertical = FALSE; ConnectionPoint *connectionpoint = NULL; ObjectChange *objchange = NULL; ddisplay_untransform_coords(ddisp, event->x, event->y, &to.x, &to.y); if (tool->state==STATE_NONE) { DiaObject *obj = NULL; Handle *handle = NULL; diagram_find_closest_handle (ddisp->diagram, &handle, &obj, &to); if (handle && handle->type != HANDLE_NON_MOVABLE && handle->id >= HANDLE_RESIZE_NW && handle->id <= HANDLE_RESIZE_SE && handle_is_clicked(ddisp, handle, &to) && g_list_length (ddisp->diagram->data->selected) == 1) ddisplay_set_all_cursor (get_direction_cursor (CURSOR_DIRECTION_0 + handle->id)); else ddisplay_set_all_cursor_name (NULL, "default"); return; /* Fast path... */ } auto_scroll = ddisplay_autoscroll(ddisp, event->x, event->y); if (!modify_move_already(tool, ddisp, &to)) return; switch (tool->state) { case STATE_MOVE_OBJECT: if (tool->orig_pos == NULL) { GList *list, *pla; int i; DiaObject *obj; /* consider non-selected children affected */ pla = list = parent_list_affected(ddisp->diagram->data->selected); tool->orig_pos = g_new(Point, g_list_length(list)); i=0; while (list != NULL) { obj = (DiaObject *) list->data; tool->orig_pos[i] = obj->position; list = g_list_next(list); i++; } g_list_free (pla); } if (tool->break_connections) diagram_unconnect_selected(ddisp->diagram); /* Pushes UNDO info */ if (gdk_event_to_dia_ModifierKeys (event->state) & MODIFIER_CONTROL) { full_delta = to; point_sub(&full_delta, &tool->start_at); vertical = (fabs(full_delta.x) < fabs(full_delta.y)); } point_add(&to, &tool->move_compensate); snap_to_grid(ddisp, &to.x, &to.y); now = tool->object->position; delta = to; point_sub(&delta, &now); if (gdk_event_to_dia_ModifierKeys (event->state) & MODIFIER_CONTROL) { /* Up-down or left-right */ if (vertical) { delta.x = tool->start_at.x + tool->move_compensate.x - now.x; } else { delta.y = tool->start_at.y + tool->move_compensate.y - now.y; } } object_add_updates_list(ddisp->diagram->data->selected, ddisp->diagram); objchange = object_list_move_delta(ddisp->diagram->data->selected, &delta); if (objchange != NULL) { undo_object_change(ddisp->diagram, tool->object, objchange); } object_add_updates_list(ddisp->diagram->data->selected, ddisp->diagram); object_add_updates(tool->object, ddisp->diagram); /* Put current mouse position in status bar */ { gchar *postext; GtkStatusbar *statusbar = GTK_STATUSBAR (ddisp->modified_status); guint context_id = gtk_statusbar_get_context_id (statusbar, "ObjectPos"); gtk_statusbar_pop (statusbar, context_id); postext = g_strdup_printf("%.3f, %.3f - %.3f, %.3f", tool->object->bounding_box.left, tool->object->bounding_box.top, tool->object->bounding_box.right, tool->object->bounding_box.bottom); gtk_statusbar_pop (statusbar, context_id); gtk_statusbar_push (statusbar, context_id, postext); g_free(postext); } diagram_update_connections_selection(ddisp->diagram); diagram_flush(ddisp->diagram); break; case STATE_MOVE_HANDLE: full_delta = to; point_sub(&full_delta, &tool->start_at); /* make sure resizing is restricted to its parent */ /* if resize was blocked by parent, that means the resizing was outward, thus it won't bother the children so we don't have to check the children */ if (!parent_handle_move_out_check(tool->object, &to)) parent_handle_move_in_check(tool->object, &to, &tool->start_at); if (gdk_event_to_dia_ModifierKeys (event->state) & MODIFIER_CONTROL) vertical = (fabs(full_delta.x) < fabs(full_delta.y)); highlight_reset_all(ddisp->diagram); if ((tool->handle->connect_type != HANDLE_NONCONNECTABLE)) { /* Move to ConnectionPoint if near: */ connectionpoint = object_find_connectpoint_display (ddisp, &to, tool->object, TRUE); if (connectionpoint != NULL) { DiaHighlightType type; to = connectionpoint->pos; if (connectionpoint->flags & CP_FLAGS_MAIN) { type = DIA_HIGHLIGHT_CONNECTIONPOINT_MAIN; } else { type = DIA_HIGHLIGHT_CONNECTIONPOINT; } highlight_object(connectionpoint->object, type, ddisp->diagram); ddisplay_set_all_cursor_name (NULL, "crosshair"); } } if (connectionpoint == NULL) { /* No connectionopoint near, then snap to grid (if enabled) */ snap_to_grid(ddisp, &to.x, &to.y); ddisplay_set_all_cursor_name (NULL, "move"); } if (tool->break_connections) { /* break connections to the handle currently selected. */ if (tool->handle->connected_to!=NULL) { Change *change = undo_unconnect (ddisp->diagram, tool->object, tool->handle); (change->apply)(change, ddisp->diagram); } } if (gdk_event_to_dia_ModifierKeys (event->state) & MODIFIER_CONTROL) { /* Up-down or left-right */ if (vertical) { to.x = tool->start_at.x; } else { to.y = tool->start_at.y; } } if (tool->orig_pos == NULL) { tool->orig_pos = g_new(Point, 1); *tool->orig_pos = tool->handle->pos; } /* Put current mouse position in status bar */ { gchar *postext; GtkStatusbar *statusbar = GTK_STATUSBAR (ddisp->modified_status); guint context_id = gtk_statusbar_get_context_id (statusbar, "ObjectPos"); if (tool->object) { /* play safe */ real w = tool->object->bounding_box.right - tool->object->bounding_box.left; real h = tool->object->bounding_box.bottom - tool->object->bounding_box.top; postext = g_strdup_printf("%.3f, %.3f (%.3fx%.3f)", to.x, to.y, w, h); } else { postext = g_strdup_printf("%.3f, %.3f", to.x, to.y); } gtk_statusbar_pop (statusbar, context_id); gtk_statusbar_push (statusbar, context_id, postext); g_free(postext); } object_add_updates(tool->object, ddisp->diagram); /* Handle undo */ if (tool->object) objchange = tool->object->ops->move_handle(tool->object, tool->handle, &to, connectionpoint, HANDLE_MOVE_USER, gdk_event_to_dia_ModifierKeys(event->state)); if (objchange != NULL) { undo_object_change(ddisp->diagram, tool->object, objchange); } object_add_updates(tool->object, ddisp->diagram); diagram_update_connections_selection(ddisp->diagram); diagram_flush(ddisp->diagram); break; case STATE_BOX_SELECT: tool->end_box = to; ddisplay_transform_coords (ddisp, MIN (tool->start_box.x, tool->end_box.x), MIN (tool->start_box.y, tool->end_box.y), &tool->x1, &tool->y1); ddisplay_transform_coords (ddisp, MAX (tool->start_box.x, tool->end_box.x), MAX (tool->start_box.y, tool->end_box.y), &tool->x2, &tool->y2); dia_interactive_renderer_set_selection (ddisp->renderer, TRUE, tool->x1, tool->y1, tool->x2 - tool->x1, tool->y2 - tool->y1); ddisplay_flush (ddisp); break; case STATE_NONE: break; default: message_error("Internal error: Strange state in modify_tool\n"); } tool->last_to = to; tool->auto_scrolled = auto_scroll; }
static DiaObject * click_select_object(DDisplay *ddisp, Point *clickedpoint, GdkEventButton *event) { Diagram *diagram; real click_distance; DiaObject *obj; diagram = ddisp->diagram; /* Find the closest object to select it: */ click_distance = ddisplay_untransform_length(ddisp, 3.0); obj = diagram_find_clicked_object(diagram, clickedpoint, click_distance); if (obj!=NULL) { /* Selected an object. */ GList *already; /*printf("Selected object!\n");*/ already = g_list_find(diagram->data->selected, obj); if (already == NULL) { /* Not already selected */ /*printf("Not already selected\n");*/ if (!(event->state & GDK_SHIFT_MASK)) { /* Not Multi-select => remove current selection */ diagram_remove_all_selected(diagram, TRUE); } diagram_select(diagram, obj); /* To be removed once text edit mode is stable. By then, * we don't want to automatically edit selected objects. textedit_activate_object(ddisp, obj, clickedpoint); */ ddisplay_do_update_menu_sensitivity(ddisp); object_add_updates_list(diagram->data->selected, diagram); diagram_flush(diagram); return obj; } else { /* Clicked on already selected. */ /*printf("Already selected\n");*/ /* To be removed once text edit mode is stable. By then, * we don't want to automatically edit selected objects. textedit_activate_object(ddisp, obj, clickedpoint); */ object_add_updates_list(diagram->data->selected, diagram); diagram_flush(diagram); if (event->state & GDK_SHIFT_MASK) { /* Multi-select */ /* Remove the selected selected */ ddisplay_do_update_menu_sensitivity(ddisp); diagram_unselect_object(diagram, (DiaObject *)already->data); diagram_flush(ddisp->diagram); } else { return obj; } } } /* Else part moved to allow union/intersection select */ return NULL; }
static void create_object_button_press(CreateObjectTool *tool, GdkEventButton *event, DDisplay *ddisp) { Point clickedpoint, origpoint; Handle *handle1; Handle *handle2; DiaObject *obj; real click_distance; ddisplay_untransform_coords(ddisp, (int)event->x, (int)event->y, &clickedpoint.x, &clickedpoint.y); origpoint = clickedpoint; snap_to_grid(ddisp, &clickedpoint.x, &clickedpoint.y); click_distance = ddisplay_untransform_length(ddisp, 3.0); obj = dia_object_default_create (tool->objtype, &clickedpoint, tool->user_data, &handle1, &handle2); tool->obj = obj; /* ensure that tool->obj is initialised in case we return early. */ if (!obj) { tool->moving = FALSE; tool->handle = NULL; message_error(_("'%s' creation failed"), tool->objtype ? tool->objtype->name : "NULL"); return; } diagram_add_object(ddisp->diagram, obj); /* Try a connect */ if (handle1 != NULL && handle1->connect_type != HANDLE_NONCONNECTABLE) { ConnectionPoint *connectionpoint; connectionpoint = object_find_connectpoint_display(ddisp, &origpoint, obj, TRUE); if (connectionpoint != NULL) { (obj->ops->move)(obj, &origpoint); } } if (!(event->state & GDK_SHIFT_MASK)) { /* Not Multi-select => remove current selection */ diagram_remove_all_selected(ddisp->diagram, TRUE); } diagram_select(ddisp->diagram, obj); /* Connect first handle if possible: */ if ((handle1!= NULL) && (handle1->connect_type != HANDLE_NONCONNECTABLE)) { object_connect_display(ddisp, obj, handle1, TRUE); } object_add_updates(obj, ddisp->diagram); ddisplay_do_update_menu_sensitivity(ddisp); diagram_flush(ddisp->diagram); if (handle2 != NULL) { tool->handle = handle2; tool->moving = TRUE; tool->last_to = handle2->pos; gdk_pointer_grab (gtk_widget_get_window(ddisp->canvas), FALSE, GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, NULL, NULL, event->time); ddisplay_set_all_cursor(get_cursor(CURSOR_SCROLL)); } else { diagram_update_extents(ddisp->diagram); tool->moving = FALSE; } }