FLTK 1.4.0
Fl_Help_View.H
1 //
2 // Help Viewer widget definitions.
3 //
4 // Copyright 1997-2010 by Easy Software Products.
5 // Image support by Matthias Melcher, Copyright 2000-2009.
6 //
7 // This library is free software. Distribution and use rights are outlined in
8 // the file "COPYING" which should have been included with this file. If this
9 // file is missing or damaged, see the license at:
10 //
11 // https://www.fltk.org/COPYING.php
12 //
13 // Please see the following page on how to report bugs and issues:
14 //
15 // https://www.fltk.org/bugs.php
16 //
17 
18 /* \file
19  Fl_Help_View widget . */
20 
21 #ifndef Fl_Help_View_H
22 #define Fl_Help_View_H
23 
24 //
25 // Include necessary header files...
26 //
27 
28 #include "Fl.H"
29 #include "Fl_Group.H"
30 #include "Fl_Scrollbar.H"
31 #include "fl_draw.H"
32 #include "filename.H"
33 
34 class Fl_Shared_Image;
35 //
36 // Fl_Help_Func type - link callback function for files...
37 //
38 
39 typedef const char *(Fl_Help_Func)(Fl_Widget *, const char *);
40 
41 //
42 // Fl_Help_Block structure...
43 //
44 
45 struct Fl_Help_Block {
46  const char *start, // Start of text
47  *end; // End of text
48  uchar border; // Draw border?
49  Fl_Color bgcolor; // Background color
50  int x, // Indentation/starting X coordinate
51  y, // Starting Y coordinate
52  w, // Width
53  h; // Height
54  int line[32]; // Left starting position for each line
55 };
56 
57 //
58 // Fl_Help_Link structure...
59 //
61 struct Fl_Help_Link {
62  char filename[192],
63  name[32];
64  int x,
65  y,
66  w,
67  h;
68 };
69 
70 /*
71  * Fl_Help_View font stack opaque implementation
72  */
73 
75 struct FL_EXPORT Fl_Help_Font_Style {
79  void get(Fl_Font &afont, Fl_Fontsize &asize, Fl_Color &acolor) {afont=f; asize=s; acolor=c;}
80  void set(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {f=afont; s=asize; c=acolor;}
81  Fl_Help_Font_Style(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {set(afont, asize, acolor);}
82  Fl_Help_Font_Style(){} // For in table use
83 };
84 
86 const size_t MAX_FL_HELP_FS_ELTS = 100;
87 
88 struct FL_EXPORT Fl_Help_Font_Stack {
91  nfonts_ = 0;
92  }
93 
94  void init(Fl_Font f, Fl_Fontsize s, Fl_Color c) {
95  nfonts_ = 0;
96  elts_[nfonts_].set(f, s, c);
97  fl_font(f, s);
98  fl_color(c);
99  }
101  void top(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { elts_[nfonts_].get(f, s, c); }
104  if (nfonts_ < MAX_FL_HELP_FS_ELTS-1) nfonts_ ++;
105  elts_[nfonts_].set(f, s, c);
106  fl_font(f, s); fl_color(c);
107  }
109  void pop(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {
110  if (nfonts_ > 0) nfonts_ --;
111  top(f, s, c);
112  fl_font(f, s); fl_color(c);
113  }
115  size_t count() const {return nfonts_;} // Gets the current number of fonts in the stack
116 
117 protected:
118  size_t nfonts_;
119  Fl_Help_Font_Style elts_[MAX_FL_HELP_FS_ELTS];
120 };
121 
125  char name[32];
126  int y;
127 };
128 
198 class FL_EXPORT Fl_Help_View : public Fl_Group { // Help viewer widget
199 
200  enum { RIGHT = -1, CENTER, LEFT };
201 
202  char title_[1024];
203  Fl_Color defcolor_,
204  bgcolor_,
205  textcolor_,
206  linkcolor_;
207  Fl_Font textfont_;
208  Fl_Fontsize textsize_;
209  const char *value_;
210  Fl_Help_Font_Stack fstack_;
211  int nblocks_,
212  ablocks_;
213  Fl_Help_Block *blocks_;
214 
215  Fl_Help_Func *link_;
216 
217  int nlinks_,
218  alinks_;
219  Fl_Help_Link *links_;
220 
221  int ntargets_,
222  atargets_;
223  Fl_Help_Target *targets_;
224 
225  char directory_[FL_PATH_MAX];
226  char filename_[FL_PATH_MAX];
227  int topline_,
228  leftline_,
229  size_,
230  hsize_,
231  scrollbar_size_;
232  Fl_Scrollbar scrollbar_,
233  hscrollbar_;
234 
235  static int selection_first;
236  static int selection_last;
237  static int selection_push_first;
238  static int selection_push_last;
239  static int selection_drag_first;
240  static int selection_drag_last;
241  static int selected;
242  static int draw_mode;
243  static int mouse_x;
244  static int mouse_y;
245  static int current_pos;
246  static Fl_Help_View *current_view;
247  static Fl_Color hv_selection_color;
248  static Fl_Color hv_selection_text_color;
249 
250 
251  void initfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { f = textfont_; s = textsize_; c = textcolor_; fstack_.init(f, s, c); }
252  void pushfont(Fl_Font f, Fl_Fontsize s) {fstack_.push(f, s, textcolor_);}
253  void pushfont(Fl_Font f, Fl_Fontsize s, Fl_Color c) {fstack_.push(f, s, c);}
254  void popfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {fstack_.pop(f, s, c);}
255 
256  Fl_Help_Block *add_block(const char *s, int xx, int yy, int ww, int hh, uchar border = 0);
257  void add_link(const char *n, int xx, int yy, int ww, int hh);
258  void add_target(const char *n, int yy);
259  static int compare_targets(const Fl_Help_Target *t0, const Fl_Help_Target *t1);
260  int do_align(Fl_Help_Block *block, int line, int xx, int a, int &l);
261 protected:
262  void draw();
263 private:
264  void format();
265  void format_table(int *table_width, int *columns, const char *table);
266  void free_data();
267  int get_align(const char *p, int a);
268  const char *get_attr(const char *p, const char *n, char *buf, int bufsize);
269  Fl_Color get_color(const char *n, Fl_Color c);
270  Fl_Shared_Image *get_image(const char *name, int W, int H);
271  int get_length(const char *l);
272 public:
273  int handle(int);
274 private:
275 
276  void hv_draw(const char *t, int x, int y, int entity_extra_length = 0);
277  char begin_selection();
278  char extend_selection();
279  void end_selection(int c=0);
280  void clear_global_selection();
281  Fl_Help_Link *find_link(int, int);
282  void follow_link(Fl_Help_Link*);
283 
284 public:
285 
286  Fl_Help_View(int xx, int yy, int ww, int hh, const char *l = 0);
287  ~Fl_Help_View();
289  const char *directory() const { if (directory_[0]) return (directory_);
290  else return ((const char *)0); }
292  const char *filename() const { if (filename_[0]) return (filename_);
293  else return ((const char *)0); }
294  int find(const char *s, int p = 0);
317  void link(Fl_Help_Func *fn) { link_ = fn; }
318  int load(const char *f);
319  void resize(int,int,int,int);
321  int size() const { return (size_); }
322  void size(int W, int H) { Fl_Widget::size(W, H); }
324  void textcolor(Fl_Color c) { if (textcolor_ == defcolor_) textcolor_ = c; defcolor_ = c; }
326  Fl_Color textcolor() const { return (defcolor_); }
328  void textfont(Fl_Font f) { textfont_ = f; format(); }
330  Fl_Font textfont() const { return (textfont_); }
332  void textsize(Fl_Fontsize s) { textsize_ = s; format(); }
334  Fl_Fontsize textsize() const { return (textsize_); }
336  const char *title() { return (title_); }
337  void topline(const char *n);
338  void topline(int);
340  int topline() const { return (topline_); }
341  void leftline(int);
343  int leftline() const { return (leftline_); }
344  void value(const char *val);
346  const char *value() const { return (value_); }
347  void clear_selection();
348  void select_all();
358  int scrollbar_size() const {
359  return(scrollbar_size_);
360  }
380  void scrollbar_size(int newSize) {
381  scrollbar_size_ = newSize;
382  }
383 };
384 
385 #endif // !Fl_Help_View_H
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:985
unsigned int Fl_Color
An FLTK color value; see also Colors
Definition: Enumerations.H:1042
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:1014
Fl static class.
The Fl_Group class is the FLTK container widget.
Definition: Fl_Group.H:42
The Fl_Help_View widget displays HTML text.
Definition: Fl_Help_View.H:198
const char * filename() const
Returns the current filename for the text in the buffer.
Definition: Fl_Help_View.H:292
const char * directory() const
Returns the current directory for the text in the buffer.
Definition: Fl_Help_View.H:289
Fl_Font textfont() const
Returns the current default text font.
Definition: Fl_Help_View.H:330
void textcolor(Fl_Color c)
Sets the default text color.
Definition: Fl_Help_View.H:324
int size() const
Gets the size of the help view.
Definition: Fl_Help_View.H:321
const char * value() const
Returns the current buffer contents.
Definition: Fl_Help_View.H:346
int scrollbar_size() const
Gets the current size of the scrollbars' troughs, in pixels.
Definition: Fl_Help_View.H:358
void link(Fl_Help_Func *fn)
This method assigns a callback function to use when a link is followed or a file is loaded (via Fl_He...
Definition: Fl_Help_View.H:317
Fl_Fontsize textsize() const
Gets the default text size.
Definition: Fl_Help_View.H:334
const char * title()
Returns the current document title, or NULL if there is no title.
Definition: Fl_Help_View.H:336
void scrollbar_size(int newSize)
Sets the pixel size of the scrollbars' troughs to newSize, in pixels.
Definition: Fl_Help_View.H:380
void textsize(Fl_Fontsize s)
Sets the default text size.
Definition: Fl_Help_View.H:332
int topline() const
Returns the current top line in pixels.
Definition: Fl_Help_View.H:340
void textfont(Fl_Font f)
Sets the default text font.
Definition: Fl_Help_View.H:328
Fl_Color textcolor() const
Returns the current default text color.
Definition: Fl_Help_View.H:326
int leftline() const
Gets the left position in pixels.
Definition: Fl_Help_View.H:343
The Fl_Scrollbar widget displays a slider with arrow buttons at the ends of the scrollbar.
Definition: Fl_Scrollbar.H:41
This class supports caching, loading, and drawing of image files.
Definition: Fl_Shared_Image.H:93
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:85
void size(int W, int H)
Changes the size of the widget.
Definition: Fl_Widget.H:347
File names and URI utility functions.
utility header to pull drawing functions together
unsigned char uchar
unsigned char
Definition: fl_types.h:28
#define FL_PATH_MAX
all path buffers should use this length
Definition: filename.H:31
void fl_color(Fl_Color c)
Set the color for all subsequent drawing operations.
Definition: fl_draw.H:50
FL_EXPORT void fl_font(Fl_Font face, Fl_Fontsize fsize)
Sets the current font, which is then used in various drawing routines.
Definition: fl_draw.cxx:431
Definition: Fl_Help_View.H:45
Definition: Fl_Help_View.H:88
void pop(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c)
Pops from the stack the font style triplet and calls fl_font() & fl_color() adequately.
Definition: Fl_Help_View.H:109
size_t nfonts_
current number of fonts in stack
Definition: Fl_Help_View.H:118
void top(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c)
Gets the top (current) element on the stack.
Definition: Fl_Help_View.H:101
Fl_Help_Font_Stack()
font stack construction, initialize attributes.
Definition: Fl_Help_View.H:90
size_t count() const
Gets the current count of font style elements in the stack.
Definition: Fl_Help_View.H:115
void push(Fl_Font f, Fl_Fontsize s, Fl_Color c)
Pushes the font style triplet on the stack, also calls fl_font() & fl_color() adequately.
Definition: Fl_Help_View.H:103
Fl_Help_View font stack element definition.
Definition: Fl_Help_View.H:75
Fl_Fontsize s
Font Size.
Definition: Fl_Help_View.H:77
Fl_Color c
Font Color.
Definition: Fl_Help_View.H:78
void set(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor)
Sets current font attributes.
Definition: Fl_Help_View.H:80
Fl_Font f
Font.
Definition: Fl_Help_View.H:76
void get(Fl_Font &afont, Fl_Fontsize &asize, Fl_Color &acolor)
Gets current font attributes.
Definition: Fl_Help_View.H:79
Fl_Help_Target structure.
Definition: Fl_Help_View.H:124
char name[32]
Target name.
Definition: Fl_Help_View.H:125
int y
Y offset of target.
Definition: Fl_Help_View.H:126