Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsWindowUtils Namespace Reference

Functions

long CountWindowsOfKind (TWindowKind windowKind)
WindowPtr GetNamedOrFrontmostWindow (TWindowKind windowKind, const char *windowName)
WindowPtr GetIndexedWindowOfKind (TWindowKind windowKind, TAEListIndex index)
TAEListIndex GetWindowIndex (TWindowKind windowKind, WindowPtr theWindow)
void GetCleanedWindowName (WindowPtr wind, char *outName, long maxLen)
void GetWindowUrlString (WindowPtr wind, char **outUrlStringPtr)
void GetWindowGlobalBounds (WindowPtr wind, Rect *outRect)
void LoadURLInWindow (WindowPtr wind, const char *urlString)
void LoadURLInXULWindow (nsIXULWindow *inWindow, const char *urlString)
Boolean WindowIsResizeable (WindowPtr wind)
Boolean WindowIsZoomable (WindowPtr wind)
Boolean WindowIsZoomed (WindowPtr wind)
Boolean WindowHasTitleBar (WindowPtr wind)
Boolean WindowIsModal (WindowPtr wind)
Boolean WindowIsCloseable (WindowPtr wind)
Boolean WindowIsFloating (WindowPtr wind)
Boolean WindowIsModified (WindowPtr wind)

Function Documentation

Definition at line 217 of file nsWindowUtils.cpp.

{
       nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID));
       ThrowErrIfNil(windowMediator, paramErr);

       nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
       if (NS_FAILED(windowMediator->GetXULWindowEnumerator(nsnull, getter_AddRefs(windowEnumerator))))
              ThrowOSErr(paramErr);                     // need a better error

       long windowCount = 0L;
       PRBool more;
       windowEnumerator->HasMoreElements(&more);
       while (more)
       {
              nsCOMPtr<nsISupports> nextWindow = nsnull;
              windowEnumerator->GetNext(getter_AddRefs(nextWindow));
              nsCOMPtr<nsIXULWindow> xulWindow(do_QueryInterface(nextWindow));
              if (!xulWindow) break;
              
              if (kAnyWindowKind == windowKind)
                     ++windowCount;
              else
              {
                     // Test window kind.
                     TWindowKind   thisWindowKind = GetXULWindowKind(xulWindow);
                     if (thisWindowKind == windowKind)
                            ++windowCount;
              }
              
              windowEnumerator->HasMoreElements(&more);
       }

       return windowCount;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsWindowUtils::GetCleanedWindowName ( WindowPtr  wind,
char *  outName,
long  maxLen 
)

Definition at line 411 of file nsWindowUtils.cpp.

{
       Str255 uncleanName;
       GetWTitle(wind, uncleanName);
       CopyPascalToCString(uncleanName, outName, maxLen);
}

Here is the call graph for this function:

Here is the caller graph for this function:

WindowPtr nsWindowUtils::GetIndexedWindowOfKind ( TWindowKind  windowKind,
TAEListIndex  index 
)

Definition at line 318 of file nsWindowUtils.cpp.

{
       nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID));
       ThrowErrIfNil(windowMediator, paramErr);
       
       nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
       if (NS_FAILED(windowMediator->GetZOrderXULWindowEnumerator(nsnull, PR_TRUE, getter_AddRefs(windowEnumerator))))
              ThrowOSErr(paramErr);                     // need a better error
   
  WindowPtr windowPtr = NULL;
       PRBool more;
       windowEnumerator->HasMoreElements(&more);
       while (more)
       {
              nsCOMPtr<nsISupports> nextWindow = nsnull;
              windowEnumerator->GetNext(getter_AddRefs(nextWindow));
              nsCOMPtr<nsIXULWindow> xulWindow(do_QueryInterface(nextWindow));
              if (!xulWindow) break;

              nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(xulWindow));
              ThrowErrIfNil(baseWindow, paramErr);
              
              nsCOMPtr<nsIWidget> widget = nsnull;
              baseWindow->GetMainWidget(getter_AddRefs(widget));
              ThrowErrIfNil(widget, paramErr);

              WindowRef     windowRef = (WindowRef)widget->GetNativeData(NS_NATIVE_DISPLAY);
              TWindowKind   thisWindowKind = GetXULWindowKind(xulWindow);
              
              // If this is the kind of window we are looking for...
              if (kAnyWindowKind == windowKind || (thisWindowKind == windowKind))
              {
                     // ...decrement index and test if this is the window at that index.
                     if (0L == --index)
                     {
                            windowPtr = (WindowPtr)windowRef;         // WindowRef is the WindowPtr.
                            break;
                     }
              }
       
              windowEnumerator->HasMoreElements(&more);
       }

       return windowPtr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

WindowPtr nsWindowUtils::GetNamedOrFrontmostWindow ( TWindowKind  windowKind,
const char *  windowName 
)

Definition at line 253 of file nsWindowUtils.cpp.

{
       // Search for window with the desired kind and name.
       nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID));
       ThrowErrIfNil(windowMediator, paramErr);
       
       nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
       if (NS_FAILED(windowMediator->GetXULWindowEnumerator(nsnull, getter_AddRefs(windowEnumerator))))
              ThrowOSErr(paramErr);                     // need a better error
   
  WindowPtr windowPtr = NULL;
       PRBool more;
       nsCString windowNameString(windowName);
       windowEnumerator->HasMoreElements(&more);
       while (more)
       {
              nsCOMPtr<nsISupports> nextWindow = nsnull;
              windowEnumerator->GetNext(getter_AddRefs(nextWindow));
              nsCOMPtr<nsIXULWindow> xulWindow(do_QueryInterface(nextWindow));
              if (!xulWindow) break;

              nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(xulWindow));
              ThrowErrIfNil(baseWindow, paramErr);
              
              nsCOMPtr<nsIWidget> widget = nsnull;
              baseWindow->GetMainWidget(getter_AddRefs(widget));
              ThrowErrIfNil(widget, paramErr);

              WindowRef     windowRef = (WindowRef)widget->GetNativeData(NS_NATIVE_DISPLAY);
              TWindowKind   thisWindowKind = GetXULWindowKind(xulWindow);
              
              // If this is the kind of window we are looking for...
              if (kAnyWindowKind == windowKind || (thisWindowKind == windowKind))
              {
                     if (NULL == windowName)
                     {
                         // ...see if its the frontmost of this kind.
                         PRInt32 zIndex;
                  widget->GetZIndex(&zIndex);
                  if (0L == zIndex)
                  {
                      windowPtr = (WindowPtr)windowRef;
                      break;
                  }
              }
              else
              {
                  // ...see if its name is the desired one.
                Str255 pascalTitle;
                GetWTitle(windowRef, pascalTitle);                                  
                     if (windowNameString.Compare((const char*)&pascalTitle[1], PR_FALSE, pascalTitle[0]) == 0)
                     {
                            windowPtr = (WindowPtr)windowRef;         // WindowRef is the WindowPtr.
                            break;
                     }
              }
              }
       
              windowEnumerator->HasMoreElements(&more);
       }
       
       return windowPtr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsWindowUtils::GetWindowGlobalBounds ( WindowPtr  wind,
Rect *  outRect 
)

Definition at line 468 of file nsWindowUtils.cpp.

{
       GrafPtr       curPort;
       GetWindowPortRect(wind, outBounds);
       GetPort(&curPort);
       SetPortWindowPort(wind);
       LocalToGlobalRect(outBounds);
       SetPort(curPort);
}

Here is the call graph for this function:

Here is the caller graph for this function:

TAEListIndex nsWindowUtils::GetWindowIndex ( TWindowKind  windowKind,
WindowPtr  theWindow 
)

Definition at line 365 of file nsWindowUtils.cpp.

{
       nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID));
       ThrowErrIfNil(windowMediator, paramErr);

       nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
       if (NS_FAILED(windowMediator->GetZOrderXULWindowEnumerator(nsnull, PR_TRUE, getter_AddRefs(windowEnumerator))))
              ThrowOSErr(paramErr);                     // need a better error

       TAEListIndex index = 0L;
       
       PRBool more;
       windowEnumerator->HasMoreElements(&more);
       while (more)
       {
              nsCOMPtr<nsISupports> nextWindow = nsnull;
              windowEnumerator->GetNext(getter_AddRefs(nextWindow));
              nsCOMPtr<nsIXULWindow> xulWindow(do_QueryInterface(nextWindow));
              if (!xulWindow) break;

              nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(xulWindow));
              ThrowErrIfNil(baseWindow, paramErr);
              
              nsCOMPtr<nsIWidget> widget = nsnull;
              baseWindow->GetMainWidget(getter_AddRefs(widget));
              ThrowErrIfNil(widget, paramErr);
              
              WindowRef     windowRef = (WindowRef)widget->GetNativeData(NS_NATIVE_DISPLAY);
              TWindowKind   thisWindowKind = GetXULWindowKind(xulWindow);

              if (kAnyWindowKind == windowKind || (thisWindowKind == windowKind))
              {
                     ++index;
                     
                     if ((WindowPtr)windowRef == theWindow)
                            return index;
              }
       
              windowEnumerator->HasMoreElements(&more);
       }

       return 0L; // error: theWindow wasn't found. Return an invalid index.
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsWindowUtils::GetWindowUrlString ( WindowPtr  wind,
char **  outUrlStringPtr 
)

Definition at line 419 of file nsWindowUtils.cpp.

{
       *outUrlStringPtr = NULL;

       nsCOMPtr<nsIXULWindow>             xulWindow;
       GetXULWindowFromWindowPtr(wind, getter_AddRefs(xulWindow));
       ThrowErrIfNil(xulWindow, paramErr);
       
       nsCOMPtr<nsIDocShellTreeItem>             contentShell;
       xulWindow->GetPrimaryContentShell(getter_AddRefs(contentShell));
       nsCOMPtr<nsIWebNavigation>                webNav(do_QueryInterface(contentShell));
       ThrowErrIfNil(webNav, paramErr);

       nsCOMPtr<nsIURI> sourceURL;
       webNav->GetCurrentURI(getter_AddRefs(sourceURL));
       ThrowErrIfNil(sourceURL, paramErr);
       
       // Now get the string;
       nsCAutoString spec;
       sourceURL->GetSpec(spec);
       
       *outUrlStringPtr = ToNewCString(spec);           
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsWindowUtils::LoadURLInWindow ( WindowPtr  wind,
const char *  urlString 
)

Definition at line 483 of file nsWindowUtils.cpp.

{
  OSErr err = noErr;

  if ( !wind )
  {
    // this makes a new window
    nsMacCommandLine&  cmdLine = nsMacCommandLine::GetMacCommandLine();
    err = cmdLine.DispatchURLToNewBrowser(urlString);
    ThrowIfOSErr(err);
  }
  else {
    // existing window. Go through hoops to load a URL in it
    nsCOMPtr<nsIXULWindow> xulWindow;
    GetXULWindowFromWindowPtr(wind, getter_AddRefs(xulWindow));
    ThrowErrIfNil(xulWindow, paramErr);

    LoadURLInXULWindow(xulWindow, urlString);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsWindowUtils::LoadURLInXULWindow ( nsIXULWindow inWindow,
const char *  urlString 
)

Definition at line 504 of file nsWindowUtils.cpp.

{
  nsCOMPtr<nsIDocShell> docShell;
  nsCOMPtr<nsIDocShellTreeItem> docItem;
  nsCOMPtr<nsIBrowserDOMWindow> bwin;

  // first try the nsIBrowserDOMWindow helper object
  // note the actual window used depends on user prefs. this may end up
  // using a different window!

  inWindow->GetDocShell(getter_AddRefs(docShell));
  docItem = do_QueryInterface(docShell);
  if (docItem) {
    nsCOMPtr<nsIDocShellTreeItem> rootItem;
    docItem->GetRootTreeItem(getter_AddRefs(rootItem));
    nsCOMPtr<nsIDOMWindow> rootWin(do_GetInterface(rootItem));
    nsCOMPtr<nsIDOMChromeWindow> chromeWin(do_QueryInterface(rootWin));
    if (chromeWin)
      chromeWin->GetBrowserDOMWindow(getter_AddRefs(bwin));
  }
  if (bwin) {
    nsCOMPtr<nsIURI> uri;
    nsDependentCString urlStr(urlString);
    NS_NewURI(getter_AddRefs(uri), urlStr, 0, 0);
    if (uri) {
      nsCOMPtr<nsIDOMWindow> newBrowserWindow;
      bwin->OpenURI(uri, 0,
                    nsIBrowserDOMWindow::OPEN_DEFAULTWINDOW,
                    nsIBrowserDOMWindow::OPEN_EXTERNAL,
                    getter_AddRefs(newBrowserWindow));
      if (newBrowserWindow)
        return;
    }
  }

  // fallback: navigate the XULWindow's content shell directly

  inWindow->GetPrimaryContentShell(getter_AddRefs(docItem));
  ThrowErrIfNil(docItem, paramErr);

  nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docItem));
  ThrowErrIfNil(webNav, paramErr);

  nsAutoString urlWString; urlWString.AssignWithConversion(urlString);       
  webNav->LoadURI(urlWString.get(), nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 597 of file nsWindowUtils.cpp.

{
       OSStatus             status;
       UInt32        features;
       status = GetWindowFeatures(wind, &features);
       return ((status == noErr) && ((features & kWindowHasTitleBar) != 0));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 610 of file nsWindowUtils.cpp.

{
       if ((long)GetWindowAttributes != kUnresolvedCFragSymbolAddress)
       {
              OSStatus             status;
              UInt32        attributes;
              
              status = GetWindowAttributes(wind, &attributes);
              return ((status == noErr) && ((attributes & kWindowCloseBoxAttribute) != 0));
       }
       
       return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 641 of file nsWindowUtils.cpp.

{
       WindowClass   windClass;
       if (GetWindowClass(wind, &windClass) == noErr)
       {
              return (windClass == kFloatingWindowClass);
       }

       return false;
}

Here is the caller graph for this function:

Definition at line 629 of file nsWindowUtils.cpp.

{
       OSStatus             status;
       UInt32        features;
       status = GetWindowFeatures(wind, &features);
       return ((status == noErr) && ((features & kWindowIsModal) != 0));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 656 of file nsWindowUtils.cpp.

{
       // еее write me
       return false;
}

Definition at line 559 of file nsWindowUtils.cpp.

{
       OSStatus             status;
       UInt32        features;
       status = GetWindowFeatures(wind, &features);
       return ((status == noErr) && ((features & kWindowCanGrow) != 0));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 571 of file nsWindowUtils.cpp.

{
       OSStatus             status;
       UInt32        features;
       status = GetWindowFeatures(wind, &features);
       return ((status == noErr) && ((features & kWindowCanZoom) != 0));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 583 of file nsWindowUtils.cpp.

{
       Rect                 r, userRect;
       GetWindowUserState(wind, &userRect);
       GetWindowPortRect(wind, &r);
       OffsetRect(&userRect, -userRect.left, -userRect.top);
       return EqualRect(&userRect, &r);
}

Here is the call graph for this function:

Here is the caller graph for this function: