FLTK 1.3.9: Fl_Help_View.H Source File

FLTK 1.3.9

Loading...
Searching...
No Matches
Fl_Help_View.H
1//
2// "$Id$"
3//
4// Help Viewer widget definitions.
5//
6// Copyright 1997-2010 by Easy Software Products.
7// Image support by Matthias Melcher, Copyright 2000-2009.
8//
9// This library is free software. Distribution and use rights are outlined in
10// the file "COPYING" which should have been included with this file. If this
11// file is missing or damaged, see the license at:
12//
13// http://www.fltk.org/COPYING.php
14//
15// Please report all bugs and problems on the following page:
16//
17// http://www.fltk.org/str.php
18//
19
20/* \file
21 Fl_Help_View widget . */
22
23#ifndef Fl_Help_View_H
24# define Fl_Help_View_H
25
26//
27// Include necessary header files...
28//
29
30# include <stdio.h>
31# include "Fl.H"
32# include "Fl_Group.H"
33# include "Fl_Scrollbar.H"
34# include "fl_draw.H"
35# include "Fl_Shared_Image.H"
36# include "filename.H"
37
38
39//
40// Fl_Help_Func type - link callback function for files...
41//
42
43
44typedef const char *(Fl_Help_Func)(Fl_Widget *, const char *);
45
46
47//
48// Fl_Help_Block structure...
49//
50
51 struct Fl_Help_Block {
52 const char *start, // Start of text
53 *end; // End of text
54 uchar border; // Draw border?
55 Fl_Color bgcolor; // Background color
56 int x, // Indentation/starting X coordinate
57 y, // Starting Y coordinate
58 w, // Width
59 h; // Height
60 int line[32]; // Left starting position for each line
61};
62
63//
64// Fl_Help_Link structure...
65//
67 struct Fl_Help_Link {
68 char filename[192],
69 name[32];
70 int x,
71 y,
72 w,
73 h;
74};
75
76/*
77 * Fl_Help_View font stack opaque implementation
78 */
79
81 struct FL_EXPORT Fl_Help_Font_Style {
82 Fl_Font f;
83 Fl_Fontsize s;
84 Fl_Color c;
85 void get(Fl_Font &afont, Fl_Fontsize &asize, Fl_Color &acolor) {afont=f; asize=s; acolor=c;}
86 void set(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {f=afont; s=asize; c=acolor;}
87 Fl_Help_Font_Style(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {set(afont, asize, acolor);}
88 Fl_Help_Font_Style(){} // For in table use
89};
90
92const size_t MAX_FL_HELP_FS_ELTS = 100;
93
94 struct FL_EXPORT Fl_Help_Font_Stack {
96 Fl_Help_Font_Stack() {
97 nfonts_ = 0;
98 }
99
100 void init(Fl_Font f, Fl_Fontsize s, Fl_Color c) {
101 nfonts_ = 0;
102 elts_[nfonts_].set(f, s, c);
103 fl_font(f, s);
104 fl_color(c);
105 }
107 void top(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { elts_[nfonts_].get(f, s, c); }
109 void push(Fl_Font f, Fl_Fontsize s, Fl_Color c) {
110 if (nfonts_ < MAX_FL_HELP_FS_ELTS-1) nfonts_ ++;
111 elts_[nfonts_].set(f, s, c);
112 fl_font(f, s); fl_color(c);
113 }
115 void pop(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {
116 if (nfonts_ > 0) nfonts_ --;
117 top(f, s, c);
118 fl_font(f, s); fl_color(c);
119 }
121 size_t count() const {return nfonts_;} // Gets the current number of fonts in the stack
122
123protected:
124 size_t nfonts_;
125 Fl_Help_Font_Style elts_[100];
126};
127
130 struct Fl_Help_Target {
131 char name[32];
132 int y;
133};
134
200 class FL_EXPORT Fl_Help_View : public Fl_Group { // Help viewer widget
201
202 enum { RIGHT = -1, CENTER, LEFT };
203
204 char title_[1024];
205 Fl_Color defcolor_,
206 bgcolor_,
207 textcolor_,
208 linkcolor_;
209 Fl_Font textfont_;
210 Fl_Fontsize textsize_;
211 const char *value_;
212 Fl_Help_Font_Stack fstack_;
213 int nblocks_,
214 ablocks_;
215 Fl_Help_Block *blocks_;
216
217 Fl_Help_Func *link_;
218
219 int nlinks_,
220 alinks_;
221 Fl_Help_Link *links_;
222
223 int ntargets_,
224 atargets_;
225 Fl_Help_Target *targets_;
226
227 char directory_[FL_PATH_MAX];
228 char filename_[FL_PATH_MAX];
229 int topline_,
230 leftline_,
231 size_,
232 hsize_,
233 scrollbar_size_;
234 Fl_Scrollbar scrollbar_,
235 hscrollbar_;
236
237 static int selection_first;
238 static int selection_last;
239 static int selection_push_first;
240 static int selection_push_last;
241 static int selection_drag_first;
242 static int selection_drag_last;
243 static int selected;
244 static int draw_mode;
245 static int mouse_x;
246 static int mouse_y;
247 static int current_pos;
248 static Fl_Help_View *current_view;
249 static Fl_Color hv_selection_color;
250 static Fl_Color hv_selection_text_color;
251
252
253 void initfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { f = textfont_; s = textsize_; c = textcolor_; fstack_.init(f, s, c); }
254 void pushfont(Fl_Font f, Fl_Fontsize s) {fstack_.push(f, s, textcolor_);}
255 void pushfont(Fl_Font f, Fl_Fontsize s, Fl_Color c) {fstack_.push(f, s, c);}
256 void popfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {fstack_.pop(f, s, c);}
257
258 Fl_Help_Block *add_block(const char *s, int xx, int yy, int ww, int hh, uchar border = 0);
259 void add_link(const char *n, int xx, int yy, int ww, int hh);
260 void add_target(const char *n, int yy);
261 static int compare_targets(const Fl_Help_Target *t0, const Fl_Help_Target *t1);
262 int do_align(Fl_Help_Block *block, int line, int xx, int a, int &l);
263#if FLTK_ABI_VERSION >= 10303
264protected:
265#endif
266 void draw();
267#if FLTK_ABI_VERSION >= 10303
268private:
269#endif
270 void format();
271 void format_table(int *table_width, int *columns, const char *table);
272 void free_data();
273 int get_align(const char *p, int a);
274 const char *get_attr(const char *p, const char *n, char *buf, int bufsize);
275 Fl_Color get_color(const char *n, Fl_Color c);
276 Fl_Shared_Image *get_image(const char *name, int W, int H);
277 int get_length(const char *l);
278#if FLTK_ABI_VERSION >= 10303
279public:
280#endif
281 int handle(int);
282#if FLTK_ABI_VERSION >= 10303
283private:
284#endif
285
286 void hv_draw(const char *t, int x, int y, int entity_extra_length = 0);
287 char begin_selection();
288 char extend_selection();
289 void end_selection(int c=0);
290 void clear_global_selection();
291 Fl_Help_Link *find_link(int, int);
292 void follow_link(Fl_Help_Link*);
293
294public:
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); }
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);
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
395#endif // !Fl_Help_View_H
396
397//
398// End of "$Id$".
399//
Fl_Font
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:875
Fl_Color
unsigned int Fl_Color
An FLTK color value; see also Colors
Definition: Enumerations.H:932
Fl_Fontsize
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:904
Fl.H
Fl static class.
Fl_Shared_Image.H
Fl_Shared_Image class.
Fl_Group
The Fl_Group class is the FLTK container widget.
Definition: Fl_Group.H:41
Fl_Help_View
The Fl_Help_View widget displays HTML text.
Definition: Fl_Help_View.H:200
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::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::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::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::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:43
Fl_Shared_Image
This class supports caching, loading, scaling, and drawing of image files.
Definition: Fl_Shared_Image.H:50
Fl_Widget
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:101
Fl_Widget::size
void size(int W, int H)
Changes the size of the widget.
Definition: Fl_Widget.H:341
filename.H
File names and URI utility functions.
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:38
fl_font
Fl_Font fl_font()
Returns the face set by the most recent call to fl_font().
Definition: fl_draw.H:515
fl_color
Fl_Color fl_color()
Returns the last fl_color() that was set.
Definition: fl_draw.H:70
Fl_Help_Block
Definition: Fl_Help_View.H:51
Fl_Help_Font_Stack
Definition: Fl_Help_View.H:94
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:115
Fl_Help_Font_Stack::nfonts_
size_t nfonts_
current number of fonts in stack
Definition: Fl_Help_View.H:124
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:107
Fl_Help_Font_Stack::Fl_Help_Font_Stack
Fl_Help_Font_Stack()
font stack construction, initialize attributes.
Definition: Fl_Help_View.H:96
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:121
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:109
Fl_Help_Font_Style
Fl_Help_View font stack element definition.
Definition: Fl_Help_View.H:81
Fl_Help_Font_Style::s
Fl_Fontsize s
Font Size.
Definition: Fl_Help_View.H:83
Fl_Help_Font_Style::c
Fl_Color c
Font Color.
Definition: Fl_Help_View.H:84
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:86
Fl_Help_Font_Style::f
Fl_Font f
Font.
Definition: Fl_Help_View.H:82
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:85
Fl_Help_Link
Definition of a link for the html viewer.
Definition: Fl_Help_View.H:67
Fl_Help_Link::name
char name[32]
Link target (blank if none)
Definition: Fl_Help_View.H:69
Fl_Help_Link::h
int h
Height of link text.
Definition: Fl_Help_View.H:73
Fl_Help_Link::filename
char filename[192]
Reference filename.
Definition: Fl_Help_View.H:68
Fl_Help_Link::w
int w
Width of link text.
Definition: Fl_Help_View.H:72
Fl_Help_Link::y
int y
Y offset of link text.
Definition: Fl_Help_View.H:71
Fl_Help_Link::x
int x
X offset of link text.
Definition: Fl_Help_View.H:70
Fl_Help_Target
Fl_Help_Target structure.
Definition: Fl_Help_View.H:130
Fl_Help_Target::name
char name[32]
Target name.
Definition: Fl_Help_View.H:131
Fl_Help_Target::y
int y
Y offset of target.
Definition: Fl_Help_View.H:132