Back to index

lightning-sunbird  0.9+nobinonly
Classes | Enumerations | Functions | Variables
EventFilter.cpp File Reference
#include "EventFilter.h"
#include <MixedMode.h>
#include <Memory.h>
#include <LowMem.h>
#include <Menus.h>
#include <Patches.h>
#include <Traps.h>

Go to the source code of this file.

Classes

struct  Patch

Enumerations

enum  { uppWaitNextEventProcInfo, uppMenuSelectProcInfo }
enum  { kIsToolboxTrap = (1 << 11) }

Functions

static pascal Boolean NewWaitNextEvent (EventMask eventMask, EventRecord *event, UInt32 sleep, RgnHandle mouseRgn)
static pascal long NewMenuSelect (Point where)
TrapType getTrapType (UInt16 trapNum)
static UniversalProcPtr SwapTrapAddress (UInt16 trapNum, UniversalProcPtr newTrapAddress)
OSStatus InstallEventFilters (EventFilterProcPtr eventFilter, MenuFilterProcPtr menuFilter)
OSStatus RemoveEventFilters ()

Variables

static Patch WaitNextEventPatch
static Patch MenuSelectPatch
static EventFilterProcPtr theEventFilter
static MenuFilterProcPtr theMenuFilter

Enumeration Type Documentation

anonymous enum
Enumerator:
uppWaitNextEventProcInfo 
uppMenuSelectProcInfo 

Definition at line 57 of file EventFilter.cpp.

     {
       uppWaitNextEventProcInfo = kPascalStackBased
              | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(EventMask)))
              | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(EventRecord*)))
              | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(UInt32)))
              | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(RgnHandle))),
       uppMenuSelectProcInfo = kPascalStackBased
              | RESULT_SIZE(SIZE_CODE(sizeof(long)))
              | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Point)))
};
anonymous enum
Enumerator:
kIsToolboxTrap 

Definition at line 72 of file EventFilter.cpp.

     {
       kIsToolboxTrap = (1 << 11)
};

Function Documentation

TrapType getTrapType ( UInt16  trapNum) [inline]

Definition at line 76 of file EventFilter.cpp.

{
       return ((trapNum & kIsToolboxTrap) != 0 ? kToolboxTrapType : kOSTrapType);
}

Definition at line 113 of file EventFilter.cpp.

{
       if (theEventFilter == NULL) {
              theEventFilter = eventFilter;
              theMenuFilter = menuFilter;

              // Patch WNE, which will be used to filter events.
              WaitNextEventPatch.Install();
              
              // Patch MenuSelect, which will be used to filter menu selections.
              MenuSelectPatch.Install();

              return noErr;
       }
       return paramErr;
}

Here is the call graph for this function:

static pascal long NewMenuSelect ( Point  where) [static]

Definition at line 164 of file EventFilter.cpp.

{
       long menuSelection = CALL_ONE_PARAMETER_UPP(MenuSelectPatch.original, uppMenuSelectProcInfo, where);
       if (menuSelection != 0) {
              Boolean filteredEvent = theMenuFilter(menuSelection);
              if (filteredEvent) {
                     // consume the menu selection by zeroing it out.
                     menuSelection = 0;
              }
       }
       return menuSelection;
}

Here is the call graph for this function:

static pascal Boolean NewWaitNextEvent ( EventMask  eventMask,
EventRecord *  event,
UInt32  sleep,
RgnHandle  mouseRgn 
) [static]

Definition at line 144 of file EventFilter.cpp.

{
       Boolean gotEvent = CALL_FOUR_PARAMETER_UPP(WaitNextEventPatch.original, uppWaitNextEventProcInfo, eventMask, event, sleep, mouseRgn);
       if (true) {
              // prevent recursive calls to the filter.
              static Boolean inFilter = false;
              if (! inFilter) {
                     inFilter = true;
                     Boolean filteredEvent = theEventFilter(event);
                     if (filteredEvent) {
                            // consume the event by making it a nullEvent.
                            event->what = nullEvent;
                            gotEvent = false;
                     }
                     inFilter = false;
              }
       }
       return gotEvent;
}

Here is the call graph for this function:

Definition at line 130 of file EventFilter.cpp.

{
       if (theEventFilter != NULL) {
              WaitNextEventPatch.Remove();
              MenuSelectPatch.Remove();
              
              theEventFilter = NULL;
              theMenuFilter = NULL;
              
              return noErr;
       }
       return paramErr;
}

Here is the call graph for this function:

static UniversalProcPtr SwapTrapAddress ( UInt16  trapNum,
UniversalProcPtr  newTrapAddress 
) [static]

Definition at line 81 of file EventFilter.cpp.

{
       TrapType type = getTrapType(trapNum);
       UniversalProcPtr oldTrapAddress = NGetTrapAddress(trapNum, type);
       NSetTrapAddress(newTrapAddress, trapNum, type);
       return oldTrapAddress;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
 {
       _MenuSelect,
       BUILD_ROUTINE_DESCRIPTOR(uppMenuSelectProcInfo, NewMenuSelect),
       NULL
}

Definition at line 104 of file EventFilter.cpp.

Definition at line 110 of file EventFilter.cpp.

Definition at line 111 of file EventFilter.cpp.

Initial value:
 {
       _WaitNextEvent,
       BUILD_ROUTINE_DESCRIPTOR(uppWaitNextEventProcInfo, NewWaitNextEvent),
       NULL
}

Definition at line 98 of file EventFilter.cpp.