cwidget 0.5.16
|
00001 // fragment.h -*-c++-*- 00002 // 00003 // Copyright (C) 2004-2005, 2007 Daniel Burrows 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License as 00007 // published by the Free Software Foundation; either version 2 of 00008 // the License, or (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 GNU 00013 // 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; see the file COPYING. If not, write to 00017 // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 // Boston, MA 02111-1307, USA. 00019 // 00020 // Fragments are pieces of text that live in a text_layout widget. 00021 // See widgets/text_layout.h for details. 00022 00023 #ifndef FRAGMENT_H 00024 #define FRAGMENT_H 00025 00026 #include "fragment_contents.h" 00027 00028 #include <cwidget/style.h> 00029 00030 #include <string> 00031 #include <vector> 00032 00033 namespace cwidget 00034 { 00037 class fragment 00038 { 00039 public: 00058 virtual fragment_contents layout(size_t firstw, 00059 size_t w, 00060 const style &st)=0; 00061 00071 virtual size_t max_width(size_t first_indent, 00072 size_t rest_indent) const=0; 00073 00081 virtual size_t trailing_width(size_t first_indent, 00082 size_t rest_indent) const=0; 00083 00085 virtual bool final_newline() const=0; 00086 00088 virtual ~fragment(); 00089 }; 00090 00091 // Factory methods to avoid cluttering the .h file: 00092 00101 fragment *text_fragment(const std::wstring &s); 00102 00112 fragment *text_fragment(const std::wstring &s, 00113 const style &st); 00114 00123 fragment *text_fragment(const std::string &s, 00124 const char *encoding=NULL); 00125 00129 fragment *text_fragment(const std::string &s, 00130 const style &st, 00131 const char *encoding=NULL); 00132 00141 inline fragment *text_fragment(const char *s, 00142 const style &st=style()) 00143 { 00144 return text_fragment(std::string(s), st); 00145 } 00146 00148 fragment *newline_fragment(); 00149 00157 fragment *style_fragment(fragment *f, 00158 const style &st); 00159 00173 fragment *sequence_fragment(const std::vector<fragment *> &fragments); 00174 00185 fragment *sequence_fragment(fragment *f, ...); 00186 00195 fragment *join_fragments(const std::vector<fragment *> &fragments, 00196 const std::wstring &between); 00197 00211 fragment *flowbox(fragment *contents); 00212 00225 fragment *fillbox(fragment *contents); 00226 00238 fragment *hardwrapbox(fragment *contents); 00239 00251 fragment *clipbox(fragment *contents); 00252 00267 fragment *indentbox(size_t firstindent, size_t restindent, fragment *contents); 00268 00277 fragment *dropbox(fragment *header, fragment *contents); 00278 00280 struct fragment_column_entry 00281 { 00285 bool proportional; 00286 00292 bool expandable; 00293 00298 size_t width; 00299 00300 enum align {top, center, bottom}; 00301 00308 align vert_align; 00309 00320 std::vector<fragment *>lines; 00321 00323 fragment_column_entry(bool _proportional, 00324 bool _expandable, 00325 size_t _width, align _vert_align, 00326 fragment *f) 00327 :proportional(_proportional), 00328 expandable(_expandable), 00329 width(_width), 00330 vert_align(_vert_align) 00331 { 00332 lines.push_back(f); 00333 } 00334 00335 fragment_column_entry(bool _proportional, 00336 bool _expandable, 00337 size_t _width, align _vert_align, 00338 const std::vector<fragment *> &_lines) 00339 :proportional(_proportional), 00340 expandable(_expandable), 00341 width(_width), 00342 vert_align(_vert_align), 00343 lines(_lines) 00344 { 00345 } 00346 00347 fragment_column_entry() 00348 :proportional(false), width(0), vert_align(top) 00349 { 00350 } 00351 }; 00352 00364 fragment *fragment_columns(const std::vector<fragment_column_entry> &columns); 00365 00393 fragment *fragf(const char *format, ...); 00394 } 00395 00396 #endif