00001 // 00002 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software 00003 // Foundation, Inc 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 00019 // 00020 // 00021 00022 #ifndef GNASH_TEXTFORMAT_H 00023 #define GNASH_TEXTFORMAT_H 00024 00025 #include "TextField.h" 00026 #include "RGBA.h" 00027 00028 #include <vector> 00029 #include <boost/cstdint.hpp> 00030 #include <string> 00031 00032 namespace gnash { 00033 class as_object; 00034 } 00035 00036 namespace gnash { 00037 00039 // 00043 template<typename T> 00044 class 00045 Optional 00046 { 00047 public: 00048 00050 Optional() 00051 : 00052 _t(), 00053 _set(false) 00054 {} 00055 00057 // 00059 Optional(const T& t) 00060 : 00061 _t(t), 00062 _set(true) 00063 {} 00064 00066 void unset() { 00067 _set = false; 00068 } 00069 00071 operator const void*() const { 00072 return _set ? this : 0; 00073 } 00074 00076 const T* operator->() const { 00077 assert(_set); 00078 return &_t; 00079 } 00080 00082 Optional<T>& operator=(const T& t) { 00083 _t = t; 00084 _set = true; 00085 return *this; 00086 } 00087 00089 const T& operator*() const { 00090 assert(_set); 00091 return _t; 00092 } 00093 00094 private: 00095 T _t; 00096 bool _set; 00097 }; 00098 00099 00101 // 00103 // 00105 class TextFormat_as : public Relay 00106 { 00107 public: 00108 00109 TextFormat_as(); 00110 00111 ~TextFormat_as() {} 00112 00114 const Optional<bool>& underlined() const { return _underline; } 00115 00117 const Optional<bool>& bold() const { return _bold; } 00118 00120 const Optional<bool>& italic() const { return _italic; } 00121 00123 const Optional<rgba>& color() const { return _color; } 00124 00126 const Optional<bool>& bullet() const { return _bullet; } 00127 00129 // 00131 TextField::TextFormatDisplay display() const { 00132 return _display; 00133 } 00134 00135 const Optional<std::vector<int> >& tabStops() const { 00136 return _tabStops; 00137 } 00138 00140 const Optional<boost::uint16_t>& indent() const { return _indent; } 00141 00143 const Optional<TextField::TextAlignment>& align() const { return _align; } 00144 00146 const Optional<std::string>& font() const { return _font; } 00147 00148 // See doc for _target member 00149 const Optional<std::string>& target() const { return _target; } 00150 00151 // See doc for _url member 00152 const Optional<std::string>& url() const { return _url; } 00153 00155 const Optional<boost::uint32_t>& blockIndent() const { 00156 return _blockIndent; 00157 } 00158 00161 const Optional<boost::uint16_t>& leading() const { return _leading; } 00162 00164 const Optional<boost::uint16_t>& leftMargin() const { return _leftMargin; } 00165 00167 const Optional<boost::uint16_t>& rightMargin() const { 00168 return _rightMargin; 00169 } 00170 00172 const Optional<boost::uint16_t>& size() const { return _pointSize; } 00173 00175 00176 void targetSet(const Optional<std::string>& s) { _target=s; } 00177 00178 void urlSet(const Optional<std::string>& s) { _url=s; } 00179 00180 void underlinedSet(const Optional<bool>& x) { _underline = x; } 00181 00182 void italicSet(const Optional<bool>& x) { _italic = x; } 00183 00184 void boldSet(const Optional<bool>& x) { _bold = x; } 00185 00186 void bulletSet(const Optional<bool>& x) { _bullet = x; } 00187 00188 void colorSet(const Optional<rgba>& x) { _color = x; } 00189 00190 void indentSet(const Optional<boost::uint16_t>& x) { _indent = x; } 00191 00192 void fontSet(const Optional<std::string>& font) { _font=font; } 00193 00194 void alignSet(const Optional<TextField::TextAlignment>& x) { _align = x; } 00195 00196 void alignSet(const std::string& align); 00197 00198 void blockIndentSet(const Optional<boost::uint32_t>& x) { 00199 _blockIndent = x; 00200 } 00201 00202 void leadingSet(const Optional<boost::uint16_t>& x) { _leading = x; } 00203 00204 void leftMarginSet(const Optional<boost::uint16_t>& x) { _leftMargin = x; } 00205 00206 void rightMarginSet(const Optional<boost::uint16_t>& x) { 00207 _rightMargin = x; 00208 } 00209 00210 void sizeSet(const Optional<boost::uint16_t>& x) { _pointSize = x; } 00211 00212 void tabStopsSet(const std::vector<int>& tabStops) { _tabStops = tabStops; } 00213 00215 void displaySet(TextField::TextFormatDisplay x) { _display = x; } 00216 void displaySet(const std::string& display); 00217 private: 00218 00220 Optional<bool> _underline; 00221 00223 Optional<bool> _bold; 00224 00226 Optional<bool> _italic; 00227 00228 // 00229 Optional<bool> _bullet; 00230 00231 TextField::TextFormatDisplay _display; 00232 00234 // 00239 Optional<TextField::TextAlignment> _align; 00240 00241 // 00242 Optional<boost::uint32_t> _blockIndent; 00243 00245 // 00248 Optional<rgba> _color; 00249 00250 // The name of a font for text as a string. 00251 Optional<std::string> _font; 00252 00255 Optional<boost::uint16_t> _indent; 00256 00259 Optional<boost::uint16_t> _leading; 00260 00262 Optional<boost::uint16_t> _leftMargin; 00263 00265 Optional<boost::uint16_t> _rightMargin; 00266 00268 Optional<boost::uint16_t> _pointSize; 00269 00271 Optional<std::vector<int> > _tabStops; 00272 00278 Optional<std::string> _target; 00279 00282 Optional<std::string> _url; 00283 }; 00284 00285 void textformat_class_init(as_object& global, const ObjectURI& uri); 00286 00287 void registerTextFormatNative(as_object& global); 00288 00289 } // end of gnash namespace 00290 00291 #endif 00292