Gnash  0.8.11dev
TextField.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 #ifndef GNASH_TEXTFIELD_H
20 #define GNASH_TEXTFIELD_H
21 
22 #include <boost/intrusive_ptr.hpp>
23 #include <map>
24 #include <string>
25 #include <vector>
26 
27 #include "InteractiveObject.h" // for inheritance
28 #include "snappingrange.h"
29 #include "SWFRect.h" // for inlines
30 #include "GnashKey.h"
31 #include "RGBA.h" // for rgba
32 
33 // Forward declarations
34 namespace gnash {
35  namespace SWF {
36  class DefineEditTextTag;
37  class TextRecord;
38  }
39  class TextFormat_as;
40  class Font;
41 }
42 
43 #ifdef __ANDROID__
44 namespace std {
45 typedef basic_string
46  <wchar_t
47  ,std::char_traits<wchar_t>
48  ,std::allocator<wchar_t> >
49 wstring;
50 }
51 #endif
52 
53 namespace gnash {
54 
57 {
58 
59 public:
60 
61  typedef std::vector<size_t> LineStarts;
62 
65  {
66  ALIGN_LEFT = 0,
69  ALIGN_JUSTIFY
70  };
71 
74  {
75  TEXTFORMAT_BLOCK = 0,
76  TEXTFORMAT_INLINE = 1
77  };
78 
80  enum AutoSize {
81 
84 
87 
90 
92  AUTOSIZE_RIGHT
93  };
94 
96  enum TypeValue {
97 
100 
104 
106  typeInput
107  };
108 
110  TextField(as_object* object, DisplayObject* parent,
111  const SWF::DefineEditTextTag& def);
112 
114  //
118  TextField(as_object* object, DisplayObject* parent, SWFRect bounds);
119 
120 
121  ~TextField();
122 
123  // TODO: should this return isSelectable() ?
125  bool mouseEnabled() const { return true; }
126 
128  //
131  InteractiveObject* topmostMouseEntity(std::int32_t x, std::int32_t y);
132 
134  //
136  virtual int getDefinitionVersion() const;
137 
139  void mouseEvent(const event_id& id);
140 
142  void keyInput(key::code k);
143 
144  const std::string& getVariableName() const
145  {
146  return _variable_name;
147  }
148 
151  //
155  void set_variable_name(const std::string& newname);
156 
159  //
163  void updateText(const std::string& s);
164 
166  std::string get_text_value() const;
167 
169  std::string get_htmltext_value() const;
170 
172  bool getTextDefined() const { return _textDefined; }
173 
174  size_t getCaretIndex() const {
175  return m_cursor;
176  }
177 
179  //
182  const std::pair<size_t, size_t>& getSelection() const {
183  return _selection;
184  }
185 
187  //
189  void replaceSelection(const std::string& replace);
190 
192  //
195  //
198  void setSelection(int start, int end);
199 
201  //
203  virtual void setWidth(double width);
204 
206  //
208  virtual void setHeight(double height);
209 
211  virtual void display(Renderer& renderer, const Transform& xform);
212 
213  void add_invalidated_bounds(InvalidatedRanges& ranges, bool force);
214 
216  virtual SWFRect getBounds() const
217  {
218  return _bounds;
219  }
220 
221  // See dox in DisplayObject.h
222  bool pointInShape(std::int32_t x, std::int32_t y) const;
223 
225  bool getDrawBackground() const;
226 
228  //
230  void setDrawBackground(bool draw);
231 
233  rgba getBackgroundColor() const;
234 
236  //
240  void setBackgroundColor(const rgba& col);
241 
243  bool getDrawBorder() const;
244 
246  //
248  void setDrawBorder(bool draw);
249 
251  rgba getBorderColor() const;
252 
254  //
258  void setBorderColor(const rgba& col);
259 
261  const rgba& getTextColor() const
262  {
263  return _textColor;
264  }
265 
267  //
270  void setTextColor(const rgba& col);
271 
275  bool getEmbedFonts() const {
276  return _embedFonts;
277  }
278 
280  std::int32_t maxChars() const {
281  return _maxChars;
282  }
283 
285  //
288  void maxChars(std::int32_t max) {
289  _maxChars = max;
290  }
291 
293  bool multiline() const {
294  return _multiline;
295  }
296 
298  //
301  void multiline(bool b) {
302  _multiline = b;
303  }
304 
306  bool password() const {
307  return _password;
308  }
309 
311  //
314  void password(bool b) {
315  _password = b;
316  }
320  //
322  void setEmbedFonts(bool use);
323 
326  {
327  return _autoSize;
328  }
329 
331  TextAlignment getTextAlignment();
332 
334  //
338  void setAutoSize(AutoSize val);
339 
341  //
345  void setType(TypeValue val) { if (val != typeInvalid) _type=val; }
346 
349  {
350  return _type;
351  }
352 
354  bool isReadOnly() const { return _type != typeInput; }
355 
357  //
363  static TypeValue parseTypeValue(const std::string& val);
364 
366  //
373  static const char* typeValueName(TypeValue val);
374 
379  bool doWordWrap() const {
380  return _wordWrap;
381  }
382 
384  //
391  void setWordWrap(bool on);
392 
394  bool doHtml() const {
395  return _html;
396  }
397 
399  //
402  void setHtml(bool on) {
403  _html = on;
404  }
405 
407  bool isSelectable() const
408  {
409  return _selectable;
410  }
411 
413  //
416  void setSelectable(bool v)
417  {
418  _selectable = v;
419  }
420 
421  // See DisplayObject::isActiveTextField
423  virtual bool isSelectableTextField() const
424  {
425  return isSelectable();
426  }
427 
429  //
436  void removeTextField();
437 
439  //
443  boost::intrusive_ptr<const Font> setFont(
444  boost::intrusive_ptr<const Font> newfont);
445 
446  const Font* getFont() { return _font.get(); }
447 
448 
449  std::uint16_t getFontHeight() const
450  {
451  return _fontHeight;
452  }
453 
454  void setFontHeight(std::uint16_t h);
455 
456  std::uint16_t getLeftMargin() const
457  {
458  return _leftMargin;
459  }
460 
461  void setLeftMargin(std::uint16_t h);
462 
463  std::uint16_t getRightMargin() const
464  {
465  return _rightMargin;
466  }
467 
468  void setRightMargin(std::uint16_t h);
469 
470  std::uint16_t getIndent() const
471  {
472  return _indent;
473  }
474 
475  void setIndent(std::uint16_t h);
476 
477  std::uint16_t getBlockIndent() const
478  {
479  return _blockIndent;
480  }
481 
482  void setBlockIndent(std::uint16_t h);
483 
485  {
486  return _alignment;
487  }
488 
489  void setAlignment(TextAlignment h);
490 
491  std::int16_t getLeading() const
492  {
493  return _leading;
494  }
495 
496  void setLeading(std::int16_t h);
497 
498  bool getUnderlined() const
499  {
500  return _underlined;
501  }
502 
504  {
505  return _display;
506  }
507 
508  bool getBullet() const
509  {
510  return _bullet;
511  }
512 
513  const std::vector<int>& getTabStops() const
514  {
515  return _tabStops;
516  }
517 
518  bool isRestrict() const
519  {
520  return _restrictDefined;
521  }
522 
523  const std::string& getRestrict() const
524  {
525  return _restrict;
526  }
527 
528  size_t getScroll() const
529  {
530  return _scroll;
531  }
532 
533  size_t getMaxScroll() const
534  {
535  return _maxScroll;
536  }
537 
538  size_t getHScroll() const
539  {
540  return _hScroll;
541  }
542 
543  size_t getMaxHScroll() const
544  {
545  return _maxHScroll;
546  }
547 
548  size_t getBottomScroll() const
549  {
550  return _bottomScroll;
551  }
552 
553  void setUnderlined(bool v);
554  void setTabStops(const std::vector<int>& tabStops);
555  void setBullet(bool b);
556  void setURL(std::string url);
557  void setTarget(std::string target);
558  void setRestrict(const std::string& restrict);
559  void setDisplay(TextFormatDisplay display);
560  void setScroll(size_t scroll) {
561  _scroll = scroll;
562  format_text();
563  }
564  void setMaxScroll(size_t maxScroll) {
565  _maxScroll = maxScroll;
566  format_text();
567  }
568  void setHScroll(size_t hScroll) {
569  _hScroll = hScroll;
570  format_text();
571  }
572  void setMaxHScroll(size_t maxHScroll) {
573  _maxHScroll = maxHScroll;
574  format_text();
575  }
576  void setbottomScroll(size_t bottomScroll) {
577  _bottomScroll = bottomScroll;
578  format_text();
579  }
580 
582  //
583  size_t cursorRecord();
584 
585  void setTextFormat(TextFormat_as& tf);
586 
587  const SWFRect& getTextBoundingBox() const {
588  return m_text_bounding_box;
589  }
590 
592  //
595  void setTextValue(const std::wstring& wstr);
596 
597 private:
598 
599  void init();
600 
603  //
607  void updateText(const std::wstring& s);
608 
609  void updateHtmlText(const std::wstring& s);
610 
611  void insertTab(SWF::TextRecord& rec, std::int32_t& x, float scale);
612 
614  //
617  virtual bool handleFocus();
618 
620  virtual void killFocus();
621 
623  void onChanged();
624 
626  void reset_bounding_box(std::int32_t x, std::int32_t y)
627  {
628  m_text_bounding_box.set_to_point(x, y);
629  }
630 
633  void format_text();
634 
636  void scrollLines();
637 
640  void newLine(std::int32_t& x, std::int32_t& y,
641  SWF::TextRecord& rec, int& last_space_glyph,
642  LineStarts::value_type& last_line_start_record, float div);
643 
645  void handleChar(std::wstring::const_iterator& it,
646  const std::wstring::const_iterator& e, std::int32_t& x,
647  std::int32_t& y, SWF::TextRecord& rec, int& last_code,
648  int& last_space_glyph,
649  LineStarts::value_type& last_line_start_record);
650 
661  bool parseHTML(std::wstring& tag,
662  std::map<std::string, std::string>& attributes,
663  std::wstring::const_iterator& it,
664  const std::wstring::const_iterator& e,
665  bool& selfclosing) const;
666 
671  float align_line(TextAlignment align, int last_line_start_record, float x);
672 
674  //
690  void registerTextVariable();
691 
692  typedef std::pair<as_object*, ObjectURI> VariableRef;
693 
698  VariableRef parseTextVariableRef(const std::string& variableName) const;
699 
701  //
704  void show_cursor(Renderer& renderer, const SWFMatrix& mat);
705 
707  //
709  boost::intrusive_ptr<const SWF::DefineEditTextTag> _tag;
710 
712  //
717  std::wstring _text;
718 
720  //
721  std::wstring _htmlText;
722 
724  SWFRect m_text_bounding_box;
725 
726  typedef std::vector<SWF::TextRecord> TextRecords;
727  TextRecords _textRecords;
728 
729  std::vector<size_t> _recordStarts;
730 
731  TextRecords _displayRecords;
732 
733  std::string _url;
734  std::string _target;
735  std::string _restrict;
736  std::set<wchar_t> _restrictedchars;
737  TextFormatDisplay _display;
738  std::vector<int> _tabStops;
739  LineStarts _line_starts;
740 
742  //
746  std::string _variable_name;
747 
748  rgba _backgroundColor;
749 
750  rgba _borderColor;
751 
752  rgba _textColor;
753 
754  TextAlignment _alignment;
755 
756  boost::intrusive_ptr<const Font> _font;
757  size_t m_cursor;
758  size_t _glyphcount;
759  size_t _scroll;
760  size_t _maxScroll;
761  size_t _hScroll;
762  size_t _maxHScroll;
763  size_t _bottomScroll;
764  size_t _linesindisplay;
765 
767  size_t _maxChars;
768 
769  AutoSize _autoSize;
770 
771  TypeValue _type;
772 
774  //
779  SWFRect _bounds;
780 
783  std::pair<size_t, size_t> _selection;
784 
785  std::int16_t _leading;
786  std::uint16_t _indent;
787 
790  std::uint16_t _blockIndent;
791 
792  std::uint16_t _leftMargin;
793 
794  std::uint16_t _rightMargin;
795 
796  std::uint16_t _fontHeight;
797 
802  bool _textDefined;
803 
804  bool _restrictDefined;
805  bool _underlined;
806  bool _bullet;
807 
808  bool m_has_focus;
809 
810 
812  bool _multiline;
813 
815  bool _password;
816 
818  //
822  bool _text_variable_registered;
823 
824  bool _drawBackground;
825 
826  bool _drawBorder;
827 
828  bool _embedFonts;
829 
830  bool _wordWrap;
831 
832  bool _html;
833 
834  bool _selectable;
835 
836 };
837 
838 } // namespace gnash
839 
840 #endif
const std::pair< size_t, size_t > & getSelection() const
Get a std::pair of size_t with start/end of selection.
Definition: TextField.h:182
The TextFormat_as Relay type stores text properties.
Definition: TextFormat_as.h:44
size_t getMaxHScroll() const
Definition: TextField.h:543
TypeValue getType() const
Get type (input, dynamic or invalid)
Definition: TextField.h:348
const std::string & getRestrict() const
Definition: TextField.h:523
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:168
A Font resource.
Definition: Font.h:89
Definition: klash_part.cpp:330
Invalid value.
Definition: TextField.h:99
void setMaxHScroll(size_t maxHScroll)
Definition: TextField.h:572
size_t getMaxScroll() const
Definition: TextField.h:533
void multiline(bool b)
Set the current multiline setting of the TextField.
Definition: TextField.h:301
Definition: SWFMatrix.h:53
bool isSelectable() const
Return true if the TextField text is selectable.
Definition: TextField.h:407
Definition: TextField.h:67
std::vector< size_t > LineStarts
Definition: TextField.h:61
Definition: GnashKey.h:157
v
Definition: test.py:11
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
const std::string & getVariableName() const
Definition: TextField.h:144
std::int32_t maxChars() const
Get the current maxChars setting of the TextField.
Definition: TextField.h:280
Definition: TextField.h:103
Definition: klash_part.cpp:329
The base class for all ActionScript objects.
Definition: as_object.h:161
TextFormatDisplay getDisplay() const
Definition: TextField.h:503
const std::vector< int > & getTabStops() const
Definition: TextField.h:513
Base class for render handlers.
Definition: Renderer.h:188
void setHtml(bool on)
Set html parameter.
Definition: TextField.h:402
void setType(TypeValue val)
Set type (input or dynamic)
Definition: TextField.h:345
size_t getCaretIndex() const
Definition: TextField.h:174
void maxChars(std::int32_t max)
Set the current maxChars setting of the TextField.
Definition: TextField.h:288
code
Definition: GnashKey.h:43
Expand TextField, anchor the horizontal center.
Definition: TextField.h:89
size_t getScroll() const
Definition: TextField.h:528
virtual SWFRect getBounds() const
Get bounding SWFRect of this TextField.
Definition: TextField.h:216
Definition: klash_part.cpp:329
Definition: TextField.h:68
TextAlignment
Text alignment values.
Definition: TextField.h:64
bool isRestrict() const
Definition: TextField.h:518
Store a TextRecord.
Definition: TextRecord.h:47
bool doHtml() const
Return true if HTML markup in text should be rendered.
Definition: TextField.h:394
void setScroll(size_t scroll)
Definition: TextField.h:560
TextFormatDisplay
Text format display values.
Definition: TextField.h:73
const rgba & getTextColor() const
Return color of the text.
Definition: TextField.h:261
std::int32_t x
Definition: BitmapData_as.cpp:434
bool password() const
Get the current password setting of the TextField.
Definition: TextField.h:306
TypeValue
Possible type values.
Definition: TextField.h:96
bool getUnderlined() const
Definition: TextField.h:498
bool getTextDefined() const
Return true if text is defined.
Definition: TextField.h:172
virtual bool isSelectableTextField() const
Return true if the TextField text is selectable.
Definition: TextField.h:423
size_t getBottomScroll() const
Definition: TextField.h:548
Definition: GnashKey.h:148
std::uint16_t getFontHeight() const
Definition: TextField.h:449
size_t getHScroll() const
Definition: TextField.h:538
bool doWordWrap() const
Return true if text should continue to next available line when hitting end of bounding box...
Definition: TextField.h:379
const SWFRect & getTextBoundingBox() const
Definition: TextField.h:587
void setSelectable(bool v)
Set &#39;selectable&#39; parameter.
Definition: TextField.h:416
void setHScroll(size_t hScroll)
Definition: TextField.h:568
The base class for interactive objects.
Definition: InteractiveObject.h:44
std::uint16_t getIndent() const
Definition: TextField.h:470
SWF Tag DefineEditText (37).
Definition: DefineEditTextTag.h:56
bool getBullet() const
Definition: TextField.h:508
std::uint16_t getRightMargin() const
Definition: TextField.h:463
std::int32_t y
Definition: BitmapData_as.cpp:435
Definition: GnashKey.h:154
Expand TextField, anchor the top-left side.
Definition: TextField.h:86
Rectangle class, see swf defined rectangle record.
Definition: SWFRect.h:44
std::string url
Definition: gnash.cpp:59
Definition: GnashKey.h:151
Do not automatically resize TextField as text grow/shrink.
Definition: TextField.h:83
bool isReadOnly() const
Return true if this TextField is read-only.
Definition: TextField.h:354
#define DSOTEXPORT
Definition: dsodefs.h:63
pixel_iterator< T > end(GnashImage &im)
Definition: ImageIterators.h:198
void setbottomScroll(size_t bottomScroll)
Definition: TextField.h:576
std::int16_t getLeading() const
Definition: TextField.h:491
A class to identify &#39;static&#39; SWF events (system events).
Definition: event_id.h:52
void setMaxScroll(size_t maxScroll)
Definition: TextField.h:564
Definition: GnashKey.h:165
bool getEmbedFonts() const
Return true if this TextField should use embedded font glyphs, false if it should use device font gly...
Definition: TextField.h:275
bool multiline() const
Get the current multiline setting of the TextField.
Definition: TextField.h:293
std::uint16_t getLeftMargin() const
Definition: TextField.h:456
AutoSize getAutoSize() const
Get autoSize value.
Definition: TextField.h:325
void setHeight(DisplayObject &o, const as_value &val)
Definition: DisplayObject.cpp:365
Definition: GnashKey.h:331
The Transform class expresses a stage in a cumulative transformation.
Definition: Transform.h:33
TextAlignment getAlignment() const
Definition: TextField.h:484
bool mouseEnabled() const
Returns true for now, TextField is always "Mouse-Enabled".
Definition: TextField.h:125
An instance of a DefineEditTextTag.
Definition: TextField.h:56
std::uint16_t getBlockIndent() const
Definition: TextField.h:477
void password(bool b)
Set the current password setting of the TextField.
Definition: TextField.h:314
const Font * getFont()
Definition: TextField.h:446
AutoSize
Possible autoSize values.
Definition: TextField.h:80
A basic RGBA type.
Definition: RGBA.h:35