Changeset 242 for trunk/src/helpers/winh.c
- Timestamp:
- Jan 19, 2003, 8:42:16 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/winh.c
r239 r242 1896 1896 1897 1897 /* 1898 *@@ winhCreateScrollBars: 1899 * creates two scroll bars with an arbitrary 1900 * position for later use with winhUpdateScrollBar. 1901 * 1902 *@@added V1.0.1 (2003-01-17) [umoeller] 1903 */ 1904 1905 BOOL winhCreateScrollBars(HWND hwndParent, 1906 HWND *phwndV, // out: vertical scroll bar 1907 HWND *phwndH) // out: horizontal scroll bar 1908 { 1909 SBCDATA sbcd; 1910 sbcd.cb = sizeof(SBCDATA); 1911 sbcd.sHilite = 0; 1912 sbcd.posFirst = 0; 1913 sbcd.posLast = 100; 1914 sbcd.posThumb = 30; 1915 sbcd.cVisible = 50; 1916 sbcd.cTotal = 50; 1917 1918 return ( (*phwndV = WinCreateWindow(hwndParent, 1919 WC_SCROLLBAR, 1920 "", 1921 SBS_VERT | SBS_THUMBSIZE | WS_VISIBLE, 1922 10, 10, 1923 20, 100, 1924 hwndParent, // owner 1925 HWND_TOP, 1926 ID_VSCROLL, 1927 &sbcd, 1928 0)) 1929 && (*phwndH = WinCreateWindow(hwndParent, 1930 WC_SCROLLBAR, 1931 "", 1932 SBS_THUMBSIZE | WS_VISIBLE, 1933 10, 10, 1934 20, 100, 1935 hwndParent, // owner 1936 HWND_TOP, 1937 ID_HSCROLL, 1938 &sbcd, 1939 0)) 1940 ); 1941 } 1942 1943 /* 1898 1944 *@@ winhUpdateScrollBar: 1899 1945 * updates the given scroll bar according to the given … … 1918 1964 * The width or height of this must be passed in ulWinPels. 1919 1965 * 1920 * -- " viewport": the entire data to be displayed, of which the1921 * "window" can only display a subrectangle, if the viewport1966 * -- "workarea": the entire data to be displayed, of which the 1967 * "window" can only display a subrectangle, if the workarea 1922 1968 * is larger than the window. 1923 1969 * 1924 * The width or height of this must be passed in ul ViewportPels.1970 * The width or height of this must be passed in ulWorkareaPels. 1925 1971 * This can be smaller than ulWinPels (if the window is larger 1926 1972 * than the data) or the same or larger than ulWinPels … … 1928 1974 * 1929 1975 * -- "window offset": the offset of the current window within 1930 * the viewport.1976 * the workarea. 1931 1977 * 1932 1978 * For horizontal scroll bars, this is the X coordinate, … … 1934 1980 * 1935 1981 * For vertical scroll bars, this is counted from the _top_ 1936 * of the viewport(0 means topmost, as opposed to OS/21982 * of the workarea (0 means topmost, as opposed to OS/2 1937 1983 * window coordinates!). This is because for vertical scroll 1938 1984 * bars controls, higher values move the thumb _down_. Yes … … 1941 1987 * The window offset is therefore always positive. 1942 1988 * 1943 * The scroll bar gets disabled if the entire viewportis visible,1944 * that is, if ul ViewportPels <= ulWinPels. In that case1989 * The scroll bar gets disabled if the entire workarea is visible, 1990 * that is, if ulWorkareaPels <= ulWinPels. In that case 1945 1991 * FALSE is returned. If (fAutoHide == TRUE), the scroll 1946 1992 * bar is not only disabled, but also hidden from the display. 1947 1993 * In that case, you will need to reformat your output because 1948 * your viewportbecomes larger without the scroll bar.1994 * your workarea becomes larger without the scroll bar. 1949 1995 * 1950 1996 * This function will set the range of the scroll bar to 0 up 1951 * to a value depending on the viewportsize. For vertical scroll1997 * to a value depending on the workarea size. For vertical scroll 1952 1998 * bars, 0 means topmost (which is kinda sick with the OS/2 1953 1999 * coordinate system), for horizontal scroll bars, 0 means leftmost. … … 1955 2001 * The maximum value of the scroll bar will be 1956 2002 * 1957 + (ul ViewportPels - ulWinPels) / usScrollUnitPels2003 + (ulWorkareaPels - ulWinPels) / usScrollUnitPels 1958 2004 * 1959 2005 * The thumb size of the scroll bar will also be adjusted 1960 * based on the viewportand window size, as it should be.2006 * based on the workarea and window size, as it should be. 1961 2007 * 1962 2008 *@@added V0.9.1 (2000-02-14) [umoeller] … … 1969 2015 // visible window part (in pixels), 1970 2016 // excluding the scroll bar! 1971 ULONG ul ViewportPels, // in: dimension of total data part, of2017 ULONG ulWorkareaPels, // in: dimension of total data part, of 1972 2018 // which ulWinPels is a sub-dimension 1973 2019 // (in pixels); … … 1982 2028 // _Pmpf(("Entering winhUpdateScrollBar")); 1983 2029 1984 // for large viewports, adjust scroll bar units2030 // for large workareas, adjust scroll bar units 1985 2031 USHORT usScrollUnitPels = 1; 1986 if (ul ViewportPels > 10000)2032 if (ulWorkareaPels > 10000) 1987 2033 usScrollUnitPels = 100; 1988 2034 1989 if (ul ViewportPels > ulWinPels)2035 if (ulWorkareaPels > ulWinPels) 1990 2036 { 1991 2037 // scrollbar needed: 1992 2038 USHORT usThumbDivisorUnits = usScrollUnitPels; 1993 2039 USHORT lMaxAllowedUnitOfs; 1994 // _Pmpf(("winhUpdateScrollBar: ul ViewportPels > ulWinPels, enabling scroller"));2040 // _Pmpf(("winhUpdateScrollBar: ulWorkareaPels > ulWinPels, enabling scroller")); 1995 2041 // divisor for thumb size (below) 1996 if (ul ViewportPels > 10000)1997 // for very large viewports, we need to2042 if (ulWorkareaPels > 10000) 2043 // for very large workareas, we need to 1998 2044 // raise the divisor, because we only 1999 2045 // have a USHORT 2000 2046 usThumbDivisorUnits = usScrollUnitPels * 100; 2001 2047 2002 // viewportis larger than window:2048 // workarea is larger than window: 2003 2049 WinEnableWindow(hwndScrollBar, TRUE); 2004 2050 if (fAutoHide) … … 2006 2052 2007 2053 // calculate limit 2008 lMaxAllowedUnitOfs = ((ul ViewportPels - ulWinPels + usScrollUnitPels)2054 lMaxAllowedUnitOfs = ((ulWorkareaPels - ulWinPels + usScrollUnitPels) 2009 2055 // scroll unit is 10 2010 2056 / usScrollUnitPels); … … 2021 2067 2022 2068 // set thumb size based on ulWinPels and 2023 // ul ViewportPels2069 // ulWorkareaPels 2024 2070 WinSendMsg(hwndScrollBar, 2025 2071 SBM_SETTHUMBSIZE, 2026 2072 MPFROM2SHORT( ulWinPels / usThumbDivisorUnits, // visible 2027 ul ViewportPels / usThumbDivisorUnits), // total2073 ulWorkareaPels / usThumbDivisorUnits), // total 2028 2074 0); 2029 2075 brc = TRUE; … … 2031 2077 else 2032 2078 { 2033 // _Pmpf(("winhUpdateScrollBar: ul ViewportPels <= ulWinPels"));2034 // entire viewportis visible:2079 // _Pmpf(("winhUpdateScrollBar: ulWorkareaPels <= ulWinPels")); 2080 // entire workarea is visible: 2035 2081 WinEnableWindow(hwndScrollBar, FALSE); 2036 2082 if (fAutoHide) … … 2066 2112 * of the scroll bar is: 2067 2113 * 2068 + ul ViewportPels - (prcl2Scroll->yTop - prcl2Scroll->yBottom)2114 + ulWorkareaPels - (prcl2Scroll->yTop - prcl2Scroll->yBottom) 2069 2115 * 2070 2116 * This function also automatically changes the scroll bar 2071 * units, should you have a viewportsize which doesn't fit2117 * units, should you have a workarea size which doesn't fit 2072 2118 * into the SHORT's that the scroll bar uses internally. As 2073 2119 * a result, this function handles a the complete range of 2074 * a ULONG for the viewport.2120 * a ULONG for the workarea. 2075 2121 * 2076 2122 * Replace "bottom" and "top" with "right" and "left" for … … 2085 2131 BOOL winhHandleScrollMsg(HWND hwnd2Scroll, // in: client window to scroll 2086 2132 HWND hwndScrollBar, // in: vertical or horizontal scroll bar window 2087 PULONG pulCurPelsOfs, // in/out: current viewportoffset;2133 PULONG pulCurPelsOfs, // in/out: current workarea offset; 2088 2134 // this is updated with the proper scroll units 2089 2135 PRECTL prcl2Scroll, // in: hwnd2Scroll rectangle to scroll … … 2091 2137 // this is passed to WinScrollWindow, 2092 2138 // which considers this inclusive! 2093 LONG ul ViewportPels, // in: total viewportdimension,2139 LONG ulWorkareaPels, // in: total workarea dimension, 2094 2140 // into which *pulCurPelsOfs is an offset 2095 2141 USHORT usLineStepPels, // in: pixels to scroll line-wise … … 2106 2152 ULONG ulWinPels; 2107 2153 2108 // for large viewports, adjust scroll bar units2154 // for large workareas, adjust scroll bar units 2109 2155 USHORT usScrollUnitPels = 1; 2110 if (ul ViewportPels > 10000)2156 if (ulWorkareaPels > 10000) 2111 2157 usScrollUnitPels = 100; 2112 2158 … … 2117 2163 ulWinPels = (prcl2Scroll->xRight - prcl2Scroll->xLeft); 2118 2164 2119 lMaxAllowedUnitOfs = ((LONG)ul ViewportPels - ulWinPels) / usScrollUnitPels;2165 lMaxAllowedUnitOfs = ((LONG)ulWorkareaPels - ulWinPels) / usScrollUnitPels; 2120 2166 2121 2167 // _Pmpf(("Entering winhHandleScrollMsg")); … … 2222 2268 2223 2269 /* 2270 *@@ winhHandleScrollMsg2: 2271 * 2272 * Returns the amount of pixels to be passed to 2273 * WinScrollWindow. 2274 * 2275 *@@added V1.0.1 (2003-01-17) [umoeller] 2276 */ 2277 2278 LONG winhHandleScrollMsg2(HWND hwndScrollBar, // in: vertical or horizontal scroll bar window 2279 PLONG plCurPelsOfs, // in/out: current workarea offset; 2280 // this is updated with the proper scroll units 2281 LONG lWindowPels, // in: window cx or cy (in window coordinates); 2282 LONG lWorkareaPels, // in: total workarea dimension, 2283 // into which *plCurPelsOfs is an offset 2284 USHORT usLineStepPels, // in: pixels to scroll line-wise 2285 // (scroll bar buttons pressed) 2286 ULONG msg, // in: either WM_VSCROLL or WM_HSCROLL 2287 MPARAM mp2) // in: complete mp2 of WM_VSCROLL/WM_HSCROLL; 2288 // this has two SHORT's (usPos and usCmd), 2289 // see PMREF for details 2290 { 2291 LONG lOldPelsOfs = *plCurPelsOfs; 2292 USHORT usPosUnits = SHORT1FROMMP(mp2), // in scroll units 2293 usCmd = SHORT2FROMMP(mp2); 2294 LONG lMaxAllowedUnitOfs; 2295 2296 // for large workareas, adjust scroll bar units 2297 USHORT usScrollUnitPels = 1; 2298 if (lWorkareaPels > 10000) 2299 usScrollUnitPels = 100; 2300 2301 lMaxAllowedUnitOfs = (lWorkareaPels - lWindowPels) / usScrollUnitPels; 2302 2303 // _Pmpf(("Entering winhHandleScrollMsg")); 2304 2305 switch (usCmd) 2306 { 2307 case SB_LINEUP: 2308 if (*plCurPelsOfs > usLineStepPels) 2309 *plCurPelsOfs -= usLineStepPels; // * usScrollUnitPels); 2310 else 2311 *plCurPelsOfs = 0; 2312 break; 2313 2314 case SB_LINEDOWN: 2315 *plCurPelsOfs += usLineStepPels; // * usScrollUnitPels); 2316 break; 2317 2318 case SB_PAGEUP: 2319 if (*plCurPelsOfs > lWindowPels) 2320 *plCurPelsOfs -= lWindowPels; // convert to units 2321 else 2322 *plCurPelsOfs = 0; 2323 break; 2324 2325 case SB_PAGEDOWN: 2326 *plCurPelsOfs += lWindowPels; // convert to units 2327 break; 2328 2329 case SB_SLIDERTRACK: 2330 *plCurPelsOfs = (usPosUnits * usScrollUnitPels); 2331 // _Pmpf((" SB_SLIDERTRACK: usUnits = %d", usPosUnits)); 2332 break; 2333 2334 case SB_SLIDERPOSITION: 2335 *plCurPelsOfs = (usPosUnits * usScrollUnitPels); 2336 break; 2337 } 2338 2339 if (*plCurPelsOfs > (lMaxAllowedUnitOfs * usScrollUnitPels)) 2340 *plCurPelsOfs = (lMaxAllowedUnitOfs * usScrollUnitPels); 2341 2342 if ( (*plCurPelsOfs != lOldPelsOfs) 2343 || (*plCurPelsOfs == 0) 2344 || (*plCurPelsOfs == (lMaxAllowedUnitOfs * usScrollUnitPels)) 2345 ) 2346 { 2347 // changed: 2348 WinSendMsg(hwndScrollBar, 2349 SBM_SETPOS, 2350 (MPARAM)(*plCurPelsOfs / usScrollUnitPels), // / usScrollUnit), 2351 0); 2352 2353 if (msg == WM_VSCROLL) 2354 return (*plCurPelsOfs - lOldPelsOfs); 2355 2356 return -(*plCurPelsOfs - lOldPelsOfs); 2357 } 2358 2359 return 0; 2360 } 2361 2362 /* 2363 *@@ winhScrollWindow: 2364 * 2365 *@@added V1.0.1 (2003-01-17) [umoeller] 2366 */ 2367 2368 BOOL winhScrollWindow(HWND hwnd2Scroll, 2369 PRECTL prclClip, // clipping rectangle or NULL 2370 PPOINTL pptlScroll) 2371 { 2372 return !!WinScrollWindow(hwnd2Scroll, 2373 pptlScroll->x, 2374 pptlScroll->y, 2375 prclClip, 2376 prclClip, 2377 NULLHANDLE, // no region 2378 NULL, // no rect 2379 SW_INVALIDATERGN); 2380 } 2381 2382 /* 2224 2383 *@@ winhProcessScrollChars: 2225 2384 * helper for processing WM_CHAR messages for … … 2264 2423 MPARAM mp1, // in: WM_CHAR mp1 2265 2424 MPARAM mp2, // in: WM_CHAR mp2 2266 ULONG ulVertMax, // in: maximum viewportcy2267 ULONG ulHorzMax) // in: maximum viewportcx2425 ULONG ulVertMax, // in: maximum workarea cy 2426 ULONG ulHorzMax) // in: maximum workarea cx 2268 2427 { 2269 2428 BOOL fProcessed = FALSE; … … 3305 3464 fl |= QPF_ID2COLORINDEX; // convert indexed color 2 to RGB V0.9.20 (2002-08-04) [umoeller] 3306 3465 3307 if ( (ul = WinQueryPresParam(hwnd,3308 3309 3310 3311 3312 3313 fl)))3466 if (ul = WinQueryPresParam(hwnd, 3467 ulppRGB, 3468 ulppIndex, 3469 &attrFound, 3470 sizeof(lColorFound), 3471 &lColorFound, 3472 fl)) 3314 3473 return lColorFound; 3315 3474 } … … 4270 4429 NULL, 4271 4430 NULL); 4431 } 4432 4433 /* 4434 *@@ winhSetParentAndOwner: 4435 * switches owner _and_ parent of the given window. 4436 * 4437 *@@added V1.0.1 (2003-01-17) [umoeller] 4438 */ 4439 4440 BOOL winhSetParentAndOwner(HWND hwnd, // in: window whose parent and owner to change 4441 HWND hwndNewParent, // in: new parent and owner 4442 BOOL fRedraw) 4443 { 4444 return ( WinSetParent(hwnd, hwndNewParent, fRedraw) 4445 && WinSetOwner(hwnd, hwndNewParent) 4446 ); 4272 4447 } 4273 4448
Note:
See TracChangeset
for help on using the changeset viewer.