embrace new WindowHandle construct

This commit is contained in:
David Rose 2009-10-01 19:11:02 +00:00
parent ee1f03abe7
commit 09e6d823c4
3 changed files with 53 additions and 27 deletions

View File

@ -642,16 +642,17 @@ class AppRunner(DirectObject):
loadPrcFileData(pathname, data) loadPrcFileData(pathname, data)
def __clearWindowPrc(self): def __clearWindowProperties(self):
""" Clears the windowPrc file that was created in a previous """ Clears the windowPrc file that was created in a previous
call to setupWindow(), if any. """ call to setupWindow(), if any. """
if self.windowPrc: if self.windowPrc:
unloadPrcFile(self.windowPrc) unloadPrcFile(self.windowPrc)
self.windowPrc = None self.windowPrc = None
WindowProperties.clearDefault()
def setupWindow(self, windowType, x, y, width, height, def setupWindow(self, windowType, x, y, width, height,
parent, subprocessWindow): parent):
""" Applies the indicated window parameters to the prc """ Applies the indicated window parameters to the prc
settings, for future windows; or applies them directly to the settings, for future windows; or applies them directly to the
main window if the window has already been opened. This is main window if the window has already been opened. This is
@ -665,37 +666,43 @@ class AppRunner(DirectObject):
wp.setOrigin(x, y) wp.setOrigin(x, y)
if width or height: if width or height:
wp.setSize(width, height) wp.setSize(width, height)
if subprocessWindow: if windowType == 'embedded':
wp.setSubprocessWindow(subprocessWindow) wp.setParentWindow(parent)
base.win.requestProperties(wp) base.win.requestProperties(wp)
return return
# If we haven't got a window already, start 'er up. Apply the # 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': if windowType == 'hidden':
data = 'window-type none\n' data = 'window-type none\n'
else: else:
data = 'window-type onscreen\n' data = 'window-type onscreen\n'
wp = WindowProperties.getDefault()
wp.clearFullscreen()
wp.clearParentWindow()
wp.clearOrigin()
wp.clearSize()
if windowType == 'fullscreen': if windowType == 'fullscreen':
data += 'fullscreen 1\n' wp.setFullscreen(True)
else:
data += 'fullscreen 0\n'
if windowType == 'embedded': if windowType == 'embedded':
data += 'parent-window-handle %s\nsubprocess-window %s\n' % ( wp.setParentWindow(parent)
parent, subprocessWindow)
else:
data += 'parent-window-handle 0\nsubprocess-window \n'
if x or y or windowType == 'embedded': if x or y or windowType == 'embedded':
data += 'win-origin %s %s\n' % (x, y) wp.setOrigin(x, y)
if width or height:
data += 'win-size %s %s\n' % (width, height) if width or height:
wp.setSize(width, height)
self.__clearWindowPrc()
self.windowPrc = loadPrcFileData("setupWindow", data) self.windowPrc = loadPrcFileData("setupWindow", data)
WindowProperties.setDefault(wp)
self.gotWindow = True self.gotWindow = True
@ -726,7 +733,7 @@ class AppRunner(DirectObject):
# Now that the window is open, we don't need to keep those # Now that the window is open, we don't need to keep those
# prc settings around any more. # prc settings around any more.
self.__clearWindowPrc() self.__clearWindowProperties()
# Inform the plugin and browser. # Inform the plugin and browser.
self.notifyRequest('onwindowopen') self.notifyRequest('onwindowopen')

View File

@ -120,6 +120,8 @@
dtoolutil:c dtoolbase:c dtool:m \ dtoolutil:c dtoolbase:c dtool:m \
interrogatedb:c dconfig:c dtoolconfig:m \ interrogatedb:c dconfig:c dtoolconfig:m \
express:c pandaexpress: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 \ prc:c pstatclient:c pandabase:c linmath:c putil:c \
pipeline:c event:c nativenet:c net:c display:c panda:m pipeline:c event:c nativenet:c net:c display:c panda:m

View File

@ -17,6 +17,12 @@
#include "binaryXml.h" #include "binaryXml.h"
#include "multifile.h" #include "multifile.h"
#include "virtualFileSystem.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. // There is only one P3DPythonRun object in any given process space.
// Makes the statics easier to deal with, and we don't need multiple // 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_width", &win_width);
xwparams->Attribute("win_height", &win_height); xwparams->Attribute("win_height", &win_height);
long parent_window_handle = 0; PT(WindowHandle) parent_window_handle;
const char *subprocess_window = "";
#ifdef _WIN32 #ifdef _WIN32
int hwnd; int hwnd;
if (xwparams->Attribute("parent_hwnd", &hwnd)) { if (xwparams->Attribute("parent_hwnd", &hwnd)) {
parent_window_handle = (long)hwnd; parent_window_handle = NativeWindowHandle::make_win((HWND)hwnd);
} }
#elif __APPLE__ #elif __APPLE__
// On Mac, we don't parent windows directly to the browser; instead, // On Mac, we don't parent windows directly to the browser; instead,
// we have to go through this subprocess-window nonsense. // we have to go through this subprocess-window nonsense.
subprocess_window = xwparams->Attribute("subprocess_window"); const char *subprocess_window = xwparams->Attribute("subprocess_window");
if (subprocess_window == NULL) { if (subprocess_window != NULL) {
subprocess_window = ""; Filename filename = Filename::from_os_specific(subprocess_window);
parent_window_handle = NativeWindowHandle::make_subprocess(filename);
} }
#elif defined(HAVE_X11) #elif defined(HAVE_X11)
// Use stringstream to decode the "long" attribute. // Use stringstream to decode the "long" attribute.
const char *parent_cstr = xwparams->Attribute("parent_xwindow"); const char *parent_cstr = xwparams->Attribute("parent_xwindow");
if (parent_cstr != NULL) { if (parent_cstr != NULL) {
long window;
istringstream strm(parent_cstr); istringstream strm(parent_cstr);
strm >> parent_window_handle; strm >> window;
parent_window_handle = NativeWindowHandle::make_x11((Window)window);
} }
#endif #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 // TODO: direct this into the particular instance. This will
// require a specialized ShowBase replacement. // require a specialized ShowBase replacement.
PyObject *result = PyObject_CallMethod PyObject *result = PyObject_CallMethod
(_runner, (char *)"setupWindow", (char *)"siiiiis", window_type.c_str(), (_runner, (char *)"setupWindow", (char *)"siiiiO", window_type.c_str(),
win_x, win_y, win_width, win_height, win_x, win_y, win_width, win_height, py_handle);
parent_window_handle, subprocess_window);
Py_DECREF(py_handle);
if (result == NULL) { if (result == NULL) {
PyErr_Print(); PyErr_Print();
} }