FLTK 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 
53 typedef const char *(Fl_Help_Func)(Fl_Widget *, const char *);
54 
55 
56 //
57 // Fl_Help_Block structure...
58 //
59 
60 struct Fl_Help_Block {
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 //
76 struct Fl_Help_Link {
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 
90 struct 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 
101 const size_t MAX_FL_HELP_FS_ELTS = 100;
102 
103 struct 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); }
118  void push(Fl_Font f, Fl_Fontsize s, Fl_Color 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  }
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  }
130  size_t count() const {return nfonts_;} // Gets the current number of fonts in the stack
131 
132 protected:
133  size_t nfonts_;
134  Fl_Help_Font_Style elts_[100];
135 };
136 
140  char name[32];
141  int y;
142 };
143 
209 class 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 
291 public:
292 
293  Fl_Help_View(int xx, int yy, int ww, int hh, const char *l = 0);
294  ~Fl_Help_View();
296  const char *directory() const { if (directory_[0]) return (directory_);
297  else return ((const char *)0); }
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  }
387  void scrollbar_size(int size) {
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 //