Changeset 201 for trunk/src/helpers/textview.c
- Timestamp:
- Aug 11, 2002, 7:07:59 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/textview.c
r167 r201 243 243 244 244 #include "helpers\textview.h" 245 #include "helpers\textv_html.h" 245 246 246 247 #pragma hdrstop … … 418 419 * 419 420 *@@added V0.9.3 (2000-05-07) [umoeller] 421 *@@changed V0.9.20 (2002-08-10) [umoeller]: now stripping \xFF too 420 422 */ 421 423 … … 423 425 ULONG ulTabSize) 424 426 { 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; 429 432 430 433 while (*pSource) 431 434 { 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] 440 455 AppendCharNoCheck(&pszNew, 441 456 &cbNew, 442 457 &pTarget, 443 458 ' '); 444 445 // skip the tab 446 pSource++; 459 pSource++; 460 break; 461 462 default: 463 AppendCharNoCheck(&pszNew, 464 &cbNew, 465 &pTarget, 466 *pSource++); 447 467 } 448 else449 AppendCharNoCheck(&pszNew,450 &cbNew,451 &pTarget,452 *pSource++);453 468 } 469 454 470 AppendCharNoCheck(&pszNew, 455 471 &cbNew, … … 542 558 // of the next line or points to the \0 character 543 559 544 return (prc);560 return prc; 545 561 } 546 562 … … 551 567 #define TXVFRECTF_ENDOFTEXT 0x0010 552 568 */ 569 553 570 /* 554 571 *@@ FORMATLINEBUF: … … 577 594 578 595 // 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) 581 600 582 601 // data copied to TXVWORD 583 602 LONG lcid; 584 603 LONG lPointSize; 585 ULONG fl Options;// any combination of CHS_UNDERSCORE and CHS_STRIKEOUT604 ULONG flChar; // any combination of CHS_UNDERSCORE and CHS_STRIKEOUT 586 605 587 606 // counters, ... … … 611 630 * 612 631 *@@added V0.9.3 (2000-05-14) [umoeller] 632 *@@changed V0.9.20 (2002-08-10) [umoeller]: rewrote link implementation 613 633 */ 614 634 … … 709 729 pWord->lcid = pflbuf->pfmtf->lcid; 710 730 pWord->lPointSize = pflbuf->lPointSize; 711 pWord->fl Options = pflbuf->flOptions;712 713 pWord-> usAnchor = pflbuf->usCurrentAnchor; // 0 if none731 pWord->flChar = pflbuf->flChar; 732 733 pWord->pszLinkTarget = pflbuf->pszCurrentLink; // 0 if none 714 734 } 715 735 716 return (pWord);736 return pWord; 717 737 } 718 738 … … 756 776 // an escape character was found; txvCreateRectangle 757 777 // 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); 760 780 ULONG ulSkip = 3; // per default, skip \xFF plus two 761 781 CHAR szDecimal[10]; … … 769 789 case 1: // change font: 770 790 // three decimals follow specifying the font 771 memcpy(szDecimal, (*ppCurrent) +2, 3);791 memcpy(szDecimal, (*ppCurrent) + 2, 3); 772 792 szDecimal[3] = 0; 773 793 lDecimal = atoi(szDecimal); … … 795 815 case 4: // U or /U 796 816 if (cCode2 == 1) 797 pflbuf->fl Options|= CHS_UNDERSCORE;817 pflbuf->flChar |= CHS_UNDERSCORE; 798 818 else 799 pflbuf->fl Options&= ~CHS_UNDERSCORE;819 pflbuf->flChar &= ~CHS_UNDERSCORE; 800 820 break; 801 821 802 822 case 5: // STRIKE or /STRIKE 803 823 if (cCode2 == 1) 804 pflbuf->fl Options|= CHS_STRIKEOUT;824 pflbuf->flChar |= CHS_STRIKEOUT; 805 825 else 806 pflbuf->fl Options&= ~CHS_STRIKEOUT;826 pflbuf->flChar &= ~CHS_STRIKEOUT; 807 827 break; 808 828 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)) 817 838 { 818 PSZ pEnd;819 memcpy(szDecimal, (*ppCurrent)+2, 4);820 szDecimal[4] = 0; 821 l Decimal = 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); 823 844 } 824 825 ulSkip = 6; 845 } 826 846 break; 827 847 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) 829 854 { 830 855 // this is variable in length and terminated with … … 834 859 // searches the buffer 835 860 PSZ pEnd; 836 if (pEnd = strchr((*ppCurrent) +2, 0xFF))861 if (pEnd = strchr((*ppCurrent) + 2, 0xFF)) 837 862 { 838 863 ulSkip = pEnd - *ppCurrent + 1; … … 849 874 // three characters follow specifying the 850 875 // percentage 851 memcpy(szDecimal, (*ppCurrent) +2, 3);876 memcpy(szDecimal, (*ppCurrent) + 2, 3); 852 877 szDecimal[3] = 0; 853 878 lDecimal = atoi(szDecimal); … … 858 883 859 884 case 0x20: // left margin changed: 860 memcpy(szDecimal, (*ppCurrent) +2, 4); // four decimals xxxx885 memcpy(szDecimal, (*ppCurrent) + 2, 4); // four decimals xxxx 861 886 szDecimal[4] = 0; 862 887 lDecimal = atoi(szDecimal); … … 871 896 872 897 case 0x21: // first line margin changed: 873 memcpy(szDecimal, (*ppCurrent) +2, 4); // +xxx, -xxx898 memcpy(szDecimal, (*ppCurrent) + 2, 4); // +xxx, -xxx 874 899 szDecimal[4] = 0; 875 900 lDecimal = atoi(szDecimal); … … 899 924 case 0x30: // spacing before paragraph: 900 925 // four chars follow with either "####" or decimal spacing 901 memcpy(szDecimal, (*ppCurrent) +2, 4);926 memcpy(szDecimal, (*ppCurrent) + 2, 4); 902 927 szDecimal[4] = 0; 903 928 if (memcmp(szDecimal, "####", 4) == 0) … … 915 940 case 0x31: // spacing before paragraph: 916 941 // four chars follow with either "####" or decimal spacing 917 memcpy(szDecimal, (*ppCurrent) +2, 4);942 memcpy(szDecimal, (*ppCurrent) + 2, 4); 918 943 szDecimal[4] = 0; 919 944 if (memcmp(szDecimal, "####", 4) == 0) … … 949 974 pEscapeWord->cEscapeCode = *(*ppCurrent + 1); 950 975 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 952 979 if (fPaintEscapeWord) 953 980 { … … 955 982 pEscapeWord->lcid = pflbuf->pfmtf->lcid; 956 983 pEscapeWord->lPointSize = pflbuf->lPointSize; 957 pEscapeWord->fl Options = pflbuf->flOptions;984 pEscapeWord->flChar = pflbuf->flChar; 958 985 } 959 986 lstAppendItem(&pxfd->llWords, pEscapeWord); … … 965 992 *ppCurrent += ulSkip; 966 993 967 return (pEscapeWord);994 return pEscapeWord; 968 995 } 969 996 … … 1055 1082 * to paint rectangles. 1056 1083 * 1057 * -- XFORMATDATA. ulViewportCX, ulViewportCY: total width1058 * and height of the " viewport", i.e. the total space1084 * -- XFORMATDATA.szlWorkspace: total width 1085 * and height of the "workspace", i.e. the total space 1059 1086 * needed to display the text (in pels). This might 1060 1087 * be smaller, the same, or larger than prclView, … … 1062 1089 * 1063 1090 * When displaying text, you should display scroll bars 1064 * if the viewportis larger than the window (prclView).1065 * 1066 * When printing, if the viewportis larger than the1091 * if the workspace is larger than the window (prclView). 1092 * 1093 * When printing, if the workspace is larger than the 1067 1094 * printer page (prclView), you will need to call 1068 1095 * txvPaintText several times for each page. … … 1087 1114 lstClear(&pxfd->llWords); 1088 1115 1089 pxfd-> ulViewportCX= 0;1090 pxfd-> ulViewportCY= 0;1116 pxfd->szlWorkspace.cx = 0; 1117 pxfd->szlWorkspace.cy = 0; 1091 1118 1092 1119 if (pxfd->strViewText.cbAllocated) … … 1366 1393 1367 1394 // 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; 1370 1397 1371 1398 // and quit the inner loop … … 1392 1419 1393 1420 // 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; 1396 1423 } 1397 1424 } … … 1586 1613 { 1587 1614 PTXVWORD pWordThis = (PTXVWORD)pWordNode->pItemData; 1588 ULONG fl Options = pWordThis->flOptions;1589 1590 if (pWordThis-> usAnchor)1591 fl Options|= CHS_UNDERSCORE;1615 ULONG flChar = pWordThis->flChar; 1616 1617 if (pWordThis->pszLinkTarget) // V0.9.20 (2002-08-10) [umoeller] 1618 flChar |= CHS_UNDERSCORE; 1592 1619 1593 1620 // x start: this word's X coordinate … … 1621 1648 &ptlStart, 1622 1649 &rclLine, 1623 fl Options,1650 flChar, 1624 1651 pWordThis->cChars, 1625 1652 (PSZ)pWordThis->pStart); … … 1749 1776 } 1750 1777 1751 return (pWordNodeFound);1778 return pWordNodeFound; 1752 1779 } 1753 1780 … … 1802 1829 } 1803 1830 1804 return (pNodeFound);1831 return pNodeFound; 1805 1832 } 1806 1833 … … 1810 1837 * 1811 1838 ********************************************************************/ 1839 1840 #define QWL_PRIVATE 4 // V0.9.20 (2002-08-10) [umoeller] 1812 1841 1813 1842 /* 1814 1843 *@@ TEXTVIEWWINDATA: 1815 1844 * view control-internal structure, stored in 1816 * QWL_ USERat fnwpTextView.1845 * QWL_PRIVATE at fnwpTextView. 1817 1846 * This is device-dependent on the text view 1818 1847 * window. … … 1826 1855 HPS hps; 1827 1856 1857 ULONG flStyle; // window style flags copied on WM_CREATE 1858 // V0.9.20 (2002-08-10) [umoeller] 1859 1828 1860 LONG lBackColor, 1829 1861 lForeColor; … … 1840 1872 1841 1873 RECTL rclViewReal, // window rect as returned by WinQueryWindowRect 1842 // (top right point is inclusive! !)1874 // (top right point is inclusive!) 1843 1875 rclViewPaint, // same as rclViewReal, but excluding scroll bars 1844 1876 rclViewText; // same as rclViewPaint, but excluding cdata borders … … 1851 1883 // anchor clicking 1852 1884 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 1854 1888 } TEXTVIEWWINDATA, *PTEXTVIEWWINDATA; 1855 1889 … … 1953 1987 // if either the vertical or horizontal scroll bar has 1954 1988 // popped up or been hidden 1955 if (ptxvd-> cdata.flStyle & XTXF_VSCROLL)1989 if (ptxvd->flStyle & XS_VSCROLL) 1956 1990 { 1957 1991 // vertical scroll bar enabled: … … 1968 2002 } 1969 2003 1970 if (ptxvd-> cdata.flStyle & XTXF_HSCROLL)2004 if (ptxvd->flStyle & XS_HSCROLL) 1971 2005 { 1972 2006 ulOfs = 0; … … 2011 2045 if (ptxvd->ulViewYOfs < 0) 2012 2046 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; 2015 2049 2016 2050 // vertical scroll bar enabled at all? 2017 if (ptxvd-> cdata.flStyle & XTXF_VSCROLL)2051 if (ptxvd->flStyle & XS_VSCROLL) 2018 2052 { 2019 2053 BOOL fEnabled = winhUpdateScrollBar(ptxvd->hwndVScroll, 2020 2054 ulWinCY, 2021 ptxvd->xfd. ulViewportCY,2055 ptxvd->xfd.szlWorkspace.cy, 2022 2056 ptxvd->ulViewYOfs, 2023 (ptxvd-> cdata.flStyle & XTXF_AUTOVHIDE));2057 (ptxvd->flStyle & XS_AUTOVHIDE)); 2024 2058 // is auto-hide on? 2025 if (ptxvd-> cdata.flStyle & XTXF_AUTOVHIDE)2059 if (ptxvd->flStyle & XS_AUTOVHIDE) 2026 2060 { 2027 2061 // yes, auto-hide on: did visibility change? … … 2046 2080 2047 2081 // horizontal scroll bar enabled at all? 2048 if (ptxvd-> cdata.flStyle & XTXF_HSCROLL)2082 if (ptxvd->flStyle & XS_HSCROLL) 2049 2083 { 2050 2084 BOOL fEnabled = winhUpdateScrollBar(ptxvd->hwndHScroll, 2051 2085 ulWinCX, 2052 ptxvd->xfd. ulViewportCX,2086 ptxvd->xfd.szlWorkspace.cx, 2053 2087 ptxvd->ulViewXOfs, 2054 (ptxvd-> cdata.flStyle & XTXF_AUTOHHIDE));2088 (ptxvd->flStyle & XS_AUTOHHIDE)); 2055 2089 // is auto-hide on? 2056 if (ptxvd-> cdata.flStyle & XTXF_AUTOHHIDE)2090 if (ptxvd->flStyle & XS_AUTOHHIDE) 2057 2091 { 2058 2092 // yes, auto-hide on: did visibility change? … … 2071 2105 2072 2106 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 2117 VOID 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 } 2073 2176 } 2074 2177 … … 2136 2239 { 2137 2240 POINTL ptlStart; 2138 ULONG fl Options = pWordThis->flOptions;2241 ULONG flChar = pWordThis->flChar; 2139 2242 PTXVRECTANGLE pLineRcl = pWordThis->pRectangle; 2140 2243 … … 2145 2248 rclLine.yTop = pLineRcl->rcl.yTop + ptxvd->ulViewYOfs; 2146 2249 2147 if (pWordThis-> usAnchor)2148 fl Options|= CHS_UNDERSCORE;2250 if (pWordThis->pszLinkTarget) 2251 flChar |= CHS_UNDERSCORE; 2149 2252 2150 2253 // x start: this word's X coordinate … … 2164 2267 2165 2268 if (!pWordThis->cEscapeCode) 2269 { 2166 2270 gpihCharStringPosAt(ptxvd->hps, 2167 2271 &ptlStart, 2168 2272 &rclLine, 2169 fl Options,2273 flChar, 2170 2274 pWordThis->cChars, 2171 2275 (PSZ)pWordThis->pStart); 2276 } 2172 2277 else 2173 2278 // escape to be painted: … … 2188 2293 { 2189 2294 PLISTNODE pNode = ptxvd->pWordNodeFirstInAnchor; 2190 USHORT usAnchor = 0;2295 PSZ pszLinkTarget = NULL; 2191 2296 while (pNode) 2192 2297 { 2193 2298 PTXVWORD pWordThis = (PTXVWORD)pNode->pItemData; 2194 if ( usAnchor == 0)2299 if (!pszLinkTarget) 2195 2300 // first loop: 2196 usAnchor = pWordThis->usAnchor;2301 pszLinkTarget = pWordThis->pszLinkTarget; 2197 2302 else 2198 if (pWordThis-> usAnchor != usAnchor)2303 if (pWordThis->pszLinkTarget != pszLinkTarget) 2199 2304 // first word with different anchor: 2200 2305 break; … … 2211 2316 * window procedure for the text view control. This is 2212 2317 * registered with the WC_XTEXTVIEW class in txvRegisterTextView. 2213 * We have a TEXTVIEWWINDATA structure in QWL_USER where we2214 * store all information we need.2215 2318 * 2216 2319 * The text view control is not a subclassed whatever control, … … 2236 2339 * 2237 2340 * -- WM_CHAR: if we have the focus, the user can move the 2238 * visible part within the viewportusing the usual2341 * visible part within the workspace using the usual 2239 2342 * cursor and HOME/END keys. 2240 2343 * … … 2251 2354 * should be speedier. 2252 2355 * 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 * 2253 2360 *@@changed V0.9.3 (2000-05-05) [umoeller]: removed TXM_NEWTEXT; now supporting WinSetWindowText 2254 2361 *@@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 2255 2367 */ 2256 2368 … … 2259 2371 MRESULT mrc = 0; 2260 2372 2261 PTEXTVIEWWINDATA ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_ USER);2373 PTEXTVIEWWINDATA ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE); 2262 2374 2263 2375 switch (msg) … … 2277 2389 mrc = (MPARAM)TRUE; // error 2278 2390 2279 // allocate TEXTVIEWWINDATA for QWL_ USER2391 // allocate TEXTVIEWWINDATA for QWL_PRIVATE 2280 2392 if (ptxvd = (PTEXTVIEWWINDATA)malloc(sizeof(TEXTVIEWWINDATA))) 2281 2393 { 2282 2394 SIZEL szlPage = {0, 0}; 2283 2395 BOOL fShow = FALSE; 2284 // LONG lcid = 0;2285 2396 2286 2397 // query message queue … … 2290 2401 2291 2402 memset(ptxvd, 0, sizeof(TEXTVIEWWINDATA)); 2292 WinSetWindowPtr(hwndTextView, QWL_ USER, ptxvd);2403 WinSetWindowPtr(hwndTextView, QWL_PRIVATE, ptxvd); 2293 2404 2294 2405 ptxvd->hab = WinQueryAnchorBlock(hwndTextView); … … 2299 2410 &szlPage, // use same page size as device 2300 2411 PU_PELS | GPIT_MICRO | GPIA_ASSOC); 2412 2413 // copy window style flags V0.9.20 (2002-08-10) [umoeller] 2414 ptxvd->flStyle = pcs->flStyle; 2301 2415 2302 2416 gpihSwitchToRGB(ptxvd->hps); … … 2345 2459 &sbcd, 2346 2460 0); 2347 fShow = ((ptxvd-> cdata.flStyle & XTXF_VSCROLL) != 0);2461 fShow = ((ptxvd->flStyle & XS_VSCROLL) != 0); 2348 2462 WinShowWindow(ptxvd->hwndVScroll, fShow); 2349 2463 ptxvd->fVScrollVisible = fShow; … … 2360 2474 &sbcd, 2361 2475 0); 2362 fShow = ((ptxvd-> cdata.flStyle & XTXF_HSCROLL) != 0);2476 fShow = ((ptxvd->flStyle & XS_HSCROLL) != 0); 2363 2477 WinShowWindow(ptxvd->hwndHScroll, fShow); 2364 2478 ptxvd->fHScrollVisible = fShow; 2365 2479 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 2366 2485 // set "code" format 2367 2486 SetFormatFont(ptxvd->hps, 2368 2369 2370 2487 &ptxvd->xfd.fmtcCode, 2488 6, 2489 "System VIO"); 2371 2490 2372 2491 // get colors from presparams/syscolors … … 2375 2494 AdjustViewRects(hwndTextView, 2376 2495 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); 2377 2513 2378 2514 mrc = (MPARAM)FALSE; // OK … … 2392 2528 { 2393 2529 WNDPARAMS *pwndParams; 2394 if (pwndParams = (WNDPARAMS *)mp1) 2530 if ( (pwndParams = (WNDPARAMS *)mp1) 2531 && (pwndParams->fsStatus & WPM_TEXT) 2532 ) 2395 2533 { 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] 2412 2538 } 2413 2539 } … … 2485 2611 // (in between scroll bars) if we have 2486 2612 // both vertical and horizontal scroll bars 2487 if ( (ptxvd-> cdata.flStyle & (XTXF_VSCROLL | XTXF_HSCROLL))2488 == (X TXF_VSCROLL | XTXF_HSCROLL)2613 if ( (ptxvd->flStyle & (XS_VSCROLL | XS_HSCROLL)) 2614 == (XS_VSCROLL | XS_HSCROLL) 2489 2615 && (ptxvd->fVScrollVisible) 2490 2616 && (ptxvd->fHScrollVisible) … … 2523 2649 &rcl2Update); 2524 2650 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 ) 2526 2655 { 2527 2656 // we have the focus: … … 2585 2714 &ptxvd->ulViewYOfs, 2586 2715 &ptxvd->rclViewText, 2587 ptxvd->xfd. ulViewportCY,2716 ptxvd->xfd.szlWorkspace.cy, 2588 2717 ptxvd->cdata.ulVScrollLineUnit, 2589 2718 msg, … … 2604 2733 &ptxvd->ulViewXOfs, 2605 2734 &ptxvd->rclViewText, 2606 ptxvd->xfd. ulViewportCX,2735 ptxvd->xfd.szlWorkspace.cx, 2607 2736 ptxvd->cdata.ulHScrollLineUnit, 2608 2737 msg, … … 2618 2747 case WM_SETFOCUS: 2619 2748 { 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 } 2626 2797 } 2627 2798 break; … … 2663 2834 ptlPos.y = SHORT2FROMMP(mp1) - ptxvd->ulViewYOfs; 2664 2835 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 ) 2666 2840 WinSetFocus(HWND_DESKTOP, hwndTextView); 2667 2841 2668 ptxvd-> usLastAnchorClicked = 0;2842 ptxvd->pszLastLinkClicked = NULL; 2669 2843 2670 2844 if (pWordNodeClicked = txvFindWordFromPoint(&ptxvd->xfd, … … 2673 2847 PTXVWORD pWordClicked = (PTXVWORD)pWordNodeClicked->pItemData; 2674 2848 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) 2679 2851 { 2680 // word has a n anchor:2852 // word has a link target: 2681 2853 PLISTNODE pNode = pWordNodeClicked; 2682 2854 … … 2689 2861 { 2690 2862 PTXVWORD pWordThis = (PTXVWORD)pNode->pItemData; 2691 if (pWordThis-> usAnchor == pWordClicked->usAnchor)2863 if (pWordThis->pszLinkTarget == pWordClicked->pszLinkTarget) 2692 2864 { 2693 2865 // still has same anchor: … … 2727 2899 WinSetCapture(HWND_DESKTOP, NULLHANDLE); 2728 2900 2729 if (ptxvd-> usLastAnchorClicked)2901 if (ptxvd->pszLastLinkClicked) 2730 2902 { 2731 2903 RepaintAnchor(ptxvd, … … 2739 2911 QWS_ID), 2740 2912 TXVN_LINK), 2741 (MPARAM)(ULONG)(ptxvd-> usLastAnchorClicked));2913 (MPARAM)(ULONG)(ptxvd->pszLastLinkClicked)); 2742 2914 } 2743 2915 … … 2803 2975 if (usFlags & KC_CTRL) 2804 2976 { 2805 sPos = ptxvd->xfd. ulViewportCY;2977 sPos = ptxvd->xfd.szlWorkspace.cy; 2806 2978 usCmd = SB_SLIDERPOSITION; 2807 2979 } … … 2826 2998 // vertical: 2827 2999 ulMsg = WM_VSCROLL; 2828 sPos = ptxvd->xfd. ulViewportCY;3000 sPos = ptxvd->xfd.szlWorkspace.cy; 2829 3001 } 2830 3002 else 2831 3003 { 2832 3004 ulMsg = WM_HSCROLL; 2833 sPos = ptxvd->xfd. ulViewportCX;3005 sPos = ptxvd->xfd.szlWorkspace.cx; 2834 3006 } 2835 3007 … … 2866 3038 * index specified in mp1. 2867 3039 * 3040 * This must be sent, not posted, to the control. 3041 * 2868 3042 * Parameters: 3043 * 2869 3044 * -- ULONG mp1: index of format to query. 2870 3045 * Must be 0 currently for the standard 2871 3046 * paragraph format. 3047 * 2872 3048 * -- PXFMTPARAGRAPH mp2: pointer to buffer 2873 3049 * which is to receive the formatting … … 2904 3080 * and such). 2905 3081 * 3082 * This must be sent, not posted, to the control. 3083 * 2906 3084 * Parameters: 3085 * 2907 3086 * -- ULONG mp1: index of format to set. 2908 3087 * Must be 0 currently for the standard 2909 3088 * paragraph format. 3089 * 2910 3090 * -- PXFMTPARAGRAPH mp2: pointer to buffer 2911 3091 * from which to copy formatting data. … … 2953 3133 * the word-wrapping style of the default 2954 3134 * paragraph formatting. 3135 * 3136 * This may be sent or posted. 3137 * 2955 3138 * (BOOL)mp1 determines whether word wrapping 2956 3139 * should be turned on or off. … … 2972 3155 *@@ TXM_QUERYCDATA: 2973 3156 * 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. 2976 3160 * 2977 3161 * 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. 2981 3169 */ 2982 3170 … … 2985 3173 { 2986 3174 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); 2988 3179 } 2989 3180 break; … … 2993 3184 * updates the current XTEXTVIEWCDATA 2994 3185 * 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. 2996 3188 * 2997 3189 * Parameters: … … 3016 3208 * of the control. 3017 3209 * 3018 * This must be sent, not posted to the control3210 * This must be sent, not posted, to the control. 3019 3211 * 3020 3212 * Parameters: … … 3046 3238 if (ptxvd->ulViewYOfs < 0) 3047 3239 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; 3050 3242 3051 3243 // vertical scroll bar enabled at all? 3052 if (ptxvd-> cdata.flStyle & XTXF_VSCROLL)3244 if (ptxvd->flStyle & XS_VSCROLL) 3053 3245 { 3054 3246 /* BOOL fEnabled = */ winhUpdateScrollBar(ptxvd->hwndVScroll, 3055 3247 ulWinCY, 3056 ptxvd->xfd. ulViewportCY,3248 ptxvd->xfd.szlWorkspace.cy, 3057 3249 ptxvd->ulViewYOfs, 3058 (ptxvd-> cdata.flStyle & XTXF_AUTOVHIDE));3250 (ptxvd->flStyle & XS_AUTOVHIDE)); 3059 3251 WinInvalidateRect(hwndTextView, NULL, FALSE); 3060 3252 } 3061 3253 } 3062 3254 } 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; 3063 3287 } 3064 3288 break; … … 3093 3317 BOOL txvRegisterTextView(HAB hab) 3094 3318 { 3095 return (WinRegisterClass(hab,3096 3097 3098 3099 sizeof(PVOID))); // QWL_USER3319 return WinRegisterClass(hab, 3320 WC_XTEXTVIEW, 3321 fnwpTextView, 3322 0, 3323 2 * sizeof(PVOID)); // QWL_USER and QWL_PRIVATE 3100 3324 } 3101 3325 … … 3111 3335 USHORT usID, 3112 3336 ULONG flWinStyle, 3113 ULONG flStyle,3114 3337 USHORT usBorder) 3115 3338 { … … 3150 3373 memset(&xtxCData, 0, sizeof(xtxCData)); 3151 3374 xtxCData.cbData = sizeof(xtxCData); 3152 xtxCData.flStyle = flStyle;3153 3375 xtxCData.ulXBorder = usBorder; 3154 3376 xtxCData.ulYBorder = usBorder; … … 3183 3405 &lForeClr); 3184 3406 } 3185 return (hwndTextView);3407 return hwndTextView; 3186 3408 } 3187 3409 … … 3240 3462 } 3241 3463 3242 return (pprq3);3464 return pprq3; 3243 3465 } 3244 3466 … … 3301 3523 palRes); // buffer 3302 3524 3303 return (hdc);3525 return hdc; 3304 3526 } 3305 3527 … … 3334 3556 } 3335 3557 3336 return (pahci);3558 return pahci; 3337 3559 } 3338 3560 … … 3362 3584 sizel.cx = 0; 3363 3585 sizel.cy = 0; 3364 return (GpiCreatePS(hab,3365 3366 3367 ulUnits | GPIA_ASSOC | GPIT_NORMAL));3586 return GpiCreatePS(hab, 3587 hdc, 3588 &sizel, 3589 ulUnits | GPIA_ASSOC | GPIT_NORMAL); 3368 3590 } 3369 3591 … … 3529 3751 prthEndDoc(hdc, hps); 3530 3752 3531 return (TRUE);3753 return TRUE; 3532 3754 } 3533 3755 … … 3549 3771 int irc = 0; 3550 3772 3551 PTEXTVIEWWINDATA ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_ USER);3773 PTEXTVIEWWINDATA ptxvd = (PTEXTVIEWWINDATA)WinQueryWindowPtr(hwndTextView, QWL_PRIVATE); 3552 3774 3553 3775 if (!ptxvd) … … 3646 3868 } 3647 3869 3648 return (irc);3870 return irc; 3649 3871 } 3650 3872
Note:
See TracChangeset
for help on using the changeset viewer.