2001-08-02 23:43:49 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
2001-08-02 23:43:49 +04:00
|
|
|
//
|
2001-10-29 06:44:33 +03:00
|
|
|
// Help Viewer widget definitions.
|
2001-08-02 23:43:49 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// Copyright 1997-2005 by Easy Software Products.
|
2001-10-29 06:44:33 +03:00
|
|
|
// Image support donated by Matthias Melcher, Copyright 2000.
|
2001-08-02 23:43:49 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
2001-08-02 23:43:49 +04:00
|
|
|
//
|
|
|
|
|
2008-09-16 11:26:22 +04:00
|
|
|
/** \file
|
|
|
|
Fl_Help_View widget . */
|
|
|
|
|
2001-11-24 05:46:19 +03:00
|
|
|
#ifndef Fl_Help_View_H
|
|
|
|
# define Fl_Help_View_H
|
2001-08-02 23:43:49 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Include necessary header files...
|
|
|
|
//
|
|
|
|
|
|
|
|
# include <stdio.h>
|
2001-11-24 05:46:19 +03:00
|
|
|
# include "Fl.H"
|
|
|
|
# include "Fl_Group.H"
|
|
|
|
# include "Fl_Scrollbar.H"
|
|
|
|
# include "fl_draw.H"
|
|
|
|
# include "Fl_Shared_Image.H"
|
2001-08-02 23:43:49 +04:00
|
|
|
|
|
|
|
|
|
|
|
//
|
2001-09-29 18:38:59 +04:00
|
|
|
// Fl_Help_Func type - link callback function for files...
|
2001-08-02 23:43:49 +04:00
|
|
|
//
|
|
|
|
|
|
|
|
|
2001-10-27 07:29:25 +04:00
|
|
|
typedef const char *(Fl_Help_Func)(Fl_Widget *, const char *);
|
2001-08-02 23:43:49 +04:00
|
|
|
|
|
|
|
|
|
|
|
//
|
2001-09-29 18:38:59 +04:00
|
|
|
// Fl_Help_Block structure...
|
2001-08-02 23:43:49 +04:00
|
|
|
//
|
|
|
|
|
2001-09-29 18:38:59 +04:00
|
|
|
struct Fl_Help_Block
|
2001-08-02 23:43:49 +04:00
|
|
|
{
|
|
|
|
const char *start, // Start of text
|
|
|
|
*end; // End of text
|
2001-12-19 21:15:34 +03:00
|
|
|
uchar border; // Draw border?
|
2002-03-05 14:26:41 +03:00
|
|
|
Fl_Color bgcolor; // Background color
|
2001-08-02 23:43:49 +04:00
|
|
|
int x, // Indentation/starting X coordinate
|
|
|
|
y, // Starting Y coordinate
|
|
|
|
w, // Width
|
|
|
|
h; // Height
|
|
|
|
int line[32]; // Left starting position for each line
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2001-09-29 18:38:59 +04:00
|
|
|
// Fl_Help_Link structure...
|
2001-08-02 23:43:49 +04:00
|
|
|
//
|
|
|
|
|
2001-09-29 18:38:59 +04:00
|
|
|
struct Fl_Help_Link
|
2001-08-02 23:43:49 +04:00
|
|
|
{
|
|
|
|
char filename[192], // Reference filename
|
|
|
|
name[32]; // Link target (blank if none)
|
|
|
|
int x, // X offset of link text
|
|
|
|
y, // Y offset of link text
|
|
|
|
w, // Width of link text
|
|
|
|
h; // Height of link text
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2001-09-29 18:38:59 +04:00
|
|
|
// Fl_Help_Target structure...
|
2001-08-02 23:43:49 +04:00
|
|
|
//
|
|
|
|
|
2001-09-29 18:38:59 +04:00
|
|
|
struct Fl_Help_Target
|
2001-08-02 23:43:49 +04:00
|
|
|
{
|
|
|
|
char name[32]; // Target name
|
|
|
|
int y; // Y offset of target
|
|
|
|
};
|
|
|
|
|
2008-09-15 00:00:03 +04:00
|
|
|
/**
|
|
|
|
The Fl_Help_View widget displays HTML text. Most HTML 2.0
|
|
|
|
elements are supported, as well as a primitive implementation of tables.
|
|
|
|
GIF, JPEG, and PNG images are displayed inline.
|
|
|
|
*/
|
2002-07-14 23:08:25 +04:00
|
|
|
class FL_EXPORT Fl_Help_View : public Fl_Group //// Help viewer widget
|
2001-08-02 23:43:49 +04:00
|
|
|
{
|
|
|
|
enum { RIGHT = -1, CENTER, LEFT }; // Alignments
|
|
|
|
|
|
|
|
char title_[1024]; // Title string
|
|
|
|
Fl_Color defcolor_, // Default text color
|
|
|
|
bgcolor_, // Background color
|
|
|
|
textcolor_, // Text color
|
|
|
|
linkcolor_; // Link color
|
2008-04-23 23:09:28 +04:00
|
|
|
Fl_Font textfont_; // Default font for text
|
2008-08-16 01:11:21 +04:00
|
|
|
Fl_Fontsize textsize_; // Default font size
|
2001-08-02 23:43:49 +04:00
|
|
|
const char *value_; // HTML text value
|
|
|
|
|
|
|
|
int nblocks_, // Number of blocks/paragraphs
|
|
|
|
ablocks_; // Allocated blocks
|
2001-09-29 18:38:59 +04:00
|
|
|
Fl_Help_Block *blocks_; // Blocks
|
2001-08-02 23:43:49 +04:00
|
|
|
|
|
|
|
int nfonts_; // Number of fonts in stack
|
2008-04-23 23:09:28 +04:00
|
|
|
Fl_Font fonts_[100]; // Font stack
|
2008-08-16 01:11:21 +04:00
|
|
|
Fl_Fontsize font_sizes_[100]; // Font Size stack
|
2001-08-02 23:43:49 +04:00
|
|
|
|
2001-09-29 18:38:59 +04:00
|
|
|
Fl_Help_Func *link_; // Link transform function
|
2001-08-02 23:43:49 +04:00
|
|
|
|
|
|
|
int nlinks_, // Number of links
|
|
|
|
alinks_; // Allocated links
|
2001-09-29 18:38:59 +04:00
|
|
|
Fl_Help_Link *links_; // Links
|
2001-08-02 23:43:49 +04:00
|
|
|
|
|
|
|
int ntargets_, // Number of targets
|
|
|
|
atargets_; // Allocated targets
|
2001-11-24 07:12:56 +03:00
|
|
|
Fl_Help_Target *targets_; // Targets
|
2001-08-02 23:43:49 +04:00
|
|
|
|
|
|
|
char directory_[1024]; // Directory for current file
|
|
|
|
char filename_[1024]; // Current filename
|
|
|
|
int topline_, // Top line in document
|
2001-11-24 07:12:56 +03:00
|
|
|
leftline_, // Lefthand position
|
|
|
|
size_, // Total document length
|
|
|
|
hsize_; // Maximum document width
|
|
|
|
Fl_Scrollbar scrollbar_, // Vertical scrollbar for document
|
|
|
|
hscrollbar_; // Horizontal scrollbar
|
2001-08-02 23:43:49 +04:00
|
|
|
|
2006-06-18 19:53:26 +04:00
|
|
|
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;
|
|
|
|
|
2001-09-29 18:38:59 +04:00
|
|
|
Fl_Help_Block *add_block(const char *s, int xx, int yy, int ww, int hh, uchar border = 0);
|
2001-08-02 23:43:49 +04:00
|
|
|
void add_link(const char *n, int xx, int yy, int ww, int hh);
|
|
|
|
void add_target(const char *n, int yy);
|
2001-09-29 18:38:59 +04:00
|
|
|
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);
|
2001-08-02 23:43:49 +04:00
|
|
|
void draw();
|
|
|
|
void format();
|
2001-09-10 07:09:43 +04:00
|
|
|
void format_table(int *table_width, int *columns, const char *table);
|
2007-12-15 19:08:23 +03:00
|
|
|
void free_data();
|
2001-08-02 23:43:49 +04:00
|
|
|
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);
|
2001-11-24 05:46:19 +03:00
|
|
|
Fl_Shared_Image *get_image(const char *name, int W, int H);
|
2001-11-24 07:12:56 +03:00
|
|
|
int get_length(const char *l);
|
2001-08-02 23:43:49 +04:00
|
|
|
int handle(int);
|
|
|
|
|
2008-08-16 01:11:21 +04:00
|
|
|
void initfont(Fl_Font &f, Fl_Fontsize &s) { nfonts_ = 0;
|
2008-04-23 23:09:28 +04:00
|
|
|
fl_font(f = fonts_[0] = textfont_,
|
|
|
|
s = font_sizes_[0] = textsize_); }
|
2008-08-16 01:11:21 +04:00
|
|
|
void pushfont(Fl_Font f, Fl_Fontsize s) { if (nfonts_ < 99) nfonts_ ++;
|
2008-04-23 23:09:28 +04:00
|
|
|
fl_font(fonts_[nfonts_] = f,
|
|
|
|
font_sizes_[nfonts_] = s); }
|
2008-08-16 01:11:21 +04:00
|
|
|
void popfont(Fl_Font &f, Fl_Fontsize &s) { if (nfonts_ > 0) nfonts_ --;
|
2008-04-23 23:09:28 +04:00
|
|
|
fl_font(f = fonts_[nfonts_],
|
|
|
|
s = font_sizes_[nfonts_]); }
|
2001-08-02 23:43:49 +04:00
|
|
|
|
2006-06-16 23:45:13 +04:00
|
|
|
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:
|
2001-08-02 23:43:49 +04:00
|
|
|
|
2001-09-29 18:38:59 +04:00
|
|
|
Fl_Help_View(int xx, int yy, int ww, int hh, const char *l = 0);
|
|
|
|
~Fl_Help_View();
|
2008-09-15 00:00:03 +04:00
|
|
|
/** This method returns the current directory for the text in the buffer. */
|
2001-08-02 23:43:49 +04:00
|
|
|
const char *directory() const { if (directory_[0]) return (directory_);
|
|
|
|
else return ((const char *)0); }
|
2008-09-15 00:00:03 +04:00
|
|
|
/** This method returns the current filename for the text in the buffer. */
|
2001-08-02 23:43:49 +04:00
|
|
|
const char *filename() const { if (filename_[0]) return (filename_);
|
|
|
|
else return ((const char *)0); }
|
2003-05-21 20:12:14 +04:00
|
|
|
int find(const char *s, int p = 0);
|
2008-09-15 00:00:03 +04:00
|
|
|
/**
|
|
|
|
This method assigns a callback function to use when a link is
|
|
|
|
followed or a file is loaded (via
|
|
|
|
Fl_Help_View::load()) that requires a different
|
|
|
|
file or path. The callback function receives a pointer to the
|
|
|
|
Fl_Help_View widget and the URI or full pathname
|
|
|
|
for the file in question. It must return a pathname that can be
|
|
|
|
opened as a local file or NULL:</P>
|
|
|
|
|
2008-09-15 23:21:20 +04:00
|
|
|
\code
|
2008-09-15 00:00:03 +04:00
|
|
|
const char *fn(Fl_Widget *w, const char *uri);
|
2008-09-15 23:21:20 +04:00
|
|
|
\endcode
|
2008-09-15 00:00:03 +04:00
|
|
|
|
|
|
|
<P>The link function can be used to retrieve remote or virtual
|
|
|
|
documents, returning a temporary file that contains the actual
|
|
|
|
data. If the link function returns NULL, the value of
|
|
|
|
the Fl_Help_View widget will remain unchanged.</P>
|
|
|
|
|
|
|
|
<P>If the link callback cannot handle the URI scheme, it should
|
|
|
|
return the uri value unchanged or set the value() of the widget
|
|
|
|
before returning NULL.
|
|
|
|
*/
|
2001-09-29 18:38:59 +04:00
|
|
|
void link(Fl_Help_Func *fn) { link_ = fn; }
|
2001-08-02 23:43:49 +04:00
|
|
|
int load(const char *f);
|
|
|
|
void resize(int,int,int,int);
|
2008-09-15 00:00:03 +04:00
|
|
|
/** Gets the size of the Help view */
|
2001-08-02 23:43:49 +04:00
|
|
|
int size() const { return (size_); }
|
2003-06-15 08:47:28 +04:00
|
|
|
void size(int W, int H) { Fl_Widget::size(W, H); }
|
2008-09-15 00:00:03 +04:00
|
|
|
/** Sets the default text color. */
|
2001-08-02 23:43:49 +04:00
|
|
|
void textcolor(Fl_Color c) { if (textcolor_ == defcolor_) textcolor_ = c; defcolor_ = c; }
|
2008-09-15 00:00:03 +04:00
|
|
|
/** Returns the current default text color. */
|
2001-08-02 23:43:49 +04:00
|
|
|
Fl_Color textcolor() const { return (defcolor_); }
|
2008-09-15 00:00:03 +04:00
|
|
|
/** Sets the default text font. */
|
2008-04-23 23:09:28 +04:00
|
|
|
void textfont(Fl_Font f) { textfont_ = f; format(); }
|
2008-09-15 00:00:03 +04:00
|
|
|
/** Returns the current default text font. */
|
2008-04-23 23:09:28 +04:00
|
|
|
Fl_Font textfont() const { return (textfont_); }
|
2008-09-15 00:00:03 +04:00
|
|
|
/** Sets the default text size. */
|
2008-08-16 01:11:21 +04:00
|
|
|
void textsize(Fl_Fontsize s) { textsize_ = s; format(); }
|
2008-09-15 00:00:03 +04:00
|
|
|
/** Gets the default text size. */
|
2008-08-16 01:11:21 +04:00
|
|
|
Fl_Fontsize textsize() const { return (textsize_); }
|
2008-09-15 00:00:03 +04:00
|
|
|
/** Returns the current document title, or NULL if there is no title. */
|
2001-08-02 23:43:49 +04:00
|
|
|
const char *title() { return (title_); }
|
|
|
|
void topline(const char *n);
|
|
|
|
void topline(int);
|
2008-09-15 00:00:03 +04:00
|
|
|
/** Returns the current top line in pixels. */
|
2001-08-02 23:43:49 +04:00
|
|
|
int topline() const { return (topline_); }
|
2001-11-24 07:12:56 +03:00
|
|
|
void leftline(int);
|
2008-09-15 00:00:03 +04:00
|
|
|
/** Gets the left position. */
|
2001-11-24 07:12:56 +03:00
|
|
|
int leftline() const { return (leftline_); }
|
2001-08-02 23:43:49 +04:00
|
|
|
void value(const char *v);
|
2008-09-15 00:00:03 +04:00
|
|
|
/** Returns the current buffer contents. */
|
2001-08-02 23:43:49 +04:00
|
|
|
const char *value() const { return (value_); }
|
2006-06-16 23:45:13 +04:00
|
|
|
void clear_selection();
|
|
|
|
void select_all();
|
2001-08-02 23:43:49 +04:00
|
|
|
};
|
|
|
|
|
2001-11-24 05:46:19 +03:00
|
|
|
#endif // !Fl_Help_View_H
|
2001-08-02 23:43:49 +04:00
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
2001-08-02 23:43:49 +04:00
|
|
|
//
|