1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469
|
/*
* Copyright 2004-2007 James Bursa <bursa@users.sourceforge.net>
* Copyright 2005 Adrian Lees <adrianl@users.sourceforge.net>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
* Save dialog and drag and drop saving (implementation).
*/
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "oslib/dragasprite.h"
#include "oslib/osbyte.h"
#include "oslib/osfile.h"
#include "oslib/osmodule.h"
#include "oslib/osspriteop.h"
#include "oslib/wimp.h"
#include "oslib/wimpspriteop.h"
#include "content/content.h"
#include "content/hlcache.h"
#include "desktop/hotlist.h"
#include "desktop/history_global_core.h"
#include "desktop/netsurf.h"
#include "desktop/save_complete.h"
#include "desktop/save_text.h"
#include "desktop/selection.h"
#include "desktop/thumbnail.h"
#include "image/bitmap.h"
#include "render/box.h"
#include "render/form.h"
#include "riscos/dialog.h"
#include "riscos/gui.h"
#include "riscos/menus.h"
#include "riscos/message.h"
#include "riscos/options.h"
#include "riscos/query.h"
#include "riscos/save.h"
#include "riscos/save_draw.h"
#include "riscos/save_pdf.h"
#include "riscos/textselection.h"
#include "riscos/thumbnail.h"
#include "riscos/wimp.h"
#include "riscos/wimp_event.h"
#include "utils/config.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/url.h"
#include "utils/utf8.h"
#include "utils/utils.h"
//typedef enum
//{
// QueryRsn_Quit,
// QueryRsn_Abort,
// QueryRsn_Overwrite
//} query_reason;
/**todo - much of the state information for a save should probably be moved into a structure
now since we could have multiple saves outstanding */
static gui_save_type gui_save_current_type;
static hlcache_handle *gui_save_content = NULL;
static struct selection *gui_save_selection = NULL;
static const char *gui_save_url = NULL;
static const char *gui_save_title = NULL;
static int gui_save_filetype;
static query_id gui_save_query;
static bool gui_save_send_dataload;
static wimp_message gui_save_message;
static bool gui_save_close_after = true;
static bool dragbox_active = false; /** in-progress Wimp_DragBox/DragASprite op */
static bool using_dragasprite = true;
static bool saving_from_dialog = true;
static osspriteop_area *saveas_area = NULL;
static wimp_w gui_save_sourcew = (wimp_w)-1;
#define LEAFNAME_MAX 200
static char save_leafname[LEAFNAME_MAX];
/** Current save directory (updated by and used for dialog-based saving) */
static char *save_dir = NULL;
static size_t save_dir_len;
typedef enum { LINK_ACORN, LINK_ANT, LINK_TEXT } link_format;
static bool ro_gui_save_complete(hlcache_handle *h, char *path);
static bool ro_gui_save_content(hlcache_handle *h, char *path, bool force_overwrite);
static void ro_gui_save_done(void);
static void ro_gui_save_bounced(wimp_message *message);
static bool ro_gui_save_object_native(hlcache_handle *h, char *path);
static bool ro_gui_save_link(const char *url, const char *title, link_format format, char *path);
static void ro_gui_save_set_state(hlcache_handle *h, gui_save_type save_type,
const char *url, char *leaf_buf, size_t leaf_len,
char *icon_buf, size_t icon_len);
static bool ro_gui_save_create_thumbnail(hlcache_handle *h, const char *name);
static void ro_gui_save_overwrite_confirmed(query_id, enum query_response res, void *p);
static void ro_gui_save_overwrite_cancelled(query_id, enum query_response res, void *p);
static const query_callback overwrite_funcs =
{
ro_gui_save_overwrite_confirmed,
ro_gui_save_overwrite_cancelled
};
/** An entry in gui_save_table. */
struct gui_save_table_entry {
int filetype;
const char *name;
};
/** Table of filetypes and default filenames. Must be in sync with
* gui_save_type (riscos/gui.h). A filetype of 0 indicates the content should
* be used.
*/
static const struct gui_save_table_entry gui_save_table[] = {
/* GUI_SAVE_SOURCE, */ { 0, "SaveSource" },
/* GUI_SAVE_DRAW, */ { 0xaff, "SaveDraw" },
/* GUI_SAVE_PDF, */ { 0xadf, "SavePDF" },
/* GUI_SAVE_TEXT, */ { 0xfff, "SaveText" },
/* GUI_SAVE_COMPLETE, */ { 0xfaf, "SaveComplete" },
/* GUI_SAVE_OBJECT_ORIG, */ { 0, "SaveObject" },
/* GUI_SAVE_OBJECT_NATIVE, */ { 0, "SaveObject" },
/* GUI_SAVE_LINK_URI, */ { 0xf91, "SaveLink" },
/* GUI_SAVE_LINK_URL, */ { 0xb28, "SaveLink" },
/* GUI_SAVE_LINK_TEXT, */ { 0xfff, "SaveLink" },
/* GUI_SAVE_HOTLIST_EXPORT_HTML, */ { 0xfaf, "Hotlist" },
/* GUI_SAVE_HISTORY_EXPORT_HTML, */ { 0xfaf, "History" },
/* GUI_SAVE_TEXT_SELECTION, */ { 0xfff, "SaveSelection" },
};
/**
* Create the saveas dialogue from the given template, and the sprite area
* necessary for our thumbnail (full page save)
*
* \param template_name name of template to be used
* \return window handle of created dialogue
*/
wimp_w ro_gui_saveas_create(const char *template_name)
{
const int sprite_size = (68 * 68 * 4) + ((68 * 68) / 8); /* 32bpp with mask */
int area_size = sizeof(osspriteop_area) + sizeof(osspriteop_header) +
256 * 8 + sprite_size;
void *area = NULL;
wimp_window *window;
os_error *error;
wimp_icon *icons;
wimp_w w;
window = ro_gui_dialog_load_template(template_name);
assert(window);
icons = window->icons;
error = xosmodule_alloc(area_size, (void **) &area);
if (error) {
LOG(("xosmodule_alloc: 0x%x: %s", error->errnum, error->errmess));
xwimp_close_template();
die(error->errmess);
} else {
saveas_area = area;
saveas_area->size = area_size;
saveas_area->first = 16;
error = xosspriteop_clear_sprites(osspriteop_USER_AREA, saveas_area);
if (error) {
LOG(("xosspriteop_clear_sprites: 0x%x: %s",
error->errnum, error->errmess));
warn_user("MiscError", error->errmess);
xosmodule_free(saveas_area);
saveas_area = NULL;
}
}
assert((icons[ICON_SAVE_ICON].flags &
(wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_INDIRECTED)) ==
(wimp_ICON_SPRITE | wimp_ICON_INDIRECTED));
icons[ICON_SAVE_ICON].data.indirected_sprite.area = saveas_area;
/* create window */
error = xwimp_create_window(window, &w);
if (error) {
LOG(("xwimp_create_window: 0x%x: %s",
error->errnum, error->errmess));
xwimp_close_template();
die(error->errmess);
}
/* the window definition is copied by the wimp and may be freed */
free(window);
return w;
}
/**
* Clean-up function that releases our sprite area and memory.
*/
void ro_gui_saveas_quit(void)
{
if (saveas_area) {
os_error *error = xosmodule_free(saveas_area);
if (error) {
LOG(("xosmodule_free: 0x%x: %s", error->errnum, error->errmess));
warn_user("MiscError", error->errmess);
}
saveas_area = NULL;
}
free(save_dir);
save_dir = NULL;
}
/**
* Prepares the save box to reflect gui_save_type and a content, and
* opens it.
*
* \param save_type type of save
* \param h content to save
* \param s selection to save
* \param url url to be saved (link types)
* \param title title (if any), when saving links
*/
void ro_gui_save_prepare(gui_save_type save_type, hlcache_handle *h,
struct selection *s, const char *url, const char *title)
{
char name_buf[FILENAME_MAX];
size_t leaf_offset = 0;
char icon_buf[20];
assert( (save_type == GUI_SAVE_LINK_URI) ||
(save_type == GUI_SAVE_LINK_URL) ||
(save_type == GUI_SAVE_LINK_TEXT) ||
(save_type == GUI_SAVE_HOTLIST_EXPORT_HTML) ||
(save_type == GUI_SAVE_HISTORY_EXPORT_HTML) ||
(save_type == GUI_SAVE_TEXT_SELECTION) || h);
gui_save_selection = s;
gui_save_url = url;
gui_save_title = title;
if (save_dir) {
leaf_offset = save_dir_len;
memcpy(name_buf, save_dir, leaf_offset);
name_buf[leaf_offset++] = '.';
}
ro_gui_save_set_state(h, save_type,
h ? nsurl_access(hlcache_handle_get_url(h)) : url,
name_buf + leaf_offset, FILENAME_MAX - leaf_offset,
icon_buf, sizeof(icon_buf));
ro_gui_set_icon_sprite(dialog_saveas, ICON_SAVE_ICON, saveas_area,
icon_buf);
ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_PATH, name_buf, true);
ro_gui_wimp_event_memorise(dialog_saveas);
}
/**
* Starts a drag for the save dialog
*
* \param pointer mouse position info from Wimp
*/
void ro_gui_save_start_drag(wimp_pointer *pointer)
{
if (pointer->buttons & (wimp_DRAG_SELECT | wimp_DRAG_ADJUST)) {
const char *sprite = ro_gui_get_icon_string(pointer->w, pointer->i);
int x = pointer->pos.x, y = pointer->pos.y;
wimp_window_state wstate;
wimp_icon_state istate;
/* start the drag from the icon's exact location, rather than the pointer */
istate.w = wstate.w = pointer->w;
istate.i = pointer->i;
if (!xwimp_get_window_state(&wstate) && !xwimp_get_icon_state(&istate)) {
x = (istate.icon.extent.x1 + istate.icon.extent.x0)/2 +
wstate.visible.x0 - wstate.xscroll;
y = (istate.icon.extent.y1 + istate.icon.extent.y0)/2 +
wstate.visible.y1 - wstate.yscroll;
}
gui_current_drag_type = GUI_DRAG_SAVE;
gui_save_sourcew = pointer->w;
saving_from_dialog = true;
gui_save_close_after = !(pointer->buttons & wimp_DRAG_ADJUST);
ro_gui_drag_icon(x, y, sprite);
}
}
/**
* Handle OK click/keypress in the save dialog.
*
* \param w window handle of save dialog
* \return true on success, false on failure
*/
bool ro_gui_save_ok(wimp_w w)
{
const char *name = ro_gui_get_icon_string(w, ICON_SAVE_PATH);
wimp_pointer pointer;
char path[256];
if (!strrchr(name, '.')) {
warn_user("NoPathError", NULL);
return false;
}
ro_gui_convert_save_path(path, sizeof path, name);
gui_save_sourcew = w;
saving_from_dialog = true;
gui_save_send_dataload = false;
gui_save_close_after = xwimp_get_pointer_info(&pointer)
|| !(pointer.buttons & wimp_CLICK_ADJUST);
memcpy(&gui_save_message.data.data_xfer.file_name, path, 1 + strlen(path));
if (ro_gui_save_content(gui_save_content, path, !option_confirm_overwrite)) {
ro_gui_save_done();
return true;
}
return false;
}
/**
* Initiates drag saving of an object directly from a browser window
*
* \param save_type type of save
* \param c content to save
* \param g gui window
*/
void gui_drag_save_object(gui_save_type save_type, hlcache_handle *c,
struct gui_window *g)
{
wimp_pointer pointer;
char icon_buf[20];
os_error *error;
/* Close the save window because otherwise we need two contexts
*/
xwimp_create_menu(wimp_CLOSE_MENU, 0, 0);
ro_gui_dialog_close(dialog_saveas);
gui_save_sourcew = g->window;
saving_from_dialog = false;
error = xwimp_get_pointer_info(&pointer);
if (error) {
LOG(("xwimp_get_pointer_info: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
return;
}
ro_gui_save_set_state(c, save_type, nsurl_access(hlcache_handle_get_url(c)),
save_leafname, LEAFNAME_MAX,
icon_buf, sizeof(icon_buf));
gui_current_drag_type = GUI_DRAG_SAVE;
ro_gui_drag_icon(pointer.pos.x, pointer.pos.y, icon_buf);
}
/**
* Initiates drag saving of a selection from a browser window
*
* \param s selection object
* \param g gui window
*/
void gui_drag_save_selection(struct selection *s, struct gui_window *g)
{
wimp_pointer pointer;
char icon_buf[20];
os_error *error;
/* Close the save window because otherwise we need two contexts
*/
xwimp_create_menu(wimp_CLOSE_MENU, 0, 0);
ro_gui_dialog_close(dialog_saveas);
gui_save_sourcew = g->window;
saving_from_dialog = false;
error = xwimp_get_pointer_info(&pointer);
if (error) {
LOG(("xwimp_get_pointer_info: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
return;
}
gui_save_selection = s;
ro_gui_save_set_state(NULL, GUI_SAVE_TEXT_SELECTION, NULL,
save_leafname, LEAFNAME_MAX,
icon_buf, sizeof(icon_buf));
gui_current_drag_type = GUI_DRAG_SAVE;
ro_gui_drag_icon(pointer.pos.x, pointer.pos.y, icon_buf);
}
/**
* Initiates drag saving of a link/URL file
*
* \param save_type format in which URL should be saved
* \param url url to be saved
* \param title title to be included in URI format, if any
* \param g gui window to save from
* \
*/
void ro_gui_drag_save_link(gui_save_type save_type, const char *url,
const char *title, struct gui_window *g)
{
wimp_pointer pointer;
char icon_buf[20];
os_error *error;
/* Close the save window because otherwise we need two contexts
*/
xwimp_create_menu(wimp_CLOSE_MENU, 0, 0);
ro_gui_dialog_close(dialog_saveas);
gui_save_url = url;
gui_save_title = title;
gui_save_sourcew = g->window;
saving_from_dialog = false;
error = xwimp_get_pointer_info(&pointer);
if (error) {
LOG(("xwimp_get_pointer_info: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
return;
}
ro_gui_save_set_state(NULL, save_type, url, save_leafname, LEAFNAME_MAX,
icon_buf, sizeof(icon_buf));
gui_current_drag_type = GUI_DRAG_SAVE;
ro_gui_drag_icon(pointer.pos.x, pointer.pos.y, icon_buf);
}
/**
* Start drag of icon under the pointer.
*/
void ro_gui_drag_icon(int x, int y, const char *sprite)
{
os_error *error;
wimp_drag drag;
int r2;
drag.initial.x0 = x - 34;
drag.initial.y0 = y - 34;
drag.initial.x1 = x + 34;
drag.initial.y1 = y + 34;
if (sprite && (xosbyte2(osbyte_READ_CMOS, 28, 0, &r2) || (r2 & 2))) {
osspriteop_area *area = (osspriteop_area*)1;
/* first try our local sprite area in case it's a thumbnail sprite */
if (saveas_area) {
error = xosspriteop_select_sprite(osspriteop_USER_AREA,
saveas_area, (osspriteop_id)sprite, NULL);
if (error) {
if (error->errnum != error_SPRITE_OP_DOESNT_EXIST) {
LOG(("xosspriteop_select_sprite: 0x%x: %s",
error->errnum, error->errmess));
warn_user("MiscError", error->errmess);
}
}
else
area = saveas_area;
}
error = xdragasprite_start(dragasprite_HPOS_CENTRE |
dragasprite_VPOS_CENTRE |
dragasprite_BOUND_POINTER |
dragasprite_DROP_SHADOW,
area, sprite, &drag.initial, 0);
if (!error) {
using_dragasprite = true;
dragbox_active = true;
return;
}
LOG(("xdragasprite_start: 0x%x: %s",
error->errnum, error->errmess));
}
drag.type = wimp_DRAG_USER_FIXED;
drag.bbox.x0 = -0x8000;
drag.bbox.y0 = -0x8000;
drag.bbox.x1 = 0x7fff;
drag.bbox.y1 = 0x7fff;
using_dragasprite = false;
error = xwimp_drag_box(&drag);
if (error) {
LOG(("xwimp_drag_box: 0x%x: %s",
error->errnum, error->errmess));
warn_user("DragError", error->errmess);
}
else
dragbox_active = true;
}
/**
* Convert a ctrl-char terminated pathname possibly containing spaces
* to a NUL-terminated one containing only hard spaces.
*
* \param dp destination buffer to receive pathname
* \param len size of destination buffer
* \param p source pathname, ctrl-char terminated
*/
void ro_gui_convert_save_path(char *dp, size_t len, const char *p)
{
char *ep = dp + len - 1; /* leave room for NUL */
assert(p <= dp || p > ep); /* in-situ conversion /is/ allowed */
while (dp < ep && *p >= ' ') /* ctrl-char terminated */
{
*dp++ = (*p == ' ') ? 160 : *p;
p++;
}
*dp = '\0';
}
void ro_gui_drag_box_cancel(void)
{
if (dragbox_active) {
os_error *error;
if (using_dragasprite) {
error = xdragasprite_stop();
if (error) {
LOG(("xdragasprite_stop: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
}
}
else {
error = xwimp_drag_box(NULL);
if (error) {
LOG(("xwimp_drag_box: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
}
}
dragbox_active = false;
}
}
/**
* Handle User_Drag_Box event for a drag from the save dialog or browser window.
*/
void ro_gui_save_drag_end(wimp_dragged *drag)
{
const char *name;
wimp_pointer pointer;
wimp_message message;
os_error *error;
char *dp, *ep;
char *local_name = NULL;
utf8_convert_ret err;
if (dragbox_active)
ro_gui_drag_box_cancel();
error = xwimp_get_pointer_info(&pointer);
if (error) {
LOG(("xwimp_get_pointer_info: 0x%x: %s",
error->errnum, error->errmess));
warn_user("WimpError", error->errmess);
return;
}
/* perform hit-test if the destination is the same as the source window;
we want to allow drag-saving from a page into the input fields within
the page, but avoid accidental replacements of the current page */
if (gui_save_sourcew != (wimp_w)-1 && pointer.w == gui_save_sourcew) {
int dx = (drag->final.x1 + drag->final.x0)/2;
int dy = (drag->final.y1 + drag->final.y0)/2;
struct gui_window *g;
bool dest_ok = false;
os_coord pos;
g = ro_gui_window_lookup(gui_save_sourcew);
if (g && ro_gui_window_to_window_pos(g, dx, dy, &pos)) {
hlcache_handle *h = g->bw->current_content;
if (h && content_get_type(h) == CONTENT_HTML) {
struct box *box = html_get_box_tree(h);
int box_x, box_y;
/* Consider the margins of the html page now */
box_x = box->margin[LEFT];
box_y = box->margin[TOP];
while (!dest_ok && (box = box_at_point(box,
pos.x, pos.y, &box_x, &box_y,
&h))) {
if (box->style &&
css_computed_visibility(
box->style) ==
CSS_VISIBILITY_HIDDEN)
continue;
if (box->gadget) {
switch (box->gadget->type) {
case GADGET_FILE:
case GADGET_TEXTBOX:
case GADGET_TEXTAREA:
case GADGET_PASSWORD:
dest_ok = true;
break;
default: /* appease compiler */
break;
}
}
}
}
}
if (!dest_ok) {
/* cancel the drag operation */
gui_current_drag_type = GUI_DRAG_NONE;
return;
}
}
if (!saving_from_dialog) {
/* saving directly from browser window, choose a
* name based upon the URL */
err = utf8_to_local_encoding(save_leafname, 0, &local_name);
if (err != UTF8_CONVERT_OK) {
/* badenc should never happen */
assert(err != UTF8_CONVERT_BADENC);
local_name = NULL;
}
name = local_name ? local_name : save_leafname;
}
else {
char *dot;
/* saving from dialog, grab leafname from icon */
name = ro_gui_get_icon_string(gui_save_sourcew, ICON_SAVE_PATH);
dot = strrchr(name, '.');
if (dot)
name = dot + 1;
}
dp = message.data.data_xfer.file_name;
ep = dp + sizeof message.data.data_xfer.file_name;
if (gui_save_current_type == GUI_SAVE_COMPLETE) {
message.data.data_xfer.file_type = 0x2000;
if (*name != '!') *dp++ = '!';
} else
message.data.data_xfer.file_type = gui_save_filetype;
ro_gui_convert_save_path(dp, ep - dp, name);
/* \todo - we're supposed to set this if drag-n-drop used */
message.your_ref = 0;
message.action = message_DATA_SAVE;
message.data.data_xfer.w = pointer.w;
message.data.data_xfer.i = pointer.i;
message.data.data_xfer.pos.x = pointer.pos.x;
message.data.data_xfer.pos.y = pointer.pos.y;
message.data.data_xfer.est_size = 1000;
message.size = 44 + ((strlen(message.data.data_xfer.file_name) + 4) &
(~3u));
ro_message_send_message_to_window(wimp_USER_MESSAGE_RECORDED, &message,
pointer.w, pointer.i, ro_gui_save_bounced, NULL);
free(local_name);
}
/**
* Send DataSave message on behalf of clipboard code and remember that it's the
* clipboard contents we're being asked for when the DataSaveAck reply arrives
*/
void ro_gui_send_datasave(gui_save_type save_type,
wimp_full_message_data_xfer *message, wimp_t to)
{
/* Close the save window because otherwise we need two contexts
*/
xwimp_create_menu(wimp_CLOSE_MENU, 0, 0);
ro_gui_dialog_close(dialog_saveas);
if (ro_message_send_message(wimp_USER_MESSAGE_RECORDED, (wimp_message*)message,
to, ro_gui_save_bounced)) {
gui_save_current_type = save_type;
gui_save_sourcew = (wimp_w)-1;
saving_from_dialog = false;
gui_current_drag_type = GUI_DRAG_SAVE;
}
}
/**
* Handle lack of Message_DataSaveAck for drags, saveas dialogs and clipboard code
*/
void ro_gui_save_bounced(wimp_message *message)
{
gui_current_drag_type = GUI_DRAG_NONE;
}
/**
* Handle Message_DataSaveAck for a drag from the save dialog or browser window,
* or Clipboard protocol.
*/
void ro_gui_save_datasave_ack(wimp_message *message)
{
char *path = message->data.data_xfer.file_name;
hlcache_handle *h = gui_save_content;
bool force_overwrite;
switch (gui_save_current_type) {
case GUI_SAVE_LINK_URI:
case GUI_SAVE_LINK_URL:
case GUI_SAVE_LINK_TEXT:
case GUI_SAVE_HOTLIST_EXPORT_HTML:
case GUI_SAVE_HISTORY_EXPORT_HTML:
case GUI_SAVE_TEXT_SELECTION:
case GUI_SAVE_CLIPBOARD_CONTENTS:
break;
default:
if (!gui_save_content) {
LOG(("unexpected DataSaveAck: gui_save_content not set"));
return;
}
break;
}
if (saving_from_dialog)
ro_gui_set_icon_string(gui_save_sourcew, ICON_SAVE_PATH,
path, true);
gui_save_send_dataload = true;
memcpy(&gui_save_message, message, sizeof(gui_save_message));
/* if saving/pasting to another application, don't request user
confirmation; a ScrapFile almost certainly exists already */
if (message->data.data_xfer.est_size == -1)
force_overwrite = true;
else
force_overwrite = !option_confirm_overwrite;
if (ro_gui_save_content(h, path, force_overwrite))
ro_gui_save_done();
}
/**
* Does the actual saving
*
* \param c content to save (or NULL for other)
* \param path path to save as
* \param force_overwrite true iff required to overwrite without prompting
* \return true on success,
* false on (i) error and error reported
* or (ii) deferred awaiting user confirmation
*/
bool ro_gui_save_content(hlcache_handle *h, char *path, bool force_overwrite)
{
os_error *error;
const char *source_data;
unsigned long source_size;
/* does the user want to check for collisions when saving? */
if (!force_overwrite) {
fileswitch_object_type obj_type;
/* check whether the destination file/dir already exists */
error = xosfile_read_stamped(path, &obj_type,
NULL, NULL, NULL, NULL, NULL);
if (error) {
LOG(("xosfile_read_stamped: 0x%x:%s", error->errnum, error->errmess));
warn_user("SaveError", error->errmess);
return false;
}
switch (obj_type) {
case osfile_NOT_FOUND:
break;
case osfile_IS_FILE:
gui_save_query = query_user("OverwriteFile", NULL, &overwrite_funcs, NULL,
messages_get("Replace"), messages_get("DontReplace"));
// gui_save_query_rsn = QueryRsn_Overwrite;
return false;
default:
error = xosfile_make_error(path, obj_type);
assert(error);
warn_user("SaveError", error->errmess);
return false;
}
}
switch (gui_save_current_type) {
#ifdef WITH_DRAW_EXPORT
case GUI_SAVE_DRAW:
return save_as_draw(h, path);
#endif
#ifdef WITH_PDF_EXPORT
case GUI_SAVE_PDF:
return save_as_pdf(h, path);
#endif
case GUI_SAVE_TEXT:
save_as_text(h, path);
xosfile_set_type(path, 0xfff);
break;
case GUI_SAVE_COMPLETE:
assert(h);
if (content_get_type(h) == CONTENT_HTML) {
if (strcmp(path, "<Wimp$Scrap>"))
return ro_gui_save_complete(h, path);
/* we can't send a whole directory to another
* application, so just send the HTML source */
gui_save_current_type = GUI_SAVE_SOURCE;
}
else
gui_save_current_type = GUI_SAVE_OBJECT_ORIG; /* \todo do this earlier? */
/* no break */
case GUI_SAVE_SOURCE:
case GUI_SAVE_OBJECT_ORIG:
source_data = content_get_source_data(h, &source_size);
error = xosfile_save_stamped(path,
ro_content_filetype(h),
(byte *) source_data,
(byte *) source_data + source_size);
if (error) {
LOG(("xosfile_save_stamped: 0x%x: %s",
error->errnum, error->errmess));
warn_user("SaveError", error->errmess);
return false;
}
break;
case GUI_SAVE_OBJECT_NATIVE:
return ro_gui_save_object_native(h, path);
case GUI_SAVE_LINK_URI:
return ro_gui_save_link(gui_save_url, gui_save_title,
LINK_ACORN, path);
case GUI_SAVE_LINK_URL:
return ro_gui_save_link(gui_save_url, gui_save_title,
LINK_ANT, path);
case GUI_SAVE_LINK_TEXT:
return ro_gui_save_link(gui_save_url, gui_save_title,
LINK_TEXT, path);
case GUI_SAVE_HOTLIST_EXPORT_HTML:
if (!hotlist_export(path))
return false;
error = xosfile_set_type(path, 0xfaf);
if (error)
LOG(("xosfile_set_type: 0x%x: %s",
error->errnum, error->errmess));
break;
case GUI_SAVE_HISTORY_EXPORT_HTML:
if (!history_global_export(path))
return false;
error = xosfile_set_type(path, 0xfaf);
if (error)
LOG(("xosfile_set_type: 0x%x: %s",
error->errnum, error->errmess));
break;
case GUI_SAVE_TEXT_SELECTION:
if (!selection_save_text(gui_save_selection, path))
return false;
xosfile_set_type(path, 0xfff);
break;
case GUI_SAVE_CLIPBOARD_CONTENTS:
return ro_gui_save_clipboard(path);
default:
LOG(("Unexpected content type: %d, path %s",
gui_save_current_type, path));
return false;
}
return true;
}
/**
* Save completed, inform recipient and close our 'save as' dialog.
*/
void ro_gui_save_done(void)
{
os_error *error;
if (gui_save_send_dataload) {
/* Ack successful save with message_DATA_LOAD */
wimp_message *message = &gui_save_message;
message->action = message_DATA_LOAD;
message->your_ref = message->my_ref;
error = xwimp_send_message(wimp_USER_MESSAGE, message,
message->sender);
if (error) {
LOG(("xwimp_send_message: 0x%x: %s",
error->errnum, error->errmess));
warn_user("SaveError", error->errmess);
}
}
if (saving_from_dialog) {
/* remember the save directory if saving to the Filer */
if (!gui_save_send_dataload ||
gui_save_message.data.data_xfer.est_size != -1) {
char *sp = gui_save_message.data.data_xfer.file_name;
char *ep = sp + sizeof(gui_save_message.data.data_xfer.file_name);
char *lastdot = NULL;
char *p = sp;
while (p < ep && *p >= 0x20) {
if (*p == '.') {
/* don't remember the directory if it's a temporary file */
if (!lastdot && p == sp + 12 &&
!memcmp(sp, "<Wimp$Scrap>", 12)) break;
lastdot = p;
}
p++;
}
if (lastdot) {
/* remember the directory */
char *new_dir = realloc(save_dir, (lastdot+1)-sp);
if (new_dir) {
save_dir_len = lastdot - sp;
memcpy(new_dir, sp, save_dir_len);
new_dir[save_dir_len] = '\0';
save_dir = new_dir;
}
}
}
if (gui_save_close_after) {
/* Close the save window */
ro_gui_dialog_close(dialog_saveas);
error = xwimp_create_menu(wimp_CLOSE_MENU, 0, 0);
if (error) {
LOG(("xwimp_create_menu: 0x%x: %s",
error->errnum, error->errmess));
warn_user("MenuError", error->errmess);
}
}
}
if (!saving_from_dialog || gui_save_close_after)
gui_save_content = 0;
}
/**
* conducts the filesystem save appropriate to the gui
* \param path save path
* \param filename name of file to save
* \param len data length
* \param sourcedata pointer to data to save, NULL when all data in c
* \param type content type
* \return true for success
*/
bool save_complete_gui_save(const char *path, const char *filename, size_t len,
const char *sourcedata, lwc_string *mime_type)
{
char *fullpath;
os_error *error;
int namelen = strlen(path) + strlen(filename) + 2;
int rotype;
fullpath = malloc(namelen);
if (fullpath == NULL) {
warn_user("NoMemory", 0);
return false;
}
snprintf(fullpath, namelen, "%s.%s", path, filename);
rotype = ro_content_filetype_from_mime_type(mime_type);
error = xosfile_save_stamped(fullpath, rotype, (byte *) sourcedata,
(byte *) sourcedata + len);
free(fullpath);
if (error) {
LOG(("xosfile_save_stamped: 0x%x: %s",
error->errnum, error->errmess));
warn_user("SaveError", error->errmess);
return false;
}
return true;
}
/**
* wrapper for lib function htmlSaveFileFormat; front sets path from
* path + filename in a filesystem-specific way
*/
int save_complete_htmlSaveFileFormat(const char *path, const char *filename,
xmlDocPtr cur, const char *encoding, int format)
{
os_error *error;
int ret;
int len = strlen(path) + strlen(filename) + 2;
char *fullpath = malloc(len);
if (fullpath == NULL){
warn_user("NoMemory", 0);
return -1;
}
snprintf(fullpath, len, "%s.%s", path, filename);
ret = htmlSaveFileFormat(fullpath, cur, encoding, format);
error = xosfile_set_type(fullpath, 0xFAF);
if (error) {
LOG(("xosfile_save_stamped: 0x%x: %s",
error->errnum, error->errmess));
/* Don't warn the user here -- they probably don't care */
}
free(fullpath);
return ret;
}
/**
* Prepare an application directory and save_complete() to it.
*
* \param h content of type CONTENT_HTML to save
* \param path path to save as
* \return true on success, false on error and error reported
*/
#define WIDTH 64
#define HEIGHT 64
#define SPRITE_SIZE (16 + 44 + ((WIDTH / 2 + 3) & ~3) * HEIGHT / 2)
bool ro_gui_save_complete(hlcache_handle *h, char *path)
{
void *spr = ((byte *) saveas_area) + saveas_area->first;
osspriteop_header *sprite = (osspriteop_header *) spr;
char name[12];
char buf[256];
FILE *fp;
os_error *error;
size_t len;
char *dot;
int i;
/* Create dir */
error = xosfile_create_dir(path, 0);
if (error) {
LOG(("xosfile_create_dir: 0x%x: %s",
error->errnum, error->errmess));
warn_user("SaveError", error->errmess);
return false;
}
/* Save !Run file */
snprintf(buf, sizeof buf, "%s.!Run", path);
fp = fopen(buf, "w");
if (!fp) {
LOG(("fopen(): errno = %i", errno));
warn_user("SaveError", strerror(errno));
return false;
}
fprintf(fp, "IconSprites <Obey$Dir>.!Sprites\n");
fprintf(fp, "Filer_Run <Obey$Dir>.index\n");
fclose(fp);
error = xosfile_set_type(buf, 0xfeb);
if (error) {
LOG(("xosfile_set_type: 0x%x: %s",
error->errnum, error->errmess));
warn_user("SaveError", error->errmess);
return false;
}
/* Make sure the sprite name matches the directory name, because
the user may have renamed the directory since we created the
thumbnail sprite */
dot = strrchr(path, '.');
if (dot) dot++; else dot = path;
len = strlen(dot);
if (len >= 12) len = 12;
memcpy(name, sprite->name, 12); /* remember original name */
memcpy(sprite->name, dot, len);
memset(sprite->name + len, 0, 12 - len);
for (i = 0; i < 12; i++) /* convert to lower case */
if (sprite->name[i] != '\0')
sprite->name[i] = tolower(sprite->name[i]);
/* Create !Sprites */
snprintf(buf, sizeof buf, "%s.!Sprites", path);
error = xosspriteop_save_sprite_file(osspriteop_NAME, saveas_area, buf);
if (error) {
LOG(("xosspriteop_save_sprite_file: 0x%x: %s",
error->errnum, error->errmess));
warn_user("SaveError", error->errmess);
return false;
}
/* restore sprite name in case the save fails and we need to try again */
memcpy(sprite->name, name, 12);
/* save URL file with original URL */
snprintf(buf, sizeof buf, "%s.URL", path);
if (!ro_gui_save_link(nsurl_access(hlcache_handle_get_url(h)),
content_get_title(h), LINK_ANT, buf))
return false;
return save_complete(h, path);
}
bool ro_gui_save_object_native(hlcache_handle *h, char *path)
{
int file_type = ro_content_filetype(h);
if (file_type == osfile_TYPE_SPRITE || file_type == osfile_TYPE_DRAW) {
/* Native sprite or drawfile */
const char *source_data;
unsigned long source_size;
os_error *error;
source_data = content_get_source_data(h, &source_size);
error = xosfile_save_stamped(path, file_type,
(byte *) source_data,
(byte *) source_data + source_size);
if (error != NULL) {
LOG(("xosfile_save_stamped: 0x%x: %s",
error->errnum, error->errmess));
warn_user("SaveError", error->errmess);
return false;
}
} else {
/* Non-native type: export */
switch (ro_content_native_type(h)) {
case osfile_TYPE_SPRITE:
{
unsigned flags = (os_version == 0xA9) ?
BITMAP_SAVE_FULL_ALPHA : 0;
bitmap_save(content_get_bitmap(h), path, flags);
}
break;
case osfile_TYPE_DRAW:
/* Must be SVG */
return save_as_draw(h, path);
default:
return false;
}
}
return true;
}
/**
* Save a link file.
*
* \param url url to be saved
* \param title corresponding title, if any
* \param format format of link file
* \param path pathname for link file
* \return true on success, false on failure and reports the error
*/
bool ro_gui_save_link(const char *url, const char *title, link_format format,
char *path)
{
FILE *fp = fopen(path, "w");
if (!fp) {
warn_user("SaveError", strerror(errno));
return false;
}
switch (format) {
case LINK_ACORN: /* URI */
fprintf(fp, "%s\t%s\n", "URI", "100");
fprintf(fp, "\t# NetSurf %s\n\n", netsurf_version);
fprintf(fp, "\t%s\n", url);
if (title)
fprintf(fp, "\t%s\n", title);
else
fprintf(fp, "\t*\n");
break;
case LINK_ANT: /* URL */
case LINK_TEXT: /* Text */
fprintf(fp, "%s\n", url);
break;
}
fclose(fp);
switch (format) {
case LINK_ACORN: /* URI */
xosfile_set_type(path, 0xf91);
break;
case LINK_ANT: /* URL */
xosfile_set_type(path, 0xb28);
break;
case LINK_TEXT: /* Text */
xosfile_set_type(path, 0xfff);
break;
}
return true;
}
/**
* Suggest a leafname and sprite name for the given content.
*
* \param h content being saved
* \param save_type type of save operation being performed
* \param url used to determine leafname
* \param leaf_buf buffer to receive suggested leafname.
* \param leaf_len size of buffer to receive suggested leafname.
* \param icon_buf buffer to receive sprite name.
* \param icon_len size of buffer to receive icon name.
*/
void ro_gui_save_set_state(hlcache_handle *h, gui_save_type save_type,
const char *url, char *leaf_buf, size_t leaf_len,
char *icon_buf, size_t icon_len)
{
/* filename */
const char *name = gui_save_table[save_type].name;
bool done = false;
char *nice = NULL;
utf8_convert_ret err;
char *local_name;
size_t i;
assert(icon_len >= 13);
/* parameters that we need to remember */
gui_save_current_type = save_type;
gui_save_content = h;
/* suggest a filetype based upon the content */
gui_save_filetype = gui_save_table[save_type].filetype;
if (!gui_save_filetype && h) {
if (save_type == GUI_SAVE_OBJECT_NATIVE) {
switch (ro_content_native_type(h)) {
case osfile_TYPE_SPRITE:
gui_save_filetype = osfile_TYPE_SPRITE;
break;
case osfile_TYPE_DRAW:
gui_save_filetype = osfile_TYPE_DRAW;
break;
default:
break;
}
}
if (!gui_save_filetype)
gui_save_filetype = ro_content_filetype(h);
}
/* leafname */
if (url && url_nice(url, &nice, option_strip_extensions) ==
URL_FUNC_OK) {
for (i = 0; nice[i]; i++) {
if (nice[i] == '.')
nice[i] = '/';
else if (nice[i] <= ' ' ||
strchr(":*#$&@^%\\", nice[i]))
nice[i] = '_';
}
name = nice;
} else {
name = messages_get(name);
}
/* filename is utf8 */
strncpy(leaf_buf, name, leaf_len);
leaf_buf[leaf_len - 1] = 0;
err = utf8_to_local_encoding(name, 0, &local_name);
if (err != UTF8_CONVERT_OK) {
/* badenc should never happen */
assert(err != UTF8_CONVERT_BADENC);
local_name = NULL;
}
name = local_name ? local_name : name;
/* sprite name used for icon and dragging */
if (save_type == GUI_SAVE_COMPLETE) {
int index;
/* Paint gets confused with uppercase characters and we need to
convert spaces to hard spaces */
icon_buf[0] = '!';
for (index = 0; index < 11 && name[index]; ) {
char ch = name[index];
if (ch == ' ')
icon_buf[++index] = 0xa0;
else
icon_buf[++index] = tolower(ch);
}
memset(&icon_buf[index + 1], 0, 11 - index);
icon_buf[12] = '\0';
if (ro_gui_save_create_thumbnail(h, icon_buf))
done = true;
}
if (!done) {
osspriteop_header *sprite;
os_error *error;
sprintf(icon_buf, "file_%.3x", gui_save_filetype);
error = ro_gui_wimp_get_sprite(icon_buf, &sprite);
if (error && error->errnum == error_SPRITE_OP_DOESNT_EXIST) {
/* try the 'unknown' filetype sprite as a fallback */
memcpy(icon_buf, "file_xxx", 9);
error = ro_gui_wimp_get_sprite(icon_buf, &sprite);
}
if (error) {
LOG(("ro_gui_wimp_get_sprite: 0x%x: %s",
error->errnum, error->errmess));
warn_user("MiscError", error->errmess);
} else {
/* the sprite area should always be large enough for
* file_xxx sprites */
assert(sprite->size <= saveas_area->size -
saveas_area->first);
memcpy((byte*)saveas_area + saveas_area->first,
sprite,
sprite->size);
saveas_area->sprite_count = 1;
saveas_area->used = saveas_area->first + sprite->size;
}
}
free(local_name);
free(nice);
}
/**
* Create a thumbnail sprite for the page being saved.
*
* \param h content to be converted
* \param name sprite name to use
* \return true iff successful
*/
bool ro_gui_save_create_thumbnail(hlcache_handle *h, const char *name)
{
osspriteop_header *sprite_header;
struct bitmap *bitmap;
osspriteop_area *area;
bitmap = bitmap_create(34, 34, BITMAP_NEW | BITMAP_OPAQUE | BITMAP_CLEAR_MEMORY);
if (!bitmap) {
LOG(("Thumbnail initialisation failed."));
return false;
}
thumbnail_create(h, bitmap, NULL);
area = thumbnail_convert_8bpp(bitmap);
bitmap_destroy(bitmap);
if (!area) {
LOG(("Thumbnail conversion failed."));
return false;
}
sprite_header = (osspriteop_header *)(area + 1);
strncpy(sprite_header->name, name, 12);
/* we can't resize the saveas sprite area because it may move and we have
no elegant way to update the window definition on all OS versions */
assert(sprite_header->size <= saveas_area->size - saveas_area->first);
memcpy((byte*)saveas_area + saveas_area->first,
sprite_header, sprite_header->size);
saveas_area->sprite_count = 1;
saveas_area->used = saveas_area->first + sprite_header->size;
free(area);
return true;
}
/**
* User has opted not to overwrite the existing file.
*/
void ro_gui_save_overwrite_cancelled(query_id id, enum query_response res, void *p)
{
if (!saving_from_dialog) {
// ro_gui_save_prepare(gui_save_current_type, gui_save_content);
// ro_gui_dialog_open_persistent(g->window, dialog_saveas, true);
}
}
/**
* Overwrite of existing file confirmed, proceed with the save.
*/
void ro_gui_save_overwrite_confirmed(query_id id, enum query_response res, void *p)
{
if (ro_gui_save_content(gui_save_content, gui_save_message.data.data_xfer.file_name, true))
ro_gui_save_done();
}
|