Back to index

lightning-sunbird  0.9+nobinonly
nsAETokens.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 
00041 #include "nsAETokens.h"
00042 
00043 // ---------------------------------------------------------------------------
00044 ConstAETokenDesc::ConstAETokenDesc(const AEDesc* token)
00045 {
00046        mTokenWasNull = (token->descriptorType == typeNull);
00047        
00048        if (!mTokenWasNull)
00049        {
00050               if (::AEGetDescDataSize(token) != sizeof(CoreTokenRecord))
00051                      ThrowOSErr(paramErr);                     // invalid token
00052 
00053               ThrowIfOSErr(::AEGetDescData(token, &mTokenRecord, sizeof(CoreTokenRecord)));
00054        }
00055 }
00056 
00057 
00058 // ---------------------------------------------------------------------------
00059 
00060 DescType ConstAETokenDesc::GetDispatchClass() const
00061 {
00062        ThrowErrIfTrue(mTokenWasNull, paramErr);
00063        return mTokenRecord.dispatchClass;
00064 }
00065 
00066 // ---------------------------------------------------------------------------
00067 
00068 DescType ConstAETokenDesc::GetObjectClass() const
00069 {
00070        ThrowErrIfTrue(mTokenWasNull, paramErr);
00071        return mTokenRecord.objectClass;
00072 }
00073 
00074 // ---------------------------------------------------------------------------
00075 // The field usePropertyCode has been removed from the token record,
00076 // so we emulate it here by seeing if the propertyCode field is typeNull,
00077 // which is interpreted to mean that this is NOT a property token
00078 
00079 Boolean ConstAETokenDesc::UsePropertyCode() const
00080 {
00081        ThrowErrIfTrue(mTokenWasNull, paramErr);
00082        return (mTokenRecord.propertyCode != typeNull);
00083 }
00084 
00085 // ---------------------------------------------------------------------------
00086 
00087 DescType ConstAETokenDesc::GetPropertyCode() const
00088 {
00089        ThrowErrIfTrue(mTokenWasNull, paramErr);
00090        return mTokenRecord.propertyCode;
00091 }
00092 
00093 // ---------------------------------------------------------------------------
00094 
00095 long ConstAETokenDesc::GetDocumentID() const
00096 {
00097        ThrowErrIfTrue(mTokenWasNull, paramErr);
00098        return mTokenRecord.documentID;
00099 }
00100 
00101 // ---------------------------------------------------------------------------
00102 
00103 WindowPtr ConstAETokenDesc::GetWindowPtr() const
00104 {
00105        ThrowErrIfTrue(mTokenWasNull, paramErr);
00106        return mTokenRecord.window;
00107 }
00108 
00109 
00110 // ---------------------------------------------------------------------------
00111 
00112 TAEListIndex ConstAETokenDesc::GetElementNumber() const
00113 {
00114        ThrowErrIfTrue(mTokenWasNull, paramErr);
00115        return mTokenRecord.elementNumber;
00116 }
00117 
00118 
00119 
00120 #pragma mark -
00121 
00122 // ---------------------------------------------------------------------------
00123 AETokenDesc::AETokenDesc(AEDesc* token)
00124 :      ConstAETokenDesc(token)
00125 ,      mTokenDesc(token)
00126 {
00127        if (mTokenWasNull)                 // we cannot wrap a null token
00128               ThrowOSErr(paramErr);
00129 }
00130 
00131 // ---------------------------------------------------------------------------
00132 AETokenDesc::~AETokenDesc()
00133 {
00134        UpdateDesc();        // update the AEDesc that we wrap
00135 }
00136 
00137 // ---------------------------------------------------------------------------
00138 
00139 void AETokenDesc::SetPropertyCode(DescType propertyCode)
00140 {
00141        mTokenRecord.propertyCode = propertyCode;
00142 }
00143 
00144 // ---------------------------------------------------------------------------
00145 void AETokenDesc::SetDispatchClass(DescType dispatchClass)
00146 {
00147        mTokenRecord.dispatchClass = dispatchClass;
00148 }
00149 
00150 
00151 // ---------------------------------------------------------------------------
00152 void AETokenDesc::SetObjectClass(DescType objectClass)
00153 {
00154        mTokenRecord.objectClass = objectClass;
00155 }
00156 
00157 // ---------------------------------------------------------------------------
00158 void AETokenDesc::SetElementNumber(TAEListIndex number)
00159 {
00160        mTokenRecord.elementNumber = number;
00161 }
00162 
00163 // ---------------------------------------------------------------------------
00164 void AETokenDesc::SetWindow(WindowPtr wind)
00165 {
00166        mTokenRecord.window = wind;
00167 }
00168 
00169 // ---------------------------------------------------------------------------
00170 void AETokenDesc::UpdateDesc()
00171 {
00172        OSErr  err = ::AEReplaceDescData(mTokenDesc->descriptorType, &mTokenRecord, sizeof(CoreTokenRecord), mTokenDesc);
00173        ThrowIfOSErr(err);
00174 }