libsswf: sswf::TagEditText Class Reference

# sswf::TagEditText Class Reference

Defines a dynamic edit text box. More...

`#include <libsswf.h>`

Inheritance diagram for sswf::TagEditText:

List of all members.

## Public Types
enum | edit_text_alignment_t { EDIT_TEXT_ALIGNMENT_LEFT = 0, EDIT_TEXT_ALIGNMENT_RIGHT = 1, EDIT_TEXT_ALIGNMENT_CENTER = 2, EDIT_TEXT_ALIGNMENT_JUSTIFY = 3 }
| Defines the different possible alignment. More...
## Public Member Functions
void | AddUsedString (const char *string)
| Add a string that will be used with that edit text box.
virtual ErrorManager::error_code_t | Save (Data &data)
| Save an edit text box in a Data buffer.
void | SetAlign (edit_text_alignment_t align)
| Set the alignment for the text.
void | SetAutoSize (bool status=true)
| Automatically resizing the edit text box.
void | SetBorder (bool status=true)
| Mark whether a border should be rendered.
void | SetBounds (const SRectangle &bounds)
| Set the bounds of the edit text.
void | SetColor (Color &color)
| The color used to render the font.
void | SetFont (const TagFont *font, long height)
| Set the font to use to render the glyphs.
void | SetHTML (bool status=true)
| Defines the box as using HTML or plain text.
void | SetIndent (long indent)
| Set the identation of the first line of text.
void | SetLeading (long leading)
| Set the identation of the first line of text.
void | SetMargins (long left, long right)
| Defines the side margin.
void | SetMaxLength (long length)
| Set the maximum length of the text in number of characters.
void | SetMultiline (bool status=true)
| Set the multiline flag to the specified status.
void | SetNoSelect (bool status=true)
| Set whether the user can select the text.
void | SetOutline (bool status=true)
| Set whether an outline should be rendered.
void | SetPassword (bool status=true)
| Set the password flag.
void | SetReadOnly (bool status=true)
| Mark the edit text box as read-only.
void | SetText (const char *text)
| Set the text to be rendered on screen.
void | SetUsedGlyphs (const char *lists)
| Mark a set of glyphs as in use.
void | SetVariableName (const char *name)
| Set the name of the variable.
void | SetWordWrap (bool status=true)
| Set whether words should wrap.
| TagEditText (TagBase *parent)
| Initializes the object.
virtual swf_type_t | TypeFlags (void) const
| Returns the type of an edit text box.
## Private Member Functions
virtual ErrorManager::error_code_t | ParseTag (swf_tag_t tag, const Data &data)
| Parse data from a file into a EditText tag.
virtual ErrorManager::error_code_t | PreSave (void)
| Check that the edit text box can be saved and in which version.
## Private Attributes
edit_text_alignment_t | f_align
bool | f_autosize
bool | f_border
SRectangle | f_bounds
Color | f_color
const TagFont * | f_font
unsigned short | f_font_height
bool | f_has_color
bool | f_html
long | f_indent
long | f_leading
long | f_left_margin
long | f_max_length
bool | f_multiline
bool | f_no_select
bool | f_outline
bool | f_password
bool | f_readonly
long | f_right_margin
char * | f_text
sswf_ucs4_t * | f_used_glyphs
sswf_ucs4_t * | f_used_strings
char * | f_var_name
bool | f_word_wrap

## Detailed Description

This tag is used to create a text box. People can write text in that box unless it is marked as read-only. Using an action scripts it is also possible to modify the text defined in an edit text box.

One important feature is the use of embedded fonts. In that case, you probably want to mark the edit text with a set of glyphs which need to be included (or "*" for all the glyphs of the font.)

See also:
  sswf::TagFont

  sswf::TagText

  SWF Alexis' Reference—DefineEditText

  SWF Alexis' Reference—swf_tag

## Member Enumeration Documentation

enum sswf::TagEditText::edit_text_alignment_t

This enumaration defines the list of possible alignment in an edit text box.

Enumerator:

  EDIT_TEXT_ALIGNMENT_LEFT | Defines the left alignment. This value is used to have the text rendered on the left edge. This is the default value.
  EDIT_TEXT_ALIGNMENT_RIGHT | Defines the right alignment. This value is used to have the text rendered on the right edge.
  EDIT_TEXT_ALIGNMENT_CENTER | Defines the centered alignment. This value is used to have the text horizontally rendered in the center of the edit text box.
  EDIT_TEXT_ALIGNMENT_JUSTIFY | Defines the justified alignment. This value is supposed to have to text aligned on the left and right edges adding some space where spaces are rendered so it looks like it fits exactly. This may work in the current version, but it has not been working in older versions (v4, v5).

## Constructor & Destructor Documentation

TagEditText::TagEditText | ( | TagBase * | parent | ) |

The constructor ensures that all the variables are set to their default.

Parameters:

  `[in]` | parent | The parent must be a TagHeader

References EDIT_TEXT_ALIGNMENT_LEFT, f_align, f_border, f_font, f_font_height, f_has_color, f_indent, f_leading, f_left_margin, f_max_length, f_multiline, f_no_select, f_outline, f_password, f_readonly, f_right_margin, f_text, f_used_glyphs, f_used_strings, f_var_name, and f_word_wrap.

## Member Function Documentation

void TagEditText::AddUsedString | ( | const char * | string | ) |

This function is used to tell the edit text box that it will need to be able to display the specified string.

This can be used to obtimize the number of glyphs included in your movie. If your edit text box cannot be edited by an end user, then it is sufficient to only save the glyphs that will at some point be used and forget about the others (especially to save some space in your file.)

For instance, if you have a set of action scripts testing different values and setting the edit text to pre-defined strings such as "Running", "Stopped", "Waiting" and "Paused" then you do not need to save the 'z' letter for instance.

Calling this function multiple times cumulates the strings.

Parameters:

  `[in]` | string | A string to add to the list of strings in use

References f_used_strings, sswf::mbtowc(), sswf::MemoryManager::MemAlloc(), sswf::MemoryManager::MemFree(), and sswf::wcslen().

ErrorManager::error_code_t TagEditText::ParseTag | ( | swf_tag_t | tag,
|  | const Data & | data |
| ) |  |  | `[private, virtual]`

This function does nothing since the EditText tag has no data.

Parameters:

  `[in]` | tag | The tag that generated this call
  `[in]` | data | The Data buffer from the Flash file being loaded

Returns:
  An error if one occurs, or ErrorManager::ERROR_CODE_NONE

Reimplemented from sswf::TagCSMTextSettings.

References sswf::ErrorManager::ERROR_CODE_NONE, sswf::ErrorManager::ERROR_CODE_OBJECT_NOT_FOUND, f_align, f_autosize, f_border, f_bounds, f_color, f_font, f_font_height, f_has_color, f_html, f_indent, f_leading, f_left_margin, f_max_length, f_multiline, f_no_select, f_outline, f_password, f_readonly, f_right_margin, f_text, f_var_name, f_word_wrap, sswf::TagBase::FindTagWithID(), sswf::Data::GetByte(), sswf::Data::GetShort(), sswf::Data::GetString(), sswf::Color::Parse(), sswf::SRectangle::Parse(), sswf::TagBaseID::ParseID(), and sswf::Data::ReadAlign().

ErrorManager::error_code_t TagEditText::PreSave | ( | void |  | ) | `[private, virtual]`

The function checks whether a font was defined for the edit text. If so, it marks all the glyphs in use according to those specified via the TagEditText::SetUsedGlyphs() and TagEditText::AddUsedString() function calls.

Errors are generated if a required glyph does not exist in the corresponding font.

See also:
  sswf::TagEditText::Save(Data& data)

  sswf::TagEditText::SetUsedGlyphs(const char *used_glyphs)

  sswf::TagEditText::AddUsedString(const char *string)

Reimplemented from sswf::TagBase.

References sswf::ErrorManager::ERROR_CODE_NO_SUCH_GLYPH, sswf::ErrorManager::ERROR_CODE_NONE, f_autosize, f_font, sswf::TagFont::font_info_t::f_glyph, f_outline, f_text, f_used_glyphs, f_used_strings, sswf::TagFont::FindGlyph(), sswf::TagFont::FontName(), sswf::TagFont::HasGlyph(), sswf::mbtowc(), sswf::MemoryManager::MemAlloc(), sswf::MemoryManager::MemFree(), sswf::TagBase::MinimumVersion(), sswf::TagBase::OnError(), sswf::TagCSMTextSettings::PreSaveCSMTextSettings(), sswf::TagFont::SetUsedByEditText(), sswf::TagFont::SetUsedGlyphs(), and sswf::wcname().

ErrorManager::error_code_t TagEditText::Save | ( | Data & | data | ) | `[virtual]`

This function saves an edit text box in the specified Data buffer.

Parameters:

  `[in]` | data | The Data buffer where the edit text box is saved

Returns:
  An error or ErrorManager::ERROR_CODE_NONE

Implements sswf::TagBase.

References sswf::Data::Align(), sswf::Data::Append(), sswf::Data::ByteSize(), f_align, f_autosize, f_border, f_bounds, f_color, f_font, f_font_height, f_has_color, f_html, f_indent, f_leading, f_left_margin, f_max_length, f_multiline, f_no_select, f_outline, f_password, f_readonly, f_right_margin, f_text, f_var_name, f_word_wrap, sswf::ErrorManager::KeepFirst(), sswf::Data::PutByte(), sswf::Data::PutShort(), sswf::Color::Save(), sswf::SRectangle::Save(), sswf::TagCSMTextSettings::SaveCSMTextSettings(), sswf::TagBaseID::SaveID(), sswf::TagBase::SaveString(), sswf::TagBase::SaveTag(), sswf::TagBase::SWF_TAG_TEXT_FIELD, and sswf::Data::WriteBits().

void TagEditText::SetAlign | ( | edit_text_alignment_t | align | ) |

This function sets the alignment for the text drawn in the edit text box.

The alignment can be set to one of these:

- TagEditText::EDIT_TEXT_ALIGNMENT_LEFT (default)
- TagEditText::EDIT_TEXT_ALIGNMENT_RIGHT
- TagEditText::EDIT_TEXT_ALIGNMENT_CENTER
- TagEditText::EDIT_TEXT_ALIGNMENT_JUSTIFY

Parameters:

  `[in]` | align | The alignment to use

References f_align.

void TagEditText::SetAutoSize | ( | bool | status = `true` | ) |

This function defines whether the box should be automatically resized or the size is defined statically.

Parameters:

  `[in]` | status | If true, the box will resize itself around the defined text

References f_autosize.

void TagEditText::SetBorder | ( | bool | status = `true` | ) |

This function requests that a border be drawn around the edit text box.

Note that the border color is usually black, and the background is always white.

Bug:
  If your text is white, it will not show up.

Parameters:

  `[in]` | status | If true, draw a background and edge

References f_border.

void TagEditText::SetBounds | ( | const SRectangle & | bounds | ) |

This function takes a rectangle representing the bounds of the edit text in the output.

Parameters:

  `[in]` | bounds | The bounds of the edit text box.

References f_bounds.

void TagEditText::SetColor | ( | Color & | color | ) |

This function is used to set the color to use to render the font.

Note that you can later use the font as a mask over pretty much any other drawings giving an effect that looks like colorful fonts.

Parameters:

  `[in]` | color | The color to use to draw the font

References f_color, and f_has_color.

void TagEditText::SetFont | ( | const TagFont * | font,
|  | long | height |
| ) |  |  |

This function defines the font to use with the edit text box and the height we want the font to be rendered at.

Bug:
  Note that if the font is a system font then the height has to be in system font metrics (such as 14 for a 14 points font.) When the font is an embedded font, then the height is taken in Twips.

Parameters:

  `[in]` | font | The font tag used to render this edit text box.
  `[in]` | height | The height to use to draw the characters.

References f_font, and f_font_height.

void TagEditText::SetHTML | ( | bool | status = `true` | ) |

The text in the edit text box can be set to Plain Text (the default) or HTML.

When set to HTML, a few tags are understood:

- <a>...</a>
- <b>...</b>
- <br>
- <font>...</font>
- <i>...</i>
- <li>...</li>
- <p>...</p>
- <tab>
- <textformat>...</textformat>
- <u>...</u>

For more information about the supported HTML, please, see SWF Alexis' Reference.

Parameters:

  `[in]` | status | If set to true, the text in the box is expected to be HTML.

See also:
  SWF Alexis' Reference—DefineEditText

References f_html.

void TagEditText::SetIndent | ( | long | indent | ) |

This alue represents the identation of the first line of text in a paragraph.

Parameters:

  `[in]` | indent | The identation of the text

References f_indent.

void TagEditText::SetLeading | ( | long | leading | ) |

This alue represents the number of pixels (in TWIPS) to skip vertically between lines of text.

Parameters:

  `[in]` | leading | The space between lines.

References f_leading.

void TagEditText::SetMargins | ( | long | left,
|  | long | right |
| ) |  |  |

This function defines the left and right margin for the text to be rendered in the box.

The margins are useful if you request a border and/or edge to be rendered.

Parameters:

  `[in]` | left | The width of the margin on the left side
  `[in]` | right | The width of the margin on the right side

References f_left_margin, and f_right_margin.

void TagEditText::SetMaxLength | ( | long | length | ) |

If the text is editable, to avoid letting people type as much as they want, use this function and set the limit you want. It is wise to always do so.

Note:
  This is supposed to be counted in characters. Encodings like UTF-8 or some asian languages may not be able to handling this properly/

Parameters:

  `[in]` | length | The maximum length a user can type

References f_max_length.

void TagEditText::SetMultiline | ( | bool | status = `true` | ) |

This function changes the behavior of the edit text box whenever strings longer than what can be rendered are used in an edit text.

References f_multiline.

void TagEditText::SetNoSelect | ( | bool | status = `true` | ) |

This function is used to mark the text in the edit text box as selectable or not. In general, an edit text box used for a label should be marked unselectable and read-only.

Parameters:

  `[in]` | status | The new status for the no-select flag.

References f_no_select.

void TagEditText::SetOutline | ( | bool | status = `true` | ) |

This flag defines whether an embedded font should be used.

Parameters:

  `[in]` | status | Set to true to use a system default font

References f_outline.

void TagEditText::SetPassword | ( | bool | status = `true` | ) |

By default, an edit text box is expected to be used for other purposes than passwords. But it can be useful, once in a while, to let people login. For that purpose, you can use this function.

The result of setting this flag to true is that the edit text box only renders asterisks,

Parameters:

  `[in]` | status | If true, the edit text box only displays asterisks.

References f_password.

void TagEditText::SetReadOnly | ( | bool | status = `true` | ) |

This function marks the edit text box as read-only. This means it can be used to display a string and the user has to right to change its content.

Parameters:

  `[in]` | status | The new status for the read-only flag.

References f_readonly.

void TagEditText::SetText | ( | const char * | text | ) |

This function sets the text that will be rendered on the screen.

The glyphs of the default text are automatically marked as required for this animation.

See also:
  sswf::TagEditText::AddUsedString(const char *string)

References f_text, sswf::MemoryManager::MemFree(), and sswf::MemoryManager::StrDup().

void TagEditText::SetUsedGlyphs | ( | const char * | used_glyphs | ) |

This function can be used to mark a set of glyphs as in use.

The special string "*" or a NULL pointer will request the function to mark all the glyphs as being in use.

The special character - (dash/minus) is used to define a range unless it is found at the very beginning or the very end of the string. For instance, to include all the upper case latin 1 letters, one can use "A-Z".

The use of this function is not cumulative. Calling it again overwrites the previous glyphs in use.

Bug:
  This glyphs marked in used must be marked as such after the PreSave() function of the corresponding TagFont is called. For this reason, we must saved this information here.

See also:
  sswf::TagEditText::AddUsedString(const char *string)

References f_used_glyphs, sswf::mbtowc(), sswf::MemoryManager::MemAlloc(), and sswf::MemoryManager::MemFree().

void TagEditText::SetVariableName | ( | const char * | name | ) |

This function is used to mark this edit text box with a name. This name can later be used in action scripts to read and set the text of the edit text box.

Parameters:

  `[in]` | name | The name of the variable

References f_var_name, sswf::MemoryManager::MemFree(), and sswf::MemoryManager::StrDup().

void TagEditText::SetWordWrap | ( | bool | status = `true` | ) |

This function is used to change the word wrap status.

By default an edit text box is set to have its text wrap.

Parameters:

  `[in]` | status | Set to true to get words to wrap, false otherwise

References f_word_wrap.

TagBase::swf_type_t TagEditText::TypeFlags | ( | void |  | ) | const`[virtual]`

This function returns the type of an edit text box.

An edit text box is a definition and a reference.

Returns:
  SWF_TYPE_DEFINE and SWF_TYPE_REFERENCE

Implements sswf::TagBase.

References SWF_TYPE_DEFINE, and SWF_TYPE_REFERENCE.

## Member Data Documentation

edit_text_alignment_t sswf::TagEditText::f_align`[private]`

Referenced by ParseTag(), Save(), SetAlign(), and TagEditText().

bool sswf::TagEditText::f_autosize`[private]`

Referenced by ParseTag(), PreSave(), Save(), and SetAutoSize().

bool sswf::TagEditText::f_border`[private]`

Referenced by ParseTag(), Save(), SetBorder(), and TagEditText().

SRectangle sswf::TagEditText::f_bounds`[private]`

Referenced by ParseTag(), Save(), and SetBounds().

Color sswf::TagEditText::f_color`[private]`

Referenced by ParseTag(), Save(), and SetColor().

const TagFont* sswf::TagEditText::f_font`[private]`

Referenced by ParseTag(), PreSave(), Save(), SetFont(), and TagEditText().

unsigned short sswf::TagEditText::f_font_height`[private]`

Referenced by ParseTag(), Save(), SetFont(), and TagEditText().

bool sswf::TagEditText::f_has_color`[private]`

Referenced by ParseTag(), Save(), SetColor(), and TagEditText().

bool sswf::TagEditText::f_html`[private]`

Referenced by ParseTag(), Save(), and SetHTML().

long sswf::TagEditText::f_indent`[private]`

Referenced by ParseTag(), Save(), SetIndent(), and TagEditText().

long sswf::TagEditText::f_leading`[private]`

Referenced by ParseTag(), Save(), SetLeading(), and TagEditText().

long sswf::TagEditText::f_left_margin`[private]`

Referenced by ParseTag(), Save(), SetMargins(), and TagEditText().

long sswf::TagEditText::f_max_length`[private]`

Referenced by ParseTag(), Save(), SetMaxLength(), and TagEditText().

bool sswf::TagEditText::f_multiline`[private]`

Referenced by ParseTag(), Save(), SetMultiline(), and TagEditText().

bool sswf::TagEditText::f_no_select`[private]`

Referenced by ParseTag(), Save(), SetNoSelect(), and TagEditText().

bool sswf::TagEditText::f_outline`[private]`

Referenced by ParseTag(), PreSave(), Save(), SetOutline(), and TagEditText().

bool sswf::TagEditText::f_password`[private]`

Referenced by ParseTag(), Save(), SetPassword(), and TagEditText().

bool sswf::TagEditText::f_readonly`[private]`

Referenced by ParseTag(), Save(), SetReadOnly(), and TagEditText().

long sswf::TagEditText::f_right_margin`[private]`

Referenced by ParseTag(), Save(), SetMargins(), and TagEditText().

char* sswf::TagEditText::f_text`[private]`

Referenced by ParseTag(), PreSave(), Save(), SetText(), and TagEditText().

sswf_ucs4_t* sswf::TagEditText::f_used_glyphs`[private]`

Referenced by PreSave(), SetUsedGlyphs(), and TagEditText().

sswf_ucs4_t* sswf::TagEditText::f_used_strings`[private]`

Referenced by AddUsedString(), PreSave(), and TagEditText().

char* sswf::TagEditText::f_var_name`[private]`

Referenced by ParseTag(), Save(), SetVariableName(), and TagEditText().

bool sswf::TagEditText::f_word_wrap`[private]`

Referenced by ParseTag(), Save(), SetWordWrap(), and TagEditText().

The documentation for this class was generated from the following files:

- libsswf.h
- libsswf_tag_edittext.c++