1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
/*
* Copyright (c) 2003 by the gtk2-perl team (see the file AUTHORS)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307 USA.
*
* $Header: /cvsroot/gtk2-perl/gtk2-perl-xs/Gtk2/xs/GtkEditable.xs,v 1.14 2004/02/06 21:34:08 kaffeetisch Exp $
*/
#include "gtk2perl.h"
#include <gperl_marshal.h>
/*
GtkEditable's insert-text signal uses an integer pointer as a write-through
parameter; unlike GtkWidget's size-request signal, we can't just pass an
editable object, because an integer is an integral type.
void user_function (GtkEditable *editable,
gchar *new_text,
gint new_text_length,
gint *position, <<=== that's the problem
gpointer user_data);
*/
static void
gtk2perl_editable_insert_text_marshal (GClosure * closure,
GValue * return_value,
guint n_param_values,
const GValue * param_values,
gpointer invocation_hint,
gpointer marshal_data)
{
STRLEN len;
gint * position_p;
SV * string, * position;
dGPERL_CLOSURE_MARSHAL_ARGS;
GPERL_CLOSURE_MARSHAL_INIT (closure, marshal_data);
PERL_UNUSED_VAR (return_value);
PERL_UNUSED_VAR (n_param_values);
PERL_UNUSED_VAR (invocation_hint);
ENTER;
SAVETMPS;
PUSHMARK (SP);
GPERL_CLOSURE_MARSHAL_PUSH_INSTANCE (param_values);
/* new_text */
string = newSVpv (g_value_get_string (param_values+1), 0);
XPUSHs (string);
/* text length is redundant, but documented. it doesn't hurt
* anything to include it, but would be a doc hassle to omit it. */
XPUSHs (sv_2mortal (newSViv (g_value_get_int (param_values+2))));
/* insert position */
position_p = g_value_get_pointer (param_values+3);
position = newSViv (*position_p);
XPUSHs (position);
GPERL_CLOSURE_MARSHAL_PUSH_DATA;
PUTBACK;
GPERL_CLOSURE_MARSHAL_CALL (G_ARRAY);
/* refresh the param_values with whatever changes the callback may
* have made. values returned on the stack take precedence over
* modifications to @_. */
if (count == 2) {
SV * sv;
/* get the values off the end of the stack. why do my
* attempts to use ST() result in segfaults? */
*position_p = POPi;
sv = POPs;
sv_utf8_upgrade (sv);
g_value_set_string ((GValue*)param_values+1, SvPV (sv, len));
g_value_set_int ((GValue*)param_values+2, len);
PUTBACK;
} else if (count == 0) {
/* returned no values, then refresh string and position
* params from the callback's args, which may have been
* modified. */
sv_utf8_upgrade (string);
g_value_set_string ((GValue*)param_values+1,
SvPV (string, len));
g_value_set_int ((GValue*)param_values+2, len);
*position_p = SvIV (position);
if (*position_p < 0)
*position_p = 0;
} else {
/* NOTE: croaking here can cause bad things to happen to the
* app, because croaking in signal handlers is bad juju. */
croak ("an insert-text signal handler must either return"
" two items (text and position)\nor return no items"
" and possibly modify its @_ parameters.\n"
" callback returned %d items", count);
}
/*
* clean up
*/
SvREFCNT_dec (string);
SvREFCNT_dec (position);
PUTBACK;
FREETMPS;
LEAVE;
}
MODULE = Gtk2::Editable PACKAGE = Gtk2::Editable PREFIX = gtk_editable_
BOOT:
gperl_signal_set_marshaller_for (GTK_TYPE_EDITABLE, "insert_text",
gtk2perl_editable_insert_text_marshal);
void
gtk_editable_select_region (editable, start, end)
GtkEditable *editable
gint start
gint end
## returns an empty list if there is no selection
=for apidoc
=for signature (start, end) = $editable->get_selection_bounds
Returns integers, start and end.
=cut
void
gtk_editable_get_selection_bounds (editable)
GtkEditable *editable
PREINIT:
gint start;
gint end;
PPCODE:
if (!gtk_editable_get_selection_bounds (editable, &start, &end))
XSRETURN_EMPTY;
EXTEND (SP, 2);
PUSHs (sv_2mortal (newSViv (start)));
PUSHs (sv_2mortal (newSViv (end)));
=for apidoc
=for signature new_position = $editable->insert_text (new_text, position)
=cut
## returns position of next char after inserted text
gint
gtk_editable_insert_text (editable, new_text, ...)
GtkEditable *editable
gchar *new_text
PREINIT:
gint new_text_length;
gint position;
CODE:
if (items == 3) {
new_text_length = strlen (new_text);
position = SvIV (ST (2));
} else if (items == 4) {
new_text_length = SvIV (ST (2));
position = SvIV (ST (3));
} else {
croak ("Usage: Gtk2::Editable::insert_text(editable, new_text, position)");
}
gtk_editable_insert_text (editable, new_text,
new_text_length, &position);
RETVAL = position;
OUTPUT:
RETVAL
void
gtk_editable_delete_text (editable, start_pos, end_pos)
GtkEditable *editable
gint start_pos
gint end_pos
gchar_own *
gtk_editable_get_chars (editable, start_pos, end_pos)
GtkEditable *editable
gint start_pos
gint end_pos
void
gtk_editable_cut_clipboard (editable)
GtkEditable *editable
void
gtk_editable_copy_clipboard (editable)
GtkEditable *editable
void
gtk_editable_paste_clipboard (editable)
GtkEditable *editable
void
gtk_editable_delete_selection (editable)
GtkEditable *editable
void
gtk_editable_set_position (editable, position)
GtkEditable *editable
gint position
gint
gtk_editable_get_position (editable)
GtkEditable *editable
void
gtk_editable_set_editable (editable, is_editable)
GtkEditable *editable
gboolean is_editable
gboolean
gtk_editable_get_editable (editable)
GtkEditable *editable
|