[8] | 1 |
|
---|
| 2 | /*
|
---|
| 3 | *@@sourcefile textview.c:
|
---|
| 4 | * all-new XTextView control as well as device-independent
|
---|
| 5 | * text formatting and printing. Whoa.
|
---|
| 6 | *
|
---|
| 7 | * <B>Text view control</B>
|
---|
| 8 | *
|
---|
| 9 | * This is a read-only control to display any given text
|
---|
| 10 | * (PSZ) in any given font. As opposed to a multi-line entry
|
---|
| 11 | * field (MLE), this can handle multiple fonts and character
|
---|
| 12 | * and paragraph formatting. Also, this thing sets its scroll
|
---|
| 13 | * bars right, which is one of the most annoying bugs in the
|
---|
| 14 | * MLE control.
|
---|
| 15 | *
|
---|
| 16 | * This is currently in the process of turning into a full-fledged
|
---|
| 17 | * "rich text" control. For example, the WarpIN "Readme" pages
|
---|
| 18 | * use this control.
|
---|
| 19 | *
|
---|
| 20 | * This is all new with V0.9.1. Great changes have been made
|
---|
| 21 | * with V0.9.3.
|
---|
| 22 | *
|
---|
| 23 | * To use the text view control, you must call txvRegisterTextView
|
---|
| 24 | * in your application first. This registers the WC_XTEXTVIEW
|
---|
| 25 | * window class with PM.
|
---|
| 26 | *
|
---|
| 27 | * Then create your XTextView using WinCreateWindow. The
|
---|
| 28 | * XTextView control has an XTEXTVIEWCDATA control data
|
---|
| 29 | * structure which optionally can be passed to WinCreateWindow
|
---|
| 30 | * like this:
|
---|
| 31 | *
|
---|
| 32 | + XTEXTVIEWCDATA xtxvCData;
|
---|
| 33 | + memset(&xtxvCData, 0, sizeof(xtxvCData));
|
---|
| 34 | + xtxvCData.cbData = sizeof(xtxvCData);
|
---|
| 35 | + xtxvCData.flStyle = XTXF_VSCROLL;
|
---|
| 36 | + xtxvCData.ulXBorder = 20;
|
---|
| 37 | + xtxvCData.ulYBorder = 20;
|
---|
| 38 | + G_hwndProcView = WinCreateWindow(hwndClient, // parent
|
---|
| 39 | + WC_XTEXTVIEW, // class
|
---|
| 40 | + "", // title, always ignored
|
---|
| 41 | + WS_VISIBLE, // style flags
|
---|
| 42 | + 0, 0, 100, 100, // pos and size
|
---|
| 43 | + hwndClient, // owner
|
---|
| 44 | + HWND_TOP, // z-order
|
---|
| 45 | + ID_PROCINFO, // win ID
|
---|
| 46 | + &xtxvCData, // control data
|
---|
| 47 | + 0); // presparams
|
---|
| 48 | +
|
---|
| 49 | * <B>Setting the text to be displayed</B>
|
---|
| 50 | *
|
---|
| 51 | * The text to be displayed must be passed to the control using
|
---|
| 52 | * the standard WinSetWindowText function (upon which PM sends a
|
---|
| 53 | * WM_SETWINDOWPARMS message to the control), which is then
|
---|
| 54 | * automatically formatted and painted.
|
---|
| 55 | *
|
---|
| 56 | * However, since the XTextView control is extremely capable,
|
---|
| 57 | * a few things need to be noted:
|
---|
| 58 | *
|
---|
| 59 | * -- The text view assumes that lines terminate with \n ONLY.
|
---|
| 60 | * The \r char is used for soft line breaks (start new line
|
---|
| 61 | * in the same paragraph, similar to the HTML BR tag). If
|
---|
| 62 | * you give the control the usual OS/2 \r\n sequence, you
|
---|
| 63 | * get large spacings. Use txvStripLinefeeds to strip the
|
---|
| 64 | * \r characters before setting the text.
|
---|
| 65 | *
|
---|
| 66 | * In short, to give the control any text, do this:
|
---|
| 67 | +
|
---|
| 68 | + PSZ psz = ... // whatever, load string
|
---|
| 69 | + txvStripLinefeeds(&psz); // reallocates
|
---|
| 70 | + WinSetWindowText(hwndTextView, psz);
|
---|
| 71 | *
|
---|
| 72 | * -- The control uses the \xFF (255) character internally as
|
---|
| 73 | * an escape code for formatting commands. See "Escape codes"
|
---|
| 74 | * below. If your text contains this character, you should
|
---|
| 75 | * overwrite all occurences with spaces, or they will be
|
---|
| 76 | * considered an escape code, which will cause problems.
|
---|
| 77 | *
|
---|
| 78 | * -- If you don't care about learning all the escape codes,
|
---|
| 79 | * you can automatically have HTML code converted to the
|
---|
| 80 | * XTextView format using txvConvertFromHTML, which will
|
---|
| 81 | * automatically insert all the codes right from plain
|
---|
| 82 | * HTML. In the above code, use txvConvertFromHTML instead
|
---|
| 83 | * of txvStripLinefeeds.
|
---|
| 84 | *
|
---|
| 85 | * <B>Code page support</B>
|
---|
| 86 | *
|
---|
| 87 | * The XTextView control assumes that the text given to it uses
|
---|
| 88 | * the same codepage as the message queue (thread) on which
|
---|
| 89 | * the control is running. So if you need codepage support,
|
---|
| 90 | * issue WinSetCp before creating the text view control.
|
---|
| 91 | *
|
---|
| 92 | * <B>Text formatting</B>
|
---|
| 93 | *
|
---|
| 94 | * The XTextView control has a default paragraph format which
|
---|
| 95 | * determines how text is formatted. If you don't change this
|
---|
| 96 | * format, the control performs no word-wrapping and displays
|
---|
| 97 | * all text "as is", that is, practically no formatting is
|
---|
| 98 | * performed.
|
---|
| 99 | *
|
---|
| 100 | * You can change the default paragraph format by sending
|
---|
| 101 | * TXM_SETPARFORMAT to the control. This takes a XFMTPARAGRAPH
|
---|
| 102 | * structure for input.
|
---|
| 103 | *
|
---|
| 104 | * To quickly enable word-wrapping only, we have the extra
|
---|
| 105 | * TXM_SETWORDWRAP message. This changes the word-wrapping flag
|
---|
| 106 | * in the default paragraph format only so you don't have to
|
---|
| 107 | * mess with all the rest.
|
---|
| 108 | *
|
---|
| 109 | * The XTextView control is extremely fast in formatting. It
|
---|
| 110 | * does pre-calculations once so that resizing the text
|
---|
| 111 | * window does not perform a full reformat, but a quick
|
---|
| 112 | * format based on the pre-calculations.
|
---|
| 113 | *
|
---|
| 114 | * Presently, formatting is done synchronously. It is planned
|
---|
| 115 | * to put formatting into a separate thread. Performance is
|
---|
| 116 | * acceptable already now unless very large texts (> 200 KB)
|
---|
| 117 | * are formatted (tested on a PII-400 machine).
|
---|
| 118 | *
|
---|
| 119 | * <B>Presentation Parameters</B>
|
---|
| 120 | *
|
---|
| 121 | * The XTextView control recognizes the following presentation
|
---|
| 122 | * parameters:
|
---|
| 123 | *
|
---|
| 124 | * -- PP_BACKGROUNDCOLOR; if not set, SYSCLR_DIALOGBACKGROUND
|
---|
| 125 | * (per default gray) is used.
|
---|
| 126 | *
|
---|
| 127 | * -- PP_FOREGROUNDCOLOR: if not set, SYSCLR_WINDOWSTATICTEXT
|
---|
| 128 | * (per default blue) is used to signify that the text
|
---|
| 129 | * cannot be worked on.
|
---|
| 130 | *
|
---|
| 131 | * -- PP_FONTNAMESIZE: default font. This is the system font,
|
---|
| 132 | * if not set.
|
---|
| 133 | *
|
---|
| 134 | * This implies that fonts and colors can be dropped on the
|
---|
| 135 | * control in the normal way. Font changes will cause a reformat.
|
---|
| 136 | *
|
---|
| 137 | * Changing those presentation parameters is equivalent to
|
---|
| 138 | * changing the corresponding fields in the default paragraph
|
---|
| 139 | * format using TXM_SETPARFORMAT.
|
---|
| 140 | *
|
---|
| 141 | * <B>Escape codes</B>
|
---|
| 142 | *
|
---|
| 143 | * All XTextView escape codes start with a \xFF (255) character,
|
---|
| 144 | * followed by at least one more character. The escape sequences
|
---|
| 145 | * are variable in length and can have parameters. For details,
|
---|
| 146 | * see textview.h where all these are listed.
|
---|
| 147 | *
|
---|
| 148 | * Escape codes are evaluated by txvFormatText during formatting.
|
---|
| 149 | *
|
---|
| 150 | * If you choose to give the text view control a text which
|
---|
| 151 | * contains escape codes, you better make sure that you get the
|
---|
| 152 | * exact codes right, or the text view control can crash. The
|
---|
| 153 | * control has been optimized for speed, so no checking is done
|
---|
| 154 | * on escape sequences.
|
---|
| 155 | *
|
---|
| 156 | * <B>Device-independent text formatting</B>
|
---|
| 157 | *
|
---|
| 158 | * If the features of the XTextView control satisfy your needs,
|
---|
| 159 | * there's not much to worry about. However, if you're interested
|
---|
| 160 | * in formatting the text yourself, here's more:
|
---|
| 161 | *
|
---|
| 162 | * This file has the txvFormatText function, which is capable
|
---|
| 163 | * of formatting an input string into any HPS. This works for
|
---|
| 164 | * windows (used by the text view control) and printers (used
|
---|
| 165 | * by txvPrint). Word-wrapping is supported. This is used by
|
---|
| 166 | * the XTextView control internally whenever (re)formatting is
|
---|
| 167 | * needed: either when the text is set or the formatting parameters
|
---|
| 168 | * (fonts, margins, etc.) have changed.
|
---|
| 169 | *
|
---|
| 170 | * These functions are designed to be used in a two-step process:
|
---|
| 171 | * first format the text (using txvFormatText), then paint it
|
---|
| 172 | * (using txvPaintText) for viewing or printing.
|
---|
| 173 | * This speeds up painting dramatically, because formatting
|
---|
| 174 | * might take some time.
|
---|
| 175 | *
|
---|
| 176 | * Note: Version numbering in this file relates to XWorkplace version
|
---|
| 177 | * numbering.
|
---|
| 178 | *
|
---|
| 179 | *@@header "helpers\textview.h"
|
---|
| 180 | *
|
---|
| 181 | *@@added V0.9.1 (2000-02-13) [umoeller]
|
---|
| 182 | */
|
---|
| 183 |
|
---|
| 184 | /*
|
---|
[374] | 185 | * Copyright (C) 2000-2008 Ulrich Mller.
|
---|
[8] | 186 | * This program is part of the XWorkplace package.
|
---|
| 187 | * This program is free software; you can redistribute it and/or modify
|
---|
| 188 | * it under the terms of the GNU General Public License as published by
|
---|
| 189 | * the Free Software Foundation, in version 2 as it comes in the COPYING
|
---|
| 190 | * file of the XWorkplace main distribution.
|
---|
| 191 | * This program is distributed in the hope that it will be useful,
|
---|
| 192 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 193 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 194 | * GNU General Public License for more details.
|
---|
| 195 | */
|
---|
| 196 |
|
---|
| 197 | #define OS2EMX_PLAIN_CHAR
|
---|
| 198 | // this is needed for "os2emx.h"; if this is defined,
|
---|
| 199 | // emx will define PSZ as _signed_ char, otherwise
|
---|
| 200 | // as unsigned char
|
---|
| 201 |
|
---|
| 202 | #define OS2EMX_PLAIN_CHAR
|
---|
| 203 | // this is needed for "os2emx.h"; if this is defined,
|
---|
| 204 | // emx will define PSZ as _signed_ char, otherwise
|
---|
| 205 | // as unsigned char
|
---|
| 206 |
|
---|
| 207 | #define INCL_WINWINDOWMGR
|
---|
| 208 | #define INCL_WINFRAMEMGR
|
---|
| 209 | #define INCL_WINMESSAGEMGR
|
---|
| 210 | #define INCL_WININPUT
|
---|
| 211 | #define INCL_WINRECTANGLES
|
---|
| 212 | #define INCL_WINPOINTERS
|
---|
| 213 | #define INCL_WINSYS
|
---|
| 214 | #define INCL_WINSCROLLBARS
|
---|
| 215 | #define INCL_WINSTDFONT
|
---|
| 216 | #define INCL_WINCOUNTRY
|
---|
| 217 |
|
---|
| 218 | #define INCL_DEV
|
---|
| 219 | #define INCL_SPL
|
---|
| 220 | #define INCL_SPLDOSPRINT
|
---|
| 221 |
|
---|
| 222 | #define INCL_GPIPRIMITIVES
|
---|
| 223 | #define INCL_GPILCIDS
|
---|
| 224 | #define INCL_GPILOGCOLORTABLE
|
---|
| 225 | #define INCL_GPITRANSFORMS
|
---|
| 226 | #define INCL_GPIREGIONS
|
---|
| 227 |
|
---|
| 228 | #define INCL_ERRORS
|
---|
| 229 | #include <os2.h>
|
---|
| 230 |
|
---|
| 231 | #include <stdlib.h>
|
---|
| 232 | #include <stdio.h>
|
---|
| 233 | #include <string.h>
|
---|
| 234 |
|
---|
| 235 | #include "setup.h" // code generation and debugging options
|
---|
| 236 |
|
---|
| 237 | #include "helpers\comctl.h"
|
---|
| 238 | #include "helpers\gpih.h"
|
---|
| 239 | #include "helpers\linklist.h"
|
---|
| 240 | #include "helpers\stringh.h"
|
---|
| 241 | #include "helpers\winh.h"
|
---|
| 242 | #include "helpers\xstring.h" // extended string helpers
|
---|
| 243 |
|
---|
| 244 | #include "helpers\textview.h"
|
---|
[201] | 245 | #include "helpers\textv_html.h"
|
---|
[8] | 246 |
|
---|
| 247 | #pragma hdrstop
|
---|
| 248 |
|
---|
| 249 | /*
|
---|
| 250 | *@@category: Helpers\PM helpers\Window classes\XTextView control
|
---|
| 251 | * See textview.c.
|
---|
| 252 | */
|
---|
| 253 |
|
---|
| 254 | /* ******************************************************************
|
---|
[14] | 255 | *
|
---|
| 256 | * Device-independent functions
|
---|
| 257 | *
|
---|
[8] | 258 | ********************************************************************/
|
---|
| 259 |
|
---|
| 260 | /*
|
---|
| 261 | *@@ txvInitFormat:
|
---|
| 262 | *
|
---|
| 263 | */
|
---|
| 264 |
|
---|
| 265 | VOID txvInitFormat(PXFORMATDATA pxfd)
|
---|
| 266 | {
|
---|
| 267 | memset(pxfd, 0, sizeof(XFORMATDATA));
|
---|
| 268 | lstInit(&pxfd->llRectangles,
|
---|
| 269 | TRUE); // auto-free items
|
---|
| 270 | lstInit(&pxfd->llWords,
|
---|
| 271 | TRUE); // auto-free items
|
---|
[375] | 272 | xstrInit(&pxfd->strOrigText, 0); // WarpIN V1.0.18
|
---|
[12] | 273 | xstrInit(&pxfd->strViewText, 0);
|
---|
[8] | 274 | }
|
---|
| 275 |
|
---|
| 276 | /*
|
---|
| 277 | *@@ SetSubFont:
|
---|
| 278 | *
|
---|
| 279 | *@@added V0.9.3 (2000-05-06) [umoeller]
|
---|
| 280 | */
|
---|
| 281 |
|
---|
[222] | 282 | STATIC VOID SetSubFont(HPS hps,
|
---|
[142] | 283 | PXFMTFONT pFont,
|
---|
| 284 | ULONG ulPointSize,
|
---|
| 285 | PSZ pszFaceName,
|
---|
| 286 | ULONG flFormat)
|
---|
[8] | 287 | {
|
---|
| 288 | CHAR ac[256];
|
---|
| 289 | ULONG ul;
|
---|
| 290 | POINTL ptlStart = {0, 0},
|
---|
| 291 | aptl[257];
|
---|
| 292 |
|
---|
| 293 | if (pFont->lcid)
|
---|
| 294 | {
|
---|
| 295 | // font already loaded:
|
---|
| 296 | if (GpiQueryCharSet(hps) == pFont->lcid)
|
---|
| 297 | // font currently selected:
|
---|
| 298 | GpiSetCharSet(hps, LCID_DEFAULT);
|
---|
| 299 | GpiDeleteSetId(hps, pFont->lcid);
|
---|
| 300 |
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 | if (pszFaceName)
|
---|
| 304 | pFont->lcid = gpihFindFont(hps,
|
---|
| 305 | ulPointSize,
|
---|
| 306 | TRUE, // family, not face name
|
---|
| 307 | pszFaceName,
|
---|
| 308 | flFormat,
|
---|
| 309 | &pFont->FontMetrics);
|
---|
| 310 | else
|
---|
| 311 | pFont->lcid = LCID_DEFAULT; // 0
|
---|
| 312 |
|
---|
| 313 | GpiSetCharSet(hps, pFont->lcid);
|
---|
| 314 | if (pFont->FontMetrics.fsDefn & FM_DEFN_OUTLINE)
|
---|
| 315 | // is outline font:
|
---|
| 316 | gpihSetPointSize(hps, ulPointSize);
|
---|
| 317 |
|
---|
| 318 | for (ul = 0;
|
---|
| 319 | ul < 256;
|
---|
| 320 | ul++)
|
---|
| 321 | ac[ul] = ul;
|
---|
| 322 |
|
---|
| 323 | GpiQueryCharStringPosAt(hps,
|
---|
| 324 | &ptlStart,
|
---|
| 325 | 0,
|
---|
| 326 | 254, // starting at one
|
---|
| 327 | ac + 1, // starting at one
|
---|
| 328 | NULL,
|
---|
| 329 | aptl);
|
---|
| 330 | // now compute width of every char
|
---|
| 331 | for (ul = 1;
|
---|
| 332 | ul < 256;
|
---|
| 333 | ul++)
|
---|
| 334 | {
|
---|
| 335 | pFont->alCX[ul] = aptl[ul+1].x - aptl[ul].x;
|
---|
| 336 | }
|
---|
| 337 | }
|
---|
| 338 |
|
---|
| 339 | /*
|
---|
[142] | 340 | *@@ SetFormatFont:
|
---|
[8] | 341 | * creates logical fonts from the specified
|
---|
| 342 | * font information.
|
---|
| 343 | *
|
---|
| 344 | *@@added V0.9.3 (2000-05-06) [umoeller]
|
---|
| 345 | */
|
---|
| 346 |
|
---|
[222] | 347 | STATIC VOID SetFormatFont(HPS hps, // in: HPS to select default font into
|
---|
[142] | 348 | PXFMTCHARACTER pxfmtc, // in/out: format data
|
---|
| 349 | ULONG ulPointSize, // in: font point size (e.g. 12) or 0
|
---|
| 350 | PSZ pszFaceName) // in: font face name (e.g. "Courier") or NULL
|
---|
[8] | 351 | {
|
---|
| 352 | pxfmtc->lPointSize = ulPointSize;
|
---|
| 353 |
|
---|
| 354 | // regular
|
---|
| 355 | SetSubFont(hps,
|
---|
| 356 | &pxfmtc->fntRegular,
|
---|
| 357 | ulPointSize,
|
---|
| 358 | pszFaceName,
|
---|
| 359 | 0);
|
---|
| 360 |
|
---|
| 361 | // bold
|
---|
| 362 | SetSubFont(hps,
|
---|
| 363 | &pxfmtc->fntBold,
|
---|
| 364 | ulPointSize,
|
---|
| 365 | pszFaceName,
|
---|
| 366 | FATTR_SEL_BOLD);
|
---|
| 367 |
|
---|
| 368 | // italics
|
---|
| 369 | SetSubFont(hps,
|
---|
| 370 | &pxfmtc->fntItalics,
|
---|
| 371 | ulPointSize,
|
---|
| 372 | pszFaceName,
|
---|
| 373 | FATTR_SEL_ITALIC);
|
---|
| 374 |
|
---|
| 375 | // bold italics
|
---|
| 376 | SetSubFont(hps,
|
---|
| 377 | &pxfmtc->fntBoldItalics,
|
---|
| 378 | ulPointSize,
|
---|
| 379 | pszFaceName,
|
---|
| 380 | FATTR_SEL_BOLD | FATTR_SEL_ITALIC);
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 | /*
|
---|
| 384 | *@@ AppendCharNoCheck:
|
---|
| 385 | *
|
---|
| 386 | *@@added V0.9.3 (2000-05-07) [umoeller]
|
---|
| 387 | */
|
---|
| 388 |
|
---|
[222] | 389 | STATIC VOID AppendCharNoCheck(char **ppszNew,
|
---|
[142] | 390 | PULONG pcbNew,
|
---|
| 391 | char **ppTarget,
|
---|
| 392 | char c)
|
---|
[8] | 393 | {
|
---|
| 394 | ULONG cbSizeThis = *ppTarget - *ppszNew;
|
---|
| 395 | if (cbSizeThis >= *pcbNew)
|
---|
| 396 | {
|
---|
| 397 | // more mem needed:
|
---|
| 398 | *pcbNew += 10000;
|
---|
| 399 | *ppszNew = (PSZ)realloc(*ppszNew, *pcbNew);
|
---|
| 400 | // if first call, pszNew is NULL, and realloc
|
---|
| 401 | // behaves just like malloc
|
---|
| 402 | // adjust target, because ptr might have changed
|
---|
| 403 | *ppTarget = *ppszNew + cbSizeThis;
|
---|
| 404 | }
|
---|
| 405 |
|
---|
| 406 | **ppTarget = c;
|
---|
| 407 | (*ppTarget)++;
|
---|
| 408 | }
|
---|
| 409 |
|
---|
| 410 | /*
|
---|
| 411 | *@@ txvStripLinefeeds:
|
---|
| 412 | * this removes all linefeeds (\r) from
|
---|
| 413 | * the specified string to prepare it
|
---|
| 414 | * for display with the text view control.
|
---|
| 415 | *
|
---|
| 416 | * This also replaces tabs (\t) with ulTabSize spaces.
|
---|
| 417 | *
|
---|
| 418 | * The buffer gets reallocated by this function, so it
|
---|
| 419 | * must be free()'able.
|
---|
| 420 | *
|
---|
| 421 | *@@added V0.9.3 (2000-05-07) [umoeller]
|
---|
[201] | 422 | *@@changed V0.9.20 (2002-08-10) [umoeller]: now stripping \xFF too
|
---|
[375] | 423 | *@@changed V1.0.18 (2008-11-24) [pr]: fixes \xFF stripping @@fixes 1116
|
---|
[8] | 424 | */
|
---|
| 425 |
|
---|
| 426 | VOID txvStripLinefeeds(char **ppszText,
|
---|
| 427 | ULONG ulTabSize)
|
---|
| 428 | {
|
---|
[201] | 429 | PSZ pSource = *ppszText;
|
---|
| 430 | ULONG cbNew = 1000;
|
---|
| 431 | PSZ pszNew = (PSZ)malloc(cbNew);
|
---|
| 432 | PSZ pTarget = pszNew;
|
---|
| 433 | ULONG ul;
|
---|
[8] | 434 |
|
---|
| 435 | while (*pSource)
|
---|
| 436 | {
|
---|
[201] | 437 | switch (*pSource)
|
---|
[8] | 438 | {
|
---|
[201] | 439 | case '\r':
|
---|
| 440 | pSource++;
|
---|
| 441 | break;
|
---|
| 442 |
|
---|
| 443 | case '\t':
|
---|
| 444 | for (ul = 0;
|
---|
| 445 | ul < ulTabSize;
|
---|
| 446 | ul++)
|
---|
| 447 | AppendCharNoCheck(&pszNew,
|
---|
| 448 | &cbNew,
|
---|
| 449 | &pTarget,
|
---|
| 450 | ' ');
|
---|
| 451 |
|
---|
| 452 | // skip the tab
|
---|
| 453 | pSource++;
|
---|
| 454 | break;
|
---|
| 455 |
|
---|
[375] | 456 | case TXVESC_CHAR: // V0.9.20 (2002-08-10) [umoeller]
|
---|
[8] | 457 | AppendCharNoCheck(&pszNew,
|
---|
| 458 | &cbNew,
|
---|
| 459 | &pTarget,
|
---|
| 460 | ' ');
|
---|
[375] | 461 | pSource += 3; // V1.0.18
|
---|
[201] | 462 | break;
|
---|
[8] | 463 |
|
---|
[201] | 464 | default:
|
---|
| 465 | AppendCharNoCheck(&pszNew,
|
---|
| 466 | &cbNew,
|
---|
| 467 | &pTarget,
|
---|
| 468 | *pSource++);
|
---|
[8] | 469 | }
|
---|
| 470 | }
|
---|
[201] | 471 |
|
---|
[8] | 472 | AppendCharNoCheck(&pszNew,
|
---|
| 473 | &cbNew,
|
---|
| 474 | &pTarget,
|
---|
| 475 | '\n');
|
---|
| 476 | AppendCharNoCheck(&pszNew,
|
---|
| 477 | &cbNew,
|
---|
| 478 | &pTarget,
|
---|
| 479 | 0);
|
---|
| 480 |
|
---|
| 481 | free(*ppszText);
|
---|
| 482 | *ppszText = pszNew;
|
---|
| 483 | }
|
---|
| 484 |
|
---|
| 485 | /* ******************************************************************
|
---|
[14] | 486 | *
|
---|
| 487 | * Device-independent text formatting
|
---|
| 488 | *
|
---|
[8] | 489 | ********************************************************************/
|
---|
| 490 |
|
---|
| 491 | /*
|
---|
| 492 | *@@ strhFindEOL2:
|
---|
| 493 | * finds the end of a line.
|
---|
| 494 | *
|
---|
| 495 | * An "end of line" means the next \r, \n, or \0 character
|
---|
| 496 | * after *ppszSearchIn.
|
---|
| 497 | *
|
---|
| 498 | * This returns the pointer to that exact character, which
|
---|
| 499 | * can be equal or higher than *ppszSearchIn.
|
---|
| 500 | * This should never return NULL because at some point,
|
---|
| 501 | * there will be a null byte in your string (unless you have
|
---|
| 502 | * a heap problem).
|
---|
| 503 | *
|
---|
| 504 | * If the EOL character is not null (\0), *ppszSearchIN is
|
---|
| 505 | * advanced to the first character of the _next_ line. This
|
---|
| 506 | * can be the EOL pointer plus one if you have a UNIX-style
|
---|
| 507 | * string (\n only at the end of each line) or EOL + 2 for
|
---|
| 508 | * DOS and OS/2-style EOLs (which have \r\n at the end of
|
---|
| 509 | * each line).
|
---|
| 510 | *
|
---|
| 511 | *@added V0.9.3 (2000-05-06) [umoeller]
|
---|
| 512 | */
|
---|
| 513 |
|
---|
[222] | 514 | STATIC PSZ strhFindEOL2(PSZ *ppszSearchIn, // in: where to search
|
---|
[142] | 515 | PULONG pulOffset) // out: offset (ptr can be NULL)
|
---|
[8] | 516 | {
|
---|
| 517 | PSZ pThis = *ppszSearchIn,
|
---|
| 518 | prc = NULL;
|
---|
| 519 | while (TRUE)
|
---|
| 520 | {
|
---|
| 521 | if ( (*pThis == '\r') || (*pThis == '\n') || (*pThis == 0) )
|
---|
| 522 | {
|
---|
| 523 | prc = pThis;
|
---|
| 524 | break;
|
---|
| 525 | }
|
---|
| 526 | pThis++;
|
---|
| 527 | }
|
---|
| 528 |
|
---|
| 529 | // before modifying pointer, store offset
|
---|
| 530 | if (pulOffset)
|
---|
| 531 | *pulOffset = prc - *ppszSearchIn;
|
---|
| 532 |
|
---|
| 533 | if (*prc == 0)
|
---|
| 534 | {
|
---|
| 535 | // null byte (end of string):
|
---|
| 536 | *ppszSearchIn = prc;
|
---|
| 537 | }
|
---|
| 538 | else
|
---|
| 539 | {
|
---|
| 540 | // not null byte (end of string):
|
---|
| 541 | // skip following newline characters
|
---|
| 542 | if (*prc == '\r')
|
---|
| 543 | {
|
---|
| 544 | if ( *(prc+1) == '\n')
|
---|
| 545 | // we have a \r char next,
|
---|
| 546 | // that's the DOS and OS/2 format (\r\n):
|
---|
| 547 | // skip that too
|
---|
| 548 | *ppszSearchIn = prc + 2;
|
---|
| 549 | else
|
---|
| 550 | *ppszSearchIn = prc + 1;
|
---|
| 551 | }
|
---|
| 552 | else if (*prc == '\n')
|
---|
| 553 | // UNIX format (used by HTML formatter also):
|
---|
| 554 | *ppszSearchIn = prc + 1;
|
---|
| 555 | }
|
---|
| 556 |
|
---|
| 557 | // now:
|
---|
| 558 | // 1) prc points to the \r, \n, or \0 character (EOL)
|
---|
| 559 | // 2) *ppszSearchIn has been advanced to the first character
|
---|
| 560 | // of the next line or points to the \0 character
|
---|
| 561 |
|
---|
[201] | 562 | return prc;
|
---|
[8] | 563 | }
|
---|
| 564 |
|
---|
| 565 | /* #define TXVFRECTF_EMPTY 0x0001
|
---|
| 566 | #define TXVFRECTF_PARAGRAPHDONE 0x0002
|
---|
| 567 | #define TXVFRECTF_WORDSLEFT 0x0004
|
---|
| 568 | #define TXVFRECTF_STOPPEDONESCAPE 0x0008
|
---|
| 569 | #define TXVFRECTF_ENDOFTEXT 0x0010
|
---|
| 570 | */
|
---|
[201] | 571 |
|
---|
[8] | 572 | /*
|
---|
| 573 | *@@ FORMATLINEBUF:
|
---|
| 574 | * worker structure to store various data
|
---|
[142] | 575 | * in txvFormatText in between CreateWord
|
---|
[8] | 576 | * calls. This has been created for speed
|
---|
| 577 | * so we don't have to pass all these on
|
---|
| 578 | * the stack all the time.
|
---|
| 579 | *
|
---|
| 580 | *@@added V0.9.3 (2000-05-06) [umoeller]
|
---|
| 581 | */
|
---|
| 582 |
|
---|
| 583 | typedef struct _FORMATLINEBUF
|
---|
| 584 | {
|
---|
| 585 | PSZ pLastChar; // ptr to null terminator in text
|
---|
| 586 |
|
---|
| 587 | // formatting data; this is set by txvFormatText according
|
---|
| 588 | // to escape characters and read by txvCreateRectangle
|
---|
| 589 | XFMTPARAGRAPH fmtp;
|
---|
| 590 | PXFMTCHARACTER pfmtc; // pointer to character formatting data
|
---|
| 591 | PXFMTFONT pfmtf; // pointer to font to use
|
---|
| 592 |
|
---|
| 593 | BOOL fPre,
|
---|
| 594 | fBold,
|
---|
| 595 | fItalics;
|
---|
| 596 |
|
---|
| 597 | // current anchor
|
---|
[206] | 598 | PCSZ pcszCurrentLinkTarget;
|
---|
[201] | 599 | // this is != NULL if we're currently in a link block
|
---|
| 600 | // and points to an item in XFORMATDATA.llLinks
|
---|
| 601 | // (simply copied to the word structs that are created)
|
---|
[8] | 602 |
|
---|
| 603 | // data copied to TXVWORD
|
---|
| 604 | LONG lcid;
|
---|
| 605 | LONG lPointSize;
|
---|
[201] | 606 | ULONG flChar; // any combination of CHS_UNDERSCORE and CHS_STRIKEOUT
|
---|
[8] | 607 |
|
---|
| 608 | // counters, ...
|
---|
| 609 | LONG lXCurrent; // current X position while adding words to rectangle
|
---|
| 610 | } FORMATLINEBUF, *PFORMATLINEBUF;
|
---|
| 611 |
|
---|
| 612 | /*
|
---|
[142] | 613 | *@@ CreateWord:
|
---|
[8] | 614 | *
|
---|
| 615 | * -- If the word ends with one or several spaces,
|
---|
| 616 | * ppStartOfWord is set to the beginning of the
|
---|
| 617 | * next word (non-space character).
|
---|
| 618 | * pWord->ulFlags is set to 0.
|
---|
| 619 | *
|
---|
| 620 | * -- If the word ends with an escape character,
|
---|
| 621 | * ppStartOfWord is set to point to the escape,
|
---|
| 622 | * which must be handled by the caller.
|
---|
| 623 | * pWord->ulFlags is set to TXVWORDF_GLUEWITHNEXT.
|
---|
| 624 | *
|
---|
| 625 | * -- If the word ends with a \n or \r,
|
---|
| 626 | * ppStartOfWord is set to the beginning of the
|
---|
| 627 | * next line (first char after \n or \r). This
|
---|
| 628 | * may be another \n or \r, but the first one
|
---|
| 629 | * is skipped.
|
---|
| 630 | * pWord->ulFlags is set to TXVWORDF_LINEBREAK or
|
---|
| 631 | * TXVWORDF_LINEFEED.
|
---|
| 632 | *
|
---|
| 633 | *@@added V0.9.3 (2000-05-14) [umoeller]
|
---|
[201] | 634 | *@@changed V0.9.20 (2002-08-10) [umoeller]: rewrote link implementation
|
---|
[8] | 635 | */
|
---|
| 636 |
|
---|
[222] | 637 | STATIC PTXVWORD CreateWord(HPS hps,
|
---|
[142] | 638 | PSZ *ppStartOfWord,
|
---|
| 639 | PFORMATLINEBUF pflbuf)
|
---|
[8] | 640 | {
|
---|
| 641 | PTXVWORD pWord = NULL;
|
---|
| 642 |
|
---|
| 643 | // find next word:
|
---|
| 644 | if (**ppStartOfWord)
|
---|
| 645 | {
|
---|
| 646 | PSZ pWordStart = *ppStartOfWord,
|
---|
| 647 | pWordEnd = NULL;
|
---|
| 648 | PSZ pCheck = *ppStartOfWord;
|
---|
[91] | 649 | ULONG cChars = 0;
|
---|
| 650 | // cCheck = 0;
|
---|
[8] | 651 |
|
---|
| 652 | pWord = (PTXVWORD)malloc(sizeof(TXVWORD));
|
---|
| 653 | memset(pWord, 0, sizeof(TXVWORD));
|
---|
| 654 | // this includes fIsEscapeSequence = FALSE;
|
---|
| 655 | pWord->pStart = pWordStart;
|
---|
| 656 |
|
---|
| 657 | // initially, this has pWordStart pointing
|
---|
| 658 | // to *ppStartOfWord. If a word is found,
|
---|
| 659 | // pWordStart is set to the first char of
|
---|
| 660 | // the word and pWordEnd receives the
|
---|
| 661 | // pointer to the first character after the word (probably space)
|
---|
| 662 | if (strhGetWord(&pWordStart, // in/out
|
---|
| 663 | pflbuf->pLastChar,
|
---|
| 664 | " ",
|
---|
| 665 | "\x0d\x0a \xFF", // in: end chars; includes our escape!
|
---|
| 666 | &pWordEnd)) // out: first char after word
|
---|
| 667 | {
|
---|
| 668 | // whoa, found a word:
|
---|
| 669 | while (*pWordEnd == ' ')
|
---|
| 670 | pWordEnd++;
|
---|
| 671 |
|
---|
| 672 | cChars = (pWordEnd - *ppStartOfWord);
|
---|
| 673 | }
|
---|
| 674 |
|
---|
| 675 | if (cChars)
|
---|
| 676 | {
|
---|
| 677 | POINTL aptlText[TXTBOX_COUNT];
|
---|
| 678 | // cChars is != 0 if strhGetWord succeeded AND the
|
---|
| 679 | // line is not empty, so go on
|
---|
[91] | 680 | // cCheck = cChars;
|
---|
[8] | 681 |
|
---|
| 682 | // advance input pointer
|
---|
| 683 | *ppStartOfWord = pWordEnd;
|
---|
| 684 |
|
---|
| 685 | GpiQueryTextBox(hps,
|
---|
| 686 | // no. of chars since start of word:
|
---|
| 687 | cChars,
|
---|
| 688 | // first char:
|
---|
| 689 | pCheck,
|
---|
| 690 | TXTBOX_COUNT,
|
---|
| 691 | (PPOINTL)&aptlText);
|
---|
| 692 |
|
---|
| 693 | pWord->cChars = cChars;
|
---|
| 694 | pWord->ulFlags = 0;
|
---|
| 695 |
|
---|
| 696 | if (cChars)
|
---|
| 697 | pWord->ulCXWithSpaces = aptlText[TXTBOX_TOPRIGHT].x;
|
---|
| 698 | else
|
---|
| 699 | pWord->ulCXWithSpaces = 0;
|
---|
| 700 |
|
---|
| 701 | pWord->ulCY = aptlText[TXTBOX_TOPRIGHT].y
|
---|
| 702 | - aptlText[TXTBOX_BOTTOMRIGHT].y;
|
---|
| 703 | // store base line ofs; aptlText[TXTBOX_BOTTOMRIGHT].y is negative
|
---|
| 704 | // if the string has any characters drawn below the base line, e.g.
|
---|
| 705 | // for the "g" and "y" characters
|
---|
| 706 | pWord->ulBaseLineOfs = -aptlText[TXTBOX_BOTTOMRIGHT].y;
|
---|
| 707 | }
|
---|
| 708 | else
|
---|
| 709 | {
|
---|
| 710 | // no word found or empty line:
|
---|
| 711 | pWord->ulCY = pflbuf->pfmtf->FontMetrics.lMaxBaselineExt;
|
---|
| 712 | }
|
---|
| 713 |
|
---|
| 714 | switch (**ppStartOfWord)
|
---|
| 715 | {
|
---|
| 716 | case TXVESC_CHAR: // '\xFF':
|
---|
| 717 | pWord->ulFlags = TXVWORDF_GLUEWITHNEXT;
|
---|
| 718 | break;
|
---|
| 719 |
|
---|
| 720 | case '\n':
|
---|
| 721 | pWord->ulFlags = TXVWORDF_LINEBREAK;
|
---|
| 722 | (*ppStartOfWord)++; // skip \n
|
---|
| 723 | break;
|
---|
| 724 |
|
---|
| 725 | case '\r':
|
---|
| 726 | pWord->ulFlags = TXVWORDF_LINEFEED;
|
---|
| 727 | (*ppStartOfWord)++; // skip \r
|
---|
| 728 | break;
|
---|
| 729 | }
|
---|
| 730 |
|
---|
| 731 | pWord->lcid = pflbuf->pfmtf->lcid;
|
---|
| 732 | pWord->lPointSize = pflbuf->lPointSize;
|
---|
[201] | 733 | pWord->flChar = pflbuf->flChar;
|
---|
[8] | 734 |
|
---|
[206] | 735 | pWord->pcszLinkTarget = pflbuf->pcszCurrentLinkTarget; // 0 if none
|
---|
[8] | 736 | }
|
---|
| 737 |
|
---|
[201] | 738 | return pWord;
|
---|
[8] | 739 | }
|
---|
| 740 |
|
---|
| 741 | /*
|
---|
| 742 | *@@ ProcessEscapes:
|
---|
| 743 | * gets called when txvFormatText stops on an
|
---|
| 744 | * escape character (\xFF). This evaluates the
|
---|
| 745 | * escape sequence, reacts accordingly, and
|
---|
| 746 | * advances *ppCurrent to after the escape
|
---|
| 747 | * sequence so that regular processing can
|
---|
| 748 | * continue.
|
---|
| 749 | *
|
---|
| 750 | * There are two types of escape sequences:
|
---|
| 751 | *
|
---|
| 752 | * -- Those which are only relevant during word processing,
|
---|
| 753 | * such as character formatting attributes (bold, italics,
|
---|
| 754 | * font, size, ...). Those affect the TXVWORD structure
|
---|
| 755 | * directly and are thus never evaluated in step 2,
|
---|
| 756 | * rectangles correlation.
|
---|
| 757 | *
|
---|
| 758 | * -- Those which affect spacings, margins, etc. (paragraph
|
---|
| 759 | * formatting). These need to be re-evaluated even during
|
---|
| 760 | * "quick" format, without words being recalculated, because
|
---|
| 761 | * those spacings affect the output rectangles.
|
---|
| 762 | *
|
---|
| 763 | * If one of those sequences is encountered, this function
|
---|
| 764 | * appends a special TXVWORD structure to XFORMATDATA.llWords.
|
---|
| 765 | *
|
---|
| 766 | *@@added V0.9.3 (2000-05-07) [umoeller]
|
---|
| 767 | */
|
---|
| 768 |
|
---|
[222] | 769 | STATIC PTXVWORD ProcessEscapes(char **ppCurrent, // in/out: current position; initially points to esc char
|
---|
[142] | 770 | PXFORMATDATA pxfd, // in/out: formatting data
|
---|
| 771 | PFORMATLINEBUF pflbuf, // in/out: formatting buffer
|
---|
| 772 | BOOL fWordsProcessed) // FALSE during step 1 (words processing),
|
---|
| 773 | // TRUE during step 2 (rectangles correlation)
|
---|
[8] | 774 | {
|
---|
| 775 | PTXVWORD pEscapeWord = NULL;
|
---|
| 776 |
|
---|
| 777 | // this is set to TRUE either above or by txvCreateRectangle if
|
---|
| 778 | // an escape character was found; txvCreateRectangle
|
---|
| 779 | // then sets pCurrent to the escape character (\xFF)
|
---|
[201] | 780 | CHAR cCode1 = *((*ppCurrent) + 1);
|
---|
| 781 | CHAR cCode2 = *((*ppCurrent) + 2);
|
---|
[8] | 782 | ULONG ulSkip = 3; // per default, skip \xFF plus two
|
---|
| 783 | CHAR szDecimal[10];
|
---|
| 784 | LONG lDecimal;
|
---|
| 785 |
|
---|
| 786 | BOOL fCreateWord = FALSE,
|
---|
| 787 | fPaintEscapeWord = FALSE;
|
---|
| 788 |
|
---|
| 789 | switch (cCode1)
|
---|
| 790 | {
|
---|
| 791 | case 1: // change font:
|
---|
| 792 | // three decimals follow specifying the font
|
---|
[201] | 793 | memcpy(szDecimal, (*ppCurrent) + 2, 3);
|
---|
[8] | 794 | szDecimal[3] = 0;
|
---|
| 795 | lDecimal = atoi(szDecimal);
|
---|
| 796 | if (lDecimal == 0)
|
---|
| 797 | pflbuf->pfmtc = &pxfd->fmtcStandard;
|
---|
| 798 | else if (lDecimal == 1)
|
---|
| 799 | pflbuf->pfmtc = &pxfd->fmtcCode;
|
---|
| 800 | ulSkip = 5;
|
---|
| 801 | break;
|
---|
| 802 |
|
---|
| 803 | case 2: // B or /B
|
---|
| 804 | if (cCode2 == 1)
|
---|
| 805 | pflbuf->fBold = TRUE;
|
---|
| 806 | else
|
---|
| 807 | pflbuf->fBold = FALSE;
|
---|
| 808 | break;
|
---|
| 809 |
|
---|
| 810 | case 3: // I or /I
|
---|
| 811 | if (cCode2 == 1)
|
---|
| 812 | pflbuf->fItalics = TRUE;
|
---|
| 813 | else
|
---|
| 814 | pflbuf->fItalics = FALSE;
|
---|
| 815 | break;
|
---|
| 816 |
|
---|
| 817 | case 4: // U or /U
|
---|
| 818 | if (cCode2 == 1)
|
---|
[201] | 819 | pflbuf->flChar |= CHS_UNDERSCORE;
|
---|
[8] | 820 | else
|
---|
[201] | 821 | pflbuf->flChar &= ~CHS_UNDERSCORE;
|
---|
[8] | 822 | break;
|
---|
| 823 |
|
---|
| 824 | case 5: // STRIKE or /STRIKE
|
---|
| 825 | if (cCode2 == 1)
|
---|
[201] | 826 | pflbuf->flChar |= CHS_STRIKEOUT;
|
---|
[8] | 827 | else
|
---|
[201] | 828 | pflbuf->flChar &= ~CHS_STRIKEOUT;
|
---|
[8] | 829 | break;
|
---|
| 830 |
|
---|
[201] | 831 | case 6: // A HREF= (link)
|
---|
| 832 | // changed implementation V0.9.20 (2002-08-10) [umoeller]
|
---|
| 833 | {
|
---|
| 834 | // this is variable in length and terminated with
|
---|
| 835 | // another 0xFF char; what's in between is the
|
---|
| 836 | // link target name and gets appended to
|
---|
| 837 | // XFORMATDATA.llLinks
|
---|
| 838 | PSZ pEnd;
|
---|
| 839 | if (pEnd = strchr((*ppCurrent) + 2, 0xFF))
|
---|
[8] | 840 | {
|
---|
[206] | 841 | PSZ pszNewLink = strhSubstr((*ppCurrent) + 2, pEnd);
|
---|
| 842 | lstAppendItem(&pxfd->llLinks,
|
---|
| 843 | pszNewLink);
|
---|
| 844 |
|
---|
| 845 | pflbuf->pcszCurrentLinkTarget = pszNewLink;
|
---|
| 846 |
|
---|
[201] | 847 | ulSkip = pEnd - *ppCurrent + 1;
|
---|
[8] | 848 | }
|
---|
[201] | 849 | }
|
---|
| 850 | break;
|
---|
[8] | 851 |
|
---|
[201] | 852 | case 7: // /A HREF (end of link)
|
---|
[206] | 853 | pflbuf->pcszCurrentLinkTarget = NULL;
|
---|
[201] | 854 | ulSkip = 2;
|
---|
[137] | 855 | break;
|
---|
[8] | 856 |
|
---|
[201] | 857 | case 8: // A NAME= (anchor name)
|
---|
[8] | 858 | {
|
---|
| 859 | // this is variable in length and terminated with
|
---|
| 860 | // another 0xFF char; we completely ignore this
|
---|
| 861 | // here and just skip the anchor name, this is
|
---|
| 862 | // only used with TXM_JUMPTOANCHORNAME, which then
|
---|
| 863 | // searches the buffer
|
---|
[137] | 864 | PSZ pEnd;
|
---|
[201] | 865 | if (pEnd = strchr((*ppCurrent) + 2, 0xFF))
|
---|
[8] | 866 | {
|
---|
| 867 | ulSkip = pEnd - *ppCurrent + 1;
|
---|
| 868 | // store this with the other words so we can
|
---|
| 869 | // find this word later
|
---|
| 870 | fCreateWord = TRUE;
|
---|
| 871 | // and store this with the rectangles
|
---|
| 872 | fPaintEscapeWord = TRUE;
|
---|
| 873 | }
|
---|
[137] | 874 | }
|
---|
| 875 | break;
|
---|
[8] | 876 |
|
---|
| 877 | case 0x10: // relative point size in percent
|
---|
| 878 | // three characters follow specifying the
|
---|
| 879 | // percentage
|
---|
[201] | 880 | memcpy(szDecimal, (*ppCurrent) + 2, 3);
|
---|
[8] | 881 | szDecimal[3] = 0;
|
---|
| 882 | lDecimal = atoi(szDecimal);
|
---|
| 883 |
|
---|
| 884 | pflbuf->lPointSize = pflbuf->pfmtc->lPointSize * lDecimal / 100;
|
---|
| 885 | ulSkip = 5;
|
---|
| 886 | break;
|
---|
| 887 |
|
---|
| 888 | case 0x20: // left margin changed:
|
---|
[201] | 889 | memcpy(szDecimal, (*ppCurrent) + 2, 4); // four decimals xxxx
|
---|
[8] | 890 | szDecimal[4] = 0;
|
---|
| 891 | lDecimal = atoi(szDecimal);
|
---|
| 892 |
|
---|
| 893 | // this is based on the current average font width, so
|
---|
| 894 | // find this:
|
---|
| 895 | pflbuf->fmtp.lLeftMargin = (lDecimal
|
---|
| 896 | * pflbuf->lPointSize);
|
---|
| 897 | ulSkip = 6;
|
---|
| 898 | fCreateWord = TRUE; // for rectangle correlation
|
---|
| 899 | break;
|
---|
| 900 |
|
---|
| 901 | case 0x21: // first line margin changed:
|
---|
[201] | 902 | memcpy(szDecimal, (*ppCurrent) + 2, 4); // +xxx, -xxx
|
---|
[8] | 903 | szDecimal[4] = 0;
|
---|
| 904 | lDecimal = atoi(szDecimal);
|
---|
| 905 |
|
---|
| 906 | // this is based on the current average font width, so
|
---|
| 907 | // find this:
|
---|
| 908 | pflbuf->fmtp.lFirstLineMargin = (lDecimal
|
---|
| 909 | * pflbuf->lPointSize);
|
---|
| 910 | ulSkip = 6;
|
---|
| 911 | fCreateWord = TRUE; // for rectangle correlation
|
---|
| 912 | break;
|
---|
| 913 |
|
---|
| 914 | case 0x22: // tab: forward current X to left margin
|
---|
| 915 | pflbuf->lXCurrent = pflbuf->fmtp.lLeftMargin;
|
---|
| 916 |
|
---|
| 917 | ulSkip = 2;
|
---|
| 918 | fCreateWord = TRUE; // for rectangle correlation
|
---|
| 919 | break;
|
---|
| 920 |
|
---|
| 921 | case 0x23: // marker: store this in output, this needs
|
---|
| 922 | // to be painted
|
---|
| 923 | fCreateWord = TRUE;
|
---|
| 924 | fPaintEscapeWord = TRUE;
|
---|
| 925 | ulSkip = 3;
|
---|
| 926 | break;
|
---|
| 927 |
|
---|
| 928 | case 0x30: // spacing before paragraph:
|
---|
| 929 | // four chars follow with either "####" or decimal spacing
|
---|
[201] | 930 | memcpy(szDecimal, (*ppCurrent) + 2, 4);
|
---|
[8] | 931 | szDecimal[4] = 0;
|
---|
| 932 | if (memcmp(szDecimal, "####", 4) == 0)
|
---|
| 933 | // reset to default:
|
---|
| 934 | pflbuf->fmtp.lSpaceBefore = pxfd->fmtpStandard.lSpaceBefore;
|
---|
| 935 | else
|
---|
| 936 | {
|
---|
| 937 | lDecimal = atoi(szDecimal);
|
---|
| 938 | pflbuf->fmtp.lSpaceBefore = lDecimal;
|
---|
| 939 | }
|
---|
| 940 | ulSkip = 6;
|
---|
| 941 | fCreateWord = TRUE; // for rectangle correlation
|
---|
| 942 | break;
|
---|
| 943 |
|
---|
| 944 | case 0x31: // spacing before paragraph:
|
---|
| 945 | // four chars follow with either "####" or decimal spacing
|
---|
[201] | 946 | memcpy(szDecimal, (*ppCurrent) + 2, 4);
|
---|
[8] | 947 | szDecimal[4] = 0;
|
---|
| 948 | if (memcmp(szDecimal, "####", 4) == 0)
|
---|
| 949 | // reset to default:
|
---|
| 950 | pflbuf->fmtp.lSpaceAfter = pxfd->fmtpStandard.lSpaceAfter;
|
---|
| 951 | else
|
---|
| 952 | {
|
---|
| 953 | lDecimal = atoi(szDecimal);
|
---|
| 954 | pflbuf->fmtp.lSpaceAfter = lDecimal;
|
---|
| 955 | }
|
---|
| 956 | ulSkip = 6;
|
---|
| 957 | fCreateWord = TRUE; // for rectangle correlation
|
---|
| 958 | break;
|
---|
| 959 |
|
---|
| 960 | case 0x32: // word-wrapping:
|
---|
| 961 | // here follows a single char being "0" or "1"
|
---|
| 962 | if ( *((*ppCurrent) + 2) == '0')
|
---|
| 963 | pflbuf->fmtp.fWordWrap = FALSE;
|
---|
| 964 | else
|
---|
| 965 | pflbuf->fmtp.fWordWrap = TRUE;
|
---|
| 966 | fCreateWord = TRUE; // for rectangle correlation
|
---|
| 967 | }
|
---|
| 968 |
|
---|
| 969 | if (fCreateWord) // append for rectangle correlation?
|
---|
| 970 | if (!fWordsProcessed) // are we processing words still (step 1)?
|
---|
| 971 | {
|
---|
| 972 | // yes: append to list for rectangle correlation later
|
---|
| 973 | pEscapeWord = (PTXVWORD)malloc(sizeof(TXVWORD));
|
---|
| 974 | memset(pEscapeWord, 0, sizeof(TXVWORD));
|
---|
| 975 | // mark as escape sequence
|
---|
| 976 | pEscapeWord->pStart = *ppCurrent;
|
---|
| 977 | pEscapeWord->cChars = ulSkip;
|
---|
| 978 | pEscapeWord->cEscapeCode = *(*ppCurrent + 1);
|
---|
| 979 | pEscapeWord->fPaintEscapeWord = fPaintEscapeWord;
|
---|
[206] | 980 | pEscapeWord->pcszLinkTarget = pflbuf->pcszCurrentLinkTarget;
|
---|
[201] | 981 | // V0.9.20 (2002-08-10) [umoeller]
|
---|
| 982 | // NULL if none
|
---|
[8] | 983 | if (fPaintEscapeWord)
|
---|
| 984 | {
|
---|
| 985 | pEscapeWord->lX = pflbuf->lXCurrent;
|
---|
| 986 | pEscapeWord->lcid = pflbuf->pfmtf->lcid;
|
---|
| 987 | pEscapeWord->lPointSize = pflbuf->lPointSize;
|
---|
[201] | 988 | pEscapeWord->flChar = pflbuf->flChar;
|
---|
[8] | 989 | }
|
---|
| 990 | lstAppendItem(&pxfd->llWords, pEscapeWord);
|
---|
| 991 | }
|
---|
| 992 |
|
---|
| 993 | if (!fWordsProcessed)
|
---|
| 994 | // if we're still processing words, advance
|
---|
| 995 | // current pointer by the escape length
|
---|
| 996 | *ppCurrent += ulSkip;
|
---|
| 997 |
|
---|
[201] | 998 | return pEscapeWord;
|
---|
[8] | 999 | }
|
---|
| 1000 |
|
---|
| 1001 | /*
|
---|
| 1002 | *@@ txvFormatText:
|
---|
| 1003 | * this is the core function to text formatting, which
|
---|
| 1004 | * must be done before the text can be painted into an
|
---|
| 1005 | * HPS. See the top of textview.c for details.
|
---|
| 1006 | *
|
---|
| 1007 | * Even though this function does not seem to have a
|
---|
| 1008 | * lot of parameters, it is extremely powerful. This
|
---|
| 1009 | * function handles paragraph and character formatting
|
---|
| 1010 | * automatically. See XFMTPARAGRAPH and XFMTCHARACTER
|
---|
| 1011 | * for possible formatting attributes, which are part
|
---|
| 1012 | * of the XFORMATDATA structure passed to this function.
|
---|
| 1013 | *
|
---|
| 1014 | * "Formatting" means splitting up any zero-terminated
|
---|
| 1015 | * string (XFORMATDATA.pszViewText) into a possibly
|
---|
| 1016 | * large list of TXVRECTANGLE structures, which each
|
---|
| 1017 | * hold a rectangle to be painted. This allows for
|
---|
| 1018 | * extremely fast painting.
|
---|
| 1019 | *
|
---|
| 1020 | * Each TXVRECTANGLE in turn holds several "words" to
|
---|
| 1021 | * be painted. A word consists of a TXVWORD structure
|
---|
| 1022 | * and is normally a sequence of characters between
|
---|
| 1023 | * spaces, \n and \r characters. As an exception, if
|
---|
| 1024 | * escape sequences come up, such a "word" is split up
|
---|
| 1025 | * into several words because character formatting
|
---|
| 1026 | * (font, size, ...) is done on a per-word basis when painting.
|
---|
| 1027 | *
|
---|
| 1028 | * This approach allows for quicker word-wrapping when only
|
---|
| 1029 | * the output (paint) rectangle is changed because we don't
|
---|
| 1030 | * have to re-calculate all the character widths (TXVWORD) once we
|
---|
| 1031 | * got the words. Instead, when re-formatting, we just recompose
|
---|
| 1032 | * the rectangles based on the words we calculated already.
|
---|
| 1033 | * Of course, when character widths change (e.g. because
|
---|
| 1034 | * fonts are changed), everything has to be redone.
|
---|
| 1035 | *
|
---|
| 1036 | * Processing depends on the current formatting settings
|
---|
| 1037 | * of the XFORMATDATA structure passed to this func and
|
---|
| 1038 | * can become quite complicated:
|
---|
| 1039 | *
|
---|
| 1040 | * -- In the simplest possible formatting mode, that is, if
|
---|
| 1041 | * word wrapping is disabled, each such TXVRECTANGLE
|
---|
| 1042 | * structure will hold one paragraph from the text
|
---|
| 1043 | * (that is, the text between two \n chars).
|
---|
| 1044 | *
|
---|
| 1045 | * -- If word wrapping is enabled, each paragraph in the text
|
---|
| 1046 | * can consist of several such rectangles if the paragraph
|
---|
| 1047 | * does not fit into one line. In that case, we create
|
---|
| 1048 | * one XFMTRECTANGLE for each line which is needed to
|
---|
| 1049 | * display the paragraph word-wrapped.
|
---|
| 1050 | *
|
---|
| 1051 | * This uses an XFORMATDATA structure for input and output
|
---|
| 1052 | * (besides the other parameters).
|
---|
| 1053 | *
|
---|
| 1054 | * On input, specify the following:
|
---|
| 1055 | *
|
---|
| 1056 | * -- hps: window or printer HPS. This is used for
|
---|
| 1057 | * formatting only, but nothing is painted.
|
---|
| 1058 | *
|
---|
| 1059 | * -- XFORMATDATA.pszViewText: the text to be formatted.
|
---|
| 1060 | * This must follow certain conventions; the \xFF,
|
---|
| 1061 | * \r, and \n characters have a special meaning.
|
---|
| 1062 | * See the top of textview.c for details.
|
---|
| 1063 | *
|
---|
| 1064 | * -- XFORMATDATA.fmtpStandard, fmtcStandard, fmtcCode:
|
---|
| 1065 | * paragraph and character formatting attributes.
|
---|
| 1066 | * For the simplest possible formatting, memset
|
---|
| 1067 | * all these to 0. Word-wrapping depends on
|
---|
| 1068 | * the paragraph formats.
|
---|
| 1069 | *
|
---|
| 1070 | * -- prclView: rectangle for which formatting should take
|
---|
| 1071 | * place. When this is called for a screen window,
|
---|
| 1072 | * this should be the visible area of the window
|
---|
| 1073 | * (WinQueryWindowRect).
|
---|
| 1074 | * When this is called with a printer PS, this should
|
---|
| 1075 | * be the size of a printer page.
|
---|
| 1076 | *
|
---|
| 1077 | * This function updates the following:
|
---|
| 1078 | *
|
---|
| 1079 | * -- XFORMATDATA.llWords: list of TXVWORD structures,
|
---|
| 1080 | * holding all the "words" in the text as described
|
---|
| 1081 | * above. This list can grow very long, but only needs
|
---|
| 1082 | * to be recalculated when fonts change.
|
---|
| 1083 | *
|
---|
| 1084 | * -- XFORMATDATA.llRectangles: list of TXVRECTANGLE
|
---|
| 1085 | * structures, correlating the words on the words list
|
---|
| 1086 | * to paint rectangles.
|
---|
| 1087 | *
|
---|
[201] | 1088 | * -- XFORMATDATA.szlWorkspace: total width
|
---|
| 1089 | * and height of the "workspace", i.e. the total space
|
---|
[8] | 1090 | * needed to display the text (in pels). This might
|
---|
| 1091 | * be smaller, the same, or larger than prclView,
|
---|
| 1092 | * depending on whether the text fits into prclView.
|
---|
| 1093 | *
|
---|
| 1094 | * When displaying text, you should display scroll bars
|
---|
[201] | 1095 | * if the workspace is larger than the window (prclView).
|
---|
[8] | 1096 | *
|
---|
[201] | 1097 | * When printing, if the workspace is larger than the
|
---|
[8] | 1098 | * printer page (prclView), you will need to call
|
---|
| 1099 | * txvPaintText several times for each page.
|
---|
| 1100 | *
|
---|
| 1101 | * All coordinates are in world space (PU_PELS).
|
---|
| 1102 | *
|
---|
| 1103 | *@@changed V0.9.3 (2000-05-06) [umoeller]: largely rewritten; now handling paragraph and character formats
|
---|
[374] | 1104 | *@@changed V1.0.18 (2008-11-16) [pr]: bodge formatting to remove unwanted scroll bars @@fixes 1086
|
---|
[47] | 1105 | *@@todo TXVWORDF_GLUEWITHNEXT
|
---|
[8] | 1106 | */
|
---|
| 1107 |
|
---|
| 1108 | VOID txvFormatText(HPS hps, // in: HPS whose font is used for
|
---|
| 1109 | // calculating text dimensions
|
---|
| 1110 | PXFORMATDATA pxfd, // in: formatting data
|
---|
| 1111 | PRECTL prclView, // in: rectangle to format for (window or printer page)
|
---|
| 1112 | BOOL fFullRecalc) // in: re-calculate word list too? (must be TRUE on the first call)
|
---|
| 1113 | {
|
---|
| 1114 | /* ULONG ulWinCX = (prclView->xRight - prclView->xLeft),
|
---|
| 1115 | ulWinCY = (prclView->yTop - prclView->yBottom); */
|
---|
| 1116 |
|
---|
| 1117 | lstClear(&pxfd->llRectangles);
|
---|
| 1118 | if (fFullRecalc)
|
---|
| 1119 | lstClear(&pxfd->llWords);
|
---|
| 1120 |
|
---|
[201] | 1121 | pxfd->szlWorkspace.cx = 0;
|
---|
| 1122 | pxfd->szlWorkspace.cy = 0;
|
---|
[8] | 1123 |
|
---|
[12] | 1124 | if (pxfd->strViewText.cbAllocated)
|
---|
[8] | 1125 | {
|
---|
[12] | 1126 | ULONG ulTextLen = pxfd->strViewText.ulLength;
|
---|
[8] | 1127 |
|
---|
| 1128 | FORMATLINEBUF flbuf;
|
---|
| 1129 | LONG lcidLast = -99,
|
---|
| 1130 | lPointSizeLast = -99;
|
---|
| 1131 |
|
---|
| 1132 | memset(&flbuf, 0, sizeof(flbuf));
|
---|
| 1133 | // copy default paragraph formatting
|
---|
| 1134 | memcpy(&flbuf.fmtp, &pxfd->fmtpStandard, sizeof(flbuf.fmtp));
|
---|
| 1135 | // set font
|
---|
| 1136 | flbuf.pfmtc = &pxfd->fmtcStandard;
|
---|
| 1137 | flbuf.lPointSize = pxfd->fmtcStandard.lPointSize;
|
---|
[12] | 1138 | flbuf.pLastChar = pxfd->strViewText.psz + ulTextLen;
|
---|
[8] | 1139 |
|
---|
| 1140 | if (ulTextLen)
|
---|
| 1141 | {
|
---|
| 1142 | ULONG cWords = 0;
|
---|
| 1143 |
|
---|
| 1144 | if (fFullRecalc)
|
---|
| 1145 | {
|
---|
| 1146 | /*
|
---|
| 1147 | * step 1: create words
|
---|
| 1148 | *
|
---|
| 1149 | */
|
---|
| 1150 |
|
---|
[12] | 1151 | PSZ pCurrent = pxfd->strViewText.psz;
|
---|
[8] | 1152 |
|
---|
| 1153 | // loop until null terminator
|
---|
| 1154 | while (*pCurrent)
|
---|
| 1155 | {
|
---|
| 1156 | PTXVWORD pWord;
|
---|
| 1157 |
|
---|
| 1158 | if (flbuf.fBold)
|
---|
| 1159 | {
|
---|
| 1160 | if (flbuf.fItalics)
|
---|
| 1161 | flbuf.pfmtf = &flbuf.pfmtc->fntBoldItalics;
|
---|
| 1162 | else
|
---|
| 1163 | flbuf.pfmtf = &flbuf.pfmtc->fntBold;
|
---|
| 1164 | }
|
---|
| 1165 | else
|
---|
| 1166 | if (flbuf.fItalics)
|
---|
| 1167 | flbuf.pfmtf = &flbuf.pfmtc->fntItalics;
|
---|
| 1168 | else
|
---|
| 1169 | flbuf.pfmtf = &flbuf.pfmtc->fntRegular;
|
---|
| 1170 |
|
---|
| 1171 | // set font for subsequent calculations,
|
---|
| 1172 | // if changed (this includes the first call)
|
---|
| 1173 | if (lcidLast != flbuf.pfmtf->lcid)
|
---|
| 1174 | {
|
---|
| 1175 | GpiSetCharSet(hps, flbuf.pfmtf->lcid);
|
---|
| 1176 | lcidLast = flbuf.pfmtf->lcid;
|
---|
| 1177 | // force recalc of point size
|
---|
| 1178 | lPointSizeLast = -99;
|
---|
| 1179 | }
|
---|
| 1180 |
|
---|
| 1181 | if (lPointSizeLast != flbuf.lPointSize)
|
---|
| 1182 | {
|
---|
| 1183 | if (flbuf.pfmtf->FontMetrics.fsDefn & FM_DEFN_OUTLINE)
|
---|
| 1184 | // is outline font:
|
---|
| 1185 | gpihSetPointSize(hps, flbuf.lPointSize);
|
---|
| 1186 | lPointSizeLast = flbuf.lPointSize;
|
---|
| 1187 | }
|
---|
| 1188 |
|
---|
[142] | 1189 | if (pWord = CreateWord(hps,
|
---|
| 1190 | &pCurrent, // advanced to next word
|
---|
| 1191 | &flbuf))
|
---|
[8] | 1192 | {
|
---|
| 1193 | lstAppendItem(&pxfd->llWords, pWord);
|
---|
| 1194 |
|
---|
| 1195 | /* {
|
---|
| 1196 | CHAR szWord[3000];
|
---|
| 1197 | strhncpy0(szWord, pWord->pStart, min(pWord->cChars, sizeof(szWord)));
|
---|
| 1198 | _Pmpf(("Found word '%s'", szWord));
|
---|
| 1199 | } */
|
---|
| 1200 |
|
---|
| 1201 | cWords++;
|
---|
| 1202 |
|
---|
| 1203 | while (*pCurrent == TXVESC_CHAR) // '\xFF')
|
---|
| 1204 | {
|
---|
| 1205 | // handle escapes;
|
---|
| 1206 | // this advances pCurrent depending on the
|
---|
| 1207 | // escape sequence length and might append
|
---|
| 1208 | // another "word" for the escape sequence
|
---|
| 1209 | // if it's relevant for rectangle correlation
|
---|
| 1210 | ProcessEscapes(&pCurrent,
|
---|
| 1211 | pxfd,
|
---|
| 1212 | &flbuf,
|
---|
| 1213 | FALSE); // fWordsProcessed
|
---|
| 1214 | }
|
---|
| 1215 | }
|
---|
| 1216 | else
|
---|
| 1217 | break;
|
---|
| 1218 | }
|
---|
| 1219 | } // end if (fFullRecalc)
|
---|
| 1220 | else
|
---|
| 1221 | cWords = lstCountItems(&pxfd->llWords);
|
---|
| 1222 |
|
---|
| 1223 | /*
|
---|
| 1224 | * step 2: create rectangles
|
---|
| 1225 | *
|
---|
| 1226 | */
|
---|
| 1227 |
|
---|
| 1228 | if (cWords)
|
---|
| 1229 | {
|
---|
| 1230 | PLISTNODE pWordNode = lstQueryFirstNode(&pxfd->llWords);
|
---|
| 1231 |
|
---|
| 1232 | LONG lCurrentYTop = prclView->yTop,
|
---|
| 1233 | lOrigYTop = lCurrentYTop;
|
---|
| 1234 |
|
---|
| 1235 | BOOL fRects2Go = TRUE;
|
---|
| 1236 |
|
---|
| 1237 | // space before paragraph; this is reset
|
---|
| 1238 | // to 0 if we start a new rectangle for
|
---|
| 1239 | // the same paragraph
|
---|
| 1240 | ULONG ulYPre = flbuf.fmtp.lSpaceBefore;
|
---|
| 1241 |
|
---|
| 1242 | // rectangles loop
|
---|
| 1243 | while (fRects2Go)
|
---|
| 1244 | {
|
---|
| 1245 | BOOL fWords2Go = TRUE;
|
---|
| 1246 | ULONG ulWordsInThisRect = 0;
|
---|
| 1247 |
|
---|
| 1248 | // maximum height of words in this rect
|
---|
| 1249 | ULONG lWordsMaxCY = 0;
|
---|
| 1250 |
|
---|
| 1251 | // start a new rectangle:
|
---|
| 1252 | PTXVRECTANGLE pRect = (PTXVRECTANGLE)malloc(sizeof(TXVRECTANGLE));
|
---|
| 1253 | lstInit(&pRect->llWords,
|
---|
| 1254 | FALSE); // no auto-free; the words are stored in the main
|
---|
| 1255 | // list also, which is freed
|
---|
| 1256 | // rectangle's xLeft;
|
---|
| 1257 | // xRight will be set when we're done with this rectangle
|
---|
| 1258 | pRect->rcl.xLeft = prclView->xLeft + flbuf.fmtp.lLeftMargin;
|
---|
| 1259 | if (ulYPre)
|
---|
| 1260 | // starting new paragraph:
|
---|
| 1261 | // add first-line offset also
|
---|
| 1262 | pRect->rcl.xLeft += flbuf.fmtp.lFirstLineMargin;
|
---|
| 1263 |
|
---|
| 1264 | // current X pos: start with left of rectangle
|
---|
| 1265 | flbuf.lXCurrent = pRect->rcl.xLeft;
|
---|
| 1266 |
|
---|
| 1267 | // max baseline ofs: set to 0, this will be raised
|
---|
| 1268 | pRect->ulMaxBaseLineOfs = 0;
|
---|
| 1269 |
|
---|
| 1270 | // words-per-rectangle loop;
|
---|
| 1271 | // we keep adding words to the rectangle until
|
---|
| 1272 | // a) words no longer fit and word-wrapping is on;
|
---|
| 1273 | // b) a newline or line feed is found;
|
---|
| 1274 | // c) the last word has been reached;
|
---|
| 1275 | while (fWords2Go)
|
---|
| 1276 | {
|
---|
| 1277 | PTXVWORD pWordThis = (PTXVWORD)pWordNode->pItemData;
|
---|
| 1278 | /*
|
---|
| 1279 | #define TXVWORDF_GLUEWITHNEXT 1 // escape
|
---|
| 1280 | #define TXVWORDF_LINEBREAK 2 // \n
|
---|
| 1281 | #define TXVWORDF_LINEFEED 4 // \r
|
---|
| 1282 | */
|
---|
| 1283 | BOOL fNextWord = FALSE;
|
---|
| 1284 |
|
---|
| 1285 | if (pWordThis->cEscapeCode)
|
---|
| 1286 | {
|
---|
| 1287 | // pseudo-word for escape sequence:
|
---|
| 1288 | // process...
|
---|
| 1289 | ProcessEscapes((PSZ*)&pWordThis->pStart,
|
---|
| 1290 | pxfd,
|
---|
| 1291 | &flbuf,
|
---|
| 1292 | TRUE);
|
---|
| 1293 |
|
---|
| 1294 | // append this sequence only if it's needed
|
---|
| 1295 | // for painting (list markers etc.)
|
---|
| 1296 | if (pWordThis->fPaintEscapeWord)
|
---|
| 1297 | {
|
---|
| 1298 | pWordThis->lX = flbuf.lXCurrent;
|
---|
[85] | 1299 | pWordThis->pRectangle = pRect;
|
---|
[8] | 1300 | lstAppendItem(&pRect->llWords, pWordThis);
|
---|
| 1301 | ulWordsInThisRect++;
|
---|
| 1302 | }
|
---|
| 1303 |
|
---|
| 1304 | fNextWord = TRUE;
|
---|
| 1305 | }
|
---|
| 1306 | else
|
---|
| 1307 | {
|
---|
| 1308 | BOOL fWordWrapped = FALSE;
|
---|
| 1309 |
|
---|
| 1310 | // not escape sequence, but real word: format...
|
---|
| 1311 | // is word-wrapping on?
|
---|
| 1312 | if (flbuf.fmtp.fWordWrap)
|
---|
| 1313 | {
|
---|
| 1314 | // yes: check if the word still fits
|
---|
[374] | 1315 | // WarpIN V1.0.18 @@todo add fudge factor of 2 - makes things work
|
---|
| 1316 | if ( (flbuf.lXCurrent + pWordThis->ulCXWithSpaces + 2
|
---|
[8] | 1317 | > prclView->xRight)
|
---|
| 1318 | // > ulWinCX)
|
---|
| 1319 | // but always add the first word in the rectangle,
|
---|
| 1320 | // because otherwise we get infinite loops
|
---|
| 1321 | && (ulWordsInThisRect > 0)
|
---|
| 1322 | )
|
---|
| 1323 | // no:
|
---|
| 1324 | fWordWrapped = TRUE;
|
---|
| 1325 | }
|
---|
| 1326 |
|
---|
| 1327 | if (fWordWrapped)
|
---|
| 1328 | // start a new rectangle with the current word:
|
---|
| 1329 | fWords2Go = FALSE;
|
---|
| 1330 | // and do _not_ advance to the next word,
|
---|
| 1331 | // but start with this word for the next
|
---|
| 1332 | // rectangle...
|
---|
| 1333 | else
|
---|
| 1334 | {
|
---|
| 1335 | // add this word to the rectangle:
|
---|
| 1336 |
|
---|
| 1337 | // store current X pos in word
|
---|
| 1338 | pWordThis->lX = flbuf.lXCurrent;
|
---|
| 1339 |
|
---|
| 1340 | // increase current X pos by word width
|
---|
| 1341 | flbuf.lXCurrent += pWordThis->ulCXWithSpaces;
|
---|
| 1342 |
|
---|
| 1343 | // store word in rectangle
|
---|
[85] | 1344 | pWordThis->pRectangle = pRect;
|
---|
[8] | 1345 | lstAppendItem(&pRect->llWords, pWordThis);
|
---|
[85] | 1346 | // @@todo memory leak right here!!!
|
---|
[8] | 1347 | ulWordsInThisRect++;
|
---|
| 1348 |
|
---|
| 1349 | // store highest word width found for this rect
|
---|
| 1350 | if (pWordThis->ulCY > lWordsMaxCY)
|
---|
| 1351 | lWordsMaxCY = pWordThis->ulCY;
|
---|
| 1352 |
|
---|
| 1353 | // store highest base line ofs found for this rect
|
---|
| 1354 | if (pWordThis->ulBaseLineOfs > pRect->ulMaxBaseLineOfs)
|
---|
| 1355 | pRect->ulMaxBaseLineOfs = pWordThis->ulBaseLineOfs;
|
---|
| 1356 |
|
---|
| 1357 | // go for next word in any case
|
---|
| 1358 | fNextWord = TRUE;
|
---|
| 1359 | } // end if (!fBreakThisWord)
|
---|
| 1360 |
|
---|
| 1361 | // now check: add more words to this rectangle?
|
---|
| 1362 | if ( (pWordThis->ulFlags == TXVWORDF_LINEBREAK)
|
---|
| 1363 | // no if linebreak found
|
---|
| 1364 | || (pWordThis->ulFlags == TXVWORDF_LINEFEED)
|
---|
| 1365 | // no if linefeed found
|
---|
| 1366 | || (!fWords2Go)
|
---|
| 1367 | // no if we're out of words or
|
---|
| 1368 | // word-break was forced
|
---|
| 1369 | )
|
---|
| 1370 | {
|
---|
| 1371 | // no: finish up this rectangle...
|
---|
| 1372 |
|
---|
| 1373 | // xLeft has been set on top
|
---|
| 1374 | pRect->rcl.xRight = flbuf.lXCurrent;
|
---|
| 1375 | pRect->rcl.yTop = lCurrentYTop - ulYPre;
|
---|
| 1376 | pRect->rcl.yBottom = pRect->rcl.yTop - lWordsMaxCY;
|
---|
| 1377 |
|
---|
| 1378 | // decrease current y top for next line
|
---|
| 1379 | lCurrentYTop = pRect->rcl.yBottom;
|
---|
| 1380 | if (!fRects2Go)
|
---|
| 1381 | // we're done completely:
|
---|
| 1382 | // add another one
|
---|
| 1383 | lCurrentYTop -= lWordsMaxCY;
|
---|
| 1384 |
|
---|
| 1385 | if (fWordWrapped)
|
---|
| 1386 | // starting with wrapped word in next line:
|
---|
| 1387 | ulYPre = 0;
|
---|
| 1388 | else
|
---|
| 1389 | if (pWordThis->ulFlags == TXVWORDF_LINEFEED)
|
---|
| 1390 | ulYPre = 0;
|
---|
| 1391 | else if (pWordThis->ulFlags == TXVWORDF_LINEBREAK)
|
---|
| 1392 | {
|
---|
| 1393 | // line break:
|
---|
| 1394 | // set y-pre for next loop
|
---|
| 1395 | ulYPre = flbuf.fmtp.lSpaceBefore;
|
---|
| 1396 | // and add paragraph post-y
|
---|
| 1397 | lCurrentYTop -= flbuf.fmtp.lSpaceAfter;
|
---|
| 1398 | }
|
---|
| 1399 |
|
---|
| 1400 | // update x extents
|
---|
[201] | 1401 | if (pRect->rcl.xRight > pxfd->szlWorkspace.cx)
|
---|
| 1402 | pxfd->szlWorkspace.cx = pRect->rcl.xRight;
|
---|
[8] | 1403 |
|
---|
| 1404 | // and quit the inner loop
|
---|
| 1405 | fWords2Go = FALSE;
|
---|
| 1406 | } // end finish up rectangle
|
---|
| 1407 | } // end else if (pWordThis->fIsEscapeSequence)
|
---|
| 1408 |
|
---|
| 1409 | if (fNextWord)
|
---|
| 1410 | {
|
---|
| 1411 | pWordNode = pWordNode->pNext;
|
---|
| 1412 | if (!pWordNode)
|
---|
| 1413 | {
|
---|
| 1414 | // no more to go:
|
---|
| 1415 | // quit
|
---|
| 1416 | fWords2Go = FALSE;
|
---|
| 1417 | fRects2Go = FALSE;
|
---|
| 1418 | }
|
---|
| 1419 | }
|
---|
| 1420 | } // end while (fWords2Go)
|
---|
| 1421 |
|
---|
| 1422 | // store rectangle
|
---|
| 1423 | lstAppendItem(&pxfd->llRectangles, pRect);
|
---|
| 1424 | }
|
---|
| 1425 |
|
---|
| 1426 | // lCurrentYTop now has the bottommost point we've used;
|
---|
[201] | 1427 | // store this as workspace (this might be negative)
|
---|
| 1428 | pxfd->szlWorkspace.cy = lOrigYTop - lCurrentYTop;
|
---|
[8] | 1429 | }
|
---|
| 1430 | }
|
---|
| 1431 | }
|
---|
| 1432 | }
|
---|
| 1433 |
|
---|
| 1434 | /* ******************************************************************
|
---|
[14] | 1435 | *
|
---|
| 1436 | * Device-independent text painting
|
---|
| 1437 | *
|
---|
[8] | 1438 | ********************************************************************/
|
---|
| 1439 |
|
---|
| 1440 | /*
|
---|
| 1441 | *@@ DrawListMarker:
|
---|
| 1442 | *
|
---|
| 1443 | *@@added V0.9.3 (2000-05-17) [umoeller]
|
---|
| 1444 | */
|
---|
| 1445 |
|
---|
[222] | 1446 | STATIC VOID DrawListMarker(HPS hps,
|
---|
[142] | 1447 | PRECTL prclLine, // current line rectangle
|
---|
| 1448 | PTXVWORD pWordThis, // current word
|
---|
| 1449 | LONG lViewXOfs) // in: x offset to paint; 0 means rightmost
|
---|
[8] | 1450 | {
|
---|
| 1451 | POINTL ptl;
|
---|
| 1452 |
|
---|
| 1453 | ULONG ulBulletSize = pWordThis->lPointSize * 2 / 3; // 2/3 of point size
|
---|
| 1454 |
|
---|
| 1455 | ARCPARAMS arcp = {1, 1, 0, 0};
|
---|
| 1456 |
|
---|
| 1457 | // pWordThis->pStart points to the \xFF character;
|
---|
| 1458 | // next is the "marker" escape (\x23),
|
---|
| 1459 | // next is the marker type
|
---|
| 1460 | CHAR cBulletType = *((pWordThis->pStart) + 2) ;
|
---|
| 1461 |
|
---|
| 1462 | switch (cBulletType)
|
---|
| 1463 | {
|
---|
| 1464 | case 2: // square (filled box)
|
---|
| 1465 | ptl.x = pWordThis->lX - lViewXOfs;
|
---|
| 1466 | // center bullet vertically
|
---|
| 1467 | ptl.y = prclLine->yBottom
|
---|
| 1468 | + ( (prclLine->yTop - prclLine->yBottom) // height
|
---|
| 1469 | - ulBulletSize
|
---|
| 1470 | ) / 2;
|
---|
| 1471 |
|
---|
| 1472 | GpiMove(hps, &ptl);
|
---|
| 1473 | ptl.x += ulBulletSize;
|
---|
| 1474 | ptl.y += ulBulletSize;
|
---|
| 1475 | GpiBox(hps, DRO_FILL, &ptl, 0, 0);
|
---|
| 1476 | break;
|
---|
| 1477 |
|
---|
| 1478 | default: // case 1: // disc (filled circle)
|
---|
| 1479 | ptl.x = pWordThis->lX - lViewXOfs;
|
---|
| 1480 | // center bullet vertically;
|
---|
| 1481 | // the arc is drawn with the current position in its center
|
---|
| 1482 | ptl.y = prclLine->yBottom
|
---|
| 1483 | + ( (prclLine->yTop - prclLine->yBottom) // height
|
---|
| 1484 | / 2
|
---|
| 1485 | );
|
---|
| 1486 |
|
---|
| 1487 | GpiSetArcParams(hps, &arcp);
|
---|
| 1488 | GpiMove(hps, &ptl);
|
---|
| 1489 | GpiFullArc(hps,
|
---|
| 1490 | (cBulletType == 3)
|
---|
| 1491 | ? DRO_OUTLINE
|
---|
| 1492 | : DRO_FILL,
|
---|
| 1493 | MAKEFIXED(ulBulletSize / 2, // radius!
|
---|
| 1494 | 0));
|
---|
| 1495 | break;
|
---|
| 1496 |
|
---|
| 1497 | }
|
---|
| 1498 | }
|
---|
| 1499 |
|
---|
| 1500 | /*
|
---|
| 1501 | *@@ txvPaintText:
|
---|
| 1502 | * device-independent function for painting.
|
---|
| 1503 | * This can only be called after the text has
|
---|
| 1504 | * been formatted (using txvFormatText).
|
---|
| 1505 | *
|
---|
| 1506 | * This only paints rectangles which are within
|
---|
| 1507 | * prcl2Paint.
|
---|
| 1508 | *
|
---|
[206] | 1509 | * -- For WM_PAINT, set this to the
|
---|
| 1510 | * update rectangle, and set fPaintHalfLines
|
---|
| 1511 | * to TRUE.
|
---|
[8] | 1512 | *
|
---|
[206] | 1513 | * -- For printing, set this to the page rectangle,
|
---|
| 1514 | * and set fPaintHalfLines to FALSE.
|
---|
[8] | 1515 | *
|
---|
| 1516 | * All coordinates are in world space (PU_PELS).
|
---|
| 1517 | *
|
---|
| 1518 | *@@changed V0.9.3 (2000-05-05) [umoeller]: fixed wrong visible lines calculations; great speedup painting!
|
---|
| 1519 | *@@changed V0.9.3 (2000-05-06) [umoeller]: now using gpihCharStringPosAt
|
---|
| 1520 | */
|
---|
| 1521 |
|
---|
| 1522 | BOOL txvPaintText(HAB hab,
|
---|
| 1523 | HPS hps, // in: window or printer PS
|
---|
| 1524 | PXFORMATDATA pxfd,
|
---|
| 1525 | PRECTL prcl2Paint, // in: invalid rectangle to be drawn,
|
---|
| 1526 | // can be NULL to paint all
|
---|
| 1527 | LONG lViewXOfs, // in: x offset to paint; 0 means rightmost
|
---|
[25] | 1528 | PULONG pulViewYOfs, // in: y offset to paint; 0 means _top_most;
|
---|
[8] | 1529 | // out: y offset which should be passed to next call
|
---|
| 1530 | // (if TRUE is returned and fPaintHalfLines == FALSE)
|
---|
| 1531 | BOOL fPaintHalfLines, // in: if FALSE, lines which do not fully fit on
|
---|
| 1532 | // the page are dropped (useful for printing)
|
---|
| 1533 | PULONG pulLineIndex) // in: line to start painting with;
|
---|
| 1534 | // out: next line to paint, if any
|
---|
| 1535 | // (if TRUE is returned and fPaintHalfLines == FALSE)
|
---|
| 1536 | {
|
---|
| 1537 | BOOL brc = FALSE,
|
---|
| 1538 | fAnyLinesPainted = FALSE;
|
---|
| 1539 | ULONG ulCurrentLineIndex = *pulLineIndex;
|
---|
[25] | 1540 | // LONG lViewYOfsSaved = *pulViewYOfs;
|
---|
[8] | 1541 | PLISTNODE pRectNode = lstNodeFromIndex(&pxfd->llRectangles,
|
---|
| 1542 | ulCurrentLineIndex);
|
---|
| 1543 |
|
---|
| 1544 | LONG lcidLast = -99;
|
---|
| 1545 | LONG lPointSizeLast = -99;
|
---|
| 1546 |
|
---|
| 1547 | while (pRectNode)
|
---|
| 1548 | {
|
---|
| 1549 | PTXVRECTANGLE pLineRcl = (PTXVRECTANGLE)pRectNode->pItemData;
|
---|
| 1550 | BOOL fPaintThis = FALSE;
|
---|
| 1551 |
|
---|
| 1552 | // compose rectangle to draw for this line
|
---|
| 1553 | RECTL rclLine;
|
---|
| 1554 | rclLine.xLeft = pLineRcl->rcl.xLeft - lViewXOfs;
|
---|
| 1555 | rclLine.xRight = pLineRcl->rcl.xRight - lViewXOfs;
|
---|
[25] | 1556 | rclLine.yBottom = pLineRcl->rcl.yBottom + *pulViewYOfs;
|
---|
| 1557 | rclLine.yTop = pLineRcl->rcl.yTop + *pulViewYOfs;
|
---|
[8] | 1558 |
|
---|
| 1559 | /* if (pmpf)
|
---|
| 1560 | {
|
---|
| 1561 | CHAR szTemp[100];
|
---|
| 1562 | ULONG cb = min(pLineRcl->cLineChars, 99);
|
---|
| 1563 | strhncpy0(szTemp, pLineRcl->pStartOfLine, cb);
|
---|
| 1564 |
|
---|
| 1565 | _Pmpf(("Checking line %d: '%s'",
|
---|
| 1566 | ulCurrentLineIndex,
|
---|
| 1567 | szTemp));
|
---|
| 1568 |
|
---|
| 1569 | _Pmpf((" (yB stored %d -> in HPS %d against win yB %d)",
|
---|
| 1570 | pLineRcl->rcl.yBottom,
|
---|
| 1571 | rclLine.yBottom,
|
---|
| 1572 | prcl2Paint->yBottom));
|
---|
| 1573 | } */
|
---|
| 1574 |
|
---|
| 1575 | if (prcl2Paint == NULL)
|
---|
| 1576 | // draw all:
|
---|
| 1577 | fPaintThis = TRUE;
|
---|
| 1578 | else
|
---|
| 1579 | {
|
---|
| 1580 | BOOL fBottomInPaint = ( (rclLine.yBottom >= prcl2Paint->yBottom)
|
---|
| 1581 | && (rclLine.yBottom <= prcl2Paint->yTop)
|
---|
| 1582 | );
|
---|
| 1583 | BOOL fTopInPaint = ( (rclLine.yTop >= prcl2Paint->yBottom)
|
---|
| 1584 | && (rclLine.yTop <= prcl2Paint->yTop)
|
---|
| 1585 | );
|
---|
| 1586 |
|
---|
| 1587 | if ((fBottomInPaint) && (fTopInPaint))
|
---|
| 1588 | // both in update rect:
|
---|
| 1589 | fPaintThis = TRUE;
|
---|
| 1590 | else
|
---|
| 1591 | if (fPaintHalfLines)
|
---|
| 1592 | {
|
---|
| 1593 | if ((fBottomInPaint) || (fTopInPaint))
|
---|
| 1594 | // only one in update rect:
|
---|
| 1595 | fPaintThis = TRUE;
|
---|
| 1596 | else
|
---|
| 1597 | // now, for very small update rectangles,
|
---|
| 1598 | // especially with slow scrolling,
|
---|
| 1599 | // we can have the case that the paint rectangle
|
---|
| 1600 | // is only a few pixels high so that the top of
|
---|
| 1601 | // the line is above the repaint, and the bottom
|
---|
| 1602 | // of the line is below it!
|
---|
| 1603 | if ( (rclLine.yTop >= prcl2Paint->yTop)
|
---|
| 1604 | && (rclLine.yBottom <= prcl2Paint->yBottom)
|
---|
| 1605 | )
|
---|
| 1606 | fPaintThis = TRUE;
|
---|
| 1607 | }
|
---|
| 1608 | }
|
---|
| 1609 |
|
---|
| 1610 | if (fPaintThis)
|
---|
| 1611 | {
|
---|
| 1612 | // rectangle invalid: paint this rectangle
|
---|
| 1613 | // by going thru the member words
|
---|
| 1614 | PLISTNODE pWordNode = lstQueryFirstNode(&pLineRcl->llWords);
|
---|
| 1615 |
|
---|
| 1616 | POINTL ptlStart;
|
---|
| 1617 |
|
---|
| 1618 | while (pWordNode)
|
---|
| 1619 | {
|
---|
| 1620 | PTXVWORD pWordThis = (PTXVWORD)pWordNode->pItemData;
|
---|
[201] | 1621 | ULONG flChar = pWordThis->flChar;
|
---|
[8] | 1622 |
|
---|
[206] | 1623 | if (pWordThis->pcszLinkTarget) // V0.9.20 (2002-08-10) [umoeller]
|
---|
[201] | 1624 | flChar |= CHS_UNDERSCORE;
|
---|
[8] | 1625 |
|
---|
| 1626 | // x start: this word's X coordinate
|
---|
| 1627 | ptlStart.x = pWordThis->lX - lViewXOfs;
|
---|
| 1628 | // y start: bottom line of rectangle plus highest
|
---|
| 1629 | // base line offset found in all words (format step 2)
|
---|
| 1630 | ptlStart.y = rclLine.yBottom + pLineRcl->ulMaxBaseLineOfs;
|
---|
| 1631 | // pWordThis->ulBaseLineOfs;
|
---|
| 1632 |
|
---|
| 1633 | // set font for subsequent calculations,
|
---|
| 1634 | // if changed (this includes the first call)
|
---|
| 1635 | if (lcidLast != pWordThis->lcid)
|
---|
| 1636 | {
|
---|
| 1637 | GpiSetCharSet(hps, pWordThis->lcid);
|
---|
| 1638 | lcidLast = pWordThis->lcid;
|
---|
| 1639 | // force recalc of point size
|
---|
| 1640 | lPointSizeLast = -99;
|
---|
| 1641 | }
|
---|
| 1642 |
|
---|
| 1643 | if (lPointSizeLast != pWordThis->lPointSize)
|
---|
| 1644 | {
|
---|
| 1645 | if (pWordThis->lPointSize)
|
---|
| 1646 | // is outline font:
|
---|
| 1647 | gpihSetPointSize(hps, pWordThis->lPointSize);
|
---|
| 1648 | lPointSizeLast = pWordThis->lPointSize;
|
---|
| 1649 | }
|
---|
| 1650 |
|
---|
| 1651 | if (!pWordThis->cEscapeCode)
|
---|
| 1652 | // regular word:
|
---|
| 1653 | gpihCharStringPosAt(hps,
|
---|
| 1654 | &ptlStart,
|
---|
| 1655 | &rclLine,
|
---|
[201] | 1656 | flChar,
|
---|
[8] | 1657 | pWordThis->cChars,
|
---|
| 1658 | (PSZ)pWordThis->pStart);
|
---|
| 1659 | else
|
---|
| 1660 | {
|
---|
| 1661 | // check escape code
|
---|
| 1662 | switch (pWordThis->cEscapeCode)
|
---|
| 1663 | {
|
---|
| 1664 | case 0x23:
|
---|
| 1665 | // escape to be painted:
|
---|
| 1666 | DrawListMarker(hps,
|
---|
| 1667 | &rclLine,
|
---|
| 1668 | pWordThis,
|
---|
| 1669 | lViewXOfs);
|
---|
| 1670 | break;
|
---|
| 1671 | }
|
---|
| 1672 | }
|
---|
| 1673 |
|
---|
| 1674 | // ptlStart.x += pWordThis->ulCXWithSpaces;
|
---|
| 1675 |
|
---|
| 1676 | fAnyLinesPainted = TRUE;
|
---|
| 1677 | pWordNode = pWordNode->pNext;
|
---|
| 1678 | }
|
---|
| 1679 |
|
---|
| 1680 | /* {
|
---|
| 1681 | LONG lColor = GpiQueryColor(hps);
|
---|
| 1682 | POINTL ptl2;
|
---|
| 1683 | GpiSetColor(hps, RGBCOL_RED);
|
---|
| 1684 | ptl2.x = rclLine.xLeft;
|
---|
| 1685 | ptl2.y = rclLine.yBottom;
|
---|
| 1686 | GpiMove(hps, &ptl2);
|
---|
| 1687 | ptl2.x = rclLine.xRight;
|
---|
| 1688 | ptl2.y = rclLine.yTop;
|
---|
| 1689 | GpiBox(hps,
|
---|
| 1690 | DRO_OUTLINE,
|
---|
| 1691 | &ptl2,
|
---|
| 1692 | 0, 0);
|
---|
| 1693 | GpiSetColor(hps, lColor);
|
---|
| 1694 | } */
|
---|
| 1695 |
|
---|
| 1696 | }
|
---|
| 1697 | else
|
---|
| 1698 | {
|
---|
| 1699 | // this line is no longer fully visible:
|
---|
| 1700 |
|
---|
| 1701 | if (fAnyLinesPainted)
|
---|
| 1702 | {
|
---|
| 1703 | // we had painted lines already:
|
---|
| 1704 | // this means that all the following lines are
|
---|
| 1705 | // too far below the window, so quit
|
---|
| 1706 | /* if (pmpf)
|
---|
| 1707 | _Pmpf(("Quitting with line %d (xL = %d yB = %d)",
|
---|
| 1708 | ulCurrentLineIndex, rclLine.xLeft, rclLine.yBottom)); */
|
---|
| 1709 |
|
---|
| 1710 | *pulLineIndex = ulCurrentLineIndex;
|
---|
| 1711 | if (pRectNode->pNext)
|
---|
| 1712 | {
|
---|
| 1713 | // another line to paint:
|
---|
| 1714 | PTXVRECTANGLE pLineRcl2 = (PTXVRECTANGLE)pRectNode->pNext->pItemData;
|
---|
| 1715 | // return TRUE
|
---|
| 1716 | brc = TRUE;
|
---|
[25] | 1717 | // and set *pulViewYOfs to the top of
|
---|
[8] | 1718 | // the next line, which wasn't visible
|
---|
| 1719 | // on the page any more
|
---|
[25] | 1720 | *pulViewYOfs = pLineRcl2->rcl.yTop + *pulViewYOfs;
|
---|
[8] | 1721 | }
|
---|
| 1722 | break;
|
---|
| 1723 | }
|
---|
| 1724 | // else no lines painted yet:
|
---|
| 1725 | // go for next node, because we're still above the visible window
|
---|
| 1726 | }
|
---|
| 1727 |
|
---|
| 1728 | // next line
|
---|
| 1729 | pRectNode = pRectNode->pNext;
|
---|
| 1730 | // raise index to return
|
---|
| 1731 | ulCurrentLineIndex++;
|
---|
| 1732 | }
|
---|
| 1733 |
|
---|
| 1734 | if (!fAnyLinesPainted)
|
---|
| 1735 | brc = FALSE;
|
---|
| 1736 |
|
---|
[167] | 1737 | return brc;
|
---|
[8] | 1738 | }
|
---|
| 1739 |
|
---|
| 1740 | /*
|
---|
| 1741 | *@@ txvFindWordFromPoint:
|
---|
| 1742 | * returns the list node of the word under the
|
---|
| 1743 | * given point. The list node is from the global
|
---|
| 1744 | * words list in pxfd.
|
---|
| 1745 | *
|
---|
| 1746 | *@@added V0.9.3 (2000-05-18) [umoeller]
|
---|
| 1747 | */
|
---|
| 1748 |
|
---|
| 1749 | PLISTNODE txvFindWordFromPoint(PXFORMATDATA pxfd,
|
---|
| 1750 | PPOINTL pptl)
|
---|
| 1751 | {
|
---|
| 1752 | PLISTNODE pWordNodeFound = NULL;
|
---|
| 1753 |
|
---|
| 1754 | PLISTNODE pRectangleNode = lstQueryFirstNode(&pxfd->llRectangles);
|
---|
| 1755 | while ((pRectangleNode) && (!pWordNodeFound))
|
---|
| 1756 | {
|
---|
| 1757 | PTXVRECTANGLE prclThis = (PTXVRECTANGLE)pRectangleNode->pItemData;
|
---|
| 1758 | if ( (pptl->x >= prclThis->rcl.xLeft)
|
---|
| 1759 | && (pptl->x <= prclThis->rcl.xRight)
|
---|
| 1760 | && (pptl->y >= prclThis->rcl.yBottom)
|
---|
| 1761 | && (pptl->y <= prclThis->rcl.yTop)
|
---|
| 1762 | )
|
---|
| 1763 | {
|
---|
| 1764 | // cool, we found the rectangle:
|
---|
| 1765 | // now go thru the words in this rectangle
|
---|
| 1766 | PLISTNODE pWordNode = lstQueryFirstNode(&prclThis->llWords);
|
---|
| 1767 | while (pWordNode)
|
---|
| 1768 | {
|
---|
| 1769 | PTXVWORD pWordThis = (PTXVWORD)pWordNode->pItemData;
|
---|
| 1770 |
|
---|
| 1771 | if ( (pptl->x >= pWordThis->lX)
|
---|
| 1772 | && (pptl->x <= pWordThis->lX + pWordThis->ulCXWithSpaces)
|
---|
| 1773 | )
|
---|
| 1774 | {
|
---|
| 1775 | pWordNodeFound = pWordNode;
|
---|
| 1776 | break;
|
---|
| 1777 | }
|
---|
| 1778 | pWordNode = pWordNode->pNext;
|
---|
| 1779 | }
|
---|
| 1780 | }
|
---|
| 1781 | pRectangleNode = pRectangleNode->pNext;
|
---|
| 1782 | }
|
---|
| 1783 |
|
---|
[201] | 1784 | return pWordNodeFound;
|
---|
[8] | 1785 | }
|
---|
| 1786 |
|
---|
| 1787 | /*
|
---|
| 1788 | *@@ txvFindWordFromAnchor:
|
---|
| 1789 | * returns the list node from the global words list
|
---|
| 1790 | * BEFORE the word which represents the escape sequence
|
---|
| 1791 | * containing the specified anchor name.
|
---|
| 1792 | *
|
---|
| 1793 | *@@added V0.9.4 (2000-06-12) [umoeller]
|
---|
| 1794 | */
|
---|
| 1795 |
|
---|
| 1796 | PLISTNODE txvFindWordFromAnchor(PXFORMATDATA pxfd,
|
---|
| 1797 | const char *pszAnchorName)
|
---|
| 1798 | {
|
---|
| 1799 | PLISTNODE pNodeFound = NULL;
|
---|
| 1800 |
|
---|
| 1801 | ULONG cbAnchorName = strlen(pszAnchorName);
|
---|
| 1802 |
|
---|
| 1803 | PLISTNODE pWordNode = lstQueryFirstNode(&pxfd->llWords);
|
---|
| 1804 | while ((pWordNode) && (!pNodeFound))
|
---|
| 1805 | {
|
---|
| 1806 | PTXVWORD pWordThis = (PTXVWORD)pWordNode->pItemData;
|
---|
| 1807 | if (pWordThis->cEscapeCode == 7)
|
---|
| 1808 | {
|
---|
| 1809 | // this word is an anchor escape sequence:
|
---|
| 1810 | if (strnicmp(pszAnchorName, (pWordThis->pStart + 2), cbAnchorName) == 0)
|
---|
| 1811 | {
|
---|
| 1812 | // matches: check length
|
---|
| 1813 | if (*(pWordThis->pStart + 2 + cbAnchorName) == (char)0xFF)
|
---|
| 1814 | // OK:
|
---|
| 1815 | pNodeFound = pWordNode;
|
---|
| 1816 | }
|
---|
| 1817 | }
|
---|
| 1818 |
|
---|
| 1819 | pWordNode = pWordNode ->pNext;
|
---|
| 1820 | }
|
---|
| 1821 |
|
---|
| 1822 | if (pNodeFound)
|
---|
| 1823 | {
|
---|
| 1824 | // anchor found:
|
---|
| 1825 | // go backwords in word list until we find a "real" word
|
---|
| 1826 | // which is no escape sequence
|
---|
| 1827 | while (pNodeFound)
|
---|
| 1828 | {
|
---|
| 1829 | PTXVWORD pWordThis = (PTXVWORD)pNodeFound->pItemData;
|
---|
| 1830 | if (pWordThis->cEscapeCode)
|
---|
| 1831 | pNodeFound = pNodeFound->pPrevious;
|
---|
| 1832 | else
|
---|
| 1833 | break;
|
---|
| 1834 | }
|
---|
| 1835 | }
|
---|
| 1836 |
|
---|
[201] | 1837 | return pNodeFound;
|
---|
[8] | 1838 | }
|
---|
| 1839 |
|
---|
| 1840 | /* ******************************************************************
|
---|
[14] | 1841 | *
|
---|
| 1842 | * Window-dependent functions
|
---|
| 1843 | *
|
---|
[8] | 1844 | ********************************************************************/
|
---|
| 1845 |
|
---|
[201] | 1846 | #define QWL_PRIVATE 4 // V0.9.20 (2002-08-10) [umoeller]
|
---|
| 1847 |
|
---|
[8] | 1848 | /*
|
---|
| 1849 | *@@ TEXTVIEWWINDATA:
|
---|
| 1850 | * view control-internal structure, stored in
|
---|
[201] | 1851 | * QWL_PRIVATE at fnwpTextView.
|
---|
[8] | 1852 | * This is device-dependent on the text view
|
---|
| 1853 | * window.
|
---|
| 1854 | */
|
---|
| 1855 |
|
---|
| 1856 | typedef struct _TEXTVIEWWINDATA
|
---|
| 1857 | {
|
---|
| 1858 | HAB hab; // anchor block (for speed)
|
---|
| 1859 |
|
---|
| 1860 | HDC hdc;
|
---|
| 1861 | HPS hps;
|
---|
| 1862 |
|
---|
[201] | 1863 | ULONG flStyle; // window style flags copied on WM_CREATE
|
---|
| 1864 | // V0.9.20 (2002-08-10) [umoeller]
|
---|
| 1865 |
|
---|
[8] | 1866 | LONG lBackColor,
|
---|
| 1867 | lForeColor;
|
---|
| 1868 |
|
---|
| 1869 | XTEXTVIEWCDATA cdata; // control data, as passed to WM_CREATE
|
---|
| 1870 |
|
---|
| 1871 | XFORMATDATA xfd;
|
---|
| 1872 |
|
---|
| 1873 | HWND hwndVScroll, // vertical scroll bar
|
---|
| 1874 | hwndHScroll; // horizontal scroll bar
|
---|
| 1875 |
|
---|
| 1876 | BOOL fVScrollVisible, // TRUE if vscroll is currently used
|
---|
| 1877 | fHScrollVisible; // TRUE if hscroll is currently used
|
---|
| 1878 |
|
---|
| 1879 | RECTL rclViewReal, // window rect as returned by WinQueryWindowRect
|
---|
[201] | 1880 | // (top right point is inclusive!)
|
---|
[8] | 1881 | rclViewPaint, // same as rclViewReal, but excluding scroll bars
|
---|
| 1882 | rclViewText; // same as rclViewPaint, but excluding cdata borders
|
---|
| 1883 |
|
---|
[25] | 1884 | ULONG ulViewXOfs, // pixels that we have scrolled to the RIGHT; 0 means very left
|
---|
| 1885 | ulViewYOfs; // pixels that we have scrolled to the BOTTOM; 0 means very top
|
---|
[8] | 1886 |
|
---|
| 1887 | BOOL fAcceptsPresParamsNow; // TRUE after first WM_PAINT
|
---|
| 1888 |
|
---|
| 1889 | // anchor clicking
|
---|
| 1890 | PLISTNODE pWordNodeFirstInAnchor; // points to first word which belongs to anchor
|
---|
[201] | 1891 | // USHORT usLastAnchorClicked; // last anchor which was clicked (1-0xFFFF)
|
---|
[206] | 1892 | PCSZ pcszLastLinkClicked; // last link that was clicked (points into llLinks)
|
---|
| 1893 | // V0.9.20 (2002-08-10) [umoeller]
|
---|
[201] | 1894 |
|
---|
[8] | 1895 | } TEXTVIEWWINDATA, *PTEXTVIEWWINDATA;
|
---|
| 1896 |
|
---|
| 1897 | #define ID_VSCROLL 100
|
---|
| 1898 | #define ID_HSCROLL 101
|
---|
| 1899 |
|
---|
| 1900 | /*
|
---|
| 1901 | *@@ UpdateTextViewPresData:
|
---|
| 1902 | * called from WM_CREATE and WM_PRESPARAMCHANGED
|
---|
| 1903 | * in fnwpTextView to update the TEXTVIEWWINDATA
|
---|
| 1904 | * from the window's presparams. This calls
|
---|
| 1905 | * txvSetDefaultFormat in turn.
|
---|
| 1906 | */
|
---|
| 1907 |
|
---|
[222] | 1908 | STATIC VOID UpdateTextViewPresData(HWND hwndTextView,
|
---|
[142] | 1909 | PTEXTVIEWWINDATA ptxvd)
|
---|
[8] | 1910 | {
|
---|
| 1911 | PSZ pszFont;
|
---|
| 1912 | ptxvd->lBackColor = winhQueryPresColor(hwndTextView,
|
---|
| 1913 | PP_BACKGROUNDCOLOR,
|
---|
| 1914 | FALSE, // no inherit
|
---|
| 1915 | SYSCLR_DIALOGBACKGROUND);
|
---|
| 1916 | ptxvd->lForeColor = winhQueryPresColor(hwndTextView,
|
---|
| 1917 | PP_FOREGROUNDCOLOR,
|
---|
| 1918 | FALSE, // no inherit
|
---|
| 1919 | SYSCLR_WINDOWSTATICTEXT);
|
---|
| 1920 |
|
---|
| 1921 | if ((pszFont = winhQueryWindowFont(hwndTextView)))
|
---|
| 1922 | {
|
---|
| 1923 | ULONG ulSize;
|
---|
| 1924 | PSZ pszFaceName;
|
---|
| 1925 | // _Pmpf(("font: %s", pszFont));
|
---|
| 1926 | if (gpihSplitPresFont(pszFont,
|
---|
| 1927 | &ulSize,
|
---|
| 1928 | &pszFaceName))
|
---|
| 1929 | {
|
---|
[142] | 1930 | SetFormatFont(ptxvd->hps,
|
---|
[8] | 1931 | &ptxvd->xfd.fmtcStandard,
|
---|
| 1932 | ulSize,
|
---|
| 1933 | pszFaceName);
|
---|
| 1934 | }
|
---|
| 1935 | free(pszFont);
|
---|
| 1936 | }
|
---|
| 1937 | }
|
---|
| 1938 |
|
---|
| 1939 | /*
|
---|
| 1940 | *@@ AdjustViewRects:
|
---|
| 1941 | * updates the internal size-dependent structures
|
---|
| 1942 | * and positions the scroll bars.
|
---|
| 1943 | *
|
---|
| 1944 | * This is device-dependent for the text view
|
---|
| 1945 | * control and must be called before FormatText2Screen
|
---|
| 1946 | * so that the view rectangles get calculated right.
|
---|
| 1947 | *
|
---|
| 1948 | * Required input in TEXTVIEWWINDATA:
|
---|
| 1949 | *
|
---|
| 1950 | * -- rclViewReal: the actual window dimensions.
|
---|
| 1951 | *
|
---|
| 1952 | * -- cdata: control data.
|
---|
| 1953 | *
|
---|
| 1954 | * Output from this function in TEXTVIEWWINDATA:
|
---|
| 1955 | *
|
---|
| 1956 | * -- rclViewPaint: the paint subrectangle (which
|
---|
| 1957 | * is rclViewReal minus scrollbars, if any).
|
---|
| 1958 | *
|
---|
| 1959 | * -- rclViewText: the text subrectangle (which
|
---|
| 1960 | * is rclViewPaint minus borders).
|
---|
[374] | 1961 | *
|
---|
| 1962 | *@@changed WarpIN V1.0.18 (2008-11-16) [pr]: fix cut/paste/typo. errors @@fixes 1086
|
---|
[8] | 1963 | */
|
---|
| 1964 |
|
---|
[222] | 1965 | STATIC VOID AdjustViewRects(HWND hwndTextView,
|
---|
[142] | 1966 | PTEXTVIEWWINDATA ptxvd)
|
---|
[8] | 1967 | {
|
---|
| 1968 | ULONG ulScrollCX = WinQuerySysValue(HWND_DESKTOP, SV_CXVSCROLL),
|
---|
| 1969 | ulScrollCY = WinQuerySysValue(HWND_DESKTOP, SV_CYHSCROLL),
|
---|
| 1970 | ulOfs;
|
---|
| 1971 |
|
---|
| 1972 | // calculate rclViewPaint:
|
---|
| 1973 | // 1) left
|
---|
| 1974 | ptxvd->rclViewPaint.xLeft = ptxvd->rclViewReal.xLeft;
|
---|
| 1975 | // 2) bottom
|
---|
| 1976 | ptxvd->rclViewPaint.yBottom = ptxvd->rclViewReal.yBottom;
|
---|
| 1977 | if (ptxvd->fHScrollVisible)
|
---|
| 1978 | // if we have a horizontal scroll bar at the bottom,
|
---|
| 1979 | // raise bottom by its height
|
---|
| 1980 | ptxvd->rclViewPaint.yBottom += ulScrollCY;
|
---|
| 1981 | // 3) right
|
---|
| 1982 | ptxvd->rclViewPaint.xRight = ptxvd->rclViewReal.xRight;
|
---|
| 1983 | if (ptxvd->fVScrollVisible)
|
---|
| 1984 | // if we have a vertical scroll bar at the right,
|
---|
| 1985 | // subtract its width from the right
|
---|
| 1986 | ptxvd->rclViewPaint.xRight -= ulScrollCX;
|
---|
| 1987 | ptxvd->rclViewPaint.yTop = ptxvd->rclViewReal.yTop;
|
---|
| 1988 |
|
---|
| 1989 | // calculate rclViewText from that
|
---|
| 1990 | ptxvd->rclViewText.xLeft = ptxvd->rclViewPaint.xLeft + ptxvd->cdata.ulXBorder;
|
---|
| 1991 | ptxvd->rclViewText.yBottom = ptxvd->rclViewPaint.yBottom + ptxvd->cdata.ulYBorder;
|
---|
| 1992 | ptxvd->rclViewText.xRight = ptxvd->rclViewPaint.xRight - ptxvd->cdata.ulXBorder;
|
---|
[374] | 1993 | ptxvd->rclViewText.yTop = ptxvd->rclViewPaint.yTop - ptxvd->cdata.ulYBorder; // WarpIN V1.0.18
|
---|
[8] | 1994 |
|
---|
| 1995 | // now reposition scroll bars; their sizes may change
|
---|
| 1996 | // if either the vertical or horizontal scroll bar has
|
---|
| 1997 | // popped up or been hidden
|
---|
[201] | 1998 | if (ptxvd->flStyle & XS_VSCROLL)
|
---|
[8] | 1999 | {
|
---|
| 2000 | // vertical scroll bar enabled:
|
---|
| 2001 | ulOfs = 0;
|
---|
| 2002 | if (ptxvd->fHScrollVisible)
|
---|
[374] | 2003 | ulOfs = ulScrollCY; // WarpIN V1.0.18
|
---|
[8] | 2004 | WinSetWindowPos(ptxvd->hwndVScroll,
|
---|
| 2005 | HWND_TOP,
|
---|
| 2006 | ptxvd->rclViewReal.xRight - ulScrollCX,
|
---|
| 2007 | ulOfs, // y
|
---|
| 2008 | ulScrollCX, // cx
|
---|
| 2009 | ptxvd->rclViewReal.yTop - ulOfs, // cy
|
---|
| 2010 | SWP_MOVE | SWP_SIZE);
|
---|
| 2011 | }
|
---|
| 2012 |
|
---|
[201] | 2013 | if (ptxvd->flStyle & XS_HSCROLL)
|
---|
[8] | 2014 | {
|
---|
| 2015 | ulOfs = 0;
|
---|
| 2016 | if (ptxvd->fVScrollVisible)
|
---|
| 2017 | ulOfs = ulScrollCX;
|
---|
| 2018 | WinSetWindowPos(ptxvd->hwndHScroll,
|
---|
| 2019 | HWND_TOP,
|
---|
| 2020 | 0,
|
---|
| 2021 | 0,
|
---|
| 2022 | ptxvd->rclViewReal.xRight - ulOfs, // cx
|
---|
| 2023 | ulScrollCY, // cy
|
---|
| 2024 | SWP_MOVE | SWP_SIZE);
|
---|
| 2025 | }
|
---|
| 2026 | }
|
---|
| 2027 |
|
---|
| 2028 | /*
|
---|
| 2029 | *@@ FormatText2Screen:
|
---|
| 2030 | * device-dependent version of text formatting
|
---|
| 2031 | * for the text view window. This calls txvFormatText
|
---|
| 2032 | * in turn and updates the view's scroll bars.
|
---|
| 2033 | *
|
---|
| 2034 | *@@changed V0.9.3 (2000-05-05) [umoeller]: fixed buggy vertical scroll bars
|
---|
[374] | 2035 | *@@changed WarpIN V1.0.18 (2008-11-16) [pr]: fix buggy horiz. scroll bars @@fixes 1086
|
---|
[8] | 2036 | */
|
---|
| 2037 |
|
---|
[222] | 2038 | STATIC VOID FormatText2Screen(HWND hwndTextView,
|
---|
[142] | 2039 | PTEXTVIEWWINDATA ptxvd,
|
---|
| 2040 | BOOL fAlreadyRecursing, // in: set this to FALSE when calling
|
---|
| 2041 | BOOL fFullRecalc)
|
---|
[8] | 2042 | {
|
---|
| 2043 | ULONG ulWinCX,
|
---|
| 2044 | ulWinCY;
|
---|
| 2045 |
|
---|
| 2046 | // call device-independent formatter with the
|
---|
| 2047 | // window presentation space
|
---|
| 2048 | txvFormatText(ptxvd->hps,
|
---|
| 2049 | &ptxvd->xfd,
|
---|
| 2050 | &ptxvd->rclViewText,
|
---|
| 2051 | fFullRecalc);
|
---|
| 2052 |
|
---|
| 2053 | ulWinCY = (ptxvd->rclViewText.yTop - ptxvd->rclViewText.yBottom);
|
---|
| 2054 |
|
---|
[25] | 2055 | if (ptxvd->ulViewYOfs < 0)
|
---|
| 2056 | ptxvd->ulViewYOfs = 0;
|
---|
[201] | 2057 | if (ptxvd->ulViewYOfs > ((LONG)ptxvd->xfd.szlWorkspace.cy - ulWinCY))
|
---|
| 2058 | ptxvd->ulViewYOfs = (LONG)ptxvd->xfd.szlWorkspace.cy - ulWinCY;
|
---|
[8] | 2059 |
|
---|
| 2060 | // vertical scroll bar enabled at all?
|
---|
[201] | 2061 | if (ptxvd->flStyle & XS_VSCROLL)
|
---|
[8] | 2062 | {
|
---|
| 2063 | BOOL fEnabled = winhUpdateScrollBar(ptxvd->hwndVScroll,
|
---|
| 2064 | ulWinCY,
|
---|
[201] | 2065 | ptxvd->xfd.szlWorkspace.cy,
|
---|
[25] | 2066 | ptxvd->ulViewYOfs,
|
---|
[201] | 2067 | (ptxvd->flStyle & XS_AUTOVHIDE));
|
---|
[8] | 2068 | // is auto-hide on?
|
---|
[201] | 2069 | if (ptxvd->flStyle & XS_AUTOVHIDE)
|
---|
[8] | 2070 | {
|
---|
| 2071 | // yes, auto-hide on: did visibility change?
|
---|
| 2072 | if (fEnabled != ptxvd->fVScrollVisible)
|
---|
| 2073 | // visibility changed:
|
---|
| 2074 | // if we're not already recursing,
|
---|
| 2075 | // force calling ourselves again
|
---|
| 2076 | if (!fAlreadyRecursing)
|
---|
| 2077 | {
|
---|
| 2078 | ptxvd->fVScrollVisible = fEnabled;
|
---|
| 2079 | AdjustViewRects(hwndTextView,
|
---|
| 2080 | ptxvd);
|
---|
| 2081 | FormatText2Screen(hwndTextView,
|
---|
| 2082 | ptxvd,
|
---|
| 2083 | TRUE, // fAlreadyRecursing
|
---|
| 2084 | FALSE); // quick format
|
---|
| 2085 | }
|
---|
| 2086 | }
|
---|
| 2087 | }
|
---|
| 2088 |
|
---|
| 2089 | ulWinCX = (ptxvd->rclViewText.xRight - ptxvd->rclViewText.xLeft);
|
---|
| 2090 |
|
---|
| 2091 | // horizontal scroll bar enabled at all?
|
---|
[201] | 2092 | if (ptxvd->flStyle & XS_HSCROLL)
|
---|
[8] | 2093 | {
|
---|
| 2094 | BOOL fEnabled = winhUpdateScrollBar(ptxvd->hwndHScroll,
|
---|
| 2095 | ulWinCX,
|
---|
[201] | 2096 | ptxvd->xfd.szlWorkspace.cx,
|
---|
[25] | 2097 | ptxvd->ulViewXOfs,
|
---|
[201] | 2098 | (ptxvd->flStyle & XS_AUTOHHIDE));
|
---|
[8] | 2099 | // is auto-hide on?
|
---|
[201] | 2100 | if (ptxvd->flStyle & XS_AUTOHHIDE)
|
---|
[8] | 2101 | {
|
---|
| 2102 | // yes, auto-hide on: did visibility change?
|
---|
| 2103 | if (fEnabled != ptxvd->fHScrollVisible)
|
---|
| 2104 | // visibility changed:
|
---|
| 2105 | // if we're not already recursing,
|
---|
| 2106 | // force calling ourselves again (at the bottom)
|
---|
| 2107 | if (!fAlreadyRecursing)
|
---|
| 2108 | {
|
---|
| 2109 | ptxvd->fHScrollVisible = fEnabled;
|
---|
| 2110 | AdjustViewRects(hwndTextView,
|
---|
| 2111 | ptxvd);
|
---|
[374] | 2112 | FormatText2Screen(hwndTextView, // WarpIN V1.0.18
|
---|
| 2113 | ptxvd,
|
---|
| 2114 | TRUE, // fAlreadyRecursing
|
---|
| 2115 | FALSE); // quick format
|
---|
[8] | 2116 | }
|
---|
| 2117 | }
|
---|
| 2118 | }
|
---|
| 2119 |
|
---|
| 2120 | WinInvalidateRect(hwndTextView, NULL, FALSE);
|
---|
| 2121 | }
|
---|
| 2122 |
|
---|
| 2123 | /*
|
---|
[201] | 2124 | *@@ SetWindowText:
|
---|
| 2125 | * implementation for WM_SETWINDOWPARAMS and
|
---|
| 2126 | * also WM_CREATE to set the window text.
|
---|
| 2127 | *
|
---|
| 2128 | *@@added V0.9.20 (2002-08-10) [umoeller]
|
---|
[375] | 2129 | *@@changed WarpIN V1.0.18 (2008-11-29) [pr]
|
---|
[201] | 2130 | */
|
---|
| 2131 |
|
---|
| 2132 | VOID SetWindowText(HWND hwndTextView,
|
---|
| 2133 | PTEXTVIEWWINDATA ptxvd,
|
---|
| 2134 | PCSZ pcszText)
|
---|
| 2135 | {
|
---|
| 2136 | if (pcszText && *pcszText)
|
---|
| 2137 | {
|
---|
| 2138 | PXSTRING pstr = &ptxvd->xfd.strViewText;
|
---|
| 2139 | PSZ p;
|
---|
| 2140 |
|
---|
[375] | 2141 | // WarpIN V1.0.18
|
---|
| 2142 | xstrcpy(&ptxvd->xfd.strOrigText,
|
---|
| 2143 | pcszText,
|
---|
| 2144 | 0);
|
---|
| 2145 |
|
---|
[201] | 2146 | switch (ptxvd->flStyle & XS_FORMAT_MASK)
|
---|
| 2147 | {
|
---|
| 2148 | case XS_PLAINTEXT: // 0x0100
|
---|
[375] | 2149 | // WarpIN V1.0.18
|
---|
| 2150 | if (p = strdup(pcszText))
|
---|
| 2151 | {
|
---|
| 2152 | PSZ p2;
|
---|
| 2153 | for (p2 = p; p2 = strchr(p2, TXVESC_CHAR); *p2 = ' ');
|
---|
| 2154 | txvStripLinefeeds(&p, 4);
|
---|
| 2155 | xstrset(pstr, p);
|
---|
| 2156 | }
|
---|
[201] | 2157 | break;
|
---|
| 2158 |
|
---|
| 2159 | case XS_HTML: // 0x0200
|
---|
[375] | 2160 | // WarpIN V1.0.18
|
---|
[201] | 2161 | if (p = strdup(pcszText))
|
---|
| 2162 | {
|
---|
[375] | 2163 | PSZ p2;
|
---|
| 2164 | for (p2 = p; p2 = strchr(p2, TXVESC_CHAR); *p2 = ' ');
|
---|
[201] | 2165 | txvConvertFromHTML(&p, NULL, NULL, NULL);
|
---|
| 2166 | xstrset(pstr, p);
|
---|
| 2167 | xstrConvertLineFormat(pstr,
|
---|
| 2168 | CRLF2LF);
|
---|
| 2169 | }
|
---|
| 2170 | break;
|
---|
| 2171 |
|
---|
| 2172 | default: // case XS_PREFORMATTED: // 0x0000
|
---|
| 2173 | // no conversion (default)
|
---|
| 2174 | xstrcpy(pstr,
|
---|
| 2175 | pcszText,
|
---|
| 2176 | 0);
|
---|
| 2177 | break;
|
---|
| 2178 | }
|
---|
| 2179 |
|
---|
| 2180 | // if the last character of the window text is not "\n",
|
---|
| 2181 | // add it explicitly here, or our lines processing
|
---|
| 2182 | // is being funny
|
---|
| 2183 | // V0.9.20 (2002-08-10) [umoeller]
|
---|
| 2184 | if (pstr->psz[pstr->ulLength - 1] != '\n')
|
---|
| 2185 | xstrcatc(pstr, '\n');
|
---|
| 2186 |
|
---|
| 2187 | ptxvd->ulViewXOfs = 0;
|
---|
| 2188 | ptxvd->ulViewYOfs = 0;
|
---|
| 2189 | AdjustViewRects(hwndTextView,
|
---|
| 2190 | ptxvd);
|
---|
| 2191 | FormatText2Screen(hwndTextView,
|
---|
| 2192 | ptxvd,
|
---|
| 2193 | FALSE,
|
---|
| 2194 | TRUE); // full format
|
---|
| 2195 | }
|
---|
| 2196 | }
|
---|
| 2197 |
|
---|
| 2198 | /*
|
---|
[8] | 2199 | *@@ PaintViewText2Screen:
|
---|
| 2200 | * device-dependent version of text painting
|
---|
| 2201 | * for the text view window. This calls txvPaintText
|
---|
| 2202 | * in turn and updates the view's scroll bars.
|
---|
| 2203 | */
|
---|
| 2204 |
|
---|
[222] | 2205 | STATIC VOID PaintViewText2Screen(PTEXTVIEWWINDATA ptxvd,
|
---|
[142] | 2206 | PRECTL prcl2Paint) // in: invalid rectangle, can be NULL == paint all
|
---|
[8] | 2207 | {
|
---|
| 2208 | ULONG ulLineIndex = 0;
|
---|
[25] | 2209 | ULONG ulYOfs = ptxvd->ulViewYOfs;
|
---|
[8] | 2210 | txvPaintText(ptxvd->hab,
|
---|
| 2211 | ptxvd->hps, // paint PS: screen
|
---|
| 2212 | &ptxvd->xfd, // formatting data
|
---|
| 2213 | prcl2Paint, // update rectangle given to us
|
---|
[25] | 2214 | ptxvd->ulViewXOfs, // current X scrolling offset
|
---|
| 2215 | &ulYOfs, // current Y scrolling offset
|
---|
[8] | 2216 | TRUE, // draw even partly visible lines
|
---|
| 2217 | &ulLineIndex);
|
---|
| 2218 | }
|
---|
| 2219 |
|
---|
| 2220 | /*
|
---|
| 2221 | *@@ PaintViewFocus:
|
---|
| 2222 | * paint a focus rectangle.
|
---|
| 2223 | */
|
---|
| 2224 |
|
---|
[222] | 2225 | STATIC VOID PaintViewFocus(HPS hps,
|
---|
[142] | 2226 | PTEXTVIEWWINDATA ptxvd,
|
---|
| 2227 | BOOL fFocus)
|
---|
[8] | 2228 | {
|
---|
| 2229 | POINTL ptl;
|
---|
| 2230 | HRGN hrgn;
|
---|
| 2231 | GpiSetClipRegion(hps,
|
---|
| 2232 | NULLHANDLE,
|
---|
| 2233 | &hrgn);
|
---|
| 2234 | GpiSetColor(hps,
|
---|
| 2235 | (fFocus)
|
---|
| 2236 | ? WinQuerySysColor(HWND_DESKTOP, SYSCLR_HILITEBACKGROUND, 0)
|
---|
| 2237 | : ptxvd->lBackColor);
|
---|
| 2238 | GpiSetLineType(hps, LINETYPE_DOT);
|
---|
| 2239 | ptl.x = ptxvd->rclViewPaint.xLeft;
|
---|
| 2240 | ptl.y = ptxvd->rclViewPaint.yBottom;
|
---|
| 2241 | GpiMove(hps, &ptl);
|
---|
| 2242 | ptl.x = ptxvd->rclViewPaint.xRight - 1;
|
---|
| 2243 | ptl.y = ptxvd->rclViewPaint.yTop - 1;
|
---|
| 2244 | GpiBox(hps,
|
---|
| 2245 | DRO_OUTLINE,
|
---|
| 2246 | &ptl,
|
---|
| 2247 | 0, 0);
|
---|
| 2248 | }
|
---|
| 2249 |
|
---|
| 2250 | /*
|
---|
| 2251 | *@@ RepaintWord:
|
---|
| 2252 | *
|
---|
| 2253 | *@@added V0.9.3 (2000-05-18) [umoeller]
|
---|
| 2254 | */
|
---|
| 2255 |
|
---|
[222] | 2256 | STATIC VOID RepaintWord(PTEXTVIEWWINDATA ptxvd,
|
---|
[142] | 2257 | PTXVWORD pWordThis,
|
---|
| 2258 | LONG lColor)
|
---|
[8] | 2259 | {
|
---|
| 2260 | POINTL ptlStart;
|
---|
[201] | 2261 | ULONG flChar = pWordThis->flChar;
|
---|
[85] | 2262 | PTXVRECTANGLE pLineRcl = pWordThis->pRectangle;
|
---|
[8] | 2263 |
|
---|
| 2264 | RECTL rclLine;
|
---|
[25] | 2265 | rclLine.xLeft = pLineRcl->rcl.xLeft - ptxvd->ulViewXOfs;
|
---|
| 2266 | rclLine.xRight = pLineRcl->rcl.xRight - ptxvd->ulViewXOfs;
|
---|
| 2267 | rclLine.yBottom = pLineRcl->rcl.yBottom + ptxvd->ulViewYOfs;
|
---|
| 2268 | rclLine.yTop = pLineRcl->rcl.yTop + ptxvd->ulViewYOfs;
|
---|
[8] | 2269 |
|
---|
[206] | 2270 | if (pWordThis->pcszLinkTarget)
|
---|
[201] | 2271 | flChar |= CHS_UNDERSCORE;
|
---|
[8] | 2272 |
|
---|
| 2273 | // x start: this word's X coordinate
|
---|
[25] | 2274 | ptlStart.x = pWordThis->lX - ptxvd->ulViewXOfs;
|
---|
[8] | 2275 | // y start: bottom line of rectangle plus highest
|
---|
| 2276 | // base line offset found in all words (format step 2)
|
---|
| 2277 | ptlStart.y = rclLine.yBottom + pLineRcl->ulMaxBaseLineOfs;
|
---|
| 2278 | // pWordThis->ulBaseLineOfs;
|
---|
| 2279 |
|
---|
| 2280 | GpiSetCharSet(ptxvd->hps, pWordThis->lcid);
|
---|
| 2281 | if (pWordThis->lPointSize)
|
---|
| 2282 | // is outline font:
|
---|
| 2283 | gpihSetPointSize(ptxvd->hps, pWordThis->lPointSize);
|
---|
| 2284 |
|
---|
| 2285 | GpiSetColor(ptxvd->hps,
|
---|
| 2286 | lColor);
|
---|
| 2287 |
|
---|
| 2288 | if (!pWordThis->cEscapeCode)
|
---|
[201] | 2289 | {
|
---|
[8] | 2290 | gpihCharStringPosAt(ptxvd->hps,
|
---|
| 2291 | &ptlStart,
|
---|
| 2292 | &rclLine,
|
---|
[201] | 2293 | flChar,
|
---|
[8] | 2294 | pWordThis->cChars,
|
---|
| 2295 | (PSZ)pWordThis->pStart);
|
---|
[201] | 2296 | }
|
---|
[8] | 2297 | else
|
---|
| 2298 | // escape to be painted:
|
---|
| 2299 | DrawListMarker(ptxvd->hps,
|
---|
| 2300 | &rclLine,
|
---|
| 2301 | pWordThis,
|
---|
[25] | 2302 | ptxvd->ulViewXOfs);
|
---|
[8] | 2303 | }
|
---|
| 2304 |
|
---|
| 2305 | /*
|
---|
| 2306 | *@@ RepaintAnchor:
|
---|
| 2307 | *
|
---|
| 2308 | *@@added V0.9.3 (2000-05-18) [umoeller]
|
---|
| 2309 | */
|
---|
| 2310 |
|
---|
[222] | 2311 | STATIC VOID RepaintAnchor(PTEXTVIEWWINDATA ptxvd,
|
---|
[142] | 2312 | LONG lColor)
|
---|
[8] | 2313 | {
|
---|
[206] | 2314 | PLISTNODE pNode = ptxvd->pWordNodeFirstInAnchor;
|
---|
| 2315 | PCSZ pcszLinkTarget = NULL;
|
---|
[8] | 2316 | while (pNode)
|
---|
| 2317 | {
|
---|
| 2318 | PTXVWORD pWordThis = (PTXVWORD)pNode->pItemData;
|
---|
[206] | 2319 | if (!pcszLinkTarget)
|
---|
[8] | 2320 | // first loop:
|
---|
[206] | 2321 | pcszLinkTarget = pWordThis->pcszLinkTarget;
|
---|
[8] | 2322 | else
|
---|
[206] | 2323 | if (pWordThis->pcszLinkTarget != pcszLinkTarget)
|
---|
[8] | 2324 | // first word with different anchor:
|
---|
| 2325 | break;
|
---|
| 2326 |
|
---|
| 2327 | RepaintWord(ptxvd,
|
---|
| 2328 | pWordThis,
|
---|
| 2329 | lColor);
|
---|
| 2330 | pNode = pNode->pNext;
|
---|
| 2331 | }
|
---|
| 2332 | }
|
---|
| 2333 |
|
---|
| 2334 | /*
|
---|
[206] | 2335 | *@@ ProcessCreate:
|
---|
| 2336 | * implementation for WM_CREATE in fnwpTextView.
|
---|
| 2337 | *
|
---|
[229] | 2338 | *@@added V1.0.0 (2002-08-12) [umoeller]
|
---|
[206] | 2339 | */
|
---|
| 2340 |
|
---|
[222] | 2341 | STATIC MRESULT ProcessCreate(HWND hwndTextView, MPARAM mp1, MPARAM mp2)
|
---|
[206] | 2342 | {
|
---|
| 2343 | PXTEXTVIEWCDATA pcd = (PXTEXTVIEWCDATA)mp1;
|
---|
| 2344 | // can be NULL
|
---|
| 2345 | PCREATESTRUCT pcs = (PCREATESTRUCT)mp2;
|
---|
| 2346 | SBCDATA sbcd;
|
---|
| 2347 |
|
---|
| 2348 | MRESULT mrc = (MRESULT)TRUE; // error
|
---|
| 2349 | PTEXTVIEWWINDATA ptxvd;
|
---|
| 2350 |
|
---|
| 2351 | // allocate TEXTVIEWWINDATA for QWL_PRIVATE
|
---|
| 2352 | if (ptxvd = (PTEXTVIEWWINDATA)malloc(sizeof(TEXTVIEWWINDATA)))
|
---|
| 2353 | {
|
---|
| 2354 | SIZEL szlPage = {0, 0};
|
---|
| 2355 | BOOL fShow = FALSE;
|
---|
| 2356 |
|
---|
| 2357 | // query message queue
|
---|
| 2358 | HMQ hmq = WinQueryWindowULong(hwndTextView, QWL_HMQ);
|
---|
| 2359 | // get codepage of message queue
|
---|
| 2360 | ULONG ulCodepage = WinQueryCp(hmq);
|
---|
| 2361 |
|
---|
| 2362 | memset(ptxvd, 0, sizeof(TEXTVIEWWINDATA));
|
---|
| 2363 | WinSetWindowPtr(hwndTextView, QWL_PRIVATE, ptxvd);
|
---|
| 2364 |
|
---|
| 2365 | ptxvd->hab = WinQueryAnchorBlock(hwndTextView);
|
---|
| 2366 |
|
---|
| 2367 | ptxvd->hdc = WinOpenWindowDC(hwndTextView);
|
---|
| 2368 | ptxvd->hps = GpiCreatePS(ptxvd->hab,
|
---|
| 2369 | ptxvd->hdc,
|
---|
| 2370 | &szlPage, // use same page size as device
|
---|
| 2371 | PU_PELS | GPIT_MICRO | GPIA_ASSOC);
|
---|
| 2372 |
|
---|
| 2373 | // copy window style flags V0.9.20 (2002-08-10) [umoeller]
|
---|
| 2374 | ptxvd->flStyle = pcs->flStyle;
|
---|
| 2375 |
|
---|
| 2376 | gpihSwitchToRGB(ptxvd->hps);
|
---|
| 2377 |
|
---|
| 2378 | // set codepage; GPI defaults this to
|
---|
| 2379 | // the process codepage
|
---|
| 2380 | GpiSetCp(ptxvd->hps, ulCodepage);
|
---|
| 2381 |
|
---|
| 2382 | txvInitFormat(&ptxvd->xfd);
|
---|
| 2383 |
|
---|
| 2384 | // copy control data, if present
|
---|
| 2385 | if (pcd)
|
---|
| 2386 | memcpy(&ptxvd->cdata, pcd, pcd->cbData);
|
---|
| 2387 |
|
---|
| 2388 | // check values which might cause null divisions
|
---|
| 2389 | if (ptxvd->cdata.ulVScrollLineUnit == 0)
|
---|
| 2390 | ptxvd->cdata.ulVScrollLineUnit = 15;
|
---|
| 2391 | if (ptxvd->cdata.ulHScrollLineUnit == 0)
|
---|
| 2392 | ptxvd->cdata.ulHScrollLineUnit = 15;
|
---|
| 2393 |
|
---|
| 2394 | ptxvd->fAcceptsPresParamsNow = FALSE;
|
---|
| 2395 |
|
---|
| 2396 | // copy window dimensions from CREATESTRUCT
|
---|
| 2397 | ptxvd->rclViewReal.xLeft = 0;
|
---|
| 2398 | ptxvd->rclViewReal.yBottom = 0;
|
---|
| 2399 | ptxvd->rclViewReal.xRight = pcs->cx;
|
---|
| 2400 | ptxvd->rclViewReal.yTop = pcs->cy;
|
---|
| 2401 |
|
---|
| 2402 | sbcd.cb = sizeof(SBCDATA);
|
---|
| 2403 | sbcd.sHilite = 0;
|
---|
| 2404 | sbcd.posFirst = 0;
|
---|
| 2405 | sbcd.posLast = 100;
|
---|
| 2406 | sbcd.posThumb = 30;
|
---|
| 2407 | sbcd.cVisible = 50;
|
---|
| 2408 | sbcd.cTotal = 50;
|
---|
| 2409 |
|
---|
| 2410 | ptxvd->hwndVScroll = WinCreateWindow(hwndTextView,
|
---|
| 2411 | WC_SCROLLBAR,
|
---|
| 2412 | "",
|
---|
| 2413 | SBS_VERT | SBS_THUMBSIZE | WS_VISIBLE,
|
---|
| 2414 | 10, 10,
|
---|
| 2415 | 20, 100,
|
---|
| 2416 | hwndTextView, // owner
|
---|
| 2417 | HWND_TOP,
|
---|
| 2418 | ID_VSCROLL,
|
---|
| 2419 | &sbcd,
|
---|
| 2420 | 0);
|
---|
| 2421 | fShow = ((ptxvd->flStyle & XS_VSCROLL) != 0);
|
---|
| 2422 | WinShowWindow(ptxvd->hwndVScroll, fShow);
|
---|
| 2423 | ptxvd->fVScrollVisible = fShow;
|
---|
| 2424 |
|
---|
| 2425 | ptxvd->hwndHScroll = WinCreateWindow(hwndTextView,
|
---|
| 2426 | WC_SCROLLBAR,
|
---|
| 2427 | "",
|
---|
| 2428 | SBS_THUMBSIZE | WS_VISIBLE,
|
---|
| 2429 | 10, 10,
|
---|
| 2430 | 20, 100,
|
---|
| 2431 | hwndTextView, // owner
|
---|
| 2432 | HWND_TOP,
|
---|
| 2433 | ID_HSCROLL,
|
---|
| 2434 | &sbcd,
|
---|
| 2435 | 0);
|
---|
| 2436 | fShow = ((ptxvd->flStyle & XS_HSCROLL) != 0);
|
---|
| 2437 | WinShowWindow(ptxvd->hwndHScroll, fShow);
|
---|
| 2438 | ptxvd->fHScrollVisible = fShow;
|
---|
| 2439 |
|
---|
| 2440 | if (ptxvd->flStyle & XS_WORDWRAP)
|
---|
| 2441 | // word-wrapping should be enabled from the start:
|
---|
| 2442 | // V0.9.20 (2002-08-10) [umoeller]
|
---|
| 2443 | ptxvd->xfd.fmtpStandard.fWordWrap = TRUE;
|
---|
| 2444 |
|
---|
| 2445 | // set "code" format
|
---|
| 2446 | SetFormatFont(ptxvd->hps,
|
---|
| 2447 | &ptxvd->xfd.fmtcCode,
|
---|
| 2448 | 6,
|
---|
| 2449 | "System VIO");
|
---|
| 2450 |
|
---|
| 2451 | // get colors from presparams/syscolors
|
---|
| 2452 | UpdateTextViewPresData(hwndTextView, ptxvd);
|
---|
| 2453 |
|
---|
| 2454 | AdjustViewRects(hwndTextView,
|
---|
| 2455 | ptxvd);
|
---|
| 2456 |
|
---|
| 2457 | if (ptxvd->flStyle & XS_HTML)
|
---|
| 2458 | {
|
---|
| 2459 | // if we're operating in HTML mode, set a
|
---|
| 2460 | // different default paragraph format to
|
---|
| 2461 | // make things prettier
|
---|
| 2462 | // V0.9.20 (2002-08-10) [umoeller]
|
---|
| 2463 | ptxvd->xfd.fmtpStandard.lSpaceBefore = 5;
|
---|
| 2464 | ptxvd->xfd.fmtpStandard.lSpaceAfter = 5;
|
---|
| 2465 | }
|
---|
| 2466 |
|
---|
| 2467 | // setting the window text on window creation never
|
---|
| 2468 | // worked V0.9.20 (2002-08-10) [umoeller]
|
---|
| 2469 | if (pcs->pszText)
|
---|
| 2470 | SetWindowText(hwndTextView,
|
---|
| 2471 | ptxvd,
|
---|
| 2472 | pcs->pszText);
|
---|
| 2473 |
|
---|
| 2474 | mrc = (MRESULT)FALSE; // OK
|
---|
| 2475 | }
|
---|
| 2476 |
|
---|
| 2477 | return mrc;
|
---|
| 2478 | }
|
---|
| 2479 |
|
---|
| 2480 | /*
|
---|
| 2481 | *@@ ProcessPaint:
|
---|
| 2482 | * implementation for WM_PAINT in fnwpTextView.
|
---|
| 2483 | *
|
---|
[229] | 2484 | *@@added V1.0.0 (2002-08-12) [umoeller]
|
---|
[206] | 2485 | */
|
---|
| 2486 |
|
---|
[222] | 2487 | STATIC VOID ProcessPaint(HWND hwndTextView)
|
---|
[206] | 2488 | {
|
---|
| 2489 | PTEXTVIEWWINDATA ptxvd;
|
---|
| 2490 | if (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 2491 | {
|
---|
| 2492 | HRGN hrgnOldClip;
|
---|
| 2493 | RECTL rclClip;
|
---|
| 2494 | RECTL rcl2Update;
|
---|
| 2495 |
|
---|
| 2496 | // get update rectangle
|
---|
| 2497 | WinQueryUpdateRect(hwndTextView,
|
---|
| 2498 | &rcl2Update);
|
---|
| 2499 | // since we're not using WinBeginPaint,
|
---|
| 2500 | // we must validate the update region,
|
---|
| 2501 | // or we'll get bombed with WM_PAINT msgs
|
---|
| 2502 | WinValidateRect(hwndTextView,
|
---|
| 2503 | NULL,
|
---|
| 2504 | FALSE);
|
---|
| 2505 |
|
---|
| 2506 | // reset clip region to "all"
|
---|
| 2507 | GpiSetClipRegion(ptxvd->hps,
|
---|
| 2508 | NULLHANDLE,
|
---|
| 2509 | &hrgnOldClip); // out: old clip region
|
---|
| 2510 | // reduce clip region to update rectangle
|
---|
| 2511 | GpiIntersectClipRectangle(ptxvd->hps,
|
---|
| 2512 | &rcl2Update); // exclusive
|
---|
| 2513 |
|
---|
| 2514 | // draw little box at the bottom right
|
---|
| 2515 | // (in between scroll bars) if we have
|
---|
| 2516 | // both vertical and horizontal scroll bars
|
---|
| 2517 | if ( (ptxvd->flStyle & (XS_VSCROLL | XS_HSCROLL))
|
---|
| 2518 | == (XS_VSCROLL | XS_HSCROLL)
|
---|
| 2519 | && (ptxvd->fVScrollVisible)
|
---|
| 2520 | && (ptxvd->fHScrollVisible)
|
---|
| 2521 | )
|
---|
| 2522 | {
|
---|
| 2523 | RECTL rclBox;
|
---|
| 2524 | rclBox.xLeft = ptxvd->rclViewPaint.xRight;
|
---|
| 2525 | rclBox.yBottom = 0;
|
---|
| 2526 | rclBox.xRight = rclBox.xLeft + WinQuerySysValue(HWND_DESKTOP, SV_CXVSCROLL);
|
---|
| 2527 | rclBox.yTop = WinQuerySysValue(HWND_DESKTOP, SV_CYHSCROLL);
|
---|
| 2528 | WinFillRect(ptxvd->hps,
|
---|
| 2529 | &rclBox,
|
---|
| 2530 | WinQuerySysColor(HWND_DESKTOP,
|
---|
| 2531 | SYSCLR_DIALOGBACKGROUND,
|
---|
| 2532 | 0));
|
---|
| 2533 | }
|
---|
| 2534 |
|
---|
| 2535 | // paint "view paint" rectangle white;
|
---|
| 2536 | // this can be larger than "view text"
|
---|
| 2537 | WinFillRect(ptxvd->hps,
|
---|
| 2538 | &ptxvd->rclViewPaint, // exclusive
|
---|
| 2539 | ptxvd->lBackColor);
|
---|
| 2540 |
|
---|
| 2541 | // now reduce clipping rectangle to "view text" rectangle
|
---|
| 2542 | rclClip.xLeft = ptxvd->rclViewText.xLeft;
|
---|
| 2543 | rclClip.xRight = ptxvd->rclViewText.xRight - 1;
|
---|
| 2544 | rclClip.yBottom = ptxvd->rclViewText.yBottom;
|
---|
| 2545 | rclClip.yTop = ptxvd->rclViewText.yTop - 1;
|
---|
| 2546 | GpiIntersectClipRectangle(ptxvd->hps,
|
---|
| 2547 | &rclClip); // exclusive
|
---|
| 2548 | // finally, draw text lines in invalid rectangle;
|
---|
| 2549 | // this subfunction is smart enough to redraw only
|
---|
| 2550 | // the lines which intersect with rcl2Update
|
---|
| 2551 | GpiSetColor(ptxvd->hps, ptxvd->lForeColor);
|
---|
| 2552 | PaintViewText2Screen(ptxvd,
|
---|
| 2553 | &rcl2Update);
|
---|
| 2554 |
|
---|
| 2555 | if ( (!(ptxvd->flStyle & XS_STATIC))
|
---|
| 2556 | // V0.9.20 (2002-08-10) [umoeller]
|
---|
| 2557 | && (WinQueryFocus(HWND_DESKTOP) == hwndTextView)
|
---|
| 2558 | )
|
---|
| 2559 | {
|
---|
| 2560 | // we have the focus:
|
---|
| 2561 | // reset clip region to "all"
|
---|
| 2562 | GpiSetClipRegion(ptxvd->hps,
|
---|
| 2563 | NULLHANDLE,
|
---|
| 2564 | &hrgnOldClip); // out: old clip region
|
---|
| 2565 | PaintViewFocus(ptxvd->hps,
|
---|
| 2566 | ptxvd,
|
---|
| 2567 | TRUE);
|
---|
| 2568 | }
|
---|
| 2569 |
|
---|
| 2570 | ptxvd->fAcceptsPresParamsNow = TRUE;
|
---|
| 2571 | }
|
---|
| 2572 | }
|
---|
| 2573 |
|
---|
| 2574 | /*
|
---|
| 2575 | *@@ ProcessPresParamChanged:
|
---|
| 2576 | * implementation for WM_PRESPARAMCHANGED in fnwpTextView.
|
---|
| 2577 | *
|
---|
[229] | 2578 | *@@added V1.0.0 (2002-08-12) [umoeller]
|
---|
[206] | 2579 | */
|
---|
| 2580 |
|
---|
[222] | 2581 | STATIC VOID ProcessPresParamChanged(HWND hwndTextView, MPARAM mp1)
|
---|
[206] | 2582 | {
|
---|
| 2583 | PTEXTVIEWWINDATA ptxvd;
|
---|
| 2584 | if (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 2585 | {
|
---|
| 2586 | switch ((LONG)mp1)
|
---|
| 2587 | {
|
---|
| 2588 | case 0: // layout palette thing dropped
|
---|
| 2589 | case PP_BACKGROUNDCOLOR:
|
---|
| 2590 | case PP_FOREGROUNDCOLOR:
|
---|
| 2591 | case PP_FONTNAMESIZE:
|
---|
| 2592 | // re-query our presparams
|
---|
| 2593 | UpdateTextViewPresData(hwndTextView, ptxvd);
|
---|
| 2594 | }
|
---|
| 2595 |
|
---|
| 2596 | if (ptxvd->fAcceptsPresParamsNow)
|
---|
| 2597 | FormatText2Screen(hwndTextView,
|
---|
| 2598 | ptxvd,
|
---|
| 2599 | FALSE,
|
---|
| 2600 | TRUE); // full reformat
|
---|
| 2601 | }
|
---|
| 2602 | }
|
---|
| 2603 |
|
---|
| 2604 | /*
|
---|
| 2605 | *@@ ProcessSetFocus:
|
---|
| 2606 | * implementation for WM_SETFOCUS in fnwpTextView.
|
---|
| 2607 | *
|
---|
[229] | 2608 | *@@added V1.0.0 (2002-08-12) [umoeller]
|
---|
[206] | 2609 | */
|
---|
| 2610 |
|
---|
[222] | 2611 | STATIC VOID ProcessSetFocus(HWND hwndTextView, MPARAM mp2)
|
---|
[206] | 2612 | {
|
---|
| 2613 | PTEXTVIEWWINDATA ptxvd;
|
---|
| 2614 | if (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 2615 | {
|
---|
| 2616 | if (ptxvd->flStyle & XS_STATIC)
|
---|
| 2617 | {
|
---|
| 2618 | if (mp2)
|
---|
| 2619 | {
|
---|
| 2620 | // we're receiving the focus, but shouldn't have it:
|
---|
| 2621 | // then behave like the static control does, that is,
|
---|
| 2622 | // give focus to the next window in the dialog
|
---|
| 2623 | HWND hwnd = hwndTextView,
|
---|
| 2624 | hwndStart = hwnd;
|
---|
| 2625 |
|
---|
| 2626 | while (TRUE)
|
---|
| 2627 | {
|
---|
| 2628 | ULONG flStyle;
|
---|
| 2629 |
|
---|
| 2630 | if (!(hwnd = WinQueryWindow(hwnd, QW_NEXT)))
|
---|
| 2631 | hwnd = WinQueryWindow(WinQueryWindow(hwndStart, QW_PARENT), QW_TOP);
|
---|
| 2632 |
|
---|
| 2633 | // avoid endless looping
|
---|
| 2634 | if (hwnd == hwndStart)
|
---|
| 2635 | {
|
---|
| 2636 | if ( (hwnd = WinQueryWindow(hwnd, QW_OWNER))
|
---|
| 2637 | && (hwnd == hwndStart)
|
---|
| 2638 | )
|
---|
| 2639 | hwnd = NULLHANDLE;
|
---|
| 2640 |
|
---|
| 2641 | break;
|
---|
| 2642 | }
|
---|
| 2643 |
|
---|
| 2644 | if ( (flStyle = WinQueryWindowULong(hwnd, QWL_STYLE))
|
---|
| 2645 | && (flStyle & (WS_DISABLED | WS_TABSTOP | WS_VISIBLE)
|
---|
| 2646 | == (WS_TABSTOP | WS_VISIBLE))
|
---|
| 2647 | )
|
---|
| 2648 | {
|
---|
| 2649 | WinSetFocus(HWND_DESKTOP, hwnd);
|
---|
| 2650 | break;
|
---|
| 2651 | }
|
---|
| 2652 | };
|
---|
| 2653 | }
|
---|
| 2654 | }
|
---|
| 2655 | else
|
---|
| 2656 | {
|
---|
| 2657 | HPS hps = WinGetPS(hwndTextView);
|
---|
| 2658 | gpihSwitchToRGB(hps);
|
---|
| 2659 | PaintViewFocus(hps,
|
---|
| 2660 | ptxvd,
|
---|
| 2661 | (mp2 != 0));
|
---|
| 2662 | WinReleasePS(hps);
|
---|
| 2663 | }
|
---|
| 2664 | }
|
---|
| 2665 | }
|
---|
| 2666 |
|
---|
| 2667 | /*
|
---|
| 2668 | *@@ ProcessButton1Down:
|
---|
| 2669 | * implementation for WM_BUTTON1DOWN in fnwpTextView.
|
---|
| 2670 | *
|
---|
[229] | 2671 | *@@added V1.0.0 (2002-08-12) [umoeller]
|
---|
[206] | 2672 | */
|
---|
| 2673 |
|
---|
[222] | 2674 | STATIC MRESULT ProcessButton1Down(HWND hwndTextView, MPARAM mp1)
|
---|
[206] | 2675 | {
|
---|
| 2676 | MRESULT mrc = 0;
|
---|
| 2677 | PTEXTVIEWWINDATA ptxvd;
|
---|
| 2678 |
|
---|
| 2679 | if (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 2680 | {
|
---|
| 2681 | POINTL ptlPos;
|
---|
| 2682 | PLISTNODE pWordNodeClicked;
|
---|
| 2683 |
|
---|
| 2684 | ptlPos.x = SHORT1FROMMP(mp1) + ptxvd->ulViewXOfs;
|
---|
| 2685 | ptlPos.y = SHORT2FROMMP(mp1) - ptxvd->ulViewYOfs;
|
---|
| 2686 |
|
---|
| 2687 | if ( (!(ptxvd->flStyle & XS_STATIC))
|
---|
| 2688 | // V0.9.20 (2002-08-10) [umoeller]
|
---|
| 2689 | && (hwndTextView != WinQueryFocus(HWND_DESKTOP))
|
---|
| 2690 | )
|
---|
| 2691 | WinSetFocus(HWND_DESKTOP, hwndTextView);
|
---|
| 2692 |
|
---|
| 2693 | ptxvd->pcszLastLinkClicked = NULL;
|
---|
| 2694 |
|
---|
| 2695 | if (pWordNodeClicked = txvFindWordFromPoint(&ptxvd->xfd,
|
---|
| 2696 | &ptlPos))
|
---|
| 2697 | {
|
---|
| 2698 | PTXVWORD pWordClicked = (PTXVWORD)pWordNodeClicked->pItemData;
|
---|
| 2699 |
|
---|
| 2700 | // store link target (can be NULL)
|
---|
| 2701 | if (ptxvd->pcszLastLinkClicked = pWordClicked->pcszLinkTarget)
|
---|
| 2702 | {
|
---|
| 2703 | // word has a link target:
|
---|
| 2704 | PLISTNODE pNode = pWordNodeClicked;
|
---|
| 2705 |
|
---|
| 2706 | // reset first word of anchor
|
---|
| 2707 | ptxvd->pWordNodeFirstInAnchor = NULL;
|
---|
| 2708 |
|
---|
| 2709 | // go back to find the first word which has this anchor,
|
---|
| 2710 | // because we need to repaint them all
|
---|
| 2711 | while (pNode)
|
---|
| 2712 | {
|
---|
| 2713 | PTXVWORD pWordThis = (PTXVWORD)pNode->pItemData;
|
---|
| 2714 | if (pWordThis->pcszLinkTarget == pWordClicked->pcszLinkTarget)
|
---|
| 2715 | {
|
---|
| 2716 | // still has same anchor:
|
---|
| 2717 | // go for previous
|
---|
| 2718 | ptxvd->pWordNodeFirstInAnchor = pNode;
|
---|
| 2719 | pNode = pNode->pPrevious;
|
---|
| 2720 | }
|
---|
| 2721 | else
|
---|
| 2722 | // different anchor:
|
---|
| 2723 | // pNodeFirst points to first node with same anchor now
|
---|
| 2724 | break;
|
---|
| 2725 | }
|
---|
| 2726 |
|
---|
| 2727 | RepaintAnchor(ptxvd,
|
---|
| 2728 | RGBCOL_RED);
|
---|
| 2729 | }
|
---|
| 2730 | }
|
---|
| 2731 |
|
---|
| 2732 | WinSetCapture(HWND_DESKTOP, hwndTextView);
|
---|
| 2733 | mrc = (MRESULT)TRUE;
|
---|
| 2734 | }
|
---|
| 2735 |
|
---|
| 2736 | return mrc;
|
---|
| 2737 | }
|
---|
| 2738 |
|
---|
| 2739 | /*
|
---|
| 2740 | *@@ ProcessButton1Up:
|
---|
| 2741 | * implementation for WM_BUTTON1UP in fnwpTextView.
|
---|
| 2742 | *
|
---|
[229] | 2743 | *@@added V1.0.0 (2002-08-12) [umoeller]
|
---|
[206] | 2744 | */
|
---|
| 2745 |
|
---|
[222] | 2746 | STATIC MRESULT ProcessButton1Up(HWND hwndTextView, MPARAM mp1)
|
---|
[206] | 2747 | {
|
---|
| 2748 | MRESULT mrc = 0;
|
---|
| 2749 | PTEXTVIEWWINDATA ptxvd;
|
---|
| 2750 |
|
---|
| 2751 | if (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 2752 | {
|
---|
| 2753 | POINTL ptlPos;
|
---|
| 2754 | HWND hwndOwner = NULLHANDLE;
|
---|
| 2755 |
|
---|
| 2756 | ptlPos.x = SHORT1FROMMP(mp1) + ptxvd->ulViewXOfs;
|
---|
| 2757 | ptlPos.y = SHORT2FROMMP(mp1) - ptxvd->ulViewYOfs;
|
---|
| 2758 | WinSetCapture(HWND_DESKTOP, NULLHANDLE);
|
---|
| 2759 |
|
---|
| 2760 | if (ptxvd->pcszLastLinkClicked)
|
---|
| 2761 | {
|
---|
| 2762 | RepaintAnchor(ptxvd,
|
---|
| 2763 | ptxvd->lForeColor);
|
---|
| 2764 |
|
---|
| 2765 | // nofify owner
|
---|
| 2766 | if (hwndOwner = WinQueryWindow(hwndTextView, QW_OWNER))
|
---|
| 2767 | WinPostMsg(hwndOwner,
|
---|
| 2768 | WM_CONTROL,
|
---|
| 2769 | MPFROM2SHORT(WinQueryWindowUShort(hwndTextView,
|
---|
| 2770 | QWS_ID),
|
---|
| 2771 | TXVN_LINK),
|
---|
| 2772 | (MPARAM)(ULONG)(ptxvd->pcszLastLinkClicked));
|
---|
| 2773 | }
|
---|
| 2774 |
|
---|
| 2775 | mrc = (MRESULT)TRUE;
|
---|
| 2776 | }
|
---|
| 2777 |
|
---|
| 2778 | return mrc;
|
---|
| 2779 | }
|
---|
| 2780 |
|
---|
| 2781 | /*
|
---|
| 2782 | *@@ ProcessChar:
|
---|
| 2783 | * implementation for WM_CHAR in fnwpTextView.
|
---|
| 2784 | *
|
---|
[229] | 2785 | *@@added V1.0.0 (2002-08-12) [umoeller]
|
---|
[374] | 2786 | *@@changed WarpIN V1.0.18 (2008-11-16) [pr]: added correct ID for horiz. scroll @@fixes 1086
|
---|
[375] | 2787 | *@@changed WarpIN V1.0.18 (2008-11-16) [pr]: added Ctrl-Ins copy capability @@fixes 1116
|
---|
[206] | 2788 | */
|
---|
| 2789 |
|
---|
[222] | 2790 | STATIC MRESULT ProcessChar(HWND hwndTextView, MPARAM mp1, MPARAM mp2)
|
---|
[206] | 2791 | {
|
---|
| 2792 | MRESULT mrc = 0;
|
---|
| 2793 | PTEXTVIEWWINDATA ptxvd;
|
---|
| 2794 |
|
---|
| 2795 | if (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 2796 | {
|
---|
| 2797 | BOOL fDefProc = TRUE;
|
---|
| 2798 | USHORT usFlags = SHORT1FROMMP(mp1);
|
---|
| 2799 | // USHORT usch = SHORT1FROMMP(mp2);
|
---|
| 2800 | USHORT usvk = SHORT2FROMMP(mp2);
|
---|
| 2801 |
|
---|
| 2802 | if (usFlags & KC_VIRTUALKEY)
|
---|
| 2803 | {
|
---|
| 2804 | ULONG ulMsg = 0;
|
---|
| 2805 | USHORT usID = ID_VSCROLL;
|
---|
| 2806 | SHORT sPos = 0;
|
---|
| 2807 | SHORT usCmd = 0;
|
---|
| 2808 | fDefProc = FALSE;
|
---|
| 2809 |
|
---|
| 2810 | switch (usvk)
|
---|
| 2811 | {
|
---|
| 2812 | case VK_UP:
|
---|
| 2813 | ulMsg = WM_VSCROLL;
|
---|
| 2814 | usCmd = SB_LINEUP;
|
---|
| 2815 | break;
|
---|
| 2816 |
|
---|
| 2817 | case VK_DOWN:
|
---|
| 2818 | ulMsg = WM_VSCROLL;
|
---|
| 2819 | usCmd = SB_LINEDOWN;
|
---|
| 2820 | break;
|
---|
| 2821 |
|
---|
| 2822 | case VK_RIGHT:
|
---|
| 2823 | ulMsg = WM_HSCROLL;
|
---|
| 2824 | usCmd = SB_LINERIGHT;
|
---|
[374] | 2825 | usID = ID_HSCROLL; // WarpIN V1.0.18
|
---|
[206] | 2826 | break;
|
---|
| 2827 |
|
---|
| 2828 | case VK_LEFT:
|
---|
| 2829 | ulMsg = WM_HSCROLL;
|
---|
| 2830 | usCmd = SB_LINELEFT;
|
---|
[374] | 2831 | usID = ID_HSCROLL; // WarpIN V1.0.18
|
---|
[206] | 2832 | break;
|
---|
| 2833 |
|
---|
| 2834 | case VK_PAGEUP:
|
---|
| 2835 | ulMsg = WM_VSCROLL;
|
---|
| 2836 | if (usFlags & KC_CTRL)
|
---|
| 2837 | {
|
---|
| 2838 | sPos = 0;
|
---|
| 2839 | usCmd = SB_SLIDERPOSITION;
|
---|
| 2840 | }
|
---|
| 2841 | else
|
---|
| 2842 | usCmd = SB_PAGEUP;
|
---|
| 2843 | break;
|
---|
| 2844 |
|
---|
| 2845 | case VK_PAGEDOWN:
|
---|
| 2846 | ulMsg = WM_VSCROLL;
|
---|
| 2847 | if (usFlags & KC_CTRL)
|
---|
| 2848 | {
|
---|
| 2849 | sPos = ptxvd->xfd.szlWorkspace.cy;
|
---|
| 2850 | usCmd = SB_SLIDERPOSITION;
|
---|
| 2851 | }
|
---|
| 2852 | else
|
---|
| 2853 | usCmd = SB_PAGEDOWN;
|
---|
| 2854 | break;
|
---|
| 2855 |
|
---|
| 2856 | case VK_HOME:
|
---|
| 2857 | if (usFlags & KC_CTRL)
|
---|
| 2858 | // vertical:
|
---|
| 2859 | ulMsg = WM_VSCROLL;
|
---|
| 2860 | else
|
---|
[374] | 2861 | {
|
---|
[206] | 2862 | ulMsg = WM_HSCROLL;
|
---|
[374] | 2863 | usID = ID_HSCROLL; // WarpIN V1.0.18
|
---|
| 2864 | }
|
---|
[206] | 2865 |
|
---|
| 2866 | sPos = 0;
|
---|
| 2867 | usCmd = SB_SLIDERPOSITION;
|
---|
| 2868 | break;
|
---|
| 2869 |
|
---|
| 2870 | case VK_END:
|
---|
| 2871 | if (usFlags & KC_CTRL)
|
---|
| 2872 | {
|
---|
| 2873 | // vertical:
|
---|
| 2874 | ulMsg = WM_VSCROLL;
|
---|
| 2875 | sPos = ptxvd->xfd.szlWorkspace.cy;
|
---|
| 2876 | }
|
---|
| 2877 | else
|
---|
| 2878 | {
|
---|
| 2879 | ulMsg = WM_HSCROLL;
|
---|
| 2880 | sPos = ptxvd->xfd.szlWorkspace.cx;
|
---|
[374] | 2881 | usID = ID_HSCROLL; // WarpIN V1.0.18
|
---|
[206] | 2882 | }
|
---|
| 2883 |
|
---|
| 2884 | usCmd = SB_SLIDERPOSITION;
|
---|
| 2885 | break;
|
---|
| 2886 |
|
---|
[375] | 2887 | // WarpIN V1.0.18
|
---|
| 2888 | case VK_INSERT:
|
---|
| 2889 | if (usFlags & KC_CTRL)
|
---|
| 2890 | {
|
---|
| 2891 | ulMsg = TXM_COPY;
|
---|
| 2892 | usID = 0;
|
---|
| 2893 | }
|
---|
| 2894 | break;
|
---|
| 2895 |
|
---|
[206] | 2896 | default:
|
---|
| 2897 | // other:
|
---|
| 2898 | fDefProc = TRUE;
|
---|
| 2899 | }
|
---|
| 2900 |
|
---|
| 2901 | if ( ((usFlags & KC_KEYUP) == 0)
|
---|
| 2902 | && (ulMsg)
|
---|
| 2903 | )
|
---|
| 2904 | WinSendMsg(hwndTextView,
|
---|
| 2905 | ulMsg,
|
---|
| 2906 | MPFROMSHORT(usID),
|
---|
| 2907 | MPFROM2SHORT(sPos,
|
---|
| 2908 | usCmd));
|
---|
| 2909 | }
|
---|
| 2910 |
|
---|
| 2911 | if (fDefProc)
|
---|
| 2912 | mrc = WinDefWindowProc(hwndTextView, WM_CHAR, mp1, mp2);
|
---|
| 2913 | // sends to owner
|
---|
| 2914 | else
|
---|
| 2915 | mrc = (MPARAM)TRUE;
|
---|
| 2916 | }
|
---|
| 2917 |
|
---|
| 2918 | return mrc;
|
---|
| 2919 | }
|
---|
| 2920 |
|
---|
| 2921 | /*
|
---|
| 2922 | *@@ ProcessJumpToAnchorName:
|
---|
| 2923 | * implementation for TXM_JUMPTOANCHORNAME in fnwpTextView.
|
---|
| 2924 | *
|
---|
[229] | 2925 | *@@added V1.0.0 (2002-08-12) [umoeller]
|
---|
[206] | 2926 | */
|
---|
| 2927 |
|
---|
[222] | 2928 | STATIC MRESULT ProcessJumpToAnchorName(HWND hwndTextView, MPARAM mp1)
|
---|
[206] | 2929 | {
|
---|
| 2930 | MRESULT mrc = 0;
|
---|
| 2931 | PTEXTVIEWWINDATA ptxvd;
|
---|
| 2932 |
|
---|
| 2933 | if ( (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 2934 | && (mp1)
|
---|
| 2935 | )
|
---|
| 2936 | {
|
---|
| 2937 | PLISTNODE pWordNode;
|
---|
| 2938 | PTXVWORD pWord;
|
---|
| 2939 | if ( (pWordNode = txvFindWordFromAnchor(&ptxvd->xfd,
|
---|
| 2940 | (const char*)mp1))
|
---|
| 2941 | && (pWord = (PTXVWORD)pWordNode->pItemData)
|
---|
| 2942 | )
|
---|
| 2943 | {
|
---|
| 2944 | // found:
|
---|
| 2945 | PTXVRECTANGLE pRect = pWord->pRectangle;
|
---|
| 2946 | ULONG ulWinCY = (ptxvd->rclViewText.yTop - ptxvd->rclViewText.yBottom);
|
---|
| 2947 |
|
---|
| 2948 | // now we need to scroll the window so that this rectangle is on top.
|
---|
| 2949 | // Since rectangles start out with the height of the window (e.g. +768)
|
---|
| 2950 | // and then have lower y coordinates down to way in the negatives,
|
---|
| 2951 | // to get the y offset, we must...
|
---|
| 2952 | ptxvd->ulViewYOfs = (-pRect->rcl.yTop) - ulWinCY;
|
---|
| 2953 |
|
---|
| 2954 | if (ptxvd->ulViewYOfs < 0)
|
---|
| 2955 | ptxvd->ulViewYOfs = 0;
|
---|
| 2956 | if (ptxvd->ulViewYOfs > ((LONG)ptxvd->xfd.szlWorkspace.cy - ulWinCY))
|
---|
| 2957 | ptxvd->ulViewYOfs = (LONG)ptxvd->xfd.szlWorkspace.cy - ulWinCY;
|
---|
| 2958 |
|
---|
| 2959 | // vertical scroll bar enabled at all?
|
---|
| 2960 | if (ptxvd->flStyle & XS_VSCROLL)
|
---|
| 2961 | {
|
---|
| 2962 | /* BOOL fEnabled = */ winhUpdateScrollBar(ptxvd->hwndVScroll,
|
---|
| 2963 | ulWinCY,
|
---|
| 2964 | ptxvd->xfd.szlWorkspace.cy,
|
---|
| 2965 | ptxvd->ulViewYOfs,
|
---|
| 2966 | (ptxvd->flStyle & XS_AUTOVHIDE));
|
---|
| 2967 | WinInvalidateRect(hwndTextView, NULL, FALSE);
|
---|
| 2968 | }
|
---|
| 2969 |
|
---|
| 2970 | mrc = (MRESULT)TRUE;
|
---|
| 2971 | }
|
---|
| 2972 | }
|
---|
| 2973 |
|
---|
| 2974 | return mrc;
|
---|
| 2975 | }
|
---|
| 2976 |
|
---|
| 2977 | /*
|
---|
| 2978 | *@@ ProcessDestroy:
|
---|
| 2979 | * implementation for WM_DESTROY in fnwpTextView.
|
---|
| 2980 | *
|
---|
[229] | 2981 | *@@added V1.0.0 (2002-08-12) [umoeller]
|
---|
[206] | 2982 | */
|
---|
| 2983 |
|
---|
[222] | 2984 | STATIC MRESULT ProcessDestroy(HWND hwndTextView, MPARAM mp1, MPARAM mp2)
|
---|
[206] | 2985 | {
|
---|
| 2986 | PTEXTVIEWWINDATA ptxvd;
|
---|
| 2987 |
|
---|
| 2988 | if (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 2989 | {
|
---|
| 2990 | xstrClear(&ptxvd->xfd.strViewText);
|
---|
[375] | 2991 | xstrClear(&ptxvd->xfd.strOrigText); // WarpIN V1.0.18
|
---|
[206] | 2992 | lstClear(&ptxvd->xfd.llRectangles);
|
---|
| 2993 | lstClear(&ptxvd->xfd.llWords);
|
---|
| 2994 | GpiDestroyPS(ptxvd->hps);
|
---|
| 2995 | free(ptxvd);
|
---|
| 2996 | WinSetWindowPtr(hwndTextView, QWL_PRIVATE, NULL);
|
---|
| 2997 | }
|
---|
| 2998 |
|
---|
| 2999 | return WinDefWindowProc(hwndTextView, WM_DESTROY, mp1, mp2);
|
---|
| 3000 | }
|
---|
| 3001 |
|
---|
| 3002 | /*
|
---|
[8] | 3003 | *@@ fnwpTextView:
|
---|
| 3004 | * window procedure for the text view control. This is
|
---|
| 3005 | * registered with the WC_XTEXTVIEW class in txvRegisterTextView.
|
---|
| 3006 | *
|
---|
| 3007 | * The text view control is not a subclassed whatever control,
|
---|
| 3008 | * but a control implemented from scratch. As a result, we
|
---|
| 3009 | * had to implement all messages which are usually recognized
|
---|
| 3010 | * by a control. In detail, we have:
|
---|
| 3011 | *
|
---|
| 3012 | * -- WM_WINDOWPOSCHANGED: if the control is resized, the
|
---|
| 3013 | * text is reformatted and the scroll bars are readjusted.
|
---|
| 3014 | * See AdjustViewRects and txvFormatText.
|
---|
| 3015 | *
|
---|
| 3016 | * -- WM_PRESPARAMCHANGED: if fonts or colors are dropped
|
---|
| 3017 | * on the control, we reformat the text also.
|
---|
| 3018 | *
|
---|
| 3019 | * -- WM_HSCROLL and WM_VSCROLL: this calls winhHandleScrollMsg
|
---|
| 3020 | * to scroll the window contents.
|
---|
| 3021 | *
|
---|
| 3022 | * -- WM_BUTTON1DOWN: this sets the focus to the control.
|
---|
| 3023 | *
|
---|
| 3024 | * -- WM_SETFOCUS: if we receive the focus, we draw a fine
|
---|
| 3025 | * dotted line in the "selection" color around the text
|
---|
| 3026 | * window.
|
---|
| 3027 | *
|
---|
| 3028 | * -- WM_CHAR: if we have the focus, the user can move the
|
---|
[201] | 3029 | * visible part within the workspace using the usual
|
---|
[8] | 3030 | * cursor and HOME/END keys.
|
---|
| 3031 | *
|
---|
| 3032 | * -- WM_MOUSEMOVE: this sends WM_CONTROLPOINTER to the
|
---|
| 3033 | * owner so the owner can change the mouse pointer.
|
---|
| 3034 | *
|
---|
| 3035 | * <B>Painting</B>
|
---|
| 3036 | *
|
---|
| 3037 | * The text view control creates a micro presentation space
|
---|
| 3038 | * from the window's device context upon WM_CREATE, which is
|
---|
| 3039 | * stored in TEXTVIEWWINDATA. We do not use WinBeginPaint in
|
---|
| 3040 | * WM_PAINT, but only the PS we created ourselves. This saves
|
---|
| 3041 | * us from resetting and researching all the fonts etc., which
|
---|
| 3042 | * should be speedier.
|
---|
| 3043 | *
|
---|
[201] | 3044 | * The text view control uses a private window word for storing
|
---|
| 3045 | * its own data. The client is free to use QWL_USER of the
|
---|
| 3046 | * text view control.
|
---|
| 3047 | *
|
---|
[8] | 3048 | *@@changed V0.9.3 (2000-05-05) [umoeller]: removed TXM_NEWTEXT; now supporting WinSetWindowText
|
---|
| 3049 | *@@changed V0.9.3 (2000-05-07) [umoeller]: crashed if create param was NULL; fixed
|
---|
[201] | 3050 | *@@changed V0.9.20 (2002-08-10) [umoeller]: no longer using QWL_USER, which is free now
|
---|
| 3051 | *@@changed V0.9.20 (2002-08-10) [umoeller]: setting text on window creation never worked, fixed
|
---|
| 3052 | *@@changed V0.9.20 (2002-08-10) [umoeller]: added TXN_ANCHORCLICKED owner notify for anchors
|
---|
| 3053 | *@@changed V0.9.20 (2002-08-10) [umoeller]: converted private style flags to XS_* window style flags
|
---|
[206] | 3054 | *@@changed V0.9.20 (2002-08-10) [umoeller]: added support for XS_STATIC
|
---|
[201] | 3055 | *@@changed V0.9.20 (2002-08-10) [umoeller]: added support for formatting HTML and plain text automatically
|
---|
[229] | 3056 | *@@changed V1.0.0 (2002-08-12) [umoeller]: optimized locality by moving big chunks into subfuncs
|
---|
[375] | 3057 | *@@changed WarpIN V1.0.18 (2008-11-16) [pr]: added Ctrl-Ins copy capability @@fixes 1116
|
---|
| 3058 | *@@changed WarpIN V1.0.18 (2008-11-29) [pr]: added style set/query functions @@fixes 1116
|
---|
[8] | 3059 | */
|
---|
| 3060 |
|
---|
[222] | 3061 | STATIC MRESULT EXPENTRY fnwpTextView(HWND hwndTextView, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
[8] | 3062 | {
|
---|
[206] | 3063 | MRESULT mrc = 0;
|
---|
| 3064 | PTEXTVIEWWINDATA ptxvd;
|
---|
[8] | 3065 |
|
---|
| 3066 | switch (msg)
|
---|
| 3067 | {
|
---|
| 3068 | /*
|
---|
| 3069 | * WM_CREATE:
|
---|
| 3070 | *
|
---|
| 3071 | */
|
---|
| 3072 |
|
---|
| 3073 | case WM_CREATE:
|
---|
[206] | 3074 | mrc = ProcessCreate(hwndTextView, mp1, mp2);
|
---|
[229] | 3075 | // extracted V1.0.0 (2002-08-12) [umoeller]
|
---|
[137] | 3076 | break;
|
---|
[8] | 3077 |
|
---|
| 3078 | /*
|
---|
| 3079 | * WM_SETWINDOWPARAMS:
|
---|
| 3080 | * this message sets the window parameters,
|
---|
| 3081 | * most importantly, the window text.
|
---|
| 3082 | *
|
---|
| 3083 | * This updates the control.
|
---|
| 3084 | */
|
---|
| 3085 |
|
---|
| 3086 | case WM_SETWINDOWPARAMS:
|
---|
[206] | 3087 | if ( (mp1)
|
---|
| 3088 | && (((PWNDPARAMS)mp1)->fsStatus & WPM_TEXT)
|
---|
| 3089 | && (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
[201] | 3090 | )
|
---|
[8] | 3091 | {
|
---|
[201] | 3092 | SetWindowText(hwndTextView,
|
---|
| 3093 | ptxvd,
|
---|
[206] | 3094 | ((PWNDPARAMS)mp1)->pszText);
|
---|
[201] | 3095 | mrc = (MRESULT)TRUE; // was missing V0.9.20 (2002-08-10) [umoeller]
|
---|
[8] | 3096 | }
|
---|
[137] | 3097 | break;
|
---|
[8] | 3098 |
|
---|
| 3099 | /*
|
---|
| 3100 | * WM_WINDOWPOSCHANGED:
|
---|
| 3101 | *
|
---|
| 3102 | */
|
---|
| 3103 |
|
---|
| 3104 | case WM_WINDOWPOSCHANGED:
|
---|
| 3105 | // resizing?
|
---|
[206] | 3106 | if ( (mp1)
|
---|
| 3107 | && (((PSWP)mp1)->fl & SWP_SIZE)
|
---|
| 3108 | && (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 3109 | )
|
---|
[8] | 3110 | {
|
---|
[206] | 3111 | WinQueryWindowRect(hwndTextView,
|
---|
| 3112 | &ptxvd->rclViewReal);
|
---|
| 3113 | AdjustViewRects(hwndTextView,
|
---|
| 3114 | ptxvd);
|
---|
| 3115 | FormatText2Screen(hwndTextView,
|
---|
| 3116 | ptxvd,
|
---|
| 3117 | FALSE,
|
---|
| 3118 | FALSE); // quick format
|
---|
[8] | 3119 | }
|
---|
[137] | 3120 | break;
|
---|
[8] | 3121 |
|
---|
| 3122 | /*
|
---|
| 3123 | * WM_PAINT:
|
---|
| 3124 | *
|
---|
| 3125 | */
|
---|
| 3126 |
|
---|
| 3127 | case WM_PAINT:
|
---|
[206] | 3128 | ProcessPaint(hwndTextView);
|
---|
[229] | 3129 | // extracted V1.0.0 (2002-08-12) [umoeller]
|
---|
[137] | 3130 | break;
|
---|
[8] | 3131 |
|
---|
| 3132 | /*
|
---|
| 3133 | * WM_PRESPARAMCHANGED:
|
---|
| 3134 | *
|
---|
| 3135 | * Changing the color or font settings
|
---|
| 3136 | * is equivalent to changing the default
|
---|
| 3137 | * paragraph format. See TXM_SETFORMAT.
|
---|
| 3138 | */
|
---|
| 3139 |
|
---|
| 3140 | case WM_PRESPARAMCHANGED:
|
---|
[206] | 3141 | ProcessPresParamChanged(hwndTextView, mp1);
|
---|
[8] | 3142 | break;
|
---|
| 3143 |
|
---|
| 3144 | /*
|
---|
| 3145 | * WM_VSCROLL:
|
---|
| 3146 | *
|
---|
| 3147 | */
|
---|
| 3148 |
|
---|
| 3149 | case WM_VSCROLL:
|
---|
[206] | 3150 | if ( (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 3151 | && (ptxvd->fVScrollVisible)
|
---|
| 3152 | )
|
---|
[8] | 3153 | {
|
---|
| 3154 | winhHandleScrollMsg(hwndTextView,
|
---|
| 3155 | ptxvd->hwndVScroll,
|
---|
[25] | 3156 | &ptxvd->ulViewYOfs,
|
---|
[8] | 3157 | &ptxvd->rclViewText,
|
---|
[201] | 3158 | ptxvd->xfd.szlWorkspace.cy,
|
---|
[8] | 3159 | ptxvd->cdata.ulVScrollLineUnit,
|
---|
| 3160 | msg,
|
---|
| 3161 | mp2);
|
---|
| 3162 | }
|
---|
[137] | 3163 | break;
|
---|
[8] | 3164 |
|
---|
| 3165 | /*
|
---|
| 3166 | * WM_HSCROLL:
|
---|
| 3167 | *
|
---|
| 3168 | */
|
---|
| 3169 |
|
---|
| 3170 | case WM_HSCROLL:
|
---|
[206] | 3171 | if ( (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 3172 | && (ptxvd->fHScrollVisible)
|
---|
| 3173 | )
|
---|
[8] | 3174 | {
|
---|
| 3175 | winhHandleScrollMsg(hwndTextView,
|
---|
| 3176 | ptxvd->hwndHScroll,
|
---|
[25] | 3177 | &ptxvd->ulViewXOfs,
|
---|
[8] | 3178 | &ptxvd->rclViewText,
|
---|
[201] | 3179 | ptxvd->xfd.szlWorkspace.cx,
|
---|
[8] | 3180 | ptxvd->cdata.ulHScrollLineUnit,
|
---|
| 3181 | msg,
|
---|
| 3182 | mp2);
|
---|
| 3183 | }
|
---|
[137] | 3184 | break;
|
---|
[8] | 3185 |
|
---|
| 3186 | /*
|
---|
| 3187 | * WM_SETFOCUS:
|
---|
| 3188 | *
|
---|
| 3189 | */
|
---|
| 3190 |
|
---|
| 3191 | case WM_SETFOCUS:
|
---|
[206] | 3192 | ProcessSetFocus(hwndTextView, mp2);
|
---|
[137] | 3193 | break;
|
---|
[8] | 3194 |
|
---|
| 3195 | /*
|
---|
| 3196 | * WM_MOUSEMOVE:
|
---|
| 3197 | * send WM_CONTROLPOINTER to owner.
|
---|
| 3198 | */
|
---|
| 3199 |
|
---|
| 3200 | case WM_MOUSEMOVE:
|
---|
| 3201 | {
|
---|
[137] | 3202 | HWND hwndOwner;
|
---|
| 3203 | if (hwndOwner = WinQueryWindow(hwndTextView, QW_OWNER))
|
---|
[8] | 3204 | {
|
---|
| 3205 | HPOINTER hptrSet
|
---|
| 3206 | = (HPOINTER)WinSendMsg(hwndOwner,
|
---|
| 3207 | WM_CONTROLPOINTER,
|
---|
| 3208 | (MPARAM)(LONG)WinQueryWindowUShort(hwndTextView,
|
---|
| 3209 | QWS_ID),
|
---|
| 3210 | (MPARAM)WinQuerySysPointer(HWND_DESKTOP,
|
---|
| 3211 | SPTR_ARROW,
|
---|
| 3212 | FALSE));
|
---|
| 3213 | WinSetPointer(HWND_DESKTOP, hptrSet);
|
---|
| 3214 | }
|
---|
[137] | 3215 | }
|
---|
| 3216 | break;
|
---|
[8] | 3217 |
|
---|
| 3218 | /*
|
---|
| 3219 | * WM_BUTTON1DOWN:
|
---|
| 3220 | *
|
---|
| 3221 | */
|
---|
| 3222 |
|
---|
| 3223 | case WM_BUTTON1DOWN:
|
---|
[206] | 3224 | mrc = ProcessButton1Down(hwndTextView, mp1);
|
---|
[137] | 3225 | break;
|
---|
[8] | 3226 |
|
---|
| 3227 | /*
|
---|
| 3228 | * WM_BUTTON1UP:
|
---|
| 3229 | *
|
---|
| 3230 | */
|
---|
| 3231 |
|
---|
| 3232 | case WM_BUTTON1UP:
|
---|
[206] | 3233 | mrc = ProcessButton1Up(hwndTextView, mp1);
|
---|
[137] | 3234 | break;
|
---|
[8] | 3235 |
|
---|
| 3236 | /*
|
---|
| 3237 | * WM_CHAR:
|
---|
| 3238 | *
|
---|
| 3239 | */
|
---|
| 3240 |
|
---|
| 3241 | case WM_CHAR:
|
---|
[206] | 3242 | mrc = ProcessChar(hwndTextView, mp1, mp2);
|
---|
[137] | 3243 | break;
|
---|
[8] | 3244 |
|
---|
| 3245 | /*
|
---|
| 3246 | *@@ TXM_QUERYPARFORMAT:
|
---|
| 3247 | * this msg can be sent to the text view control
|
---|
| 3248 | * to retrieve the paragraph format with the
|
---|
| 3249 | * index specified in mp1.
|
---|
| 3250 | *
|
---|
[201] | 3251 | * This must be sent, not posted, to the control.
|
---|
| 3252 | *
|
---|
[8] | 3253 | * Parameters:
|
---|
[201] | 3254 | *
|
---|
[8] | 3255 | * -- ULONG mp1: index of format to query.
|
---|
| 3256 | * Must be 0 currently for the standard
|
---|
| 3257 | * paragraph format.
|
---|
[201] | 3258 | *
|
---|
[8] | 3259 | * -- PXFMTPARAGRAPH mp2: pointer to buffer
|
---|
| 3260 | * which is to receive the formatting
|
---|
| 3261 | * data.
|
---|
| 3262 | *
|
---|
| 3263 | * Returns TRUE if copying was successful.
|
---|
| 3264 | *
|
---|
| 3265 | *@@added V0.9.3 (2000-05-06) [umoeller]
|
---|
| 3266 | */
|
---|
| 3267 |
|
---|
| 3268 | case TXM_QUERYPARFORMAT:
|
---|
[206] | 3269 | if ( (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 3270 | && (!mp1)
|
---|
| 3271 | && (mp2)
|
---|
| 3272 | )
|
---|
[8] | 3273 | {
|
---|
[206] | 3274 | memcpy(mp2,
|
---|
| 3275 | &ptxvd->xfd.fmtpStandard,
|
---|
| 3276 | sizeof(XFMTPARAGRAPH));
|
---|
[8] | 3277 | mrc = (MPARAM)TRUE;
|
---|
| 3278 | }
|
---|
[137] | 3279 | break;
|
---|
[8] | 3280 |
|
---|
| 3281 | /*
|
---|
| 3282 | *@@ TXM_SETPARFORMAT:
|
---|
| 3283 | * reverse to TXM_QUERYPARFORMAT, this sets a
|
---|
| 3284 | * paragraph format (line spacings, margins
|
---|
| 3285 | * and such).
|
---|
| 3286 | *
|
---|
[201] | 3287 | * This must be sent, not posted, to the control.
|
---|
| 3288 | *
|
---|
[8] | 3289 | * Parameters:
|
---|
[201] | 3290 | *
|
---|
[8] | 3291 | * -- ULONG mp1: index of format to set.
|
---|
| 3292 | * Must be 0 currently for the standard
|
---|
| 3293 | * paragraph format.
|
---|
[201] | 3294 | *
|
---|
[8] | 3295 | * -- PXFMTPARAGRAPH mp2: pointer to buffer
|
---|
| 3296 | * from which to copy formatting data.
|
---|
| 3297 | * If this pointer is NULL, the format
|
---|
| 3298 | * is reset to the default.
|
---|
| 3299 | *
|
---|
| 3300 | * This reformats the control.
|
---|
| 3301 | *
|
---|
| 3302 | *@@added V0.9.3 (2000-05-06) [umoeller]
|
---|
| 3303 | */
|
---|
| 3304 |
|
---|
| 3305 | case TXM_SETPARFORMAT:
|
---|
[206] | 3306 | if ( (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 3307 | && (!mp1)
|
---|
| 3308 | )
|
---|
[8] | 3309 | {
|
---|
| 3310 | if (mp2)
|
---|
[206] | 3311 | // copy:
|
---|
| 3312 | memcpy(&ptxvd->xfd.fmtpStandard,
|
---|
| 3313 | mp2,
|
---|
| 3314 | sizeof(XFMTPARAGRAPH));
|
---|
[8] | 3315 | else
|
---|
| 3316 | // default:
|
---|
[206] | 3317 | memset(&ptxvd->xfd.fmtpStandard,
|
---|
| 3318 | 0,
|
---|
| 3319 | sizeof(XFMTPARAGRAPH));
|
---|
[8] | 3320 |
|
---|
| 3321 | FormatText2Screen(hwndTextView,
|
---|
| 3322 | ptxvd,
|
---|
| 3323 | FALSE,
|
---|
| 3324 | TRUE); // full reformat
|
---|
| 3325 |
|
---|
| 3326 | mrc = (MPARAM)TRUE;
|
---|
| 3327 | }
|
---|
[137] | 3328 | break;
|
---|
[8] | 3329 |
|
---|
| 3330 | /*
|
---|
| 3331 | *@@ TXM_SETWORDWRAP:
|
---|
| 3332 | * this text view control msg quickly changes
|
---|
| 3333 | * the word-wrapping style of the default
|
---|
| 3334 | * paragraph formatting.
|
---|
[201] | 3335 | *
|
---|
| 3336 | * This may be sent or posted.
|
---|
| 3337 | *
|
---|
[8] | 3338 | * (BOOL)mp1 determines whether word wrapping
|
---|
| 3339 | * should be turned on or off.
|
---|
| 3340 | */
|
---|
| 3341 |
|
---|
| 3342 | case TXM_SETWORDWRAP:
|
---|
[206] | 3343 | if (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 3344 | {
|
---|
| 3345 | BOOL ulOldFlFormat = ptxvd->xfd.fmtpStandard.fWordWrap;
|
---|
| 3346 | ptxvd->xfd.fmtpStandard.fWordWrap = (BOOL)mp1;
|
---|
| 3347 | if (ptxvd->xfd.fmtpStandard.fWordWrap != ulOldFlFormat)
|
---|
| 3348 | FormatText2Screen(hwndTextView,
|
---|
| 3349 | ptxvd,
|
---|
| 3350 | FALSE,
|
---|
| 3351 | FALSE); // quick format
|
---|
| 3352 | }
|
---|
[137] | 3353 | break;
|
---|
[8] | 3354 |
|
---|
| 3355 | /*
|
---|
| 3356 | *@@ TXM_QUERYCDATA:
|
---|
| 3357 | * copies the current XTEXTVIEWCDATA
|
---|
[201] | 3358 | * into the specified buffer.
|
---|
[8] | 3359 | *
|
---|
[201] | 3360 | * This must be sent, not posted, to the control.
|
---|
| 3361 | *
|
---|
[8] | 3362 | * Parameters:
|
---|
[201] | 3363 | *
|
---|
| 3364 | * -- PXTEXTVIEWCDATA mp1: target buffer.
|
---|
| 3365 | * Before calling this, you MUST specify
|
---|
| 3366 | * XTEXTVIEWCDATA.cbData.
|
---|
| 3367 | *
|
---|
[206] | 3368 | * Returns the bytes that were copied as
|
---|
[201] | 3369 | * a ULONG.
|
---|
[8] | 3370 | */
|
---|
| 3371 |
|
---|
| 3372 | case TXM_QUERYCDATA:
|
---|
[206] | 3373 | if ( (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 3374 | && (mp1)
|
---|
| 3375 | )
|
---|
[8] | 3376 | {
|
---|
| 3377 | PXTEXTVIEWCDATA pTarget = (PXTEXTVIEWCDATA)mp1;
|
---|
[201] | 3378 | mrc = (MRESULT)min(pTarget->cbData, sizeof(XTEXTVIEWCDATA));
|
---|
| 3379 | memcpy(pTarget,
|
---|
| 3380 | &ptxvd->cdata,
|
---|
| 3381 | (ULONG)mrc);
|
---|
[8] | 3382 | }
|
---|
| 3383 | break;
|
---|
| 3384 |
|
---|
| 3385 | /*
|
---|
| 3386 | *@@ TXM_SETCDATA:
|
---|
| 3387 | * updates the current XTEXTVIEWCDATA
|
---|
| 3388 | * with the data from the specified buffer.
|
---|
| 3389 | *
|
---|
[201] | 3390 | * This must be sent, not posted, to the control.
|
---|
| 3391 | *
|
---|
[8] | 3392 | * Parameters:
|
---|
[206] | 3393 | *
|
---|
[8] | 3394 | * -- PXTEXTVIEWCDATA mp1: source buffer.
|
---|
| 3395 | * Before calling this, you MUST specify
|
---|
| 3396 | * XTEXTVIEWCDATA.cbData.
|
---|
[206] | 3397 | *
|
---|
| 3398 | * Returns the bytes that were copied as
|
---|
| 3399 | * a ULONG.
|
---|
| 3400 | *
|
---|
[229] | 3401 | *@@changed V1.0.0 (2002-08-12) [umoeller]: now returning bytes
|
---|
[8] | 3402 | */
|
---|
| 3403 |
|
---|
| 3404 | case TXM_SETCDATA:
|
---|
[206] | 3405 | if ( (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 3406 | && (mp1)
|
---|
| 3407 | )
|
---|
[8] | 3408 | {
|
---|
| 3409 | PXTEXTVIEWCDATA pSource = (PXTEXTVIEWCDATA)mp1;
|
---|
[206] | 3410 | mrc = (MRESULT)min(pSource->cbData, sizeof(XTEXTVIEWCDATA));
|
---|
| 3411 | memcpy(&ptxvd->cdata,
|
---|
| 3412 | pSource,
|
---|
| 3413 | (ULONG)mrc);
|
---|
[8] | 3414 | }
|
---|
| 3415 | break;
|
---|
| 3416 |
|
---|
| 3417 | /*
|
---|
| 3418 | *@@ TXM_JUMPTOANCHORNAME:
|
---|
| 3419 | * scrolls the XTextView control contents so that
|
---|
| 3420 | * the text marked with the specified anchor name
|
---|
| 3421 | * (TXVESC_ANCHORNAME escape) appears at the top
|
---|
| 3422 | * of the control.
|
---|
| 3423 | *
|
---|
[201] | 3424 | * This must be sent, not posted, to the control.
|
---|
[8] | 3425 | *
|
---|
| 3426 | * Parameters:
|
---|
| 3427 | * -- PSZ mp1: anchor name (e.g. "anchor1").
|
---|
| 3428 | *
|
---|
[206] | 3429 | * Returns TRUE if the jump was successful.
|
---|
| 3430 | *
|
---|
[8] | 3431 | *@@added V0.9.4 (2000-06-12) [umoeller]
|
---|
| 3432 | */
|
---|
| 3433 |
|
---|
| 3434 | case TXM_JUMPTOANCHORNAME:
|
---|
[206] | 3435 | mrc = ProcessJumpToAnchorName(hwndTextView, mp1);
|
---|
[137] | 3436 | break;
|
---|
[8] | 3437 |
|
---|
| 3438 | /*
|
---|
[201] | 3439 | *@@ TXM_QUERYTEXTEXTENT:
|
---|
| 3440 | * returns the extents of the currently set text,
|
---|
| 3441 | * that is, the width and height of the internal
|
---|
| 3442 | * work area, of which the current view rectangle
|
---|
| 3443 | * displays a subrectangle.
|
---|
| 3444 | *
|
---|
| 3445 | * This must be sent, not posted, to the control.
|
---|
| 3446 | *
|
---|
| 3447 | * Parameters:
|
---|
| 3448 | *
|
---|
| 3449 | * -- PSIZEL mp1: pointer to a SIZEL buffer,
|
---|
| 3450 | * which receives the extent in the cx and
|
---|
| 3451 | * cy members. These will be set to null
|
---|
| 3452 | * values if the control currently has no
|
---|
| 3453 | * text.
|
---|
| 3454 | *
|
---|
| 3455 | * Returns TRUE on success.
|
---|
| 3456 | *
|
---|
| 3457 | *@@added V0.9.20 (2002-08-10) [umoeller]
|
---|
| 3458 | */
|
---|
| 3459 |
|
---|
| 3460 | case TXM_QUERYTEXTEXTENT:
|
---|
[206] | 3461 | if ( (mp1)
|
---|
| 3462 | && (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 3463 | )
|
---|
[201] | 3464 | {
|
---|
| 3465 | memcpy((PSIZEL)mp1,
|
---|
| 3466 | &ptxvd->xfd.szlWorkspace,
|
---|
| 3467 | sizeof(SIZEL));
|
---|
| 3468 | mrc = (MRESULT)TRUE;
|
---|
| 3469 | }
|
---|
| 3470 | break;
|
---|
| 3471 |
|
---|
| 3472 | /*
|
---|
[375] | 3473 | *@@ TXM_QUERYSTYLE:
|
---|
| 3474 | * returns the current style flags.
|
---|
| 3475 | *
|
---|
| 3476 | * This must be sent, not posted, to the control.
|
---|
| 3477 | *
|
---|
| 3478 | * Parameters:
|
---|
| 3479 | *
|
---|
| 3480 | * -- PULONG mp1: pointer to a ULONG buffer.
|
---|
| 3481 | *
|
---|
| 3482 | * Returns TRUE on success.
|
---|
| 3483 | *
|
---|
| 3484 | *@@added WarpIN V1.0.18 (2008-11-29) [pr]
|
---|
| 3485 | */
|
---|
| 3486 |
|
---|
| 3487 | case TXM_QUERYSTYLE:
|
---|
| 3488 | if ( (mp1)
|
---|
| 3489 | && (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 3490 | )
|
---|
| 3491 | {
|
---|
| 3492 | *((ULONG *) mp1) = ptxvd->flStyle;
|
---|
| 3493 | mrc = (MRESULT)TRUE;
|
---|
| 3494 | }
|
---|
| 3495 | break;
|
---|
| 3496 |
|
---|
| 3497 | /*
|
---|
| 3498 | *@@ TXM_SETSTYLE:
|
---|
| 3499 | * sets the current style flags.
|
---|
| 3500 | *
|
---|
| 3501 | * This must be sent, not posted, to the control.
|
---|
| 3502 | *
|
---|
| 3503 | * Parameters:
|
---|
| 3504 | *
|
---|
| 3505 | * -- PULONG mp1: pointer to a ULONG buffer.
|
---|
| 3506 | *
|
---|
| 3507 | * Returns TRUE on success.
|
---|
| 3508 | *
|
---|
| 3509 | *@@added WarpIN V1.0.18 (2008-11-29) [pr]
|
---|
| 3510 | */
|
---|
| 3511 |
|
---|
| 3512 | case TXM_SETSTYLE:
|
---|
| 3513 | if ( (mp1)
|
---|
| 3514 | && (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 3515 | )
|
---|
| 3516 | {
|
---|
| 3517 | ptxvd->flStyle = *((ULONG *) mp1);
|
---|
| 3518 | mrc = (MRESULT)TRUE;
|
---|
| 3519 | }
|
---|
| 3520 | break;
|
---|
| 3521 |
|
---|
| 3522 | /*
|
---|
| 3523 | *@@ TXM_COPY:
|
---|
| 3524 | * copies the unprocessed window text to the clipboard.
|
---|
| 3525 | *
|
---|
| 3526 | * Returns TRUE on success.
|
---|
| 3527 | *
|
---|
| 3528 | *@@added WarpIN V1.0.18 (2008-11-16) [pr]
|
---|
| 3529 | */
|
---|
| 3530 |
|
---|
| 3531 | case TXM_COPY:
|
---|
| 3532 | if (ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE))
|
---|
| 3533 | {
|
---|
| 3534 | mrc = (MRESULT) winhSetClipboardText(ptxvd->hab,
|
---|
| 3535 | ptxvd->xfd.strOrigText.psz,
|
---|
| 3536 | strlen(ptxvd->xfd.strOrigText.psz));
|
---|
| 3537 | }
|
---|
| 3538 | break;
|
---|
| 3539 |
|
---|
| 3540 | /*
|
---|
[8] | 3541 | * WM_DESTROY:
|
---|
| 3542 | * clean up.
|
---|
| 3543 | */
|
---|
| 3544 |
|
---|
| 3545 | case WM_DESTROY:
|
---|
[206] | 3546 | mrc = ProcessDestroy(hwndTextView, mp1, mp2);
|
---|
[8] | 3547 | break;
|
---|
| 3548 |
|
---|
| 3549 | default:
|
---|
| 3550 | mrc = WinDefWindowProc(hwndTextView, msg, mp1, mp2);
|
---|
| 3551 | }
|
---|
| 3552 |
|
---|
[167] | 3553 | return mrc;
|
---|
[8] | 3554 | }
|
---|
| 3555 |
|
---|
| 3556 | /*
|
---|
| 3557 | *@@ txvRegisterTextView:
|
---|
| 3558 | * registers the Text View class with PM. Required
|
---|
| 3559 | * before the text view control can be used.
|
---|
| 3560 | */
|
---|
| 3561 |
|
---|
| 3562 | BOOL txvRegisterTextView(HAB hab)
|
---|
| 3563 | {
|
---|
[201] | 3564 | return WinRegisterClass(hab,
|
---|
| 3565 | WC_XTEXTVIEW,
|
---|
| 3566 | fnwpTextView,
|
---|
| 3567 | 0,
|
---|
| 3568 | 2 * sizeof(PVOID)); // QWL_USER and QWL_PRIVATE
|
---|
[8] | 3569 | }
|
---|
| 3570 |
|
---|
| 3571 | /*
|
---|
| 3572 | *@@ txvReplaceWithTextView:
|
---|
| 3573 | * replaces any window with a text view control.
|
---|
| 3574 | * You must call txvRegisterTextView beforehand.
|
---|
| 3575 | *
|
---|
| 3576 | *@@added V0.9.1 (2000-02-13) [umoeller]
|
---|
| 3577 | */
|
---|
| 3578 |
|
---|
| 3579 | HWND txvReplaceWithTextView(HWND hwndParentAndOwner,
|
---|
| 3580 | USHORT usID,
|
---|
| 3581 | ULONG flWinStyle,
|
---|
| 3582 | USHORT usBorder)
|
---|
| 3583 | {
|
---|
| 3584 | HWND hwndMLE = WinWindowFromID(hwndParentAndOwner, usID),
|
---|
| 3585 | hwndTextView = NULLHANDLE;
|
---|
| 3586 | if (hwndMLE)
|
---|
| 3587 | {
|
---|
| 3588 | ULONG ul,
|
---|
| 3589 | // attrFound,
|
---|
| 3590 | abValue[32];
|
---|
| 3591 | SWP swpMLE;
|
---|
| 3592 | XTEXTVIEWCDATA xtxCData;
|
---|
| 3593 | PSZ pszFont = winhQueryWindowFont(hwndMLE);
|
---|
| 3594 | LONG lBackClr = -1,
|
---|
| 3595 | lForeClr = -1;
|
---|
| 3596 |
|
---|
| 3597 | if ((ul = WinQueryPresParam(hwndMLE,
|
---|
| 3598 | PP_BACKGROUNDCOLOR,
|
---|
| 3599 | 0,
|
---|
| 3600 | NULL,
|
---|
| 3601 | (ULONG)sizeof(abValue),
|
---|
| 3602 | (PVOID)&abValue,
|
---|
| 3603 | QPF_NOINHERIT)))
|
---|
| 3604 | lBackClr = abValue[0];
|
---|
| 3605 |
|
---|
| 3606 | if ((ul = WinQueryPresParam(hwndMLE,
|
---|
| 3607 | PP_FOREGROUNDCOLOR,
|
---|
| 3608 | 0,
|
---|
| 3609 | NULL,
|
---|
| 3610 | (ULONG)sizeof(abValue),
|
---|
| 3611 | (PVOID)&abValue,
|
---|
| 3612 | QPF_NOINHERIT)))
|
---|
| 3613 | lForeClr = abValue[0];
|
---|
| 3614 |
|
---|
| 3615 | WinQueryWindowPos(hwndMLE, &swpMLE);
|
---|
| 3616 |
|
---|
| 3617 | WinDestroyWindow(hwndMLE);
|
---|
| 3618 | memset(&xtxCData, 0, sizeof(xtxCData));
|
---|
| 3619 | xtxCData.cbData = sizeof(xtxCData);
|
---|
| 3620 | xtxCData.ulXBorder = usBorder;
|
---|
| 3621 | xtxCData.ulYBorder = usBorder;
|
---|
| 3622 | hwndTextView = WinCreateWindow(hwndParentAndOwner,
|
---|
| 3623 | WC_XTEXTVIEW,
|
---|
| 3624 | "",
|
---|
| 3625 | flWinStyle,
|
---|
| 3626 | swpMLE.x,
|
---|
| 3627 | swpMLE.y,
|
---|
| 3628 | swpMLE.cx,
|
---|
| 3629 | swpMLE.cy,
|
---|
| 3630 | hwndParentAndOwner,
|
---|
| 3631 | HWND_TOP,
|
---|
| 3632 | usID,
|
---|
| 3633 | &xtxCData,
|
---|
| 3634 | 0);
|
---|
| 3635 | if (pszFont)
|
---|
| 3636 | {
|
---|
| 3637 | winhSetWindowFont(hwndTextView, pszFont);
|
---|
| 3638 | free(pszFont);
|
---|
| 3639 | }
|
---|
| 3640 |
|
---|
| 3641 | if (lBackClr != -1)
|
---|
| 3642 | WinSetPresParam(hwndTextView,
|
---|
| 3643 | PP_BACKGROUNDCOLOR,
|
---|
| 3644 | sizeof(ULONG),
|
---|
| 3645 | &lBackClr);
|
---|
| 3646 | if (lForeClr != -1)
|
---|
| 3647 | WinSetPresParam(hwndTextView,
|
---|
| 3648 | PP_FOREGROUNDCOLOR,
|
---|
| 3649 | sizeof(ULONG),
|
---|
| 3650 | &lForeClr);
|
---|
| 3651 | }
|
---|
[201] | 3652 | return hwndTextView;
|
---|
[8] | 3653 | }
|
---|
| 3654 |
|
---|
| 3655 | /* ******************************************************************
|
---|
[14] | 3656 | *
|
---|
| 3657 | * Printer-dependent functions
|
---|
| 3658 | *
|
---|
[8] | 3659 | ********************************************************************/
|
---|
| 3660 |
|
---|
| 3661 | /*
|
---|
| 3662 | *@@ prthQueryQueues:
|
---|
| 3663 | * returns a buffer containing all print queues
|
---|
| 3664 | * on the system.
|
---|
| 3665 | *
|
---|
| 3666 | * This is usually the first step before printing.
|
---|
| 3667 | * After calling this function, show a dlg to the
|
---|
| 3668 | * user, allow him to select the printer queue
|
---|
| 3669 | * to be used. This can then be passed to
|
---|
| 3670 | * prthCreatePrinterDC.
|
---|
| 3671 | *
|
---|
| 3672 | * Use prthFreeBuf to free the returned buffer.
|
---|
| 3673 | */
|
---|
| 3674 |
|
---|
[222] | 3675 | STATIC PRQINFO3* prthEnumQueues(PULONG pulReturned) // out: no. of queues found
|
---|
[8] | 3676 | {
|
---|
| 3677 | SPLERR rc;
|
---|
| 3678 | ULONG cTotal;
|
---|
| 3679 | ULONG cbNeeded = 0;
|
---|
| 3680 | PRQINFO3 *pprq3 = NULL;
|
---|
| 3681 |
|
---|
| 3682 | // count queues & get number of bytes needed for buffer
|
---|
| 3683 | rc = SplEnumQueue(NULL, // default computer
|
---|
| 3684 | 3, // detail level
|
---|
| 3685 | NULL, // pbuf
|
---|
| 3686 | 0L, // cbBuf
|
---|
| 3687 | pulReturned, // out: entries returned
|
---|
| 3688 | &cTotal, // out: total entries available
|
---|
| 3689 | &cbNeeded,
|
---|
| 3690 | NULL); // reserved
|
---|
| 3691 |
|
---|
[91] | 3692 | if (!rc && cbNeeded)
|
---|
[8] | 3693 | {
|
---|
| 3694 | pprq3 = (PRQINFO3*)malloc(cbNeeded);
|
---|
| 3695 | if (pprq3)
|
---|
| 3696 | {
|
---|
| 3697 | // enum the queues
|
---|
| 3698 | rc = SplEnumQueue(NULL,
|
---|
| 3699 | 3,
|
---|
| 3700 | pprq3,
|
---|
| 3701 | cbNeeded,
|
---|
| 3702 | pulReturned,
|
---|
| 3703 | &cTotal,
|
---|
| 3704 | &cbNeeded,
|
---|
| 3705 | NULL);
|
---|
| 3706 | }
|
---|
| 3707 | }
|
---|
| 3708 |
|
---|
[201] | 3709 | return pprq3;
|
---|
[8] | 3710 | }
|
---|
| 3711 |
|
---|
| 3712 | /*
|
---|
| 3713 | *@@ prthFreeBuf:
|
---|
| 3714 | *
|
---|
| 3715 | */
|
---|
| 3716 |
|
---|
[222] | 3717 | STATIC VOID prthFreeBuf(PVOID pprq3)
|
---|
[8] | 3718 | {
|
---|
| 3719 | if (pprq3)
|
---|
| 3720 | free(pprq3);
|
---|
| 3721 | }
|
---|
| 3722 |
|
---|
| 3723 | /*
|
---|
| 3724 | *@@ prthCreatePrinterDC:
|
---|
| 3725 | * creates a device context for the printer
|
---|
| 3726 | * specified by the given printer queue.
|
---|
| 3727 | *
|
---|
| 3728 | * As a nifty feature, this returns printer
|
---|
| 3729 | * device resolution automatically in the
|
---|
| 3730 | * specified buffer.
|
---|
| 3731 | *
|
---|
| 3732 | * Returns NULLHANDLE (== DEV_ERROR) on errors.
|
---|
| 3733 | *
|
---|
| 3734 | * Use DevCloseDC to destroy the DC.
|
---|
| 3735 | *
|
---|
| 3736 | * Based on print sample by Peter Fitzsimmons, Fri 95-09-29 02:47:16am.
|
---|
| 3737 | */
|
---|
| 3738 |
|
---|
[222] | 3739 | STATIC HDC prthCreatePrinterDC(HAB hab,
|
---|
[142] | 3740 | PRQINFO3 *pprq3,
|
---|
| 3741 | PLONG palRes) // out: 2 longs holding horizontal and vertical
|
---|
| 3742 | // printer resolution in pels per inch
|
---|
[8] | 3743 | {
|
---|
| 3744 | HDC hdc = NULLHANDLE;
|
---|
| 3745 | DEVOPENSTRUC dos;
|
---|
| 3746 | PSZ p;
|
---|
| 3747 |
|
---|
| 3748 | memset(&dos, 0, sizeof(dos));
|
---|
| 3749 | p = strrchr(pprq3->pszDriverName, '.');
|
---|
| 3750 | if (p)
|
---|
| 3751 | *p = 0; // del everything after '.'
|
---|
| 3752 |
|
---|
| 3753 | dos.pszLogAddress = pprq3->pszName;
|
---|
| 3754 | dos.pszDriverName = pprq3->pszDriverName;
|
---|
| 3755 | dos.pdriv = pprq3->pDriverData;
|
---|
| 3756 | dos.pszDataType = "PM_Q_STD";
|
---|
| 3757 | hdc = DevOpenDC(hab,
|
---|
| 3758 | OD_QUEUED,
|
---|
| 3759 | "*",
|
---|
| 3760 | 4L, // count of items in next param
|
---|
| 3761 | (PDEVOPENDATA)&dos,
|
---|
| 3762 | 0); // compatible DC
|
---|
| 3763 |
|
---|
| 3764 | if (hdc)
|
---|
| 3765 | DevQueryCaps(hdc,
|
---|
| 3766 | CAPS_HORIZONTAL_FONT_RES,
|
---|
| 3767 | 2,
|
---|
| 3768 | palRes); // buffer
|
---|
| 3769 |
|
---|
[201] | 3770 | return hdc;
|
---|
[8] | 3771 | }
|
---|
| 3772 |
|
---|
| 3773 | /*
|
---|
| 3774 | *@@ prthQueryForms:
|
---|
| 3775 | * returns a buffer containing all forms
|
---|
| 3776 | * supported by the specified printer DC.
|
---|
| 3777 | *
|
---|
| 3778 | * Use prthFreeBuf to free the returned
|
---|
| 3779 | * buffer.
|
---|
| 3780 | *
|
---|
| 3781 | * HCINFO uses different model spaces for
|
---|
| 3782 | * the returned info. See PMREF for details.
|
---|
| 3783 | */
|
---|
| 3784 |
|
---|
[222] | 3785 | STATIC HCINFO* prthQueryForms(HDC hdc,
|
---|
[142] | 3786 | PULONG pulCount)
|
---|
[8] | 3787 | {
|
---|
| 3788 | HCINFO *pahci = NULL;
|
---|
| 3789 |
|
---|
| 3790 | LONG cForms;
|
---|
| 3791 |
|
---|
| 3792 | // get form count
|
---|
| 3793 | cForms = DevQueryHardcopyCaps(hdc, 0L, 0L, NULL); // phci);
|
---|
| 3794 | if (cForms)
|
---|
| 3795 | {
|
---|
| 3796 | pahci = (HCINFO*)malloc(cForms * sizeof(HCINFO));
|
---|
| 3797 | if (pahci)
|
---|
| 3798 | {
|
---|
| 3799 | *pulCount = DevQueryHardcopyCaps(hdc, 0, cForms, pahci);
|
---|
| 3800 | }
|
---|
| 3801 | }
|
---|
| 3802 |
|
---|
[201] | 3803 | return pahci;
|
---|
[8] | 3804 | }
|
---|
| 3805 |
|
---|
| 3806 | /*
|
---|
| 3807 | *@@ prthCreatePS:
|
---|
| 3808 | * creates a "normal" presentation space from the specified
|
---|
| 3809 | * printer device context (which can be opened thru
|
---|
| 3810 | * prthCreatePrinterDC).
|
---|
| 3811 | *
|
---|
| 3812 | * Returns NULLHANDLE on errors.
|
---|
| 3813 | *
|
---|
| 3814 | * Based on print sample by Peter Fitzsimmons, Fri 95-09-29 02:47:16am.
|
---|
| 3815 | */
|
---|
| 3816 |
|
---|
[222] | 3817 | STATIC HPS prthCreatePS(HAB hab, // in: anchor block
|
---|
[142] | 3818 | HDC hdc, // in: printer device context
|
---|
| 3819 | ULONG ulUnits) // in: one of:
|
---|
| 3820 | // -- PU_PELS
|
---|
| 3821 | // -- PU_LOMETRIC
|
---|
| 3822 | // -- PU_HIMETRIC
|
---|
| 3823 | // -- PU_LOENGLISH
|
---|
| 3824 | // -- PU_HIENGLISH
|
---|
| 3825 | // -- PU_TWIPS
|
---|
[8] | 3826 | {
|
---|
| 3827 | SIZEL sizel;
|
---|
| 3828 |
|
---|
| 3829 | sizel.cx = 0;
|
---|
| 3830 | sizel.cy = 0;
|
---|
[201] | 3831 | return GpiCreatePS(hab,
|
---|
| 3832 | hdc,
|
---|
| 3833 | &sizel,
|
---|
| 3834 | ulUnits | GPIA_ASSOC | GPIT_NORMAL);
|
---|
[8] | 3835 | }
|
---|
| 3836 |
|
---|
| 3837 | /*
|
---|
| 3838 | *@@ prthStartDoc:
|
---|
| 3839 | * calls DevEscape with DEVESC_STARTDOC.
|
---|
| 3840 | * This must be called before any painting
|
---|
| 3841 | * into the HDC's HPS. Any GPI calls made
|
---|
| 3842 | * before this are ignored.
|
---|
| 3843 | *
|
---|
| 3844 | * pszDocTitle appears in the spooler.
|
---|
| 3845 | */
|
---|
| 3846 |
|
---|
[222] | 3847 | STATIC VOID prthStartDoc(HDC hdc,
|
---|
[142] | 3848 | PSZ pszDocTitle)
|
---|
[8] | 3849 | {
|
---|
| 3850 | DevEscape(hdc,
|
---|
| 3851 | DEVESC_STARTDOC,
|
---|
| 3852 | strlen(pszDocTitle),
|
---|
| 3853 | pszDocTitle,
|
---|
| 3854 | 0L,
|
---|
| 3855 | 0L);
|
---|
| 3856 | }
|
---|
| 3857 |
|
---|
| 3858 | /*
|
---|
| 3859 | *@@ prthNextPage:
|
---|
| 3860 | * calls DevEscape with DEVESC_NEWFRAME.
|
---|
| 3861 | * Signals when an application has finished writing to a page and wants to
|
---|
| 3862 | * start a new page. It is similar to GpiErase processing for a screen device
|
---|
| 3863 | * context, and causes a reset of the attributes. This escape is used with a
|
---|
| 3864 | * printer device to advance to a new page.
|
---|
| 3865 | */
|
---|
| 3866 |
|
---|
[222] | 3867 | STATIC VOID prthNextPage(HDC hdc)
|
---|
[8] | 3868 | {
|
---|
| 3869 | DevEscape(hdc,
|
---|
| 3870 | DEVESC_NEWFRAME,
|
---|
| 3871 | 0,
|
---|
| 3872 | 0,
|
---|
| 3873 | 0,
|
---|
| 3874 | 0);
|
---|
| 3875 | }
|
---|
| 3876 |
|
---|
| 3877 | /*
|
---|
| 3878 | *@@ prthEndDoc:
|
---|
| 3879 | * calls DevEscape with DEVESC_ENDDOC
|
---|
| 3880 | * and disassociates the HPS from the HDC.
|
---|
| 3881 | * Call this right before doing
|
---|
| 3882 | + GpiDestroyPS(hps);
|
---|
| 3883 | + DevCloseDC(hdc);
|
---|
| 3884 | */
|
---|
| 3885 |
|
---|
[222] | 3886 | STATIC VOID prthEndDoc(HDC hdc,
|
---|
[142] | 3887 | HPS hps)
|
---|
[8] | 3888 | {
|
---|
| 3889 | DevEscape(hdc, DEVESC_ENDDOC, 0L, 0L, 0, NULL);
|
---|
| 3890 | GpiAssociate(hps, NULLHANDLE);
|
---|
| 3891 | }
|
---|
| 3892 |
|
---|
| 3893 | /*
|
---|
| 3894 | *@@ txvPrint:
|
---|
| 3895 | * this does the actual printing.
|
---|
| 3896 | */
|
---|
| 3897 |
|
---|
| 3898 | BOOL txvPrint(HAB hab,
|
---|
| 3899 | HDC hdc, // in: printer device context
|
---|
| 3900 | HPS hps, // in: printer presentation space (using PU_PELS)
|
---|
| 3901 | PSZ pszViewText, // in: text to print
|
---|
| 3902 | ULONG ulSize, // in: default font point size
|
---|
| 3903 | PSZ pszFaceName, // in: default font face name
|
---|
| 3904 | HCINFO *phci, // in: hardcopy form to use
|
---|
| 3905 | PSZ pszDocTitle, // in: document title (appears in spooler)
|
---|
| 3906 | FNPRINTCALLBACK *pfnCallback)
|
---|
| 3907 | {
|
---|
| 3908 | RECTL rclPageDevice,
|
---|
| 3909 | rclPageWorld;
|
---|
| 3910 | XFORMATDATA xfd;
|
---|
| 3911 | BOOL fAnotherPage = FALSE;
|
---|
| 3912 | ULONG ulCurrentLineIndex = 0,
|
---|
| 3913 | ulCurrentPage = 1;
|
---|
[25] | 3914 | ULONG ulCurrentYOfs = 0;
|
---|
[8] | 3915 |
|
---|
| 3916 | /* MATRIXLF matlf;
|
---|
| 3917 | POINTL ptlCenter;
|
---|
| 3918 | FIXED scalars[2]; */
|
---|
| 3919 |
|
---|
| 3920 | // important: we must do a STARTDOC before we use the printer HPS.
|
---|
| 3921 | prthStartDoc(hdc,
|
---|
| 3922 | pszDocTitle);
|
---|
| 3923 |
|
---|
| 3924 | // the PS is in TWIPS, but our world coordinate
|
---|
| 3925 | // space is in pels, so we need to transform
|
---|
| 3926 | /* GpiQueryViewingTransformMatrix(hps,
|
---|
| 3927 | 1L,
|
---|
| 3928 | &matlf);
|
---|
| 3929 | ptlCenter.x = 0;
|
---|
| 3930 | ptlCenter.y = 0;
|
---|
| 3931 | scalars[0] = MAKEFIXED(2,0);
|
---|
| 3932 | scalars[1] = MAKEFIXED(3,0);
|
---|
| 3933 |
|
---|
| 3934 | GpiScale (hps,
|
---|
| 3935 | &matlf,
|
---|
| 3936 | TRANSFORM_REPLACE,
|
---|
| 3937 | scalars,
|
---|
| 3938 | &ptlCenter); */
|
---|
| 3939 |
|
---|
| 3940 | // initialize format with font from window
|
---|
| 3941 | txvInitFormat(&xfd);
|
---|
| 3942 |
|
---|
[142] | 3943 | /* SetFormatFont(hps,
|
---|
[8] | 3944 | &xfd,
|
---|
| 3945 | ulSize,
|
---|
| 3946 | pszFaceName); */
|
---|
| 3947 |
|
---|
| 3948 | // use text from window
|
---|
[23] | 3949 | xstrcpy(&xfd.strViewText, pszViewText, 0);
|
---|
[8] | 3950 |
|
---|
| 3951 | // setup page
|
---|
| 3952 | GpiQueryPageViewport(hps,
|
---|
| 3953 | &rclPageDevice);
|
---|
| 3954 | // this is in device units; convert this
|
---|
| 3955 | // to the world coordinate space of the printer PS
|
---|
| 3956 | memcpy(&rclPageWorld, &rclPageDevice, sizeof(RECTL));
|
---|
| 3957 | GpiConvert(hps,
|
---|
| 3958 | CVTC_DEVICE, // source
|
---|
| 3959 | CVTC_WORLD,
|
---|
| 3960 | 2, // 2 points, it's a rectangle
|
---|
| 3961 | (PPOINTL)&rclPageWorld);
|
---|
| 3962 |
|
---|
| 3963 | // left and bottom margins are in millimeters...
|
---|
| 3964 | /* rclPage.xLeft = 100; // ###
|
---|
| 3965 | rclPage.yBottom = 100;
|
---|
| 3966 | rclPage.xRight = rclPage.xLeft + phci->xPels;
|
---|
| 3967 | rclPage.yTop = rclPage.yBottom + phci->yPels; */
|
---|
| 3968 |
|
---|
| 3969 | txvFormatText(hps,
|
---|
| 3970 | &xfd, // in: ptxvd->rclViewText
|
---|
| 3971 | &rclPageWorld,
|
---|
| 3972 | TRUE);
|
---|
| 3973 |
|
---|
| 3974 | do
|
---|
| 3975 | {
|
---|
| 3976 | _Pmpf(("---- printing page %d",
|
---|
| 3977 | ulCurrentPage));
|
---|
| 3978 |
|
---|
| 3979 | fAnotherPage = txvPaintText(hab,
|
---|
| 3980 | hps,
|
---|
| 3981 | &xfd,
|
---|
| 3982 | &rclPageWorld,
|
---|
| 3983 | 0,
|
---|
[25] | 3984 | &ulCurrentYOfs,
|
---|
[8] | 3985 | FALSE, // draw only fully visible lines
|
---|
| 3986 | &ulCurrentLineIndex); // in/out: line to start with
|
---|
| 3987 | if (fAnotherPage)
|
---|
| 3988 | {
|
---|
| 3989 | prthNextPage(hdc);
|
---|
| 3990 |
|
---|
| 3991 | if (pfnCallback(ulCurrentPage++, 0) == FALSE)
|
---|
| 3992 | fAnotherPage = FALSE;
|
---|
| 3993 | }
|
---|
| 3994 | } while (fAnotherPage);
|
---|
| 3995 |
|
---|
| 3996 | prthEndDoc(hdc, hps);
|
---|
| 3997 |
|
---|
[201] | 3998 | return TRUE;
|
---|
[8] | 3999 | }
|
---|
| 4000 |
|
---|
| 4001 | /*
|
---|
| 4002 | *@@ txvPrintWindow:
|
---|
| 4003 | * one-shot function which prints the contents
|
---|
| 4004 | * of the specified XTextView control to the
|
---|
| 4005 | * default printer, using the default form.
|
---|
| 4006 | *
|
---|
| 4007 | * Returns a nonzero value upon errors.
|
---|
| 4008 | *
|
---|
| 4009 | * Based on print sample by Peter Fitzsimmons, Fri 95-09-29 02:47:16am.
|
---|
| 4010 | */
|
---|
| 4011 |
|
---|
| 4012 | int txvPrintWindow(HWND hwndTextView,
|
---|
| 4013 | PSZ pszDocTitle, // in: document title (appears in spooler)
|
---|
| 4014 | FNPRINTCALLBACK *pfnCallback)
|
---|
| 4015 | {
|
---|
| 4016 | int irc = 0;
|
---|
| 4017 |
|
---|
[201] | 4018 | PTEXTVIEWWINDATA ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE);
|
---|
[8] | 4019 |
|
---|
| 4020 | if (!ptxvd)
|
---|
| 4021 | irc = 1;
|
---|
| 4022 | else
|
---|
| 4023 | {
|
---|
| 4024 | ULONG cReturned = 0;
|
---|
| 4025 | PRQINFO3 *pprq3 = prthEnumQueues(&cReturned);
|
---|
| 4026 | HDC hdc = NULLHANDLE;
|
---|
| 4027 | LONG caps[2];
|
---|
| 4028 |
|
---|
| 4029 | // find default queue
|
---|
| 4030 | if (pprq3)
|
---|
| 4031 | {
|
---|
| 4032 | ULONG i;
|
---|
| 4033 | // search for default queue;
|
---|
| 4034 | for (i = 0; i < cReturned; i++)
|
---|
| 4035 | if (pprq3[i].fsType & PRQ3_TYPE_APPDEFAULT)
|
---|
| 4036 | {
|
---|
| 4037 | hdc = prthCreatePrinterDC(ptxvd->hab,
|
---|
| 4038 | &pprq3[i],
|
---|
| 4039 | caps);
|
---|
| 4040 |
|
---|
| 4041 | break;
|
---|
| 4042 | }
|
---|
| 4043 | prthFreeBuf(pprq3);
|
---|
| 4044 | }
|
---|
| 4045 |
|
---|
| 4046 | if (!hdc)
|
---|
| 4047 | irc = 2;
|
---|
| 4048 | else
|
---|
| 4049 | {
|
---|
| 4050 | // OK, we got a printer DC:
|
---|
| 4051 | HPS hps;
|
---|
| 4052 | ULONG cForms = 0;
|
---|
| 4053 | HCINFO *pahci,
|
---|
| 4054 | *phciSelected = 0;
|
---|
| 4055 |
|
---|
| 4056 | // find default form
|
---|
| 4057 | pahci = prthQueryForms(hdc,
|
---|
| 4058 | &cForms);
|
---|
| 4059 | if (pahci)
|
---|
| 4060 | {
|
---|
| 4061 | HCINFO *phciThis = pahci;
|
---|
| 4062 | ULONG i;
|
---|
| 4063 | for (i = 0;
|
---|
| 4064 | i < cForms;
|
---|
| 4065 | i++, phciThis++)
|
---|
| 4066 | {
|
---|
| 4067 | if (phciThis->flAttributes & HCAPS_CURRENT)
|
---|
| 4068 | {
|
---|
| 4069 | phciSelected = phciThis;
|
---|
| 4070 | }
|
---|
| 4071 | }
|
---|
| 4072 | }
|
---|
| 4073 |
|
---|
| 4074 | if (!phciSelected)
|
---|
| 4075 | irc = 3;
|
---|
| 4076 | else
|
---|
| 4077 | {
|
---|
| 4078 | // create printer PS
|
---|
| 4079 | hps = prthCreatePS(ptxvd->hab,
|
---|
| 4080 | hdc,
|
---|
| 4081 | PU_PELS);
|
---|
| 4082 |
|
---|
| 4083 | if (hps == GPI_ERROR)
|
---|
| 4084 | irc = 4;
|
---|
| 4085 | else
|
---|
| 4086 | {
|
---|
| 4087 | PSZ pszFont;
|
---|
| 4088 | ULONG ulSize = 0;
|
---|
| 4089 | PSZ pszFaceName = 0;
|
---|
| 4090 |
|
---|
| 4091 | if ((pszFont = winhQueryWindowFont(hwndTextView)))
|
---|
| 4092 | gpihSplitPresFont(pszFont,
|
---|
| 4093 | &ulSize,
|
---|
| 4094 | &pszFaceName);
|
---|
| 4095 | txvPrint(ptxvd->hab,
|
---|
| 4096 | hdc,
|
---|
| 4097 | hps,
|
---|
[12] | 4098 | ptxvd->xfd.strViewText.psz,
|
---|
[8] | 4099 | ulSize,
|
---|
| 4100 | pszFaceName,
|
---|
| 4101 | phciSelected,
|
---|
| 4102 | pszDocTitle,
|
---|
| 4103 | pfnCallback);
|
---|
| 4104 |
|
---|
| 4105 | if (pszFont)
|
---|
| 4106 | free(pszFont);
|
---|
| 4107 |
|
---|
| 4108 | GpiDestroyPS(hps);
|
---|
| 4109 | }
|
---|
| 4110 | }
|
---|
| 4111 | DevCloseDC(hdc);
|
---|
| 4112 | }
|
---|
| 4113 | }
|
---|
| 4114 |
|
---|
[201] | 4115 | return irc;
|
---|
[8] | 4116 | }
|
---|
| 4117 |
|
---|
| 4118 |
|
---|