Annotation of libwww/Library/src/HTAlert.c, revision 2.39
2.18 frystyk 1: /* HTAlert.c
2.39 ! frystyk 2: ** DIALOG MANAGER
2.18 frystyk 3: **
2.23 frystyk 4: ** (c) COPYRIGHT MIT 1995.
2.18 frystyk 5: ** Please first read the full copyright statement in the file COPYRIGH.
1.1 timbl 6: **
7: ** REPLACE THIS MODULE with a GUI version in a GUI environment!
8: **
9: ** History:
10: ** Jun 92 Created May 1992 By C.T. Barker
11: ** Feb 93 Simplified, portablised TBL
2.8 luotonen 12: ** Sep 93 Corrected 3 bugs in HTConfirm() :-( AL
2.39 ! frystyk 13: ** Nov 95 Rewritten using callbacks HFN
1.1 timbl 14: */
15:
2.20 frystyk 16: /* Library include files */
2.29 frystyk 17: #include "WWWLib.h"
2.21 frystyk 18: #include "HTError.h" /* Implemented here */
19: #include "HTAlert.h" /* Implemented here */
1.1 timbl 20:
2.39 ! frystyk 21: typedef struct _HTAlert {
! 22: HTAlertCallback * cbf;
! 23: HTAlertOpcode opcode;
! 24: } HTAlert;
! 25:
! 26: struct _HTAlertPar {
! 27: char * message;
! 28: char * secret;
! 29: void * output;
! 30: };
2.28 frystyk 31:
2.25 frystyk 32: PRIVATE BOOL HTInteractive=YES; /* Any prompts from the Library? */
1.1 timbl 33:
2.39 ! frystyk 34: PRIVATE HTList * HTMessages = NULL; /* Global list of alert functions */
! 35:
2.21 frystyk 36: /* ------------------------------------------------------------------------- */
2.25 frystyk 37:
2.39 ! frystyk 38: /*
! 39: ** All messaging can be turned on or off as you like
! 40: */
! 41: PUBLIC void HTAlert_setInteractive (BOOL interactive)
2.25 frystyk 42: {
43: HTInteractive = interactive;
44: }
45:
2.39 ! frystyk 46: PUBLIC BOOL HTAlert_interactive (void)
2.25 frystyk 47: {
48: return HTInteractive;
49: }
2.21 frystyk 50:
2.39 ! frystyk 51: /* HTAlertCall_add
! 52: ** ---------------
! 53: ** Register a call back function that is to be called when generating
! 54: ** messages, dialog, prompts, progress reports etc.
! 55: **
! 56: ** The opcode signifies which call back function to call depending of the
! 57: ** type of the message. Opcode can be one of the enumerations defined
! 58: ** by HTAlertOpcode.
! 59: */
! 60: PUBLIC BOOL HTAlertCall_add (HTList * list, HTAlertCallback * cbf,
! 61: HTAlertOpcode opcode)
! 62: {
! 63: if (WWWTRACE)
! 64: TTYPrint(TDEST, "Alert Add... HTAlertCallback %p\n", (void *) cbf);
! 65: if (list && cbf) {
! 66: HTAlert *me = (HTAlert *) calloc(1, sizeof(HTAlert));
! 67: if (!me) outofmem(__FILE__, "HTAlertCall_add");
! 68: me->cbf = cbf;
! 69: me->opcode = opcode;
! 70: return HTList_addObject(list, (void *) me);
! 71: }
! 72: return NO;
! 73: }
! 74:
! 75: /* HTAlertCall_delete
! 76: ** ------------------
! 77: ** Unregister a call back function from a list
! 78: */
! 79: PUBLIC BOOL HTAlertCall_delete (HTList * list, HTAlertCallback *cbf)
! 80: {
! 81: if (WWWTRACE)
! 82: TTYPrint(TDEST, "Call delete HTAlertCallback %p\n", (void *) cbf);
! 83: if (list && cbf) {
! 84: HTList *cur = list;
! 85: HTAlert *pres;
! 86: while ((pres = (HTAlert *) HTList_nextObject(cur))) {
! 87: if (pres->cbf == cbf) {
! 88: HTList_removeObject(list, (void *) pres);
! 89: free(pres);
! 90: return YES;
! 91: }
! 92: }
! 93: }
! 94: return NO;
! 95: }
2.28 frystyk 96:
2.39 ! frystyk 97: /* HTAlertCall_deleteAll
! 98: ** ---------------------
! 99: ** Unregisters all call back functions
! 100: */
! 101: PUBLIC BOOL HTAlertCall_deleteAll (HTList * list)
! 102: {
! 103: if (WWWTRACE)
! 104: TTYPrint(TDEST, "Call delete All callback functions\n");
! 105: if (list) {
! 106: HTList *cur = list;
! 107: HTAlert *pres;
! 108: while ((pres = (HTAlert *) HTList_nextObject(cur))) {
! 109: HTList_removeObject(list, (void *) pres);
! 110: free(pres);
! 111: }
! 112: HTList_delete(list);
! 113: return YES;
2.28 frystyk 114: }
2.39 ! frystyk 115: return NO;
! 116: }
! 117:
! 118: /* HTAlertCall_find
! 119: ** ----------------
! 120: ** Finds a callback function corresponding to the opcode. If none has
! 121: ** been registered then NULL is returned.
! 122: */
! 123: PUBLIC HTAlertCallback * HTAlertCall_find (HTList * list, HTAlertOpcode opcode)
! 124: {
! 125: if (list && HTInteractive) {
! 126: HTAlert * pres;
! 127: while ((pres = (HTAlert *) HTList_nextObject(list)) != NULL) {
! 128: if (pres->opcode & opcode)
! 129: return pres->cbf;
2.28 frystyk 130: }
2.39 ! frystyk 131: if (WWWTRACE)
! 132: TTYPrint(TDEST, "Alert Find.. No entry found for opcode %d\n",opcode);
2.28 frystyk 133: }
2.39 ! frystyk 134: return NULL;
2.21 frystyk 135: }
136:
2.39 ! frystyk 137: /*
! 138: ** Global List of Alert functions. list can be NULL
! 139: */
! 140: PUBLIC void HTAlert_setGlobal (HTList * list)
! 141: {
! 142: HTMessages = list;
! 143: }
2.21 frystyk 144:
2.39 ! frystyk 145: PUBLIC HTList * HTAlert_global (void)
1.1 timbl 146: {
2.39 ! frystyk 147: return HTMessages;
1.1 timbl 148: }
149:
2.39 ! frystyk 150: PUBLIC BOOL HTAlert_add (HTAlertCallback * cbf, HTAlertOpcode opcode)
1.1 timbl 151: {
2.39 ! frystyk 152: if (!HTMessages) HTMessages = HTList_new();
! 153: return HTAlertCall_add(HTMessages, cbf, opcode);
1.1 timbl 154: }
155:
2.39 ! frystyk 156: /* HTAlert_find
! 157: ** ------------
! 158: ** Finds a global callback function corresponding to the opcode
1.1 timbl 159: */
2.39 ! frystyk 160: PUBLIC HTAlertCallback * HTAlert_find (HTAlertOpcode opcode)
1.1 timbl 161: {
2.39 ! frystyk 162: return HTAlertCall_find(HTMessages, opcode);
1.1 timbl 163: }
2.8 luotonen 164:
2.39 ! frystyk 165: PUBLIC HTAlertPar * HTAlert_newReply (void)
! 166: {
! 167: HTAlertPar * me = (HTAlertPar *) calloc(1, sizeof(HTAlertPar));
! 168: if (!me) outofmem(__FILE__, "HTAlert_newReply");
! 169: return me;
! 170: }
2.8 luotonen 171:
2.39 ! frystyk 172: /* HTAlert_deleteReply
! 173: ** -------------------
! 174: ** Delete reply structure but don't touch the replies themselves.
2.8 luotonen 175: */
2.39 ! frystyk 176: PUBLIC void HTAlert_deleteReply (HTAlertPar * old)
2.8 luotonen 177: {
2.39 ! frystyk 178: if (old) free(old);
2.11 luotonen 179: }
180:
2.39 ! frystyk 181: PUBLIC char * HTAlert_replyMessage (HTAlertPar * me)
! 182: {
! 183: return me ? me->message : NULL;
! 184: }
2.11 luotonen 185:
2.39 ! frystyk 186: PUBLIC BOOL HTAlert_setReplyMessage (HTAlertPar * me, CONST char * message)
2.11 luotonen 187: {
2.39 ! frystyk 188: if (me && message) {
! 189: StrAllocCopy(me->message, message);
! 190: return YES;
! 191: }
! 192: return NO;
2.8 luotonen 193: }
194:
2.39 ! frystyk 195: PUBLIC char * HTAlert_replySecret (HTAlertPar * me)
! 196: {
! 197: return me ? me->secret : NULL;
! 198: }
2.21 frystyk 199:
2.39 ! frystyk 200: PUBLIC BOOL HTAlert_setReplySecret (HTAlertPar * me, CONST char * secret)
2.21 frystyk 201: {
2.39 ! frystyk 202: if (me && secret) {
! 203: StrAllocCopy(me->secret, secret);
! 204: return YES;
! 205: }
! 206: return NO;
! 207: }
2.21 frystyk 208:
2.39 ! frystyk 209: PUBLIC void * HTAlert_replyOutput (HTAlertPar * me)
! 210: {
! 211: return me ? me->output : NULL;
! 212: }
2.21 frystyk 213:
2.39 ! frystyk 214: PUBLIC BOOL HTAlert_setReplyOutput (HTAlertPar * me, void * output)
! 215: {
! 216: if (me) {
! 217: me->output = output;
! 218: return YES;
2.21 frystyk 219: }
2.39 ! frystyk 220: return NO;
2.21 frystyk 221: }
2.38 frystyk 222:
223: /* TTYPrint
224: ** --------
225: ** Single function through which all trace messages must pass - EGP
226: */
227: #if WWWTRACE_MODE == WWWTRACE_TTY && (!defined(_WINDOWS) || defined(_CONSOLE))
228: int TTYPrint(FILE* file, const char* fmt, ...)
229: {
230: int len;
231: char space[513];
232: char* pArgs;
233:
234: pArgs = (char*)(&fmt + 1);
235: len = vsprintf(space, (char*)fmt, (char*)pArgs);
236: fprintf(file, space);
237: return (len);
238: }
2.39 ! frystyk 239: /* otherwise handled in www.c with the rest of the window stuff */
2.38 frystyk 240: #endif
2.39 ! frystyk 241:
Webmaster