FLTK 1.3.x
|
00001 // 00002 // "$Id: Fl_Help_View.H 8063 2010-12-19 21:20:10Z matt $" 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 { 00062 const char *start, // Start of text 00063 *end; // End of text 00064 uchar border; // Draw border? 00065 Fl_Color bgcolor; // Background color 00066 int x, // Indentation/starting X coordinate 00067 y, // Starting Y coordinate 00068 w, // Width 00069 h; // Height 00070 int line[32]; // Left starting position for each line 00071 }; 00072 00073 // 00074 // Fl_Help_Link structure... 00075 // 00077 struct Fl_Help_Link 00078 { 00079 char filename[192], 00080 name[32]; 00081 int x, 00082 y, 00083 w, 00084 h; 00085 }; 00086 00087 /* 00088 * Fl_Help_View font stack opaque implementation 00089 */ 00090 00092 struct Fl_Help_Font_Style { 00093 Fl_Font f; 00094 Fl_Fontsize s; 00095 Fl_Color c; 00096 void get(Fl_Font &afont, Fl_Fontsize &asize, Fl_Color &acolor) {afont=f; asize=s; acolor=c;} 00097 void set(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {f=afont; s=asize; c=acolor;} 00098 Fl_Help_Font_Style(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {set(afont, asize, acolor);} 00099 Fl_Help_Font_Style(){} // For in table use 00100 }; 00101 00103 const size_t MAX_FL_HELP_FS_ELTS = 100; 00104 00105 struct Fl_Help_Font_Stack { 00107 Fl_Help_Font_Stack() { 00108 nfonts_ = 0; 00109 } 00110 00111 void init(Fl_Font f, Fl_Fontsize s, Fl_Color c) { 00112 nfonts_ = 0; 00113 elts_[nfonts_].set(f, s, c); 00114 fl_font(f, s); 00115 fl_color(c); 00116 } 00118 void top(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { elts_[nfonts_].get(f, s, c); } 00120 void push(Fl_Font f, Fl_Fontsize s, Fl_Color c) { 00121 if (nfonts_ < MAX_FL_HELP_FS_ELTS-1) nfonts_ ++; 00122 elts_[nfonts_].set(f, s, c); 00123 fl_font(f, s); fl_color(c); 00124 } 00126 void pop(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { 00127 if (nfonts_ > 0) nfonts_ --; 00128 top(f, s, c); 00129 fl_font(f, s); fl_color(c); 00130 } 00132 size_t count() const {return nfonts_;} // Gets the current number of fonts in the stack 00133 00134 protected: 00135 size_t nfonts_; 00136 Fl_Help_Font_Style elts_[100]; 00137 }; 00138 00141 struct Fl_Help_Target 00142 { 00143 char name[32]; 00144 int y; 00145 }; 00146 00212 class FL_EXPORT Fl_Help_View : public Fl_Group // Help viewer widget 00213 { 00214 enum { RIGHT = -1, CENTER, LEFT }; 00215 00216 char title_[1024]; 00217 Fl_Color defcolor_, 00218 bgcolor_, 00219 textcolor_, 00220 linkcolor_; 00221 Fl_Font textfont_; 00222 Fl_Fontsize textsize_; 00223 const char *value_; 00224 Fl_Help_Font_Stack fstack_; 00225 int nblocks_, 00226 ablocks_; 00227 Fl_Help_Block *blocks_; 00228 00229 Fl_Help_Func *link_; 00230 00231 int nlinks_, 00232 alinks_; 00233 Fl_Help_Link *links_; 00234 00235 int ntargets_, 00236 atargets_; 00237 Fl_Help_Target *targets_; 00238 00239 char directory_[FL_PATH_MAX]; 00240 char filename_[FL_PATH_MAX]; 00241 int topline_, 00242 leftline_, 00243 size_, 00244 hsize_, 00245 scrollbar_size_; 00246 Fl_Scrollbar scrollbar_, 00247 hscrollbar_; 00248 00249 static int selection_first; 00250 static int selection_last; 00251 static int selection_push_first; 00252 static int selection_push_last; 00253 static int selection_drag_first; 00254 static int selection_drag_last; 00255 static int selected; 00256 static int draw_mode; 00257 static int mouse_x; 00258 static int mouse_y; 00259 static int current_pos; 00260 static Fl_Help_View *current_view; 00261 static Fl_Color hv_selection_color; 00262 static Fl_Color hv_selection_text_color; 00263 00264 00265 void initfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { f = textfont_; s = textsize_; c = textcolor_; fstack_.init(f, s, c); } 00266 void pushfont(Fl_Font f, Fl_Fontsize s) {fstack_.push(f, s, textcolor_);} 00267 void pushfont(Fl_Font f, Fl_Fontsize s, Fl_Color c) {fstack_.push(f, s, c);} 00268 void popfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {fstack_.pop(f, s, c);} 00269 00270 Fl_Help_Block *add_block(const char *s, int xx, int yy, int ww, int hh, uchar border = 0); 00271 void add_link(const char *n, int xx, int yy, int ww, int hh); 00272 void add_target(const char *n, int yy); 00273 static int compare_targets(const Fl_Help_Target *t0, const Fl_Help_Target *t1); 00274 int do_align(Fl_Help_Block *block, int line, int xx, int a, int &l); 00275 void draw(); 00276 void format(); 00277 void format_table(int *table_width, int *columns, const char *table); 00278 void free_data(); 00279 int get_align(const char *p, int a); 00280 const char *get_attr(const char *p, const char *n, char *buf, int bufsize); 00281 Fl_Color get_color(const char *n, Fl_Color c); 00282 Fl_Shared_Image *get_image(const char *name, int W, int H); 00283 int get_length(const char *l); 00284 int handle(int); 00285 00286 void hv_draw(const char *t, int x, int y); 00287 char begin_selection(); 00288 char extend_selection(); 00289 void end_selection(int c=0); 00290 void clear_global_selection(); 00291 Fl_Help_Link *find_link(int, int); 00292 void follow_link(Fl_Help_Link*); 00293 00294 public: 00295 00296 Fl_Help_View(int xx, int yy, int ww, int hh, const char *l = 0); 00297 ~Fl_Help_View(); 00299 const char *directory() const { if (directory_[0]) return (directory_); 00300 else return ((const char *)0); } 00302 const char *filename() const { if (filename_[0]) return (filename_); 00303 else return ((const char *)0); } 00304 int find(const char *s, int p = 0); 00327 void link(Fl_Help_Func *fn) { link_ = fn; } 00328 int load(const char *f); 00329 void resize(int,int,int,int); 00331 int size() const { return (size_); } 00332 void size(int W, int H) { Fl_Widget::size(W, H); } 00334 void textcolor(Fl_Color c) { if (textcolor_ == defcolor_) textcolor_ = c; defcolor_ = c; } 00336 Fl_Color textcolor() const { return (defcolor_); } 00338 void textfont(Fl_Font f) { textfont_ = f; format(); } 00340 Fl_Font textfont() const { return (textfont_); } 00342 void textsize(Fl_Fontsize s) { textsize_ = s; format(); } 00344 Fl_Fontsize textsize() const { return (textsize_); } 00346 const char *title() { return (title_); } 00347 void topline(const char *n); 00348 void topline(int); 00350 int topline() const { return (topline_); } 00351 void leftline(int); 00353 int leftline() const { return (leftline_); } 00354 void value(const char *val); 00356 const char *value() const { return (value_); } 00357 void clear_selection(); 00358 void select_all(); 00368 int scrollbar_size() const { 00369 return(scrollbar_size_); 00370 } 00390 void scrollbar_size(int size) { 00391 scrollbar_size_ = size; 00392 } 00393 }; 00394 00395 #endif // !Fl_Help_View_H 00396 00397 // 00398 // End of "$Id: Fl_Help_View.H 8063 2010-12-19 21:20:10Z matt $". 00399 //