/* * saveas * Handler for a save dbox under new dbox system * * v. 1.00 (9 August 1993) * * © 1993-1998 Straylight */ /*----- Licensing note ----------------------------------------------------* * * This file is part of Straylight's Steel library. * * Steel 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; either version 2, or (at your option) * any later version. * * Steel 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 Steel. If not, write to the Free Software Foundation, * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "wimp.h" #include "wimpt.h" #include "win.h" #include "dbox.h" #include "help.h" #include "saveas.h" #include "fileicon.h" #include "stddbox.h" #include "msgs.h" #include "template.h" #include "werr.h" static dbox saveas__db; static int saveas__filetype; static xfersend_saveproc saveas__saveproc; static xfersend_sendproc saveas__sendproc; static xfersend_printproc saveas__printproc; static void *saveas__handle; static int saveas__estsize; static char *saveas__title; static BOOL saveas__xfer; #define saveas__FILEICON 1 #define saveas__FILENAME 2 #define saveas__OK 0 /* * BOOL saveas__raw(dbox d,wimp_eventstr *e,void *handle) * * Use * Raw event handler for the save as dialogue box. * * Parameters * dbox d == the saveas dialogue box * wimp_eventstr *e == the current wimp event * void *handle == the caller's handle */ static BOOL saveas__raw(dbox d,wimp_eventstr *e,void *handle) { BOOL handled=FALSE; char name[256]; switch (e->e) { case wimp_EBUT: if (e->data.but.m.bbits==wimp_BDRAGLEFT) { dbox_getfield(d,saveas__FILENAME,name,256); saveas__xfer=TRUE; xfersend ( saveas__filetype, name, saveas__estsize, saveas__saveproc, saveas__sendproc, saveas__printproc, e, handle ); handled=TRUE; } break; } return (handled); } /* * void saveas * ( * char *title, * char *name, * int filetype, * int estsize, * xfersend_saveproc saveproc, * xfersend_sendproc sendproc, * xfersend_printproc printproc, * void *handle * ) * * Use * Creates and handles a save as dialogue box (even saving your data for * you!). * * Parameters * char *title == the title of the dialogue box. * char *name == the default filename for the box. * int filetype == the filetype of the data to be sent. * int estsize == the estimated file size. * xfersend_saveproc saveproc == function to save the data. * xfersend_sendproc sendproc == function to export data to another * application (RAM transfer). * xfersend_printproc printproc == function to print data. * void *handle == your handle to the data (or anything else!) */ void saveas ( char *title, char *name, int filetype, int estsize, xfersend_saveproc saveproc, xfersend_sendproc sendproc, xfersend_printproc printproc, void *handle ) { BOOL stop=FALSE; int index; BOOL dotYet; char fname[256]; saveas__title=title; saveas__filetype=filetype; saveas__estsize=estsize; saveas__saveproc=saveproc; saveas__sendproc=sendproc; saveas__printproc=printproc; saveas__handle=handle; if (template_exists("save")) { if (saveas__db=dbox_create("save"),saveas__db==0) return; } else { if (saveas__db=dbox_create("xfer_send"),saveas__db==0) return; } xfersend_close_on_xfer(TRUE,dbox_syshandle(saveas__db)); win_settitle(dbox_syshandle(saveas__db),"%s",saveas__title); dbox_setfield(saveas__db,saveas__FILENAME,"%s",name); fileicon(dbox_syshandle(saveas__db), saveas__FILEICON, saveas__filetype, name); dbox_rawEventHandler(saveas__db,saveas__raw,saveas__handle); dbox_display(saveas__db,FALSE); while (!stop) { switch (dbox_fillin(saveas__db)) { case dbox_CLOSE: stop=TRUE; break; case dbox_HELP: if (help_wasHelp()) { help_startHelp(); help_addLine ( msgs_lookup("saveasHM:This is the %s dialogue box."), saveas__title ); switch (dbox_helpField()) { case saveas__FILEICON: help_addLine(msgs_lookup ( "saveasFIH:Drag this icon to a Filer window or " "another application to save the file." )); break; } help_readFromIcon(); help_endHelp(); } break; case saveas__OK: if (wimpt_options() & 7) dbox_clickicon(saveas__db,saveas__OK); dbox_getfield(saveas__db,saveas__FILENAME,fname,256); dotYet=FALSE; for (index=0;fname[index]!=0;index++) { if (fname[index]=='.') dotYet=TRUE; } if (!dotYet) { if (wimpt_options() & 7) { note(msgs_lookup("saveasDI:To save, drag icon to a " "directory viewer.")); dbox_unclick(); } else { werr(FALSE,msgs_lookup("saveasDI:To save, drag icon to a " "directory viewer.")); } } else { saveas__xfer=FALSE; stop=saveas__saveproc(fname,saveas__handle); if (dbox_wasAdjustClick() || !stop) { if (wimpt_options() & 7) dbox_unclick(); stop=FALSE; } else { dbox_hide(saveas__db); if (wimpt_options() & 7) dbox_unclick(); } } break; } } xfersend_close_on_xfer(FALSE,0); dbox_delete(saveas__db); } /* * BOOL saveas_file_is_safe(void) * * Use * Informs caller if the file is going to a safe home. * * Returns * TRUE if the file is 'safe' - i.e. on disk */ BOOL saveas_file_is_safe(void) { if (saveas__xfer) return (xfersend_file_is_safe()); else return (TRUE); }