/* * stddbox * * Some standard Straylight dboxes. * * © 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 "dbox.h" #include "nopoll.h" #include "bbc.h" #include "stddbox.h" #include "werr.h" #include "win.h" #include "wimpt.h" #include "msgs.h" #include "saveas.h" #include "help.h" #include #include #include #define stddbox__WARNING_TITLE 0 #define stddbox__WARNING_MESSAGE 5 #define stddbox__WARNING_OK 4 #define stddbox__WARNING_CANCEL 3 #define stddbox__NOTE_TITLE 2 #define stddbox__NOTE_MESSAGE 0 #define stddbox__NOTE_OK 1 #define stddbox__WRITE_OK 0 #define stddbox__WRITE_WRITE 1 #define stddbox__SAVEWARN_TITLE 0 #define stddbox__SAVEWARN_MESSAGE 5 #define stddbox__SAVEWARN_CANCEL 3 #define stddbox__SAVEWARN_SAVE 4 #define stddbox__SAVEWARN_REMOVE 7 #define stddbox__PROGINFO_TITLE 0 #define stddbox__PROGINFO_NAME 7 #define stddbox__PROGINFO_PURPOSE 5 #define stddbox__PROGINFO_AUTHOR 3 #define stddbox__PROGINFO_VERSION 1 static xfersend_saveproc stddbox__save; static BOOL stddbox__saved; /* * BOOL warning(char *okMsg,char *warn,...) * * Use * Pops up a warning box, with a Cancel button and a default action button * with your own text in it. * * Parameters * char *okMsg == what to put in the default action button * char *warn == the warning message (printf()-style format string) * * Returns * TRUE if the user chose the OK button. */ BOOL warning(char *okMsg,char *warn,...) { dbox warndb=dbox_create("warning"); va_list ap; int clicked; char msg[256]; va_start(ap,warn); vsprintf(msg,warn,ap); va_end(ap); if (!warndb) return FALSE; win_settitle ( dbox_syshandle(warndb), msgs_lookup("stddbWARN:Warning from %s"), wimpt_programname() ); dbox_setfield(warndb,stddbox__WARNING_MESSAGE,msg); dbox_setfield(warndb,stddbox__WARNING_OK,okMsg); if (!dbox_hasTitle(warndb)) dbox_setEmbeddedTitle(warndb,stddbox__WARNING_TITLE,FALSE); werr_bleepy(); clicked=nopoll_doDbox ( warndb, nopoll_CENTRE, stddbox__WARNING_OK, stddbox__WARNING_CANCEL, -1 ); dbox_delete(warndb); return (clicked==nopoll_OK); } /* * void note(char *notemsg,...) * * Use * Displays a small note on the screen, so you can tell the user that he * has done something silly, etc. A lot nicer than old werr(). * * Parameters * char *notemsg == the note (printf()-style format string) */ void note(char *notemsg,...) { dbox notedb=dbox_create("note"); va_list ap; char msg[256]; va_start(ap,notemsg); vsprintf(msg,notemsg,ap); va_end(ap); if (!notedb) return; win_settitle ( dbox_syshandle(notedb), msgs_lookup("stddbNOTE:Note from %s"), wimpt_programname() ); dbox_setfield(notedb,stddbox__NOTE_MESSAGE,msg); if (!dbox_hasTitle(notedb)) dbox_setEmbeddedTitle(notedb,stddbox__NOTE_TITLE,FALSE); nopoll_doDbox(notedb,nopoll_ONPTR,stddbox__NOTE_OK,-1,-1); dbox_delete(notedb); } /* * BOOL writable * ( * char *title, * char *deflt, * char *result, * stddbox_writableHandler proc, * void *handle * ) * * Use * Opens a dialogue box for the user to input a string. Needs the * 'writable' template. * * Parameters * char *title == the title for the dialogue box. * char *default == the default string to put in the writable area. * char *result == a buffer to contain the result string. May be 0. * stddbox_writableHandler proc == proc to call when OK is clicked. May * be 0. Return TRUE if successful (i.e. we may close the dbox). * void *handle == passed to proc. * * Returns * TRUE if the string has been updated. */ BOOL writable ( char *title, char *deflt, char *result, stddbox_writableHandler proc, void *handle ) { dbox w=dbox_create("writable"); BOOL stop=FALSE; BOOL changed=FALSE; char buffer[256]; BOOL mayClose; if (result==0) result=buffer; if (w==0) return (FALSE); dbox_setfield(w,1,"%s",deflt); win_settitle(dbox_syshandle(w),"%s",title); dbox_display(w,FALSE); while (!stop) { switch (dbox_fillin(w)) { case dbox_CLOSE: stop=TRUE; break; case 0: dbox_clickicon(w,0); dbox_getfield(w,1,result,256); if (proc) mayClose=proc(result,handle); else mayClose=TRUE; changed=TRUE; if (dbox_wasAdjustClick() || mayClose==FALSE) dbox_unclick(); else { dbox_hide(w); dbox_unclick(); stop=TRUE; } break; } } dbox_delete(w); return (changed); } /* * BOOL stddbox__saver(char *filename,void *handle) * * Use * Passes on the save request to the caller's own save routine, and erases * the data if the file is now safe. * * Parameters * char *filename == where to save the file * void *handle == the caller's handle to the data */ static BOOL stddbox__saver(char *filename,void *handle) { if (stddbox__save(filename,handle)==FALSE) return (FALSE); if (saveas_file_is_safe()) stddbox__saved=TRUE; return (TRUE); } /* * void saveWarn * ( * BOOL useName, * void (*dispose)(void *handle), * char *title, * char *name, * int filetype, * int estsize, * xfersend_saveproc saveproc, * xfersend_sendproc sendproc, * xfersend_printproc printproc, * void *handle * ) * * Use * Pops up a save warning box allowing the use the luxury of saving his * data before closing the file. The file is only removed if the data is * 'safe'. * * Parameters * BOOL useName == whether to use the given name in the warning message * void (*dispose)(void *handle) == function to dispose the user's data * the others == as for saveas() */ void saveWarn ( BOOL useName, void (*dispose)(void *handle), char *title, char *name, int filetype, int estsize, xfersend_saveproc saveproc, xfersend_sendproc sendproc, xfersend_printproc printproc, void *handle ) { dbox d; if (win_anyWindows()) { d=dbox_create("saveWarn"); if (!d) return; win_settitle ( dbox_syshandle(d), msgs_lookup("stddbWARN:Warning from %s"), wimpt_programname() ); if (useName) dbox_setfield ( d, stddbox__SAVEWARN_MESSAGE, msgs_lookup("stddbREFN:File '%s' has been modified, but not saved. " "Do you want to discard these changes, save and then " "close the file, or cancel?"), name ); else dbox_setfield ( d, stddbox__SAVEWARN_MESSAGE, msgs_lookup("stddbREF:This file has been modified, but not saved. " "Do you want to discard these changes, save and then " "close the file, or cancel?") ); if (!dbox_hasTitle(d)) dbox_setEmbeddedTitle(d,stddbox__SAVEWARN_TITLE,FALSE); stddbox__save=saveproc; werr_bleepy(); switch (nopoll_doDbox ( d, nopoll_CENTRE, stddbox__SAVEWARN_SAVE, stddbox__SAVEWARN_CANCEL, stddbox__SAVEWARN_REMOVE )) { case nopoll_OK: stddbox__saved=FALSE; saveas ( title, name, filetype, estsize, stddbox__saver, sendproc, printproc, handle ); if (stddbox__saved) dispose(handle); break; case nopoll_CANCEL: break; case nopoll_OTHER: dispose(handle); break; } dbox_delete(d); } else { BOOL killIt; if (useName) killIt=werr_error ( 2, msgs_lookup("stddbREFN:Are you sure you want to " "remove edited file '%s'?"), name ); else killIt=werr_error ( 2, msgs_lookup("stddbREF:Are you sure you want to " "remove your edited file?") ); if (killIt) dispose(handle); } } /* * void progInfo * ( * char *name, * char *purpose, * char *author, * int version, * char *date * ) * * Use * Presents a standard progInfo window giving information about an * application. * * Parameters * char *name == the name of the program * char *purpose == what it does * char *author == author/copyright string (usually something like * '© 1993-1998 Straylight') * int version == the version number*100 (e.g. 374 for 3.74 etc.) * char *date == the date of compilation (use _TIME_NOW) */ void progInfo(char *name,char *purpose,char *author,int version,char *date) { dbox d=dbox_create("progInfo"); char buffer[100]; if (!d) return; if (!dbox_hasTitle(d)) dbox_setEmbeddedTitle(d,stddbox__PROGINFO_TITLE,TRUE); dbox_setfield(d,stddbox__PROGINFO_NAME,"%s",name); dbox_setfield(d,stddbox__PROGINFO_PURPOSE,"%s",purpose); dbox_setfield(d,stddbox__PROGINFO_AUTHOR,"%s",author); dbox_setfield ( d, stddbox__PROGINFO_VERSION, "%i.%02i (%s)", version/100, version%100, date ); sprintf(buffer, msgs_lookup("stddbPIH:This window gives you " "information about this version of %s."), wimpt_programname()); mbox(d,buffer); } /* * void mbox(dbox d) * * Use * Handles a monologue box (like info windows) where no input is required. * You should create the dbox, fill in any fields required. This routine * then handles the rest. It deletes the dbox when it's finished - it's of * no use to the caller anyway - who wants a used dialogue box with no * input? Yuk... * * You can specify a help message tag to be displayed before any messages * embedded in the icons. This is passed through msgs_lookup before * sending to help_addLine. Specify zero for this to send no message. * * Parameters * dbox d == the box to handle * char *help == the help message tag to stick on the top */ void mbox(dbox d,char *help) { BOOL done=FALSE; dbox_display(d,dbox_MENU_OVERPTR); while (!done) { switch (dbox_fillin(d)) { case dbox_CLOSE: done=TRUE; break; case dbox_HELP: help_startHelp(); if (help) help_addLine(msgs_lookup(help)); help_readFromIcon(); help_endHelp(); break; } } dbox_delete(d); }