2 * Copyright (C) 2007 Pekka Lampila <pekka.lampila@iki.fi>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
24 #include "swfdec_as_internal.h"
25 #include "swfdec_as_strings.h"
26 #include "swfdec_as_context.h"
27 #include "swfdec_debug.h"
28 #include "swfdec_movie.h"
29 #include "swfdec_player_internal.h"
30 #include "swfdec_sandbox.h"
31 #include "swfdec_button_movie.h"
32 #include "swfdec_sprite_movie.h"
33 #include "swfdec_text_field_movie.h"
34 #include "swfdec_text_buffer.h"
36 SWFDEC_AS_NATIVE (600, 0, swfdec_selection_getBeginIndex
)
38 swfdec_selection_getBeginIndex (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
39 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
41 SwfdecPlayerPrivate
*priv
= SWFDEC_PLAYER (cx
)->priv
;
42 SwfdecTextFieldMovie
*text
;
46 if (!SWFDEC_IS_TEXT_FIELD_MOVIE (priv
->focus
)) {
47 *ret
= swfdec_as_value_from_integer (cx
, -1);
50 text
= SWFDEC_TEXT_FIELD_MOVIE (priv
->focus
);
51 swfdec_text_buffer_get_selection (text
->text
, &start
, &end
);
52 s
= swfdec_text_buffer_get_text (text
->text
);
53 *ret
= swfdec_as_value_from_integer (cx
, g_utf8_pointer_to_offset (s
, s
+ start
));
56 SWFDEC_AS_NATIVE (600, 1, swfdec_selection_getEndIndex
)
58 swfdec_selection_getEndIndex (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
59 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
61 SwfdecPlayerPrivate
*priv
= SWFDEC_PLAYER (cx
)->priv
;
62 SwfdecTextFieldMovie
*text
;
66 if (!SWFDEC_IS_TEXT_FIELD_MOVIE (priv
->focus
)) {
67 *ret
= swfdec_as_value_from_integer (cx
, -1);
70 text
= SWFDEC_TEXT_FIELD_MOVIE (priv
->focus
);
71 swfdec_text_buffer_get_selection (text
->text
, &start
, &end
);
72 s
= swfdec_text_buffer_get_text (text
->text
);
73 *ret
= swfdec_as_value_from_integer (cx
, g_utf8_pointer_to_offset (s
, s
+ end
));
76 SWFDEC_AS_NATIVE (600, 2, swfdec_selection_getCaretIndex
)
78 swfdec_selection_getCaretIndex (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
79 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
81 SwfdecPlayerPrivate
*priv
= SWFDEC_PLAYER (cx
)->priv
;
82 SwfdecTextFieldMovie
*text
;
85 if (!SWFDEC_IS_TEXT_FIELD_MOVIE (priv
->focus
)) {
86 *ret
= swfdec_as_value_from_integer (cx
, -1);
89 text
= SWFDEC_TEXT_FIELD_MOVIE (priv
->focus
);
90 s
= swfdec_text_buffer_get_text (text
->text
);
91 *ret
= swfdec_as_value_from_integer (cx
, g_utf8_pointer_to_offset (s
,
92 s
+ swfdec_text_buffer_get_cursor (text
->text
)));
95 SWFDEC_AS_NATIVE (600, 3, swfdec_selection_getFocus
)
97 swfdec_selection_getFocus (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
98 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
100 SwfdecPlayerPrivate
*priv
= SWFDEC_PLAYER (cx
)->priv
;
103 char *s
= swfdec_movie_get_path (SWFDEC_MOVIE (priv
->focus
), TRUE
);
104 SWFDEC_AS_VALUE_SET_STRING (ret
, swfdec_as_context_give_string (cx
, s
));
106 SWFDEC_AS_VALUE_SET_NULL (ret
);
111 swfdec_actor_can_grab_focus (SwfdecActor
*actor
)
115 /* Functions like this just make me love Flash */
116 if (SWFDEC_IS_SPRITE_MOVIE (actor
) ||
117 SWFDEC_IS_BUTTON_MOVIE (actor
)) {
118 if (SWFDEC_MOVIE (actor
)->parent
== NULL
)
120 if (!swfdec_as_object_get_variable (swfdec_as_relay_get_as_object (SWFDEC_AS_RELAY (actor
)),
121 SWFDEC_AS_STR_focusEnabled
, &val
))
122 return swfdec_actor_get_mouse_events (actor
);
123 return swfdec_as_value_to_boolean (swfdec_gc_object_get_context (actor
), val
);
124 } else if (SWFDEC_IS_TEXT_FIELD_MOVIE (actor
)) {
125 /* cool that you can select all textfields, eh? */
132 SWFDEC_AS_NATIVE (600, 4, swfdec_selection_setFocus
)
134 swfdec_selection_setFocus (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
135 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
138 SwfdecSandbox
*sandbox
;
140 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, FALSE
);
141 SWFDEC_AS_CHECK (0, NULL
, "M", &actor
);
144 if (!SWFDEC_IS_ACTOR (actor
) ||
145 !swfdec_actor_can_grab_focus (actor
))
149 /* FIXME: how is security handled here? */
150 sandbox
= swfdec_sandbox_get (SWFDEC_PLAYER (cx
));
151 swfdec_sandbox_unuse (sandbox
);
152 swfdec_player_grab_focus (SWFDEC_PLAYER (cx
), actor
);
153 swfdec_sandbox_use (sandbox
);
155 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, TRUE
);
160 SWFDEC_AS_NATIVE (600, 5, swfdec_selection_setSelection
)
162 swfdec_selection_setSelection (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
163 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
165 SWFDEC_STUB ("Selection.setSelection (static)");