FLTK 1.4.0
Loading...
Searching...
No Matches
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// Copyright 2011-2022 by Bill Spitzak and others.
7//
8// This library is free software. Distribution and use rights are outlined in
9// the file "COPYING" which should have been included with this file. If this
10// file is missing or damaged, see the license at:
11//
12// https://www.fltk.org/COPYING.php
13//
14// Please see the following page on how to report bugs and issues:
15//
16// https://www.fltk.org/bugs.php
17//
18
19/* \file
20 Fl_Help_View widget . */
21
22#ifndef Fl_Help_View_H
23#define Fl_Help_View_H
24
25//
26// Include necessary header files...
27//
28
29#include "Fl.H"
30#include "Fl_Group.H"
31#include "Fl_Scrollbar.H"
32#include "fl_draw.H"
33#include "filename.H"
34
35class Fl_Shared_Image;
36//
37// Fl_Help_Func type - link callback function for files...
38//
39
40typedef const char *(Fl_Help_Func)(Fl_Widget *, const char *);
41
42//
43// Fl_Help_Block structure...
44//
45
47 const char *start, // Start of text
48 *end; // End of text
49 uchar border; // Draw border?
50 Fl_Color bgcolor; // Background color
51 int x, // Indentation/starting X coordinate
52 y, // Starting Y coordinate
53 w, // Width
54 h; // Height
55 int line[32]; // Left starting position for each line
56 int ol; // is ordered list <OL> element
57 int ol_num; // item number in ordered list
58};
59
60//
61// Fl_Help_Link structure...
62//
65 char filename[192],
66 name[32];
67 int x,
68 y,
69 w,
70 h;
71};
72
73/*
74 * Fl_Help_View font stack opaque implementation
75 */
76
78struct FL_EXPORT Fl_Help_Font_Style {
82 void get(Fl_Font &afont, Fl_Fontsize &asize, Fl_Color &acolor) {afont=f; asize=s; acolor=c;}
83 void set(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {f=afont; s=asize; c=acolor;}
84 Fl_Help_Font_Style(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {set(afont, asize, acolor);}
85 Fl_Help_Font_Style(){} // For in table use
86};
87
89const size_t MAX_FL_HELP_FS_ELTS = 100;
90
91struct FL_EXPORT Fl_Help_Font_Stack {
94 nfonts_ = 0;
95 }
96
97 void init(Fl_Font f, Fl_Fontsize s, Fl_Color c) {
98 nfonts_ = 0;
99 elts_[nfonts_].set(f, s, c);
100 fl_font(f, s);
101 fl_color(c);
102 }
104 void top(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { elts_[nfonts_].get(f, s, c); }
107 if (nfonts_ < MAX_FL_HELP_FS_ELTS-1) nfonts_ ++;
108 elts_[nfonts_].set(f, s, c);
109 fl_font(f, s); fl_color(c);
110 }
112 void pop(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {
113 if (nfonts_ > 0) nfonts_ --;
114 top(f, s, c);
115 fl_font(f, s); fl_color(c);
116 }
118 size_t count() const {return nfonts_;} // Gets the current number of fonts in the stack
119
120protected:
121 size_t nfonts_;
122 Fl_Help_Font_Style elts_[MAX_FL_HELP_FS_ELTS];
123};
124
128 char name[32];
129 int y;
130};
131
201class FL_EXPORT Fl_Help_View : public Fl_Group { // Help viewer widget
202
203 enum { RIGHT = -1, CENTER, LEFT };
204
205 char title_[1024];
206 Fl_Color defcolor_,
207 bgcolor_,
208 textcolor_,
209 linkcolor_;
210 Fl_Font textfont_;
211 Fl_Fontsize textsize_;
212 const char *value_;
213 Fl_Help_Font_Stack fstack_;
214 int nblocks_,
215 ablocks_;
216 Fl_Help_Block *blocks_;
217
218 Fl_Help_Func *link_;
219
220 int nlinks_,
221 alinks_;
222 Fl_Help_Link *links_;
223
224 int ntargets_,
225 atargets_;
226 Fl_Help_Target *targets_;
227
228 char directory_[FL_PATH_MAX];
229 char filename_[FL_PATH_MAX];
230 int topline_,
231 leftline_,
232 size_,
233 hsize_,
234 scrollbar_size_;
235 Fl_Scrollbar scrollbar_,
236 hscrollbar_;
237
238 static int selection_first;
239 static int selection_last;
240 static int selection_push_first;
241 static int selection_push_last;
242 static int selection_drag_first;
243 static int selection_drag_last;
244 static int selected;
245 static int draw_mode;
246 static int mouse_x;
247 static int mouse_y;
248 static int current_pos;
249 static Fl_Help_View *current_view;
250 static Fl_Color hv_selection_color;
251 static Fl_Color hv_selection_text_color;
252
253
254 void initfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { f = textfont_; s = textsize_; c = textcolor_; fstack_.init(f, s, c); }
255 void pushfont(Fl_Font f, Fl_Fontsize s) {fstack_.push(f, s, textcolor_);}
256 void pushfont(Fl_Font f, Fl_Fontsize s, Fl_Color c) {fstack_.push(f, s, c);}
257 void popfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {fstack_.pop(f, s, c);}
258
259 Fl_Help_Block *add_block(const char *s, int xx, int yy, int ww, int hh, uchar border = 0);
260 void add_link(const char *n, int xx, int yy, int ww, int hh);
261 void add_target(const char *n, int yy);
262 static int compare_targets(const Fl_Help_Target *t0, const Fl_Help_Target *t1);
263 int do_align(Fl_Help_Block *block, int line, int xx, int a, int &l);
264protected:
265 void draw() FL_OVERRIDE;
266private:
267 void format();
268 void format_table(int *table_width, int *columns, const char *table);
269 void free_data();
270 int get_align(const char *p, int a);
271 const char *get_attr(const char *p, const char *n, char *buf, int bufsize);
272 Fl_Color get_color(const char *n, Fl_Color c);
273 Fl_Shared_Image *get_image(const char *name, int W, int H);
274 int get_length(const char *l);
275public:
276 int handle(int) FL_OVERRIDE;
277private:
278
279 void hv_draw(const char *t, int x, int y, int entity_extra_length = 0);
280 char begin_selection();
281 char extend_selection();
282 void end_selection(int c=0);
283 void clear_global_selection();
284 Fl_Help_Link *find_link(int, int);
285 void follow_link(Fl_Help_Link*);
286
287public:
288
289 Fl_Help_View(int xx, int yy, int ww, int hh, const char *l = 0);
292 const char *directory() const { if (directory_[0]) return (directory_);
293 else return ((const char *)0); }
295 const char *filename() const { if (filename_[0]) return (filename_);
296 else return ((const char *)0); }
297 int find(const char *s, int p = 0);
320 void link(Fl_Help_Func *fn) { link_ = fn; }
321 int load(const char *f);
322 void resize(int,int,int,int) FL_OVERRIDE;
324 int size() const { return (size_); }
325 void size(int W, int H) { Fl_Widget::size(W, H); }
327 void textcolor(Fl_Color c) { if (textcolor_ == defcolor_) textcolor_ = c; defcolor_ = c; }
329 Fl_Color textcolor() const { return (defcolor_); }
331 void textfont(Fl_Font f) { textfont_ = f; format(); }
333 Fl_Font textfont() const { return (textfont_); }
335 void textsize(Fl_Fontsize s) { textsize_ = s; format(); }
337 Fl_Fontsize textsize() const { return (textsize_); }
339 const char *title() { return (title_); }
340 void topline(const char *n);
341 void topline(int);
343 int topline() const { return (topline_); }
344 void leftline(int);
346 int leftline() const { return (leftline_); }
347 void value(const char *val);
349 const char *value() const { return (value_); }
350 void clear_selection();
351 void select_all();
361 int scrollbar_size() const {
362 return(scrollbar_size_);
363 }
383 void scrollbar_size(int newSize) {
384 scrollbar_size_ = newSize;
385 }
386};
387
388#endif // !Fl_Help_View_H
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:1044
unsigned int Fl_Color
An FLTK color value; see also Colors
Definition Enumerations.H:1101
int Fl_Fontsize
Size of a font in pixels.
Definition Enumerations.H:1073
Fl static class.
Fl_Group and Fl_End classes.
The Fl_Group class is the FLTK container widget.
Definition Fl_Group.H:56
The Fl_Help_View widget displays HTML text.
Definition Fl_Help_View.H:201
Fl_Font textfont() const
Returns the current default text font.
Definition Fl_Help_View.H:333
void textcolor(Fl_Color c)
Sets the default text color.
Definition Fl_Help_View.H:327
int size() const
Gets the size of the help view.
Definition Fl_Help_View.H:324
const char * filename() const
Returns the current filename for the text in the buffer.
Definition Fl_Help_View.H:295
int scrollbar_size() const
Gets the current size of the scrollbars' troughs, in pixels.
Definition Fl_Help_View.H:361
const char * title()
Returns the current document title, or NULL if there is no title.
Definition Fl_Help_View.H:339
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:320
Fl_Fontsize textsize() const
Gets the default text size.
Definition Fl_Help_View.H:337
const char * value() const
Returns the current buffer contents.
Definition Fl_Help_View.H:349
void scrollbar_size(int newSize)
Sets the pixel size of the scrollbars' troughs to newSize, in pixels.
Definition Fl_Help_View.H:383
const char * directory() const
Returns the current directory for the text in the buffer.
Definition Fl_Help_View.H:292
void textsize(Fl_Fontsize s)
Sets the default text size.
Definition Fl_Help_View.H:335
int topline() const
Returns the current top line in pixels.
Definition Fl_Help_View.H:343
void textfont(Fl_Font f)
Sets the default text font.
Definition Fl_Help_View.H:331
Fl_Color textcolor() const
Returns the current default text color.
Definition Fl_Help_View.H:329
int leftline() const
Gets the left position in pixels.
Definition Fl_Help_View.H:346
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:94
Fl_Widget is the base class for all widgets in FLTK.
Definition Fl_Widget.H:104
void size(int W, int H)
Changes the size of the widget.
Definition Fl_Widget.H:410
File names and URI utility functions.
#define FL_OVERRIDE
This macro makes it safe to use the C++11 keyword override with older compilers.
Definition fl_attr.h:46
utility header to pull drawing functions together
unsigned char uchar
unsigned char
Definition fl_types.h:30
#define FL_PATH_MAX
all path buffers should use this length
Definition filename.H:45
Fl_Font fl_font()
Return the face set by the most recent call to fl_font().
Definition fl_draw.H:796
Fl_Color fl_color()
Return the last fl_color() that was set.
Definition fl_draw.H:74
Definition Fl_Help_View.H:46
Definition Fl_Help_View.H:91
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:112
size_t nfonts_
current number of fonts in stack
Definition Fl_Help_View.H:121
void top(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c)
Gets the top (current) element on the stack.
Definition Fl_Help_View.H:104
Fl_Help_Font_Stack()
font stack construction, initialize attributes.
Definition Fl_Help_View.H:93
size_t count() const
Gets the current count of font style elements in the stack.
Definition Fl_Help_View.H:118
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:106
Fl_Help_View font stack element definition.
Definition Fl_Help_View.H:78
Fl_Fontsize s
Font Size.
Definition Fl_Help_View.H:80
Fl_Color c
Font Color.
Definition Fl_Help_View.H:81
void set(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor)
Sets current font attributes.
Definition Fl_Help_View.H:83
Fl_Font f
Font.
Definition Fl_Help_View.H:79
void get(Fl_Font &afont, Fl_Fontsize &asize, Fl_Color &acolor)
Gets current font attributes.
Definition Fl_Help_View.H:82
Fl_Help_Target structure.
Definition Fl_Help_View.H:127
char name[32]
Target name.
Definition Fl_Help_View.H:128
int y
Y offset of target.
Definition Fl_Help_View.H:129