00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _FL_SIMPLE_HTML_H_
00023 #define _FL_SIMPLE_HTML_H_
00024
00025 #include <stdio.h>
00026
00027 #include <efltk/Fl.h>
00028 #include <efltk/Fl_Group.h>
00029 #include <efltk/Fl_Scrollbar.h>
00030 #include <efltk/fl_draw.h>
00031 #include <efltk/Fl_Image.h>
00032 #include <efltk/Fl_Image_Cache.h>
00033
00034
00035
00036
00037 typedef const char *(Fl_Help_Func)(Fl_Widget *, const char *);
00038
00039
00040
00041
00042 struct Fl_Help_Block
00043 {
00044 const char *start,
00045 *end;
00046 uchar border;
00047 Fl_Color bgcolor;
00048 int x,
00049 y,
00050 w,
00051 h;
00052 int line[32];
00053 };
00054
00055
00056
00057
00058
00059 struct Fl_Help_Link
00060 {
00061 char filename[192],
00062 name[32];
00063 int x,
00064 y,
00065 w,
00066 h;
00067 };
00068
00069
00070
00071
00072
00073 struct Fl_Help_Target
00074 {
00075 char name[32];
00076 int y;
00077 };
00078
00080 class Fl_Simple_Html : public Fl_Group
00081 {
00082 Fl_Image_Cache cache;
00083
00084 enum { RIGHT = -1, CENTER, LEFT };
00085
00086 char title_[1024];
00087 Fl_Color defcolor_,
00088 bgcolor_,
00089 textcolor_,
00090 linkcolor_;
00091 Fl_Font textfont_;
00092 uchar textsize_;
00093
00094 const char *value_;
00095
00096 int nblocks_,
00097 ablocks_;
00098 Fl_Help_Block *blocks_;
00099
00100 int nfonts_;
00101 Fl_Font fonts_[100];
00102 uchar fontss_[100];
00103
00104 Fl_Help_Func *link_;
00105
00106 int nlinks_,
00107 alinks_;
00108 Fl_Help_Link *links_;
00109
00110 int ntargets_,
00111 atargets_;
00112 Fl_Help_Target *targets_;
00113
00114 char directory_[1024];
00115 char filename_[1024];
00116 char prevfilename_[1024];
00117
00118 int topline_,
00119 leftline_,
00120 size_,
00121 hsize_;
00122
00123 Fl_Scrollbar scrollbar_,
00124 hscrollbar_;
00125
00126 Fl_Help_Block *add_block(const char *s, int xx, int yy, int ww, int hh, uchar border = 0);
00127 void add_link(const char *n, int xx, int yy, int ww, int hh);
00128 void add_target(const char *n, int yy);
00129 static int compare_targets(const Fl_Help_Target *t0, const Fl_Help_Target *t1);
00130 int do_align(Fl_Help_Block *block, int line, int xx, int a, int &l);
00131 void draw();
00132 void format();
00133 void format_table(int *table_width, int *columns, const char *table);
00134 int get_align(const char *p, int a);
00135 const char *get_attr(const char *p, const char *n, char *buf, int bufsize);
00136 Fl_Color get_color(const char *n, Fl_Color c);
00137 Fl_Image *get_image(const char *name, int W, int H);
00138 int get_length(const char *l);
00139 int handle(int);
00140
00141 void initfont(Fl_Font &f, uchar &s) {
00142 nfonts_ = 0;
00143 fl_font(f = fonts_[0] = textfont_, s = fontss_[0] = textsize_);
00144 }
00145
00146 void pushfont(Fl_Font f, uchar s) {
00147 if (nfonts_ < 99) nfonts_ ++;
00148 fl_font(fonts_[nfonts_] = f, fontss_[nfonts_] = s);
00149 }
00150
00151 void popfont(Fl_Font &f, uchar &s) {
00152 if (nfonts_ > 0) nfonts_ --;
00153 fl_font(f = fonts_[nfonts_], s = fontss_[nfonts_]);
00154 }
00155
00156 void ctor_init(int ww,int hh);
00157
00158 public:
00159
00161 Fl_Simple_Html(int xx, int yy, int ww, int hh, const char *l = 0);
00162
00164 Fl_Simple_Html(const char* l = 0,int layout_size=30,Fl_Align layout_al=FL_ALIGN_TOP,int label_w=-1);
00165
00167 ~Fl_Simple_Html();
00168
00169 const char *directory() const {
00170 if (directory_[0]) return (directory_);
00171 else return ((const char *)0);
00172 }
00173 const char *filename() const {
00174 if (filename_[0]) return (filename_);
00175 else return ((const char *)0);
00176 }
00177 const char *prev_filename() const {
00178 if (prevfilename_[0]) return (prevfilename_);
00179 else return ((const char *)0);
00180 }
00181 void link(Fl_Help_Func *fn) { link_ = fn; }
00182 int load(const char *f);
00183 void layout();
00184 int size() const { return (size_); }
00185 void textcolor(Fl_Color c) { if(textcolor_ == defcolor_) textcolor_ = c; defcolor_ = c; }
00186 Fl_Color textcolor() const { return (defcolor_); }
00187 void textfont(Fl_Font f) { textfont_ = f; format(); }
00188 Fl_Font textfont() const { return (textfont_); }
00189 void textsize(uchar s) { textsize_ = s; format(); }
00190 uchar textsize() const { return (textsize_); }
00191 const char *title() { return (title_); }
00192 void topline(const char *n);
00193 void topline(int);
00194 int topline() const { return (topline_); }
00195 void leftline(int);
00196 int leftline() const { return (leftline_); }
00197 void value(const char *v);
00198 const char *value() const { return (value_); }
00199 };
00200
00201 #endif