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

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

Initial checkin of helpers code, which used to be in WarpIN.

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