home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / CApplicationEventAttachment.cp next >
Encoding:
Text File  |  1998-04-08  |  5.2 KB  |  159 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19.  
  20. //    Usage Notes:
  21. //
  22. //    (1) Add this attachment as the first attachment to the application object.
  23. //    (2) The EventRecord from ProcessNextEvent *must* persist across calls to
  24. //        ProcessNextEvent in order to prevent dangling references to the event.
  25.  
  26. #include "CApplicationEventAttachment.h"
  27.  
  28. #include <LPeriodical.h>
  29.  
  30. #include "nspr.h"
  31. #include "CMochaHacks.h"
  32.  
  33. // ---------------------------------------------------------------------------------
  34. //        Ñ [Static data members]
  35. // ---------------------------------------------------------------------------------
  36.  
  37. LApplication*    CApplicationEventAttachment::sApplication    = nil;
  38. EventRecord*    CApplicationEventAttachment::sCurrentEvent    = nil;
  39. EventRecord        CApplicationEventAttachment::sFakeNullEvent;
  40. Boolean            CApplicationEventAttachment::sFakeNullEventInitialized = false;
  41.  
  42. // ---------------------------------------------------------------------------
  43. //        Ñ CApplicationEventAttachment
  44. // ---------------------------------------------------------------------------
  45.  
  46. CApplicationEventAttachment::CApplicationEventAttachment()
  47.     :    LAttachment(msg_Event)
  48. {
  49. }
  50.  
  51. // ---------------------------------------------------------------------------
  52. //        Ñ ~CApplicationEventAttachment
  53. // ---------------------------------------------------------------------------
  54.  
  55. CApplicationEventAttachment::~CApplicationEventAttachment()
  56. {
  57. }
  58.  
  59. // ---------------------------------------------------------------------------
  60. //        Ñ ExecuteSelf
  61. // ---------------------------------------------------------------------------
  62. //    Remember the current event and the application object
  63.  
  64. void
  65. CApplicationEventAttachment::ExecuteSelf(
  66.     MessageT        inMessage,
  67.     void*            ioParam)
  68. {
  69. #pragma unused(inMessage)
  70.  
  71.     sCurrentEvent = static_cast<EventRecord*>(ioParam);
  72.     
  73.     if (!sApplication)
  74.     {
  75.         sApplication = dynamic_cast<LApplication*>(mOwnerHost);
  76.     }
  77. }
  78.  
  79. // ---------------------------------------------------------------------------
  80. //        Ñ GetApplication
  81. // ---------------------------------------------------------------------------
  82.  
  83. LApplication&
  84. CApplicationEventAttachment::GetApplication()
  85. {
  86.     ThrowIfNil_(sApplication);
  87.     
  88.     return *sApplication;
  89. }
  90.  
  91. // ---------------------------------------------------------------------------
  92. //        Ñ GetCurrentEvent
  93. // ---------------------------------------------------------------------------
  94.  
  95. EventRecord&
  96. CApplicationEventAttachment::GetCurrentEvent()
  97. {
  98.     if (!sCurrentEvent)
  99.     {
  100.         if (!sFakeNullEventInitialized)
  101.         {
  102.             sFakeNullEvent.what = nullEvent;
  103.             sFakeNullEvent.message = 0;
  104.             sFakeNullEvent.when = 0;
  105.             sFakeNullEvent.where.h = sFakeNullEvent.where.v    = 0;
  106.             sFakeNullEvent.modifiers = 0;
  107.             
  108.             sFakeNullEventInitialized = true;
  109.         }
  110.         
  111.         return sFakeNullEvent;
  112.     }
  113.     
  114.     return *sCurrentEvent;
  115. }
  116.  
  117. // ---------------------------------------------------------------------------
  118. //        Ñ CurrentEventHasModifiers
  119. // ---------------------------------------------------------------------------
  120.  
  121. Boolean
  122. CApplicationEventAttachment::CurrentEventHasModifiers(
  123.     EventModifiers        inModifiers)
  124. {
  125.     Boolean            hasModifier        = false;
  126.     EventModifiers    hackedModifiers    = inModifiers;
  127.     
  128.     if (GetCurrentEvent().what == kPrivateNSPREventType)
  129.     {
  130.         // This is ridiculous. Sometimes when event.what is kPrivateNSPREventType
  131.         // the modifiers are mapped to the mocha stuff and sometimes they're 
  132.         // native mac. So we have to first see if it seems to be mapped as mocha
  133.         // before arbitrarily mapping inModifiers. And to make matters worse,
  134.         // the darn mocha event mask stuff overlaps native mac modifiers for
  135.         // the alt (option) modifier - so we're snookered in that case. TODO: is this
  136.         // the best we can do short of fixing mocha event masks to match
  137.         // the mac (at lease in the case of the Mac - we could #ifdef it).
  138.         
  139.         if ((GetCurrentEvent().modifiers & EVENT_ALT_MASK) ||
  140.             (GetCurrentEvent().modifiers & EVENT_CONTROL_MASK) ||
  141.             (GetCurrentEvent().modifiers & EVENT_SHIFT_MASK) ||
  142.             (GetCurrentEvent().modifiers & EVENT_META_MASK))
  143.         {
  144.             hackedModifiers = CMochaHacks::MochaModifiers(inModifiers);
  145.         }
  146.     }
  147.  
  148.     return ((GetCurrentEvent().modifiers & hackedModifiers) ? true : false);
  149. }    
  150.  
  151. // ---------------------------------------------------------------------------
  152. //        Ñ ProcessNextEvent
  153. // ---------------------------------------------------------------------------
  154.  
  155. void
  156. CApplicationEventAttachment::ProcessNextEvent()
  157. {
  158.     GetApplication().ProcessNextEvent();
  159. }