home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Programmation / c / Extensions / APPSource.lha / APlusPlus / libsource / IntuiMessageC.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  2.9 KB  |  85 lines

  1. /******************************************************************************
  2.  **
  3.  **   C++ Class Library for the Amiga⌐ system software.
  4.  **
  5.  **   Copyright (C) 1994 by Armin Vogt  **  EMail: armin@uni-paderborn.de
  6.  **   All Rights Reserved.
  7.  **
  8.  **   $Source: apphome:RCS/libsource/IntuiMessageC.cxx,v $
  9.  **   $Revision: 1.7 $
  10.  **   $Date: 1994/07/27 11:49:12 $
  11.  **   $Author: Armin_Vogt $
  12.  **
  13.  ******************************************************************************/
  14.  
  15.  
  16. #include <APlusPlus/intuition/IntuiMessageC.h>
  17. #include <APlusPlus/intuition/GadgetCV.h>
  18. #include <APlusPlus/intuition/WindowCV.h>
  19. #include <string.h>
  20.  
  21.  
  22. static const char rcs_id[] = "$Id: IntuiMessageC.cxx,v 1.7 1994/07/27 11:49:12 Armin_Vogt Exp Armin_Vogt $";
  23.  
  24. //runtime type inquiry support
  25. typeinfo(IntuiMessageC, no_bases, rcs_id)
  26.  
  27.  
  28. IntuiMessageC::IntuiMessageC(IDCMPClass mclass)
  29. {
  30.    memset(this,0,sizeof(this));
  31.    Class = mclass;
  32. }
  33.  
  34. WindowCV *IntuiMessageC::decodeWindowCV() const
  35. {
  36.    // test window ptr in WindowCV object against the received message IDCMPWindow
  37.    WindowCV *winC;
  38.    if (IDCMPWindow)
  39.       if (NULL != (winC = (WindowCV*)IDCMPWindow->UserData) )
  40.          if (winC->window() == IDCMPWindow) return winC;
  41.  
  42.    return NULL;
  43. }
  44.  
  45. GadgetCV *IntuiMessageC::decodeGadgetCV() const
  46.    /* Gets the sending Gadget object from a received message.
  47.       BE AWARE of the fact that, except for GadTools, all gadgets only supply a reference to
  48.       themselves in ONLY the GADGETDOWN/GADGETUP message's IAddress field!
  49.       GadTools gadgets also supply the gadget address for MOUSEMOVE messages.
  50.       Therefore calling decodeGadgetCV() on a different IntuiMessage will return NULL.
  51.       THIS METHOD IS SAFE TO BE CALLED ON EVERY INTUIMESSAGE CLASS.
  52.       Every GadgetCV derived object stores the address of itself into the encapsulated
  53.       Gadget structure. This makes it easy and fast to get the corresponding GadgetCV
  54.       object to an incoming Gadget IntuiMessage.
  55.    */
  56. {
  57.    GadgetCV *gadgetCV;
  58.    if (getClass() & (CLASS_GADGETDOWN|CLASS_GADGETUP|CLASS_MOUSEMOVE))
  59.       // IDCMPUPDATE messages hold a taglist in IAddress!!
  60.    {
  61.       struct Gadget *gadget;
  62.       if (NULL != (gadget = (struct Gadget*)getIAddress()) )
  63.  
  64.    /* ENFORCER HITS!! If the presumptive gadget is NO gadget, assuming this unknown address
  65.    ** points to a gadget and further dereferencing UserData to a Gadget object will probably
  66.    ** lead to bus errors!!!
  67.    */
  68.          if (NULL != (gadgetCV = (GadgetCV*)(gadget->UserData)))
  69.             if (gadgetCV->object() == gadget) return gadgetCV;
  70.             else _dprintf(" IntuiMessageC::decodeGadgetCV(): GadgetCV in IAddress INVALID!\n");
  71.  
  72.       _dprintf(" IntuiMessageC::decodeGadgetCV(): no GadgetCV in IAddress.\n");
  73.    }
  74.    else _dprintf(" IntuiMessageC::decodeGadgetCV(): IDCMPUPDATE\n");
  75.    return NULL;
  76. }
  77.  
  78. BOOL IntuiMessageC::isFakeMsg() const
  79. {
  80.    if (*(ULONG*)((IntuiMessage*)this) == 0L)
  81.       return TRUE;
  82.    else
  83.       return FALSE;
  84. }
  85.