Fl_Help_View.H 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. //
  2. // "$Id: Fl_Help_View.H 5991 2007-12-15 16:08:23Z mike $"
  3. //
  4. // Help Viewer widget definitions.
  5. //
  6. // Copyright 1997-2005 by Easy Software Products.
  7. // Image support donated by Matthias Melcher, Copyright 2000.
  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. // Inline:
  29. //
  30. // Fl_Help_View::directory() - Get the directory string.
  31. // Fl_Help_View::filename() - Get the filename string.
  32. // Fl_Help_View::link() - Set the link callback.
  33. // Fl_Help_View::size() - Get the total document length.
  34. // Fl_Help_View::size() - Set the document width and height.
  35. // Fl_Help_View::textcolor() - Set the default text color.
  36. // Fl_Help_View::textcolor() - Get the default text color.
  37. // Fl_Help_View::textsize() - Set the default font size.
  38. // Fl_Help_View::textsize() - Get the default font size.
  39. // Fl_Help_View::title() - Get the title string.
  40. // Fl_Help_View::topline() - Get the top line in document.
  41. // Fl_Help_View::leftline() - Get the left line position.
  42. // Fl_Help_View::value() - Get the HTML text value.
  43. // Fl_Help_View::monofont() - Set the default mono font.
  44. // Fl_Help_View::monofont() - Get the default mono font.
  45. // Fl_Help_View::reformat() - Format the help text.
  46. // Fl_Help_View::sansfont() - Set the default sans font.
  47. // Fl_Help_View::sansfont() - Get the default sans font.
  48. // Fl_Help_View::serifont() - Set the default serif font.
  49. // Fl_Help_View::serifont() - Get the default serif font.
  50. //
  51. #ifndef Fl_Help_View_H
  52. # define Fl_Help_View_H
  53. //
  54. // Include necessary header files...
  55. //
  56. # include <stdio.h>
  57. # include "Fl.H"
  58. # include "Fl_Group.H"
  59. # include "Fl_Scrollbar.H"
  60. # include "fl_draw.H"
  61. # include "Fl_Shared_Image.H"
  62. //
  63. // Fl_Help_Func type - link callback function for files...
  64. //
  65. typedef const char *(Fl_Help_Func)(Fl_Widget *, const char *);
  66. //
  67. // Fl_Help_Block structure
  68. //
  69. // note: we can change private structs accessed by pointers
  70. struct Fl_Help_Block
  71. {
  72. const char *start, // Start of text
  73. *end; // End of text
  74. unsigned char border; // Draw border?
  75. Fl_Color bgcolor; // Background color
  76. int x, // Indentation/starting X coordinate
  77. y, // Starting Y coordinate
  78. w, // Width
  79. h; // Height
  80. // new fields, removed int line[32];
  81. unsigned char fsize; // current font size
  82. int font, // current font
  83. maxh, // max image height
  84. imgy, // image y position
  85. pre, // pre text flag
  86. type, // blockquote/ol/ul/li type parameter
  87. tag, // tag/element fourcc int
  88. line, // Left starting position for each line
  89. cbi; // current block index
  90. };
  91. //
  92. // Fl_Help_Link structure
  93. //
  94. struct Fl_Help_Link
  95. {
  96. char filename[192], // Link reference filename
  97. name[32]; // Link target name, blank if none
  98. int x, // X offset of link text
  99. y, // Y offset of link text
  100. w, // Width of link text
  101. h; // Height of link text
  102. };
  103. //
  104. // Fl_Help_Target structure
  105. //
  106. // note: hijacking this lets us add new data members via the d-pointer
  107. struct Fl_Help_Target
  108. {
  109. // new fields, removed char name[32]; int y;
  110. Fl_Help_Link *targets, // Targets
  111. *linkp; // Currently clicked link
  112. unsigned char ispush, // link is pushed
  113. islink, // link clicked
  114. resized, // window resized
  115. ispath, // is path used
  116. nstyle, // navigation style flag
  117. isnew, // is new page
  118. pad7, //
  119. pad8; //
  120. int top, // current topline
  121. ltop, // last topline
  122. isnav, // is nav link
  123. rwidth, // resize width
  124. cssurllen, // css url length
  125. csswordlen, // css word length
  126. *cssword; // css word value
  127. long rtime, // resize time
  128. rsec, // resize seconds
  129. rmil, // resize millisecs
  130. csstextlen; // css text length
  131. char *csstext, // css text value
  132. *cssurl, // css url value
  133. path[1024], // current file path
  134. lpath[1024]; // last file path
  135. int nfonts, // number of fonts in stack
  136. fonts[100][2]; // font stack
  137. };
  138. //
  139. // Fl_Help_View class...
  140. //
  141. class FL_EXPORT Fl_Help_View : public Fl_Group // Help viewer widget
  142. {
  143. private:
  144. enum { RIGHT = -1, CENTER, LEFT }; // Alignments
  145. char title_[1024]; // Title string
  146. Fl_Color defcolor_, // Default text color
  147. bgcolor_, // Background color
  148. textcolor_, // Text color
  149. linkcolor_; // Link color
  150. unsigned char textfont_, // Default font - replaced
  151. textsize_; // Default font size - replaced
  152. const char *value_; // HTML text value
  153. int nblocks_, // Number of blocks/lines
  154. ablocks_; // Allocated blocks
  155. Fl_Help_Block *blocks_; // Blocks
  156. int nfonts_; // Number of fonts in stack - replaced
  157. unsigned char fonts_[100][2]; // Font stack - replaced
  158. Fl_Help_Func *link_; // Link transform function
  159. int nlinks_, // Number of links
  160. alinks_; // Allocated links
  161. Fl_Help_Link *links_; // Links
  162. int ntargets_, // Number of targets
  163. atargets_; // Allocated targets
  164. Fl_Help_Target *d; // d-pointer struct - was *targets_
  165. // note: we can rename existing data members
  166. char directory_[1024], // Directory for current file
  167. filename_[1024]; // Current filename
  168. int topline_, // Top line in document
  169. leftline_, // Left line position
  170. size_, // Total document length
  171. hsize_; // Maximum document width
  172. Fl_Scrollbar scrollbar_, // Vertical scrollbar for document
  173. hscrollbar_; // Horizontal scrollbar
  174. static int selection_first; // Text selection
  175. static int selection_last;
  176. static int selection_push_first;
  177. static int selection_push_last;
  178. static int selection_drag_first;
  179. static int selection_drag_last;
  180. static int selected;
  181. static int draw_mode;
  182. static int mouse_x;
  183. static int mouse_y;
  184. static int current_pos;
  185. static Fl_Help_View *current_view;
  186. static Fl_Color hv_selection_color;
  187. static Fl_Color hv_selection_text_color;
  188. // new private static class variables
  189. static int serifont_; // default serif font
  190. static int sansfont_; // default sans font
  191. static int monofont_; // default monospace font
  192. static unsigned char fontsize_; // default font size
  193. static short face_[250][4]; // font face table [m,b,i,p]
  194. static unsigned char flet_[30]; // first face for letter table
  195. static unsigned char fref_[1000]; // face reference table
  196. Fl_Help_Block *add_block(const char *sp, int xx, int yy, int ww, int hh, unsigned char bc = 0);
  197. void add_link(const char *np, int xx, int yy, int ww, int hh);
  198. void add_target(const char *np, int yy);
  199. static int compare_targets(const Fl_Help_Target *t0, const Fl_Help_Target *t1);
  200. int do_align(Fl_Help_Block *b, int li, int xx, int ca, int &sl);
  201. void draw();
  202. void format();
  203. void format_table(int *tw, int *maxcols, const char *tp);
  204. void free_data();
  205. int get_align(const char *ap, int da);
  206. const char *get_attr(const char *ap, const char *np, char *buf, int sb);
  207. Fl_Color get_color(const char *np, Fl_Color dc);
  208. Fl_Shared_Image *get_image(const char *np, int iw, int ih);
  209. int get_length(const char *lp);
  210. //int handle(int event); // moved to public
  211. // note: you can remove private non-virtual functions if not called by inline functions
  212. void initfont(unsigned char &fi, unsigned char &fs) { // Reset stack - replaced, for when nfonts > 255
  213. nfonts_ = 0;
  214. fl_font(fi = fonts_[0][0] = serifont_, fs = fonts_[0][1] = fontsize_);
  215. }
  216. void pushfont(unsigned char fi, unsigned char fs) { // Push font - replaced
  217. if (nfonts_ < 99) nfonts_ ++;
  218. fl_font(fonts_[nfonts_][0] = fi, fonts_[nfonts_][1] = fs);
  219. }
  220. void popfont(unsigned char &fi, unsigned char &fs) { // Pop font - replaced
  221. if (nfonts_ > 0) nfonts_ --;
  222. fl_font(fi = fonts_[nfonts_][0], fs = fonts_[nfonts_][1]);
  223. }
  224. void hv_draw(const char *tp, int xx, int yy);
  225. char begin_selection();
  226. char extend_selection();
  227. void end_selection(int cb = 0);
  228. void clear_global_selection();
  229. Fl_Help_Link *find_link(int xx, int yy);
  230. void follow_link(Fl_Help_Link *lp);
  231. // new private functions
  232. // note: for BC we can't modify existing function declarations
  233. Fl_Help_Block *add_block(const Fl_Help_Block &b, const char *sp, int ww);
  234. unsigned char build_faces();
  235. static int cmp_targets(const Fl_Help_Link *t0, const Fl_Help_Link *t1);
  236. const char *format_table(int &tw, int *maxcols, const char *tp, int xx, int rc);
  237. int get_css_value(const char *sp, const char *pp, char *vp);
  238. int get_font_size(const char *hp);
  239. int get_length(const char *lp, int hw);
  240. void initfont(int &fi, unsigned char &fs);
  241. int load_css(const char *fp);
  242. void parse_css(Fl_Help_Block &b, const char *sp, char *buf);
  243. void popfont(int &fi, unsigned char &fs);
  244. void pushfont(int fi, unsigned char fs);
  245. public:
  246. Fl_Help_View(int xx, int yy, int ww, int hh, const char *lp = 0);
  247. ~Fl_Help_View();
  248. const char *directory() const { // Get the directory string
  249. if (directory_[0]) return directory_;
  250. else return (const char *)0;
  251. }
  252. const char *filename() const { // Get the filename string
  253. if (filename_[0]) return filename_;
  254. else return (const char *)0;
  255. }
  256. int find(const char *sp, int pos = 0);
  257. void link(Fl_Help_Func *fn) { // Set the link callback
  258. link_ = fn;
  259. }
  260. int load(const char *fp);
  261. void resize(int xx, int yy, int ww, int hh);
  262. int size() const { // Get the total document length
  263. return size_;
  264. }
  265. void size(int ww, int hh) { // Set the document width and height
  266. Fl_Widget::size(ww, hh);
  267. }
  268. void textcolor(Fl_Color tc) { // Set the default text color
  269. if (textcolor_ == defcolor_) textcolor_ = tc;
  270. defcolor_ = tc;
  271. }
  272. Fl_Color textcolor() const { // Get the default text color
  273. return defcolor_;
  274. }
  275. void textfont(unsigned char fi) { // Set the text font, obsolete
  276. textfont_ = fi;
  277. //format(); // removed
  278. // note: we can remove the contents of inline functions
  279. }
  280. unsigned char textfont() const { // Get the text font, obsolete
  281. return textfont_;
  282. }
  283. void textsize(unsigned char fs) { // Set the default font size
  284. fontsize_ = fs;
  285. //format(); // removed
  286. }
  287. unsigned char textsize() const { // Get the default font size
  288. return fontsize_;
  289. }
  290. const char *title() { // Get the title string
  291. return title_;
  292. }
  293. void topline(const char *np);
  294. void topline(int yy);
  295. int topline() const { // Get the top line in document
  296. return topline_;
  297. }
  298. void leftline(int xx);
  299. int leftline() const { // Get the left line position
  300. return leftline_;
  301. }
  302. void value(const char *tp);
  303. const char *value() const { // Get the HTML text value
  304. return value_;
  305. }
  306. void clear_selection();
  307. void select_all();
  308. // new public functions
  309. int fileislink();
  310. void filepath(const char *fp);
  311. char *filepath();
  312. int font_face(const char *sp);
  313. int font_style(int fi, unsigned char fs);
  314. int gettopline();
  315. int handle(int event); // moved from private
  316. void monofont(int fi) { // set the default mono font
  317. monofont_ = fi;
  318. }
  319. int monofont() const { // get the default mono font
  320. return monofont_;
  321. }
  322. void reformat() { // format the help text - wrapper function
  323. format();
  324. }
  325. void sansfont(int fi) { // set the default sans font
  326. sansfont_ = fi;
  327. }
  328. int sansfont() const { // get the default sans font
  329. return sansfont_;
  330. }
  331. void serifont(int fi) { // set the default serif font
  332. serifont_ = fi;
  333. }
  334. int serifont() const { // get the default serif font
  335. return serifont_;
  336. }
  337. void setstyle(int flag);
  338. };
  339. #endif // !Fl_Help_View_H
  340. //
  341. // End of "$Id: Fl_Help_View.H 5991 2007-12-15 16:08:23Z mike $".
  342. //