/source_maker/templates/class_methods/wxevthandler_connect.php

https://bitbucket.org/lordgnu/wxphp · PHP · 196 lines · 144 code · 26 blank · 26 comment · 16 complexity · e51bdfc75b551c97224016ee59ec3622 MD5 · raw file

  1. void <?=$class_name?>_php::onEvent(wxEvent& evnt)
  2. {
  3. #ifdef USE_WXPHP_DEBUG
  4. php_printf("Invoking virtual <?=$class_name?>::onEvent\n");
  5. php_printf("===========================================\n");
  6. #endif
  7. zval *arg[1];
  8. MAKE_STD_ZVAL(arg[0]);
  9. char _wxResource[] = "wxResource";
  10. TSRMLS_FETCH();
  11. if(0)
  12. {}
  13. <? foreach(derivationsOfClass('wxEvent') as $kevn=>$vevn){ ?>
  14. else if(!tcscmp(evnt.GetClassInfo()->GetClassName(), wxT("<?=$kevn?>")))
  15. {
  16. #ifdef USE_WXPHP_DEBUG
  17. php_printf("Converting event type '<?=$kevn?>' to zval to call user function.\n\n");
  18. #endif
  19. object_init_ex(arg[0], php_<?=$kevn?>_entry);
  20. add_property_resource(arg[0], _wxResource, zend_list_insert(&evnt, le_<?=$kevn?>));
  21. }
  22. <? } ?>
  23. else if(!tcscmp(evnt.GetClassInfo()->GetClassName(), wxT("wxEvent")))
  24. {
  25. #ifdef USE_WXPHP_DEBUG
  26. php_printf("Converting event type 'wxEvent' to zval to call user function.\n\n");
  27. #endif
  28. object_init_ex(arg[0], php_wxEvent_entry);
  29. add_property_resource(arg[0], _wxResource, zend_list_insert(&evnt, le_wxEvent));
  30. }
  31. else
  32. {
  33. #ifdef USE_WXPHP_DEBUG
  34. php_printf("Event type not declared\n\n");
  35. #endif
  36. wxString errorMsg;
  37. errorMsg += "Failed to pass as argument event of type: ";
  38. errorMsg += evnt.GetClassInfo()->GetClassName();
  39. wxMessageBox(errorMsg);
  40. }
  41. char* wxname;
  42. zval dummy;
  43. zval* fc_name;
  44. wxCommandEvent* ce;
  45. wxPhpClientData* co;
  46. ce = (wxCommandEvent*) evnt.m_callbackUserData;
  47. co = (wxPhpClientData*) ce->GetClientObject();
  48. MAKE_STD_ZVAL(fc_name);
  49. wxname = (char*)malloc(sizeof(wxChar)*(ce->GetString().size()+1));
  50. strcpy(wxname, (const char *) ce->GetString().char_str());
  51. ZVAL_STRING(fc_name, wxname, 1);
  52. //Free allocated memory since ZVAL_STRING does a copy of it
  53. free(wxname);
  54. if(call_user_function(NULL, &(co->phpObj), fc_name, &dummy, 1, arg TSRMLS_CC) == FAILURE)
  55. {
  56. wxString errorMessage = "Failed to call method: '";
  57. errorMessage += ce->GetString().char_str();
  58. errorMessage += "'";
  59. wxMessageBox(errorMessage);
  60. }
  61. }
  62. PHP_METHOD(php_<?=$class_name?>, Connect)
  63. {
  64. #ifdef USE_WXPHP_DEBUG
  65. php_printf("Invoking <?=$class_name?>::Connect\n");
  66. php_printf("===========================================\n");
  67. php_printf("Parameters received: %d\n", ZEND_NUM_ARGS());
  68. #endif
  69. zval **tmp;
  70. int rsrc_type;
  71. int id_to_find;
  72. int valid = 1;
  73. char _wxResource[] = "wxResource";
  74. wxEvtHandler *_this;
  75. if(getThis())
  76. {
  77. if(zend_hash_find(Z_OBJPROP_P(getThis()), _wxResource, sizeof(_wxResource), (void **)&tmp) == FAILURE)
  78. {
  79. return;
  80. }
  81. }
  82. else
  83. {
  84. zend_error(E_ERROR, "Failed to get parent object of Connect method");
  85. }
  86. id_to_find = Z_RESVAL_P(*tmp);
  87. _this = (wxEvtHandler*) zend_list_find(id_to_find, &rsrc_type);
  88. zval* fc;
  89. long flag, id0 = 0, id1 = 0;
  90. zval** fc_obj;
  91. zval** fc_name;
  92. char* ct;
  93. int args = ZEND_NUM_ARGS();
  94. //To supress some warnings due to passing a string directly
  95. char parse_parameters_4[] = "lllz";
  96. char parse_parameters_3[] = "llz";
  97. char parse_parameters_2[] = "lz";
  98. switch(args)
  99. {
  100. case 4:
  101. #ifdef USE_WXPHP_DEBUG
  102. php_printf("Parsing parameters with \"lllz\"\n");
  103. #endif
  104. if(zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, args TSRMLS_CC, parse_parameters_4, &id0, &id1, &flag , (void**)&fc) == FAILURE)
  105. {
  106. zend_error(E_ERROR, "Incorrect type of parameters");
  107. return;
  108. }
  109. break;
  110. case 3:
  111. #ifdef USE_WXPHP_DEBUG
  112. php_printf("Parsing parameters with \"llz\"\n");
  113. #endif
  114. if(zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, args TSRMLS_CC, parse_parameters_3, &id0, &flag , (void**)&fc) == FAILURE)
  115. {
  116. zend_error(E_ERROR, "Incorrect type of parameters");
  117. return;
  118. }
  119. break;
  120. case 2:
  121. #ifdef USE_WXPHP_DEBUG
  122. php_printf("Parsing parameters with \"lz\"\n");
  123. #endif
  124. if(zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, args TSRMLS_CC, parse_parameters_2, &flag , (void**)&fc) == FAILURE)
  125. {
  126. zend_error(E_ERROR, "Incorrect type of parameters");
  127. return;
  128. }
  129. break;
  130. default:
  131. zend_error(E_ERROR, "Wrong amount of parameters");
  132. }
  133. zend_hash_index_find(HASH_OF(fc), 0, (void**)&fc_obj);
  134. zend_hash_index_find(HASH_OF(fc), 1, (void**)&fc_name);
  135. Z_ADDREF_P(*fc_obj);
  136. ct = (*fc_name)->value.str.val;
  137. wxCommandEvent* ce = new wxCommandEvent();
  138. ce->SetString(wxString::Format(wxT("%s"), ct));
  139. ce->SetClientObject(new wxPhpClientData(*fc_obj));
  140. switch(args)
  141. {
  142. case 4:
  143. #ifdef USE_WXPHP_DEBUG
  144. php_printf("Executing: _this->Connect(id0, id1, flag, wxEventHandler(<?=$class_name?>_php::onEvent), ce);\n");
  145. php_printf("Object id: %d Object last id: %d Event type: %d\n", (int)id0, (int)id1, (int)flag);
  146. #endif
  147. _this->Connect(id0, id1, flag, wxEventHandler(<?=$class_name?>_php::onEvent), ce);
  148. break;
  149. case 3:
  150. #ifdef USE_WXPHP_DEBUG
  151. php_printf("Executing: _this->Connect(id0, flag, wxEventHandler(<?=$class_name?>_php::onEvent), ce);\n");
  152. php_printf("Object id: %d Event type: %d\n", (int)id0, (int)flag);
  153. #endif
  154. _this->Connect(id0, flag, wxEventHandler(<?=$class_name?>_php::onEvent), ce);
  155. break;
  156. case 2:
  157. #ifdef USE_WXPHP_DEBUG
  158. php_printf("Executing: _this->Connect(flag, wxEventHandler(<?=$class_name?>_php::onEvent), ce);\n");
  159. php_printf("Event type: %d\n", (int)flag);
  160. #endif
  161. _this->Connect(flag, wxEventHandler(<?=$class_name?>_php::onEvent), ce);
  162. break;
  163. default:
  164. wxMessageBox(_T("Failed to create event\n"));
  165. break;
  166. }
  167. #ifdef USE_WXPHP_DEBUG
  168. php_printf("===========================================\n\n");
  169. #endif
  170. }