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