Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Fl_Simple_Html.h

00001 /*
00002  * $Id: Fl_Simple_Html.h,v 1.4 2003/05/13 21:26:35 parshin Exp $
00003  *
00004  * Extended Fast Light Toolkit (EFLTK)
00005  * Copyright (C) 2002-2003 by EDE-Team
00006  * WWW: http://www.sourceforge.net/projects/ede
00007  *
00008  * Fast Light Toolkit (FLTK)
00009  * Copyright (C) 1998-2003 by Bill Spitzak and others.
00010  * WWW: http://www.fltk.org
00011  *
00012  * This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00013  * version 2. See COPYING for details.
00014  *
00015  * Author : Mikko Lahteenmaki
00016  * Email  : mikko@fltk.net
00017  *
00018  * Please report all bugs and problems to "efltk-bugs@fltk.net"
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 // Fl_Help_Func type - link callback function for files...
00036 //
00037 typedef const char *(Fl_Help_Func)(Fl_Widget *, const char *);
00038 
00039 //
00040 // Fl_Help_Block structure...
00041 //
00042 struct Fl_Help_Block
00043 {
00044     const char *start,      // Start of text
00045         *end;       // End of text
00046     uchar border;       // Draw border?
00047     Fl_Color bgcolor;   // Background color
00048     int x,      // Indentation/starting X coordinate
00049         y,      // Starting Y coordinate
00050         w,      // Width
00051         h;      // Height
00052     int line[32];   // Left starting position for each line
00053 };
00054 
00055 //
00056 // Fl_Help_Link structure...
00057 //
00058 
00059 struct Fl_Help_Link
00060 {
00061     char filename[192], // Reference filename
00062         name[32];   // Link target (blank if none)
00063     int x,      // X offset of link text
00064         y,      // Y offset of link text
00065         w,      // Width of link text
00066         h;      // Height of link text
00067 };
00068 
00069 //
00070 // Fl_Help_Target structure...
00071 //
00072 
00073 struct Fl_Help_Target
00074 {
00075     char name[32];  // Target name
00076     int  y;     // Y offset of target
00077 };
00078 
00080 class Fl_Simple_Html : public Fl_Group  
00081 {
00082     Fl_Image_Cache cache; //Image cache
00083 
00084     enum { RIGHT = -1, CENTER, LEFT };  // Alignments
00085 
00086     char title_[1024];      // Title string
00087     Fl_Color defcolor_,     // Default text color
00088         bgcolor_,       // Background color
00089         textcolor_,     // Text color
00090         linkcolor_;     // Link color
00091     Fl_Font textfont_;      // Default font for text
00092     uchar textsize_;        // Default font size
00093 
00094     const char  *value_;        // HTML text value
00095 
00096     int nblocks_,       // Number of blocks/paragraphs
00097         ablocks_;       // Allocated blocks
00098     Fl_Help_Block *blocks_;     // Blocks
00099 
00100     int nfonts_;        // Number of fonts in stack
00101     Fl_Font     fonts_[100];        // Font stack
00102     uchar       fontss_[100];       // sizes
00103 
00104     Fl_Help_Func *link_;            // Link transform function
00105 
00106     int nlinks_,        // Number of links
00107         alinks_;        // Allocated links
00108     Fl_Help_Link *links_;       // Links
00109 
00110     int ntargets_,      // Number of targets
00111         atargets_;      // Allocated targets
00112     Fl_Help_Target *targets_;       // Targets
00113 
00114     char    directory_[1024];   // Directory for current file
00115     char    filename_[1024];    // Current filename
00116     char    prevfilename_[1024];    // Prev filename
00117 
00118     int     topline_,       // Top line in document
00119         leftline_,      // Lefthand position
00120         size_,          // Total document length
00121         hsize_;         // Maximum document width
00122 
00123     Fl_Scrollbar    scrollbar_,     // Vertical scrollbar for document
00124         hscrollbar_;        // Horizontal scrollbar
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

Generated on Thu Jul 31 15:33:45 2003 for eFLTK by doxygen1.2.15