2 // Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
9 // This program 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
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #include "DefineEditTextTag.h"
20 #include "TypesParser.h"
21 #include "RunResources.h"
22 #include "TextField_as.h"
23 #include "TextField.h"
24 #include "movie_definition.h"
26 #include "SWFStream.h"
27 #include "Global_as.h"
33 DefineEditTextTag::loader(SWFStream
& in
, TagType tag
, movie_definition
& m
,
34 const RunResources
& /*r*/)
36 assert(tag
== SWF::DEFINEEDITTEXT
); // 37
39 const boost::uint16_t id
= in
.read_u16();
41 std::auto_ptr
<DefineEditTextTag
> editText(new DefineEditTextTag(in
, m
, id
));
43 m
.addDisplayObject(id
, editText
.release());
47 DefineEditTextTag::createDisplayObject(Global_as
& gl
, DisplayObject
* parent
)
50 // Resolve the font, if possible
52 as_object
* obj
= createTextFieldObject(gl
);
54 // If the TextField class is not present, the construction of a TextField
56 // TODO: check what happens in this case (when the TextField class is
57 // removed before this tag is processed).
59 // Note that it is expected that createDisplayObject() always returns
60 // a DisplayObject and not null.
61 log_error("Failed to construct a TextField object; using"
62 "a substitute object");
63 obj
= new as_object(gl
);
66 TextField
* ch
= new TextField(obj
, parent
, *this);
73 DefineEditTextTag::read(SWFStream
& in
, movie_definition
& m
)
81 int flags
= in
.read_u8();
82 _hasText
= flags
& (1 << 7);
83 _wordWrap
= flags
& (1 << 6);
84 _multiline
= flags
& (1 << 5);
85 _password
= flags
& (1 << 4);
86 _readOnly
= flags
& (1 << 3);
88 const bool hasColor
= flags
& (1 << 2);
89 const bool hasMaxChars
= flags
& (1 << 1);
90 const bool hasFont
= flags
& (1 << 0);
93 // 0: no font class, 1 font class and height, can't be true if has_font was true
94 bool hasFontClass
= flags
& (1 << 7);
95 if (hasFontClass
&& hasFont
)
97 IF_VERBOSE_MALFORMED_SWF(
98 log_swferror("DefineEditText: hasFontClass can't be true if "
99 "hasFont is true, ignoring");
101 hasFontClass
= false;
104 _autoSize
= flags
& (1 << 6);
105 bool hasLayout
= flags
& (1 << 5);
106 _noSelect
= flags
& (1 << 4);
107 _border
= flags
& (1 << 3);
109 // authored as static text (not dynamic text)
110 bool wasStatic
= flags
& (1 << 2);
112 // TODO: what is this for?
115 _html
= flags
& (1 << 1);
116 _useOutlines
= flags
& (1 << 0);
121 _fontID
= in
.read_u16();
122 _font
= m
.get_font(_fontID
);
125 IF_VERBOSE_MALFORMED_SWF(
126 log_swferror("DefineEditText: tag refers to unknown font "
130 _textHeight
= in
.read_u16();
132 else if (hasFontClass
)
134 std::string fontClassName
;
135 in
.read_string(fontClassName
);
136 log_unimpl("Font class support for DefineEditText (%d)",
141 _color
= readRGBA(in
);
147 _maxChars
= in
.read_u16();
152 in
.ensureBytes(9); //1 + 2 + 2 + 2 + 2
153 _alignment
= static_cast<TextField::TextAlignment
>(in
.read_u8());
154 _leftMargin
= in
.read_u16();
155 _rightMargin
= in
.read_u16();
156 _indent
= in
.read_s16();
157 _leading
= in
.read_s16();
160 in
.read_string(_variableName
);
164 in
.read_string(_defaultText
);
168 log_parse("edit_text_char:\n"
173 _variableName
, _defaultText
, _fontID
, _textHeight
);
177 DefineEditTextTag::DefineEditTextTag(SWFStream
& in
, movie_definition
& m
,
194 _alignment(TextField::ALIGN_LEFT
),
200 _color
.set(0, 0, 0, 255);
202 // Parse the tag from the stream.