home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / CAppleEventHandler.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  13.0 KB  |  367 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. // CAppleEventHandler.h
  20.  
  21. #include "PascalString.h"
  22. #include "xp_mem.h"
  23.  
  24. enum KioskEnum {KioskOff = 0, KioskOn = 1};
  25.     
  26.  
  27. class CAppleEventHandler
  28. {
  29. public:
  30.     static CAppleEventHandler*    sAppleEventHandler;        // One and only instance of AEvents
  31.  
  32.     // --- Standard Constructors and Destructors
  33.     
  34.                         CAppleEventHandler();
  35.     virtual                ~CAppleEventHandler();
  36.     // virtual void        Initialize();
  37.  
  38.     
  39.     // --- Top Level Apple Event Handling
  40.     
  41.     virtual void         HandleAppleEvent(const AppleEvent    &inAppleEvent,
  42.                                     AppleEvent            &outAEReply,
  43.                                     AEDesc                &outResult,
  44.                                     long                inAENumber);
  45.     virtual void        GetAEProperty(DescType inProperty,
  46.                                     const AEDesc    &inRequestedType,
  47.                                     AEDesc            &outPropertyDesc) const;
  48.     virtual void        SetAEProperty(DescType inProperty,
  49.                             const AEDesc    &inRequestedType,
  50.                             AEDesc            &outPropertyDesc);
  51.  
  52.     // ---  AEOM support
  53.     void                GetSubModelByUniqueID(DescType        inModelID,
  54.                                     const AEDesc    &inKeyData,
  55.                                     AEDesc            &outToken) const;
  56.  
  57.     static KioskEnum     GetKioskMode(){return sAppleEventHandler->fKioskMode;}
  58.  
  59.  
  60. protected:
  61.  
  62. private:
  63.  
  64.     KioskEnum            fKioskMode;
  65.     
  66.     void                 HandleOpenURLEvent(const AppleEvent    &inAppleEvent,
  67.                                     AppleEvent            &outAEReply,
  68.                                     AEDesc                &outResult,
  69.                                     long                inAENumber);
  70. // spy Apple Event suite
  71. // file/URL opening + misc
  72.     void                 HandleGetURLEvent(const AppleEvent    &inAppleEvent,
  73.                                     AppleEvent            &outAEReply,
  74.                                     AEDesc                &outResult,
  75.                                     long                inAENumber);
  76.                                     
  77.     void                 HandleGetWDEvent(const AppleEvent    &inAppleEvent,
  78.                                     AppleEvent            &outAEReply,
  79.                                     AEDesc                &outResult,
  80.                                     long                inAENumber);
  81.                                     
  82.     void                 HandleShowFile(const AppleEvent    &inAppleEvent,
  83.                                     AppleEvent            &outAEReply,
  84.                                     AEDesc                &outResult,
  85.                                     long                inAENumber);
  86.     void                 HandleParseAnchor(const AppleEvent    &inAppleEvent,
  87.                                     AppleEvent            &outAEReply,
  88.                                     AEDesc                &outResult,
  89.                                     long                inAENumber);
  90. // Progress
  91.  
  92.     void                 HandleCancelProgress(const AppleEvent    &inAppleEvent,
  93.                                     AppleEvent            &outAEReply,
  94.                                     AEDesc                &outResult,
  95.                                     long                inAENumber);
  96. // Spy window events
  97.     void                 HandleSpyActivate(const AppleEvent    &inAppleEvent,
  98.                                     AppleEvent            &outAEReply,
  99.                                     AEDesc                &outResult,
  100.                                     long                inAENumber);
  101.     void                 HandleSpyListWindows(const AppleEvent    &inAppleEvent,
  102.                                     AppleEvent            &outAEReply,
  103.                                     AEDesc                &outResult,
  104.                                     long                inAENumber);
  105.     void                 HandleSpyGetWindowInfo(const AppleEvent    &inAppleEvent,
  106.                                     AppleEvent            &outAEReply,
  107.                                     AEDesc                &outResult,
  108.                                     long                inAENumber);
  109.     void                 HandleWindowRegistration(const AppleEvent    &inAppleEvent,
  110.                                     AppleEvent            &outAEReply,
  111.                                     AEDesc                &outResult,
  112.                                     long                inAENumber);
  113. // Netscape suite
  114.     void                HandleOpenBookmarksEvent(const AppleEvent    &inAppleEvent,
  115.                                     AppleEvent            &outAEReply,
  116.                                     AEDesc                &outResult,
  117.                                     long                inAENumber);
  118.     void                HandleReadHelpFileEvent(const AppleEvent    &inAppleEvent,
  119.                                     AppleEvent            &outAEReply,
  120.                                     AEDesc                &outResult,
  121.                                     long                inAENumber);
  122.     void                 HandleGoEvent( const AppleEvent    &inAppleEvent,
  123.                                     AppleEvent            &outAEReply,
  124.                                     AEDesc                &outResult,
  125.                                     long                inAENumber);
  126.     void                HandleOpenAddressBookEvent(const AppleEvent    &inAppleEvent,
  127.                                     AppleEvent            &outAEReply,
  128.                                     AEDesc                &outResult,
  129.                                     long                inAENumber);                                
  130.  
  131.     void                HandleOpenComponentEvent(const AppleEvent    &inAppleEvent,
  132.                                     AppleEvent            &outAEReply,
  133.                                     AEDesc                &outResult,
  134.                                     long                inAENumber);                                
  135.  
  136.     void                HandleCommandEvent(const AppleEvent    &inAppleEvent,
  137.                                     AppleEvent            &outAEReply,
  138.                                     AEDesc                &outResult,
  139.                                     long                inAENumber);                                
  140.  
  141.     void                 HandleGetActiveProfileEvent(const AppleEvent    &inAppleEvent,
  142.                                     AppleEvent            &outAEReply,
  143.                                     AEDesc                &outResult,
  144.                                     long                inAENumber);        
  145. };
  146.  
  147.  
  148. /*-------------------------------------------------------------*/
  149. //     class EudoraSuite
  150. //    Tools used to communicate with Eudora
  151. //    The only real use these have is if we are operating in
  152. //    Browser-only mode and the user wishes to use Eudora to
  153. //    handle mail functions.
  154. //
  155. /*-------------------------------------------------------------*/
  156.  
  157. // --------------------------------------------------------------
  158. /*    Some Constants used by the Eudora Suite                         */
  159. // --------------------------------------------------------------
  160.  
  161. #define attachDouble 0
  162. #define attachSingle 1
  163. #define attachBinHex 2
  164. #define attachUUencode 3
  165.  
  166. #define EU_Norm_Priority 0
  167. #define EU_High_Priority 60
  168. #define EU_Highest_Priority 1
  169. #define EU_Low_Priority 160
  170. #define EU_Lowest_Priority 200
  171.  
  172. class EudoraSuite
  173. {
  174. public:
  175.  
  176.     // --------------------------------------------------------------
  177.     /*    This makes a Null AppleEvent descriptor.    
  178.                  */
  179.     // --------------------------------------------------------------
  180.     static void MakeNullDesc (AEDesc *theDesc);
  181.  
  182.     // --------------------------------------------------------------
  183.     /*    This makes a string AppleEvent descriptor.   
  184.                  */
  185.     // --------------------------------------------------------------
  186.     static OSErr MakeStringDesc (Str255 theStr,AEDesc *theDesc);
  187.  
  188.  
  189.     // --------------------------------------------------------------
  190.     /*    This stuffs the required parameters into the AppleEvent. 
  191.                  */
  192.     // --------------------------------------------------------------
  193.  
  194.  
  195.     static OSErr CreateObjSpecifier (AEKeyword theClass,AEDesc theContainer,
  196.             AEKeyword theForm,AEDesc theData, Boolean disposeInputs,AEDesc *theSpec);
  197.  
  198.     // --------------------------------------------------------------
  199.     /*    This creates an AEDesc for the current message.
  200.         (The current message index = 1)     
  201.  
  202.         In:    Pointer to AEDesc to return
  203.         Out: AEDesc constructed. */
  204.     // --------------------------------------------------------------
  205.  
  206.     static OSErr MakeCurrentMsgSpec (AEDesc *theSpec);
  207.  
  208.  
  209.     // --------------------------------------------------------------
  210.     /*    Send a given Apple Event.  Special case for Eudora, should
  211.         be rewritten, but it works for the moment.
  212.         In:    AppleEvent
  213.         Out: Event sent  */
  214.     // --------------------------------------------------------------
  215.     static OSErr SendEvent (AppleEvent *theEvent);
  216.  
  217.     // --------------------------------------------------------------
  218.     /*    Create an Apple Event to be sent to Eudora
  219.         In:    Event Class
  220.             Event ID
  221.             Ptr to Apple Event
  222.         Out: Event constructed and returned.  */
  223.     // --------------------------------------------------------------
  224.     static OSErr MakeEvent (AEEventClass eventClass,AEEventID eventID,AppleEvent *theEvent);
  225.  
  226.     // --------------------------------------------------------------
  227.     /*    This sets the data in a specified field. It operates on the frontmost message 
  228.         in Eudora. It is the equivalent of sending the following AppleScript:
  229.         set field "fieldname" of message 0 to "data"
  230.  
  231.         Examples for setting up a complete mail message:
  232.             EudoraSuite::SendSetData("\pto",toRecipientPtr);
  233.             EudoraSuite::SendSetData("\pcc",ccRecipientPtr);
  234.             EudoraSuite::SendSetData("\pbcc",bccRecipientPtr);
  235.             EudoraSuite::SendSetData("\psubject",subjectPtr);
  236.             EudoraSuite::SendSetData("\p",bodyPtr);
  237.             
  238.         In:    Field to set the data in (Subject, Address, Content, etc)
  239.             Pointer to text data.
  240.             Size of pointer (allows us to work with XP_Ptrs.
  241.         Out: Apple Event sent to Eudora, setting a given field.  */
  242.     // --------------------------------------------------------------
  243.     static OSErr SendSetData(Str31 theFieldName, Ptr thePtr, long thePtrSize);
  244.     
  245.     // --------------------------------------------------------------
  246.     /*    Everything you need to tell Eudora to construct a new message
  247.         and send it.
  248.         In:    Pointer to the list of e mail addresses to send TO
  249.             Pointer to the list of e mail addresses to send CC
  250.             Pointer to the list of e mail addresses to send BCC
  251.             Pointer to the Subject text
  252.             Priority level of message.
  253.             XP_HUGE_CHAR_PTR to the contents of the mail
  254.             Pointer to an FSSpec (or null if none) for an enclosure.
  255.         Out: Apple Events sent to Eudora telling it to construct the
  256.             message and send it. */
  257.     // --------------------------------------------------------------
  258.  
  259.     static OSErr  SendMessage(
  260.         Ptr        toRecipientPtr, 
  261.         Ptr        ccRecipientPtr,
  262.         Ptr        bccRecipientPtr,
  263.         Ptr        subjectPtr,
  264.         XP_HUGE_CHAR_PTR        bodyPtr,
  265.         long    thePriority,
  266.         FSSpec    *theEnclosurePtr);
  267.  
  268.     static OSErr Set_Eudora_Priority(long thePriority);
  269.  
  270. };
  271.  
  272.  
  273. /*-------------------------------------------------------------*/
  274. //     class MoreExtractFromAEDesc
  275. //    Apple event helpers -- extension of UExtractFromAEDesc.h
  276. //    All the miscellaneous AppleEvent helper routines.
  277. /*-------------------------------------------------------------*/
  278.  
  279. class MoreExtractFromAEDesc
  280. {
  281. public:
  282.  
  283.     // --------------------------------------------------------------
  284.     /*    Given an AppleEvent, locate a string given a keyword and
  285.         return the string
  286.         In:    Event to search
  287.             AEKeyword assocaated with the string
  288.             C string ptr
  289.         Out: Pointer to a newly created C string returned */
  290.     // --------------------------------------------------------------
  291.     static void GetCString(const AppleEvent    &inAppleEvent, AEKeyword keyword, 
  292.             char * & s);
  293.  
  294.     // --------------------------------------------------------------
  295.     /*    Given an AEDesc of type typeChar, return it's string.
  296.         In:    AEDesc containing a string
  297.             C string ptr
  298.         Out: Pointer to a newly created C string returned */
  299.     // --------------------------------------------------------------
  300.     static void TheCString(const AEDesc &inDesc, char * & outPtr);
  301.     
  302.     // --------------------------------------------------------------
  303.     /*    Add an error string and error code to an AppleEvent.
  304.         Typically used when constructing the return event when an
  305.         error occured
  306.         In:    Apple Event to append to
  307.             Error string
  308.             Error code
  309.         Out: keyErrorNum and keyErrorSting AEDescs are added to the Event. */
  310.     // --------------------------------------------------------------
  311.     static void MakeErrorReturn(AppleEvent &event, const CStr255& errorString, 
  312.             OSErr errorCode);
  313.  
  314.     // --------------------------------------------------------------
  315.     /*    Display an error dialog if the given AppleEvent contains
  316.         a keyErrorNumber.  a keyErrorString is optional and will be
  317.         displayed if present
  318.         In:    Apple Event
  319.         Out: Error dialog displayed if error data present. */
  320.     // --------------------------------------------------------------
  321.     static Boolean DisplayErrorReply(AppleEvent &reply);
  322.  
  323.     // --------------------------------------------------------------
  324.     /*    Return the process serial number of the sending process.
  325.         In:    Apple Event send by some app.
  326.         Out: ProcessSerialNumber of the sending app. */
  327.     // --------------------------------------------------------------
  328.     static ProcessSerialNumber ExtractAESender(const AppleEvent &inAppleEvent);
  329.  
  330.     static void DispatchURLDirectly(const AppleEvent &inAppleEvent);
  331. }; // class MoreExtractFromAEDesc
  332.  
  333.  
  334. /*-------------------------------------------------------------*/
  335. //    class AEUtilities
  336. //    Some more simple Apple Event utility routines.
  337. /*-------------------------------------------------------------*/
  338.  
  339. class AEUtilities
  340. {
  341. public:
  342.  
  343.     // --------------------------------------------------------------
  344.     /*    CreateAppleEvent
  345.         Create a new Apple Event from scratch.
  346.         In:    Apple Event suite
  347.             Apple Event ID
  348.             Ptr to return Apple Event
  349.             ProcessSerialNumber of the target app to send event to.
  350.         Out:A new Apple Event is created.  More data may be added to
  351.             the event simply by calling AEPutParamDesc or AEPutParamPtr */
  352.     // --------------------------------------------------------------
  353.     static    OSErr CreateAppleEvent(OSType suite, OSType id, 
  354.         AppleEvent &event, ProcessSerialNumber targetPSN);
  355.  
  356.     // --------------------------------------------------------------
  357.     /*    Check to see if there is an error in the given AEvent.
  358.         We simply return an OSError equiv to the error value
  359.         in the event.  If none exists (or an error took place
  360.         during access) we return 0.
  361.         In:    Apple Event to test
  362.         Out:Error value returned */
  363.     // --------------------------------------------------------------
  364.     static    OSErr EventHasErrorReply(AppleEvent & reply);
  365.  
  366. };
  367.