1 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 29 30 34 3 4 5 6 7 8 9 3 4 5 6 7 8 9 10 11 12 13 14 15 17 18 typedef struct 19 { 20 int errnum; 21 char errmess[252]; 22 } os_error; 23 24 25 26 27 28 29 30 31 0 || 0 32 32 33 34 35 36 37 39 40 41 42 43 44 45 46 47 48 49 50 51 11 extern void Error_ReportInternal(int errornum, char *report, ...); 12 extern void Error_ReportFatalInternal(int errornum, char *report, ...); 13 extern void Error_Report(int errornum, char *report, ...); 14 extern void Error_ReportFatal(int errornum, char *report, ...); 15 extern unsigned Error_Check(os_error *error); 16 extern void Error_CheckFatal(os_error *error); 17 extern unsigned Error_OutOfMemory( unsigned fatal, char *place); 18 19 20 21 22 23 24 0 && ! 0 25 25 26 27 extern os_error error_global; 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 3 4 5 6 7 8 9 11 12 3 4 5 6 7 8 9 11 12 typedef struct 13 { 14 int x, y; 15 } wimp_point; 16 typedef wimp_point wimp_coord; 17 typedef struct 18 { 19 wimp_point min; 20 wimp_point max; 21 } wimp_rect; 22 typedef wimp_rect wimp_box; 23 typedef int window_handle; 24 typedef int icon_handle; 25 typedef int task_handle; 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 typedef union 46 { 47 int value; 48 struct 49 { 50 unsigned int wimpcolour : 4; 51 unsigned int gcolaction : 3; 52 unsigned int foreback : 1; 53 unsigned int padding : 24; 54 } data; 55 } wimp_colour; 56 typedef union 57 { 58 int value; 59 struct 60 { 61 char gcol; 62 char red; 63 char green; 64 char blue; 65 } data; 66 } palette_entry; 67 typedef struct 68 { 69 palette_entry colour[16]; 70 palette_entry border; 71 palette_entry mouse1; 72 palette_entry mouse2; 73 palette_entry mouse3; 74 } palette_block; 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 typedef union 123 { 124 unsigned int value; 125 struct 126 { 127 unsigned int garbage1 : 6; 128 unsigned int font : 1; 129 unsigned int garbage2 : 17; 130 unsigned int handle : 8; 131 } font; 132 struct 133 { 134 unsigned int text : 1; 135 unsigned int sprite : 1; 136 unsigned int border : 1; 137 unsigned int hcentre : 1; 138 unsigned int vcentre : 1; 139 unsigned int filled : 1; 140 unsigned int font : 1; 141 unsigned int needshelp : 1; 142 unsigned int indirected : 1; 143 unsigned int rightjustify : 1; 144 unsigned int allowadjust : 1; 145 unsigned int halfsize : 1; 146 unsigned int buttontype : 4; 147 unsigned int esg : 5; 148 unsigned int selected : 1; 149 unsigned int shaded : 1; 150 unsigned int deleted : 1; 151 unsigned int foreground : 4; 152 unsigned int background : 4; 153 } data; 154 } icon_flags; 155 typedef struct 156 { 157 char *buffer; 158 char *validstring; 159 unsigned int bufflen; 160 } icon_indtext; 161 typedef struct 162 { 163 const char *name; 164 void *spritearea; 165 unsigned int nameisname; 166 } icon_indsprite; 167 typedef union 168 { 169 char text[ 12 ]; 170 icon_indtext indirecttext; 171 char spritename[ 12 ]; 172 icon_indsprite indirectsprite; 173 } icon_data; 174 typedef struct 175 { 176 wimp_box workarearect; 177 icon_flags flags; 178 icon_data data; 179 } icon_block; 180 typedef struct 181 { 182 window_handle window; 183 icon_block icondata; 184 } icon_createblock; 185 typedef union 186 { 187 struct 188 { 189 unsigned int hastitle : 1; 190 unsigned int moveable : 1; 191 unsigned int hasvscroll : 1; 192 unsigned int hashscroll : 1; 193 unsigned int autoredraw : 1; 194 unsigned int pane : 1; 195 unsigned int nobounds : 1; 196 unsigned int nobackclose : 1; 197 unsigned int scrollrq : 1; 198 unsigned int scrollrqdebounced : 1; 199 unsigned int realcolours : 1; 200 unsigned int backwindow : 1; 201 unsigned int hotkeys : 1; 202 unsigned int keeponscreen : 1; 203 unsigned int ignoreright : 1; 204 unsigned int ignorebottom : 1; 205 unsigned int open : 1; 206 unsigned int top : 1; 207 unsigned int fullsize : 1; 208 unsigned int istoggling : 1; 209 unsigned int focus : 1; 210 unsigned int forceonce : 1; 211 unsigned int dummy22 : 1; 212 unsigned int dummy23 : 1; 213 unsigned int backicon : 1; 214 unsigned int closeicon : 1; 215 unsigned int titlebar : 1; 216 unsigned int toggleicon : 1; 217 unsigned int vscroll : 1; 218 unsigned int adjusticon : 1; 219 unsigned int hscroll : 1; 220 unsigned int newflags : 1; 221 } data; 222 int value; 223 } window_flags; 224 typedef struct 225 { 226 int x : 16; 227 int y : 16; 228 } window_minsize; 229 typedef enum 230 { 231 windowcol_TITLEFORE = 0, 232 windowcol_TITLEBACK, 233 windowcol_WORKFORE, 234 windowcol_WORKBACK, 235 windowcol_SCROLLBACK, 236 windowcol_SCROLLFORE, 237 windowcol_TITLEHILITE 238 } window_colourindices; 239 typedef struct 240 { 241 wimp_box screenrect; 242 wimp_point scroll; 243 window_handle behind; 244 window_flags flags; 245 char colours[8]; 246 wimp_box workarearect; 247 icon_flags titleflags; 248 icon_flags workflags; 249 void *spritearea; 250 window_minsize minsize; 251 icon_data title; 252 unsigned int numicons; 253 } window_block; 254 typedef struct 255 { 256 window_handle window; 257 wimp_box screenrect; 258 wimp_point scroll; 259 window_handle behind; 260 } window_openblock; 261 typedef struct 262 { 263 window_openblock openblock; 264 window_flags flags; 265 } window_state; 266 typedef struct 267 { 268 window_handle window; 269 window_block block; 270 } window_info; 271 typedef struct 272 { 273 window_handle window; 274 wimp_box rect; 275 wimp_point scroll; 276 wimp_box cliprect; 277 } window_redrawblock; 278 typedef struct 279 { 280 window_handle window; 281 wimp_box screenrect; 282 } window_outline; 283 284 285 286 287 288 289 290 typedef union 291 { 292 unsigned int value; 293 struct 294 { 295 unsigned int adjust : 1; 296 unsigned int menu : 1; 297 unsigned int select : 1; 298 unsigned int dummy3 : 1; 299 unsigned int dragadjust : 1; 300 unsigned int dummy5 : 1; 301 unsigned int dragselect : 1; 302 unsigned int dummy7 : 1; 303 unsigned int clickadjust : 1; 304 unsigned int dummy9 : 1; 305 unsigned int clickselect : 1; 306 } data; 307 } button_state; 308 typedef struct 309 { 310 wimp_point pos; 311 button_state button; 312 window_handle window; 313 icon_handle icon; 314 } mouse_block; 315 typedef struct 316 { 317 int shapenumber; 318 char *shapedata; 319 unsigned int width; 320 unsigned int height; 321 wimp_point active; 322 } pointer_shapeblock; 323 typedef enum 324 { 325 drag_MOVEWINDOW = 1, 326 drag_RESIZEWINDOW, 327 drag_SCROLLX, 328 drag_SCROLLY, 329 drag_FIXEDBOX, 330 drag_RUBBERBOX, 331 drag_INVISIBLE, 332 drag_USERFIXEDBBOX, 333 drag_USERRUBBERBOX, 334 drag_USERFIXEDNC, 335 drag_USERRUBBERNC 336 } drag_type; 337 typedef struct 338 { 339 window_handle window; 340 drag_type type; 341 wimp_box screenrect; 342 wimp_box parent; 343 } drag_block; 344 typedef union 345 { 346 unsigned int value; 347 struct 348 { 349 unsigned int ok : 1; 350 unsigned int cancel : 1; 351 unsigned int highlightcancel : 1; 352 unsigned int noprompt : 1; 353 unsigned int noprefix : 1; 354 unsigned int nowait : 1; 355 unsigned int closebox : 1; 356 } data; 357 } error_flags; 358 typedef struct menu_block *menu_ptr; 359 typedef union 360 { 361 unsigned int value; 362 struct 363 { 364 unsigned int ticked : 1; 365 unsigned int dotted : 1; 366 unsigned int writable : 1; 367 unsigned int notifysub : 1; 368 unsigned int openshaded : 1; 369 unsigned int dummy2 : 2; 370 unsigned int last : 1; 371 unsigned int indtitle : 1; 372 unsigned int dummy13 : 13; 373 unsigned int shaded : 1; 374 unsigned int dummy1 : 1; 375 unsigned int foreground : 4; 376 unsigned int background : 4; 377 } data; 378 } menu_flags; 379 typedef union 380 { 381 menu_ptr menu; 382 window_handle window; 383 int value; 384 } menu_submenu; 385 typedef struct 386 { 387 menu_flags menuflags; 388 menu_submenu submenu; 389 icon_flags iconflags; 390 icon_data icondata; 391 } menu_item; 392 typedef struct menu_block 393 { 394 char title [ 12 ]; 395 char titlefore, titleback, workfore, workback; 396 unsigned int width; 397 unsigned int height; 398 unsigned int gap; 399 } menu_block; 400 typedef int key_press; 401 typedef struct 402 { 403 window_handle window; 404 icon_handle icon; 405 wimp_point offset; 406 int height; 407 int index; 408 } caret_block; 409 typedef struct 410 { 411 caret_block caret; 412 key_press code; 413 } key_block; 414 typedef struct 415 { 416 int address; 417 int contents; 418 } pollword_block; 419 typedef enum 420 { 421 message_QUIT = 0, 422 message_CLOSEDOWN = 0, 423 message_DATASAVE = 1, 424 message_DATASAVEACK = 2, 425 message_DATASAVEOK = 2, 426 message_DATALOAD = 3, 427 message_DATALOADACK = 4, 428 message_DATALOADOK = 4, 429 message_DATAOPEN, 430 message_RAMFETCH, 431 message_RAMTRANSMIT, 432 message_PREQUIT, 433 message_PALETTECHANGE, 434 message_SAVEDESK, 435 message_DEVICECLAIM, 436 message_DEVICEINUSE, 437 message_DATASAVED, 438 message_FILEROPENDIR = 0x400, 439 message_FILERCLOSEDIR, 440 message_FILEROPENDIRAT, 441 message_FILERSELECTIONDIRECTORY, 442 message_FILERADDSELECTION, 443 message_FILERACTION, 444 message_FILERCONTROLACTION, 445 message_FILERSELECTION, 446 message_HELPREQUEST = 0x502, 447 message_HELPREPLY, 448 message_NOTIFY = 0x40040, 449 message_MENUWARNING = 0x400C0, 450 message_MENUWARN = 0x400C0, 451 message_MODECHANGE, 452 message_TASKINITIALISE = 0x400C2, 453 message_INITTASK = 0x400C2, 454 message_TASKCLOSEDOWN = 0x400C3, 455 message_CLOSETASK = 0x400C3, 456 message_SLOTSIZE = 0x400C4, 457 message_SLOTCHANGE = 0x400C4, 458 message_SETSLOT = 0x400C5, 459 message_TASKNAMERQ, 460 message_TASKNAMEIS, 461 message_TASKSTARTED, 462 message_MENUSDELETED, 463 message_WINDOWINFO = 0x400CC, 464 message_POPUPRQ = 0x46D40, 465 message_POPUPREQUEST = 0x46D40, 466 message_POPUPSTATE, 467 message_POPUPCLOSED, 468 message_PRINTFILE = 0x80140, 469 message_WILLPRINT, 470 message_PRINTSAVE, 471 message_PRINTINIT, 472 message_PRINTERROR, 473 message_PRINTTYPEODD, 474 message_PRINTTYPEKNOWN, 475 message_SETPRINTER, 476 message_PSPRINTERQUERY = 0x8014c, 477 message_PSPRINTERACK, 478 message_PSPRINTERMODIFIED, 479 message_PSPRINTERDEFAULTS, 480 message_PSPRINTERDEFAULTED, 481 message_PSPRINTERNOTPS, 482 message_RESETPRINTER, 483 message_PSISFONTPRINTRUNNING, 484 message_TASKWINDOW_INPUT = 0x808c0, 485 message_TASKWINDOW_OUTPUT, 486 message_TASKWINDOW_EGO, 487 message_TASKWINDOW_MORIO, 488 message_TASKWINDOW_MORITE, 489 message_TASKWINDOW_NEWTASK, 490 message_TASKWINDOW_SUSPEND, 491 message_TASKWINDOW_RESUME 492 } message_action; 493 typedef int message_destinee; 494 typedef struct 495 { 496 unsigned int size; 497 task_handle sender; 498 unsigned int myref; 499 unsigned int yourref; 500 message_action action; 501 } message_header; 502 typedef struct 503 { 504 window_handle window; 505 icon_handle icon; 506 wimp_point pos; 507 int estsize; 508 int filetype; 509 char leafname[12]; 510 } message_datasave; 511 typedef struct 512 { 513 window_handle window; 514 icon_handle icon; 515 wimp_point pos; 516 int estsize; 517 int filetype; 518 char filename[212]; 519 } message_datasaveack; 520 typedef struct 521 { 522 window_handle window; 523 icon_handle icon; 524 wimp_point pos; 525 int size; 526 int filetype; 527 char filename[212]; 528 } message_dataload; 529 typedef struct 530 { 531 window_handle window; 532 icon_handle icon; 533 wimp_point pos; 534 int size; 535 int filetype; 536 char filename[212]; 537 } message_dataloadack; 538 typedef message_dataload message_dataopen; 539 typedef struct 540 { 541 char *buffer; 542 int buffsize; 543 } message_ramfetch; 544 typedef struct 545 { 546 char *buffer; 547 int byteswritten; 548 } message_ramtransmit; 549 typedef struct 550 { 551 mouse_block where; 552 } message_helprequest; 553 typedef struct 554 { 555 char text[200]; 556 } message_helpreply; 557 typedef struct 558 { 559 int filler[5]; 560 int filetype; 561 char filename[212]; 562 } message_print; 563 typedef struct 564 { 565 int id; 566 wimp_point openpos; 567 int selection[10]; 568 } message_menuwarn; 569 typedef struct 570 { 571 window_handle window; 572 task_handle task; 573 char title[20]; 574 } message_iconize; 575 typedef struct 576 { 577 window_handle window; 578 int dummy; 579 char spritename[8]; 580 char title[20]; 581 } message_windowinfo; 582 typedef struct 583 { 584 message_header header; 585 union 586 { 587 char bytes [236]; 588 int words [59]; 589 message_datasave datasave; 590 message_datasaveack datasaveack; 591 message_dataload dataload; 592 message_dataopen dataopen; 593 message_ramfetch ramfetch; 594 message_ramtransmit ramtransmit; 595 message_helprequest helprequest; 596 message_helpreply helpreply; 597 message_print print; 598 message_menuwarn menuwarn; 599 message_iconize iconize; 600 message_windowinfo windowinfo; 601 0 602 602 603 604 605 } data; 606 } message_block; 607 608 typedef enum 609 { 610 event_ANY = -99, 611 event_NULL = 0, 612 event_REDRAW, 613 event_OPEN, 614 event_CLOSE, 615 event_PTRLEAVE, 616 event_PTRENTER, 617 event_CLICK = 6, 618 event_BUTTON = 6, 619 event_USERDRAG, 620 event_KEY, 621 event_MENU, 622 event_SCROLL, 623 event_LOSECARET, 624 event_GAINCARET, 625 event_NONZEROPOLLWORD, 626 event_USERMESSAGE = 17, 627 event_SEND = 17, 628 event_USERMESSAGERECORDED = 18, 629 event_SENDWANTACK = 18, 630 event_USERMESSAGEACK = 19, 631 event_ACK = 19 632 } event_type; 633 typedef union 634 { 635 unsigned int value; 636 struct 637 { 638 unsigned int null : 1; 639 unsigned int redraw : 1; 640 unsigned int open : 1; 641 unsigned int close : 1; 642 unsigned int ptrleave : 1; 643 unsigned int ptrenter : 1; 644 unsigned int click : 1; 645 unsigned int userdrag : 1; 646 unsigned int key : 1; 647 unsigned int menu : 1; 648 unsigned int scroll : 1; 649 unsigned int losecaret : 1; 650 unsigned int gaincaret : 1; 651 unsigned int nonzeropollword : 1; 652 unsigned int dummy14 : 1; 653 unsigned int dummy15 : 1; 654 unsigned int dummy16 : 1; 655 unsigned int usermessage : 1; 656 unsigned int usermessagerecorded : 1; 657 unsigned int usermessageack : 1; 658 unsigned int dummy20 : 1; 659 unsigned int dummy21 : 1; 660 unsigned int r3ispollwordptr : 1; 661 unsigned int highprioritypoll : 1; 662 unsigned int keepfpregisters : 1; 663 } data; 664 } event_pollmask; 665 typedef struct 666 { 667 window_openblock openblock; 668 wimp_point direction; 669 } scroll_rq; 670 typedef union 671 { 672 caret_block caret; 673 key_block key; 674 pollword_block pollword; 675 window_openblock openblock; 676 message_block message; 677 mouse_block mouse; 678 wimp_box screenrect; 679 int selection[10]; 680 scroll_rq scroll; 681 char bytes [256]; 682 int words [64]; 683 } event_data; 684 typedef struct 685 { 686 event_type type; 687 event_data data; 688 } event_pollblock; 689 typedef struct 690 { 691 char fonts[256]; 692 } font_array; 693 typedef struct 694 { 695 window_block *buffer; 696 char *workfree; 697 char *workend; 698 font_array *font; 699 char *name; 700 unsigned int index; 701 } template_block; 702 typedef struct 703 { 704 wimp_point mul; 705 wimp_point div; 706 } scale_block; 707 708 709 710 711 14 extern os_error *Wimp_Initialise(unsigned int *version, 15 char *name, 16 task_handle *task, 17 int *messages); 18 extern os_error *Wimp_CloseDown(task_handle task); 19 extern os_error *Wimp_StartTask(char *command); 20 extern os_error *Wimp_StartTask3(char *command, task_handle *newtask); 21 extern os_error *Wimp_SlotSize(int *currentslot, int *nextslot, int *freepool); 22 extern os_error *Wimp_TransferBlock(task_handle sourcetask, 23 void *sourcebuffer, 24 task_handle desttask, 25 void *destbuffer, 26 unsigned int length); 27 extern os_error *Wimp_ReportError(os_error *error, int flags, char *name); 28 extern int Wimp_ReportErrorR(os_error *error, int flags, char *name); 29 extern os_error *Wimp_SendMessage (event_type eventtype, 30 message_block *message, 31 message_destinee destinee, 32 icon_handle icon); 33 extern os_error *Wimp_OpenTemplate(char *name); 34 extern os_error *Wimp_CloseTemplate(void); 35 extern os_error *Wimp_LoadTemplate(template_block *wtemplate); 36 extern os_error *Wimp_CreateWindow(window_block *block, window_handle *window); 37 extern os_error *Wimp_OpenWindow(window_openblock *block); 38 extern os_error *Wimp_CloseWindow(window_handle window); 39 extern os_error *Wimp_DeleteWindow(window_handle window); 40 extern os_error *Wimp_RedrawWindow(window_redrawblock *block, unsigned *more); 41 extern os_error *Wimp_UpdateWindow(window_redrawblock *block, unsigned *more); 42 extern os_error *Wimp_GetRectangle(window_redrawblock *block, unsigned *more); 43 extern os_error *Wimp_GetWindowState(window_handle window,window_state *state); 44 extern os_error *Wimp_GetWindowInfo(window_info *info); 45 extern os_error *Wimp_GetWindowInfoNoIcons(window_info *info); 46 extern os_error *Wimp_GetWindowOutline(window_outline *outline); 47 extern os_error *Wimp_SetExtent(window_handle window, wimp_box *newextent); 48 extern os_error *Wimp_ForceRedraw(window_redrawblock *block); 49 extern os_error *Wimp_CreateIcon(icon_createblock *block, icon_handle *icon); 50 extern os_error *Wimp_DeleteIcon(window_handle window, icon_handle icon); 51 extern os_error *Wimp_SetIconState(window_handle window, 52 icon_handle icon, 53 int value, 54 int mask); 55 extern os_error *Wimp_GetIconState(window_handle window, 56 icon_handle icon, 57 icon_block *iconinfo); 58 extern os_error *Wimp_WhichIcon(window_handle window, 59 icon_handle *icons, 60 int mask, 61 int settings); 62 extern os_error *Wimp_PlotIcon(icon_block *fakeicon); 63 extern os_error *Wimp_PlotIcon2( icon_block *fakeicon, int xorigin, int yorigin); 64 65 66 67 extern os_error *Wimp_Poll3(event_pollmask mask, event_pollblock *event, 68 void *pollword); 69 extern os_error *Wimp_PollIdle3(event_pollmask mask, event_pollblock *block, 70 int earliest, void *pollword); 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 extern os_error *Wimp_SaveFPStateOnPoll(void); 92 extern os_error *Wimp_CorruptFPStateOnPoll(void); 93 extern os_error *Wimp_GetPointerInfo(mouse_block *ptrinfo); 94 extern os_error *Wimp_SetPointerShape(pointer_shapeblock *shape); 95 extern os_error *Wimp_DragBox(drag_block *draginfo); 96 extern os_error *Wimp_SetCaretPosition(caret_block *caret); 97 extern os_error *Wimp_GetCaretPosition(caret_block *caret); 98 extern os_error *Wimp_CreateMenu(menu_ptr menu, int xpos, int ypos); 99 extern os_error *Wimp_CreateSubMenu(menu_ptr menu, int xpos, int ypos); 100 extern os_error *Wimp_DecodeMenu(menu_ptr menu, 101 int *selections, 102 char *result); 103 extern os_error *Wimp_ProcessKey(int character); 104 extern os_error *Wimp_SetMode(int mode); 105 extern os_error *Wimp_SetColour(int colour); 106 extern os_error *Wimp_ReadPalette(palette_block *palette); 107 extern os_error *Wimp_SetPalette(palette_block *palette); 108 extern os_error *Wimp_ReadPixTrans(int areaindex, 109 void *area, 110 void *sprite, 111 scale_block *scaleblock, 112 char *transblock); 113 extern os_error *Wimp_SetFontColours(int foreground, int background); 114 extern os_error *Wimp_SpriteOp( int r[10]); 115 extern os_error *Wimp_BaseOfSprites(void **rom_base, void **ram_base); 116 extern os_error *Wimp_BlockCopy(window_handle window, wimp_box *source, 117 int x, int y); 118 extern os_error *Wimp_CommandWindow(int); 119 120 121 122 123 37 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 18 19 20 21 22 23 24 26 27 28 3 4 5 6 7 8 9 11 typedef struct linklist_header 12 { 13 struct linklist_header *next; 14 struct linklist_header *previous; 15 } linklist_header ; 16 extern void LinkList_AddToHead(linklist_header *anchor, linklist_header *item); 17 extern void LinkList_AddToTail(linklist_header *anchor, linklist_header *item); 18 extern void LinkList_InsertBefore(linklist_header *anchor, 19 linklist_header *pos, 20 linklist_header *item); 21 extern void LinkList_InsertAfter(linklist_header *anchor, 22 linklist_header *pos, 23 linklist_header *item); 24 extern unsigned LinkList_InList(linklist_header *anchor, linklist_header *item); 25 extern int LinkList_ListLength(linklist_header *anchor); 26 extern void LinkList_Unlink(linklist_header *anchor, linklist_header *item); 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 30 31 32 34 35 36 3 4 5 6 7 8 9 11 12 14 typedef unsigned (*event_handler) (event_pollblock *poll_block, void *reference); 15 16 17 18 19 20 21 22 0 && ! 1 23 23 24 25 26 27 28 29 extern event_pollmask event_mask; 30 extern int event_taskhandle; 31 extern unsigned int event_wimpversion; 32 extern char event_taskname[40]; 33 extern event_pollblock event_lastevent; 34 35 extern unsigned Event_Claim(event_type eventtype, 36 window_handle window, icon_handle icon, 37 event_handler handler, void *reference); 38 extern unsigned Event_Release(event_type event, 39 window_handle window, icon_handle icon, 40 event_handler handler, void *reference); 41 extern void Event_ReleaseWindow(window_handle window); 42 extern void Event_Process(event_pollblock *event); 43 extern void Event_Poll(void); 44 extern void Event_Initialise(char *taskname); 45 extern void Event_Initialise3(char *taskname, int version, int *messages); 46 extern void Event_CloseDown(void); 47 typedef unsigned (*event_claimorreleasefn)( 48 event_type eventtype, 49 window_handle window, 50 icon_handle icon, 51 event_handler handler, 52 void *reference 53 ); 54 55 56 57 58 38 39 40 41 42 43 typedef struct 44 { 45 linklist_header header; 46 event_type eventtype; 47 event_handler handler; 48 void *reference; 49 } event_claimrecord; 50 51 typedef char event_class; 52 53 54 55 56 57 typedef struct 58 { 59 linklist_header header; 60 icon_handle icon; 61 linklist_header claimlist; 62 } event_iconrecord; 63 64 typedef struct 65 { 66 linklist_header header; 67 window_handle window; 68 linklist_header iconlist; 69 linklist_header claimlist; 70 } event_windowrecord; 71 72 73 39 40 48 48 48 48 48 48 48 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 68 68 68 68 68 68 69 70 event_pollmask event_mask = 0; +++ Serious error: expected '{' 71 event_pollblock event_lastevent; 72 task_handle event_taskhandle = 0; 73 unsigned int event_wimpversion = 0; 74 75 76 77 78 79 80 81 82 83 84 85 86 87 static short usagecounts[ 20 ]= { 88 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 89 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 90 }; 91 92 93 94 95 98 98 98 99 static event_class eventclass [ 20 ] = 100 { 101 3 , 102 2 , 103 2 , 104 2 , 105 2 , 106 2 , 107 1 , 108 3 , 109 1 , 110 3 , 111 2 , 112 1 , 113 1 , 114 3 , 115 0 , 116 0 , 117 0 , 118 3 , 119 3 , 120 3 121 }; 122 123 static linklist_header catchalls = { 0 , 0 }; 124 125 static linklist_header eventqueues[ 20 ] = 126 { 127 { 0 , 0 }, 128 { 0 , 0 }, 129 { 0 , 0 }, 130 { 0 , 0 }, 131 { 0 , 0 }, 132 { 0 , 0 }, 133 { 0 , 0 }, 134 { 0 , 0 }, 135 { 0 , 0 }, 136 { 0 , 0 }, 137 { 0 , 0 }, 138 { 0 , 0 }, 139 { 0 , 0 }, 140 { 0 , 0 }, 141 { 0 , 0 }, 142 { 0 , 0 }, 143 { 0 , 0 }, 144 { 0 , 0 }, 145 { 0 , 0 }, 146 { 0 , 0 } 147 }; 148 149 150 static linklist_header window_anchor = { 0 , 0 }; 151 static void *currentscan = 0 ; 152 153 154 155 156 157 static unsigned DispatchIconEvents(event_pollblock *event, void *reference); 158 static unsigned DispatchWindowEvents(event_pollblock *event, void *reference); 159 static unsigned DispatchMiscEvents(event_pollblock *event, void *reference); 160 161 static event_handler event_handlers[ 20 ] = { 162 DispatchMiscEvents, 163 DispatchWindowEvents, 164 DispatchWindowEvents, 165 DispatchWindowEvents, 166 DispatchWindowEvents, 167 DispatchWindowEvents, 168 DispatchIconEvents, 169 DispatchMiscEvents, 170 DispatchIconEvents, 171 DispatchMiscEvents, 172 DispatchWindowEvents, 173 DispatchIconEvents, 174 DispatchIconEvents, 175 0 , 176 0 , 177 0 , 178 0 , 179 DispatchMiscEvents, 180 DispatchMiscEvents, 181 DispatchMiscEvents 182 }; 183 184 185 186 static const char event_masks[ 20 ] = { 187 1 , 188 0 , 189 0 , 190 0 , 191 1 , 192 1 , 193 0 , 194 0 , 195 0 , 196 0 , 197 0 , 198 1 , 199 1 , 200 1 , 201 0 , 202 0 , 203 0 , 204 0 , 205 1 , 206 1 207 }; 208 209 210 212 212 213 214 215 216 217 218 static void IncrementUsage(event_type event) 219 { 220 if ((usagecounts[event])++ == 0) 221 { 222 event_mask.value &= ~(1 << event); 223 224 225 if (event == event_NONZEROPOLLWORD) 226 event_mask.data.r3ispollwordptr = 1 ; 227 } 228 } 229 230 231 232 static void DecrementUsage(event_type event) 233 { 234 if (--(usagecounts[event]) == 0) 235 { 236 if (event_masks[event]) 237 event_mask.value |= 1 << event; 238 239 240 if (event == event_NONZEROPOLLWORD) 241 event_mask.data.r3ispollwordptr = 0 ; 242 } 243 } 244 245 246 247 static event_iconrecord *CreateIconRecord(event_windowrecord *windowrecord, 248 icon_handle icon) 249 { 250 event_iconrecord *current; 251 252 current = malloc(sizeof(event_iconrecord)); 253 if (current == 0 ) 254 Error_ReportInternal( 1 +0 , "Can't allocate memory for an icon record" ); 255 else 256 { 257 current->icon = icon; 258 { ( &(current->claimlist) )->next = 0 ; ( &(current->claimlist) )->previous = 0 ; } ; 259 LinkList_AddToTail(&(windowrecord->iconlist), &(current->header)); 260 } 261 262 return(current); 263 } 264 265 266 267 static event_windowrecord *CreateWindowRecord(window_handle window) 268 { 269 event_windowrecord *current; 270 271 current = malloc(sizeof(event_windowrecord)); 272 if (current == 0 ) 273 Error_ReportInternal( 1 +1 , "Can't allocate memory for a window record" ); 274 else 275 { 276 current->window = window; 277 { ( &(current->iconlist) )->next = 0 ; ( &(current->iconlist) )->previous = 0 ; } ; 278 { ( &(current->claimlist) )->next = 0 ; ( &(current->claimlist) )->previous = 0 ; } ; 279 LinkList_AddToTail(&window_anchor, &(current->header)); 280 } 281 return(current); 282 } 283 284 285 286 static event_iconrecord *FindIcon(event_windowrecord *windowrecord, 287 icon_handle icon) 288 { 289 event_iconrecord *current; 290 291 current = ((void *)( &(windowrecord->iconlist) )->next) ; 292 while (current != 0 ) 293 { 294 if (current->icon == icon) 295 break; 296 current = ((void *) ((linklist_header *)( &(current->header) ))->next) ; 297 } 298 return(current); 299 } 300 301 302 303 static event_windowrecord *FindWindow(window_handle window) 304 { 305 event_windowrecord *current; 306 307 current = ((void *)( &window_anchor )->next) ; 308 while (current != 0 ) 309 { 310 if (current->window == window) 311 break; 312 current = ((void *) ((linklist_header *)( &(current->header) ))->next) ; 313 } 314 315 return(current); 316 } 317 318 319 320 extern unsigned Event_Claim(event_type eventtype, 321 window_handle window, icon_handle icon, 322 event_handler handler, void *reference) 323 { 324 event_claimrecord *record; 325 event_iconrecord *iconrecord; 326 event_windowrecord *windowrecord; 327 int index; 328 unsigned result; 329 330 result = 0 ; 331 if ((eventtype == event_ANY) || 332 ((eventtype >= 0) && (eventtype < 20 ) && 333 (eventclass[eventtype] != 0 ))) 334 { 335 record = malloc(sizeof(event_claimrecord)); 336 if (record == 0 ) 337 { 338 Error_ReportInternal( 1 +2 , "Can't allocate memory to record an event claim" ); 339 return( 1 ); 340 } 341 342 record->eventtype = eventtype; 343 record->handler = handler; 344 record->reference = reference; 345 346 if (window == event_ANY) 347 { 348 if (eventtype == event_ANY) 349 { 350 351 LinkList_AddToHead(&catchalls, &(record->header)); 352 result = 1 ; 353 354 for (index = 1; index < 20 ; index++) 355 if (eventclass[index] != 0 ) 356 IncrementUsage( (event_type) index); 357 } 358 else 359 { 360 361 LinkList_AddToHead(&(eventqueues[eventtype]), &(record->header)); 362 result = 1 ; 363 364 IncrementUsage(eventtype); 365 } 366 } 367 else 368 { 369 370 windowrecord = FindWindow(window); 371 if (windowrecord == 0 ) 372 windowrecord = CreateWindowRecord(window); 373 374 if (windowrecord != 0 ) 375 { 376 if (icon == event_ANY) 377 { 378 379 if (eventtype == event_ANY) 380 { 381 382 LinkList_AddToTail(&(windowrecord->claimlist), &(record->header)); 383 result = 1 ; 384 385 386 for (index = 1; index < 20 ; index++) 387 if (eventclass[index] != 0 ) 388 IncrementUsage ( (event_type) index); 389 } 390 else 391 { 392 393 LinkList_AddToHead(&(windowrecord->claimlist), &(record->header)); 394 result = 1 ; 395 396 IncrementUsage(eventtype); 397 } 398 399 } 400 else 401 { 402 403 iconrecord = FindIcon(windowrecord, icon); 404 if (iconrecord == 0 ) 405 iconrecord = CreateIconRecord(windowrecord, icon); 406 407 if (iconrecord != 0 ) 408 { 409 if (eventtype == event_ANY) 410 { 411 412 LinkList_AddToTail(&(iconrecord->claimlist),&(record->header)); 413 result = 1 ; 414 415 416 for (index = 1; index < 20 ; index++) 417 if (eventclass[index] != 0 ) 418 IncrementUsage( (event_type) index); 419 } 420 else 421 { 422 423 LinkList_AddToHead(&(iconrecord->claimlist), &(record->header)); 424 result = 1 ; 425 426 IncrementUsage(eventtype); 427 } 428 } 429 } 430 } 431 } 432 if (result == 0 ) 433 free (record); 434 } 435 else 436 Error_ReportInternal( 1 +3 , "Attempt to claim invalid event type" ); 437 438 return(result); 439 } 440 441 442 443 static void LoseClaim(linklist_header *listheader, 444 event_claimrecord *claimrecord) 445 { 446 int index; 447 448 if (claimrecord->eventtype == event_ANY) 449 { 450 451 for (index = 1; index < 20 ; index++) 452 if (eventclass[index] != 0 ) 453 DecrementUsage( (event_type) index); 454 } 455 else 456 DecrementUsage(claimrecord->eventtype); 457 458 if (claimrecord == currentscan) 459 currentscan = 0 ; 460 461 462 LinkList_Unlink(listheader, &(claimrecord->header)); 463 464 free(claimrecord); 465 } 466 467 468 469 static unsigned RemoveClaim(linklist_header *header, 470 event_type eventtype, 471 event_handler handler, void *reference, 472 int *lastone) 473 476 476 476 477 { 478 event_claimrecord *claimrecord; 479 unsigned result; 480 481 result = 0 ; 482 claimrecord = ((void *)( header )->next) ; 483 484 while (claimrecord != 0 ) 485 { 486 if ((claimrecord->eventtype == eventtype) && 487 (claimrecord->handler == handler) && 488 (claimrecord->reference == reference)) 489 { 490 LoseClaim(header, claimrecord); 491 result = 1 ; 492 break; 493 } 494 495 claimrecord = ((void *) ((linklist_header *)( &(claimrecord->header) ))->next) ; 496 } 497 498 if ((result) && (lastone != 0 )) 499 *lastone = ( ((void *)( header )->next) == 0 ); 500 501 return(result); 502 } 503 504 505 506 static void LoseIcon(linklist_header *list, event_iconrecord *iconrecord) 507 { 508 event_claimrecord *claimrecord; 509 510 while ((claimrecord = ((void *)( &(iconrecord->claimlist) )->next) ) != 0 ) 511 LoseClaim(&(iconrecord->claimlist), claimrecord); 512 513 LinkList_Unlink(list, &(iconrecord->header)); 514 free(iconrecord); 515 } 516 517 518 519 static void LoseWindow(event_windowrecord *windowrecord) 520 { 521 LinkList_Unlink(&window_anchor, &(windowrecord->header)); 522 free(windowrecord); 523 } 524 525 526 527 extern unsigned Event_Release(event_type event, 528 window_handle window, icon_handle icon, 529 event_handler handler, void *reference) 530 { 531 event_windowrecord *windowrecord; 532 event_iconrecord *iconrecord; 533 int lastone; 534 unsigned result; 535 536 result = 0 ; 537 538 if (window == event_ANY) 539 { 540 if (event == event_ANY) 541 result = RemoveClaim(&catchalls, event, handler, reference, 0 ); 542 else 543 result = RemoveClaim (&(eventqueues[event]), 544 event, handler, reference, 0 ); 545 } 546 else 547 { 548 windowrecord = FindWindow(window); 549 if (windowrecord != 0 ) 550 { 551 if (icon == event_ANY) 552 result = RemoveClaim(&(windowrecord->claimlist), 553 event, handler, reference, 0 ); 554 else 555 { 556 iconrecord = FindIcon(windowrecord, icon); 557 if (iconrecord != 0 ) 558 { 559 if (RemoveClaim(&(iconrecord->claimlist), 560 event, handler, reference, &lastone)) 561 { 562 result = 1 ; 563 if (lastone) 564 LoseIcon(&(windowrecord->iconlist), iconrecord); 565 } 566 } 567 } 568 569 if (result) 570 { 571 if (( ((void *)( &(windowrecord->iconlist) )->next) == 0 ) && 572 ( ((void *)( &(windowrecord->claimlist) )->next) == 0 )) 573 LoseWindow(windowrecord); 574 } 575 } 576 } 577 578 if (!result) 579 Error_ReportInternal( 1 +4 , "Can't trace event claim" ); 580 581 return (result) ; 582 } 583 584 585 586 extern void Event_ReleaseWindow(window_handle window) 587 { 588 event_claimrecord *claimrecord; 589 event_iconrecord *iconrecord; 590 event_windowrecord *windowrecord; 591 592 windowrecord = FindWindow(window); 593 if (windowrecord != 0 ) 594 { 595 while ((claimrecord = ((void *)( &(windowrecord->claimlist) )->next) ) 596 != 0 ) 597 LoseClaim(&(windowrecord->claimlist), claimrecord) ; 598 599 while ((iconrecord = ((void *)( &(windowrecord->iconlist) )->next) ) 600 != 0 ) 601 LoseIcon(&(windowrecord->iconlist), iconrecord); 602 603 LoseWindow(windowrecord); 604 } 605 } 606 607 608 609 611 611 612 613 static unsigned ScanMiscQueue(linklist_header *queue, event_pollblock *event) 614 { 615 event_claimrecord *current; 616 617 current = ((void *)( queue )->next) ; 618 while (current != 0 ) 619 { 620 currentscan = current; 621 if (current->handler(event, current->reference)) 622 return( 1 ); 623 624 if (currentscan == current) 625 current = ((void *) ((linklist_header *)( &(current->header) ))->next) ; 626 else 627 current = ((void *)( queue )->next) ; 628 } 629 return( 0 ); 630 } 631 632 633 634 static unsigned DispatchMiscEvents(event_pollblock *event, void *reference) 635 639 639 639 639 640 { 641 unsigned dummy; 642 linklist_header *queue; 643 644 (( reference ) = ( reference )) ; 645 646 queue = &eventqueues[event->type]; 647 dummy = ScanMiscQueue(queue, event); 648 649 if (!dummy) 650 dummy = ScanMiscQueue(&catchalls, event); 651 652 653 if (!dummy) 654 if (((event->type == event_USERMESSAGE) || 655 (event->type == event_USERMESSAGERECORDED)) && 656 (event->data.message.header.action == message_QUIT)) 657 exit(0); 658 659 return( 1 ); 660 661 } 662 663 664 665 static unsigned ScanWindowQueue(linklist_header *queue, event_pollblock *event) 666 { 667 event_claimrecord *current; 668 669 current = ((void *)( queue )->next) ; 670 while (current != 0 ) 671 { 672 currentscan = current ; 673 if ((current->eventtype == event->type) || 674 (current->eventtype == event_ANY)) 675 if (current->handler(event, current->reference)) 676 return( 1 ); 677 678 if (currentscan == current) 679 current = ((void *) ((linklist_header *)( &(current->header) ))->next) ; 680 else 681 current = ((void *)( queue )->next) ; 682 } 683 return( 0 ); 684 } 685 686 687 688 static unsigned DispatchIconEvents(event_pollblock *event, void *reference) 689 { 690 icon_handle icon; 691 event_iconrecord *iconrecord; 692 window_handle window; 693 event_windowrecord *windowrecord; 694 695 (( reference ) = ( reference )) ; 696 697 if (event->type == event_CLICK) 698 window = event->data.mouse.window; 699 else 700 window = event->data.openblock.window; 701 702 windowrecord = FindWindow(window); 703 if (windowrecord != 0 ) 704 { 705 switch (event->type) 706 { 707 case event_CLICK: 708 icon = event->data.mouse.icon; 709 break; 710 711 case event_KEY: 712 icon = event->data.key.caret.icon; 713 break; 714 715 case event_LOSECARET: 716 case event_GAINCARET: 717 icon = event->data.caret.icon; 718 break; 719 720 default: 721 icon = -1; 722 break; 723 } 724 725 if (icon != -1) 726 { 727 iconrecord = FindIcon(windowrecord, icon); 728 if (iconrecord != 0 ) 729 if (ScanWindowQueue(&(iconrecord->claimlist), event)) 730 return( 1 ); 731 } 732 733 if (ScanWindowQueue(&(windowrecord->claimlist), event)) 734 return( 1 ); 735 } 736 737 739 739 740 741 return(DispatchMiscEvents(event, 0 )); 742 } 743 744 745 746 static unsigned DispatchWindowEvents(event_pollblock *event, void *reference) 747 { 748 window_handle window; 749 event_windowrecord *windowrecord; 750 751 (( reference ) = ( reference )) ; 752 753 window = event->data.openblock.window; 754 windowrecord = FindWindow(window); 755 756 if (windowrecord != 0 ) 757 if (ScanWindowQueue(&(windowrecord->claimlist), event)) 758 return( 1 ); 759 760 762 762 763 764 return(DispatchMiscEvents(event, 0 )); 765 } 766 767 768 static void Event__ExitFunction( void) 769 770 771 772 773 { 774 if (event_taskhandle != 0) 775 Wimp_CloseDown(event_taskhandle); 776 } 777 778 779 780 781 783 783 784 785 extern void Event_Initialise(char *taskname) 786 { 787 Event_Initialise3(taskname, 200, 0 ); 788 } 789 790 791 792 extern void Event_Initialise3(char *taskname, int version, int *messages) 793 { 794 int index; 795 796 atexit( Event__ExitFunction ); 797 798 for (index = 0; index < 20 ; index++) 799 { 800 if (event_masks[index]) 801 event_mask.value |= 1 << index; 802 } 803 804 if (version >= 300) 805 { 806 eventclass[event_NONZEROPOLLWORD] = 3 ; 807 event_handlers[event_NONZEROPOLLWORD] = DispatchMiscEvents; 808 } 809 810 event_wimpversion = version; 811 812 813 Error_CheckFatal(Wimp_Initialise(&event_wimpversion, 814 taskname, &event_taskhandle, messages)); 815 816 817 strncpy(event_taskname, taskname, 39); 818 819 event_taskname[39] = 0; 820 } 821 822 823 extern void Event_Process(event_pollblock *event) 824 { 825 event_handler handler; 826 827 handler = (event_handler) (event_handlers[event->type]); 828 handler(event, 0 ); 829 } 830 831 832 extern void Event_Poll(void) 833 { 834 Wimp_Poll3( event_mask , &event_lastevent , 0) ; 835 Event_Process(&event_lastevent); 836 } 837 838 839 extern void Event_CloseDown(void) 840 { 841 exit(0); 842 } 843