1 | // |
---|
2 | // "$Id: HelpView.h 3491 2004-07-04 17:43:01Z laza2000 $" |
---|
3 | // |
---|
4 | // Help Viewer widget definitions. |
---|
5 | // |
---|
6 | // Copyright 1997-2003 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 to "fltk-bugs@fltk.org". |
---|
25 | // |
---|
26 | |
---|
27 | #ifndef HelpView_H |
---|
28 | # define HelpView_H |
---|
29 | |
---|
30 | // |
---|
31 | // Include necessary header files... |
---|
32 | // |
---|
33 | |
---|
34 | # include <stdio.h> |
---|
35 | # include <fltk/Group.h> |
---|
36 | # include <fltk/Scrollbar.h> |
---|
37 | # include <fltk/draw.h> |
---|
38 | # include <fltk/SharedImage.h> |
---|
39 | |
---|
40 | namespace fltk { |
---|
41 | |
---|
42 | // |
---|
43 | // HelpFunc type - link callback function for files... |
---|
44 | // |
---|
45 | |
---|
46 | |
---|
47 | typedef const char *(HelpFunc) (Widget *, const char *); |
---|
48 | |
---|
49 | |
---|
50 | // |
---|
51 | // HelpBlock structure... |
---|
52 | // |
---|
53 | |
---|
54 | struct HelpBlock { |
---|
55 | const char *start, // Start of text |
---|
56 | *end; // End of text |
---|
57 | uchar border; // Draw border? |
---|
58 | Color bgcolor; // Background color |
---|
59 | int x, // Indentation/starting X coordinate |
---|
60 | y, // Starting Y coordinate |
---|
61 | w, // Width |
---|
62 | h; // Height |
---|
63 | int line[32]; // Left starting position for each line |
---|
64 | }; |
---|
65 | |
---|
66 | // |
---|
67 | // HelpLink structure... |
---|
68 | // |
---|
69 | |
---|
70 | struct HelpLink { |
---|
71 | char filename[192], // Reference filename |
---|
72 | name[32]; // Link target (blank if none) |
---|
73 | int x, // X offset of link text |
---|
74 | y, // Y offset of link text |
---|
75 | w, // Width of link text |
---|
76 | h; // Height of link text |
---|
77 | }; |
---|
78 | |
---|
79 | // |
---|
80 | // HelpTarget structure... |
---|
81 | // |
---|
82 | |
---|
83 | struct HelpTarget { |
---|
84 | char name[32]; // Target name |
---|
85 | int y; // Y offset of target |
---|
86 | }; |
---|
87 | |
---|
88 | // |
---|
89 | // HelpView class... |
---|
90 | // |
---|
91 | |
---|
92 | class FL_IMAGES_API HelpView : public Group //// Help viewer widget |
---|
93 | { |
---|
94 | enum { RIGHT = -1, CENTER, LEFT }; // Alignments |
---|
95 | |
---|
96 | char title_[1024]; // Title string |
---|
97 | Color defcolor_, // Default text color |
---|
98 | bgcolor_, // Background color |
---|
99 | textcolor_, // Text color |
---|
100 | linkcolor_; // Link color |
---|
101 | Font *textfont_; // Default font for text |
---|
102 | int textsize_; // Default font size |
---|
103 | const char *value_; // HTML text value |
---|
104 | |
---|
105 | int nblocks_, // Number of blocks/paragraphs |
---|
106 | ablocks_; // Allocated blocks |
---|
107 | HelpBlock *blocks_; // Blocks |
---|
108 | |
---|
109 | int nfonts_; // Number of fonts in stack |
---|
110 | Font *fonts_[100]; // Font stack |
---|
111 | int fontsizes_[100]; |
---|
112 | |
---|
113 | HelpFunc *link_; // Link transform function |
---|
114 | |
---|
115 | int nlinks_, // Number of links |
---|
116 | alinks_; // Allocated links |
---|
117 | HelpLink *links_; // Links |
---|
118 | |
---|
119 | int ntargets_, // Number of targets |
---|
120 | atargets_; // Allocated targets |
---|
121 | HelpTarget *targets_; // Targets |
---|
122 | |
---|
123 | char directory_[1024]; // Directory for current file |
---|
124 | char filename_[1024]; // Current filename |
---|
125 | int topline_, // Top line in document |
---|
126 | leftline_, // Lefthand position |
---|
127 | size_, // Total document length |
---|
128 | hsize_; // Maximum document width |
---|
129 | Scrollbar *scrollbar_, // Vertical scrollbar for document |
---|
130 | *hscrollbar_; // Horizontal scrollbar |
---|
131 | |
---|
132 | HelpBlock *add_block (const char *s, int xx, int yy, int ww, int hh, |
---|
133 | uchar border = 0); |
---|
134 | void add_link (const char *n, int xx, int yy, int ww, int hh); |
---|
135 | void add_target (const char *n, int yy); |
---|
136 | static int compare_targets (const HelpTarget * t0, |
---|
137 | const HelpTarget * t1); |
---|
138 | int do_align (HelpBlock * block, int line, int xx, int a, int &l); |
---|
139 | void draw (); |
---|
140 | void format (); |
---|
141 | void format_table (int *table_width, int *columns, const char *table); |
---|
142 | int get_align (const char *p, int a); |
---|
143 | const char *get_attr (const char *p, const char *n, char *buf, int bufsize); |
---|
144 | Color get_color (const char *n, Color c); |
---|
145 | SharedImage *get_image (const char *name, int W, int H); |
---|
146 | int get_length (const char *l); |
---|
147 | int handle (int); |
---|
148 | |
---|
149 | void initfont (Font *&f, int &s) { |
---|
150 | nfonts_ = 0; |
---|
151 | f = fonts_[0] = textfont_; |
---|
152 | s = fontsizes_[0] = textsize_; |
---|
153 | setfont (f, (float)s-1); |
---|
154 | } |
---|
155 | void pushfont (Font *f, int s) { |
---|
156 | if (nfonts_ < 99) nfonts_++; |
---|
157 | fonts_[nfonts_] = f; |
---|
158 | fontsizes_[nfonts_] = s; |
---|
159 | setfont (f, (float)s-1); |
---|
160 | } |
---|
161 | void popfont (Font *&f, int &s) { |
---|
162 | if (nfonts_ > 0) nfonts_--; |
---|
163 | f = fonts_[nfonts_]; |
---|
164 | s = fontsizes_[nfonts_]; |
---|
165 | setfont(f, (float)s-1); |
---|
166 | } |
---|
167 | |
---|
168 | public: |
---|
169 | |
---|
170 | HelpView (int xx, int yy, int ww, int hh, const char *l = 0); |
---|
171 | |
---|
172 | ~HelpView (); |
---|
173 | const char *directory () const { |
---|
174 | if (directory_[0]) |
---|
175 | return (directory_); |
---|
176 | else |
---|
177 | return ((const char *) 0); |
---|
178 | } |
---|
179 | const char *filename () const { |
---|
180 | if (filename_[0]) |
---|
181 | return (filename_); |
---|
182 | else |
---|
183 | return ((const char *) 0); |
---|
184 | } void link (HelpFunc * fn) { |
---|
185 | link_ = fn; |
---|
186 | } |
---|
187 | int load (const char *f); |
---|
188 | void resize (int, int, int, int); |
---|
189 | void layout(); |
---|
190 | int size () const { return (size_); } |
---|
191 | void textcolor (Color c) { |
---|
192 | if (textcolor_ == defcolor_) |
---|
193 | textcolor_ = c; |
---|
194 | defcolor_ = c; |
---|
195 | } |
---|
196 | Color textcolor () const { return (defcolor_); } |
---|
197 | void textfont (Font *f) { |
---|
198 | textfont_ = f; |
---|
199 | format(); |
---|
200 | } |
---|
201 | Font *textfont () const { return (textfont_); } |
---|
202 | void textsize (int s) { |
---|
203 | textsize_ = s; |
---|
204 | format (); |
---|
205 | } |
---|
206 | int textsize () const { return (textsize_); } |
---|
207 | const char *title () { return (title_); } |
---|
208 | void topline (const char *n); |
---|
209 | void topline (int); |
---|
210 | int topline () const { return (topline_); } |
---|
211 | void leftline (int); |
---|
212 | int leftline () const { return (leftline_); } |
---|
213 | void value (const char *v); |
---|
214 | const char *value () const { return (value_); } |
---|
215 | }; |
---|
216 | |
---|
217 | } // namespace fltk |
---|
218 | |
---|
219 | #endif // !HelpView_H |
---|
220 | |
---|
221 | // |
---|
222 | // End of "$Id: HelpView.h 3491 2004-07-04 17:43:01Z laza2000 $". |
---|
223 | // |
---|