FLTK
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 
194 class FL_EXPORT Fl_Help_View : public Fl_Group { // Help viewer widget
195 
196  enum { RIGHT = -1, CENTER, LEFT };
197 
198  char title_[1024];
199  Fl_Color defcolor_,
200  bgcolor_,
201  textcolor_,
202  linkcolor_;
203  Fl_Font textfont_;
204  Fl_Fontsize textsize_;
205  const char *value_;
206  Fl_Help_Font_Stack fstack_;
207  int nblocks_,
208  ablocks_;
209  Fl_Help_Block *blocks_;
210 
211  Fl_Help_Func *link_;
212 
213  int nlinks_,
214  alinks_;
215  Fl_Help_Link *links_;
216 
217  int ntargets_,
218  atargets_;
219  Fl_Help_Target *targets_;
220 
221  char directory_[FL_PATH_MAX];
222  char filename_[FL_PATH_MAX];
223  int topline_,
224  leftline_,
225  size_,
226  hsize_,
227  scrollbar_size_;
228  Fl_Scrollbar scrollbar_,
229  hscrollbar_;
230 
231  static int selection_first;
232  static int selection_last;
233  static int selection_push_first;
234  static int selection_push_last;
235  static int selection_drag_first;
236  static int selection_drag_last;
237  static int selected;
238  static int draw_mode;
239  static int mouse_x;
240  static int mouse_y;
241  static int current_pos;
242  static Fl_Help_View *current_view;
243  static Fl_Color hv_selection_color;
244  static Fl_Color hv_selection_text_color;
245 
246 
247  void initfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { f = textfont_; s = textsize_; c = textcolor_; fstack_.init(f, s, c); }
248  void pushfont(Fl_Font f, Fl_Fontsize s) {fstack_.push(f, s, textcolor_);}
249  void pushfont(Fl_Font f, Fl_Fontsize s, Fl_Color c) {fstack_.push(f, s, c);}
250  void popfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {fstack_.pop(f, s, c);}
251 
252  Fl_Help_Block *add_block(const char *s, int xx, int yy, int ww, int hh, uchar border = 0);
253  void add_link(const char *n, int xx, int yy, int ww, int hh);
254  void add_target(const char *n, int yy);
255  static int compare_targets(const Fl_Help_Target *t0, const Fl_Help_Target *t1);
256  int do_align(Fl_Help_Block *block, int line, int xx, int a, int &l);
257 protected:
258  void draw();
259 private:
260  void format();
261  void format_table(int *table_width, int *columns, const char *table);
262  void free_data();
263  int get_align(const char *p, int a);
264  const char *get_attr(const char *p, const char *n, char *buf, int bufsize);
265  Fl_Color get_color(const char *n, Fl_Color c);
266  Fl_Shared_Image *get_image(const char *name, int W, int H);
267  int get_length(const char *l);
268 public:
269  int handle(int);
270 private:
271 
272  void hv_draw(const char *t, int x, int y, int entity_extra_length = 0);
273  char begin_selection();
274  char extend_selection();
275  void end_selection(int c=0);
276  void clear_global_selection();
277  Fl_Help_Link *find_link(int, int);
278  void follow_link(Fl_Help_Link*);
279 
280 public:
281 
282  Fl_Help_View(int xx, int yy, int ww, int hh, const char *l = 0);
283  ~Fl_Help_View();
285  const char *directory() const { if (directory_[0]) return (directory_);
286  else return ((const char *)0); }
288  const char *filename() const { if (filename_[0]) return (filename_);
289  else return ((const char *)0); }
290  int find(const char *s, int p = 0);
313  void link(Fl_Help_Func *fn) { link_ = fn; }
314  int load(const char *f);
315  void resize(int,int,int,int);
317  int size() const { return (size_); }
318  void size(int W, int H) { Fl_Widget::size(W, H); }
320  void textcolor(Fl_Color c) { if (textcolor_ == defcolor_) textcolor_ = c; defcolor_ = c; }
322  Fl_Color textcolor() const { return (defcolor_); }
324  void textfont(Fl_Font f) { textfont_ = f; format(); }
326  Fl_Font textfont() const { return (textfont_); }
328  void textsize(Fl_Fontsize s) { textsize_ = s; format(); }
330  Fl_Fontsize textsize() const { return (textsize_); }
332  const char *title() { return (title_); }
333  void topline(const char *n);
334  void topline(int);
336  int topline() const { return (topline_); }
337  void leftline(int);
339  int leftline() const { return (leftline_); }
340  void value(const char *val);
342  const char *value() const { return (value_); }
343  void clear_selection();
344  void select_all();
354  int scrollbar_size() const {
355  return(scrollbar_size_);
356  }
376  void scrollbar_size(int newSize) {
377  scrollbar_size_ = newSize;
378  }
379 };
380 
381 #endif // !Fl_Help_View_H
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:85
int size() const
Gets the size of the help view.
Definition: Fl_Help_View.H:317
Fl_Fontsize textsize() const
Gets the default text size.
Definition: Fl_Help_View.H:330
Fl_Font textfont() const
Returns the current default text font.
Definition: Fl_Help_View.H:326
void scrollbar_size(int newSize)
Sets the pixel size of the scrollbars&#39; troughs to newSize, in pixels.
Definition: Fl_Help_View.H:376
size_t count() const
Gets the current count of font style elements in the stack.
Definition: Fl_Help_View.H:115
int scrollbar_size() const
Gets the current size of the scrollbars&#39; troughs, in pixels.
Definition: Fl_Help_View.H:354
File names and URI utility functions.
void textsize(Fl_Fontsize s)
Sets the default text size.
Definition: Fl_Help_View.H:328
Fl static class.
void textfont(Fl_Font f)
Sets the default text font.
Definition: Fl_Help_View.H:324
void fl_color(Fl_Color c)
Sets the color for all subsequent drawing operations.
Definition: fl_draw.H:49
int topline() const
Returns the current top line in pixels.
Definition: Fl_Help_View.H:336
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:313
void size(int W, int H)
Changes the size of the widget.
Definition: Fl_Widget.H:328
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
Fl_Help_Font_Stack()
font stack construction, initialize attributes.
Definition: Fl_Help_View.H:90
Fl_Color textcolor() const
Returns the current default text color.
Definition: Fl_Help_View.H:322
The Fl_Help_View widget displays HTML text.
Definition: Fl_Help_View.H:194
const char * title()
Returns the current document title, or NULL if there is no title.
Definition: Fl_Help_View.H:332
void textcolor(Fl_Color c)
Sets the default text color.
Definition: Fl_Help_View.H:320
Definition: Fl_Help_View.H:88
Fl_Font f
Font.
Definition: Fl_Help_View.H:76
const char * value() const
Returns the current buffer contents.
Definition: Fl_Help_View.H:342
const char * directory() const
Returns the current directory for the text in the buffer.
Definition: Fl_Help_View.H:285
The Fl_Group class is the FLTK container widget.
Definition: Fl_Group.H:42
size_t nfonts_
current number of fonts in stack
Definition: Fl_Help_View.H:118
Fl_Color c
Font Color.
Definition: Fl_Help_View.H:78
Fl_Help_View font stack element definition.
Definition: Fl_Help_View.H:75
Fl_Help_Target structure.
Definition: Fl_Help_View.H:124
int y
Y offset of target.
Definition: Fl_Help_View.H:126
#define FL_PATH_MAX
all path buffers should use this length
Definition: filename.H:31
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:1014
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
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
Fl_Fontsize s
Font Size.
Definition: Fl_Help_View.H:77
utility header to pull drawing functions together
unsigned int Fl_Color
An FLTK color value; see also Colors.
Definition: Enumerations.H:1042
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:985
This class supports caching, loading, and drawing of image files.
Definition: Fl_Shared_Image.H:49
Definition: Fl_Help_View.H:45
const char * filename() const
Returns the current filename for the text in the buffer.
Definition: Fl_Help_View.H:288
int leftline() const
Gets the left position in pixels.
Definition: Fl_Help_View.H:339
The Fl_Scrollbar widget displays a slider with arrow buttons at the ends of the scrollbar.
Definition: Fl_Scrollbar.H:41
unsigned char uchar
unsigned char
Definition: fl_types.h:28
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