Re: adding NSView from other application
Re: adding NSView from other application
- Subject: Re: adding NSView from other application
- From: Christopher Atlan <email@hidden>
- Date: Thu, 31 Mar 2005 05:32:41 +0200
Hey,
thanks a lot for your answer
just to clarify
it's not my application
just someone ask me to think about that
yes, thanks a lot, i'm the one how ask about.
he said that it works fine for windows and linux
here is a fragment of the code for a2 application (receiver)
linux:
int javaXId = atoi(mMsgString);
NS_ASSERTION(javaXId, "Invalid X window handle\n");
pBrowser = g_new0(GtkBrowser, 1);
pBrowser->topLevelWindow = gtk_plug_new(javaXId);
and windows
HWND hWnd = (HWND) atoi(mMsgString);
pBrowserWnd = new BrowserWindow();
if (!pBrowserWnd)
break;
SetRect(&rect, 0, 0, 0, 0);
HWND hWndClient = pBrowserWnd->Create(hWnd,rect,
_T("about:blank"),
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
WS_EX_CLIENTEDGE);
where mMsgString is a string received from application a1 (via TCP/IP for example)
and it contains address of widget created by a1
so they wanted to do the same thing on mac os x
here a little describtion so i hope you can better understand the problem:
The problem behind the design is that: we have a java prozess that use jni to create the NSView. This is AWT native window based on the JAWT handler.
The other prozess is a program using WebKit Framework, and should draw itself in the NSView which the java prozess has created.
These tow prozess/program talk over a socket(tcp) connection.
Way we not use in Java the CocoaCanvas? Because we need Java Applet support in the WebKit, and we get this only if the WebKit do not run in a Java Prozess.
Here the important code that create the nsview one java jni site (you can find a example on http://developer.apple.com/samplecode/JAWTExample/listing4.html ):
JAWT awt;
JAWT_DrawingSurface* ds = NULL;
JAWT_DrawingSurfaceInfo* dsi = NULL;
JAWT_MacOSXDrawingSurfaceInfo* dsi_mac = NULL;
jboolean result = JNI_FALSE;
jint lock = 0;
NSView *view;
// get the AWT
awt.version = JAWT_VERSION_1_4;
result = JAWT_GetAWT(env, &awt);
...
// Get the drawing surface. This can be safely cached.
// Anything below the DS (DSI, contexts, etc)
// can possibly change/go away and should not be cached.
ds = awt.GetDrawingSurface(env, canvas);
...
// Lock the drawing surface
// You must lock EACH TIME before drawing
lock = ds->Lock(ds);
// Get the drawing surface info
dsi = ds->GetDrawingSurfaceInfo(ds);
// Check DrawingSurfaceInfo. This can be NULL on Mac OS X
// if the windowing system is not ready
if (dsi != NULL) {
// Get the platform-specific drawing info
// We will use this to get at Cocoa and CoreGraphics
// See <JavaVM/jawt_md.h>
dsi_mac = (JAWT_MacOSXDrawingSurfaceInfo*)dsi->platformInfo;
if ((*env)->ExceptionOccurred(env)) {
(*env)->ExceptionDescribe(env);
}
// Get the corresponding peer from the caller canvas
view = dsi_mac->cocoaViewRef;
// Free the DrawingSurfaceInfo
ds->FreeDrawingSurfaceInfo(dsi);
...
}
// Unlock the drawing surface
// You must unlock EACH TIME when done drawing
ds->Unlock(ds);
...
// Free the drawing surface (if not caching it)
awt.FreeDrawingSurface(ds);
...
return (jint)view;
thanks,
Christopher Atlan
thanks again
On Mar 30, 2005, at 4:20 PM, Ondra Cada wrote:
Dmitry,
On 30.3.2005, at 22:52, Dmitry Markman wrote:
I'd like to clarify some issue
Well, it's not that simple.
in general we can formulate problem as following:
1. there are 2 applications a1 and a2
2. a1 application creates NSView and send address of that NSView to a2 application (via TCP/IP protocol for example)
3. a2 application create NSView and attempts to add that new NSView to the NSView that a1 application created
I think it's impossible on the Macintosh,
It is not general enough. Exactly as formulated, it truly is not possible with any system which uses virtual address space. And that, I believe, is just anything these days, even, IIRC, the Symbian of mobile phones does that :))
but I'd like to know for sure and reasons (if it's impossible)
There are possibilities though to get precisely the functionality (I think) you want. First, you can get it almost for free with distributed objects: through them, you can access any object remotely, and you even should be able to vend the NSView in question bycopy (never tried myself).
Besides, without knowing the applications design one can't be sure, but it smells to me suspicious: do you really want to *create* the view in one and *send the view* to another? (No offence meant, perhaps your design is excellent, just I wonder...)
You seldom enough create views programmatically: some, I daresay, 99.9% of tasks are better solved using NIBs -- and of course, you can load one application's NIB into another app any time (presumed there are proper access rights, of course).
Also, the idea of creating a view and moving it into a different environment sounds suspicious too: don't you perchance rather want to share/send the *data* which control the view creation, and -- possibly -- to share a bundle/framework with the code which crates the view based on the data?
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
Dmitry Markman
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden