FLTK 1.3.0
Fl_Help_View.H
00001 //
00002 // "$Id$"
00003 //
00004 // Help Viewer widget definitions.
00005 //
00006 // Copyright 1997-2010 by Easy Software Products.
00007 // Image support by Matthias Melcher, Copyright 2000-2009.
00008 //
00009 // This library is free software. Distribution and use rights are outlined in
00010 // the file "COPYING" which should have been included with this file.  If this
00011 // file is missing or damaged, see the license at:
00012 //
00013 //     http://www.fltk.org/COPYING.php
00014 //
00015 // Please report all bugs and problems on the following page:
00016 //
00017 //     http://www.fltk.org/str.php
00018 //
00019 
00020 /* \file
00021    Fl_Help_View widget . */
00022 
00023 #ifndef Fl_Help_View_H
00024 #  define Fl_Help_View_H
00025 
00026 //
00027 // Include necessary header files...
00028 //
00029 
00030 #  include <stdio.h>
00031 #  include "Fl.H"
00032 #  include "Fl_Group.H"
00033 #  include "Fl_Scrollbar.H"
00034 #  include "fl_draw.H"
00035 #  include "Fl_Shared_Image.H"
00036 #  include "filename.H"
00037 
00038 
00039 //
00040 // Fl_Help_Func type - link callback function for files...
00041 //
00042 
00043 
00044 typedef const char *(Fl_Help_Func)(Fl_Widget *, const char *);
00045 
00046 
00047 //
00048 // Fl_Help_Block structure...
00049 //
00050 
00051 struct Fl_Help_Block {
00052   const char    *start,         // Start of text
00053                 *end;           // End of text
00054   uchar         border;         // Draw border?
00055   Fl_Color      bgcolor;        // Background color
00056   int           x,              // Indentation/starting X coordinate
00057                 y,              // Starting Y coordinate
00058                 w,              // Width
00059                 h;              // Height
00060   int           line[32];       // Left starting position for each line
00061 };
00062 
00063 //
00064 // Fl_Help_Link structure...
00065 //
00067 struct Fl_Help_Link {
00068   char          filename[192],  
00069                 name[32];       
00070   int           x,              
00071                 y,              
00072                 w,              
00073                 h;              
00074 };
00075 
00076 /*
00077  * Fl_Help_View font stack opaque implementation
00078  */
00079 
00081 struct FL_EXPORT Fl_Help_Font_Style {
00082   Fl_Font      f;  
00083   Fl_Fontsize  s;  
00084   Fl_Color     c;  
00085   void get(Fl_Font &afont, Fl_Fontsize &asize, Fl_Color &acolor) {afont=f; asize=s; acolor=c;} 
00086   void set(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {f=afont; s=asize; c=acolor;} 
00087   Fl_Help_Font_Style(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {set(afont, asize, acolor);}
00088   Fl_Help_Font_Style(){} // For in table use
00089 };
00090 
00092 const size_t MAX_FL_HELP_FS_ELTS = 100;
00093 
00094 struct FL_EXPORT Fl_Help_Font_Stack {
00096   Fl_Help_Font_Stack() {
00097     nfonts_ = 0;
00098   }
00099 
00100   void init(Fl_Font f, Fl_Fontsize s, Fl_Color c) { 
00101     nfonts_ = 0;
00102     elts_[nfonts_].set(f, s, c);
00103     fl_font(f, s); 
00104     fl_color(c);
00105   }
00107   void top(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { elts_[nfonts_].get(f, s, c); }
00109   void push(Fl_Font f, Fl_Fontsize s, Fl_Color c) { 
00110     if (nfonts_ <  MAX_FL_HELP_FS_ELTS-1) nfonts_ ++;
00111     elts_[nfonts_].set(f, s, c);
00112     fl_font(f, s); fl_color(c); 
00113   }
00115   void pop(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { 
00116     if (nfonts_ > 0) nfonts_ --;
00117     top(f, s, c);
00118     fl_font(f, s); fl_color(c);
00119   }
00121   size_t count() const {return nfonts_;} // Gets the current number of fonts in the stack
00122 
00123 protected:
00124   size_t nfonts_;               
00125   Fl_Help_Font_Style elts_[100]; 
00126 };
00127 
00130 struct Fl_Help_Target {
00131   char          name[32];       
00132   int           y;              
00133 };
00134 
00200 class FL_EXPORT Fl_Help_View : public Fl_Group {        // Help viewer widget
00201   
00202   enum { RIGHT = -1, CENTER, LEFT };    
00203 
00204   char          title_[1024];           
00205   Fl_Color      defcolor_,              
00206                 bgcolor_,               
00207                 textcolor_,             
00208                 linkcolor_;             
00209   Fl_Font       textfont_;              
00210   Fl_Fontsize  textsize_;               
00211   const char    *value_;                
00212   Fl_Help_Font_Stack fstack_;           
00213   int           nblocks_,               
00214                 ablocks_;               
00215   Fl_Help_Block *blocks_;               
00216 
00217   Fl_Help_Func  *link_;                 
00218 
00219   int           nlinks_,                
00220                 alinks_;                
00221   Fl_Help_Link  *links_;                
00222 
00223   int           ntargets_,              
00224                 atargets_;              
00225   Fl_Help_Target *targets_;             
00226 
00227   char          directory_[FL_PATH_MAX];
00228   char          filename_[FL_PATH_MAX]; 
00229   int           topline_,               
00230                 leftline_,              
00231                 size_,                  
00232                 hsize_,                 
00233                 scrollbar_size_;        
00234   Fl_Scrollbar  scrollbar_,             
00235                 hscrollbar_;            
00236 
00237   static int    selection_first;
00238   static int    selection_last;
00239   static int    selection_push_first;
00240   static int    selection_push_last;
00241   static int    selection_drag_first;
00242   static int    selection_drag_last;
00243   static int    selected;
00244   static int    draw_mode;
00245   static int    mouse_x;
00246   static int    mouse_y;
00247   static int    current_pos;
00248   static Fl_Help_View *current_view;
00249   static Fl_Color hv_selection_color;
00250   static Fl_Color hv_selection_text_color;
00251 
00252 
00253   void initfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { f = textfont_; s = textsize_; c = textcolor_; fstack_.init(f, s, c); }
00254   void pushfont(Fl_Font f, Fl_Fontsize s) {fstack_.push(f, s, textcolor_);}
00255   void pushfont(Fl_Font f, Fl_Fontsize s, Fl_Color c) {fstack_.push(f, s, c);}
00256   void popfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {fstack_.pop(f, s, c);}
00257 
00258   Fl_Help_Block *add_block(const char *s, int xx, int yy, int ww, int hh, uchar border = 0);
00259   void          add_link(const char *n, int xx, int yy, int ww, int hh);
00260   void          add_target(const char *n, int yy);
00261   static int    compare_targets(const Fl_Help_Target *t0, const Fl_Help_Target *t1);
00262   int           do_align(Fl_Help_Block *block, int line, int xx, int a, int &l);
00263   void          draw();
00264   void          format();
00265   void          format_table(int *table_width, int *columns, const char *table);
00266   void          free_data();
00267   int           get_align(const char *p, int a);
00268   const char    *get_attr(const char *p, const char *n, char *buf, int bufsize);
00269   Fl_Color      get_color(const char *n, Fl_Color c);
00270   Fl_Shared_Image *get_image(const char *name, int W, int H);
00271   int           get_length(const char *l);
00272   int           handle(int);
00273 
00274   void          hv_draw(const char *t, int x, int y);
00275   char          begin_selection();
00276   char          extend_selection();
00277   void          end_selection(int c=0);
00278   void          clear_global_selection();
00279   Fl_Help_Link  *find_link(int, int);
00280   void          follow_link(Fl_Help_Link*);
00281 
00282 public:
00283 
00284   Fl_Help_View(int xx, int yy, int ww, int hh, const char *l = 0);
00285   ~Fl_Help_View();
00287   const char    *directory() const { if (directory_[0]) return (directory_);
00288                                         else return ((const char *)0); }
00290   const char    *filename() const { if (filename_[0]) return (filename_);
00291                                         else return ((const char *)0); }
00292   int           find(const char *s, int p = 0);
00315   void          link(Fl_Help_Func *fn) { link_ = fn; }
00316   int           load(const char *f);
00317   void          resize(int,int,int,int);
00319   int           size() const { return (size_); }
00320   void          size(int W, int H) { Fl_Widget::size(W, H); }
00322   void          textcolor(Fl_Color c) { if (textcolor_ == defcolor_) textcolor_ = c; defcolor_ = c; }
00324   Fl_Color      textcolor() const { return (defcolor_); }
00326   void          textfont(Fl_Font f) { textfont_ = f; format(); }
00328   Fl_Font       textfont() const { return (textfont_); }
00330   void          textsize(Fl_Fontsize s) { textsize_ = s; format(); }
00332   Fl_Fontsize  textsize() const { return (textsize_); }
00334   const char    *title() { return (title_); }
00335   void          topline(const char *n);
00336   void          topline(int);
00338   int           topline() const { return (topline_); }
00339   void          leftline(int);
00341   int           leftline() const { return (leftline_); }
00342   void          value(const char *val);
00344   const char    *value() const { return (value_); }
00345   void          clear_selection();
00346   void          select_all();
00356   int scrollbar_size() const {
00357       return(scrollbar_size_);
00358   }
00378   void scrollbar_size(int newSize) {
00379       scrollbar_size_ = newSize;
00380   }   
00381 };
00382 
00383 #endif // !Fl_Help_View_H
00384 
00385 //
00386 // End of "$Id$".
00387 //