static void scroll_button_press(ScrollTool *tool, GdkEventButton *event, DDisplay *ddisp) { Point clickedpoint; tool->use_hand = (event->state & GDK_SHIFT_MASK) != 0; if (tool->use_hand) { if (!closed_hand_cursor) closed_hand_cursor = create_cursor(ddisp->canvas->window, hand_closed_data_bits, hand_closed_data_width, hand_closed_data_height, hand_closed_mask_bits, hand_closed_data_width/2, hand_closed_data_height/2); ddisplay_set_all_cursor(closed_hand_cursor); } else ddisplay_set_all_cursor(scroll_cursor); ddisplay_untransform_coords(ddisp, (int)event->x, (int)event->y, &clickedpoint.x, &clickedpoint.y); tool->scrolling = TRUE; tool->last_pos = clickedpoint; }
static void scroll_motion(ScrollTool *tool, GdkEventMotion *event, DDisplay *ddisp) { Point to; Point delta; /* set the cursor appropriately, and change use_hand if needed */ if (!tool->scrolling) { /* try to minimise the number of cursor type changes */ if ((event->state & GDK_SHIFT_MASK) != 0) { if (!tool->use_hand) { tool->use_hand = TRUE; if (!open_hand_cursor) open_hand_cursor = create_cursor(ddisp->canvas->window, hand_open_data_bits, hand_open_data_width, hand_open_data_height, hand_open_mask_bits, hand_open_data_width/2, hand_open_data_height/2); ddisplay_set_all_cursor(open_hand_cursor); } } else if (tool->use_hand) { tool->use_hand = FALSE; ddisplay_set_all_cursor(scroll_cursor); } return; } ddisplay_untransform_coords(ddisp, event->x, event->y, &to.x, &to.y); if (tool->use_hand) { delta = tool->last_pos; point_sub(&delta, &to); tool->last_pos = to; point_add(&tool->last_pos, &delta); /* we use this so you can scroll past the edge of the image */ point_add(&delta, &ddisp->origo); ddisplay_set_origo(ddisp, delta.x, delta.y); ddisplay_update_scrollbars(ddisp); ddisplay_add_update_all(ddisp); } else { delta = to; point_sub(&delta, &tool->last_pos); point_scale(&delta, 0.5); ddisplay_scroll(ddisp, &delta); tool->last_pos = to; } ddisplay_flush(ddisp); }
void free_scroll_tool(Tool *tool) { g_free(tool); ddisplay_set_all_cursor(default_cursor); }
static int do_if_clicked_handle(DDisplay *ddisp, ModifyTool *tool, Point *clickedpoint, GdkEventButton *event) { DiaObject *obj; Handle *handle; real dist; handle = NULL; dist = diagram_find_closest_handle(ddisp->diagram, &handle, &obj, clickedpoint); if (handle_is_clicked(ddisp, handle, clickedpoint)) { tool->state = STATE_MOVE_HANDLE; tool->break_connections = TRUE; tool->last_to = handle->pos; tool->handle = handle; tool->object = obj; 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); tool->start_at = handle->pos; tool->start_time = time_micro(); ddisplay_set_all_cursor(get_cursor(CURSOR_SCROLL)); return TRUE; } return FALSE; }
static void modify_button_press(ModifyTool *tool, GdkEventButton *event, DDisplay *ddisp) { Point clickedpoint; DiaObject *clicked_obj; gboolean some_selected; ddisplay_untransform_coords(ddisp, (int)event->x, (int)event->y, &clickedpoint.x, &clickedpoint.y); /* don't got to single handle movement if there is more than one object selected */ some_selected = g_list_length (ddisp->diagram->data->selected) > 1; if (!some_selected && do_if_clicked_handle(ddisp, tool, &clickedpoint, event)) return; clicked_obj = click_select_object(ddisp, &clickedpoint, event); if (!some_selected && do_if_clicked_handle(ddisp, tool, &clickedpoint, event)) return; if ( clicked_obj != NULL ) { tool->state = STATE_MOVE_OBJECT; tool->object = clicked_obj; tool->move_compensate = clicked_obj->position; point_sub(&tool->move_compensate, &clickedpoint); tool->break_connections = TRUE; /* unconnect when not grabbing handles, just setting to * FALSE is not enough. Need to refine the move op, too. */ 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); tool->start_at = clickedpoint; tool->start_time = time_micro(); ddisplay_set_all_cursor(get_cursor(CURSOR_SCROLL)); } else { tool->state = STATE_BOX_SELECT; tool->start_box = clickedpoint; tool->end_box = clickedpoint; tool->x1 = tool->x2 = (int) event->x; tool->y1 = tool->y2 = (int) event->y; if (tool->gc == NULL) { tool->gc = gdk_gc_new(gtk_widget_get_window(ddisp->canvas)); gdk_gc_set_line_attributes(tool->gc, 1, GDK_LINE_ON_OFF_DASH, GDK_CAP_BUTT, GDK_JOIN_MITER); gdk_gc_set_foreground(tool->gc, &color_gdk_white); gdk_gc_set_function(tool->gc, GDK_XOR); } gdk_draw_rectangle (gtk_widget_get_window (ddisp->canvas), tool->gc, FALSE, tool->x1, tool->y1, tool->x2 - tool->x1, tool->y2 - tool->y1); 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); } }
void free_create_object_tool(Tool *tool) { CreateObjectTool *real_tool = (CreateObjectTool *)tool; if (real_tool->moving) { /* should not get here, but see bug #619246 */ gdk_pointer_ungrab (GDK_CURRENT_TIME); ddisplay_set_all_cursor(default_cursor); } g_free(tool); }
static void scroll_button_release(ScrollTool *tool, GdkEventButton *event, DDisplay *ddisp) { tool->use_hand = (event->state & GDK_SHIFT_MASK) != 0; if (tool->use_hand) { if (!open_hand_cursor) open_hand_cursor = create_cursor(ddisp->canvas->window, hand_open_data_bits, hand_open_data_width, hand_open_data_height, hand_open_mask_bits, hand_open_data_width/2, hand_open_data_height/2); ddisplay_set_all_cursor(open_hand_cursor); } else ddisplay_set_all_cursor(scroll_cursor); tool->scrolling = FALSE; }
Tool * create_scroll_tool(void) { ScrollTool *tool; tool = g_new(ScrollTool, 1); tool->tool.type = SCROLL_TOOL; tool->tool.button_press_func = (ButtonPressFunc) &scroll_button_press; tool->tool.button_release_func = (ButtonReleaseFunc) &scroll_button_release; tool->tool.motion_func = (MotionFunc) &scroll_motion; tool->tool.double_click_func = (DoubleClickFunc) &scroll_double_click; tool->scrolling = FALSE; tool->use_hand = FALSE; if (scroll_cursor == NULL) { scroll_cursor = gdk_cursor_new(GDK_FLEUR); } ddisplay_set_all_cursor(scroll_cursor); return (Tool *)tool; }
Tool * create_create_object_tool(DiaObjectType *objtype, void *user_data, int invert_persistence) { CreateObjectTool *tool; tool = g_new0(CreateObjectTool, 1); tool->tool.type = CREATE_OBJECT_TOOL; tool->tool.button_press_func = (ButtonPressFunc) &create_object_button_press; tool->tool.button_release_func = (ButtonReleaseFunc) &create_object_button_release; tool->tool.motion_func = (MotionFunc) &create_object_motion; tool->tool.double_click_func = (DoubleClickFunc) &create_object_double_click; tool->objtype = objtype; tool->user_data = user_data; tool->moving = FALSE; tool->invert_persistence = invert_persistence; ddisplay_set_all_cursor(get_cursor(CURSOR_CREATE)); return (Tool *) tool; }
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; }
void app_init (int argc, char **argv) { static gboolean nosplash = FALSE; static gboolean nonew = FALSE; static gboolean use_integrated_ui = TRUE; static gboolean credits = FALSE; static gboolean version = FALSE; static gboolean verbose = FALSE; static gboolean log_to_stderr = FALSE; #ifdef HAVE_GNOME GnomeClient *client; #endif static char *export_file_name = NULL; static char *export_file_format = NULL; static char *size = NULL; static char *show_layers = NULL; gboolean made_conversions = FALSE; GSList *files = NULL; static const gchar **filenames = NULL; int i = 0; gchar *export_format_string = /* Translators: The argument is a list of options, not to be translated */ g_strdup_printf(_("Select the filter/format out of: %s"), "cgm, dia, dxf, eps, eps-builtin, " EPS_PANGO "fig, mp, plt, hpgl, png (" # if defined(HAVE_LIBPNG) && defined(HAVE_LIBART) "png-libart, " # endif # ifdef HAVE_CAIRO "cairo-png, cairo-alpha-png, " # endif /* we always have pixbuf but don't know exactly all it's *few* save formats */ "pixbuf-png), jpg, " "shape, svg, tex (pgf-tex, pstricks-tex), " WMF "wpg"); GOptionContext *context = NULL; static GOptionEntry options[] = { {"export", 'e', 0, G_OPTION_ARG_FILENAME, NULL /* &export_file_name */, N_("Export loaded file and exit"), N_("OUTPUT")}, {"filter",'t', 0, G_OPTION_ARG_STRING, NULL /* &export_file_format */, NULL /* &export_format_string */, N_("TYPE") }, {"size", 's', 0, G_OPTION_ARG_STRING, NULL, N_("Export graphics size"), N_("WxH")}, {"show-layers", 'L', 0, G_OPTION_ARG_STRING, NULL, N_("Show only specified layers (e.g. when exporting). Can be either the layer name or a range of layer numbers (X-Y)"), N_("LAYER,LAYER,...")}, {"nosplash", 'n', 0, G_OPTION_ARG_NONE, &nosplash, N_("Don't show the splash screen"), NULL }, {"nonew", 'n', 0, G_OPTION_ARG_NONE, &nonew, N_("Don't create an empty diagram"), NULL }, {"classic", '\0', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &use_integrated_ui, N_("Start classic user interface (no diagrams in tabs)"), NULL }, {"log-to-stderr", 'l', 0, G_OPTION_ARG_NONE, &log_to_stderr, N_("Send error messages to stderr instead of showing dialogs."), NULL }, {"input-directory", 'I', 0, G_OPTION_ARG_CALLBACK, _check_option_input_directory, N_("Directory containing input files"), N_("DIRECTORY")}, {"output-directory", 'O', 0, G_OPTION_ARG_CALLBACK, _check_option_output_directory, N_("Directory containing output files"), N_("DIRECTORY")}, {"credits", 'c', 0, G_OPTION_ARG_NONE, &credits, N_("Display credits list and exit"), NULL }, {"verbose", 0, 0, G_OPTION_ARG_NONE, &verbose, N_("Generate verbose output"), NULL }, {"version", 'v', 0, G_OPTION_ARG_NONE, &version, N_("Display version and exit"), NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, NULL /* &filenames */, NULL, NULL }, { NULL } }; /* for users of app_init() the default is interactive */ dia_is_interactive = TRUE; options[0].arg_data = &export_file_name; options[1].arg_data = &export_file_format; options[1].description = export_format_string; options[2].arg_data = &size; options[3].arg_data = &show_layers; g_assert (strcmp (options[13].long_name, G_OPTION_REMAINING) == 0); options[13].arg_data = (void*)&filenames; argv0 = (argc > 0) ? argv[0] : "(none)"; #if GTK_CHECK_VERSION(2,24,0) /* ... use setlocale directly? */ #else gtk_set_locale(); #endif setlocale(LC_NUMERIC, "C"); _setup_textdomains (); context = g_option_context_new(_("[FILE...]")); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); #ifndef HAVE_GNOME /* avoid to add it a second time */ g_option_context_add_group (context, gtk_get_option_group (FALSE)); #endif if (argv) { GError *error = NULL; if (!g_option_context_parse (context, &argc, &argv, &error)) { if (error) { /* IMO !error here is a bug upstream, triggered e.g. with --gdk-debug=updates */ g_print ("%s", error->message); g_error_free (error); } else { g_print (_("Invalid option?")); } g_option_context_free(context); exit(1); } /* second level check of command line options, existance of input files etc. */ if (filenames) { while (filenames[i] != NULL) { gchar *filename; gchar *testpath; if (g_str_has_prefix (filenames[i], "file://")) { filename = g_filename_from_uri (filenames[i], NULL, NULL); if (!g_utf8_validate(filename, -1, NULL)) { gchar *tfn = filename; filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); g_free(tfn); } } else filename = g_filename_to_utf8 (filenames[i], -1, NULL, NULL, NULL); if (!filename) { g_print (_("Filename conversion failed: %s\n"), filenames[i]); continue; } if (g_path_is_absolute(filename)) testpath = filename; else testpath = g_build_filename(input_directory ? input_directory : ".", filename, NULL); /* we still have a problem here, if GLib's file name encoding would not be utf-8 */ if (g_file_test (testpath, G_FILE_TEST_IS_REGULAR)) files = g_slist_append(files, filename); else { g_print (_("Missing input: %s\n"), filename); g_free (filename); } if (filename != testpath) g_free (testpath); ++i; } } /* given some files to output, we are not starting up the UI */ if (export_file_name || export_file_format || size) dia_is_interactive = FALSE; } if (argv && dia_is_interactive && !version) { #ifdef HAVE_GNOME GnomeProgram *program = gnome_program_init (PACKAGE, VERSION, LIBGNOMEUI_MODULE, argc, argv, /* haven't found a quick way to pass GOption here */ GNOME_PARAM_GOPTION_CONTEXT, context, GNOME_PROGRAM_STANDARD_PROPERTIES, GNOME_PARAM_NONE); client = gnome_master_client(); if(client == NULL) { g_warning(_("Can't connect to session manager!\n")); } else { g_signal_connect(G_OBJECT (client), "save_yourself", G_CALLBACK (save_state), NULL); g_signal_connect(G_OBJECT (client), "die", G_CALLBACK (session_die), NULL); } /* This smaller icon is 48x48, standard Gnome size */ /* gnome_window_icon_set_default_from_file (GNOME_ICONDIR"/dia_gnome_icon.png");*/ #else # ifdef G_THREADS_ENABLED g_thread_init (NULL); # endif gtk_init(&argc, &argv); #endif } else { #ifdef G_THREADS_ENABLED g_thread_init (NULL); #endif g_type_init(); /* * On Windows there is no command line without display so that gtk_init is harmless. * On X11 we need gtk_init_check() to avoid exit() just because there is no display * running outside of X11. */ if (!gtk_init_check(&argc, &argv)) dia_log_message ("Running without display"); } /* done with option parsing, don't leak */ g_free(export_format_string); if (version) { gchar *ver_utf8; gchar *ver_locale; #if (defined __TIME__) && (defined __DATE__) /* TRANSLATOR: 2nd and 3rd %s are time and date respectively. */ ver_utf8 = g_strdup_printf(_("Dia version %s, compiled %s %s\n"), VERSION, __TIME__, __DATE__); #else ver_utf8 = g_strdup_printf(_("Dia version %s\n"), VERSION); #endif ver_locale = g_locale_from_utf8(ver_utf8, -1, NULL, NULL, NULL); printf("%s\n", ver_locale); g_free(ver_locale); g_free(ver_utf8); if (verbose) dump_dependencies(); exit(0); } if (!dia_is_interactive) log_to_stderr = TRUE; libdia_init ( (dia_is_interactive ? DIA_INTERACTIVE : 0) | (log_to_stderr ? DIA_MESSAGE_STDERR : 0) | (verbose ? DIA_VERBOSE : 0) ); print_credits(credits); if (dia_is_interactive) { create_user_dirs(); if (!nosplash) app_splash_init(""); /* Init cursors: */ default_cursor = gdk_cursor_new(GDK_LEFT_PTR); ddisplay_set_all_cursor(default_cursor); } dia_register_plugins(); dia_register_builtin_plugin(internal_plugin_init); load_all_sheets(); /* new mechanism */ dia_log_message ("object defaults"); { DiaContext *ctx = dia_context_new (_("Object Defaults")); dia_object_defaults_load (NULL, TRUE /* prefs.object_defaults_create_lazy */, ctx); dia_context_release (ctx); } debug_break(); if (object_get_type("Standard - Box") == NULL) { message_error(_("Couldn't find standard objects when looking for " "object-libs; exiting...\n")); g_critical( _("Couldn't find standard objects when looking for " "object-libs in '%s'; exiting...\n"), dia_get_lib_directory("dia")); exit(1); } persistence_load(); /** Must load prefs after persistence */ prefs_init(); if (dia_is_interactive) { /* further initialization *before* reading files */ active_tool = create_modify_tool(); dia_log_message ("ui creation"); if (use_integrated_ui) { create_integrated_ui(); } else { create_toolbox(); /* for the integrated ui case it is integrated */ persistence_register_window_create("layer_window", (NullaryFunc*)&layer_dialog_create); } /*fill recent file menu */ recent_file_history_init(); /* Set up autosave to check every 5 minutes */ g_timeout_add_seconds(5*60, autosave_check_autosave, NULL); #if 0 /* do we really open these automatically in the next session? */ persistence_register_window_create("diagram_tree", &diagram_tree_show); #endif persistence_register_window_create("sheets_main_dialog", (NullaryFunc*)&sheets_dialog_create); /* In current setup, we can't find the autosaved files. */ /*autosave_restore_documents();*/ } dia_log_message ("diagrams"); made_conversions = handle_all_diagrams(files, export_file_name, export_file_format, size, show_layers, input_directory, output_directory); if (dia_is_interactive && files == NULL && !nonew) { if (use_integrated_ui) { GList * list; file_new_callback(NULL); list = dia_open_diagrams(); if (list) { Diagram * diagram = list->data; diagram_update_extents(diagram); diagram->is_default = TRUE; } } else { gchar *filename = g_filename_from_utf8(_("Diagram1.dia"), -1, NULL, NULL, NULL); Diagram *diagram = new_diagram (filename); g_free(filename); if (diagram != NULL) { diagram_update_extents(diagram); diagram->is_default = TRUE; /* I think this is done in diagram_init() with a call to * layer_dialog_update_diagram_list() */ layer_dialog_set_diagram(diagram); new_display(diagram); } } } g_slist_free(files); if (made_conversions) exit(0); dynobj_refresh_init(); dia_log_message ("initialized"); }
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; } }
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 create_object_button_release(CreateObjectTool *tool, GdkEventButton *event, DDisplay *ddisp) { GList *list = NULL; DiaObject *obj = tool->obj; gboolean reset; GList *parent_candidates; g_return_if_fail (obj != NULL); if (!obj) /* not sure if this isn't enough */ return; /* could be a legal invariant */ if (tool->moving) { gdk_pointer_ungrab (event->time); object_add_updates(tool->obj, ddisp->diagram); tool->obj->ops->move_handle(tool->obj, tool->handle, &tool->last_to, NULL, HANDLE_MOVE_CREATE_FINAL, 0); object_add_updates(tool->obj, ddisp->diagram); } parent_candidates = layer_find_objects_containing_rectangle(obj->parent_layer, &obj->bounding_box); /* whole object must be within another object to parent it */ for (; parent_candidates != NULL; parent_candidates = g_list_next(parent_candidates)) { DiaObject *parent_obj = (DiaObject *) parent_candidates->data; if (obj != parent_obj && object_within_parent(obj, parent_obj)) { Change *change = undo_parenting(ddisp->diagram, parent_obj, obj, TRUE); (change->apply)(change, ddisp->diagram); break; /* obj->parent = parent_obj; parent_obj->children = g_list_append(parent_obj->children, obj); */ } } g_list_free(parent_candidates); list = g_list_prepend(list, tool->obj); undo_insert_objects(ddisp->diagram, list, 1); if (tool->moving) { if (tool->handle->connect_type != HANDLE_NONCONNECTABLE) { object_connect_display(ddisp, tool->obj, tool->handle, TRUE); diagram_update_connections_selection(ddisp->diagram); diagram_flush(ddisp->diagram); } tool->moving = FALSE; tool->handle = NULL; tool->obj = NULL; } { /* 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); } highlight_reset_all(ddisp->diagram); reset = prefs.reset_tools_after_create != tool->invert_persistence; /* kind of backward: first starting editing to see if it is possible at all, than GUI reflection */ if (textedit_activate_object(ddisp, obj, NULL) && reset) { gtk_action_activate (menus_get_action ("ToolsTextedit")); reset = FALSE; /* don't switch off textedit below */ } diagram_update_extents(ddisp->diagram); diagram_modified(ddisp->diagram); undo_set_transactionpoint(ddisp->diagram->undo); if (reset) tool_reset(); ddisplay_set_all_cursor(default_cursor); ddisplay_do_update_menu_sensitivity(ddisp); }