Commit a90d48bb authored by ROOL's avatar ROOL 🤖
Browse files

Sprite copy, Draw paste fixes

Detail:
  Correction to Sprite collation to the clipboard to get the sprite header right.
  On paste, if there's already an object selected replace it with the pasted item.
Admin:
  Submission for Clipboard Support bounty.

Version 1.32. Tagged as 'Draw-1_32'
parent 3869741b
......@@ -11,13 +11,13 @@
GBLS Module_HelpVersion
GBLS Module_ComponentName
GBLS Module_ComponentPath
Module_MajorVersion SETS "1.31"
Module_Version SETA 131
Module_MajorVersion SETS "1.32"
Module_Version SETA 132
Module_MinorVersion SETS ""
Module_Date SETS "09 Feb 2019"
Module_ApplicationDate SETS "09-Feb-19"
Module_Date SETS "24 Feb 2019"
Module_ApplicationDate SETS "24-Feb-19"
Module_ComponentName SETS "Draw"
Module_ComponentPath SETS "apache/RiscOS/Sources/Apps/Draw"
Module_FullVersion SETS "1.31"
Module_HelpVersion SETS "1.31 (09 Feb 2019)"
Module_FullVersion SETS "1.32"
Module_HelpVersion SETS "1.32 (24 Feb 2019)"
END
/* (1.31)
/* (1.32)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 1.31
#define Module_MajorVersion_CMHG 1.32
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 09 Feb 2019
#define Module_Date_CMHG 24 Feb 2019
#define Module_MajorVersion "1.31"
#define Module_Version 131
#define Module_MajorVersion "1.32"
#define Module_Version 132
#define Module_MinorVersion ""
#define Module_Date "09 Feb 2019"
#define Module_Date "24 Feb 2019"
#define Module_ApplicationDate "09-Feb-19"
#define Module_ApplicationDate "24-Feb-19"
#define Module_ComponentName "Draw"
#define Module_ComponentPath "apache/RiscOS/Sources/Apps/Draw"
#define Module_FullVersion "1.31"
#define Module_HelpVersion "1.31 (09 Feb 2019)"
#define Module_LibraryVersionInfo "1:31"
#define Module_FullVersion "1.32"
#define Module_HelpVersion "1.32 (24 Feb 2019)"
#define Module_LibraryVersionInfo "1:32"
......@@ -1772,6 +1772,10 @@ static void draw_paper__wimp_event_handler (wimp_eventstr *e, void *handle)
/*Gravitate to grid position*/
draw_grid_snap_if_locked (vuue, &mouseD);
/*Delete any existing selection */
if (draw_selection->owner == diag)
draw_select_delete(draw_selection->owner);
/*Do the load*/
err = draw_load_file (diag, vuue, &mouseD, FALSE);
}
......
......@@ -56,12 +56,13 @@
/*Globals: current clipboard data if we have ownership*/
char *clipdata = NULL;
int cliplength = 0;
static BOOL draw_owns_clipboard = FALSE;
static BOOL draw_clipboard_openup(const char *name, int *handle)
{ os_regset blk;
blk.r[0] = 0xCF; /*OpenUp, Ignore file$path, give err if a dir.!*/
blk.r[0] = 0x87; /*OpenOut, Ignore file$path, give err if a dir.!*/
blk.r[1] = (int)name;
if (wimpt_complain(os_find(&blk))) return FALSE;
......@@ -111,13 +112,13 @@ static BOOL draw_clipboard_extract_sprites(draw_objptr ptr, char **sprite_buffer
switch (ptr.objhdrp->tag) {
case draw_OBJSPRITE:
if (sprite_buffer) {
if (FLEX_EXTEND((flex_ptr)sprite_buffer, hdr->freeoff+ptr.spritep->sprite.next) == 0) {
if (FLEX_EXTEND((flex_ptr)sprite_buffer, hdr->freeoff + ptr.spritep->sprite.next - 4) == 0) {
FLEX_FREE((flex_ptr)sprite_buffer);
wimpt_complain(draw_make_oserror("DrawNR"));
return FALSE;
}
memcpy(*sprite_buffer+hdr->freeoff, &ptr.spritep->sprite, ptr.spritep->sprite.next);
memcpy(*sprite_buffer + hdr->freeoff - 4, &ptr.spritep->sprite, ptr.spritep->sprite.next);
hdr->freeoff += ptr.spritep->sprite.next;
hdr->number++;
}
......@@ -126,13 +127,13 @@ static BOOL draw_clipboard_extract_sprites(draw_objptr ptr, char **sprite_buffer
case draw_OBJTRFMSPRITE:
if (sprite_buffer) {
if (FLEX_EXTEND((flex_ptr)sprite_buffer, hdr->freeoff+ptr.trfmspritep->sprite.next) == 0) {
if (FLEX_EXTEND((flex_ptr)sprite_buffer, hdr->freeoff + ptr.trfmspritep->sprite.next - 4) == 0) {
FLEX_FREE((flex_ptr)sprite_buffer);
wimpt_complain(draw_make_oserror("DrawNR"));
return FALSE;
}
memcpy(*sprite_buffer+hdr->freeoff, &ptr.trfmspritep->sprite, ptr.trfmspritep->sprite.next);
memcpy(*sprite_buffer + hdr->freeoff - 4, &ptr.trfmspritep->sprite, ptr.trfmspritep->sprite.next);
hdr->freeoff += ptr.trfmspritep->sprite.next;
hdr->number++;
}
......@@ -186,11 +187,10 @@ static BOOL draw_clipboard_write_spritefile(int handle, char *buffer, int buffer
}
}
/*Fill in the sprite header*/
memcpy(sprite_buffer, &hdr, SpriteAreaCBsize);
/*Fill in the sprite header minus the first word (area length) as we're writing a file*/
memcpy(sprite_buffer, &hdr.number, SpriteAreaCBsize - 4);
/*Do the write */
result = draw_clipboard_write_bytes(handle, sprite_buffer + 4, hdr.freeoff - 4);
result = draw_clipboard_write_bytes(handle, sprite_buffer, hdr.freeoff - 4);
FLEX_FREE((flex_ptr)&sprite_buffer);
......@@ -258,7 +258,8 @@ static BOOL draw_clipboard_extract_text(draw_objptr ptr, char **text_buffer, int
/*We are now pointing to the text area itself*/
char *textptr = textcol.textareaendp->text;
int fragment_length = 1 + strlen(textptr);
if (text_buffer != 0) {
if (text_buffer != NULL) {
if (FLEX_EXTEND((flex_ptr)text_buffer, *text_length + fragment_length) == 0) {
FLEX_FREE((flex_ptr)text_buffer);
wimpt_complain(draw_make_oserror("DrawNR"));
......@@ -387,6 +388,8 @@ static void draw_clipboard_export_ramxfer(wimp_eventstr *ev, int filetype, char
hdr.sproff = SpriteAreaCBsize;
hdr.freeoff = SpriteAreaCBsize;
export_length = SpriteAreaCBsize - 4; /* Header without the size entry */
if (FLEX_ALLOC((flex_ptr)&export_buffer, SpriteAreaCBsize) == 0) {
wimpt_complain(draw_make_oserror("DrawNR"));
return;
......@@ -395,14 +398,14 @@ static void draw_clipboard_export_ramxfer(wimp_eventstr *ev, int filetype, char
for (ptr.bytep = buffer + sizeof(draw_fileheader);
ptr.bytep < buffer + buffer_length;
ptr.bytep += ptr.objhdrp->size) {
if (!draw_clipboard_extract_sprites(ptr, &export_buffer, &hdr, 0)) {
if (!draw_clipboard_extract_sprites(ptr, &export_buffer, &hdr, &export_length)) {
FLEX_FREE((flex_ptr)&export_buffer);
return;
}
}
/*Fill in the sprite header*/
memcpy(export_buffer, &hdr, SpriteAreaCBsize);
memcpy(export_buffer, &hdr.number, SpriteAreaCBsize - 4);
export_needs_free = TRUE;
}
break;
......@@ -463,8 +466,6 @@ static void draw_clipboard_export_ramxfer(wimp_eventstr *ev, int filetype, char
}
}
static BOOL draw_owns_clipboard = FALSE;
void draw_clipboard_release(void)
{ /*Another task has claimed the clipboard*/
......@@ -518,7 +519,7 @@ static int draw_clipboard_send_datarequest(wimp_eventstr *e)
wimp_sendmessage(wimp_ESENDWANTACK, &msg, 0);
/*We either get back a datasave or a bounce */
/*We either get back a datasave or a bounce*/
while (1) {
wimpt_poll(event_getmask(), e);
switch (e->e) {
......@@ -584,6 +585,10 @@ void draw_clipboard_paste(diagrec *diag, viewrec *vuue)
/*We either just do an internal copy, or pull from external clipboard task*/
if (draw_owns_clipboard) {
/*Internal action*/
if (draw_selection->owner == diag) {
draw_select_delete(draw_selection->owner);
}
draw_file_loadfile(diag, vuue, msgs_lookup("FileSe"), FileType_Draw, cliplength, via_CLIPBOARD_INT, &mouseD);
return;
}
......@@ -592,6 +597,11 @@ void draw_clipboard_paste(diagrec *diag, viewrec *vuue)
/*Request data from clipboard...*/
if (0 == draw_clipboard_send_datarequest(&e)) return; /*Message was bounced, oddly*/
/*Success. Delete any existing selection (as it gets replaced) if we're pasting into the same diagram*/
if (draw_selection->owner == diag) {
draw_select_delete(draw_selection->owner);
}
/*Now e contains the datasave reply, pass to Draw's normal data import function*/
draw_load_file(diag, vuue, &mouseD, FALSE);
}
......
......@@ -1214,7 +1214,7 @@ static void do_select (int which, int code, char *hit, diagrec *diag,
case s_Select_Cut:
draw_file_copy_selection(diag);
err=draw_select_delete(sel);
err = draw_select_delete(sel);
break;
case s_Select_Copy:
......@@ -3049,13 +3049,13 @@ void draw_menu_processkeys (diagrec *diag, viewrec *vuue, int key)
case 24 /* ^X (Delete exists below) */: /* Cut selection to clipboard */
if (edit) {}
else do_select(1,s_Select_Cut,NULL,diag,vuue);
else do_select(1, s_Select_Cut, NULL, diag, vuue);
break;
case 22 /* ^V or Insert */:
case akbd_InsertK:
if (edit) {}
else do_select(1,s_Select_Paste,NULL,diag,vuue);
else do_select(1, s_Select_Paste, NULL, diag, vuue);
break;
case akbd_Fn + 8: /* Undo */
......
......@@ -1115,7 +1115,7 @@ os_error *draw_select_back (diagrec *src)
/*Make a copy of the selection, jogging it.*/
/*Can copy to another diagram*/
os_error *draw_select_copy (diagrec *src, diagrec *dest, trans_str *trans)
os_error *draw_select_copy (diagrec *src, diagrec *dest, trans_str *trans, BOOL delete_source)
{ os_error *err = 0;
BOOL ok;
......@@ -1133,6 +1133,12 @@ os_error *draw_select_copy (diagrec *src, diagrec *dest, trans_str *trans)
{ /*Copy objects*/
copy_selection (src, dest, offset);
if (delete_source)
{ /*Delete from original if desired*/
delete_selection(src,TRUE);
draw_selection->indx = 0;
}
/*Change state on copy to another diagram*/
if (src != dest)
{ /*Change source to line entry*/
......
......@@ -53,7 +53,7 @@ extern os_error *draw_select_delete (diagrec *src);
extern os_error *draw_select_front (diagrec *src);
extern os_error *draw_select_back (diagrec *src);
extern os_error *draw_select_copy (diagrec *src, diagrec *dest,
trans_str *trans);
trans_str *trans, BOOL delete_source);
extern os_error *draw_select_group (diagrec *src);
extern void draw_select_copydown (diagrec *diag, int from_off,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment