2 * Copyright (C) 2007 Benjamin Otte <otte@gnome.org>
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 "swfedit_list.h"
26 G_DEFINE_TYPE (SwfeditList
, swfedit_list
, SWFEDIT_TYPE_TOKEN
)
29 swfedit_list_dispose (GObject
*object
)
31 //SwfeditList *list = SWFEDIT_LIST (object);
33 G_OBJECT_CLASS (swfedit_list_parent_class
)->dispose (object
);
37 swfedit_list_changed (SwfeditToken
*token
, guint i
)
40 SwfeditList
*list
= SWFEDIT_LIST (token
);
41 SwfeditTokenEntry
*entry
= &g_array_index (token
->tokens
, SwfeditTokenEntry
, i
);
43 /* update visibility */
44 for (j
= i
+ 1; j
% list
->n_defs
!= 0; j
++) {
45 if (list
->def
[j
].n_items
== (j
% list
->n_defs
) + 1) {
46 swfedit_token_set_visible (token
, j
, entry
->value
!= NULL
);
50 j
= list
->def
[i
% list
->n_defs
].n_items
;
52 entry
= &g_array_index (token
->tokens
,
53 SwfeditTokenEntry
, j
- 1);
54 if (entry
->type
== SWFEDIT_TOKEN_UINT32
) {
55 SwfdecOut
*out
= swfdec_out_open ();
57 swfedit_tag_write_token (token
, out
, i
);
58 buffer
= swfdec_out_close (out
);
59 if (entry
->value
!= GUINT_TO_POINTER (buffer
->length
)) {
60 swfedit_token_set (token
, i
/ list
->n_defs
* list
->n_defs
+ j
- 1,
61 GUINT_TO_POINTER (buffer
->length
));
63 swfdec_buffer_unref (buffer
);
67 if (i
== token
->tokens
->len
- 1) {
68 for (j
= 0; j
< list
->n_defs
; j
++) {
69 const SwfeditTagDefinition
*def
= &list
->def
[(j
+ 1) % list
->n_defs
];
70 swfedit_tag_add_token (SWFEDIT_TOKEN (list
), def
->name
, def
->type
, def
->hint
);
76 swfedit_list_class_init (SwfeditListClass
*klass
)
78 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
79 SwfeditTokenClass
*token_class
= SWFEDIT_TOKEN_CLASS (klass
);
81 object_class
->dispose
= swfedit_list_dispose
;
83 token_class
->changed
= swfedit_list_changed
;
87 swfedit_list_init (SwfeditList
*list
)
92 swfedit_list_new_internal (const SwfeditTagDefinition
*def
)
96 list
= g_object_new (SWFEDIT_TYPE_LIST
, NULL
);
98 for (; def
->name
; def
++)
105 swfedit_list_new (const SwfeditTagDefinition
*def
)
109 g_return_val_if_fail (def
!= NULL
, NULL
);
111 list
= swfedit_list_new_internal (def
);
112 swfedit_tag_add_token (SWFEDIT_TOKEN (list
), def
->name
, def
->type
, def
->hint
);
118 swfedit_list_new_read (SwfeditToken
*parent
, SwfdecBits
*bits
, const SwfeditTagDefinition
*def
)
121 SwfeditTokenEntry
*entry
;
124 g_return_val_if_fail (bits
!= NULL
, NULL
);
125 g_return_val_if_fail (def
!= NULL
, NULL
);
127 list
= swfedit_list_new_internal (def
);
128 SWFEDIT_TOKEN (list
)->parent
= parent
;
132 swfedit_tag_read_tag (SWFEDIT_TOKEN (list
), bits
, def
);
133 entry
= &g_array_index (SWFEDIT_TOKEN (list
)->tokens
, SwfeditTokenEntry
,
134 SWFEDIT_TOKEN (list
)->tokens
->len
- 1);
135 if (GPOINTER_TO_UINT (entry
->value
) == 0)
139 for (;def
->name
!= NULL
; def
++) {
140 SwfeditTagDefinition def2
= *def
;
142 def2
.n_items
+= offset
;
143 swfedit_tag_read_tag (SWFEDIT_TOKEN (list
), bits
, &def2
);
145 offset
+= list
->n_defs
;