Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GNASH_TEXTFIELD_H
00020 #define GNASH_TEXTFIELD_H
00021
00022 #include "InteractiveObject.h"
00023 #include "LineStyle.h"
00024 #include "snappingrange.h"
00025 #include "SWFRect.h"
00026
00027 #include <boost/intrusive_ptr.hpp>
00028 #include <map>
00029 #include <string>
00030 #include <vector>
00031
00032
00033 namespace gnash {
00034 namespace SWF {
00035 class DefineEditTextTag;
00036 class TextRecord;
00037 }
00038 class TextFormat_as;
00039 class Font;
00040 }
00041
00042 namespace gnash {
00043
00045 class TextField : public InteractiveObject
00046 {
00047
00048 public:
00049
00050 typedef std::vector<size_t> LineStarts;
00051
00053 enum TextAlignment
00054 {
00055 ALIGN_LEFT = 0,
00056 ALIGN_RIGHT,
00057 ALIGN_CENTER,
00058 ALIGN_JUSTIFY
00059 };
00060
00062 enum TextFormatDisplay
00063 {
00064 TEXTFORMAT_BLOCK = 0,
00065 TEXTFORMAT_INLINE = 1
00066 };
00067
00069 enum AutoSize {
00070
00072 AUTOSIZE_NONE,
00073
00075 AUTOSIZE_LEFT,
00076
00078 AUTOSIZE_CENTER,
00079
00081 AUTOSIZE_RIGHT
00082 };
00083
00085 enum TypeValue {
00086
00088 typeInvalid,
00089
00092 typeDynamic,
00093
00095 typeInput
00096 };
00097
00099 TextField(as_object* object, DisplayObject* parent,
00100 const SWF::DefineEditTextTag& def);
00101
00103
00107 TextField(as_object* object, DisplayObject* parent, const SWFRect& bounds);
00108
00109
00110 ~TextField();
00111
00112
00114 bool mouseEnabled() const { return true; }
00115
00117
00120 InteractiveObject* topmostMouseEntity(boost::int32_t x, boost::int32_t y);
00121
00122
00123 virtual cxform get_world_cxform() const;
00124
00126
00128 virtual int getDefinitionVersion() const;
00129
00131 void notifyEvent(const event_id& id);
00132
00133 const std::string& getVariableName() const
00134 {
00135 return _variable_name;
00136 }
00137
00140
00144 void set_variable_name(const std::string& newname);
00145
00148
00152 void updateText(const std::string& s);
00153
00154 void updateHtmlText(const std::string& s);
00155
00157 std::string get_text_value() const;
00158
00160 std::string get_htmltext_value() const;
00161
00163 bool getTextDefined() const { return _textDefined; }
00164
00165 size_t getCaretIndex() const {
00166 return m_cursor;
00167 }
00168
00170 const std::pair<size_t, size_t>& getSelection() const {
00171 return _selection;
00172 }
00173
00175
00177 void replaceSelection(const std::string& replace);
00178
00180
00183
00186 void setSelection(int start, int end);
00187
00189
00191 virtual void setWidth(double width);
00192
00194
00196 virtual void setHeight(double height);
00197
00199 void display(Renderer& renderer);
00200
00201 void add_invalidated_bounds(InvalidatedRanges& ranges, bool force);
00202
00204 virtual SWFRect getBounds() const
00205 {
00206 return _bounds;
00207 }
00208
00209
00210 bool pointInShape(boost::int32_t x, boost::int32_t y) const;
00211
00213 bool getDrawBackground() const;
00214
00216
00218 void setDrawBackground(bool draw);
00219
00221 rgba getBackgroundColor() const;
00222
00224
00228 void setBackgroundColor(const rgba& col);
00229
00231 bool getDrawBorder() const;
00232
00234
00236 void setDrawBorder(bool draw);
00237
00239 rgba getBorderColor() const;
00240
00242
00246 void setBorderColor(const rgba& col);
00247
00249 const rgba& getTextColor() const
00250 {
00251 return _textColor;
00252 }
00253
00255
00258 void setTextColor(const rgba& col);
00259
00263 bool getEmbedFonts() const {
00264 return _embedFonts;
00265 }
00266
00268 boost::int32_t maxChars() const {
00269 return _maxChars;
00270 }
00271
00273
00276 void maxChars(boost::int32_t max) {
00277 _maxChars = max;
00278 }
00279
00281 bool multiline() const {
00282 return _multiline;
00283 }
00284
00286
00289 void multiline(bool b) {
00290 _multiline = b;
00291 }
00292
00294 bool password() const {
00295 return _password;
00296 }
00297
00299
00302 void password(bool b) {
00303 _password = b;
00304 }
00308
00310 void setEmbedFonts(bool use);
00311
00313 AutoSize getAutoSize() const
00314 {
00315 return _autoSize;
00316 }
00317
00319 TextAlignment getTextAlignment();
00320
00322
00326 void setAutoSize(AutoSize val);
00327
00329
00333 void setType(TypeValue val) { if (val != typeInvalid) _type=val; }
00334
00336 TypeValue getType() const
00337 {
00338 return _type;
00339 }
00340
00342 bool isReadOnly() const { return _type != typeInput; }
00343
00345
00351 static TypeValue parseTypeValue(const std::string& val);
00352
00354
00361 static const char* typeValueName(TypeValue val);
00362
00367 bool doWordWrap() const {
00368 return _wordWrap;
00369 }
00370
00372
00379 void setWordWrap(bool on);
00380
00382 bool doHtml() const {
00383 return _html;
00384 }
00385
00387
00390 void setHtml(bool on) {
00391 _html = on;
00392 }
00393
00395 bool isSelectable() const
00396 {
00397 return _selectable;
00398 }
00399
00401
00404 void setSelectable(bool v)
00405 {
00406 _selectable = v;
00407 }
00408
00409
00411 virtual bool isSelectableTextField() const
00412 {
00413 return isSelectable();
00414 }
00415
00417
00424 void removeTextField();
00425
00427
00431 boost::intrusive_ptr<const Font> setFont(
00432 boost::intrusive_ptr<const Font> newfont);
00433
00434 const Font* getFont() { return _font.get(); }
00435
00436
00437 boost::uint16_t getFontHeight() const
00438 {
00439 return _fontHeight;
00440 }
00441
00442 void setFontHeight(boost::uint16_t h);
00443
00444 boost::uint16_t getLeftMargin() const
00445 {
00446 return _leftMargin;
00447 }
00448
00449 void setLeftMargin(boost::uint16_t h);
00450
00451 boost::uint16_t getRightMargin() const
00452 {
00453 return _rightMargin;
00454 }
00455
00456 void setRightMargin(boost::uint16_t h);
00457
00458 boost::uint16_t getIndent() const
00459 {
00460 return _indent;
00461 }
00462
00463 void setIndent(boost::uint16_t h);
00464
00465 boost::uint16_t getBlockIndent() const
00466 {
00467 return _blockIndent;
00468 }
00469
00470 void setBlockIndent(boost::uint16_t h);
00471
00472 TextAlignment getAlignment() const
00473 {
00474 return _alignment;
00475 }
00476
00477 void setAlignment(TextAlignment h);
00478
00479 boost::int16_t getLeading() const
00480 {
00481 return _leading;
00482 }
00483
00484 void setLeading(boost::int16_t h);
00485
00486 bool getUnderlined() const
00487 {
00488 return _underlined;
00489 }
00490
00491 TextFormatDisplay getDisplay() const
00492 {
00493 return _display;
00494 }
00495
00496 bool getBullet() const
00497 {
00498 return _bullet;
00499 }
00500
00501 const std::vector<int>& getTabStops() const
00502 {
00503 return _tabStops;
00504 }
00505
00506 bool isRestrict() const
00507 {
00508 return _restrictDefined;
00509 }
00510
00511 const std::string& getRestrict() const
00512 {
00513 return _restrict;
00514 }
00515
00516 size_t getScroll() const
00517 {
00518 return _scroll;
00519 }
00520
00521 size_t getMaxScroll() const
00522 {
00523 return _maxScroll;
00524 }
00525
00526 size_t getHScroll() const
00527 {
00528 return _hScroll;
00529 }
00530
00531 size_t getMaxHScroll() const
00532 {
00533 return _maxHScroll;
00534 }
00535
00536 size_t getBottomScroll() const
00537 {
00538 return _bottomScroll;
00539 }
00540
00541 void setUnderlined(bool v);
00542 void setTabStops(const std::vector<int>& tabStops);
00543 void setBullet(bool b);
00544 void setURL(std::string url);
00545 void setTarget(std::string target);
00546 void setRestrict(const std::string& restrict);
00547 void setDisplay(TextFormatDisplay display);
00548 void setScroll(size_t scroll) {
00549 _scroll = scroll;
00550 format_text();
00551 }
00552 void setMaxScroll(size_t maxScroll) {
00553 _maxScroll = maxScroll;
00554 format_text();
00555 }
00556 void setHScroll(size_t hScroll) {
00557 _hScroll = hScroll;
00558 format_text();
00559 }
00560 void setMaxHScroll(size_t maxHScroll) {
00561 _maxHScroll = maxHScroll;
00562 format_text();
00563 }
00564 void setbottomScroll(size_t bottomScroll) {
00565 _bottomScroll = bottomScroll;
00566 format_text();
00567 }
00568
00570
00571 size_t cursorRecord();
00572
00573 void setTextFormat(TextFormat_as& tf);
00574
00575 const SWFRect& getTextBoundingBox() const
00576 {
00577 return m_text_bounding_box;
00578 }
00579
00581
00584 void setTextValue(const std::wstring& wstr);
00585
00587
00588 void setHtmlTextValue(const std::wstring& wstr);
00589
00590 private:
00591
00592 void init();
00593
00596
00600 void updateText(const std::wstring& s);
00601
00602 void updateHtmlText(const std::wstring& s);
00603
00604 void insertTab(SWF::TextRecord& rec, boost::int32_t& x, float scale);
00605
00607
00610 virtual bool handleFocus();
00611
00613 virtual void killFocus();
00614
00616 void onChanged();
00617
00619 void reset_bounding_box(boost::int32_t x, boost::int32_t y)
00620 {
00621 m_text_bounding_box.set_to_point(x, y);
00622 }
00623
00626 void format_text();
00627
00629 void scrollLines();
00630
00633 void newLine(boost::int32_t& x, boost::int32_t& y,
00634 SWF::TextRecord& rec, int& last_space_glyph,
00635 LineStarts::value_type& last_line_start_record, float div);
00636
00638 void handleChar(std::wstring::const_iterator& it,
00639 const std::wstring::const_iterator& e, boost::int32_t& x,
00640 boost::int32_t& y, SWF::TextRecord& rec, int& last_code,
00641 int& last_space_glyph,
00642 LineStarts::value_type& last_line_start_record);
00643
00654 bool parseHTML(std::wstring& tag,
00655 std::map<std::string, std::string>& attributes,
00656 std::wstring::const_iterator& it,
00657 const std::wstring::const_iterator& e,
00658 bool& selfclosing) const;
00659
00664 float align_line(TextAlignment align, int last_line_start_record, float x);
00665
00667
00683 void registerTextVariable();
00684
00685 typedef std::pair<as_object*, string_table::key> VariableRef;
00686
00691 VariableRef parseTextVariableRef(const std::string& variableName) const;
00692
00694
00697 void show_cursor(Renderer& renderer, const SWFMatrix& mat);
00698
00700
00702 boost::intrusive_ptr<const SWF::DefineEditTextTag> _tag;
00703
00705
00710 std::wstring _text;
00711
00713
00714 std::wstring _htmlText;
00715
00717 SWFRect m_text_bounding_box;
00718
00719 typedef std::vector<SWF::TextRecord> TextRecords;
00720 TextRecords _textRecords;
00721
00722 std::vector<size_t> _recordStarts;
00723
00724 TextRecords _displayRecords;
00725
00726 std::string _url;
00727 std::string _target;
00728 std::string _restrict;
00729 std::set<wchar_t> _restrictedchars;
00730 TextFormatDisplay _display;
00731 std::vector<int> _tabStops;
00732 LineStarts _line_starts;
00733
00735
00739 std::string _variable_name;
00740
00741 rgba _backgroundColor;
00742
00743 rgba _borderColor;
00744
00745 rgba _textColor;
00746
00747 TextAlignment _alignment;
00748
00749 boost::intrusive_ptr<const Font> _font;
00750 size_t m_cursor;
00751 size_t _glyphcount;
00752 size_t _scroll;
00753 size_t _maxScroll;
00754 size_t _hScroll;
00755 size_t _maxHScroll;
00756 size_t _bottomScroll;
00757 size_t _linesindisplay;
00758
00760 size_t _maxChars;
00761
00762 AutoSize _autoSize;
00763
00764 TypeValue _type;
00765
00767
00772 SWFRect _bounds;
00773
00776 std::pair<size_t, size_t> _selection;
00777
00778 boost::int16_t _leading;
00779 boost::uint16_t _indent;
00780
00783 boost::uint16_t _blockIndent;
00784
00785 boost::uint16_t _leftMargin;
00786
00787 boost::uint16_t _rightMargin;
00788
00789 boost::uint16_t _fontHeight;
00790
00795 bool _textDefined;
00796
00797 bool _htmlTextDefined;
00798
00799 bool _restrictDefined;
00800 bool _underlined;
00801 bool _bullet;
00802
00803 bool m_has_focus;
00804
00805
00807 bool _multiline;
00808
00810 bool _password;
00811
00813
00817 bool _text_variable_registered;
00818
00819 bool _drawBackground;
00820
00821 bool _drawBorder;
00822
00823 bool _embedFonts;
00824
00825 bool _wordWrap;
00826
00827 bool _html;
00828
00829 bool _selectable;
00830
00831 };
00832
00833 }
00834
00835 #endif