Enhanced to demonstrate use of nsIDOMWindow::OpenDialog

git-svn-id: svn://10.0.0.236/trunk@36512 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
law%netscape.com 1999-06-23 05:33:03 +00:00
parent 64252804be
commit dd0df766ff
4 changed files with 81 additions and 21 deletions

View File

@ -18,6 +18,8 @@
#include "nsIAppShellComponent.idl"
interface nsIObserver;
/*------------------------ nsISampleAppShellComponent --------------------------
| This file describes the interface for a sample "application shell |
| component." |
@ -39,12 +41,12 @@ interface nsISampleAppShellComponent : nsIAppShellComponent {
| o Modal dialog from C++ |
| o Modal dialog from JavaScript |
--------------------------------------------------------------------------*/
void DoDialogTests();
void DoDialogTests( in nsISupports parent, in nsIObserver observer );
};
%{C++
#define NS_ISAMPLEAPPSHELLCOMPONENT_PROGID NS_IAPPSHELLCOMPONENT_PROGID "/sample"
#define NS_ISAMPLEAPPSHELLCOMPONENT_CLASSNAME "Mozilla Sample App Shell Component"
#define NS_DECL_ISAMPLEAPPSHELLCOMPONENT \
NS_IMETHOD DoDialogTests();
NS_IMETHOD DoDialogTests( nsISupports *, nsIObserver * );
%}

View File

@ -22,23 +22,6 @@
-->
<broadcaster id="data.input" value=""/>
<broadcaster id="data.output" value=""/>
<!--
The broadcaster with id="data.execute" is, by convention,
special in that it is a "reverse" broadcaster, used to
send notifications from the UI to the underlying C++ code.
There will generally be a set of "commands" that the C++
code supports. The UI indicates the requested command by
setting the command attribute of this broadcaster. The
setting of that attribute also triggers the command.
"Parameters" are passed via other attributes on this element,
or, via attributes on other broadcaster elements (as in this
example). If you use other attributes, then take care to set
those attributes before the command attribute (as that will
trigger the command execution).
-->
<broadcaster id="data.execute" command=""/>
</data>
<html:script>
@ -63,7 +46,6 @@
data = new Object;
data.input = document.getElementById( "data.input" );
data.output = document.getElementById( "data.output" );
data.execute = document.getElementById( "data.execute" );
}
/*
@ -89,6 +71,10 @@
the dialog, then loads the initial dialog contents.
*/
function onLoad() {
window.arguments[0].Observe( window, "sample", "onLoad called" );
// Init data.
initData();

View File

@ -48,6 +48,7 @@ LLIBS = \
$(LIBNSPR) \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\netlib.lib \
$(DIST)\lib\js3250.lib \
$(NULL)
#//------------------------------------------------------------------------

View File

@ -19,6 +19,11 @@
#include "nsIAppShellComponentImpl.h"
#include "nsIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIXPConnect.h"
#include "nsIObserver.h"
#if 0
#include "nsCOMPtr.h"
#include "pratom.h"
@ -79,9 +84,75 @@ private:
NS_IMETHODIMP
nsSampleAppShellComponent::DoDialogTests() {
nsSampleAppShellComponent::DoDialogTests( nsISupports *parent, nsIObserver *observer ) {
nsresult rv = NS_OK;
DEBUG_PRINTF( PR_STDOUT, "nsSampleAppShellComponent::DoDialogTests called\n" );
if ( parent && observer ) {
// Open the dialog from C++.
nsCOMPtr<nsIDOMWindow> parentWindow = do_QueryInterface( parent, &rv );
if ( NS_SUCCEEDED( rv ) ) {
// Get JS context from parent window.
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface( parentWindow, &rv );
if ( NS_SUCCEEDED( rv ) ) {
nsCOMPtr<nsIScriptContext> context;
sgo->GetContext( getter_AddRefs( context ) );
if ( context ) {
JSContext *jsContext = (JSContext*)context->GetNativeContext();
if ( jsContext ) {
// Convert observer to jsval so we can pass it as argument.
static NS_DEFINE_CID( kXPConnectCID, NS_XPCONNECT_CID );
NS_WITH_SERVICE( nsIXPConnect, xpc, kXPConnectCID, &rv );
if ( NS_SUCCEEDED( rv ) ) {
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
rv = xpc->WrapNative( jsContext,
observer,
nsIObserver::GetIID(),
getter_AddRefs( wrapper ) );
if ( NS_SUCCEEDED( rv ) ) {
JSObject* obj;
rv = wrapper->GetJSObject( &obj );
if ( NS_SUCCEEDED( rv ) ) {
// Get a jsval corresponding to the wrapped object.
jsval arg = OBJECT_TO_JSVAL( obj );
void *stackPtr;
jsval *argv = JS_PushArguments( jsContext, &stackPtr, "ssso",
"resource:/res/samples/nsSampleAppShellComponent.xul",
"",
"chrome",
arg );
if ( argv ) {
nsIDOMWindow *newWindow;
rv = parentWindow->OpenDialog( jsContext, argv, 4, &newWindow );
if ( NS_SUCCEEDED( rv ) ) {
} else {
}
JS_PopArguments( jsContext, stackPtr );
} else {
}
}
}
//? NS_RELEASE(aSupports);
} else {
}
} else {
}
} else {
}
} else {
}
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: QueryInterface failed, rv=0x%08X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: DoDialogTests was passed a null pointer!\n",
__FILE__, (int)__LINE__ );
rv = NS_ERROR_NULL_POINTER;
}
return rv;
}