Changeset 243 for trunk/src/helpers/winh.c
- Timestamp:
- Jan 29, 2003, 7:41:39 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/winh.c
r242 r243 1896 1896 1897 1897 /* 1898 *@@ winhCreateScrollBars:1899 * creates two scroll bars with an arbitrary1900 * 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 bar1907 HWND *phwndH) // out: horizontal scroll bar1908 {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, // owner1925 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, // owner1936 HWND_TOP,1937 ID_HSCROLL,1938 &sbcd,1939 0))1940 );1941 }1942 1943 /*1944 1898 *@@ winhUpdateScrollBar: 1945 1899 * updates the given scroll bar according to the given … … 1958 1912 * Terminology: 1959 1913 * 1960 * -- "window": the actual window with scroll bars which displays 1961 * a subrectangle of the available data. With a typical PM 1962 * application, this will be your client window. 1963 * 1964 * The width or height of this must be passed in ulWinPels. 1965 * 1966 * -- "workarea": the entire data to be displayed, of which the 1967 * "window" can only display a subrectangle, if the workarea 1968 * is larger than the window. 1969 * 1970 * The width or height of this must be passed in ulWorkareaPels. 1971 * This can be smaller than ulWinPels (if the window is larger 1972 * than the data) or the same or larger than ulWinPels 1973 * (if the window is too small to show all the data). 1974 * 1975 * -- "window offset": the offset of the current window within 1976 * the workarea. 1977 * 1978 * For horizontal scroll bars, this is the X coordinate, 1979 * counting from the left of the window (0 means leftmost). 1980 * 1981 * For vertical scroll bars, this is counted from the _top_ 1982 * of the workarea (0 means topmost, as opposed to OS/2 1983 * window coordinates!). This is because for vertical scroll 1984 * bars controls, higher values move the thumb _down_. Yes 1985 * indeed, this conflicts with PM's coordinate system. 1986 * 1987 * The window offset is therefore always positive. 1914 * -- "window": the actual window with scroll bars which displays 1915 * a subrectangle of the available data. With a typical PM 1916 * application, this will be your client window. 1917 * 1918 * The width or height of this must be passed in ulWinPels. 1919 * 1920 * -- "workarea": the entire data to be displayed, of which the 1921 * "window" can only display a subrectangle, if the workarea 1922 * is larger than the window. 1923 * 1924 * The width or height of this must be passed in ulWorkareaPels. 1925 * This can be smaller than ulWinPels (if the window is larger 1926 * than the data) or the same or larger than ulWinPels 1927 * (if the window is too small to show all the data). 1928 * 1929 * This value is exclusive in the sense that the maximum 1930 * window offset (below) can be the workarea minus one. 1931 * 1932 * -- "window offset": the zero-based offset of the current 1933 * window within the workarea, whose maximum value is 1934 * the workarea minus one. 1935 * 1936 * For horizontal scroll bars, this is the X coordinate, 1937 * counting from the left of the window (0 means leftmost). 1938 * 1939 * For vertical scroll bars, this is counted from the _top_ 1940 * of the workarea (0 means topmost, as opposed to OS/2 1941 * window coordinates!). This is because for vertical scroll 1942 * bars controls, higher values move the thumb _down_. Yes 1943 * indeed, this conflicts with PM's coordinate system. 1944 * 1945 * The window offset is therefore always positive. 1988 1946 * 1989 1947 * The scroll bar gets disabled if the entire workarea is visible, … … 2009 1967 *@@changed V0.9.3 (2000-04-30) [umoeller]: fixed pels/unit confusion 2010 1968 *@@changed V0.9.3 (2000-05-08) [umoeller]: now handling scroll units automatically 1969 *@@changed V1.0.1 (2003-01-25) [umoeller]: fixed max value which caused right/bottommost scroll button to never be disabled 1970 *@@changed V1.0.1 (2003-01-25) [umoeller]: fixed bad thumb position for large offsets 2011 1971 */ 2012 1972 … … 2026 1986 BOOL brc = FALSE; 2027 1987 2028 // _Pmpf(("Entering winhUpdateScrollBar"));2029 2030 // for large workareas, adjust scroll bar units2031 USHORT usScrollUnitPels= 1;2032 if (ulWorkareaPels > 10000)2033 usScrollUnitPels = 100; 2034 2035 if (ulWorkareaPels > ulWinPels)2036 { 1988 if (ulWorkareaPels >= ulWinPels) 1989 { 1990 // for large workareas, adjust scroll bar units 1991 USHORT usDivisor = 1; 1992 USHORT lMaxAllowedUnitOfs; 1993 1994 if (ulWorkareaPels > 10000) 1995 usDivisor = 100; 1996 2037 1997 // scrollbar needed: 2038 USHORT usThumbDivisorUnits = usScrollUnitPels;2039 USHORT lMaxAllowedUnitOfs;2040 // _Pmpf(("winhUpdateScrollBar: ulWorkareaPels > ulWinPels, enabling scroller"));2041 // divisor for thumb size (below)2042 if (ulWorkareaPels > 10000)2043 // for very large workareas, we need to2044 // raise the divisor, because we only2045 // have a USHORT2046 usThumbDivisorUnits = usScrollUnitPels * 100;2047 1998 2048 1999 // workarea is larger than window: … … 2052 2003 2053 2004 // calculate limit 2054 lMaxAllowedUnitOfs = ((ulWorkareaPels - ulWinPels + usScrollUnitPels) 2055 // scroll unit is 10 2056 / usScrollUnitPels); 2057 2058 // _Pmpf((" usCurUnitOfs: %d", ulCurUnitOfs)); 2059 // _Pmpf((" usMaxUnits: %d", lMaxAllowedUnitOfs)); 2005 lMaxAllowedUnitOfs = (ulWorkareaPels - ulWinPels) 2006 / usDivisor; 2060 2007 2061 2008 // set thumb position and limit 2062 2009 WinSendMsg(hwndScrollBar, 2063 2010 SBM_SETSCROLLBAR, 2064 (MPARAM)(ulCurPelsOfs ), // / usThumbDivisorUnits), // position: 0 means top2011 (MPARAM)(ulCurPelsOfs / usDivisor), // position: 0 means top 2065 2012 MPFROM2SHORT(0, // minimum 2066 2013 lMaxAllowedUnitOfs)); // maximum … … 2070 2017 WinSendMsg(hwndScrollBar, 2071 2018 SBM_SETTHUMBSIZE, 2072 MPFROM2SHORT( ulWinPels / us ThumbDivisorUnits, // visible2073 ulWorkareaPels / us ThumbDivisorUnits), // total2019 MPFROM2SHORT( ulWinPels / usDivisor, // visible 2020 ulWorkareaPels / usDivisor), // total 2074 2021 0); 2075 2022 brc = TRUE; … … 2077 2024 else 2078 2025 { 2079 // _Pmpf(("winhUpdateScrollBar: ulWorkareaPels <= ulWinPels"));2080 2026 // entire workarea is visible: 2081 2027 WinEnableWindow(hwndScrollBar, FALSE); … … 2091 2037 /* 2092 2038 *@@ winhHandleScrollMsg: 2093 * this helper handles a WM_VSCROLL or WM_HSCROLL 2094 * message posted to a client window when the user 2095 * has worked on a client scroll bar. Calling this 2096 * function is ALL you need to do to handle those 2097 * two messages. 2039 * this helper handles a WM_VSCROLL or WM_HSCROLL message 2040 * posted to a client window when the user has worked on a 2041 * client scroll bar. Calling this function is all you need to 2042 * do to handle those two messages. 2098 2043 * 2099 2044 * This is most useful in conjunction with winhUpdateScrollBar. 2100 2045 * See that function for the terminology also. 2101 2046 * 2102 * This function calculates the new scrollbar position 2103 * (from the mp2 value, which can be line up/down, 2104 * page up/down, or slider track) and calls WinScrollWindow 2105 * accordingly. The window part which became invalid 2106 * because of the scrolling is automatically invalidated 2107 * (using WinInvalidateRect), so expect a WM_PAINT after 2108 * calling this function. 2047 * This function calculates the new scrollbar position (from 2048 * the mp2 value, which can be line up/down, page up/down, or 2049 * slider track) and calculates the scrolling offset 2050 * accordingly, which is returned as a LONG. 2109 2051 * 2110 2052 * This function assumes that the scrollbar operates 2111 2053 * on values starting from zero. The maximum value 2112 * of the scroll bar is :2113 * 2114 + ulWorkareaPels - (prcl2Scroll->yTop - prcl2Scroll->yBottom)2115 * 2116 * This function also automatically changes the scroll bar2054 * of the scroll bar is therefore 2055 * 2056 + lWorkareaPels - (prcl2Scroll->yTop - prcl2Scroll->yBottom) 2057 * 2058 * This function also automatically shrinks the scroll bar 2117 2059 * units, should you have a workarea size which doesn't fit 2118 2060 * into the SHORT's that the scroll bar uses internally. As 2119 2061 * a result, this function handles a the complete range of 2120 * a ULONG for the workarea. 2062 * a LONG for the workarea. (The PM scroll bar implementation 2063 * is really brain-dead in this respect... the workarea can 2064 * easily be larger than 32768 pixels. That's what scroll bars 2065 * are for in the first place, dammit.) 2121 2066 * 2122 2067 * Replace "bottom" and "top" with "right" and "left" for 2123 2068 * horizontal scrollbars in the above formula. 2069 * 2070 * Returns the amount of pixels to be passed to winhScrollWindow 2071 * afterwards. 2124 2072 * 2125 2073 *@@added V0.9.1 (2000-02-13) [umoeller] … … 2127 2075 *@@changed V0.9.3 (2000-05-08) [umoeller]: now handling scroll units automatically 2128 2076 *@@changed V0.9.7 (2001-01-17) [umoeller]: changed PLONG to PULONG 2129 */ 2130 2131 BOOL winhHandleScrollMsg(HWND hwnd2Scroll, // in: client window to scroll 2132 HWND hwndScrollBar, // in: vertical or horizontal scroll bar window 2133 PULONG pulCurPelsOfs, // in/out: current workarea offset; 2134 // this is updated with the proper scroll units 2135 PRECTL prcl2Scroll, // in: hwnd2Scroll rectangle to scroll 2136 // (in window coordinates); 2137 // this is passed to WinScrollWindow, 2138 // which considers this inclusive! 2139 LONG ulWorkareaPels, // in: total workarea dimension, 2140 // into which *pulCurPelsOfs is an offset 2077 *@@changed V1.0.1 (2003-01-25) [umoeller]: changed prototype, no longer calling WinScrollWindow, fixed offset bugs 2078 */ 2079 2080 LONG winhHandleScrollMsg(HWND hwndScrollBar, // in: vertical or horizontal scroll bar window 2081 PLONG plCurPelsOfs, // in/out: current workarea offset (in window coordinates) 2082 LONG lWindowPels, // in: window cx or cy (in window coordinates) 2083 LONG lWorkareaPels, // in: total workarea dimension, 2084 // into which *plCurPelsOfs is an offset 2141 2085 USHORT usLineStepPels, // in: pixels to scroll line-wise 2142 2086 // (scroll bar buttons pressed) … … 2146 2090 // see PMREF for details 2147 2091 { 2148 ULONG ulOldPelsOfs = *pulCurPelsOfs;2092 LONG lOldPelsOfs = *plCurPelsOfs; 2149 2093 USHORT usPosUnits = SHORT1FROMMP(mp2), // in scroll units 2150 2094 usCmd = SHORT2FROMMP(mp2); 2151 LONG lMaxAllowedUnitOfs; 2152 ULONG ulWinPels; 2095 LONG lLimitPels; 2153 2096 2154 2097 // for large workareas, adjust scroll bar units 2155 USHORT usScrollUnitPels = 1; 2156 if (ulWorkareaPels > 10000) 2157 usScrollUnitPels = 100; 2158 2159 // calculate window size (vertical or horizontal) 2160 if (msg == WM_VSCROLL) 2161 ulWinPels = (prcl2Scroll->yTop - prcl2Scroll->yBottom); 2162 else 2163 ulWinPels = (prcl2Scroll->xRight - prcl2Scroll->xLeft); 2164 2165 lMaxAllowedUnitOfs = ((LONG)ulWorkareaPels - ulWinPels) / usScrollUnitPels; 2166 2167 // _Pmpf(("Entering winhHandleScrollMsg")); 2098 LONG lScrollUnitPels = 1; 2099 if (lWorkareaPels > 10000) 2100 lScrollUnitPels = 100; 2168 2101 2169 2102 switch (usCmd) 2170 2103 { 2171 2104 case SB_LINEUP: 2172 if (*pulCurPelsOfs > usLineStepPels) 2173 *pulCurPelsOfs -= usLineStepPels; // * usScrollUnitPels); 2174 else 2175 *pulCurPelsOfs = 0; 2105 *plCurPelsOfs -= usLineStepPels; 2176 2106 break; 2177 2107 2178 2108 case SB_LINEDOWN: 2179 *p ulCurPelsOfs += usLineStepPels; // * usScrollUnitPels);2109 *plCurPelsOfs += usLineStepPels; 2180 2110 break; 2181 2111 2182 2112 case SB_PAGEUP: 2183 if (*pulCurPelsOfs > ulWinPels) 2184 *pulCurPelsOfs -= ulWinPels; // convert to units 2185 else 2186 *pulCurPelsOfs = 0; 2113 *plCurPelsOfs -= lWindowPels; 2187 2114 break; 2188 2115 2189 2116 case SB_PAGEDOWN: 2190 *p ulCurPelsOfs += ulWinPels; // convert to units2117 *plCurPelsOfs += lWindowPels; 2191 2118 break; 2192 2119 2193 2120 case SB_SLIDERTRACK: 2194 *pulCurPelsOfs = (usPosUnits * usScrollUnitPels); 2195 // _Pmpf((" SB_SLIDERTRACK: usUnits = %d", usPosUnits)); 2121 *plCurPelsOfs = (LONG)usPosUnits * lScrollUnitPels; 2196 2122 break; 2197 2123 2198 2124 case SB_SLIDERPOSITION: 2199 *p ulCurPelsOfs = (usPosUnits * usScrollUnitPels);2125 *plCurPelsOfs = (LONG)usPosUnits * lScrollUnitPels; 2200 2126 break; 2201 2127 } 2202 2128 2203 // are we close to the lower limit? 2204 /* if (*plCurUnitOfs < usLineStepUnits) // usScrollUnit) 2205 *plCurUnitOfs = 0; 2206 // are we close to the upper limit? 2207 else if (*plCurUnitOfs + usLineStepUnits > lMaxUnitOfs) 2208 { 2209 _Pmpf((" !!! limiting: %d to %d", *plCurUnitOfs, lMaxUnitOfs)); 2210 *plCurUnitOfs = lMaxUnitOfs; 2211 } */ 2212 2213 /* if (*plCurPelsOfs < 0) 2214 *plCurPelsOfs = 0; */ // checked above 2215 if (*pulCurPelsOfs > (lMaxAllowedUnitOfs * usScrollUnitPels)) 2216 { 2217 *pulCurPelsOfs = (lMaxAllowedUnitOfs * usScrollUnitPels); 2218 } 2219 if ( (*pulCurPelsOfs != ulOldPelsOfs) 2220 || (*pulCurPelsOfs == 0) 2221 || (*pulCurPelsOfs == (lMaxAllowedUnitOfs * usScrollUnitPels)) 2129 // calc max scroll offset: 2130 // if we have a viewport of 200 and the window size is 199, 2131 // we can have scroll values of 0 or 1 2132 lLimitPels = lWorkareaPels - lWindowPels; 2133 2134 // now delimit 2135 if (*plCurPelsOfs < 0) 2136 *plCurPelsOfs = 0; 2137 else if (*plCurPelsOfs > lLimitPels) 2138 *plCurPelsOfs = lLimitPels; 2139 2140 if ( (*plCurPelsOfs != lOldPelsOfs) 2141 || (*plCurPelsOfs == 0) 2142 || (*plCurPelsOfs == lLimitPels) 2222 2143 ) 2223 2144 { 2224 RECTL rcl2Scroll,2225 rcl2Update;2226 2227 2145 // changed: 2228 2146 WinSendMsg(hwndScrollBar, 2229 2147 SBM_SETPOS, 2230 (MPARAM)(*pulCurPelsOfs / usScrollUnitPels), // / usScrollUnit), 2231 0); 2232 // scroll window rectangle: 2233 rcl2Scroll.xLeft = prcl2Scroll->xLeft; 2234 rcl2Scroll.xRight = prcl2Scroll->xRight; 2235 rcl2Scroll.yBottom = prcl2Scroll->yBottom; 2236 rcl2Scroll.yTop = prcl2Scroll->yTop; 2237 2238 if (msg == WM_VSCROLL) 2239 WinScrollWindow(hwnd2Scroll, 2240 0, 2241 (*pulCurPelsOfs - ulOldPelsOfs) // scroll units changed 2242 , // * usScrollUnitPels, // convert to pels 2243 &rcl2Scroll, // rcl to scroll 2244 prcl2Scroll, // clipping rect 2245 NULLHANDLE, // no region 2246 &rcl2Update, 2247 0); 2248 else 2249 WinScrollWindow(hwnd2Scroll, 2250 -(LONG)(*pulCurPelsOfs - ulOldPelsOfs) // scroll units changed 2251 , // * usScrollUnitPels, 2252 0, 2253 &rcl2Scroll, // rcl to scroll 2254 prcl2Scroll, // clipping rect 2255 NULLHANDLE, // no region 2256 &rcl2Update, 2257 0); 2258 2259 // WinScrollWindow has stored the invalid window 2260 // rectangle which needs to be repainted in rcl2Update: 2261 WinInvalidateRect(hwnd2Scroll, &rcl2Update, FALSE); 2262 } 2263 2264 // _Pmpf(("End of winhHandleScrollMsg")); 2265 2266 return TRUE; 2267 } 2268 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), 2148 (MPARAM)(*plCurPelsOfs / lScrollUnitPels), 2351 2149 0); 2352 2150 … … 2381 2179 2382 2180 /* 2383 *@@ winhProcessScrollChars :2181 *@@ winhProcessScrollChars2: 2384 2182 * helper for processing WM_CHAR messages for 2385 2183 * client windows with scroll bars. … … 2400 2198 * The following keystrokes are processed here: 2401 2199 * 2402 * -- "cursor up, down, right, left": scroll one 2403 * line in the proper direction. 2404 * -- "page up, down": scroll one page up or down. 2405 * -- "Home": scroll leftmost. 2406 * -- "Ctrl+ Home": scroll topmost. 2407 * -- "End": scroll rightmost. 2408 * -- "Ctrl+ End": scroll bottommost. 2409 * -- "Ctrl + page up, down": scroll one screen left or right. 2410 * 2411 * This is CUA behavior. 2412 * 2413 * Returns TRUE if the message has been 2414 * processed. 2200 * -- "cursor up, down, right, left": scroll one 2201 * line in the proper direction. 2202 * -- "page up, down": scroll one page up or down. 2203 * -- "Home": scroll leftmost. 2204 * -- "Ctrl+ Home": scroll topmost. 2205 * -- "End": scroll rightmost. 2206 * -- "Ctrl+ End": scroll bottommost. 2207 * -- "Ctrl + page up, down": scroll one screen left or right. 2208 * 2209 * This is CUA behavior, if anyone still cares about that. 2210 * 2211 * Returns TRUE if the message has been processed. 2415 2212 * 2416 2213 *@@added V0.9.3 (2000-04-29) [umoeller] … … 2418 2215 */ 2419 2216 2420 BOOL winhProcessScrollChars(HWND hwndClient, // in: client window 2421 HWND hwndVScroll, // in: vertical scroll bar 2422 HWND hwndHScroll, // in: horizontal scroll bar 2423 MPARAM mp1, // in: WM_CHAR mp1 2424 MPARAM mp2, // in: WM_CHAR mp2 2425 ULONG ulVertMax, // in: maximum workarea cy 2426 ULONG ulHorzMax) // in: maximum workarea cx 2217 BOOL winhProcessScrollChars2(HWND hwndClient, // in: client window 2218 const SCROLLABLEWINDOW *pscrw, // in: scroller data 2219 MPARAM mp1, // in: WM_CHAR mp1 2220 MPARAM mp2) // in: WM_CHAR mp2 2427 2221 { 2428 2222 BOOL fProcessed = FALSE; 2429 2223 USHORT usFlags = SHORT1FROMMP(mp1); 2430 // USHORT usch = SHORT1FROMMP(mp2);2431 2224 USHORT usvk = SHORT2FROMMP(mp2); 2432 2433 // _Pmpf(("Entering winhProcessScrollChars"));2434 2225 2435 2226 if (usFlags & KC_VIRTUALKEY) … … 2494 2285 // vertical: 2495 2286 ulMsg = WM_VSCROLL; 2496 sPos = ulVertMax;2287 sPos = pscrw->szlWorkarea.cy; 2497 2288 } 2498 2289 else 2499 2290 { 2500 2291 ulMsg = WM_HSCROLL; 2501 sPos = ulHorzMax;2292 sPos = pscrw->szlWorkarea.cx; 2502 2293 } 2503 2294 … … 2515 2306 { 2516 2307 HWND hwndScrollBar = ((ulMsg == WM_VSCROLL) 2517 ? hwndVScroll2518 : hwndHScroll);2308 ? pscrw->hwndVScroll 2309 : pscrw->hwndHScroll); 2519 2310 if (WinIsWindowEnabled(hwndScrollBar)) 2520 2311 { … … 2530 2321 } 2531 2322 2532 // _Pmpf(("End of winhProcessScrollChars"));2533 2534 2323 return fProcessed; 2324 } 2325 2326 /* 2327 *@@ winhProcessScrollChars: 2328 * wrapper around winhProcessScrollChars2 for prototype 2329 * compatibility. 2330 * 2331 *@@added V1.0.1 (2003-01-25) [umoeller] 2332 */ 2333 2334 BOOL winhProcessScrollChars(HWND hwndClient, // in: client window 2335 HWND hwndVScroll, // in: vertical scroll bar 2336 HWND hwndHScroll, // in: horizontal scroll bar 2337 MPARAM mp1, // in: WM_CHAR mp1 2338 MPARAM mp2, // in: WM_CHAR mp2 2339 ULONG ulVertMax, // in: maximum workarea cy 2340 ULONG ulHorzMax) // in: maximum workarea cx 2341 { 2342 SCROLLABLEWINDOW scrw; 2343 2344 scrw.hwndVScroll = hwndVScroll; 2345 scrw.hwndHScroll = hwndHScroll; 2346 scrw.szlWorkarea.cx = ulHorzMax; 2347 scrw.szlWorkarea.cy = ulVertMax; 2348 2349 return winhProcessScrollChars2(hwndClient, 2350 &scrw, 2351 mp1, 2352 mp2); 2353 } 2354 2355 /* 2356 *@@ winhCreateScrollBars: 2357 * creates two scroll bars with an arbitrary 2358 * position for later use with winhUpdateScrollBar. 2359 * 2360 *@@added V1.0.1 (2003-01-25) [umoeller] 2361 */ 2362 2363 BOOL XWPENTRY winhCreateScroller(HWND hwndParent, // in: parent and owner of scroll bars 2364 PSCROLLABLEWINDOW pscrw, // out: scroller data 2365 ULONG idVScroll, // in: window ID of vertical scroll bar 2366 ULONG idHScroll) // in: window ID of horizontal scroll bar 2367 { 2368 SBCDATA sbcd; 2369 sbcd.cb = sizeof(SBCDATA); 2370 sbcd.sHilite = 0; 2371 sbcd.posFirst = 0; 2372 sbcd.posLast = 100; 2373 sbcd.posThumb = 30; 2374 sbcd.cVisible = 50; 2375 sbcd.cTotal = 50; 2376 2377 pscrw->cxScrollBar = WinQuerySysValue(HWND_DESKTOP, SV_CXVSCROLL); 2378 pscrw->cyScrollBar = WinQuerySysValue(HWND_DESKTOP, SV_CYHSCROLL); 2379 2380 pscrw->idVScroll = idVScroll; 2381 pscrw->idHScroll = idHScroll; 2382 2383 pscrw->szlWorkarea.cx 2384 = pscrw->szlWorkarea.cy 2385 = pscrw->ptlScrollOfs.x 2386 = pscrw->ptlScrollOfs.y 2387 = 0; 2388 2389 return ( (pscrw->hwndVScroll = WinCreateWindow(hwndParent, 2390 WC_SCROLLBAR, 2391 "", 2392 SBS_VERT | SBS_THUMBSIZE | WS_VISIBLE, 2393 10, 10, 2394 20, 100, 2395 hwndParent, // owner 2396 HWND_TOP, 2397 idVScroll, 2398 &sbcd, 2399 0)) 2400 && (pscrw->hwndHScroll = WinCreateWindow(hwndParent, 2401 WC_SCROLLBAR, 2402 "", 2403 SBS_THUMBSIZE | WS_VISIBLE, 2404 10, 10, 2405 20, 100, 2406 hwndParent, // owner 2407 HWND_TOP, 2408 idHScroll, 2409 &sbcd, 2410 0)) 2411 ); 2412 } 2413 2414 /* 2415 *@@ winhHandleScrollerMsgs: 2416 * unified function that you can simply call for all of 2417 * the WM_HSCROLL, WM_VSCROLL, and WM_CHAR messages to 2418 * get full automatic scrolling support for window 2419 * messages. 2420 * 2421 * This calls winhHandleScrollMsg, winhScrollWindow, 2422 * and winhProcessScrollChars in turn as appropriate. 2423 * 2424 * However, you still need to call winhUpdateScrollBar 2425 * for each scroll bar whenever either the workarea or 2426 * window size changes. 2427 * 2428 * See winhUpdateScrollBar for the terminology. 2429 * 2430 * The size of the workarea must be passed in with 2431 * pscrw, as well as the window and scrollbar handles. 2432 * By contrast, the current window size must be passed 2433 * in via the pszlWin parameter. This allows for cooperation 2434 * with the ctlDefWindowProc funcs, which have their own 2435 * fields for this in DEFWINDOWDATA so we won't duplicate. 2436 * 2437 * Preconditions: 2438 * 2439 * -- hwnd2Scroll (the "client") and the scroll bar windows 2440 * must be siblings presently. In other words, scrolling 2441 * won't work correctly if the scroll bars are children 2442 * of the client because we do not presently handle 2443 * passing a clipping rectangle to WinScrollWindow here. 2444 * 2445 *@@added V1.0.1 (2003-01-25) [umoeller] 2446 */ 2447 2448 MRESULT winhHandleScrollerMsgs(HWND hwnd2Scroll, // in: "client" window 2449 PSCROLLABLEWINDOW pscrw, // in: scroller data 2450 PSIZEL pszlWin, 2451 ULONG msg, 2452 MPARAM mp1, 2453 MPARAM mp2) 2454 { 2455 MRESULT mrc = 0; 2456 POINTL ptlScroll = {0, 0}; 2457 2458 switch (msg) 2459 { 2460 case WM_VSCROLL: 2461 if (ptlScroll.y = winhHandleScrollMsg(pscrw->hwndVScroll, 2462 &pscrw->ptlScrollOfs.y, 2463 pszlWin->cy, 2464 pscrw->szlWorkarea.cy, 2465 10, 2466 msg, 2467 mp2)) 2468 winhScrollWindow(hwnd2Scroll, 2469 NULL, 2470 &ptlScroll); 2471 break; 2472 2473 case WM_HSCROLL: 2474 if (ptlScroll.x = winhHandleScrollMsg(pscrw->hwndHScroll, 2475 &pscrw->ptlScrollOfs.x, 2476 pszlWin->cx, 2477 pscrw->szlWorkarea.cx, 2478 10, 2479 msg, 2480 mp2)) 2481 winhScrollWindow(hwnd2Scroll, 2482 NULL, 2483 &ptlScroll); 2484 break; 2485 2486 case WM_CHAR: 2487 mrc = (MRESULT)winhProcessScrollChars(hwnd2Scroll, 2488 pscrw->hwndVScroll, 2489 pscrw->hwndHScroll, 2490 mp1, 2491 mp2, 2492 pscrw->szlWorkarea.cy, 2493 pscrw->szlWorkarea.cx); 2494 break; 2495 } 2496 2497 return mrc; 2535 2498 } 2536 2499 … … 3763 3726 3764 3727 return hswitch; 3728 } 3729 3730 /* 3731 *@@ winhUpdateTasklist: 3732 * refreshes the task list entry for the given 3733 * window with a new title text. 3734 * 3735 *@@added V1.0.1 (2003-01-25) [umoeller] 3736 */ 3737 3738 BOOL winhUpdateTasklist(HWND hwnd, 3739 PCSZ pcszNewTitle) 3740 { 3741 HSWITCH hsw; 3742 if (hsw = WinQuerySwitchHandle(hwnd, 0)) 3743 { 3744 SWCNTRL swc; 3745 WinQuerySwitchEntry(hsw, &swc); 3746 strhncpy0(swc.szSwtitle, 3747 pcszNewTitle, 3748 sizeof(swc.szSwtitle)); 3749 return !WinChangeSwitchEntry(hsw, &swc); 3750 } 3751 3752 return FALSE; 3765 3753 } 3766 3754
Note:
See TracChangeset
for help on using the changeset viewer.