Back to index

lightning-sunbird  0.9+nobinonly
nsWindowUtils.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 #include <MacWindows.h>
00040 
00041 #include "nsCommandLineServiceMac.h"
00042 #include "nsCOMPtr.h"
00043 #include "nsIBaseWindow.h"
00044 #include "nsIBrowserDOMWindow.h"
00045 #include "nsIContent.h"
00046 #include "nsIDocShell.h"
00047 #include "nsIDocShellTreeItem.h"
00048 #include "nsIDocument.h"
00049 #include "nsIDOMDocument.h"
00050 #include "nsIDOMWindow.h"
00051 #include "nsIDOMChromeWindow.h"
00052 #include "nsIDOMWindowInternal.h"
00053 #include "nsIDOMElement.h"
00054 #include "nsIDOMNode.h"
00055 #include "nsIServiceManager.h"
00056 #include "nsIWebNavigation.h"
00057 #include "nsIWidget.h"
00058 #include "nsIWindowMediator.h"
00059 #include "nsIURI.h"
00060 #include "nsIXULWindow.h"
00061 #include "nsString.h"
00062 #include "nsNetUtil.h"
00063 #include "nsWindowUtils.h"
00064 #include "nsMacUtils.h"
00065 #include "nsXPIDLString.h"
00066 #include "nsIXULWindow.h"
00067 #include "nsWindowUtils.h"
00068 #include "nsReadableUtils.h"
00069 
00070 #include "nsAEUtils.h"
00071 
00072 using namespace nsWindowUtils;
00073 
00074 // CIDs
00075 static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID);
00076 
00077 
00078 /*----------------------------------------------------------------------------
00079        GetXULWindowFromWindowPtr 
00080        
00081        Get an nsIXULWindow from a WindowPtr. Returns an ADDREFFED xulWindow,
00082        which you must release (hint: use an nsCOMPtr).
00083        
00084        Throws on error.
00085 ----------------------------------------------------------------------------*/
00086 
00087 static void GetXULWindowFromWindowPtr(WindowPtr inWindowPtr, nsIXULWindow **outXULWindow)
00088 {
00089        *outXULWindow = NULL;
00090        
00091        if (!inWindowPtr)
00092               ThrowOSErr(paramErr);
00093        
00094        nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID));
00095        ThrowErrIfNil(windowMediator, paramErr);
00096 
00097        nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
00098        if (NS_FAILED(windowMediator->GetXULWindowEnumerator(nsnull, getter_AddRefs(windowEnumerator))))
00099               ThrowOSErr(paramErr);                     // need a better error
00100 
00101        // Find the window
00102        while (true)
00103        {
00104               PRBool more = false;
00105               windowEnumerator->HasMoreElements(&more);
00106               if (!more)
00107                      break;
00108                      
00109               nsCOMPtr<nsISupports> nextWindow = nsnull;
00110               windowEnumerator->GetNext(getter_AddRefs(nextWindow));
00111               nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(nextWindow));
00112               if (NULL == baseWindow)
00113                   continue;
00114                   
00115               nsCOMPtr<nsIWidget> widget = nsnull;
00116               baseWindow->GetMainWidget(getter_AddRefs(widget));
00117               if (NULL == widget)
00118                   continue;
00119               
00120               WindowRef windowRef = (WindowRef)widget->GetNativeData(NS_NATIVE_DISPLAY);
00121               if ((WindowPtr)windowRef == inWindowPtr)
00122               {
00123                      // !!! There really must be an easier way to do this. JavaScript?
00124                      nsCOMPtr<nsIXULWindow> xulWindow(do_QueryInterface(nextWindow));
00125                      if (!xulWindow)
00126                             break;
00127                             
00128                      NS_ADDREF(*outXULWindow = xulWindow);
00129                      return;                            
00130               }             
00131        }
00132        
00133        // if we got here, we didn't find the window
00134        ThrowOSErr(paramErr);
00135 }
00136 
00137 
00138 /*----------------------------------------------------------------------------
00139        GetXULWindowTypeString
00140        
00141        Get the type string for a XUL window 
00142        
00143 ----------------------------------------------------------------------------*/
00144 static void GetXULWindowTypeString(nsIXULWindow *inXULWindow, nsString& outWindowType)
00145 {
00146        outWindowType.Truncate();
00147 
00148        if (inXULWindow)
00149        {
00150               nsCOMPtr<nsIDocShellTreeItem>             contentShell;
00151               inXULWindow->GetPrimaryContentShell(getter_AddRefs(contentShell));
00152               nsCOMPtr<nsIWebNavigation>                webNav(do_QueryInterface(contentShell));
00153               ThrowErrIfNil(webNav, paramErr);
00154 
00155               nsCOMPtr<nsIDOMDocument> domDoc;
00156               webNav->GetDocument(getter_AddRefs(domDoc));
00157               if (domDoc)
00158               {
00159              nsCOMPtr<nsIDOMElement> element;
00160              domDoc->GetDocumentElement(getter_AddRefs(element));
00161              if (element)
00162                element->GetAttribute(NS_LITERAL_STRING("windowtype"), outWindowType);             
00163               }
00164        }
00165 }
00166 
00167 
00168 /*----------------------------------------------------------------------------
00169        WindowKindFromTypeString
00170 
00171        
00172 ----------------------------------------------------------------------------*/
00173 static TWindowKind WindowKindFromTypeString(const nsString& inWindowType)
00174 {
00175        if (inWindowType.IsEmpty())
00176               return kAnyWindowKind;
00177               
00178        if (inWindowType.EqualsLiteral("navigator:browser"))
00179               return kBrowserWindowKind;
00180 
00181        if (inWindowType.EqualsLiteral("mail:3pane"))
00182               return kMailWindowKind;
00183 
00184        if (inWindowType.EqualsLiteral("msgcompose"))
00185               return kMailComposeWindowKind;
00186 
00187        if (inWindowType.EqualsLiteral("mail:addressbook"))
00188               return kAddressBookWindowKind;
00189 
00190        if (inWindowType.EqualsLiteral("composer:html"))
00191               return kComposerWindowKind;
00192 
00193        if (inWindowType.EqualsLiteral("composer:text"))
00194               return kComposerWindowKind;
00195 
00196        return kOtherWindowKind;
00197 }
00198 
00199 
00200 /*----------------------------------------------------------------------------
00201        GetXULWindowKind
00202 
00203        
00204 ----------------------------------------------------------------------------*/
00205 static TWindowKind GetXULWindowKind(nsIXULWindow *inXULWindow)
00206 {
00207        nsAutoString         windowType;
00208        GetXULWindowTypeString(inXULWindow, windowType);
00209        return WindowKindFromTypeString(windowType);
00210 }
00211 
00212 
00213 /*----------------------------------------------------------------------------
00214        CountWindowsOfKind 
00215        
00216 ----------------------------------------------------------------------------*/
00217 long nsWindowUtils::CountWindowsOfKind(TWindowKind windowKind)
00218 {
00219        nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID));
00220        ThrowErrIfNil(windowMediator, paramErr);
00221 
00222        nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
00223        if (NS_FAILED(windowMediator->GetXULWindowEnumerator(nsnull, getter_AddRefs(windowEnumerator))))
00224               ThrowOSErr(paramErr);                     // need a better error
00225 
00226        long windowCount = 0L;
00227        PRBool more;
00228        windowEnumerator->HasMoreElements(&more);
00229        while (more)
00230        {
00231               nsCOMPtr<nsISupports> nextWindow = nsnull;
00232               windowEnumerator->GetNext(getter_AddRefs(nextWindow));
00233               nsCOMPtr<nsIXULWindow> xulWindow(do_QueryInterface(nextWindow));
00234               if (!xulWindow) break;
00235               
00236               if (kAnyWindowKind == windowKind)
00237                      ++windowCount;
00238               else
00239               {
00240                      // Test window kind.
00241                      TWindowKind   thisWindowKind = GetXULWindowKind(xulWindow);
00242                      if (thisWindowKind == windowKind)
00243                             ++windowCount;
00244               }
00245               
00246               windowEnumerator->HasMoreElements(&more);
00247        }
00248 
00249        return windowCount;
00250 }
00251 
00252 
00253 WindowPtr nsWindowUtils::GetNamedOrFrontmostWindow(TWindowKind windowKind, const char* windowName)
00254 {
00255        // Search for window with the desired kind and name.
00256        nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID));
00257        ThrowErrIfNil(windowMediator, paramErr);
00258        
00259        nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
00260        if (NS_FAILED(windowMediator->GetXULWindowEnumerator(nsnull, getter_AddRefs(windowEnumerator))))
00261               ThrowOSErr(paramErr);                     // need a better error
00262    
00263   WindowPtr windowPtr = NULL;
00264        PRBool more;
00265        nsCString windowNameString(windowName);
00266        windowEnumerator->HasMoreElements(&more);
00267        while (more)
00268        {
00269               nsCOMPtr<nsISupports> nextWindow = nsnull;
00270               windowEnumerator->GetNext(getter_AddRefs(nextWindow));
00271               nsCOMPtr<nsIXULWindow> xulWindow(do_QueryInterface(nextWindow));
00272               if (!xulWindow) break;
00273 
00274               nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(xulWindow));
00275               ThrowErrIfNil(baseWindow, paramErr);
00276               
00277               nsCOMPtr<nsIWidget> widget = nsnull;
00278               baseWindow->GetMainWidget(getter_AddRefs(widget));
00279               ThrowErrIfNil(widget, paramErr);
00280 
00281               WindowRef     windowRef = (WindowRef)widget->GetNativeData(NS_NATIVE_DISPLAY);
00282               TWindowKind   thisWindowKind = GetXULWindowKind(xulWindow);
00283               
00284               // If this is the kind of window we are looking for...
00285               if (kAnyWindowKind == windowKind || (thisWindowKind == windowKind))
00286               {
00287                      if (NULL == windowName)
00288                      {
00289                          // ...see if its the frontmost of this kind.
00290                          PRInt32 zIndex;
00291                   widget->GetZIndex(&zIndex);
00292                   if (0L == zIndex)
00293                   {
00294                       windowPtr = (WindowPtr)windowRef;
00295                       break;
00296                   }
00297               }
00298               else
00299               {
00300                   // ...see if its name is the desired one.
00301                 Str255 pascalTitle;
00302                 GetWTitle(windowRef, pascalTitle);                                  
00303                      if (windowNameString.Compare((const char*)&pascalTitle[1], PR_FALSE, pascalTitle[0]) == 0)
00304                      {
00305                             windowPtr = (WindowPtr)windowRef;         // WindowRef is the WindowPtr.
00306                             break;
00307                      }
00308               }
00309               }
00310        
00311               windowEnumerator->HasMoreElements(&more);
00312        }
00313        
00314        return windowPtr;
00315 }
00316 
00317 
00318 WindowPtr nsWindowUtils::GetIndexedWindowOfKind(TWindowKind windowKind, TAEListIndex index)
00319 {
00320        nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID));
00321        ThrowErrIfNil(windowMediator, paramErr);
00322        
00323        nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
00324        if (NS_FAILED(windowMediator->GetZOrderXULWindowEnumerator(nsnull, PR_TRUE, getter_AddRefs(windowEnumerator))))
00325               ThrowOSErr(paramErr);                     // need a better error
00326    
00327   WindowPtr windowPtr = NULL;
00328        PRBool more;
00329        windowEnumerator->HasMoreElements(&more);
00330        while (more)
00331        {
00332               nsCOMPtr<nsISupports> nextWindow = nsnull;
00333               windowEnumerator->GetNext(getter_AddRefs(nextWindow));
00334               nsCOMPtr<nsIXULWindow> xulWindow(do_QueryInterface(nextWindow));
00335               if (!xulWindow) break;
00336 
00337               nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(xulWindow));
00338               ThrowErrIfNil(baseWindow, paramErr);
00339               
00340               nsCOMPtr<nsIWidget> widget = nsnull;
00341               baseWindow->GetMainWidget(getter_AddRefs(widget));
00342               ThrowErrIfNil(widget, paramErr);
00343 
00344               WindowRef     windowRef = (WindowRef)widget->GetNativeData(NS_NATIVE_DISPLAY);
00345               TWindowKind   thisWindowKind = GetXULWindowKind(xulWindow);
00346               
00347               // If this is the kind of window we are looking for...
00348               if (kAnyWindowKind == windowKind || (thisWindowKind == windowKind))
00349               {
00350                      // ...decrement index and test if this is the window at that index.
00351                      if (0L == --index)
00352                      {
00353                             windowPtr = (WindowPtr)windowRef;         // WindowRef is the WindowPtr.
00354                             break;
00355                      }
00356               }
00357        
00358               windowEnumerator->HasMoreElements(&more);
00359        }
00360 
00361        return windowPtr;
00362 }
00363 
00364 
00365 TAEListIndex nsWindowUtils::GetWindowIndex(TWindowKind windowKind, WindowPtr theWindow)
00366 {
00367        nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID));
00368        ThrowErrIfNil(windowMediator, paramErr);
00369 
00370        nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
00371        if (NS_FAILED(windowMediator->GetZOrderXULWindowEnumerator(nsnull, PR_TRUE, getter_AddRefs(windowEnumerator))))
00372               ThrowOSErr(paramErr);                     // need a better error
00373 
00374        TAEListIndex index = 0L;
00375        
00376        PRBool more;
00377        windowEnumerator->HasMoreElements(&more);
00378        while (more)
00379        {
00380               nsCOMPtr<nsISupports> nextWindow = nsnull;
00381               windowEnumerator->GetNext(getter_AddRefs(nextWindow));
00382               nsCOMPtr<nsIXULWindow> xulWindow(do_QueryInterface(nextWindow));
00383               if (!xulWindow) break;
00384 
00385               nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(xulWindow));
00386               ThrowErrIfNil(baseWindow, paramErr);
00387               
00388               nsCOMPtr<nsIWidget> widget = nsnull;
00389               baseWindow->GetMainWidget(getter_AddRefs(widget));
00390               ThrowErrIfNil(widget, paramErr);
00391               
00392               WindowRef     windowRef = (WindowRef)widget->GetNativeData(NS_NATIVE_DISPLAY);
00393               TWindowKind   thisWindowKind = GetXULWindowKind(xulWindow);
00394 
00395               if (kAnyWindowKind == windowKind || (thisWindowKind == windowKind))
00396               {
00397                      ++index;
00398                      
00399                      if ((WindowPtr)windowRef == theWindow)
00400                             return index;
00401               }
00402        
00403               windowEnumerator->HasMoreElements(&more);
00404        }
00405 
00406        return 0L; // error: theWindow wasn't found. Return an invalid index.
00407 }
00408 
00409 
00410 //---------------------------------------------------------
00411 void nsWindowUtils::GetCleanedWindowName(WindowPtr wind, char* outName, long maxLen)
00412 {
00413        Str255 uncleanName;
00414        GetWTitle(wind, uncleanName);
00415        CopyPascalToCString(uncleanName, outName, maxLen);
00416 }
00417 
00418 //---------------------------------------------------------
00419 void nsWindowUtils::GetWindowUrlString(WindowPtr wind, char** outUrlStringPtr)
00420 {
00421        *outUrlStringPtr = NULL;
00422 
00423        nsCOMPtr<nsIXULWindow>             xulWindow;
00424        GetXULWindowFromWindowPtr(wind, getter_AddRefs(xulWindow));
00425        ThrowErrIfNil(xulWindow, paramErr);
00426        
00427        nsCOMPtr<nsIDocShellTreeItem>             contentShell;
00428        xulWindow->GetPrimaryContentShell(getter_AddRefs(contentShell));
00429        nsCOMPtr<nsIWebNavigation>                webNav(do_QueryInterface(contentShell));
00430        ThrowErrIfNil(webNav, paramErr);
00431 
00432        nsCOMPtr<nsIURI> sourceURL;
00433        webNav->GetCurrentURI(getter_AddRefs(sourceURL));
00434        ThrowErrIfNil(sourceURL, paramErr);
00435        
00436        // Now get the string;
00437        nsCAutoString spec;
00438        sourceURL->GetSpec(spec);
00439        
00440        *outUrlStringPtr = ToNewCString(spec);           
00441 }
00442 
00443 
00444 //---------------------------------------------------------
00445 inline void GetWindowPortRect(WindowPtr wind, Rect *outRect)
00446 {
00447 #if OPAQUE_TOOLBOX_STRUCTS
00448     ::GetPortBounds(GetWindowPort(wind), outRect);
00449 #else
00450        *outRect = wind->portRect;
00451 #endif
00452 }
00453 
00454 /*----------------------------------------------------------------------------
00455        LocalToGlobalRect 
00456        
00457        Convert a rectangle from local to global coordinates.
00458                      
00459        Entry: r = pointer to rectangle.
00460 ----------------------------------------------------------------------------*/
00461 
00462 static void LocalToGlobalRect (Rect *r)
00463 {
00464        LocalToGlobal((Point*)&r->top);
00465        LocalToGlobal((Point*)&r->bottom);
00466 }
00467 
00468 void nsWindowUtils::GetWindowGlobalBounds(WindowPtr wind, Rect* outBounds)
00469 {
00470        GrafPtr       curPort;
00471        GetWindowPortRect(wind, outBounds);
00472        GetPort(&curPort);
00473        SetPortWindowPort(wind);
00474        LocalToGlobalRect(outBounds);
00475        SetPort(curPort);
00476 }
00477 
00478 
00479 /*----------------------------------------------------------------------------
00480        LoadURLInWindow 
00481 
00482 ----------------------------------------------------------------------------*/
00483 void nsWindowUtils::LoadURLInWindow(WindowPtr wind, const char* urlString)
00484 {
00485   OSErr err = noErr;
00486 
00487   if ( !wind )
00488   {
00489     // this makes a new window
00490     nsMacCommandLine&  cmdLine = nsMacCommandLine::GetMacCommandLine();
00491     err = cmdLine.DispatchURLToNewBrowser(urlString);
00492     ThrowIfOSErr(err);
00493   }
00494   else {
00495     // existing window. Go through hoops to load a URL in it
00496     nsCOMPtr<nsIXULWindow> xulWindow;
00497     GetXULWindowFromWindowPtr(wind, getter_AddRefs(xulWindow));
00498     ThrowErrIfNil(xulWindow, paramErr);
00499 
00500     LoadURLInXULWindow(xulWindow, urlString);
00501   }
00502 }
00503 
00504 void nsWindowUtils::LoadURLInXULWindow(nsIXULWindow* inWindow, const char* urlString)
00505 {
00506   nsCOMPtr<nsIDocShell> docShell;
00507   nsCOMPtr<nsIDocShellTreeItem> docItem;
00508   nsCOMPtr<nsIBrowserDOMWindow> bwin;
00509 
00510   // first try the nsIBrowserDOMWindow helper object
00511   // note the actual window used depends on user prefs. this may end up
00512   // using a different window!
00513 
00514   inWindow->GetDocShell(getter_AddRefs(docShell));
00515   docItem = do_QueryInterface(docShell);
00516   if (docItem) {
00517     nsCOMPtr<nsIDocShellTreeItem> rootItem;
00518     docItem->GetRootTreeItem(getter_AddRefs(rootItem));
00519     nsCOMPtr<nsIDOMWindow> rootWin(do_GetInterface(rootItem));
00520     nsCOMPtr<nsIDOMChromeWindow> chromeWin(do_QueryInterface(rootWin));
00521     if (chromeWin)
00522       chromeWin->GetBrowserDOMWindow(getter_AddRefs(bwin));
00523   }
00524   if (bwin) {
00525     nsCOMPtr<nsIURI> uri;
00526     nsDependentCString urlStr(urlString);
00527     NS_NewURI(getter_AddRefs(uri), urlStr, 0, 0);
00528     if (uri) {
00529       nsCOMPtr<nsIDOMWindow> newBrowserWindow;
00530       bwin->OpenURI(uri, 0,
00531                     nsIBrowserDOMWindow::OPEN_DEFAULTWINDOW,
00532                     nsIBrowserDOMWindow::OPEN_EXTERNAL,
00533                     getter_AddRefs(newBrowserWindow));
00534       if (newBrowserWindow)
00535         return;
00536     }
00537   }
00538 
00539   // fallback: navigate the XULWindow's content shell directly
00540 
00541   inWindow->GetPrimaryContentShell(getter_AddRefs(docItem));
00542   ThrowErrIfNil(docItem, paramErr);
00543 
00544   nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docItem));
00545   ThrowErrIfNil(webNav, paramErr);
00546 
00547   nsAutoString urlWString; urlWString.AssignWithConversion(urlString);       
00548   webNav->LoadURI(urlWString.get(), nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull);
00549 }
00550 
00551 
00552 #pragma mark -
00553 
00554 /*----------------------------------------------------------------------------
00555        WindowIsResizeable 
00556 
00557 ----------------------------------------------------------------------------*/
00558 
00559 Boolean nsWindowUtils::WindowIsResizeable(WindowPtr wind)
00560 {
00561        OSStatus             status;
00562        UInt32        features;
00563        status = GetWindowFeatures(wind, &features);
00564        return ((status == noErr) && ((features & kWindowCanGrow) != 0));
00565 }
00566 
00567 /*----------------------------------------------------------------------------
00568        WindowIsZoomable 
00569 
00570 ----------------------------------------------------------------------------*/
00571 Boolean nsWindowUtils::WindowIsZoomable(WindowPtr wind)
00572 {
00573        OSStatus             status;
00574        UInt32        features;
00575        status = GetWindowFeatures(wind, &features);
00576        return ((status == noErr) && ((features & kWindowCanZoom) != 0));
00577 }
00578 
00579 /*----------------------------------------------------------------------------
00580        WindowIsZoomed 
00581 
00582 ----------------------------------------------------------------------------*/
00583 Boolean nsWindowUtils::WindowIsZoomed(WindowPtr wind)
00584 {
00585        Rect                 r, userRect;
00586        GetWindowUserState(wind, &userRect);
00587        GetWindowPortRect(wind, &r);
00588        OffsetRect(&userRect, -userRect.left, -userRect.top);
00589        return EqualRect(&userRect, &r);
00590 }
00591 
00592 /*----------------------------------------------------------------------------
00593        WindowHasTitleBar 
00594        
00595        This stuff only works in 8.0 and later (Appearance Mgr)
00596 ----------------------------------------------------------------------------*/
00597 Boolean nsWindowUtils::WindowHasTitleBar(WindowPtr wind)
00598 {
00599        OSStatus             status;
00600        UInt32        features;
00601        status = GetWindowFeatures(wind, &features);
00602        return ((status == noErr) && ((features & kWindowHasTitleBar) != 0));
00603 }
00604 
00605 /*----------------------------------------------------------------------------
00606        WindowIsCloseable 
00607        
00608        This stuff only works in 8.5 and later (Appearance Mgr)
00609 ----------------------------------------------------------------------------*/
00610 Boolean nsWindowUtils::WindowIsCloseable(WindowPtr wind)
00611 {
00612        if ((long)GetWindowAttributes != kUnresolvedCFragSymbolAddress)
00613        {
00614               OSStatus             status;
00615               UInt32        attributes;
00616               
00617               status = GetWindowAttributes(wind, &attributes);
00618               return ((status == noErr) && ((attributes & kWindowCloseBoxAttribute) != 0));
00619        }
00620        
00621        return true;
00622 }
00623 
00624 /*----------------------------------------------------------------------------
00625        WindowIsModal 
00626        
00627        This stuff only works in 8.0 and later (Appearance Mgr)
00628 ----------------------------------------------------------------------------*/
00629 Boolean nsWindowUtils::WindowIsModal(WindowPtr wind)
00630 {
00631        OSStatus             status;
00632        UInt32        features;
00633        status = GetWindowFeatures(wind, &features);
00634        return ((status == noErr) && ((features & kWindowIsModal) != 0));
00635 }
00636 
00637 /*----------------------------------------------------------------------------
00638        WindowIsFloating 
00639        
00640 ----------------------------------------------------------------------------*/
00641 Boolean nsWindowUtils::WindowIsFloating(WindowPtr wind)
00642 {
00643        WindowClass   windClass;
00644        if (GetWindowClass(wind, &windClass) == noErr)
00645        {
00646               return (windClass == kFloatingWindowClass);
00647        }
00648 
00649        return false;
00650 }
00651 
00652 /*----------------------------------------------------------------------------
00653        WindowIsModified 
00654        
00655 ----------------------------------------------------------------------------*/
00656 Boolean nsWindowUtils::WindowIsModified(WindowPtr wind)
00657 {
00658        // еее write me
00659        return false;
00660 }