Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/vaclgui/helpview.hpp @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 * AnaGram, A System for Syntax Directed Programming | |
3 * Copyright 1997-2002 Parsifal Software. All Rights Reserved. | |
4 * See the file COPYING for license and usage terms. | |
5 * | |
6 * helpview.hpp | |
7 */ | |
8 | |
9 #ifndef HELPVIEW_HPP | |
10 #define HELPVIEW_HPP | |
11 | |
12 #include <icanvas.hpp> | |
13 #include <iclipbrd.hpp> | |
14 #include <icmdevt.hpp> | |
15 #include <icmdhdr.hpp> | |
16 //#include <icoordsy.hpp> | |
17 //#include <idrawcv.hpp> | |
18 //#include <iexcbase.hpp> | |
19 #include <ifont.hpp> | |
20 //#include <igbundle.hpp> | |
21 //#include <iglist.hpp> | |
22 //#include <igrafctx.hpp> | |
23 //#include <igstring.hpp> | |
24 #include <ipainhdr.hpp> | |
25 #include <ipainevt.hpp> | |
26 #include <ikeyhdr.hpp> | |
27 #include <ikeyevt.hpp> | |
28 #include <imenuevt.hpp> | |
29 #include <imenuhdr.hpp> | |
30 #include <imoushdr.hpp> | |
31 #include <imousevt.hpp> | |
32 #include <ipopmenu.hpp> | |
33 //#include <irefcnt.hpp> | |
34 #include <iscroll.hpp> | |
35 #include <iscrlevt.hpp> | |
36 #include <iscrlhdr.hpp> | |
37 //#include <isizeevt.hpp> | |
38 //#include <isizehdr.hpp> | |
39 //#include <ititle.hpp> | |
40 | |
41 class AgString; // from agstring.h | |
42 #include "agbaltree.h" | |
43 #include "cint.h" | |
44 #include "dict.h" | |
45 #include "digset.hpp" | |
46 #include "frame.hpp" | |
47 #include "search.h" | |
48 | |
49 | |
50 #if 0 | |
51 struct HelpId { | |
52 int index; | |
53 HelpId(int x) : index(x) {} | |
54 HelpId() : index(0) {} | |
55 int operator < (const HelpId id) const { | |
56 int flag = stricmp(dict_str(help_dict, index), | |
57 dict_str(help_dict, id.index)); | |
58 if (flag) { | |
59 return flag < 0; | |
60 } | |
61 return strcmp(dict_str(help_dict, index), | |
62 dict_str(help_dict, id.index)) < 0; | |
63 | |
64 } | |
65 operator int () { return index; } | |
66 }; | |
67 #endif | |
68 | |
69 class HelpWord : public DigSetter::Dig { | |
70 public: | |
71 enum Style { textStyle, linkStyle, usedStyle, titleStyle }; | |
72 HelpWord() {} | |
73 HelpWord(char *, int, cint, Style index = textStyle); | |
74 HelpWord(const HelpWord &); | |
75 | |
76 //int link; | |
77 AgString linktopic; | |
78 | |
79 int indent : 1; | |
80 int forceBreak : 1; | |
81 int noBreak : 1; | |
82 int linkTraversed: 1; | |
83 int highlight : 1; | |
84 int bullet : 1; | |
85 void moveTo(cint where_) { where = where_; } | |
86 IRectangle rect(DigSetter::Style *style); | |
87 int operator < (const HelpWord &x) const { return this < &x; } | |
88 }; | |
89 | |
90 | |
91 | |
92 class DrawingArea | |
93 : public IStaticText | |
94 , public ICommandHandler | |
95 , public IMenuHandler | |
96 , public IMouseHandler | |
97 , public IPaintHandler | |
98 , public AgHelpHandler | |
99 { | |
100 public: | |
101 DrawingArea(IWindow *, AgString); | |
102 ~DrawingArea(); | |
103 void reset(); | |
104 | |
105 ISize preferredSize; | |
106 int nLines; | |
107 int measure; | |
108 int spaceRequired; | |
109 IPopUpMenu popUpMenu; | |
110 | |
111 DrawingArea &initPopUp(); | |
112 DrawingArea &remeasureText(); | |
113 AgFrame *frameWindow; | |
114 | |
115 static AgBalancedTree<AgString> traversedLinks; | |
116 | |
117 char *highlightText; | |
118 int nHighlight; | |
119 DrawingArea &refreshWords(char *p, int n); | |
120 DrawingArea ©To(IClipboard &c); | |
121 | |
122 enum ButtonState { buttonIdle, buttonDown, waitingForClick }; | |
123 ButtonState rightButtonState; | |
124 | |
125 protected: | |
126 | |
127 Boolean DrawingArea::paintWindow(IPaintEvent &event); | |
128 Boolean command(ICommandEvent &event); | |
129 ISize calcMinimumSize() const; | |
130 | |
131 Boolean mouseClicked(IMouseClickEvent &event); | |
132 Boolean mouseMoved(IMouseEvent &event); | |
133 Boolean makePopUpMenu(IMenuEvent &event); | |
134 Boolean showHelp(IEvent &event); | |
135 | |
136 DrawingArea &measureText(); | |
137 AgString getHelpText(const char *topic); | |
138 AgArray<AgString> findLinks(AgString msg); | |
139 static AgArray<AgString> sortLinks(AgArray<AgString> links); | |
140 | |
141 virtual IFont font() const { | |
142 return FontSpec::help; | |
143 } | |
144 | |
145 int lineHeight() { | |
146 IFont &font = FontSpec::help; | |
147 return font.externalLeading() + font.maxSize().height(); | |
148 } | |
149 int maxCharWidth() { | |
150 IFont &font = FontSpec::help; | |
151 return font.maxSize().width(); | |
152 } | |
153 int avgCharWidth() { | |
154 IFont &font = FontSpec::help; | |
155 return font.avgCharWidth(); | |
156 } | |
157 int maxDescender() { | |
158 IFont &font = FontSpec::help; | |
159 return font.maxDescender(); | |
160 } | |
161 | |
162 DrawingArea &refreshLinks(); | |
163 void refreshAllLinks(); | |
164 | |
165 AgClassAction<DrawingArea> refreshAction; | |
166 | |
167 public: | |
168 AgString helpText; | |
169 AgString topic; | |
170 int myTextLength; | |
171 | |
172 AgStack<HelpWord> word; | |
173 int nWords; | |
174 static DigSetter::Style displayStyle[4]; | |
175 DigSetter setter; | |
176 int painting; | |
177 | |
178 private: | |
179 int fingerCursorSet; | |
180 IPointerHandle fingerCursor; | |
181 | |
182 IFont windowFont; | |
183 int longestLine; | |
184 int margin; | |
185 int paraIndent; | |
186 int paraLeading; | |
187 int helpShowing; | |
188 | |
189 AgArray<AgString> links; | |
190 AgArray<AgString> sortedLinks; | |
191 AgArray<int> linkedWords; | |
192 //static AgDictionary<DrawingArea *> activeViews; | |
193 static AgBalancedTree<DrawingArea *> activeViews; | |
194 | |
195 int charWidth[256]; | |
196 }; | |
197 | |
198 class AgHelpView | |
199 : public ICanvas | |
200 , public IKeyboardHandler | |
201 , public IResizeHandler | |
202 , public IScrollHandler | |
203 { | |
204 public: | |
205 static const int defaultWindowHeight; | |
206 | |
207 // Constructor | |
208 AgHelpView(IWindow *, AgString); | |
209 | |
210 // Destructor | |
211 ~AgHelpView(); | |
212 | |
213 ISize suggestSize(); | |
214 | |
215 AgHelpView &layout(); | |
216 AgHelpView &doLayout(); | |
217 AgHelpView &repositionWindow(); | |
218 | |
219 DrawingArea dataArea; | |
220 | |
221 SearchProcess searchProcess; | |
222 | |
223 virtual Boolean findNext(AgString); | |
224 virtual Boolean findPrev(AgString); | |
225 AgHelpView &positionWords(char *p, int n); | |
226 AgHelpView ©To(IClipboard &c) { | |
227 dataArea.copyTo(c); | |
228 return *this; | |
229 } | |
230 | |
231 protected: | |
232 | |
233 // Layout functions | |
234 | |
235 int lineHeight() { | |
236 IFont &font = FontSpec::help; | |
237 return font.externalLeading() + font.maxSize().height(); | |
238 } | |
239 int maxCharWidth() { | |
240 IFont &font = FontSpec::help; | |
241 return font.maxSize().width(); | |
242 } | |
243 int avgCharWidth() { | |
244 IFont &font = FontSpec::help; | |
245 return font.avgCharWidth(); | |
246 } | |
247 int maxDescender() { | |
248 IFont &font = FontSpec::help; | |
249 return font.maxDescender(); | |
250 } | |
251 | |
252 Boolean windowResize(IResizeEvent &event); | |
253 ISize calcMinimumSize() const; | |
254 | |
255 // Handler functions | |
256 | |
257 | |
258 // Keyboard handler | |
259 Boolean virtualKeyPress(IKeyboardEvent &); | |
260 | |
261 // Menu handler | |
262 | |
263 | |
264 // Scroll handler | |
265 | |
266 Boolean lineDown(IScrollEvent &); | |
267 Boolean lineUp(IScrollEvent &); | |
268 Boolean pageDown(IScrollEvent &); | |
269 Boolean pageUp(IScrollEvent &); | |
270 Boolean scrollBoxTrack(IScrollEvent &); | |
271 | |
272 private: | |
273 | |
274 public: | |
275 // child windows | |
276 IScrollBar verticalScrollBar; | |
277 | |
278 // window parameters | |
279 int windowId; | |
280 //IWindow *ownerWindow; | |
281 int highlightIndex; | |
282 | |
283 //layout state | |
284 Boolean vsbShowing; | |
285 int layoutActive; | |
286 | |
287 AgNotificationAction<AgHelpView> colorChange; | |
288 void onColorChange() { refresh(); } | |
289 AgNotificationAction<AgHelpView> fontChange; | |
290 void onFontChange(); | |
291 }; | |
292 | |
293 class AgHelpWindow | |
294 : public AgFrame | |
295 { | |
296 public: | |
297 AgHelpWindow(AgString); | |
298 ~AgHelpWindow(); | |
299 | |
300 // otherwise the compiler complains this is hidden | |
301 virtual int showHelp(IEvent &e) { return AgFrame::showHelp(e); } | |
302 | |
303 static Boolean AgHelpWindow::showHelp(AgString topic); | |
304 static Boolean AgHelpWindow::showHelpCentered(AgString topic); | |
305 | |
306 //private: | |
307 AgString copyTitleText; | |
308 | |
309 // Child Windows | |
310 AgHelpView helpView; | |
311 | |
312 public: | |
313 AgHelpWindow &setFocus() { | |
314 helpView.setFocus(); | |
315 return *this; | |
316 } | |
317 virtual Boolean findNext(AgString s) { | |
318 return helpView.findNext(s); | |
319 } | |
320 virtual Boolean findPrev(AgString s) { | |
321 return helpView.findPrev(s); | |
322 } | |
323 AgHelpWindow ©To(IClipboard &c) { | |
324 helpView.copyTo(c); | |
325 return *this; | |
326 } | |
327 AgString copyTitle() { return copyTitleText.pointer(); }; | |
328 }; | |
329 | |
330 | |
331 #endif /* HELPVIEW_HPP */ |