FLTK 1.3.0
|
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; you can redistribute it and/or 00010 // modify it under the terms of the GNU Library General Public 00011 // License as published by the Free Software Foundation; either 00012 // version 2 of the License, or (at your option) any later version. 00013 // 00014 // This library is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 // Library General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU Library General Public 00020 // License along with this library; if not, write to the Free Software 00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00022 // USA. 00023 // 00024 // Please report all bugs and problems on the following page: 00025 // 00026 // http://www.fltk.org/str.php 00027 // 00028 00029 /* \file 00030 Fl_Help_View widget . */ 00031 00032 #ifndef Fl_Help_View_H 00033 # define Fl_Help_View_H 00034 00035 // 00036 // Include necessary header files... 00037 // 00038 00039 # include <stdio.h> 00040 # include "Fl.H" 00041 # include "Fl_Group.H" 00042 # include "Fl_Scrollbar.H" 00043 # include "fl_draw.H" 00044 # include "Fl_Shared_Image.H" 00045 # include "filename.H" 00046 00047 00048 // 00049 // Fl_Help_Func type - link callback function for files... 00050 // 00051 00052 00053 typedef const char *(Fl_Help_Func)(Fl_Widget *, const char *); 00054 00055 00056 // 00057 // Fl_Help_Block structure... 00058 // 00059 00060 struct Fl_Help_Block { 00061 const char *start, // Start of text 00062 *end; // End of text 00063 uchar border; // Draw border? 00064 Fl_Color bgcolor; // Background color 00065 int x, // Indentation/starting X coordinate 00066 y, // Starting Y coordinate 00067 w, // Width 00068 h; // Height 00069 int line[32]; // Left starting position for each line 00070 }; 00071 00072 // 00073 // Fl_Help_Link structure... 00074 // 00076 struct Fl_Help_Link { 00077 char filename[192], 00078 name[32]; 00079 int x, 00080 y, 00081 w, 00082 h; 00083 }; 00084 00085 /* 00086 * Fl_Help_View font stack opaque implementation 00087 */ 00088 00090 struct FL_EXPORT Fl_Help_Font_Style { 00091 Fl_Font f; 00092 Fl_Fontsize s; 00093 Fl_Color c; 00094 void get(Fl_Font &afont, Fl_Fontsize &asize, Fl_Color &acolor) {afont=f; asize=s; acolor=c;} 00095 void set(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {f=afont; s=asize; c=acolor;} 00096 Fl_Help_Font_Style(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {set(afont, asize, acolor);} 00097 Fl_Help_Font_Style(){} // For in table use 00098 }; 00099 00101 const size_t MAX_FL_HELP_FS_ELTS = 100; 00102 00103 struct FL_EXPORT Fl_Help_Font_Stack { 00105 Fl_Help_Font_Stack() { 00106 nfonts_ = 0; 00107 } 00108 00109 void init(Fl_Font f, Fl_Fontsize s, Fl_Color c) { 00110 nfonts_ = 0; 00111 elts_[nfonts_].set(f, s, c); 00112 fl_font(f, s); 00113 fl_color(c); 00114 } 00116 void top(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { elts_[nfonts_].get(f, s, c); } 00118 void push(Fl_Font f, Fl_Fontsize s, Fl_Color c) { 00119 if (nfonts_ < MAX_FL_HELP_FS_ELTS-1) nfonts_ ++; 00120 elts_[nfonts_].set(f, s, c); 00121 fl_font(f, s); fl_color(c); 00122 } 00124 void pop(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { 00125 if (nfonts_ > 0) nfonts_ --; 00126 top(f, s, c); 00127 fl_font(f, s); fl_color(c); 00128 } 00130 size_t count() const {return nfonts_;} // Gets the current number of fonts in the stack 00131 00132 protected: 00133 size_t nfonts_; 00134 Fl_Help_Font_Style elts_[100]; 00135 }; 00136 00139 struct Fl_Help_Target { 00140 char name[32]; 00141 int y; 00142 }; 00143 00209 class FL_EXPORT Fl_Help_View : public Fl_Group { // Help viewer widget 00210 00211 enum { RIGHT = -1, CENTER, LEFT }; 00212 00213 char title_[1024]; 00214 Fl_Color defcolor_, 00215 bgcolor_, 00216 textcolor_, 00217 linkcolor_; 00218 Fl_Font textfont_; 00219 Fl_Fontsize textsize_; 00220 const char *value_; 00221 Fl_Help_Font_Stack fstack_; 00222 int nblocks_, 00223 ablocks_; 00224 Fl_Help_Block *blocks_; 00225 00226 Fl_Help_Func *link_; 00227 00228 int nlinks_, 00229 alinks_; 00230 Fl_Help_Link *links_; 00231 00232 int ntargets_, 00233 atargets_; 00234 Fl_Help_Target *targets_; 00235 00236 char directory_[FL_PATH_MAX]; 00237 char filename_[FL_PATH_MAX]; 00238 int topline_, 00239 leftline_, 00240 size_, 00241 hsize_, 00242 scrollbar_size_; 00243 Fl_Scrollbar scrollbar_, 00244 hscrollbar_; 00245 00246 static int selection_first; 00247 static int selection_last; 00248 static int selection_push_first; 00249 static int selection_push_last; 00250 static int selection_drag_first; 00251 static int selection_drag_last; 00252 static int selected; 00253 static int draw_mode; 00254 static int mouse_x; 00255 static int mouse_y; 00256 static int current_pos; 00257 static Fl_Help_View *current_view; 00258 static Fl_Color hv_selection_color; 00259 static Fl_Color hv_selection_text_color; 00260 00261 00262 void initfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { f = textfont_; s = textsize_; c = textcolor_; fstack_.init(f, s, c); } 00263 void pushfont(Fl_Font f, Fl_Fontsize s) {fstack_.push(f, s, textcolor_);} 00264 void pushfont(Fl_Font f, Fl_Fontsize s, Fl_Color c) {fstack_.push(f, s, c);} 00265 void popfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {fstack_.pop(f, s, c);} 00266 00267 Fl_Help_Block *add_block(const char *s, int xx, int yy, int ww, int hh, uchar border = 0); 00268 void add_link(const char *n, int xx, int yy, int ww, int hh); 00269 void add_target(const char *n, int yy); 00270 static int compare_targets(const Fl_Help_Target *t0, const Fl_Help_Target *t1); 00271 int do_align(Fl_Help_Block *block, int line, int xx, int a, int &l); 00272 void draw(); 00273 void format(); 00274 void format_table(int *table_width, int *columns, const char *table); 00275 void free_data(); 00276 int get_align(const char *p, int a); 00277 const char *get_attr(const char *p, const char *n, char *buf, int bufsize); 00278 Fl_Color get_color(const char *n, Fl_Color c); 00279 Fl_Shared_Image *get_image(const char *name, int W, int H); 00280 int get_length(const char *l); 00281 int handle(int); 00282 00283 void hv_draw(const char *t, int x, int y); 00284 char begin_selection(); 00285 char extend_selection(); 00286 void end_selection(int c=0); 00287 void clear_global_selection(); 00288 Fl_Help_Link *find_link(int, int); 00289 void follow_link(Fl_Help_Link*); 00290 00291 public: 00292 00293 Fl_Help_View(int xx, int yy, int ww, int hh, const char *l = 0); 00294 ~Fl_Help_View(); 00296 const char *directory() const { if (directory_[0]) return (directory_); 00297 else return ((const char *)0); } 00299 const char *filename() const { if (filename_[0]) return (filename_); 00300 else return ((const char *)0); } 00301 int find(const char *s, int p = 0); 00324 void link(Fl_Help_Func *fn) { link_ = fn; } 00325 int load(const char *f); 00326 void resize(int,int,int,int); 00328 int size() const { return (size_); } 00329 void size(int W, int H) { Fl_Widget::size(W, H); } 00331 void textcolor(Fl_Color c) { if (textcolor_ == defcolor_) textcolor_ = c; defcolor_ = c; } 00333 Fl_Color textcolor() const { return (defcolor_); } 00335 void textfont(Fl_Font f) { textfont_ = f; format(); } 00337 Fl_Font textfont() const { return (textfont_); } 00339 void textsize(Fl_Fontsize s) { textsize_ = s; format(); } 00341 Fl_Fontsize textsize() const { return (textsize_); } 00343 const char *title() { return (title_); } 00344 void topline(const char *n); 00345 void topline(int); 00347 int topline() const { return (topline_); } 00348 void leftline(int); 00350 int leftline() const { return (leftline_); } 00351 void value(const char *val); 00353 const char *value() const { return (value_); } 00354 void clear_selection(); 00355 void select_all(); 00365 int scrollbar_size() const { 00366 return(scrollbar_size_); 00367 } 00387 void scrollbar_size(int size) { 00388 scrollbar_size_ = size; 00389 } 00390 }; 00391 00392 #endif // !Fl_Help_View_H 00393 00394 // 00395 // End of "$Id$". 00396 //