events 23.5 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/* Copyright 1996 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/* Title:   events.c
 * Purpose: filters registered with the Toolbox.  Events are delivered here.
 * Author:  IDJ
 * History: 7-Oct-93: IDJ: created
19
 *         16-Mar-99: EPW: Now return the component id in Wimp_KeyPressed's
Neil Turton's avatar
Neil Turton committed
20 21 22 23 24 25 26 27 28 29 30
 *
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "kernel.h"
#include "swis.h"


31 32 33 34 35 36 37 38 39 40
#include "tboxlibint/const.h"
#include "tboxlibint/macros.h"
#include "tboxlibint/debug.h"
#include "tboxlibint/mem.h"
#include "tboxlibint/string32.h"
#include "tboxlibint/messages.h"
#include "tboxlibint/style.h"

#include "tboxlibint/objects/toolbox.h"
#include "tboxlibint/objects/window.h"
Neil Turton's avatar
Neil Turton committed
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

#include "object.h"
#include "events.h"
#include "task.h"
#include "gadgets.h"
#include "show.h"
#include "hide.h"
#include "veneers.h"

#include "events.h"



/* NOTE: currently (3-Feb-94) it seems best to express interest in all events which
 * can happen on Wimp windows, and set up the id block to contain the id of this
 * Toolbox Window.
 */


static WindowAboutToBeShownEvent about_to_be_shown_event;
static WindowInternal           *window_about_to_be_shown = NULL;
static void ( *GadgetNeedsPrefilter)(void) = NULL;

extern void postfilter_callback(void);

void gadget_prefilter_state(void (* state)(void))
{
        GadgetNeedsPrefilter=state;
}


static WindowInternal *events__find_window (WindowInternal *w, int window_handle)
{
    while (w != NULL)
    {
        if (w->wimp_window_handle == window_handle)
            break;
        w = w->next;
    }
    return w;
}



static WindowInternal *events__find_window_from_id (WindowInternal *w, ObjectID window_id)
{
    while (w != NULL)
    {
        if (w->id == window_id)
            break;
        w = w->next;
    }
    return w;
}

extern _kernel_oserror *events_send_help(char *help,wimp_PollBlock *poll_block)
{
         wimp_Message     reply;
         int i,m=strlen(help);

         string_copy_chk (reply.data.help_reply.text,help, wimp_MAX_MSG_DATA_SIZE);
         reply.hdr.your_ref = poll_block->msg.hdr.my_ref;
         reply.hdr.action   = wimp_MHELP_REPLY;
         reply.hdr.size     = (m + 4 +sizeof(wimp_MsgHdr)) & ~3;
         if (reply.hdr.size>256) reply.hdr.size = 256;

         for (i=m;(i<(m+5)) && (i<wimp_MAX_MSG_DATA_SIZE);i++)
            reply.data.help_reply.text[i] =0;
         return wimp_send_message (wimp_ESEND, &reply,poll_block->msg.hdr.task_handle,0,0);
}

static _kernel_oserror *events__open_window (WindowInternal *w, wimp_OpenWindow *open_block,int *st)
{
    _kernel_oserror *e = NULL;

    if (w->flags & Window_AutoOpen)
    {

Kevin Bracey's avatar
Kevin Bracey committed
119 120 121 122
        if (w->panes)
           e = show_with_panes(w, (wimp_NestedOpenWindow *) open_block, 0, 0, 0);
        else
           e = wimp_open_window(open_block);
Neil Turton's avatar
Neil Turton committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141

        *st =-1;    /* claim event */
    }
    else *st =1;

    return e;
}



static _kernel_oserror *events__close_window (WindowInternal *w, wimp_CloseWindowRequest *close,int *st)
{
    _kernel_oserror *e = NULL;

    if (w->flags & Window_AutoClose)
    {
        e = wimp_close_window (&close->window_handle);

        if (!e) {
142
           if (w->show_balance <= 0) w->show_balance = 1;
Neil Turton's avatar
Neil Turton committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
           _hide_raise_hidden(w);
           close_panes(w);
        }
        *st =-1;
    }
    else *st =1;
    return e;
}


static char events__pointer_ttab[] = "\0\1\2\3\0\1\2\3\0\1\2\3\0\1\2\3";


_kernel_oserror *events_pointer_over_window (WindowInternal *w)
{
    _kernel_oserror *e = NULL;
    _kernel_swi_regs regs;
Kevin Bracey's avatar
Kevin Bracey committed
160
    int oldptr;
Neil Turton's avatar
Neil Turton committed
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

    /*
     * if the window has a pointer shape defined, then we need to set the
     * RISC OS shape 2 pointer to this shape, and then install this as the
     * current pointer shape (OS_Byte 106).  First we try the client's
     * sprite area, then the Wimp sprite pool.
     */

    DEBUG debug_output ("pointer", "Ptr entering window\n");

    if (w->pointer_shape != NULL)
    {
        /*
         * get the client's sprite area pointer
         */

        regs.r[0] = Toolbox_GetSysInfo_SpriteArea;
        if ((e = _kernel_swi (Toolbox_GetSysInfo, &regs, &regs)) != NULL)
            goto end;


        /*
         * try to set pointer shape 2, from client's sprite area
         */

        DEBUG debug_output ("pointer", "Ptr shape %s\n", w->pointer_shape);

        regs.r[1] = regs.r[0];                 /* user sprite area */
        regs.r[0] = 36 + 256;                  /* set pointer shape (from user area) */
        regs.r[2] = (int)w->pointer_shape;     /* sprite name */
        regs.r[3] = 2;                         /* shape 2 */
        regs.r[4] = w->pointer_x_hot;          /* pointer x hot spot */
        regs.r[5] = w->pointer_y_hot;          /* pointer y hot spot */
        regs.r[6] = 0;                         /* scale for mode */
        regs.r[7] = (int)events__pointer_ttab; /* fixed translation table */

197
        if ((regs.r[1] == 1) || (_kernel_swi (OS_SpriteOp, &regs, &regs) != NULL))
Neil Turton's avatar
Neil Turton committed
198 199 200 201 202 203 204 205 206 207 208 209 210
        {
            DEBUG debug_output ("pointer", "Try wimp sprite pool (for %s)\n", w->pointer_shape);

            /* regs have been preserved (except R0) */
            regs.r[0] = 36;                  /* try to set pointer shape again */

            if ((e = _kernel_swi (Wimp_SpriteOp, &regs, &regs)) != NULL)
                goto end;
        }


        /*
         * set pointer shape 2 (the one we've just defined)
Kevin Bracey's avatar
Kevin Bracey committed
211
         * If the pointer was previously off, turn it off again
Neil Turton's avatar
Neil Turton committed
212 213
         */

Kevin Bracey's avatar
Kevin Bracey committed
214 215 216
        e = _swix (OS_Byte, _INR(0,1)|_OUT(1), 106, 2, &oldptr);
        if (!e && (oldptr & 0x7f) == 0)
            _swix (OS_Byte, _INR(0,1), 106, oldptr);
Neil Turton's avatar
Neil Turton committed
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
    }

end:
    DEBUG if (e) debug_output ("pointer", "Set pointer failed (%s)\n", e->errmess);

    return e;
}

_kernel_oserror *events_pointer_leaving_window (WindowInternal *w)
{
    _kernel_oserror *e = NULL;

    /*
     * if the window has a pointer defined, then we need to restore the default
     * RISC OS pointer shape (shape 1).
     */

    if (w->pointer_shape != NULL)
235 236 237 238 239 240 241
    {
        int oldptr;

        e = _swix(OS_Byte, _INR(0,1)|_OUT(1), 106, 1, &oldptr);
        if (!e && (oldptr & 0x7f) == 0)
            _swix(OS_Byte, _INR(0,1), 106, oldptr);
    }
Neil Turton's avatar
Neil Turton committed
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

    return e;
}


static int events__user_message (WindowInternal *w, wimp_PollBlock *poll_block, IDBlock *id_block)
{
    return gadgets_user_message (w, poll_block, id_block);
}


static _kernel_oserror *events__toolbox_event (WindowInternal *w, ToolboxEvent *event, IDBlock *id_block)
{
    /*
     * If it's a Window_AboutToBeShown event, then we need to remember the id of the window, so that
     * we can show it in the prefilter for this task (also we remember the values passed in
     * R2 and R3).
     */



    if (event->hdr.event_code == Window_AboutToBeShown)
    {
        window_about_to_be_shown = w;
        about_to_be_shown_event  = *((WindowAboutToBeShownEvent *)event);
    }
    else
        return gadgets_toolbox_event (w, event, id_block);

    return NULL;
}


static _kernel_oserror *events__show_menu (WindowInternal *w, int x, int y)
{
    /*
     * This function shows the Menu attached to a Window in its
     * Style Guide compliant place (offset from pointer)
     * x and y give mouse pointer coords.
     */

    _kernel_swi_regs regs;
    TopLeft          buffer;

    IGNORE(y);

    DEBUG debug_output ("events", "Showing Menu\n");


    /*
     * display menu in Style Guide compliant place
     *
     */

    buffer.x = x - style_MENU_OFFSET;
    buffer.y = y;

    DEBUG debug_output ("events", "Show at (%d,%d)\n", buffer.x, buffer.y);

    regs.r[0] = 0x00000001;         /* transient */
    regs.r[1] = (int)w->menu;
    regs.r[2] = Toolbox_ShowObject_TopLeft;
    regs.r[3] = (int)&buffer;
    regs.r[4] = (int)w->id;
    regs.r[5] = -1;                  /* no component id */

    return _kernel_swi (Toolbox_ShowObject, &regs, &regs);
}


static _kernel_oserror *events__keyboard_shortcut (WindowInternal *w, int key_code, int *claimed)
{
    int ki;
    _kernel_swi_regs regs;
    _kernel_oserror *e;

    for (ki = 0; ki < w->num_keyboard_shortcuts; ki++)
    {
        if (w->keyboard_shortcuts[ki].wimp_key_code == key_code)
        {
            ToolboxEvent event;

            /*
             * raise associated toolbox event if defined
             */

            if (w->keyboard_shortcuts[ki].key_event != 0)
            {
                *claimed = TRUE;

                event.hdr.size = sizeof(ToolboxEventHeader) + sizeof(int);
                event.hdr.event_code = w->keyboard_shortcuts[ki].key_event;
                event.hdr.flags =0;

                regs.r[0] = 0;
                regs.r[1] = (int)w->id;
                regs.r[2] = -1;
                regs.r[3] = (int)&event;
                if ((e = _kernel_swi (Toolbox_RaiseToolboxEvent, &regs, &regs)) != NULL)
                    return e;
            }


            /*
Kevin Bracey's avatar
Kevin Bracey committed
346 347
             * if an object is attached, show it either centred, or in the
             * default place.
Neil Turton's avatar
Neil Turton committed
348 349 350 351 352 353 354 355
             */

            if (w->keyboard_shortcuts[ki].key_show != 0)
            {
                *claimed = TRUE;

                regs.r[0] = (w->keyboard_shortcuts[ki].flags & KeyBoardShortcut_ShowAsTransient)?Toolbox_ShowObject_AsMenu:0;
                regs.r[1] = (int)w->keyboard_shortcuts[ki].key_show;
Kevin Bracey's avatar
Kevin Bracey committed
356 357 358 359 360 361
                if (w->keyboard_shortcuts[ki].flags & KeyBoardShortcut_ShowInCentre)
                    regs.r[2] = Toolbox_ShowObject_Centre;
                else if (w->keyboard_shortcuts[ki].flags & KeyBoardShortcut_ShowAtPointer)
                    regs.r[2] = Toolbox_ShowObject_AtPointer;
                else
                    regs.r[2] = Toolbox_ShowObject_Default;
Neil Turton's avatar
Neil Turton committed
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
                regs.r[3] = 0;
                regs.r[4] = (int)w->id;
                regs.r[5] = -1;

                if ((e = _kernel_swi (Toolbox_ShowObject, &regs, &regs)) != NULL)
                    return e;
            }

            break;
        }
    }

    return NULL;
}



extern _kernel_oserror *events_postfilter (_kernel_swi_regs *r)
{

    /*
     * called from the main Toolbox postfilter, when an event happens which
     * this module has expressed an interest in.
     * R0 = Wimp event reason code
     * R1 ->client's Wimp event block
     * R2 = Task Descriptor of task interested in the event
     * R3 ->6-word "ID block" as passed to Toolbox_Initialise
     *
     */

    /*
     * This function gets a pointer to the task interested in the event in
     * R2 (since this was the value passed to Toolbox_RegisterPostFilter).
     * If the event is dealt with by this module (eg ID block gets updated).
     * then set R0 to non-null before return.
     */

    int event_code              = r->r[0];
    TaskDescriptor  *t          = (TaskDescriptor *)r->r[2];
    IDBlock         *id_block   = (IDBlock *)r->r[3];
    wimp_PollBlock  *poll_block = (wimp_PollBlock *)r->r[1];
    WindowInternal  *w;
    _kernel_oserror *e          = NULL;


    r->r[0] = 0;   /* default is that we haven't updated id block */


    /*
     * for safety if no task decriptor, just return
     */

    if (t == NULL)
        return NULL;


    /*
     * NOTE: for each event, we look to see if it is for one of our windows
     */

    switch (event_code)
    {
        case wimp_EREDRAW:
            if ((w = events__find_window (t->object_list, poll_block->redraw_window_request.window_handle)) == NULL)
                return NULL;

            id_block->self_id = w->id;
            id_block->self_component = -1;

            r->r[0] = 1;  /* updated id block */

            break;


        case wimp_EOPEN:
            if ((w = events__find_window (t->object_list, poll_block->open_window_request.open_block.window_handle)) == NULL)
                return NULL;
            else
            {
                e = events__open_window (w, &poll_block->open_window_request.open_block,&(r->r[0]));

                id_block->self_id = w->id;
                id_block->self_component = -1;

            }
            break;


        case wimp_ECLOSE:
            if ((w = events__find_window (t->object_list, poll_block->close_window_request.window_handle)) == NULL)
                return NULL;
            else
            {
                e = events__close_window (w, &poll_block->close_window_request, &(r->r[0]));

                id_block->self_id = w->id;
                id_block->self_component = -1;

            }
            break;


        case wimp_EPTR_ENTER:
            if ((w = events__find_window (t->object_list, poll_block->pointer_entering_window.window_handle)) == NULL)
                return NULL;
            else
            {
                e = events_pointer_over_window (w);

                id_block->self_id = w->id;
                id_block->self_component = -1;

                r->r[0] = 1;  /* updated id block */
            }
            break;


        case wimp_EPTR_LEAVE:
            if ((w = events__find_window (t->object_list, poll_block->pointer_leaving_window.window_handle)) == NULL)
                return NULL;
            else
            {
                e = events_pointer_leaving_window (w);

                id_block->self_id = w->id;
                id_block->self_component = -1;

                r->r[0] = 1;  /* updated id block */
            }
            break;


        case wimp_EBUT:
            {
                int claimed = FALSE;

                if ((w = events__find_window (t->object_list, poll_block->mouse_click.window_handle)) == NULL)
                    return NULL;

                id_block->self_id = w->id;

                /*
                 * try gadgets first, and if not claimed, deal with it ourselves.
                 * We are only interested in Menu clicks.
                 */

                e = gadgets_mouse_click (w, poll_block, &claimed, id_block);

                if (!claimed) {
                  if ((poll_block->mouse_click.buttons & wimp_MENU_BUTTON) && (w->menu != NULL) && (e == NULL)) {
                    e = events__show_menu (w, poll_block->mouse_click.x, poll_block->mouse_click.y);
                  }
                }
                r->r[0] = 1;  /* updated id block */
            }

            break;

        case wimp_EUSER_DRAG:

                e = gadgets_user_drag(poll_block);
                break;


        case wimp_EKEY:
            {
                /* there are three cases we have to deal with here:
                    - if the key bit in the poll mask was clear (ie. the task wanted
                      key presses, then we must tell the toolbox to claim it (in wimp
                      terms) as otherwise the task will do a Wimp_ProcessKey (as it
                      probably doesn't need it)
                    - if the mask bit was set (ie. the task didn't want key presses)
                      then either:
                        - we use the key and tell the toolbox we've done so.
                        - we do a Wimp_ProcessKey
                 */

                int claimed = FALSE;
                IDBlock blk = * id_block;

                DEBUG debug_output ("events", "Received key %d for task %8X (key mask %d)\n",
                    poll_block->key_pressed.key_code ,t, t->mask & wimp_EMKEY);

                if ((w = events__find_window (t->object_list, poll_block->key_pressed.caret.window_handle)) != NULL)
                    {


                       if (w->num_keyboard_shortcuts > 0) {
                          e = events__keyboard_shortcut (w, poll_block->key_pressed.key_code, &claimed);
                       }
                       if (!claimed && (e == NULL)) {
                          e = gadgets_key_pressed (w, poll_block, &claimed, id_block);
                       }
                    }
556 557
                else
                   return NULL;
Neil Turton's avatar
Neil Turton committed
558 559 560 561 562 563 564

                if ((!claimed) && (t->mask & wimp_EMKEY)) {
                   switch (poll_block->key_pressed.key_code ) {
                      /* only pass on if not a special key */
                    case 13: /* return */
                    case 8: /* delete */
                    case 27: /* escape */
565 566 567 568 569 570
                    case 0x18a: case 0x19a: case 0x1aa: case 0x1ba: /* tab */
                    case 0x18b: case 0x19b: case 0x1ab: case 0x1bb: /* end */
                    case 0x18c: case 0x18d: case 0x18e: case 0x18f: /* arrows */
                    case 0x19c: case 0x19d: case 0x19e: case 0x19f: /* arrows */
                    case 0x1ac: case 0x1ad: case 0x1ae: case 0x1af: /* arrows */
                    case 0x1bc: case 0x1bd: case 0x1be: case 0x1bf: /* arrows */
Neil Turton's avatar
Neil Turton committed
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585

                      break;
                    default:
                      DEBUG debug_output ("events", "Passing on key %d\n",poll_block->key_pressed.key_code);
                      wimp_process_key(poll_block->key_pressed.key_code );
                   }
                }

                if (!(t->mask & wimp_EMKEY)) {
                   if (claimed) {
                     r->r[0] =-1;
                     *id_block = blk;
                   }
                   else {
                     id_block->self_id = w->id;
586
                     /* We now return the component id, if there is one */
587 588 589
                     if ((poll_block->key_pressed.caret.icon_handle >= 0) &&
                         (poll_block->key_pressed.caret.icon_handle <
                                      w->num_icon_mappings))
590 591 592 593 594 595
                         id_block->self_component =
                                 w->icon_mappings[
                                 poll_block->key_pressed.caret.icon_handle]->
                                 gadget_hdr.component_id;
                     else
                         id_block->self_component = -1;
Neil Turton's avatar
Neil Turton committed
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
                     r->r[0] = 1;  /* updated id block */
                   }
                }
            }

            break;


        case wimp_ESCROLL:
            if ((w = events__find_window (t->object_list, poll_block->scroll_request.open_block.window_handle)) == NULL)
                return NULL;

            id_block->self_id = w->id;
            id_block->self_component = -1;

            r->r[0] = 1;  /* updated id block */

            break;


        case wimp_ELOSE_CARET:
            if ((w = events__find_window (t->object_list, poll_block->lose_caret.caret.window_handle)) == NULL)
                return NULL;

            id_block->self_id = w->id;
            id_block->self_component = -1;

            r->r[0] = 1;  /* updated id block */

            break;


        case wimp_EGAIN_CARET:
            if ((w = events__find_window (t->object_list, poll_block->gain_caret.caret.window_handle)) == NULL)
                return NULL;

            id_block->self_id = w->id;
            id_block->self_component = -1;

            r->r[0] = 1;  /* updated id block */

            break;


        case wimp_ESEND:
        case wimp_ESEND_WANT_ACK:
            if (poll_block->msg.hdr.action == wimp_MHELP_REQUEST)
            {
                if ((w = events__find_window (t->object_list, poll_block->msg.data.help_request.window_handle)) == NULL)
                    return NULL;

                /*
                 * try the gadgets first, and if not claimed, send help if we have some.
                 */

                if (gadgets_help_message (w, poll_block, id_block))
                    r->r[0] = 1;
                else
                {
                    if (w->help_message != NULL)
                    {
                        if ((e = events_send_help(w->help_message,poll_block)) != NULL)
                            break;

                    }

                    id_block->self_id = w->id;
                    id_block->self_component = -1;
                    r->r[0] = 1;
                }
            }
            else if(poll_block->msg.hdr.action == wimp_MMENUS_DELETED)
            {
Stewart Brodie's avatar
Stewart Brodie committed
669 670
                  DEBUG debug_output("events", "wimp_MENUS_DELETED (%08x)\n", poll_block->msg.data.words[0]);
                  hide_raise_hidden(poll_block->msg.data.words[0]);
671
                  DEBUG debug_output("events", "about to leave\n");
Neil Turton's avatar
Neil Turton committed
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

            }
            else if(poll_block->msg.hdr.action == wimp_MMENU_WARNING)
            {
                  raise_if_become_hidden();

            }
            else
            {
                w = t->object_list;

                while (w != NULL)
                {
                    if (events__user_message (w, poll_block, id_block) != FALSE)
                        break;
                    w = w->next;
                }

                if (w != NULL)
                    r->r[0] = 1;
            }
            break;


        case wimp_ETOOLBOX_EVENT:
            if ((w = events__find_window_from_id (t->object_list, id_block->self_id)) != NULL)
                 e = events__toolbox_event (w, &poll_block->toolbox_event, id_block);
            else {

                /* event isn't from a window, so could be from menu, in which case need
                   to pass round all windows! YUK */

                w = t->object_list;

                while (w != NULL)
                {
                    e = events__toolbox_event (w, &poll_block->toolbox_event, id_block);
                    w = w->next;
                }

             }

            break;


        default:
            break;
    }

    return e;
}



extern _kernel_oserror *events_prefilter (_kernel_swi_regs *r)
{

    /*
     * called from the main Toolbox prefilter, when Wimp_Poll is called.
     * R0 = mask passed to Wimp_Poll
     * R1 ->client's poll block passed to Wimp_Poll
     * R2 = Task Descriptor.
     *
     */

    /*
     * This function gets a pointer to the current task in
     * R2 (since this was the value passed to Toolbox_RegisterPreFilter).
     * This function can enable additional events by zero-ing bits in
     * r->r[0]
     */

    extern int ReFindFonts;
    _kernel_oserror *e = NULL;
    TaskDescriptor  *t          = (TaskDescriptor *)r->r[2];

    /* has there been a mode change ? */

    if (ReFindFonts) {
       ReFindFonts = 0;

       DEBUG debug_output("fonts","Prefilter, need to look for new fonts\n");

       task_refind_fonts();

    }

    /* remember the mask - needed so that we can decide what to do with key presses */

    t->mask = r->r[0];

    /*
     * Enable most events, 'cos we are interested in them!
     */

    r->r[0] &= ~(wimp_EMREDRAW       |
                 wimp_EMOPEN         |
                 wimp_EMCLOSE        |
                 wimp_EMPTR_LEAVE    |
                 wimp_EMPTR_ENTER    |
                 wimp_EMBUT          |
                 wimp_EMKEY          |
                 wimp_EMUSER_DRAG    |
                 wimp_EMSCROLL       |
                 wimp_EMLOSE_CARET   |
                 wimp_EMGAIN_CARET   |
                 wimp_EMSEND         |
                 wimp_EMSEND_WANT_ACK);
    /*
     * If we have received a warning before showing a Window, then we actually
     * do the show now.
     */

    if (window_about_to_be_shown != NULL)
    {
        e = show_do_the_show (window_about_to_be_shown,
                                   about_to_be_shown_event.hdr.flags,
                                   about_to_be_shown_event.r2,
                                   (void *)&about_to_be_shown_event.r3);

        window_about_to_be_shown = NULL;
    }

    if (GadgetNeedsPrefilter != NULL) (*GadgetNeedsPrefilter)();

    return e;
}