From fc10c7c5a02400d9dbc07e3b9fee0141e1855f9e Mon Sep 17 00:00:00 2001 From: David Rose Date: Sat, 21 Nov 2009 01:20:55 +0000 Subject: [PATCH] further interface generalizations --- direct/src/plugin/p3dInstance.cxx | 10 +++---- direct/src/plugin/p3dInstance.h | 2 +- direct/src/plugin/p3dOsxSplashWindow.cxx | 5 ++-- direct/src/plugin/p3dOsxSplashWindow.h | 2 +- direct/src/plugin/p3dSplashWindow.cxx | 2 +- direct/src/plugin/p3dSplashWindow.h | 2 +- direct/src/plugin/p3d_plugin.cxx | 9 +++--- direct/src/plugin/p3d_plugin.h | 38 ++++++++++++++---------- direct/src/plugin_activex/PPInstance.cpp | 2 +- direct/src/plugin_npapi/ppInstance.cxx | 2 +- direct/src/plugin_standalone/panda3d.cxx | 2 +- 11 files changed, 42 insertions(+), 34 deletions(-) diff --git a/direct/src/plugin/p3dInstance.cxx b/direct/src/plugin/p3dInstance.cxx index f9034c49f3..db0aadd5c3 100644 --- a/direct/src/plugin/p3dInstance.cxx +++ b/direct/src/plugin/p3dInstance.cxx @@ -796,7 +796,7 @@ feed_url_stream(int unique_id, // true if the event is handled, false if ignored. //////////////////////////////////////////////////////////////////// bool P3DInstance:: -handle_event(P3D_event_data event) { +handle_event(const P3D_event_data &event) { bool retval = false; if (_splash_window != NULL) { if (_splash_window->handle_event(event)) { @@ -804,11 +804,9 @@ handle_event(P3D_event_data event) { } } -#ifdef _WIN32 - // This function is not used in Win32 and does nothing. - -#elif defined(__APPLE__) - EventRecord *er = event._event; +#if defined(__APPLE__) + assert(event._event_type == P3D_ET_osx_event_record); + EventRecord *er = event._event._osx_event_record._event; // Need to ensure we have the correct port set, in order to // convert the mouse coordinates successfully via diff --git a/direct/src/plugin/p3dInstance.h b/direct/src/plugin/p3dInstance.h index ca10e44961..b88985905d 100644 --- a/direct/src/plugin/p3dInstance.h +++ b/direct/src/plugin/p3dInstance.h @@ -82,7 +82,7 @@ public: const unsigned char *this_data, size_t this_data_size); - bool handle_event(P3D_event_data event); + bool handle_event(const P3D_event_data &event); inline int get_instance_id() const; inline const string &get_session_key() const; diff --git a/direct/src/plugin/p3dOsxSplashWindow.cxx b/direct/src/plugin/p3dOsxSplashWindow.cxx index a3eab71785..5583aa2e7a 100644 --- a/direct/src/plugin/p3dOsxSplashWindow.cxx +++ b/direct/src/plugin/p3dOsxSplashWindow.cxx @@ -201,8 +201,9 @@ set_install_progress(double install_progress) { // if ignored. //////////////////////////////////////////////////////////////////// bool P3DOsxSplashWindow:: -handle_event(P3D_event_data event) { - EventRecord *er = event._event; +handle_event(const P3D_event_data &event) { + assert(event._event_type == P3D_ET_osx_event_record); + EventRecord *er = event._event._osx_event_record._event; // Need to ensure we have the correct port set, in order to // convert the mouse coordinates successfully via diff --git a/direct/src/plugin/p3dOsxSplashWindow.h b/direct/src/plugin/p3dOsxSplashWindow.h index 7fd01a5583..a8ab0eeb1a 100644 --- a/direct/src/plugin/p3dOsxSplashWindow.h +++ b/direct/src/plugin/p3dOsxSplashWindow.h @@ -40,7 +40,7 @@ public: virtual void set_install_label(const string &install_label); virtual void set_install_progress(double install_progress); - virtual bool handle_event(P3D_event_data event); + virtual bool handle_event(const P3D_event_data &event); protected: virtual void refresh(); diff --git a/direct/src/plugin/p3dSplashWindow.cxx b/direct/src/plugin/p3dSplashWindow.cxx index f67e302eb8..933e037c31 100755 --- a/direct/src/plugin/p3dSplashWindow.cxx +++ b/direct/src/plugin/p3dSplashWindow.cxx @@ -203,7 +203,7 @@ set_install_progress(double install_progress) { // if ignored. //////////////////////////////////////////////////////////////////// bool P3DSplashWindow:: -handle_event(P3D_event_data event) { +handle_event(const P3D_event_data &event) { return false; } diff --git a/direct/src/plugin/p3dSplashWindow.h b/direct/src/plugin/p3dSplashWindow.h index 34740bc65a..8b609441ff 100755 --- a/direct/src/plugin/p3dSplashWindow.h +++ b/direct/src/plugin/p3dSplashWindow.h @@ -60,7 +60,7 @@ public: virtual void set_install_label(const string &install_label); virtual void set_install_progress(double install_progress); - virtual bool handle_event(P3D_event_data event); + virtual bool handle_event(const P3D_event_data &event); virtual void set_button_active(bool flag); virtual void request_keyboard_focus(); diff --git a/direct/src/plugin/p3d_plugin.cxx b/direct/src/plugin/p3d_plugin.cxx index 8829f5638e..f33d39d707 100644 --- a/direct/src/plugin/p3d_plugin.cxx +++ b/direct/src/plugin/p3d_plugin.cxx @@ -185,10 +185,10 @@ P3D_instance_setup_window(P3D_instance *instance, P3D_window_type window_type, int win_x, int win_y, int win_width, int win_height, - P3D_window_handle parent_window) { + const P3D_window_handle *parent_window) { assert(P3DInstanceManager::get_global_ptr()->is_initialized()); P3DWindowParams wparams(window_type, win_x, win_y, - win_width, win_height, parent_window); + win_width, win_height, *parent_window); ACQUIRE_LOCK(_api_lock); P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr(); @@ -559,7 +559,8 @@ P3D_instance_feed_url_stream(P3D_instance *instance, int unique_id, } bool -P3D_instance_handle_event(P3D_instance *instance, P3D_event_data event) { +P3D_instance_handle_event(P3D_instance *instance, + const P3D_event_data *event) { assert(P3DInstanceManager::get_global_ptr()->is_initialized()); ACQUIRE_LOCK(_api_lock); @@ -567,7 +568,7 @@ P3D_instance_handle_event(P3D_instance *instance, P3D_event_data event) { P3DInstance *inst = inst_mgr->validate_instance(instance); bool result = false; if (inst != NULL) { - result = inst->handle_event(event); + result = inst->handle_event(*event); } RELEASE_LOCK(_api_lock); diff --git a/direct/src/plugin/p3d_plugin.h b/direct/src/plugin/p3d_plugin.h index 2bd910c3ad..0059240da6 100644 --- a/direct/src/plugin/p3d_plugin.h +++ b/direct/src/plugin/p3d_plugin.h @@ -79,7 +79,7 @@ extern "C" { (below). This number will be incremented whenever there are changes to any of the interface specifications defined in this header file. */ -#define P3D_API_VERSION 9 +#define P3D_API_VERSION 10 /************************ GLOBAL FUNCTIONS **************************/ @@ -376,7 +376,7 @@ P3D_instance_setup_window_func(P3D_instance *instance, P3D_window_type window_type, int win_x, int win_y, int win_width, int win_height, - P3D_window_handle parent_window); + const P3D_window_handle *parent_window); /********************** SCRIPTING SUPPORT **************************/ @@ -899,30 +899,38 @@ P3D_instance_feed_url_stream_func(P3D_instance *instance, int unique_id, const void *this_data, size_t this_data_size); -/* This structure abstracts out the event pointer data types for the - different platforms, as passed to P3D_instance_handle_event(), - below. */ +/* This enum and set of structures abstract out the event pointer data + types for the different platforms, as passed to + P3D_instance_handle_event(), below. */ + +typedef enum { + P3D_ET_none = 0, + P3D_ET_osx_event_record, +} P3D_event_type; + typedef struct { -#ifdef _WIN32 - // Not used for Win32. - -#elif defined(__APPLE__) +#if defined(__APPLE__) EventRecord *_event; - -#elif defined(HAVE_X11) - // XEvent *_event; ? #endif +} P3D_event_osx_event_record; + +typedef struct { + P3D_event_type _event_type; + union { + P3D_event_osx_event_record _osx_event_record; + } _event; } P3D_event_data; /* Use this function to supply a new os-specific window event to the plugin. This is presently used only on OSX, where the window - events are needed for proper plugin handling; and possibly also on - X11. On Windows, window events are handled natively by the plugin. + events are needed for proper plugin handling. On Windows and X11, + window events are handled natively by the plugin. The return value is true if the handler has processed the event, false if it has been ignored. */ typedef bool -P3D_instance_handle_event_func(P3D_instance *instance, P3D_event_data event); +P3D_instance_handle_event_func(P3D_instance *instance, + const P3D_event_data *event); #ifdef P3D_FUNCTION_PROTOTYPES diff --git a/direct/src/plugin_activex/PPInstance.cpp b/direct/src/plugin_activex/PPInstance.cpp index 26a52cf0ac..11f41c72a6 100644 --- a/direct/src/plugin_activex/PPInstance.cpp +++ b/direct/src/plugin_activex/PPInstance.cpp @@ -530,7 +530,7 @@ int PPInstance::Start( const std::string& p3dFilename ) m_p3dObject = P3D_instance_get_panda_script_object( m_p3dInstance ); P3D_OBJECT_INCREF( m_p3dObject ); - P3D_instance_setup_window( m_p3dInstance, P3D_WT_embedded, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, parent_window ); + P3D_instance_setup_window( m_p3dInstance, P3D_WT_embedded, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, &parent_window ); nout << "Starting new P3D instance " << p3dFilename << "\n"; diff --git a/direct/src/plugin_npapi/ppInstance.cxx b/direct/src/plugin_npapi/ppInstance.cxx index 081d7794cd..8a7e1fb98a 100644 --- a/direct/src/plugin_npapi/ppInstance.cxx +++ b/direct/src/plugin_npapi/ppInstance.cxx @@ -1378,7 +1378,7 @@ send_window() { P3D_instance_setup_window (_p3d_inst, window_type, x, y, _window.width, _window.height, - parent_window); + &parent_window); } //////////////////////////////////////////////////////////////////// diff --git a/direct/src/plugin_standalone/panda3d.cxx b/direct/src/plugin_standalone/panda3d.cxx index e34441e425..72f1ea3326 100644 --- a/direct/src/plugin_standalone/panda3d.cxx +++ b/direct/src/plugin_standalone/panda3d.cxx @@ -1039,7 +1039,7 @@ create_instance(const string &p3d, bool start_instance, } P3D_instance_setup_window - (inst, _window_type, _win_x, _win_y, _win_width, _win_height, _parent_window); + (inst, _window_type, _win_x, _win_y, _win_width, _win_height, &_parent_window); } return inst;