summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorGeorg Richter <georg@php.net>2001-12-28 10:35:53 +0000
committerGeorg Richter <georg@php.net>2001-12-28 10:35:53 +0000
commit87932e1e598275ddf9ae679a85bd03a94f8b03b8 (patch)
treea48e7ed4a2673cb1af62ffab1cd714a231c1f643 /ext
parentb22a77601836ce3ab79e63f9fffe0972d07fd454 (diff)
downloadphp-git-87932e1e598275ddf9ae679a85bd03a94f8b03b8.tar.gz
mouse support for ncurses added:
ncurses_getmouse, ncurses_ungetmouse, ncurses_mouse_trafo, ncurses_wmouse_trafo
Diffstat (limited to 'ext')
-rw-r--r--ext/ncurses/ncurses_fe.c9
-rw-r--r--ext/ncurses/ncurses_functions.c144
-rw-r--r--ext/ncurses/php_ncurses_fe.h4
3 files changed, 151 insertions, 6 deletions
diff --git a/ext/ncurses/ncurses_fe.c b/ext/ncurses/ncurses_fe.c
index 769ba4fb6b..7cf3583bde 100644
--- a/ext/ncurses/ncurses_fe.c
+++ b/ext/ncurses/ncurses_fe.c
@@ -25,8 +25,11 @@
#include "php_ini.h"
#include "php_ncurses.h"
-static unsigned char second_args_force_ref[] = {2, BYREF_NONE, BYREF_FORCE};
static unsigned char first_args_force_ref[] = {1, BYREF_FORCE};
+static unsigned char firstandsecond_args_force_ref[] = {2, BYREF_FORCE, BYREF_FORCE};
+static unsigned char second_args_force_ref[] = {2, BYREF_NONE, BYREF_FORCE};
+static unsigned char secondandthird_args_force_ref[] = {3, BYREF_NONE, BYREF_FORCE, BYREF_FORCE};
+
/* ncurses_functions[]
*
* Every user visible function must have an entry in ncurses_functions[].
@@ -147,6 +150,10 @@ function_entry ncurses_functions[] = {
PHP_FE(ncurses_termname, NULL)
PHP_FE(ncurses_longname, NULL)
PHP_FE(ncurses_mousemask, second_args_force_ref)
+ PHP_FE(ncurses_getmouse, first_args_force_ref)
+ PHP_FE(ncurses_ungetmouse, NULL)
+ PHP_FE(ncurses_mouse_trafo, firstandsecond_args_force_ref)
+ PHP_FE(ncurses_wmouse_trafo, secondandthird_args_force_ref)
PHP_FE(ncurses_waddstr, NULL)
PHP_FE(ncurses_wnoutrefresh, NULL)
PHP_FE(ncurses_wclear, NULL)
diff --git a/ext/ncurses/ncurses_functions.c b/ext/ncurses/ncurses_functions.c
index 0c0fe1aa16..aa59a7328c 100644
--- a/ext/ncurses/ncurses_functions.c
+++ b/ext/ncurses/ncurses_functions.c
@@ -38,7 +38,7 @@ PHP_FUNCTION(ncurses_addch)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&ch)==FAILURE) {
return;
}
-
+
RETURN_LONG(addch(ch));
}
/* }}} */
@@ -678,11 +678,11 @@ PHP_FUNCTION(ncurses_insdelln)
PHP_FUNCTION(ncurses_mouseinterval)
{
long intarg;
-
+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&intarg)==FAILURE) {
return;
}
-
+
RETURN_LONG(mouseinterval(intarg));
}
/* }}} */
@@ -734,7 +734,7 @@ PHP_FUNCTION(ncurses_slk_attroff)
PHP_FUNCTION(ncurses_slk_attron)
{
long intarg;
-
+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&intarg)==FAILURE) {
return;
}
@@ -1447,7 +1447,141 @@ PHP_FUNCTION(ncurses_mousemask)
}
/* }}} */
-/* {{{ proto int ncurses_wmove(resource WINDOW, int x, int y)
+/* {{{ proto int ncurses_getmouse(array mevent)
+ Reads mouse event from queue */
+PHP_FUNCTION(ncurses_getmouse)
+{
+ zval **arg;
+ MEVENT mevent;
+ ulong retval;
+
+ if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE){
+ WRONG_PARAM_COUNT;
+ }
+
+ pval_destructor(*arg);
+ array_init(*arg);
+
+ retval = getmouse(&mevent);
+
+ add_assoc_long(*arg, "id", mevent.id);
+ add_assoc_long(*arg, "x", mevent.x);
+ add_assoc_long(*arg, "y", mevent.y);
+ add_assoc_long(*arg, "z", mevent.z);
+ add_assoc_long(*arg, "mmask", mevent.bstate);
+
+ RETURN_LONG(retval);
+}
+/* }}} */
+
+/* {{{ proto int ncurses_ungetmouse(array mevent)
+ push mouse event to queue */
+PHP_FUNCTION(ncurses_ungetmouse)
+{
+ zval **arg, **pvalue;
+ MEVENT mevent;
+ ulong retval;
+
+ if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE){
+ WRONG_PARAM_COUNT;
+ }
+
+ if (Z_TYPE_PP(arg) != IS_ARRAY){
+ php_error(E_WARNING, "ncurses_ungetmouse: expected mevent as array");
+ RETURN_FALSE;
+ }
+
+ if (zend_hash_find(Z_ARRVAL_PP(arg), "id", sizeof("id"), (void **) &pvalue)== SUCCESS) {
+ convert_to_long_ex(pvalue);
+ mevent.id = Z_LVAL_PP(pvalue);
+ }
+
+ if (zend_hash_find(Z_ARRVAL_PP(arg), "x", sizeof("x"), (void **) &pvalue)== SUCCESS) {
+ convert_to_long_ex(pvalue);
+ mevent.x = Z_LVAL_PP(pvalue);
+ }
+
+ if (zend_hash_find(Z_ARRVAL_PP(arg), "y", sizeof("y"), (void **) &pvalue)== SUCCESS) {
+ convert_to_long_ex(pvalue);
+ mevent.y = Z_LVAL_PP(pvalue);
+ }
+
+ if (zend_hash_find(Z_ARRVAL_PP(arg), "z", sizeof("z"), (void **) &pvalue)== SUCCESS) {
+ convert_to_long_ex(pvalue);
+ mevent.z = Z_LVAL_PP(pvalue);
+ }
+
+ if (zend_hash_find(Z_ARRVAL_PP(arg), "mmask", sizeof("mmask"), (void **) &pvalue)== SUCCESS) {
+ convert_to_long_ex(pvalue);
+ mevent.bstate = Z_LVAL_PP(pvalue);
+ }
+
+ retval = ungetmouse(&mevent);
+
+ RETURN_LONG(retval);
+}
+/* }}} */
+
+/* {{{ proto bool ncurses_mouse_trafo(int y, int x, bool toscreen)
+ transform coordinates */
+PHP_FUNCTION(ncurses_mouse_trafo)
+{
+ zval **x, **y, **toscreen;
+ ulong nx, ny, retval;
+
+ WINDOW **win;
+ if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &y, &x, &toscreen) == FAILURE){
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_long_ex(x);
+ convert_to_long_ex(y);
+ convert_to_boolean_ex(toscreen);
+
+ ny = Z_LVAL_PP(y);
+ nx = Z_LVAL_PP(x);
+
+ retval = mouse_trafo (&ny, &nx, Z_LVAL_PP(toscreen));
+
+ Z_LVAL_PP(y) = ny;
+ Z_LVAL_PP(x) = nx;
+
+ RETURN_BOOL(retval);
+}
+/* }}} */
+
+/* {{{ proto bool ncurses_wmouse_trafo(resource WINDOW, int y, int x, bool toscreen)
+ Transforms window/stdscr coordinates */
+PHP_FUNCTION(ncurses_wmouse_trafo)
+{
+ zval **handle, **x, **y, **toscreen;
+ ulong nx, ny, retval;
+ WINDOW **win;
+
+ if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &y, &x, &toscreen) == FAILURE){
+ WRONG_PARAM_COUNT;
+ }
+
+ FETCH_WINRES(win, handle);
+
+ convert_to_long_ex(x);
+ convert_to_long_ex(y);
+ convert_to_boolean_ex(toscreen);
+
+ ny = Z_LVAL_PP(y);
+ nx = Z_LVAL_PP(x);
+
+ retval = wmouse_trafo (*win, &ny, &nx, Z_LVAL_PP(toscreen));
+
+ Z_LVAL_PP(y) = ny;
+ Z_LVAL_PP(x) = nx;
+
+ RETURN_BOOL(retval);
+}
+/* }}} */
+
+
+/* {{{ proto int ncurses_wmove(resource WINDOW, int y, int x)
Moves windows output position */
PHP_FUNCTION(ncurses_wmove)
{
diff --git a/ext/ncurses/php_ncurses_fe.h b/ext/ncurses/php_ncurses_fe.h
index 154666f387..0b595f06db 100644
--- a/ext/ncurses/php_ncurses_fe.h
+++ b/ext/ncurses/php_ncurses_fe.h
@@ -135,6 +135,10 @@ PHP_FUNCTION(ncurses_keyok);
PHP_FUNCTION(ncurses_termname);
PHP_FUNCTION(ncurses_longname);
PHP_FUNCTION(ncurses_mousemask);
+PHP_FUNCTION(ncurses_getmouse);
+PHP_FUNCTION(ncurses_ungetmouse);
+PHP_FUNCTION(ncurses_mouse_trafo);
+PHP_FUNCTION(ncurses_wmouse_trafo);
PHP_FUNCTION(ncurses_waddstr);
PHP_FUNCTION(ncurses_wnoutrefresh);
PHP_FUNCTION(ncurses_wclear);