Back to index

lightning-sunbird  0.9+nobinonly
nsAEGenericClass.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Simon Fraser <sfraser@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 
00040 #include "nsAEUtils.h"
00041 #include "nsAETokens.h"
00042 #include "nsAECoreClass.h"
00043 
00044 #include "nsAEGenericClass.h"
00045 
00046 
00047 /*----------------------------------------------------------------------------
00048        AEGenericClass 
00049        
00050 ----------------------------------------------------------------------------*/
00051 AEGenericClass::AEGenericClass(DescType classType, DescType containerClass)
00052 :      mClass(classType)
00053 ,      mContainerClass(containerClass)
00054 ,      mItemFromContainerAccessor(nil)
00055 {
00056 
00057        // Window from null accessor used by the entire window hierarchy
00058        mItemFromContainerAccessor = NewOSLAccessorUPP(AEGenericClass::ItemFromContainerAccessor);
00059        ThrowIfNil(mItemFromContainerAccessor);
00060        
00061        OSErr  err;
00062        err = AEInstallObjectAccessor(mClass,            containerClass, 
00063                                                                       mItemFromContainerAccessor, 
00064                                                                       (long)this, 
00065                                                                       false);
00066 
00067        // although items of a given class can't contain other items of the same class, 
00068        // we need this accessor to support formRelativePostion,
00069        // which sends us one item as a "container" and asks us to find
00070        // either the item before or after that item
00071        err = AEInstallObjectAccessor(mClass,            mClass, 
00072                                                                       mItemFromContainerAccessor, 
00073                                                                       (long)this, 
00074                                                                       false);
00075        ThrowIfOSErr(err);
00076 
00077 }
00078 
00079 /*----------------------------------------------------------------------------
00080        ~AEGenericClass 
00081        
00082 ----------------------------------------------------------------------------*/
00083 AEGenericClass::~AEGenericClass()
00084 {
00085        if (mItemFromContainerAccessor)
00086               DisposeOSLAccessorUPP(mItemFromContainerAccessor);
00087 }
00088 
00089 #pragma mark -
00090 
00091 
00092 /*----------------------------------------------------------------------------
00093        DispatchEvent 
00094        
00095        Handles all OSL messages that this object should handle
00096 ----------------------------------------------------------------------------*/
00097 void AEGenericClass::DispatchEvent(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00098 {
00099        OSErr         err = noErr;
00100        
00101        AEEventID            eventID;
00102        OSType        typeCode;
00103        Size                 actualSize    = 0L;
00104        
00105        // Get the event ID
00106        err = AEGetAttributePtr(appleEvent,       keyEventIDAttr, 
00107                                                                typeType, 
00108                                                                &typeCode, 
00109                                                                (Ptr)&eventID, 
00110                                                                sizeof(eventID), 
00111                                                                &actualSize);
00112        ThrowIfOSErr(err);
00113        
00114        try
00115        {
00116               switch (eventID)
00117               {
00118                      case kAEClone:
00119                             HandleDuplicate(token, appleEvent, reply);
00120                             break;
00121                             
00122                      case kAEClose:
00123                             HandleClose(token, appleEvent, reply);
00124                             break;
00125                             
00126                      case kAECountElements:
00127                             HandleCount(token, appleEvent, reply);
00128                             break;
00129                             
00130                      case kAECreateElement:
00131                             HandleMake(token, appleEvent, reply);
00132                             break;
00133                             
00134                      case kAEDelete:
00135                             HandleDelete(token, appleEvent, reply);
00136                             break;
00137                             
00138                      case kAEDoObjectsExist:
00139                             HandleExists(token, appleEvent, reply);
00140                             break;
00141                             
00142                      case kAEGetData:
00143                             HandleGetData(token, appleEvent, reply);
00144                             break;
00145                             
00146                      case kAEGetDataSize:
00147                             HandleDataSize(token, appleEvent, reply);
00148                             break;
00149                             
00150                      case kAEMove:
00151                             HandleMove(token, appleEvent, reply);
00152                             break;
00153                             
00154                      case kAEOpen:        // == kAEOpenDocuments
00155                             HandleOpen(token, appleEvent, reply);
00156                             break;
00157                             
00158                      case kAEPrint:
00159                             HandlePrint(token, appleEvent, reply);
00160                             break;
00161                      
00162                      case kAEOpenApplication:
00163                             HandleRun(token, appleEvent, reply);
00164                             break;
00165                      
00166                      case kAEReopenApplication:
00167                        HandleReOpen(token, appleEvent, reply);
00168                        break; 
00169                                                  
00170                      case kAEQuitApplication:
00171                             HandleQuit(token, appleEvent, reply);
00172                             break;
00173                             
00174                      case kAESave:
00175                             HandleSave(token, appleEvent, reply);
00176                             break;
00177                             
00178                      case kAESetData:
00179                             HandleSetData(token, appleEvent, reply);
00180                             break;
00181 
00182                      // MT-NW suite
00183                      case kAEExtract:
00184                             HandleExtract(token, appleEvent, reply);
00185                             break;
00186                             
00187                      case kAESendMessage:
00188                             HandleSendMessage(token, appleEvent, reply);
00189                             break;
00190                             
00191                      default:
00192                             err = errAEEventNotHandled;
00193                             break;
00194               }
00195        }
00196        catch (OSErr catchErr)
00197        {
00198               PutReplyErrorNumber(reply, catchErr);
00199               throw;
00200        }
00201        catch ( ... )
00202        {
00203               PutReplyErrorNumber(reply, paramErr);
00204               throw;
00205        }
00206 }
00207 
00208 
00209 /*----------------------------------------------------------------------------
00210        GetProperty 
00211        
00212 ----------------------------------------------------------------------------*/
00213 void   AEGenericClass::GetProperty(                            DescType                    desiredClass,
00214                                                                       const AEDesc*        containerToken,
00215                                                                       DescType                    containerClass,
00216                                                                       DescType                    keyForm,
00217                                                                       const AEDesc*        keyData,
00218                                                                       AEDesc*                     resultToken)
00219 {
00220        
00221        // call the base class utility method, which calls back up to the object
00222        GetPropertyFromListOrObject(desiredClass, containerToken, containerClass, keyForm, keyData, resultToken);
00223 }
00224 
00225 #pragma mark -
00226 
00227 /*----------------------------------------------------------------------------
00228        ItemFromContainerAccessor
00229        
00230        Callback for getting an item from its container
00231 ----------------------------------------------------------------------------*/
00232 pascal OSErr AEGenericClass::ItemFromContainerAccessor( DescType                    desiredClass,        // cWindow
00233                                                                                     const AEDesc*        containerToken,      // null container
00234                                                                                     DescType                    containerClass,       // cApplication
00235                                                                                     DescType                    keyForm,
00236                                                                                     const AEDesc*        keyData,
00237                                                                                     AEDesc*                     resultToken,         // specified window is returned in result
00238                                                                                     long                        refCon)
00239 {
00240        AEGenericClass*      itemClass = reinterpret_cast<AEGenericClass *>(refCon);
00241        if (!itemClass) return paramErr;
00242        
00243        OSErr         err = noErr;
00244        
00245        try
00246        {
00247               itemClass->GetItemFromContainer(desiredClass, containerToken, containerClass, keyForm, keyData, resultToken);
00248        }
00249        catch(OSErr catchErr)
00250        {
00251               err = catchErr;
00252        }
00253        catch(...)
00254        {
00255               err = paramErr;
00256        }
00257        
00258        return err;
00259 }
00260 
00261 
00262 
00263 #pragma mark -
00264 
00265 /*----------------------------------------------------------------------------
00266        HandleClose 
00267        
00268 ----------------------------------------------------------------------------*/
00269 void AEGenericClass::HandleClose(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00270 {
00271        ThrowIfOSErr(errAEEventNotHandled);
00272 }
00273 
00274 /*----------------------------------------------------------------------------
00275        HandleCount 
00276        
00277 ----------------------------------------------------------------------------*/
00278 void AEGenericClass::HandleCount(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00279 {
00280        ConstAETokenDesc     tokenDesc(token);
00281        long                 numberOfObjects = 0;
00282        DescType             objectClass;
00283        OSErr         err = noErr;  
00284 
00285        if (!reply->dataHandle)
00286               return;
00287        
00288        // Get the class of object that we will count
00289        err = GetObjectClassFromAppleEvent(appleEvent, &objectClass);
00290        ThrowIfOSErr(err);
00291        
00292        err = CheckForUnusedParameters(appleEvent);
00293        ThrowIfOSErr(err);
00294 
00295        if (AEListUtils::TokenContainsTokenList(token))
00296        {
00297               err = AECountItems(token, &numberOfObjects);
00298               ThrowIfOSErr(err);
00299               
00300        }
00301        else
00302        {
00303               CountObjects(objectClass, tokenDesc.GetDispatchClass(), token, &numberOfObjects);
00304        }
00305 
00306        err = AEPutParamPtr(reply, keyAEResult, 
00307                                                          typeLongInteger, 
00308                                                          (Ptr)&numberOfObjects, 
00309                                                          sizeof(long));
00310        ThrowIfOSErr(err);
00311 }
00312 
00313 
00314 /*----------------------------------------------------------------------------
00315        HandleGetData 
00316        
00317 ----------------------------------------------------------------------------*/
00318 void AEGenericClass::HandleGetData(AEDesc *tokenOrTokenList, const AppleEvent *appleEvent, AppleEvent *reply)
00319 {
00320        OSErr         err                  = noErr;      
00321        StAEDesc             data;
00322        StAEDesc             desiredTypes;
00323        
00324        (void)AEGetParamDesc(appleEvent, keyAERequestedType, typeAEList, &desiredTypes);
00325        
00326        GetDataFromListOrObject(tokenOrTokenList, &desiredTypes, &data);
00327 
00328        if (reply->descriptorType != typeNull)
00329        {
00330               err = AEPutKeyDesc(reply, keyDirectObject, &data);
00331               ThrowIfOSErr(err);
00332        }
00333 }
00334 
00335 /*----------------------------------------------------------------------------
00336        HandleSetData 
00337 
00338        
00339 ----------------------------------------------------------------------------*/
00340 void AEGenericClass::HandleSetData(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00341 {
00342        SetDataForListOrObject(token, appleEvent, reply);
00343 }
00344 
00345 /*----------------------------------------------------------------------------
00346        HandleDataSize 
00347        
00348 ----------------------------------------------------------------------------*/
00349 void AEGenericClass::HandleDataSize(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00350 {
00351        ThrowIfOSErr(errAEEventNotHandled);
00352 }
00353 
00354 /*----------------------------------------------------------------------------
00355        HandleDelete 
00356 
00357        All attempts to delete an empty list are handled here
00358        Application contains documents and windows, and they can't be deleted
00359        
00360 ----------------------------------------------------------------------------*/
00361 void AEGenericClass::HandleDelete(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00362 {
00363        ThrowIfOSErr(errAEEventNotHandled);
00364 }
00365 
00366 /*----------------------------------------------------------------------------
00367        HandleDuplicate 
00368        
00369 ----------------------------------------------------------------------------*/
00370 void AEGenericClass::HandleDuplicate(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00371 {
00372        ThrowIfOSErr(errAEEventNotHandled);
00373 }
00374 
00375 /*----------------------------------------------------------------------------
00376        HandleExists 
00377 
00378        If <anObject> exists...
00379        The AEResolve() function in AERCoreSuite.c will already have filtered
00380        out all cases where the object did not exist, so this function should
00381        always return TRUE.
00382 
00383 ----------------------------------------------------------------------------*/
00384 void AEGenericClass::HandleExists(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00385 {
00386        OSErr  err;
00387        Boolean       foundIt       = true;
00388 
00389        err = AEPutParamPtr(reply, 
00390                                     keyAEResult, 
00391                                     typeBoolean, 
00392                                     (Ptr)&foundIt, 
00393                                     sizeof(Boolean));
00394               
00395        ThrowIfOSErr(err);
00396 }
00397 
00398 /*----------------------------------------------------------------------------
00399        HandleMake 
00400 
00401        
00402 ----------------------------------------------------------------------------*/
00403 void AEGenericClass::HandleMake(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00404 {
00405        DescType             insertionPos  = typeNull;
00406        OSErr         err                  = noErr;
00407 
00408        StAEDesc             insertionLoc;
00409        StAEDesc             objectSpec;
00410 
00411        // For Create Element, the object specifier is contained in  
00412        // a typeInsertionLoc record instead of in a direct parameter. 
00413        // We coerce the insertionLoc record into an AERecord so we can extract the fields.  
00414        // Notice that this is a REQUIRED parameter, but we give it a default behavior
00415        // by creating a new element at beginning of the first document
00416        
00417        err = ::AEGetParamDesc(appleEvent,                             // Extract as a AERecord
00418                                                           keyAEInsertHere, 
00419                                                           typeAERecord, 
00420                                                           &insertionLoc);
00421        if (err == errAEDescNotFound)
00422        {
00423               insertionPos  = kAEBeginning;
00424               err                  = noErr;
00425        }
00426        else if (err == noErr)
00427        {
00428               // Get the enumerated insertion location (at end, in front, before, after, replace.)
00429               
00430               OSType        typeCode;
00431               Size                 actualSize;
00432               err = ::AEGetKeyPtr(&insertionLoc, 
00433                                                                keyAEPosition,                     // insertion location
00434                                                                typeEnumeration, 
00435                                                                &typeCode, 
00436                                                                (Ptr)&insertionPos,
00437                                                                sizeof(insertionPos), 
00438                                                                &actualSize);
00439 
00440               // Extract and resolve the object specifier from the insertion location record.
00441               // In a case like "make new rectangle before rectangle 1 of document 1",
00442               // the ospec will resolve to "rectangle 1 of document 1"
00443                              
00444               err = ::AEGetKeyDesc(&insertionLoc, 
00445                                                                keyAEObject, 
00446                                                                typeWildCard, 
00447                                                                &objectSpec);
00448        }
00449 
00450        // if there was a object specifier in the insertion location (eg, "before rectangle 1 of document 1"),
00451        //   then we call AEResolve() to get a token for it,
00452        // Otherwise, is was something like "at end" or "at beginning", which is also OK, 
00453        //   then deal with it correctly later.
00454        if (objectSpec.descriptorType == typeNull) 
00455        {
00456               ::AEDisposeDesc(token);                   // destroy it's old representation, token will now be null descriptor
00457        }
00458        else
00459        {
00460               err = ::AEResolve(&objectSpec, 
00461                                                   kAEIDoMinimum, 
00462                                                   token);                    // token will contain info about the object to insert before, after, etc.
00463               ThrowIfOSErr(err);
00464        }
00465               
00466        // Extract the optional parameters from the AppleEvent
00467        
00468        // ----- [with data ....] -----
00469        
00470        StAEDesc             withData;
00471        const AEDesc* withDataPtr = nil;
00472        
00473        err = ::AEGetParamDesc(appleEvent, 
00474                                                           keyAEData,
00475                                                           typeWildCard,
00476                                                           &withData);
00477        if (err == errAEDescNotFound)
00478               err = noErr;
00479        else
00480        {
00481               ThrowIfOSErr(err);
00482               withDataPtr = &withData;
00483        }
00484 
00485        // ----- [with properties {property: value, ...}] -----
00486        StAEDesc             withProperties;
00487        const AEDesc* withPropertiesPtr = nil;
00488        err = AEGetParamDesc(appleEvent, 
00489                                                           keyAEPropData, 
00490                                                           typeWildCard, 
00491                                                           &withProperties);
00492                                                           
00493        if (err == errAEDescNotFound)
00494               err = noErr;
00495        else
00496        {
00497               ThrowIfOSErr(err);
00498               withPropertiesPtr = &withProperties;
00499        }
00500        
00501        // Finally, use the token and other parameters to create & initialize the object
00502        MakeNewObject(insertionPos, token, withDataPtr, withPropertiesPtr, reply);
00503 }
00504 
00505 /*----------------------------------------------------------------------------
00506        HandleMove 
00507 
00508        
00509 ----------------------------------------------------------------------------*/
00510 void AEGenericClass::HandleMove(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00511 {
00512        ThrowIfOSErr(errAEEventNotHandled);
00513 }
00514 
00515 /*----------------------------------------------------------------------------
00516        HandleOpen 
00517 
00518        
00519 ----------------------------------------------------------------------------*/
00520 void AEGenericClass::HandleOpen(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00521 {
00522        ThrowIfOSErr(errAEEventNotHandled);
00523 }
00524 
00525 /*----------------------------------------------------------------------------
00526        HandleReOpen 
00527 
00528        
00529 ----------------------------------------------------------------------------*/
00530 void AEGenericClass::HandleReOpen(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00531 {
00532        ThrowIfOSErr(errAEEventNotHandled);
00533 }
00534 
00535 /*----------------------------------------------------------------------------
00536        HandleRun 
00537 
00538        
00539 ----------------------------------------------------------------------------*/
00540 void AEGenericClass::HandleRun(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00541 {
00542        ThrowIfOSErr(errAEEventNotHandled);
00543 }
00544 
00545 /*----------------------------------------------------------------------------
00546        HandlePrint 
00547 
00548        
00549 ----------------------------------------------------------------------------*/
00550 void AEGenericClass::HandlePrint(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00551 {
00552        ThrowIfOSErr(errAEEventNotHandled);
00553 }
00554 
00555 /*----------------------------------------------------------------------------
00556        HandleQuit 
00557 
00558        
00559 ----------------------------------------------------------------------------*/
00560 void AEGenericClass::HandleQuit(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00561 {
00562        ThrowIfOSErr(errAEEventNotHandled);
00563 }
00564 
00565 /*----------------------------------------------------------------------------
00566        HandleSave 
00567 
00568        
00569 ----------------------------------------------------------------------------*/
00570 void AEGenericClass::HandleSave(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00571 {
00572        ThrowOSErr(errAEEventNotHandled);
00573 }
00574 
00575 
00576 /*----------------------------------------------------------------------------
00577        HandleExtract 
00578 
00579        
00580 ----------------------------------------------------------------------------*/
00581 void AEGenericClass::HandleExtract(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00582 {
00583        ThrowOSErr(errAEEventNotHandled);
00584 }
00585 
00586 
00587 /*----------------------------------------------------------------------------
00588        HandleSendMessage 
00589 
00590        
00591 ----------------------------------------------------------------------------*/
00592 void AEGenericClass::HandleSendMessage(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00593 {
00594        ThrowOSErr(errAEEventNotHandled);
00595 }
00596 
00597 
00598 #pragma mark -
00599 
00600 /*----------------------------------------------------------------------------
00601        CompareObjects 
00602        
00603 ----------------------------------------------------------------------------*/
00604 void AEGenericClass::CompareObjects(                           DescType                    comparisonOperator,
00605                                                                              const AEDesc *              object,
00606                                                                              const AEDesc *              descriptorOrObject,
00607                                                                              Boolean *                   result)
00608 {
00609        ThrowOSErr(errAEEventNotHandled);
00610 }
00611 
00612 /*----------------------------------------------------------------------------
00613        CountObjects 
00614        
00615 ----------------------------------------------------------------------------*/
00616 void AEGenericClass::CountObjects(                             DescType                    desiredType,
00617                                                                              DescType                    containerClass,
00618                                                                              const AEDesc *              container,
00619                                                                              long *               result)
00620 {
00621        ThrowOSErr(errAEEventNotHandled);
00622 }
00623 
00624 #pragma mark -
00625 
00626 /*----------------------------------------------------------------------------
00627        GetDataFromListOrObject 
00628 
00629        
00630 ----------------------------------------------------------------------------*/
00631 
00632 void AEGenericClass::GetDataFromListOrObject(const AEDesc *tokenOrTokenList, AEDesc *desiredTypes, AEDesc *data)
00633 {
00634        if (AEListUtils::TokenContainsTokenList(tokenOrTokenList) == false)
00635        {
00636               GetDataFromObject(tokenOrTokenList, desiredTypes, data);
00637        }
00638        else
00639        {
00640               ThrowIfOSErr(AECreateList(nil, 0, false, data));
00641               GetDataFromList(tokenOrTokenList, desiredTypes, data);
00642        }
00643 }
00644 
00645 /*----------------------------------------------------------------------------
00646        GetDataFromListOrObject 
00647 
00648        
00649 ----------------------------------------------------------------------------*/
00650 
00651 void AEGenericClass::SetDataForListOrObject(const AEDesc *tokenOrTokenList, const AppleEvent *appleEvent, AppleEvent *reply)
00652 {
00653        StAEDesc                    data;
00654        
00655        switch (tokenOrTokenList->descriptorType)
00656        {
00657               case typeAEList:
00658                      {
00659                             AECoreClass::GetAECoreHandler()->GetEventKeyDataParameter(appleEvent, typeWildCard, &data);
00660                             SetDataForList(tokenOrTokenList, &data);
00661                      }
00662                      break;
00663                             
00664               case cProperty:
00665                      {
00666                             ConstAETokenDesc     tokenDesc(tokenOrTokenList);
00667                             DescType             propertyCode = tokenDesc.GetPropertyCode();
00668                             //DescType           objectClass    = tokenDesc.GetObjectClass();
00669                             
00670                             if (CanSetProperty(propertyCode))
00671                             {
00672                                    AECoreClass::GetAECoreHandler()->GetEventKeyDataParameter(appleEvent, GetKeyEventDataAs(propertyCode), &data);
00673                                    SetDataForObject(tokenOrTokenList, &data);
00674                             }
00675                             else
00676                             {
00677                                    ThrowIfOSErr(errAENotModifiable);
00678                             }
00679                      }
00680                      break;
00681                      
00682               default:
00683                      ThrowIfOSErr(errAENotModifiable);
00684        }
00685 }
00686 
00687 /*----------------------------------------------------------------------------
00688        GetDataFromList 
00689 
00690        
00691 ----------------------------------------------------------------------------*/
00692 void AEGenericClass::GetDataFromList(const AEDesc *srcList, AEDesc *desiredTypes, AEDesc *dstList)
00693 {
00694        OSErr         err;
00695        long                 itemNum;
00696        long                 numItems;
00697        DescType             keyword;
00698        StAEDesc             srcItem;
00699        StAEDesc             dstItem;
00700               
00701        err = AECountItems((AEDescList*)srcList, &numItems);
00702        ThrowIfOSErr(err);
00703               
00704        for (itemNum = 1; itemNum <= numItems; itemNum++)
00705        {
00706               err = AEGetNthDesc(srcList, itemNum, typeWildCard, &keyword, &srcItem);
00707               ThrowIfOSErr(err);
00708               
00709               if (AEListUtils::TokenContainsTokenList(&srcItem) == false)
00710               {
00711                      GetDataFromObject(&srcItem, desiredTypes, &dstItem);  // Get data from single item
00712               }
00713               else
00714               {
00715                      ThrowIfOSErr(AECreateList(nil, 0, false, &dstItem));
00716                      GetDataFromList(&srcItem, desiredTypes, &dstItem);
00717               }
00718               err = AEPutDesc(dstList, itemNum, &dstItem);
00719               ThrowIfOSErr(err);
00720        }
00721 }
00722 
00723 
00724 /*----------------------------------------------------------------------------
00725        GetDataFromObject 
00726 
00727        
00728 ----------------------------------------------------------------------------*/
00729 void AEGenericClass::GetDataFromObject(const AEDesc *token, AEDesc *desiredTypes, AEDesc *data)
00730 {
00731        ConstAETokenDesc            tokenDesc(token);
00732        DescType                    propertyCode         = tokenDesc.GetPropertyCode();
00733        OSErr                err                         = noErr;
00734 
00735        switch (propertyCode)
00736        {
00737               case pContents:
00738               case typeNull:
00739                      // must mean contents. Make a self specifier.
00740                      CreateSpecifier(token, data);
00741                      break;
00742                      
00743               default:
00744                      err = errAECantSupplyType;
00745                      break;
00746        }
00747        
00748        ThrowIfOSErr(err);
00749 }
00750 
00751 
00752 /*----------------------------------------------------------------------------
00753        SetDataForList 
00754 
00755        Given a token that contains a list of cWindow tokens,
00756        walk the list recursively to set the data for each token in the list
00757        
00758 ----------------------------------------------------------------------------*/
00759 void AEGenericClass::SetDataForList(const AEDesc *token, AEDesc *data)
00760 {
00761        OSErr                err;
00762               
00763        if (AEListUtils::TokenContainsTokenList(token) == false)
00764        {
00765               SetDataForObject(token, data);
00766        }
00767        else
00768        {
00769               long                 numItems;
00770               long                 itemNum;
00771               err = AECountItems((AEDescList*)token, &numItems);
00772               ThrowIfOSErr(err);
00773               
00774               for (itemNum = 1; itemNum <= numItems; itemNum++)
00775               {
00776                      StAEDesc             tempToken;
00777                      AEKeyword     keyword;
00778                      
00779                      err = AEGetNthDesc((AEDescList*)token, itemNum, typeWildCard, &keyword, &tempToken);
00780                      ThrowIfOSErr(err);
00781                      
00782                      if (AEListUtils::TokenContainsTokenList(&tempToken) == false)
00783                      {
00784                             SetDataForObject(&tempToken, data);              // Set data from single item
00785                      }
00786                      else
00787                      {
00788                             SetDataForList(&tempToken, data);  // Recurse sublist
00789                      }
00790               }
00791        }
00792 }
00793 
00794 
00795 /*----------------------------------------------------------------------------
00796        CanGetProperty 
00797 
00798 ----------------------------------------------------------------------------*/
00799 DescType AEGenericClass::GetKeyEventDataAs(DescType propertyCode)
00800 {
00801        return typeWildCard;
00802 }
00803 
00804 #pragma mark -
00805 
00806 /*----------------------------------------------------------------------------
00807        CanGetProperty 
00808 
00809 ----------------------------------------------------------------------------*/
00810 Boolean AEGenericClass::CanGetProperty(DescType propertyCode)
00811 {
00812        Boolean       canGet = false;
00813        
00814        switch (propertyCode)
00815        {
00816               case pContents:
00817                      canGet = true;
00818                      break;
00819        }
00820        return canGet;
00821 }
00822 
00823 /*----------------------------------------------------------------------------
00824        CanSetProperty 
00825 
00826 ----------------------------------------------------------------------------*/
00827 Boolean AEGenericClass::CanSetProperty(DescType propertyCode)
00828 {
00829        return false;
00830 }
00831 
00832 
00833 #pragma mark -
00834 
00835 /*----------------------------------------------------------------------------
00836        CreateSpecifier 
00837 
00838        Subclasses should not need to override this. It 
00839 ----------------------------------------------------------------------------*/
00840 void AEGenericClass::CreateSpecifier(const AEDesc *token, AEDesc *outSpecifier)
00841 {
00842        CreateSelfSpecifier(token, outSpecifier);
00843 }
00844 
00845 /*----------------------------------------------------------------------------
00846        GetContainerSpecifier 
00847 
00848 ----------------------------------------------------------------------------*/
00849 void AEGenericClass::GetContainerSpecifier(const AEDesc *token, AEDesc *outContainerSpecifier)
00850 {
00851        outContainerSpecifier->descriptorType = typeNull;
00852        outContainerSpecifier->dataHandle = nil;
00853        
00854        AEDispatchHandler*   handler = AECoreClass::GetDispatchHandlerForClass(mContainerClass);
00855        if (handler)
00856        {
00857               handler->CreateSelfSpecifier(token, outContainerSpecifier);
00858        }
00859 }
00860 
00861 #pragma mark -
00862 
00863 /*----------------------------------------------------------------------------
00864        GetPropertyFromListOrObject 
00865 
00866 ----------------------------------------------------------------------------*/
00867 void AEGenericClass::GetPropertyFromListOrObject(              DescType                    desiredClass,
00868                                                                                     const AEDesc*        containerToken,
00869                                                                                     DescType                    containerClass,
00870                                                                                     DescType                    keyForm,
00871                                                                                     const AEDesc*        keyData,
00872                                                                                     AEDesc*                     resultToken)
00873 {
00874        if (AEListUtils::TokenContainsTokenList((AEDescList*)containerToken) == false)
00875        {
00876               GetPropertyFromObject(desiredClass, containerToken, containerClass, keyForm, keyData, resultToken);
00877        }
00878        else
00879        {
00880               OSErr  err = AECreateList(nil, 0, false, resultToken);
00881               ThrowIfOSErr(err);
00882               
00883               GetPropertyFromList(desiredClass, containerToken, containerClass, keyForm, keyData, resultToken);
00884        }
00885 }
00886 
00887 
00888 /*----------------------------------------------------------------------------
00889        GetPropertyFromList 
00890 
00891 ----------------------------------------------------------------------------*/
00892 void AEGenericClass::GetPropertyFromList(                      DescType                    desiredClass,
00893                                                                                     const AEDesc*        containerToken,
00894                                                                                     DescType                    containerClass,
00895                                                                                     DescType                    keyForm,
00896                                                                                     const AEDesc*        keyData,
00897                                                                                     AEDesc*                     resultToken)
00898 {
00899        OSErr         err           = noErr;
00900        long                 itemNum;
00901        long                 numItems;
00902        DescType             keyword;
00903        
00904        err = AECountItems((AEDescList*)containerToken, &numItems);
00905        ThrowIfOSErr(err);
00906               
00907        for (itemNum = 1; itemNum <= numItems; itemNum++)
00908        {
00909               StAEDesc             srcItem;
00910               StAEDesc             dstItem;
00911               
00912               err = AEGetNthDesc(containerToken, itemNum, typeWildCard, &keyword, &srcItem);
00913               ThrowIfOSErr(err);
00914               
00915               if (AEListUtils::TokenContainsTokenList(&srcItem) == false)
00916               {
00917                      GetPropertyFromObject(desiredClass, &srcItem, containerClass, keyForm, keyData, &dstItem);
00918               }
00919               else
00920               {
00921                      err = AECreateList(nil, 0, false, &dstItem);
00922                      ThrowIfOSErr(err);
00923                      
00924                      GetPropertyFromList(desiredClass, &srcItem, containerClass, keyForm, keyData, &dstItem);
00925               }
00926 
00927               err = AEPutDesc(resultToken, itemNum, &dstItem);
00928               ThrowIfOSErr(err);
00929        }
00930        
00931 }
00932 
00933 
00934 /*----------------------------------------------------------------------------
00935        GetPropertyFromObject 
00936 
00937 ----------------------------------------------------------------------------*/
00938 void AEGenericClass::GetPropertyFromObject(                    DescType                    desiredType,
00939                                                                              const AEDesc*        containerToken,
00940                                                                              DescType                    containerClass,
00941                                                                              DescType                    keyForm,
00942                                                                              const AEDesc*        keyData,
00943                                                                              AEDesc*                     resultToken)
00944 {
00945        OSErr                err;   
00946        DescType                    requestedProperty;
00947 
00948        err = AEDuplicateDesc(containerToken, resultToken);
00949        ThrowIfOSErr(err);
00950               
00951        requestedProperty = **(DescType**)(keyData->dataHandle);
00952        
00953        if (requestedProperty == kAEAll || requestedProperty == keyAEProperties)
00954               requestedProperty = pProperties;
00955 
00956        if (CanGetProperty(requestedProperty) || CanSetProperty(requestedProperty))
00957        {
00958               AETokenDesc          resultTokenDesc(resultToken);
00959               resultToken->descriptorType = desiredType;
00960               resultTokenDesc.SetPropertyCode(requestedProperty);
00961        }
00962        else
00963        {
00964               ThrowIfOSErr(errAEEventNotHandled);
00965        }
00966 }
00967 
00968 
00969 #pragma mark -
00970 
00971 
00972 /*----------------------------------------------------------------------------
00973        MakeNewObject 
00974 
00975 ----------------------------------------------------------------------------*/
00976 void AEGenericClass::MakeNewObject(                            const DescType              insertionPosition,
00977                                                                              const AEDesc*        token,
00978                                                                              const AEDesc*        ptrToWithData, 
00979                                                                              const AEDesc*        ptrToWithProperties,
00980                                                                              AppleEvent*          reply)
00981 {
00982        ThrowOSErr(errAEEventNotHandled);
00983 }
00984