00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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