Ignore:
Timestamp:
Nov 17, 2008, 12:17:05 AM (17 years ago)
Author:
pr
Message:

Fix scroll bar bugs in textview controls. Bug 1086.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1-0/src/helpers/winh.c

    r346 r374  
    1919
    2020/*
    21  *      Copyright (C) 1997-2006 Ulrich M”ller.
     21 *      Copyright (C) 1997-2008 Ulrich M”ller.
    2222 *      This file is part of the "XWorkplace helpers" source package.
    2323 *      This is free software; you can redistribute it and/or modify
     
    18571857 *      Terminology:
    18581858 *
    1859  *      -- "window": the actual window with scroll bars which displays
    1860  *         a subrectangle of the available data. With a typical PM
    1861  *         application, this will be your client window.
    1862  *
    1863  *         The width or height of this must be passed in ulWinPels.
    1864  *
    1865  *      -- "viewport": the entire data to be displayed, of which the
    1866  *         "window" can only display a subrectangle, if the viewport
    1867  *         is larger than the window.
    1868  *
    1869  *         The width or height of this must be passed in ulViewportPels.
    1870  *         This can be smaller than ulWinPels (if the window is larger
    1871  *         than the data) or the same or larger than ulWinPels
    1872  *         (if the window is too small to show all the data).
    1873  *
    1874  *      -- "window offset": the offset of the current window within
    1875  *         the viewport.
    1876  *
    1877  *         For horizontal scroll bars, this is the X coordinate,
    1878  *         counting from the left of the window (0 means leftmost).
    1879  *
    1880  *         For vertical scroll bars, this is counted from the _top_
    1881  *         of the viewport (0 means topmost, as opposed to OS/2
    1882  *         window coordinates!). This is because for vertical scroll
    1883  *         bars controls, higher values move the thumb _down_. Yes
    1884  *         indeed, this conflicts with PM's coordinate system.
    1885  *
    1886  *         The window offset is therefore always positive.
    1887  *
    1888  *      The scroll bar gets disabled if the entire viewport is visible,
    1889  *      that is, if ulViewportPels <= ulWinPels. In that case
     1859 *      --  "window": the actual window with scroll bars which displays
     1860 *          a subrectangle of the available data. With a typical PM
     1861 *          application, this will be your client window.
     1862 *
     1863 *          The width or height of this must be passed in ulWinPels.
     1864 *
     1865 *      --  "workarea": the entire data to be displayed, of which the
     1866 *          "window" can only display a subrectangle, if the workarea
     1867 *          is larger than the window.
     1868 *
     1869 *          The width or height of this must be passed in ulWorkareaPels.
     1870 *          This can be smaller than ulWinPels (if the window is larger
     1871 *          than the data) or the same or larger than ulWinPels
     1872 *          (if the window is too small to show all the data).
     1873 *
     1874 *          This value is exclusive in the sense that the maximum
     1875 *          window offset (below) can be the workarea minus one.
     1876 *
     1877 *      --  "window offset": the zero-based offset of the current
     1878 *          window within the workarea, whose maximum value is
     1879 *          the workarea minus one.
     1880 *
     1881 *          [pr]: I disagree with the above "workarea minus one" stuff.
     1882 *                It is perfectly possible to have the workarea and the
     1883 *                window area the same size and to display all the content.
     1884 *                This also means you do NOT get a disabled scroll bar
     1885 *                any more when they are the same size.
     1886 *
     1887 *          For horizontal scroll bars, this is the X coordinate,
     1888 *          counting from the left of the window (0 means leftmost).
     1889 *
     1890 *          For vertical scroll bars, this is counted from the _top_
     1891 *          of the workarea (0 means topmost, as opposed to OS/2
     1892 *          window coordinates!). This is because for vertical scroll
     1893 *          bars controls, higher values move the thumb _down_. Yes
     1894 *          indeed, this conflicts with PM's coordinate system.
     1895 *
     1896 *          The window offset is therefore always positive.
     1897 *
     1898 *      The scroll bar gets disabled if the entire workarea is visible,
     1899 *      that is, if ulWorkareaPels <= ulWinPels. In that case
    18901900 *      FALSE is returned. If (fAutoHide == TRUE), the scroll
    18911901 *      bar is not only disabled, but also hidden from the display.
    18921902 *      In that case, you will need to reformat your output because
    1893  *      your viewport becomes larger without the scroll bar.
     1903 *      your workarea becomes larger without the scroll bar.
    18941904 *
    18951905 *      This function will set the range of the scroll bar to 0 up
    1896  *      to a value depending on the viewport size. For vertical scroll
     1906 *      to a value depending on the workarea size. For vertical scroll
    18971907 *      bars, 0 means topmost (which is kinda sick with the OS/2
    18981908 *      coordinate system), for horizontal scroll bars, 0 means leftmost.
     
    19001910 *      The maximum value of the scroll bar will be
    19011911 *
    1902  +          (ulViewportPels - ulWinPels) / usScrollUnitPels
     1912 +          (ulWorkareaPels - ulWinPels) / usScrollUnitPels
    19031913 *
    19041914 *      The thumb size of the scroll bar will also be adjusted
    1905  *      based on the viewport and window size, as it should be.
     1915 *      based on the workarea and window size, as it should be.
    19061916 *
    19071917 *@@added V0.9.1 (2000-02-14) [umoeller]
    19081918 *@@changed V0.9.3 (2000-04-30) [umoeller]: fixed pels/unit confusion
    19091919 *@@changed V0.9.3 (2000-05-08) [umoeller]: now handling scroll units automatically
     1920 *@@changed V1.0.1 (2003-01-25) [umoeller]: fixed max value which caused right/bottommost scroll button to never be disabled
     1921 *@@changed V1.0.1 (2003-01-25) [umoeller]: fixed bad thumb position for large offsets
     1922 *@@changed WarpIN V1.0.18 (2008-11-16) [pr]: fix rounding errors @@fixes 1086
     1923 *@@changed WarpIN V1.0.18 (2008-11-16) [pr]: disable scroll bars when workarea = win area @@fixes 1086
    19101924 */
    19111925
     
    19141928                                                // visible window part (in pixels),
    19151929                                                // excluding the scroll bar!
    1916                          ULONG ulViewportPels,  // in: dimension of total data part, of
     1930                         ULONG ulWorkareaPels,  // in: dimension of total data part, of
    19171931                                                // which ulWinPels is a sub-dimension
    19181932                                                // (in pixels);
     
    19251939    BOOL brc = FALSE;
    19261940
    1927     // _Pmpf(("Entering winhUpdateScrollBar"));
    1928 
    1929     // for large viewports, adjust scroll bar units
    1930     USHORT  usScrollUnitPels = 1;
    1931     if (ulViewportPels > 10000)
    1932         usScrollUnitPels = 100;
    1933 
    1934     if (ulViewportPels > ulWinPels)
    1935     {
     1941    if (ulWorkareaPels > ulWinPels) // WarpIN V1.0.18
     1942    {
     1943        // for large workareas, adjust scroll bar units
     1944        USHORT  usDivisor = 1, usRounder;
     1945        USHORT  lMaxAllowedUnitOfs;
     1946
     1947        if (ulWorkareaPels > 10000)
     1948            usDivisor = 100;
     1949
     1950        usRounder = usDivisor - 1;  // WarpIN V1.0.18
    19361951        // scrollbar needed:
    1937         USHORT  usThumbDivisorUnits = usScrollUnitPels;
    1938         USHORT  lMaxAllowedUnitOfs;
    1939         // _Pmpf(("winhUpdateScrollBar: ulViewportPels > ulWinPels, enabling scroller"));
    1940         // divisor for thumb size (below)
    1941         if (ulViewportPels > 10000)
    1942             // for very large viewports, we need to
    1943             // raise the divisor, because we only
    1944             // have a USHORT
    1945             usThumbDivisorUnits = usScrollUnitPels * 100;
    1946 
    1947         // viewport is larger than window:
     1952
     1953        // workarea is larger than window:
    19481954        WinEnableWindow(hwndScrollBar, TRUE);
    19491955        if (fAutoHide)
     
    19511957
    19521958        // calculate limit
    1953         lMaxAllowedUnitOfs = ((ulViewportPels - ulWinPels + usScrollUnitPels)
    1954                                // scroll unit is 10
    1955                                / usScrollUnitPels);
    1956 
    1957         // _Pmpf(("    usCurUnitOfs: %d", ulCurUnitOfs));
    1958         // _Pmpf(("    usMaxUnits: %d", lMaxAllowedUnitOfs));
     1959        lMaxAllowedUnitOfs =   (ulWorkareaPels - ulWinPels + usRounder)
     1960                             / usDivisor;
    19591961
    19601962        // set thumb position and limit
    19611963        WinSendMsg(hwndScrollBar,
    19621964                   SBM_SETSCROLLBAR,
    1963                    (MPARAM)(ulCurPelsOfs), //  / usThumbDivisorUnits),   // position: 0 means top
     1965                   (MPARAM)((ulCurPelsOfs + usRounder) / usDivisor),   // position: 0 means top
    19641966                   MPFROM2SHORT(0,  // minimum
    19651967                                lMaxAllowedUnitOfs));    // maximum
    19661968
    19671969        // set thumb size based on ulWinPels and
    1968         // ulViewportPels
     1970        // ulWorkareaPels
    19691971        WinSendMsg(hwndScrollBar,
    19701972                   SBM_SETTHUMBSIZE,
    1971                    MPFROM2SHORT(    ulWinPels / usThumbDivisorUnits,       // visible
    1972                                     ulViewportPels / usThumbDivisorUnits), // total
     1973                   MPFROM2SHORT(    (ulWinPels + usRounder) / usDivisor,       // visible
     1974                                    (ulWorkareaPels + usRounder) / usDivisor), // total
    19731975                   0);
    19741976        brc = TRUE;
     
    19761978    else
    19771979    {
    1978         // _Pmpf(("winhUpdateScrollBar: ulViewportPels <= ulWinPels"));
    1979         // entire viewport is visible:
     1980        // entire workarea is visible:
    19801981        WinEnableWindow(hwndScrollBar, FALSE);
    19811982        if (fAutoHide)
     
    20262027 *@@changed V0.9.3 (2000-05-08) [umoeller]: now handling scroll units automatically
    20272028 *@@changed V0.9.7 (2001-01-17) [umoeller]: changed PLONG to PULONG
     2029 *@@changed WarpIN V1.0.18 (2008-11-16) [pr]: fix rounding error @@fixes 1086
    20282030 */
    20292031
     
    21272129        WinSendMsg(hwndScrollBar,
    21282130                   SBM_SETPOS,
    2129                    (MPARAM)(*pulCurPelsOfs / usScrollUnitPels), //  / usScrollUnit),
     2131                   (MPARAM)((*pulCurPelsOfs + (usScrollUnitPels / 2)) / usScrollUnitPels),
     2132                   (MPARAM)((*pulCurPelsOfs + (usScrollUnitPels / 2)) / usScrollUnitPels),  // WarpIN V1.0.18
    21302133                   0);
    21312134        // scroll window rectangle:
Note: See TracChangeset for help on using the changeset viewer.