NTK 1.3.0
Fl_Help_View.H
1//
2// "$Id: Fl_Help_View.H 8306 2011-01-24 17:04:22Z matt $"
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; you can redistribute it and/or
10// modify it under the terms of the GNU Library General Public
11// License as published by the Free Software Foundation; either
12// version 2 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Library General Public License for more details.
18//
19// You should have received a copy of the GNU Library General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22// USA.
23//
24// Please report all bugs and problems on the following page:
25//
26// http://www.fltk.org/str.php
27//
28
29/* \file
30 Fl_Help_View widget . */
31
32#ifndef Fl_Help_View_H
33# define Fl_Help_View_H
34
35//
36// Include necessary header files...
37//
38
39# include <stdio.h>
40# include "Fl.H"
41# include "Fl_Group.H"
42# include "Fl_Scrollbar.H"
43# include "fl_draw.H"
44# include "Fl_Shared_Image.H"
45# include "filename.H"
46
47
48//
49// Fl_Help_Func type - link callback function for files...
50//
51
52
53typedef const char *(Fl_Help_Func)(Fl_Widget *, const char *);
54
55
56//
57// Fl_Help_Block structure...
58//
59
61 const char *start, // Start of text
62 *end; // End of text
63 uchar border; // Draw border?
64 Fl_Color bgcolor; // Background color
65 int x, // Indentation/starting X coordinate
66 y, // Starting Y coordinate
67 w, // Width
68 h; // Height
69 int line[32]; // Left starting position for each line
70};
71
72//
73// Fl_Help_Link structure...
74//
77 char filename[192],
78 name[32];
79 int x,
80 y,
81 w,
82 h;
83};
84
85/*
86 * Fl_Help_View font stack opaque implementation
87 */
88
90struct FL_EXPORT Fl_Help_Font_Style {
94 void get(Fl_Font &afont, Fl_Fontsize &asize, Fl_Color &acolor) {afont=f; asize=s; acolor=c;}
95 void set(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {f=afont; s=asize; c=acolor;}
96 Fl_Help_Font_Style(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {set(afont, asize, acolor);}
97 Fl_Help_Font_Style(){} // For in table use
98};
99
101const size_t MAX_FL_HELP_FS_ELTS = 100;
102
103struct FL_EXPORT Fl_Help_Font_Stack {
106 nfonts_ = 0;
107 }
108
109 void init(Fl_Font f, Fl_Fontsize s, Fl_Color c) {
110 nfonts_ = 0;
111 elts_[nfonts_].set(f, s, c);
112 fl_font(f, s);
113 fl_color(c);
114 }
116 void top(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { elts_[nfonts_].get(f, s, c); }
119 if (nfonts_ < MAX_FL_HELP_FS_ELTS-1) nfonts_ ++;
120 elts_[nfonts_].set(f, s, c);
121 fl_font(f, s); fl_color(c);
122 }
123
124 void pop(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {
125 if (nfonts_ > 0) nfonts_ --;
126 top(f, s, c);
127 fl_font(f, s); fl_color(c);
128 }
129
130 size_t count() const {return nfonts_;} // Gets the current number of fonts in the stack
131
132protected:
133 size_t nfonts_;
135};
136
138
140 char name[32];
141 int y;
142};
143
209class FL_EXPORT Fl_Help_View : public Fl_Group { // Help viewer widget
210
211 enum { RIGHT = -1, CENTER, LEFT };
212
213 char title_[1024];
214 Fl_Color defcolor_,
215 bgcolor_,
216 textcolor_,
217 linkcolor_;
218 Fl_Font textfont_;
219 Fl_Fontsize textsize_;
220 const char *value_;
221 Fl_Help_Font_Stack fstack_;
222 int nblocks_,
223 ablocks_;
224 Fl_Help_Block *blocks_;
225
226 Fl_Help_Func *link_;
227
228 int nlinks_,
229 alinks_;
230 Fl_Help_Link *links_;
231
232 int ntargets_,
233 atargets_;
234 Fl_Help_Target *targets_;
235
236 char directory_[FL_PATH_MAX];
237 char filename_[FL_PATH_MAX];
238 int topline_,
239 leftline_,
240 size_,
241 hsize_,
242 scrollbar_size_;
243 Fl_Scrollbar scrollbar_,
244 hscrollbar_;
245
246 static int selection_first;
247 static int selection_last;
248 static int selection_push_first;
249 static int selection_push_last;
250 static int selection_drag_first;
251 static int selection_drag_last;
252 static int selected;
253 static int draw_mode;
254 static int mouse_x;
255 static int mouse_y;
256 static int current_pos;
257 static Fl_Help_View *current_view;
258 static Fl_Color hv_selection_color;
259 static Fl_Color hv_selection_text_color;
260
261
262 void initfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { f = textfont_; s = textsize_; c = textcolor_; fstack_.init(f, s, c); }
263 void pushfont(Fl_Font f, Fl_Fontsize s) {fstack_.push(f, s, textcolor_);}
264 void pushfont(Fl_Font f, Fl_Fontsize s, Fl_Color c) {fstack_.push(f, s, c);}
265 void popfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {fstack_.pop(f, s, c);}
266
267 Fl_Help_Block *add_block(const char *s, int xx, int yy, int ww, int hh, uchar border = 0);
268 void add_link(const char *n, int xx, int yy, int ww, int hh);
269 void add_target(const char *n, int yy);
270 static int compare_targets(const Fl_Help_Target *t0, const Fl_Help_Target *t1);
271 int do_align(Fl_Help_Block *block, int line, int xx, int a, int &l);
272 void draw();
273 void format();
274 void format_table(int *table_width, int *columns, const char *table);
275 void free_data();
276 int get_align(const char *p, int a);
277 const char *get_attr(const char *p, const char *n, char *buf, int bufsize);
278 Fl_Color get_color(const char *n, Fl_Color c);
279 Fl_Shared_Image *get_image(const char *name, int W, int H);
280 int get_length(const char *l);
281 int handle(int);
282
283 void hv_draw(const char *t, int x, int y);
284 char begin_selection();
285 char extend_selection();
286 void end_selection(int c=0);
287 void clear_global_selection();
288 Fl_Help_Link *find_link(int, int);
289 void follow_link(Fl_Help_Link*);
290
291public:
292
293 Fl_Help_View(int xx, int yy, int ww, int hh, const char *l = 0);
296 const char *directory() const { if (directory_[0]) return (directory_);
297 else return ((const char *)0); }
298
299 const char *filename() const { if (filename_[0]) return (filename_);
300 else return ((const char *)0); }
301 int find(const char *s, int p = 0);
324 void link(Fl_Help_Func *fn) { link_ = fn; }
325 int load(const char *f);
326 void resize(int,int,int,int);
328 int size() const { return (size_); }
329 void size(int W, int H) { Fl_Widget::size(W, H); }
331 void textcolor(Fl_Color c) { if (textcolor_ == defcolor_) textcolor_ = c; defcolor_ = c; }
333 Fl_Color textcolor() const { return (defcolor_); }
335 void textfont(Fl_Font f) { textfont_ = f; format(); }
337 Fl_Font textfont() const { return (textfont_); }
339 void textsize(Fl_Fontsize s) { textsize_ = s; format(); }
341 Fl_Fontsize textsize() const { return (textsize_); }
343 const char *title() { return (title_); }
344 void topline(const char *n);
345 void topline(int);
347 int topline() const { return (topline_); }
348 void leftline(int);
350 int leftline() const { return (leftline_); }
351 void value(const char *val);
353 const char *value() const { return (value_); }
354 void clear_selection();
355 void select_all();
365 int scrollbar_size() const {
366 return(scrollbar_size_);
367 }
368
388 scrollbar_size_ = size;
389 }
390};
391
392#endif // !Fl_Help_View_H
393
394//
395// End of "$Id: Fl_Help_View.H 8306 2011-01-24 17:04:22Z matt $".
396//
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:707
unsigned int Fl_Color
an FLTK color value
Definition Enumerations.H:764
int Fl_Fontsize
Size of a font in pixels.
Definition Enumerations.H:736
Fl static class.
Fl_Shared_Image class.
Fl_Font textfont() const
Returns the current default text font.
Definition Fl_Help_View.H:337
void textcolor(Fl_Color c)
Sets the default text color.
Definition Fl_Help_View.H:331
int size() const
Gets the size of the help view.
Definition Fl_Help_View.H:328
const char * filename() const
Returns the current filename for the text in the buffer.
Definition Fl_Help_View.H:299
int scrollbar_size() const
Gets the current size of the scrollbars' troughs, in pixels.
Definition Fl_Help_View.H:365
const char * title()
Returns the current document title, or NULL if there is no title.
Definition Fl_Help_View.H:343
void scrollbar_size(int size)
Sets the pixel size of the scrollbars' troughs to the size, in pixels.
Definition Fl_Help_View.H:387
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:324
Fl_Fontsize textsize() const
Gets the default text size.
Definition Fl_Help_View.H:341
const char * value() const
Returns the current buffer contents.
Definition Fl_Help_View.H:353
const char * directory() const
Returns the current directory for the text in the buffer.
Definition Fl_Help_View.H:296
void textsize(Fl_Fontsize s)
Sets the default text size.
Definition Fl_Help_View.H:339
int topline() const
Returns the current top line in pixels.
Definition Fl_Help_View.H:347
void textfont(Fl_Font f)
Sets the default text font.
Definition Fl_Help_View.H:335
Fl_Color textcolor() const
Returns the current default text color.
Definition Fl_Help_View.H:333
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:3032
int leftline() const
Gets the left position in pixels.
Definition Fl_Help_View.H:350
The Fl_Scrollbar widget displays a slider with arrow buttons at the ends of the scrollbar.
Definition Fl_Scrollbar.H:52
This class supports caching, loading, and drawing of image files.
Definition Fl_Shared_Image.H:49
Fl_Widget is the base class for all widgets in FLTK.
Definition Fl_Widget.H:111
void x(int v)
Internal use only.
Definition Fl_Widget.H:150
void size(int W, int H)
Changes the size of the widget.
Definition Fl_Widget.H:340
void y(int v)
Internal use only.
Definition Fl_Widget.H:152
utility header to pull drawing functions together
unsigned char uchar
unsigned char
Definition fl_types.h:39
#define FL_PATH_MAX
all path buffers should use this length
Definition filename.H:44
Fl_Font fl_font()
Returns the face set by the most recent call to fl_font().
Definition fl_draw.H:508
Fl_Color fl_color()
Returns the last fl_color() that was set.
Definition fl_draw.H:79
Definition Fl_Help_View.H:60
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:124
size_t nfonts_
current number of fonts in stack
Definition Fl_Help_View.H:133
void top(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c)
Gets the top (current) element on the stack.
Definition Fl_Help_View.H:116
Fl_Help_Font_Style elts_[100]
font elements
Definition Fl_Help_View.H:134
Fl_Help_Font_Stack()
font stack construction, initialize attributes.
Definition Fl_Help_View.H:105
size_t count() const
Gets the current count of font style elements in the stack.
Definition Fl_Help_View.H:130
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:118
Fl_Help_View font stack element definition.
Definition Fl_Help_View.H:90
Fl_Fontsize s
Font Size.
Definition Fl_Help_View.H:92
Fl_Color c
Font Color.
Definition Fl_Help_View.H:93
void set(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor)
Sets current font attributes.
Definition Fl_Help_View.H:95
Fl_Font f
Font.
Definition Fl_Help_View.H:91
void get(Fl_Font &afont, Fl_Fontsize &asize, Fl_Color &acolor)
Gets current font attributes.
Definition Fl_Help_View.H:94
Fl_Help_Target structure.
Definition Fl_Help_View.H:139
char name[32]
Target name.
Definition Fl_Help_View.H:140
int y
Y offset of target.
Definition Fl_Help_View.H:141