Fl_Help_View-dad.H 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. //
  2. // "$Id: Fl_Help_View.H 8864 2011-07-19 04:49:30Z greg.ercolano $"
  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. /* \file
  20. Fl_Help_View widget . */
  21. #ifndef Fl_Help_View_H
  22. # define Fl_Help_View_H
  23. //
  24. // Include necessary header files...
  25. //
  26. # include <stdio.h>
  27. # include "Fl.H"
  28. # include "Fl_Group.H"
  29. # include "Fl_Scrollbar.H"
  30. # include "fl_draw.H"
  31. # include "Fl_Shared_Image.H"
  32. # include "filename.H"
  33. //
  34. // Fl_Help_Func type - link callback function for files...
  35. //
  36. typedef const char *(Fl_Help_Func)(Fl_Widget *, const char *, const char *);
  37. //
  38. // Fl_Help_Block structure...
  39. //
  40. struct Fl_Help_Block
  41. {
  42. const char *start, // Start of text
  43. *end; // End of text
  44. uchar border; // Draw border?
  45. Fl_Color bgcolor; // Background color
  46. Fl_Color border_color; // Border color
  47. int x, // Indentation/starting X coordinate
  48. y, // Starting Y coordinate
  49. w, // Width
  50. h; // Height
  51. int line[32]; // Left starting position for each line
  52. };
  53. //
  54. // Fl_Help_Link structure...
  55. //
  56. /** Definition of a link for the html viewer. */
  57. struct Fl_Help_Link
  58. {
  59. char filename[192], ///< Reference filename
  60. name[32]; ///< Link target (blank if none)
  61. int x, ///< X offset of link text
  62. y, ///< Y offset of link text
  63. w, ///< Width of link text
  64. h; ///< Height of link text
  65. };
  66. /*
  67. * Fl_Help_View font stack opaque implementation
  68. */
  69. /** Fl_Help_View font stack element definition. */
  70. struct Fl_Help_Font_Style {
  71. Fl_Font f; ///< Font
  72. Fl_Fontsize s; ///< Font Size
  73. Fl_Color c; ///< Font Color
  74. void get(Fl_Font &afont, Fl_Fontsize &asize, Fl_Color &acolor) {afont=f; asize=s; acolor=c;} ///< Gets current font attributes
  75. void set(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {f=afont; s=asize; c=acolor;} ///< Sets current font attributes
  76. Fl_Help_Font_Style(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {set(afont, asize, acolor);}
  77. Fl_Help_Font_Style(){} // For in table use
  78. };
  79. /** Fl_Help_View font stack definition. */
  80. const size_t MAX_FL_HELP_FS_ELTS = 100;
  81. struct Fl_Help_Font_Stack {
  82. /** font stack construction, initialize attributes. */
  83. Fl_Help_Font_Stack() {
  84. nfonts_ = 0;
  85. }
  86. void init(Fl_Font f, Fl_Fontsize s, Fl_Color c) {
  87. nfonts_ = 0;
  88. elts_[nfonts_].set(f, s, c);
  89. fl_font(f, s);
  90. fl_color(c);
  91. }
  92. /** Gets the top (current) element on the stack. */
  93. void top(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { elts_[nfonts_].get(f, s, c); }
  94. /** Pushes the font style triplet on the stack, also calls fl_font() & fl_color() adequately */
  95. void push(Fl_Font f, Fl_Fontsize s, Fl_Color c) {
  96. if (nfonts_ < MAX_FL_HELP_FS_ELTS-1) nfonts_ ++;
  97. elts_[nfonts_].set(f, s, c);
  98. fl_font(f, s); fl_color(c);
  99. }
  100. /** Pops from the stack the font style triplet and calls fl_font() & fl_color() adequately */
  101. void pop(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {
  102. if (nfonts_ > 0) nfonts_ --;
  103. top(f, s, c);
  104. fl_font(f, s); fl_color(c);
  105. }
  106. /** Gets the current count of font style elements in the stack. */
  107. size_t count() const {return nfonts_;} // Gets the current number of fonts in the stack
  108. protected:
  109. size_t nfonts_; ///< current number of fonts in stack
  110. Fl_Help_Font_Style elts_[100]; ///< font elements
  111. };
  112. /** Fl_Help_Target structure */
  113. struct Fl_Help_Target
  114. {
  115. char name[32]; ///< Target name
  116. int y; ///< Y offset of target
  117. };
  118. /**
  119. The Fl_Help_View widget displays HTML text. Most HTML 2.0
  120. elements are supported, as well as a primitive implementation of tables.
  121. GIF, JPEG, and PNG images are displayed inline.
  122. Supported HTML tags:
  123. - A: HREF/NAME
  124. - B
  125. - BODY: BGCOLOR/TEXT/LINK
  126. - BR
  127. - CENTER
  128. - CODE
  129. - DD
  130. - DL
  131. - DT
  132. - EM
  133. - FONT: COLOR/SIZE/FACE=(helvetica/arial/sans/times/serif/symbol/courier)
  134. - H1/H2/H3/H4/H5/H6
  135. - HEAD
  136. - HR
  137. - I
  138. - IMG: SRC/WIDTH/HEIGHT/ALT
  139. - KBD
  140. - LI
  141. - OL
  142. - P
  143. - PRE
  144. - STRONG
  145. - TABLE: TH/TD/TR/BORDER/BGCOLOR/COLSPAN/ALIGN=CENTER|RIGHT|LEFT
  146. - TITLE
  147. - TT
  148. - U
  149. - UL
  150. - VAR
  151. Supported color names:
  152. - black,red,green,yellow,blue,magenta,fuchsia,cyan,aqua,white,gray,grey,lime,maroon,navy,olive,purple,silver,teal.
  153. Supported urls:
  154. - Internal: file:
  155. - External: http: ftp: https: ipp: mailto: news:
  156. Quoted char names:
  157. - Aacute aacute Acirc acirc acute AElig aelig Agrave agrave amp Aring aring Atilde atilde Auml auml
  158. - brvbar bull
  159. - Ccedil ccedil cedil cent copy curren
  160. - deg divide
  161. - Eacute eacute Ecirc ecirc Egrave egrave ETH eth Euml euml euro
  162. - frac12 frac14 frac34
  163. - gt
  164. - Iacute iacute Icirc icirc iexcl Igrave igrave iquest Iuml iuml
  165. - laquo lt
  166. - macr micro middot
  167. - nbsp not Ntilde ntilde
  168. - Oacute oacute Ocirc ocirc Ograve ograve ordf ordm Oslash oslash Otilde otilde Ouml ouml
  169. - para premil plusmn pound
  170. - quot
  171. - raquo reg
  172. - sect shy sup1 sup2 sup3 szlig
  173. - THORN thorn times trade
  174. - Uacute uacute Ucirc ucirc Ugrave ugrave uml Uuml uuml
  175. - Yacute yacute
  176. - yen Yuml yuml
  177. */
  178. class FL_EXPORT Fl_Help_View : public Fl_Group // Help viewer widget
  179. {
  180. enum { RIGHT = -1, CENTER, LEFT }; ///< Alignments
  181. char title_[1024]; ///< Title string
  182. Fl_Color defcolor_, ///< Default text color
  183. bgcolor_, ///< Background color
  184. textcolor_, ///< Text color
  185. linkcolor_; ///< Link color
  186. Fl_Font textfont_; ///< Default font for text
  187. Fl_Fontsize textsize_; ///< Default font size
  188. const char *value_; ///< HTML text value
  189. Fl_Help_Font_Stack fstack_; ///< font stack management
  190. int nblocks_, ///< Number of blocks/paragraphs
  191. ablocks_; ///< Allocated blocks
  192. Fl_Help_Block *blocks_; ///< Blocks
  193. Fl_Help_Func *link_; ///< Link transform function
  194. int nlinks_, ///< Number of links
  195. alinks_; ///< Allocated links
  196. Fl_Help_Link *links_; ///< Links
  197. int ntargets_, ///< Number of targets
  198. atargets_; ///< Allocated targets
  199. Fl_Help_Target *targets_; ///< Targets
  200. char directory_[FL_PATH_MAX];///< Directory for current file
  201. char filename_[FL_PATH_MAX]; ///< Current filename
  202. int topline_, ///< Top line in document
  203. leftline_, ///< Lefthand position
  204. size_, ///< Total document length
  205. hsize_, ///< Maximum document width
  206. scrollbar_size_; ///< Size for both scrollbars
  207. Fl_Scrollbar scrollbar_, ///< Vertical scrollbar for document
  208. hscrollbar_; ///< Horizontal scrollbar
  209. int font_increment_; //to remove a magic number
  210. int td_top_gap_; //to remove a magic number
  211. int td_bottom_gap_; //to remove a magic number
  212. int tr_gap_; //to remove a magic number
  213. int line31_; //to remove a magic number
  214. int td_margin_;
  215. int td_width_adjust_;
  216. Fl_Offscreen fl_help_view_buffer;
  217. int selection_first;
  218. int selection_last;
  219. int selection_push_first;
  220. int selection_push_last;
  221. int selection_drag_first;
  222. int selection_drag_last;
  223. int selected;
  224. int draw_mode;
  225. int mouse_x;
  226. int mouse_y;
  227. int current_pos;
  228. Fl_Help_View *current_view;
  229. Fl_Color hv_selection_color;
  230. Fl_Color hv_selection_text_color;
  231. void initfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { f = textfont_; s = textsize_; c = textcolor_; fstack_.init(f, s, c); }
  232. void pushfont(Fl_Font f, Fl_Fontsize s) {fstack_.push(f, s, textcolor_);}
  233. void pushfont(Fl_Font f, Fl_Fontsize s, Fl_Color c) {fstack_.push(f, s, c);}
  234. void popfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {fstack_.pop(f, s, c);}
  235. Fl_Help_Block *add_block(const char *s, int xx, int yy, int ww, int hh, uchar border = 0,
  236. Fl_Color border_color = FL_BLACK);
  237. void add_link(const char *n, int xx, int yy, int ww, int hh);
  238. void add_target(const char *n, int yy);
  239. static int compare_targets(const Fl_Help_Target *t0, const Fl_Help_Target *t1);
  240. int do_align(Fl_Help_Block *block, int line, int xx, int a, int &l);
  241. void format();
  242. void format_table(int *table_width, int *columns, const char *table);
  243. void free_data();
  244. int get_align(const char *p, int a);
  245. const char *get_attr(const char *p, const char *n, char *buf, int bufsize);
  246. void check_font_attr(const char *attrs, Fl_Font &font, Fl_Fontsize &fsize);
  247. Fl_Color get_color(const char *n, Fl_Color c);
  248. Fl_Shared_Image *get_image(const char *name, int W, int H);
  249. int get_length(const char *l);
  250. void hv_draw(const char *t, int x, int y);
  251. char begin_selection();
  252. char extend_selection();
  253. void end_selection(int c=0);
  254. void clear_global_selection();
  255. Fl_Help_Link *find_link(int, int);
  256. void follow_link(Fl_Help_Link*);
  257. public:
  258. int handle(int);
  259. void draw();
  260. Fl_Help_View(int xx, int yy, int ww, int hh, const char *l = 0);
  261. ~Fl_Help_View();
  262. /** Returns the current directory for the text in the buffer. */
  263. const char *directory() const { if (directory_[0]) return (directory_);
  264. else return ((const char *)0); }
  265. /** Returns the current filename for the text in the buffer. */
  266. const char *filename() const { if (filename_[0]) return (filename_);
  267. else return ((const char *)0); }
  268. int find(const char *s, int p = 0);
  269. /**
  270. This method assigns a callback function to use when a link is
  271. followed or a file is loaded (via Fl_Help_View::load()) that
  272. requires a different file or path.
  273. The callback function receives a pointer to the Fl_Help_View
  274. widget and the URI or full pathname for the file in question.
  275. It must return a pathname that can be opened as a local file or NULL:
  276. \code
  277. const char *fn(Fl_Widget *w, const char *uri);
  278. \endcode
  279. The link function can be used to retrieve remote or virtual
  280. documents, returning a temporary file that contains the actual
  281. data. If the link function returns NULL, the value of
  282. the Fl_Help_View widget will remain unchanged.
  283. If the link callback cannot handle the URI scheme, it should
  284. return the uri value unchanged or set the value() of the widget
  285. before returning NULL.
  286. */
  287. void link(Fl_Help_Func *fn) { link_ = fn; }
  288. int load(const char *f);
  289. void resize(int,int,int,int);
  290. /** Gets the size of the help view. */
  291. int size() const { return (size_); }
  292. void size(int W, int H) { Fl_Widget::size(W, H); }
  293. /** Sets the default text color. */
  294. void textcolor(Fl_Color c) { if (textcolor_ == defcolor_) textcolor_ = c; defcolor_ = c; }
  295. /** Returns the current default text color. */
  296. Fl_Color textcolor() const { return (defcolor_); }
  297. /** Sets the default text font. */
  298. void textfont(Fl_Font f) { textfont_ = f; format(); }
  299. /** Returns the current default text font. */
  300. Fl_Font textfont() const { return (textfont_); }
  301. /** Sets the default text size. */
  302. void textsize(Fl_Fontsize s) { textsize_ = s; format(); }
  303. /** Gets the default text size. */
  304. Fl_Fontsize textsize() const { return (textsize_); }
  305. /** Returns the current document title, or NULL if there is no title. */
  306. const char *title() { return (title_); }
  307. void topline(const char *n);
  308. void topline(int);
  309. /** Returns the current top line in pixels. */
  310. int topline() const { return (topline_); }
  311. void leftline(int);
  312. /** Gets the left position in pixels. */
  313. int leftline() const { return (leftline_); }
  314. void value(const char *val);
  315. /** Returns the current buffer contents. */
  316. const char *value() const { return (value_); }
  317. void clear_selection();
  318. void select_all();
  319. /**
  320. Gets the current size of the scrollbars' troughs, in pixels.
  321. If this value is zero (default), this widget will use the
  322. Fl::scrollbar_size() value as the scrollbar's width.
  323. \returns Scrollbar size in pixels, or 0 if the global Fl::scrollbar_size() is being used.
  324. \see Fl::scrollbar_size(int)
  325. */
  326. int scrollbar_size() const {
  327. return(scrollbar_size_);
  328. }
  329. /**
  330. Sets the pixel size of the scrollbars' troughs to the \p size, in pixels.
  331. Normally you should not need this method, and should use
  332. Fl::scrollbar_size(int) instead to manage the size of ALL
  333. your widgets' scrollbars. This ensures your application
  334. has a consistent UI, is the default behavior, and is normally
  335. what you want.
  336. Only use THIS method if you really need to override the global
  337. scrollbar size. The need for this should be rare.
  338. Setting \p size to the special value of 0 causes the widget to
  339. track the global Fl::scrollbar_size(), which is the default.
  340. \param[in] size Sets the scrollbar size in pixels.\n
  341. If 0 (default), scrollbar size tracks the global Fl::scrollbar_size()
  342. \see Fl::scrollbar_size()
  343. */
  344. void scrollbar_size(int size) {
  345. scrollbar_size_ = size;
  346. }
  347. /** Returns the current font increment in pixels. */
  348. int font_increment() const { return (font_increment_); }
  349. void font_increment(int i) {font_increment_ = i;};
  350. int td_top_gap() const { return (td_top_gap_); }
  351. void td_top_gap(int i) {td_top_gap_ = i;};
  352. int td_bottom_gap() const { return (td_bottom_gap_); }
  353. void td_bottom_gap(int i) {td_bottom_gap_ = i;};
  354. int tr_gap() const { return (tr_gap_); }
  355. void tr_gap(int i) {tr_gap_ = i;};
  356. int line31() const { return (line31_); }
  357. void line31(int i) {line31_ = i;};
  358. int td_margin() const { return (td_margin_); }
  359. void td_margin(int i) {td_margin_ = i;};
  360. int td_width_adjust() const { return (td_width_adjust_); }
  361. void td_width_adjust(int i) {td_width_adjust_ = i;};
  362. DECLARE_CLASS_CHEAP_RTTI_2(Fl_Help_View, Fl_Group)
  363. };
  364. #endif // !Fl_Help_View_H
  365. //
  366. // End of "$Id: Fl_Help_View.H 8864 2011-07-19 04:49:30Z greg.ercolano $".
  367. //