Back to index

lightning-sunbird  0.9+nobinonly
nsAEWindowClass.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 <string.h>
00041 #include <AEPackObject.h>
00042 
00043 #include "nsMemory.h"
00044 #include "nsWindowUtils.h"
00045 
00046 #include "nsAppleEvents.h"
00047 
00048 #include "nsAEUtils.h"
00049 #include "nsAETokens.h"
00050 #include "nsAECoreClass.h"
00051 #include "nsAEApplicationClass.h"
00052 
00053 #include "nsAEWindowClass.h"
00054 
00055 #include "nsGfxUtils.h"
00056 
00057 using namespace nsWindowUtils;
00058 
00059 /*----------------------------------------------------------------------------
00060        GetNumItems 
00061        
00062 ----------------------------------------------------------------------------*/
00063 UInt32 AEWindowIterator::GetNumItems(const AEDesc* containerToken)
00064 {
00065        return CountWindowsOfKind(mWindowKind);
00066 }
00067 
00068 /*----------------------------------------------------------------------------
00069        GetNamedItemReference 
00070        
00071 ----------------------------------------------------------------------------*/
00072 AEClassIterator::ItemRef AEWindowIterator::GetNamedItemReference(const AEDesc* containerToken, const char *itemName)
00073 {
00074        WindowPtr     wind;
00075        wind = GetNamedOrFrontmostWindow(mWindowKind, itemName);
00076        return (wind) ? (ItemRef)wind : kNoItemRef;
00077 }
00078 
00079 /*----------------------------------------------------------------------------
00080        GetIndexedItemReference 
00081        
00082 ----------------------------------------------------------------------------*/
00083 AEClassIterator::ItemRef AEWindowIterator::GetIndexedItemReference(const AEDesc* containerToken, TAEListIndex itemIndex)
00084 {
00085        WindowPtr     wind = GetIndexedWindowOfKind(mWindowKind, itemIndex);
00086        return (wind) ? (ItemRef)wind : kNoItemRef;
00087 }
00088 
00089 /*----------------------------------------------------------------------------
00090        GetNamedItemID 
00091        
00092        Window refs and IDs are the same for windows
00093 ----------------------------------------------------------------------------*/
00094 AEClassIterator::ItemID AEWindowIterator::GetNamedItemID(const AEDesc* containerToken, const char *itemName)
00095 {
00096        WindowPtr     wind;
00097        wind = GetNamedOrFrontmostWindow(mWindowKind, itemName);
00098        return (wind) ? (ItemRef)wind : kNoItemID;
00099 }
00100 
00101 /*----------------------------------------------------------------------------
00102        GetIndexFromItemID 
00103        
00104 ----------------------------------------------------------------------------*/
00105 TAEListIndex AEWindowIterator::GetIndexFromItemID(const AEDesc* containerToken, ItemID itemID)
00106 {
00107        return GetWindowIndex(mWindowKind, (WindowPtr)itemID);
00108 }
00109 
00110 /*----------------------------------------------------------------------------
00111        GetIndexedItemID 
00112        
00113 ----------------------------------------------------------------------------*/
00114 AEClassIterator::ItemID AEWindowIterator::GetIndexedItemID(const AEDesc* containerToken, TAEListIndex itemIndex)
00115 {
00116        WindowPtr     wind = GetIndexedWindowOfKind(mWindowKind, itemIndex);
00117        return (wind) ? (ItemRef)wind : kNoItemID;
00118 }
00119 
00120 /*----------------------------------------------------------------------------
00121        GetIndexedItemName 
00122        
00123 ----------------------------------------------------------------------------*/
00124 void   AEWindowIterator::GetIndexedItemName(const AEDesc* containerToken, TAEListIndex itemIndex, char *outName, long maxLen)
00125 {
00126        WindowPtr     wind = GetIndexedWindowOfKind(mWindowKind, itemIndex);
00127        GetCleanedWindowName(wind, outName, maxLen);
00128 }
00129 
00130 /*----------------------------------------------------------------------------
00131        GetIDFromReference 
00132        
00133 ----------------------------------------------------------------------------*/
00134 AEClassIterator::ItemID AEWindowIterator::GetIDFromReference(const AEDesc* containerToken, ItemRef itemRef)
00135 {
00136        return (ItemID)itemRef;
00137 }
00138 
00139 /*----------------------------------------------------------------------------
00140        GetReferenceFromID 
00141        
00142 ----------------------------------------------------------------------------*/
00143 AEClassIterator::ItemRef AEWindowIterator::GetReferenceFromID(const AEDesc* containerToken, ItemID itemID)
00144 {
00145        return (ItemRef)itemID;
00146 }
00147 
00148 /*----------------------------------------------------------------------------
00149        GetItemIDFromToken 
00150        
00151 ----------------------------------------------------------------------------*/
00152 AEClassIterator::ItemID AEWindowIterator::GetItemIDFromToken(const AEDesc* token)
00153 {
00154        ConstAETokenDesc     tokenDesc(token);
00155        return (ItemID)tokenDesc.GetWindowPtr();
00156 }
00157 
00158 /*----------------------------------------------------------------------------
00159        SetItemIDInCoreToken 
00160        
00161 ----------------------------------------------------------------------------*/
00162 void AEWindowIterator::SetItemIDInCoreToken(const AEDesc* containerToken, CoreTokenRecord* tokenRecord, ItemID itemID)
00163 {
00164        tokenRecord->window = (WindowPtr)itemID;
00165 }
00166 
00167 
00168 #pragma mark -
00169 
00170 /*----------------------------------------------------------------------------
00171        AEWindowClass 
00172        
00173 ----------------------------------------------------------------------------*/
00174 AEWindowClass::AEWindowClass(DescType classType, TWindowKind windowKind)
00175 :      AEGenericClass(classType, typeNull)
00176 ,      mWindowKind(windowKind)
00177 ,      mDocumentAccessor(nil)
00178 {
00179 }
00180 
00181 /*----------------------------------------------------------------------------
00182        ~AEWindowClass 
00183        
00184 ----------------------------------------------------------------------------*/
00185 AEWindowClass::~AEWindowClass()
00186 {
00187        if (mDocumentAccessor)
00188               DisposeOSLAccessorUPP(mDocumentAccessor);
00189 }
00190 
00191 #pragma mark -
00192 
00193 
00194 /*----------------------------------------------------------------------------
00195        GetItemFromContainer 
00196        
00197 ----------------------------------------------------------------------------*/
00198 void AEWindowClass::GetItemFromContainer(        DescType                    desiredClass,
00199                                                                       const AEDesc*        containerToken,
00200                                                                       DescType                    containerClass, 
00201                                                                       DescType                    keyForm,
00202                                                                       const AEDesc*        keyData,
00203                                                                       AEDesc*                     resultToken)
00204 {
00205        AEWindowIterator            windowIterator(GetClass(), GetThisWindowKind());
00206        windowIterator.GetItemFromContainer(desiredClass, containerToken, containerClass, keyForm, keyData, resultToken);
00207 }
00208 
00209 /*----------------------------------------------------------------------------
00210        CompareObjects 
00211        
00212 ----------------------------------------------------------------------------*/
00213 void AEWindowClass::CompareObjects(                            DescType                    comparisonOperator,
00214                                                                              const AEDesc *              object1,
00215                                                                              const AEDesc *              object2,
00216                                                                              Boolean *                   result)
00217 {
00218        
00219 
00220 }
00221 
00222 
00223 /*----------------------------------------------------------------------------
00224        CountObjects 
00225        
00226 ----------------------------------------------------------------------------*/
00227 void AEWindowClass::CountObjects(                       DescType                    desiredType,
00228                                                                       DescType                    containerClass,
00229                                                                       const AEDesc *              container,
00230                                                                       long *               result)
00231 {
00232        *result = CountWindows(mWindowKind);
00233 }
00234 
00235 #pragma mark -
00236 
00237 /*----------------------------------------------------------------------------
00238        HandleClose 
00239        
00240 ----------------------------------------------------------------------------*/
00241 void AEWindowClass::HandleClose(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00242 {
00243        OSErr         err    = noErr;      
00244        
00245        StAEDesc             saving;
00246        StAEDesc             savingIn;
00247        
00248        AEDesc        *ptrToSaving  = nil;
00249        AEDesc        *ptrToSavingIn = nil;
00250        
00251        // Extract the [saving yes/no/ask] optional parameter, if present
00252        err = AEGetParamDesc(appleEvent, keyAESaveOptions, typeWildCard, &saving);
00253        
00254        if (err == noErr)
00255               ptrToSaving = &saving;
00256        else if (err == errAEDescNotFound)
00257           err = noErr;
00258        else
00259               ThrowIfOSErr(err);
00260        
00261        // Extract the [saving in <alias>] optional parameter, if present
00262        err = AEGetParamDesc(appleEvent, keyAEFile, typeFSS, &savingIn);
00263        
00264        if (err == noErr)
00265               ptrToSavingIn = &savingIn;
00266        else if (err == errAEDescNotFound)
00267           err = noErr;
00268        else
00269               ThrowIfOSErr(err);
00270 
00271        // Check for any required parameters we may have missed
00272        err = CheckForUnusedParameters(appleEvent);
00273        ThrowIfOSErr(err);
00274               
00275        // Now, do the application-related work
00276        if (AEListUtils::TokenContainsTokenList(token))
00277        {
00278               long                 numItems;
00279               long                 itemNum;
00280               AEKeyword     keyword;
00281                             
00282               err = AECountItems(token, &numItems);
00283               ThrowIfOSErr(err);
00284               
00285               if (numItems > 0)
00286               {
00287                      for (itemNum = 1; itemNum <= numItems; itemNum++)
00288                      {
00289                             StAEDesc             windowToken;
00290                             err = AEGetNthDesc(token, itemNum, typeWildCard, &keyword, &windowToken);
00291                             if (err != noErr) break;
00292                                    
00293                             //AECoreClass::sAECoreHandler->GetDocumentClass()->CloseWindowSaving(&windowToken, ptrToSaving, ptrToSavingIn);
00294                      }
00295               }
00296        }
00297        else
00298        {
00299               //AECoreClass::sAECoreHandler->GetDocumentClass()->CloseWindowSaving(token, ptrToSaving, ptrToSavingIn);
00300        }
00301 }
00302 
00303 /*----------------------------------------------------------------------------
00304        HandleDataSize 
00305        
00306 ----------------------------------------------------------------------------*/
00307 void AEWindowClass::HandleDataSize(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00308 {
00309        ThrowIfOSErr(errAEEventNotHandled);
00310 }
00311 
00312 /*----------------------------------------------------------------------------
00313        HandleDelete 
00314 
00315        All attempts to delete an empty list are handled here
00316        Application contains documents and windows, and they can't be deleted
00317        
00318 ----------------------------------------------------------------------------*/
00319 void AEWindowClass::HandleDelete(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00320 {
00321        ThrowIfOSErr(errAEEventNotHandled);
00322 }
00323 
00324 /*----------------------------------------------------------------------------
00325        HandleDuplicate 
00326        
00327 ----------------------------------------------------------------------------*/
00328 void AEWindowClass::HandleDuplicate(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00329 {
00330        ThrowIfOSErr(errAEEventNotHandled);
00331 }
00332 
00333 /*----------------------------------------------------------------------------
00334        HandleExists 
00335 
00336 ----------------------------------------------------------------------------*/
00337 void AEWindowClass::HandleExists(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00338 {
00339        ThrowIfOSErr(errAEEventNotHandled);
00340 }
00341 
00342 /*----------------------------------------------------------------------------
00343        HandleMake 
00344 
00345        We can't make generic windows.
00346        
00347 ----------------------------------------------------------------------------*/
00348 void AEWindowClass::HandleMake(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00349 {
00350        ThrowIfOSErr(errAEEventNotHandled);
00351 }
00352 
00353 /*----------------------------------------------------------------------------
00354        HandleMove 
00355 
00356        
00357 ----------------------------------------------------------------------------*/
00358 void AEWindowClass::HandleMove(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00359 {
00360        ThrowIfOSErr(errAEEventNotHandled);
00361 }
00362 
00363 /*----------------------------------------------------------------------------
00364        HandleOpen 
00365 
00366        
00367 ----------------------------------------------------------------------------*/
00368 void AEWindowClass::HandleOpen(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00369 {
00370        ThrowIfOSErr(errAEEventNotHandled);
00371 }
00372 
00373 /*----------------------------------------------------------------------------
00374        HandlePrint 
00375 
00376        
00377 ----------------------------------------------------------------------------*/
00378 void AEWindowClass::HandlePrint(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00379 {
00380        ThrowIfOSErr(errAEEventNotHandled);
00381 }
00382 
00383 /*----------------------------------------------------------------------------
00384        HandleQuit 
00385 
00386        
00387 ----------------------------------------------------------------------------*/
00388 void AEWindowClass::HandleQuit(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00389 {
00390        ThrowIfOSErr(errAEEventNotHandled);
00391 }
00392 
00393 /*----------------------------------------------------------------------------
00394        HandleSave 
00395 
00396        
00397 ----------------------------------------------------------------------------*/
00398 void AEWindowClass::HandleSave(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
00399 {
00400        ThrowIfOSErr(errAEEventNotHandled);
00401 }
00402 
00403 #pragma mark -
00404 
00405 
00406 /*----------------------------------------------------------------------------
00407        GetDataFromObject 
00408 
00409        
00410 ----------------------------------------------------------------------------*/
00411 void AEWindowClass::GetDataFromObject(const AEDesc *token, AEDesc *desiredTypes, AEDesc *data)
00412 {
00413        OSErr                err                         = noErr;
00414        
00415        ConstAETokenDesc            tokenDesc(token);
00416        DescType                    aType = mClass;
00417        Rect                        aRect;
00418        
00419        Point                       aPoint;
00420        Boolean                     aBoolean;
00421        long                        index;
00422        CStr255                     windowTitle;
00423        char*                       urlString = NULL;
00424        
00425        DescType                    propertyCode         = tokenDesc.GetPropertyCode();
00426        WindowPtr            window                      = tokenDesc.GetWindowPtr();
00427               
00428        switch (propertyCode)
00429        {
00430               case pProperties:
00431                      err = AECreateList(NULL, 0L, true, data);
00432                      ThrowIfOSErr(err);
00433 
00434                      err = AEPutKeyPtr(data, pObjectType, typeType, &aType, sizeof(DescType));
00435 
00436                      GetCleanedWindowName(window, windowTitle, 255);
00437                      err = AEPutKeyPtr(data, pTitle,  typeChar, windowTitle, strlen(windowTitle));
00438                      
00439                      GetWindowUrlString(window, &urlString);
00440                      if (urlString)
00441                      {
00442                             err = AEPutKeyPtr(data, AE_www_typeWindowURL,  typeChar, urlString, strlen(urlString));
00443                             nsMemory::Free(urlString); urlString = NULL;
00444                      }
00445                      
00446                      index = GetWindowIndex(GetThisWindowKind(), window);
00447                      err = AEPutKeyPtr(data, pIndex, typeLongInteger, &index, sizeof(long));
00448 
00449                      GetWindowGlobalBounds(window, &aRect);
00450                      err = AEPutKeyPtr(data, pBounds, typeQDRectangle, &aRect, sizeof(Rect));
00451                      aPoint.h = aRect.left;
00452                      aPoint.v = aRect.top;
00453                      err = AEPutKeyPtr(data, pLocation, typeQDPoint, &aPoint, sizeof(Point));
00454                      
00455                      aBoolean = WindowIsCloseable(window);
00456                      err = AEPutKeyPtr(data, pHasCloseBox, typeBoolean, &aBoolean, sizeof(Boolean));
00457 
00458                      aBoolean = WindowHasTitleBar(window);
00459                      err = AEPutKeyPtr(data, pHasTitleBar, typeBoolean, &aBoolean, sizeof(Boolean));
00460 
00461                      aBoolean = WindowIsModal(window);
00462                      err = AEPutKeyPtr(data, pIsModal, typeBoolean, &aBoolean, sizeof(Boolean));
00463 
00464                      aBoolean = WindowIsResizeable(window);
00465                      err = AEPutKeyPtr(data, pIsResizable, typeBoolean, &aBoolean, sizeof(Boolean));
00466 
00467                      aBoolean = WindowIsZoomable(window);
00468                      err = AEPutKeyPtr(data, pIsZoomable, typeBoolean, &aBoolean, sizeof(Boolean));
00469 
00470                      aBoolean = WindowIsZoomed(window);
00471                      err = AEPutKeyPtr(data, pIsZoomed, typeBoolean, &aBoolean, sizeof(Boolean));
00472                      
00473                      aBoolean = !WindowIsModal(window);
00474                      err = AEPutKeyPtr(data, pIsModeless, typeBoolean, &aBoolean, sizeof(Boolean));
00475                      
00476                      aBoolean = WindowIsModal(window) && WindowHasTitleBar(window);
00477                      err = AEPutKeyPtr(data, pIsMovableModal, typeBoolean, &aBoolean, sizeof(Boolean));
00478                      
00479                      aBoolean = WindowIsFloating(window);
00480                      err = AEPutKeyPtr(data, pIsFloating, typeBoolean, &aBoolean, sizeof(Boolean));
00481                      
00482                      aBoolean = IsWindowVisible(window);
00483                      err = AEPutKeyPtr(data, pVisible, typeBoolean, &aBoolean, sizeof(Boolean));
00484                      break;
00485                                                  
00486               case pBestType:
00487               case pClass:
00488               case pDefaultType:
00489               case pObjectType:
00490                      err = AECreateDesc(typeType, &aType, sizeof(DescType), data);
00491                      break;
00492                                    
00493               case pBounds:
00494                      GetWindowGlobalBounds(window, &aRect);
00495                      err = AECreateDesc(typeQDRectangle, &aRect, sizeof(Rect), data);
00496                      break;
00497                      
00498               case pLocation:
00499                      GetWindowGlobalBounds(window, &aRect);
00500                      aPoint.h = aRect.left;
00501                      aPoint.v = aRect.top;
00502                      err = AECreateDesc(typeQDPoint, &aPoint, sizeof(Point), data);
00503                      break;
00504                      
00505               case pIsModeless:
00506                      aBoolean = !WindowIsModal(window);
00507                      err = AECreateDesc(typeBoolean, &aBoolean, sizeof(Boolean), data);
00508                      break;
00509                      
00510               case pIsMovableModal:
00511                      aBoolean = WindowIsModal(window) && WindowHasTitleBar(window);
00512                      err = AECreateDesc(typeBoolean, &aBoolean, sizeof(Boolean), data);
00513                      break;
00514                                                                              
00515               case pHasCloseBox:
00516                      aBoolean = WindowIsCloseable(window);
00517                      err = AECreateDesc(typeBoolean, &aBoolean, sizeof(Boolean), data);
00518                      break;
00519                      
00520               case pHasTitleBar:
00521                      aBoolean = WindowHasTitleBar(window);
00522                      err = AECreateDesc(typeBoolean, &aBoolean, sizeof(Boolean), data);
00523                      break;
00524                      
00525               case pIndex:
00526                      index = GetWindowIndex(GetThisWindowKind(), window);
00527                      err = AECreateDesc(typeLongInteger, &index, sizeof(long), data);
00528                      break;
00529                                                  
00530               case pIsModal:
00531                      aBoolean = WindowIsModal(window);
00532                      err = AECreateDesc(typeBoolean, &aBoolean, sizeof(Boolean), data);
00533                      break;
00534                      
00535               case pIsResizable:
00536                      aBoolean = WindowIsResizeable(window);
00537                      err = AECreateDesc(typeBoolean, &aBoolean, sizeof(Boolean), data);
00538                      break;
00539                      
00540               case pIsZoomable:
00541                      aBoolean = WindowIsZoomable(window);
00542                      err = AECreateDesc(typeBoolean, &aBoolean, sizeof(Boolean), data);
00543                      break;
00544                      
00545               case pIsZoomed:
00546                      aBoolean = WindowIsZoomed(window);
00547                      err = AECreateDesc(typeBoolean, &aBoolean, sizeof(Boolean), data);
00548                      break;
00549                      
00550               case pVisible:
00551                      aBoolean = IsWindowVisible(window);
00552                      err = AECreateDesc(typeBoolean, &aBoolean, sizeof(Boolean), data);
00553                      break;
00554               
00555               case pIsFloating:
00556                      aBoolean = WindowIsFloating(window);
00557                      err = AECreateDesc(typeBoolean, &aBoolean, sizeof(Boolean), data);
00558                      break;
00559                      
00560               case pName:          // Synonym for pTitle
00561               case pTitle:
00562                      GetCleanedWindowName(window, windowTitle, 255);
00563                      err = AECreateDesc(typeChar, windowTitle, strlen(windowTitle), data);
00564                      break;
00565                                                  
00566               case AE_www_typeWindowURL:
00567                  GetWindowUrlString(window, &urlString);
00568                  if (urlString)
00569                  {
00570                         err = AECreateDesc(typeChar, urlString, strlen(urlString), data);
00571                         nsMemory::Free(urlString); urlString = NULL;
00572                       }
00573                  break;
00574                                                  
00575               default:
00576                      Inherited::GetDataFromObject(token, desiredTypes, data);
00577                      break;
00578        }
00579        
00580        ThrowIfOSErr(err);
00581 }
00582 
00583 /*----------------------------------------------------------------------------
00584        SetDataForObject 
00585 
00586        
00587 ----------------------------------------------------------------------------*/
00588 void AEWindowClass::SetDataForObject(const AEDesc *token, AEDesc *data)
00589 {
00590        OSErr         err;
00591        
00592        ConstAETokenDesc     tokenDesc(token);
00593 
00594        Boolean              usePropertyCode      = tokenDesc.UsePropertyCode();
00595        WindowPtr     window                      = tokenDesc.GetWindowPtr();
00596               
00597        if (usePropertyCode == false)
00598        {
00599               ThrowIfOSErr(errAEWriteDenied);
00600        }
00601        else
00602        {
00603               DescType      propertyCode = tokenDesc.GetPropertyCode();
00604               
00605               // Convert the single property to a record containing one property
00606 
00607               if (data->descriptorType == typeAERecord)
00608               {             
00609                      SetWindowProperties(window, data);
00610               }
00611               else   // Build a record with one property
00612               {
00613                      StAEDesc             propertyRecord;
00614                      
00615                      err = AECreateList(nil, 0, true, &propertyRecord);
00616                      ThrowIfOSErr(err);
00617                      
00618                      err = AEPutKeyDesc(&propertyRecord, propertyCode, data);
00619                      ThrowIfOSErr(err);
00620               
00621                      SetWindowProperties(window, &propertyRecord);
00622               }
00623        }
00624 }
00625 
00626 #pragma mark -
00627 
00628 /*----------------------------------------------------------------------------
00629        CanSetProperty 
00630 
00631        
00632 ----------------------------------------------------------------------------*/
00633 Boolean AEWindowClass::CanSetProperty(DescType propertyCode)
00634 {
00635        Boolean       result = false;
00636               
00637        switch (propertyCode)
00638        {
00639               // Properties we can set:
00640                                           
00641               case pProperties:
00642                      result = true;
00643                      break;
00644                      
00645               // Properties that can be set only for certain types of windows:
00646               
00647               case pTitle:
00648               case pName:   // Synonym for pTitle
00649 
00650               case pBounds:
00651               case pLocation:
00652               case pIndex:
00653               case pVisible:
00654               case pIsZoomed:
00655                      result = true;
00656                      break;
00657               
00658               // Properties we should be able to set, but not implemented yet:
00659               case AE_www_typeWindowURL:
00660                      result = false;
00661                      break;
00662 
00663               // Properties we can't set:
00664 
00665               default:
00666               case pBestType:
00667               case pClass:
00668               case pDefaultType:
00669               case pObjectType:
00670                             
00671               case pIsModeless:
00672               case pIsMovableModal:
00673               case pIsSuspended:
00674               case pIsPalette:
00675               case pIsDialog:
00676 
00677               case pHasCloseBox:
00678               case pHasTitleBar:
00679 
00680               case pIsFloating:
00681               case pIsModal:
00682               case pIsResizable:
00683               case pIsZoomable:
00684                      result = Inherited::CanSetProperty(propertyCode);
00685                      break;
00686        }
00687 
00688        return result;
00689 }
00690 
00691 
00692 /*----------------------------------------------------------------------------
00693        CanGetProperty 
00694 
00695        
00696 ----------------------------------------------------------------------------*/
00697 Boolean AEWindowClass::CanGetProperty(DescType propertyCode)
00698 {
00699        Boolean       result = false;
00700        
00701        switch (propertyCode)
00702        {
00703               // Properties we can get:
00704               
00705               case pBestType:
00706               case pClass:
00707               case pDefaultType:
00708               case pObjectType:
00709               
00710               case pContents:
00711               
00712               case pProperties:
00713               case keyAEProperties:
00714               
00715               case pTitle:
00716               case pName:   // Synonym for pTitle
00717               
00718               case AE_www_typeWindowURL:
00719               
00720               case pIsModeless:
00721               case pIsMovableModal:
00722               case pIsSuspended:
00723               case pIsPalette:
00724               case pIsDialog:
00725               
00726               case pBounds:
00727               case pLocation:
00728 
00729               case pHasCloseBox:
00730               case pHasTitleBar:
00731               case pIndex:
00732 
00733               case pIsFloating:
00734               case pIsModal:
00735               case pIsResizable:
00736               case pIsZoomable:
00737 
00738               case pIsZoomed:
00739               case pVisible:
00740                      result = true;
00741                      break;
00742                      
00743               // Properties we can't get:
00744               default:
00745                      result = Inherited::CanGetProperty(propertyCode);
00746                      break;
00747        }
00748 
00749        return result;
00750 }
00751 
00752 #pragma mark -
00753 
00754 /*----------------------------------------------------------------------------
00755        SetWindowProperties 
00756 
00757        
00758 ----------------------------------------------------------------------------*/
00759 void AEWindowClass::SetWindowProperties(WindowPtr window, const AEDesc *propertyRecord)
00760 {
00761        OSErr                       err                  = noErr;
00762        OSErr                       ignoreError   = noErr;
00763        long                               numProperties        = 0L;
00764        StAEDesc                           data;
00765        
00766        if (propertyRecord == nil || propertyRecord->descriptorType != typeAERecord)
00767        {
00768               ThrowIfOSErr(errAEWrongDataType);
00769        }
00770                             
00771        err = AECountItems(propertyRecord, &numProperties);
00772        ThrowIfOSErr(err);
00773        if (numProperties <= 0)
00774               ThrowIfOSErr(paramErr);
00775               
00776        StPortSetter  portSetter(window);
00777 
00778        // pBounds
00779        
00780        ignoreError = AEGetKeyDesc(propertyRecord, pBounds, typeQDRectangle, &data);
00781        if (ignoreError != errAEDescNotFound)
00782        {
00783               Rect r;
00784               err = DescToRect(&data, &r);
00785 
00786               if (err == noErr)
00787               {             
00788                      MoveWindow(window, r.left, r.top, false);
00789                      // short windowWidth =  r.right - r.left;
00790                      // short windowDepth =  r.bottom - r.top;
00791                      // DoResize(window, windowWidth, windowDepth);
00792               }
00793                                    
00794               data.Clear();
00795        }
00796 
00797        // pLocation
00798        
00799        ignoreError = AEGetKeyDesc(propertyRecord, pLocation, typeQDPoint, &data);
00800        if (ignoreError != errAEDescNotFound)
00801        {
00802               Point p;
00803               err = DescToPoint(&data, &p);
00804 
00805               if (err == noErr)
00806                      MoveWindow(window, p.h, p.v, false);  // don't let Window Manager bring it to front!
00807 
00808               data.Clear();
00809        }
00810 
00811        // pIndex
00812        
00813        ignoreError = AEGetKeyDesc(propertyRecord, pIndex, typeLongInteger, &data);
00814        if (ignoreError != errAEDescNotFound)
00815        {
00816               long                 index;
00817               long                 numWindows;
00818               WindowPtr     behindWindow;
00819               
00820               err = DescToLong(&data, &index);
00821 
00822               if (err == noErr)
00823               {      
00824                      numWindows = CountWindows(GetThisWindowKind());
00825                      if (index < 0)
00826                             index = numWindows + index + 1;
00827                      
00828                      if (index == 1)
00829                      {
00830                             SelectWindow(window);
00831                      }
00832                      else
00833                      {
00834                             behindWindow = GetWindowByIndex(GetThisWindowKind(), index);
00835                             if (behindWindow != NULL)
00836                             {
00837                                    SendBehind(window, behindWindow);
00838                             }
00839                             else
00840                             {
00841                                    err = errAEEventNotHandled;
00842                             }
00843                      }
00844               }                                  
00845 
00846               data.Clear();
00847        }
00848 
00849        // pIsZoomed
00850        
00851        ignoreError = AEGetKeyDesc(propertyRecord, pIsZoomed, typeBoolean, &data);
00852        if (ignoreError != errAEDescNotFound)
00853        {
00854               Boolean       zoomIt;
00855               
00856               err = DescToBoolean(&data, &zoomIt);
00857               
00858               if (err == noErr)
00859               {
00860                      if (zoomIt)
00861                             ZoomWindow(window, inZoomOut, false);
00862                      else
00863                             ZoomWindow(window, inZoomIn, false);
00864               }                                  
00865 
00866               data.Clear();
00867        }
00868 
00869        // pVisible
00870        
00871        ignoreError = AEGetKeyDesc(propertyRecord, pVisible, typeBoolean, &data);
00872        if (ignoreError != errAEDescNotFound)
00873        {
00874               Boolean showIt;
00875               err = DescToBoolean(&data, &showIt);
00876               
00877               if (err == noErr)
00878               {
00879                      if (showIt)
00880                             ShowWindow(window);
00881                      else
00882                             HideWindow(window);
00883               }                                  
00884 
00885               data.Clear();
00886        }
00887 }
00888 
00889 #pragma mark -
00890 
00891 
00892 /*----------------------------------------------------------------------------
00893        MakeWindowObjectSpecifier 
00894 
00895        
00896 ----------------------------------------------------------------------------*/
00897 void AEWindowClass::MakeWindowObjectSpecifier(WindowPtr wind, AEDesc *outSpecifier)
00898 {
00899        // fill in the reply with the newly created object
00900        CoreTokenRecord      coreToken;
00901        StAEDesc                    windowToken;
00902        
00903        coreToken.window = wind;
00904        
00905        OSErr  err = ::AECreateDesc(typeObjectSpecifier, &coreToken, sizeof(CoreTokenRecord), &windowToken);
00906        ThrowIfOSErr(err);
00907               
00908        CreateSelfSpecifier(&windowToken, outSpecifier);
00909 }
00910 
00911 
00912 /*----------------------------------------------------------------------------
00913        CreateSelfSpecifier 
00914 
00915 ----------------------------------------------------------------------------*/
00916 void AEWindowClass::CreateSelfSpecifier(const AEDesc *token, AEDesc *outSpecifier)
00917 {
00918        ConstAETokenDesc     tokenDesc(token);
00919        WindowPtr     window = tokenDesc.GetWindowPtr();
00920        long                 position = GetWindowIndex(mWindowKind, window);
00921        AEDesc        selfDesc = { typeNull, nil };
00922        AEDesc        containerSpecifier = { typeNull, nil };
00923        DescType             desiredClass = mClass;
00924        DescType             keyForm = formAbsolutePosition;
00925        OSErr         err = noErr;
00926        
00927        GetContainerSpecifier(token, &containerSpecifier);
00928        
00929        err = ::AECreateDesc(typeLongInteger, &position, sizeof(long), &selfDesc);
00930        ThrowIfOSErr(err);
00931        
00932        err = ::CreateObjSpecifier(desiredClass, &containerSpecifier, keyForm, &selfDesc, true, outSpecifier);
00933        ThrowIfOSErr(err);
00934 }
00935 
00936 #pragma mark -
00937 
00938 /*----------------------------------------------------------------------------
00939        CountWindows 
00940        
00941 ----------------------------------------------------------------------------*/
00942 long AEWindowClass::CountWindows(TWindowKind windowKind)
00943 {
00944        return CountWindowsOfKind(windowKind);
00945 }
00946 
00947 
00948 /*----------------------------------------------------------------------------
00949        GetWindowByIndex 
00950        
00951 ----------------------------------------------------------------------------*/
00952 WindowPtr AEWindowClass::GetWindowByIndex(TWindowKind windowKind, long index)
00953 {
00954        return GetIndexedWindowOfKind(windowKind, index);
00955 }
00956 
00957 /*----------------------------------------------------------------------------
00958        GetWindowByTitle 
00959        
00960 ----------------------------------------------------------------------------*/
00961 WindowPtr AEWindowClass::GetWindowByTitle(TWindowKind windowKind, ConstStr63Param title)
00962 {
00963        CStr255              windowName;
00964        CopyPascalToCString((const StringPtr)title, windowName, 255);
00965        return GetNamedOrFrontmostWindow(windowKind, windowName);
00966 }
00967 
00968 /*----------------------------------------------------------------------------
00969        GetWindowIndex 
00970        
00971 ----------------------------------------------------------------------------*/
00972 long AEWindowClass::GetWindowIndex(TWindowKind windowKind, WindowPtr window)
00973 {
00974        return nsWindowUtils::GetWindowIndex(windowKind, window);
00975 }
00976 
00977 
00978 /*----------------------------------------------------------------------------
00979        GetPreviousWindow 
00980        
00981 ----------------------------------------------------------------------------*/
00982 WindowPtr AEWindowClass::GetPreviousWindow(TWindowKind windowKind, WindowPtr wind)
00983 {
00984        short  windowIndex = GetWindowIndex(windowKind, wind);
00985        return GetIndexedWindowOfKind(windowKind, windowIndex - 1);
00986 }
00987 
00988