From 09e6d823c42c3c895761be6b1ea6b80cfcdca91f Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 1 Oct 2009 19:11:02 +0000 Subject: [PATCH] embrace new WindowHandle construct --- direct/src/p3d/AppRunner.py | 41 +++++++++++++++++------------- direct/src/plugin/Sources.pp | 2 ++ direct/src/plugin/p3dPythonRun.cxx | 37 +++++++++++++++++++-------- 3 files changed, 53 insertions(+), 27 deletions(-) diff --git a/direct/src/p3d/AppRunner.py b/direct/src/p3d/AppRunner.py index d48f7b1c22..cf75c4f9c8 100644 --- a/direct/src/p3d/AppRunner.py +++ b/direct/src/p3d/AppRunner.py @@ -642,16 +642,17 @@ class AppRunner(DirectObject): loadPrcFileData(pathname, data) - def __clearWindowPrc(self): + def __clearWindowProperties(self): """ Clears the windowPrc file that was created in a previous call to setupWindow(), if any. """ if self.windowPrc: unloadPrcFile(self.windowPrc) self.windowPrc = None + WindowProperties.clearDefault() def setupWindow(self, windowType, x, y, width, height, - parent, subprocessWindow): + parent): """ Applies the indicated window parameters to the prc settings, for future windows; or applies them directly to the main window if the window has already been opened. This is @@ -665,37 +666,43 @@ class AppRunner(DirectObject): wp.setOrigin(x, y) if width or height: wp.setSize(width, height) - if subprocessWindow: - wp.setSubprocessWindow(subprocessWindow) + if windowType == 'embedded': + wp.setParentWindow(parent) base.win.requestProperties(wp) return # If we haven't got a window already, start 'er up. Apply the - # requested setting to the prc file. + # requested setting to the prc file, and to the default + # WindowProperties structure. + + self.__clearWindowProperties() if windowType == 'hidden': data = 'window-type none\n' else: data = 'window-type onscreen\n' + wp = WindowProperties.getDefault() + + wp.clearFullscreen() + wp.clearParentWindow() + wp.clearOrigin() + wp.clearSize() + if windowType == 'fullscreen': - data += 'fullscreen 1\n' - else: - data += 'fullscreen 0\n' + wp.setFullscreen(True) if windowType == 'embedded': - data += 'parent-window-handle %s\nsubprocess-window %s\n' % ( - parent, subprocessWindow) - else: - data += 'parent-window-handle 0\nsubprocess-window \n' + wp.setParentWindow(parent) if x or y or windowType == 'embedded': - data += 'win-origin %s %s\n' % (x, y) - if width or height: - data += 'win-size %s %s\n' % (width, height) + wp.setOrigin(x, y) + + if width or height: + wp.setSize(width, height) - self.__clearWindowPrc() self.windowPrc = loadPrcFileData("setupWindow", data) + WindowProperties.setDefault(wp) self.gotWindow = True @@ -726,7 +733,7 @@ class AppRunner(DirectObject): # Now that the window is open, we don't need to keep those # prc settings around any more. - self.__clearWindowPrc() + self.__clearWindowProperties() # Inform the plugin and browser. self.notifyRequest('onwindowopen') diff --git a/direct/src/plugin/Sources.pp b/direct/src/plugin/Sources.pp index a855f66d17..19b8e4fc0a 100644 --- a/direct/src/plugin/Sources.pp +++ b/direct/src/plugin/Sources.pp @@ -120,6 +120,8 @@ dtoolutil:c dtoolbase:c dtool:m \ interrogatedb:c dconfig:c dtoolconfig:m \ express:c pandaexpress:m \ + pgraph:c pgraphnodes:c cull:c gsgbase:c gobj:c \ + mathutil:c lerp:c downloader:c pnmimage:c \ prc:c pstatclient:c pandabase:c linmath:c putil:c \ pipeline:c event:c nativenet:c net:c display:c panda:m diff --git a/direct/src/plugin/p3dPythonRun.cxx b/direct/src/plugin/p3dPythonRun.cxx index 03f8a9bb29..769d2e2e7c 100755 --- a/direct/src/plugin/p3dPythonRun.cxx +++ b/direct/src/plugin/p3dPythonRun.cxx @@ -17,6 +17,12 @@ #include "binaryXml.h" #include "multifile.h" #include "virtualFileSystem.h" +#include "nativeWindowHandle.h" + +#ifndef CPPPARSER +#include "py_panda.h" +IMPORT_THIS struct Dtool_PyTypedObject Dtool_WindowHandle; +#endif // There is only one P3DPythonRun object in any given process space. // Makes the statics easier to deal with, and we don't need multiple @@ -1262,39 +1268,50 @@ setup_window(P3DCInstance *inst, TiXmlElement *xwparams) { xwparams->Attribute("win_width", &win_width); xwparams->Attribute("win_height", &win_height); - long parent_window_handle = 0; - const char *subprocess_window = ""; + PT(WindowHandle) parent_window_handle; #ifdef _WIN32 int hwnd; if (xwparams->Attribute("parent_hwnd", &hwnd)) { - parent_window_handle = (long)hwnd; + parent_window_handle = NativeWindowHandle::make_win((HWND)hwnd); } #elif __APPLE__ // On Mac, we don't parent windows directly to the browser; instead, // we have to go through this subprocess-window nonsense. - subprocess_window = xwparams->Attribute("subprocess_window"); - if (subprocess_window == NULL) { - subprocess_window = ""; + const char *subprocess_window = xwparams->Attribute("subprocess_window"); + if (subprocess_window != NULL) { + Filename filename = Filename::from_os_specific(subprocess_window); + parent_window_handle = NativeWindowHandle::make_subprocess(filename); } #elif defined(HAVE_X11) // Use stringstream to decode the "long" attribute. const char *parent_cstr = xwparams->Attribute("parent_xwindow"); if (parent_cstr != NULL) { + long window; istringstream strm(parent_cstr); - strm >> parent_window_handle; + strm >> window; + parent_window_handle = NativeWindowHandle::make_x11((Window)window); } #endif + PyObject *py_handle = Py_None; + if (parent_window_handle != NULL) { + parent_window_handle->ref(); + py_handle = DTool_CreatePyInstanceTyped(parent_window_handle, Dtool_WindowHandle, true, false, parent_window_handle->get_type_index()); + } + Py_INCREF(py_handle); + // TODO: direct this into the particular instance. This will // require a specialized ShowBase replacement. PyObject *result = PyObject_CallMethod - (_runner, (char *)"setupWindow", (char *)"siiiiis", window_type.c_str(), - win_x, win_y, win_width, win_height, - parent_window_handle, subprocess_window); + (_runner, (char *)"setupWindow", (char *)"siiiiO", window_type.c_str(), + win_x, win_y, win_width, win_height, py_handle); + + Py_DECREF(py_handle); + if (result == NULL) { PyErr_Print(); }