Ignore:
Timestamp:
Jan 19, 2003, 8:42:16 PM (23 years ago)
Author:
umoeller
Message:

First attempt at new container contol.

File:
1 edited

Legend:

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

    r239 r242  
    18961896
    18971897/*
     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
     1905BOOL 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/*
    18981944 *@@ winhUpdateScrollBar:
    18991945 *      updates the given scroll bar according to the given
     
    19181964 *         The width or height of this must be passed in ulWinPels.
    19191965 *
    1920  *      -- "viewport": the entire data to be displayed, of which the
    1921  *         "window" can only display a subrectangle, if the viewport
     1966 *      -- "workarea": the entire data to be displayed, of which the
     1967 *         "window" can only display a subrectangle, if the workarea
    19221968 *         is larger than the window.
    19231969 *
    1924  *         The width or height of this must be passed in ulViewportPels.
     1970 *         The width or height of this must be passed in ulWorkareaPels.
    19251971 *         This can be smaller than ulWinPels (if the window is larger
    19261972 *         than the data) or the same or larger than ulWinPels
     
    19281974 *
    19291975 *      -- "window offset": the offset of the current window within
    1930  *         the viewport.
     1976 *         the workarea.
    19311977 *
    19321978 *         For horizontal scroll bars, this is the X coordinate,
     
    19341980 *
    19351981 *         For vertical scroll bars, this is counted from the _top_
    1936  *         of the viewport (0 means topmost, as opposed to OS/2
     1982 *         of the workarea (0 means topmost, as opposed to OS/2
    19371983 *         window coordinates!). This is because for vertical scroll
    19381984 *         bars controls, higher values move the thumb _down_. Yes
     
    19411987 *         The window offset is therefore always positive.
    19421988 *
    1943  *      The scroll bar gets disabled if the entire viewport is visible,
    1944  *      that is, if ulViewportPels <= ulWinPels. In that case
     1989 *      The scroll bar gets disabled if the entire workarea is visible,
     1990 *      that is, if ulWorkareaPels <= ulWinPels. In that case
    19451991 *      FALSE is returned. If (fAutoHide == TRUE), the scroll
    19461992 *      bar is not only disabled, but also hidden from the display.
    19471993 *      In that case, you will need to reformat your output because
    1948  *      your viewport becomes larger without the scroll bar.
     1994 *      your workarea becomes larger without the scroll bar.
    19491995 *
    19501996 *      This function will set the range of the scroll bar to 0 up
    1951  *      to a value depending on the viewport size. For vertical scroll
     1997 *      to a value depending on the workarea size. For vertical scroll
    19521998 *      bars, 0 means topmost (which is kinda sick with the OS/2
    19531999 *      coordinate system), for horizontal scroll bars, 0 means leftmost.
     
    19552001 *      The maximum value of the scroll bar will be
    19562002 *
    1957  +          (ulViewportPels - ulWinPels) / usScrollUnitPels
     2003 +          (ulWorkareaPels - ulWinPels) / usScrollUnitPels
    19582004 *
    19592005 *      The thumb size of the scroll bar will also be adjusted
    1960  *      based on the viewport and window size, as it should be.
     2006 *      based on the workarea and window size, as it should be.
    19612007 *
    19622008 *@@added V0.9.1 (2000-02-14) [umoeller]
     
    19692015                                                // visible window part (in pixels),
    19702016                                                // excluding the scroll bar!
    1971                          ULONG ulViewportPels,  // in: dimension of total data part, of
     2017                         ULONG ulWorkareaPels,  // in: dimension of total data part, of
    19722018                                                // which ulWinPels is a sub-dimension
    19732019                                                // (in pixels);
     
    19822028    // _Pmpf(("Entering winhUpdateScrollBar"));
    19832029
    1984     // for large viewports, adjust scroll bar units
     2030    // for large workareas, adjust scroll bar units
    19852031    USHORT  usScrollUnitPels = 1;
    1986     if (ulViewportPels > 10000)
     2032    if (ulWorkareaPels > 10000)
    19872033        usScrollUnitPels = 100;
    19882034
    1989     if (ulViewportPels > ulWinPels)
     2035    if (ulWorkareaPels > ulWinPels)
    19902036    {
    19912037        // scrollbar needed:
    19922038        USHORT  usThumbDivisorUnits = usScrollUnitPels;
    19932039        USHORT  lMaxAllowedUnitOfs;
    1994         // _Pmpf(("winhUpdateScrollBar: ulViewportPels > ulWinPels, enabling scroller"));
     2040        // _Pmpf(("winhUpdateScrollBar: ulWorkareaPels > ulWinPels, enabling scroller"));
    19952041        // divisor for thumb size (below)
    1996         if (ulViewportPels > 10000)
    1997             // for very large viewports, we need to
     2042        if (ulWorkareaPels > 10000)
     2043            // for very large workareas, we need to
    19982044            // raise the divisor, because we only
    19992045            // have a USHORT
    20002046            usThumbDivisorUnits = usScrollUnitPels * 100;
    20012047
    2002         // viewport is larger than window:
     2048        // workarea is larger than window:
    20032049        WinEnableWindow(hwndScrollBar, TRUE);
    20042050        if (fAutoHide)
     
    20062052
    20072053        // calculate limit
    2008         lMaxAllowedUnitOfs = ((ulViewportPels - ulWinPels + usScrollUnitPels)
     2054        lMaxAllowedUnitOfs = ((ulWorkareaPels - ulWinPels + usScrollUnitPels)
    20092055                               // scroll unit is 10
    20102056                               / usScrollUnitPels);
     
    20212067
    20222068        // set thumb size based on ulWinPels and
    2023         // ulViewportPels
     2069        // ulWorkareaPels
    20242070        WinSendMsg(hwndScrollBar,
    20252071                   SBM_SETTHUMBSIZE,
    20262072                   MPFROM2SHORT(    ulWinPels / usThumbDivisorUnits,       // visible
    2027                                     ulViewportPels / usThumbDivisorUnits), // total
     2073                                    ulWorkareaPels / usThumbDivisorUnits), // total
    20282074                   0);
    20292075        brc = TRUE;
     
    20312077    else
    20322078    {
    2033         // _Pmpf(("winhUpdateScrollBar: ulViewportPels <= ulWinPels"));
    2034         // entire viewport is visible:
     2079        // _Pmpf(("winhUpdateScrollBar: ulWorkareaPels <= ulWinPels"));
     2080        // entire workarea is visible:
    20352081        WinEnableWindow(hwndScrollBar, FALSE);
    20362082        if (fAutoHide)
     
    20662112 *      of the scroll bar is:
    20672113 *
    2068  +          ulViewportPels - (prcl2Scroll->yTop - prcl2Scroll->yBottom)
     2114 +          ulWorkareaPels - (prcl2Scroll->yTop - prcl2Scroll->yBottom)
    20692115 *
    20702116 *      This function also automatically changes the scroll bar
    2071  *      units, should you have a viewport size which doesn't fit
     2117 *      units, should you have a workarea size which doesn't fit
    20722118 *      into the SHORT's that the scroll bar uses internally. As
    20732119 *      a result, this function handles a the complete range of
    2074  *      a ULONG for the viewport.
     2120 *      a ULONG for the workarea.
    20752121 *
    20762122 *      Replace "bottom" and "top" with "right" and "left" for
     
    20852131BOOL winhHandleScrollMsg(HWND hwnd2Scroll,          // in: client window to scroll
    20862132                         HWND hwndScrollBar,        // in: vertical or horizontal scroll bar window
    2087                          PULONG pulCurPelsOfs,      // in/out: current viewport offset;
     2133                         PULONG pulCurPelsOfs,      // in/out: current workarea offset;
    20882134                                                    // this is updated with the proper scroll units
    20892135                         PRECTL prcl2Scroll,        // in: hwnd2Scroll rectangle to scroll
     
    20912137                                                    // this is passed to WinScrollWindow,
    20922138                                                    // which considers this inclusive!
    2093                          LONG ulViewportPels,       // in: total viewport dimension,
     2139                         LONG ulWorkareaPels,       // in: total workarea dimension,
    20942140                                                    // into which *pulCurPelsOfs is an offset
    20952141                         USHORT usLineStepPels,     // in: pixels to scroll line-wise
     
    21062152    ULONG   ulWinPels;
    21072153
    2108     // for large viewports, adjust scroll bar units
     2154    // for large workareas, adjust scroll bar units
    21092155    USHORT  usScrollUnitPels = 1;
    2110     if (ulViewportPels > 10000)
     2156    if (ulWorkareaPels > 10000)
    21112157        usScrollUnitPels = 100;
    21122158
     
    21172163        ulWinPels = (prcl2Scroll->xRight - prcl2Scroll->xLeft);
    21182164
    2119     lMaxAllowedUnitOfs = ((LONG)ulViewportPels - ulWinPels) / usScrollUnitPels;
     2165    lMaxAllowedUnitOfs = ((LONG)ulWorkareaPels - ulWinPels) / usScrollUnitPels;
    21202166
    21212167    // _Pmpf(("Entering winhHandleScrollMsg"));
     
    22222268
    22232269/*
     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
     2278LONG 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
     2368BOOL 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/*
    22242383 *@@ winhProcessScrollChars:
    22252384 *      helper for processing WM_CHAR messages for
     
    22642423                            MPARAM mp1,         // in: WM_CHAR mp1
    22652424                            MPARAM mp2,         // in: WM_CHAR mp2
    2266                             ULONG ulVertMax,    // in: maximum viewport cy
    2267                             ULONG ulHorzMax)    // in: maximum viewport cx
     2425                            ULONG ulVertMax,    // in: maximum workarea cy
     2426                            ULONG ulHorzMax)    // in: maximum workarea cx
    22682427{
    22692428    BOOL    fProcessed = FALSE;
     
    33053464            fl |= QPF_ID2COLORINDEX;            // convert indexed color 2 to RGB V0.9.20 (2002-08-04) [umoeller]
    33063465
    3307         if ((ul = WinQueryPresParam(hwnd,
    3308                                     ulppRGB,
    3309                                     ulppIndex,
    3310                                     &attrFound,
    3311                                     sizeof(lColorFound),
    3312                                     &lColorFound,
    3313                                     fl)))
     3466        if (ul = WinQueryPresParam(hwnd,
     3467                                   ulppRGB,
     3468                                   ulppIndex,
     3469                                   &attrFound,
     3470                                   sizeof(lColorFound),
     3471                                   &lColorFound,
     3472                                   fl))
    33143473            return lColorFound;
    33153474    }
     
    42704429                           NULL,
    42714430                           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
     4440BOOL 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           );
    42724447}
    42734448
Note: See TracChangeset for help on using the changeset viewer.