2001-09-28 20:14:13 +00:00
|
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 16:52:41 +00:00
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2000-02-11 22:06:28 +00:00
|
|
|
|
*
|
2004-04-17 16:52:41 +00:00
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
|
* http://www.mozilla.org/MPL/
|
2000-02-11 22:06:28 +00:00
|
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
|
* License.
|
2000-02-11 22:06:28 +00:00
|
|
|
|
*
|
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
|
*
|
2004-04-17 16:52:41 +00:00
|
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2000-02-11 22:06:28 +00:00
|
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
|
* Contributor(s):
|
2004-04-17 16:52:41 +00:00
|
|
|
|
* Simon Fraser <sfraser@netscape.com>
|
2001-09-28 20:14:13 +00:00
|
|
|
|
*
|
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 16:52:41 +00:00
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-28 20:14:13 +00:00
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 16:52:41 +00:00
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 16:52:41 +00:00
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
|
*
|
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-02-11 22:06:28 +00:00
|
|
|
|
|
2001-01-20 02:50:37 +00:00
|
|
|
|
#include <MacWindows.h>
|
2000-02-11 22:06:28 +00:00
|
|
|
|
|
2001-01-20 02:50:37 +00:00
|
|
|
|
#include "nsCommandLineServiceMac.h"
|
2004-02-11 01:01:31 +00:00
|
|
|
|
#include "nsCOMPtr.h"
|
2001-01-20 02:50:37 +00:00
|
|
|
|
#include "nsIBaseWindow.h"
|
2004-12-07 16:09:32 +00:00
|
|
|
|
#include "nsIBrowserDOMWindow.h"
|
2001-01-20 02:50:37 +00:00
|
|
|
|
#include "nsIContent.h"
|
2004-12-07 16:09:32 +00:00
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
|
#include "nsIDocShellTreeItem.h"
|
2001-01-20 02:50:37 +00:00
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
|
#include "nsIDOMWindow.h"
|
2004-12-07 16:09:32 +00:00
|
|
|
|
#include "nsIDOMChromeWindow.h"
|
2001-01-20 02:50:37 +00:00
|
|
|
|
#include "nsIDOMWindowInternal.h"
|
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
|
#include "nsIWindowMediator.h"
|
|
|
|
|
#include "nsIURI.h"
|
|
|
|
|
#include "nsIXULWindow.h"
|
2001-03-12 23:17:18 +00:00
|
|
|
|
#include "nsString.h"
|
2004-12-07 16:09:32 +00:00
|
|
|
|
#include "nsNetUtil.h"
|
2000-02-11 22:06:28 +00:00
|
|
|
|
#include "nsWindowUtils.h"
|
2001-01-20 02:50:37 +00:00
|
|
|
|
#include "nsMacUtils.h"
|
|
|
|
|
#include "nsXPIDLString.h"
|
2004-10-29 19:28:38 +00:00
|
|
|
|
#include "nsIXULWindow.h"
|
2001-10-19 14:14:15 +00:00
|
|
|
|
#include "nsWindowUtils.h"
|
2002-03-06 07:48:55 +00:00
|
|
|
|
#include "nsReadableUtils.h"
|
2000-02-11 22:06:28 +00:00
|
|
|
|
|
2001-01-20 02:50:37 +00:00
|
|
|
|
#include "nsAEUtils.h"
|
2000-02-11 22:06:28 +00:00
|
|
|
|
|
2001-12-10 21:58:15 +00:00
|
|
|
|
using namespace nsWindowUtils;
|
|
|
|
|
|
2001-01-20 02:50:37 +00:00
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
|
GetXULWindowFromWindowPtr
|
|
|
|
|
|
|
|
|
|
Get an nsIXULWindow from a WindowPtr. Returns an ADDREFFED xulWindow,
|
|
|
|
|
which you must release (hint: use an nsCOMPtr).
|
|
|
|
|
|
|
|
|
|
Throws on error.
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
static void GetXULWindowFromWindowPtr(WindowPtr inWindowPtr, nsIXULWindow **outXULWindow)
|
|
|
|
|
{
|
|
|
|
|
*outXULWindow = NULL;
|
|
|
|
|
|
|
|
|
|
if (!inWindowPtr)
|
|
|
|
|
ThrowOSErr(paramErr);
|
|
|
|
|
|
2006-06-03 23:42:13 +00:00
|
|
|
|
nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
2001-01-20 02:50:37 +00:00
|
|
|
|
ThrowErrIfNil(windowMediator, paramErr);
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
|
|
|
|
|
if (NS_FAILED(windowMediator->GetXULWindowEnumerator(nsnull, getter_AddRefs(windowEnumerator))))
|
|
|
|
|
ThrowOSErr(paramErr); // need a better error
|
|
|
|
|
|
|
|
|
|
// Find the window
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
PRBool more = false;
|
|
|
|
|
windowEnumerator->HasMoreElements(&more);
|
|
|
|
|
if (!more)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> nextWindow = nsnull;
|
|
|
|
|
windowEnumerator->GetNext(getter_AddRefs(nextWindow));
|
|
|
|
|
nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(nextWindow));
|
|
|
|
|
if (NULL == baseWindow)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget = nsnull;
|
|
|
|
|
baseWindow->GetMainWidget(getter_AddRefs(widget));
|
|
|
|
|
if (NULL == widget)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
WindowRef windowRef = (WindowRef)widget->GetNativeData(NS_NATIVE_DISPLAY);
|
|
|
|
|
if ((WindowPtr)windowRef == inWindowPtr)
|
|
|
|
|
{
|
|
|
|
|
// !!! There really must be an easier way to do this. JavaScript?
|
|
|
|
|
nsCOMPtr<nsIXULWindow> xulWindow(do_QueryInterface(nextWindow));
|
|
|
|
|
if (!xulWindow)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
NS_ADDREF(*outXULWindow = xulWindow);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if we got here, we didn't find the window
|
|
|
|
|
ThrowOSErr(paramErr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
|
GetXULWindowTypeString
|
|
|
|
|
|
|
|
|
|
Get the type string for a XUL window
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
|
static void GetXULWindowTypeString(nsIXULWindow *inXULWindow, nsString& outWindowType)
|
|
|
|
|
{
|
|
|
|
|
outWindowType.Truncate();
|
|
|
|
|
|
|
|
|
|
if (inXULWindow)
|
|
|
|
|
{
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> contentShell;
|
|
|
|
|
inXULWindow->GetPrimaryContentShell(getter_AddRefs(contentShell));
|
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(contentShell));
|
|
|
|
|
ThrowErrIfNil(webNav, paramErr);
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
|
webNav->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
|
if (domDoc)
|
|
|
|
|
{
|
|
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
|
domDoc->GetDocumentElement(getter_AddRefs(element));
|
|
|
|
|
if (element)
|
|
|
|
|
element->GetAttribute(NS_LITERAL_STRING("windowtype"), outWindowType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
|
WindowKindFromTypeString
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
|
static TWindowKind WindowKindFromTypeString(const nsString& inWindowType)
|
|
|
|
|
{
|
|
|
|
|
if (inWindowType.IsEmpty())
|
|
|
|
|
return kAnyWindowKind;
|
|
|
|
|
|
2004-05-22 22:15:22 +00:00
|
|
|
|
if (inWindowType.EqualsLiteral("navigator:browser"))
|
2001-01-20 02:50:37 +00:00
|
|
|
|
return kBrowserWindowKind;
|
|
|
|
|
|
2004-05-22 22:15:22 +00:00
|
|
|
|
if (inWindowType.EqualsLiteral("mail:3pane"))
|
2001-01-20 02:50:37 +00:00
|
|
|
|
return kMailWindowKind;
|
|
|
|
|
|
2004-05-22 22:15:22 +00:00
|
|
|
|
if (inWindowType.EqualsLiteral("msgcompose"))
|
2001-01-20 02:50:37 +00:00
|
|
|
|
return kMailComposeWindowKind;
|
|
|
|
|
|
2004-05-22 22:15:22 +00:00
|
|
|
|
if (inWindowType.EqualsLiteral("mail:addressbook"))
|
2001-01-20 02:50:37 +00:00
|
|
|
|
return kAddressBookWindowKind;
|
|
|
|
|
|
2004-05-22 22:15:22 +00:00
|
|
|
|
if (inWindowType.EqualsLiteral("composer:html"))
|
2001-01-20 02:50:37 +00:00
|
|
|
|
return kComposerWindowKind;
|
|
|
|
|
|
2004-05-22 22:15:22 +00:00
|
|
|
|
if (inWindowType.EqualsLiteral("composer:text"))
|
2001-01-20 02:50:37 +00:00
|
|
|
|
return kComposerWindowKind;
|
|
|
|
|
|
|
|
|
|
return kOtherWindowKind;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
|
GetXULWindowKind
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
|
static TWindowKind GetXULWindowKind(nsIXULWindow *inXULWindow)
|
|
|
|
|
{
|
|
|
|
|
nsAutoString windowType;
|
|
|
|
|
GetXULWindowTypeString(inXULWindow, windowType);
|
|
|
|
|
return WindowKindFromTypeString(windowType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
|
CountWindowsOfKind
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
2001-12-10 21:58:15 +00:00
|
|
|
|
long nsWindowUtils::CountWindowsOfKind(TWindowKind windowKind)
|
2000-02-11 22:06:28 +00:00
|
|
|
|
{
|
2006-06-03 23:42:13 +00:00
|
|
|
|
nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
2001-01-20 02:50:37 +00:00
|
|
|
|
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;
|
2000-02-11 22:06:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-12-10 21:58:15 +00:00
|
|
|
|
WindowPtr nsWindowUtils::GetNamedOrFrontmostWindow(TWindowKind windowKind, const char* windowName)
|
2000-02-11 22:06:28 +00:00
|
|
|
|
{
|
2001-01-20 02:50:37 +00:00
|
|
|
|
// Search for window with the desired kind and name.
|
2006-06-03 23:42:13 +00:00
|
|
|
|
nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
2001-01-20 02:50:37 +00:00
|
|
|
|
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);
|
2004-04-15 20:44:53 +00:00
|
|
|
|
if (windowNameString.Compare((const char*)&pascalTitle[1], PR_FALSE, pascalTitle[0]) == 0)
|
2001-01-20 02:50:37 +00:00
|
|
|
|
{
|
|
|
|
|
windowPtr = (WindowPtr)windowRef; // WindowRef is the WindowPtr.
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
windowEnumerator->HasMoreElements(&more);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return windowPtr;
|
2000-02-11 22:06:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-12-10 21:58:15 +00:00
|
|
|
|
WindowPtr nsWindowUtils::GetIndexedWindowOfKind(TWindowKind windowKind, TAEListIndex index)
|
2000-02-11 22:06:28 +00:00
|
|
|
|
{
|
2006-06-03 23:42:13 +00:00
|
|
|
|
nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
2001-01-20 02:50:37 +00:00
|
|
|
|
ThrowErrIfNil(windowMediator, paramErr);
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
|
2002-10-04 00:35:01 +00:00
|
|
|
|
if (NS_FAILED(windowMediator->GetZOrderXULWindowEnumerator(nsnull, PR_TRUE, getter_AddRefs(windowEnumerator))))
|
2001-01-20 02:50:37 +00:00
|
|
|
|
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;
|
2000-02-11 22:06:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-12-10 21:58:15 +00:00
|
|
|
|
TAEListIndex nsWindowUtils::GetWindowIndex(TWindowKind windowKind, WindowPtr theWindow)
|
2000-02-11 22:06:28 +00:00
|
|
|
|
{
|
2006-06-03 23:42:13 +00:00
|
|
|
|
nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
2001-01-20 02:50:37 +00:00
|
|
|
|
ThrowErrIfNil(windowMediator, paramErr);
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
|
2002-10-04 00:35:01 +00:00
|
|
|
|
if (NS_FAILED(windowMediator->GetZOrderXULWindowEnumerator(nsnull, PR_TRUE, getter_AddRefs(windowEnumerator))))
|
2001-01-20 02:50:37 +00:00
|
|
|
|
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.
|
2000-02-11 22:06:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-01-20 02:50:37 +00:00
|
|
|
|
//---------------------------------------------------------
|
2001-12-10 21:58:15 +00:00
|
|
|
|
void nsWindowUtils::GetCleanedWindowName(WindowPtr wind, char* outName, long maxLen)
|
2000-02-11 22:06:28 +00:00
|
|
|
|
{
|
2001-01-20 02:50:37 +00:00
|
|
|
|
Str255 uncleanName;
|
|
|
|
|
GetWTitle(wind, uncleanName);
|
|
|
|
|
CopyPascalToCString(uncleanName, outName, maxLen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2001-12-10 21:58:15 +00:00
|
|
|
|
void nsWindowUtils::GetWindowUrlString(WindowPtr wind, char** outUrlStringPtr)
|
2001-01-20 02:50:37 +00:00
|
|
|
|
{
|
|
|
|
|
*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;
|
2002-03-06 07:48:55 +00:00
|
|
|
|
nsCAutoString spec;
|
|
|
|
|
sourceURL->GetSpec(spec);
|
|
|
|
|
|
|
|
|
|
*outUrlStringPtr = ToNewCString(spec);
|
2000-02-11 22:06:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
inline void GetWindowPortRect(WindowPtr wind, Rect *outRect)
|
|
|
|
|
{
|
2000-06-20 23:10:06 +00:00
|
|
|
|
#if OPAQUE_TOOLBOX_STRUCTS
|
|
|
|
|
::GetPortBounds(GetWindowPort(wind), outRect);
|
|
|
|
|
#else
|
2000-02-11 22:06:28 +00:00
|
|
|
|
*outRect = wind->portRect;
|
2000-06-20 23:10:06 +00:00
|
|
|
|
#endif
|
2000-02-11 22:06:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
|
LocalToGlobalRect
|
|
|
|
|
|
|
|
|
|
Convert a rectangle from local to global coordinates.
|
|
|
|
|
|
|
|
|
|
Entry: r = pointer to rectangle.
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
static void LocalToGlobalRect (Rect *r)
|
|
|
|
|
{
|
|
|
|
|
LocalToGlobal((Point*)&r->top);
|
|
|
|
|
LocalToGlobal((Point*)&r->bottom);
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-10 21:58:15 +00:00
|
|
|
|
void nsWindowUtils::GetWindowGlobalBounds(WindowPtr wind, Rect* outBounds)
|
2000-02-11 22:06:28 +00:00
|
|
|
|
{
|
|
|
|
|
GrafPtr curPort;
|
|
|
|
|
GetWindowPortRect(wind, outBounds);
|
|
|
|
|
GetPort(&curPort);
|
2000-06-20 23:10:06 +00:00
|
|
|
|
SetPortWindowPort(wind);
|
2000-02-11 22:06:28 +00:00
|
|
|
|
LocalToGlobalRect(outBounds);
|
|
|
|
|
SetPort(curPort);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-01-20 02:50:37 +00:00
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
|
LoadURLInWindow
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
2001-12-10 21:58:15 +00:00
|
|
|
|
void nsWindowUtils::LoadURLInWindow(WindowPtr wind, const char* urlString)
|
2001-01-20 02:50:37 +00:00
|
|
|
|
{
|
2001-10-19 14:14:15 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-01-20 02:50:37 +00:00
|
|
|
|
|
2001-12-10 21:58:15 +00:00
|
|
|
|
void nsWindowUtils::LoadURLInXULWindow(nsIXULWindow* inWindow, const char* urlString)
|
2001-10-19 14:14:15 +00:00
|
|
|
|
{
|
2004-12-07 16:09:32 +00:00
|
|
|
|
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);
|
2001-01-20 02:50:37 +00:00
|
|
|
|
|
2004-12-07 16:09:32 +00:00
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docItem));
|
2001-10-19 14:14:15 +00:00
|
|
|
|
ThrowErrIfNil(webNav, paramErr);
|
2001-01-20 02:50:37 +00:00
|
|
|
|
|
2001-10-19 14:14:15 +00:00
|
|
|
|
nsAutoString urlWString; urlWString.AssignWithConversion(urlString);
|
2001-11-30 22:35:33 +00:00
|
|
|
|
webNav->LoadURI(urlWString.get(), nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull);
|
2001-01-20 02:50:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-10-19 14:14:15 +00:00
|
|
|
|
|
2000-02-11 22:06:28 +00:00
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
|
WindowIsResizeable
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
|
|
2001-12-10 21:58:15 +00:00
|
|
|
|
Boolean nsWindowUtils::WindowIsResizeable(WindowPtr wind)
|
2000-02-11 22:06:28 +00:00
|
|
|
|
{
|
|
|
|
|
OSStatus status;
|
|
|
|
|
UInt32 features;
|
|
|
|
|
status = GetWindowFeatures(wind, &features);
|
|
|
|
|
return ((status == noErr) && ((features & kWindowCanGrow) != 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
|
WindowIsZoomable
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
2001-12-10 21:58:15 +00:00
|
|
|
|
Boolean nsWindowUtils::WindowIsZoomable(WindowPtr wind)
|
2000-02-11 22:06:28 +00:00
|
|
|
|
{
|
|
|
|
|
OSStatus status;
|
|
|
|
|
UInt32 features;
|
|
|
|
|
status = GetWindowFeatures(wind, &features);
|
|
|
|
|
return ((status == noErr) && ((features & kWindowCanZoom) != 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
|
WindowIsZoomed
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
2001-12-10 21:58:15 +00:00
|
|
|
|
Boolean nsWindowUtils::WindowIsZoomed(WindowPtr wind)
|
2000-02-11 22:06:28 +00:00
|
|
|
|
{
|
|
|
|
|
Rect r, userRect;
|
|
|
|
|
GetWindowUserState(wind, &userRect);
|
|
|
|
|
GetWindowPortRect(wind, &r);
|
|
|
|
|
OffsetRect(&userRect, -userRect.left, -userRect.top);
|
|
|
|
|
return EqualRect(&userRect, &r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
|
WindowHasTitleBar
|
|
|
|
|
|
|
|
|
|
This stuff only works in 8.0 and later (Appearance Mgr)
|
|
|
|
|
----------------------------------------------------------------------------*/
|
2001-12-10 21:58:15 +00:00
|
|
|
|
Boolean nsWindowUtils::WindowHasTitleBar(WindowPtr wind)
|
2000-02-11 22:06:28 +00:00
|
|
|
|
{
|
|
|
|
|
OSStatus status;
|
|
|
|
|
UInt32 features;
|
|
|
|
|
status = GetWindowFeatures(wind, &features);
|
|
|
|
|
return ((status == noErr) && ((features & kWindowHasTitleBar) != 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
|
WindowIsCloseable
|
|
|
|
|
|
|
|
|
|
This stuff only works in 8.5 and later (Appearance Mgr)
|
|
|
|
|
----------------------------------------------------------------------------*/
|
2001-12-10 21:58:15 +00:00
|
|
|
|
Boolean nsWindowUtils::WindowIsCloseable(WindowPtr wind)
|
2000-02-11 22:06:28 +00:00
|
|
|
|
{
|
|
|
|
|
if ((long)GetWindowAttributes != kUnresolvedCFragSymbolAddress)
|
|
|
|
|
{
|
|
|
|
|
OSStatus status;
|
|
|
|
|
UInt32 attributes;
|
|
|
|
|
|
|
|
|
|
status = GetWindowAttributes(wind, &attributes);
|
|
|
|
|
return ((status == noErr) && ((attributes & kWindowCloseBoxAttribute) != 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
|
WindowIsModal
|
|
|
|
|
|
|
|
|
|
This stuff only works in 8.0 and later (Appearance Mgr)
|
|
|
|
|
----------------------------------------------------------------------------*/
|
2001-12-10 21:58:15 +00:00
|
|
|
|
Boolean nsWindowUtils::WindowIsModal(WindowPtr wind)
|
2000-02-11 22:06:28 +00:00
|
|
|
|
{
|
|
|
|
|
OSStatus status;
|
|
|
|
|
UInt32 features;
|
|
|
|
|
status = GetWindowFeatures(wind, &features);
|
|
|
|
|
return ((status == noErr) && ((features & kWindowIsModal) != 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
|
WindowIsFloating
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
2001-12-10 21:58:15 +00:00
|
|
|
|
Boolean nsWindowUtils::WindowIsFloating(WindowPtr wind)
|
2000-02-11 22:06:28 +00:00
|
|
|
|
{
|
|
|
|
|
WindowClass windClass;
|
|
|
|
|
if (GetWindowClass(wind, &windClass) == noErr)
|
|
|
|
|
{
|
|
|
|
|
return (windClass == kFloatingWindowClass);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
|
WindowIsModified
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------*/
|
2001-12-10 21:58:15 +00:00
|
|
|
|
Boolean nsWindowUtils::WindowIsModified(WindowPtr wind)
|
2000-02-11 22:06:28 +00:00
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD> write me
|
|
|
|
|
return false;
|
|
|
|
|
}
|