Skip to content

Instantly share code, notes, and snippets.

@jgmdev
Created August 26, 2014 23:14
Show Gist options
  • Save jgmdev/6a76f715796a8a74471e to your computer and use it in GitHub Desktop.
Save jgmdev/6a76f715796a8a74471e to your computer and use it in GitHub Desktop.
Patch to bind FilterEvent Method to wxApp
diff --git a/includes/app.h b/includes/app.h
index ed9fd0b..097a6c3 100644
--- a/includes/app.h
+++ b/includes/app.h
@@ -22,6 +22,7 @@ class wxAppWrapper : public wxApp
public:
bool OnInit();
int OnExit();
+ int FilterEvent(wxEvent& event);
#ifdef __WXMAC__
void MacNewFile();
diff --git a/src/app.cpp b/src/app.cpp
index 0776c32..00c0718 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -12,6 +12,7 @@
#include "php_wxwidgets.h"
#include "app.h"
+#include "events.h"
/**
* Set the wxWidgets application handler.
@@ -65,6 +66,20 @@ zend_object_value php_wxApp_new(zend_class_entry *class_type TSRMLS_DC)
}
END_EXTERN_C()
+bool wxAppWrapper::OnInit()
+{
+ zval *retval;
+ zval func_name;
+
+ ZVAL_STRINGL(&func_name, (char *)"OnInit", sizeof("OnInit")-1, 0);
+
+ wxFileSystem::AddHandler(new wxZipFSHandler);
+
+ call_user_function_ex(NULL, &phpObj, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC);
+
+ return true;
+}
+
int wxAppWrapper::OnExit()
{
zval *retval;
@@ -77,18 +92,89 @@ int wxAppWrapper::OnExit()
return 0;
}
-bool wxAppWrapper::OnInit()
+int wxAppWrapper::FilterEvent(wxEvent& event)
{
- zval *retval;
- zval func_name;
+ static bool is_php_user_space_implemented = true;
+
+ if(!is_php_user_space_implemented)
+ {
+ return -1;
+ }
- ZVAL_STRINGL(&func_name, (char *)"OnInit", sizeof("OnInit")-1, 0);
+ #ifdef USE_WXPHP_DEBUG
+ php_printf("Invoking virtual FilterEvent\n");
+ php_printf("===========================================\n");
+ #endif
- wxFileSystem::AddHandler(new wxZipFSHandler);
+ zval function_name;
+
+ ZVAL_STRINGL(
+ &function_name,
+ (char *)"FilterEvent",
+ 11,
+ 0
+ );
- call_user_function_ex(NULL, &phpObj, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC);
+ zval** params[1];
+ zval *arguments[1];
- return true;
+ //Initilize arguments array
+ MAKE_STD_ZVAL(arguments[0]);
+
+ zval* return_value;
+ MAKE_STD_ZVAL(return_value);
+
+ int function_called;
+
+ //Parameters for conversion
+ object_init_ex(arguments[0], php_wxEvent_entry);
+
+ ((zo_wxEvent*) zend_object_store_get_object(arguments[0] TSRMLS_CC))
+ ->native_object = (wxEvent_php*) &event
+ ;
+
+ //Set parameters that are sent to function
+ params[0] = &arguments[0];
+
+ #ifdef USE_WXPHP_DEBUG
+ php_printf("Trying to call user defined method\n");
+ #endif
+
+ function_called = call_user_function_ex(
+ NULL,
+ &phpObj,
+ &function_name,
+ &return_value,
+ 1,
+ params,
+ 0,
+ NULL TSRMLS_CC
+ );
+
+ //Delete already used parameters from memory
+ zval_ptr_dtor(&arguments[0]);
+
+ if(function_called == FAILURE)
+ {
+ is_php_user_space_implemented = false;
+
+ #ifdef USE_WXPHP_DEBUG
+ php_printf("Invocation of user defined method failed\n");
+ #endif
+
+ return -1;
+ }
+
+ #ifdef USE_WXPHP_DEBUG
+ php_printf("Returning userspace value.\n");
+ #endif
+
+ int retval = Z_LVAL_P(return_value);
+
+ zval_ptr_dtor(&return_value);
+ efree(return_value);
+
+ return retval;
}
#ifdef __WXMAC__
@@ -132,7 +218,7 @@ void wxAppWrapper::MacNewFile()
}
}
-void wxAppWrapper::MacOpenFiles ( const wxArrayString & fileNames)
+void wxAppWrapper::MacOpenFiles (const wxArrayString & fileNames)
{
static bool is_php_user_space_implemented = true;
diff --git a/tools/source_maker/source_templates/app.cpp b/tools/source_maker/source_templates/app.cpp
index 0776c32..00c0718 100644
--- a/tools/source_maker/source_templates/app.cpp
+++ b/tools/source_maker/source_templates/app.cpp
@@ -12,6 +12,7 @@
#include "php_wxwidgets.h"
#include "app.h"
+#include "events.h"
/**
* Set the wxWidgets application handler.
@@ -65,6 +66,20 @@ zend_object_value php_wxApp_new(zend_class_entry *class_type TSRMLS_DC)
}
END_EXTERN_C()
+bool wxAppWrapper::OnInit()
+{
+ zval *retval;
+ zval func_name;
+
+ ZVAL_STRINGL(&func_name, (char *)"OnInit", sizeof("OnInit")-1, 0);
+
+ wxFileSystem::AddHandler(new wxZipFSHandler);
+
+ call_user_function_ex(NULL, &phpObj, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC);
+
+ return true;
+}
+
int wxAppWrapper::OnExit()
{
zval *retval;
@@ -77,18 +92,89 @@ int wxAppWrapper::OnExit()
return 0;
}
-bool wxAppWrapper::OnInit()
+int wxAppWrapper::FilterEvent(wxEvent& event)
{
- zval *retval;
- zval func_name;
+ static bool is_php_user_space_implemented = true;
+
+ if(!is_php_user_space_implemented)
+ {
+ return -1;
+ }
- ZVAL_STRINGL(&func_name, (char *)"OnInit", sizeof("OnInit")-1, 0);
+ #ifdef USE_WXPHP_DEBUG
+ php_printf("Invoking virtual FilterEvent\n");
+ php_printf("===========================================\n");
+ #endif
- wxFileSystem::AddHandler(new wxZipFSHandler);
+ zval function_name;
+
+ ZVAL_STRINGL(
+ &function_name,
+ (char *)"FilterEvent",
+ 11,
+ 0
+ );
- call_user_function_ex(NULL, &phpObj, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC);
+ zval** params[1];
+ zval *arguments[1];
- return true;
+ //Initilize arguments array
+ MAKE_STD_ZVAL(arguments[0]);
+
+ zval* return_value;
+ MAKE_STD_ZVAL(return_value);
+
+ int function_called;
+
+ //Parameters for conversion
+ object_init_ex(arguments[0], php_wxEvent_entry);
+
+ ((zo_wxEvent*) zend_object_store_get_object(arguments[0] TSRMLS_CC))
+ ->native_object = (wxEvent_php*) &event
+ ;
+
+ //Set parameters that are sent to function
+ params[0] = &arguments[0];
+
+ #ifdef USE_WXPHP_DEBUG
+ php_printf("Trying to call user defined method\n");
+ #endif
+
+ function_called = call_user_function_ex(
+ NULL,
+ &phpObj,
+ &function_name,
+ &return_value,
+ 1,
+ params,
+ 0,
+ NULL TSRMLS_CC
+ );
+
+ //Delete already used parameters from memory
+ zval_ptr_dtor(&arguments[0]);
+
+ if(function_called == FAILURE)
+ {
+ is_php_user_space_implemented = false;
+
+ #ifdef USE_WXPHP_DEBUG
+ php_printf("Invocation of user defined method failed\n");
+ #endif
+
+ return -1;
+ }
+
+ #ifdef USE_WXPHP_DEBUG
+ php_printf("Returning userspace value.\n");
+ #endif
+
+ int retval = Z_LVAL_P(return_value);
+
+ zval_ptr_dtor(&return_value);
+ efree(return_value);
+
+ return retval;
}
#ifdef __WXMAC__
@@ -132,7 +218,7 @@ void wxAppWrapper::MacNewFile()
}
}
-void wxAppWrapper::MacOpenFiles ( const wxArrayString & fileNames)
+void wxAppWrapper::MacOpenFiles (const wxArrayString & fileNames)
{
static bool is_php_user_space_implemented = true;
diff --git a/tools/source_maker/source_templates/app.h b/tools/source_maker/source_templates/app.h
index ed9fd0b..097a6c3 100644
--- a/tools/source_maker/source_templates/app.h
+++ b/tools/source_maker/source_templates/app.h
@@ -22,6 +22,7 @@ class wxAppWrapper : public wxApp
public:
bool OnInit();
int OnExit();
+ int FilterEvent(wxEvent& event);
#ifdef __WXMAC__
void MacNewFile();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment