瀏覽代碼

further interface generalizations

David Rose 16 年之前
父節點
當前提交
fc10c7c5a0

+ 4 - 6
direct/src/plugin/p3dInstance.cxx

@@ -796,7 +796,7 @@ feed_url_stream(int unique_id,
 //               true if the event is handled, false if ignored.
 //               true if the event is handled, false if ignored.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool P3DInstance::
 bool P3DInstance::
-handle_event(P3D_event_data event) {
+handle_event(const P3D_event_data &event) {
   bool retval = false;
   bool retval = false;
   if (_splash_window != NULL) {
   if (_splash_window != NULL) {
     if (_splash_window->handle_event(event)) {
     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
   // Need to ensure we have the correct port set, in order to
   // convert the mouse coordinates successfully via
   // convert the mouse coordinates successfully via

+ 1 - 1
direct/src/plugin/p3dInstance.h

@@ -82,7 +82,7 @@ public:
                        const unsigned char *this_data, 
                        const unsigned char *this_data, 
                        size_t this_data_size);
                        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 int get_instance_id() const;
   inline const string &get_session_key() const;
   inline const string &get_session_key() const;

+ 3 - 2
direct/src/plugin/p3dOsxSplashWindow.cxx

@@ -201,8 +201,9 @@ set_install_progress(double install_progress) {
 //               if ignored.
 //               if ignored.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool P3DOsxSplashWindow::
 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
   // Need to ensure we have the correct port set, in order to
   // convert the mouse coordinates successfully via
   // convert the mouse coordinates successfully via

+ 1 - 1
direct/src/plugin/p3dOsxSplashWindow.h

@@ -40,7 +40,7 @@ public:
   virtual void set_install_label(const string &install_label);
   virtual void set_install_label(const string &install_label);
   virtual void set_install_progress(double install_progress);
   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:
 protected:
   virtual void refresh();
   virtual void refresh();

+ 1 - 1
direct/src/plugin/p3dSplashWindow.cxx

@@ -203,7 +203,7 @@ set_install_progress(double install_progress) {
 //               if ignored.
 //               if ignored.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool P3DSplashWindow::
 bool P3DSplashWindow::
-handle_event(P3D_event_data event) {
+handle_event(const P3D_event_data &event) {
   return false;
   return false;
 }
 }
 
 

+ 1 - 1
direct/src/plugin/p3dSplashWindow.h

@@ -60,7 +60,7 @@ public:
   virtual void set_install_label(const string &install_label);
   virtual void set_install_label(const string &install_label);
   virtual void set_install_progress(double install_progress);
   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 set_button_active(bool flag);
   virtual void request_keyboard_focus();
   virtual void request_keyboard_focus();

+ 5 - 4
direct/src/plugin/p3d_plugin.cxx

@@ -185,10 +185,10 @@ P3D_instance_setup_window(P3D_instance *instance,
                           P3D_window_type window_type,
                           P3D_window_type window_type,
                           int win_x, int win_y,
                           int win_x, int win_y,
                           int win_width, int win_height,
                           int win_width, int win_height,
-                          P3D_window_handle parent_window) {
+                          const P3D_window_handle *parent_window) {
   assert(P3DInstanceManager::get_global_ptr()->is_initialized());
   assert(P3DInstanceManager::get_global_ptr()->is_initialized());
   P3DWindowParams wparams(window_type, win_x, win_y,
   P3DWindowParams wparams(window_type, win_x, win_y,
-                          win_width, win_height, parent_window);
+                          win_width, win_height, *parent_window);
 
 
   ACQUIRE_LOCK(_api_lock);
   ACQUIRE_LOCK(_api_lock);
   P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
   P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
@@ -559,7 +559,8 @@ P3D_instance_feed_url_stream(P3D_instance *instance, int unique_id,
 }
 }
 
 
 bool
 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());
   assert(P3DInstanceManager::get_global_ptr()->is_initialized());
   ACQUIRE_LOCK(_api_lock);
   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);
   P3DInstance *inst = inst_mgr->validate_instance(instance);
   bool result = false;
   bool result = false;
   if (inst != NULL) {
   if (inst != NULL) {
-    result = inst->handle_event(event);
+    result = inst->handle_event(*event);
   }
   }
 
 
   RELEASE_LOCK(_api_lock);
   RELEASE_LOCK(_api_lock);

+ 23 - 15
direct/src/plugin/p3d_plugin.h

@@ -79,7 +79,7 @@ extern "C" {
    (below). This number will be incremented whenever there are changes
    (below). This number will be incremented whenever there are changes
    to any of the interface specifications defined in this header
    to any of the interface specifications defined in this header
    file. */
    file. */
-#define P3D_API_VERSION 9
+#define P3D_API_VERSION 10
 
 
 /************************ GLOBAL FUNCTIONS **************************/
 /************************ GLOBAL FUNCTIONS **************************/
 
 
@@ -376,7 +376,7 @@ P3D_instance_setup_window_func(P3D_instance *instance,
                                P3D_window_type window_type,
                                P3D_window_type window_type,
                                int win_x, int win_y,
                                int win_x, int win_y,
                                int win_width, int win_height,
                                int win_width, int win_height,
-                               P3D_window_handle parent_window);
+                               const P3D_window_handle *parent_window);
 
 
 
 
 /********************** SCRIPTING SUPPORT **************************/
 /********************** SCRIPTING SUPPORT **************************/
@@ -899,30 +899,38 @@ P3D_instance_feed_url_stream_func(P3D_instance *instance, int unique_id,
                                   const void *this_data, 
                                   const void *this_data, 
                                   size_t this_data_size);
                                   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. */
-typedef struct {
-#ifdef _WIN32
-  // Not used for Win32.
+/* 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. */
 
 
-#elif defined(__APPLE__)
-  EventRecord *_event;
+typedef enum {
+  P3D_ET_none = 0,
+  P3D_ET_osx_event_record,
+} P3D_event_type;
 
 
-#elif defined(HAVE_X11)
-  //  XEvent *_event; ?
+typedef struct {
+#if defined(__APPLE__)
+  EventRecord *_event;
 #endif
 #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;
 } P3D_event_data;
 
 
 /* Use this function to supply a new os-specific window event to the
 /* Use this function to supply a new os-specific window event to the
    plugin.  This is presently used only on OSX, where the window
    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,
    The return value is true if the handler has processed the event,
    false if it has been ignored. */
    false if it has been ignored. */
 typedef bool
 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
 #ifdef P3D_FUNCTION_PROTOTYPES
 
 

+ 1 - 1
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 );
     m_p3dObject = P3D_instance_get_panda_script_object( m_p3dInstance );
     P3D_OBJECT_INCREF( m_p3dObject );
     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";
     nout << "Starting new P3D instance " << p3dFilename << "\n";
 
 

+ 1 - 1
direct/src/plugin_npapi/ppInstance.cxx

@@ -1378,7 +1378,7 @@ send_window() {
   P3D_instance_setup_window
   P3D_instance_setup_window
     (_p3d_inst, window_type,
     (_p3d_inst, window_type,
      x, y, _window.width, _window.height,
      x, y, _window.width, _window.height,
-     parent_window);
+     &parent_window);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 1 - 1
direct/src/plugin_standalone/panda3d.cxx

@@ -1039,7 +1039,7 @@ create_instance(const string &p3d, bool start_instance,
     }
     }
 
 
     P3D_instance_setup_window
     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;
   return inst;