FLTK 1.5.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-2024 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#if FL_ABI_VERSION >= 10401
229 char directory_[2 * FL_PATH_MAX + 15];
230#else
231 char directory_[FL_PATH_MAX];
232#endif
233
234 char filename_[FL_PATH_MAX];
235 int topline_,
236 leftline_,
237 size_,
238 hsize_,
239 scrollbar_size_;
240 Fl_Scrollbar scrollbar_,
241 hscrollbar_;
242
243 static int selection_first_;
244 static int selection_last_;
245 static int selection_push_first_;
246 static int selection_push_last_;
247 static int selection_drag_first_;
248 static int selection_drag_last_;
249 static int selected_;
250 static int draw_mode_;
251 static int mouse_x_;
252 static int mouse_y_;
253 static int current_pos_;
254 static Fl_Help_View *current_view_;
255 static Fl_Color hv_selection_color_;
256 static Fl_Color hv_selection_text_color_;
257
258
259 void initfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { f = textfont_; s = textsize_; c = textcolor_; fstack_.init(f, s, c); }
260 void pushfont(Fl_Font f, Fl_Fontsize s) {fstack_.push(f, s, textcolor_);}
261 void pushfont(Fl_Font f, Fl_Fontsize s, Fl_Color c) {fstack_.push(f, s, c);}
262 void popfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {fstack_.pop(f, s, c);}
263
264 Fl_Help_Block *add_block(const char *s, int xx, int yy, int ww, int hh, uchar border = 0);
265 void add_link(const char *n, int xx, int yy, int ww, int hh);
266 void add_target(const char *n, int yy);
267 static int compare_targets(const Fl_Help_Target *t0, const Fl_Help_Target *t1);
268 int do_align(Fl_Help_Block *block, int line, int xx, int a, int &l);
269protected:
270 void draw() FL_OVERRIDE;
271private:
272 void format();
273 void format_table(int *table_width, int *columns, const char *table);
274 void free_data();
275 int get_align(const char *p, int a);
276 const char *get_attr(const char *p, const char *n, char *buf, int bufsize);
277 Fl_Color get_color(const char *n, Fl_Color c);
278 Fl_Shared_Image *get_image(const char *name, int W, int H);
279 int get_length(const char *l);
280public:
281 int handle(int) FL_OVERRIDE;
282private:
283
284 void hv_draw(const char *t, int x, int y, int entity_extra_length = 0);
285 char begin_selection();
286 char extend_selection();
287 void end_selection(int c=0);
288 void clear_global_selection();
289 Fl_Help_Link *find_link(int, int);
290 void follow_link(Fl_Help_Link*);
291
292public:
293
294 static const char *copy_menu_text;
295
296 Fl_Help_View(int xx, int yy, int ww, int hh, const char *l = 0);
299 const char *directory() const { if (directory_[0]) return (directory_);
300 else return ((const char *)0); }
302 const char *filename() const { if (filename_[0]) return (filename_);
303 else return ((const char *)0); }
304 int find(const char *s, int p = 0);
327 void link(Fl_Help_Func *fn) { link_ = fn; }
328 int load(const char *f);
329 void resize(int,int,int,int) FL_OVERRIDE;
331 int size() const { return (size_); }
332 void size(int W, int H) { Fl_Widget::size(W, H); }
334 void textcolor(Fl_Color c) { if (textcolor_ == defcolor_) textcolor_ = c; defcolor_ = c; }
336 Fl_Color textcolor() const { return (defcolor_); }
338 void textfont(Fl_Font f) { textfont_ = f; format(); }
340 Fl_Font textfont() const { return (textfont_); }
342 void textsize(Fl_Fontsize s) { textsize_ = s; format(); }
344 Fl_Fontsize textsize() const { return (textsize_); }
346 const char *title() { return (title_); }
347 void topline(const char *n);
348 void topline(int);
350 int topline() const { return (topline_); }
351 void leftline(int);
353 int leftline() const { return (leftline_); }
354 void value(const char *val);
356 const char *value() const { return (value_); }
357 void clear_selection();
358 void select_all();
368 int scrollbar_size() const {
369 return(scrollbar_size_);
370 }
390 void scrollbar_size(int newSize) {
391 scrollbar_size_ = newSize;
392 }
393
394 // Check if the user selected text in this view.
395 int text_selected();
396
397 // If text is selected in this view, copy it to a clipboard.
398 int copy(int clipboard=1);
399};
400
401#endif // !Fl_Help_View_H
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:1057
unsigned int Fl_Color
An FLTK color value; see also Colors
Definition Enumerations.H:1114
int Fl_Fontsize
Size of a font in pixels.
Definition Enumerations.H:1086
Fl static class.
Fl_Group and Fl_End classes.
The Fl_Group class is the main FLTK container widget.
Definition Fl_Group.H:59
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:340
void textcolor(Fl_Color c)
Sets the default text color.
Definition Fl_Help_View.H:334
int size() const
Gets the size of the help view.
Definition Fl_Help_View.H:331
const char * filename() const
Returns the current filename for the text in the buffer.
Definition Fl_Help_View.H:302
int scrollbar_size() const
Gets the current size of the scrollbars' troughs, in pixels.
Definition Fl_Help_View.H:368
const char * title()
Returns the current document title, or NULL if there is no title.
Definition Fl_Help_View.H:346
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:327
Fl_Fontsize textsize() const
Gets the default text size.
Definition Fl_Help_View.H:344
const char * value() const
Returns the current buffer contents.
Definition Fl_Help_View.H:356
void scrollbar_size(int newSize)
Sets the pixel size of the scrollbars' troughs to newSize, in pixels.
Definition Fl_Help_View.H:390
static const char * copy_menu_text
[this text may be customized at run-time]
Definition Fl_Help_View.H:294
const char * directory() const
Returns the current directory for the text in the buffer.
Definition Fl_Help_View.H:299
void textsize(Fl_Fontsize s)
Sets the default text size.
Definition Fl_Help_View.H:342
int topline() const
Returns the current top line in pixels.
Definition Fl_Help_View.H:350
void textfont(Fl_Font f)
Sets the default text font.
Definition Fl_Help_View.H:338
Fl_Color textcolor() const
Returns the current default text color.
Definition Fl_Help_View.H:336
int leftline() const
Gets the left position in pixels.
Definition Fl_Help_View.H:353
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:112
void size(int W, int H)
Changes the size of the widget.
Definition Fl_Widget.H:418
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:38
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:811
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