Fl_Help_View.H
//
// "$Id: Fl_Help_View.H 9126 2011-10-04 13:10:55Z manolo $"
//
// Help Viewer widget definitions.
//
// Copyright 1997-2010 by Easy Software Products.
// Image support by Matthias Melcher, Copyright 2000-2009.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// http://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
/* \file
Fl_Help_View widget . */
#ifndef Fl_Help_View_H
# define Fl_Help_View_H
//
// Include necessary header files...
//
# include <stdio.h>
# include "Fl.H"
# include "Fl_Group.H"
# include "Fl_Scrollbar.H"
# include "fl_draw.H"
# include "Fl_Shared_Image.H"
# include "filename.H"
//
// Fl_Help_Func type - link callback function for files...
//
typedef const char *(Fl_Help_Func)(Fl_Widget *, const char *);
//
// Fl_Help_Block structure...
//
struct Fl_Help_Block {
const char *start, // Start of text
*end; // End of text
uchar border; // Draw border?
Fl_Color bgcolor; // Background color
int x, // Indentation/starting X coordinate
y, // Starting Y coordinate
w, // Width
h; // Height
int line[32]; // Left starting position for each line
};
//
// Fl_Help_Link structure...
//
struct Fl_Help_Link {
char filename[192],
name[32];
int x,
y,
w,
h;
};
/*
* Fl_Help_View font stack opaque implementation
*/
struct FL_EXPORT Fl_Help_Font_Style {
Fl_Font f;
Fl_Fontsize s;
Fl_Color c;
void get(Fl_Font &afont, Fl_Fontsize &asize, Fl_Color &acolor) {afont=f; asize=s; acolor=c;}
void set(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {f=afont; s=asize; c=acolor;}
Fl_Help_Font_Style(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {set(afont, asize, acolor);}
Fl_Help_Font_Style(){} // For in table use
};
const size_t MAX_FL_HELP_FS_ELTS = 100;
struct FL_EXPORT Fl_Help_Font_Stack {
Fl_Help_Font_Stack() {
nfonts_ = 0;
}
void init(Fl_Font f, Fl_Fontsize s, Fl_Color c) {
nfonts_ = 0;
elts_[nfonts_].set(f, s, c);
fl_font(f, s);
fl_color(c);
}
void top(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { elts_[nfonts_].get(f, s, c); }
void push(Fl_Font f, Fl_Fontsize s, Fl_Color c) {
if (nfonts_ < MAX_FL_HELP_FS_ELTS-1) nfonts_ ++;
elts_[nfonts_].set(f, s, c);
fl_font(f, s); fl_color(c);
}
void pop(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {
if (nfonts_ > 0) nfonts_ --;
top(f, s, c);
fl_font(f, s); fl_color(c);
}
size_t count() const {return nfonts_;} // Gets the current number of fonts in the stack
protected:
size_t nfonts_;
Fl_Help_Font_Style elts_[100];
};
struct Fl_Help_Target {
char name[32];
int y;
};
class FL_EXPORT Fl_Help_View : public Fl_Group { // Help viewer widget
enum { RIGHT = -1, CENTER, LEFT };
char title_[1024];
Fl_Color defcolor_,
bgcolor_,
textcolor_,
linkcolor_;
Fl_Font textfont_;
Fl_Fontsize textsize_;
const char *value_;
Fl_Help_Font_Stack fstack_;
int nblocks_,
ablocks_;
Fl_Help_Block *blocks_;
Fl_Help_Func *link_;
int nlinks_,
alinks_;
Fl_Help_Link *links_;
int ntargets_,
atargets_;
Fl_Help_Target *targets_;
char directory_[FL_PATH_MAX];
char filename_[FL_PATH_MAX];
int topline_,
leftline_,
size_,
hsize_,
scrollbar_size_;
Fl_Scrollbar scrollbar_,
hscrollbar_;
static int selection_first;
static int selection_last;
static int selection_push_first;
static int selection_push_last;
static int selection_drag_first;
static int selection_drag_last;
static int selected;
static int draw_mode;
static int mouse_x;
static int mouse_y;
static int current_pos;
static Fl_Help_View *current_view;
static Fl_Color hv_selection_color;
static Fl_Color hv_selection_text_color;
void initfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { f = textfont_; s = textsize_; c = textcolor_; fstack_.init(f, s, c); }
void pushfont(Fl_Font f, Fl_Fontsize s) {fstack_.push(f, s, textcolor_);}
void pushfont(Fl_Font f, Fl_Fontsize s, Fl_Color c) {fstack_.push(f, s, c);}
void popfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {fstack_.pop(f, s, c);}
Fl_Help_Block *add_block(const char *s, int xx, int yy, int ww, int hh, uchar border = 0);
void add_link(const char *n, int xx, int yy, int ww, int hh);
void add_target(const char *n, int yy);
static int compare_targets(const Fl_Help_Target *t0, const Fl_Help_Target *t1);
int do_align(Fl_Help_Block *block, int line, int xx, int a, int &l);
void draw();
void format();
void format_table(int *table_width, int *columns, const char *table);
void free_data();
int get_align(const char *p, int a);
const char *get_attr(const char *p, const char *n, char *buf, int bufsize);
Fl_Color get_color(const char *n, Fl_Color c);
Fl_Shared_Image *get_image(const char *name, int W, int H);
int get_length(const char *l);
int handle(int);
void hv_draw(const char *t, int x, int y);
char begin_selection();
char extend_selection();
void end_selection(int c=0);
void clear_global_selection();
Fl_Help_Link *find_link(int, int);
void follow_link(Fl_Help_Link*);
public:
Fl_Help_View(int xx, int yy, int ww, int hh, const char *l = 0);
~Fl_Help_View();
const char *directory() const { if (directory_[0]) return (directory_);
else return ((const char *)0); }
const char *filename() const { if (filename_[0]) return (filename_);
else return ((const char *)0); }
int find(const char *s, int p = 0);
void link(Fl_Help_Func *fn) { link_ = fn; }
int load(const char *f);
void resize(int,int,int,int);
int size() const { return (size_); }
void size(int W, int H) { Fl_Widget::size(W, H); }
void textcolor(Fl_Color c) { if (textcolor_ == defcolor_) textcolor_ = c; defcolor_ = c; }
Fl_Color textcolor() const { return (defcolor_); }
void textfont(Fl_Font f) { textfont_ = f; format(); }
Fl_Font textfont() const { return (textfont_); }
void textsize(Fl_Fontsize s) { textsize_ = s; format(); }
Fl_Fontsize textsize() const { return (textsize_); }
const char *title() { return (title_); }
void topline(const char *n);
void topline(int);
int topline() const { return (topline_); }
void leftline(int);
int leftline() const { return (leftline_); }
void value(const char *val);
const char *value() const { return (value_); }
void clear_selection();
void select_all();
int scrollbar_size() const {
return(scrollbar_size_);
}
void scrollbar_size(int newSize) {
scrollbar_size_ = newSize;
}
};
#endif // !Fl_Help_View_H
//
// End of "$Id: Fl_Help_View.H 9126 2011-10-04 13:10:55Z manolo $".
//
- © 1998-2012 by Bill Spitzak and others.