FLTK 1.4.5: Fl_Help_View.H Source File

FLTK 1.4.5

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
46 struct Fl_Help_Block {
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//
64 struct Fl_Help_Link {
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
78 struct FL_EXPORT Fl_Help_Font_Style {
79 Fl_Font f;
80 Fl_Fontsize s;
81 Fl_Color c;
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
91 struct FL_EXPORT Fl_Help_Font_Stack {
93 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); }
106 void push(Fl_Font f, Fl_Fontsize s, Fl_Color 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 }
111
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 }
117
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
126
127 struct Fl_Help_Target {
128 char name[32];
129 int y;
130};
131
201 class 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);
297 ~Fl_Help_View();
299 const char *directory() const { if (directory_[0]) return (directory_);
300 else return ((const char *)0); }
301
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 }
371
390 void scrollbar_size(int newSize) {
391 scrollbar_size_ = newSize;
392 }
393
394 Fl_Scrollbar *scrollbar() { return &scrollbar_; }
396 Fl_Scrollbar *hscrollbar() { return &hscrollbar_; }
397
398 // Check if the user selected text in this view.
399 int text_selected();
400
401 // If text is selected in this view, copy it to a clipboard.
402 int copy(int clipboard=1);
403};
404
405#endif // !Fl_Help_View_H
Fl_Font
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:1063
Fl_Color
unsigned int Fl_Color
An FLTK color value; see also Colors.
Definition Enumerations.H:1120
Fl_Fontsize
int Fl_Fontsize
Size of a font in pixels.
Definition Enumerations.H:1092
Fl.H
Fl static class.
Fl_Group.H
Fl_Group and Fl_End classes.
Fl_Help_View::draw
void draw() FL_OVERRIDE
Draws the Fl_Help_View widget.
Definition Fl_Help_View.cxx:524
Fl_Help_View::textfont
Fl_Font textfont() const
Returns the current default text font.
Definition Fl_Help_View.H:340
Fl_Help_View::textcolor
void textcolor(Fl_Color c)
Sets the default text color.
Definition Fl_Help_View.H:334
Fl_Help_View::size
int size() const
Gets the size of the help view.
Definition Fl_Help_View.H:331
Fl_Help_View::filename
const char * filename() const
Returns the current filename for the text in the buffer.
Definition Fl_Help_View.H:302
Fl_Help_View::scrollbar_size
int scrollbar_size() const
Gets the current size of the scrollbars' troughs, in pixels.
Definition Fl_Help_View.H:368
Fl_Help_View::title
const char * title()
Returns the current document title, or NULL if there is no title.
Definition Fl_Help_View.H:346
Fl_Help_View::link
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_Help_View::textsize
Fl_Fontsize textsize() const
Gets the default text size.
Definition Fl_Help_View.H:344
Fl_Help_View::value
const char * value() const
Returns the current buffer contents.
Definition Fl_Help_View.H:356
Fl_Help_View::handle
int handle(int) FL_OVERRIDE
Handles events in the widget.
Definition Fl_Help_View.cxx:3148
Fl_Help_View::scrollbar_size
void scrollbar_size(int newSize)
Sets the pixel size of the scrollbars' troughs to newSize, in pixels.
Definition Fl_Help_View.H:390
Fl_Help_View::scrollbar
Fl_Scrollbar * scrollbar()
Return pointer to vertical scrollbar.
Definition Fl_Help_View.H:394
Fl_Help_View::copy_menu_text
static const char * copy_menu_text
[this text may be customized at run-time]
Definition Fl_Help_View.H:294
Fl_Help_View::directory
const char * directory() const
Returns the current directory for the text in the buffer.
Definition Fl_Help_View.H:299
Fl_Help_View::textsize
void textsize(Fl_Fontsize s)
Sets the default text size.
Definition Fl_Help_View.H:342
Fl_Help_View::hscrollbar
Fl_Scrollbar * hscrollbar()
Return pointer to horizontal scrollbar.
Definition Fl_Help_View.H:396
Fl_Help_View::topline
int topline() const
Returns the current top line in pixels.
Definition Fl_Help_View.H:350
Fl_Help_View::textfont
void textfont(Fl_Font f)
Sets the default text font.
Definition Fl_Help_View.H:338
Fl_Help_View::textcolor
Fl_Color textcolor() const
Returns the current default text color.
Definition Fl_Help_View.H:336
Fl_Help_View::Fl_Help_View
Fl_Help_View(int xx, int yy, int ww, int hh, const char *l=0)
The constructor creates the Fl_Help_View widget at the specified position and size.
Definition Fl_Help_View.cxx:3249
Fl_Help_View::leftline
int leftline() const
Gets the left position in pixels.
Definition Fl_Help_View.H:353
Fl_Scrollbar
The Fl_Scrollbar widget displays a slider with arrow buttons at the ends of the scrollbar.
Definition Fl_Scrollbar.H:41
Fl_Shared_Image
This class supports caching, loading, and drawing of image files.
Definition Fl_Shared_Image.H:94
Fl_Widget
Fl_Widget is the base class for all widgets in FLTK.
Definition Fl_Widget.H:112
Fl_Widget::x
void x(int v)
Internal use only.
Definition Fl_Widget.H:150
Fl_Widget::size
void size(int W, int H)
Changes the size of the widget.
Definition Fl_Widget.H:418
Fl_Widget::y
void y(int v)
Internal use only.
Definition Fl_Widget.H:152
filename.H
File names and URI utility functions.
FL_OVERRIDE
#define FL_OVERRIDE
This macro makes it safe to use the C++11 keyword override with older compilers.
Definition fl_attr.h:46
fl_draw.H
utility header to pull drawing functions together
uchar
unsigned char uchar
unsigned char
Definition fl_types.h:30
FL_PATH_MAX
#define FL_PATH_MAX
all path buffers should use this length
Definition filename.H:45
fl_font
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 fl_color()
Return the last fl_color() that was set.
Definition fl_draw.H:74
Fl_Help_Block
Definition Fl_Help_View.H:46
Fl_Help_Font_Stack
Definition Fl_Help_View.H:91
Fl_Help_Font_Stack::pop
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
Fl_Help_Font_Stack::nfonts_
size_t nfonts_
current number of fonts in stack
Definition Fl_Help_View.H:121
Fl_Help_Font_Stack::top
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::Fl_Help_Font_Stack
Fl_Help_Font_Stack()
font stack construction, initialize attributes.
Definition Fl_Help_View.H:93
Fl_Help_Font_Stack::elts_
Fl_Help_Font_Style elts_[MAX_FL_HELP_FS_ELTS]
font elements
Definition Fl_Help_View.H:122
Fl_Help_Font_Stack::count
size_t count() const
Gets the current count of font style elements in the stack.
Definition Fl_Help_View.H:118
Fl_Help_Font_Stack::push
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_Font_Style
Fl_Help_View font stack element definition.
Definition Fl_Help_View.H:78
Fl_Help_Font_Style::s
Fl_Fontsize s
Font Size.
Definition Fl_Help_View.H:80
Fl_Help_Font_Style::c
Fl_Color c
Font Color.
Definition Fl_Help_View.H:81
Fl_Help_Font_Style::set
void set(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor)
Sets current font attributes.
Definition Fl_Help_View.H:83
Fl_Help_Font_Style::f
Fl_Font f
Font.
Definition Fl_Help_View.H:79
Fl_Help_Font_Style::get
void get(Fl_Font &afont, Fl_Fontsize &asize, Fl_Color &acolor)
Gets current font attributes.
Definition Fl_Help_View.H:82
Fl_Help_Link
Definition of a link for the html viewer.
Definition Fl_Help_View.H:64
Fl_Help_Link::name
char name[32]
Link target (blank if none).
Definition Fl_Help_View.H:66
Fl_Help_Link::h
int h
Height of link text.
Definition Fl_Help_View.H:70
Fl_Help_Link::filename
char filename[192]
Reference filename.
Definition Fl_Help_View.H:65
Fl_Help_Link::w
int w
Width of link text.
Definition Fl_Help_View.H:69
Fl_Help_Link::y
int y
Y offset of link text.
Definition Fl_Help_View.H:68
Fl_Help_Link::x
int x
X offset of link text.
Definition Fl_Help_View.H:67
Fl_Help_Target
Fl_Help_Target structure.
Definition Fl_Help_View.H:127
Fl_Help_Target::name
char name[32]
Target name.
Definition Fl_Help_View.H:128
Fl_Help_Target::y
int y
Y offset of target.
Definition Fl_Help_View.H:129