Bug 132106 - Put code into PPEmbed to support XUL preferences dialog. r=pink/sr=beard/a=asa

git-svn-id: svn://10.0.0.236/trunk@117186 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
ccarlen%netscape.com 2002-03-22 15:52:22 +00:00
parent ff56da1585
commit 571f68ebcc
8 changed files with 166 additions and 39 deletions

View File

@ -44,6 +44,7 @@
#include "ApplIDs.h"
#include "CBrowserWindow.h"
#include "CBrowserShell.h"
#include "CBrowserChrome.h"
#include "CWindowCreator.h"
#include "CUrlField.h"
#include "CThrobber.h"
@ -73,6 +74,8 @@
#include "macstdlibextras.h"
#include "SIOUX.h"
#include "nsNetUtil.h"
#include "nsIWindowWatcher.h"
#include "nsIDOMWindow.h"
#include <TextServices.h>
@ -140,6 +143,10 @@ CBrowserApp::CBrowserApp()
mRefCnt = 1;
#endif
#if TARGET_CARBON
InstallCarbonEventHandlers();
#endif
if ( PP_PowerPlant::UEnvironment::HasFeature( PP_PowerPlant::env_HasAppearance ) ) {
::RegisterAppearanceClient();
}
@ -318,7 +325,7 @@ CBrowserApp::MakeMenuBar()
LApplication::MakeMenuBar();
// Insert a menu which is not in the menu bar but which contains
// items which appear in contextual menus. We have to do this hack
// items which appear only in contextual menus. We have to do this hack
// because LCMAttachment::AddCommand needs a command which is in
// some LMenu in order to get the text for a contextual menu item.
@ -417,6 +424,9 @@ CBrowserApp::ObeyCommand(
switch (inCommand) {
case PP_PowerPlant::cmd_About:
break;
case PP_PowerPlant::cmd_New:
{
LWindow *theWindow = CWindowCreator::CreateWindowInternal(nsIWebBrowserChrome::CHROME_DEFAULT, -1, -1);
@ -455,6 +465,38 @@ CBrowserApp::ObeyCommand(
}
break;
case PP_PowerPlant::cmd_Preferences:
{
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
ThrowIfNil_(wwatch);
// Note: We're not making this window modal even though it looks like a modal
// dialog (has OK and Cancel buttons). Reason is, the help window which can
// be opened from the prefs dialog is non-modal. If the prefs dialog was modal,
// the help window would be stuck behind it in the non-modal layer.
// And, since its non-modal, we have to check for an already open prefs window
// and just select it rather than making a new one.
nsCOMPtr<nsIDOMWindow> extantPrefsWindow;
wwatch->GetWindowByName(NS_LITERAL_STRING("_prefs").get(), nsnull, getter_AddRefs(extantPrefsWindow));
if (extantPrefsWindow) {
// activate the window
LWindow *extantPrefsLWindow = CBrowserChrome::GetLWindowForDOMWindow(extantPrefsWindow);
ThrowIfNil_(extantPrefsLWindow);
extantPrefsLWindow->Select();
}
else {
nsCOMPtr<nsIDOMWindow> domWindow;
wwatch->OpenWindow(nsnull,
"chrome://communicator/content/pref/pref.xul",
"_prefs",
"centerscreen,chrome,dialog,titlebar",
nsnull,
getter_AddRefs(domWindow));
}
}
break;
// Any that you don't handle, such as cmd_About and cmd_Quit,
// will be passed up to LApplication
default:
@ -482,7 +524,10 @@ CBrowserApp::FindCommandStatus(
switch (inCommand) {
// Return menu item status according to command messages.
case PP_PowerPlant::cmd_About:
outEnabled = false;
break;
case PP_PowerPlant::cmd_New:
outEnabled = true;
break;
@ -492,6 +537,10 @@ CBrowserApp::FindCommandStatus(
outEnabled = true;
break;
case PP_PowerPlant::cmd_Preferences:
outEnabled = true;
break;
// Any that you don't handle, such as cmd_About and cmd_Quit,
// will be passed up to LApplication
default:
@ -520,6 +569,67 @@ Boolean CBrowserApp::AttemptQuitSelf(SInt32 inSaveOption)
return true;
}
#if TARGET_CARBON
void CBrowserApp::InstallCarbonEventHandlers()
{
EventTypeSpec appEventList[] = {{kEventClassCommand, kEventCommandProcess},
{kEventClassCommand, kEventCommandUpdateStatus}};
InstallApplicationEventHandler(NewEventHandlerUPP(AppEventHandler), 2, appEventList, this, NULL);
}
pascal OSStatus CBrowserApp::AppEventHandler(EventHandlerCallRef aHandlerChain,
EventRef event,
void* userData)
{
HICommand command;
OSStatus result = eventNotHandledErr; /* report failure by default */
if (::GetEventParameter(event, kEventParamDirectObject,
typeHICommand, NULL, sizeof(HICommand),
NULL, &command) != noErr)
return result;
switch (::GetEventKind(event))
{
case kEventCommandProcess:
{
switch (command.commandID)
{
case kHICommandPreferences:
CBrowserApp *theApp = reinterpret_cast<CBrowserApp*>(userData);
theApp->ObeyCommand(PP_PowerPlant::cmd_Preferences, nsnull);
result = noErr;
break;
default:
break;
}
}
break;
case kEventCommandUpdateStatus:
{
switch (command.commandID)
{
case kHICommandPreferences:
::EnableMenuCommand(nsnull, kHICommandPreferences);
result = noErr;
break;
default:
break;
}
}
break;
default:
break;
}
return result;
}
#endif // TARGET_CARBON
nsresult CBrowserApp::InitializePrefs()
{
nsresult rv;

View File

@ -71,6 +71,13 @@ protected:
virtual void StartUp(); // override startup functions
virtual nsresult OverrideComponents();
virtual void MakeMenuBar();
#if TARGET_CARBON
virtual void InstallCarbonEventHandlers();
static pascal OSStatus AppEventHandler(EventHandlerCallRef myHandlerChain,
EventRef event,
void* userData);
#endif
virtual nsresult InitializePrefs();

View File

@ -53,6 +53,8 @@
#include "nsIDOMWindow.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIWindowWatcher.h"
#include "nsIServiceManagerUtils.h"
#include "UMacUnicode.h"
#include "ApplIDs.h"
@ -521,3 +523,31 @@ void CBrowserChrome::ListenToMessage(MessageT inMessage, void* ioParam)
break;
}
}
//*****************************************************************************
// Static Utility Method
//*****************************************************************************
LWindow* CBrowserChrome::GetLWindowForDOMWindow(nsIDOMWindow* aDOMWindow)
{
if (!aDOMWindow)
return nsnull;
nsCOMPtr<nsIWindowWatcher> windowWatcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!windowWatcher)
return nsnull;
nsCOMPtr<nsIWebBrowserChrome> windowChrome;
windowWatcher->GetChromeForWindow(aDOMWindow, getter_AddRefs(windowChrome));
if (!windowChrome)
return nsnull;
nsCOMPtr<nsIEmbeddingSiteWindow> siteWindow(do_QueryInterface(windowChrome));
if (!siteWindow)
return nsnull;
WindowPtr macWindow = nsnull;
siteWindow->GetSiteWindow((void **)&macWindow);
if (!macWindow)
return nsnull;
return LWindow::FetchWindowObject(macWindow);
}

View File

@ -85,6 +85,9 @@ public:
// LListener
virtual void ListenToMessage(MessageT inMessage,
void* ioParam);
// Utility
static LWindow* GetLWindowForDOMWindow(nsIDOMWindow* aDOMWindow);
protected:
CBrowserChrome(CBrowserShell* aShell,

View File

@ -132,8 +132,6 @@ LWindow* CWindowCreator::CreateWindowInternal(PRUint32 inChromeFlags,
UInt32 windowAttrs = (windAttr_Enabled | windAttr_Targetable);
if (chromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_DIALOG)
{
windowAttrs |= windAttr_Modal;
if (chromeFlags & nsIWebBrowserChrome::CHROME_TITLEBAR)
{
windowDefProc = kWindowMovableModalDialogProc;
@ -144,8 +142,6 @@ LWindow* CWindowCreator::CreateWindowInternal(PRUint32 inChromeFlags,
}
else
{
windowAttrs |= windAttr_Regular;
if (chromeFlags & nsIWebBrowserChrome::CHROME_WINDOW_RESIZE)
{
windowDefProc = kWindowGrowDocumentProc;
@ -157,6 +153,11 @@ LWindow* CWindowCreator::CreateWindowInternal(PRUint32 inChromeFlags,
if (chromeFlags & nsIWebBrowserChrome::CHROME_WINDOW_CLOSE)
windowAttrs |= windAttr_CloseBox;
}
if (chromeFlags & nsIWebBrowserChrome::CHROME_MODAL)
windowAttrs |= windAttr_Modal;
else
windowAttrs |= windAttr_Regular;
theWindow = new CBrowserWindow(LCommander::GetTopCommander(), globalBounds, "\p", windowDefProc, windowAttrs, window_InFront);
ThrowIfNil_(theWindow);

View File

@ -50,6 +50,7 @@
// Local Includes
#include "ApplIDs.h"
#include "UMacUnicode.h"
#include "CBrowserChrome.h"
// PowerPlant
#include <LStaticText.h>
@ -70,9 +71,6 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPROMPTSERVICE
protected:
LCommander* GetParentCommander(nsIDOMWindow* aDOMWindow);
};
//*****************************************************************************
@ -88,34 +86,11 @@ CPromptService::~CPromptService()
{
}
LCommander* CPromptService::GetParentCommander(nsIDOMWindow* aDOMWindow)
{
nsresult rv;
LCommander *resultCommander = LCommander::GetDefaultCommander();
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!wwatch) return nsnull;
nsCOMPtr<nsIWebBrowserChrome> windowChrome;
rv = wwatch->GetChromeForWindow(aDOMWindow, getter_AddRefs(windowChrome));
if (NS_FAILED(rv)) return nsnull;
nsCOMPtr<nsIEmbeddingSiteWindow> window(do_QueryInterface(windowChrome, &rv));
if (NS_FAILED(rv)) return nsnull;
WindowPtr macWindow;
rv = window->GetSiteWindow((void **)&macWindow);
if (NS_FAILED(rv)) return nsnull;
resultCommander = LWindow::FetchWindowObject(macWindow);
NS_ASSERTION(resultCommander, "Couldn't get PowerPlant window");
return resultCommander;
}
NS_IMETHODIMP CPromptService::Alert(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
const PRUnichar *text)
{
StDialogHandler theHandler(dlog_Alert, GetParentCommander(parent));
StDialogHandler theHandler(dlog_Alert, CBrowserChrome::GetLWindowForDOMWindow(parent));
LWindow *theDialog = theHandler.GetDialog();
nsCAutoString cStr;
Str255 pStr;
@ -148,7 +123,7 @@ NS_IMETHODIMP CPromptService::AlertCheck(nsIDOMWindow *parent, const PRUnichar *
{
NS_ENSURE_ARG_POINTER(checkValue);
StDialogHandler theHandler(dlog_ConfirmCheck, GetParentCommander(parent));
StDialogHandler theHandler(dlog_ConfirmCheck, CBrowserChrome::GetLWindowForDOMWindow(parent));
LWindow *theDialog = theHandler.GetDialog();
nsCAutoString cStr;
Str255 pStr;
@ -189,7 +164,7 @@ NS_IMETHODIMP CPromptService::Confirm(nsIDOMWindow *parent, const PRUnichar *dia
{
NS_ENSURE_ARG_POINTER(_retval);
StDialogHandler theHandler(dlog_Confirm, GetParentCommander(parent));
StDialogHandler theHandler(dlog_Confirm, CBrowserChrome::GetLWindowForDOMWindow(parent));
LWindow *theDialog = theHandler.GetDialog();
nsCAutoString cStr;
Str255 pStr;
@ -232,7 +207,7 @@ NS_IMETHODIMP CPromptService::ConfirmCheck(nsIDOMWindow *parent, const PRUnichar
NS_ENSURE_ARG_POINTER(checkValue);
NS_ENSURE_ARG_POINTER(_retval);
StDialogHandler theHandler(dlog_ConfirmCheck, GetParentCommander(parent));
StDialogHandler theHandler(dlog_ConfirmCheck, CBrowserChrome::GetLWindowForDOMWindow(parent));
LWindow *theDialog = theHandler.GetDialog();
nsCAutoString cStr;
Str255 pStr;
@ -294,7 +269,7 @@ NS_IMETHODIMP CPromptService::Prompt(nsIDOMWindow *parent, const PRUnichar *dial
nsresult resultErr = NS_OK;
StDialogHandler theHandler(dlog_Prompt, GetParentCommander(parent));
StDialogHandler theHandler(dlog_Prompt, CBrowserChrome::GetLWindowForDOMWindow(parent));
LWindow *theDialog = theHandler.GetDialog();
LCheckBox *checkbox = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID('Chck'));
nsCAutoString cStr;
@ -374,7 +349,7 @@ NS_IMETHODIMP CPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent, co
nsresult resultErr = NS_OK;
StDialogHandler theHandler(dlog_PromptNameAndPass, GetParentCommander(parent));
StDialogHandler theHandler(dlog_PromptNameAndPass, CBrowserChrome::GetLWindowForDOMWindow(parent));
LWindow *theDialog = theHandler.GetDialog();
LCheckBox *checkbox = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID('Chck'));
nsCAutoString cStr;
@ -469,7 +444,7 @@ NS_IMETHODIMP CPromptService::PromptPassword(nsIDOMWindow *parent, const PRUnich
nsresult resultErr = NS_OK;
StDialogHandler theHandler(dlog_PromptPassword, GetParentCommander(parent));
StDialogHandler theHandler(dlog_PromptPassword, CBrowserChrome::GetLWindowForDOMWindow(parent));
LWindow *theDialog = theHandler.GetDialog();
LCheckBox *checkbox = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID('Chck'));
nsCAutoString cStr;

View File

@ -45,6 +45,7 @@
// PowerPlant definitions
#define PP_Uses_PowerPlant_Namespace 0
#define PP_Suppress_Notes_22 1
#define PP_Uses_Aqua_MenuBar 1
#if !defined(TARGET_CARBON) || !TARGET_CARBON
#define ACCESSOR_CALLS_ARE_FUNCTIONS 1