source: trunk/include/helpers/textview.h@ 14

Last change on this file since 14 was 14, checked in by umoeller, 25 years ago

Major updates; timers, LVM, miscellaneous.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 20.1 KB
Line 
1
2/*
3 *@@sourcefile textview.h:
4 * header file for textview.c. See remarks there.
5 *
6 * Note: Version numbering in this file relates to XWorkplace version
7 * numbering.
8 */
9
10/* Copyright (C) 2000 Ulrich M”ller.
11 * This file is part of the "XWorkplace helpers" source package.
12 * This is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published
14 * by the Free Software Foundation, in version 2 as it comes in the
15 * "COPYING" file of the XWorkplace main distribution.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 *@@include #define INCL_SPL // for printing functions
22 *@@include #include <os2.h>
23 *@@include #include "linklist.h" // for device-independent functions
24 *@@include #include "xstring.h" // for device-independent functions
25 *@@include #include "textview.h"
26 */
27
28#if __cplusplus
29extern "C" {
30#endif
31
32#ifndef TEXTVIEW_HEADER_INCLUDED
33 #define TEXTVIEW_HEADER_INCLUDED
34
35 /* ******************************************************************
36 *
37 * Escape sequences
38 *
39 ********************************************************************/
40
41 /*
42 *@@ TXVESC_CHAR:
43 * general escape character which introduces
44 * all escape sequences.
45 */
46
47 #define TXVESC_CHAR '\xFF'
48 #define TXVESC_STRING "\xFF"
49
50 // fixed formatting tags: PRE, B, I U, STRIKE
51 // (no parameters)
52 /* #define TXVESC_PRE_BEGIN TXVESC_STRING "\x01\x01"
53 #define TXVESC_PRE_END TXVESC_STRING "\x01\x02" */
54
55 #define TXVESC_SET_FONT TXVESC_STRING "\x01"
56 // here follow three characters with the
57 // font index:
58 // e.g. "000" == default font
59 // "001" == monospaced font
60 // Fonts 0 and 1 always exist in the XTextView control.
61 // Other fonts are presently not supported.
62 // --> total size: 5
63
64 #define TXVESC_BOLD_BEGIN TXVESC_STRING "\x02\x01"
65 #define TXVESC_BOLD_END TXVESC_STRING "\x02\x02"
66
67 #define TXVESC_ITALICS_BEGIN TXVESC_STRING "\x03\x01"
68 #define TXVESC_ITALICS_END TXVESC_STRING "\x03\x02"
69
70 #define TXVESC_UNDERLINE_BEGIN TXVESC_STRING "\x04\x01"
71 #define TXVESC_UNDERLINE_END TXVESC_STRING "\x04\x02"
72
73 #define TXVESC_STRIKE_BEGIN TXVESC_STRING "\x05\x01"
74 #define TXVESC_STRIKE_END TXVESC_STRING "\x05\x02"
75
76 // links
77 #define TXVESC_LINK TXVESC_STRING "\x06"
78 // here follow four characters with the
79 // link index in hex (0001-FFFF);
80 // "####" means end of link
81 // --> total size: 6
82
83 #define TXVESC_ANCHORNAME TXVESC_STRING "\x07"
84 // here follows the anchor name, which is
85 // variable in length and must be terminated
86 // with another 0xFF escape code (NOT null byte);
87 // --> total size: 2 plus anchor name length
88 // plus 1 for 0xFF terminator
89
90 // character formatting with parameters:
91 #define TXVESC_POINTSIZE_REL TXVESC_STRING "\x10"
92 // here follow three characters with a percentage
93 // of the default point size
94 // e.g. "050" == half the size
95 // "200" == double the size
96 // --> total size: 5
97
98 /*
99 * paragraph formatting
100 * -- left and right margins:
101 */
102
103 #define TXVESC_LEFTMARGIN TXVESC_STRING "\x20"
104 // here follow four characters to specify the
105 // new first line left margin (XFMTPARAGRAPH.lLeftMargin),
106 // which is based on the average char width of
107 // the current font:
108 // e.g. "0020" == set margin to 20 average char widths
109 // --> total size: 6
110
111 #define TXVESC_FIRSTLINEMARGIN_LEFT TXVESC_STRING "\x21-"
112 #define TXVESC_FIRSTLINEMARGIN_RIGHT TXVESC_STRING "\x21+"
113 // here follow three characters to specify the
114 // new absolute left margin (XFMTPARAGRAPH.lFirstLineMargin)
115 // which is based on the average char width of
116 // the current font:
117 // e.g. "+020" == set first line margin to 20 average char widths
118 // e.g. "-020" == set first line margin to 20 average char widths
119 // --> total size: 6
120
121 #define TXVESC_TAB TXVESC_STRING "\x22"
122 // the tab can be used to move from the first line margin
123 // to the left margin, if the first line margin is negative;
124 // used with list items (UL LI and such)
125 // --> total size: 2
126
127 #define TXVESC_MARKER TXVESC_STRING "\x23"
128 // draw marker at the current position: the next byte
129 // determines the type of marker:
130 // -- 1: disc (filled circle)
131 // -- 2: square (filled box)
132 // -- 3: circle (hollow circle)
133 // --> total size: 3
134
135 /*
136 * paragraph formatting
137 * -- paragraph spacing:
138 */
139
140 #define TXVESC_SPACEBEFORE TXVESC_STRING "\x30"
141 #define TXVESC_SPACEAFTER TXVESC_STRING "\x31"
142 // here follow four characters to specify the
143 // new spacing before or after a paragraph:
144 // e.g. "0020" == twenty
145 // !! special case: "####" means reset to default
146 // --> total size: 6
147
148 #define TXVESC_WORDWRAP TXVESC_STRING "\x32"
149 // here follows a single character being "0" or "1"
150 // --> total size: 3
151
152 /* ******************************************************************
153 *
154 * Device-independent functions
155 *
156 ********************************************************************/
157
158 #define TXVWORDF_GLUEWITHNEXT 1 // escape
159 #define TXVWORDF_LINEBREAK 2 // \n
160 #define TXVWORDF_LINEFEED 4 // \r
161
162 /*
163 *@@ TXVWORD:
164 * this defines a "word" to be drawn. A word is
165 * normally a sequence of characters between
166 * space, \n, or \r characters, unless escape
167 * sequences come up. See txvFormatText.
168 *
169 *@@added V0.9.3 (2000-05-14) [umoeller]
170 */
171
172 typedef struct _TXVWORD
173 {
174 const char *pStart; // ptr into TEXTVIEWWINDATA.pszViewText
175 ULONG cChars; // characters in line to draw, starting
176 // at pStartOfLine;
177 // this might be less than the next \n
178 // char if word-wrapping has been enabled
179 // or an escape character was found
180
181 CHAR cEscapeCode;
182 // if 0, this word represents a substring to be painted
183 // ("normal word").
184 // If != 0; this "word" holds an escape sequence in *pStart
185 // which must be considered for paragraph formatting, but
186 // NOT be painted, except if fPaintEscapeWord is TRUE also.
187 // cEscapeCode then holds a copy of the escape character
188 // (which is pStart + 1).
189 BOOL fPaintEscapeWord;
190 // if this is TRUE, this escape is some special graphics
191 // to be painted also (e.g. list markers). txvPaint then
192 // evaluates the escape code (in pStart) to see what needs
193 // to be done.
194
195 // all the following are only set if (fIsEscapeSequence == FALSE):
196
197 ULONG ulFlags;
198 // one of the following:
199 // -- TXVWORDF_GLUEWITHNEXT: this "word" was cut because
200 // an escape sequence was found; this word must
201 // therefore be in the same line with the next word
202 // -- TXVWORDF_LINEBREAK: this word ends with a \n char;
203 // start new paragraph after this
204 // -- TXVWORDF_LINEFEED: this words ends with a \r char;
205 // start new line after this
206
207 ULONG ulCXWithSpaces, // width of word (in pels), including trailing spaces
208 ulCXWord, // width of word (in pels), without trailing spaces
209 ulCY; // height of word (in pels)
210
211 LONG lX; // X position to paint this word at;
212 // this is (re)set during word-to-rectangle correlation!
213 PVOID pvRectangle; // reverse pointer to the TXVRECTANGLE structure to
214 // which this word belongs; useful for repainting;
215 // this is (re)set during word-to-rectangle correlation!
216 ULONG ulBaseLineOfs; // base line offset; add this to rcl.yBottom
217 // to get the the start point to be used for
218 // GpiCharStringPosAt
219
220 LONG lcid; // logical font ID to use for this rectangle
221 LONG lPointSize; // point size to use for this rectangle;
222 // this is set to 0 for bitmap fonts
223 ULONG flOptions; // flOptions parameter for GpiCharStringPosAt;
224 // this will only have the CHS_UNDERSCORE or
225 // CHS_STRIKEOUT flags set
226
227 USHORT usAnchor; // != 0 if this word belongs to an anchor
228 } TXVWORD, *PTXVWORD;
229
230 #ifdef LINKLIST_HEADER_INCLUDED
231 /*
232 *@@ TXVRECTANGLE:
233 * this defines one line to be drawn.
234 * This is device-independent.
235 * See txvFormatText.
236 */
237
238 typedef struct _TXVRECTANGLE
239 {
240 RECTL rcl; // rectangle of this line, into which
241 // the words in llWords should be painted;
242 // the bottom of this rectangle specifies the
243 // bottommost point used (neccessary for
244 // characters with underlengths, such as
245 // "g" or "y"); ulMaxBaseLineOfs must be
246 // added to the starting point
247 // when using GpiCharStringPosAt
248 ULONG ulMaxBaseLineOfs; // highest ulBaseLineOfs of all words
249 // belonging to this rectangle.
250 LINKLIST llWords; // list of TXVWORD's which belong to this
251 // rectangle. Note that these are duplicate
252 // pointers to be able to correlate rectangles
253 // to words; there is a second list of TXVWORD's
254 // in XFORMATDATA which holds really all the
255 // words which were created (for cleanup).
256 // So one allocated TXVWORD structure can
257 // have two pointers pointing to it.
258 } TXVRECTANGLE, *PTXVRECTANGLE;
259 #endif
260
261 /*
262 *@@ XFMTFONT:
263 * specifies a font to be used in
264 * XFMTCHARACTER.
265 *
266 *@@added V0.9.3 (2000-05-06) [umoeller]
267 */
268
269 typedef struct _XFMTFONT
270 {
271 LONG lcid;
272 // default font to use for this paragraph
273 FONTMETRICS FontMetrics;
274 LONG alCX[256]; // width of each ASCII character for this
275 // string; computed by txvSetFormatFont
276 } XFMTFONT, *PXFMTFONT;
277
278 /*
279 *@@ XFMTCHARACTER:
280 * character formatting parameters.
281 * This is used by the formatting engine
282 * (txvFormat)
283 * to describe character formatting.
284 * Character formatting can only be
285 * changed between words (TXVWORD).
286 *
287 *@@added V0.9.3 (2000-05-06) [umoeller]
288 */
289
290 typedef struct _XFMTCHARACTER
291 {
292 LONG lPointSize;
293 // default font size to use for this paragraph
294 XFMTFONT fntRegular,
295 fntBold,
296 fntItalics,
297 fntBoldItalics;
298 } XFMTCHARACTER, *PXFMTCHARACTER;
299
300 /*
301 *@@ XFMTPARAGRAPH:
302 * paragraph formatting parameters.
303 * This is used by the formatting engine
304 * (txvFormat)
305 * for every paragraph which is started.
306 *
307 *@@added V0.9.3 (2000-05-06) [umoeller]
308 */
309
310 typedef struct _XFMTPARAGRAPH
311 {
312 BOOL fWordWrap;
313 LONG lLeftMargin,
314 // left indentation for all lines
315 // (in pixels)
316 lRightMargin,
317 // right indentation for all lines
318 // (in pixels)
319 lFirstLineMargin;
320 // additional indentation for first line only;
321 // this is added to lLeftMargin (can be negative)
322 // (in pixels)
323 LONG lSpaceBefore,
324 // space before each paragraph
325 // (in pixels)
326 lSpaceAfter;
327 // space after each paragraph
328 // (in pixels)
329 } XFMTPARAGRAPH, *PXFMTPARAGRAPH;
330
331 #ifdef LINKLIST_HEADER_INCLUDED
332 #ifdef XSTRING_HEADER_INCLUDED
333
334 /*
335 *@@ XFORMATDATA:
336 * text formatting data. Passed to
337 * txvPaintText, stored in TEXTVIEWWINDATA.
338 * This is device-independent.
339 */
340
341 typedef struct _XFORMATDATA
342 {
343 // input to txvFormatText
344 XSTRING strViewText; // original view text
345 // from WinSetWindowText
346
347 XFMTPARAGRAPH
348 fmtpStandard; // standard paragraph format
349
350 XFMTCHARACTER
351 fmtcStandard, // format for standard text
352 fmtcCode; // format for code text (monospaced; PRE, CODE etc.)
353
354 // output from txvFormatText
355 LINKLIST llRectangles;
356 // list of TXVRECTANGLE, from top to bottom;
357 // text pointers point into pszViewText
358 LINKLIST llWords;
359 // list of TXVWORD's, in order of creation;
360 // this is just for proper cleanup. The items
361 // in the TXVRECTANGLE.llWords list also point
362 // to the words stored in this list.
363
364 ULONG ulViewportCX, // width of viewport (total text space)
365 ulViewportCY; // height of viewport (total text space)
366
367 } XFORMATDATA, *PXFORMATDATA;
368
369 VOID txvInitFormat(PXFORMATDATA pxfd);
370
371 VOID txvFormatText(HPS hps,
372 PXFORMATDATA pxfd,
373 PRECTL prclView,
374 BOOL fFullRecalc);
375 #endif
376 #endif
377
378 VOID txvStripLinefeeds(char **ppszText,
379 ULONG ulTabSize);
380
381 /* ******************************************************************
382 *
383 * Window-dependent functions
384 *
385 ********************************************************************/
386
387 /*
388 * XTextView messages:
389 *
390 */
391
392 #define TXM_QUERYCHARFORMAT (WM_USER + 1022)
393 #define TXM_SETCHARFORMAT (WM_USER + 1023)
394 #define TXM_QUERYPARFORMAT (WM_USER + 1022)
395 #define TXM_SETPARFORMAT (WM_USER + 1023)
396 #define TXM_SETWORDWRAP (WM_USER + 1024)
397 #define TXM_QUERYCDATA (WM_USER + 1025)
398 #define TXM_SETCDATA (WM_USER + 1026)
399 #define TXM_JUMPTOANCHORNAME (WM_USER + 1027)
400
401 #define WC_XTEXTVIEW "XTextViewClass"
402
403 /*
404 * XTextView nofication codes:
405 *
406 */
407
408 /*
409 *@@ TXVN_LINK:
410 * WM_CONTROL notification code posted (!)
411 * to the XTextView control's owner.
412 *
413 * Parameters:
414 *
415 * -- USHORT SHORT1FROMMP(mp1): id of the control.
416 * -- USHORT SHORT2FROMMP(mp1): nofify code (TXVN_LINK).
417 * -- USHORT mp2: index of anchor (1 >= index > 0xFFFF).
418 *
419 *@@added V0.9.3 (2000-05-18) [umoeller]
420 */
421
422 #define TXVN_LINK 1
423
424 /*
425 * XTextView style flags:
426 *
427 */
428
429 #define XTXF_VSCROLL 0x0100
430 #define XTXF_HSCROLL 0x0200
431 #define XTXF_AUTOVHIDE 0x0400
432 #define XTXF_AUTOHHIDE 0x0800
433
434 /*
435 *@@ XTEXTVIEWCDATA:
436 * control data structure for text view
437 * control. This can be passed to
438 * WinCreateWindow with the pCtlData
439 * parameter. You then MUST set the
440 * "cbData" field to sizeof(XTEXTVIEWCDATA).
441 */
442
443 typedef struct _XTEXTVIEWCDATA
444 {
445 USHORT cbData;
446 ULONG flStyle;
447 // XTXF_* flags:
448 // -- XTXF_VSCROLL: show vertical scroll bar.
449 // -- XTXF_HSCROLL: show horizontal scroll bar.
450 // -- XTXF_AUTOVHIDE: with XTXF_VSCROLL: automatically hide scrollbar.
451 // -- XTXF_AUTOHHIDE: with XTXF_HSCROLL: automatically hide scrollbar.
452 ULONG ulXBorder,
453 // space to leave on the left and right of text view;
454 // defaults to 0
455 ulYBorder;
456 // space to leave on the top and bottom of text view;
457 // defaults to 0
458 ULONG ulVScrollLineUnit,
459 // pixels to scroll if scroll bar "up" or "down" button
460 // is pressed; defaults to 15
461 ulHScrollLineUnit;
462 // pixels to scroll if scroll bar "left" or "right" button
463 // is pressed; defaults to 15
464 } XTEXTVIEWCDATA, *PXTEXTVIEWCDATA;
465
466
467 BOOL txvRegisterTextView(HAB hab);
468
469 HWND txvReplaceWithTextView(HWND hwndParentAndOwner,
470 USHORT usID,
471 ULONG flWinStyle,
472 ULONG flStyle,
473 USHORT usBorder);
474
475 /* ******************************************************************
476 *
477 * Printer-dependent functions
478 *
479 ********************************************************************/
480
481 typedef BOOL APIENTRY FNPRINTCALLBACK(ULONG ulPage,
482 ULONG ulUser);
483
484 #ifdef INCL_SPL
485 BOOL txvPrint(HAB hab,
486 HDC hdc,
487 HPS hps,
488 PSZ pszViewText,
489 ULONG ulSize,
490 PSZ pszFaceName,
491 HCINFO *phci,
492 PSZ pszDocTitle,
493 FNPRINTCALLBACK *pfnCallback);
494 #endif
495
496 int txvPrintWindow(HWND hwndTextView,
497 PSZ pszDocTitle,
498 FNPRINTCALLBACK *pfnCallback);
499
500#endif
501
502#if __cplusplus
503}
504#endif
505
Note: See TracBrowser for help on using the repository browser.