+// paste external text
+void clipboard_paste_text(gchar *text)
+{
+ struct Item *item;
+ double pt[2];
+
+ reset_selection();
+ get_current_pointer_coords(pt);
+ set_current_page(pt);
+
+ ui.selection = g_new(struct Selection, 1);
+ ui.selection->type = ITEM_SELECTRECT;
+ ui.selection->layer = ui.cur_layer;
+ ui.selection->items = NULL;
+
+ item = g_new(struct Item, 1);
+ ui.selection->items = g_list_append(ui.selection->items, item);
+ ui.cur_layer->items = g_list_append(ui.cur_layer->items, item);
+ ui.cur_layer->nitems++;
+ item->type = ITEM_TEXT;
+ g_memmove(&(item->brush), ui.cur_brush, sizeof(struct Brush));
+ item->text = text; // text was newly allocated, we keep it
+ item->font_name = g_strdup(ui.font_name);
+ item->font_size = ui.font_size;
+ item->bbox.left = pt[0]; item->bbox.top = pt[1];
+ make_canvas_item_one(ui.cur_layer->group, item);
+ update_item_bbox(item);
+
+ // move the text to fit on the page if needed
+ if (item->bbox.right > ui.cur_page->width) item->bbox.left += ui.cur_page->width-item->bbox.right;
+ if (item->bbox.left < 0) item->bbox.left = 0;
+ if (item->bbox.bottom > ui.cur_page->height) item->bbox.top += ui.cur_page->height-item->bbox.bottom;
+ if (item->bbox.top < 0) item->bbox.top = 0;
+ gnome_canvas_item_set(item->canvas_item, "x", item->bbox.left, "y", item->bbox.top, NULL);
+ update_item_bbox(item);
+
+ ui.selection->bbox = item->bbox;
+ ui.selection->canvas_item = gnome_canvas_item_new(ui.cur_layer->group,
+ gnome_canvas_rect_get_type(), "width-pixels", 1,
+ "outline-color-rgba", 0x000000ff,
+ "fill-color-rgba", 0x80808040,
+ "x1", ui.selection->bbox.left, "x2", ui.selection->bbox.right,
+ "y1", ui.selection->bbox.top, "y2", ui.selection->bbox.bottom, NULL);
+ make_dashed(ui.selection->canvas_item);
+
+ prepare_new_undo();
+ undo->type = ITEM_PASTE;
+ undo->layer = ui.cur_layer;
+ undo->itemlist = g_list_copy(ui.selection->items);
+
+ update_copy_paste_enabled();
+ update_color_menu();
+ update_thickness_buttons();
+ update_color_buttons();
+ update_font_button();
+ update_cursor(); // FIXME: can't know if pointer is within selection!
+}
+