Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Static Private Member Functions | Static Private Attributes
nsMacTSMMessagePump Class Reference

#include <nsMacTSMMessagePump.h>

Collaboration diagram for nsMacTSMMessagePump:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsMacTSMMessagePump ()
 ~nsMacTSMMessagePump ()

Static Public Member Functions

static nsMacTSMMessagePumpGetSingleton ()
static void Shutdown ()

Static Private Member Functions

static pascal OSErr PositionToOffsetHandler (const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)
static pascal OSErr OffsetToPositionHandler (const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)
static pascal OSErr UnicodeUpdateHandler (const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)
static pascal OSErr UnicodeNotFromInputMethodHandler (const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)
static pascal OSErr UnicodeGetSelectedTextHandler (const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)

Static Private Attributes

static AEEventHandlerUPP mPos2OffsetUPP = NULL
static AEEventHandlerUPP mOffset2PosUPP = NULL
static AEEventHandlerUPP mUpdateUPP = NULL
static AEEventHandlerUPP mKeyboardUPP = NULL
static AEEventHandlerUPP mGetSelectedTextUPP = NULL
static nsMacTSMMessagePumpgSingleton = nsnull

Detailed Description

Definition at line 53 of file nsMacTSMMessagePump.h.


Constructor & Destructor Documentation

Definition at line 66 of file nsMacTSMMessagePump.cpp.

{
       OSErr  err;

       mPos2OffsetUPP = NewAEEventHandlerUPP(nsMacTSMMessagePump::PositionToOffsetHandler);
       NS_ASSERTION(mPos2OffsetUPP!=NULL, "nsMacTSMMessagePump::InstallTSMAEHandlers: NewAEEventHandlerUPP[Pos2Pffset] failed");

       mOffset2PosUPP = NewAEEventHandlerUPP(nsMacTSMMessagePump::OffsetToPositionHandler);
       NS_ASSERTION(mPos2OffsetUPP!=NULL, "nsMacTSMMessagePump::InstallTSMAEHandlers: NewAEEventHandlerUPP[Pos2Pffset] failed");

  mUpdateUPP = NewAEEventHandlerUPP(nsMacTSMMessagePump::UnicodeUpdateHandler);
  NS_ASSERTION(mPos2OffsetUPP!=NULL, "nsMacTSMMessagePump::InstallTSMAEHandlers: NewAEEventHandlerUPP[Pos2Pffset] failed");

  err = AEInstallEventHandler(kTextServiceClass, kPos2Offset, mPos2OffsetUPP, (long)this, false);
  NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::InstallTSMAEHandlers: AEInstallEventHandler[Pos2Offset] failed");

  err = AEInstallEventHandler(kTextServiceClass, kOffset2Pos, mOffset2PosUPP, (long)this, false);
  NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::InstallTSMAEHandlers: AEInstallEventHandler[Offset2Pos] failed");

  err = AEInstallEventHandler(kTextServiceClass, kUpdateActiveInputArea, mUpdateUPP, (long)this, false);
  NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::InstallTSMAEHandlers: AEInstallEventHandler[Update] failed");

  mKeyboardUPP = NewAEEventHandlerUPP(nsMacTSMMessagePump::UnicodeNotFromInputMethodHandler);
  NS_ASSERTION(mKeyboardUPP!=NULL, "nsMacTSMMessagePump::InstallTSMAEHandlers: NewAEEventHandlerUPP[FromInputMethod] failed");

  err = AEInstallEventHandler(kTextServiceClass, kUnicodeNotFromInputMethod, mKeyboardUPP, (long)this, false);
  NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::InstallTSMAEHandlers: AEInstallEventHandler[FromInputMethod] failed");

  mGetSelectedTextUPP = NewAEEventHandlerUPP(nsMacTSMMessagePump::UnicodeGetSelectedTextHandler);
  NS_ASSERTION(mGetSelectedTextUPP!=NULL, "nsMacTSMMessagePump::InstallTSMAEHandlers: NewAEEventHandlerUPP[GetSelectedText] failed");

  err = AEInstallEventHandler(kTextServiceClass, kGetSelectedText, mGetSelectedTextUPP, (long)this, false);
  NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::InstallTSMAEHandlers: AEInstallEventHandler[GetSelectedText] failed");

}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 102 of file nsMacTSMMessagePump.cpp.

{
       OSErr  err;
       
       err = AERemoveEventHandler(kTextServiceClass, kPos2Offset, mPos2OffsetUPP, false);
       NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::RemoveTSMAEHandlers: AERemoveEventHandler[Pos2Offset] failed");

       err = AERemoveEventHandler(kTextServiceClass, kOffset2Pos, mOffset2PosUPP, false);
       NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::RemoveTSMAEHandlers: AERemoveEventHandler[Offset2Pos] failed");

       err = AERemoveEventHandler(kTextServiceClass, kUpdateActiveInputArea, mUpdateUPP, false);
       NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::RemoveTSMAEHandlers: AERemoveEventHandler[Update] failed");

       ::DisposeAEEventHandlerUPP(mPos2OffsetUPP);
       ::DisposeAEEventHandlerUPP(mOffset2PosUPP);
       ::DisposeAEEventHandlerUPP(mUpdateUPP);

  err = AERemoveEventHandler(kTextServiceClass, kUnicodeNotFromInputMethod, mKeyboardUPP, false);
  NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::RemoveTSMAEHandlers: AERemoveEventHandler[FromInputMethod] failed");
  ::DisposeAEEventHandlerUPP(mKeyboardUPP);

  err = AERemoveEventHandler(kTextServiceClass, kGetSelectedText, mGetSelectedTextUPP, false);
  NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::RemoveTSMAEHandlers: AERemoveEventHandler[GetSelectedText] failed");
  ::DisposeAEEventHandlerUPP(mGetSelectedTextUPP);

}

Member Function Documentation

Definition at line 132 of file nsMacTSMMessagePump.cpp.

{
       if (nsnull == gSingleton)
       {
              gSingleton = new nsMacTSMMessagePump();
              NS_ASSERTION(gSingleton!=NULL, "nsMacTSMMessagePump::GetSingleton: Unable to create TSM Message Pump.");
       }
       return gSingleton;
}

Here is the call graph for this function:

Here is the caller graph for this function:

pascal OSErr nsMacTSMMessagePump::OffsetToPositionHandler ( const AppleEvent *  theAppleEvent,
AppleEvent *  reply,
long  handlerRefcon 
) [static, private]

Definition at line 205 of file nsMacTSMMessagePump.cpp.

{
       OSErr                       err;
       DescType                    returnedType;
       nsMacEventHandler*   eventHandler; 
       Size                        actualSize;
       Point                       thePoint;
       long                        offset;
       nsresult                    res;

       //
       // Extract the nsMacEvenbtHandler for this TSMDocument.  It's stored as the refcon.
       //
       err = AEGetParamPtr(theAppleEvent, keyAETSMDocumentRefcon, typeLongInteger, &returnedType,
                                          &eventHandler, sizeof(eventHandler), &actualSize);
       NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::OffsetToPositionHandler: AEGetParamPtr[TSMRefcon] failed.");
       if (err!=noErr) 
              return err;
       
       //
       // Extract the Offset parameter
       //
       err = AEGetParamPtr(theAppleEvent, keyAEOffset, typeLongInteger, &returnedType,
                                          &offset, sizeof(offset), &actualSize);
       NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::PositionToOffsetHandler: AEGetParamPtr[Offset] failed.");
       if (err!=noErr) 
              return err;
       
       //
       // Pass the OffsetToPosition request to the widgets to handle
       //
       res = eventHandler->HandleOffsetToPosition(offset, &thePoint);
       NS_ASSERTION(NS_SUCCEEDED(res), "nsMacMessagePup::PositionToOffsetHandler: OffsetToPosition handler failed.");
       if (NS_FAILED(res)) 
              return paramErr;
       
       //
       // build up the reply (point)
       //
       err = AEPutParamPtr(reply, keyAEPoint, typeQDPoint, &thePoint, sizeof(Point));
       NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::PositionToOffsetHandler: AEPutParamPtr[Point] failed.");
       if (err!=noErr) 
              return err;
       
       return noErr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

pascal OSErr nsMacTSMMessagePump::PositionToOffsetHandler ( const AppleEvent *  theAppleEvent,
AppleEvent *  reply,
long  handlerRefcon 
) [static, private]

Definition at line 156 of file nsMacTSMMessagePump.cpp.

{
       OSErr                       err;
       DescType                    returnedType;
       nsMacEventHandler*   eventHandler; 
       Size                        actualSize;
       Point                       thePoint;
       long                        offset;
       short                       regionClass;

       //
       // Extract the nsMacEventHandler for this TSMDocument.  It's stored as the TSMDocument's
       //     refcon
       //
       err = AEGetParamPtr(theAppleEvent, keyAETSMDocumentRefcon, typeLongInteger, &returnedType,
                                          &eventHandler, sizeof(eventHandler), &actualSize);
       NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::PositionToOffsetHandler: AEGetParamPtr[TSMRefcon] failed");
       if (err!=noErr) 
              return err;
       
       //
       // Extract the Position parameter.
       //
       err = AEGetParamPtr(theAppleEvent, keyAECurrentPoint, typeQDPoint, &returnedType,
                                          &thePoint, sizeof(thePoint), &actualSize);
       NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::PositionToOffsetHandler: AGGetParamPtr[Point] failed");
       if (err!=noErr) 
              return err;

       //
       // pass the request to the widget system
       //
       offset = eventHandler->HandlePositionToOffset(thePoint, &regionClass);
       
       //
       // build up the AE reply (need offset and region class)
       //
       err = AEPutParamPtr(reply, keyAEOffset, typeLongInteger, &offset, sizeof(offset));
       NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::PositionToOffsetHandler: AEPutParamPtr failed");
       if (err!=noErr) 
              return err;
       
       err = AEPutParamPtr(reply, keyAERegionClass, typeShortInteger, &regionClass, sizeof(regionClass));
       NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::PositionToOffsetHandler: AEPutParamPtr failed");
       if (err!=noErr) 
              return err;

       return noErr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 142 of file nsMacTSMMessagePump.cpp.

{
       if (gSingleton) {
              delete gSingleton;
              gSingleton = nsnull;
       }
}
pascal OSErr nsMacTSMMessagePump::UnicodeGetSelectedTextHandler ( const AppleEvent *  theAppleEvent,
AppleEvent *  reply,
long  handlerRefcon 
) [static, private]

Definition at line 423 of file nsMacTSMMessagePump.cpp.

{
  OSErr err;  
  DescType returnedType;
  nsMacEventHandler*  eventHandler;  
  Size actualSize;
  long maxReturnSize = 0;
  long returnSize;
  nsresult res;

  //
  // Extract the nsMacEvenbtHandler for this TSMDocument.  It's stored as the refcon.
  //
  err = AEGetParamPtr(theAppleEvent, keyAETSMDocumentRefcon, typeLongInteger, &returnedType,
            &eventHandler, sizeof(eventHandler), &actualSize);
  NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::UnicodeGetSelectedTextHandler: AEGetParamPtr[TSMRefcon] failed.");
  if (err!=noErr) 
    return err;
  
  //
  // Extract the Offset parameter
  //
  err = AEGetParamPtr(theAppleEvent, keyAEBufferSize, typeLongInteger, &returnedType,
            &maxReturnSize, sizeof(maxReturnSize), &actualSize);
  // optional parameter, ignore if we cannot get it.
  
  //
  // Pass the OffsetToPosition request to the widgets to handle
  //
  nsAutoString outString;
  res = eventHandler->HandleUnicodeGetSelectedText(outString);
  NS_ASSERTION(NS_SUCCEEDED(res), "nsMacMessagePup::UnicodeGetSelectedTextHandler: HandleGetSelectedText handler failed.");
  if (NS_FAILED(res)) 
    return paramErr;
  
  //
  // build up the reply (point)
  //
  returnSize = outString.Length()*sizeof(PRUnichar);
  if ((maxReturnSize >0) && (returnSize > maxReturnSize))
    returnSize = maxReturnSize & ~1L; // Round down
  
  err = AEPutParamPtr(reply, keyAETheData, typeUnicodeText, outString.get(), returnSize);
  NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::UnicodeGetSelectedTextHandler: AEPutParamPtr[Point] failed.");
  if (err!=noErr) 
    return err;
  
  return noErr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

pascal OSErr nsMacTSMMessagePump::UnicodeNotFromInputMethodHandler ( const AppleEvent *  theAppleEvent,
AppleEvent *  reply,
long  handlerRefcon 
) [static, private]

Definition at line 382 of file nsMacTSMMessagePump.cpp.

{
  OSErr               err;
  nsMacEventHandler*  eventHandler;
  AEDesc              text;
  DescType            returnedType;
  Size                actualSize;
  EventRecord         event;

  err = GetAppleEventTSMData(theAppleEvent, &eventHandler, &text);
  if (err != noErr) 
    return err;
  
  err = ::AEGetParamPtr(theAppleEvent, keyAETSMEventRecord, typeLowLevelEventRecord, &returnedType,
                        &event, sizeof(event), &actualSize);
  NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::UnicodeNotFromInputMethodHandler: AEGetParamPtr[event] failed.");
  if (noErr != err)
  {
    (void)::AEDisposeDesc(&text);
    return err;
  }

  nsAutoString unicodeText;
  Size text_size;
  err = AETextToString(text, unicodeText, text_size);
  if (noErr == err)
  {
    nsresult res;
    res = eventHandler->HandleUKeyEvent(unicodeText.get(), text_size, event);
    NS_ASSERTION(NS_SUCCEEDED(res), "nsMacMessagePump::UnicodeNotFromInputMethodHandler: HandleUpdated failed.");
    if (NS_FAILED(res)) {
      err = paramErr;
      // fall to cleanup below
    }
  }

  (void)::AEDisposeDesc(&text);
  return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

pascal OSErr nsMacTSMMessagePump::UnicodeUpdateHandler ( const AppleEvent *  theAppleEvent,
AppleEvent *  reply,
long  handlerRefcon 
) [static, private]

Definition at line 298 of file nsMacTSMMessagePump.cpp.

{
  OSErr                 err = noErr;
  DescType              returnedType;
  nsMacEventHandler*    eventHandler;
  Size                  actualSize;
  AEDesc                text, hiliteRangeArray;
  long                  fixLength;
  nsresult              res;
  TextRangeArray*       hiliteRangePtr;

  err = GetAppleEventTSMData(theAppleEvent, &eventHandler, &text);
  if (err) 
    return err;

  //
  // length of converted text
  //
  err = ::AEGetParamPtr(theAppleEvent, keyAEFixLength, typeLongInteger, &returnedType,
                        &fixLength, sizeof(fixLength), &actualSize);
  NS_ASSERTION(err==noErr, "nsMacTSMMessagePump::UnicodeUpdateHandler: AEGetParamPtr[fixlen] failed.");
  if (err) 
    return err;

  //
  // extract the hilite ranges (optional param)
  //
  err = ::AEGetParamDesc(theAppleEvent, keyAEHiliteRange, typeTextRangeArray, &hiliteRangeArray);
  NS_ASSERTION(err==noErr||err==errAEDescNotFound, "nsMacTSMMessagePump::UnicodeUpdateHandler: AEGetParamDesc[hiliteRangeArray] failed.");
  if (errAEDescNotFound == err)
  {
    hiliteRangePtr = NULL;
  } 
  else if (noErr == err)
  { 

    Size hiliteRangeSize = ::AEGetDescDataSize(&hiliteRangeArray);
    hiliteRangePtr = (TextRangeArray *) NewPtr(hiliteRangeSize);
    if (!hiliteRangePtr)
    {
      err = MemError();
      goto err2;
    }
    err = ::AEGetDescData(&hiliteRangeArray, (void *)hiliteRangePtr, hiliteRangeSize);
    if (noErr != err)
    {
      goto err1; 
    }
  }
  else
  {
    goto err3;
  }

  // grab the text now
  {
    nsAutoString unicodeText;
    Size text_size;
    err = AETextToString(text, unicodeText, text_size);
    if (noErr == err)
    {
      res = eventHandler->UnicodeHandleUpdateInputArea(unicodeText.get(), text_size, fixLength / 2, hiliteRangePtr);
      NS_ASSERTION(NS_SUCCEEDED(res), "nsMacMessagePump::UnicodeUpdateHandler: HandleUpdated failed.");
      if (NS_FAILED(res))
        err = paramErr;
        // fall to cleanup below
    }
  }

  //
  // clean up
  //
err1:
    if (hiliteRangePtr)
      ::DisposePtr((Ptr)hiliteRangePtr);

err2:
  (void)::AEDisposeDesc(&hiliteRangeArray);
err3:
  (void)::AEDisposeDesc(&text);

  return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 74 of file nsMacTSMMessagePump.h.

AEEventHandlerUPP nsMacTSMMessagePump::mGetSelectedTextUPP = NULL [static, private]

Definition at line 72 of file nsMacTSMMessagePump.h.

AEEventHandlerUPP nsMacTSMMessagePump::mKeyboardUPP = NULL [static, private]

Definition at line 71 of file nsMacTSMMessagePump.h.

AEEventHandlerUPP nsMacTSMMessagePump::mOffset2PosUPP = NULL [static, private]

Definition at line 69 of file nsMacTSMMessagePump.h.

AEEventHandlerUPP nsMacTSMMessagePump::mPos2OffsetUPP = NULL [static, private]

Definition at line 68 of file nsMacTSMMessagePump.h.

AEEventHandlerUPP nsMacTSMMessagePump::mUpdateUPP = NULL [static, private]

Definition at line 70 of file nsMacTSMMessagePump.h.


The documentation for this class was generated from the following files: