Ignore:
Timestamp:
Aug 11, 2002, 7:07:59 PM (23 years ago)
Author:
umoeller
Message:

Major work on textview control and dialogs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/textview.c

    r167 r201  
    243243
    244244#include "helpers\textview.h"
     245#include "helpers\textv_html.h"
    245246
    246247#pragma hdrstop
     
    418419 *
    419420 *@@added V0.9.3 (2000-05-07) [umoeller]
     421 *@@changed V0.9.20 (2002-08-10) [umoeller]: now stripping \xFF too
    420422 */
    421423
     
    423425                       ULONG ulTabSize)
    424426{
    425     PSZ pSource = *ppszText;
    426     ULONG cbNew = 1000;
    427     PSZ pszNew = (PSZ)malloc(cbNew);
    428     PSZ pTarget = pszNew;
     427    PSZ     pSource = *ppszText;
     428    ULONG   cbNew = 1000;
     429    PSZ     pszNew = (PSZ)malloc(cbNew);
     430    PSZ     pTarget = pszNew;
     431    ULONG   ul;
    429432
    430433    while (*pSource)
    431434    {
    432         if (*pSource == '\r')
    433             pSource++;
    434         else if (*pSource == '\t')
    435         {
    436             ULONG ul;
    437             for (ul = 0;
    438                  ul < ulTabSize;
    439                  ul++)
     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]
    440455                AppendCharNoCheck(&pszNew,
    441456                                  &cbNew,
    442457                                  &pTarget,
    443458                                  ' ');
    444 
    445             // skip the tab
    446             pSource++;
     459                pSource++;
     460            break;
     461
     462            default:
     463                AppendCharNoCheck(&pszNew,
     464                                  &cbNew,
     465                                  &pTarget,
     466                                  *pSource++);
    447467        }
    448         else
    449             AppendCharNoCheck(&pszNew,
    450                               &cbNew,
    451                               &pTarget,
    452                               *pSource++);
    453468    }
     469
    454470    AppendCharNoCheck(&pszNew,
    455471                      &cbNew,
     
    542558    //      of the next line or points to the \0 character
    543559
    544     return (prc);
     560    return prc;
    545561}
    546562
     
    551567#define TXVFRECTF_ENDOFTEXT              0x0010
    552568   */
     569
    553570/*
    554571 *@@ FORMATLINEBUF:
     
    577594
    578595    // current anchor
    579     USHORT          usCurrentAnchor;
    580                         // this is > 0 if we're currently in an anchor block
     596    PSZ             pszCurrentLink;
     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)
    581600
    582601    // data copied to TXVWORD
    583602    LONG            lcid;
    584603    LONG            lPointSize;
    585     ULONG           flOptions;  // any combination of CHS_UNDERSCORE and CHS_STRIKEOUT
     604    ULONG           flChar;     // any combination of CHS_UNDERSCORE and CHS_STRIKEOUT
    586605
    587606    // counters, ...
     
    611630 *
    612631 *@@added V0.9.3 (2000-05-14) [umoeller]
     632 *@@changed V0.9.20 (2002-08-10) [umoeller]: rewrote link implementation
    613633 */
    614634
     
    709729        pWord->lcid = pflbuf->pfmtf->lcid;
    710730        pWord->lPointSize = pflbuf->lPointSize;
    711         pWord->flOptions = pflbuf->flOptions;
    712 
    713         pWord->usAnchor = pflbuf->usCurrentAnchor; // 0 if none
     731        pWord->flChar = pflbuf->flChar;
     732
     733        pWord->pszLinkTarget = pflbuf->pszCurrentLink; // 0 if none
    714734    }
    715735
    716     return (pWord);
     736    return pWord;
    717737}
    718738
     
    756776    // an escape character was found; txvCreateRectangle
    757777    // then sets pCurrent to the escape character (\xFF)
    758     CHAR    cCode1 = *((*ppCurrent)+1);
    759     CHAR    cCode2 = *((*ppCurrent)+2);
     778    CHAR    cCode1 = *((*ppCurrent) + 1);
     779    CHAR    cCode2 = *((*ppCurrent) + 2);
    760780    ULONG   ulSkip = 3; // per default, skip \xFF plus two
    761781    CHAR    szDecimal[10];
     
    769789        case 1:     // change font:
    770790            // three decimals follow specifying the font
    771             memcpy(szDecimal, (*ppCurrent)+2, 3);
     791            memcpy(szDecimal, (*ppCurrent) + 2, 3);
    772792            szDecimal[3] = 0;
    773793            lDecimal = atoi(szDecimal);
     
    795815        case 4:     // U or /U
    796816            if (cCode2 == 1)
    797                 pflbuf->flOptions |= CHS_UNDERSCORE;
     817                pflbuf->flChar |= CHS_UNDERSCORE;
    798818            else
    799                 pflbuf->flOptions &= ~CHS_UNDERSCORE;
     819                pflbuf->flChar &= ~CHS_UNDERSCORE;
    800820        break;
    801821
    802822        case 5:     // STRIKE or /STRIKE
    803823            if (cCode2 == 1)
    804                 pflbuf->flOptions |= CHS_STRIKEOUT;
     824                pflbuf->flChar |= CHS_STRIKEOUT;
    805825            else
    806                 pflbuf->flOptions &= ~CHS_STRIKEOUT;
     826                pflbuf->flChar &= ~CHS_STRIKEOUT;
    807827        break;
    808828
    809         case 6:     // A or /A HREF= (link)
    810             // four characters with hex anchor index (>=1)
    811             // or "####"
    812             if (  *( (*ppCurrent)+2 )
    813                   == '#'
    814                )
    815                 pflbuf->usCurrentAnchor = 0;
    816             else
     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))
    817838            {
    818                 PSZ pEnd;
    819                 memcpy(szDecimal, (*ppCurrent)+2, 4);
    820                 szDecimal[4] = 0;
    821                 lDecimal = strtol(szDecimal, &pEnd, 16);
    822                 pflbuf->usCurrentAnchor = lDecimal;
     839                pflbuf->pszCurrentLink = strhSubstr((*ppCurrent) + 2, pEnd);
     840                ulSkip = pEnd - *ppCurrent + 1;
     841
     842                lstAppendItem(&pxfd->llLinks,
     843                              pflbuf->pszCurrentLink);
    823844            }
    824 
    825             ulSkip = 6;
     845        }
    826846        break;
    827847
    828         case 7:     // A NAME= (anchor name)
     848        case 7:     // /A HREF (end of link)
     849            pflbuf->pszCurrentLink = NULL;
     850            ulSkip = 2;
     851        break;
     852
     853        case 8:     // A NAME= (anchor name)
    829854        {
    830855            // this is variable in length and terminated with
     
    834859            // searches the buffer
    835860            PSZ pEnd;
    836             if (pEnd = strchr((*ppCurrent)+2, 0xFF))
     861            if (pEnd = strchr((*ppCurrent) + 2, 0xFF))
    837862            {
    838863                ulSkip = pEnd - *ppCurrent + 1;
     
    849874            // three characters follow specifying the
    850875            // percentage
    851             memcpy(szDecimal, (*ppCurrent)+2, 3);
     876            memcpy(szDecimal, (*ppCurrent) + 2, 3);
    852877            szDecimal[3] = 0;
    853878            lDecimal = atoi(szDecimal);
     
    858883
    859884        case 0x20: // left margin changed:
    860             memcpy(szDecimal, (*ppCurrent)+2, 4);   // four decimals xxxx
     885            memcpy(szDecimal, (*ppCurrent) + 2, 4);   // four decimals xxxx
    861886            szDecimal[4] = 0;
    862887            lDecimal = atoi(szDecimal);
     
    871896
    872897        case 0x21: // first line margin changed:
    873             memcpy(szDecimal, (*ppCurrent)+2, 4);   // +xxx, -xxx
     898            memcpy(szDecimal, (*ppCurrent) + 2, 4);   // +xxx, -xxx
    874899            szDecimal[4] = 0;
    875900            lDecimal = atoi(szDecimal);
     
    899924        case 0x30:  // spacing before paragraph:
    900925            // four chars follow with either "####" or decimal spacing
    901             memcpy(szDecimal, (*ppCurrent)+2, 4);
     926            memcpy(szDecimal, (*ppCurrent) + 2, 4);
    902927            szDecimal[4] = 0;
    903928            if (memcmp(szDecimal, "####", 4) == 0)
     
    915940        case 0x31:  // spacing before paragraph:
    916941            // four chars follow with either "####" or decimal spacing
    917             memcpy(szDecimal, (*ppCurrent)+2, 4);
     942            memcpy(szDecimal, (*ppCurrent) + 2, 4);
    918943            szDecimal[4] = 0;
    919944            if (memcmp(szDecimal, "####", 4) == 0)
     
    949974            pEscapeWord->cEscapeCode = *(*ppCurrent + 1);
    950975            pEscapeWord->fPaintEscapeWord = fPaintEscapeWord;
    951             pEscapeWord->usAnchor = pflbuf->usCurrentAnchor; // 0 if none
     976            pEscapeWord->pszLinkTarget = pflbuf->pszCurrentLink;
     977                    // V0.9.20 (2002-08-10) [umoeller]
     978                    // NULL if none
    952979            if (fPaintEscapeWord)
    953980            {
     
    955982                pEscapeWord->lcid = pflbuf->pfmtf->lcid;
    956983                pEscapeWord->lPointSize = pflbuf->lPointSize;
    957                 pEscapeWord->flOptions = pflbuf->flOptions;
     984                pEscapeWord->flChar = pflbuf->flChar;
    958985            }
    959986            lstAppendItem(&pxfd->llWords, pEscapeWord);
     
    965992        *ppCurrent += ulSkip;
    966993
    967     return (pEscapeWord);
     994    return pEscapeWord;
    968995}
    969996
     
    10551082 *         to paint rectangles.
    10561083 *
    1057  *      -- XFORMATDATA.ulViewportCX, ulViewportCY: total width
    1058  *         and height of the "viewport", i.e. the total space
     1084 *      -- XFORMATDATA.szlWorkspace: total width
     1085 *         and height of the "workspace", i.e. the total space
    10591086 *         needed to display the text (in pels). This might
    10601087 *         be smaller, the same, or larger than prclView,
     
    10621089 *
    10631090 *         When displaying text, you should display scroll bars
    1064  *         if the viewport is larger than the window (prclView).
    1065  *
    1066  *         When printing, if the viewport is larger than the
     1091 *         if the workspace is larger than the window (prclView).
     1092 *
     1093 *         When printing, if the workspace is larger than the
    10671094 *         printer page (prclView), you will need to call
    10681095 *         txvPaintText several times for each page.
     
    10871114        lstClear(&pxfd->llWords);
    10881115
    1089     pxfd->ulViewportCX = 0;
    1090     pxfd->ulViewportCY = 0;
     1116    pxfd->szlWorkspace.cx = 0;
     1117    pxfd->szlWorkspace.cy = 0;
    10911118
    10921119    if (pxfd->strViewText.cbAllocated)
     
    13661393
    13671394                                // update x extents
    1368                                 if (pRect->rcl.xRight > pxfd->ulViewportCX)
    1369                                     pxfd->ulViewportCX = pRect->rcl.xRight;
     1395                                if (pRect->rcl.xRight > pxfd->szlWorkspace.cx)
     1396                                    pxfd->szlWorkspace.cx = pRect->rcl.xRight;
    13701397
    13711398                                // and quit the inner loop
     
    13921419
    13931420                // lCurrentYTop now has the bottommost point we've used;
    1394                 // store this as viewport (this might be negative)
    1395                 pxfd->ulViewportCY = lOrigYTop - lCurrentYTop;
     1421                // store this as workspace (this might be negative)
     1422                pxfd->szlWorkspace.cy = lOrigYTop - lCurrentYTop;
    13961423            }
    13971424        }
     
    15861613            {
    15871614                PTXVWORD pWordThis = (PTXVWORD)pWordNode->pItemData;
    1588                 ULONG flOptions = pWordThis->flOptions;
    1589 
    1590                 if (pWordThis->usAnchor)
    1591                     flOptions |= CHS_UNDERSCORE;
     1615                ULONG flChar = pWordThis->flChar;
     1616
     1617                if (pWordThis->pszLinkTarget)       // V0.9.20 (2002-08-10) [umoeller]
     1618                    flChar |= CHS_UNDERSCORE;
    15921619
    15931620                // x start: this word's X coordinate
     
    16211648                                        &ptlStart,
    16221649                                        &rclLine,
    1623                                         flOptions,
     1650                                        flChar,
    16241651                                        pWordThis->cChars,
    16251652                                        (PSZ)pWordThis->pStart);
     
    17491776    }
    17501777
    1751     return (pWordNodeFound);
     1778    return pWordNodeFound;
    17521779}
    17531780
     
    18021829    }
    18031830
    1804     return (pNodeFound);
     1831    return pNodeFound;
    18051832}
    18061833
     
    18101837 *
    18111838 ********************************************************************/
     1839
     1840#define QWL_PRIVATE     4               // V0.9.20 (2002-08-10) [umoeller]
    18121841
    18131842/*
    18141843 *@@ TEXTVIEWWINDATA:
    18151844 *      view control-internal structure, stored in
    1816  *      QWL_USER at fnwpTextView.
     1845 *      QWL_PRIVATE at fnwpTextView.
    18171846 *      This is device-dependent on the text view
    18181847 *      window.
     
    18261855    HPS     hps;
    18271856
     1857    ULONG   flStyle;            // window style flags copied on WM_CREATE
     1858                                // V0.9.20 (2002-08-10) [umoeller]
     1859
    18281860    LONG    lBackColor,
    18291861            lForeColor;
     
    18401872
    18411873    RECTL   rclViewReal,        // window rect as returned by WinQueryWindowRect
    1842                                 // (top right point is inclusive!!)
     1874                                // (top right point is inclusive!)
    18431875            rclViewPaint,       // same as rclViewReal, but excluding scroll bars
    18441876            rclViewText;        // same as rclViewPaint, but excluding cdata borders
     
    18511883    // anchor clicking
    18521884    PLISTNODE   pWordNodeFirstInAnchor;  // points to first word which belongs to anchor
    1853     USHORT      usLastAnchorClicked;    // last anchor which was clicked (1-0xFFFF)
     1885    // USHORT      usLastAnchorClicked;    // last anchor which was clicked (1-0xFFFF)
     1886    PSZ         pszLastLinkClicked;     // last link that was clicked (points into llLinks)
     1887
    18541888} TEXTVIEWWINDATA, *PTEXTVIEWWINDATA;
    18551889
     
    19531987    // if either the vertical or horizontal scroll bar has
    19541988    // popped up or been hidden
    1955     if (ptxvd->cdata.flStyle & XTXF_VSCROLL)
     1989    if (ptxvd->flStyle & XS_VSCROLL)
    19561990    {
    19571991        // vertical scroll bar enabled:
     
    19682002    }
    19692003
    1970     if (ptxvd->cdata.flStyle & XTXF_HSCROLL)
     2004    if (ptxvd->flStyle & XS_HSCROLL)
    19712005    {
    19722006        ulOfs = 0;
     
    20112045    if (ptxvd->ulViewYOfs < 0)
    20122046        ptxvd->ulViewYOfs = 0;
    2013     if (ptxvd->ulViewYOfs > ((LONG)ptxvd->xfd.ulViewportCY - ulWinCY))
    2014         ptxvd->ulViewYOfs = (LONG)ptxvd->xfd.ulViewportCY - ulWinCY;
     2047    if (ptxvd->ulViewYOfs > ((LONG)ptxvd->xfd.szlWorkspace.cy - ulWinCY))
     2048        ptxvd->ulViewYOfs = (LONG)ptxvd->xfd.szlWorkspace.cy - ulWinCY;
    20152049
    20162050    // vertical scroll bar enabled at all?
    2017     if (ptxvd->cdata.flStyle & XTXF_VSCROLL)
     2051    if (ptxvd->flStyle & XS_VSCROLL)
    20182052    {
    20192053        BOOL fEnabled = winhUpdateScrollBar(ptxvd->hwndVScroll,
    20202054                                            ulWinCY,
    2021                                             ptxvd->xfd.ulViewportCY,
     2055                                            ptxvd->xfd.szlWorkspace.cy,
    20222056                                            ptxvd->ulViewYOfs,
    2023                                             (ptxvd->cdata.flStyle & XTXF_AUTOVHIDE));
     2057                                            (ptxvd->flStyle & XS_AUTOVHIDE));
    20242058        // is auto-hide on?
    2025         if (ptxvd->cdata.flStyle & XTXF_AUTOVHIDE)
     2059        if (ptxvd->flStyle & XS_AUTOVHIDE)
    20262060        {
    20272061            // yes, auto-hide on: did visibility change?
     
    20462080
    20472081    // horizontal scroll bar enabled at all?
    2048     if (ptxvd->cdata.flStyle & XTXF_HSCROLL)
     2082    if (ptxvd->flStyle & XS_HSCROLL)
    20492083    {
    20502084        BOOL fEnabled = winhUpdateScrollBar(ptxvd->hwndHScroll,
    20512085                                            ulWinCX,
    2052                                             ptxvd->xfd.ulViewportCX,
     2086                                            ptxvd->xfd.szlWorkspace.cx,
    20532087                                            ptxvd->ulViewXOfs,
    2054                                             (ptxvd->cdata.flStyle & XTXF_AUTOHHIDE));
     2088                                            (ptxvd->flStyle & XS_AUTOHHIDE));
    20552089        // is auto-hide on?
    2056         if (ptxvd->cdata.flStyle & XTXF_AUTOHHIDE)
     2090        if (ptxvd->flStyle & XS_AUTOHHIDE)
    20572091        {
    20582092            // yes, auto-hide on: did visibility change?
     
    20712105
    20722106    WinInvalidateRect(hwndTextView, NULL, FALSE);
     2107}
     2108
     2109/*
     2110 *@@ SetWindowText:
     2111 *      implementation for WM_SETWINDOWPARAMS and
     2112 *      also WM_CREATE to set the window text.
     2113 *
     2114 *@@added V0.9.20 (2002-08-10) [umoeller]
     2115 */
     2116
     2117VOID SetWindowText(HWND hwndTextView,
     2118                   PTEXTVIEWWINDATA ptxvd,
     2119                   PCSZ pcszText)
     2120{
     2121    if (pcszText && *pcszText)
     2122    {
     2123        PXSTRING pstr = &ptxvd->xfd.strViewText;
     2124        PSZ p;
     2125
     2126        switch (ptxvd->flStyle & XS_FORMAT_MASK)
     2127        {
     2128            case XS_PLAINTEXT:          // 0x0100
     2129                xstrcpy(pstr,
     2130                        pcszText,
     2131                        0);
     2132                xstrConvertLineFormat(pstr,
     2133                                      CRLF2LF);
     2134                p = pstr->psz;
     2135                while (p = strchr(p, '\xFF'))
     2136                    *p = ' ';
     2137            break;
     2138
     2139            case XS_HTML:               // 0x0200
     2140                if (p = strdup(pcszText))
     2141                {
     2142                    PSZ p2 = p;
     2143                    while (p2 = strchr(p2, '\xFF'))
     2144                        *p2 = ' ';
     2145                    txvConvertFromHTML(&p, NULL, NULL, NULL);
     2146                    xstrset(pstr, p);
     2147                    xstrConvertLineFormat(pstr,
     2148                                          CRLF2LF);
     2149                }
     2150            break;
     2151
     2152            default: // case XS_PREFORMATTED:       // 0x0000
     2153                // no conversion (default)
     2154                xstrcpy(pstr,
     2155                        pcszText,
     2156                        0);
     2157            break;
     2158        }
     2159
     2160        // if the last character of the window text is not "\n",
     2161        // add it explicitly here, or our lines processing
     2162        // is being funny
     2163        // V0.9.20 (2002-08-10) [umoeller]
     2164        if (pstr->psz[pstr->ulLength - 1] != '\n')
     2165            xstrcatc(pstr, '\n');
     2166
     2167        ptxvd->ulViewXOfs = 0;
     2168        ptxvd->ulViewYOfs = 0;
     2169        AdjustViewRects(hwndTextView,
     2170                        ptxvd);
     2171        FormatText2Screen(hwndTextView,
     2172                          ptxvd,
     2173                          FALSE,
     2174                          TRUE);        // full format
     2175    }
    20732176}
    20742177
     
    21362239{
    21372240    POINTL ptlStart;
    2138     ULONG flOptions = pWordThis->flOptions;
     2241    ULONG flChar = pWordThis->flChar;
    21392242    PTXVRECTANGLE pLineRcl = pWordThis->pRectangle;
    21402243
     
    21452248    rclLine.yTop = pLineRcl->rcl.yTop + ptxvd->ulViewYOfs;
    21462249
    2147     if (pWordThis->usAnchor)
    2148         flOptions |= CHS_UNDERSCORE;
     2250    if (pWordThis->pszLinkTarget)
     2251        flChar |= CHS_UNDERSCORE;
    21492252
    21502253    // x start: this word's X coordinate
     
    21642267
    21652268    if (!pWordThis->cEscapeCode)
     2269    {
    21662270        gpihCharStringPosAt(ptxvd->hps,
    21672271                            &ptlStart,
    21682272                            &rclLine,
    2169                             flOptions,
     2273                            flChar,
    21702274                            pWordThis->cChars,
    21712275                            (PSZ)pWordThis->pStart);
     2276    }
    21722277    else
    21732278        // escape to be painted:
     
    21882293{
    21892294    PLISTNODE pNode = ptxvd->pWordNodeFirstInAnchor;
    2190     USHORT usAnchor = 0;
     2295    PSZ     pszLinkTarget = NULL;
    21912296    while (pNode)
    21922297    {
    21932298        PTXVWORD pWordThis = (PTXVWORD)pNode->pItemData;
    2194         if (usAnchor == 0)
     2299        if (!pszLinkTarget)
    21952300            // first loop:
    2196             usAnchor = pWordThis->usAnchor;
     2301            pszLinkTarget = pWordThis->pszLinkTarget;
    21972302        else
    2198             if (pWordThis->usAnchor != usAnchor)
     2303            if (pWordThis->pszLinkTarget != pszLinkTarget)
    21992304                // first word with different anchor:
    22002305                break;
     
    22112316 *      window procedure for the text view control. This is
    22122317 *      registered with the WC_XTEXTVIEW class in txvRegisterTextView.
    2213  *      We have a TEXTVIEWWINDATA structure in QWL_USER where we
    2214  *      store all information we need.
    22152318 *
    22162319 *      The text view control is not a subclassed whatever control,
     
    22362339 *
    22372340 *      -- WM_CHAR: if we have the focus, the user can move the
    2238  *         visible part within the viewport using the usual
     2341 *         visible part within the workspace using the usual
    22392342 *         cursor and HOME/END keys.
    22402343 *
     
    22512354 *      should be speedier.
    22522355 *
     2356 *      The text view control uses a private window word for storing
     2357 *      its own data. The client is free to use QWL_USER of the
     2358 *      text view control.
     2359 *
    22532360 *@@changed V0.9.3 (2000-05-05) [umoeller]: removed TXM_NEWTEXT; now supporting WinSetWindowText
    22542361 *@@changed V0.9.3 (2000-05-07) [umoeller]: crashed if create param was NULL; fixed
     2362 *@@changed V0.9.20 (2002-08-10) [umoeller]: no longer using QWL_USER, which is free now
     2363 *@@changed V0.9.20 (2002-08-10) [umoeller]: setting text on window creation never worked, fixed
     2364 *@@changed V0.9.20 (2002-08-10) [umoeller]: added TXN_ANCHORCLICKED owner notify for anchors
     2365 *@@changed V0.9.20 (2002-08-10) [umoeller]: converted private style flags to XS_* window style flags
     2366 *@@changed V0.9.20 (2002-08-10) [umoeller]: added support for formatting HTML and plain text automatically
    22552367 */
    22562368
     
    22592371    MRESULT mrc = 0;
    22602372
    2261     PTEXTVIEWWINDATA ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_USER);
     2373    PTEXTVIEWWINDATA ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE);
    22622374
    22632375    switch (msg)
     
    22772389            mrc = (MPARAM)TRUE;     // error
    22782390
    2279             // allocate TEXTVIEWWINDATA for QWL_USER
     2391            // allocate TEXTVIEWWINDATA for QWL_PRIVATE
    22802392            if (ptxvd = (PTEXTVIEWWINDATA)malloc(sizeof(TEXTVIEWWINDATA)))
    22812393            {
    22822394                SIZEL   szlPage = {0, 0};
    22832395                BOOL    fShow = FALSE;
    2284                 // LONG    lcid = 0;
    22852396
    22862397                // query message queue
     
    22902401
    22912402                memset(ptxvd, 0, sizeof(TEXTVIEWWINDATA));
    2292                 WinSetWindowPtr(hwndTextView, QWL_USER, ptxvd);
     2403                WinSetWindowPtr(hwndTextView, QWL_PRIVATE, ptxvd);
    22932404
    22942405                ptxvd->hab = WinQueryAnchorBlock(hwndTextView);
     
    22992410                                         &szlPage, // use same page size as device
    23002411                                         PU_PELS | GPIT_MICRO | GPIA_ASSOC);
     2412
     2413                // copy window style flags V0.9.20 (2002-08-10) [umoeller]
     2414                ptxvd->flStyle = pcs->flStyle;
    23012415
    23022416                gpihSwitchToRGB(ptxvd->hps);
     
    23452459                                                     &sbcd,
    23462460                                                     0);
    2347                 fShow = ((ptxvd->cdata.flStyle & XTXF_VSCROLL) != 0);
     2461                fShow = ((ptxvd->flStyle & XS_VSCROLL) != 0);
    23482462                WinShowWindow(ptxvd->hwndVScroll, fShow);
    23492463                ptxvd->fVScrollVisible = fShow;
     
    23602474                                                     &sbcd,
    23612475                                                     0);
    2362                 fShow = ((ptxvd->cdata.flStyle & XTXF_HSCROLL) != 0);
     2476                fShow = ((ptxvd->flStyle & XS_HSCROLL) != 0);
    23632477                WinShowWindow(ptxvd->hwndHScroll, fShow);
    23642478                ptxvd->fHScrollVisible = fShow;
    23652479
     2480                if (ptxvd->flStyle & XS_WORDWRAP)
     2481                    // word-wrapping should be enabled from the start:
     2482                    // V0.9.20 (2002-08-10) [umoeller]
     2483                    ptxvd->xfd.fmtpStandard.fWordWrap = TRUE;
     2484
    23662485                // set "code" format
    23672486                SetFormatFont(ptxvd->hps,
    2368                                  &ptxvd->xfd.fmtcCode,
    2369                                  6,
    2370                                  "System VIO");
     2487                              &ptxvd->xfd.fmtcCode,
     2488                              6,
     2489                              "System VIO");
    23712490
    23722491                // get colors from presparams/syscolors
     
    23752494                AdjustViewRects(hwndTextView,
    23762495                                ptxvd);
     2496
     2497                if (ptxvd->flStyle & XS_HTML)
     2498                {
     2499                    // if we're operating in HTML mode, set a
     2500                    // different default paragraph format to
     2501                    // make things prettier
     2502                    // V0.9.20 (2002-08-10) [umoeller]
     2503                    ptxvd->xfd.fmtpStandard.lSpaceBefore = 5;
     2504                    ptxvd->xfd.fmtpStandard.lSpaceAfter = 5;
     2505                }
     2506
     2507                // setting the window text on window creation never
     2508                // worked V0.9.20 (2002-08-10) [umoeller]
     2509                if (pcs->pszText)
     2510                    SetWindowText(hwndTextView,
     2511                                  ptxvd,
     2512                                  pcs->pszText);
    23772513
    23782514                mrc = (MPARAM)FALSE;        // OK
     
    23922528        {
    23932529            WNDPARAMS *pwndParams;
    2394             if (pwndParams = (WNDPARAMS *)mp1)
     2530            if (    (pwndParams = (WNDPARAMS *)mp1)
     2531                 && (pwndParams->fsStatus & WPM_TEXT)
     2532               )
    23952533            {
    2396                 if (pwndParams->fsStatus & WPM_TEXT)
    2397                 {
    2398                     xstrcpy(&ptxvd->xfd.strViewText,
    2399                             pwndParams->pszText,
    2400                             0);
    2401                     ptxvd->ulViewXOfs = 0;
    2402                     ptxvd->ulViewYOfs = 0;
    2403                     /* ptxvd->fVScrollVisible = FALSE;
    2404                     ptxvd->fHScrollVisible = FALSE; */
    2405                     AdjustViewRects(hwndTextView,
    2406                                     ptxvd);
    2407                     FormatText2Screen(hwndTextView,
    2408                                       ptxvd,
    2409                                       FALSE,
    2410                                       TRUE);        // full format
    2411                 }
     2534                SetWindowText(hwndTextView,
     2535                              ptxvd,
     2536                              pwndParams->pszText);
     2537                mrc = (MRESULT)TRUE;     // was missing V0.9.20 (2002-08-10) [umoeller]
    24122538            }
    24132539        }
     
    24852611                // (in between scroll bars) if we have
    24862612                // both vertical and horizontal scroll bars
    2487                 if (    (ptxvd->cdata.flStyle & (XTXF_VSCROLL | XTXF_HSCROLL))
    2488                         == (XTXF_VSCROLL | XTXF_HSCROLL)
     2613                if (    (ptxvd->flStyle & (XS_VSCROLL | XS_HSCROLL))
     2614                        == (XS_VSCROLL | XS_HSCROLL)
    24892615                     && (ptxvd->fVScrollVisible)
    24902616                     && (ptxvd->fHScrollVisible)
     
    25232649                                     &rcl2Update);
    25242650
    2525                 if (WinQueryFocus(HWND_DESKTOP) == hwndTextView)
     2651                if (    (!(ptxvd->flStyle & XS_STATIC))
     2652                                // V0.9.20 (2002-08-10) [umoeller]
     2653                     && (WinQueryFocus(HWND_DESKTOP) == hwndTextView)
     2654                   )
    25262655                {
    25272656                    // we have the focus:
     
    25852714                                    &ptxvd->ulViewYOfs,
    25862715                                    &ptxvd->rclViewText,
    2587                                     ptxvd->xfd.ulViewportCY,
     2716                                    ptxvd->xfd.szlWorkspace.cy,
    25882717                                    ptxvd->cdata.ulVScrollLineUnit,
    25892718                                    msg,
     
    26042733                                    &ptxvd->ulViewXOfs,
    26052734                                    &ptxvd->rclViewText,
    2606                                     ptxvd->xfd.ulViewportCX,
     2735                                    ptxvd->xfd.szlWorkspace.cx,
    26072736                                    ptxvd->cdata.ulHScrollLineUnit,
    26082737                                    msg,
     
    26182747        case WM_SETFOCUS:
    26192748        {
    2620             HPS hps = WinGetPS(hwndTextView);
    2621             gpihSwitchToRGB(hps);
    2622             PaintViewFocus(hps,
    2623                            ptxvd,
    2624                            (mp2 != 0));
    2625             WinReleasePS(hps);
     2749            if (ptxvd->flStyle & XS_STATIC)
     2750            {
     2751                if (mp2)
     2752                {
     2753                    // we're receiving the focus, but shouldn't have it:
     2754                    // then behave like the static control does, that is,
     2755                    // give focus to the next window in the dialog
     2756                    HWND    hwnd = hwndTextView,
     2757                            hwndStart = hwnd;
     2758
     2759                    while (TRUE)
     2760                    {
     2761                        ULONG flStyle;
     2762
     2763                        if (!(hwnd = WinQueryWindow(hwnd, QW_NEXT)))
     2764                            hwnd = WinQueryWindow(WinQueryWindow(hwndStart, QW_PARENT), QW_TOP);
     2765
     2766                        // avoid endless looping
     2767                        if (hwnd == hwndStart)
     2768                        {
     2769                            if (    (hwnd = WinQueryWindow(hwnd, QW_OWNER))
     2770                                 && (hwnd == hwndStart)
     2771                               )
     2772                                hwnd = NULLHANDLE;
     2773
     2774                            break;
     2775                        }
     2776
     2777                        if (    (flStyle = WinQueryWindowULong(hwnd, QWL_STYLE))
     2778                             && (flStyle & (WS_DISABLED | WS_TABSTOP | WS_VISIBLE)
     2779                                    == (WS_TABSTOP | WS_VISIBLE))
     2780                           )
     2781                        {
     2782                            WinSetFocus(HWND_DESKTOP, hwnd);
     2783                            break;
     2784                        }
     2785                    };
     2786                }
     2787            }
     2788            else
     2789            {
     2790                HPS hps = WinGetPS(hwndTextView);
     2791                gpihSwitchToRGB(hps);
     2792                PaintViewFocus(hps,
     2793                               ptxvd,
     2794                               (mp2 != 0));
     2795                WinReleasePS(hps);
     2796            }
    26262797        }
    26272798        break;
     
    26632834            ptlPos.y = SHORT2FROMMP(mp1) - ptxvd->ulViewYOfs;
    26642835
    2665             if (hwndTextView != WinQueryFocus(HWND_DESKTOP))
     2836            if (    (!(ptxvd->flStyle & XS_STATIC))
     2837                            // V0.9.20 (2002-08-10) [umoeller]
     2838                 && (hwndTextView != WinQueryFocus(HWND_DESKTOP))
     2839               )
    26662840                WinSetFocus(HWND_DESKTOP, hwndTextView);
    26672841
    2668             ptxvd->usLastAnchorClicked = 0;
     2842            ptxvd->pszLastLinkClicked = NULL;
    26692843
    26702844            if (pWordNodeClicked = txvFindWordFromPoint(&ptxvd->xfd,
     
    26732847                PTXVWORD pWordClicked = (PTXVWORD)pWordNodeClicked->pItemData;
    26742848
    2675                 // store anchor (can be 0)
    2676                 ptxvd->usLastAnchorClicked = pWordClicked->usAnchor;
    2677 
    2678                 if (pWordClicked->usAnchor)
     2849                // store link target (can be NULL)
     2850                if (ptxvd->pszLastLinkClicked = pWordClicked->pszLinkTarget)
    26792851                {
    2680                     // word has an anchor:
     2852                    // word has a link target:
    26812853                    PLISTNODE   pNode = pWordNodeClicked;
    26822854
     
    26892861                    {
    26902862                        PTXVWORD pWordThis = (PTXVWORD)pNode->pItemData;
    2691                         if (pWordThis->usAnchor == pWordClicked->usAnchor)
     2863                        if (pWordThis->pszLinkTarget == pWordClicked->pszLinkTarget)
    26922864                        {
    26932865                            // still has same anchor:
     
    27272899            WinSetCapture(HWND_DESKTOP, NULLHANDLE);
    27282900
    2729             if (ptxvd->usLastAnchorClicked)
     2901            if (ptxvd->pszLastLinkClicked)
    27302902            {
    27312903                RepaintAnchor(ptxvd,
     
    27392911                                                                 QWS_ID),
    27402912                                            TXVN_LINK),
    2741                                (MPARAM)(ULONG)(ptxvd->usLastAnchorClicked));
     2913                               (MPARAM)(ULONG)(ptxvd->pszLastLinkClicked));
    27422914            }
    27432915
     
    28032975                        if (usFlags & KC_CTRL)
    28042976                        {
    2805                             sPos = ptxvd->xfd.ulViewportCY;
     2977                            sPos = ptxvd->xfd.szlWorkspace.cy;
    28062978                            usCmd = SB_SLIDERPOSITION;
    28072979                        }
     
    28262998                            // vertical:
    28272999                            ulMsg = WM_VSCROLL;
    2828                             sPos = ptxvd->xfd.ulViewportCY;
     3000                            sPos = ptxvd->xfd.szlWorkspace.cy;
    28293001                        }
    28303002                        else
    28313003                        {
    28323004                            ulMsg = WM_HSCROLL;
    2833                             sPos = ptxvd->xfd.ulViewportCX;
     3005                            sPos = ptxvd->xfd.szlWorkspace.cx;
    28343006                        }
    28353007
     
    28663038         *      index specified in mp1.
    28673039         *
     3040         *      This must be sent, not posted, to the control.
     3041         *
    28683042         *      Parameters:
     3043         *
    28693044         *      -- ULONG mp1: index of format to query.
    28703045         *              Must be 0 currently for the standard
    28713046         *              paragraph format.
     3047         *
    28723048         *      -- PXFMTPARAGRAPH mp2: pointer to buffer
    28733049         *              which is to receive the formatting
     
    29043080         *      and such).
    29053081         *
     3082         *      This must be sent, not posted, to the control.
     3083         *
    29063084         *      Parameters:
     3085         *
    29073086         *      -- ULONG mp1: index of format to set.
    29083087         *              Must be 0 currently for the standard
    29093088         *              paragraph format.
     3089         *
    29103090         *      -- PXFMTPARAGRAPH mp2: pointer to buffer
    29113091         *              from which to copy formatting data.
     
    29533133         *      the word-wrapping style of the default
    29543134         *      paragraph formatting.
     3135         *
     3136         *      This may be sent or posted.
     3137         *
    29553138         *      (BOOL)mp1 determines whether word wrapping
    29563139         *      should be turned on or off.
     
    29723155         *@@ TXM_QUERYCDATA:
    29733156         *      copies the current XTEXTVIEWCDATA
    2974          *      into the specified buffer. This must
    2975          *      be sent to the control.
     3157         *      into the specified buffer.
     3158         *
     3159         *      This must be sent, not posted, to the control.
    29763160         *
    29773161         *      Parameters:
    2978          *      -- PXTEXTVIEWCDATA mp1: target buffer.
    2979          *         Before calling this, you MUST specify
    2980          *         XTEXTVIEWCDATA.cbData.
     3162         *
     3163         *      --  PXTEXTVIEWCDATA mp1: target buffer.
     3164         *          Before calling this, you MUST specify
     3165         *          XTEXTVIEWCDATA.cbData.
     3166         *
     3167         *      Returns: the bytes that were copied as
     3168         *      a ULONG.
    29813169         */
    29823170
     
    29853173            {
    29863174                PXTEXTVIEWCDATA pTarget = (PXTEXTVIEWCDATA)mp1;
    2987                 memcpy(pTarget, &ptxvd->cdata, pTarget->cbData);
     3175                mrc = (MRESULT)min(pTarget->cbData, sizeof(XTEXTVIEWCDATA));
     3176                memcpy(pTarget,
     3177                       &ptxvd->cdata,
     3178                       (ULONG)mrc);
    29883179            }
    29893180        break;
     
    29933184         *      updates the current XTEXTVIEWCDATA
    29943185         *      with the data from the specified buffer.
    2995          *      This must be sent to the control.
     3186         *
     3187         *      This must be sent, not posted, to the control.
    29963188         *
    29973189         *      Parameters:
     
    30163208         *      of the control.
    30173209         *
    3018          *      This must be sent, not posted to the control
     3210         *      This must be sent, not posted, to the control.
    30193211         *
    30203212         *      Parameters:
     
    30463238                        if (ptxvd->ulViewYOfs < 0)
    30473239                            ptxvd->ulViewYOfs = 0;
    3048                         if (ptxvd->ulViewYOfs > ((LONG)ptxvd->xfd.ulViewportCY - ulWinCY))
    3049                             ptxvd->ulViewYOfs = (LONG)ptxvd->xfd.ulViewportCY - ulWinCY;
     3240                        if (ptxvd->ulViewYOfs > ((LONG)ptxvd->xfd.szlWorkspace.cy - ulWinCY))
     3241                            ptxvd->ulViewYOfs = (LONG)ptxvd->xfd.szlWorkspace.cy - ulWinCY;
    30503242
    30513243                        // vertical scroll bar enabled at all?
    3052                         if (ptxvd->cdata.flStyle & XTXF_VSCROLL)
     3244                        if (ptxvd->flStyle & XS_VSCROLL)
    30533245                        {
    30543246                            /* BOOL fEnabled = */ winhUpdateScrollBar(ptxvd->hwndVScroll,
    30553247                                                                ulWinCY,
    3056                                                                 ptxvd->xfd.ulViewportCY,
     3248                                                                ptxvd->xfd.szlWorkspace.cy,
    30573249                                                                ptxvd->ulViewYOfs,
    3058                                                                 (ptxvd->cdata.flStyle & XTXF_AUTOVHIDE));
     3250                                                                (ptxvd->flStyle & XS_AUTOVHIDE));
    30593251                            WinInvalidateRect(hwndTextView, NULL, FALSE);
    30603252                        }
    30613253                    }
    30623254                }
     3255            }
     3256        break;
     3257
     3258        /*
     3259         *@@ TXM_QUERYTEXTEXTENT:
     3260         *      returns the extents of the currently set text,
     3261         *      that is, the width and height of the internal
     3262         *      work area, of which the current view rectangle
     3263         *      displays a subrectangle.
     3264         *
     3265         *      This must be sent, not posted, to the control.
     3266         *
     3267         *      Parameters:
     3268         *
     3269         *      --  PSIZEL mp1: pointer to a SIZEL buffer,
     3270         *          which receives the extent in the cx and
     3271         *          cy members. These will be set to null
     3272         *          values if the control currently has no
     3273         *          text.
     3274         *
     3275         *      Returns TRUE on success.
     3276         *
     3277         *@@added V0.9.20 (2002-08-10) [umoeller]
     3278         */
     3279
     3280        case TXM_QUERYTEXTEXTENT:
     3281            if (mp1)
     3282            {
     3283                memcpy((PSIZEL)mp1,
     3284                       &ptxvd->xfd.szlWorkspace,
     3285                       sizeof(SIZEL));
     3286                mrc = (MRESULT)TRUE;
    30633287            }
    30643288        break;
     
    30933317BOOL txvRegisterTextView(HAB hab)
    30943318{
    3095     return (WinRegisterClass(hab,
    3096                              WC_XTEXTVIEW,
    3097                              fnwpTextView,
    3098                              0,
    3099                              sizeof(PVOID)));     // QWL_USER
     3319    return WinRegisterClass(hab,
     3320                            WC_XTEXTVIEW,
     3321                            fnwpTextView,
     3322                            0,
     3323                            2 * sizeof(PVOID));     // QWL_USER and QWL_PRIVATE
    31003324}
    31013325
     
    31113335                            USHORT usID,
    31123336                            ULONG flWinStyle,
    3113                             ULONG flStyle,
    31143337                            USHORT usBorder)
    31153338{
     
    31503373        memset(&xtxCData, 0, sizeof(xtxCData));
    31513374        xtxCData.cbData = sizeof(xtxCData);
    3152         xtxCData.flStyle = flStyle;
    31533375        xtxCData.ulXBorder = usBorder;
    31543376        xtxCData.ulYBorder = usBorder;
     
    31833405                            &lForeClr);
    31843406    }
    3185     return (hwndTextView);
     3407    return hwndTextView;
    31863408}
    31873409
     
    32403462    }
    32413463
    3242     return (pprq3);
     3464    return pprq3;
    32433465}
    32443466
     
    33013523                     palRes);   // buffer
    33023524
    3303     return (hdc);
     3525    return hdc;
    33043526}
    33053527
     
    33343556    }
    33353557
    3336     return (pahci);
     3558    return pahci;
    33373559}
    33383560
     
    33623584    sizel.cx = 0;
    33633585    sizel.cy = 0;
    3364     return (GpiCreatePS(hab,
    3365                         hdc,
    3366                         &sizel,
    3367                         ulUnits | GPIA_ASSOC | GPIT_NORMAL));
     3586    return GpiCreatePS(hab,
     3587                       hdc,
     3588                       &sizel,
     3589                       ulUnits | GPIA_ASSOC | GPIT_NORMAL);
    33683590}
    33693591
     
    35293751    prthEndDoc(hdc, hps);
    35303752
    3531     return (TRUE);
     3753    return TRUE;
    35323754}
    35333755
     
    35493771    int     irc = 0;
    35503772
    3551     PTEXTVIEWWINDATA ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_USER);
     3773    PTEXTVIEWWINDATA ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE);
    35523774
    35533775    if (!ptxvd)
     
    36463868    }
    36473869
    3648     return (irc);
     3870    return irc;
    36493871}
    36503872
Note: See TracChangeset for help on using the changeset viewer.