/*! \brief Evaluates the stroke. * \par Function Description * This function transforms the stroke input so far in an action. * * It makes use of the guile procedure <B>eval-stroke</B> to evaluate * the stroke sequence into a possible action. The mouse footprint is * erased in this function. * * It returns 1 if the stroke has been successfully evaluated as an * action. It returns 0 if libstroke failed to transform the stroke * or there is no action attached to the stroke. * * \param [in] w_current The GschemToplevel object. * \returns 1 on success, 0 otherwise. */ gint x_stroke_translate_and_execute (GschemToplevel *w_current) { gchar sequence[STROKE_MAX_SEQUENCE]; StrokePoint *point; int min_x, min_y, max_x, max_y; guint i; g_assert (stroke_points != NULL); if (stroke_points->len == 0) return 0; point = &g_array_index (stroke_points, StrokePoint, 0); min_x = max_x = point->x; min_y = max_y = point->y; for (i = 1; i < stroke_points->len; i++) { point = &g_array_index (stroke_points, StrokePoint, i); min_x = MIN (min_x, point->x); min_y = MIN (min_y, point->y); max_x = MAX (max_x, point->x); max_y = MAX (max_y, point->y); } o_invalidate_rect (w_current, min_x, min_y, max_x + 1, max_y + 1); /* resets length of array */ stroke_points->len = 0; /* try evaluating stroke */ if (stroke_trans ((char*)&sequence)) { gchar *guile_string = g_strdup_printf("(eval-stroke \"%s\")", sequence); SCM ret; scm_dynwind_begin ((scm_t_dynwind_flags) 0); scm_dynwind_unwind_handler (g_free, guile_string, SCM_F_WIND_EXPLICITLY); ret = g_scm_c_eval_string_protected (guile_string); scm_dynwind_end (); return (SCM_NFALSEP (ret)); } return 0; }
/*! \brief Evaluates the stroke. * \par Function Description * This function transforms the stroke input so far in an action. * * It makes use of the guile procedure <B>eval-stroke</B> to evaluate * the stroke sequence into a possible action. The mouse footprint is * erased in this function. * * It returns 1 if the stroke has been successfully evaluated as an * action. It returns 0 if libstroke failed to transform the stroke * or there is no action attached to the stroke. * * \param [in] w_current The GSCHEM_TOPLEVEL object. * \returns 1 on success, 0 otherwise. */ gint x_stroke_translate_and_execute (GSCHEM_TOPLEVEL *w_current) { gchar sequence[STROKE_MAX_SEQUENCE]; StrokePoint *point; int min_x, min_y, max_x, max_y; gint i; g_assert (stroke_points != NULL); if (stroke_points->len == 0) return 0; point = &g_array_index (stroke_points, StrokePoint, 0); min_x = max_x = point->x; min_y = max_y = point->y; for (i = 1; i < stroke_points->len; i++) { point = &g_array_index (stroke_points, StrokePoint, i); min_x = min (min_x, point->x); min_y = min (min_y, point->y); max_x = max (max_x, point->x); max_y = max (max_y, point->y); } o_invalidate_rect (w_current, min_x, min_y, max_x + 1, max_y + 1); /* resets length of array */ stroke_points->len = 0; /* try evaluating stroke */ if (stroke_trans ((char*)&sequence)) { gchar *guile_string = g_strdup_printf("(eval-stroke \"%s\")", sequence); SCM ret; ret = g_scm_c_eval_string_protected (guile_string); g_free (guile_string); return (SCM_NFALSEP (ret)); } return 0; }
/* for now this only supports single chars, not shift/alt/ctrl etc... */ int g_keys_execute(GSCHEM_TOPLEVEL *w_current, int state, int keyval) { char *guile_string = NULL; char *modifier = NULL; char *key_name = NULL; char *mod_end = NULL; SCM scm_retval; if (keyval == 0) { return 0; } key_name = gdk_keyval_name(keyval); if ( key_name == NULL ) { return 0; } /* don't pass the raw modifier key presses to the guile code */ if (strstr(key_name, "Alt") || strstr(key_name, "Shift") || strstr(key_name, "Control") ) { return 0; } /* Allocate space for concatenation of all strings below */ modifier = mod_end = g_strnfill(3*10, '\0'); /* The accels below must be in alphabetic order! */ if (state & GDK_MOD1_MASK) { mod_end = g_stpcpy(mod_end, "Alt "); } if (state & GDK_CONTROL_MASK) { mod_end = g_stpcpy(mod_end, "Control "); } if (state & GDK_SHIFT_MASK) { mod_end = g_stpcpy(mod_end, "Shift "); } if(strcmp(key_name, "Escape") == 0) { g_free(w_current->keyaccel_string); w_current->keyaccel_string = NULL; } else if(w_current->keyaccel_string && strlen(w_current->keyaccel_string) + strlen(key_name) > 10) { g_free(w_current->keyaccel_string); w_current->keyaccel_string = g_strconcat(modifier, key_name, NULL); } else { gchar *p, *r; p = w_current->keyaccel_string; w_current->keyaccel_string = g_strconcat(modifier, key_name, NULL); if(p) { r = g_strconcat(p, w_current->keyaccel_string, NULL); g_free(p); g_free(w_current->keyaccel_string); w_current->keyaccel_string = r; } } i_show_state(w_current, NULL); guile_string = g_strdup_printf("(press-key \"%s%s\")", modifier, key_name); #if DEBUG printf("_%s_\n", guile_string); #endif scm_retval = g_scm_c_eval_string_protected (guile_string); g_free(guile_string); g_free(modifier); return (SCM_FALSEP (scm_retval)) ? 0 : 1; }